6 printf("Usage: blergtool <store|fetch> <storename> [record]\n");
9 int main(int argc, char *argv[]) {
15 if (strncmp(argv[1], "store", 5) == 0) {
16 char *store = argv[2];
17 struct blerg *f = blerg_open(store);
19 printf("Blerg open failed\n");
23 size_t bytes_read = 0;
24 char *data = malloc(65536);
26 bytes_read += fread(data + bytes_read, 1, 65536 - bytes_read, stdin);
27 } while (bytes_read < 65536 && !feof(stdin));
28 int record = blerg_store(f, data, bytes_read);
33 fprintf(stderr, "Could not store\n");
36 fprintf(stderr, "Stored record %d\n", record);
38 } else if (strncmp(argv[1], "fetch", 5) == 0) {
39 char *store = argv[2];
40 int record = atoi(argv[3]);
41 struct blerg *f = blerg_open(store);
43 printf("Blerg open failed\n");
49 blerg_fetch(f, record, &data, &size);
51 fwrite(data, 1, size, stdout);