61b89e0cffef48d76fc26462df7b25883e8955f3
[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                 CHECK_ERROR("i18n_unumber_create", ret);
611
612                 /* Format the given number according to the given locale. */
613                 i18n_uchar formatted_number[BUF_SIZE] = {0, };
614                 i18n_unumber_format_double(num_format, my_number, formatted_number, BUF_SIZE, NULL);
615
616                 /* Display the formatting result. */
617                 char string[BUF_SIZE];
618                 i18n_ustring_copy_au(string, formatted_number);
619
620                 char *number_str;
621                 number_str = __print_i18n_type_string("number_format", i);
622                 printf("| %-30.30s | %s\n", number_str, string);
623                 free(number_str);
624         }
625         PRINT_ASCIIDOC_LOG("|===\n");
626
627         /* Release the decimal number formatter. */
628         ret = i18n_unumber_destroy(num_format);
629         CHECK_ERROR("i18n_unumber_destroy", ret);
630
631         return 0;
632 }
633
634 static int __get_symbol()
635 {
636         printf(" - To get various number symbol\n");
637         printf("****************************************\n");
638
639         /* Create a default number formatter. */
640         i18n_unumber_format_h num_format = NULL;
641         int ret = i18n_unumber_create(I18N_UNUMBER_DEFAULT, NULL, -1, default_locale, NULL, &num_format);
642         CHECK_ERROR("18n_unumber_create", ret);
643
644         int i;
645
646         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
647         PRINT_ASCIIDOC_LOG("|===\n");
648         printf("| %-47.47s | %s\n",      "NUMBER SYMBOL" , "OUTPUT");
649         for (i = 0; i < I18N_UNUMBER_FORMAT_SYMBOL_COUNT; ++i) {
650                 /* Format the selected symbol according to the chosen locale. */
651                 int buf_len;
652                 i18n_uchar u_buffer[BUF_SIZE];
653                 ret = i18n_unumber_get_symbol(num_format, (i18n_unumber_format_symbol_e)i, u_buffer, BUF_SIZE, &buf_len);
654                 CHECK_ERROR("18n_unumber_get_symbol", ret);
655
656                 /* Display the formatted symbol. */
657                 char string[BUF_SIZE];
658                 i18n_ustring_copy_au(string, u_buffer);
659
660                 char *symbol_str;
661                 symbol_str = __print_i18n_type_string("symbol", i+1);
662                 printf("| %-47.47s | %s\n", symbol_str, string);
663                 free(symbol_str);
664         }
665         PRINT_ASCIIDOC_LOG("|===\n");
666
667         /* Release the default number formatter object. */
668         ret = i18n_unumber_destroy(num_format);
669         CHECK_ERROR("i18n_unumber_destroy", ret);
670
671         return 0;
672 }
673
674 static const char *layout_orientation_converter(i18n_ulocale_layout_type_e type)
675 {
676         switch (type) {
677         case I18N_ULOCALE_LAYOUT_LTR:
678                 return "LTR";
679
680         case I18N_ULOCALE_LAYOUT_RTL:
681                 return "RTL";
682
683         case I18N_ULOCALE_LAYOUT_TTB:
684                 return "TTB";
685
686         case I18N_ULOCALE_LAYOUT_BTT:
687                 return "BTT";
688
689         default:
690                 return "UNKNOWN";
691         }
692 }
693
694
695 static int __get_language_info()
696 {
697         printf(" - To get language information\n");
698         printf("****************************************\n");
699
700         i18n_uchar lang[BUF_SIZE];
701
702         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
703         PRINT_ASCIIDOC_LOG("|===\n");
704         printf("| KEY                                    | VALUE\n");
705
706         /* Get the default locale code */
707         printf("| Default locale code    | %s\n", default_locale);
708
709         /* Get the display name of the selected locale. */
710         i18n_uchar name[BUF_SIZE];
711         int name_len;
712
713         int ret =
714             i18n_ulocale_get_display_name(default_locale, default_locale, name, BUF_SIZE, &name_len);
715         CHECK_ERROR("i18n_ulocale_get_display_name", ret);
716         char name_ch[BUF_SIZE];
717         i18n_ustring_copy_au(name_ch, name);
718         printf("| Language display name  | %s\n", name_ch);
719
720
721         /* Get the language related to the selected locale. */
722         i18n_ulocale_get_display_language(default_locale, default_locale, lang, BUF_SIZE);
723
724         /* Get the string representation of the obtained language. */
725         char language[BUF_SIZE];
726         i18n_ustring_copy_au(language, lang);
727         printf("| Full name                              | %s\n", language);
728
729         /* Get the obtained language code. */
730         int32_t lang_len;
731         ret = i18n_ulocale_get_language(default_locale, language, BUF_SIZE, &lang_len);
732         CHECK_ERROR("i18n_ulocale_get_language", ret);
733         printf("| language code                  | %s\n", language);
734
735         /* Get the ISO code of the selected locale. */
736         const char *language_iso = i18n_ulocale_get_iso3_language(default_locale);
737         printf("| ISO code                               | %s\n", language_iso);
738
739         /* Get the type of the line orientation related to the selected locale. */
740         i18n_ulocale_layout_type_e type;
741         ret = i18n_ulocale_get_line_orientation(default_locale, &type);
742         CHECK_ERROR("i18n_ulocale_get_line_orientation", ret);
743         const char *orientation = layout_orientation_converter(type);
744         printf("| Line orientation               | %s\n", orientation);
745
746         /* Get the characters orientation related to the selected locale. */
747         ret = i18n_ulocale_get_character_orientation(default_locale, &type);
748         CHECK_ERROR("i18n_ulocale_get_character_orientation", ret);
749         orientation = layout_orientation_converter(type);
750         printf("| Characters orientation | %s\n", orientation);
751
752         /* Get the variant code related to the selected locale. */
753         char variant[BUF_SIZE];
754         ret = i18n_ulocale_get_variant(default_locale, variant, BUF_SIZE);
755         CHECK_ERROR("i18n_ulocale_get_variant", ret);
756         printf("| variant code                   | %s\n", variant);
757         PRINT_ASCIIDOC_LOG("|===\n");
758
759         return 0;
760 }
761
762 static int __manage_string_iteration(char *input_string)
763 {
764         printf(" - To manage the string iteration\n");
765         printf("****************************************\n");
766
767         PRINT_DEBUG_LOG("Input string : %s\n", input_string);
768         i18n_uchar *string_to_examine;
769         i18n_ubreak_iterator_h boundary;
770
771         if (!input_string) {
772                 const char *input_text = "Twinkle, twinkle, little star. How I wonder what you are";
773                 printf(" - Input string : %s\n", input_text);
774                 string_to_examine =
775                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
776                 if(NULL == string_to_examine)
777                         return I18N_ERROR_OUT_OF_MEMORY;
778                 i18n_ustring_copy_ua(string_to_examine, input_text);
779         } else {
780                 char input_text[1000] = {0, };
781                 COPY_STR(input_text, input_string, 999);
782                 printf(" - Input string : %s\n", input_text);
783                 string_to_examine =
784                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
785                 if(NULL == string_to_examine)
786                         return I18N_ERROR_OUT_OF_MEMORY;
787                 i18n_ustring_copy_ua(string_to_examine, input_text);
788         }
789
790         int i;
791         int ret = 0;
792         char *iter_type;
793
794         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
795         PRINT_ASCIIDOC_LOG("|===\n");
796         printf("| %-19.19s | %s\n", "ITER First", "VALUE");
797
798         /* Displays the first element in the given text */
799         for (i = 0; i <= I18N_UBRK_SENTENCE; i++) {
800                 iter_type = NULL;
801                 ret = i18n_ubrk_create((i18n_ubreak_iterator_type_e)i, default_locale, string_to_examine, -1, &boundary);
802                 CHECK_ERROR("i18n_ubrk_create", ret);
803                 int32_t start = i18n_ubrk_first(boundary);
804                 int32_t end = i18n_ubrk_next(boundary);
805                 i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1));
806                 if (NULL == result) {
807                         free(string_to_examine);
808                         return I18N_ERROR_OUT_OF_MEMORY;
809                 }
810                 result[end - start] = '\0';
811                 i18n_ustring_copy_n(result, &string_to_examine[start], end-start);
812                 char str[BUF_SIZE];
813                 i18n_ustring_copy_au(str, result);
814                 free(result);
815
816                 iter_type =  __print_i18n_type_string("iter_type", i);
817                 printf("| %-19.19s | %s\n", iter_type, str);
818                 free(iter_type);
819         }
820         PRINT_ASCIIDOC_LOG("|===\n");
821
822         printf("\n");
823         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
824         PRINT_ASCIIDOC_LOG("|===\n");
825         printf("| %-19.19s | %s\n", "ITER Last", "VALUE");
826         /* Displays the last element in the given text */
827         for (i = 0; i <= I18N_UBRK_SENTENCE; i++) {
828                 iter_type = NULL;
829                 ret = i18n_ubrk_create((i18n_ubreak_iterator_type_e)i, default_locale, string_to_examine, -1, &boundary);
830                 CHECK_ERROR("i18n_ubrk_create", ret);
831                 int32_t end = i18n_ubrk_last(boundary);
832                 int32_t start = i18n_ubrk_previous(boundary);
833                 i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1));
834                 if (NULL == result) {
835                         free(string_to_examine);
836                         return I18N_ERROR_OUT_OF_MEMORY;
837                 }
838                 result[end - start] = '\0';
839                 i18n_ustring_copy_n(result, &string_to_examine[start], end-start);
840                 char str[BUF_SIZE];
841                 i18n_ustring_copy_au(str, result);
842                 free(result);
843
844                 iter_type =  __print_i18n_type_string("iter_type", i);
845                 printf("| %-19.19s | %s\n", iter_type, str);
846                 free(iter_type);
847         }
848         PRINT_ASCIIDOC_LOG("|===\n");
849
850         free(string_to_examine);
851         ret = i18n_ubrk_destroy(boundary);
852         CHECK_ERROR("i18n_ubrk_destroy", ret);
853
854         return 0;
855 }
856
857 static int __analyze_string(char *custom_string)
858 {
859         printf(" - To manage the string\n");
860         printf("****************************************\n");
861
862         i18n_uchar *string_to_examine;
863
864         if (!custom_string) {
865                 const char *input_text = "String";
866                 printf(" - Input string : %s\n", input_text);
867                 string_to_examine =
868                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
869                 i18n_ustring_copy_ua(string_to_examine, input_text);
870         } else {
871                 char *input_text = custom_string;
872                 printf(" - Input string : %s\n", input_text);
873                 string_to_examine =
874                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1));
875                 i18n_ustring_copy_ua(string_to_examine, input_text);
876         }
877
878         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
879         PRINT_ASCIIDOC_LOG("|===\n");
880         printf("| KEY           | VALUE\n");
881
882         /* Get length */
883         int32_t len = i18n_ustring_get_length(string_to_examine);
884         printf("| Length        | %d\n", len);
885
886         /* To upper */
887         i18n_uchar dest[BUF_SIZE + 1];
888         i18n_ustring_to_upper(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
889         CHECK_ERROR("i18n_ustring_to_upper", error_code);
890
891         char s[BUF_SIZE];
892         i18n_ustring_copy_au(s, dest);
893         printf("| TO UPPER      | %s\n", s);
894
895         /* To lower */
896         i18n_ustring_to_lower(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code);
897         CHECK_ERROR("i18n_ustring_to_lower", error_code);
898         i18n_ustring_copy_au(s, dest);
899         printf("| to lower      | %s\n", s);
900
901         /* To title */
902         i18n_ustring_to_title_new(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, NULL);
903         CHECK_ERROR("i18n_ustring_to_title_new", error_code);
904         i18n_ustring_copy_au(s, dest);
905         printf("| To Title      | %s\n", s);
906
907         PRINT_ASCIIDOC_LOG("|===\n");
908
909         return 0;
910 }
911
912 bool timezone_cb(const char *timezone_id, void *user_data)
913 {
914         printf("%s\n", timezone_id);
915         return true;
916 }
917
918 static int __get_available_timezone()
919 {
920         int ret = 0;
921         printf(" - To get the list of time zone");
922         printf("****************************************\n");
923
924         ret = i18n_timezone_foreach_timezone_id(timezone_cb, NULL);
925         CHECK_ERROR("i18n_timezone_foreach_timezone_id", ret);
926
927         return 0;
928 }
929
930 static int __get_timezone_info(char *timezone_id)
931 {
932         int ret = 0;
933         printf(" - To get time zone information\n");
934
935         static i18n_timezone_h tmz;
936         i18n_uchar default_timezone_id[BUF_SIZE] = {0, };
937
938         if (!timezone_id) {
939                 /* Get the default timezone. */
940                 ret = i18n_timezone_create_default(&tmz);
941                 CHECK_ERROR("18n_timezone_create_default", ret);
942                 ret = i18n_timezone_get_id(tmz, &timezone_id);
943                 CHECK_ERROR("i18n_timezone_get_id", ret);
944                 printf(" - Default timezone Id : %s\n", timezone_id);
945         } else {
946                 ret = i18n_timezone_create(&tmz, timezone_id);
947                 CHECK_ERROR("18n_timezone_create", ret);
948                 printf(" - Input timezone Id : %s\n", timezone_id);
949         }
950
951         printf("****************************************\n");
952
953         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
954         PRINT_ASCIIDOC_LOG("|===\n");
955         printf("| KEY                                    | VALUE\n");
956
957         /* Get the display name of the default or selected timezone. */
958         char *display_name;
959         ret = i18n_timezone_get_display_name(tmz, &display_name);
960         CHECK_ERROR("i18n_timezone_get_display_name", ret);
961         printf("| Current timezone               | %s\n", display_name);
962
963         /* Get the current time of the default or selected timezone. */
964         i18n_udate date_now;
965         ret = i18n_ucalendar_get_now(&date_now);
966         CHECK_ERROR("i18n_ucalendar_get_now", ret);
967         PRINT_DEBUG_LOG("i18n_ucalendar_get_now = %lf\n", date_now);
968
969         i18n_udate_format_h format_h = NULL;
970         i18n_udatepg_h udatepg;
971         ret = i18n_udatepg_create("ko_KR", &udatepg);
972         CHECK_ERROR("i18n_udatepg_create", ret);
973
974         i18n_uchar format[BUF_SIZE] = {0, };
975         i18n_ustring_copy_ua_n(format, "ddMMMyyyyHHmmssz", BUF_SIZE);
976
977         int pattern_len = 0, len = 0;
978         i18n_uchar pattern[BUF_SIZE] = {0, }, skeleton[BUF_SIZE] = {0, };
979         i18n_ustring_copy_ua(skeleton, I18N_UDATE_MONTH_DAY);
980         len = i18n_ustring_get_length(skeleton);
981         ret = i18n_udatepg_get_best_pattern(udatepg, skeleton, len, pattern, BUF_SIZE, &pattern_len);
982         CHECK_ERROR("i18n_udatepg_get_best_pattern", ret);
983
984         i18n_ustring_copy_ua(default_timezone_id, timezone_id);
985         ret = i18n_udate_create(I18N_UDATE_FULL, I18N_UDATE_FULL, default_locale, default_timezone_id, -1, pattern, -1, &format_h);
986         CHECK_ERROR("i18n_udate_create", ret);
987
988         i18n_uchar result[BUF_SIZE] = {0, };
989         int date_len = 0;
990         ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len);
991         CHECK_ERROR("i18n_udate_format_date", ret);
992
993         char s[BUF_SIZE] = {0, };
994         i18n_ustring_copy_au(s, result);
995         printf("| Current time                   | %s\n", s);
996
997         /* Get the selected timezone ID. */
998         ret = i18n_timezone_get_id(tmz, &timezone_id);
999         CHECK_ERROR("i18n_timezone_get_id", ret);
1000         printf("| Timezone ID                    | %s\n", timezone_id);
1001
1002         /* Check whether the selected time zone uses daylight savings time or not. */
1003         i18n_ubool daylight_time;
1004         ret = i18n_timezone_use_daylight_time(tmz, &daylight_time);
1005         CHECK_ERROR("i18n_timezone_use_daylight_time", ret);
1006         printf("| Uses DST                               | %s\n", daylight_time ? "yes" : "no");
1007
1008         /*
1009          * Get the amount of time that need to be added to the
1010          * local standard time to get the local wall clock time.
1011          */
1012         int32_t dst_savings;
1013         ret = i18n_timezone_get_dst_savings(tmz, &dst_savings);
1014         CHECK_ERROR("i18n_timezone_get_dst_savings", ret);
1015         printf("| DST savings in [min]   | %d\n", dst_savings / MS_TO_MIN);
1016
1017         /* Get the selected time zone raw GMT offset. */
1018         int32_t offset_milliseconds;
1019         ret = i18n_timezone_get_raw_offset(tmz, &offset_milliseconds);
1020         CHECK_ERROR("i18n_timezone_get_raw_offset", ret);
1021         if (offset_milliseconds / MS_TO_HOUR > 0)
1022                 printf("| Raw GMT offset                 | GMT +%d\n", offset_milliseconds / MS_TO_HOUR);
1023         else
1024                 printf("| Raw GMT offset                 | GMT %d\n", offset_milliseconds / MS_TO_HOUR);
1025
1026         /* Get the region code associated with the selected time zone. */
1027         char region[BUF_SIZE];
1028         int32_t region_len = -1;
1029         ret = i18n_timezone_get_region(timezone_id, region, &region_len, BUF_SIZE);
1030         CHECK_ERROR("i18n_timezone_get_region", ret);
1031         printf("| Associated region code | %s\n", region);
1032
1033         PRINT_ASCIIDOC_LOG("|===\n");
1034
1035         /* Release the time zone object. */
1036         ret = i18n_udatepg_destroy(udatepg);
1037         CHECK_ERROR("i18n_udatepg_destroy", ret);
1038         ret = i18n_timezone_destroy(tmz);
1039         CHECK_ERROR("i18n_timezone_destroy", ret);
1040         free(timezone_id);
1041         free(display_name);
1042
1043         return 0;
1044 }
1045
1046 static int __get_tzdata_version()
1047 {
1048         const char *ver = i18n_timezone_get_tzdata_version();
1049         printf("tzdata version : %s\n", ver);
1050         printf("****************************************\n");
1051
1052         return 0;
1053 }
1054
1055 static int32_t _get_uchar_length(const char *arr)
1056 {
1057         int32_t ulen = strlen(arr);
1058         i18n_uchar _text[ulen + 1];
1059         i18n_ustring_copy_ua(_text, arr);
1060
1061         return i18n_ustring_get_length(_text);
1062 }
1063
1064 static int __show_ubidi(char *input_text)
1065 {
1066         printf(" - Examples of the Unicode Bidirectional Algorithm\n");
1067         printf(" - Input text : %s\n", input_text ? input_text : "Samsung is ïº±ïºŽï»¤ïº³ï»®ï»¨ïºŸ in Arabic.");
1068         printf("****************************************\n");
1069
1070         int i, j;
1071         const char* text;
1072         static i18n_ubidi_h ubidi;
1073         i18n_ubidi_create(&ubidi);
1074
1075         if (!input_text) {
1076                 text = "Samsung is Ø³Ø§Ù…سونج in Arabic";
1077         } else {
1078                 text = input_text;
1079         }
1080
1081         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
1082         PRINT_ASCIIDOC_LOG("|===\n");
1083         printf("| %-46.46s | %-34.34s | %s \n", "MODES", "OPTIONS", "OUTPUT");
1084
1085         for (i = 0; i < N_MODES; i++) {
1086                 /* Sets ubidi reordering mode */
1087                 int ret = i18n_ubidi_set_reordering_mode(ubidi, reordering_modes[i].mode);
1088                 CHECK_ERROR("i18n_ubidi_set_reordering_mode", ret);
1089
1090                 /* Sets ubidi paragraphs and perform the Unicode bidi algorithm */
1091                 int src_length = _get_uchar_length(text);
1092                 PRINT_DEBUG_LOG("src_length: %d\n", src_length);
1093
1094                 i18n_uchar *src = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (src_length + 1));
1095                 i18n_ustring_copy_ua(src, text);
1096                 ret = i18n_ubidi_set_para(ubidi, src, src_length, I18N_UBIDI_DEFAULT_LTR, NULL);
1097
1098                 /* Writes ubidi reordered text to the entry with write_options */
1099                 i18n_uchar dst[BUF_SIZE];
1100                 int output_length = 0;
1101
1102                 for (j = 0; j < N_OPTIONS; j++) {
1103                         ret = i18n_ubidi_write_reordered(ubidi, reordering_options[j].option, BUF_SIZE,
1104                                         dst, &output_length);
1105                         CHECK_ERROR("i18n_ubidi_write_reordered", ret);
1106
1107                         char buffer[BUF_SIZE];
1108                         i18n_ustring_copy_au(buffer, dst);
1109                         printf("| %-46.46s | %-34.34s | %s \n", reordering_modes[i].display_name, reordering_options[j].display_name, buffer);
1110                 }
1111                 free(src);
1112         }
1113         PRINT_ASCIIDOC_LOG("|===\n");
1114
1115         if (ubidi != NULL) {
1116                 i18n_ubidi_destroy(ubidi);
1117                 ubidi = NULL;
1118         }
1119
1120         return 0;
1121 }
1122
1123 #if (__TIZEN_VER >= 4)
1124 int32_t _ustring_append_n(i18n_uchar *dest, int32_t dest_length, const i18n_uchar *src, int32_t src_length)
1125 {
1126         for (int32_t i = 0; i < src_length; ++i) {
1127                 dest[dest_length] = src[i];
1128                 ++dest_length;
1129         }
1130         return dest_length;
1131 }
1132
1133 i18n_uchar *_convert_unicode_numeric_values(const i18n_uchar *input, int32_t length)
1134 {
1135         if (length <= 0)
1136                 return NULL;
1137         int32_t output_length = 1;
1138
1139         double *values = (double *) malloc(length * sizeof(double));
1140         int max_value_length = 0;
1141
1142         /* Count output length */
1143         for (int32_t i = 0; i < length; ++i) {
1144                 double value = 0;
1145                 i18n_uchar_get_numeric_value(input[i], &value);
1146                 values[i] = value;
1147                 if (value != I18N_U_NO_NUMERIC_VALUE) {
1148                         int value_length = snprintf(NULL, 0, "%g", value);
1149                         if (value_length > max_value_length)
1150                                 max_value_length = value_length;
1151                         if (!INT_ADD_RANGE_OVERFLOW(output_length, value_length))
1152                                 output_length += value_length;
1153                 } else {
1154                         if (!INT_ADD_RANGE_OVERFLOW(output_length, 1))
1155                                 output_length += 1;
1156                 }
1157         }
1158
1159         /* +1 NULL terminator */
1160         if (!INT_ADD_RANGE_OVERFLOW(max_value_length, 1))
1161                 max_value_length += 1;
1162
1163         i18n_uchar *output = (i18n_uchar *) calloc(output_length, sizeof(input[0]));
1164         if (output == NULL) {
1165                 free(values);
1166                 return NULL;
1167         }
1168         i18n_ustring_mem_set(output, '\0', output_length);
1169         char *tmp = (char *) malloc((max_value_length) * sizeof(input[0]));
1170         i18n_uchar *c = (i18n_uchar *) malloc((max_value_length) * sizeof(input[0]));
1171
1172         int32_t current_length = 0;
1173         for (int32_t i = 0; i < length; ++i) {
1174                 double value = values[i];
1175                 if (value != I18N_U_NO_NUMERIC_VALUE) {
1176                         /* Convert double to i18n_uchar */
1177                         if (NULL == tmp) {
1178                                 free(values);
1179                                 free(c);
1180                                 free(output);
1181                                 return NULL;
1182                         }
1183                         snprintf(tmp, max_value_length, "%g", value);
1184                         i18n_ustring_copy_ua_n(c, tmp, max_value_length);
1185                         /* Append converted number to output string */
1186                         int32_t src_length = i18n_ustring_get_length(c);
1187                         current_length = _ustring_append_n(output, current_length, c, src_length);
1188                 } else {
1189                         current_length = _ustring_append_n(output, current_length, input + i, 1);
1190                 }
1191         }
1192         free(values);
1193         free(c);
1194         free(tmp);
1195
1196         return output;
1197 }
1198
1199 static int __convert_number(char *custom_number)
1200 {
1201         printf(" - To convert the number\n");
1202         printf("****************************************\n");
1203
1204         i18n_uchar *number_to_convert;
1205
1206         if (!custom_number) {
1207                 const char *input_number = "abc০১২৩def四五六ⅦⅧⅨ";
1208                 printf(" Input number : %s\n", input_number);
1209                 number_to_convert =
1210                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_number) + 1));
1211                 if (NULL == number_to_convert)
1212                         return I18N_ERROR_OUT_OF_MEMORY;
1213
1214                 i18n_ustring_copy_ua_n(number_to_convert, input_number, BUF_SIZE);
1215
1216                 i18n_uchar *str = _convert_unicode_numeric_values(number_to_convert, i18n_ustring_get_length(number_to_convert));
1217                 if (NULL == str) {
1218                         printf("\nError: Out of memory.\n");
1219                         free(number_to_convert);
1220                         return 0;
1221                 }
1222                 char p_string[BUF_SIZE];
1223                 i18n_ustring_copy_au_n(p_string, str, BUF_SIZE);
1224                 printf(" Convert number : %s\n", p_string);
1225                 free(str);
1226                 PRINT_ASCIIDOC_LOG("|===\n");
1227
1228         } else {
1229                 char *input_number = custom_number;
1230                 printf(" Input number : %s\n", input_number);
1231                 number_to_convert =
1232                     (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_number) + 1));
1233                 i18n_ustring_copy_ua(number_to_convert, input_number);
1234
1235                 i18n_uchar *str = _convert_unicode_numeric_values(number_to_convert, i18n_ustring_get_length(number_to_convert));
1236                 if (NULL == str) {
1237                         printf("\nError: Out of memory.\n");
1238                         free(number_to_convert);
1239                         return 0;
1240                 }
1241                 char p_string[BUF_SIZE];
1242                 i18n_ustring_copy_au_n(p_string, str, BUF_SIZE);
1243                 printf(" Convert number : %s\n", p_string);
1244                 free(str);
1245                 PRINT_ASCIIDOC_LOG("|===\n");
1246         }
1247         free(number_to_convert);
1248         return 0;
1249 }
1250
1251 struct create_mu {
1252         const char* unit_type;
1253         const char* unit_subtype;
1254         int (*fp)(i18n_measure_unit_h *measure_unit);
1255 };
1256
1257 struct create_mu mu[] = {
1258         {"acceleration", "g-force", i18n_measure_unit_create_g_force},
1259         {"acceleration", "meter-per-second-squared", i18n_measure_unit_create_meter_per_second_squared},
1260         {"angle", "arc-minute", i18n_measure_unit_create_arc_minute},
1261         {"angle", "arc-second", i18n_measure_unit_create_arc_second},
1262         {"angle", "degree", i18n_measure_unit_create_degree},
1263         {"angle", "radian", i18n_measure_unit_create_radian},
1264         {"area", "acre", i18n_measure_unit_create_acre},
1265         {"area", "hectare", i18n_measure_unit_create_hectare},
1266         {"area", "square-centimeter", i18n_measure_unit_create_square_centimeter},
1267         {"area", "square-foot", i18n_measure_unit_create_square_foot},
1268         {"area", "square-inch", i18n_measure_unit_create_square_inch},
1269         {"area", "square-kilometer", i18n_measure_unit_create_square_kilometer},
1270         {"area", "square-meter", i18n_measure_unit_create_square_meter},
1271         {"area", "square-mile", i18n_measure_unit_create_square_mile},
1272         {"area", "square-yard", i18n_measure_unit_create_square_yard},
1273         {"concentr", "karat", i18n_measure_unit_create_karat},
1274         {"consumption", "liter-per-kilometer", i18n_measure_unit_create_liter_per_kilometer},
1275         {"consumption", "mile-per-gallon", i18n_measure_unit_create_mile_per_gallon},
1276         {"digital", "bit", i18n_measure_unit_create_bit},
1277         {"digital", "byte", i18n_measure_unit_create_byte},
1278         {"digital", "gigabit", i18n_measure_unit_create_gigabit},
1279         {"digital", "gigabyte", i18n_measure_unit_create_gigabyte},
1280         {"digital", "kilobit", i18n_measure_unit_create_kilobit},
1281         {"digital", "kilobyte", i18n_measure_unit_create_kilobyte},
1282         {"digital", "megabit", i18n_measure_unit_create_megabit},
1283         {"digital", "megabyte", i18n_measure_unit_create_megabyte},
1284         {"digital", "terabit", i18n_measure_unit_create_terabit},
1285         {"digital", "terabyte", i18n_measure_unit_create_terabyte},
1286         {"duration", "day", i18n_measure_unit_create_day},
1287         {"duration", "hour", i18n_measure_unit_create_hour},
1288         {"duration", "microsecond", i18n_measure_unit_create_microsecond},
1289         {"duration", "milisecond", i18n_measure_unit_create_millisecond},
1290         {"duration", "minute", i18n_measure_unit_create_minute},
1291         {"duration", "month", i18n_measure_unit_create_month},
1292         {"duration", "nanosecond", i18n_measure_unit_create_nanosecond},
1293         {"duration", "second", i18n_measure_unit_create_second},
1294         {"duration", "week", i18n_measure_unit_create_week},
1295         {"duration", "year", i18n_measure_unit_create_year},
1296         {"electric", "ampere", i18n_measure_unit_create_ampere},
1297         {"electric", "miliampere", i18n_measure_unit_create_milliampere},
1298         {"electric", "ohm", i18n_measure_unit_create_ohm},
1299         {"electric", "volt", i18n_measure_unit_create_volt},
1300         {"energy", "calorie", i18n_measure_unit_create_calorie},
1301         {"energy", "foodcalorie", i18n_measure_unit_create_foodcalorie},
1302         {"energy", "joule", i18n_measure_unit_create_joule},
1303         {"energy", "kilocalorie", i18n_measure_unit_create_kilocalorie},
1304         {"energy", "kilojoule", i18n_measure_unit_create_kilojoule},
1305         {"energy", "kilowatt-hour", i18n_measure_unit_create_kilowatt_hour},
1306         {"frequency", "gigahertz", i18n_measure_unit_create_gigahertz},
1307         {"frequency", "hertz", i18n_measure_unit_create_hertz},
1308         {"frequency", "kilohertz", i18n_measure_unit_create_kilohertz},
1309         {"frequency", "megahertz", i18n_measure_unit_create_megahertz},
1310         {"length", "astronomical-unit", i18n_measure_unit_create_astronomical_unit},
1311         {"length", "centimeter", i18n_measure_unit_create_centimeter},
1312         {"length", "decimeter", i18n_measure_unit_create_decimeter},
1313         {"length", "fathom", i18n_measure_unit_create_fathom},
1314         {"length", "foot", i18n_measure_unit_create_foot},
1315         {"length", "furlong", i18n_measure_unit_create_furlong},
1316         {"length", "inch", i18n_measure_unit_create_inch},
1317         {"length", "kilometer", i18n_measure_unit_create_kilometer},
1318         {"length", "light-year", i18n_measure_unit_create_light_year},
1319         {"length", "meter", i18n_measure_unit_create_meter},
1320         {"length", "micrometer", i18n_measure_unit_create_micrometer},
1321         {"length", "mile", i18n_measure_unit_create_mile},
1322         {"length", "millimeter", i18n_measure_unit_create_millimeter},
1323         {"length", "nanometer", i18n_measure_unit_create_nanometer},
1324         {"length", "nautical-mile", i18n_measure_unit_create_nautical_mile},
1325         {"length", "parsec", i18n_measure_unit_create_parsec},
1326         {"length", "picometer", i18n_measure_unit_create_picometer},
1327         {"length", "yard", i18n_measure_unit_create_yard},
1328         {"light", "lux", i18n_measure_unit_create_lux},
1329         {"mass", "carat", i18n_measure_unit_create_carat},
1330         {"mass", "gram", i18n_measure_unit_create_gram},
1331         {"mass", "kilogram", i18n_measure_unit_create_kilogram},
1332         {"mass", "metric-ton", i18n_measure_unit_create_metric_ton},
1333         {"mass", "microgram", i18n_measure_unit_create_microgram},
1334         {"mass", "milligram", i18n_measure_unit_create_milligram},
1335         {"mass", "ounce-troy", i18n_measure_unit_create_ounce_troy},
1336         {"mass", "ounce", i18n_measure_unit_create_ounce},
1337         {"mass", "pound", i18n_measure_unit_create_pound},
1338         {"mass", "stone", i18n_measure_unit_create_stone},
1339         {"mass", "ton", i18n_measure_unit_create_ton},
1340         {"power", "gigawatt", i18n_measure_unit_create_gigawatt},
1341         {"power", "horsepower", i18n_measure_unit_create_horsepower},
1342         {"power", "kilowatt", i18n_measure_unit_create_kilowatt},
1343         {"power", "megawatt", i18n_measure_unit_create_megawatt},
1344         {"power", "milliwatt", i18n_measure_unit_create_milliwatt},
1345         {"power", "watt", i18n_measure_unit_create_watt},
1346         {"pressure", "hectopascal", i18n_measure_unit_create_hectopascal},
1347         {"pressure", "inch-hg", i18n_measure_unit_create_inch_hg},
1348         {"pressure", "millibar", i18n_measure_unit_create_millibar},
1349         {"pressure", "millimeter-of-mercury", i18n_measure_unit_create_millimeter_of_mercury},
1350         {"pressure", "pound-per-square-inch", i18n_measure_unit_create_pound_per_square_inch},
1351         {"speed", "kilometer-per-hour", i18n_measure_unit_create_kilometer_per_hour},
1352         {"speed", "meter-per-second", i18n_measure_unit_create_meter_per_second},
1353         {"speed", "mile-per-hour", i18n_measure_unit_create_mile_per_hour},
1354         {"temperature", "celsius", i18n_measure_unit_create_celsius},
1355         {"temperature", "fahrenheit", i18n_measure_unit_create_fahrenheit},
1356         {"temperature", "kelvin", i18n_measure_unit_create_kelvin},
1357         {"volume", "acre-foot", i18n_measure_unit_create_acre_foot},
1358         {"volume", "bushel", i18n_measure_unit_create_bushel},
1359         {"volume", "centiliter", i18n_measure_unit_create_centiliter},
1360         {"volume", "cubic-centimeter", i18n_measure_unit_create_cubic_centimeter},
1361         {"volume", "cubic-foot", i18n_measure_unit_create_cubic_foot},
1362         {"volume", "cubic-inch", i18n_measure_unit_create_cubic_inch},
1363         {"volume", "cubic-kilometer", i18n_measure_unit_create_cubic_kilometer},
1364         {"volume", "cubic-meter", i18n_measure_unit_create_cubic_meter},
1365         {"volume", "cubic-mile", i18n_measure_unit_create_cubic_mile},
1366         {"volume", "cubic-yard", i18n_measure_unit_create_cubic_yard},
1367         {"volume", "cup", i18n_measure_unit_create_cup},
1368         {"volume", "deciliter", i18n_measure_unit_create_deciliter},
1369         {"volume", "fluid-ounce", i18n_measure_unit_create_fluid_ounce},
1370         {"volume", "gallon", i18n_measure_unit_create_gallon},
1371         {"volume", "hectoliter", i18n_measure_unit_create_hectoliter},
1372         {"volume", "liter", i18n_measure_unit_create_liter},
1373         {"volume", "megaliter", i18n_measure_unit_create_megaliter},
1374         {"volume", "milliliter", i18n_measure_unit_create_milliliter},
1375         {"volume", "pint", i18n_measure_unit_create_pint},
1376         {"volume", "quart", i18n_measure_unit_create_quart},
1377         {"volume", "tablespoon", i18n_measure_unit_create_tablespoon},
1378         {"volume", "teaspoon", i18n_measure_unit_create_teaspoon}
1379         };
1380
1381 static int __show_measure_unit(char *input_number)
1382 {
1383         printf(" - To show the measure unit\n");
1384         printf(" - Input number : %s\n", input_number ? input_number : "137");
1385
1386         printf("****************************************\n");
1387
1388         if (!input_number)
1389                 input_number = (char *)"137";
1390         PRINT_DEBUG_LOG("Input number : %s\n", input_number);
1391
1392         PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
1393         PRINT_ASCIIDOC_LOG("|===\n");
1394         printf("| TYPE         | SUBTYPE                  | NARROW    | SHORT        | WIDE \n");
1395
1396         unsigned int i;
1397         for (i = 0; i < sizeof(mu) / sizeof(mu[0]); i++) {
1398                 i18n_measure_unit_h measure_unit = NULL;
1399                 int error_code = mu[i].fp(&measure_unit);
1400
1401                 i18n_formattable_h formattable = NULL;
1402                 double numer;
1403                 sscanf(input_number, "%lf", &numer);
1404                 error_code = i18n_formattable_create_with_double(numer, &formattable);
1405
1406                 i18n_measure_h measure;
1407                 error_code = i18n_measure_create(formattable, measure_unit, &measure);
1408                 i18n_formattable_destroy(formattable);
1409
1410                 int measure_array_count = 0;
1411                 const int max_measures = 10;
1412                 i18n_measure_h measure_array[max_measures] = { NULL };
1413                 measure_array[measure_array_count++] = measure;
1414
1415                 i18n_measure_format_h measure_format_narrow = NULL;
1416                 i18n_measure_format_create("en", "US", I18N_UMEASFMT_WIDTH_NARROW, &measure_format_narrow);
1417
1418                 i18n_measure_format_h measure_format_short = NULL;
1419                 i18n_measure_format_create("en", "US", I18N_UMEASFMT_WIDTH_SHORT, &measure_format_short);
1420
1421                 i18n_measure_format_h measure_format_wide = NULL;
1422                 i18n_measure_format_create("en", "US", I18N_UMEASFMT_WIDTH_WIDE, &measure_format_wide);
1423
1424                 i18n_field_position_h field_position = NULL;
1425                 i18n_field_position_create_for_field(5, &field_position);
1426                 const int width = 100;
1427                 const char *input = " ";
1428                 i18n_uchar dest_narrow[width];
1429                 i18n_ustring_copy_ua_n(dest_narrow, input, width);
1430                 i18n_uchar dest_short[width];
1431                 i18n_ustring_copy_ua_n(dest_short, input, width);
1432                 i18n_uchar dest_wide[width];
1433                 i18n_ustring_copy_ua_n(dest_wide, input, width);
1434
1435                 int32_t length = 0;
1436                 error_code = i18n_measure_format_format_measures(measure_format_narrow, measure_array, measure_array_count,
1437                                 field_position, width, dest_narrow, &length);
1438                 CHECK_ERROR("i18n_measure_format_format_measures[I18N_UMEASFMT_WIDTH_NARROW]", error_code);
1439                 error_code = i18n_measure_format_format_measures(measure_format_short, measure_array, measure_array_count,
1440                                 field_position, width, dest_short, &length);
1441                 CHECK_ERROR("i18n_measure_format_format_measures[I18N_UMEASFMT_WIDTH_SHORT]", error_code);
1442                 error_code = i18n_measure_format_format_measures(measure_format_wide, measure_array, measure_array_count,
1443                                 field_position, width, dest_wide, &length);
1444                 CHECK_ERROR("i18n_measure_format_format_measures[I18N_UMEASFMT_WIDTH_WIDE]", error_code);
1445                 PRINT_DEBUG_LOG("length = %d\n", length);
1446
1447                 char output_text_narrow[width + 1] = { 0x00, };
1448                 char output_text_short[width + 1] = { 0x00, };
1449                 char output_text_wide[width + 1] = { 0x00, };
1450                 i18n_ustring_copy_au_n(output_text_narrow, dest_narrow, width);
1451                 i18n_ustring_copy_au_n(output_text_short, dest_short, width);
1452                 i18n_ustring_copy_au_n(output_text_wide, dest_wide, width);
1453
1454                 printf("| %-12s | %-24s |%-10s |%-15s |%s\n", mu[i].unit_type, mu[i].unit_subtype, output_text_narrow, output_text_short, output_text_wide);
1455                 i18n_measure_destroy(measure);
1456         }
1457     PRINT_ASCIIDOC_LOG("|===\n");
1458
1459         return 0;
1460 }
1461 #endif
1462
1463 #if (__TIZEN_VER >= 5)
1464 static int __test_plural_rules(char *input_number)
1465 {
1466
1467         printf(" - To show plural rules\n");
1468         printf(" - Rule text : one: n is 1; few: n in 2..4\n");
1469         printf(" - Input number : %s\n", input_number ? input_number : "3");
1470
1471         printf("****************************************\n");
1472
1473         i18n_plural_rules_h rules = NULL;
1474
1475         const char *rule_text = "one: n is 1; few: n in 2..4";
1476         PRINT_DEBUG_LOG("%s \n", rule_text);
1477
1478         /* Creates a plural rules object from a description. */
1479         int error_code = i18n_plural_rules_create_rules_from_descr(rule_text, &rules);
1480
1481         /* Create an enumeration of the keywords for the given locale. */
1482         i18n_uenumeration_h keywords = NULL;
1483         error_code = i18n_plural_rules_get_keywords(rules, &keywords);
1484         CHECK_ERROR("i18n_plural_rules_get_keywords", error_code);
1485
1486         /* Get the number of the keywords that the enumeration contains. */
1487         int32_t count = i18n_uenumeration_count(keywords);
1488         printf("Number of keywords: %d\n", count);
1489
1490         /* Get the first keyword from the enumeration. */
1491         int len;
1492         const char *keyword = i18n_uenumeration_next(keywords, &len);
1493         CHECK_ERROR("i18n_uenumeration_next", get_last_result());
1494
1495         /* Iterate over all of the keywords found in the enumeration. */
1496         printf("Display list of keywords: ");
1497         while (keyword != NULL) {
1498                 /* Display the currently processed keyword. */
1499                 printf("%s ", keyword);
1500
1501                 /* Get the next keyword from the enumeration. */
1502                 keyword = i18n_uenumeration_next(keywords, &len);
1503                 CHECK_ERROR("i18n_uenumeration_next", get_last_result())
1504         }
1505         printf("\n");
1506
1507         /* Release the keywords enumeration as it is not needed anymore. */
1508         error_code = i18n_uenumeration_destroy(keywords);
1509         if (error_code != I18N_ERROR_NONE) {
1510                 CHECK_ERROR("i18n_uenumeration_destroy", error_code);
1511         }
1512
1513         /* Create unumber format, to get number from user input. */
1514         i18n_unumber_format_h unumber;
1515         error_code = i18n_unumber_create(I18N_UNUMBER_DECIMAL, NULL, -1, default_locale, NULL, &unumber);
1516         CHECK_ERROR("i18n_unumber_create", error_code);
1517
1518         if (!input_number)
1519                 input_number = (char *)"3";
1520         PRINT_DEBUG_LOG("Input number : %s\n", input_number);
1521
1522         i18n_uchar i18nchar_input[BUF_SIZE] = { 0 };
1523         i18n_ustring_copy_ua(i18nchar_input, input_number);
1524
1525         /* Parse string to double. */
1526         double input = i18n_unumber_parse_double(unumber, i18nchar_input, -1, NULL);
1527
1528         /* Get rule from user defined number and print it to user. */
1529         i18n_uchar buffer[BUF_SIZE] = { 0 };
1530         int output_length = -1;
1531         error_code = i18n_plural_rules_select_double(rules, input, BUF_SIZE, buffer, &output_length);
1532         CHECK_ERROR("i18n_plural_rules_select_double", error_code);
1533
1534         char output_buffer[BUF_SIZE] = { 0 };
1535         i18n_ustring_copy_au_n(output_buffer, buffer, BUF_SIZE);
1536         printf("Matched rule: %s \n", output_buffer);
1537
1538         /* Release the rules as it is not needed anymore. */
1539         error_code = i18n_plural_rules_destroy(rules);
1540         if (error_code != I18N_ERROR_NONE) {
1541                 CHECK_ERROR("i18n_plural_rules_destroy", error_code);
1542         }
1543
1544         return 0;
1545 }
1546 #endif
1547
1548 void allTest()
1549 {
1550         int ret = 0, i = 0;
1551         int loc_count;
1552
1553         loc_count = i18n_ulocale_count_available();
1554         for (i = 0; i < loc_count; i++) {
1555                 default_locale = i18n_ulocale_get_available(i);
1556                 printf("\n== Date and Time Test");
1557                 printf("\n****************************************");
1558                 printf("\n - locales : %s\n", default_locale);
1559                 ret = __get_date_and_time(NULL);
1560                 printf("\n");
1561                 printf("\n== Number Format Test");
1562                 printf("\n****************************************");
1563                 printf("\n - locales : %s\n", default_locale);
1564                 ret = __get_number_format("3.5");
1565                 printf("\n");
1566                 printf("\n== Number Symbol Test");
1567                 printf("\n****************************************");
1568                 printf("\n - locales : %s\n", default_locale);
1569                 ret = __get_symbol();
1570                 printf("\n");
1571                 printf("\n== Language Info");
1572                 printf("\n****************************************");
1573                 printf("\n - locales : %s\n", default_locale);
1574                 ret = __get_language_info();
1575                 printf("\n");
1576         }
1577
1578         printf("\n== String Iteration Test");
1579         printf("\n****************************************\n");
1580         ret = __manage_string_iteration(NULL);
1581         printf("\n");
1582
1583         printf("\n== String Test");
1584         printf("\n****************************************\n");
1585         ret = __analyze_string(NULL);
1586         printf("\n");
1587         printf("\n== Timezone Info");
1588         printf("\n****************************************\n");
1589         ret = __get_timezone_info(NULL);
1590         printf("\n");
1591
1592         printf("\n== TZ Data Version Info");
1593         printf("\n****************************************\n");
1594         ret = __get_tzdata_version();
1595         if (ret == -1) {
1596                 printf("get i18n time zone info list failed\n");
1597         }
1598 }
1599
1600 void showAllLocale()
1601 {
1602         __get_available_locales();
1603 }
1604
1605 void showLangInfo(char *locale)
1606 {
1607         int ret = 0, i = 0;
1608         int loc_count;
1609
1610         if (!locale) {
1611                 loc_count = i18n_ulocale_count_available();
1612                 for (i = 0; i < loc_count; i++) {
1613                         default_locale = i18n_ulocale_get_available(i);
1614                         printf("\n== Language Info");
1615                         printf("\n****************************************");
1616                         printf("\n - locales : %s\n", default_locale);
1617                         ret = __get_language_info();
1618                         if (ret == -1) {
1619                                 printf("get i18n language info list failed\n");
1620                         }
1621                 }
1622         } else {
1623                 default_locale = locale;
1624                 printf("\n== Language Info");
1625                 printf("\n****************************************");
1626                 printf("\n - locales : %s\n", default_locale);
1627                 ret = __get_language_info();
1628                 if (ret == -1) {
1629                         printf("get i18n language info list failed\n");
1630                 }
1631         }
1632 }
1633
1634 void showTimezone(char *timezone_id)
1635 {
1636         int ret = 0;
1637         printf("\n== Timezone Info");
1638         printf("\n****************************************\n");
1639         ret = __get_timezone_info(timezone_id);
1640         if (ret == -1) {
1641                 printf("get i18n time zone info list failed\n");
1642         }
1643 }
1644
1645 void showAllTimezone()
1646 {
1647
1648         int ret = 0;
1649         printf("\n== List of Timezone");
1650         printf("\n****************************************\n");
1651         ret = __get_available_timezone();
1652         if (ret != 0) {
1653                 printf("get the list of time zone failed\n");
1654         }
1655 }
1656
1657 void showTzdataVersion()
1658 {
1659         printf("\n== TZ Data Version Info");
1660         printf("\n****************************************\n");
1661         __get_tzdata_version();
1662 }
1663
1664 void showUbidi(char *input)
1665 {
1666         printf("\n== Show Ubidi");
1667         printf("\n****************************************\n");
1668         __show_ubidi(input);
1669 }
1670
1671 #if (__TIZEN_VER >= 4)
1672 void testNumberConvert(char *input)
1673 {
1674         int ret = 0;
1675
1676         printf("\n== Number Converting Test");
1677         printf("\n****************************************\n");
1678         ret = __convert_number(input);
1679         if (ret == -1) {
1680                 printf("number converting failed\n");
1681         }
1682 }
1683
1684 void showMeasureUnit(char *input)
1685 {
1686         printf("\n== Show Measure Unit");
1687         printf("\n****************************************\n");
1688         __show_measure_unit(input);
1689 }
1690 #endif
1691
1692 #if (__TIZEN_VER >= 5)
1693 void testPluralRules(char *input)
1694 {
1695         printf("\n== Test Plural Rules");
1696         printf("\n****************************************\n");
1697         __test_plural_rules(input);
1698 }
1699 #endif
1700
1701 void showDatentimeFormat(char *locale)
1702 {
1703         int ret = 0, i = 0;
1704         int loc_count;
1705
1706         if (!locale) {
1707                 loc_count = i18n_ulocale_count_available();
1708                 for (i = 0; i < loc_count; i++) {
1709                         default_locale = i18n_ulocale_get_available(i);
1710                         printf("\n== Show Date basic format");
1711                         printf("\n****************************************");
1712                         printf("\n - locales : %s\n", default_locale);
1713                         ret = __get_date_basic_format();
1714                         if (ret == -1) {
1715                                 printf("get i18n date and time basic format list failed\n");
1716                         }
1717                 }
1718         } else {
1719                 default_locale = locale;
1720                 printf("\n== Show Date basic format");
1721                 printf("\n****************************************");
1722                 printf("\n - locales : %s\n", default_locale);
1723                 ret = __get_date_basic_format();
1724                 if (ret == -1) {
1725                         printf("get i18n date and time basic format list failed\n");
1726                 }
1727         }
1728 }
1729
1730 void testDatentime(char *input, char *locale)
1731 {
1732         int ret = 0, i = 0;
1733         int loc_count;
1734
1735         if (!locale) {
1736                 loc_count = i18n_ulocale_count_available();
1737                 for (i = 0; i < loc_count; i++) {
1738                         default_locale = i18n_ulocale_get_available(i);
1739                         printf("\n== Date and Time Test");
1740                         printf("\n****************************************");
1741                         printf("\n - locales : %s\n", default_locale);
1742                         ret = __get_date_and_time(input);
1743                         if (ret == -1) {
1744                                 printf("get i18n date and time list failed\n");
1745                         }
1746                 }
1747         } else {
1748                 default_locale = locale;
1749                 printf("\n== Date and Time Test");
1750                 printf("\n****************************************");
1751                 printf("\n - locales : %s\n", default_locale);
1752                 ret = __get_date_and_time(input);
1753                 if (ret == -1) {
1754                         printf("get i18n date and time list failed\n");
1755                 }
1756         }
1757 }
1758
1759 void testNumberFormat(char *input, char *locale)
1760 {
1761         int ret = 0, i = 0;
1762         int loc_count;
1763
1764         if (!input) {
1765         } else {
1766                 if (!locale) {
1767                         loc_count = i18n_ulocale_count_available();
1768                         for (i = 0; i < loc_count; i++) {
1769                                 default_locale = i18n_ulocale_get_available(i);
1770                                 printf("\n== Number Format Test");
1771                                 printf("\n****************************************");
1772                                 printf("\n - locales : %s\n", default_locale);
1773                                 ret = __get_number_format(input);
1774                                 if (ret == -1) {
1775                                         printf("get number format list failed\n");
1776                                 }
1777                         }
1778                 } else {
1779                         default_locale = locale;
1780                         printf("\n== Number Format Test");
1781                         printf("\n****************************************");
1782                         printf("\n - locales : %s\n", default_locale);
1783                         ret = __get_number_format(input);
1784                         if (ret == -1) {
1785                                 printf("get number format list failed\n");
1786                         }
1787                 }
1788         }
1789 }
1790
1791 void testNumberSymbol(char *locale)
1792 {
1793         int ret = 0, i = 0;
1794         int loc_count;
1795
1796         if (!locale) {
1797                 loc_count = i18n_ulocale_count_available();
1798                 for (i = 0; i < loc_count; i++) {
1799                         default_locale = i18n_ulocale_get_available(i);
1800                         printf("\n== Number Symbol Test");
1801                         printf("\n****************************************");
1802                         printf("\n - locales : %s\n", default_locale);
1803                         ret = __get_symbol();
1804                         if (ret == -1) {
1805                                 printf("get i18n symbol list failed\n");
1806                         }
1807                 }
1808         } else {
1809                 default_locale = locale;
1810                 printf("\n== Number Symbol Test");
1811                 printf("\n****************************************");
1812                 printf("\n - locales : %s\n", default_locale);
1813                 ret = __get_symbol();
1814                 if (ret == -1) {
1815                         printf("get i18n symbol list failed\n");
1816                 }
1817         }
1818 }
1819
1820 void testString(char *input)
1821 {
1822         int ret = 0;
1823
1824         printf("\n== String Test");
1825         printf("\n****************************************\n");
1826         ret = __analyze_string(input);
1827         if (ret == -1) {
1828                 printf("get i18n string list failed\n");
1829         }
1830 }
1831
1832 void testStringIter(char *input)
1833 {
1834         int ret = 0;
1835
1836         printf("\n== String Iteration Test");
1837         printf("\n****************************************\n");
1838         ret = __manage_string_iteration(input);
1839         if (ret == -1) {
1840                 printf("get i18n string iteration list failed\n");
1841         }
1842 }
1843
1844 int main(int argc, char *argv[])
1845 {
1846         struct arguments arguments = {0, };
1847
1848         argp_parse(&argp, argc, argv, 0, 0, &arguments);
1849
1850         if (arguments.all) {
1851                 memset(&arguments, 0x00, sizeof(arguments));
1852
1853                 allTest();
1854         }
1855
1856         if (arguments.printASCII) {
1857                 ASCIIDOC_FLAG = 1;
1858         }
1859
1860         if (arguments.showAllLocale) {
1861                 showAllLocale();
1862         }
1863
1864         if (arguments.showLangInfo) {
1865                 showLangInfo(arguments.setLocale);
1866         }
1867
1868         if (arguments.showDateFormat) {
1869                 showDatentimeFormat(arguments.setLocale);
1870         }
1871
1872         if (arguments.testDatentime) {
1873                 testDatentime(arguments.testTimeArg, arguments.setLocale);
1874         }
1875
1876         if (arguments.testNumberFormat) {
1877                 testNumberFormat(arguments.testNumberFormatArg, arguments.setLocale);
1878         }
1879
1880         if (arguments.testNumberSymbol) {
1881                 testNumberSymbol(arguments.setLocale);
1882         }
1883
1884         if (arguments.testString) {
1885                 testString(arguments.testStringArg);
1886         }
1887
1888         if (arguments.testStringIter) {
1889                 testStringIter(arguments.testStringIterArg);
1890         }
1891
1892         if (arguments.showTimezone) {
1893                 showTimezone(arguments.timezoneId);
1894         }
1895
1896         if (arguments.showAllTimezone) {
1897                 showAllTimezone();
1898         }
1899
1900         if (arguments.showTzdataVersion) {
1901                 showTzdataVersion();
1902         }
1903
1904         if (arguments.showUbidi) {
1905                 showUbidi(arguments.testTextArg);
1906         }
1907
1908 #if (__TIZEN_VER >= 4)
1909         if (arguments.testNumberConvert) {
1910                 testNumberConvert(arguments.testNumberConvertArg);
1911         }
1912
1913         if (arguments.showMeasureUnit) {
1914                 showMeasureUnit(arguments.testInputNumArg);
1915         }
1916 #endif
1917 #if (__TIZEN_VER >= 5)
1918         if (arguments.testPluralRules) {
1919                 testPluralRules(arguments.testPluralRulesArg);
1920         }
1921 #endif
1922
1923         return 0;
1924 }