7 printf("Usage: blergtool <store|fetch> <storename> [record]\n");
10 int main(int argc, char *argv[]) {
16 if (strncmp(argv[1], "store", 5) == 0) {
17 char *store = argv[2];
18 struct blerg *f = blerg_open(store);
20 printf("Blerg open failed\n");
24 size_t bytes_read = 0;
25 char *data = malloc(65536);
27 bytes_read += fread(data + bytes_read, 1, 65536 - bytes_read, stdin);
28 } while (bytes_read < 65536 && !feof(stdin));
29 int record = blerg_store(f, data, bytes_read);
34 fprintf(stderr, "Could not store\n");
37 fprintf(stderr, "Stored record %d\n", record);
39 } else if (strncmp(argv[1], "fetch", 5) == 0) {
40 char *store = argv[2];
41 int record = atoi(argv[3]);
42 struct blerg *f = blerg_open(store);
44 printf("Blerg open failed\n");
50 blerg_fetch(f, record, &data, &size);
52 fwrite(data, 1, size, stdout);
54 } else if (strncmp(argv[1], "list", 4) == 0) {
57 struct tag *list = tag_list(tag, 0, &count, -1);
62 for (i = 0; i < count; i++) {
63 printf("%s %d\n", list[i].author, list[i].record);