diff --git a/sources/configure.ac b/sources/configure.ac index 63bc0ab..3f8c688 100644 --- a/sources/configure.ac +++ b/sources/configure.ac @@ -16,7 +16,7 @@ AC_PATH_PROG(RM, rm, /bin/rm) AC_PATH_PROG(RMDIR, rmdir, /bin/rmdir) # Checks for header files. -AC_CHECK_HEADERS([time.h limits.h stdlib.h string.h sys/time.h unistd.h]) +AC_CHECK_HEADERS([time.h limits.h stdlib.h string.h sys/time.h unistd.h langinfo.h]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_SIZE_T diff --git a/sources/libjalali/jalali.c b/sources/libjalali/jalali.c index a531514..d7de8db 100644 --- a/sources/libjalali/jalali.c +++ b/sources/libjalali/jalali.c @@ -45,6 +45,69 @@ } \ } +/** Set locale from the environment. + * + * In case `HAVE_LANGINFO_H` (`langinfo.h` is defined), this will set the + * locale, in any other case, does nothing. + */ +void setlocale_from_env() { +#ifdef HAVE_LANGINFO_H + setlocale(LC_ALL, ""); +#endif /* HAVE_LANGINFO_H */ +} + +char *abdow(int __item) { +#ifdef HAVE_LANGINFO_H +#define __CASE_NL(n, fallback) \ + case n: \ + return nl_langinfo(ABDAY_##n) +#else /* !HAVE_LANGINFO_H */ +#define __CASE_NL(n, fallback) \ + case n: \ + return (char *)fallback +#endif /* HAVE_LANGINFO_H */ + + switch (__item) { + __CASE_NL(1, "Sun"); + __CASE_NL(2, "Mon"); + __CASE_NL(3, "Tue"); + __CASE_NL(4, "Wed"); + __CASE_NL(5, "Thu"); + __CASE_NL(6, "Fri"); + __CASE_NL(7, "Sat"); + default: + return (char *)""; + } + +#undef __CASE_NL +} + +char *dow(int __item) { +#ifdef HAVE_LANGINFO_H +#define __CASE_NL(n, fallback) \ + case n: \ + return nl_langinfo(DAY_##n) +#else /* !HAVE_LANGINFO_H */ +#define __CASE_NL(n, fallback) \ + case n: \ + return (char *)fallback +#endif /* HAVE_LANGINFO_H */ + + switch (__item) { + __CASE_NL(1, "Sunday"); + __CASE_NL(2, "Monday"); + __CASE_NL(3, "Tuesday"); + __CASE_NL(4, "Wednesday"); + __CASE_NL(5, "Thursday"); + __CASE_NL(6, "Friday"); + __CASE_NL(7, "Saturday"); + default: + return (char *)""; + } + +#undef __CASE_NL +} + const int cycle_patterns[] = {J_PT0, J_PT1, J_PT2, J_PT3, INT_MAX}; const int leaps[] = {J_L0, J_L1, J_L2, J_L3, INT_MAX}; diff --git a/sources/libjalali/jalali.h b/sources/libjalali/jalali.h index 3729e90..bf1af6f 100644 --- a/sources/libjalali/jalali.h +++ b/sources/libjalali/jalali.h @@ -33,6 +33,48 @@ extern "C" { #define LIBJALALI_VERSION "0.5.1" +#ifdef HAVE_LANGINFO_H +#include +#include +#endif /* HAVE_LANGINFO_H */ + +/** Set locale from the environment. + * + * In case `HAVE_LANGINFO_H` (`langinfo.h` is defined), this will set the + * locale, in any other case, does nothing. + */ +void setlocale_from_env(); + +/** Return the day of week in a locale or English for 1 to 7 (Sun = 1). + * + * In case `HAVE_LANGINFO_H` (`langinfo.h` is defined), this will use `DAY_n` + * in localized context, otherwise, it's just hardcoded English days of week. + * + * @return the localized name of the day of the week or empty if not 1-7. + */ +char *dow(int __item); + +/** Return the first 3 letters of `dow` in a locale for 1 to 7 (Sun = 1). + * + * This function is exactly as `dow`, see that for more information. + * + * There is no guarantee that this will return a string equal to 3, less or + * more since this might be set from the locales. The user must check the length + * and prepare proper paddings and else when using the abbrevations. Also, this + * string is ASCII hence slicing into it manually may lead to invalid + * characters. + * + * For this very reason, there is no "3 letters only" or "2 letters only" + * variations of this function as before. + */ +char *abdow(int __item); + +/** Do as in `dow` but Saturday is 0 instead of 7. */ +#define DOW06(n) (dow((n == 0) ? 7 : n)) + +/** Do as in `abdow` but Saturday is 0 instead of 7. */ +#define ABDOW06(n) (abdow((n == 0) ? 7 : n)) + struct jtm { int tm_sec; /* Seconds. (0-59) */ int tm_min; /* Minutes. (0-59) */ diff --git a/sources/libjalali/jtime.c b/sources/libjalali/jtime.c index e30e04d..fc4a128 100644 --- a/sources/libjalali/jtime.c +++ b/sources/libjalali/jtime.c @@ -29,36 +29,11 @@ #include "jtime.h" const char *GMT_ZONE = "UTC"; -const char *GMT_ZONE_fa = "گرینویچ"; const char *jalali_months[] = { "Farvardin", "Ordibehesht", "Khordaad", "Tir", "Mordaad", "Shahrivar", "Mehr", "Aabaan", "Aazar", "Dey", "Bahman", "Esfand"}; -const char *fa_jalali_months[] = {"فروردین", "اردیبهشت", "خرداد", "تیر", - "مرداد", "شهریور", "مهر", "آبان", - "آذر", "دی", "بهمن", "اسفند"}; -const char *jalali_months_3[] = {"Far", "Ord", "Kho", "Tir", "Mor", "Sha", - "Meh", "Aba", "Aza", "Dey", "Bah", "Esf"}; -const char *fa_jalali_months_3[] = {"فرو", "ارد", "خرد", "تیر", "مرد", "شهر", - "مهر", "آبا", "آذر", "دی ", "بهم", "اسف"}; -const char *jalali_days_fa[] = { - "Shanbeh", "Yek-Shanbeh", "Do-Shanbeh", "Seh-Shanbeh", - "Chahaar-Shanbeh", "Panj-Shanbeh", "Jomeh"}; -const char *fa_jalali_days[] = {"شنبه", "یکشنبه", "دوشنبه", "سه شنبه", - "چهارشنبه", "پنجشنبه", "جمعه"}; -const char *jalali_days_3_fa[] = {"Sha", "Yek", "Dos", "Ses", - "Cha", "Pan", "Jom"}; -const char *fa_jalali_days_3[] = {"شنب", "یکش", "دوش", "سهش", - "چها", "پنج", "جمع"}; -const char *jalali_days_2_fa[] = {"Sh", "Ye", "Do", "Se", "Ch", "Pa", "Jo"}; - -const char *fa_jalali_days_2[] = {"شن", "یک", "دو", "سه", "چه", "پن", "جم"}; -const char *jalali_days[] = {"Saturday", "Sunday", "Monday", "Tuesday", - "Wednesday", "Thursday", "Friday"}; -const char *jalali_days_3[] = {"Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri"}; -const char *jalali_days_2[] = {"Sa", "Su", "Mo", "Tu", "We", "Th", "Fr"}; -const char *farsi_digits[] = {"۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"}; - -const char *tzname_fa[2] = {"زمان زمستانی", "زمان تابستانی"}; +const char *ab_jalali_months[] = {"Far", "Ord", "Kho", "Tir", "Mor", "Sha", + "Meh", "Aba", "Aza", "Dey", "Bah", "Esf"}; static char in_buf[MAX_BUF_SIZE] = {0}; static struct jtm in_jtm; @@ -80,14 +55,13 @@ void in_jasctime(const struct jtm *jtm, char *buf) { return; if (buf) { - sprintf(buf, "%s %s %02d %02d:%02d:%02d %d\n", - jalali_days_3_fa[jtm->tm_wday], jalali_months_3[jtm->tm_mon], - jtm->tm_mday, jtm->tm_hour, jtm->tm_min, jtm->tm_sec, jtm->tm_year); + sprintf(buf, "%s %s %02d %02d:%02d:%02d %d\n", ABDOW06(jtm->tm_wday), + ab_jalali_months[jtm->tm_mon], jtm->tm_mday, jtm->tm_hour, + jtm->tm_min, jtm->tm_sec, jtm->tm_year); } else { snprintf(in_buf, MAX_BUF_SIZE, "%s %s %02d %02d:%02d:%02d %d\n", - jalali_days_3_fa[jtm->tm_wday], jalali_months_3[jtm->tm_mon], - jtm->tm_mday, jtm->tm_hour, jtm->tm_min, jtm->tm_sec, - jtm->tm_year); + ABDOW06(jtm->tm_wday), ab_jalali_months[jtm->tm_mon], jtm->tm_mday, + jtm->tm_hour, jtm->tm_min, jtm->tm_sec, jtm->tm_year); } } @@ -249,17 +223,17 @@ size_t jstrftime(char *s, size_t max, const char *format, switch (format[i + 1]) { /* The abbreviated weekday name. */ case 'a': - strncpy(buf, jalali_days_3[jtm->tm_wday], MAX_BUF_SIZE); + strncpy(buf, ABDOW06(jtm->tm_wday), MAX_BUF_SIZE); break; /* The full weekday name. */ case 'A': - strncpy(buf, jalali_days[jtm->tm_wday], MAX_BUF_SIZE); + strncpy(buf, DOW06(jtm->tm_wday), MAX_BUF_SIZE); break; /* The abbreviated month name. */ case 'b': - strncpy(buf, jalali_months_3[jtm->tm_mon], MAX_BUF_SIZE); + strncpy(buf, ab_jalali_months[jtm->tm_mon], MAX_BUF_SIZE); break; /* The full month name. */ @@ -274,8 +248,8 @@ size_t jstrftime(char *s, size_t max, const char *format, case 'c': tzset(); snprintf(buf, MAX_BUF_SIZE, "%s %d %s %d %02d:%02d:%02d %s", - jalali_days_3_fa[jtm->tm_wday], jtm->tm_mday, - jalali_months_3[jtm->tm_mon], jtm->tm_year, jtm->tm_hour, + ABDOW06(jtm->tm_wday), jtm->tm_mday, + ab_jalali_months[jtm->tm_mon], jtm->tm_year, jtm->tm_hour, jtm->tm_min, jtm->tm_sec, jtm->tm_zone); break; @@ -303,25 +277,6 @@ size_t jstrftime(char *s, size_t max, const char *format, snprintf(buf, MAX_BUF_SIZE, "%2d", jtm->tm_mday); break; - /* - * The preferred date and time representation in Farsi. (utf8) - * example: سه شنبه ۱۷ خرداد ۱۳۹۰، ساعت ۰۸:۱۹:۲۳ (IRDT) - */ - case 'E': - tzset(); - jalali_to_farsi(_l1, 10, 2, "۰", jtm->tm_hour); - jalali_to_farsi(_l2, 10, 2, "۰", jtm->tm_min); - jalali_to_farsi(_l3, 10, 2, "۰", jtm->tm_sec); - jalali_to_farsi(_la, 100, 2, "۰", jtm->tm_mday); - jalali_to_farsi(_lb, 100, 0, " ", jtm->tm_year); - snprintf(buf, MAX_BUF_SIZE, "%s %s %s %s، ساعت %s:%s:%s - %s", - fa_jalali_days[jtm->tm_wday], _la, - fa_jalali_months[jtm->tm_mon], _lb, _l1, _l2, _l3, - (jtm->tm_zone == GMT_ZONE) ? GMT_ZONE_fa - : tzname_fa[jtm->tm_isdst]); - - break; - /* * Equivalent to %Y-%m-%d (similar to the ISO 8601 date format). */ @@ -330,36 +285,6 @@ size_t jstrftime(char *s, size_t max, const char *format, jtm->tm_mon + 1, jtm->tm_mday); break; - /* The abbreviated weekday name. (Farsi-UTF8) */ - case 'g': - strncpy(buf, fa_jalali_days_3[jtm->tm_wday], MAX_BUF_SIZE); - break; - - /* The full weekday name. (Farsi-UTF8) */ - case 'G': - strncpy(buf, fa_jalali_days[jtm->tm_wday], MAX_BUF_SIZE); - break; - - /* The abbreviated month name. (Farsi-UTF8) */ - case 'v': - strncpy(buf, fa_jalali_months_3[jtm->tm_mon], MAX_BUF_SIZE); - break; - - /* The full month name. (Farsi-UTF8) */ - case 'V': - strncpy(buf, fa_jalali_months[jtm->tm_mon], MAX_BUF_SIZE); - break; - - /* The abbreviated weekday name. (Farsi) */ - case 'h': - strncpy(buf, jalali_days_3_fa[jtm->tm_wday], MAX_BUF_SIZE); - break; - - /* The full weekday name. (Farsi) */ - case 'q': - strncpy(buf, jalali_days_fa[jtm->tm_wday], MAX_BUF_SIZE); - break; - /* * The hour as a decimal number using a 24-hour clock * (range 00 to 23). @@ -420,15 +345,6 @@ size_t jstrftime(char *s, size_t max, const char *format, snprintf(buf, MAX_BUF_SIZE, "\n"); break; - /* - * Either "ق.ظ" or "ب.ظ" according to the given time value. - * Noon is treated as "ق.ظ" and midnight as "ب.ظ". - */ - case 'O': - snprintf(buf, MAX_BUF_SIZE, "%s", - (jtm->tm_hour >= 0 && jtm->tm_hour < 12) ? "ق.ظ" : "ب.ظ"); - break; - /* * Either "AM" or "PM" according to the given time value. * Noon is treated as "PM" and midnight as "AM". @@ -518,36 +434,12 @@ size_t jstrftime(char *s, size_t max, const char *format, snprintf(buf, MAX_BUF_SIZE, "%d", jtm->tm_wday); break; - /* - * The preferred date representation without the time - * in Farsi. (utf8) - */ - case 'W': - jalali_to_farsi(_la, 100, 0, " ", jtm->tm_year); - jalali_to_farsi(_l1, 10, 2, "۰", jtm->tm_mon + 1); - jalali_to_farsi(_l2, 10, 2, "۰", jtm->tm_mday); - - snprintf(buf, MAX_BUF_SIZE, "%s/%s/%s", _la, _l1, _l2); - break; - /* The preferred date representation without the time. */ case 'x': snprintf(buf, MAX_BUF_SIZE, "%02d/%02d/%d", jtm->tm_mday, jtm->tm_mon + 1, jtm->tm_year); break; - /* - * The preferred time representation in Farsi. (utf8) - */ - case 'X': - jalali_to_farsi(_l1, 10, 2, "۰", jtm->tm_hour); - jalali_to_farsi(_l2, 10, 2, "۰", jtm->tm_min); - jalali_to_farsi(_l3, 10, 2, "۰", jtm->tm_sec); - - snprintf(buf, MAX_BUF_SIZE, "%s:%s:%s", _l1, _l2, _l3); - - break; - /* * The year as a decimal number without a century * (range 00 to 99). @@ -689,26 +581,28 @@ char *jstrptime(const char *s, const char *format, struct jtm *jtm) { switch (fd) { /* The abbreviated or full weekday name. */ case 'a': - case 'A': - ptr = (fd == 'a') ? (char **)jalali_days_3 : (char **)jalali_days; - f = 0; - for (k = 0; k < J_WEEK_LENGTH; k++) { - if (!strcasecmp(buf, ptr[k])) { + if (!strcasecmp(buf, ABDOW06(k))) { jtm->tm_wday = k; - f = 1; + break; } } + return (char *)&s[i]; - if (!f) - return (char *)&s[i]; - - break; + /* The full weekday name. */ + case 'A': + for (k = 0; k < J_WEEK_LENGTH; k++) { + if (!strcasecmp(buf, DOW06(k))) { + jtm->tm_wday = k; + break; + } + } + return (char *)&s[i]; /* The abbreviated or full month name. */ case 'b': case 'B': - ptr = (fd == 'b') ? (char **)jalali_months_3 : (char **)jalali_months; + ptr = (fd == 'b') ? (char **)ab_jalali_months : (char **)jalali_months; f = 0; for (k = 0; k < J_YEAR_LENGTH_IN_MONTHS; k++) { @@ -781,24 +675,6 @@ char *jstrptime(const char *s, const char *format, struct jtm *jtm) { jtm->tm_year = atoi(buf); break; - /* The abbreviated or full weekday name. (Farsi) */ - case 'q': - case 'h': - ptr = (fd == 'h') ? (char **)jalali_days_3_fa : (char **)jalali_days_fa; - f = 0; - - for (k = 0; k < J_WEEK_LENGTH; k++) { - if (!strcasecmp(buf, ptr[k])) { - jtm->tm_wday = k; - f = 1; - } - } - - if (!f) - return (char *)&s[i]; - - break; - default: break; } @@ -846,45 +722,3 @@ char *jctime_r(const time_t *timep, char *buf) { return buf; } - -/* - * @Utils - * Utility functions for internal use. - * jalali_to_farsi() converts an integer's digits to Arabic-Indic - * padding works just like printf() field width. - */ -int jalali_to_farsi(char *buf, size_t n, int padding, char *pad, int d) { - char _buf[100] = {0}; - int i = 0, j = 0; - int p = 0; - int c = 0; - int cw = (pad[0] < 0) ? 2 : 1; - - for (i = d; i != 0; c++, - _buf[p] = farsi_digits[i % 10 > 0 ? i % 10 : -(i % 10)][1], - _buf[p + 1] = farsi_digits[i % 10 > 0 ? i % 10 : -(i % 10)][0], i /= 10, - p += 2) - ; - - if (d < 0) { - _buf[p] = '-'; - c++; - p++; - } - - _buf[p] = 0; - buf[0] = 0; - i = 0; - - for (i = 0; (i < (padding - c)) && (i * cw < (int)(n - 1)); - strcat(buf, pad), i++) - ; - buf[i * cw] = 0; - - for (j = 0, i *= cw; (j < p) && (i < (int)(n - 1)); - buf[i] = _buf[p - j - 1], i++, j++) - ; - buf[i] = 0; - - return i; -} diff --git a/sources/man/jstrftime.3 b/sources/man/jstrftime.3 index f3882e2..3f071fa 100644 --- a/sources/man/jstrftime.3 +++ b/sources/man/jstrftime.3 @@ -80,32 +80,11 @@ Like The day of the month as a decimal number, but a leading zero is replaced by a space. (SU) .TP -.B %E -The preferred date and time in Farsi. (utf8) -.TP .B %F Equivalent to .B %Y-%m-%d (similar to the ISO\ 8601 date format). (C99) .TP -.B %h -The abbreviated Farsi transliterated weekday name. -.TP -.B %q -The full Farsi transliterated weekday name. -.TP -.B %g -The abbreviated Farsi weekday name. (utf8) -.TP -.B %G -The full Farsi weekday name. (utf8) -.TP -.B %v -The abbreviated Farsi month name. (utf8) -.TP -.B %V -The full Farsi month name. (utf8) -.TP .B %H The hour as a decimal number using a 24-hour clock (range 00 to 23). .TP @@ -138,9 +117,6 @@ The minute as a decimal number (range 00 to 59). .B %n A newline character. (SU) .TP -.B %O -AM or PM notation for the given time in Farsi equivalent. (utf8) -.TP .B %p Either "AM" or "PM" according to the given time value. Noon is treated as "PM" and midnight as "AM". @@ -190,15 +166,9 @@ The day of the week as a decimal, range 0 to 6, Saturday being 0. See also .BR %u . .TP -.B %W -The preferred date in %Y/%m/%d format and Farsi. (utf8) -.TP .B %x The preferred date representation without the time. .TP -.B %X -The preferred time representation without the date in Farsi. (utf8) -.TP .B %y The year as a decimal number without a century (range 00 to 99). .TP diff --git a/sources/man/jstrptime.3 b/sources/man/jstrptime.3 index 4b8d28b..6ce2071 100644 --- a/sources/man/jstrptime.3 +++ b/sources/man/jstrptime.3 @@ -75,7 +75,7 @@ The .B % character. .TP -.BR %a " or " %A " or " %h " or " %q +.BR %a " or " %A The weekday name in abbreviated form or the full name. .TP .BR %b " or " %B diff --git a/sources/src/jcal.c b/sources/src/jcal.c index ff221f0..9eb09d1 100644 --- a/sources/src/jcal.c +++ b/sources/src/jcal.c @@ -29,15 +29,6 @@ #include "termcap.h" extern const char *jalali_months[]; -extern const char *jalali_days[]; -extern const char *jalali_days_fa[]; -extern const char *jalali_days_3[]; -extern const char *jalali_days_3_fa[]; -extern const char *jalali_days_2[]; -extern const char *jalali_days_2_fa[]; -extern const char *fa_jalali_months[]; -extern const char *fa_jalali_days_3[]; -extern const char *fa_jalali_days_2[]; extern const int jalali_month_len[]; @@ -153,68 +144,31 @@ void show_cal_matrix(struct cal_layout *l, struct cal_matrix *mat) { if (mat->m[i][j] == 0) printf((l->julian) ? " " : " "); else if (mat->m[i][j] > 1000 && l->color) { - if (l->farsi) { - jalali_to_farsi(buf, 100, 2 + l->julian, " ", mat->m[i][j] - 1000); - } else { - snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j] - 1000); - } - + snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j] - 1000); printf("%s%s%s ", TERM_BLACK_ON_WHITE, buf, TERM_RESET); } else if (mat->m[i][j] > 1000 && !l->color) { - if (l->farsi) { - jalali_to_farsi(buf, 100, 2 + l->julian, " ", mat->m[i][j] - 1000); - } else { - snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j] - 1000); - } - + snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j] - 1000); printf("%s ", buf); - } else { - if (l->farsi) { - jalali_to_farsi(buf, 100, 2 + l->julian, " ", mat->m[i][j]); - } else { - snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j]); - } - + snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j]); printf("%s ", buf); } } else { if (mat->m[i][j] == 0) printf((l->julian) ? " " : " "); else if (mat->m[i][j] > 1000 && l->color) { - if (l->farsi) { - jalali_to_farsi(buf, 100, 2 + l->julian, " ", mat->m[i][j] - 1000); - } else { - snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j] - 1000); - } - + snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j] - 1000); printf("%s%s%s", TERM_RED_ON_WHITE, buf, TERM_RESET); } else if ((mat->m[i][j] > 1000) && (!l->color)) { - if (l->farsi) { - jalali_to_farsi(buf, 100, 2 + l->julian, " ", mat->m[i][j] - 1000); - } else { - snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j] - 1000); - } - + snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j] - 1000); printf("%s", buf); } else if (l->color) { - if (l->farsi) { - jalali_to_farsi(buf, 100, 2 + l->julian, " ", mat->m[i][j]); - } else { - snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j]); - } - + snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j]); printf("%s%s%s", TERM_RED, buf, TERM_RESET); - } else { - if (l->farsi) { - jalali_to_farsi(buf, 100, 2 + l->julian, " ", mat->m[i][j]); - } else { - snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j]); - } - + snprintf(buf, 100, "%*d", 2 + l->julian, mat->m[i][j]); printf("%s", buf); } } @@ -261,44 +215,26 @@ void destroy_cal_matrix(struct cal_matrix *mat) { */ void show_cal(struct cal_layout *l, struct cal_matrix *m, struct jtm **_j) { - char **ptr_d; - + int cell_width = (l->julian) ? 3 : 2; int i, k; - int cw = (l->farsi) ? 2 : 1; - int cal_width = (l->julian) ? 7 * 3 + 6 : 7 * 2 + 6; + int cal_width = 7 * cell_width + 6; char cal_t[3][MAX_BUF_SIZE]; char cal_y[3][100]; int cal_tw[3]; char buf[100]; - if (l->farsi) - ptr_d = (l->julian) ? (char **)fa_jalali_days_3 : (char **)fa_jalali_days_2; - else if (l->english) - ptr_d = (l->julian) ? (char **)jalali_days_3 : (char **)jalali_days_2; - else - ptr_d = (l->julian) ? (char **)jalali_days_3_fa : (char **)jalali_days_2_fa; - for (i = 0; i < m->n; i++) { - if (l->farsi) { - jalali_to_farsi(buf, 100, 0, " ", - _j[i]->tm_year + - ((l->pahlavi) ? PAHLAVI_ISLAMIC_DIFF : 0)); - } else { - snprintf(buf, 100, "%d", - _j[i]->tm_year + ((l->pahlavi) ? PAHLAVI_ISLAMIC_DIFF : 0)); - } - snprintf(cal_y[i], 100, "%s%s", buf, - (l->pahlavi) ? ((l->farsi) ? " په" : "(pa)") : ""); + snprintf(buf, 100, "%d", + _j[i]->tm_year + ((l->pahlavi) ? PAHLAVI_ISLAMIC_DIFF : 0)); + snprintf(cal_y[i], 100, "%s%s", buf, (l->pahlavi) ? "(pa)" : ""); buf[0] = 0; } for (i = 0; i < m->n; i++) { - snprintf(cal_t[i], MAX_BUF_SIZE, "%s %s", - (l->farsi) ? fa_jalali_months[_j[i]->tm_mon] - : jalali_months[_j[i]->tm_mon], + snprintf(cal_t[i], MAX_BUF_SIZE, "%s %s", jalali_months[_j[i]->tm_mon], (l->syear) ? cal_y[i] : ""); - cal_tw[i] = (cal_width - (strlen(cal_t[i]) / cw)) / 2; + cal_tw[i] = (cal_width - strlen(cal_t[i])) / 2; } for (i = 0; i < m->n; i++) { @@ -313,7 +249,7 @@ void show_cal(struct cal_layout *l, struct cal_matrix *m, struct jtm **_j) { } for (k = 0; k < (cal_width - cal_tw[i] - - (strlen(cal_t[i]) / cw + ((cw > 1) ? 1 : 0))); + (strlen(cal_t[i]) + (/* (cw > 1) ? 1 : */ 0))); k++) { printf(" "); } @@ -328,19 +264,16 @@ void show_cal(struct cal_layout *l, struct cal_matrix *m, struct jtm **_j) { printf("\n"); for (i = 0; i < m->n; i++) { - for (k = 0; k < 6; k++) { + for (k = 0; k < 7; k++) { + char *s = ABDOW06(k); if (l->color) { - printf("%s%s%s ", TERM_WHITE, ptr_d[k], TERM_RESET); + printf("%s%*.*s%s ", k == 6 ? TERM_RED : TERM_WHITE, cell_width, + cell_width, s, TERM_RESET); } else { - printf("%s ", ptr_d[k]); + printf("%*.*s ", cell_width, cell_width, s); } } - if (l->color) - printf("%s%s%s", TERM_RED, ptr_d[6], TERM_RESET); - else - printf("%s", ptr_d[6]); - if (i != m->n - 1) { for (k = 0; k < l->margin; k++) { printf(" "); @@ -441,16 +374,10 @@ void show_year(struct cal_layout *l, struct jtm *j) { int cal_tw; int i; - if (l->farsi) { - jalali_to_farsi(buf, 100, 0, " ", - j->tm_year + ((l->pahlavi) ? PAHLAVI_ISLAMIC_DIFF : 0)); - } else { - snprintf(buf, 100, "%d", - j->tm_year + ((l->pahlavi) ? PAHLAVI_ISLAMIC_DIFF : 0)); - } + snprintf(buf, 100, "%d", + j->tm_year + ((l->pahlavi) ? PAHLAVI_ISLAMIC_DIFF : 0)); - snprintf(title, 100, "%s%s", buf, - (l->pahlavi) ? (l->farsi ? " پهلوی" : " (Pahlavi)") : ""); + snprintf(title, 100, "%s%s", buf, (l->pahlavi) ? " (Pahlavi)" : ""); cal_tw = (cal_width - strlen(title)) / 2; @@ -488,6 +415,8 @@ void show_year(struct cal_layout *l, struct jtm *j) { } int main(int argc, char **argv) { + setlocale_from_env(); + struct cal_layout l; struct jtm j = {0}; time_t t; @@ -508,9 +437,7 @@ int main(int argc, char **argv) { l.color = 1; l.pahlavi = 0; - l.farsi = 0; l.julian = 0; - l.english = 0; l.margin = 3; /* Parsing date values. (YYYY MM DD) */ @@ -552,21 +479,11 @@ int main(int argc, char **argv) { l.pahlavi = 1; break; - case 'p': - l.farsi = 1; - l.english = 0; - break; - /* Displays Julian days (Day of year) instead of day of month. */ case 'j': l.julian = 1; break; - /* Displays English names of weekdays. */ - case 'e': - l.english = 1; - break; - /* Display one-month calendar for a given date. */ case '1': show = &show_1; diff --git a/sources/src/jcal.h b/sources/src/jcal.h index e0980fd..30fdaae 100644 --- a/sources/src/jcal.h +++ b/sources/src/jcal.h @@ -33,8 +33,6 @@ struct cal_layout { int color; /* If enabled, drawer tries to colorize output. */ int julian; /* Displays julian days (1-366) instead of month days. */ int pahlavi; /* jcal uses Pahlavi instead of Islamic epoch. */ - int english; /* Use Farsi transliteration for weekday names. */ - int farsi; /* Use Farsi utf8 names and numbers. */ int margin; /* Marginal space between two cals. */ int syear; /* If enabled, jcal shows year above cals. */ }; diff --git a/sources/src/jdate.c b/sources/src/jdate.c index 29094bd..3eb4990 100644 --- a/sources/src/jdate.c +++ b/sources/src/jdate.c @@ -58,6 +58,8 @@ int mod_time(const char *path, time_t *t, int a) { } int main(int argc, char **argv) { + setlocale_from_env(); + int opt; int i; int err; diff --git a/sources/test_kit/jalali/elc.c b/sources/test_kit/jalali/elc.c index 26fcd09..acf1620 100644 --- a/sources/test_kit/jalali/elc.c +++ b/sources/test_kit/jalali/elc.c @@ -4,6 +4,8 @@ #include "jalali.h" int main(int argc, char **argv) { + setlocale_from_env(); + if (argc != 3) { printf("wrong arguments given\n"); printf("elc: leap counter from YEAR1 to YEAR2\n"); diff --git a/sources/test_kit/jalali/get_date.c b/sources/test_kit/jalali/get_date.c index 8acb81f..c0d9af1 100644 --- a/sources/test_kit/jalali/get_date.c +++ b/sources/test_kit/jalali/get_date.c @@ -4,6 +4,8 @@ #include "jalali.h" int main(int argc, char **argv) { + setlocale_from_env(); + if (argc != 2) { printf("wrong arguments given\n"); printf("usage: get_date DIFF_FROM_EPOCH_BY_DAYS\n"); diff --git a/sources/test_kit/jalali/get_diff.c b/sources/test_kit/jalali/get_diff.c index a9b54e2..43e4248 100644 --- a/sources/test_kit/jalali/get_diff.c +++ b/sources/test_kit/jalali/get_diff.c @@ -4,6 +4,8 @@ #include "jalali.h" int main(int argc, char **argv) { + setlocale_from_env(); + if (argc != 4) { printf("wrong arguments given\n"); printf("usage: get_diff DAY MONTH YEAR\n"); diff --git a/sources/test_kit/jalali/jalali_update.c b/sources/test_kit/jalali/jalali_update.c index eae2468..01b274a 100644 --- a/sources/test_kit/jalali/jalali_update.c +++ b/sources/test_kit/jalali/jalali_update.c @@ -5,6 +5,8 @@ #include "jtime.h" int main(int argc, char **argv) { + setlocale_from_env(); + time_t t; struct jtm j; int mday_diff = 60; diff --git a/sources/test_kit/jalali/jyinfo.c b/sources/test_kit/jalali/jyinfo.c index 0550aba..468719b 100644 --- a/sources/test_kit/jalali/jyinfo.c +++ b/sources/test_kit/jalali/jyinfo.c @@ -4,6 +4,8 @@ #include "jalali.h" int main(int argc, char **argv) { + setlocale_from_env(); + struct jyinfo a; if (argc != 2) { diff --git a/sources/test_kit/jalali/leap.c b/sources/test_kit/jalali/leap.c index cb77416..11cd26b 100644 --- a/sources/test_kit/jalali/leap.c +++ b/sources/test_kit/jalali/leap.c @@ -4,6 +4,8 @@ #include "jalali.h" int main(int argc, char **argv) { + setlocale_from_env(); + if (argc != 2) { printf("wrong arguments given\n"); printf("usage: leap YEAR\n"); diff --git a/sources/test_kit/jalali/sec_converter.c b/sources/test_kit/jalali/sec_converter.c index f3b9fc8..192c2f7 100644 --- a/sources/test_kit/jalali/sec_converter.c +++ b/sources/test_kit/jalali/sec_converter.c @@ -4,6 +4,8 @@ #include "jalali.h" int main(int argc, char **argv) { + setlocale_from_env(); + if (argc != 2) { printf("wrong arguments given\n"); printf("usage: sec_converter SECONDS\n"); diff --git a/sources/test_kit/jtime/jasctime.c b/sources/test_kit/jtime/jasctime.c index e3770ba..66e53fe 100644 --- a/sources/test_kit/jtime/jasctime.c +++ b/sources/test_kit/jtime/jasctime.c @@ -5,6 +5,8 @@ #include "jtime.h" int main() { + setlocale_from_env(); + time_t ltime; time(<ime); struct ab_jtm a; diff --git a/sources/test_kit/jtime/jctime.c b/sources/test_kit/jtime/jctime.c index 26ebb20..d2727f0 100644 --- a/sources/test_kit/jtime/jctime.c +++ b/sources/test_kit/jtime/jctime.c @@ -5,6 +5,8 @@ #include "jtime.h" int main() { + setlocale_from_env(); + time_t t; time(&t); struct jtm j; diff --git a/sources/test_kit/jtime/jgmtime.c b/sources/test_kit/jtime/jgmtime.c index d9eb7bc..ba1e985 100644 --- a/sources/test_kit/jtime/jgmtime.c +++ b/sources/test_kit/jtime/jgmtime.c @@ -5,6 +5,8 @@ #include "jtime.h" int main() { + setlocale_from_env(); + time_t t; time(&t); struct jtm j; diff --git a/sources/test_kit/jtime/jlocaltime.c b/sources/test_kit/jtime/jlocaltime.c index ce53a96..10e77b6 100644 --- a/sources/test_kit/jtime/jlocaltime.c +++ b/sources/test_kit/jtime/jlocaltime.c @@ -5,6 +5,8 @@ #include "jtime.h" int main() { + setlocale_from_env(); + time_t t; time(&t); struct jtm *p; diff --git a/sources/test_kit/jtime/jmktime.c b/sources/test_kit/jtime/jmktime.c index bbafe69..adf1b39 100644 --- a/sources/test_kit/jtime/jmktime.c +++ b/sources/test_kit/jtime/jmktime.c @@ -5,6 +5,8 @@ #include "jtime.h" int main() { + setlocale_from_env(); + time_t t; time(&t); struct jtm j; diff --git a/sources/test_kit/jtime/jstrftime.c b/sources/test_kit/jtime/jstrftime.c index 608107c..da77245 100644 --- a/sources/test_kit/jtime/jstrftime.c +++ b/sources/test_kit/jtime/jstrftime.c @@ -6,6 +6,8 @@ #include "jtime.h" int main(int argc, char **argv) { + setlocale_from_env(); + if (argc != 2) { printf("wrong arguments given\n"); printf("usage jstrftime FORMAT\n"); diff --git a/sources/test_kit/jtime/jstrptime.c b/sources/test_kit/jtime/jstrptime.c index 86e7fea..38946da 100644 --- a/sources/test_kit/jtime/jstrptime.c +++ b/sources/test_kit/jtime/jstrptime.c @@ -8,6 +8,8 @@ #include "jtime.h" int main() { + setlocale_from_env(); + char *s; char *fmt; s = readline("string > ");