Path: blob/main/contrib/libxo/tests/gettext/gt_01.c
39536 views
/*1* Copyright (c) 2015, 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, June 20158*/910#include <stdio.h>11#include <stdlib.h>12#include <string.h>13#include <unistd.h>14#include <errno.h>15#include <ctype.h>16#include <time.h>17#include <sys/time.h>18#include <sys/param.h>19#include <locale.h>20#include <libintl.h>2122#include "xo.h"23#include "xo_encoder.h"2425int26main (int argc, char **argv)27{28static char domainname[] = "gt_01";29static char path[MAXPATHLEN];30const char *tzone = "EST";31const char *lang = "pig_latin";3233argc = xo_parse_args(argc, argv);34if (argc < 0)35return 1;3637for (argc = 1; argv[argc]; argc++) {38if (xo_streq(argv[argc], "tz"))39tzone = argv[++argc];40else if (xo_streq(argv[argc], "lang"))41lang = argv[++argc];42else if (xo_streq(argv[argc], "po"))43strlcpy(path, argv[++argc], sizeof(path));44}4546setenv("LANG", lang, 1);47setenv("TZ", tzone, 1);4849if (path[0] == 0) {50getcwd(path, sizeof(path));51strlcat(path, "/po", sizeof(path));52}5354setlocale(LC_ALL, "");55bindtextdomain(domainname, path);56bindtextdomain("ldns", path);57bindtextdomain("strerror", path);58textdomain(domainname);59tzset();6061xo_open_container("top");6263xo_emit("{G:}Your {qg:adjective} {g:noun} is {g:verb} {qg:owner} {g:target}\n",64"flaming", "sword", "burning", "my", "couch");6566xo_emit("{G:}The {qg:adjective} {g:noun} was {g:verb} {qg:owner} {g:target}\n",67"flaming", "sword", "burning", "my", "couch");686970int i;71for (i = 0; i < 5; i++)72xo_emit("{lw:bytes/%d}{Ngp:byte,bytes}\n", i);7374xo_emit("{G:}{L:total} {:total/%u}\n", 1234);7576xo_emit("{G:ldns}Received {:received/%zu} {Ngp:byte,bytes} "77"from {:from/%s}#{:port/%d} in {:time/%d} ms\n",78(size_t) 1234, "foop", 4321, 32);7980xo_emit("{G:}Received {:received/%zu} {Ngp:byte,bytes} "81"from {:from/%s}#{:port/%d} in {:time/%d} ms\n",82(size_t) 1234, "foop", 4321, 32);8384xo_emit("{G:/%s}Received {:received/%zu} {Ngp:byte,bytes} "85"from {:from/%s}#{:port/%d} in {:time/%d} ms\n",86"ldns", (size_t) 1234, "foop", 4321, 32);8788struct timeval tv;89tv.tv_sec = 1435085229;90tv.tv_usec = 123456;9192struct tm tm;93(void) gmtime_r(&tv.tv_sec, &tm);9495char date[64];96strftime(date, sizeof(date), "%+", &tm);9798xo_emit("{G:}Only {:marzlevanes/%d} {Ngp:marzlevane,marzlevanes} "99"are functioning correctly\n", 3);100101xo_emit("{G:}Version {:version} {:date}\n", "1.2.3", date);102103errno = EACCES;104xo_emit_warn("{G:}Unable to {g:verb/objectulate} forward velociping");105xo_emit_warn("{G:}{g:style/automatic} synchronization of {g:type/cardinal} "106"{g:target/grammeters} failed");107xo_emit("{G:}{Lwcg:hydrocoptic marzlevanes}{:marzlevanes/%d}\n", 6);108109xo_emit("{G:}{Lwcg:Windings}{g:windings}\n", "lotus-o-delta");110111xo_close_container("top");112xo_finish();113114return 0;115}116117118