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.
10 printf("Usage: blergtool <store|fetch> <storename> [record]\n");
13 int main(int argc, char *argv[]) {
19 if (strncmp(argv[1], "store", 5) == 0) {
20 char *store = argv[2];
21 struct blerg *f = blerg_open(store);
23 printf("Blerg open failed\n");
27 size_t bytes_read = 0;
28 char *data = malloc(65536);
30 bytes_read += fread(data + bytes_read, 1, 65536 - bytes_read, stdin);
31 } while (bytes_read < 65536 && !feof(stdin));
32 int record = blerg_store(f, data, bytes_read);
37 fprintf(stderr, "Could not store\n");
40 fprintf(stderr, "Stored record %d\n", record);
42 } else if (strncmp(argv[1], "fetch", 5) == 0) {
43 char *store = argv[2];
44 int record = atoi(argv[3]);
45 struct blerg *f = blerg_open(store);
47 printf("Blerg open failed\n");
53 blerg_fetch(f, record, &data, &size);
55 fwrite(data, 1, size, stdout);
57 } else if (strncmp(argv[1], "list", 4) == 0) {
60 struct tag *list = tag_list(tag, 0, &count, -1);
65 for (i = 0; i < count; i++) {
66 printf("%s %d\n", list[i].author, list[i].record);