#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);
RETURN_ERROR_IF_NOT_SUCCESS(InputOutputStream_ToOutputStream(input_output_stream, &output_stream));
RETURN_ERROR_IF_NOT_SUCCESS(OutputStream_GetOutputPosition(output_stream, ¤t_offset));
RETURN_ERROR_IF_NOT_SUCCESS(OutputStream_Release(output_stream));
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);
RETURN_ERROR_IF_NOT_SUCCESS(InputOutputStream_ToOutputStream(input_output_stream, &output_stream));
RETURN_ERROR_IF_NOT_SUCCESS(OutputStream_GetOutputPosition(output_stream, ¤t_offset));
RETURN_ERROR_IF_NOT_SUCCESS(OutputStream_Release(output_stream));
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(File_Initialize(source_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_Create(&file_writer));
RETURN_ERROR_IF_NOT_SUCCESS(FileWriter_Subscribe(file_writer, file_writer_observer));
RETURN_ERROR_IF_NOT_SUCCESS(FileWriter_Write(file_writer, source_file, destination_file));
RETURN_ERROR_IF_NOT_SUCCESS(FileWriter_Release(file_writer));
RETURN_ERROR_IF_NOT_SUCCESS(FileWriterObserver_Release(file_writer_observer));
RETURN_ERROR_IF_NOT_SUCCESS(File_Release(destination_file));
RETURN_ERROR_IF_NOT_SUCCESS(File_Release(source_file));
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}
Represents low-level file access handle.
Implements serialization of Files to destination stream.
Allows hooking on FileWriterHandle events.
Output stream can write sequences of characters and represent other kinds of data.
const error_type VANILLAPDF_ERROR_SUCCESS
Indicates that the operation completed successfully.
uint32_t error_type
This is return value type of all API functions.
Definition c_types.h:25
int64_t offset_type
Offset type compatible with standard IO.
Definition c_types.h:56
int32_t integer_type
32-bit signed integer
Definition c_types.h:51
const char * string_type
C-Style string.
Definition c_types.h:82