#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); \
}
#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,
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();
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);
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) {
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;
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);
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);
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);
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");
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);
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);
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);
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;
}
/* 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;
/* 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];
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;
}
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);
/* 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. */
/* 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");
(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 =
}
int i;
+ int ret = 0;
char *iter_type;
PRINT_ASCIIDOC_LOG("\n[options=\"header\"]\n");
/* 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));
/* 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));
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;
}
static int __get_timezone_info()
{
+ int ret = 0;
printf(" - To get time zone information\n");
printf("****************************************\n");
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");
/*
* 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
/* 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;
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);
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);
int main(int argc, char *argv[])
{
- struct arguments arguments = {0,};
+ struct arguments arguments = {0, };
init_env();
argp_parse(&argp, argc, argv, 0, 0, &arguments);