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[]) {
34 if (strncmp(argv[1], "store", 5) == 0) {
35 char *store = argv[2];
36 struct blerg *f = blerg_open(store);
38 printf("Blerg open failed\n");
42 size_t bytes_read = 0;
43 char *data = malloc(65536);
45 bytes_read += fread(data + bytes_read, 1, 65536 - bytes_read, stdin);
46 } while (bytes_read < 65536 && !feof(stdin));
47 int record = blerg_store(f, data, bytes_read);
52 fprintf(stderr, "Could not store\n");
55 fprintf(stderr, "Stored record %d\n", record);
57 } else if (strncmp(argv[1], "fetch", 5) == 0) {
58 char *store = argv[2];
59 int record = atoi(argv[3]);
60 struct blerg *f = blerg_open(store);
62 printf("Blerg open failed\n");
68 if (blerg_fetch(f, record, &data, &size)) {
69 fwrite(data, 1, size, stdout);
73 } else if (strncmp(argv[1], "list", 4) == 0) {
76 struct blergref *list = tag_list(tag, 0, &count, -1);
81 for (i = 0; i < count; i++) {
82 printf("%s %d\n", list[i].author, list[i].record);
86 } else if (strncmp(argv[1], "mute", 4) == 0) {
87 char *store = argv[2];
88 struct blerg *f = blerg_open(store);
90 printf("Blerg open failed\n");
96 } else if (strncmp(argv[1], "unmute", 6) == 0) {
97 char *store = argv[2];
98 struct blerg *f = blerg_open(store);
100 printf("Blerg open failed\n");
104 blerg_set_mute(f, 0);
106 } else if (strncmp(argv[1], "subscribe", 9) == 0) {
108 printf("Not enough arguments for subscribe\n");
112 if (!subscription_add(argv[2], argv[3])) {
113 printf("Could not subscribe %s to %s\n", argv[2], argv[3]);
116 } else if (strncmp(argv[1], "unsubscribe", 11) == 0) {
118 printf("Not enough arguments for unsubscribe\n");
122 if (!subscription_remove(argv[2], argv[3])) {
123 printf("Could not subscribe %s to %s\n", argv[2], argv[3]);