1273562Smarcel/*
2273562Smarcel * Copyright (c) 2014, Juniper Networks, Inc.
3273562Smarcel * All rights reserved.
4273562Smarcel * This SOFTWARE is licensed under the LICENSE provided in the
5273562Smarcel * ../Copyright file. By downloading, installing, copying, or otherwise
6273562Smarcel * using the SOFTWARE, you agree to be bound by the terms of that
7273562Smarcel * LICENSE.
8273562Smarcel * Phil Shafer, July 2014
9273562Smarcel */
10273562Smarcel
11273562Smarcel#include <stdio.h>
12273562Smarcel#include <stdlib.h>
13273562Smarcel#include <string.h>
14273562Smarcel
15273562Smarcel#include "xo.h"
16273562Smarcel
17273562Smarcelxo_info_t info[] = {
18273562Smarcel    { "employee", "object", "Employee data" },
19273562Smarcel    { "first-name", "string", "First name of employee" },
20273562Smarcel    { "last-name", "string", "Last name of employee" },
21273562Smarcel    { "department", "number", "Department number" },
22273562Smarcel};
23273562Smarcelint info_count = (sizeof(info) / sizeof(info[0]));
24273562Smarcel
25273562Smarcelint
26273562Smarcelmain (int argc, char **argv)
27273562Smarcel{
28273562Smarcel    struct employee {
29273562Smarcel	const char *e_first;
30273562Smarcel	const char *e_last;
31273562Smarcel	unsigned e_dept;
32273562Smarcel    } employees[] = {
33273562Smarcel	{ "Terry", "Jones", 660 },
34273562Smarcel	{ "Leslie", "Patterson", 341 },
35273562Smarcel	{ "Ashley", "Smith", 1440 },
36273562Smarcel	{ NULL, NULL }
37273562Smarcel    }, *ep = employees;
38273562Smarcel
39273562Smarcel    argc = xo_parse_args(argc, argv);
40273562Smarcel    if (argc < 0)
41273562Smarcel	return 1;
42273562Smarcel
43273562Smarcel    xo_set_info(NULL, info, info_count);
44273562Smarcel
45273562Smarcel    xo_set_flags(NULL, XOF_DTRT);
46273562Smarcel
47273562Smarcel    xo_open_container("employees");
48273562Smarcel    xo_open_list("employee");
49273562Smarcel
50273562Smarcel    for ( ; ep->e_first; ep++) {
51273562Smarcel	xo_open_instance("employee");
52273562Smarcel	xo_emit("{:first-name} {:last-name} works in dept #{:department/%u}\n",
53273562Smarcel		ep->e_first, ep->e_last, ep->e_dept);
54273562Smarcel	xo_close_instance_d();
55273562Smarcel    }
56273562Smarcel
57273562Smarcel    xo_close_list_d();
58273562Smarcel    xo_close_container_d();
59273562Smarcel
60273562Smarcel    xo_finish();
61273562Smarcel
62273562Smarcel    return 0;
63273562Smarcel}
64