1 /* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
2 * BSD-style license. Please see the COPYING file for details.
11 "Usage: blergtool <command> [args]\n"
13 "Where command is one of:\n"
15 " blergtool store <storename>\n"
16 " blergtool fetch <storename> [record]\n"
17 " blergtool mute <storename>\n"
18 " blergtool unmute <storename>\n"
19 " blergtool subscribe <storename> <target>\n"
20 " blergtool unsubscribe <storename> <target>\n"
24 int main(int argc, char *argv[]) {
30 if (strncmp(argv[1], "store", 5) == 0) {
31 char *store = argv[2];
32 struct blerg *f = blerg_open(store);
34 printf("Blerg open failed\n");
38 size_t bytes_read = 0;
39 char *data = malloc(65536);
41 bytes_read += fread(data + bytes_read, 1, 65536 - bytes_read, stdin);
42 } while (bytes_read < 65536 && !feof(stdin));
43 int record = blerg_store(f, data, bytes_read);
48 fprintf(stderr, "Could not store\n");
51 fprintf(stderr, "Stored record %d\n", record);
53 } else if (strncmp(argv[1], "fetch", 5) == 0) {
54 char *store = argv[2];
55 int record = atoi(argv[3]);
56 struct blerg *f = blerg_open(store);
58 printf("Blerg open failed\n");
64 if (blerg_fetch(f, record, &data, &size)) {
65 fwrite(data, 1, size, stdout);
69 } else if (strncmp(argv[1], "list", 4) == 0) {
72 struct blergref *list = tag_list(tag, 0, &count, -1);
77 for (i = 0; i < count; i++) {
78 printf("%s %d\n", list[i].author, list[i].record);
82 } else if (strncmp(argv[1], "mute", 4) == 0) {
83 char *store = argv[2];
84 struct blerg *f = blerg_open(store);
86 printf("Blerg open failed\n");
92 } else if (strncmp(argv[1], "unmute", 6) == 0) {
93 char *store = argv[2];
94 struct blerg *f = blerg_open(store);
96 printf("Blerg open failed\n");
100 blerg_set_mute(f, 0);
102 } else if (strncmp(argv[1], "subscribe", 9) == 0) {
104 printf("Not enough arguments for subscribe\n");
108 if (!subscription_add(argv[2], argv[3])) {
109 printf("Could not subscribe %s to %s\n", argv[2], argv[3]);
112 } else if (strncmp(argv[1], "unsubscribe", 11) == 0) {
114 printf("Not enough arguments for unsubscribe\n");
118 if (!subscription_remove(argv[2], argv[3])) {
119 printf("Could not subscribe %s to %s\n", argv[2], argv[3]);