MCPcopy Create free account
hub / github.com/acl-dev/acl / main

Function main

lib_acl_cpp/samples/json/json15/json.cpp:19–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19int main(int argc, char* argv[]) {
20 acl::string file;
21 acl::string names;
22 bool use_remove = false;
23 int ch;
24
25 while ((ch = getopt(argc, argv, "hf:n:D")) > 0) {
26 switch (ch) {
27 case 'h':
28 usage(argv[0]);
29 return 0;
30 case 'f':
31 file = optarg;
32 break;
33 case 'n':
34 names = optarg;
35 break;
36 case 'D':
37 use_remove = true;
38 break;
39 default:
40 break;
41 }
42 }
43
44 if (file.empty() || names.empty()) {
45 usage(argv[0]);
46 return 1;
47 }
48
49 acl::string buf;
50 if (!acl::ifstream::load(file, &buf)) {
51 printf("load %s error %s\r\n", file.c_str(), acl::last_serror());
52 return 1;
53 }
54
55 std::vector<std::string> tokens;
56 acl::split(names.c_str(), ",; \t", tokens);
57
58 acl::json json(buf);
59 if (!json.finish()) {
60 printf("invalid json: %s\r\n", buf.c_str());
61 return 1;
62 }
63
64 acl::json_node* node = json.first_node();
65 while (node) {
66 const char* tag = node->tag_name();
67 if (tag == NULL || *tag == 0) {
68 node = json.next_node();
69 continue;
70 }
71
72 if (matched(tokens, tag)) {
73 if (use_remove) {
74 node = json.free_node(node);
75 } else {
76 node->disable(true);

Callers

nothing calls this directly

Calls 14

splitFunction · 0.85
matchedFunction · 0.85
free_nodeMethod · 0.80
disableMethod · 0.80
usageFunction · 0.70
getoptFunction · 0.50
last_serrorFunction · 0.50
emptyMethod · 0.45
c_strMethod · 0.45
finishMethod · 0.45
first_nodeMethod · 0.45
tag_nameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…