2 * Copyright (c) 2014-2019, 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
17 #include "xo_encoder.h"
19 #include "xo_humanize.h"
22 main (int argc, char **argv)
24 xo_set_program("test_02");
26 argc = xo_parse_args(argc, argv);
30 for (argc = 1; argv[argc]; argc++) {
31 if (xo_streq(argv[argc], "xml"))
32 xo_set_style(NULL, XO_STYLE_XML);
33 else if (xo_streq(argv[argc], "json"))
34 xo_set_style(NULL, XO_STYLE_JSON);
35 else if (xo_streq(argv[argc], "text"))
36 xo_set_style(NULL, XO_STYLE_TEXT);
37 else if (xo_streq(argv[argc], "html"))
38 xo_set_style(NULL, XO_STYLE_HTML);
39 else if (xo_streq(argv[argc], "pretty"))
40 xo_set_flags(NULL, XOF_PRETTY);
41 else if (xo_streq(argv[argc], "xpath"))
42 xo_set_flags(NULL, XOF_XPATH);
43 else if (xo_streq(argv[argc], "info"))
44 xo_set_flags(NULL, XOF_INFO);
47 xo_set_flags(NULL, XOF_UNITS); /* Always test w/ this */
50 xo_open_container_h(NULL, "top");
52 xo_open_container("data");
54 xo_emit("{kt:name/%-*.*s}{eq:flags/0x%x}",
57 xo_emit("{d:/%-*.*s}{etk:name}{eq:flags/0x%x}",
58 5, 5, "em0", "em0", 34883);
60 xo_emit("We are {{emit}}{{ting}} some {:what}\n", "braces");
64 xo_message_e("abcdef");
66 xo_message("improper use of profanity; %s; %s",
67 "ten yard penalty", "first down");
69 xo_emit("length {:length/%6.6s}\n", "abcdefghijklmnopqrstuvwxyz");
72 xo_emit("close {:fd/%d} returned {:error/%m} {:test}\n", -1, "good");
74 xo_emit("close {:fd/%d} returned {:error/%6.6m} {:test}\n", -1, "good");
77 xo_message("improper use of profanity; %s; %s",
78 "ten yard penalty", "first down");
80 xo_emit(" {:lines/%7ju} {:words/%7ju} "
81 "{:characters/%7ju} {d:filename/%s}\n",
82 (uintmax_t) 20, (uintmax_t) 30, (uintmax_t) 40, "file");
85 for (i = 0; i < 5; i++)
86 xo_emit("{lw:bytes/%d}{Np:byte,bytes}\n", i);
89 xo_emit("{:mbuf-current/%u}/{:mbuf-cache/%u}/{:mbuf-total/%u} "
90 "{N:mbufs <&> in use (current\\/cache\\/total)}\n",
93 xo_emit("{:distance/%u}{Uw:miles} from {:location}\n", 50, "Boston");
94 xo_emit("{:memory/%u}{U:k} left out of {:total/%u}{U:kb}\n", 64, 640);
95 xo_emit("{:memory/%u}{U:/%s} left out of {:total/%u}{U:/%s}\n",
96 64, "k", 640, "kilobytes");
98 xo_emit("{,title:/before%safter:}\n", "working");
100 xo_emit("{,display,white,colon:some/%s}"
101 "{,value:ten/%ju}{,value:eleven/%ju}\n",
102 "string", (uintmax_t) 10, (uintmax_t) 11);
104 xo_emit("{:unknown/%u} "
105 "{N:/packet%s here\\/there\\/everywhere}\n",
108 xo_emit("{:unknown/%u} "
109 "{,note:/packet%s here\\/there\\/everywhere}\n",
112 xo_emit("({[:/%d}{n:min/15}/{n:cur/20}/{:max/%d}{]:})\n", 30, 125);
113 xo_emit("({[:30}{:min/%u}/{:cur/%u}/{:max/%u}{]:})\n", 15, 20, 125);
114 xo_emit("({[:-30}{n:min/15}/{n:cur/20}/{n:max/125}{]:})\n");
115 xo_emit("({[:}{:min/%u}/{:cur/%u}/{:max/%u}{]:/%d})\n", 15, 20, 125, -30);
117 xo_emit("Humanize: {h:val1/%u}, {h,hn-space:val2/%u}, "
118 "{h,hn-decimal:val3/%u}, {h,hn-1000:val4/%u}, "
119 "{h,hn-decimal:val5/%u}\n",
123 (42 * 1024 + 420) * 1024,
126 xo_open_list("flag");
127 xo_emit("{lq:flag/one} {lq:flag/two} {lq:flag/three}\n");
128 xo_close_list("flag");
130 xo_emit("{n:works/%s}\n", NULL);
132 xo_emit("{e:empty-tag/}");
133 xo_emit("1:{qt:t1/%*d} 2:{qt:t2/test%-*u} "
134 "3:{qt:t3/%10sx} 4:{qt:t4/x%-*.*s}\n",
135 6, 1000, 8, 5000, "ten-long", 10, 10, "test");
136 xo_emit("{E:this is an error}\n");
137 xo_emit("{E:/%s more error%s}\n", "two", "s" );
138 xo_emit("{W:this is an warning}\n");
139 xo_emit("{W:/%s more warning%s}\n", "two", "s" );
140 xo_emit("{L:/V1\\/V2 packet%s}: {:count/%u}\n", "s", 10);
143 xo_emit("{:test/%04d} {L:/tr%s}\n", test, (test == 1) ? "y" : "ies");
145 xo_message("improper use of profanity; %s; %s",
146 "ten yard penalty", "first down");
148 xo_error("Shut 'er down, Clancey! She's a-pumpin' mud! <>!,\"!<>\n");
149 xo_error("err message (%d)", 1);
150 xo_error("err message (%d)\n", 2);
151 xo_errorn("err message (%d)", 1);
152 xo_errorn("err message (%d)\n", 2);
154 xo_close_container("data");
156 xo_close_container_h(NULL, "top");