From: Hyunjee Kim Date: Mon, 10 Apr 2017 05:59:49 +0000 (+0900) Subject: [i18ninfo] Add several functions X-Git-Tag: submit/tizen/20170424.073737~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f32b0dac3e579310781fef2a9ab537f7480d99ca;p=platform%2Fcore%2Fapi%2Fbase-utils.git [i18ninfo] Add several functions - ascii doc generator - add custom time opion in testDatentime - add "show date basic format" menu Change-Id: Ib4d0571e62b512d97e29000baaede02e2af51ecf Signed-off-by: Hyunjee Kim --- diff --git a/i18ninfo/geni18n/geni18n.sh b/i18ninfo/geni18n/geni18n.sh new file mode 100755 index 0000000..b659be9 --- /dev/null +++ b/i18ninfo/geni18n/geni18n.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +#list=`sdb shell i18ninfo -L | tr -d '\r'` +list=`sdb shell locale -a | tr -d '\r'` + +mkdir ./result + +for file in $list +do + echo "Processing i18n report for ($file)" + + echo "= [$file] i18ninfo" > $file.txt + echo "" >> $file.txt + + sdb shell LANG=en_US.utf8 i18ninfo --test-datentime -l $file > $file.txt + sdb shell LANG=en_US.utf8 i18ninfo --show-lang-info -l $file >> $file.txt + sdb shell LANG=en_US.utf8 i18ninfo --show-timezone -l $file >> $file.txt + sdb shell LANG=en_US.utf8 i18ninfo --test-number-format=1234.56 -l $file >> $file.txt + sdb shell LANG=en_US.utf8 i18ninfo --show-tzdata-version -l $file >> $file.txt + sdb shell LANG=en_US.utf8 i18ninfo --test-string=안녕하세요 -l $file >> $file.txt +# iconv -t utf-8 $file.txt | highlight --syntax html --encoding utf-8 > $file.html + asciidoc --backend=xhtml11 $file.txt +done + + +echo "Generating index.html" +echo == i18ntest page > index.txt +echo "[options=\"header\"]" >> index.txt +echo "|===" >> index.txt +for file in $list +do +echo "| $file | link:$file.html[$file] " >> index.txt +done +echo "|===" >> index.txt +asciidoc --backend=xhtml11 index.txt + +mv *.txt *.html ./result diff --git a/i18ninfo/geni18n/geni18n_dev.sh b/i18ninfo/geni18n/geni18n_dev.sh new file mode 100755 index 0000000..7797116 --- /dev/null +++ b/i18ninfo/geni18n/geni18n_dev.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +export PATH=../:$PATH + +list=`i18ninfo -L | tr -d '\r'` +#list=`locale -a | tr -d '\r'` + +mkdir -p ./result + +for file in $list +do + echo "Processing i18n report for ($file)" + + echo "= [$file] i18ninfo" > $file.txt + echo "" >> $file.txt + + LANG=en_US.utf8 i18ninfo --test-datentime -l $file >> $file.txt + LANG=en_US.utf8 i18ninfo --show-lang-info -l $file >> $file.txt + LANG=en_US.utf8 i18ninfo --show-timezone -l $file >> $file.txt + LANG=en_US.utf8 i18ninfo --test-number-format=1234.56 -l $file >> $file.txt + LANG=en_US.utf8 i18ninfo --show-tzdata-version -l $file >> $file.txt + LANG=en_US.utf8 i18ninfo --test-string=안녕하세요 -l $file >> $file.txt +# iconv -t utf-8 $file.txt | highlight --syntax html --encoding utf-8 > $file.html +done + +mv *.txt ./result diff --git a/i18ninfo/i18ninfo.c b/i18ninfo/i18ninfo.c index dc3d562..031fc8c 100644 --- a/i18ninfo/i18ninfo.c +++ b/i18ninfo/i18ninfo.c @@ -3,11 +3,13 @@ #include #include #include +#include #include "i18ninfo_argp.h" #include #define DEBUG_FLAG 0 +static int ASCIIDOC_FLAG = 0; #define BUF_SIZE 64 #define MS_TO_MIN 60000 @@ -31,6 +33,7 @@ (dst)[(dst_len) - 1] = '\0'; \ } while (0) +#define PRINT_ASCIIDOC_LOG(fmt) if (ASCIIDOC_FLAG) printf(fmt) char *default_locale = I18N_ULOCALE_UK; i18n_uchar default_timezone_id[BUF_SIZE] = {0,}; @@ -62,7 +65,8 @@ int n_enum_time_counter, n_enum_date_counter, error_code; static void __get_available_locales(); -static int __get_date_and_time(); +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(); @@ -92,6 +96,17 @@ static void __get_available_locales() } } +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)); @@ -302,15 +317,161 @@ char *__print_i18n_type_string(char *type, int num) return str; } -static int __get_date_and_time() +static const 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 (type == "day") date_now += i * 86400000; + else if (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 various date and time format\n"); + 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("| # | %-11.11s | %-11.11s | %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 | %-11.1s | %-11.3s | %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("| # | %-11.11s | %-11.11s | %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 | %-11.1s | %-11.3s | %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("| # | %-11.11s | %-11.11s | %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 | %-11.11s | %-11.11s | %-11.11s\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("| # | %-11.11s | %-11.11s | %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 | %-11.1s | %-11.3s | %s\n", i, s_narrow, s_short, s_long); + } + PRINT_ASCIIDOC_LOG("|===\n"); + + return 0; +} + +i18n_udate _time_convert(char *input_time) +{ + long long int lli; + 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, "en_US", 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; - i18n_udate_format_h format_h = NULL; - int error_code = i18n_ucalendar_get_now(&date_now); - PRINT_DEBUG_LOG("i18n_ucalendar_get_now = %lf\n", date_now); + if (!input_time) { + int error_code = i18n_ucalendar_get_now(&date_now); + 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); @@ -320,17 +481,18 @@ static int __get_date_and_time() int pattern_len; i18n_uchar pattern[BUF_SIZE]; - error_code = i18n_udatepg_get_best_pattern(udatepg, I18N_UDATE_MONTH_DAY, BUF_SIZE, pattern, BUF_SIZE, - &pattern_len); + error_code = i18n_udatepg_get_best_pattern(udatepg, I18N_UDATE_MONTH_DAY, BUF_SIZE, pattern, BUF_SIZE, &pattern_len); CHECK_ERROR("i18n_udatepg_get_best_pattern", error_code); - printf(" * TIME TYPE X DATE TYPE : OUTPUT\n"); + 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); + 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)); @@ -341,26 +503,34 @@ static int __get_date_and_time() 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("TIME[%-17.17s] DATE[%-26.26s] : %s\n", time_str, date_str, s); + 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(" - 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. */ @@ -377,9 +547,10 @@ static int __get_number_format(char *input_number) char *number_str; number_str = __print_i18n_type_string("number_format", i); - printf("NUMBER_FORMAT[%-30.30s] : %s\n", number_str, string); + 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); @@ -390,7 +561,8 @@ static int __get_number_format(char *input_number) static int __get_symbol() { - printf(" * To get various number symbol\n"); + printf(" - To get various number symbol\n"); + printf("****************************************\n"); /* Create a default number formatter. */ i18n_unumber_format_h num_format = NULL; @@ -398,6 +570,10 @@ static int __get_symbol() 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; @@ -411,9 +587,10 @@ static int __get_symbol() char *symbol_str; symbol_str = __print_i18n_type_string("symbol", i+1); - printf("SYMBOL[%-47.47s] : %s\n", symbol_str, string); + 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); @@ -445,23 +622,28 @@ static const char *layout_orientation_converter(i18n_ulocale_layout_type_e type) static int __get_language_info() { - printf(" * To get language information\n"); + 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); + 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); + 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); + printf("| Language display name | %s\n", name_ch); /* Get the language related to the selected locale. */ @@ -470,43 +652,45 @@ static int __get_language_info() /* Get the string representation of the obtained language. */ char language[BUF_SIZE]; i18n_ustring_copy_au(language, lang); - printf("Full name : %s\n", language); + 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); + 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); + 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); + 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); + 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); + 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(" - To manage the string iteration\n"); + printf("****************************************\n"); PRINT_DEBUG_LOG("Input string : %s\n", input_string); i18n_uchar *string_to_examine; @@ -514,22 +698,26 @@ static int __manage_string_iteration(char *input_string) if (!input_string) { char *input_text = "Twinkle, twinkle, little star.\ How I wonder what you are"; - printf("Input string : %s\n", input_text); + printf("\nInput string : %s\n", input_text); string_to_examine = - (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); + (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_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++) { error_code = i18n_ubrk_create(i, default_locale, string_to_examine, -1, &boundary); @@ -544,9 +732,14 @@ static int __manage_string_iteration(char *input_string) free(result); iter_type = __print_i18n_type_string("iter_type", i); - printf("ITER First element[%-19.19s] : %s\n", iter_type, str); + printf("| %-19.19s | %s\n", iter_type, str); } + 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++) { error_code = i18n_ubrk_create(i, default_locale, string_to_examine, -1, &boundary); @@ -561,8 +754,9 @@ static int __manage_string_iteration(char *input_string) free(result); iter_type = __print_i18n_type_string("iter_type", i); - printf("ITER Last element[%-19.19s] : %s\n", iter_type, str); + printf("| %-19.19s | %s\n", iter_type, str); } + PRINT_ASCIIDOC_LOG("|===\n"); free(iter_type); free(string_to_examine); @@ -574,29 +768,34 @@ static int __manage_string_iteration(char *input_string) static int __analyze_string(char *custom_string) { - printf(" * To manage the string\n"); + printf(" - To manage the string\n"); + printf("****************************************\n"); i18n_uchar *string_to_examine; if (!custom_string) { char *input_text = "String"; - printf("Input string : %s\n", input_text); + printf("\n Input string : %s\n", input_text); string_to_examine = - (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); + (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("Input string : %s\n", input_text); + printf("\n Input string : %s\n", input_text); string_to_examine = - (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); + (i18n_uchar *) malloc(sizeof(i18n_uchar) * (strlen(input_text) + 1)); i18n_ustring_copy_ua(string_to_examine, input_text); } int i; + 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); + printf("| Length | %d\n", len); /* To upper */ i18n_uchar dest[BUF_SIZE + 1]; @@ -605,29 +804,36 @@ static int __analyze_string(char *custom_string) char s[BUF_SIZE]; i18n_ustring_copy_au(s, dest); - printf("TO UPPER : %s\n", s); + 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); + printf("| to lower | %s\n", s); /* To title */ i18n_ustring_to_title_new(dest, BUF_SIZE + 1, string_to_examine, BUF_SIZE, NULL, &error_code); CHECK_ERROR("i18n_ustring_to_title_new", error_code); i18n_ustring_copy_au(s, dest); - printf("To Title : %s\n", s); + 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(" - 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); @@ -636,19 +842,19 @@ static int __get_timezone_info() 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); + 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); + 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"); + printf("| Uses DST | %s\n", daylight_time ? "yes" : "no"); /* * Get the amount of time that need to be added to the @@ -658,23 +864,25 @@ static int __get_timezone_info() char ms[BUF_SIZE]; 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); + 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); + 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); + 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); + printf("| Associated region code | %s\n", region); + + PRINT_ASCIIDOC_LOG("|===\n"); /* Release the time zone object. */ error_code = i18n_timezone_destroy(tmz); @@ -689,9 +897,9 @@ static int __get_tzdata_version() { const char *ver = i18n_timezone_get_tzdata_version(); printf("tzdata version : %s\n", ver); + printf("****************************************\n"); return 0; - } void allTest() @@ -702,21 +910,44 @@ void allTest() loc_count = i18n_ulocale_count_available(); for (i = 0; i < loc_count; i++) { default_locale = i18n_ulocale_get_available(i); - printf("\n * locales : %s\n", default_locale); - ret = __get_date_and_time(); + 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"); @@ -737,7 +968,9 @@ void showLangInfo(char *locale) loc_count = i18n_ulocale_count_available(); for (i = 0; i < loc_count; i++) { default_locale = i18n_ulocale_get_available(i); - printf("\n * locales : %s\n", default_locale); + printf("\n== Language Info"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); ret = __get_language_info(); } if (ret == -1) { @@ -745,7 +978,9 @@ void showLangInfo(char *locale) } } else { default_locale = locale; - printf("\n * locales : %s\n", default_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"); @@ -756,6 +991,8 @@ void showLangInfo(char *locale) 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"); @@ -764,10 +1001,41 @@ void showTimezone() void showTzdataVersion() { + printf("\n== TZ Data Version Info"); + printf("\n****************************************\n"); __get_tzdata_version(); } -void testDatentime(char *locale) +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; @@ -776,16 +1044,20 @@ void testDatentime(char *locale) loc_count = i18n_ulocale_count_available(); for (i = 0; i < loc_count; i++) { default_locale = i18n_ulocale_get_available(i); - printf("\n * locales : %s\n", default_locale); - ret = __get_date_and_time(); + 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 * locales : %s\n", default_locale); - ret = __get_date_and_time(); + 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"); } @@ -805,7 +1077,9 @@ void testNumberFormat(char *input, char *locale) loc_count = i18n_ulocale_count_available(); for (i = 0; i < loc_count; i++) { default_locale = i18n_ulocale_get_available(i); - printf("\n * locales : %s\n", default_locale); + printf("\n== Number Format Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); ret = __get_number_format(input); } if (ret == -1) { @@ -813,7 +1087,9 @@ void testNumberFormat(char *input, char *locale) } } else { default_locale = locale; - printf("\n * locales : %s\n", default_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"); @@ -831,7 +1107,9 @@ void testNumberSymbol(char *locale) loc_count = i18n_ulocale_count_available(); for (i = 0; i < loc_count; i++) { default_locale = i18n_ulocale_get_available(i); - printf("\n * locales : %s\n", default_locale); + printf("\n== Number Symbol Test"); + printf("\n****************************************"); + printf("\n - locales : %s\n", default_locale); ret = __get_symbol(); } if (ret == -1) { @@ -839,7 +1117,9 @@ void testNumberSymbol(char *locale) } } else { default_locale = locale; - printf("\n * locales : %s\n", default_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"); @@ -851,6 +1131,8 @@ 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"); @@ -861,6 +1143,8 @@ 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"); @@ -873,6 +1157,7 @@ int main(int argc, char *argv[]) struct arguments arguments = {0,}; + init_env(); argp_parse(&argp, argc, argv, 0, 0, &arguments); if (arguments.all) { @@ -889,8 +1174,12 @@ int main(int argc, char *argv[]) showLangInfo(arguments.setLocale); } + if (arguments.showDateFormat) { + showDatentimeFormat(arguments.setLocale); + } + if (arguments.testDatentime) { - testDatentime(arguments.setLocale); + testDatentime(arguments.testTimeArg, arguments.setLocale); } if (arguments.testNumberFormat) { diff --git a/i18ninfo/i18ninfo_argp.h b/i18ninfo/i18ninfo_argp.h index 2f45ee4..2025d39 100644 --- a/i18ninfo/i18ninfo_argp.h +++ b/i18ninfo/i18ninfo_argp.h @@ -4,29 +4,27 @@ -const char *argp_program_version = - "i18ninfo 1.0"; -const char *argp_program_bug_address = - ""; +const char *argp_program_version = "i18ninfo 1.0"; +const char *argp_program_bug_address = ""; /* Program documentation. */ -static char doc[] = - "i18ninfo -- Base-utils Api testing program"; +static char doc[] = "i18ninfo -- Base-utils Api testing program"; /* A description of the arguments we accept. */ static char args_doc[] = "[Target] ..."; static struct argp_option options[] = { - {"all", 'a', 0, 0, "Show all information and test" , 0 }, - {"show-all-locale", 'L', 0, 0, "Show all supported locales list", 0 }, - {"show-lang-info", 'I', 0, 0, "Show language information", 0 }, - {"show-timezone", 'T', 0, 0, "Show timezone", 0 }, - {"show-tzdata-version", 'Z', 0, 0, "Show tzdata version", 0 }, - {"test-datentime", 'd', 0, 0, "Date and time format test", 0 }, - {"test-number-format", 'n', "Number", 0, "Number format test", 0 }, - {"test-number-symbol", 'N', 0, 0, "Number symbol test", 0 }, - {"test-string", 's', "Word", OPTION_ARG_OPTIONAL, "String test", 0 }, - {"test-string-iter", 'S', "Type", OPTION_ARG_OPTIONAL, "String iteration test", 0 }, - {"set-locale", 'l', "locale", 0, "Set specific locale", 0 }, + {"all", 'a', 0, 0, "Show all information and test" , 0 }, + {"show-all-locale", 'L', 0, 0, "Show all supported locales list", 0 }, + {"show-lang-info", 'I', 0, 0, "Show language information", 0 }, + {"show-timezone", 'T', 0, 0, "Show timezone", 0 }, + {"show-tzdata-version", 'Z', 0, 0, "Show tzdata version", 0 }, + {"show-date-format", 'D', 0, 0, "Show Date basic format", 0 }, + {"test-datentime", 'd', "DateTime", OPTION_ARG_OPTIONAL, "Date and time format test", 0 }, + {"test-number-format", 'n', "Number", 0, "Number format test", 0 }, + {"test-number-symbol", 'N', 0, 0, "Number symbol test", 0 }, + {"test-string", 's', "Word", OPTION_ARG_OPTIONAL, "String test", 0 }, + {"test-string-iter", 'S', "Type", OPTION_ARG_OPTIONAL, "String iteration test", 0 }, + {"set-locale", 'l', "locale", 0, "Set specific locale", 0 }, { 0 } }; @@ -37,6 +35,7 @@ struct arguments { int showLangInfo; int showTimezone; int showTzdataVersion; + int showDateFormat; int testDatentime; int testNumberFormat; int testNumberSymbol; @@ -46,6 +45,7 @@ struct arguments { char *arg1; /* arg1 */ char **strings; /* [string…] */ + char *testTimeArg; char *testNumberFormatArg; char *testStringArg; char *testStringIterArg; @@ -84,21 +84,32 @@ parse_opt(int key, char *arg, struct argp_state *state) arguments->arg_flag = 5; arguments->showTzdataVersion = 1; break; - case 'd': + case 'D': arguments->arg_flag = 6; + arguments->showDateFormat = 1; + break; + case 'd': + arguments->arg_flag = 7; arguments->testDatentime = 1; + + nextArg = state->argv[state->next]; + if (nextArg && *nextArg != '-') { + arguments->testTimeArg = nextArg; + state->next++; + } + break; case 'n': - arguments->arg_flag = 7; + arguments->arg_flag = 8; arguments->testNumberFormat = 1; arguments->testNumberFormatArg = arg; break; case 'N': - arguments->arg_flag = 8; + arguments->arg_flag = 9; arguments->testNumberSymbol = 1; break; case 's': - arguments->arg_flag = 9; + arguments->arg_flag = 10; arguments->testString = 1; nextArg = state->argv[state->next]; @@ -108,7 +119,7 @@ parse_opt(int key, char *arg, struct argp_state *state) } break; case 'S': - arguments->arg_flag = 10; + arguments->arg_flag = 11; arguments->testStringIter = 1; nextArg = state->argv[state->next];