]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libxo/tests/core/test_12.c
Merge lldb release_80 branch r351543, and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / libxo / tests / core / test_12.c
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     int opt_color = 1;
26
27     argc = xo_parse_args(argc, argv);
28     if (argc < 0)
29         return 1;
30
31     for (argc = 1; argv[argc]; argc++) {
32         if (strcmp(argv[argc], "xml") == 0)
33             xo_set_style(NULL, XO_STYLE_XML);
34         else if (strcmp(argv[argc], "json") == 0)
35             xo_set_style(NULL, XO_STYLE_JSON);
36         else if (strcmp(argv[argc], "text") == 0)
37             xo_set_style(NULL, XO_STYLE_TEXT);
38         else if (strcmp(argv[argc], "html") == 0)
39             xo_set_style(NULL, XO_STYLE_HTML);
40         else if (strcmp(argv[argc], "no-color") == 0)
41             opt_color = 0;
42         else if (strcmp(argv[argc], "pretty") == 0)
43             xo_set_flags(NULL, XOF_PRETTY);
44         else if (strcmp(argv[argc], "xpath") == 0)
45             xo_set_flags(NULL, XOF_XPATH);
46         else if (strcmp(argv[argc], "info") == 0)
47             xo_set_flags(NULL, XOF_INFO);
48         else if (strcmp(argv[argc], "no-retain") == 0)
49             flags &= ~XOEF_RETAIN;
50         else if (strcmp(argv[argc], "big") == 0) {
51             if (argv[argc + 1])
52                 count = atoi(argv[++argc]);
53         }
54     }
55
56     xo_set_flags(NULL, XOF_UNITS); /* Always test w/ this */
57     if (opt_color)
58         xo_set_flags(NULL, XOF_COLOR); /* Force color output */
59     xo_set_file(stdout);
60
61     xo_open_container("top");
62     xo_open_container("data");
63
64     xo_emit("{C:fg-red,bg-green}Merry XMas!!{C:}\n");
65
66     xo_emit("One {C:fg-yellow,bg-blue}{:animal}{C:}, "
67             "Two {C:fg-green,bg-yellow}{:animal}{C:}\n",
68           "fish", "fish");
69
70     const char *fmt1 = "The {C:fg-red}{k:name}{C:reset} is "
71         "{C:/fg-%s}{:color}{C:reset} til {:time/%02d:%02d}\n";
72     const char *fmt2 = "My {C:fg-red}{:hand}{C:reset} hand is "
73         "{C:/fg-%s}{:color}{C:reset} til {:time/%02d:%02d}\n";
74
75     for (i = 0; i < count; i++) {
76         xo_open_instance("thing");
77         xo_emit_f(flags, fmt1, "thing", "green", "green", 2, 15);
78         xo_emit_f(flags, fmt2, "left", "blue", "blue", 3, 45);
79     }
80
81     xo_close_container("data");
82     xo_close_container_h(NULL, "top");
83
84     xo_finish();
85
86     return 0;
87 }