xref: /freebsd/contrib/libxo/tests/core/test_05.c (revision 2b15cb3d0922bd70ea592f0da9b4a5b167f4d53f)
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 
45     argc = xo_parse_args(argc, argv);
46     if (argc < 0)
47 	return 1;
48 
49     xo_set_info(NULL, info, info_count);
50 
51     xo_open_container("employees");
52 
53     xo_emit("Οὐχὶ ταὐτὰ παρίσταταί μοι {:v1/%s}, {:v2/%s}\n",
54 	    "γιγνώσκειν", "ὦ ἄνδρες ᾿Αθηναῖοι");
55 
56     xo_emit("გთხოვთ {:v1/%s} {:v2/%s}\n",
57 	    "ახლავე გაიაროთ რეგისტრაცია",
58 	    "Unicode-ის მეათე საერთაშორისო");
59 
60     xo_open_list("employee");
61 
62     xo_emit("{T:First Name/%-25s}{T:Last Name/%-14s}"
63 	    "{T:/%-12s}{T:Time (%)}\n", "Department");
64     for ( ; ep->e_first; ep++) {
65 	xo_open_instance("employee");
66 	xo_emit("{[:-25}{:first-name/%s} ({:nic-name/\"%s\"}){]:}"
67 		"{:last-name/%-14..14s/%s}"
68 		"{:department/%8u/%u}{:percent-time/%8u/%u}\n",
69 		ep->e_first, ep->e_nic, ep->e_last, ep->e_dept, ep->e_percent);
70 	if (ep->e_percent > 50) {
71 	    xo_attr("full-time", "%s", "honest & for true");
72 	    xo_emit("{e:benefits/%s}", "full");
73 	}
74 	xo_close_instance("employee");
75     }
76 
77     xo_close_list("employee");
78     xo_close_container("employees");
79 
80     xo_finish();
81 
82     return 0;
83 }
84