diff options
Diffstat (limited to 'examples/c4add.c')
| -rw-r--r-- | examples/c4add.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/c4add.c b/examples/c4add.c new file mode 100644 index 0000000..2fa7e82 --- /dev/null +++ b/examples/c4add.c @@ -0,0 +1,42 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "cc4group.h" + +int main(int argc, char* argv[]) +{ + if(argc != 3 && argc != 4) + { + fprintf(stderr, "USAGE: %s <group> <file|directory> [target path]\n", argv[0]); + return EXIT_FAILURE; + } + + CC4Group* group = cc4group.new(); + bool success = cc4group.openExisting(group, argv[1]); + if(!success) + { + fprintf(stderr, "ERROR: Can not open group file \"%s\": %s\n", argv[1], cc4group.getErrorMessage(group)); + } + else + { + success = cc4group.addFromDisk(group, argv[2], argc == 4 ? argv[3] : argv[2], cc4group.AllowedEntryTypes.All); + + if(!success) + { + fprintf(stderr, "ERROR: Can not add file/directory \"%s\" from disk: %s\n", argv[2], cc4group.getErrorMessage(group)); + } + else + { + success = cc4group.saveOverwrite(group, argv[1]); + + if(!success) + { + fprintf(stderr, "ERROR: Can not save group file \"%s\": %s\n", argv[2], cc4group.getErrorMessage(group)); + } + } + } + cc4group.delete(group); + + return success ? EXIT_SUCCESS : EXIT_FAILURE; +} |
