Path: blob/main/contrib/libxo/tests/core/test_12.c
39537 views
/*1* Copyright (c) 2014, Juniper Networks, Inc.2* All rights reserved.3* This SOFTWARE is licensed under the LICENSE provided in the4* ../Copyright file. By downloading, installing, copying, or otherwise5* using the SOFTWARE, you agree to be bound by the terms of that6* LICENSE.7* Phil Shafer, July 20148*/910#include <stdio.h>11#include <stdlib.h>12#include <stdint.h>13#include <string.h>1415#include "xo_config.h"16#include "xo.h"17#include "xo_encoder.h"1819int20main (int argc, char **argv)21{22int i, count = 10;23int mon = 0;24xo_emit_flags_t flags = XOEF_RETAIN;25int opt_color = 1;2627xo_set_program("test_12");2829argc = xo_parse_args(argc, argv);30if (argc < 0)31return 1;3233for (argc = 1; argv[argc]; argc++) {34if (xo_streq(argv[argc], "xml"))35xo_set_style(NULL, XO_STYLE_XML);36else if (xo_streq(argv[argc], "json"))37xo_set_style(NULL, XO_STYLE_JSON);38else if (xo_streq(argv[argc], "text"))39xo_set_style(NULL, XO_STYLE_TEXT);40else if (xo_streq(argv[argc], "html"))41xo_set_style(NULL, XO_STYLE_HTML);42else if (xo_streq(argv[argc], "no-color"))43opt_color = 0;44else if (xo_streq(argv[argc], "pretty"))45xo_set_flags(NULL, XOF_PRETTY);46else if (xo_streq(argv[argc], "xpath"))47xo_set_flags(NULL, XOF_XPATH);48else if (xo_streq(argv[argc], "info"))49xo_set_flags(NULL, XOF_INFO);50else if (xo_streq(argv[argc], "no-retain"))51flags &= ~XOEF_RETAIN;52else if (xo_streq(argv[argc], "big")) {53if (argv[argc + 1])54count = atoi(argv[++argc]);55}56}5758xo_set_flags(NULL, XOF_UNITS); /* Always test w/ this */59if (opt_color)60xo_set_flags(NULL, XOF_COLOR); /* Force color output */61xo_set_file(stdout);6263xo_open_container("top");64xo_open_container("data");6566xo_emit("{C:fg-red,bg-green}Merry XMas!!{C:}\n");6768xo_emit("One {C:fg-yellow,bg-blue}{:animal}{C:}, "69"Two {C:fg-green,bg-yellow}{:animal}{C:}\n",70"fish", "fish");7172const char *fmt1 = "The {C:fg-red}{k:name}{C:reset} is "73"{C:/fg-%s}{:color}{C:reset} til {:time/%02d:%02d}\n";74const char *fmt2 = "My {C:fg-red}{:hand}{C:reset} hand is "75"{C:/fg-%s}{:color}{C:reset} til {:time/%02d:%02d}\n";7677for (i = 0; i < count; i++) {78xo_open_instance("thing");79xo_emit_f(flags, fmt1, "thing", "green", "green", 2, 15);80xo_emit_f(flags, fmt2, "left", "blue", "blue", 3, 45);81}8283xo_open_container("2by4");84xo_emit("There is {:4x4} in {:2morrow}\n", "truck", "tomorrow");85xo_close_container("2by4");868788xo_close_container("data");89xo_close_container_h(NULL, "top");9091xo_finish();9293return 0;94}959697