Path: blob/main/contrib/libxo/tests/core/test_06.c
39537 views
/*1* Copyright (c) 2014, Juniper Networks, Inc.2* All rights reserved.3* This SOFTWARE is licensed under the LICENSE provided in the4* ../Copyright file. By downloading, installing, copying, or otherwise5* using the SOFTWARE, you agree to be bound by the terms of that6* LICENSE.7* Phil Shafer, July 20148*/910#include <stdio.h>11#include <stdlib.h>12#include <string.h>1314#include "xo.h"1516xo_info_t info[] = {17{ "employee", "object", "Employee data" },18{ "first-name", "string", "First name of employee" },19{ "last-name", "string", "Last name of employee" },20{ "department", "number", "Department number" },21};22int info_count = (sizeof(info) / sizeof(info[0]));2324int25main (int argc, char **argv)26{27struct employee {28const char *e_first;29const char *e_last;30unsigned e_dept;31} employees[] = {32{ "Terry", "Jones", 660 },33{ "Leslie", "Patterson", 341 },34{ "Ashley", "Smith", 1440 },35{ NULL, NULL }36}, *ep = employees;3738argc = xo_parse_args(argc, argv);39if (argc < 0)40return 1;4142xo_set_info(NULL, info, info_count);4344xo_set_flags(NULL, XOF_DTRT);4546xo_open_container("employees");47xo_open_list("employee");4849for ( ; ep->e_first; ep++) {50xo_open_instance("employee");51xo_emit("{:first-name} {:last-name} works in dept #{:department/%u}\n",52ep->e_first, ep->e_last, ep->e_dept);53xo_close_instance_d();54}5556xo_close_list_d();57xo_close_container_d();5859xo_finish();6061return 0;62}636465