From: DongHun Kwak Date: Tue, 30 May 2017 07:52:59 +0000 (+0900) Subject: Change i18ninfo.c to i18ninfo.cpp X-Git-Tag: submit/tizen/20170530.091429^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e6b4cde755f3a63f0b9b69449b694cabec21511c;p=platform%2Fcore%2Fapi%2Fbase-utils.git Change i18ninfo.c to i18ninfo.cpp [Model] All [BinType] AP [Customer] OPEN [Issue#] N/A [Request] N/A [Occurrence Version] N/A [Problem] cpp build testing [Cause & Measure] cpp build testing [Checking Method] N/A [Team] Open Source Management and Setting Part [Developer] dh0128.kwak [Solution company] Samsung [Change Type] N/A Change-Id: If43ae80337fb8a01c9bb41288117a4e6b066f721 Signed-off-by: DongHun Kwak --- diff --git a/i18ninfo/CMakeLists.txt b/i18ninfo/CMakeLists.txt index 6bf5291..3e9c8f9 100644 --- a/i18ninfo/CMakeLists.txt +++ b/i18ninfo/CMakeLists.txt @@ -1,10 +1,10 @@ -PROJECT(i18ninfo C) +PROJECT(i18ninfo CXX) SET(test_tool "i18ninfo") INCLUDE_DIRECTORIES("../src/include") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") aux_source_directory(. sources) diff --git a/i18ninfo/i18ninfo.c b/i18ninfo/i18ninfo.c deleted file mode 100644 index d185361..0000000 --- a/i18ninfo/i18ninfo.c +++ /dev/null @@ -1,1322 +0,0 @@ -#define _GNU_SOURCE 1 -#include -#include -#include -#include -#include -#include -#include "i18ninfo_argp.h" - -#include - -#define DEBUG_FLAG 0 -static int ASCIIDOC_FLAG = 0; - -#define BUF_SIZE 1000 -#define MS_TO_MIN 60000 -#define MS_TO_HOUR 3600000 - -#define PRINT_ERROR_LOG(func_name, error_code) if (DEBUG_FLAG) { \ - fprintf(stderr, "\033[0;31m%s failed! Error: %s [code: %d] \033[0m\n",\ - func_name, get_error_message(error_code), error_code); \ - } - -#define PRINT_DEBUG_LOG(fmt, arg...) if (DEBUG_FLAG) { do {\ - fprintf(stdout, "\033[0;32m" fmt "\033[1;32m \033[0m", ##arg); } while (0); \ - } - -#define CHECK_ERROR(fun_name, error_code) if (error_code != 0) { \ - PRINT_ERROR_LOG(fun_name, error_code); \ - } - -#define COPY_STR(dst, src, dst_len) do { \ - strncpy((dst), (src), (dst_len + 1)); \ - (dst)[(dst_len)] = '\0'; \ -} while (0) - -#define PRINT_ASCIIDOC_LOG(fmt) if (ASCIIDOC_FLAG) printf(fmt) - -const char *default_locale = I18N_ULOCALE_UK; -i18n_uchar default_timezone_id[BUF_SIZE] = {0,}; - -i18n_udate_format_style_e eTimeFormatStyle[] = { - I18N_UDATE_FULL, - I18N_UDATE_LONG, - I18N_UDATE_MEDIUM, - I18N_UDATE_SHORT, - I18N_UDATE_NONE -}; - -i18n_udate_format_style_e eDateFormatStyle[] = { - I18N_UDATE_FULL, - I18N_UDATE_LONG, - I18N_UDATE_MEDIUM, - I18N_UDATE_SHORT, - I18N_UDATE_RELATIVE, - I18N_UDATE_LONG_RELATIVE, - I18N_UDATE_MEDIUM_RELATIVE, - I18N_UDATE_SHORT_RELATIVE, - I18N_UDATE_NONE -}; - -typedef struct { - const char *display_name; - uint16_t option; -} reordering_option; - -#define N_OPTIONS 5 - -static reordering_option reordering_options[N_OPTIONS] = { - {"I18N_UBIDI_KEEP_BASE_COMBINING", I18N_UBIDI_KEEP_BASE_COMBINING}, - {"I18N_UBIDI_DO_MIRRORING", I18N_UBIDI_DO_MIRRORING}, - {"I18N_UBIDI_INSERT_LRM_FOR_NUMERIC", I18N_UBIDI_INSERT_LRM_FOR_NUMERIC}, - {"I18N_UBIDI_REMOVE_BIDI_CONTROLS", I18N_UBIDI_REMOVE_BIDI_CONTROLS}, - {"I18N_UBIDI_OUTPUT_REVERSE", I18N_UBIDI_OUTPUT_REVERSE}, -}; - -typedef struct { - const char *display_name; - i18n_ubidi_reordering_mode_e mode; -} reordering_mode; - -#define N_MODES I18N_UBIDI_REORDER_COUNT - -static reordering_mode reordering_modes[N_MODES] = { - {"I18N_UBIDI_REORDER_DEFAULT", I18N_UBIDI_REORDER_DEFAULT}, - {"I18N_UBIDI_REORDER_NUMBERS_SPECIAL", I18N_UBIDI_REORDER_NUMBERS_SPECIAL}, - {"I18N_UBIDI_REORDER_GROUP_NUMBERS_WITH_R", I18N_UBIDI_REORDER_GROUP_NUMBERS_WITH_R}, - {"I18N_UBIDI_REORDER_RUNS_ONLY", I18N_UBIDI_REORDER_RUNS_ONLY}, - {"I18N_UBIDI_REORDER_INVERSE_NUMBERS_AS_L", I18N_UBIDI_REORDER_INVERSE_NUMBERS_AS_L}, - {"I18N_UBIDI_REORDER_INVERSE_LIKE_DIRECT", I18N_UBIDI_REORDER_INVERSE_LIKE_DIRECT}, - {"I18N_UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL", I18N_UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL} -}; - -int n_date_enum_size = sizeof(eDateFormatStyle) / sizeof(eDateFormatStyle[0]); -int n_time_enum_size = sizeof(eTimeFormatStyle) / sizeof(eTimeFormatStyle[0]); - -int n_enum_time_counter, n_enum_date_counter, error_code; - - -static void __get_available_locales(); -static int __get_date_basic_format(); -static int __get_date_and_time(char *input_time); -static int __get_number_format(char *input_number); -static int __get_symbol(); -static int __get_language_info(); -static int __manage_string_iteration(char *custom_type); -static int __analyze_string(char *custom_string); -static int __get_timezone_info(); -static int __get_tzdata_version(); - -char *__print_i18n_type_string(char *type, int num); - -static void __get_available_locales() -{ - const char *loc_list; - int32_t loc_count, i; - - loc_count = i18n_ulocale_count_available(); - if (loc_count == 0) - printf("empty\n"); - else if (loc_count < 0) - printf("wrong\n"); - else { - PRINT_DEBUG_LOG("locale count : %d\n", loc_count); - for (i = 0; i < loc_count; i++) { - loc_list = i18n_ulocale_get_available(i); - printf("%s\n", loc_list); - } - } -} - -static void init_env() -{ - - char *env_buf; - - env_buf = getenv("ASCIIDOC_FLAG"); - if (env_buf != NULL && strcmp(env_buf, "true") == 0) { - ASCIIDOC_FLAG = 1; - } -} - -char *__print_i18n_type_string(char *type, int num) -{ - char *str = calloc(300, sizeof(char)); - PRINT_DEBUG_LOG("input type: %s, num: %d\n", type, num); - if (!strcmp(type, "time")) { - switch (num) { - case 0: - COPY_STR(str, "I18N_UDATE_FULL", strlen("I18N_UDATE_FULL")); - break; - case 1: - COPY_STR(str, "I18N_UDATE_LONG", strlen("I18N_UDATE_LONG")); - break; - case 2: - COPY_STR(str, "I18N_UDATE_MEDIUM", strlen("I18N_UDATE_MEDIUM")); - break; - case 3: - COPY_STR(str, "I18N_UDATE_SHORT", strlen("I18N_UDATE_SHORT")); - break; - case 4: - COPY_STR(str, "I18N_UDATE_NONE", strlen("I18N_UDATE_NONE")); - break; - default: - COPY_STR(str, "err", strlen("err")); - break; - } - } else if (!strcmp(type, "date")) { - switch (num) { - case 0: - COPY_STR(str, "I18N_UDATE_FULL", strlen("I18N_UDATE_FULL")); - break; - case 1: - COPY_STR(str, "I18N_UDATE_LONG", strlen("I18N_UDATE_LONG")); - break; - case 2: - COPY_STR(str, "I18N_UDATE_MEDIUM", strlen("I18N_UDATE_MEDIUM")); - break; - case 3: - COPY_STR(str, "I18N_UDATE_SHORT", strlen("I18N_UDATE_SHORT")); - break; - case 4: - COPY_STR(str, "I18N_UDATE_RELATIVE", strlen("I18N_UDATE_RELATIVE")); - break; - case 5: - COPY_STR(str, "I18N_UDATE_LONG_RELATIVE", strlen("I18N_UDATE_LONG_RELATIVE")); - break; - case 6: - COPY_STR(str, "I18N_UDATE_MEDIUM_RELATIVE", strlen("I18N_UDATE_MEDIUM_RELATIVE")); - break; - case 7: - COPY_STR(str, "I18N_UDATE_SHORT_RELATIVE", strlen("I18N_UDATE_SHORT_RELATIVE")); - break; - case 8: - COPY_STR(str, "I18N_UDATE_NONE", strlen("I18N_UDATE_NONE")); - break; - default: - COPY_STR(str, "err", strlen("err")); - break; - } - } else if (!strcmp(type, "number_format")) { - switch (num) { - case 1: - COPY_STR(str, "I18N_UNUMBER_DECIMAL", strlen("I18N_UNUMBER_DECIMAL")); - break; - case 2: - COPY_STR(str, "I18N_UNUMBER_CURRENCY", strlen("I18N_UNUMBER_CURRENCY")); - break; - case 3: - COPY_STR(str, "I18N_UNUMBER_PERCENT", strlen("I18N_UNUMBER_PERCENT")); - break; - case 4: - COPY_STR(str, "I18N_UNUMBER_SCIENTIFIC", strlen("I18N_UNUMBER_SCIENTIFIC")); - break; - case 5: - COPY_STR(str, "I18N_UNUMBER_SPELLOUT", strlen("I18N_UNUMBER_SPELLOUT")); - break; - case 6: - COPY_STR(str, "I18N_UNUMBER_ORDINAL", strlen("I18N_UNUMBER_ORDINAL")); - break; - case 7: - COPY_STR(str, "I18N_UNUMBER_DURATION", strlen("I18N_UNUMBER_DURATION")); - break; - case 8: - COPY_STR(str, "I18N_UNUMBER_NUMBERING_SYSTEM", strlen("I18N_UNUMBER_NUMBERING_SYSTEM")); - break; - case 9: - COPY_STR(str, "I18N_UNUMBER_PATTERN_RULEBASED", strlen("I18N_UNUMBER_PATTERN_RULEBASED")); - break; - case 10: - COPY_STR(str, "I18N_UNUMBER_CURRENCY_ISO", strlen("I18N_UNUMBER_CURRENCY_ISO")); - break; - case 11: - COPY_STR(str, "I18N_UNUMBER_CURRENCY_PLURAL", strlen("I18N_UNUMBER_CURRENCY_PLURAL")); - break; - case 12: - COPY_STR(str, "I18N_UNUMBER_FORMAT_STYLE_COUNT", strlen("I18N_UNUMBER_FORMAT_STYLE_COUNT")); - break; - default: - COPY_STR(str, "err", strlen("err")); - break; - } - } else if (!strcmp(type, "symbol")) { - switch (num) { - case 1: - COPY_STR(str, "I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL")); - break; - case 2: - COPY_STR(str, "I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL")); - break; - case 3: - COPY_STR(str, "I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL")); - break; - case 4: - COPY_STR(str, "I18N_UNUMBER_PERCENT_SYMBOL", strlen("I18N_UNUMBER_PERCENT_SYMBOL")); - break; - case 5: - COPY_STR(str, "I18N_UNUMBER_ZERO_DIGIT_SYMBOL", strlen("I18N_UNUMBER_ZERO_DIGIT_SYMBOL")); - break; - case 6: - COPY_STR(str, "I18N_UNUMBER_DIGIT_SYMBOL", strlen("I18N_UNUMBER_DIGIT_SYMBOL")); - break; - case 7: - COPY_STR(str, "I18N_UNUMBER_MINUS_SIGN_SYMBOL", strlen("I18N_UNUMBER_MINUS_SIGN_SYMBOL")); - break; - case 8: - COPY_STR(str, "I18N_UNUMBER_PLUS_SIGN_SYMBOL", strlen("I18N_UNUMBER_PLUS_SIGN_SYMBOL")); - break; - case 9: - COPY_STR(str, "I18N_UNUMBER_CURRENCY_SYMBOL", strlen("I18N_UNUMBER_CURRENCY_SYMBOL")); - break; - case 10: - COPY_STR(str, "I18N_UNUMBER_INTL_CURRENCY_SYMBOL", strlen("I18N_UNUMBER_INTL_CURRENCY_SYMBOL")); - break; - case 11: - COPY_STR(str, "I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL")); - break; - case 12: - COPY_STR(str, "I18N_UNUMBER_EXPONENTIAL_SYMBOL", strlen("I18N_UNUMBER_EXPONENTIAL_SYMBOL")); - break; - case 13: - COPY_STR(str, "I18N_UNUMBER_PERMILL_SYMBOL", strlen("I18N_UNUMBER_PERMILL_SYMBOL")); - break; - case 14: - COPY_STR(str, "I18N_UNUMBER_PAD_ESCAPE_SYMBOL", strlen("I18N_UNUMBER_PAD_ESCAPE_SYMBOL")); - break; - case 15: - COPY_STR(str, "I18N_UNUMBER_INFINITY_SYMBOL", strlen("I18N_UNUMBER_INFINITY_SYMBOL")); - break; - case 16: - COPY_STR(str, "I18N_UNUMBER_NAN_SYMBOL", strlen("I18N_UNUMBER_NAN_SYMBOL")); - break; - case 17: - COPY_STR(str, "I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL")); - break; - case 18: - COPY_STR(str, "I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL")); - break; - case 19: - COPY_STR(str, "I18N_UNUMBER_ONE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_ONE_DIGIT_SYMBOL")); - break; - case 20: - COPY_STR(str, "I18N_UNUMBER_TWO_DIGIT_SYMBOL", strlen("I18N_UNUMBER_TWO_DIGIT_SYMBOL")); - break; - case 21: - COPY_STR(str, "I18N_UNUMBER_THREE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_THREE_DIGIT_SYMBOL")); - break; - case 22: - COPY_STR(str, "I18N_UNUMBER_FOUR_DIGIT_SYMBOL", strlen("I18N_UNUMBER_FOUR_DIGIT_SYMBOL")); - break; - case 23: - COPY_STR(str, "I18N_UNUMBER_FIVE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_FIVE_DIGIT_SYMBOL")); - break; - case 24: - COPY_STR(str, "I18N_UNUMBER_SIX_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SIX_DIGIT_SYMBOL")); - break; - case 25: - COPY_STR(str, "I18N_UNUMBER_SEVEN_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SEVEN_DIGIT_SYMBOL")); - break; - case 26: - COPY_STR(str, "I18N_UNUMBER_EIGHT_DIGIT_SYMBOL", strlen("I18N_UNUMBER_EIGHT_DIGIT_SYMBOL")); - break; - case 27: - COPY_STR(str, "I18N_UNUMBER_NINE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_NINE_DIGIT_SYMBOL")); - break; - default: - COPY_STR(str, "err", strlen("err")); - break; - } - } else if (!strcmp(type, "iter_type")) { - switch (num) { - case 0: - COPY_STR(str, "I18N_UBRK_CHARACTER", strlen("I18N_UBRK_CHARACTER")); - break; - case 1: - COPY_STR(str, "I18N_UBRK_WORD", strlen("I18N_UBRK_WORD")); - break; - case 2: - COPY_STR(str, "I18N_UBRK_LINE", strlen("I18N_UBRK_LINE")); - break; - case 3: - COPY_STR(str, "I18N_UBRK_SENTENCE", strlen("I18N_UBRK_SENTENCE")); - break; - default: - COPY_STR(str, "err", strlen("err")); - break; - } - } - PRINT_DEBUG_LOG("return string: %s\n", str); - return str; -} - -static char *_date_basic_format_convert(char *input_pattern, int i, char *type) -{ - i18n_udate_format_h format_h = NULL; - i18n_uchar timezone[BUF_SIZE] = {0,}; - i18n_ustring_copy_ua_n(timezone, default_locale, BUF_SIZE); - i18n_uchar pattern[BUF_SIZE] = {0,}; - i18n_ustring_copy_ua_n(pattern, input_pattern, BUF_SIZE); - error_code = i18n_udate_create(I18N_UDATE_PATTERN, I18N_UDATE_PATTERN, default_locale, timezone, -1, pattern, -1, &format_h); - - i18n_udate date_now = 259200000; - - if (!strcmp(type, "day")) date_now += i * 86400000; - else if (!strcmp(type, "month")) { - int k; - for (k = 0; k < i; k++) - date_now += 2678400000; - } else { - i18n_ucalendar_get_now(&date_now); - } - - i18n_uchar *result = (i18n_uchar *) malloc(BUF_SIZE * sizeof(i18n_uchar)); - int date_len = 0; - error_code = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len); - - char *s = (char *)malloc(BUF_SIZE * sizeof(char)); - i18n_ustring_copy_au(s, result); - i18n_udate_destroy(format_h); - free(result); - - PRINT_DEBUG_LOG("======%s\n", s); - return s; -} - -static int __get_date_basic_format() -{ - printf(" - To get basic date format\n"); - printf("****************************************\n"); - - char *f_narrow, *f_short, *f_long, *s_narrow, *s_short, *s_long; - int i; - - //Day - Formatting - printf(" Day - Formatting\n"); - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| # | %s | %s | %s \n", "Narrow Names" , "Short Names" , "Long Names"); - for (i = 0; i < 7; i++) { - f_narrow = _date_basic_format_convert("EEEEE", i, "day"); - f_short = _date_basic_format_convert("EEE", i, "day"); - f_long = _date_basic_format_convert("EEEE", i, "day"); - - printf("| %d | %s | %s | %s\n", i, f_narrow, f_short, f_long); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - //Day - stand-alone - printf(" Day - Stand-alone\n"); - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| # | %-s | %s | %s \n", "Narrow Names" , "Short Names" , "Long Names"); - for (i = 0; i < 7; i++) { - s_narrow = _date_basic_format_convert("ccccc", i, "day"); - s_short = _date_basic_format_convert("ccc", i, "day"); - s_long = _date_basic_format_convert("cccc", i, "day"); - - printf("| %d | %s | %s | %s\n", i, s_narrow, s_short, s_long); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - //Month - Formatting - printf(" Month - Formatting\n"); - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| # | %-s | %s | %s \n", "Narrow Names" , "Short Names" , "Long Names"); - for (i = 0; i < 12; i++) { - f_narrow = _date_basic_format_convert("MMMMM", i, "month"); - f_short = _date_basic_format_convert("MMM", i, "month"); - f_long = _date_basic_format_convert("MMMM", i, "month"); - - printf("| %-2d | %s | %s | %s\n", i, f_narrow, f_short, f_long); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - //Month - stand-alone - printf(" Month - Stand-alone\n"); - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| # | %s | %s | %s \n", "Narrow Names" , "Short Names" , "Long Names"); - - for (i = 0; i < 12; i++) { - s_narrow = _date_basic_format_convert("LLLLL", i, "month"); - s_short = _date_basic_format_convert("LLL", i, "month"); - s_long = _date_basic_format_convert("LLLL", i, "month"); - - printf("| %-2d | %s | %s | %s\n", i, s_narrow, s_short, s_long); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - return 0; -} - -i18n_udate _time_convert(char *input_time) -{ - i18n_ucalendar_h ucal; - i18n_udate date; - int ret = I18N_ERROR_NONE; - int year, month, day, hour, minute, second; - struct tm result; - - strptime(input_time, "%Y%m%d%H%M%S", &result); - if (result.tm_year >= 100) - result.tm_year = result.tm_year%100 + 2000; - 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); - - /*create i18n_ucalendar_h */ - ret = i18n_ucalendar_create(0, -1, NULL, I18N_UCALENDAR_DEFAULT, &ucal); - if (ret) { - printf("i18n_ucalendar_create failed.\n"); - return -1; - } - - /*set i18n_ucalendar_h's date */ - i18n_ucalendar_set_date_time(ucal, result.tm_year, result.tm_mon, result.tm_mday, result.tm_hour, result.tm_min, result.tm_sec); - i18n_ucalendar_get(ucal, I18N_UCALENDAR_YEAR, &year); - i18n_ucalendar_get(ucal, I18N_UCALENDAR_MONTH, &month); - i18n_ucalendar_get(ucal, I18N_UCALENDAR_DATE, &day); - i18n_ucalendar_get(ucal, I18N_UCALENDAR_HOUR, &hour); - i18n_ucalendar_get(ucal, I18N_UCALENDAR_MINUTE, &minute); - i18n_ucalendar_get(ucal, I18N_UCALENDAR_SECOND, &second); - 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); - /* get i18n_ucalendar's current time and converts it from milliseconds to seconds */ - i18n_ucalendar_get_milliseconds(ucal, &date); - - /* destroy i18n_ucalendar_h */ - i18n_ucalendar_destroy(ucal); - - return date; -} - -static int __get_date_and_time(char *input_time) -{ - printf(" - To get various date and time format\n"); - printf("****************************************\n"); - - i18n_udate date_now; - if (!input_time) { - int error_code = i18n_ucalendar_get_now(&date_now); - CHECK_ERROR("i18n_ucalendar_get_now", error_code); - PRINT_DEBUG_LOG("i18n_ucalendar_get_now = %lf\n", date_now); - } else { - date_now = _time_convert(input_time); - PRINT_DEBUG_LOG("_time_convert = %lf\n", date_now); - } - - i18n_udate_format_h format_h = NULL; - i18n_udatepg_h udatepg; - error_code = i18n_udatepg_create(default_locale, &udatepg); - CHECK_ERROR("i18n_udatepg_create", error_code); - - i18n_uchar format[BUF_SIZE]; - i18n_ustring_copy_ua_n(format, "ddMMMyyyyHHmmssz", BUF_SIZE); - - int pattern_len, len; - i18n_uchar pattern[BUF_SIZE], skeleton[BUF_SIZE]; - i18n_ustring_copy_ua(skeleton, I18N_UDATE_MONTH_DAY); - len = i18n_ustring_get_length(skeleton); - error_code = i18n_udatepg_get_best_pattern(udatepg, skeleton, len, pattern, BUF_SIZE, &pattern_len); - CHECK_ERROR("i18n_udatepg_get_best_pattern", error_code); - - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| %-17.17s | %-26.26s | %s \n", "TIME TYPE" , "DATE TYPE" , "OUTPUT"); - for (n_enum_date_counter = 0; n_enum_date_counter < n_date_enum_size; n_enum_date_counter++) { - for (n_enum_time_counter = 0; n_enum_time_counter < n_time_enum_size; n_enum_time_counter++) { - i18n_ustring_copy_ua_n(default_timezone_id, default_locale, BUF_SIZE); - error_code = i18n_udate_create(eTimeFormatStyle[n_enum_time_counter], - eDateFormatStyle[n_enum_date_counter], - default_locale, default_timezone_id, -1, pattern, -1, &format_h); - CHECK_ERROR("i18n_udate_create", error_code); - - i18n_uchar *result = (i18n_uchar *) malloc(BUF_SIZE * sizeof(i18n_uchar)); - int date_len; - error_code = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len); - CHECK_ERROR("i18n_udate_format_date", error_code); - - char s[BUF_SIZE]; - i18n_ustring_copy_au(s, result); - free(result); - - char *time_str, *date_str; - time_str = __print_i18n_type_string("time", n_enum_time_counter); - date_str = __print_i18n_type_string("date", n_enum_date_counter); - printf("| %-17.17s | %-26.26s | %s\n", time_str, date_str, s); - free(time_str); - free(date_str); - } - } - - PRINT_ASCIIDOC_LOG("|===\n"); - return 0; -} - -static int __get_number_format(char *input_number) -{ - printf(" - To get various number format\n"); - printf("****************************************\n"); - double my_number = atof(input_number); - PRINT_DEBUG_LOG("Input number = %f\n", my_number); - - i18n_unumber_format_h num_format = NULL; - i18n_uchar formatted_number[BUF_SIZE]; - - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| %-30.30s | %s\n", "NUMBER FORMAT" , "OUTPUT"); - - int i; - for (i = I18N_UNUMBER_DECIMAL; i <= I18N_UNUMBER_FORMAT_STYLE_COUNT; ++i) { - /* Create a number formatter. */ - int error_code = i18n_unumber_create(i, NULL, -1, default_locale, NULL, &num_format); - CHECK_ERROR("i18n_unumber_create", error_code); - - /* Format the given number according to the given locale. */ - memset(formatted_number, 0, BUF_SIZE); - i18n_unumber_format_double(num_format, my_number, formatted_number, BUF_SIZE, NULL); - - /* Display the formatting result. */ - char string[BUF_SIZE]; - i18n_ustring_copy_au(string, formatted_number); - - char *number_str; - number_str = __print_i18n_type_string("number_format", i); - printf("| %-30.30s | %s\n", number_str, string); - free(number_str); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - /* Release the decimal number formatter. */ - error_code = i18n_unumber_destroy(num_format); - CHECK_ERROR("i18n_unumber_destroy", error_code); - - return 0; -} - -static int __get_symbol() -{ - printf(" - To get various number symbol\n"); - printf("****************************************\n"); - - /* Create a default number formatter. */ - i18n_unumber_format_h num_format = NULL; - int error_code = i18n_unumber_create(I18N_UNUMBER_DEFAULT, NULL, -1, default_locale, NULL, &num_format); - CHECK_ERROR("18n_unumber_create", error_code); - - int i; - - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| %-47.47s | %s\n", "NUMBER SYMBOL" , "OUTPUT"); - for (i = 0; i < I18N_UNUMBER_FORMAT_SYMBOL_COUNT; ++i) { - /* Format the selected symbol according to the chosen locale. */ - int buf_len; - i18n_uchar u_buffer[BUF_SIZE]; - error_code = i18n_unumber_get_symbol(num_format, i, u_buffer, BUF_SIZE, &buf_len); - CHECK_ERROR("18n_unumber_get_symbol", error_code); - - /* Display the formatted symbol. */ - char string[BUF_SIZE]; - i18n_ustring_copy_au(string, u_buffer); - - char *symbol_str; - symbol_str = __print_i18n_type_string("symbol", i+1); - printf("| %-47.47s | %s\n", symbol_str, string); - free(symbol_str); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - /* Release the default number formatter object. */ - error_code = i18n_unumber_destroy(num_format); - CHECK_ERROR("i18n_unumber_destroy", error_code); - - return 0; -} - -static const char *layout_orientation_converter(i18n_ulocale_layout_type_e type) -{ - switch (type) { - case I18N_ULOCALE_LAYOUT_LTR: - return "LTR"; - - case I18N_ULOCALE_LAYOUT_RTL: - return "RTL"; - - case I18N_ULOCALE_LAYOUT_TTB: - return "TTB"; - - case I18N_ULOCALE_LAYOUT_BTT: - return "BTT"; - - default: - return "UNKNOWN"; - } -} - - -static int __get_language_info() -{ - printf(" - To get language information\n"); - printf("****************************************\n"); - - i18n_uchar lang[BUF_SIZE]; - - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| KEY | VALUE\n"); - - /* Get the default locale code */ - printf("| Default locale code | %s\n", default_locale); - - /* Get the display name of the selected locale. */ - i18n_uchar name[BUF_SIZE]; - int name_len; - - int error_code = - i18n_ulocale_get_display_name(default_locale, default_locale, name, BUF_SIZE, &name_len); - CHECK_ERROR("i18n_ulocale_get_display_name", error_code); - char name_ch[BUF_SIZE]; - i18n_ustring_copy_au(name_ch, name); - printf("| Language display name | %s\n", name_ch); - - - /* Get the language related to the selected locale. */ - i18n_ulocale_get_display_language(default_locale, default_locale, lang, BUF_SIZE); - - /* Get the string representation of the obtained language. */ - char language[BUF_SIZE]; - i18n_ustring_copy_au(language, lang); - printf("| Full name | %s\n", language); - - /* Get the obtained language code. */ - int32_t lang_len; - error_code = i18n_ulocale_get_language(default_locale, language, BUF_SIZE, &lang_len); - CHECK_ERROR("i18n_ulocale_get_language", error_code); - printf("| language code | %s\n", language); - - /* Get the ISO code of the selected locale. */ - const char *language_iso = i18n_ulocale_get_iso3_language(default_locale); - printf("| ISO code | %s\n", language_iso); - - /* Get the type of the line orientation related to the selected locale. */ - i18n_ulocale_layout_type_e type; - error_code = i18n_ulocale_get_line_orientation(default_locale, &type); - CHECK_ERROR("i18n_ulocale_get_line_orientation", error_code); - const char *orientation = layout_orientation_converter(type); - printf("| Line orientation | %s\n", orientation); - - /* Get the characters orientation related to the selected locale. */ - error_code = i18n_ulocale_get_character_orientation(default_locale, &type); - CHECK_ERROR("i18n_ulocale_get_character_orientation", error_code); - orientation = layout_orientation_converter(type); - printf("| Characters orientation | %s\n", orientation); - - /* Get the variant code related to the selected locale. */ - char variant[BUF_SIZE]; - error_code = i18n_ulocale_get_variant(default_locale, variant, BUF_SIZE); - CHECK_ERROR("i18n_ulocale_get_variant", error_code); - printf("| variant code | %s\n", variant); - PRINT_ASCIIDOC_LOG("|===\n"); - - return 0; -} - -static int __manage_string_iteration(char *input_string) -{ - printf(" - To manage the string iteration\n"); - printf("****************************************\n"); - - PRINT_DEBUG_LOG("Input string : %s\n", input_string); - i18n_uchar *string_to_examine; - i18n_ubreak_iterator_h boundary; - - if (!input_string) { - char *input_text = "Twinkle, twinkle, little star. How I wonder what you are"; - printf("\nInput string : %s\n", input_text); - string_to_examine = - (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); - i18n_ustring_copy_ua(string_to_examine, input_text); - } else { - char input_text[1000] = {0,}; - COPY_STR(input_text, input_string, 999); - printf("Input string : %s\n", input_text); - string_to_examine = - (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); - i18n_ustring_copy_ua(string_to_examine, input_text); - } - - int i; - char *iter_type; - - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| %-19.19s | %s\n", "ITER First", "VALUE"); - - /* Displays the first element in the given text */ - for (i = 0; i <= I18N_UBRK_SENTENCE; i++) { - iter_type = NULL; - error_code = i18n_ubrk_create(i, default_locale, string_to_examine, -1, &boundary); - CHECK_ERROR("i18n_ubrk_create", error_code); - int32_t start = i18n_ubrk_first(boundary); - int32_t end = i18n_ubrk_next(boundary); - i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1)); - result[end - start] = '\0'; - i18n_ustring_copy_n(result, &string_to_examine[start], end-start); - char str[BUF_SIZE]; - i18n_ustring_copy_au(str, result); - free(result); - - iter_type = __print_i18n_type_string("iter_type", i); - printf("| %-19.19s | %s\n", iter_type, str); - free(iter_type); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - printf("\n"); - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| %-19.19s | %s\n", "ITER Last", "VALUE"); - /* Displays the last element in the given text */ - for (i = 0; i <= I18N_UBRK_SENTENCE; i++) { - iter_type = NULL; - error_code = i18n_ubrk_create(i, default_locale, string_to_examine, -1, &boundary); - CHECK_ERROR("i18n_ubrk_create", error_code); - int32_t end = i18n_ubrk_last(boundary); - int32_t start = i18n_ubrk_previous(boundary); - i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1)); - result[end - start] = '\0'; - i18n_ustring_copy_n(result, &string_to_examine[start], end-start); - char str[BUF_SIZE]; - i18n_ustring_copy_au(str, result); - free(result); - - iter_type = __print_i18n_type_string("iter_type", i); - printf("| %-19.19s | %s\n", iter_type, str); - free(iter_type); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - free(string_to_examine); - error_code = i18n_ubrk_destroy(boundary); - CHECK_ERROR("i18n_ubrk_destroy", error_code); - - return 0; -} - -static int __analyze_string(char *custom_string) -{ - printf(" - To manage the string\n"); - printf("****************************************\n"); - - i18n_uchar *string_to_examine; - - if (!custom_string) { - char *input_text = "String"; - printf("\n Input string : %s\n", input_text); - string_to_examine = - (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); - i18n_ustring_copy_ua(string_to_examine, input_text); - } else { - char *input_text = custom_string; - printf("\n Input string : %s\n", input_text); - string_to_examine = - (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); - i18n_ustring_copy_ua(string_to_examine, input_text); - } - - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| KEY | VALUE\n"); - - /* Get length */ - int32_t len = i18n_ustring_get_length(string_to_examine); - printf("| Length | %d\n", len); - - /* To upper */ - i18n_uchar dest[BUF_SIZE + 1]; - i18n_ustring_to_upper(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code); - CHECK_ERROR("i18n_ustring_to_upper", error_code); - - char s[BUF_SIZE]; - i18n_ustring_copy_au(s, dest); - printf("| TO UPPER | %s\n", s); - - /* To lower */ - i18n_ustring_to_lower(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code); - CHECK_ERROR("i18n_ustring_to_lower", error_code); - i18n_ustring_copy_au(s, dest); - printf("| to lower | %s\n", s); - - /* To title */ - i18n_ustring_to_title_new(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, NULL); - CHECK_ERROR("i18n_ustring_to_title_new", error_code); - i18n_ustring_copy_au(s, dest); - printf("| To Title | %s\n", s); - - PRINT_ASCIIDOC_LOG("|===\n"); - - return 0; -} - -static int __get_timezone_info() -{ - printf(" - To get time zone information\n"); - printf("****************************************\n"); - - static i18n_timezone_h tmz; - - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| KEY | VALUE\n"); - - /* Get the default timezone. */ - error_code = i18n_timezone_create_default(&tmz); - CHECK_ERROR("18n_timezone_create_default", error_code); - - /* Get the display name of the default timezone. */ - char *display_name; - error_code = i18n_timezone_get_display_name(tmz, &display_name); - CHECK_ERROR("i18n_timezone_get_display_name", error_code); - printf("| Current timezone | %s\n", display_name); - - /* Get the selected timezone ID. */ - char *timezone_id; - error_code = i18n_timezone_get_id(tmz, &timezone_id); - CHECK_ERROR("i18n_timezone_get_id", error_code); - printf("| Timezone ID | %s\n", timezone_id); - - /* Check whether the selected time zone uses daylight savings time or not. */ - i18n_ubool daylight_time; - error_code = i18n_timezone_use_daylight_time(tmz, &daylight_time); - CHECK_ERROR("i18n_timezone_use_daylight_time", error_code); - printf("| Uses DST | %s\n", daylight_time ? "yes" : "no"); - - /* - * Get the amount of time that need to be added to the - * local standard time to get the local wall clock time. - */ - int32_t dst_savings; - error_code = i18n_timezone_get_dst_savings(tmz, &dst_savings); - CHECK_ERROR("i18n_timezone_get_dst_savings", error_code); - printf("| DST savings in [min] | %d\n", dst_savings / MS_TO_MIN); - - /* Get the selected time zone raw GMT offset. */ - int32_t offset_milliseconds; - error_code = i18n_timezone_get_raw_offset(tmz, &offset_milliseconds); - CHECK_ERROR("i18n_timezone_get_raw_offset", error_code); - if (offset_milliseconds / MS_TO_HOUR > 0) - printf("| Raw GMT offset | GMT +%d\n", offset_milliseconds / MS_TO_HOUR); - else - printf("| Raw GMT offset | GMT %d\n", offset_milliseconds / MS_TO_HOUR); - - /* Get the region code associated with the selected time zone. */ - char region[BUF_SIZE]; - int32_t region_len = -1; - error_code = i18n_timezone_get_region(timezone_id, region, ®ion_len, BUF_SIZE); - CHECK_ERROR("i18n_timezone_get_region", error_code); - printf("| Associated region code | %s\n", region); - - PRINT_ASCIIDOC_LOG("|===\n"); - - /* Release the time zone object. */ - error_code = i18n_timezone_destroy(tmz); - CHECK_ERROR("i18n_timezone_destroy", error_code); - free(timezone_id); - - return 0; - -} - -static int __get_tzdata_version() -{ - const char *ver = i18n_timezone_get_tzdata_version(); - printf("tzdata version : %s\n", ver); - printf("****************************************\n"); - - return 0; -} - -static int32_t _get_uchar_length(const char *arr) -{ - int32_t ulen = strlen(arr); - i18n_uchar _text[ulen + 1]; - i18n_ustring_copy_ua(_text, arr); - - return i18n_ustring_get_length(_text); -} - -static int __show_ubidi(char *input_text) -{ - printf(" - Examples of the Unicode Bidirectional Algorithm\n"); - printf(" - input text : %s\n", input_text ? input_text : "Samsung is ﺱﺎﻤﺳﻮﻨﺟ in Arabic."); - printf("****************************************\n"); - - int i, j; - const char* text; - static i18n_ubidi_h ubidi; - i18n_ubidi_create(&ubidi); - - if (!input_text) { - text = "Samsung is سامسونج in Arabic"; - } else { - text = input_text; - } - - PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); - PRINT_ASCIIDOC_LOG("|===\n"); - printf("| %-46.46s | %-34.34s | %s \n", "MODES", "OPTIONS", "OUTPUT"); - - for (i = 0; i < N_MODES; i++) { - /* Sets ubidi reordering mode */ - int error_code = i18n_ubidi_set_reordering_mode(ubidi, reordering_modes[i].mode); - CHECK_ERROR("i18n_ubidi_set_reordering_mode", error_code); - - /* Sets ubidi paragraphs and perform the Unicode bidi algorithm */ - int src_length = _get_uchar_length(text); - PRINT_DEBUG_LOG("src_length: %d\n", src_length); - - i18n_uchar *src = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (src_length + 1)); - i18n_ustring_copy_ua(src, text); - error_code = i18n_ubidi_set_para(ubidi, src, src_length, I18N_UBIDI_DEFAULT_LTR, NULL); - - /* Writes ubidi reordered text to the entry with write_options */ - i18n_uchar dst[BUF_SIZE]; - int output_length = 0; - - for (j = 0; j < N_OPTIONS; j++) { - error_code = i18n_ubidi_write_reordered(ubidi, reordering_options[j].option, BUF_SIZE, - dst, &output_length); - CHECK_ERROR("i18n_ubidi_write_reordered", error_code); - - char buffer[BUF_SIZE]; - i18n_ustring_copy_au(buffer, dst); - printf("| %-46.46s | %-34.34s | %s \n", reordering_modes[i].display_name, reordering_options[j].display_name, buffer); - } - free(src); - } - PRINT_ASCIIDOC_LOG("|===\n"); - - if (ubidi != NULL) { - i18n_ubidi_destroy(ubidi); - ubidi = NULL; - } - - return 0; -} - -void allTest() -{ - int ret = 0, i = 0; - int loc_count; - - loc_count = i18n_ulocale_count_available(); - for (i = 0; i < loc_count; i++) { - default_locale = i18n_ulocale_get_available(i); - printf("\n== Date and Time Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_date_and_time(NULL); - printf("\n"); - printf("\n== Number Format Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_number_format("3.5"); - printf("\n"); - printf("\n== Number Symbol Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_symbol(); - printf("\n"); - printf("\n== Language Info"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_language_info(); - printf("\n"); - } - - printf("\n== String Iteration Test"); - printf("\n****************************************\n"); - ret = __manage_string_iteration(NULL); - printf("\n"); - - printf("\n== String Test"); - printf("\n****************************************\n"); - ret = __analyze_string(NULL); - printf("\n"); - printf("\n== Timezone Info"); - printf("\n****************************************\n"); - ret = __get_timezone_info(); - printf("\n"); - - printf("\n== TZ Data Version Info"); - printf("\n****************************************\n"); - ret = __get_tzdata_version(); - if (ret == -1) { - printf("get i18n time zone info list failed\n"); - } -} - -void showAllLocale() -{ - __get_available_locales(); -} - -void showLangInfo(char *locale) -{ - int ret = 0, i = 0; - int loc_count; - - if (!locale) { - loc_count = i18n_ulocale_count_available(); - for (i = 0; i < loc_count; i++) { - default_locale = i18n_ulocale_get_available(i); - printf("\n== Language Info"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_language_info(); - } - if (ret == -1) { - printf("get i18n language info list failed\n"); - } - } else { - default_locale = locale; - printf("\n== Language Info"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_language_info(); - if (ret == -1) { - printf("get i18n language info list failed\n"); - } - } -} - -void showTimezone() -{ - int ret = 0; - printf("\n== Timezone Info"); - printf("\n****************************************\n"); - ret = __get_timezone_info(); - if (ret == -1) { - printf("get i18n time zone info list failed\n"); - } -} - -void showTzdataVersion() -{ - printf("\n== TZ Data Version Info"); - printf("\n****************************************\n"); - __get_tzdata_version(); -} - -void showUbidi(char *input) -{ - printf("\n== Show Ubidi"); - printf("\n****************************************\n"); - __show_ubidi(input); -} - -void showDatentimeFormat(char *locale) -{ - int ret = 0, i = 0; - int loc_count; - - if (!locale) { - loc_count = i18n_ulocale_count_available(); - for (i = 0; i < loc_count; i++) { - default_locale = i18n_ulocale_get_available(i); - printf("\n== Show Date basic format"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_date_basic_format(); - } - if (ret == -1) { - printf("get i18n date and time basic format list failed\n"); - } - } else { - default_locale = locale; - printf("\n== Show Date basic format"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_date_basic_format(); - if (ret == -1) { - printf("get i18n date and time basic format list failed\n"); - } - } -} - -void testDatentime(char *input, char *locale) -{ - int ret = 0, i = 0; - int loc_count; - - if (!locale) { - loc_count = i18n_ulocale_count_available(); - for (i = 0; i < loc_count; i++) { - default_locale = i18n_ulocale_get_available(i); - printf("\n== Date and Time Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_date_and_time(input); - } - if (ret == -1) { - printf("get i18n date and time list failed\n"); - } - } else { - default_locale = locale; - printf("\n== Date and Time Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_date_and_time(input); - if (ret == -1) { - printf("get i18n date and time list failed\n"); - } - - } -} - -void testNumberFormat(char *input, char *locale) -{ - int ret = 0, i = 0; - int loc_count; - - if (!input) { - - } else { - if (!locale) { - loc_count = i18n_ulocale_count_available(); - for (i = 0; i < loc_count; i++) { - default_locale = i18n_ulocale_get_available(i); - printf("\n== Number Format Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_number_format(input); - } - if (ret == -1) { - printf("get number format list failed\n"); - } - } else { - default_locale = locale; - printf("\n== Number Format Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_number_format(input); - if (ret == -1) { - printf("get number format list failed\n"); - } - } - } -} - -void testNumberSymbol(char *locale) -{ - int ret = 0, i = 0; - int loc_count; - - if (!locale) { - loc_count = i18n_ulocale_count_available(); - for (i = 0; i < loc_count; i++) { - default_locale = i18n_ulocale_get_available(i); - printf("\n== Number Symbol Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_symbol(); - } - if (ret == -1) { - printf("get i18n symbol list failed\n"); - } - } else { - default_locale = locale; - printf("\n== Number Symbol Test"); - printf("\n****************************************"); - printf("\n - locales : %s\n", default_locale); - ret = __get_symbol(); - if (ret == -1) { - printf("get i18n symbol list failed\n"); - } - } -} - -void testString(char *input) -{ - int ret = 0; - - printf("\n== String Test"); - printf("\n****************************************\n"); - ret = __analyze_string(input); - if (ret == -1) { - printf("get i18n string list failed\n"); - } -} - -void testStringIter(char *input) -{ - int ret = 0; - - printf("\n== String Iteration Test"); - printf("\n****************************************\n"); - ret = __manage_string_iteration(input); - if (ret == -1) { - printf("get i18n string iteration list failed\n"); - } -} - -int main(int argc, char *argv[]) -{ - struct arguments arguments = {0,}; - - init_env(); - argp_parse(&argp, argc, argv, 0, 0, &arguments); - - if (arguments.all) { - memset(&arguments, 0x00, sizeof(arguments)); - - allTest(); - } - - if (arguments.showAllLocale) { - showAllLocale(); - } - - if (arguments.showLangInfo) { - showLangInfo(arguments.setLocale); - } - - if (arguments.showDateFormat) { - showDatentimeFormat(arguments.setLocale); - } - - if (arguments.testDatentime) { - testDatentime(arguments.testTimeArg, arguments.setLocale); - } - - if (arguments.testNumberFormat) { - testNumberFormat(arguments.testNumberFormatArg, arguments.setLocale); - } - - if (arguments.testNumberSymbol) { - testNumberSymbol(arguments.setLocale); - } - - if (arguments.testString) { - testString(arguments.testStringArg); - } - - if (arguments.testStringIter) { - testStringIter(arguments.testStringIterArg); - } - - if (arguments.showTimezone) { - showTimezone(); - } - - if (arguments.showTzdataVersion) { - showTzdataVersion(); - } - - if (arguments.showUbidi) { - showUbidi(arguments.testTextArg); - } - - return 0; -} diff --git a/i18ninfo/i18ninfo.cpp b/i18ninfo/i18ninfo.cpp new file mode 100644 index 0000000..e07bd23 --- /dev/null +++ b/i18ninfo/i18ninfo.cpp @@ -0,0 +1,1331 @@ +#define _GNU_SOURCE 1 +#include +#include +#include +#include +#include +#include +#include "i18ninfo_argp.h" + +#include + +#define DEBUG_FLAG 0 +static int ASCIIDOC_FLAG = 0; + +#define BUF_SIZE 1000 +#define MS_TO_MIN 60000 +#define MS_TO_HOUR 3600000 + +#define PRINT_ERROR_LOG(func_name, error_code) if (DEBUG_FLAG) { \ + fprintf(stderr, "\033[0;31m%s failed! Error: %s [code: %d] \033[0m\n", \ + func_name, get_error_message(error_code), error_code); \ + } + +#define PRINT_DEBUG_LOG(fmt, arg...) if (DEBUG_FLAG) { do {\ + fprintf(stdout, "\033[0;32m" fmt "\033[1;32m \033[0m", ##arg); } while (0); \ + } + +#define CHECK_ERROR(fun_name, error_code) if (error_code != 0) { \ + PRINT_ERROR_LOG(fun_name, error_code); \ + } + +#define COPY_STR(dst, src, dst_len) do { \ + strncpy((dst), (src), (dst_len + 1)); \ + (dst)[(dst_len)] = '\0'; \ +} while (0) + +#define PRINT_ASCIIDOC_LOG(fmt) if (ASCIIDOC_FLAG) printf(fmt) + +const char *default_locale = I18N_ULOCALE_UK; +i18n_uchar default_timezone_id[BUF_SIZE] = {0, }; + +i18n_udate_format_style_e eTimeFormatStyle[] = { + I18N_UDATE_FULL, + I18N_UDATE_LONG, + I18N_UDATE_MEDIUM, + I18N_UDATE_SHORT, + I18N_UDATE_NONE +}; + +i18n_udate_format_style_e eDateFormatStyle[] = { + I18N_UDATE_FULL, + I18N_UDATE_LONG, + I18N_UDATE_MEDIUM, + I18N_UDATE_SHORT, + I18N_UDATE_RELATIVE, + I18N_UDATE_LONG_RELATIVE, + I18N_UDATE_MEDIUM_RELATIVE, + I18N_UDATE_SHORT_RELATIVE, + I18N_UDATE_NONE +}; + +typedef struct { + const char *display_name; + uint16_t option; +} reordering_option; + +#define N_OPTIONS 5 + +static reordering_option reordering_options[N_OPTIONS] = { + {"I18N_UBIDI_KEEP_BASE_COMBINING", I18N_UBIDI_KEEP_BASE_COMBINING}, + {"I18N_UBIDI_DO_MIRRORING", I18N_UBIDI_DO_MIRRORING}, + {"I18N_UBIDI_INSERT_LRM_FOR_NUMERIC", I18N_UBIDI_INSERT_LRM_FOR_NUMERIC}, + {"I18N_UBIDI_REMOVE_BIDI_CONTROLS", I18N_UBIDI_REMOVE_BIDI_CONTROLS}, + {"I18N_UBIDI_OUTPUT_REVERSE", I18N_UBIDI_OUTPUT_REVERSE}, +}; + +typedef struct { + const char *display_name; + i18n_ubidi_reordering_mode_e mode; +} reordering_mode; + +#define N_MODES I18N_UBIDI_REORDER_COUNT + +static reordering_mode reordering_modes[N_MODES] = { + {"I18N_UBIDI_REORDER_DEFAULT", I18N_UBIDI_REORDER_DEFAULT}, + {"I18N_UBIDI_REORDER_NUMBERS_SPECIAL", I18N_UBIDI_REORDER_NUMBERS_SPECIAL}, + {"I18N_UBIDI_REORDER_GROUP_NUMBERS_WITH_R", I18N_UBIDI_REORDER_GROUP_NUMBERS_WITH_R}, + {"I18N_UBIDI_REORDER_RUNS_ONLY", I18N_UBIDI_REORDER_RUNS_ONLY}, + {"I18N_UBIDI_REORDER_INVERSE_NUMBERS_AS_L", I18N_UBIDI_REORDER_INVERSE_NUMBERS_AS_L}, + {"I18N_UBIDI_REORDER_INVERSE_LIKE_DIRECT", I18N_UBIDI_REORDER_INVERSE_LIKE_DIRECT}, + {"I18N_UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL", I18N_UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL} +}; + +int n_date_enum_size = sizeof(eDateFormatStyle) / sizeof(eDateFormatStyle[0]); +int n_time_enum_size = sizeof(eTimeFormatStyle) / sizeof(eTimeFormatStyle[0]); + +int n_enum_time_counter, n_enum_date_counter; +i18n_error_code_e error_code; + + +static void __get_available_locales(); +static int __get_date_basic_format(); +static int __get_date_and_time(char *input_time); +static int __get_number_format(char *input_number); +static int __get_symbol(); +static int __get_language_info(); +static int __manage_string_iteration(char *custom_type); +static int __analyze_string(char *custom_string); +static int __get_timezone_info(); +static int __get_tzdata_version(); + +char *__print_i18n_type_string(char *type, int num); + +static void __get_available_locales() +{ + const char *loc_list; + int32_t loc_count, i; + + loc_count = i18n_ulocale_count_available(); + if (loc_count == 0) { + printf("empty\n"); + } else if (loc_count < 0) { + printf("wrong\n"); + } else { + PRINT_DEBUG_LOG("locale count : %d\n", loc_count); + for (i = 0; i < loc_count; i++) { + loc_list = i18n_ulocale_get_available(i); + printf("%s\n", loc_list); + } + } +} + +static void init_env() +{ + + char *env_buf; + + env_buf = getenv("ASCIIDOC_FLAG"); + if (env_buf != NULL && strcmp(env_buf, "true") == 0) { + ASCIIDOC_FLAG = 1; + } +} + +char *__print_i18n_type_string(char *type, int num) +{ + char *str = (char*)calloc(300, sizeof(char)); + PRINT_DEBUG_LOG("input type: %s, num: %d\n", type, num); + if (!strcmp(type, "time")) { + switch (num) { + case 0: + COPY_STR(str, "I18N_UDATE_FULL", strlen("I18N_UDATE_FULL")); + break; + case 1: + COPY_STR(str, "I18N_UDATE_LONG", strlen("I18N_UDATE_LONG")); + break; + case 2: + COPY_STR(str, "I18N_UDATE_MEDIUM", strlen("I18N_UDATE_MEDIUM")); + break; + case 3: + COPY_STR(str, "I18N_UDATE_SHORT", strlen("I18N_UDATE_SHORT")); + break; + case 4: + COPY_STR(str, "I18N_UDATE_NONE", strlen("I18N_UDATE_NONE")); + break; + default: + COPY_STR(str, "err", strlen("err")); + break; + } + } else if (!strcmp(type, "date")) { + switch (num) { + case 0: + COPY_STR(str, "I18N_UDATE_FULL", strlen("I18N_UDATE_FULL")); + break; + case 1: + COPY_STR(str, "I18N_UDATE_LONG", strlen("I18N_UDATE_LONG")); + break; + case 2: + COPY_STR(str, "I18N_UDATE_MEDIUM", strlen("I18N_UDATE_MEDIUM")); + break; + case 3: + COPY_STR(str, "I18N_UDATE_SHORT", strlen("I18N_UDATE_SHORT")); + break; + case 4: + COPY_STR(str, "I18N_UDATE_RELATIVE", strlen("I18N_UDATE_RELATIVE")); + break; + case 5: + COPY_STR(str, "I18N_UDATE_LONG_RELATIVE", strlen("I18N_UDATE_LONG_RELATIVE")); + break; + case 6: + COPY_STR(str, "I18N_UDATE_MEDIUM_RELATIVE", strlen("I18N_UDATE_MEDIUM_RELATIVE")); + break; + case 7: + COPY_STR(str, "I18N_UDATE_SHORT_RELATIVE", strlen("I18N_UDATE_SHORT_RELATIVE")); + break; + case 8: + COPY_STR(str, "I18N_UDATE_NONE", strlen("I18N_UDATE_NONE")); + break; + default: + COPY_STR(str, "err", strlen("err")); + break; + } + } else if (!strcmp(type, "number_format")) { + switch (num) { + case 1: + COPY_STR(str, "I18N_UNUMBER_DECIMAL", strlen("I18N_UNUMBER_DECIMAL")); + break; + case 2: + COPY_STR(str, "I18N_UNUMBER_CURRENCY", strlen("I18N_UNUMBER_CURRENCY")); + break; + case 3: + COPY_STR(str, "I18N_UNUMBER_PERCENT", strlen("I18N_UNUMBER_PERCENT")); + break; + case 4: + COPY_STR(str, "I18N_UNUMBER_SCIENTIFIC", strlen("I18N_UNUMBER_SCIENTIFIC")); + break; + case 5: + COPY_STR(str, "I18N_UNUMBER_SPELLOUT", strlen("I18N_UNUMBER_SPELLOUT")); + break; + case 6: + COPY_STR(str, "I18N_UNUMBER_ORDINAL", strlen("I18N_UNUMBER_ORDINAL")); + break; + case 7: + COPY_STR(str, "I18N_UNUMBER_DURATION", strlen("I18N_UNUMBER_DURATION")); + break; + case 8: + COPY_STR(str, "I18N_UNUMBER_NUMBERING_SYSTEM", strlen("I18N_UNUMBER_NUMBERING_SYSTEM")); + break; + case 9: + COPY_STR(str, "I18N_UNUMBER_PATTERN_RULEBASED", strlen("I18N_UNUMBER_PATTERN_RULEBASED")); + break; + case 10: + COPY_STR(str, "I18N_UNUMBER_CURRENCY_ISO", strlen("I18N_UNUMBER_CURRENCY_ISO")); + break; + case 11: + COPY_STR(str, "I18N_UNUMBER_CURRENCY_PLURAL", strlen("I18N_UNUMBER_CURRENCY_PLURAL")); + break; + case 12: + COPY_STR(str, "I18N_UNUMBER_FORMAT_STYLE_COUNT", strlen("I18N_UNUMBER_FORMAT_STYLE_COUNT")); + break; + default: + COPY_STR(str, "err", strlen("err")); + break; + } + } else if (!strcmp(type, "symbol")) { + switch (num) { + case 1: + COPY_STR(str, "I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL")); + break; + case 2: + COPY_STR(str, "I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL")); + break; + case 3: + COPY_STR(str, "I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL")); + break; + case 4: + COPY_STR(str, "I18N_UNUMBER_PERCENT_SYMBOL", strlen("I18N_UNUMBER_PERCENT_SYMBOL")); + break; + case 5: + COPY_STR(str, "I18N_UNUMBER_ZERO_DIGIT_SYMBOL", strlen("I18N_UNUMBER_ZERO_DIGIT_SYMBOL")); + break; + case 6: + COPY_STR(str, "I18N_UNUMBER_DIGIT_SYMBOL", strlen("I18N_UNUMBER_DIGIT_SYMBOL")); + break; + case 7: + COPY_STR(str, "I18N_UNUMBER_MINUS_SIGN_SYMBOL", strlen("I18N_UNUMBER_MINUS_SIGN_SYMBOL")); + break; + case 8: + COPY_STR(str, "I18N_UNUMBER_PLUS_SIGN_SYMBOL", strlen("I18N_UNUMBER_PLUS_SIGN_SYMBOL")); + break; + case 9: + COPY_STR(str, "I18N_UNUMBER_CURRENCY_SYMBOL", strlen("I18N_UNUMBER_CURRENCY_SYMBOL")); + break; + case 10: + COPY_STR(str, "I18N_UNUMBER_INTL_CURRENCY_SYMBOL", strlen("I18N_UNUMBER_INTL_CURRENCY_SYMBOL")); + break; + case 11: + COPY_STR(str, "I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL")); + break; + case 12: + COPY_STR(str, "I18N_UNUMBER_EXPONENTIAL_SYMBOL", strlen("I18N_UNUMBER_EXPONENTIAL_SYMBOL")); + break; + case 13: + COPY_STR(str, "I18N_UNUMBER_PERMILL_SYMBOL", strlen("I18N_UNUMBER_PERMILL_SYMBOL")); + break; + case 14: + COPY_STR(str, "I18N_UNUMBER_PAD_ESCAPE_SYMBOL", strlen("I18N_UNUMBER_PAD_ESCAPE_SYMBOL")); + break; + case 15: + COPY_STR(str, "I18N_UNUMBER_INFINITY_SYMBOL", strlen("I18N_UNUMBER_INFINITY_SYMBOL")); + break; + case 16: + COPY_STR(str, "I18N_UNUMBER_NAN_SYMBOL", strlen("I18N_UNUMBER_NAN_SYMBOL")); + break; + case 17: + COPY_STR(str, "I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL")); + break; + case 18: + COPY_STR(str, "I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL", strlen("I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL")); + break; + case 19: + COPY_STR(str, "I18N_UNUMBER_ONE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_ONE_DIGIT_SYMBOL")); + break; + case 20: + COPY_STR(str, "I18N_UNUMBER_TWO_DIGIT_SYMBOL", strlen("I18N_UNUMBER_TWO_DIGIT_SYMBOL")); + break; + case 21: + COPY_STR(str, "I18N_UNUMBER_THREE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_THREE_DIGIT_SYMBOL")); + break; + case 22: + COPY_STR(str, "I18N_UNUMBER_FOUR_DIGIT_SYMBOL", strlen("I18N_UNUMBER_FOUR_DIGIT_SYMBOL")); + break; + case 23: + COPY_STR(str, "I18N_UNUMBER_FIVE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_FIVE_DIGIT_SYMBOL")); + break; + case 24: + COPY_STR(str, "I18N_UNUMBER_SIX_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SIX_DIGIT_SYMBOL")); + break; + case 25: + COPY_STR(str, "I18N_UNUMBER_SEVEN_DIGIT_SYMBOL", strlen("I18N_UNUMBER_SEVEN_DIGIT_SYMBOL")); + break; + case 26: + COPY_STR(str, "I18N_UNUMBER_EIGHT_DIGIT_SYMBOL", strlen("I18N_UNUMBER_EIGHT_DIGIT_SYMBOL")); + break; + case 27: + COPY_STR(str, "I18N_UNUMBER_NINE_DIGIT_SYMBOL", strlen("I18N_UNUMBER_NINE_DIGIT_SYMBOL")); + break; + default: + COPY_STR(str, "err", strlen("err")); + break; + } + } else if (!strcmp(type, "iter_type")) { + switch (num) { + case 0: + COPY_STR(str, "I18N_UBRK_CHARACTER", strlen("I18N_UBRK_CHARACTER")); + break; + case 1: + COPY_STR(str, "I18N_UBRK_WORD", strlen("I18N_UBRK_WORD")); + break; + case 2: + COPY_STR(str, "I18N_UBRK_LINE", strlen("I18N_UBRK_LINE")); + break; + case 3: + COPY_STR(str, "I18N_UBRK_SENTENCE", strlen("I18N_UBRK_SENTENCE")); + break; + default: + COPY_STR(str, "err", strlen("err")); + break; + } + } + PRINT_DEBUG_LOG("return string: %s\n", str); + return str; +} + +static char *_date_basic_format_convert(char *input_pattern, int i, char *type) +{ + + int ret = 0; + i18n_udate_format_h format_h = NULL; + i18n_uchar timezone[BUF_SIZE] = {0, }; + i18n_ustring_copy_ua_n(timezone, default_locale, BUF_SIZE); + i18n_uchar pattern[BUF_SIZE] = {0, }; + i18n_ustring_copy_ua_n(pattern, input_pattern, BUF_SIZE); + ret = i18n_udate_create(I18N_UDATE_PATTERN, I18N_UDATE_PATTERN, default_locale, timezone, -1, pattern, -1, &format_h); + + i18n_udate date_now = 259200000; + + if (!strcmp(type, "day")) { + date_now += i * 86400000; + } else if (!strcmp(type, "month")) { + int k; + for (k = 0; k < i; k++) + date_now += 2678400000; + } else { + i18n_ucalendar_get_now(&date_now); + } + + i18n_uchar *result = (i18n_uchar *) malloc(BUF_SIZE * sizeof(i18n_uchar)); + int date_len = 0; + ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len); + + char *s = (char *)malloc(BUF_SIZE * sizeof(char)); + i18n_ustring_copy_au(s, result); + i18n_udate_destroy(format_h); + free(result); + + PRINT_DEBUG_LOG("======%s\n", s); + return s; +} + +static int __get_date_basic_format() +{ + printf(" - To get basic date format\n"); + printf("****************************************\n"); + + char *f_narrow, *f_short, *f_long, *s_narrow, *s_short, *s_long; + int i; + + //Day - Formatting + printf(" Day - Formatting\n"); + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| # | %s | %s | %s \n", "Narrow Names" , "Short Names" , "Long Names"); + for (i = 0; i < 7; i++) { + f_narrow = _date_basic_format_convert("EEEEE", i, "day"); + f_short = _date_basic_format_convert("EEE", i, "day"); + f_long = _date_basic_format_convert("EEEE", i, "day"); + + printf("| %d | %s | %s | %s\n", i, f_narrow, f_short, f_long); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + //Day - stand-alone + printf(" Day - Stand-alone\n"); + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| # | %-s | %s | %s \n", "Narrow Names" , "Short Names" , "Long Names"); + for (i = 0; i < 7; i++) { + s_narrow = _date_basic_format_convert("ccccc", i, "day"); + s_short = _date_basic_format_convert("ccc", i, "day"); + s_long = _date_basic_format_convert("cccc", i, "day"); + + printf("| %d | %s | %s | %s\n", i, s_narrow, s_short, s_long); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + //Month - Formatting + printf(" Month - Formatting\n"); + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| # | %-s | %s | %s \n", "Narrow Names" , "Short Names" , "Long Names"); + for (i = 0; i < 12; i++) { + f_narrow = _date_basic_format_convert("MMMMM", i, "month"); + f_short = _date_basic_format_convert("MMM", i, "month"); + f_long = _date_basic_format_convert("MMMM", i, "month"); + + printf("| %-2d | %s | %s | %s\n", i, f_narrow, f_short, f_long); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + //Month - stand-alone + printf(" Month - Stand-alone\n"); + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| # | %s | %s | %s \n", "Narrow Names" , "Short Names" , "Long Names"); + + for (i = 0; i < 12; i++) { + s_narrow = _date_basic_format_convert("LLLLL", i, "month"); + s_short = _date_basic_format_convert("LLL", i, "month"); + s_long = _date_basic_format_convert("LLLL", i, "month"); + + printf("| %-2d | %s | %s | %s\n", i, s_narrow, s_short, s_long); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + return 0; +} + +i18n_udate _time_convert(char *input_time) +{ + i18n_ucalendar_h ucal; + i18n_udate date; + int ret = I18N_ERROR_NONE; + int year, month, day, hour, minute, second; + struct tm result; + + strptime(input_time, "%Y%m%d%H%M%S", &result); + if (result.tm_year >= 100) + result.tm_year = result.tm_year%100 + 2000; + 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); + + /*create i18n_ucalendar_h */ + ret = i18n_ucalendar_create(0, -1, NULL, I18N_UCALENDAR_DEFAULT, &ucal); + if (ret) { + printf("i18n_ucalendar_create failed.\n"); + return -1; + } + + /*set i18n_ucalendar_h's date */ + i18n_ucalendar_set_date_time(ucal, result.tm_year, result.tm_mon, result.tm_mday, result.tm_hour, result.tm_min, result.tm_sec); + i18n_ucalendar_get(ucal, I18N_UCALENDAR_YEAR, &year); + i18n_ucalendar_get(ucal, I18N_UCALENDAR_MONTH, &month); + i18n_ucalendar_get(ucal, I18N_UCALENDAR_DATE, &day); + i18n_ucalendar_get(ucal, I18N_UCALENDAR_HOUR, &hour); + i18n_ucalendar_get(ucal, I18N_UCALENDAR_MINUTE, &minute); + i18n_ucalendar_get(ucal, I18N_UCALENDAR_SECOND, &second); + 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); + /* get i18n_ucalendar's current time and converts it from milliseconds to seconds */ + i18n_ucalendar_get_milliseconds(ucal, &date); + + /* destroy i18n_ucalendar_h */ + i18n_ucalendar_destroy(ucal); + + return date; +} + +static int __get_date_and_time(char *input_time) +{ + int ret = 0; + printf(" - To get various date and time format\n"); + printf("****************************************\n"); + + i18n_udate date_now; + if (!input_time) { + ret = i18n_ucalendar_get_now(&date_now); + CHECK_ERROR("i18n_ucalendar_get_now", ret); + PRINT_DEBUG_LOG("i18n_ucalendar_get_now = %lf\n", date_now); + } else { + date_now = _time_convert(input_time); + PRINT_DEBUG_LOG("_time_convert = %lf\n", date_now); + } + + i18n_udate_format_h format_h = NULL; + i18n_udatepg_h udatepg; + ret = i18n_udatepg_create(default_locale, &udatepg); + CHECK_ERROR("i18n_udatepg_create", ret); + + i18n_uchar format[BUF_SIZE]; + i18n_ustring_copy_ua_n(format, "ddMMMyyyyHHmmssz", BUF_SIZE); + + int pattern_len, len; + i18n_uchar pattern[BUF_SIZE], skeleton[BUF_SIZE]; + i18n_ustring_copy_ua(skeleton, I18N_UDATE_MONTH_DAY); + len = i18n_ustring_get_length(skeleton); + ret = i18n_udatepg_get_best_pattern(udatepg, skeleton, len, pattern, BUF_SIZE, &pattern_len); + CHECK_ERROR("i18n_udatepg_get_best_pattern", ret); + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| %-17.17s | %-26.26s | %s \n", "TIME TYPE" , "DATE TYPE" , "OUTPUT"); + for (n_enum_date_counter = 0; n_enum_date_counter < n_date_enum_size; n_enum_date_counter++) { + for (n_enum_time_counter = 0; n_enum_time_counter < n_time_enum_size; n_enum_time_counter++) { + i18n_ustring_copy_ua_n(default_timezone_id, default_locale, BUF_SIZE); + ret = i18n_udate_create(eTimeFormatStyle[n_enum_time_counter], + eDateFormatStyle[n_enum_date_counter], + default_locale, default_timezone_id, -1, pattern, -1, &format_h); + CHECK_ERROR("i18n_udate_create", ret); + + i18n_uchar *result = (i18n_uchar *) malloc(BUF_SIZE * sizeof(i18n_uchar)); + int date_len; + ret = i18n_udate_format_date(format_h, date_now, result, BUF_SIZE, NULL, &date_len); + CHECK_ERROR("i18n_udate_format_date", ret); + + char s[BUF_SIZE]; + i18n_ustring_copy_au(s, result); + free(result); + + char *time_str, *date_str; + time_str = __print_i18n_type_string("time", n_enum_time_counter); + date_str = __print_i18n_type_string("date", n_enum_date_counter); + printf("| %-17.17s | %-26.26s | %s\n", time_str, date_str, s); + free(time_str); + free(date_str); + } + } + + PRINT_ASCIIDOC_LOG("|===\n"); + return 0; +} + +static int __get_number_format(char *input_number) +{ + + int ret = 0; + printf(" - To get various number format\n"); + printf("****************************************\n"); + double my_number = atof(input_number); + PRINT_DEBUG_LOG("Input number = %f\n", my_number); + + i18n_unumber_format_h num_format = NULL; + i18n_uchar formatted_number[BUF_SIZE]; + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| %-30.30s | %s\n", "NUMBER FORMAT" , "OUTPUT"); + + int i; + for (i = I18N_UNUMBER_DECIMAL; i <= I18N_UNUMBER_FORMAT_STYLE_COUNT; ++i) { + /* Create a number formatter. */ + ret = i18n_unumber_create((i18n_unumber_format_style_e)i, NULL, -1, default_locale, NULL, &num_format); + CHECK_ERROR("i18n_unumber_create", ret); + + /* Format the given number according to the given locale. */ + memset(formatted_number, 0, BUF_SIZE); + i18n_unumber_format_double(num_format, my_number, formatted_number, BUF_SIZE, NULL); + + /* Display the formatting result. */ + char string[BUF_SIZE]; + i18n_ustring_copy_au(string, formatted_number); + + char *number_str; + number_str = __print_i18n_type_string("number_format", i); + printf("| %-30.30s | %s\n", number_str, string); + free(number_str); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + /* Release the decimal number formatter. */ + ret = i18n_unumber_destroy(num_format); + CHECK_ERROR("i18n_unumber_destroy", ret); + + return 0; +} + +static int __get_symbol() +{ + printf(" - To get various number symbol\n"); + printf("****************************************\n"); + + /* Create a default number formatter. */ + i18n_unumber_format_h num_format = NULL; + int ret = i18n_unumber_create(I18N_UNUMBER_DEFAULT, NULL, -1, default_locale, NULL, &num_format); + CHECK_ERROR("18n_unumber_create", ret); + + int i; + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| %-47.47s | %s\n", "NUMBER SYMBOL" , "OUTPUT"); + for (i = 0; i < I18N_UNUMBER_FORMAT_SYMBOL_COUNT; ++i) { + /* Format the selected symbol according to the chosen locale. */ + int buf_len; + i18n_uchar u_buffer[BUF_SIZE]; + ret = i18n_unumber_get_symbol(num_format, (i18n_unumber_format_symbol_e)i, u_buffer, BUF_SIZE, &buf_len); + CHECK_ERROR("18n_unumber_get_symbol", ret); + + /* Display the formatted symbol. */ + char string[BUF_SIZE]; + i18n_ustring_copy_au(string, u_buffer); + + char *symbol_str; + symbol_str = __print_i18n_type_string("symbol", i+1); + printf("| %-47.47s | %s\n", symbol_str, string); + free(symbol_str); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + /* Release the default number formatter object. */ + ret = i18n_unumber_destroy(num_format); + CHECK_ERROR("i18n_unumber_destroy", ret); + + return 0; +} + +static const char *layout_orientation_converter(i18n_ulocale_layout_type_e type) +{ + switch (type) { + case I18N_ULOCALE_LAYOUT_LTR: + return "LTR"; + + case I18N_ULOCALE_LAYOUT_RTL: + return "RTL"; + + case I18N_ULOCALE_LAYOUT_TTB: + return "TTB"; + + case I18N_ULOCALE_LAYOUT_BTT: + return "BTT"; + + default: + return "UNKNOWN"; + } +} + + +static int __get_language_info() +{ + printf(" - To get language information\n"); + printf("****************************************\n"); + + i18n_uchar lang[BUF_SIZE]; + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| KEY | VALUE\n"); + + /* Get the default locale code */ + printf("| Default locale code | %s\n", default_locale); + + /* Get the display name of the selected locale. */ + i18n_uchar name[BUF_SIZE]; + int name_len; + + int ret = + i18n_ulocale_get_display_name(default_locale, default_locale, name, BUF_SIZE, &name_len); + CHECK_ERROR("i18n_ulocale_get_display_name", ret); + char name_ch[BUF_SIZE]; + i18n_ustring_copy_au(name_ch, name); + printf("| Language display name | %s\n", name_ch); + + + /* Get the language related to the selected locale. */ + i18n_ulocale_get_display_language(default_locale, default_locale, lang, BUF_SIZE); + + /* Get the string representation of the obtained language. */ + char language[BUF_SIZE]; + i18n_ustring_copy_au(language, lang); + printf("| Full name | %s\n", language); + + /* Get the obtained language code. */ + int32_t lang_len; + ret = i18n_ulocale_get_language(default_locale, language, BUF_SIZE, &lang_len); + CHECK_ERROR("i18n_ulocale_get_language", ret); + printf("| language code | %s\n", language); + + /* Get the ISO code of the selected locale. */ + const char *language_iso = i18n_ulocale_get_iso3_language(default_locale); + printf("| ISO code | %s\n", language_iso); + + /* Get the type of the line orientation related to the selected locale. */ + i18n_ulocale_layout_type_e type; + ret = i18n_ulocale_get_line_orientation(default_locale, &type); + CHECK_ERROR("i18n_ulocale_get_line_orientation", ret); + const char *orientation = layout_orientation_converter(type); + printf("| Line orientation | %s\n", orientation); + + /* Get the characters orientation related to the selected locale. */ + ret = i18n_ulocale_get_character_orientation(default_locale, &type); + CHECK_ERROR("i18n_ulocale_get_character_orientation", ret); + orientation = layout_orientation_converter(type); + printf("| Characters orientation | %s\n", orientation); + + /* Get the variant code related to the selected locale. */ + char variant[BUF_SIZE]; + ret = i18n_ulocale_get_variant(default_locale, variant, BUF_SIZE); + CHECK_ERROR("i18n_ulocale_get_variant", ret); + printf("| variant code | %s\n", variant); + PRINT_ASCIIDOC_LOG("|===\n"); + + return 0; +} + +static int __manage_string_iteration(char *input_string) +{ + printf(" - To manage the string iteration\n"); + printf("****************************************\n"); + + PRINT_DEBUG_LOG("Input string : %s\n", input_string); + i18n_uchar *string_to_examine; + i18n_ubreak_iterator_h boundary; + + if (!input_string) { + char *input_text = "Twinkle, twinkle, little star. How I wonder what you are"; + printf("\nInput string : %s\n", input_text); + string_to_examine = + (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); + i18n_ustring_copy_ua(string_to_examine, input_text); + } else { + char input_text[1000] = {0, }; + COPY_STR(input_text, input_string, 999); + printf("Input string : %s\n", input_text); + string_to_examine = + (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); + i18n_ustring_copy_ua(string_to_examine, input_text); + } + + int i; + int ret = 0; + char *iter_type; + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| %-19.19s | %s\n", "ITER First", "VALUE"); + + /* Displays the first element in the given text */ + for (i = 0; i <= I18N_UBRK_SENTENCE; i++) { + iter_type = NULL; + ret = i18n_ubrk_create((i18n_ubreak_iterator_type_e)i, default_locale, string_to_examine, -1, &boundary); + CHECK_ERROR("i18n_ubrk_create", ret); + int32_t start = i18n_ubrk_first(boundary); + int32_t end = i18n_ubrk_next(boundary); + i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1)); + result[end - start] = '\0'; + i18n_ustring_copy_n(result, &string_to_examine[start], end-start); + char str[BUF_SIZE]; + i18n_ustring_copy_au(str, result); + free(result); + + iter_type = __print_i18n_type_string("iter_type", i); + printf("| %-19.19s | %s\n", iter_type, str); + free(iter_type); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + printf("\n"); + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| %-19.19s | %s\n", "ITER Last", "VALUE"); + /* Displays the last element in the given text */ + for (i = 0; i <= I18N_UBRK_SENTENCE; i++) { + iter_type = NULL; + ret = i18n_ubrk_create((i18n_ubreak_iterator_type_e)i, default_locale, string_to_examine, -1, &boundary); + CHECK_ERROR("i18n_ubrk_create", ret); + int32_t end = i18n_ubrk_last(boundary); + int32_t start = i18n_ubrk_previous(boundary); + i18n_uchar *result = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (end - start + 1)); + result[end - start] = '\0'; + i18n_ustring_copy_n(result, &string_to_examine[start], end-start); + char str[BUF_SIZE]; + i18n_ustring_copy_au(str, result); + free(result); + + iter_type = __print_i18n_type_string("iter_type", i); + printf("| %-19.19s | %s\n", iter_type, str); + free(iter_type); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + free(string_to_examine); + ret = i18n_ubrk_destroy(boundary); + CHECK_ERROR("i18n_ubrk_destroy", ret); + + return 0; +} + +static int __analyze_string(char *custom_string) +{ + printf(" - To manage the string\n"); + printf("****************************************\n"); + + i18n_uchar *string_to_examine; + + if (!custom_string) { + char *input_text = "String"; + printf("\n Input string : %s\n", input_text); + string_to_examine = + (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); + i18n_ustring_copy_ua(string_to_examine, input_text); + } else { + char *input_text = custom_string; + printf("\n Input string : %s\n", input_text); + string_to_examine = + (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); + i18n_ustring_copy_ua(string_to_examine, input_text); + } + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| KEY | VALUE\n"); + + /* Get length */ + int32_t len = i18n_ustring_get_length(string_to_examine); + printf("| Length | %d\n", len); + + /* To upper */ + i18n_uchar dest[BUF_SIZE + 1]; + i18n_ustring_to_upper(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code); + CHECK_ERROR("i18n_ustring_to_upper", error_code); + + char s[BUF_SIZE]; + i18n_ustring_copy_au(s, dest); + printf("| TO UPPER | %s\n", s); + + /* To lower */ + i18n_ustring_to_lower(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code); + CHECK_ERROR("i18n_ustring_to_lower", error_code); + i18n_ustring_copy_au(s, dest); + printf("| to lower | %s\n", s); + + /* To title */ + i18n_ustring_to_title_new(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, NULL); + CHECK_ERROR("i18n_ustring_to_title_new", error_code); + i18n_ustring_copy_au(s, dest); + printf("| To Title | %s\n", s); + + PRINT_ASCIIDOC_LOG("|===\n"); + + return 0; +} + +static int __get_timezone_info() +{ + int ret = 0; + printf(" - To get time zone information\n"); + printf("****************************************\n"); + + static i18n_timezone_h tmz; + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| KEY | VALUE\n"); + + /* Get the default timezone. */ + ret = i18n_timezone_create_default(&tmz); + CHECK_ERROR("18n_timezone_create_default", ret); + + /* Get the display name of the default timezone. */ + char *display_name; + ret = i18n_timezone_get_display_name(tmz, &display_name); + CHECK_ERROR("i18n_timezone_get_display_name", ret); + printf("| Current timezone | %s\n", display_name); + + /* Get the selected timezone ID. */ + char *timezone_id; + ret = i18n_timezone_get_id(tmz, &timezone_id); + CHECK_ERROR("i18n_timezone_get_id", ret); + printf("| Timezone ID | %s\n", timezone_id); + + /* Check whether the selected time zone uses daylight savings time or not. */ + i18n_ubool daylight_time; + ret = i18n_timezone_use_daylight_time(tmz, &daylight_time); + CHECK_ERROR("i18n_timezone_use_daylight_time", ret); + printf("| Uses DST | %s\n", daylight_time ? "yes" : "no"); + + /* + * Get the amount of time that need to be added to the + * local standard time to get the local wall clock time. + */ + int32_t dst_savings; + ret = i18n_timezone_get_dst_savings(tmz, &dst_savings); + CHECK_ERROR("i18n_timezone_get_dst_savings", ret); + printf("| DST savings in [min] | %d\n", dst_savings / MS_TO_MIN); + + /* Get the selected time zone raw GMT offset. */ + int32_t offset_milliseconds; + ret = i18n_timezone_get_raw_offset(tmz, &offset_milliseconds); + CHECK_ERROR("i18n_timezone_get_raw_offset", ret); + if (offset_milliseconds / MS_TO_HOUR > 0) + printf("| Raw GMT offset | GMT +%d\n", offset_milliseconds / MS_TO_HOUR); + else + printf("| Raw GMT offset | GMT %d\n", offset_milliseconds / MS_TO_HOUR); + + /* Get the region code associated with the selected time zone. */ + char region[BUF_SIZE]; + int32_t region_len = -1; + ret = i18n_timezone_get_region(timezone_id, region, ®ion_len, BUF_SIZE); + CHECK_ERROR("i18n_timezone_get_region", ret); + printf("| Associated region code | %s\n", region); + + PRINT_ASCIIDOC_LOG("|===\n"); + + /* Release the time zone object. */ + ret = i18n_timezone_destroy(tmz); + CHECK_ERROR("i18n_timezone_destroy", ret); + free(timezone_id); + + return 0; + +} + +static int __get_tzdata_version() +{ + const char *ver = i18n_timezone_get_tzdata_version(); + printf("tzdata version : %s\n", ver); + printf("****************************************\n"); + + return 0; +} + +static int32_t _get_uchar_length(const char *arr) +{ + int32_t ulen = strlen(arr); + i18n_uchar _text[ulen + 1]; + i18n_ustring_copy_ua(_text, arr); + + return i18n_ustring_get_length(_text); +} + +static int __show_ubidi(char *input_text) +{ + printf(" - Examples of the Unicode Bidirectional Algorithm\n"); + printf(" - input text : %s\n", input_text ? input_text : "Samsung is ﺱﺎﻤﺳﻮﻨﺟ in Arabic."); + printf("****************************************\n"); + + int i, j; + const char* text; + static i18n_ubidi_h ubidi; + i18n_ubidi_create(&ubidi); + + if (!input_text) { + text = "Samsung is سامسونج in Arabic"; + } else { + text = input_text; + } + + PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); + PRINT_ASCIIDOC_LOG("|===\n"); + printf("| %-46.46s | %-34.34s | %s \n", "MODES", "OPTIONS", "OUTPUT"); + + for (i = 0; i < N_MODES; i++) { + /* Sets ubidi reordering mode */ + int ret = i18n_ubidi_set_reordering_mode(ubidi, reordering_modes[i].mode); + CHECK_ERROR("i18n_ubidi_set_reordering_mode", ret); + + /* Sets ubidi paragraphs and perform the Unicode bidi algorithm */ + int src_length = _get_uchar_length(text); + PRINT_DEBUG_LOG("src_length: %d\n", src_length); + + i18n_uchar *src = (i18n_uchar *) malloc(sizeof(i18n_uchar) * (src_length + 1)); + i18n_ustring_copy_ua(src, text); + ret = i18n_ubidi_set_para(ubidi, src, src_length, I18N_UBIDI_DEFAULT_LTR, NULL); + + /* Writes ubidi reordered text to the entry with write_options */ + i18n_uchar dst[BUF_SIZE]; + int output_length = 0; + + for (j = 0; j < N_OPTIONS; j++) { + ret = i18n_ubidi_write_reordered(ubidi, reordering_options[j].option, BUF_SIZE, + dst, &output_length); + CHECK_ERROR("i18n_ubidi_write_reordered", ret); + + char buffer[BUF_SIZE]; + i18n_ustring_copy_au(buffer, dst); + printf("| %-46.46s | %-34.34s | %s \n", reordering_modes[i].display_name, reordering_options[j].display_name, buffer); + } + free(src); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + if (ubidi != NULL) { + i18n_ubidi_destroy(ubidi); + ubidi = NULL; + } + + return 0; +} + +void allTest() +{ + int ret = 0, i = 0; + int loc_count; + + loc_count = i18n_ulocale_count_available(); + for (i = 0; i < loc_count; i++) { + default_locale = i18n_ulocale_get_available(i); + printf("\n== Date and Time Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_date_and_time(NULL); + printf("\n"); + printf("\n== Number Format Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_number_format("3.5"); + printf("\n"); + printf("\n== Number Symbol Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_symbol(); + printf("\n"); + printf("\n== Language Info"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_language_info(); + printf("\n"); + } + + printf("\n== String Iteration Test"); + printf("\n****************************************\n"); + ret = __manage_string_iteration(NULL); + printf("\n"); + + printf("\n== String Test"); + printf("\n****************************************\n"); + ret = __analyze_string(NULL); + printf("\n"); + printf("\n== Timezone Info"); + printf("\n****************************************\n"); + ret = __get_timezone_info(); + printf("\n"); + + printf("\n== TZ Data Version Info"); + printf("\n****************************************\n"); + ret = __get_tzdata_version(); + if (ret == -1) { + printf("get i18n time zone info list failed\n"); + } +} + +void showAllLocale() +{ + __get_available_locales(); +} + +void showLangInfo(char *locale) +{ + int ret = 0, i = 0; + int loc_count; + + if (!locale) { + loc_count = i18n_ulocale_count_available(); + for (i = 0; i < loc_count; i++) { + default_locale = i18n_ulocale_get_available(i); + printf("\n== Language Info"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_language_info(); + } + if (ret == -1) { + printf("get i18n language info list failed\n"); + } + } else { + default_locale = locale; + printf("\n== Language Info"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_language_info(); + if (ret == -1) { + printf("get i18n language info list failed\n"); + } + } +} + +void showTimezone() +{ + int ret = 0; + printf("\n== Timezone Info"); + printf("\n****************************************\n"); + ret = __get_timezone_info(); + if (ret == -1) { + printf("get i18n time zone info list failed\n"); + } +} + +void showTzdataVersion() +{ + printf("\n== TZ Data Version Info"); + printf("\n****************************************\n"); + __get_tzdata_version(); +} + +void showUbidi(char *input) +{ + printf("\n== Show Ubidi"); + printf("\n****************************************\n"); + __show_ubidi(input); +} + +void showDatentimeFormat(char *locale) +{ + int ret = 0, i = 0; + int loc_count; + + if (!locale) { + loc_count = i18n_ulocale_count_available(); + for (i = 0; i < loc_count; i++) { + default_locale = i18n_ulocale_get_available(i); + printf("\n== Show Date basic format"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_date_basic_format(); + } + if (ret == -1) { + printf("get i18n date and time basic format list failed\n"); + } + } else { + default_locale = locale; + printf("\n== Show Date basic format"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_date_basic_format(); + if (ret == -1) { + printf("get i18n date and time basic format list failed\n"); + } + } +} + +void testDatentime(char *input, char *locale) +{ + int ret = 0, i = 0; + int loc_count; + + if (!locale) { + loc_count = i18n_ulocale_count_available(); + for (i = 0; i < loc_count; i++) { + default_locale = i18n_ulocale_get_available(i); + printf("\n== Date and Time Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_date_and_time(input); + } + if (ret == -1) { + printf("get i18n date and time list failed\n"); + } + } else { + default_locale = locale; + printf("\n== Date and Time Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_date_and_time(input); + if (ret == -1) { + printf("get i18n date and time list failed\n"); + } + + } +} + +void testNumberFormat(char *input, char *locale) +{ + int ret = 0, i = 0; + int loc_count; + + if (!input) { + + } else { + if (!locale) { + loc_count = i18n_ulocale_count_available(); + for (i = 0; i < loc_count; i++) { + default_locale = i18n_ulocale_get_available(i); + printf("\n== Number Format Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_number_format(input); + } + if (ret == -1) { + printf("get number format list failed\n"); + } + } else { + default_locale = locale; + printf("\n== Number Format Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_number_format(input); + if (ret == -1) { + printf("get number format list failed\n"); + } + } + } +} + +void testNumberSymbol(char *locale) +{ + int ret = 0, i = 0; + int loc_count; + + if (!locale) { + loc_count = i18n_ulocale_count_available(); + for (i = 0; i < loc_count; i++) { + default_locale = i18n_ulocale_get_available(i); + printf("\n== Number Symbol Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_symbol(); + } + if (ret == -1) { + printf("get i18n symbol list failed\n"); + } + } else { + default_locale = locale; + printf("\n== Number Symbol Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); + ret = __get_symbol(); + if (ret == -1) { + printf("get i18n symbol list failed\n"); + } + } +} + +void testString(char *input) +{ + int ret = 0; + + printf("\n== String Test"); + printf("\n****************************************\n"); + ret = __analyze_string(input); + if (ret == -1) { + printf("get i18n string list failed\n"); + } +} + +void testStringIter(char *input) +{ + int ret = 0; + + printf("\n== String Iteration Test"); + printf("\n****************************************\n"); + ret = __manage_string_iteration(input); + if (ret == -1) { + printf("get i18n string iteration list failed\n"); + } +} + +int main(int argc, char *argv[]) +{ + struct arguments arguments = {0, }; + + init_env(); + argp_parse(&argp, argc, argv, 0, 0, &arguments); + + if (arguments.all) { + memset(&arguments, 0x00, sizeof(arguments)); + + allTest(); + } + + if (arguments.showAllLocale) { + showAllLocale(); + } + + if (arguments.showLangInfo) { + showLangInfo(arguments.setLocale); + } + + if (arguments.showDateFormat) { + showDatentimeFormat(arguments.setLocale); + } + + if (arguments.testDatentime) { + testDatentime(arguments.testTimeArg, arguments.setLocale); + } + + if (arguments.testNumberFormat) { + testNumberFormat(arguments.testNumberFormatArg, arguments.setLocale); + } + + if (arguments.testNumberSymbol) { + testNumberSymbol(arguments.setLocale); + } + + if (arguments.testString) { + testString(arguments.testStringArg); + } + + if (arguments.testStringIter) { + testStringIter(arguments.testStringIterArg); + } + + if (arguments.showTimezone) { + showTimezone(); + } + + if (arguments.showTzdataVersion) { + showTzdataVersion(); + } + + if (arguments.showUbidi) { + showUbidi(arguments.testTextArg); + } + + return 0; +} diff --git a/i18ninfo/i18ninfo_argp.h b/i18ninfo/i18ninfo_argp.h index 0ea3062..6d30d2a 100644 --- a/i18ninfo/i18ninfo_argp.h +++ b/i18ninfo/i18ninfo_argp.h @@ -61,7 +61,7 @@ parse_opt(int key, char *arg, struct argp_state *state) { /* Get the input argument from argp_parse, which we know is a pointer to our arguments structure. */ - struct arguments *arguments = state->input; + struct arguments *arguments = (struct arguments *)state->input; char *nextArg; /*printf("key [%x] [%c] arg [%s]\n", key, key, arg); */ diff --git a/packaging/capi-base-utils.spec b/packaging/capi-base-utils.spec index 1ca3285..1fcddde 100755 --- a/packaging/capi-base-utils.spec +++ b/packaging/capi-base-utils.spec @@ -28,7 +28,7 @@ The base utils library for internationalization and localization (Development) %package -n i18ninfo License: Apache-2.0 Summary: The Base Utils Tool -Version: 1.0.1 +Version: 1.1.0 Group: Base Requires: capi-base-utils