From: Hyunjee Kim Date: Thu, 11 Jan 2018 06:44:08 +0000 (+0900) Subject: [i18ninfo] Add timezoneId option in timezone info menu X-Git-Tag: submit/tizen/20180118.063705^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=870173dbb994913d9ef2510b65ae6adbab7ffb7f;p=platform%2Fcore%2Fapi%2Fbase-utils.git [i18ninfo] Add timezoneId option in timezone info menu Change-Id: Ie612efc5bacf146019f858d34cc79de1ca1a9bfe Signed-off-by: Hyunjee Kim --- diff --git a/i18ninfo/i18ninfo.cpp b/i18ninfo/i18ninfo.cpp index 2ba443e..5168ad3 100644 --- a/i18ninfo/i18ninfo.cpp +++ b/i18ninfo/i18ninfo.cpp @@ -873,22 +873,50 @@ static int __analyze_string(char *custom_string) return 0; } -static int __get_timezone_info() +bool timezone_cb(const char *timezone_id, void *user_data) +{ + printf("%s\n", timezone_id); + return true; +} + +static int __get_available_timezone() { int ret = 0; - printf(" - To get time zone information\n"); + printf(" - To get the list of time zone"); printf("****************************************\n"); + ret = i18n_timezone_foreach_timezone_id(timezone_cb, NULL); + CHECK_ERROR("i18n_timezone_foreach_timezone_id", ret); + + return 0; +} + +static int __get_timezone_info(char *timezone_id) +{ + int ret = 0; + printf(" - To get time zone information\n"); + static i18n_timezone_h tmz; + if (!timezone_id) { + /* Get the default timezone. */ + ret = i18n_timezone_create_default(&tmz); + CHECK_ERROR("18n_timezone_create_default", ret); + ret = i18n_timezone_get_id(tmz, &timezone_id); + CHECK_ERROR("i18n_timezone_get_id", ret); + printf(" - Default timezone Id : %s\n", timezone_id); + } else { + ret = i18n_timezone_create(&tmz, timezone_id); + CHECK_ERROR("18n_timezone_create", ret); + printf(" - Input timezone Id : %s\n", timezone_id); + } + + printf("****************************************\n"); + 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); @@ -896,7 +924,6 @@ static int __get_timezone_info() 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); @@ -1385,7 +1412,7 @@ void allTest() printf("\n"); printf("\n== Timezone Info"); printf("\n****************************************\n"); - ret = __get_timezone_info(); + ret = __get_timezone_info(NULL); printf("\n"); printf("\n== TZ Data Version Info"); @@ -1430,17 +1457,29 @@ void showLangInfo(char *locale) } } -void showTimezone() +void showTimezone(char *timezone_id) { int ret = 0; printf("\n== Timezone Info"); printf("\n****************************************\n"); - ret = __get_timezone_info(); + ret = __get_timezone_info(timezone_id); if (ret == -1) { printf("get i18n time zone info list failed\n"); } } +void showAllTimezone() +{ + + int ret = 0; + printf("\n== List of Timezone"); + printf("\n****************************************\n"); + ret = __get_available_timezone(); + if (ret != 0) { + printf("get the list of time zone failed\n"); + } +} + void showTzdataVersion() { printf("\n== TZ Data Version Info"); @@ -1668,7 +1707,11 @@ int main(int argc, char *argv[]) } if (arguments.showTimezone) { - showTimezone(); + showTimezone(arguments.timezoneId); + } + + if (arguments.showAllTimezone) { + showAllTimezone(); } if (arguments.showTzdataVersion) { diff --git a/i18ninfo/i18ninfo_argp.h b/i18ninfo/i18ninfo_argp.h index 5f1f224..3302eb2 100644 --- a/i18ninfo/i18ninfo_argp.h +++ b/i18ninfo/i18ninfo_argp.h @@ -16,7 +16,8 @@ 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-all-timezone", 'T', 0, 0, "Show all supported timezone list", 0 }, + {"show-timezone", 't', "TimezoneId", OPTION_ARG_OPTIONAL, "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 }, @@ -40,6 +41,7 @@ struct arguments { int showAllLocale; int showLangInfo; int showTimezone; + int showAllTimezone; int showTzdataVersion; int showDateFormat; int testDatentime; @@ -67,6 +69,7 @@ struct arguments { char *testNumberConvertArg; char *testInputNumArg; #endif + char *timezoneId; }; /* Parse a single option. */ @@ -93,9 +96,16 @@ parse_opt(int key, char *arg, struct argp_state *state) arguments->arg_flag = 3; arguments->showLangInfo = 1; break; - case 'T': + case 't': arguments->arg_flag = 4; arguments->showTimezone = 1; + + nextArg = state->argv[state->next]; + if (nextArg && *nextArg != '-') { + arguments->timezoneId = nextArg; + state->next++; + } + break; case 'Z': arguments->arg_flag = 5; @@ -189,6 +199,11 @@ parse_opt(int key, char *arg, struct argp_state *state) #endif + case 'T': + arguments->arg_flag = 15; + arguments->showAllTimezone = 1; + break; + case ARGP_KEY_NO_ARGS: if (arguments->arg_flag == 0) { argp_usage(state);