Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/libxo/tests/core/test_07.c
39537 views
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 <string.h>
14
15
#include "xo.h"
16
17
xo_info_t info[] = {
18
{ "employee", "object", "Employee data" },
19
{ "first-name", "string", "First name of employee" },
20
{ "last-name", "string", "Last name of employee" },
21
{ "department", "number", "Department number" },
22
{ "percent-time", "number", "Percentage of full & part time (%)" },
23
};
24
int info_count = (sizeof(info) / sizeof(info[0]));
25
26
int
27
main (int argc, char **argv)
28
{
29
struct employee {
30
const char *e_first;
31
const char *e_nic;
32
const char *e_last;
33
unsigned e_dept;
34
unsigned e_percent;
35
} employees[] = {
36
{ "Jim", "რეგტ", "გთხოვთ ახ", 431, 90 },
37
{ "Terry", "<one", "Οὐχὶ ταὐτὰ παρίσταταί μοι Jones", 660, 90 },
38
{ "Leslie", "Les", "Patterson", 341,60 },
39
{ "Ashley", "Ash", "Meter & Smith", 1440, 40 },
40
{ "0123456789", "0123456789", "012345678901234567890", 1440, 40 },
41
{ "ახლა", "გაიარო", "საერთაშორისო", 123, 90 },
42
{ NULL, NULL }
43
}, *ep = employees;
44
int rc;
45
46
argc = xo_parse_args(argc, argv);
47
if (argc < 0)
48
return 1;
49
50
xo_set_info(NULL, info, info_count);
51
xo_set_flags(NULL, XOF_COLUMNS);
52
53
xo_open_container("employees");
54
55
xo_open_list("test");
56
xo_open_instance("test");
57
xo_emit("{ek:filename/%s}", NULL);
58
xo_close_instance("test");
59
xo_close_list("test");
60
61
rc = xo_emit("Οὐχὶ ταὐτὰ παρίσταταί μοι {:v1/%s}, {:v2/%s}\n",
62
"γιγνώσκειν", "ὦ ἄνδρες ᾿Αθηναῖοι");
63
rc = xo_emit("{:columns/%d}\n", rc);
64
xo_emit("{:columns/%d}\n", rc);
65
66
rc = xo_emit("გთხოვთ {:v1/%s} {:v2/%s}\n",
67
"ახლავე გაიაროთ რეგისტრაცია",
68
"Unicode-ის მეათე საერთაშორისო");
69
xo_emit("{:columns/%d}\n", rc);
70
71
72
rc = xo_emit("{T:First Name/%-25s}{T:Last Name/%-14s}"
73
"{T:/%-12s}{T:Time (%)}\n", "Department");
74
xo_emit("{:columns/%d}\n", rc);
75
76
xo_open_list("employee");
77
for ( ; ep->e_first; ep++) {
78
xo_open_instance("employee");
79
rc = xo_emit("{[:-25}{:first-name/%s} ({:nic-name/\"%s\"}){]:}"
80
"{:last-name/%-14..14s/%s}"
81
"{:department/%8u/%u}{:percent-time/%8u/%u}\n",
82
ep->e_first, ep->e_nic, ep->e_last, ep->e_dept, ep->e_percent);
83
xo_emit("{:columns/%d}\n", rc);
84
if (ep->e_percent > 50) {
85
xo_attr("full-time", "%s", "honest & for true");
86
xo_emit("{e:benefits/%s}", "full");
87
}
88
xo_close_instance("employee");
89
}
90
91
xo_close_list("employee");
92
xo_close_container("employees");
93
94
xo_finish();
95
96
return 0;
97
}
98
99