summaryrefslogtreecommitdiffstats
path: root/examples/c4rm.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/c4rm.c')
-rw-r--r--examples/c4rm.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/c4rm.c b/examples/c4rm.c
new file mode 100644
index 0000000..5677125
--- /dev/null
+++ b/examples/c4rm.c
@@ -0,0 +1,49 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "cc4group.h"
+
+int main(int argc, char* argv[])
+{
+ bool recursive = argc == 4 && strcmp(argv[1], "-r") == 0;
+
+ if(argc != 3 && !recursive)
+ {
+ fprintf(stderr, "USAGE: %s [-r] <group> <entry>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if(recursive)
+ {
+ ++argv;
+ }
+
+ 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.deleteEntry(group, argv[2], recursive);
+
+ if(!success)
+ {
+ fprintf(stderr, "ERROR: Can not delete group entry \"%s\": %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;
+}