Example use of compression filters.
#include "tools.h"
void print_filter_help() {
printf("Usage: filter -f [flate|dct|ascii85|ascii_hex] [encode|decode] -s [source file] -d [destination file]");
}
int process_filter(int argc, char *argv[]) {
int arg_counter = 0;
const char *filter_type = NULL;
const char *operation = NULL;
const char *source_file = NULL;
const char *destination_file = NULL;
for (arg_counter = 0; arg_counter < argc; ++arg_counter) {
if (strcmp(argv[arg_counter], "-f") == 0 && (arg_counter + 2 < argc)) {
filter_type = argv[arg_counter + 1];
operation = argv[arg_counter + 2];
arg_counter++;
arg_counter++;
} else if (strcmp(argv[arg_counter], "-s") == 0 && (arg_counter + 1 < argc)) {
source_file = argv[arg_counter + 1];
arg_counter++;
} else if (strcmp(argv[arg_counter], "-d") == 0 && (arg_counter + 1 < argc)) {
destination_file = argv[arg_counter + 1];
arg_counter++;
} else {
print_filter_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
}
if (filter_type == NULL || operation == NULL || source_file == NULL || destination_file == NULL) {
print_filter_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
is_encode = (strcmp(operation, "encode") == 0);
is_decode = (strcmp(operation, "decode") == 0);
if (!is_encode && !is_decode) {
print_filter_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
is_flate_decode = (strcmp(filter_type, "flate") == 0);
is_dct_decode = (strcmp(filter_type, "dct") == 0);
is_ascii85_decode = (strcmp(filter_type, "ascii85") == 0);
is_ascii_hex_decode = (strcmp(filter_type, "ascii_hex") == 0);
if (!is_flate_decode && !is_dct_decode && !is_ascii85_decode && !is_ascii_hex_decode) {
print_filter_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
if (is_flate_decode) {
if (is_encode) {
}
if (is_decode) {
}
}
if (is_dct_decode) {
if (is_encode) {
}
if (is_decode) {
}
}
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}