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
18 main (int argc, char **argv)
20 static char base_grocery[] = "GRO";
21 static char base_hardware[] = "HRD";
27 const char *i_sku_base;
30 struct item list[] = {
31 { "gum", 1412, 54, 10, base_grocery, 415 },
32 { "rope", 85, 4, 2, base_hardware, 212 },
33 { "ladder", 0, 2, 1, base_hardware, 517 },
34 { "bolt", 4123, 144, 42, base_hardware, 632 },
35 { "water", 17, 14, 2, base_grocery, 2331 },
36 { NULL, 0, 0, 0, NULL, 0 }
38 struct item list2[] = {
39 { "fish", 1321, 45, 1, base_grocery, 533 },
40 { NULL, 0, 0, 0, NULL, 0 }
44 { "in-stock", "number", "Number of items in stock" },
45 { "name", "string", "Name of the item" },
46 { "on-order", "number", "Number of items on order" },
47 { "sku", "string", "Stock Keeping Unit" },
48 { "sold", "number", "Number of items sold" },
52 argc = xo_parse_args(argc, argv);
56 for (argc = 1; argv[argc]; argc++) {
57 if (strcmp(argv[argc], "xml") == 0)
58 xo_set_style(NULL, XO_STYLE_XML);
59 else if (strcmp(argv[argc], "json") == 0)
60 xo_set_style(NULL, XO_STYLE_JSON);
61 else if (strcmp(argv[argc], "text") == 0)
62 xo_set_style(NULL, XO_STYLE_TEXT);
63 else if (strcmp(argv[argc], "html") == 0)
64 xo_set_style(NULL, XO_STYLE_HTML);
65 else if (strcmp(argv[argc], "pretty") == 0)
66 xo_set_flags(NULL, XOF_PRETTY);
67 else if (strcmp(argv[argc], "xpath") == 0)
68 xo_set_flags(NULL, XOF_XPATH);
69 else if (strcmp(argv[argc], "info") == 0)
70 xo_set_flags(NULL, XOF_INFO);
71 else if (strcmp(argv[argc], "error") == 0) {
73 xo_err(1, "error detected");
77 xo_set_info(NULL, info, -1);
78 xo_set_flags(NULL, XOF_KEYS);
80 xo_open_container_h(NULL, "top");
82 xo_emit("testing argument modifier {a:}.{a:}...\n",
83 "host", "my-box", "domain", "example.com");
85 xo_emit("testing argument modifier with encoding to {ea:}.{a:}...\n",
86 "host", "my-box", "domain", "example.com");
88 xo_emit("{La:} {a:}\n", "Label text", "label", "value");
90 xo_emit_field("Vt", "max-chaos", NULL, NULL, " very ");
91 xo_emit_field("V", "min-chaos", "%d", NULL, 42);
92 xo_emit_field("V", "some-chaos", "%d\n", "[%d]", 42);
94 xo_emit("Connecting to {:host}.{:domain}...\n", "my-box", "example.com");
96 xo_attr("test", "value");
97 xo_open_container("data");
99 xo_attr("test2", "value2");
101 xo_emit("{T:Item/%-10s}{T:Total Sold/%12s}{T:In Stock/%12s}"
102 "{T:On Order/%12s}{T:SKU/%5s}\n");
104 for (ip = list; ip->i_title; ip++) {
105 xo_open_instance("item");
106 xo_attr("test3", "value3");
108 xo_emit("{keq:sku/%s-%u/%s-000-%u}"
109 "{k:name/%-10s/%s}{n:sold/%12u/%u}{:in-stock/%12u/%u}"
110 "{:on-order/%12u/%u}{qkd:sku/%5s-000-%u/%s-000-%u}\n",
111 ip->i_sku_base, ip->i_sku_num,
112 ip->i_title, ip->i_sold, ip->i_instock, ip->i_onorder,
113 ip->i_sku_base, ip->i_sku_num);
115 xo_close_instance("item");
118 xo_close_list("item");
119 xo_close_container("data");
123 xo_open_container("data2");
124 xo_open_list("item");
126 for (ip = list; ip->i_title; ip++) {
127 xo_open_instance("item");
129 xo_emit("{keq:sku/%s-%u/%s-000-%u}", ip->i_sku_base, ip->i_sku_num);
130 xo_emit("{L:Item} '{k:name/%s}':\n", ip->i_title);
131 xo_emit("{P: }{L:Total sold}: {n:sold/%u%s}\n",
132 ip->i_sold, ip->i_sold ? ".0" : "");
133 xo_emit("{P: }{Lcw:In stock}{:in-stock/%u}\n", ip->i_instock);
134 xo_emit("{P: }{Lcw:On order}{:on-order/%u}\n", ip->i_onorder);
135 xo_emit("{P: }{L:SKU}: {qkd:sku/%s-000-%u}\n",
136 ip->i_sku_base, ip->i_sku_num);
138 xo_close_instance("item");
141 xo_close_list("item");
142 xo_close_container("data2");
144 xo_open_container("data3");
145 xo_open_list("item");
147 for (ip = list2; ip->i_title; ip++) {
148 xo_open_instance("item");
150 xo_emit("{keq:sku/%s-%u/%s-000-%u}", ip->i_sku_base, ip->i_sku_num);
151 xo_emit("{L:Item} '{k:name/%s}':\n", ip->i_title);
152 xo_emit("{P: }{L:Total sold}: {n:sold/%u%s}\n",
153 ip->i_sold, ip->i_sold ? ".0" : "");
154 xo_emit("{P: }{Lcw:In stock}{:in-stock/%u}\n", ip->i_instock);
155 xo_emit("{P: }{Lcw:On order}{:on-order/%u}\n", ip->i_onorder);
156 xo_emit("{P: }{L:SKU}: {qkd:sku/%s-000-%u}\n",
157 ip->i_sku_base, ip->i_sku_num);
159 xo_close_instance("item");
162 xo_close_list("item");
163 xo_close_container("data3");
165 xo_open_container("data4");
166 xo_open_list("item");
168 for (ip = list; ip->i_title; ip++) {
169 xo_attr("test4", "value4");
170 xo_emit("{Lwc:Item}{l:item}\n", ip->i_title);
173 xo_close_list("item");
174 xo_close_container("data4");
176 xo_emit("X{P:}X", "epic fail");
177 xo_emit("X{T:}X", "epic fail");
178 xo_emit("X{N:}X", "epic fail");
179 xo_emit("X{L:}X\n", "epic fail");
181 xo_emit("X{P: }X{Lwc:Cost}{:cost/%u}\n", 425);
182 xo_emit("X{P:/%30s}X{Lwc:Cost}{:cost/%u}\n", "", 455);
184 xo_emit("{e:mode/%s}{e:mode_octal/%s} {t:links/%s} "
185 "{t:user/%s} {t:group/%s} \n",
186 "mode", "octal", "links",
187 "user", "group", "extra1", "extra2", "extra3");
189 xo_emit("{t:mode/%s}{e:mode_octal/%03o} {t:links/%*u} "
190 "{t:user/%-*s} {t:group/%-*s} \n",
191 "/some/file", (int) 0640, 8, 1,
192 10, "user", 12, "group");
194 xo_close_container_h(NULL, "top");