#include "tools.h"
void print_write_custom_help() {
printf("Usage: write_custom -s [source file] -d [destination file]");
}
typedef struct {
int data;
} ObserverData;
ObserverData* observer_data = (ObserverData*) user_data;
long long current_offset_converted = 0;
UNUSED(observer_data);
current_offset_converted = current_offset;
printf("File writer is initializing\n");
printf("Current output position: %lld\n", current_offset_converted);
}
ObserverData* observer_data = (ObserverData*) user_data;
long long current_offset_converted = 0;
UNUSED(observer_data);
current_offset_converted = current_offset;
printf("File writer is finalizing\n");
printf("Current output position: %lld\n", current_offset_converted);
}
int process_write_custom(int argc, char *argv[]) {
ObserverData observer_data = { 0 };
for (i = 0; i < argc; ++i) {
if (strcmp(argv[i], "-s") == 0 && (i + 1 < argc)) {
source_file_path = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-d") == 0 && (i + 1 < argc)) {
destination_file_path = argv[i + 1];
i++;
} else {
print_write_custom_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
}
if (source_file_path == NULL || destination_file_path == NULL) {
print_write_custom_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
RETURN_ERROR_IF_NOT_SUCCESS(
File_Open(source_file_path, &source_file));
RETURN_ERROR_IF_NOT_SUCCESS(
File_Create(destination_file_path, &destination_file));
RETURN_ERROR_IF_NOT_SUCCESS(
FileWriterObserver_CreateCustom(on_initializing, on_finalizing, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &observer_data, &file_writer_observer));
RETURN_ERROR_IF_NOT_SUCCESS(
FileWriter_Write(file_writer, source_file, destination_file));
RETURN_ERROR_IF_NOT_SUCCESS(
File_Release(destination_file));
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}