From: DongHun Kwak Date: Tue, 30 May 2017 07:52:59 +0000 (+0900) Subject: Change i18ninfo.c to i18ninfo.cpp X-Git-Tag: accepted/tizen/unified/20170531.082752^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F131620%2F5;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.cpp similarity index 89% rename from i18ninfo/i18ninfo.c rename to i18ninfo/i18ninfo.cpp index d185361..e07bd23 100644 --- a/i18ninfo/i18ninfo.c +++ b/i18ninfo/i18ninfo.cpp @@ -17,7 +17,7 @@ static int ASCIIDOC_FLAG = 0; #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",\ + fprintf(stderr, "\033[0;31m%s failed! Error: %s [code: %d] \033[0m\n", \ func_name, get_error_message(error_code), error_code); \ } @@ -37,7 +37,7 @@ static int ASCIIDOC_FLAG = 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_uchar default_timezone_id[BUF_SIZE] = {0, }; i18n_udate_format_style_e eTimeFormatStyle[] = { I18N_UDATE_FULL, @@ -94,7 +94,8 @@ static reordering_mode reordering_modes[N_MODES] = { 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; +int n_enum_time_counter, n_enum_date_counter; +i18n_error_code_e error_code; static void __get_available_locales(); @@ -116,11 +117,11 @@ static void __get_available_locales() int32_t loc_count, i; loc_count = i18n_ulocale_count_available(); - if (loc_count == 0) + if (loc_count == 0) { printf("empty\n"); - else if (loc_count < 0) + } else if (loc_count < 0) { printf("wrong\n"); - else { + } else { PRINT_DEBUG_LOG("locale count : %d\n", loc_count); for (i = 0; i < loc_count; i++) { loc_list = i18n_ulocale_get_available(i); @@ -142,7 +143,7 @@ static void init_env() char *__print_i18n_type_string(char *type, int num) { - char *str = calloc(300, sizeof(char)); + char *str = (char*)calloc(300, sizeof(char)); PRINT_DEBUG_LOG("input type: %s, num: %d\n", type, num); if (!strcmp(type, "time")) { switch (num) { @@ -352,17 +353,20 @@ char *__print_i18n_type_string(char *type, int num) 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_uchar timezone[BUF_SIZE] = {0, }; i18n_ustring_copy_ua_n(timezone, default_locale, BUF_SIZE); - i18n_uchar pattern[BUF_SIZE] = {0,}; + 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); + 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")) { + if (!strcmp(type, "day")) { + date_now += i * 86400000; + } else if (!strcmp(type, "month")) { int k; for (k = 0; k < i; k++) date_now += 2678400000; @@ -372,7 +376,7 @@ static char *_date_basic_format_convert(char *input_pattern, int i, char *type) 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); + 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); @@ -491,13 +495,14 @@ i18n_udate _time_convert(char *input_time) 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) { - int error_code = i18n_ucalendar_get_now(&date_now); - CHECK_ERROR("i18n_ucalendar_get_now", error_code); + 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); @@ -506,8 +511,8 @@ static int __get_date_and_time(char *input_time) 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); + 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); @@ -516,8 +521,8 @@ static int __get_date_and_time(char *input_time) 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); + 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"); @@ -525,15 +530,15 @@ static int __get_date_and_time(char *input_time) 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], + 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", error_code); + CHECK_ERROR("i18n_udate_create", ret); 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); + 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); @@ -554,6 +559,8 @@ static int __get_date_and_time(char *input_time) 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); @@ -569,8 +576,8 @@ static int __get_number_format(char *input_number) 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); + 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); @@ -588,8 +595,8 @@ static int __get_number_format(char *input_number) PRINT_ASCIIDOC_LOG("|===\n"); /* Release the decimal number formatter. */ - error_code = i18n_unumber_destroy(num_format); - CHECK_ERROR("i18n_unumber_destroy", error_code); + ret = i18n_unumber_destroy(num_format); + CHECK_ERROR("i18n_unumber_destroy", ret); return 0; } @@ -601,8 +608,8 @@ static int __get_symbol() /* 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 ret = i18n_unumber_create(I18N_UNUMBER_DEFAULT, NULL, -1, default_locale, NULL, &num_format); + CHECK_ERROR("18n_unumber_create", ret); int i; @@ -613,8 +620,8 @@ static int __get_symbol() /* 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); + 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]; @@ -628,8 +635,8 @@ static int __get_symbol() PRINT_ASCIIDOC_LOG("|===\n"); /* Release the default number formatter object. */ - error_code = i18n_unumber_destroy(num_format); - CHECK_ERROR("i18n_unumber_destroy", error_code); + ret = i18n_unumber_destroy(num_format); + CHECK_ERROR("i18n_unumber_destroy", ret); return 0; } @@ -673,9 +680,9 @@ static int __get_language_info() i18n_uchar name[BUF_SIZE]; int name_len; - int error_code = + int ret = i18n_ulocale_get_display_name(default_locale, default_locale, name, BUF_SIZE, &name_len); - CHECK_ERROR("i18n_ulocale_get_display_name", error_code); + 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); @@ -691,8 +698,8 @@ static int __get_language_info() /* 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); + 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. */ @@ -701,21 +708,21 @@ static int __get_language_info() /* 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); + 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. */ - error_code = i18n_ulocale_get_character_orientation(default_locale, &type); - CHECK_ERROR("i18n_ulocale_get_character_orientation", error_code); + 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]; - error_code = i18n_ulocale_get_variant(default_locale, variant, BUF_SIZE); - CHECK_ERROR("i18n_ulocale_get_variant", error_code); + 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"); @@ -738,7 +745,7 @@ static int __manage_string_iteration(char *input_string) (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,}; + char input_text[1000] = {0, }; COPY_STR(input_text, input_string, 999); printf("Input string : %s\n", input_text); string_to_examine = @@ -747,6 +754,7 @@ static int __manage_string_iteration(char *input_string) } int i; + int ret = 0; char *iter_type; PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n"); @@ -756,8 +764,8 @@ static int __manage_string_iteration(char *input_string) /* 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); + 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)); @@ -780,8 +788,8 @@ static int __manage_string_iteration(char *input_string) /* 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); + 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)); @@ -798,8 +806,8 @@ static int __manage_string_iteration(char *input_string) PRINT_ASCIIDOC_LOG("|===\n"); free(string_to_examine); - error_code = i18n_ubrk_destroy(boundary); - CHECK_ERROR("i18n_ubrk_destroy", error_code); + ret = i18n_ubrk_destroy(boundary); + CHECK_ERROR("i18n_ubrk_destroy", ret); return 0; } @@ -861,6 +869,7 @@ static int __analyze_string(char *custom_string) static int __get_timezone_info() { + int ret = 0; printf(" - To get time zone information\n"); printf("****************************************\n"); @@ -871,25 +880,25 @@ static int __get_timezone_info() printf("| KEY | VALUE\n"); /* Get the default timezone. */ - error_code = i18n_timezone_create_default(&tmz); - CHECK_ERROR("18n_timezone_create_default", error_code); + ret = i18n_timezone_create_default(&tmz); + CHECK_ERROR("18n_timezone_create_default", ret); /* 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); + 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; - error_code = i18n_timezone_get_id(tmz, &timezone_id); - CHECK_ERROR("i18n_timezone_get_id", error_code); + 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; - error_code = i18n_timezone_use_daylight_time(tmz, &daylight_time); - CHECK_ERROR("i18n_timezone_use_daylight_time", error_code); + 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"); /* @@ -897,14 +906,14 @@ static int __get_timezone_info() * 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); + 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; - error_code = i18n_timezone_get_raw_offset(tmz, &offset_milliseconds); - CHECK_ERROR("i18n_timezone_get_raw_offset", error_code); + 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 @@ -913,15 +922,15 @@ static int __get_timezone_info() /* 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); + 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. */ - error_code = i18n_timezone_destroy(tmz); - CHECK_ERROR("i18n_timezone_destroy", error_code); + ret = i18n_timezone_destroy(tmz); + CHECK_ERROR("i18n_timezone_destroy", ret); free(timezone_id); return 0; @@ -969,8 +978,8 @@ static int __show_ubidi(char *input_text) 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); + 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); @@ -978,16 +987,16 @@ static int __show_ubidi(char *input_text) 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); + 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++) { - error_code = i18n_ubidi_write_reordered(ubidi, reordering_options[j].option, BUF_SIZE, + ret = i18n_ubidi_write_reordered(ubidi, reordering_options[j].option, BUF_SIZE, dst, &output_length); - CHECK_ERROR("i18n_ubidi_write_reordered", error_code); + CHECK_ERROR("i18n_ubidi_write_reordered", ret); char buffer[BUF_SIZE]; i18n_ustring_copy_au(buffer, dst); @@ -1263,7 +1272,7 @@ void testStringIter(char *input) int main(int argc, char *argv[]) { - struct arguments arguments = {0,}; + struct arguments arguments = {0, }; init_env(); argp_parse(&argp, argc, argv, 0, 0, &arguments); 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