-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamples.c
More file actions
49 lines (43 loc) · 1.05 KB
/
samples.c
File metadata and controls
49 lines (43 loc) · 1.05 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "lib/json.h"
#define MEMPOOL_SIZE 65536
void parse_file(char* filename)
{
char* inBuffer = malloc(MEMPOOL_SIZE);
char* outBuffer;
FILE * file = fopen(filename, "r");
if (file)
{
int c = 0, i = 0;
while ((c = getc(file)) != EOF)
{
inBuffer[i++] = c;
}
inBuffer[i++] = '\0';
outBuffer = malloc(i);
fclose(file);
}
printf("Input:\n%s\n", inBuffer);
// Parse the input
JsonObject *parsed;
bool success = parse_JsonObject(inBuffer, &parsed);
assert(success);
// Dump the object
success = dump_JsonObject(parsed, outBuffer);
assert(success);
printf("Output:\n%s\n", outBuffer);
free(inBuffer);
free(outBuffer);
}
int main()
{
// Statically allocate 65kB.
char mempool[MEMPOOL_SIZE];
Json_set_mempool(mempool, MEMPOOL_SIZE);
parse_file("samples/sample1.json");
parse_file("samples/sample2.json");
parse_file("samples/sample3.json");
return 0;
}