summaryrefslogtreecommitdiff
path: root/canls.c
blob: f47656e0b06d60b04a0a4023b5d9a9c046530191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

enum {
	bufsize = 16,
};

typedef char byte;

struct listing {
	long id, folder_id, size;
	char *uuid, *filename, *upload_status, *content_type, *url;
	char *created_at, *updated_at, *unlock_at, *lock_at, thumbnail_url;
	char *modified_at, *mime_class, *media_entry_id, *category;
	byte locked, hidden, hidden_for_user, locked_for_user;
};

typedef struct listing Listing;

int
main()
{
	FILE* infile = fopen("dump", "r");
	if (infile == NULL) {
		fprintf(stderr, "No dump provided. Run dump.sh.\n");
	}
	
	char buf[bufsize];
	char *contents = NULL;
	int read, size = 0;
	while ((read = fread(buf, 1, bufsize, infile)) > 0) {
		size += read;
		contents = realloc(contents, size);
		memmove(&contents[size-read], buf, read);
	}

	int i, j = 0;
	char ch;
	Listing *l = calloc(1, sizeof(Listing));
	int l_size = sizeof(Listing);
	for (i = 0; i < size; i++) {
		ch = contents[i];
		switch (ch) {
		case '\n':
			j++;
			l_size += sizeof(Listing);
			l = realloc(l, l_size);
			break;
		default:
		}
	}
	printf("%d\n", l_size);
	return 0;
}