From: Hyunjee Kim Date: Thu, 23 Mar 2017 06:49:28 +0000 (+0900) Subject: Add i18ninfo tools and Fix spec files X-Git-Tag: submit/tizen/20170412.084016~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9c177ffbd35d18a1ad98f1e2d588e38a6edd7a20;p=platform%2Fcore%2Fapi%2Fbase-utils.git Add i18ninfo tools and Fix spec files - remove unused dependency - Fix license path Change-Id: Ibf698c84e4d5bad3418f944e05a8dcdf22b22266 Signed-off-by: Hyunjee Kim --- diff --git a/i18ninfo/CMakeLists.txt b/i18ninfo/CMakeLists.txt new file mode 100644 index 0000000..31f3c4d --- /dev/null +++ b/i18ninfo/CMakeLists.txt @@ -0,0 +1,23 @@ +PROJECT(i18ninfo C) + +SET(test_tool "i18ninfo") +SET(dependents "capi-base-utils-i18n") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${test_tool} REQUIRED ${dependents}) +FOREACH(flag ${${test_tool}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +aux_source_directory(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + MESSAGE("${src_name}") + ADD_EXECUTABLE(${src_name} ${src}) + TARGET_LINK_LIBRARIES(${src_name} "base-utils-i18n" ${${test_tool}_LDFLAGS}) +ENDFOREACH() + +INSTALL(TARGETS i18ninfo DESTINATION ${BIN_INSTALL_DIR}) diff --git a/i18ninfo/i18ninfo.c b/i18ninfo/i18ninfo.c new file mode 100644 index 0000000..1b79442 --- /dev/null +++ b/i18ninfo/i18ninfo.c @@ -0,0 +1,878 @@ +#include +#include +#include +#include +#include +#include "i18ninfo_argp.h" + +#include + +#define DEBUG_FLAG 0 + +#define BUF_SIZE 64 +#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); \ + } + + +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 +}; + +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_and_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(); + +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); + } + } +} + +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 (type == "time") { + switch (num) { + case 0: + strcpy(str, "I18N_UDATE_FULL"); + break; + case 1: + strcpy(str, "I18N_UDATE_LONG"); + break; + case 2: + strcpy(str, "I18N_UDATE_MEDIUM"); + break; + case 3: + strcpy(str, "I18N_UDATE_SHORT"); + break; + case 4: + strcpy(str, "I18N_UDATE_NONE"); + break; + default: + strcpy(str, "err"); + break; + } + } else if (type == "date") { + switch (num) { + case 0: + strcpy(str, "I18N_UDATE_FULL"); + break; + case 1: + strcpy(str, "I18N_UDATE_LONG"); + break; + case 2: + strcpy(str, "I18N_UDATE_MEDIUM"); + break; + case 3: + strcpy(str, "I18N_UDATE_SHORT"); + break; + case 4: + strcpy(str, "I18N_UDATE_RELATIVE"); + break; + case 5: + strcpy(str, "I18N_UDATE_LONG_RELATIVE"); + break; + case 6: + strcpy(str, "I18N_UDATE_MEDIUM_RELATIVE"); + break; + case 7: + strcpy(str, "I18N_UDATE_SHORT_RELATIVE"); + break; + case 8: + strcpy(str, "I18N_UDATE_NONE"); + break; + default: + strcpy(str, "err"); + break; + } + } else if (type == "number_format") { + switch (num) { + case 1: + strcpy(str, "I18N_UNUMBER_DECIMAL"); + break; + case 2: + strcpy(str, "I18N_UNUMBER_CURRENCY"); + break; + case 3: + strcpy(str, "I18N_UNUMBER_PERCENT"); + break; + case 4: + strcpy(str, "I18N_UNUMBER_SCIENTIFIC"); + break; + case 5: + strcpy(str, "I18N_UNUMBER_SPELLOUT"); + break; + case 6: + strcpy(str, "I18N_UNUMBER_ORDINAL"); + break; + case 7: + strcpy(str, "I18N_UNUMBER_DURATION"); + break; + case 8: + strcpy(str, "I18N_UNUMBER_NUMBERING_SYSTEM"); + break; + case 9: + strcpy(str, "I18N_UNUMBER_PATTERN_RULEBASED"); + break; + case 10: + strcpy(str, "I18N_UNUMBER_CURRENCY_ISO"); + break; + case 11: + strcpy(str, "I18N_UNUMBER_CURRENCY_PLURAL"); + break; + case 12: + strcpy(str, "I18N_UNUMBER_FORMAT_STYLE_COUNT"); + break; + default: + strcpy(str, "err"); + break; + } + } else if (type == "symbol") { + switch (num) { + case 1: + strcpy(str, "I18N_UNUMBER_DECIMAL_SEPARATOR_SYMBOL"); + break; + case 2: + strcpy(str, "I18N_UNUMBER_GROUPING_SEPARATOR_SYMBOL"); + break; + case 3: + strcpy(str, "I18N_UNUMBER_PATTERN_SEPARATOR_SYMBOL"); + break; + case 4: + strcpy(str, "I18N_UNUMBER_PERCENT_SYMBOL"); + break; + case 5: + strcpy(str, "I18N_UNUMBER_ZERO_DIGIT_SYMBOL"); + break; + case 6: + strcpy(str, "I18N_UNUMBER_DIGIT_SYMBOL"); + break; + case 7: + strcpy(str, "I18N_UNUMBER_MINUS_SIGN_SYMBOL"); + break; + case 8: + strcpy(str, "I18N_UNUMBER_PLUS_SIGN_SYMBOL"); + break; + case 9: + strcpy(str, "I18N_UNUMBER_CURRENCY_SYMBOL"); + break; + case 10: + strcpy(str, "I18N_UNUMBER_INTL_CURRENCY_SYMBOL"); + break; + case 11: + strcpy(str, "I18N_UNUMBER_MONETARY_SEPARATOR_SYMBOL"); + break; + case 12: + strcpy(str, "I18N_UNUMBER_EXPONENTIAL_SYMBOL"); + break; + case 13: + strcpy(str, "I18N_UNUMBER_PERMILL_SYMBOL"); + break; + case 14: + strcpy(str, "I18N_UNUMBER_PAD_ESCAPE_SYMBOL"); + break; + case 15: + strcpy(str, "I18N_UNUMBER_INFINITY_SYMBOL"); + break; + case 16: + strcpy(str, "I18N_UNUMBER_NAN_SYMBOL"); + break; + case 17: + strcpy(str, "I18N_UNUMBER_SIGNIFICANT_DIGIT_SYMBOL"); + break; + case 18: + strcpy(str, "I18N_UNUMBER_MONETARY_GROUPING_SEPARATOR_SYMBOL"); + break; + case 19: + strcpy(str, "I18N_UNUMBER_ONE_DIGIT_SYMBOL"); + break; + case 20: + strcpy(str, "I18N_UNUMBER_TWO_DIGIT_SYMBOL"); + break; + case 21: + strcpy(str, "I18N_UNUMBER_THREE_DIGIT_SYMBOL"); + break; + case 22: + strcpy(str, "I18N_UNUMBER_FOUR_DIGIT_SYMBOL"); + break; + case 23: + strcpy(str, "I18N_UNUMBER_FIVE_DIGIT_SYMBOL"); + break; + case 24: + strcpy(str, "I18N_UNUMBER_SIX_DIGIT_SYMBOL"); + break; + case 25: + strcpy(str, "I18N_UNUMBER_SEVEN_DIGIT_SYMBOL"); + break; + case 26: + strcpy(str, "I18N_UNUMBER_EIGHT_DIGIT_SYMBOL"); + break; + case 27: + strcpy(str, "I18N_UNUMBER_NINE_DIGIT_SYMBOL"); + break; + default: + strcpy(str, "err"); + break; + } + } else if (type == "iter_type") { + switch (num) { + case 0: + strcpy(str, "I18N_UBRK_CHARACTER"); + break; + case 1: + strcpy(str, "I18N_UBRK_WORD"); + break; + case 2: + strcpy(str, "I18N_UBRK_LINE"); + break; + case 3: + strcpy(str, "I18N_UBRK_SENTENCE"); + break; + default: + strcpy(str, "err"); + break; + } + } + PRINT_DEBUG_LOG("return string: %s\n", str); + return str; +} + +static int __get_date_and_time() +{ + printf(" * To get various date and time format\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); + + 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; + i18n_uchar pattern[BUF_SIZE]; + 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"); + 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); + printf("TIME[%-17.17s] DATE[%-26.26s] : %s\n", __print_i18n_type_string("time", n_enum_time_counter), __print_i18n_type_string("date", n_enum_date_counter), s); + } + } + return 0; +} + +static int __get_number_format(char *input_number) +{ + printf(" * To get various number format\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]; + + 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); + + printf("NUMBER_FORMAT[%-30.30s] : %s\n", __print_i18n_type_string("number_format", i), string); + } + + /* Release the decimal number formatter. */ + error_code = i18n_unumber_destroy(num_format); + CHECK_ERROR("i18n_unumber_destroy", error_code); +} + +static int __get_symbol() +{ + printf(" * To get various number symbol\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; + 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); + printf("SYMBOL[%-47.47s] : %s\n", __print_i18n_type_string("symbol", i+1), string); + } + + /* Release the default number formatter object. */ + error_code = i18n_unumber_destroy(num_format); + CHECK_ERROR("i18n_unumber_destroy", error_code); +} + +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"); + + i18n_uchar lang[BUF_SIZE]; + + /* 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); +} + +static int __manage_string_iteration(char *input_string) +{ + printf(" * To manage the string iteration\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("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[1000] = {0,}; + strncpy(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; + + /* 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); + 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); + printf("ITER First element[%-19.19s] : %s\n", __print_i18n_type_string("iter_type", i), str); + } + + /* 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); + 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); + printf("ITER Last element[%-19.19s] : %s\n", __print_i18n_type_string("iter_type", i), str); + } + + free(string_to_examine); + error_code = i18n_ubrk_destroy(boundary); + CHECK_ERROR("i18n_ubrk_destroy", error_code); +} + +static int __analyze_string(char *custom_string) +{ + printf(" * To manage the string\n"); + + i18n_uchar *string_to_examine; + + if (!custom_string) { + char *input_text = "String"; + 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); + } else { + char *input_text = custom_string; + 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; + + /* 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, &error_code); + CHECK_ERROR("i18n_ustring_to_title_new", error_code); + i18n_ustring_copy_au(s, dest); + printf("To Title : %s\n", s); + +} + +static int __get_timezone_info() +{ + printf(" * To get time zone information\n"); + + static i18n_timezone_h tmz; + + /* 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; + 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); + + /* 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); + + /* Release the time zone object. */ + error_code = i18n_timezone_destroy(tmz); + CHECK_ERROR("i18n_timezone_destroy", error_code); +} + +static int __get_tzdata_version() +{ + const char *ver = i18n_timezone_get_tzdata_version(); + printf("tzdata version : %s\n", ver); +} + +void allTest() +{ + int ret, 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 * locales : %s\n", default_locale); + ret = __get_date_and_time(); + printf("\n"); + ret = __get_number_format("3.5"); + printf("\n"); + ret = __get_symbol(); + printf("\n"); + ret = __get_language_info(); + printf("\n"); + } + ret = __manage_string_iteration(NULL); + printf("\n"); + ret = __analyze_string(NULL); + printf("\n"); + ret = __get_timezone_info(); + 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, 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 * 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 * 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; + ret = __get_timezone_info(); + if (ret == -1) { + printf("get i18n time zone info list failed\n"); + } +} + +void showTzdataVersion() +{ + __get_tzdata_version(); +} + +void testDatentime(char *locale) +{ + int ret, 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 * locales : %s\n", default_locale); + ret = __get_date_and_time(); + } + 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(); + if (ret == -1) { + printf("get i18n date and time list failed\n"); + } + + } +} + +void testNumberFormat(char *input, char *locale) +{ + int ret, 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 * 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 * 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, 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 * locales : %s\n", default_locale); + ret = __get_symbol(); + } + if (ret == -1) { + printf("get i18n symbol list failed\n"); + } + } else { + default_locale = locale; + 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; + + ret = __analyze_string(input); + if (ret == -1) { + printf("get i18n string list failed\n"); + } +} + +void testStringIter(char *input) +{ + int ret = 0; + + ret = __manage_string_iteration(input); + if (ret == -1) { + printf("get i18n string iteration list failed\n"); + } +} + +int main(int argc, char *argv[]) +{ + int ret = 0, i = 0; + + struct arguments arguments = {0,}; + + 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.testDatentime) { + testDatentime(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(); + } + + return 0; +} diff --git a/i18ninfo/i18ninfo_argp.h b/i18ninfo/i18ninfo_argp.h new file mode 100644 index 0000000..2f45ee4 --- /dev/null +++ b/i18ninfo/i18ninfo_argp.h @@ -0,0 +1,138 @@ +#include +#include +#include + + + +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"; +/* 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 }, + { 0 } +}; + +struct arguments { + int arg_flag; + int all; + int showAllLocale; + int showLangInfo; + int showTimezone; + int showTzdataVersion; + int testDatentime; + int testNumberFormat; + int testNumberSymbol; + int testString; + int testStringIter; + + char *arg1; /* arg1 */ + char **strings; /* [string…] */ + + char *testNumberFormatArg; + char *testStringArg; + char *testStringIterArg; + char *setLocale; +}; + +/* Parse a single option. */ +static error_t +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; + char *nextArg; + + /*printf("key [%x] [%c] arg [%s]\n", key, key, arg); */ + + switch (key) { + case 'a': + arguments->arg_flag = 1; + arguments->all = 1; + break; + case 'L': + arguments->arg_flag = 2; + arguments->showAllLocale = 1; + break; + case 'I': + arguments->arg_flag = 3; + arguments->showLangInfo = 1; + break; + case 'T': + arguments->arg_flag = 4; + arguments->showTimezone = 1; + break; + case 'Z': + arguments->arg_flag = 5; + arguments->showTzdataVersion = 1; + break; + case 'd': + arguments->arg_flag = 6; + arguments->testDatentime = 1; + break; + case 'n': + arguments->arg_flag = 7; + arguments->testNumberFormat = 1; + arguments->testNumberFormatArg = arg; + break; + case 'N': + arguments->arg_flag = 8; + arguments->testNumberSymbol = 1; + break; + case 's': + arguments->arg_flag = 9; + arguments->testString = 1; + + nextArg = state->argv[state->next]; + if (nextArg && *nextArg != '-') { + arguments->testStringArg = nextArg; + state->next++; + } + break; + case 'S': + arguments->arg_flag = 10; + arguments->testStringIter = 1; + + nextArg = state->argv[state->next]; + if (nextArg && *nextArg != '-') { + arguments->testStringIterArg = nextArg; + state->next++; + } + break; + case 'l': + arguments->setLocale = arg; + break; + + case ARGP_KEY_NO_ARGS: + if (arguments->arg_flag == 0) { + argp_usage(state); + } + + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +/* Our argp parser. */ +static struct argp argp = { options, parse_opt, args_doc, doc }; + + diff --git a/packaging/capi-base-utils.spec b/packaging/capi-base-utils.spec index c23590e..628c03c 100755 --- a/packaging/capi-base-utils.spec +++ b/packaging/capi-base-utils.spec @@ -1,6 +1,6 @@ Name: capi-base-utils Summary: Base Utils -Version: 2.0.2 +Version: 3.0.0 Release: 1 Group: Base License: Apache-2.0 and ICU @@ -21,11 +21,6 @@ License: Apache-2.0 and ICU Summary: The Base Utils Library (Development) Group: Base Requires: %{name} = %{version}-%{release} -Provides: capi-base-utils-devel-profile_common = %{version}-%{release} -Provides: capi-base-utils-devel-profile_mobile = %{version}-%{release} -Provides: capi-base-utils-devel-profile_ivi = %{version}-%{release} -Provides: capi-base-utils-devel-profile_tv = %{version}-%{release} -Provides: capi-base-utils-devel-profile_wearable = %{version}-%{release} %description devel The base utils library for internationalization and localization (Development) @@ -34,7 +29,6 @@ The base utils library for internationalization and localization (Development) %setup -q %build -#export CFLAGS="$CFLAGS -Wall -Werror -Wno-unused-function" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIB_INSTALL_DIR:PATH=%{_libdir} -DINCLUDE_INSTALL_DIR:PATH=%{_includedir} \ -DPKG_NAME=%{name} -DPKG_VERSION=%{version} \ @@ -43,9 +37,6 @@ make %{?jobs:-j%jobs} %install rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}/usr/share/license -cp LICENSE %{buildroot}/usr/share/license/%{name} -cat LICENSE.ICU >> %{buildroot}/usr/share/license/%{name} %post -p /sbin/ldconfig @@ -54,7 +45,7 @@ cat LICENSE.ICU >> %{buildroot}/usr/share/license/%{name} %files %manifest capi-base-utils.manifest %{_libdir}/libbase-utils-i18n.so* -/usr/share/license/%{name} +%license LICENSE LICENSE.ICU %files devel %defattr(-,root,root,-) diff --git a/packaging/i18ninfo.spec b/packaging/i18ninfo.spec new file mode 100755 index 0000000..773a9c5 --- /dev/null +++ b/packaging/i18ninfo.spec @@ -0,0 +1,32 @@ +Name: i18ninfo +Summary: The Base Utils Tool +Version: 1.0.0 +Release: 1 +Group: Base +License: Apache-2.0 and ICU +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(capi-base-utils-i18n) + +%description +The base utils library test tool + +%prep +%setup -q + +%build +pushd i18ninfo +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DBIN_INSTALL_DIR:PATH=%{_bindir} -DINCLUDE_INSTALL_DIR:PATH=%{_includedir} \ + -DPKG_NAME=%{name} -DPKG_VERSION=%{version} +make %{?jobs:-j%jobs} +popd + +%install +#rm -rf %{buildroot} +pushd i18ninfo +%make_install +popd + +%files +%defattr(-,root,root,-) +%{_bindir}/i18ninfo