diff --git a/.gitignore b/.gitignore index f567c79..8ef00d0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,163 @@ Thumbs.db .Spotlight-V100 .Trashes -.idea +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake cmake-build-* -build \ No newline at end of file + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +### macOS template +# General +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.TemporaryItems +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +### Linux template +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* +### Windows template +# Windows thumbnail cache files +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk +### C template +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf \ No newline at end of file diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..572ef0b --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +caesiumclt \ No newline at end of file diff --git a/.idea/caesium-clt.iml b/.idea/caesium-clt.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/caesium-clt.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..ecc50f5 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,125 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..81967a4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..96d27b3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/scopes/Inspection.xml b/.idea/scopes/Inspection.xml new file mode 100644 index 0000000..7eb5c79 --- /dev/null +++ b/.idea/scopes/Inspection.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/helper.c b/src/helper.c index d81d10a..61c37e0 100644 --- a/src/helper.c +++ b/src/helper.c @@ -7,7 +7,7 @@ #include #define getcwd _getcwd #else -#include + #endif #include "helper.h" @@ -40,33 +40,27 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options) while ((option = optparse_long(&opts, longopts, NULL)) != -1) { switch (option) { case 'q': - options->jpeg.quality = atoi(opts.optarg); + options->jpeg.quality = (int)strtol(opts.optarg, (char **)NULL, 10);; if (options->jpeg.quality < 0 || options->jpeg.quality > 100) { display_error(ERROR, 1); } break; case 'e': options->jpeg.exif_copy = true; - case 'p': - options->jpeg.progressive = false; - break; case 'o': - realpath(opts.optarg, parameters.output_folder); - //TODO Resolve ~ if (opts.optarg[0] == '~') { - snprintf(parameters.output_folder, strlen(parameters.output_folder), "%s", parameters.output_folder); + if (opts.optarg[strlen(opts.optarg) - 1] == '/' || opts.optarg[strlen(opts.optarg) - 1] == '\\') { + snprintf(parameters.output_folder, strlen(opts.optarg) + 1, "%s", opts.optarg); + } else { +#ifdef _WIN32 + snprintf(parameters.output_folder, strlen(opts.optarg) + 2, "%s\\", opts.optarg); +#else + snprintf(parameters.output_folder, strlen(opts.optarg) + 2, "%s/", opts.optarg); +#endif + } + } else { + realpath(opts.optarg, parameters.output_folder); } -// if (opts.optarg[strlen(opts.optarg) - 1] == '/' || opts.optarg[strlen(opts.optarg) - 1] == '\\') { -// snprintf(parameters.output_folder, strlen(opts.optarg) + 1, "%s", opts.optarg); -// } else { -//#ifdef _WIN32 -// snprintf(parameters.output_folder, strlen(opts.optarg) + 2, "%s\\", opts.optarg); -//#else -// snprintf(parameters.output_folder, strlen(opts.optarg) + 2, "%s/", opts.optarg); -//#endif -// } - - //Prepend the current directory if necessary break; case 'R': parameters.recursive = true; @@ -89,7 +83,6 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options) display_error(ERROR, 2); } } - //Remaining arguments char *arg; bool files_flag = false, folders_flag = false; @@ -101,25 +94,23 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options) } //Check if it's a directory and add its content - realpath(arg, resolved_path); - //TODO Resolve ~ if (arg[0] == '~') { - snprintf(resolved_path, strlen(resolved_path), "%s", resolved_path); + if (arg[strlen(arg) - 1] == '/' || arg[strlen(arg) - 1] == '\\') { + snprintf(resolved_path, strlen(arg), "%s", arg); + } else { +#ifdef _WIN32 + snprintf(resolved_path, strlen(arg) + 1, "%s\\", arg); +#else + snprintf(resolved_path, strlen(arg) + 1, "%s/", arg); +#endif + } + } else { + realpath(arg, resolved_path); } if (is_directory(resolved_path)) { if (!files_flag) { folders_flag = true; snprintf(parameters.input_folder, strlen(resolved_path) + 1, "%s", resolved_path); -// if (arg[strlen(arg) - 1] == '/' || arg[strlen(arg) - 1] == '\\') { -// parameters.input_folder = strdup(arg); -// } else { -// parameters.input_folder = malloc((strlen(arg) + 2) * sizeof(char)); -//#ifdef _WIN32 -// snprintf(parameters.input_folder, (strlen(arg) + 2), "%s\\", arg); -//#else -// snprintf(parameters.input_folder, (strlen(arg) + 2), "%s/", arg); -//#endif -// } int count = 0; count = scan_folder(resolved_path, ¶meters, parameters.recursive); if (count == 0) { @@ -199,7 +190,8 @@ int start_compression(cclt_options *options, cs_image_pars *parameters) snprintf(output_full_folder, strlen(options->output_folder) + size + 1, "%s%s", options->output_folder, &options->input_files[i][index]); output_full_path = malloc((strlen(output_full_folder) + strlen(filename) + 1) * sizeof(char)); - snprintf(output_full_path, strlen(output_full_folder) + strlen(filename) + 1, "%s%s", output_full_folder, + snprintf(output_full_path, strlen(output_full_folder) + strlen(filename) + 1, "%s%s", + output_full_folder, filename); mkpath(output_full_folder); diff --git a/src/main.c b/src/main.c index f25c067..d4e47e8 100755 --- a/src/main.c +++ b/src/main.c @@ -4,8 +4,6 @@ #include #include "utils.h" -#include - int main(int argc, char *argv[]) { @@ -29,7 +27,7 @@ int main(int argc, char *argv[]) start_compression(&options, &compress_options); - //Cleanup the two memory allocated objects + //Cleanup the memory allocated objects free(options.input_files); //Get the difference diff --git a/src/utils.c b/src/utils.c index 4980e03..5afb0fe 100644 --- a/src/utils.c +++ b/src/utils.c @@ -4,7 +4,6 @@ #include #include #include -#include #include "utils.h" #include "tinydir.h" @@ -21,7 +20,6 @@ void print_help() "Options:\n" "\t-q, --quality\t\tset output file quality between [0-100], 0 for optimization\n" "\t-e, --exif\t\tkeeps EXIF info during compression\n" - "\t-p, --progressive\t\toutputs a progressive JPEG\n" "\t-o, --output\t\toutput folder\n" "\t-R, --recursive\t\tif input is a folder, scan subfolders too\n" "\t-S, --keep-structure\tkeep the folder structure, use with -R\n" @@ -141,6 +139,10 @@ off_t get_file_size(const char *path) char *get_human_size(off_t size) { + if (size == 0) { + return "0.00 B"; + } + //We should not get more than TB images char *unit[5] = {"B", "KB", "MB", "GB", "TB"}; //Index of the array containing the correct unit