2 * Copyright (c) 2014, 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
16 #include "xo_encoder.h"
19 { "employee", "object", "Employee data" },
20 { "first-name", "string", "First name of employee" },
21 { "last-name", "string", "Last name of employee" },
22 { "department", "number", "Department number" },
24 int info_count = (sizeof(info) / sizeof(info[0]));
27 main (int argc, char **argv)
29 unsigned opt_count = 1;
30 unsigned opt_extra = 0;
37 { "Terry", "Jones", 660 },
38 { "Leslie", "Patterson", 341 },
39 { "Ashley", "Smith", 1440 },
43 argc = xo_parse_args(argc, argv);
47 for (argc = 1; argv[argc]; argc++) {
48 if (xo_streq(argv[argc], "count")) {
50 opt_count = atoi(argv[++argc]);
51 } else if (xo_streq(argv[argc], "extra")) {
53 opt_extra = atoi(argv[++argc]);
57 xo_set_info(NULL, info, info_count);
59 xo_open_container("employees");
60 xo_open_list("employee");
62 xo_emit("[{:extra/%*s}]\n", opt_extra, "");
64 xo_emit("{T:/%13s} {T:/%5s} {T:/%6s} {T:/%7s} {T:/%8s} {T:Size(s)}\n",
65 "Type", "InUse", "MemUse", "HighUse", "Requests");
66 xo_open_list("memory");
67 xo_open_instance("memory");
70 #define TO_ULL(_x) ((unsigned long long) _x)
71 xo_emit("{k:type/%13s} {:in-use/%5" PRIu64 "} "
72 "{:memory-use/%5" PRIu64 "}{U:K} {:high-use/%7s} "
73 "{:requests/%8" PRIu64 "} ",
74 "name", TO_ULL(12345), TO_ULL(54321), "-", TO_ULL(32145));
79 for (i = 0; i < 32; i++) {
82 xo_emit("{l:size/%d}", 1 << (i + 4));
85 xo_close_list("size");
87 xo_close_instance("memory");
89 xo_close_list("memory");
91 while (opt_count-- != 0) {
92 for (ep = employees; ep->e_first; ep++) {
93 xo_open_instance("employee");
94 xo_emit("{:first-name} {:last-name} works in "
95 "dept #{:department/%u}\n",
96 ep->e_first, ep->e_last, ep->e_dept);
97 xo_close_instance("employee");
103 xo_close_list("employee");
104 xo_close_container("employees");