xref: /freebsd/contrib/libxo/tests/core/test_03.c (revision 7e00348e7605b9906601438008341ffc37c00e2c)
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 };
23 int info_count = (sizeof(info) / sizeof(info[0]));
24 
25 int
26 main (int argc, char **argv)
27 {
28     struct employee {
29 	const char *e_first;
30 	const char *e_last;
31 	unsigned e_dept;
32     } employees[] = {
33 	{ "Terry", "Jones", 660 },
34 	{ "Leslie", "Patterson", 341 },
35 	{ "Ashley", "Smith", 1440 },
36 	{ NULL, NULL }
37     }, *ep = employees;
38 
39     argc = xo_parse_args(argc, argv);
40     if (argc < 0)
41 	return 1;
42 
43     xo_set_info(NULL, info, info_count);
44 
45     xo_open_container("employees");
46     xo_open_list("employee");
47 
48     for ( ; ep->e_first; ep++) {
49 	xo_open_instance("employee");
50 	xo_emit("{:first-name} {:last-name} works in dept #{:department/%u}\n",
51 		ep->e_first, ep->e_last, ep->e_dept);
52 	xo_close_instance("employee");
53     }
54 
55     xo_close_list("employee");
56     xo_close_container("employees");
57 
58     xo_finish();
59 
60     return 0;
61 }
62