X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=tools%2Fblergtool.c;h=968081abb25af07074a5a90f845908f5d65a7cae;hb=e6dca775a923fa76d62b3ea420fd8b7bae3c420b;hp=d5aef50f9f26e2b7677f22b8ef324f7f78705a10;hpb=1cf0f1ebfbd5b5a621af2a49ac0328fd0cec4bf4;p=blerg.git diff --git a/tools/blergtool.c b/tools/blergtool.c index d5aef50..968081a 100644 --- a/tools/blergtool.c +++ b/tools/blergtool.c @@ -1,10 +1,24 @@ +/* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a + * BSD-style license. Please see the COPYING file for details. + */ #include #include #include "database.h" #include "tags.h" void help() { - printf("Usage: blergtool [record]\n"); + printf( + "Usage: blergtool [args]\n" + "\n" + "Where command is one of:\n" + "\n" + " blergtool store \n" + " blergtool fetch [record]\n" + " blergtool mute \n" + " blergtool unmute \n" + " blergtool subscribe \n" + " blergtool unsubscribe \n" + ); } int main(int argc, char *argv[]) { @@ -13,6 +27,10 @@ int main(int argc, char *argv[]) { exit(1); } + if (!blerg_init()) { + exit(2); + } + if (strncmp(argv[1], "store", 5) == 0) { char *store = argv[2]; struct blerg *f = blerg_open(store); @@ -47,14 +65,15 @@ int main(int argc, char *argv[]) { char *data; int size; - blerg_fetch(f, record, &data, &size); + if (blerg_fetch(f, record, &data, &size)) { + fwrite(data, 1, size, stdout); + free(data); + } blerg_close(f); - fwrite(data, 1, size, stdout); - free(data); } else if (strncmp(argv[1], "list", 4) == 0) { char *tag = argv[2]; - uint64_t count = 50; - struct tag *list = tag_list(tag, 0, &count, -1); + int count = 50; + struct blergref *list = tag_list(tag, 0, &count, -1); if (list == NULL) { printf("No entries"); } else { @@ -64,6 +83,46 @@ int main(int argc, char *argv[]) { } free(list); } + } else if (strncmp(argv[1], "mute", 4) == 0) { + char *store = argv[2]; + struct blerg *f = blerg_open(store); + if (!f) { + printf("Blerg open failed\n"); + exit(1); + } + + blerg_set_mute(f, 1); + blerg_close(f); + } else if (strncmp(argv[1], "unmute", 6) == 0) { + char *store = argv[2]; + struct blerg *f = blerg_open(store); + if (!f) { + printf("Blerg open failed\n"); + exit(1); + } + + blerg_set_mute(f, 0); + blerg_close(f); + } else if (strncmp(argv[1], "subscribe", 9) == 0) { + if (argc < 4) { + printf("Not enough arguments for subscribe\n"); + help(); + exit(1); + } + if (!subscription_add(argv[2], argv[3])) { + printf("Could not subscribe %s to %s\n", argv[2], argv[3]); + exit(1); + } + } else if (strncmp(argv[1], "unsubscribe", 11) == 0) { + if (argc < 4) { + printf("Not enough arguments for unsubscribe\n"); + help(); + exit(1); + } + if (!subscription_remove(argv[2], argv[3])) { + printf("Could not subscribe %s to %s\n", argv[2], argv[3]); + exit(1); + } } else { help(); }