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 { "percent-time", "number", "Percentage of full & part time (%)" }, 23 }; 24 int info_count = (sizeof(info) / sizeof(info[0])); 25 26 int 27 main (int argc, char **argv) 28 { 29 struct employee { 30 const char *e_first; 31 const char *e_nic; 32 const char *e_last; 33 unsigned e_dept; 34 unsigned e_percent; 35 } employees[] = { 36 { "Jim", "რეგტ", "გთხოვთ ახ", 431, 90 }, 37 { "Terry", "<one", "Οὐχὶ ταὐτὰ παρίσταταί μοι Jones", 660, 90 }, 38 { "Leslie", "Les", "Patterson", 341,60 }, 39 { "Ashley", "Ash", "Meter & Smith", 1440, 40 }, 40 { "0123456789", "0123456789", "012345678901234567890", 1440, 40 }, 41 { "ახლა", "გაიარო", "საერთაშორისო", 123, 90 }, 42 { "෴ණ්ණ෴෴ණ්ණ෴", "Mick", 43 "෴ණ්ණ෴෴ණ්ණ෴෴ණ්ණ෴෴෴", 110, 20 }, 44 { NULL, NULL } 45 }, *ep = employees; 46 int rc; 47 48 argc = xo_parse_args(argc, argv); 49 if (argc < 0) 50 return 1; 51 52 xo_set_info(NULL, info, info_count); 53 xo_set_flags(NULL, XOF_COLUMNS); 54 55 xo_open_container("employees"); 56 57 xo_emit("Οὐχὶ ταὐτὰ παρίσταταί μοι {:v1/%s}, {:v2/%s}\n", 58 "γιγνώσκειν", "ὦ ἄνδρες ᾿Αθηναῖοι"); 59 60 rc = xo_emit("გთხოვთ {:v1/%s} {:v2/%s}\n", 61 "ახლავე გაიაროთ რეგისტრაცია", 62 "Unicode-ის მეათე საერთაშორისო"); 63 xo_emit("{Twc:Width}{:width/%d}\n", rc); 64 65 /* Okay, Sinhala is uber cool ... */ 66 rc = xo_emit("[{:sinhala}]\n", "෴ණ්ණ෴"); 67 xo_emit("{Twc:Width}{:width/%d}\n", rc); 68 rc = xo_emit("[{:sinhala}]\n", "෴"); 69 xo_emit("{Twc:Width}{:width/%d}\n", rc); 70 rc = xo_emit("[{:sinhala/%-4..4s/%s}]\n", "෴ණ්ණ෴෴ණ්ණ෴"); 71 xo_emit("[{:not-sinhala/%-4..4s/%s}]\n", "123456"); 72 rc = xo_emit("[{:tag/%s}]\n", "ර්ඝ"); 73 xo_emit("{Twc:Width}{:width/%d}\n", rc); 74 75 xo_open_list("employee"); 76 77 xo_emit("{T:First Name/%-25s}{T:Last Name/%-14s}" 78 "{T:/%-12s}{T:Time (%)}\n", "Department"); 79 for ( ; ep->e_first; ep++) { 80 xo_open_instance("employee"); 81 xo_emit("{[:-25}{:first-name/%s} ({:nic-name/\"%s\"}){]:}" 82 "{:last-name/%-14..14s/%s}" 83 "{:department/%8u/%u}{:percent-time/%8u/%u}\n", 84 ep->e_first, ep->e_nic, ep->e_last, ep->e_dept, ep->e_percent); 85 if (ep->e_percent > 50) { 86 xo_attr("full-time", "%s", "honest & for true"); 87 xo_emit("{e:benefits/%s}", "full"); 88 } 89 xo_close_instance("employee"); 90 } 91 92 xo_close_list("employee"); 93 xo_close_container("employees"); 94 95 xo_finish(); 96 97 return 0; 98 } 99