X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=tools%2Fblergtool.c;h=c689d2f2367372072b52de0d83f5fb0622aaac89;hb=3e3138025852408ef03f3213972e042e12841bed;hp=b0e7368589f91134267de8ee7d0c2196269e0fbf;hpb=ec8746b44dc85fd3e3b42835f779890684a9e90a;p=blerg.git diff --git a/tools/blergtool.c b/tools/blergtool.c index b0e7368..c689d2f 100644 --- a/tools/blergtool.c +++ b/tools/blergtool.c @@ -3,11 +3,24 @@ */ #include #include +#include #include "database.h" +#include "subscription.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[]) { @@ -16,6 +29,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); @@ -50,10 +67,11 @@ 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]; int count = 50; @@ -63,10 +81,50 @@ int main(int argc, char *argv[]) { } else { int i; for (i = 0; i < count; i++) { - printf("%s %d\n", list[i].author, list[i].record); + printf("%s %llu\n", list[i].author, list[i].record); } 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_status(f, BLERGSTATUS_MUTED, 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_status(f, BLERGSTATUS_MUTED, 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(); }