-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.c
70 lines (67 loc) · 1.85 KB
/
main.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
#include <stdio.h>
#include <kuliya.h>
/**
* Match `node_type` enum to a string.
* @param type Kuliya schema node type.
* @returns String representation for the enum value.
*/
const char *match_node_type(const node_type type)
{
switch (type)
{
case UNIVERSITY:
return "UNIVERSITY";
case ACADEMY:
return "ACADEMY";
case PRIVATE_SCHOOL:
return "PRIVATE_SCHOOL";
case INSTITUTE:
return "INSTITUTE";
case FACULTY:
return "FACULTY";
case DEPARTMENT:
return "DEPARTMENT";
case SPECIALTY:
return "SPECIALTY";
case SECTOR:
return "SECTOR";
}
}
/**
* Print kuliya schema with JSON format to a file (.e.g `stdout`).
* @param out File output.
* @param schema Kuliya node schema.
*/
void print_kuliya_schema(FILE *out, const kuliya_schema *schema)
{
fprintf(out, "{\n");
fprintf(out, "\t\"name\": {\n");
fprintf(out, "\t\t\"ar\": \"%s\",\n", schema->name.ar);
fprintf(out, "\t\t\"en\": \"%s\",\n", schema->name.en);
fprintf(out, "\t\t\"fr\": \"%s\"\n", schema->name.fr);
fprintf(out, "\t},\n");
fprintf(out, "\t\"type\": \"%s\"%s\n", match_node_type(schema->type), schema->terms != NULL ? "," : "");
if (schema->terms != NULL)
{
fprintf(out, "\t\"terms\": {\n");
fprintf(out, "\t\t\"perYear\": %d,\n", schema->terms->per_year);
fprintf(out, "\t\t\"slots\": [%d", schema->terms->slots[0]);
for (size_t i = 1; i < schema->terms->number_of_slots; i++)
{
fprintf(out, ", %d", schema->terms->slots[i]);
}
fprintf(out, "]\n");
fprintf(out, "\t}\n");
}
fprintf(out, "}\n");
}
int main(void)
{
kuliya_init();
kuliya_schema *res = get_node_by_path("umkb/fst/dee/sec");
if (res != NULL)
{
print_kuliya_schema(stdout, res);
}
kuliya_deinit();
}