MCPcopy Create free account
hub / github.com/F-Stack/f-stack / main

Function main

tools/libxo/tests/core/test_08.c:20–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#include "xo_encoder.h"
19
20int
21main (int argc, char **argv)
22{
23 struct item {
24 const char *i_title;
25 int i_count;
26 };
27 struct item list[] = {
28 { "gum", 1412 },
29 { "rope", 85 },
30 { "ladder", 0 },
31 { "bolt", 4123 },
32 { "water", 17 },
33 { NULL, 0 }
34 };
35 struct item *ip;
36 int i;
37
38 argc = xo_parse_args(argc, argv);
39 if (argc < 0)
40 return 1;
41
42 for (argc = 1; argv[argc]; argc++) {
43 if (xo_streq(argv[argc], "xml"))
44 xo_set_style(NULL, XO_STYLE_XML);
45 else if (xo_streq(argv[argc], "json"))
46 xo_set_style(NULL, XO_STYLE_JSON);
47 else if (xo_streq(argv[argc], "text"))
48 xo_set_style(NULL, XO_STYLE_TEXT);
49 else if (xo_streq(argv[argc], "html"))
50 xo_set_style(NULL, XO_STYLE_HTML);
51 else if (xo_streq(argv[argc], "pretty"))
52 xo_set_flags(NULL, XOF_PRETTY);
53 else if (xo_streq(argv[argc], "xpath"))
54 xo_set_flags(NULL, XOF_XPATH);
55 else if (xo_streq(argv[argc], "info"))
56 xo_set_flags(NULL, XOF_INFO);
57 else if (xo_streq(argv[argc], "error")) {
58 close(-1);
59 xo_err(1, "error detected");
60 }
61 }
62
63 xo_set_flags(NULL, XOF_KEYS);
64 xo_set_program("test");
65
66 xo_open_container_h(NULL, "top");
67
68 xo_open_container("data");
69 xo_open_container("contents");
70 xo_open_list("item");
71
72 xo_emit("{T:Item/%-10s}{T:Count/%12s}\n");
73
74 for (ip = list; ip->i_title; ip++) {
75 xo_open_instance("item");
76
77 xo_emit("{k:name/%-10s/%s}{n:count/%12u/%u}\n",

Callers

nothing calls this directly

Calls 15

xo_parse_argsFunction · 0.85
xo_streqFunction · 0.85
xo_set_styleFunction · 0.85
xo_set_flagsFunction · 0.85
xo_errFunction · 0.85
xo_set_programFunction · 0.85
xo_open_container_hFunction · 0.85
xo_open_containerFunction · 0.85
xo_open_listFunction · 0.85
xo_emitFunction · 0.85
xo_open_instanceFunction · 0.85
xo_close_instanceFunction · 0.85

Tested by

no test coverage detected