xref: /freebsd/contrib/libxo/tests/core/test_12.c (revision 86c9d9918f1db7cdd968b60f8902466887bcd9e9)
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_config.h"
17 #include "xo.h"
18 
19 int
20 main (int argc, char **argv)
21 {
22     int i, count = 10;
23     int mon = 0;
24     xo_emit_flags_t flags = XOEF_RETAIN;
25 
26     argc = xo_parse_args(argc, argv);
27     if (argc < 0)
28 	return 1;
29 
30     for (argc = 1; argv[argc]; argc++) {
31 	if (strcmp(argv[argc], "xml") == 0)
32 	    xo_set_style(NULL, XO_STYLE_XML);
33 	else if (strcmp(argv[argc], "json") == 0)
34 	    xo_set_style(NULL, XO_STYLE_JSON);
35 	else if (strcmp(argv[argc], "text") == 0)
36 	    xo_set_style(NULL, XO_STYLE_TEXT);
37 	else if (strcmp(argv[argc], "html") == 0)
38 	    xo_set_style(NULL, XO_STYLE_HTML);
39 	else if (strcmp(argv[argc], "pretty") == 0)
40 	    xo_set_flags(NULL, XOF_PRETTY);
41 	else if (strcmp(argv[argc], "xpath") == 0)
42 	    xo_set_flags(NULL, XOF_XPATH);
43 	else if (strcmp(argv[argc], "info") == 0)
44 	    xo_set_flags(NULL, XOF_INFO);
45 	else if (strcmp(argv[argc], "no-retain") == 0)
46 	    flags &= ~XOEF_RETAIN;
47 	else if (strcmp(argv[argc], "big") == 0) {
48 	    if (argv[argc + 1])
49 		count = atoi(argv[++argc]);
50 	}
51     }
52 
53     xo_set_flags(NULL, XOF_UNITS); /* Always test w/ this */
54     xo_set_file(stdout);
55 
56     xo_open_container("top");
57     xo_open_container("data");
58 
59     const char *fmt1 = "The {C:fg-red}{k:name}{C:reset} is "
60 	"{C:/fg-%s}{:color}{C:reset} til {:time/%02d:%02d}\n";
61     const char *fmt2 = "My {C:fg-red}{:hand}{C:reset} hand is "
62 	"{C:/fg-%s}{:color}{C:reset} til {:time/%02d:%02d}\n";
63 
64     for (i = 0; i < count; i++) {
65 	xo_open_instance("thing");
66 	xo_emit_f(flags, fmt1, "thing", "green", "green", 2, 15);
67 	xo_emit_f(flags, fmt2, "left", "blue", "blue", 3, 45);
68     }
69 
70     xo_close_container("data");
71     xo_close_container_h(NULL, "top");
72 
73     xo_finish();
74 
75     return 0;
76 }
77