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    { "percent-time", "number", "Percentage of full & part time (%)" },
23273562Smarcel};
24273562Smarcelint info_count = (sizeof(info) / sizeof(info[0]));
25273562Smarcel
26273562Smarcelint
27273562Smarcelmain (int argc, char **argv)
28273562Smarcel{
29273562Smarcel    struct employee {
30273562Smarcel	const char *e_first;
31273562Smarcel	const char *e_nic;
32273562Smarcel	const char *e_last;
33273562Smarcel	unsigned e_dept;
34273562Smarcel	unsigned e_percent;
35273562Smarcel    } employees[] = {
36273562Smarcel	{ "Jim", "������������", "������������������ ������", 431, 90 },
37273562Smarcel	{ "Terry", "<one", "���������� ������������ ���������������������� ������ Jones", 660, 90 },
38273562Smarcel	{ "Leslie", "Les", "Patterson", 341,60 },
39273562Smarcel	{ "Ashley", "Ash", "Meter & Smith", 1440, 40 },
40273562Smarcel	{ "0123456789", "0123456789", "012345678901234567890", 1440, 40 },
41273562Smarcel	{ "������������", "������������������", "������������������������������������", 123, 90 },
42273562Smarcel	{ NULL, NULL }
43273562Smarcel    }, *ep = employees;
44273562Smarcel    int rc;
45273562Smarcel
46273562Smarcel    argc = xo_parse_args(argc, argv);
47273562Smarcel    if (argc < 0)
48273562Smarcel	return 1;
49273562Smarcel
50273562Smarcel    xo_set_info(NULL, info, info_count);
51273562Smarcel    xo_set_flags(NULL, XOF_COLUMNS);
52273562Smarcel
53273562Smarcel    xo_open_container("employees");
54273562Smarcel
55274405Smarcel    xo_open_list("test");
56274405Smarcel    xo_open_instance("test");
57274405Smarcel    xo_emit("{ek:filename/%s}", NULL);
58274405Smarcel    xo_close_instance("test");
59274405Smarcel    xo_close_list("test");
60274405Smarcel
61273562Smarcel    rc = xo_emit("���������� ������������ ���������������������� ������ {:v1/%s}, {:v2/%s}\n",
62273562Smarcel	    "���������������������", "��� ������������� ��������������������");
63273562Smarcel    rc = xo_emit("{:columns/%d}\n", rc);
64273562Smarcel    xo_emit("{:columns/%d}\n", rc);
65273562Smarcel
66273562Smarcel    rc = xo_emit("������������������ {:v1/%s} {:v2/%s}\n",
67273562Smarcel	    "������������������ ��������������������� ���������������������������������",
68273562Smarcel	    "Unicode-������ ��������������� ������������������������������������");
69273562Smarcel    xo_emit("{:columns/%d}\n", rc);
70273562Smarcel
71273562Smarcel
72273562Smarcel    rc = xo_emit("{T:First Name/%-25s}{T:Last Name/%-14s}"
73273562Smarcel	    "{T:/%-12s}{T:Time (%)}\n", "Department");
74273562Smarcel    xo_emit("{:columns/%d}\n", rc);
75277353Smarcel
76277353Smarcel    xo_open_list("employee");
77273562Smarcel    for ( ; ep->e_first; ep++) {
78273562Smarcel	xo_open_instance("employee");
79273562Smarcel	rc = xo_emit("{[:-25}{:first-name/%s} ({:nic-name/\"%s\"}){]:}"
80273562Smarcel		"{:last-name/%-14..14s/%s}"
81273562Smarcel		"{:department/%8u/%u}{:percent-time/%8u/%u}\n",
82273562Smarcel		ep->e_first, ep->e_nic, ep->e_last, ep->e_dept, ep->e_percent);
83273562Smarcel	xo_emit("{:columns/%d}\n", rc);
84273562Smarcel	if (ep->e_percent > 50) {
85273562Smarcel	    xo_attr("full-time", "%s", "honest & for true");
86273562Smarcel	    xo_emit("{e:benefits/%s}", "full");
87273562Smarcel	}
88273562Smarcel	xo_close_instance("employee");
89273562Smarcel    }
90273562Smarcel
91273562Smarcel    xo_close_list("employee");
92273562Smarcel    xo_close_container("employees");
93273562Smarcel
94273562Smarcel    xo_finish();
95273562Smarcel
96273562Smarcel    return 0;
97273562Smarcel}
98