2 * Copyright (c) 2014, Juniper Networks, Inc.
4 * This SOFTWARE is licensed under the LICENSE provided in the
5 * ../Copyright file. By downloading, installing, copying, or otherwise
6 * using the SOFTWARE, you agree to be bound by the terms of that
8 * Phil Shafer, July 2014
19 main (int argc, char **argv)
21 static char base_grocery[] = "GRO";
22 static char base_hardware[] = "HRD";
28 const char *i_sku_base;
31 struct item list[] = {
32 { "gum", 1412, 54, 10, base_grocery, 415 },
33 { "rope", 85, 4, 2, base_hardware, 212 },
34 { "ladder", 0, 2, 1, base_hardware, 517 },
35 { "bolt", 4123, 144, 42, base_hardware, 632 },
36 { "water", 17, 14, 2, base_grocery, 2331 },
37 { NULL, 0, 0, 0, NULL, 0 }
39 struct item list2[] = {
40 { "fish", 1321, 45, 1, base_grocery, 533 },
41 { NULL, 0, 0, 0, NULL, 0 }
45 { "in-stock", "number", "Number of items in stock" },
46 { "name", "string", "Name of the item" },
47 { "on-order", "number", "Number of items on order" },
48 { "sku", "string", "Stock Keeping Unit" },
49 { "sold", "number", "Number of items sold" },
53 argc = xo_parse_args(argc, argv);
57 for (argc = 1; argv[argc]; argc++) {
58 if (strcmp(argv[argc], "xml") == 0)
59 xo_set_style(NULL, XO_STYLE_XML);
60 else if (strcmp(argv[argc], "json") == 0)
61 xo_set_style(NULL, XO_STYLE_JSON);
62 else if (strcmp(argv[argc], "text") == 0)
63 xo_set_style(NULL, XO_STYLE_TEXT);
64 else if (strcmp(argv[argc], "html") == 0)
65 xo_set_style(NULL, XO_STYLE_HTML);
66 else if (strcmp(argv[argc], "pretty") == 0)
67 xo_set_flags(NULL, XOF_PRETTY);
68 else if (strcmp(argv[argc], "xpath") == 0)
69 xo_set_flags(NULL, XOF_XPATH);
70 else if (strcmp(argv[argc], "info") == 0)
71 xo_set_flags(NULL, XOF_INFO);
72 else if (strcmp(argv[argc], "error") == 0) {
74 xo_err(1, "error detected");
78 xo_set_info(NULL, info, -1);
79 xo_set_flags(NULL, XOF_KEYS);
81 xo_open_container_h(NULL, "top");
83 xo_emit("{e:kve_start/%#jx}", (uintmax_t) 0xdeadbeef);
84 xo_emit("{e:kve_end/%#jx}", (uintmax_t) 0xcabb1e);
86 xo_emit("testing argument modifier {a:}.{a:}...\n",
87 "host", "my-box", "domain", "example.com");
89 xo_emit("testing argument modifier with encoding to {ea:}.{a:}...\n",
90 "host", "my-box", "domain", "example.com");
92 xo_emit("{La:} {a:}\n", "Label text", "label", "value");
94 xo_emit_field("Vt", "max-chaos", NULL, NULL, " very ");
95 xo_emit_field("V", "min-chaos", "%d", NULL, 42);
96 xo_emit_field("V", "some-chaos", "%d\n", "[%d]", 42);
98 xo_emit("Connecting to {:host}.{:domain}...\n", "my-box", "example.com");
100 xo_attr("test", "value");
101 xo_open_container("data");
102 xo_open_list("item");
103 xo_attr("test2", "value2");
105 xo_emit("{T:Item/%-10s}{T:Total Sold/%12s}{T:In Stock/%12s}"
106 "{T:On Order/%12s}{T:SKU/%5s}\n");
108 for (ip = list; ip->i_title; ip++) {
109 xo_open_instance("item");
110 xo_attr("test3", "value3");
112 xo_emit("{keq:sku/%s-%u/%s-000-%u}"
113 "{k:name/%-10s/%s}{n:sold/%12u/%u}{:in-stock/%12u/%u}"
114 "{:on-order/%12u/%u}{qkd:sku/%5s-000-%u/%s-000-%u}\n",
115 ip->i_sku_base, ip->i_sku_num,
116 ip->i_title, ip->i_sold, ip->i_instock, ip->i_onorder,
117 ip->i_sku_base, ip->i_sku_num);
119 xo_close_instance("item");
122 xo_close_list("item");
123 xo_close_container("data");
127 xo_open_container("data2");
128 xo_open_list("item");
130 for (ip = list; ip->i_title; ip++) {
131 xo_open_instance("item");
133 xo_emit("{keq:sku/%s-%u/%s-000-%u}", ip->i_sku_base, ip->i_sku_num);
134 xo_emit("{L:Item} '{k:name/%s}':\n", ip->i_title);
135 xo_emit("{P: }{L:Total sold}: {n:sold/%u%s}\n",
136 ip->i_sold, ip->i_sold ? ".0" : "");
137 xo_emit("{P: }{Lcw:In stock}{:in-stock/%u}\n", ip->i_instock);
138 xo_emit("{P: }{Lcw:On order}{:on-order/%u}\n", ip->i_onorder);
139 xo_emit("{P: }{L:SKU}: {qkd:sku/%s-000-%u}\n",
140 ip->i_sku_base, ip->i_sku_num);
142 xo_close_instance("item");
145 xo_close_list("item");
146 xo_close_container("data2");
148 xo_open_container("data3");
149 xo_open_list("item");
151 for (ip = list2; ip->i_title; ip++) {
152 xo_open_instance("item");
154 xo_emit("{keq:sku/%s-%u/%s-000-%u}", ip->i_sku_base, ip->i_sku_num);
155 xo_emit("{L:Item} '{k:name/%s}':\n", ip->i_title);
156 xo_emit("{P: }{L:Total sold}: {n:sold/%u%s}\n",
157 ip->i_sold, ip->i_sold ? ".0" : "");
158 xo_emit("{P: }{Lcw:In stock}{:in-stock/%u}\n", ip->i_instock);
159 xo_emit("{P: }{Lcw:On order}{:on-order/%u}\n", ip->i_onorder);
160 xo_emit("{P: }{L:SKU}: {qkd:sku/%s-000-%u}\n",
161 ip->i_sku_base, ip->i_sku_num);
163 xo_close_instance("item");
166 xo_close_list("item");
167 xo_close_container("data3");
169 xo_open_container("data4");
170 xo_open_list("item");
172 for (ip = list; ip->i_title; ip++) {
173 xo_attr("test4", "value4");
174 xo_emit("{Lwc:Item}{l:item}\n", ip->i_title);
177 xo_close_list("item");
178 xo_close_container("data4");
180 xo_emit("X{P:}X", "epic fail");
181 xo_emit("X{T:}X", "epic fail");
182 xo_emit("X{N:}X", "epic fail");
183 xo_emit("X{L:}X\n", "epic fail");
185 xo_emit("X{P: }X{Lwc:Cost}{:cost/%u}\n", 425);
186 xo_emit("X{P:/%30s}X{Lwc:Cost}{:cost/%u}\n", "", 455);
188 xo_emit("{e:mode/%s}{e:mode_octal/%s} {t:links/%s} "
189 "{t:user/%s} {t:group/%s} \n",
190 "mode", "octal", "links",
191 "user", "group", "extra1", "extra2", "extra3");
193 xo_emit("{t:mode/%s}{e:mode_octal/%03o} {t:links/%*u} "
194 "{t:user/%-*s} {t:group/%-*s} \n",
195 "/some/file", (int) 0640, 8, 1,
196 10, "user", 12, "group");
198 xo_close_container_h(NULL, "top");