Deleted Added
full compact
test_02.c (273562) test_02.c (287111)
1/*
2 * Copyright (c) 2014, Juniper Networks, Inc.
3 * All rights reserved.
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
7 * LICENSE.
8 * Phil Shafer, July 2014
9 */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <stdint.h>
14#include <string.h>
15
16#include "xo.h"
17
1/*
2 * Copyright (c) 2014, Juniper Networks, Inc.
3 * All rights reserved.
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
7 * LICENSE.
8 * Phil Shafer, July 2014
9 */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <stdint.h>
14#include <string.h>
15
16#include "xo.h"
17
18#include "xo_humanize.h"
19
18int
19main (int argc, char **argv)
20{
21 argc = xo_parse_args(argc, argv);
22 if (argc < 0)
23 return 1;
24
25 for (argc = 1; argv[argc]; argc++) {

--- 14 unchanged lines hidden (view full) ---

40 }
41
42 xo_set_flags(NULL, XOF_UNITS); /* Always test w/ this */
43
44 xo_open_container_h(NULL, "top");
45
46 xo_open_container("data");
47
20int
21main (int argc, char **argv)
22{
23 argc = xo_parse_args(argc, argv);
24 if (argc < 0)
25 return 1;
26
27 for (argc = 1; argv[argc]; argc++) {

--- 14 unchanged lines hidden (view full) ---

42 }
43
44 xo_set_flags(NULL, XOF_UNITS); /* Always test w/ this */
45
46 xo_open_container_h(NULL, "top");
47
48 xo_open_container("data");
49
50 xo_emit("We are {{emit}}{{ting}} some {:what}\n", "braces");
51
52 xo_message("abcdef");
53 close(-1);
54 xo_message_e("abcdef");
55
56 xo_message("improper use of profanity; %s; %s",
57 "ten yard penalty", "first down");
58
59 xo_emit("length {:length/%6.6s}\n", "abcdefghijklmnopqrstuvwxyz");
60
61 close(-1);
62 xo_emit("close {:fd/%d} returned {:error/%m} {:test}\n", -1, "good");
63 close(-1);
64 xo_emit("close {:fd/%d} returned {:error/%6.6m} {:test}\n", -1, "good");
65
66
67 xo_message("improper use of profanity; %s; %s",
68 "ten yard penalty", "first down");
69
70 xo_emit(" {:lines/%7ju} {:words/%7ju} "
71 "{:characters/%7ju} {d:filename/%s}\n",
72 20, 30, 40, "file");
73
74 int i;
75 for (i = 0; i < 5; i++)
76 xo_emit("{lw:bytes/%d}{Np:byte,bytes}\n", i);
77
78
48 xo_emit("{:mbuf-current/%u}/{:mbuf-cache/%u}/{:mbuf-total/%u} "
49 "{N:mbufs <&> in use (current\\/cache\\/total)}\n",
50 10, 20, 30);
51
52 xo_emit("{:distance/%u}{Uw:miles} from {:location}\n", 50, "Boston");
53 xo_emit("{:memory/%u}{U:k} left out of {:total/%u}{U:kb}\n", 64, 640);
54 xo_emit("{:memory/%u}{U:/%s} left out of {:total/%u}{U:/%s}\n",
55 64, "k", 640, "kilobytes");
56
79 xo_emit("{:mbuf-current/%u}/{:mbuf-cache/%u}/{:mbuf-total/%u} "
80 "{N:mbufs <&> in use (current\\/cache\\/total)}\n",
81 10, 20, 30);
82
83 xo_emit("{:distance/%u}{Uw:miles} from {:location}\n", 50, "Boston");
84 xo_emit("{:memory/%u}{U:k} left out of {:total/%u}{U:kb}\n", 64, 640);
85 xo_emit("{:memory/%u}{U:/%s} left out of {:total/%u}{U:/%s}\n",
86 64, "k", 640, "kilobytes");
87
57 xo_emit("{T:/before%safter:}\n", "working");
88 xo_emit("{,title:/before%safter:}\n", "working");
58
89
59 xo_emit("{d:some/%s}{:ten/%ju}{:eleven/%ju}\n",
90 xo_emit("{,display,white,colon:some/%s}"
91 "{,value:ten/%ju}{,value:eleven/%ju}\n",
60 "string", (uintmax_t) 10, (uintmax_t) 11);
61
62 xo_emit("{:unknown/%u} "
63 "{N:/packet%s here\\/there\\/everywhere}\n",
64 1010, "s");
65
92 "string", (uintmax_t) 10, (uintmax_t) 11);
93
94 xo_emit("{:unknown/%u} "
95 "{N:/packet%s here\\/there\\/everywhere}\n",
96 1010, "s");
97
98 xo_emit("{:unknown/%u} "
99 "{,note:/packet%s here\\/there\\/everywhere}\n",
100 1010, "s");
101
66 xo_emit("({[:/%d}{n:min/15}/{n:cur/20}/{:max/%d}{]:})\n", 30, 125);
67 xo_emit("({[:30}{:min/%u}/{:cur/%u}/{:max/%u}{]:})\n", 15, 20, 125);
68 xo_emit("({[:-30}{n:min/15}/{n:cur/20}/{n:max/125}{]:})\n");
69 xo_emit("({[:}{:min/%u}/{:cur/%u}/{:max/%u}{]:/%d})\n", 15, 20, 125, -30);
70
102 xo_emit("({[:/%d}{n:min/15}/{n:cur/20}/{:max/%d}{]:})\n", 30, 125);
103 xo_emit("({[:30}{:min/%u}/{:cur/%u}/{:max/%u}{]:})\n", 15, 20, 125);
104 xo_emit("({[:-30}{n:min/15}/{n:cur/20}/{n:max/125}{]:})\n");
105 xo_emit("({[:}{:min/%u}/{:cur/%u}/{:max/%u}{]:/%d})\n", 15, 20, 125, -30);
106
107 xo_emit("Humanize: {h:val1/%u}, {h,hn-space:val2/%u}, "
108 "{h,hn-decimal:val3/%u}, {h,hn-1000:val4/%u}, "
109 "{h,hn-decimal:val5/%u}\n",
110 21,
111 57 * 1024,
112 96 * 1024 * 1024,
113 (42 * 1024 + 420) * 1024,
114 1342172800);
115
71 xo_open_list("flag");
72 xo_emit("{lq:flag/one} {lq:flag/two} {lq:flag/three}\n");
73 xo_close_list("flag");
74
116 xo_open_list("flag");
117 xo_emit("{lq:flag/one} {lq:flag/two} {lq:flag/three}\n");
118 xo_close_list("flag");
119
120 xo_emit("{n:works/%s}\n", NULL);
121
75 xo_emit("{e:empty-tag/}");
122 xo_emit("{e:empty-tag/}");
76 xo_emit("1:{qt:t1/%*d} 2:{qt:t2/test%-*u} 3:{qt:t3/%10sx} 4:{qt:t4/x%-*.*s}\n",
123 xo_emit("1:{qt:t1/%*d} 2:{qt:t2/test%-*u} "
124 "3:{qt:t3/%10sx} 4:{qt:t4/x%-*.*s}\n",
77 6, 1000, 8, 5000, "ten-long", 10, 10, "test");
78 xo_emit("{E:this is an error}\n");
79 xo_emit("{E:/%s more error%s}\n", "two", "s" );
80 xo_emit("{W:this is an warning}\n");
81 xo_emit("{W:/%s more warning%s}\n", "two", "s" );
82 xo_emit("{L:/V1\\/V2 packet%s}: {:count/%u}\n", "s", 10);
83
84 int test = 4;

--- 15 unchanged lines hidden ---
125 6, 1000, 8, 5000, "ten-long", 10, 10, "test");
126 xo_emit("{E:this is an error}\n");
127 xo_emit("{E:/%s more error%s}\n", "two", "s" );
128 xo_emit("{W:this is an warning}\n");
129 xo_emit("{W:/%s more warning%s}\n", "two", "s" );
130 xo_emit("{L:/V1\\/V2 packet%s}: {:count/%u}\n", "s", 10);
131
132 int test = 4;

--- 15 unchanged lines hidden ---