diff --git a/.gitignore b/.gitignore index 4c2e4f0..1393016 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ tmp/* build/* autom4te.cache aclocal.m4 -configure \ No newline at end of file +configure +configure diff --git a/README.md b/README.md index 20e0331..af13f35 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## Caesium Command Line Tools -##### CCLT - v0.9.1-beta (build 20151012) - Copyright © Matteo Paonessa, 2015. All Rights Reserved. +##### CCLT - v0.9.1-beta (build 20160121) - Copyright © Matteo Paonessa, 2016. All Rights Reserved. ---------- @@ -11,7 +11,7 @@ ---------- ###### TESTED PLATFORMS -* MacOSX El Capitan (v. 10.11) +* Mac OS X El Capitan (v10.11.1) * Arch Linux * Ubuntu 14.04.2 @@ -23,30 +23,26 @@ See INSTALL for more details. ---------- ###### USAGE EXAMPLES + +Losslessly compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` ``` $ caesiumclt -l -o ~/output/ ~/image.jpg ``` -Losslessly compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` +Compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` with lossy compression and quality set to 80 ``` $ caesiumclt -q 80 -o ~/output/ ~/image.jpg ``` -Compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` with lossy compression and quality set to 80 +Losslessly compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` and keeps EXIF metadata ``` $ caesiumclt -l -e -o ~/output/ ~/image.jpg ``` -Losslessly compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` and keeps EXIF metadata +Losslessly compress ```Pictures``` folder and subfolders, located in the ```home``` directory, into a folder called ```output``` ``` $ caesiumclt -l -R -o ~/output/ ~/Pictures ``` -Losslessly compress ```Pictures``` folder and subfolders, located in the ```home``` directory, into a folder called ```output``` - -``` -$ caesiumclt -q 80 -s 50% -o ~/output/ ~/image1.jpg -``` -Compress with quality 80 and resize at 50% ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` ---------- diff --git a/configure b/configure index e3f62c7..220c71b 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for caesiumclt 1.9.9. +# Generated by GNU Autoconf 2.69 for caesiumclt 0.9.1-beta. # # Report bugs to . # @@ -580,8 +580,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='caesiumclt' PACKAGE_TARNAME='caesiumclt' -PACKAGE_VERSION='1.9.9' -PACKAGE_STRING='caesiumclt 1.9.9' +PACKAGE_VERSION='0.9.1-beta' +PACKAGE_STRING='caesiumclt 0.9.1-beta' PACKAGE_BUGREPORT='caesium@saerasoft.com' PACKAGE_URL='' @@ -1267,7 +1267,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures caesiumclt 1.9.9 to adapt to many kinds of systems. +\`configure' configures caesiumclt 0.9.1-beta to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1333,7 +1333,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of caesiumclt 1.9.9:";; + short | recursive ) echo "Configuration of caesiumclt 0.9.1-beta:";; esac cat <<\_ACEOF @@ -1429,7 +1429,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -caesiumclt configure 1.9.9 +caesiumclt configure 0.9.1-beta generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1852,7 +1852,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by caesiumclt $as_me 1.9.9, which was +It was created by caesiumclt $as_me 0.9.1-beta, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2716,7 +2716,7 @@ fi # Define the identity of the package. PACKAGE='caesiumclt' - VERSION='1.9.9' + VERSION='0.9.1-beta' cat >>confdefs.h <<_ACEOF @@ -5130,7 +5130,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by caesiumclt $as_me 1.9.9, which was +This file was extended by caesiumclt $as_me 0.9.1-beta, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5187,7 +5187,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -caesiumclt config.status 1.9.9 +caesiumclt config.status 0.9.1-beta configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 8d5b12d..498eeb7 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([caesiumclt], [1.9.9], [caesium@saerasoft.com]) +AC_INIT([caesiumclt], [0.9.1-beta], [caesium@saerasoft.com]) AC_CONFIG_SRCDIR([src/]) AC_CONFIG_AUX_DIR(tools) AM_INIT_AUTOMAKE(-Wall -Werror foreign) @@ -22,10 +22,10 @@ AC_ARG_WITH(libjpeg, [ --libjpeg=DIR libjpeg is installed in ], fi if test -d "${jpeginfo_cv_libjpeg}/lib"; then LDFLAGS="-L${jpeginfo_cv_libjpeg}/lib $LDFLAGS" - CPPFLAGS="$CPPFLAGS -I${jpeginfo_cv_libjpeg}/include" + CPPFLAGS="$CPPFLAGS -I${jpeginfo_cv_libjpeg}/include" else LDFLAGS="-L${jpeginfo_cv_libjpeg} $LDFLAGS" - CPPFLAGS="$CPPFLAGS -I${jpeginfo_cv_libjpeg}" + CPPFLAGS="$CPPFLAGS -I${jpeginfo_cv_libjpeg}" fi]) # Checks for libraries. diff --git a/src/compresshelper.c b/src/compresshelper.c index 1c6ff64..98e7350 100644 --- a/src/compresshelper.c +++ b/src/compresshelper.c @@ -5,8 +5,8 @@ #include #include #include -#include #include +#include #include "utils.h" #include "jpeg.h" @@ -88,9 +88,10 @@ cclt_compress_parameters parse_arguments(int argc, char* argv[]) { } } else { int i = 0; - if (isDirectory(argv[optind])) { + if (is_directory(argv[optind])) { //TODO Works but I'd like to pass the list and return the number of files instead - parameters.input_files = scan_folder(argv[optind], ¶meters.input_files_count, parameters.recursive); + parameters.input_files_count = scan_folder(parameters.input_files, argv[optind], parameters.recursive); + //parameters.input_files = scan_folder(argv[optind], ¶meters.input_files_count, parameters.recursive); return parameters; } parameters.input_files = (char**) malloc ((argc - optind) * sizeof (char*)); diff --git a/src/jpeg.c b/src/jpeg.c index 742d051..7c9ebc5 100644 --- a/src/jpeg.c +++ b/src/jpeg.c @@ -167,7 +167,6 @@ void cclt_jpeg_compress(char* output_file, unsigned char* image_buffer, cclt_com output_buffer = NULL; tjCompressHandle = tjInitCompress(); - //TODO Scale must be a power of 2. Can we resolve it? //TODO Error checks tjCompress2(tjCompressHandle, image_buffer, diff --git a/src/main.c b/src/main.c index 575d61d..5d68fc9 100755 --- a/src/main.c +++ b/src/main.c @@ -45,9 +45,13 @@ void cclt_start(char** input_files, int n, char* output_folder, cclt_compress_pa off_t i_size, o_size; int status; //Pointer for stat() call + char* output_filename = (char*) malloc ((strlen(output_folder) + 1) * sizeof(char)); + //CRITICAL SEGFUCKINGFAULT + //TODO input_files[i] รจ NULL when we pass a folder with -R char* i_tmp = (char*) malloc (strlen(input_files[i]) * sizeof(char)); + strcpy(i_tmp, input_files[i]); strcpy(output_filename, output_folder); @@ -61,9 +65,6 @@ void cclt_start(char** input_files, int n, char* output_folder, cclt_compress_pa output_filename = realloc(output_filename, (strlen(output_filename) + strlen(basename(i_tmp))) * sizeof(char)); output_filename = strcat(output_filename, basename(i_tmp)); - //TODO OVERALL progress update? - //print_progress(i + 1, pars.input_files_count, "Progress: "); - //Get input stats status = stat(input_files[i], &st_buf); if (status != 0) { @@ -73,7 +74,7 @@ void cclt_start(char** input_files, int n, char* output_folder, cclt_compress_pa //Check if we ran into a folder //TODO Check symlinks too - if (isDirectory(input_files[i])) { + if (is_directory(input_files[i])) { //Folder found, but we don't need it here printf("Folder found\n"); i++; @@ -161,6 +162,9 @@ int main (int argc, char *argv[]) { clock_t start = clock(), diff; //We need the file list right here cclt_start(pars.input_files, pars.input_files_count, pars.output_folder, &pars, &i_t_size, &o_t_size); + /*for (int i = 0; i < pars.input_files_count; i++) { + printf("FILE %d: %s\n", i, pars.input_files[i]); + }*/ diff = clock() - start; fprintf(stdout, "-------------------------------\nCompression completed in %lum%lus\n%s -> %s [%.2f%% | %s]\n", @@ -171,5 +175,5 @@ int main (int argc, char *argv[]) { ((float) o_t_size - i_t_size) * 100 / i_t_size, get_human_size(((long) o_t_size - i_t_size))); - exit(0); + return 0; } diff --git a/src/utils.c b/src/utils.c index 815d771..49c86e4 100644 --- a/src/utils.c +++ b/src/utils.c @@ -51,7 +51,6 @@ void print_help() { "\t-e\tkeeps EXIF info during compression\n" "\t-o\tcompress to custom folder\n" "\t-l\tuse lossless optimization\n" - "\t-s\tscale to value, expressed as percentage (e.g. 20%%) [Only 1/2^n allowed]\n" "\t-R\tif input is a folder, scan subfolders too\n" //TODO Remove this warning "\t-S\tkeep the folder structure [Not active yet]\n" @@ -60,14 +59,6 @@ void print_help() { exit(0); } -void print_progress(int current, int max, char* message) { - fprintf(stdout, "\e[?25l"); - fprintf(stdout, "\r%s[%d%%]", message, current * 100 / max); - if (current == max) { - fprintf(stdout, "\e[?25h\n"); - } -} - //TODO Recheck int mkpath(const char *pathname, mode_t mode) { @@ -76,7 +67,7 @@ int mkpath(const char *pathname, mode_t mode) { /* make a parent directory path */ strncpy(parent, pathname, sizeof(parent)); parent[sizeof(parent) - 1] = '\0'; - for(p = parent + strlen(parent); *p != '/' && p != parent; p--); + for (p = parent + strlen(parent); *p != '/' && p != parent; p--); *p = '\0'; /* try make parent directory */ if(p != parent && mkpath(parent, mode) != 0) { @@ -93,19 +84,18 @@ int mkpath(const char *pathname, mode_t mode) { return -1; } -char** scan_folder(char* basedir, int* n, int recur) { +int scan_folder(char** fileList, char* basedir, int recur) { + //TODO CRITIAL Pass list as 1st parameter DIR *dir; struct dirent *ent; char* entpath = NULL; struct stat s; int indexes = 0; int i = 0; - char** fileList = NULL; char absolute_path[PATH_MAX]; char* ptr = realpath(basedir, absolute_path); - dir = opendir(ptr); if (dir != NULL) { @@ -130,7 +120,7 @@ char** scan_folder(char* basedir, int* n, int recur) { if (S_ISDIR(s.st_mode)) { // Directory, walk it if recursive is set if (recur != 0) { - fileList = scan_folder(entpath, n, recur); + scan_folder(fileList, entpath, recur); } } else { //File, add to the list @@ -142,6 +132,7 @@ char** scan_folder(char* basedir, int* n, int recur) { fileList[i] = (char*) malloc(strlen(entpath) * sizeof(char)); //Copy the file path in the array fileList[i] = strcpy(fileList[i], entpath); + printf("%s\n", fileList[i]); i++; } } @@ -151,8 +142,8 @@ char** scan_folder(char* basedir, int* n, int recur) { exit(-19); } free(entpath); - *n = i; - return fileList; + + return i; } enum image_type detect_image_type(char* path) { @@ -187,7 +178,7 @@ enum image_type detect_image_type(char* path) { } } -int isDirectory(const char *file_path) { +int is_directory(const char *file_path) { struct stat s; stat(file_path, &s); return S_ISDIR(s.st_mode); diff --git a/src/utils.h b/src/utils.h index 2da5312..1d4ac88 100644 --- a/src/utils.h +++ b/src/utils.h @@ -6,7 +6,7 @@ #include #define APP_VERSION "0.9.1-beta" -#define BUILD 20150921 +#define BUILD 20160116 typedef struct cclt_compress_parameters { int quality; @@ -32,11 +32,10 @@ enum image_type { int string_to_int(char* in_string); void print_help(); -void print_progress(int current, int max, char* message); int mkpath(const char *pathname, mode_t mode); enum image_type detect_image_type(char* path); -int isDirectory(const char *file_path); -char** scan_folder(char* basedir, int* n, int recur); +int is_directory(const char *file_path); +int scan_folder(char** fileList, char* basedir, int recur); char* get_human_size(long size); #endif