-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_book.c
77 lines (67 loc) · 1.25 KB
/
print_book.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include "json.h"
#include "print_book.h"
#define FORMAT_NUM 4
void print_arr(struct arr* arr, int num)
{
int i;
struct value* p_v = arr->p_v;
for (i = 0; i < FORMAT_NUM * num; i++)
printf(" ");
while(p_v)
{
switch (p_v->type)
{
case INT:
printf("%d, ", *(int*)p_v->p_data);
break;
case STR:
printf("%s, ", (char*)p_v->p_data);
break;
case ARR:
print_arr(arr, num + 1);
break;
case OBJ:
printf("\n");
print_book((struct obj*)p_v->p_data,num + 1);
break;
default:
printf("\n");
break;
}
p_v = p_v->p_next;
}
}
void print_book(struct obj* obj, int num)
{
int i;
struct key* key = obj->p_k;
while(key)
{
for (i = 0; i < FORMAT_NUM * num; i++)
printf(" ");
printf("%s:", key->key);
switch (key->p_v->type)
{
case INT:
printf("%d\n", *(int*)key->p_v->p_data);
break;
case STR:
((char*)key->p_v->p_data)[STRSIZE - 1] = 0;
printf("%s\n", (char*)key->p_v->p_data);
break;
case ARR:
printf("\n");
print_arr((struct arr*)key->p_v->p_data, num + 1);
printf("\n");
break;
case OBJ:
printf("\n");
print_book((struct obj*)key->p_v->p_data,num + 1);
break;
default:
break;
}
key = key->p_next;
}
}