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
21 main (int argc, char **argv)
23 static char base_grocery[] = "GRO";
24 static char base_hardware[] = "HRD";
30 const char *i_sku_base;
33 struct item list[] = {
34 { "gum", 1412, 54, 10, base_grocery, 415 },
35 { "rope", 85, 4, 2, base_hardware, 212 },
36 { "ladder", 0, 2, 1, base_hardware, 517 },
37 { "bolt", 4123, 144, 42, base_hardware, 632 },
38 { "water", 17, 14, 2, base_grocery, 2331 },
39 { NULL, 0, 0, 0, NULL, 0 }
41 struct item list2[] = {
42 { "fish", 1321, 45, 1, base_grocery, 533 },
43 { NULL, 0, 0, 0, NULL, 0 }
47 { "in-stock", "number", "Number of items in stock" },
48 { "name", "string", "Name of the item" },
49 { "on-order", "number", "Number of items on order" },
50 { "sku", "string", "Stock Keeping Unit" },
51 { "sold", "number", "Number of items sold" },
54 int info_count = (sizeof(info) / sizeof(info[0])) - 1;
56 argc = xo_parse_args(argc, argv);
60 for (argc = 1; argv[argc]; argc++) {
61 if (strcmp(argv[argc], "xml") == 0)
62 xo_set_style(NULL, XO_STYLE_XML);
63 else if (strcmp(argv[argc], "json") == 0)
64 xo_set_style(NULL, XO_STYLE_JSON);
65 else if (strcmp(argv[argc], "text") == 0)
66 xo_set_style(NULL, XO_STYLE_TEXT);
67 else if (strcmp(argv[argc], "html") == 0)
68 xo_set_style(NULL, XO_STYLE_HTML);
69 else if (strcmp(argv[argc], "pretty") == 0)
70 xo_set_flags(NULL, XOF_PRETTY);
71 else if (strcmp(argv[argc], "xpath") == 0)
72 xo_set_flags(NULL, XOF_XPATH);
73 else if (strcmp(argv[argc], "info") == 0)
74 xo_set_flags(NULL, XOF_INFO);
75 else if (strcmp(argv[argc], "error") == 0) {
77 xo_err(1, "error detected");
81 xo_set_info(NULL, info, info_count);
82 xo_set_flags(NULL, XOF_KEYS);
84 /* Normally one would use "XOF_COLOR_ALLOWED", but we want to force it */
85 xo_set_flags(NULL, XOF_COLOR);
87 xo_set_version("3.1.4");
89 xo_open_container_h(NULL, "top");
91 xo_attr("test", "value");
92 xo_open_container("data");
94 xo_attr("test2", "value2");
96 static const char *colors[] =
97 { "blue", "green", "red", "yellow", "default", NULL };
100 for (i = 0; colors[i]; i++) {
102 xo_emit("{C:/bg-%s}", colors[i-1]);
103 xo_emit("{C:/fg-%s}{T:/%s}", colors[i], colors[i]);
105 xo_emit("{C:reset}\n");
107 xo_emit("{C:bold}{:data} {C:underline}{:data} {C:inverse}{:data} "
108 "{C:no-bold}{:data} {C:no-inverse}{:data} "
109 "{C:no-underline}{:data}\n",
110 "bold", "bold-ul", "triple", "inv-ul", "underline", "plain");
112 xo_emit("{T:Item/%-10s}{C:bold,underline}{T:Total Sold/%12s}{C:no-bold}"
113 "{T:In Stock/%12s}{C:/%s}"
114 "{T:On Order/%12s}{C:normal}{T:SKU/%5s}\n", "inverse");
121 for (ip = list; ip->i_title; ip++) {
122 xo_open_instance("item");
123 xo_attr("test3", "value3");
125 xo_emit("{keq:sku/%s-%u/%s-000-%u}"
126 "{k:name/%-10s/%s}{n:sold/%12u/%u}"
127 "{C:/%s}{:in-stock/%12u/%u}{C:normal}"
128 "{C:/fg-%s}{:on-order/%12u/%u}{C:/fg-default}"
129 "{qkd:sku/%5s-000-%u/%s-000-%u}\n",
130 ip->i_sku_base, ip->i_sku_num,
131 ip->i_title, ip->i_sold,
132 (ip->i_instock < 5) ? "inverse" : "normal", ip->i_instock,
133 (ip->i_onorder > 5) ? "yellow" : "default", ip->i_onorder,
134 ip->i_sku_base, ip->i_sku_num);
136 xo_close_instance("item");
139 xo_close_list("item");
140 xo_close_container("data");
144 xo_open_container("data");
145 xo_open_list("item");
147 for (ip = list; 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}{C:inverse}{:in-stock/%u}{C:}\n",
156 xo_emit("{P: }{Lcw:On order}{:on-order/%u}\n", ip->i_onorder);
157 xo_emit("{P: }{L:SKU}: {qkd:sku/%s-000-%u}\n",
158 ip->i_sku_base, ip->i_sku_num);
160 xo_close_instance("item");
163 xo_close_list("item");
164 xo_close_container("data");
166 xo_open_container("data");
167 xo_open_list("item");
169 for (ip = list2; ip->i_title; ip++) {
170 xo_open_instance("item");
172 xo_emit("{keq:sku/%s-%u/%s-000-%u}", ip->i_sku_base, ip->i_sku_num);
173 xo_emit("{L:Item} '{k:name/%s}':\n", ip->i_title);
174 xo_emit("{P: }{C:bg-blue , fg-white, bold }{L:Total sold}: "
175 "{n:sold/%u%s}{C:}\n",
176 ip->i_sold, ip->i_sold ? ".0" : "");
177 xo_emit("{P: }{Lcw:In stock}{:in-stock/%u}\n", ip->i_instock);
178 xo_emit("{P: }{Lcw:On order}{:on-order/%u}\n", ip->i_onorder);
179 xo_emit("{P: }{L:SKU}: {qkd:sku/%s-000-%u}\n",
180 ip->i_sku_base, ip->i_sku_num);
182 xo_close_instance("item");
185 xo_close_list("item");
186 xo_close_container("data");
188 xo_open_container("data");
189 xo_open_list("item");
191 for (ip = list; ip->i_title; ip++) {
192 xo_attr("test4", "value4");
193 xo_emit("{Lwc:Item}{l:item}\n", ip->i_title);
196 xo_close_list("item");
197 xo_close_container("data");
199 xo_emit("X{P:}X", "epic fail");
200 xo_emit("X{T:}X", "epic fail");
201 xo_emit("X{N:}X", "epic fail");
202 xo_emit("X{L:}X\n", "epic fail");
204 xo_emit("X{P: }X{Lwc:Cost}{:cost/%u}\n", 425);
205 xo_emit("X{P:/%30s}X{Lwc:Cost}{:cost/%u}\n", "", 455);
207 xo_close_container_h(NULL, "top");