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.
8 #include "subscription.h"
13 "Usage: blergtool <command> [args]\n"
15 "Where command is one of:\n"
17 " blergtool store <storename>\n"
18 " blergtool fetch <storename> [record]\n"
19 " blergtool mute <storename>\n"
20 " blergtool unmute <storename>\n"
21 " blergtool subscribe <storename> <target>\n"
22 " blergtool unsubscribe <storename> <target>\n"
26 int main(int argc, char *argv[]) {
36 if (strncmp(argv[1], "store", 5) == 0) {
37 char *store = argv[2];
38 struct blerg *f = blerg_open(store);
40 printf("Blerg open failed\n");
44 size_t bytes_read = 0;
45 char *data = malloc(65536);
47 bytes_read += fread(data + bytes_read, 1, 65536 - bytes_read, stdin);
48 } while (bytes_read < 65536 && !feof(stdin));
49 int record = blerg_store(f, data, bytes_read);
54 fprintf(stderr, "Could not store\n");
57 fprintf(stderr, "Stored record %d\n", record);
59 } else if (strncmp(argv[1], "fetch", 5) == 0) {
60 char *store = argv[2];
61 int record = atoi(argv[3]);
62 struct blerg *f = blerg_open(store);
64 printf("Blerg open failed\n");
70 if (blerg_fetch(f, record, &data, &size)) {
71 fwrite(data, 1, size, stdout);
75 } else if (strncmp(argv[1], "list", 4) == 0) {
78 struct blergref *list = tag_list(tag, 0, &count, -1);
83 for (i = 0; i < count; i++) {
84 printf("%s %llu\n", list[i].author, list[i].record);
88 } else if (strncmp(argv[1], "mute", 4) == 0) {
89 char *store = argv[2];
90 struct blerg *f = blerg_open(store);
92 printf("Blerg open failed\n");
96 blerg_set_status(f, BLERGSTATUS_MUTED, 1);
98 } else if (strncmp(argv[1], "unmute", 6) == 0) {
99 char *store = argv[2];
100 struct blerg *f = blerg_open(store);
102 printf("Blerg open failed\n");
106 blerg_set_status(f, BLERGSTATUS_MUTED, 0);
108 } else if (strncmp(argv[1], "subscribe", 9) == 0) {
110 printf("Not enough arguments for subscribe\n");
114 if (!subscription_add(argv[2], argv[3])) {
115 printf("Could not subscribe %s to %s\n", argv[2], argv[3]);
118 } else if (strncmp(argv[1], "unsubscribe", 11) == 0) {
120 printf("Not enough arguments for unsubscribe\n");
124 if (!subscription_remove(argv[2], argv[3])) {
125 printf("Could not subscribe %s to %s\n", argv[2], argv[3]);