Fix i18n_unumber_create usage
[platform/core/api/base-utils.git] / i18ninfo / i18ninfo.cpp
1 #define _GNU_SOURCE 1
2 #include <time.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <stddef.h>
6 #include <string.h>
7 #include <assert.h>
8 #include "i18ninfo_argp.h"
9
10 #include <utils_i18n.h>
11
12 #define DEBUG_FLAG 0
13 static int ASCIIDOC_FLAG = 0;
14
15 #define BUF_SIZE 1000
16 #define MS_TO_MIN 60000
17 #define MS_TO_HOUR 3600000
18
19 #define PRINT_ERROR_LOG(func_name, error_code) ({ fprintf(stderr, "\033[0;31m%s failed! Error: %s [code: %d] \033[0m\n", \
20                         func_name, get_error_message(error_code), error_code); })
21
22 #define PRINT_DEBUG_LOG(fmt, arg...) ((DEBUG_FLAG) ? fprintf(stdout, "\033[0;32m" fmt "\033[1;32m \033[0m", ##arg) : 0 )
23
24 #define CHECK_ERROR(fun_name, error_code) if (error_code != 0) { \
25                 PRINT_ERROR_LOG(fun_name, error_code); \
26         }
27
28 #define COPY_STR(dst, src, dst_len) do {            \
29                         strncpy((dst), (src), (dst_len + 1));       \
30                         (dst)[(dst_len)] = '\0';            \
31 } while (0)
32
33 #define PRINT_ASCIIDOC_LOG(fmt) if (ASCIIDOC_FLAG) printf(fmt)
34
35 #define INT_ADD_RANGE_OVERFLOW(a, b) \
36         ((b) < 0                          \
37          ? (a) < INT_MIN - (b)         \
38          : INT_MAX - (b) < (a))
39
40
41 const char *default_locale = I18N_ULOCALE_UK;
42
43 i18n_udate_format_style_e eTimeFormatStyle[] = {
44         I18N_UDATE_FULL,
45         I18N_UDATE_LONG,
46         I18N_UDATE_MEDIUM,
47         I18N_UDATE_SHORT,
48         I18N_UDATE_NONE
49 };
50
51 i18n_udate_format_style_e eDateFormatStyle[] = {
52         I18N_UDATE_FULL,
53         I18N_UDATE_LONG,
54         I18N_UDATE_MEDIUM,
55         I18N_UDATE_SHORT,
56         I18N_UDATE_RELATIVE,
57         I18N_UDATE_LONG_RELATIVE,
58         I18N_UDATE_MEDIUM_RELATIVE,
59         I18N_UDATE_SHORT_RELATIVE,
60         I18N_UDATE_NONE
61 };
62
63 typedef struct {
64         const char *display_name;
65         uint16_t option;
66 } reordering_option;
67
68 #define N_OPTIONS 5
69
70 static reordering_option reordering_options[N_OPTIONS] = {
71         {"I18N_UBIDI_KEEP_BASE_COMBINING", I18N_UBIDI_KEEP_BASE_COMBINING},
72         {"I18N_UBIDI_DO_MIRRORING", I18N_UBIDI_DO_MIRRORING},
73         {"I18N_UBIDI_INSERT_LRM_FOR_NUMERIC", I18N_UBIDI_INSERT_LRM_FOR_NUMERIC},
74         {"I18N_UBIDI_REMOVE_BIDI_CONTROLS", I18N_UBIDI_REMOVE_BIDI_CONTROLS},
75         {"I18N_UBIDI_OUTPUT_REVERSE", I18N_UBIDI_OUTPUT_REVERSE},
76 };
77
78 typedef struct {
79         const char *display_name;
80         i18n_ubidi_reordering_mode_e mode;
81 } reordering_mode;
82
83 #define N_MODES I18N_UBIDI_REORDER_COUNT
84
85 static reordering_mode reordering_modes[N_MODES] = {
86         {"I18N_UBIDI_REORDER_DEFAULT", I18N_UBIDI_REORDER_DEFAULT},
87         {"I18N_UBIDI_REORDER_NUMBERS_SPECIAL", I18N_UBIDI_REORDER_NUMBERS_SPECIAL},
88         {"I18N_UBIDI_REORDER_GROUP_NUMBERS_WITH_R", I18N_UBIDI_REORDER_GROUP_NUMBERS_WITH_R},
89         {"I18N_UBIDI_REORDER_RUNS_ONLY", I18N_UBIDI_REORDER_RUNS_ONLY},
90         {"I18N_UBIDI_REORDER_INVERSE_NUMBERS_AS_L", I18N_UBIDI_REORDER_INVERSE_NUMBERS_AS_L},
91         {"I18N_UBIDI_REORDER_INVERSE_LIKE_DIRECT", I18N_UBIDI_REORDER_INVERSE_LIKE_DIRECT},
92         {"I18N_UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL", I18N_UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL}
93 };
94
95 int n_date_enum_size = sizeof(eDateFormatStyle) / sizeof(eDateFormatStyle[0]);
96 int n_time_enum_size = sizeof(eTimeFormatStyle) / sizeof(eTimeFormatStyle[0]);
97
98 int n_enum_time_counter, n_enum_date_counter;
99 i18n_error_code_e error_code;
100
101
102 static void __get_available_locales();
103 static int __get_date_basic_format();
104 static int __get_date_and_time(char *input_time);
105 static int __get_number_format(const char *input_number);
106 static int __get_symbol();
107 static int __get_language_info();
108 static int __manage_string_iteration(char *custom_type);
109 static int __analyze_string(char *custom_string);
110 static int __get_timezone_info();
111 static int __get_tzdata_version();
112
113 char *__print_i18n_type_string(char *type, int num);
114
115 static void __get_available_locales()
116 {
117         const char *loc_list;
118         int32_t loc_count, i;
119
120         loc_count = i18n_ulocale_count_available();
121         if (loc_count == 0) {
122                 printf("empty\n");
123         } else if (loc_count < 0) {
124                 printf("wrong\n");
125         } else {
126                 PRINT_DEBUG_LOG("locale count : %d\n", loc_count);
127                 for (i = 0; i < loc_count; i++) {
128                         loc_list = i18n_ulocale_get_available(i);
129                         printf("%s\n", loc_list);
130                 }
131         }
132 }
133
134 char *__print_i18n_type_string(const char *type, int num)
135 {
136         char *str = (char*)calloc(300, sizeof(char));
137         PRINT_DEBUG_LOG("input type: %s, num: %d\n", type, num);
138         if (!strcmp(type, "time")) {
139                 switch (num) {
140                 case 0:
141                         COPY_STR(str, "I18N_UDATE_FULL", strlen("I18N_UDATE_FULL"));
142                         break;
143                 case 1:
144                         COPY_STR(str, "I18N_UDATE_LONG", strlen("I18N_UDATE_LONG"));
145                         break;
146                 case 2:
147                         COPY_STR(str, "I18N_UDATE_MEDIUM", strlen("I18N_UDATE_MEDIUM"));
148                         break;
149                 case 3:
150                         COPY_STR(str, "I18N_UDATE_SHORT", strlen("I18N_UDATE_SHORT"));
151                         break;
152                 case 4:
153                         COPY_STR(str, "I18N_UDATE_NONE", strlen("I18N_UDATE_NONE"));
154                         break;
155                 default:
156                         COPY_STR(str, "err", strlen("err"));
157                         break;
158                 }
159         } else if (!strcmp(type, "date")) {
160                 switch (num) {
161                 case 0:
162                         COPY_STR(str, "I18N_UDATE_FULL", strlen("I18N_UDATE_FULL"));
163                         break;
164                 case 1:
165                         COPY_STR(str, "I18N_UDATE_LONG", strlen("I18N_UDATE_LONG"));
166                         break;
167                 case 2:
168                         COPY_STR(str, "I18N_UDATE_MEDIUM", strlen("I18N_UDATE_MEDIUM"));
169                         break;
170                 case 3:
171                         COPY_STR(str, "I18N_UDATE_SHORT", strlen("I18N_UDATE_SHORT"));
172                         break;
173                 case 4:
174                         COPY_STR(str, "I18N_UDATE_RELATIVE", strlen("I18N_UDATE_RELATIVE"));
175                         break;
176                 case 5:
177                         COPY_STR(str, "I18N_UDATE_LONG_RELATIVE", strlen("I18N_UDATE_LONG_RELATIVE"));
178                         break;
179                 case 6:
180                         COPY_STR(str, "I18N_UDATE_MEDIUM_RELATIVE", strlen("I18N_UDATE_MEDIUM_RELATIVE"));
181                         break;
182                 case 7:
183                         COPY_STR(str, "I18N_UDATE_SHORT_RELATIVE", strlen("I18N_UDATE_SHORT_RELATIVE"));
184                         break;
185                 case 8:
186                         COPY_STR(str, "I18N_UDATE_NONE", strlen("I18N_UDATE_NONE"));
187                         break;
188                 default:
189                         COPY_STR(str, "err", strlen("err"));
190                         break;
191                 }
192         } else if (!strcmp(type, "number_format")) {
193                 switch (num) {
194                 case 1:
195                         COPY_STR(str, "I18N_UNUMBER_DECIMAL", strlen("I18N_UNUMBER_DECIMAL"));
196                         break;
197                 case 2:
198                         COPY_STR(str, "I18N_UNUMBER_CURRENCY", strlen("I18N_UNUMBER_CURRENCY"));
199                         break;
200                 case 3:
201                         COPY_STR(str, "I18N_UNUMBER_PERCENT", strlen("I18N_UNUMBER_PERCENT"));
202                         break;
203                 case 4:
204                         COPY_STR(str, "I18N_UNUMBER_SCIENTIFIC", strlen("I18N_UNUMBER_SCIENTIFIC"));
205                         break;
206                 case 5:
207                         COPY_STR(str, "I18N_UNUMBER_SPELLOUT", strlen("I18N_UNUMBER_SPELLOUT"));
208                         break;
209                 case 6:
210                         COPY_STR(str, "I18N_UNUMBER_ORDINAL", strlen("I18N_UNUMBER_ORDINAL"));
211                         break;
212                 case 7:
213                         COPY_STR(str, "I18N_UNUMBER_DURATION", strlen("I18N_UNUMBER_DURATION"));
214                         break;
215                 case 8:
216                         COPY_STR(str, "I18N_UNUMBER_NUMBERING_SYSTEM", strlen("I18N_UNUMBER_NUMBERING_SYSTEM"));
217                         break;
218                 case 9:
219                         COPY_STR(str, "I18N_UNUMBER_PATTERN_RULEBASED", strlen("I18N_UNUMBER_PATTERN_RULEBASED"));
220                         break;
221                 case 10:
222                         COPY_STR(str, "I18N_UNUMBER_CURRENCY_ISO", strlen("I18N_UNUMBER_CURRENCY_ISO"));
223                         break;
224                 case 11:
225                         COPY_STR(str, "I18N_UNUMBER_CURRENCY_PLURAL", strlen("I18N_UNUMBER_CURRENCY_PLURAL"));
226                         break;
227 #if (__TIZEN_VER >= 4)
228                 case 12:
229                         COPY_STR(str, "I18N_UNUMBER_CURRENCY_ACCOUNTING", strlen("I18N_UNUMBER_CURRENCY_ACCOUNTING"));
230                         break;
231                 case 13:
232                         COPY_STR(str, "I18N_UNUMBER_CASH_CURRENCY", strlen("I18N_UNUMBER_CASH_CURRENCY"));
233                         break;
234 #endif
235                 case 14:
236                         COPY_STR(str, "I18N_UNUMBER_FORMAT_STYLE_COUNT", strlen("I18N_UNUMBER_FORMAT_STYLE_COUNT"));
237                         break;
238                 default:
239                         COPY_STR(str, "err", strlen("err"));
240                         break;
241                 }
242         } else if (!strcmp(type, "symbol")) {
243                 switch (num) {
244                 case 1:
245                         COPY_STR(str, "I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL"));
246                         break;
247                 case 2:
248                         COPY_STR(str, "I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL"));
249                         break;
250                 case 3:
251                         COPY_STR(str, "I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL"));
252                         break;
253                 case 4:
254                         COPY_STR(str, "I18N_UNUMBER_PERCENT_SYMBOL", strlen("I18N_UNUMBER_PERCENT_SYMBOL"));
255                         break;
256                 case 5:
257                         COPY_STR(str, "I18N_UNUMBER_ZERO_DIGIT_SYMBOL", strlen("I18N_UNUMBER_ZERO_DIGIT_SYMBOL"));
258                         break;
259                 case 6:
260                         COPY_STR(str, "I18N_UNUMBER_DIGIT_SYMBOL", strlen("I18N_UNUMBER_DIGIT_SYMBOL"));
261                         break;
262                 case 7:
263                         COPY_STR(str, "I18N_UNUMBER_MINUS_SIGN_SYMBOL", strlen("I18N_UNUMBER_MINUS_SIGN_SYMBOL"));
264                         break;
265                 case 8:
266                         COPY_STR(str, "I18N_UNUMBER_PLUS_SIGN_SYMBOL", strlen("I18N_UNUMBER_PLUS_SIGN_SYMBOL"));
267                         break;
268                 case 9:
269                         COPY_STR(str, "I18N_UNUMBER_CURRENCY_SYMBOL", strlen("I18N_UNUMBER_CURRENCY_SYMBOL"));
270                         break;
271                 case 10:
272                         COPY_STR(str, "I18N_UNUMBER_INTL_CURRENCY_SYMBOL", strlen("I18N_UNUMBER_INTL_CURRENCY_SYMBOL"));
273                         break;
274                 case 11:
275                         COPY_STR(str, "I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL"));
276                         break;
277                 case 12:
278                         COPY_STR(str, "I18N_UNUMBER_EXPONENTIAL_SYMBOL", strlen("I18N_UNUMBER_EXPONENTIAL_SYMBOL"));
279                         break;
280                 case 13:
281                         COPY_STR(str, "I18N_UNUMBER_PERMILL_SYMBOL", strlen("I18N_UNUMBER_PERMILL_SYMBOL"));
282                         break;
283                 case 14:
284                         COPY_STR(str, "I18N_UNUMBER_PAD_ESCAPE_SYMBOL", strlen("I18N_UNUMBER_PAD_ESCAPE_SYMBOL"));
285                         break;
286                 case 15:
287                         COPY_STR(str, "I18N_UNUMBER_INFINITY_SYMBOL", strlen("I18N_UNUMBER_INFINITY_SYMBOL"));
288                         break;
289                 case 16:
290                         COPY_STR(str, "I18N_UNUMBER_NAN_SYMBOL", strlen("I18N_UNUMBER_NAN_SYMBOL"));
291                         break;
292                 case 17:
293                         COPY_STR(str, "I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL"));
294                         break;
295                 case 18:
296                         COPY_STR(str, "I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL"));
297                         break;
298                 case 19:
299                         COPY_STR(str, "I18N_UNUMBER_ONE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_ONE_DIGIT_SYMBOL"));
300                         break;
301                 case 20:
302                         COPY_STR(str, "I18N_UNUMBER_TWO_DIGIT_SYMBOL", strlen("I18N_UNUMBER_TWO_DIGIT_SYMBOL"));
303                         break;
304                 case 21:
305                         COPY_STR(str, "I18N_UNUMBER_THREE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_THREE_DIGIT_SYMBOL"));
306                         break;
307                 case 22:
308                         COPY_STR(str, "I18N_UNUMBER_FOUR_DIGIT_SYMBOL", strlen("I18N_UNUMBER_FOUR_DIGIT_SYMBOL"));
309                         break;
310                 case 23:
311                         COPY_STR(str, "I18N_UNUMBER_FIVE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_FIVE_DIGIT_SYMBOL"));
312                         break;
313                 case 24:
314                         COPY_STR(str, "I18N_UNUMBER_SIX_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SIX_DIGIT_SYMBOL"));
315                         break;
316                 case 25:
317                         COPY_STR(str, "I18N_UNUMBER_SEVEN_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SEVEN_DIGIT_SYMBOL"));
318                         break;
319                 case 26:
320                         COPY_STR(str, "I18N_UNUMBER_EIGHT_DIGIT_SYMBOL", strlen("I18N_UNUMBER_EIGHT_DIGIT_SYMBOL"));
321                         break;
322                 case 27:
323                         COPY_STR(str, "I18N_UNUMBER_NINE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_NINE_DIGIT_SYMBOL"));
324                         break;
325                 default:
326                         COPY_STR(str, "err", strlen("err"));
327                         break;
328                 }
329         } else if (!strcmp(type, "iter_type")) {
330                 switch (num) {
331                 case 0:
332                         COPY_STR(str, "I18N_UBRK_CHARACTER", strlen("I18N_UBRK_CHARACTER"));
333                         break;
334                 case 1:
335                         COPY_STR(str, "I18N_UBRK_WORD", strlen("I18N_UBRK_WORD"));
336                         break;
337                 case 2:
338                         COPY_STR(str, "I18N_UBRK_LINE", strlen("I18N_UBRK_LINE"));
339                         break;
340                 case 3:
341                         COPY_STR(str, "I18N_UBRK_SENTENCE", strlen("I18N_UBRK_SENTENCE"));
342                         break;
343                 default:
344                         COPY_STR(str, "err", strlen("err"));
345                         break;
346                 }
347         }
348         PRINT_DEBUG_LOG("return string: %s\n", str);
349         return str;
350 }
351
352 static char *_date_basic_format_convert(const char *input_pattern, int i, const char *type)
353 {
354         int ret = 0;
355         i18n_udate_format_h format_h = NULL;
356         i18n_uchar timezone[BUF_SIZE] = {0, };
357         i18n_ustring_copy_ua_n(timezone, default_locale, BUF_SIZE);
358         i18n_uchar pattern[BUF_SIZE] = {0, };
359         i18n_ustring_copy_ua_n(pattern, input_pattern, BUF_SIZE);
360         ret = i18n_udate_create(I18N_UDATE_PATTERN, I18N_UDATE_PATTERN, default_locale, timezone,  -1, pattern, -1, &format_h);
361         CHECK_ERROR("i18n_udate_create", ret);
362
363         i18n_udate date_now = 259200000;
364
365         if (!strcmp(type, "day")) {
366         date_now += i * 86400000;
367         } else if (!strcmp(type, "month")) {
368                 int k;
369                 for (k = 0; k < i; k++)
370                         date_now += 2678400000;
371         } else {
372                 i18n_ucalendar_get_now(&date_now);
373         }
374
375         i18n_uchar *result = (i18n_uchar *) malloc(BUF_SIZE * sizeof(i18n_uchar));
376         int date_len = 0;
377         ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len);
378         CHECK_ERROR("i18n_udate_format_date", ret);
379
380         char *s = (char *)malloc(BUF_SIZE * sizeof(char));
381         i18n_ustring_copy_au(s, result);
382         i18n_udate_destroy(format_h);
383         free(result);
384
385         PRINT_DEBUG_LOG("======%s\n", s);
386         return s;
387 }
388
389 static int __get_date_basic_format()
390 {
391         printf(" - To get basic date format\n");
392         printf("****************************************\n");
393
394         char *f_narrow, *f_short, *f_long, *s_narrow, *s_short, *s_long;
395         int i;
396
397         //Day - Formatting
398         printf(" Day - Formatting\n");
399         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
400         PRINT_ASCIIDOC_LOG("|===\n");
401         printf("| # | %s | %s | %s \n", "Narrow Names" , "Short Names" ,  "Long Names");
402         for (i = 0; i < 7; i++) {
403                 f_narrow = _date_basic_format_convert("EEEEE", i, "day");
404                 f_short = _date_basic_format_convert("EEE", i, "day");
405                 f_long = _date_basic_format_convert("EEEE", i, "day");
406
407                 printf("| %d | %s | %s | %s\n", i, f_narrow, f_short, f_long);
408
409                 free(f_narrow);
410                 free(f_short);
411                 free(f_long);
412         }
413         PRINT_ASCIIDOC_LOG("|===\n");
414
415         //Day - stand-alone
416         printf(" Day - Stand-alone\n");
417         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
418         PRINT_ASCIIDOC_LOG("|===\n");
419         printf("| # | %-s | %s | %s \n",        "Narrow Names" , "Short Names" ,  "Long Names");
420         for (i = 0; i < 7; i++) {
421                 s_narrow = _date_basic_format_convert("ccccc", i, "day");
422                 s_short = _date_basic_format_convert("ccc", i, "day");
423                 s_long = _date_basic_format_convert("cccc", i, "day");
424
425                 printf("| %d | %s | %s | %s\n", i, s_narrow, s_short, s_long);
426
427                 free(s_narrow);
428                 free(s_short);
429                 free(s_long);
430         }
431         PRINT_ASCIIDOC_LOG("|===\n");
432
433         //Month - Formatting
434         printf(" Month - Formatting\n");
435         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
436         PRINT_ASCIIDOC_LOG("|===\n");
437         printf("| #  | %-s | %s | %s \n",       "Narrow Names" , "Short Names" ,  "Long Names");
438         for (i = 0; i < 12; i++) {
439                 f_narrow = _date_basic_format_convert("MMMMM", i, "month");
440                 f_short = _date_basic_format_convert("MMM", i, "month");
441                 f_long = _date_basic_format_convert("MMMM", i, "month");
442
443                 printf("| %-2d | %s | %s | %s\n", i, f_narrow, f_short, f_long);
444
445                 free(f_narrow);
446                 free(f_short);
447                 free(f_long);
448         }
449         PRINT_ASCIIDOC_LOG("|===\n");
450
451         //Month - stand-alone
452         printf(" Month - Stand-alone\n");
453         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
454         PRINT_ASCIIDOC_LOG("|===\n");
455         printf("| #  | %s | %s | %s \n",        "Narrow Names" , "Short Names" ,  "Long Names");
456
457         for (i = 0; i < 12; i++) {
458                 s_narrow = _date_basic_format_convert("LLLLL", i, "month");
459                 s_short = _date_basic_format_convert("LLL", i, "month");
460                 s_long = _date_basic_format_convert("LLLL", i, "month");
461
462                 printf("| %-2d | %s | %s | %s\n", i, s_narrow, s_short, s_long);
463
464                 free(s_narrow);
465                 free(s_short);
466                 free(s_long);
467         }
468         PRINT_ASCIIDOC_LOG("|===\n");
469
470
471         return 0;
472 }
473
474 i18n_udate _time_convert(char *input_time)
475 {
476         i18n_ucalendar_h ucal;
477         i18n_udate date;
478         int ret = I18N_ERROR_NONE;
479         int year, month, day, hour, minute, second;
480         struct tm result;
481
482         strptime(input_time, "%Y%m%d%H%M%S", &result);
483         if (result.tm_year >= 100)
484                 result.tm_year = result.tm_year%100 + 2000;
485         PRINT_DEBUG_LOG("Date from strptime, year:%d month:%d day:%d hour:%d minute:%d second:%d.\n", result.tm_year, result.tm_mon+1, result.tm_mday, result.tm_hour, result.tm_min, result.tm_sec);
486
487         /*create i18n_ucalendar_h */
488         ret = i18n_ucalendar_create(0, -1, NULL, I18N_UCALENDAR_DEFAULT, &ucal);
489         if (ret) {
490                 printf("i18n_ucalendar_create failed.\n");
491                 return -1;
492         }
493
494         /*set i18n_ucalendar_h's date */
495         i18n_ucalendar_set_date_time(ucal, result.tm_year, result.tm_mon, result.tm_mday, result.tm_hour, result.tm_min, result.tm_sec);
496         i18n_ucalendar_get(ucal, I18N_UCALENDAR_YEAR, &year);
497         i18n_ucalendar_get(ucal, I18N_UCALENDAR_MONTH, &month);
498         i18n_ucalendar_get(ucal, I18N_UCALENDAR_DATE, &day);
499         i18n_ucalendar_get(ucal, I18N_UCALENDAR_HOUR, &hour);
500         i18n_ucalendar_get(ucal, I18N_UCALENDAR_MINUTE, &minute);
501         i18n_ucalendar_get(ucal, I18N_UCALENDAR_SECOND, &second);
502         PRINT_DEBUG_LOG("Date from ucal, year:%d month:%d day:%d hour:%d minute:%d second:%d.\n", year, month, day, hour, minute, second);
503         /* get i18n_ucalendar's current time and converts it from milliseconds to seconds */
504         i18n_ucalendar_get_milliseconds(ucal, &date);
505
506         /* destroy i18n_ucalendar_h */
507         i18n_ucalendar_destroy(ucal);
508
509         return date;
510 }
511
512 static int __get_date_and_time(char *input_time)
513 {
514         int ret = 0;
515         printf(" - To get various date and time format\n");
516         printf("****************************************\n");
517
518         i18n_udate date_now;
519         if (!input_time) {
520                 ret = i18n_ucalendar_get_now(&date_now);
521                 CHECK_ERROR("i18n_ucalendar_get_now", ret);
522                 PRINT_DEBUG_LOG("i18n_ucalendar_get_now = %lf\n", date_now);
523         } else {
524                 date_now = _time_convert(input_time);
525                 PRINT_DEBUG_LOG("_time_convert = %lf\n", date_now);
526         }
527
528         i18n_udate_format_h format_h = NULL;
529         i18n_udatepg_h udatepg;
530         ret = i18n_udatepg_create(default_locale, &udatepg);
531         CHECK_ERROR("i18n_udatepg_create", ret);
532
533         i18n_uchar format[BUF_SIZE];
534         i18n_ustring_copy_ua_n(format, "ddMMMyyyyHHmmssz", BUF_SIZE);
535
536         /* To get default time zone id */
537         i18n_timezone_h tmz;
538         char *timezone_id;
539         i18n_uchar default_timezone_id[BUF_SIZE] = {0, };
540
541         ret = i18n_timezone_create_default(&tmz);
542         CHECK_ERROR("18n_timezone_create_default", ret);
543         ret = i18n_timezone_get_id(tmz, &timezone_id);
544         i18n_ustring_copy_ua_n(default_timezone_id, timezone_id, strlen(timezone_id));
545
546         int pattern_len, len;
547         i18n_uchar pattern[BUF_SIZE], skeleton[BUF_SIZE];
548         i18n_ustring_copy_ua(skeleton, I18N_UDATE_MONTH_DAY);
549         len = i18n_ustring_get_length(skeleton);
550         ret = i18n_udatepg_get_best_pattern(udatepg, skeleton, len, pattern, BUF_SIZE, &pattern_len);
551         CHECK_ERROR("i18n_udatepg_get_best_pattern", ret);
552
553         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
554         PRINT_ASCIIDOC_LOG("|===\n");
555         printf("| %-17.17s | %-26.26s | %s \n",  "TIME TYPE" , "DATE TYPE" ,  "OUTPUT");
556         for (n_enum_date_counter = 0; n_enum_date_counter < n_date_enum_size; n_enum_date_counter++) {
557                 for (n_enum_time_counter = 0; n_enum_time_counter < n_time_enum_size; n_enum_time_counter++) {
558                         ret = i18n_udate_create(eTimeFormatStyle[n_enum_time_counter],
559                                         eDateFormatStyle[n_enum_date_counter],
560                                         default_locale, default_timezone_id, -1, pattern, -1, &format_h);
561                         CHECK_ERROR("i18n_udate_create", ret);
562
563                         i18n_uchar *result = (i18n_uchar *) malloc(BUF_SIZE * sizeof(i18n_uchar));
564                         int date_len;
565                         ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len);
566                         CHECK_ERROR("i18n_udate_format_date", ret);
567
568                         char s[BUF_SIZE];
569                         i18n_ustring_copy_au(s, result);
570                         free(result);
571
572                         char *time_str, *date_str;
573                         time_str = __print_i18n_type_string("time", n_enum_time_counter);
574                         date_str = __print_i18n_type_string("date", n_enum_date_counter);
575                         printf("| %-17.17s | %-26.26s | %s\n", time_str, date_str, s);
576                         free(time_str);
577                         free(date_str);
578                 }
579         }
580
581         /* Release the time zone object. */
582         ret = i18n_udatepg_destroy(udatepg);
583         CHECK_ERROR("i18n_udatepg_destroy", ret);
584         ret = i18n_timezone_destroy(tmz);
585         CHECK_ERROR("i18n_timezone_destroy", ret);
586         free(timezone_id);
587         PRINT_ASCIIDOC_LOG("|===\n");
588         return 0;
589 }
590
591 static int __get_number_format(const char *input_number)
592 {
593         int ret = 0;
594         printf(" - To get various number format\n");
595         printf(" - Input number : %s\n", input_number);
596         printf("****************************************\n");
597         double my_number = atof(input_number);
598         PRINT_DEBUG_LOG("Input number = %f\n", my_number);
599
600         i18n_unumber_format_h num_format = NULL;
601
602         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
603         PRINT_ASCIIDOC_LOG("|===\n");
604         printf("| %-30.30s | %s\n",      "NUMBER FORMAT" , "OUTPUT");
605
606         int i;
607         for (i = I18N_UNUMBER_DECIMAL; i <= I18N_UNUMBER_FORMAT_STYLE_COUNT; ++i) {
608                 /* Create a number formatter. */
609                 ret = i18n_unumber_create((i18n_unumber_format_style_e)i, NULL, -1, default_locale, NULL, &num_format);
610                 if ((i18n_unumber_format_style_e)i == I18N_UNUMBER_PATTERN_RULEBASED) {
611                         i18n_uchar pattern[1024];
612
613                         i18n_ustring_copy_ua(pattern,
614                                         "%standard:\n"
615                                         "-x: minus >>;\n"
616                                         "x.x: << point >>;\n"
617                                         "zero; one; two; three; four; five; six; seven; eight; nine;\n"
618                                         "ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n"
619                                         "seventeen; eighteen; nineteen;\n"
620                                         "20: twenty[->>];\n"
621                                         "30: thirty[->>];\n"
622                                         "40: forty[->>];\n"
623                                         "50: fifty[->>];\n"
624                                         "60: sixty[->>];\n"
625                                         "70: seventy[->>];\n"
626                                         "80: eighty[->>];\n"
627                                         "90: ninety[->>];\n"
628                                         "100: =#,##0=;\n");
629
630                         ret = i18n_unumber_create(I18N_UNUMBER_PATTERN_RULEBASED, pattern, -1, default_locale, NULL, &num_format);
631                 }
632                 CHECK_ERROR("i18n_unumber_create", ret);
633
634                 /* Format the given number according to the given locale. */
635                 i18n_uchar formatted_number[BUF_SIZE] = {0, };
636                 i18n_unumber_format_double(num_format, my_number, formatted_number, BUF_SIZE, NULL);
637
638                 /* Display the formatting result. */
639                 char string[BUF_SIZE];
640                 i18n_ustring_copy_au(string, formatted_number);
641
642                 char *number_str;
643                 number_str = __print_i18n_type_string("number_format", i);
644                 printf("| %-30.30s | %s\n", number_str, string);
645                 free(number_str);
646         }
647         PRINT_ASCIIDOC_LOG("|===\n");
648
649         /* Release the decimal number formatter. */
650         ret = i18n_unumber_destroy(num_format);
651         CHECK_ERROR("i18n_unumber_destroy", ret);
652
653         return 0;
654 }
655
656 static int __get_symbol()
657 {
658         printf(" - To get various number symbol\n");
659         printf("****************************************\n");
660
661         /* Create a default number formatter. */
662         i18n_unumber_format_h num_format = NULL;
663         int ret = i18n_unumber_create(I18N_UNUMBER_DEFAULT, NULL, -1, default_locale, NULL, &num_format);
664         CHECK_ERROR("18n_unumber_create", ret);
665
666         int i;
667
668         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
669         PRINT_ASCIIDOC_LOG("|===\n");
670         printf("| %-47.47s | %s\n",      "NUMBER SYMBOL" , "OUTPUT");
671         for (i = 0; i < I18N_UNUMBER_FORMAT_SYMBOL_COUNT; ++i) {
672                 /* Format the selected symbol according to the chosen locale. */
673                 int buf_len;
674                 i18n_uchar u_buffer[BUF_SIZE];
675                 ret = i18n_unumber_get_symbol(num_format, (i18n_unumber_format_symbol_e)i, u_buffer, BUF_SIZE, &buf_len);
676                 CHECK_ERROR("18n_unumber_get_symbol", ret);
677
678                 /* Display the formatted symbol. */
679                 char string[BUF_SIZE];
680                 i18n_ustring_copy_au(string, u_buffer);
681
682                 char *symbol_str;
683                 symbol_str = __print_i18n_type_string("symbol", i+1);
684                 printf("| %-47.47s | %s\n", symbol_str, string);
685                 free(symbol_str);
686         }
687         PRINT_ASCIIDOC_LOG("|===\n");
688
689         /* Release the default number formatter object. */
690         ret = i18n_unumber_destroy(num_format);
691         CHECK_ERROR("i18n_unumber_destroy", ret);
692
693         return 0;
694 }
695
696 static const char *layout_orientation_converter(i18n_ulocale_layout_type_e type)
697 {
698         switch (type) {
699         case I18N_ULOCALE_LAYOUT_LTR:
700                 return "LTR";
701
702         case I18N_ULOCALE_LAYOUT_RTL:
703                 return "RTL";
704
705         case I18N_ULOCALE_LAYOUT_TTB:
706                 return "TTB";
707
708         case I18N_ULOCALE_LAYOUT_BTT:
709                 return "BTT";
710
711         default:
712                 return "UNKNOWN";
713         }
714 }
715
716
717 static int __get_language_info()
718 {
719         printf(" - To get language information\n");
720         printf("****************************************\n");
721
722         i18n_uchar lang[BUF_SIZE];
723
724         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
725         PRINT_ASCIIDOC_LOG("|===\n");
726         printf("| KEY                                    | VALUE\n");
727
728         /* Get the default locale code */
729         printf("| Default locale code    | %s\n", default_locale);
730
731         /* Get the display name of the selected locale. */
732         i18n_uchar name[BUF_SIZE];
733         int name_len;
734
735         int ret =
736             i18n_ulocale_get_display_name(default_locale, default_locale, name, BUF_SIZE, &name_len);
737         CHECK_ERROR("i18n_ulocale_get_display_name", ret);
738         char name_ch[BUF_SIZE];
739         i18n_ustring_copy_au(name_ch, name);
740         printf("| Language display name  | %s\n", name_ch);
741
742
743         /* Get the language related to the selected locale. */
744         i18n_ulocale_get_display_language(default_locale, default_locale, lang, BUF_SIZE);
745
746         /* Get the string representation of the obtained language. */
747         char language[BUF_SIZE];
748         i18n_ustring_copy_au(language, lang);
749         printf("| Full name                              | %s\n", language);
750
751         /* Get the obtained language code. */
752         int32_t lang_len;
753         ret = i18n_ulocale_get_language(default_locale, language, BUF_SIZE, &lang_len);
754         CHECK_ERROR("i18n_ulocale_get_language", ret);
755         printf("| language code                  | %s\n", language);
756
757         /* Get the ISO code of the selected locale. */
758         const char *language_iso = i18n_ulocale_get_iso3_language(default_locale);
759         printf("| ISO code                               | %s\n", language_iso);
760
761         /* Get the type of the line orientation related to the selected locale. */
762         i18n_ulocale_layout_type_e type;
763         ret = i18n_ulocale_get_line_orientation(default_locale, &type);
764         CHECK_ERROR("i18n_ulocale_get_line_orientation", ret);
765         const char *orientation = layout_orientation_converter(type);
766         printf("| Line orientation               | %s\n", orientation);
767
768         /* Get the characters orientation related to the selected locale. */
769         ret = i18n_ulocale_get_character_orientation(default_locale, &type);
770         CHECK_ERROR("i18n_ulocale_get_character_orientation", ret);
771         orientation = layout_orientation_converter(type);
772         printf("| Characters orientation | %s\n", orientation);
773
774         /* Get the variant code related to the selected locale. */
775         char variant[BUF_SIZE];
776         ret = i18n_ulocale_get_variant(default_locale, variant, BUF_SIZE);
777         CHECK_ERROR("i18n_ulocale_get_variant", ret);
778         printf("| variant code                   | %s\n", variant);
779         PRINT_ASCIIDOC_LOG("|===\n");
780
781         return 0;
782 }
783
784 static int __manage_string_iteration(char *input_string)
785 {
786         printf(" - To manage the string iteration\n");
787         printf("****************************************\n");
788
789         PRINT_DEBUG_LOG("Input string : %s\n", input_string);
790         i18n_uchar *string_to_examine;
791         i18n_ubreak_iterator_h boundary;
792
793         if (!input_string) {
794                 const char *input_text = "Twinkle, twinkle, little star. How I wonder what you are";
795                 printf(" - Input string : %s\n", input_text);
796                 string_to_examine =
797                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
798                 if(NULL == string_to_examine)
799                         return I18N_ERROR_OUT_OF_MEMORY;
800                 i18n_ustring_copy_ua(string_to_examine, input_text);
801         } else {
802                 char input_text[1000] = {0, };
803                 COPY_STR(input_text, input_string, 999);
804                 printf(" - Input string : %s\n", input_text);
805                 string_to_examine =
806                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
807                 if(NULL == string_to_examine)
808                         return I18N_ERROR_OUT_OF_MEMORY;
809                 i18n_ustring_copy_ua(string_to_examine, input_text);
810         }
811
812         int i;
813         int ret = 0;
814         char *iter_type;
815
816         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
817         PRINT_ASCIIDOC_LOG("|===\n");
818         printf("| %-19.19s | %s\n", "ITER First", "VALUE");
819
820         /* Displays the first element in the given text */
821         for (i = 0; i <= I18N_UBRK_SENTENCE; i++) {
822                 iter_type = NULL;
823                 ret = i18n_ubrk_create((i18n_ubreak_iterator_type_e)i, default_locale, string_to_examine, -1, &boundary);
824                 CHECK_ERROR("i18n_ubrk_create", ret);
825                 int32_t start = i18n_ubrk_first(boundary);
826                 int32_t end = i18n_ubrk_next(boundary);
827                 i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1));
828                 if (NULL == result) {
829                         free(string_to_examine);
830                         return I18N_ERROR_OUT_OF_MEMORY;
831                 }
832                 result[end - start] = '\0';
833                 i18n_ustring_copy_n(result, &string_to_examine[start], end-start);
834                 char str[BUF_SIZE];
835                 i18n_ustring_copy_au(str, result);
836                 free(result);
837
838                 iter_type =  __print_i18n_type_string("iter_type", i);
839                 printf("| %-19.19s | %s\n", iter_type, str);
840                 free(iter_type);
841         }
842         PRINT_ASCIIDOC_LOG("|===\n");
843
844         printf("\n");
845         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
846         PRINT_ASCIIDOC_LOG("|===\n");
847         printf("| %-19.19s | %s\n", "ITER Last", "VALUE");
848         /* Displays the last element in the given text */
849         for (i = 0; i <= I18N_UBRK_SENTENCE; i++) {
850                 iter_type = NULL;
851                 ret = i18n_ubrk_create((i18n_ubreak_iterator_type_e)i, default_locale, string_to_examine, -1, &boundary);
852                 CHECK_ERROR("i18n_ubrk_create", ret);
853                 int32_t end = i18n_ubrk_last(boundary);
854                 int32_t start = i18n_ubrk_previous(boundary);
855                 i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1));
856                 if (NULL == result) {
857                         free(string_to_examine);
858                         return I18N_ERROR_OUT_OF_MEMORY;
859                 }
860                 result[end - start] = '\0';
861                 i18n_ustring_copy_n(result, &string_to_examine[start], end-start);
862                 char str[BUF_SIZE];
863                 i18n_ustring_copy_au(str, result);
864                 free(result);
865
866                 iter_type =  __print_i18n_type_string("iter_type", i);
867                 printf("| %-19.19s | %s\n", iter_type, str);
868                 free(iter_type);
869         }
870         PRINT_ASCIIDOC_LOG("|===\n");
871
872         free(string_to_examine);
873         ret = i18n_ubrk_destroy(boundary);
874         CHECK_ERROR("i18n_ubrk_destroy", ret);
875
876         return 0;
877 }
878
879 static int __analyze_string(char *custom_string)
880 {
881         printf(" - To manage the string\n");
882         printf("****************************************\n");
883
884         i18n_uchar *string_to_examine;
885
886         if (!custom_string) {
887                 const char *input_text = "String";
888                 printf(" - Input string : %s\n", input_text);
889                 string_to_examine =
890                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
891                 i18n_ustring_copy_ua(string_to_examine, input_text);
892         } else {
893                 char *input_text = custom_string;
894                 printf(" - Input string : %s\n", input_text);
895                 string_to_examine =
896                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
897                 i18n_ustring_copy_ua(string_to_examine, input_text);
898         }
899
900         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
901         PRINT_ASCIIDOC_LOG("|===\n");
902         printf("| KEY           | VALUE\n");
903
904         /* Get length */
905         int32_t len = i18n_ustring_get_length(string_to_examine);
906         printf("| Length        | %d\n", len);
907
908         /* To upper */
909         i18n_uchar dest[BUF_SIZE + 1];
910         i18n_ustring_to_upper(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
911         CHECK_ERROR("i18n_ustring_to_upper", error_code);
912
913         char s[BUF_SIZE];
914         i18n_ustring_copy_au(s, dest);
915         printf("| TO UPPER      | %s\n", s);
916
917         /* To lower */
918         i18n_ustring_to_lower(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
919         CHECK_ERROR("i18n_ustring_to_lower", error_code);
920         i18n_ustring_copy_au(s, dest);
921         printf("| to lower      | %s\n", s);
922
923         /* To title */
924         i18n_ustring_to_title_new(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, NULL);
925         CHECK_ERROR("i18n_ustring_to_title_new", error_code);
926         i18n_ustring_copy_au(s, dest);
927         printf("| To Title      | %s\n", s);
928
929         PRINT_ASCIIDOC_LOG("|===\n");
930
931         return 0;
932 }
933
934 bool timezone_cb(const char *timezone_id, void *user_data)
935 {
936         printf("%s\n", timezone_id);
937         return true;
938 }
939
940 static int __get_available_timezone()
941 {
942         int ret = 0;
943         printf(" - To get the list of time zone");
944         printf("****************************************\n");
945
946         ret = i18n_timezone_foreach_timezone_id(timezone_cb, NULL);
947         CHECK_ERROR("i18n_timezone_foreach_timezone_id", ret);
948
949         return 0;
950 }
951
952 static int __get_timezone_info(char *timezone_id)
953 {
954         int ret = 0;
955         printf(" - To get time zone information\n");
956
957         static i18n_timezone_h tmz;
958         i18n_uchar default_timezone_id[BUF_SIZE] = {0, };
959
960         if (!timezone_id) {
961                 /* Get the default timezone. */
962                 ret = i18n_timezone_create_default(&tmz);
963                 CHECK_ERROR("18n_timezone_create_default", ret);
964                 ret = i18n_timezone_get_id(tmz, &timezone_id);
965                 CHECK_ERROR("i18n_timezone_get_id", ret);
966                 printf(" - Default timezone Id : %s\n", timezone_id);
967         } else {
968                 ret = i18n_timezone_create(&tmz, timezone_id);
969                 CHECK_ERROR("18n_timezone_create", ret);
970                 printf(" - Input timezone Id : %s\n", timezone_id);
971         }
972
973         printf("****************************************\n");
974
975         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
976         PRINT_ASCIIDOC_LOG("|===\n");
977         printf("| KEY                                    | VALUE\n");
978
979         /* Get the display name of the default or selected timezone. */
980         char *display_name;
981         ret = i18n_timezone_get_display_name(tmz, &display_name);
982         CHECK_ERROR("i18n_timezone_get_display_name", ret);
983         printf("| Current timezone               | %s\n", display_name);
984
985         /* Get the current time of the default or selected timezone. */
986         i18n_udate date_now;
987         ret = i18n_ucalendar_get_now(&date_now);
988         CHECK_ERROR("i18n_ucalendar_get_now", ret);
989         PRINT_DEBUG_LOG("i18n_ucalendar_get_now = %lf\n", date_now);
990
991         i18n_udate_format_h format_h = NULL;
992         i18n_udatepg_h udatepg;
993         ret = i18n_udatepg_create("ko_KR", &udatepg);
994         CHECK_ERROR("i18n_udatepg_create", ret);
995
996         i18n_uchar format[BUF_SIZE] = {0, };
997         i18n_ustring_copy_ua_n(format, "ddMMMyyyyHHmmssz", BUF_SIZE);
998
999         int pattern_len = 0, len = 0;
1000         i18n_uchar pattern[BUF_SIZE] = {0, }, skeleton[BUF_SIZE] = {0, };
1001         i18n_ustring_copy_ua(skeleton, I18N_UDATE_MONTH_DAY);
1002         len = i18n_ustring_get_length(skeleton);
1003         ret = i18n_udatepg_get_best_pattern(udatepg, skeleton, len, pattern, BUF_SIZE, &pattern_len);
1004         CHECK_ERROR("i18n_udatepg_get_best_pattern", ret);
1005
1006         i18n_ustring_copy_ua(default_timezone_id, timezone_id);
1007         ret = i18n_udate_create(I18N_UDATE_FULL, I18N_UDATE_FULL, default_locale, default_timezone_id, -1, pattern, -1, &format_h);
1008         CHECK_ERROR("i18n_udate_create", ret);
1009
1010         i18n_uchar result[BUF_SIZE] = {0, };
1011         int date_len = 0;
1012         ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len);
1013         CHECK_ERROR("i18n_udate_format_date", ret);
1014
1015         char s[BUF_SIZE] = {0, };
1016         i18n_ustring_copy_au(s, result);
1017         printf("| Current time                   | %s\n", s);
1018
1019         /* Get the selected timezone ID. */
1020         ret = i18n_timezone_get_id(tmz, &timezone_id);
1021         CHECK_ERROR("i18n_timezone_get_id", ret);
1022         printf("| Timezone ID                    | %s\n", timezone_id);
1023
1024         /* Check whether the selected time zone uses daylight savings time or not. */
1025         i18n_ubool daylight_time;
1026         ret = i18n_timezone_use_daylight_time(tmz, &daylight_time);
1027         CHECK_ERROR("i18n_timezone_use_daylight_time", ret);
1028         printf("| Uses DST                               | %s\n", daylight_time ? "yes" : "no");
1029
1030         /*
1031          * Get the amount of time that need to be added to the
1032          * local standard time to get the local wall clock time.
1033          */
1034         int32_t dst_savings;
1035         ret = i18n_timezone_get_dst_savings(tmz, &dst_savings);
1036         CHECK_ERROR("i18n_timezone_get_dst_savings", ret);
1037         printf("| DST savings in [min]   | %d\n", dst_savings / MS_TO_MIN);
1038
1039         /* Get the selected time zone raw GMT offset. */
1040         int32_t offset_milliseconds;
1041         ret = i18n_timezone_get_raw_offset(tmz, &offset_milliseconds);
1042         CHECK_ERROR("i18n_timezone_get_raw_offset", ret);
1043         if (offset_milliseconds / MS_TO_HOUR > 0)
1044                 printf("| Raw GMT offset                 | GMT +%d\n", offset_milliseconds / MS_TO_HOUR);
1045         else
1046                 printf("| Raw GMT offset                 | GMT %d\n", offset_milliseconds / MS_TO_HOUR);
1047
1048         /* Get the region code associated with the selected time zone. */
1049         char region[BUF_SIZE];
1050         int32_t region_len = -1;
1051         ret = i18n_timezone_get_region(timezone_id, region, &region_len, BUF_SIZE);
1052         CHECK_ERROR("i18n_timezone_get_region", ret);
1053         printf("| Associated region code | %s\n", region);
1054
1055         PRINT_ASCIIDOC_LOG("|===\n");
1056
1057         /* Release the time zone object. */
1058         ret = i18n_udatepg_destroy(udatepg);
1059         CHECK_ERROR("i18n_udatepg_destroy", ret);
1060         ret = i18n_timezone_destroy(tmz);
1061         CHECK_ERROR("i18n_timezone_destroy", ret);
1062         free(timezone_id);
1063         free(display_name);
1064
1065         return 0;
1066 }
1067
1068 static int __get_tzdata_version()
1069 {
1070         const char *ver = i18n_timezone_get_tzdata_version();
1071         printf("tzdata version : %s\n", ver);
1072         printf("****************************************\n");
1073
1074         return 0;
1075 }
1076
1077 static int32_t _get_uchar_length(const char *arr)
1078 {
1079         int32_t ulen = strlen(arr);
1080         i18n_uchar _text[ulen + 1];
1081         i18n_ustring_copy_ua(_text, arr);
1082
1083         return i18n_ustring_get_length(_text);
1084 }
1085
1086 static int __show_ubidi(char *input_text)
1087 {
1088         printf(" - Examples of the Unicode Bidirectional Algorithm\n");
1089         printf(" - Input text : %s\n", input_text ? input_text : "Samsung is ïº±ïºŽï»¤ïº³ï»®ï»¨ïºŸ in Arabic.");
1090         printf("****************************************\n");
1091
1092         int i, j;
1093         const char* text;
1094         static i18n_ubidi_h ubidi;
1095         i18n_ubidi_create(&ubidi);
1096
1097         if (!input_text) {
1098                 text = "Samsung is Ø³Ø§Ù…سونج in Arabic";
1099         } else {
1100                 text = input_text;
1101         }
1102
1103         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
1104         PRINT_ASCIIDOC_LOG("|===\n");
1105         printf("| %-46.46s | %-34.34s | %s \n", "MODES", "OPTIONS", "OUTPUT");
1106
1107         for (i = 0; i < N_MODES; i++) {
1108                 /* Sets ubidi reordering mode */
1109                 int ret = i18n_ubidi_set_reordering_mode(ubidi, reordering_modes[i].mode);
1110                 CHECK_ERROR("i18n_ubidi_set_reordering_mode", ret);
1111
1112                 /* Sets ubidi paragraphs and perform the Unicode bidi algorithm */
1113                 int src_length = _get_uchar_length(text);
1114                 PRINT_DEBUG_LOG("src_length: %d\n", src_length);
1115
1116                 i18n_uchar *src = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (src_length + 1));
1117                 i18n_ustring_copy_ua(src, text);
1118                 ret = i18n_ubidi_set_para(ubidi, src, src_length, I18N_UBIDI_DEFAULT_LTR, NULL);
1119
1120                 /* Writes ubidi reordered text to the entry with write_options */
1121                 i18n_uchar dst[BUF_SIZE];
1122                 int output_length = 0;
1123
1124                 for (j = 0; j < N_OPTIONS; j++) {
1125                         ret = i18n_ubidi_write_reordered(ubidi, reordering_options[j].option, BUF_SIZE,
1126                                         dst, &output_length);
1127                         CHECK_ERROR("i18n_ubidi_write_reordered", ret);
1128
1129                         char buffer[BUF_SIZE];
1130                         i18n_ustring_copy_au(buffer, dst);
1131                         printf("| %-46.46s | %-34.34s | %s \n", reordering_modes[i].display_name, reordering_options[j].display_name, buffer);
1132                 }
1133                 free(src);
1134         }
1135         PRINT_ASCIIDOC_LOG("|===\n");
1136
1137         if (ubidi != NULL) {
1138                 i18n_ubidi_destroy(ubidi);
1139                 ubidi = NULL;
1140         }
1141
1142         return 0;
1143 }
1144
1145 #if (__TIZEN_VER >= 4)
1146 int32_t _ustring_append_n(i18n_uchar *dest, int32_t dest_length, const i18n_uchar *src, int32_t src_length)
1147 {
1148         for (int32_t i = 0; i < src_length; ++i) {
1149                 dest[dest_length] = src[i];
1150                 ++dest_length;
1151         }
1152         return dest_length;
1153 }
1154
1155 i18n_uchar *_convert_unicode_numeric_values(const i18n_uchar *input, int32_t length)
1156 {
1157         if (length <= 0)
1158                 return NULL;
1159         int32_t output_length = 1;
1160
1161         double *values = (double *) malloc(length * sizeof(double));
1162         int max_value_length = 0;
1163
1164         /* Count output length */
1165         for (int32_t i = 0; i < length; ++i) {
1166                 double value = 0;
1167                 i18n_uchar_get_numeric_value(input[i], &value);
1168                 values[i] = value;
1169                 if (value != I18N_U_NO_NUMERIC_VALUE) {
1170                         int value_length = snprintf(NULL, 0, "%g", value);
1171                         if (value_length > max_value_length)
1172                                 max_value_length = value_length;
1173                         if (!INT_ADD_RANGE_OVERFLOW(output_length, value_length))
1174                                 output_length += value_length;
1175                 } else {
1176                         if (!INT_ADD_RANGE_OVERFLOW(output_length, 1))
1177                                 output_length += 1;
1178                 }
1179         }
1180
1181         /* +1 NULL terminator */
1182         if (!INT_ADD_RANGE_OVERFLOW(max_value_length, 1))
1183                 max_value_length += 1;
1184
1185         i18n_uchar *output = (i18n_uchar *) calloc(output_length, sizeof(input[0]));
1186         if (output == NULL) {
1187                 free(values);
1188                 return NULL;
1189         }
1190         i18n_ustring_mem_set(output, '\0', output_length);
1191         char *tmp = (char *) malloc((max_value_length) * sizeof(input[0]));
1192         i18n_uchar *c = (i18n_uchar *) malloc((max_value_length) * sizeof(input[0]));
1193
1194         int32_t current_length = 0;
1195         for (int32_t i = 0; i < length; ++i) {
1196                 double value = values[i];
1197                 if (value != I18N_U_NO_NUMERIC_VALUE) {
1198                         /* Convert double to i18n_uchar */
1199                         if (NULL == tmp) {
1200                                 free(values);
1201                                 free(c);
1202                                 free(output);
1203                                 return NULL;
1204                         }
1205                         snprintf(tmp, max_value_length, "%g", value);
1206                         i18n_ustring_copy_ua_n(c, tmp, max_value_length);
1207                         /* Append converted number to output string */
1208                         int32_t src_length = i18n_ustring_get_length(c);
1209                         current_length = _ustring_append_n(output, current_length, c, src_length);
1210                 } else {
1211                         current_length = _ustring_append_n(output, current_length, input + i, 1);
1212                 }
1213         }
1214         free(values);
1215         free(c);
1216         free(tmp);
1217
1218         return output;
1219 }
1220
1221 static int __convert_number(char *custom_number)
1222 {
1223         printf(" - To convert the number\n");
1224         printf("****************************************\n");
1225
1226         i18n_uchar *number_to_convert;
1227
1228         if (!custom_number) {
1229                 const char *input_number = "abc০১২৩def四五六ⅦⅧⅨ";
1230                 printf(" Input number : %s\n", input_number);
1231                 number_to_convert =
1232                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_number) + 1));
1233                 if (NULL == number_to_convert)
1234                         return I18N_ERROR_OUT_OF_MEMORY;
1235
1236                 i18n_ustring_copy_ua_n(number_to_convert, input_number, BUF_SIZE);
1237
1238                 i18n_uchar *str = _convert_unicode_numeric_values(number_to_convert, i18n_ustring_get_length(number_to_convert));
1239                 if (NULL == str) {
1240                         printf("\nError: Out of memory.\n");
1241                         free(number_to_convert);
1242                         return 0;
1243                 }
1244                 char p_string[BUF_SIZE];
1245                 i18n_ustring_copy_au_n(p_string, str, BUF_SIZE);
1246                 printf(" Convert number : %s\n", p_string);
1247                 free(str);
1248                 PRINT_ASCIIDOC_LOG("|===\n");
1249
1250         } else {
1251                 char *input_number = custom_number;
1252                 printf(" Input number : %s\n", input_number);
1253                 number_to_convert =
1254                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_number) + 1));
1255                 i18n_ustring_copy_ua(number_to_convert, input_number);
1256
1257                 i18n_uchar *str = _convert_unicode_numeric_values(number_to_convert, i18n_ustring_get_length(number_to_convert));
1258                 if (NULL == str) {
1259                         printf("\nError: Out of memory.\n");
1260                         free(number_to_convert);
1261                         return 0;
1262                 }
1263                 char p_string[BUF_SIZE];
1264                 i18n_ustring_copy_au_n(p_string, str, BUF_SIZE);
1265                 printf(" Convert number : %s\n", p_string);
1266                 free(str);
1267                 PRINT_ASCIIDOC_LOG("|===\n");
1268         }
1269         free(number_to_convert);
1270         return 0;
1271 }
1272
1273 struct create_mu {
1274         const char* unit_type;
1275         const char* unit_subtype;
1276         int (*fp)(i18n_measure_unit_h *measure_unit);
1277 };
1278
1279 struct create_mu mu[] = {
1280         {"acceleration", "g-force", i18n_measure_unit_create_g_force},
1281         {"acceleration", "meter-per-second-squared", i18n_measure_unit_create_meter_per_second_squared},
1282         {"angle", "arc-minute", i18n_measure_unit_create_arc_minute},
1283         {"angle", "arc-second", i18n_measure_unit_create_arc_second},
1284         {"angle", "degree", i18n_measure_unit_create_degree},
1285         {"angle", "radian", i18n_measure_unit_create_radian},
1286         {"area", "acre", i18n_measure_unit_create_acre},
1287         {"area", "hectare", i18n_measure_unit_create_hectare},
1288         {"area", "square-centimeter", i18n_measure_unit_create_square_centimeter},
1289         {"area", "square-foot", i18n_measure_unit_create_square_foot},
1290         {"area", "square-inch", i18n_measure_unit_create_square_inch},
1291         {"area", "square-kilometer", i18n_measure_unit_create_square_kilometer},
1292         {"area", "square-meter", i18n_measure_unit_create_square_meter},
1293         {"area", "square-mile", i18n_measure_unit_create_square_mile},
1294         {"area", "square-yard", i18n_measure_unit_create_square_yard},
1295         {"concentr", "karat", i18n_measure_unit_create_karat},
1296         {"consumption", "liter-per-kilometer", i18n_measure_unit_create_liter_per_kilometer},
1297         {"consumption", "mile-per-gallon", i18n_measure_unit_create_mile_per_gallon},
1298         {"digital", "bit", i18n_measure_unit_create_bit},
1299         {"digital", "byte", i18n_measure_unit_create_byte},
1300         {"digital", "gigabit", i18n_measure_unit_create_gigabit},
1301         {"digital", "gigabyte", i18n_measure_unit_create_gigabyte},
1302         {"digital", "kilobit", i18n_measure_unit_create_kilobit},
1303         {"digital", "kilobyte", i18n_measure_unit_create_kilobyte},
1304         {"digital", "megabit", i18n_measure_unit_create_megabit},
1305         {"digital", "megabyte", i18n_measure_unit_create_megabyte},
1306         {"digital", "terabit", i18n_measure_unit_create_terabit},
1307         {"digital", "terabyte", i18n_measure_unit_create_terabyte},
1308         {"duration", "day", i18n_measure_unit_create_day},
1309         {"duration", "hour", i18n_measure_unit_create_hour},
1310         {"duration", "microsecond", i18n_measure_unit_create_microsecond},
1311         {"duration", "milisecond", i18n_measure_unit_create_millisecond},
1312         {"duration", "minute", i18n_measure_unit_create_minute},
1313         {"duration", "month", i18n_measure_unit_create_month},
1314         {"duration", "nanosecond", i18n_measure_unit_create_nanosecond},
1315         {"duration", "second", i18n_measure_unit_create_second},
1316         {"duration", "week", i18n_measure_unit_create_week},
1317         {"duration", "year", i18n_measure_unit_create_year},
1318         {"electric", "ampere", i18n_measure_unit_create_ampere},
1319         {"electric", "miliampere", i18n_measure_unit_create_milliampere},
1320         {"electric", "ohm", i18n_measure_unit_create_ohm},
1321         {"electric", "volt", i18n_measure_unit_create_volt},
1322         {"energy", "calorie", i18n_measure_unit_create_calorie},
1323         {"energy", "foodcalorie", i18n_measure_unit_create_foodcalorie},
1324         {"energy", "joule", i18n_measure_unit_create_joule},
1325         {"energy", "kilocalorie", i18n_measure_unit_create_kilocalorie},
1326         {"energy", "kilojoule", i18n_measure_unit_create_kilojoule},
1327         {"energy", "kilowatt-hour", i18n_measure_unit_create_kilowatt_hour},
1328         {"frequency", "gigahertz", i18n_measure_unit_create_gigahertz},
1329         {"frequency", "hertz", i18n_measure_unit_create_hertz},
1330         {"frequency", "kilohertz", i18n_measure_unit_create_kilohertz},
1331         {"frequency", "megahertz", i18n_measure_unit_create_megahertz},
1332         {"length", "astronomical-unit", i18n_measure_unit_create_astronomical_unit},
1333         {"length", "centimeter", i18n_measure_unit_create_centimeter},
1334         {"length", "decimeter", i18n_measure_unit_create_decimeter},
1335         {"length", "fathom", i18n_measure_unit_create_fathom},
1336         {"length", "foot", i18n_measure_unit_create_foot},
1337         {"length", "furlong", i18n_measure_unit_create_furlong},
1338         {"length", "inch", i18n_measure_unit_create_inch},
1339         {"length", "kilometer", i18n_measure_unit_create_kilometer},
1340         {"length", "light-year", i18n_measure_unit_create_light_year},
1341         {"length", "meter", i18n_measure_unit_create_meter},
1342         {"length", "micrometer", i18n_measure_unit_create_micrometer},
1343         {"length", "mile", i18n_measure_unit_create_mile},
1344         {"length", "millimeter", i18n_measure_unit_create_millimeter},
1345         {"length", "nanometer", i18n_measure_unit_create_nanometer},
1346         {"length", "nautical-mile", i18n_measure_unit_create_nautical_mile},
1347         {"length", "parsec", i18n_measure_unit_create_parsec},
1348         {"length", "picometer", i18n_measure_unit_create_picometer},
1349         {"length", "yard", i18n_measure_unit_create_yard},
1350         {"light", "lux", i18n_measure_unit_create_lux},
1351         {"mass", "carat", i18n_measure_unit_create_carat},
1352         {"mass", "gram", i18n_measure_unit_create_gram},
1353         {"mass", "kilogram", i18n_measure_unit_create_kilogram},
1354         {"mass", "metric-ton", i18n_measure_unit_create_metric_ton},
1355         {"mass", "microgram", i18n_measure_unit_create_microgram},
1356         {"mass", "milligram", i18n_measure_unit_create_milligram},
1357         {"mass", "ounce-troy", i18n_measure_unit_create_ounce_troy},
1358         {"mass", "ounce", i18n_measure_unit_create_ounce},
1359         {"mass", "pound", i18n_measure_unit_create_pound},
1360         {"mass", "stone", i18n_measure_unit_create_stone},
1361         {"mass", "ton", i18n_measure_unit_create_ton},
1362         {"power", "gigawatt", i18n_measure_unit_create_gigawatt},
1363         {"power", "horsepower", i18n_measure_unit_create_horsepower},
1364         {"power", "kilowatt", i18n_measure_unit_create_kilowatt},
1365         {"power", "megawatt", i18n_measure_unit_create_megawatt},
1366         {"power", "milliwatt", i18n_measure_unit_create_milliwatt},
1367         {"power", "watt", i18n_measure_unit_create_watt},
1368         {"pressure", "hectopascal", i18n_measure_unit_create_hectopascal},
1369         {"pressure", "inch-hg", i18n_measure_unit_create_inch_hg},
1370         {"pressure", "millibar", i18n_measure_unit_create_millibar},
1371         {"pressure", "millimeter-of-mercury", i18n_measure_unit_create_millimeter_of_mercury},
1372         {"pressure", "pound-per-square-inch", i18n_measure_unit_create_pound_per_square_inch},
1373         {"speed", "kilometer-per-hour", i18n_measure_unit_create_kilometer_per_hour},
1374         {"speed", "meter-per-second", i18n_measure_unit_create_meter_per_second},
1375         {"speed", "mile-per-hour", i18n_measure_unit_create_mile_per_hour},
1376         {"temperature", "celsius", i18n_measure_unit_create_celsius},
1377         {"temperature", "fahrenheit", i18n_measure_unit_create_fahrenheit},
1378         {"temperature", "kelvin", i18n_measure_unit_create_kelvin},
1379         {"volume", "acre-foot", i18n_measure_unit_create_acre_foot},
1380         {"volume", "bushel", i18n_measure_unit_create_bushel},
1381         {"volume", "centiliter", i18n_measure_unit_create_centiliter},
1382         {"volume", "cubic-centimeter", i18n_measure_unit_create_cubic_centimeter},
1383         {"volume", "cubic-foot", i18n_measure_unit_create_cubic_foot},
1384         {"volume", "cubic-inch", i18n_measure_unit_create_cubic_inch},
1385         {"volume", "cubic-kilometer", i18n_measure_unit_create_cubic_kilometer},
1386         {"volume", "cubic-meter", i18n_measure_unit_create_cubic_meter},
1387         {"volume", "cubic-mile", i18n_measure_unit_create_cubic_mile},
1388         {"volume", "cubic-yard", i18n_measure_unit_create_cubic_yard},
1389         {"volume", "cup", i18n_measure_unit_create_cup},
1390         {"volume", "deciliter", i18n_measure_unit_create_deciliter},
1391         {"volume", "fluid-ounce", i18n_measure_unit_create_fluid_ounce},
1392         {"volume", "gallon", i18n_measure_unit_create_gallon},
1393         {"volume", "hectoliter", i18n_measure_unit_create_hectoliter},
1394         {"volume", "liter", i18n_measure_unit_create_liter},
1395         {"volume", "megaliter", i18n_measure_unit_create_megaliter},
1396         {"volume", "milliliter", i18n_measure_unit_create_milliliter},
1397         {"volume", "pint", i18n_measure_unit_create_pint},
1398         {"volume", "quart", i18n_measure_unit_create_quart},
1399         {"volume", "tablespoon", i18n_measure_unit_create_tablespoon},
1400         {"volume", "teaspoon", i18n_measure_unit_create_teaspoon}
1401         };
1402
1403 static int __show_measure_unit(char *input_number)
1404 {
1405         printf(" - To show the measure unit\n");
1406         printf(" - Input number : %s\n", input_number ? input_number : "137");
1407
1408         printf("****************************************\n");
1409
1410         if (!input_number)
1411                 input_number = (char *)"137";
1412         PRINT_DEBUG_LOG("Input number : %s\n", input_number);
1413
1414         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
1415         PRINT_ASCIIDOC_LOG("|===\n");
1416         printf("| TYPE         | SUBTYPE                  | NARROW    | SHORT        | WIDE \n");
1417
1418         unsigned int i;
1419         for (i = 0; i < sizeof(mu) / sizeof(mu[0]); i++) {
1420                 i18n_measure_unit_h measure_unit = NULL;
1421                 int error_code = mu[i].fp(&measure_unit);
1422
1423                 i18n_formattable_h formattable = NULL;
1424                 double numer;
1425                 sscanf(input_number, "%lf", &numer);
1426                 error_code = i18n_formattable_create_with_double(numer, &formattable);
1427
1428                 i18n_measure_h measure;
1429                 error_code = i18n_measure_create(formattable, measure_unit, &measure);
1430                 i18n_formattable_destroy(formattable);
1431
1432                 int measure_array_count = 0;
1433                 const int max_measures = 10;
1434                 i18n_measure_h measure_array[max_measures] = { NULL };
1435                 measure_array[measure_array_count++] = measure;
1436
1437                 i18n_measure_format_h measure_format_narrow = NULL;
1438                 i18n_measure_format_create("en", "US", I18N_UMEASFMT_WIDTH_NARROW, &measure_format_narrow);
1439
1440                 i18n_measure_format_h measure_format_short = NULL;
1441                 i18n_measure_format_create("en", "US", I18N_UMEASFMT_WIDTH_SHORT, &measure_format_short);
1442
1443                 i18n_measure_format_h measure_format_wide = NULL;
1444                 i18n_measure_format_create("en", "US", I18N_UMEASFMT_WIDTH_WIDE, &measure_format_wide);
1445
1446                 i18n_field_position_h field_position = NULL;
1447                 i18n_field_position_create_for_field(5, &field_position);
1448                 const int width = 100;
1449                 const char *input = " ";
1450                 i18n_uchar dest_narrow[width];
1451                 i18n_ustring_copy_ua_n(dest_narrow, input, width);
1452                 i18n_uchar dest_short[width];
1453                 i18n_ustring_copy_ua_n(dest_short, input, width);
1454                 i18n_uchar dest_wide[width];
1455                 i18n_ustring_copy_ua_n(dest_wide, input, width);
1456
1457                 int32_t length = 0;
1458                 error_code = i18n_measure_format_format_measures(measure_format_narrow, measure_array, measure_array_count,
1459                                 field_position, width, dest_narrow, &length);
1460                 CHECK_ERROR("i18n_measure_format_format_measures[I18N_UMEASFMT_WIDTH_NARROW]", error_code);
1461                 error_code = i18n_measure_format_format_measures(measure_format_short, measure_array, measure_array_count,
1462                                 field_position, width, dest_short, &length);
1463                 CHECK_ERROR("i18n_measure_format_format_measures[I18N_UMEASFMT_WIDTH_SHORT]", error_code);
1464                 error_code = i18n_measure_format_format_measures(measure_format_wide, measure_array, measure_array_count,
1465                                 field_position, width, dest_wide, &length);
1466                 CHECK_ERROR("i18n_measure_format_format_measures[I18N_UMEASFMT_WIDTH_WIDE]", error_code);
1467                 PRINT_DEBUG_LOG("length = %d\n", length);
1468
1469                 char output_text_narrow[width + 1] = { 0x00, };
1470                 char output_text_short[width + 1] = { 0x00, };
1471                 char output_text_wide[width + 1] = { 0x00, };
1472                 i18n_ustring_copy_au_n(output_text_narrow, dest_narrow, width);
1473                 i18n_ustring_copy_au_n(output_text_short, dest_short, width);
1474                 i18n_ustring_copy_au_n(output_text_wide, dest_wide, width);
1475
1476                 printf("| %-12s | %-24s |%-10s |%-15s |%s\n", mu[i].unit_type, mu[i].unit_subtype, output_text_narrow, output_text_short, output_text_wide);
1477                 i18n_measure_destroy(measure);
1478         }
1479     PRINT_ASCIIDOC_LOG("|===\n");
1480
1481         return 0;
1482 }
1483 #endif
1484
1485 #if (__TIZEN_VER >= 5)
1486 static int __test_plural_rules(char *input_number)
1487 {
1488
1489         printf(" - To show plural rules\n");
1490         printf(" - Rule text : one: n is 1; few: n in 2..4\n");
1491         printf(" - Input number : %s\n", input_number ? input_number : "3");
1492
1493         printf("****************************************\n");
1494
1495         i18n_plural_rules_h rules = NULL;
1496
1497         const char *rule_text = "one: n is 1; few: n in 2..4";
1498         PRINT_DEBUG_LOG("%s \n", rule_text);
1499
1500         /* Creates a plural rules object from a description. */
1501         int error_code = i18n_plural_rules_create_rules_from_descr(rule_text, &rules);
1502
1503         /* Create an enumeration of the keywords for the given locale. */
1504         i18n_uenumeration_h keywords = NULL;
1505         error_code = i18n_plural_rules_get_keywords(rules, &keywords);
1506         CHECK_ERROR("i18n_plural_rules_get_keywords", error_code);
1507
1508         /* Get the number of the keywords that the enumeration contains. */
1509         int32_t count = i18n_uenumeration_count(keywords);
1510         printf("Number of keywords: %d\n", count);
1511
1512         /* Get the first keyword from the enumeration. */
1513         int len;
1514         const char *keyword = i18n_uenumeration_next(keywords, &len);
1515         CHECK_ERROR("i18n_uenumeration_next", get_last_result());
1516
1517         /* Iterate over all of the keywords found in the enumeration. */
1518         printf("Display list of keywords: ");
1519         while (keyword != NULL) {
1520                 /* Display the currently processed keyword. */
1521                 printf("%s ", keyword);
1522
1523                 /* Get the next keyword from the enumeration. */
1524                 keyword = i18n_uenumeration_next(keywords, &len);
1525                 CHECK_ERROR("i18n_uenumeration_next", get_last_result())
1526         }
1527         printf("\n");
1528
1529         /* Release the keywords enumeration as it is not needed anymore. */
1530         error_code = i18n_uenumeration_destroy(keywords);
1531         if (error_code != I18N_ERROR_NONE) {
1532                 CHECK_ERROR("i18n_uenumeration_destroy", error_code);
1533         }
1534
1535         /* Create unumber format, to get number from user input. */
1536         i18n_unumber_format_h unumber;
1537         error_code = i18n_unumber_create(I18N_UNUMBER_DECIMAL, NULL, -1, default_locale, NULL, &unumber);
1538         CHECK_ERROR("i18n_unumber_create", error_code);
1539
1540         if (!input_number)
1541                 input_number = (char *)"3";
1542         PRINT_DEBUG_LOG("Input number : %s\n", input_number);
1543
1544         i18n_uchar i18nchar_input[BUF_SIZE] = { 0 };
1545         i18n_ustring_copy_ua(i18nchar_input, input_number);
1546
1547         /* Parse string to double. */
1548         double input = i18n_unumber_parse_double(unumber, i18nchar_input, -1, NULL);
1549
1550         /* Get rule from user defined number and print it to user. */
1551         i18n_uchar buffer[BUF_SIZE] = { 0 };
1552         int output_length = -1;
1553         error_code = i18n_plural_rules_select_double(rules, input, BUF_SIZE, buffer, &output_length);
1554         CHECK_ERROR("i18n_plural_rules_select_double", error_code);
1555
1556         char output_buffer[BUF_SIZE] = { 0 };
1557         i18n_ustring_copy_au_n(output_buffer, buffer, BUF_SIZE);
1558         printf("Matched rule: %s \n", output_buffer);
1559
1560         /* Release the rules as it is not needed anymore. */
1561         error_code = i18n_plural_rules_destroy(rules);
1562         if (error_code != I18N_ERROR_NONE) {
1563                 CHECK_ERROR("i18n_plural_rules_destroy", error_code);
1564         }
1565
1566         return 0;
1567 }
1568 #endif
1569
1570 void allTest()
1571 {
1572         int ret = 0, i = 0;
1573         int loc_count;
1574
1575         loc_count = i18n_ulocale_count_available();
1576         for (i = 0; i < loc_count; i++) {
1577                 default_locale = i18n_ulocale_get_available(i);
1578                 printf("\n== Date and Time Test");
1579                 printf("\n****************************************");
1580                 printf("\n - locales : %s\n", default_locale);
1581                 ret = __get_date_and_time(NULL);
1582                 printf("\n");
1583                 printf("\n== Number Format Test");
1584                 printf("\n****************************************");
1585                 printf("\n - locales : %s\n", default_locale);
1586                 ret = __get_number_format("3.5");
1587                 printf("\n");
1588                 printf("\n== Number Symbol Test");
1589                 printf("\n****************************************");
1590                 printf("\n - locales : %s\n", default_locale);
1591                 ret = __get_symbol();
1592                 printf("\n");
1593                 printf("\n== Language Info");
1594                 printf("\n****************************************");
1595                 printf("\n - locales : %s\n", default_locale);
1596                 ret = __get_language_info();
1597                 printf("\n");
1598         }
1599
1600         printf("\n== String Iteration Test");
1601         printf("\n****************************************\n");
1602         ret = __manage_string_iteration(NULL);
1603         printf("\n");
1604
1605         printf("\n== String Test");
1606         printf("\n****************************************\n");
1607         ret = __analyze_string(NULL);
1608         printf("\n");
1609         printf("\n== Timezone Info");
1610         printf("\n****************************************\n");
1611         ret = __get_timezone_info(NULL);
1612         printf("\n");
1613
1614         printf("\n== TZ Data Version Info");
1615         printf("\n****************************************\n");
1616         ret = __get_tzdata_version();
1617         if (ret == -1) {
1618                 printf("get i18n time zone info list failed\n");
1619         }
1620 }
1621
1622 void showAllLocale()
1623 {
1624         __get_available_locales();
1625 }
1626
1627 void showLangInfo(char *locale)
1628 {
1629         int ret = 0, i = 0;
1630         int loc_count;
1631
1632         if (!locale) {
1633                 loc_count = i18n_ulocale_count_available();
1634                 for (i = 0; i < loc_count; i++) {
1635                         default_locale = i18n_ulocale_get_available(i);
1636                         printf("\n== Language Info");
1637                         printf("\n****************************************");
1638                         printf("\n - locales : %s\n", default_locale);
1639                         ret = __get_language_info();
1640                         if (ret == -1) {
1641                                 printf("get i18n language info list failed\n");
1642                         }
1643                 }
1644         } else {
1645                 default_locale = locale;
1646                 printf("\n== Language Info");
1647                 printf("\n****************************************");
1648                 printf("\n - locales : %s\n", default_locale);
1649                 ret = __get_language_info();
1650                 if (ret == -1) {
1651                         printf("get i18n language info list failed\n");
1652                 }
1653         }
1654 }
1655
1656 void showTimezone(char *timezone_id)
1657 {
1658         int ret = 0;
1659         printf("\n== Timezone Info");
1660         printf("\n****************************************\n");
1661         ret = __get_timezone_info(timezone_id);
1662         if (ret == -1) {
1663                 printf("get i18n time zone info list failed\n");
1664         }
1665 }
1666
1667 void showAllTimezone()
1668 {
1669
1670         int ret = 0;
1671         printf("\n== List of Timezone");
1672         printf("\n****************************************\n");
1673         ret = __get_available_timezone();
1674         if (ret != 0) {
1675                 printf("get the list of time zone failed\n");
1676         }
1677 }
1678
1679 void showTzdataVersion()
1680 {
1681         printf("\n== TZ Data Version Info");
1682         printf("\n****************************************\n");
1683         __get_tzdata_version();
1684 }
1685
1686 void showUbidi(char *input)
1687 {
1688         printf("\n== Show Ubidi");
1689         printf("\n****************************************\n");
1690         __show_ubidi(input);
1691 }
1692
1693 #if (__TIZEN_VER >= 4)
1694 void testNumberConvert(char *input)
1695 {
1696         int ret = 0;
1697
1698         printf("\n== Number Converting Test");
1699         printf("\n****************************************\n");
1700         ret = __convert_number(input);
1701         if (ret == -1) {
1702                 printf("number converting failed\n");
1703         }
1704 }
1705
1706 void showMeasureUnit(char *input)
1707 {
1708         printf("\n== Show Measure Unit");
1709         printf("\n****************************************\n");
1710         __show_measure_unit(input);
1711 }
1712 #endif
1713
1714 #if (__TIZEN_VER >= 5)
1715 void testPluralRules(char *input)
1716 {
1717         printf("\n== Test Plural Rules");
1718         printf("\n****************************************\n");
1719         __test_plural_rules(input);
1720 }
1721 #endif
1722
1723 void showDatentimeFormat(char *locale)
1724 {
1725         int ret = 0, i = 0;
1726         int loc_count;
1727
1728         if (!locale) {
1729                 loc_count = i18n_ulocale_count_available();
1730                 for (i = 0; i < loc_count; i++) {
1731                         default_locale = i18n_ulocale_get_available(i);
1732                         printf("\n== Show Date basic format");
1733                         printf("\n****************************************");
1734                         printf("\n - locales : %s\n", default_locale);
1735                         ret = __get_date_basic_format();
1736                         if (ret == -1) {
1737                                 printf("get i18n date and time basic format list failed\n");
1738                         }
1739                 }
1740         } else {
1741                 default_locale = locale;
1742                 printf("\n== Show Date basic format");
1743                 printf("\n****************************************");
1744                 printf("\n - locales : %s\n", default_locale);
1745                 ret = __get_date_basic_format();
1746                 if (ret == -1) {
1747                         printf("get i18n date and time basic format list failed\n");
1748                 }
1749         }
1750 }
1751
1752 void testDatentime(char *input, char *locale)
1753 {
1754         int ret = 0, i = 0;
1755         int loc_count;
1756
1757         if (!locale) {
1758                 loc_count = i18n_ulocale_count_available();
1759                 for (i = 0; i < loc_count; i++) {
1760                         default_locale = i18n_ulocale_get_available(i);
1761                         printf("\n== Date and Time Test");
1762                         printf("\n****************************************");
1763                         printf("\n - locales : %s\n", default_locale);
1764                         ret = __get_date_and_time(input);
1765                         if (ret == -1) {
1766                                 printf("get i18n date and time list failed\n");
1767                         }
1768                 }
1769         } else {
1770                 default_locale = locale;
1771                 printf("\n== Date and Time Test");
1772                 printf("\n****************************************");
1773                 printf("\n - locales : %s\n", default_locale);
1774                 ret = __get_date_and_time(input);
1775                 if (ret == -1) {
1776                         printf("get i18n date and time list failed\n");
1777                 }
1778         }
1779 }
1780
1781 void testNumberFormat(char *input, char *locale)
1782 {
1783         int ret = 0, i = 0;
1784         int loc_count;
1785
1786         if (!input) {
1787         } else {
1788                 if (!locale) {
1789                         loc_count = i18n_ulocale_count_available();
1790                         for (i = 0; i < loc_count; i++) {
1791                                 default_locale = i18n_ulocale_get_available(i);
1792                                 printf("\n== Number Format Test");
1793                                 printf("\n****************************************");
1794                                 printf("\n - locales : %s\n", default_locale);
1795                                 ret = __get_number_format(input);
1796                                 if (ret == -1) {
1797                                         printf("get number format list failed\n");
1798                                 }
1799                         }
1800                 } else {
1801                         default_locale = locale;
1802                         printf("\n== Number Format Test");
1803                         printf("\n****************************************");
1804                         printf("\n - locales : %s\n", default_locale);
1805                         ret = __get_number_format(input);
1806                         if (ret == -1) {
1807                                 printf("get number format list failed\n");
1808                         }
1809                 }
1810         }
1811 }
1812
1813 void testNumberSymbol(char *locale)
1814 {
1815         int ret = 0, i = 0;
1816         int loc_count;
1817
1818         if (!locale) {
1819                 loc_count = i18n_ulocale_count_available();
1820                 for (i = 0; i < loc_count; i++) {
1821                         default_locale = i18n_ulocale_get_available(i);
1822                         printf("\n== Number Symbol Test");
1823                         printf("\n****************************************");
1824                         printf("\n - locales : %s\n", default_locale);
1825                         ret = __get_symbol();
1826                         if (ret == -1) {
1827                                 printf("get i18n symbol list failed\n");
1828                         }
1829                 }
1830         } else {
1831                 default_locale = locale;
1832                 printf("\n== Number Symbol Test");
1833                 printf("\n****************************************");
1834                 printf("\n - locales : %s\n", default_locale);
1835                 ret = __get_symbol();
1836                 if (ret == -1) {
1837                         printf("get i18n symbol list failed\n");
1838                 }
1839         }
1840 }
1841
1842 void testString(char *input)
1843 {
1844         int ret = 0;
1845
1846         printf("\n== String Test");
1847         printf("\n****************************************\n");
1848         ret = __analyze_string(input);
1849         if (ret == -1) {
1850                 printf("get i18n string list failed\n");
1851         }
1852 }
1853
1854 void testStringIter(char *input)
1855 {
1856         int ret = 0;
1857
1858         printf("\n== String Iteration Test");
1859         printf("\n****************************************\n");
1860         ret = __manage_string_iteration(input);
1861         if (ret == -1) {
1862                 printf("get i18n string iteration list failed\n");
1863         }
1864 }
1865
1866 int main(int argc, char *argv[])
1867 {
1868         struct arguments arguments = {0, };
1869
1870         argp_parse(&argp, argc, argv, 0, 0, &arguments);
1871
1872         if (arguments.all) {
1873                 memset(&arguments, 0x00, sizeof(arguments));
1874
1875                 allTest();
1876         }
1877
1878         if (arguments.printASCII) {
1879                 ASCIIDOC_FLAG = 1;
1880         }
1881
1882         if (arguments.showAllLocale) {
1883                 showAllLocale();
1884         }
1885
1886         if (arguments.showLangInfo) {
1887                 showLangInfo(arguments.setLocale);
1888         }
1889
1890         if (arguments.showDateFormat) {
1891                 showDatentimeFormat(arguments.setLocale);
1892         }
1893
1894         if (arguments.testDatentime) {
1895                 testDatentime(arguments.testTimeArg, arguments.setLocale);
1896         }
1897
1898         if (arguments.testNumberFormat) {
1899                 testNumberFormat(arguments.testNumberFormatArg, arguments.setLocale);
1900         }
1901
1902         if (arguments.testNumberSymbol) {
1903                 testNumberSymbol(arguments.setLocale);
1904         }
1905
1906         if (arguments.testString) {
1907                 testString(arguments.testStringArg);
1908         }
1909
1910         if (arguments.testStringIter) {
1911                 testStringIter(arguments.testStringIterArg);
1912         }
1913
1914         if (arguments.showTimezone) {
1915                 showTimezone(arguments.timezoneId);
1916         }
1917
1918         if (arguments.showAllTimezone) {
1919                 showAllTimezone();
1920         }
1921
1922         if (arguments.showTzdataVersion) {
1923                 showTzdataVersion();
1924         }
1925
1926         if (arguments.showUbidi) {
1927                 showUbidi(arguments.testTextArg);
1928         }
1929
1930 #if (__TIZEN_VER >= 4)
1931         if (arguments.testNumberConvert) {
1932                 testNumberConvert(arguments.testNumberConvertArg);
1933         }
1934
1935         if (arguments.showMeasureUnit) {
1936                 showMeasureUnit(arguments.testInputNumArg);
1937         }
1938 #endif
1939 #if (__TIZEN_VER >= 5)
1940         if (arguments.testPluralRules) {
1941                 testPluralRules(arguments.testPluralRulesArg);
1942         }
1943 #endif
1944
1945         return 0;
1946 }