diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2018-08-15 22:46:40 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2018-08-15 23:15:15 +0200 |
| commit | 0d1ae015fef8e15442dafa61b9c8d929ce467969 (patch) | |
| tree | a8d56fd12f5c5366e1f6fa3ecc20c78c0202f747 /examples/unc4group.c | |
| parent | e04f662a42c75cb202684e7254d3b7600e6e1756 (diff) | |
| download | cc4group-0d1ae015fef8e15442dafa61b9c8d929ce467969.tar.gz cc4group-0d1ae015fef8e15442dafa61b9c8d929ce467969.zip | |
Refactor code into a library and implement basic file management methods
Diffstat (limited to 'examples/unc4group.c')
| -rw-r--r-- | examples/unc4group.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/unc4group.c b/examples/unc4group.c new file mode 100644 index 0000000..8d08eb3 --- /dev/null +++ b/examples/unc4group.c @@ -0,0 +1,46 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "cc4group.h" + +int main(int argc, char* argv[]) +{ + if(argc != 3 && argc != 4) + { + fprintf(stderr, "USAGE: %s <group> [group entry] <target>\n", argv[0]); + return EXIT_FAILURE; + } + + CC4Group* group = cc4group.new(); + if(!cc4group.openExisting(group, argv[1])) + { + fprintf(stderr, "ERROR: Can not open group file \"%s\": %s\n", argv[1], cc4group.getErrorMessage(group)); + + cc4group.delete(group); + return EXIT_FAILURE; + } + + bool success; + if(argc == 3) + { + success = cc4group.extractAll(group, argv[2]); + } + else if(argc == 4) + { + success = cc4group.extractSingle(group, argv[2], argv[3]); + } + else + { + fprintf(stderr, "ERROR: Can't get here\n"); + success = false; + } + + if(!success) + { + fprintf(stderr, "ERROR: Extracting the desired file/group: %s\n", cc4group.getErrorMessage(group)); + } + + cc4group.delete(group); + + return success ? EXIT_SUCCESS : EXIT_FAILURE; +} |
