test_05.c revision 303975
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#include <wchar.h> 15 16#include "xo.h" 17#include "xo_config.h" 18 19#ifdef LIBXO_WCWIDTH 20#include "xo_wcwidth.h" 21#else /* LIBXO_WCWIDTH */ 22#define xo_wcwidth(_x) wcwidth(_x) 23#endif /* LIBXO_WCWIDTH */ 24 25xo_info_t info[] = { 26 { "employee", "object", "Employee data" }, 27 { "first-name", "string", "First name of employee" }, 28 { "last-name", "string", "Last name of employee" }, 29 { "department", "number", "Department number" }, 30 { "percent-time", "number", "Percentage of full & part time (%)" }, 31}; 32int info_count = (sizeof(info) / sizeof(info[0])); 33 34int 35main (int argc, char **argv) 36{ 37 struct employee { 38 const char *e_first; 39 const char *e_nic; 40 const char *e_last; 41 unsigned e_dept; 42 unsigned e_percent; 43 } employees[] = { 44 { "Jim", "������������", "������������������ ������", 431, 90 }, 45 { "Terry", "<one", "���������� ������������ ���������������������� ������ Jones", 660, 90 }, 46 { "Leslie", "Les", "Patterson", 341,60 }, 47 { "Ashley", "Ash", "Meter & Smith", 1440, 40 }, 48 { "0123456789", "0123456789", "012345678901234567890", 1440, 40 }, 49 { "������������", "������������������", "������������������������������������", 123, 90 }, 50 { "������������������������������", "Mick", 51 "���������������������������������������������������", 110, 20 }, 52 { NULL, NULL } 53 }, *ep = employees; 54 int rc, i; 55 56 argc = xo_parse_args(argc, argv); 57 if (argc < 0) 58 return 1; 59 60 xo_set_info(NULL, info, info_count); 61 xo_set_flags(NULL, XOF_COLUMNS); 62 63 xo_open_container("indian-languages"); 64 65 xo_emit("{T:Sample text}\n"); 66 xo_emit("This sample text was taken from the Punjabi Wikipedia " 67 "article on Lahore and transliterated into the Latin script.\n"); 68 69 xo_emit("{T:Gurmukhi:}\n"); 70 xo_emit("{:gurmukhi}\n", 71 "������������ ��������������������������� ��������������� ������ ��������������������� ������ ��� ��������� ��������������� ������ ��������� ��������������� ��������� ������������ ������������ ������������ ������ ��������� ������������ ��������������� ������ ��� ������������ ������������������������ ������ ���������������, ��������������� ������ ������������������ ������ ������������ ������ ��������� ������ ������ ��������������� ������������������������ ������ ��������� ������ ������������ ��������������� ������ ��� ������������ ������������-���-������������ ������ ������������ ������ ������������ ������ ������ ������������ ��������� ��������������� ��������� ������������ ������ ������������ ������ ���"); 72 73 74 xo_emit("{T:Shahmukhi:}\n"); 75 xo_emit("{:shahmukhi}\n", 76 "�������� ���������������� ���������� ���� �������������������� ������ ������ �������� ���� ������ ���������� ������ ������ �������� �������� ������ ������ ������ ������ ������ �������� �������������� ���� ������������ ���������� ���� ������������ ���� ������ ���� ���� ���� ������ ������������ �������������� ���� ���� ���� �������� ���������� ������ �������� ���������� �������� ���� ���������� ���� �������� ���� �������� ������ �������� ���� �������� ���� �������� ���� ��"); 77 78 xo_emit("{T:Transliteration}:\n"); 79 xo_emit("{:tranliteration}\n", 80 "lahor p��kist��n panj��b d�� d��rul hak��mat ��. l��k gi���t�� d�� n����� kar��c�� t����� b��ad lahor d��j�� sab t����� va�������� shahr ��. lahor p��kist��n d�� si��s��, rahtal�� t�� pa��������� d�� g������� �� t�� is la�� ihn����� p��kist��n d�� dil v�� keh�� j��nd�� ��. lahor dari���� r��v�� d�� kan����� t�� vasd�� ��. isd�� l��k gi���t�� ikk kar����� d�� n������� ��."); 81 82 xo_close_container("indian-languages"); 83 84 xo_open_container("employees"); 85 86 wchar_t wc[] = { L'���', L'���', L'���', L'���', 0x17D2, L'���', 0 }; 87 for (i = 0; wc[i]; i++) 88 xo_emit("Wide char: {lq:wc/%lc - %#lx - %d}\n", 89 wc[i], (unsigned long) wc[i], xo_wcwidth(wc[i])); 90 91 wchar_t msg[] = { L'1', 0x034f, L'2', 0x20dd, 0 }; 92 for (i = 0; msg[i]; i++) 93 xo_emit("Wide char: {lq:wc/%lc - %#lx - %d}\n", 94 msg[i], (unsigned long) msg[i], xo_wcwidth((int) msg[i])); 95 xo_emit("Cool: [{:fancy/%ls}]\n", msg); 96 97 xo_emit("���������� ������������ ���������������������� ������ {:v1/%s}, {:v2/%s}\n", 98 "���������������������", "��� ������������� ��������������������"); 99 100 rc = xo_emit("������������������ {:v1/%s} {:v2/%s}\n", 101 "������������������ ��������������������� ���������������������������������", 102 "Unicode-������ ��������������� ������������������������������������"); 103 xo_emit("{Twc:Width}{:width/%d}\n", rc); 104 105 /* Okay, Sinhala is uber cool ... */ 106 rc = xo_emit("[{:sinhala}]\n", "���������������"); 107 xo_emit("{Twc:Width}{:width/%d}\n", rc); 108 109 rc = xo_emit("[{:sinhala}]\n", "���"); 110 xo_emit("{Twc:Width}{:width/%d}\n", rc); 111 112 rc = xo_emit("[{:sinhala/%-4..4s/%s}]\n", "������������������������������"); 113 xo_emit("{Twc:Width}{:width/%d}\n", rc); 114 115 xo_emit("[{:not-sinhala/%-4..4s/%s}]\n", "123456"); 116 117 rc = xo_emit("[{:tag/%s}]\n", "������������"); 118 xo_emit("{Twc:Width}{:width/%d}\n", rc); 119 120 xo_open_list("employee"); 121 122 xo_emit("{T:First Name/%-25s}{T:Last Name/%-14s}" 123 "{T:/%-12s}{T:Time (%)}\n", "Department"); 124 for ( ; ep->e_first; ep++) { 125 xo_open_instance("employee"); 126 xo_emit("{[:-25}{:first-name/%s} ({:nic-name/\"%s\"}){]:}" 127 "{:last-name/%-14..14s/%s}" 128 "{:department/%8u}{:percent-time/%8u}\n", 129 ep->e_first, ep->e_nic, ep->e_last, ep->e_dept, ep->e_percent); 130 if (ep->e_percent > 50) { 131 xo_attr("full-time", "%s", "honest & for true"); 132 xo_emit("{e:benefits/%s}", "full"); 133 } 134 xo_close_instance("employee"); 135 } 136 137 xo_close_list("employee"); 138 xo_close_container("employees"); 139 140 xo_finish(); 141 142 return 0; 143} 144