Path: blob/main/contrib/libxo/tests/core/test_07.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{ "percent-time", "number", "Percentage of full & part time (%)" },22};23int info_count = (sizeof(info) / sizeof(info[0]));2425int26main (int argc, char **argv)27{28struct employee {29const char *e_first;30const char *e_nic;31const char *e_last;32unsigned e_dept;33unsigned e_percent;34} employees[] = {35{ "Jim", "რეგტ", "გთხოვთ ახ", 431, 90 },36{ "Terry", "<one", "Οὐχὶ ταὐτὰ παρίσταταί μοι Jones", 660, 90 },37{ "Leslie", "Les", "Patterson", 341,60 },38{ "Ashley", "Ash", "Meter & Smith", 1440, 40 },39{ "0123456789", "0123456789", "012345678901234567890", 1440, 40 },40{ "ახლა", "გაიარო", "საერთაშორისო", 123, 90 },41{ NULL, NULL }42}, *ep = employees;43int rc;4445argc = xo_parse_args(argc, argv);46if (argc < 0)47return 1;4849xo_set_info(NULL, info, info_count);50xo_set_flags(NULL, XOF_COLUMNS);5152xo_open_container("employees");5354xo_open_list("test");55xo_open_instance("test");56xo_emit("{ek:filename/%s}", NULL);57xo_close_instance("test");58xo_close_list("test");5960rc = xo_emit("Οὐχὶ ταὐτὰ παρίσταταί μοι {:v1/%s}, {:v2/%s}\n",61"γιγνώσκειν", "ὦ ἄνδρες ᾿Αθηναῖοι");62rc = xo_emit("{:columns/%d}\n", rc);63xo_emit("{:columns/%d}\n", rc);6465rc = xo_emit("გთხოვთ {:v1/%s} {:v2/%s}\n",66"ახლავე გაიაროთ რეგისტრაცია",67"Unicode-ის მეათე საერთაშორისო");68xo_emit("{:columns/%d}\n", rc);697071rc = xo_emit("{T:First Name/%-25s}{T:Last Name/%-14s}"72"{T:/%-12s}{T:Time (%)}\n", "Department");73xo_emit("{:columns/%d}\n", rc);7475xo_open_list("employee");76for ( ; ep->e_first; ep++) {77xo_open_instance("employee");78rc = xo_emit("{[:-25}{:first-name/%s} ({:nic-name/\"%s\"}){]:}"79"{:last-name/%-14..14s/%s}"80"{:department/%8u/%u}{:percent-time/%8u/%u}\n",81ep->e_first, ep->e_nic, ep->e_last, ep->e_dept, ep->e_percent);82xo_emit("{:columns/%d}\n", rc);83if (ep->e_percent > 50) {84xo_attr("full-time", "%s", "honest & for true");85xo_emit("{e:benefits/%s}", "full");86}87xo_close_instance("employee");88}8990xo_close_list("employee");91xo_close_container("employees");9293xo_finish();9495return 0;96}979899