10Sduke/*
20Sduke * Copyright (c) 2014, Juniper Networks, Inc.
30Sduke * All rights reserved.
412555Sdholmes * This SOFTWARE is licensed under the LICENSE provided in the
50Sduke * ../Copyright file. By downloading, installing, copying, or otherwise
60Sduke * using the SOFTWARE, you agree to be bound by the terms of that
70Sduke * LICENSE.
80Sduke * Phil Shafer, July 2014
90Sduke */
100Sduke
110Sduke#include <stdio.h>
120Sduke#include <stdlib.h>
130Sduke#include <string.h>
140Sduke#include <wchar.h>
150Sduke
160Sduke#include "xo.h"
170Sduke#include "xo_config.h"
180Sduke
190Sduke#ifdef LIBXO_WCWIDTH
200Sduke#include "xo_wcwidth.h"
211472Strims#else /* LIBXO_WCWIDTH */
221472Strims#define xo_wcwidth(_x) wcwidth(_x)
231472Strims#endif /* LIBXO_WCWIDTH */
240Sduke
250Sdukexo_info_t info[] = {
260Sduke    { "employee", "object", "Employee data" },
2712821Sihse    { "first-name", "string", "First name of employee" },
280Sduke    { "last-name", "string", "Last name of employee" },
2912821Sihse    { "department", "number", "Department number" },
3012821Sihse    { "percent-time", "number", "Percentage of full & part time (%)" },
3112821Sihse};
320Sdukeint info_count = (sizeof(info) / sizeof(info[0]));
330Sduke
340Sdukeint
350Sdukemain (int argc, char **argv)
360Sduke{
370Sduke    struct employee {
380Sduke	const char *e_first;
390Sduke	const char *e_nic;
400Sduke	const char *e_last;
410Sduke	unsigned e_dept;
420Sduke	unsigned e_percent;
430Sduke    } employees[] = {
4412821Sihse	{ "Jim", "������������", "������������������ ������", 431, 90 },
450Sduke	{ "Terry", "<one", "���������� ������������ ���������������������� ������ Jones", 660, 90 },
460Sduke	{ "Leslie", "Les", "Patterson", 341,60 },
470Sduke	{ "Ashley", "Ash", "Meter & Smith", 1440, 40 },
480Sduke	{ "0123456789", "0123456789", "012345678901234567890", 1440, 40 },
490Sduke	{ "������������", "������������������", "������������������������������������", 123, 90 },
5012821Sihse	{ "������������������������������", "Mick",
510Sduke	  "���������������������������������������������������", 110, 20 },
520Sduke	{ NULL, NULL }
530Sduke    }, *ep = employees;
540Sduke    int rc, i;
550Sduke
560Sduke    argc = xo_parse_args(argc, argv);
570Sduke    if (argc < 0)
580Sduke	return 1;
590Sduke
600Sduke    xo_set_info(NULL, info, info_count);
610Sduke    xo_set_flags(NULL, XOF_COLUMNS);
620Sduke
630Sduke    xo_open_container("indian-languages");
640Sduke
650Sduke    xo_emit("{T:Sample text}\n");
660Sduke    xo_emit("This sample text was taken from the Punjabi Wikipedia "
670Sduke	    "article on Lahore and transliterated into the Latin script.\n");
680Sduke
690Sduke    xo_emit("{T:Gurmukhi:}\n");
700Sduke    xo_emit("{:gurmukhi}\n",
710Sduke	    "������������ ��������������������������� ��������������� ������ ��������������������� ������ ��� ��������� ��������������� ������ ��������� ��������������� ��������� ������������ ������������ ������������ ������ ��������� ������������ ��������������� ������ ��� ������������ ������������������������ ������ ���������������, ��������������� ������ ������������������ ������ ������������ ������ ��������� ������ ������ ��������������� ������������������������ ������ ��������� ������ ������������ ��������������� ������ ��� ������������ ������������-���-������������ ������ ������������ ������ ������������ ������ ������ ������������ ��������� ��������������� ��������� ������������ ������ ������������ ������ ���");
720Sduke
730Sduke
740Sduke    xo_emit("{T:Shahmukhi:}\n");
750Sduke    xo_emit("{:shahmukhi}\n",
760Sduke	    "�������� ���������������� ���������� ���� �������������������� ������ ������ �������� ���� ������ ���������� ������ ������ �������� �������� ������ ������ ������ ������ ������ �������� �������������� ���� ������������ ���������� ���� ������������ ���� ������ ���� ���� ���� ������ ������������ �������������� ���� ���� ���� �������� ���������� ������ �������� ���������� �������� ���� ���������� ���� �������� ���� �������� ������ �������� ���� �������� ���� �������� ���� ��");
770Sduke
780Sduke    xo_emit("{T:Transliteration}:\n");
790Sduke    xo_emit("{:tranliteration}\n",
8012821Sihse	    "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������� ��.");
810Sduke
820Sduke    xo_close_container("indian-languages");
830Sduke
840Sduke    xo_open_container("employees");
850Sduke
860Sduke    wchar_t wc[] = { L'���', L'���', L'���', L'���', 0x17D2, L'���', 0 };
870Sduke    for (i = 0; wc[i]; i++)
880Sduke	xo_emit("Wide char: {lq:wc/%lc - %#lx - %d}\n",
890Sduke		wc[i], (unsigned long) wc[i], xo_wcwidth(wc[i]));
900Sduke
910Sduke    wchar_t msg[] = { L'1', 0x034f, L'2', 0x20dd, 0 };
920Sduke    for (i = 0; msg[i]; i++)
930Sduke	xo_emit("Wide char: {lq:wc/%lc - %#lx - %d}\n",
940Sduke		msg[i], (unsigned long) msg[i], xo_wcwidth((int) msg[i]));
950Sduke    xo_emit("Cool: [{:fancy/%ls}]\n", msg);
960Sduke
970Sduke    xo_emit("���������� ������������ ���������������������� ������ {:v1/%s}, {:v2/%s}\n",
980Sduke	    "���������������������", "��� ������������� ��������������������");
990Sduke
1000Sduke    rc = xo_emit("������������������ {:v1/%s} {:v2/%s}\n",
1010Sduke	    "������������������ ��������������������� ���������������������������������",
1020Sduke	    "Unicode-������ ��������������� ������������������������������������");
1030Sduke    xo_emit("{Twc:Width}{:width/%d}\n", rc);
1040Sduke
1050Sduke    /* Okay, Sinhala is uber cool ... */
1060Sduke    rc = xo_emit("[{:sinhala}]\n", "���������������");
1070Sduke    xo_emit("{Twc:Width}{:width/%d}\n", rc);
1080Sduke
1090Sduke    rc = xo_emit("[{:sinhala}]\n", "���");
11012821Sihse    xo_emit("{Twc:Width}{:width/%d}\n", rc);
1110Sduke
1120Sduke    rc = xo_emit("[{:sinhala/%-4..4s/%s}]\n", "������������������������������");
1130Sduke    xo_emit("{Twc:Width}{:width/%d}\n", rc);
1140Sduke
1150Sduke    xo_emit("[{:not-sinhala/%-4..4s/%s}]\n", "123456");
1160Sduke
1170Sduke    rc = xo_emit("[{:tag/%s}]\n", "������������");
1180Sduke    xo_emit("{Twc:Width}{:width/%d}\n", rc);
1190Sduke
1200Sduke    xo_open_list("employee");
1210Sduke
1220Sduke    xo_emit("{T:First Name/%-25s}{T:Last Name/%-14s}"
1230Sduke	    "{T:/%-12s}{T:Time (%)}\n", "Department");
1240Sduke    for ( ; ep->e_first; ep++) {
1250Sduke	xo_open_instance("employee");
1260Sduke	xo_emit("{[:-25}{:first-name/%s} ({:nic-name/\"%s\"}){]:}"
1270Sduke		"{:last-name/%-14..14s/%s}"
1280Sduke		"{:department/%8u}{:percent-time/%8u}\n",
1290Sduke		ep->e_first, ep->e_nic, ep->e_last, ep->e_dept, ep->e_percent);
1300Sduke	if (ep->e_percent > 50) {
1310Sduke	    xo_attr("full-time", "%s", "honest & for true");
1320Sduke	    xo_emit("{e:benefits/%s}", "full");
1330Sduke	}
1340Sduke	xo_close_instance("employee");
1350Sduke    }
1360Sduke
1370Sduke    xo_close_list("employee");
1380Sduke    xo_close_container("employees");
1390Sduke
1400Sduke    xo_finish();
1410Sduke
1420Sduke    return 0;
1430Sduke}
1440Sduke