Path: blob/main/contrib/libxo/tests/core/test_05.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>13#include <wchar.h>1415#include "xo.h"16#include "xo_config.h"1718#ifdef LIBXO_WCWIDTH19#include "xo_wcwidth.h"20#else /* LIBXO_WCWIDTH */21#define xo_wcwidth(_x) wcwidth(_x)22#endif /* LIBXO_WCWIDTH */2324xo_info_t info[] = {25{ "employee", "object", "Employee data" },26{ "first-name", "string", "First name of employee" },27{ "last-name", "string", "Last name of employee" },28{ "department", "number", "Department number" },29{ "percent-time", "number", "Percentage of full & part time (%)" },30};31int info_count = (sizeof(info) / sizeof(info[0]));3233int34main (int argc, char **argv)35{36struct employee {37const char *e_first;38const char *e_nic;39const char *e_last;40unsigned e_dept;41unsigned e_percent;42} employees[] = {43{ "Jim", "რეგტ", "გთხოვთ ახ", 431, 90 },44{ "Terry", "<one", "Οὐχὶ ταὐτὰ παρίσταταί μοι Jones", 660, 90 },45{ "Leslie", "Les", "Patterson", 341,60 },46{ "Ashley", "Ash", "Meter & Smith", 1440, 40 },47{ "0123456789", "0123456789", "012345678901234567890", 1440, 40 },48{ "ახლა", "გაიარო", "საერთაშორისო", 123, 90 },49{ "෴ණ්ණ෴෴ණ්ණ෴", "Mick",50"෴ණ්ණ෴෴ණ්ණ෴෴ණ්ණ෴෴෴", 110, 20 },51{ NULL, NULL }52}, *ep = employees;53int rc, i;5455argc = xo_parse_args(argc, argv);56if (argc < 0)57return 1;5859xo_set_info(NULL, info, info_count);60xo_set_flags(NULL, XOF_COLUMNS);6162xo_open_container("indian-languages");6364xo_emit("{T:Sample text}\n");65xo_emit("This sample text was taken from the Punjabi Wikipedia "66"article on Lahore and transliterated into the Latin script.\n");6768xo_emit("{T:Gurmukhi:}\n");69xo_emit("{:gurmukhi}\n",70"ਲਹੌਰ ਪਾਕਿਸਤਾਨੀ ਪੰਜਾਬ ਦੀ ਰਾਜਧਾਨੀ ਹੈ । ਲੋਕ ਗਿਣਤੀ ਦੇ ਨਾਲ ਕਰਾਚੀ ਤੋਂ ਬਾਅਦ ਲਹੌਰ ਦੂਜਾ ਸਭ ਤੋਂ ਵੱਡਾ ਸ਼ਹਿਰ ਹੈ । ਲਹੌਰ ਪਾਕਿਸਤਾਨ ਦਾ ਸਿਆਸੀ, ਰਹਤਲੀ ਤੇ ਪੜ੍ਹਾਈ ਦਾ ਗੜ੍ਹ ਹੈ ਅਤੇ ਇਸ ਲਈ ਇਹਨੂੰ ਪਾਕਿਸਤਾਨ ਦਾ ਦਿਲ ਵੀ ਕਿਹਾ ਜਾਂਦਾ ਹੈ । ਲਹੌਰ ਦਰਿਆ-ਏ-ਰਾਵੀ ਦੇ ਕੰਢੇ ਤੇ ਵਸਦਾ ਹੈ ਤੇ ਇਸਦੀ ਲੋਕ ਗਿਣਤੀ ਇੱਕ ਕਰੋੜ ਦੇ ਨੇੜੇ ਹੈ ।");717273xo_emit("{T:Shahmukhi:}\n");74xo_emit("{:shahmukhi}\n",75"لہور پاکستانی پنجاب دا دارالحکومت اے۔ لوک گنتی دے نال کراچی توں بعد لہور دوجا سبھ توں وڈا شہر اے۔ لہور پاکستان دا سیاسی، رہتلی تے پڑھائی دا گڑھ اے تے اس لئی ایھنوں پاکستان دا دل وی کیھا جاندا اے۔ لہور دریاۓ راوی دے کنڈھے تے وسدا اے اسدی لوک گنتی اک کروڑ دے نیڑے اے ۔");7677xo_emit("{T:Transliteration}:\n");78xo_emit("{:tranliteration}\n",79"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ēṛē ē.");8081xo_close_container("indian-languages");8283xo_open_container("employees");8485wchar_t wc[] = { L'෴', L'ණ', L'්', L'ණ', 0x17D2, L'෴', 0 };86for (i = 0; wc[i]; i++)87xo_emit("Wide char: {lq:wc/%lc - %#lx - %d}\n",88wc[i], (unsigned long) wc[i], xo_wcwidth(wc[i]));8990wchar_t msg[] = { L'1', 0x034f, L'2', 0x20dd, 0 };91for (i = 0; msg[i]; i++)92xo_emit("Wide char: {lq:wc/%lc - %#lx - %d}\n",93msg[i], (unsigned long) msg[i], xo_wcwidth((int) msg[i]));94xo_emit("Cool: [{:fancy/%ls}]\n", msg);9596xo_emit("Οὐχὶ ταὐτὰ παρίσταταί μοι {:v1/%s}, {:v2/%s}\n",97"γιγνώσκειν", "ὦ ἄνδρες ᾿Αθηναῖοι");9899rc = xo_emit("გთხოვთ {:v1/%s} {:v2/%s}\n",100"ახლავე გაიაროთ რეგისტრაცია",101"Unicode-ის მეათე საერთაშორისო");102xo_emit("{Twc:Width}{:width/%d}\n", rc);103104/* Okay, Sinhala is uber cool ... */105rc = xo_emit("[{:sinhala}]\n", "෴ණ්ණ෴");106xo_emit("{Twc:Width}{:width/%d}\n", rc);107108rc = xo_emit("[{:sinhala}]\n", "෴");109xo_emit("{Twc:Width}{:width/%d}\n", rc);110111rc = xo_emit("[{:sinhala/%-4..4s/%s}]\n", "෴ණ්ණ෴෴ණ්ණ෴");112xo_emit("{Twc:Width}{:width/%d}\n", rc);113114xo_emit("[{:not-sinhala/%-4..4s/%s}]\n", "123456");115116rc = xo_emit("[{:tag/%s}]\n", "ර්ඝ");117xo_emit("{Twc:Width}{:width/%d}\n", rc);118119xo_open_list("employee");120121xo_emit("{T:First Name/%-25s}{T:Last Name/%-14s}"122"{T:/%-12s}{T:Time (%)}\n", "Department");123for ( ; ep->e_first; ep++) {124xo_open_instance("employee");125xo_emit("{[:-25}{:first-name/%s} ({:nic-name/\"%s\"}){]:}"126"{:last-name/%-14..14s/%s}"127"{:department/%8u}{:percent-time/%8u}\n",128ep->e_first, ep->e_nic, ep->e_last, ep->e_dept, ep->e_percent);129if (ep->e_percent > 50) {130xo_attr("full-time", "%s", "honest & for true");131xo_emit("{e:benefits/%s}", "full");132}133xo_close_instance("employee");134}135136xo_close_list("employee");137xo_close_container("employees");138139xo_finish();140141return 0;142}143144145