Initial
This commit is contained in:
parent
fd6e9c64e7
commit
4af0415e73
|
@ -3,8 +3,8 @@ project(caesiumclt)
|
|||
|
||||
# The version number.
|
||||
set(VERSION_MAJOR 0)
|
||||
set(VERSION_MINOR 10)
|
||||
set(VERSION_PATCH 2)
|
||||
set(VERSION_MINOR 11)
|
||||
set(VERSION_PATCH 0)
|
||||
|
||||
configure_file(
|
||||
"src/config.h.in"
|
||||
|
|
|
@ -39,9 +39,9 @@ const char *get_error_message(int code)
|
|||
case 9:
|
||||
return "Input files provided. Cannot mix them with a folder.";
|
||||
case 10:
|
||||
return "-R is useless on files.";
|
||||
return "-R has no effects on files.";
|
||||
case 11:
|
||||
return "-S is useless without -R.";
|
||||
return "-S has no effect without -R.";
|
||||
case 12:
|
||||
return "Cannot set output folder inside the input one";
|
||||
|
||||
|
|
11
src/helper.c
11
src/helper.c
|
@ -18,6 +18,7 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options)
|
|||
struct optparse_long longopts[] = {
|
||||
{"quality", 'q', OPTPARSE_REQUIRED},
|
||||
{"exif", 'e', OPTPARSE_NONE},
|
||||
{"progressive", 'p', OPTPARSE_NONE},
|
||||
{"output", 'o', OPTPARSE_REQUIRED},
|
||||
{"recursive", 'R', OPTPARSE_NONE},
|
||||
{"keep-structure", 'S', OPTPARSE_NONE},
|
||||
|
@ -37,6 +38,8 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options)
|
|||
break;
|
||||
case 'e':
|
||||
options->jpeg.exif_copy = true;
|
||||
case 'p':
|
||||
options->jpeg.progressive = false;
|
||||
break;
|
||||
case 'o':
|
||||
if (opts.optarg[strlen(opts.optarg) - 1] == '/' || opts.optarg[strlen(opts.optarg) - 1] == '\\') {
|
||||
|
@ -76,7 +79,7 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options)
|
|||
while ((arg = optparse_arg(&opts))) {
|
||||
if (folders_flag) {
|
||||
display_error(WARNING, 8);
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
//Check if it's a directory and add its content
|
||||
if (is_directory(arg)) {
|
||||
|
@ -155,9 +158,11 @@ int start_compression(cclt_options *options, cs_image_pars *parameters)
|
|||
size_t index = strspn(options->input_folder, options->input_files[i]) + 1;
|
||||
size_t size = strlen(options->input_files[i]) - index - strlen(filename);
|
||||
char output_full_folder[strlen(options->output_folder) + size + 1];
|
||||
snprintf(output_full_folder, strlen(options->output_folder) + size + 1, "%s%s", options->output_folder, &options->input_files[i][index]);
|
||||
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, filename);
|
||||
snprintf(output_full_path, strlen(output_full_folder) + strlen(filename) + 1, "%s%s", output_full_folder,
|
||||
filename);
|
||||
mkpath(output_full_folder);
|
||||
}
|
||||
|
||||
|
|
|
@ -99,11 +99,6 @@ int optparse(struct optparse *options, const char *optstring)
|
|||
int type = argtype(optstring, option[0]);
|
||||
char *next = options->argv[options->optind + 1];
|
||||
switch (type) {
|
||||
case -1: {
|
||||
options->optind++;
|
||||
char str[2] = {option[0]};
|
||||
return opterror(options, MSG_INVALID, str);
|
||||
}
|
||||
case OPTPARSE_NONE:
|
||||
if (option[1]) {
|
||||
options->subopt++;
|
||||
|
@ -134,8 +129,13 @@ int optparse(struct optparse *options, const char *optstring)
|
|||
else
|
||||
options->optarg = 0;
|
||||
return option[0];
|
||||
default:
|
||||
case -1: {
|
||||
options->optind++;
|
||||
char str[2] = {option[0]};
|
||||
return opterror(options, MSG_INVALID, str);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *optparse_arg(struct optparse *options)
|
||||
|
|
|
@ -19,6 +19,7 @@ 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"
|
||||
|
@ -107,9 +108,7 @@ char *get_filename(char *full_path)
|
|||
|
||||
//Get just the filename
|
||||
tofree = strdup(full_path);
|
||||
//TODO change to strncpy
|
||||
strcpy(tofree, full_path);
|
||||
//TODO Windows?
|
||||
snprintf(tofree, strlen(full_path) + 1, "%s", full_path);
|
||||
#ifdef _WIN32
|
||||
while ((token = strsep(&tofree, "\\")) != NULL) {
|
||||
#else
|
||||
|
@ -132,7 +131,7 @@ off_t get_file_size(const char *path)
|
|||
display_error(ERROR, 7);
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
unsigned long len = (unsigned long)ftell(f);
|
||||
off_t len = ftell(f);
|
||||
fclose(f);
|
||||
|
||||
return len;
|
||||
|
|
Loading…
Reference in New Issue