forked from B-Y-P/4coder-community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4ed_api_check.cpp
104 lines (89 loc) · 2.76 KB
/
4ed_api_check.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Mr. 4th Dimention - Allen Webster
*
* 06.10.2019
*
* Type checker that lists errors between two api parses.
*
*/
// TOP
#include "4coder_base_types.h"
#include "4coder_token.h"
#include "generated/lexer_cpp.h"
#include "4ed_api_definition.h"
#include "4coder_base_types.cpp"
#include "4coder_stringf.cpp"
#include "4coder_malloc_allocator.cpp"
#include "4coder_token.cpp"
#include "generated/lexer_cpp.cpp"
#include "4coder_file.cpp"
#include "4ed_api_definition.cpp"
#include "4ed_api_parser.cpp"
#include <stdio.h>
////////////////////////////////
function void
print_usage(void){
printf("usage: <script> <source-1> {<source-1>} : <source-2> {<source-2>}\n"
" source-1 : the authoritative/master api source file(s)\n"
" source-2 : the 'remote' api source file(s) to check against the master\n");
exit(1);
}
int
main(int argc, char **argv){
Arena arena = make_arena_malloc();
if (argc < 4){
print_usage();
}
API_Definition_List master_list = {};
API_Definition_List remote_list = {};
{
i32 i = 1;
for (;i < argc; i += 1){
char *file_name = argv[i];
if (string_match(SCu8(file_name), string_u8_litexpr(":"))){
i += 1;
break;
}
FILE *file = fopen(file_name, "rb");
if (file == 0){
printf("error: could not open input file: '%s'\n", file_name);
continue;
}
String_Const_u8 text = data_from_file(&arena, file);
fclose(file);
if (text.size > 0){
api_parse_source_add_to_list(&arena, SCu8(file_name), text, &master_list);
}
}
for (;i < argc; i += 1){
char *file_name = argv[i];
FILE *file = fopen(file_name, "rb");
if (file == 0){
printf("error: could not open input file: '%s'\n", file_name);
continue;
}
String_Const_u8 text = data_from_file(&arena, file);
fclose(file);
if (text.size > 0){
api_parse_source_add_to_list(&arena, SCu8(file_name), text, &remote_list);
}
}
}
if (master_list.count == 0){
printf("error: no apis in master list\n");
exit(1);
}
if (remote_list.count == 0){
printf("error: no apis in remote list\n");
exit(1);
}
List_String_Const_u8 errors = {};
api_list_check(&arena, &master_list, &remote_list, APICheck_ReportAll, &errors);
String_Const_u8 string = string_list_flatten(&arena, errors, StringFill_NullTerminate);
printf("%.*s", string_expand(string));
if (string.size > 0){
exit(1);
}
return(0);
}
// BOTTOM