From 56dd51ef189f06b385f5289937e967b4139580d9 Mon Sep 17 00:00:00 2001 From: "M. Yas. Davoodeh" Date: Sat, 5 Apr 2025 23:43:43 +0330 Subject: [PATCH] Format all the .c and .h files --- sources/src/jcal.c | 959 +++++++++++------------- sources/src/jcal.h | 48 +- sources/src/jdate.c | 453 ++++++----- sources/src/jdate.h | 37 +- sources/test_kit/jalali/elc.c | 32 +- sources/test_kit/jalali/get_date.c | 26 +- sources/test_kit/jalali/get_diff.c | 38 +- sources/test_kit/jalali/jalali_update.c | 100 ++- sources/test_kit/jalali/jyinfo.c | 21 +- sources/test_kit/jalali/leap.c | 13 +- sources/test_kit/jalali/sec_converter.c | 21 +- sources/test_kit/jtime/jasctime.c | 25 +- sources/test_kit/jtime/jctime.c | 17 +- sources/test_kit/jtime/jgmtime.c | 19 +- sources/test_kit/jtime/jlocaltime.c | 19 +- sources/test_kit/jtime/jmktime.c | 15 +- sources/test_kit/jtime/jstrftime.c | 29 +- sources/test_kit/jtime/jstrptime.c | 20 +- 18 files changed, 932 insertions(+), 960 deletions(-) diff --git a/sources/src/jcal.c b/sources/src/jcal.c index e4afb96..ff221f0 100644 --- a/sources/src/jcal.c +++ b/sources/src/jcal.c @@ -19,28 +19,29 @@ */ #include -#include #include +#include #include -#include "termcap.h" -#include "jcal.h" + #include "../libjalali/jalali.h" #include "../libjalali/jtime.h" +#include "jcal.h" +#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 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[]; -extern char* optarg; +extern char *optarg; /* * @Create, set, destroy and show set of cal_matrix functions. @@ -58,204 +59,169 @@ extern char* optarg; * Sets the matrix according to a given jalali date and prefix. */ -void set_cal_matrix(struct cal_layout* l, - struct jtm* ct, - struct cal_matrix* mat, - int prefix) -{ - struct jtm mb; - struct jtm lt; - - time_t t; - - int diff; - int _prefix = prefix * (7 + l->margin); - int m, c; - int i, j; - - time(&t); - jlocaltime_r(&t, <); - - memcpy(&mb, ct, sizeof(struct jtm)); - - diff = (mb.tm_mday - 1) % 7; - mb.tm_wday = (mb.tm_wday - diff) % 7; - if (mb.tm_wday < 0) - mb.tm_wday += 7; - - mb.tm_mday = 1; - jalali_create_days_from_date(&mb); - - m = (jalali_is_jleap(mb.tm_year) && mb.tm_mon == 11) ? 30 : - jalali_month_len[mb.tm_mon]; - - j = mb.tm_wday; - for (i=0,c=0; i<=mat->height && c < m; i++) { - for (; j<=6 && c < m; j++) { - if ((mb.tm_year == lt.tm_year) && (mb.tm_mon == lt.tm_mon) - && (mb.tm_mday + c == lt.tm_mday)) { - mat->m[i][j+_prefix] = (l->julian) ? 1000 + mb.tm_yday + c + 1 : - 1000 + mb.tm_mday + c; - } else { - mat->m[i][j+_prefix] = (l->julian) ? mb.tm_yday + c + 1 : - mb.tm_mday + c; - } - c++; - } - j = 0; +void set_cal_matrix(struct cal_layout *l, struct jtm *ct, + struct cal_matrix *mat, int prefix) { + struct jtm mb; + struct jtm lt; + + time_t t; + + int diff; + int _prefix = prefix * (7 + l->margin); + int m, c; + int i, j; + + time(&t); + jlocaltime_r(&t, <); + + memcpy(&mb, ct, sizeof(struct jtm)); + + diff = (mb.tm_mday - 1) % 7; + mb.tm_wday = (mb.tm_wday - diff) % 7; + if (mb.tm_wday < 0) + mb.tm_wday += 7; + + mb.tm_mday = 1; + jalali_create_days_from_date(&mb); + + m = (jalali_is_jleap(mb.tm_year) && mb.tm_mon == 11) + ? 30 + : jalali_month_len[mb.tm_mon]; + + j = mb.tm_wday; + for (i = 0, c = 0; i <= mat->height && c < m; i++) { + for (; j <= 6 && c < m; j++) { + if ((mb.tm_year == lt.tm_year) && (mb.tm_mon == lt.tm_mon) && + (mb.tm_mday + c == lt.tm_mday)) { + mat->m[i][j + _prefix] = + (l->julian) ? 1000 + mb.tm_yday + c + 1 : 1000 + mb.tm_mday + c; + } else { + mat->m[i][j + _prefix] = + (l->julian) ? mb.tm_yday + c + 1 : mb.tm_mday + c; + } + c++; } + j = 0; + } } - /* * Returns 0, if the given column is located within margins between calendars, * 1 otherwise. */ -int is_in_margin(struct cal_layout* l, - struct cal_matrix* mat, - int c) -{ - int i; - - if (mat->n == 1) { - if (c < 6) - return 0; - else if (c == 6) - return 2; - else - return 1; - } +int is_in_margin(struct cal_layout *l, struct cal_matrix *mat, int c) { + int i; - for (i=0; i<=mat->n - 1; i++) { - if (c < (i * (7 + l->margin)) + 7 - 1) { - return 0; - } - else if (c == (i * (7 + l->margin) + 7) - 1) { - return 2; - } - else if ((c >= (i * (7 + l->margin) + 7)) && - (c < ((i+1) * (7 + l->margin)))) { - return 1; - } + if (mat->n == 1) { + if (c < 6) + return 0; + else if (c == 6) + return 2; + else + return 1; + } + + for (i = 0; i <= mat->n - 1; i++) { + if (c < (i * (7 + l->margin)) + 7 - 1) { + return 0; + } else if (c == (i * (7 + l->margin) + 7) - 1) { + return 2; + } else if ((c >= (i * (7 + l->margin) + 7)) && + (c < ((i + 1) * (7 + l->margin)))) { + return 1; } - return 0; + } + return 0; } - /* * Displays the calendar matrix over standard screen. * @Should not be used directly. (See display_cal()) */ -void show_cal_matrix(struct cal_layout* l, struct cal_matrix* mat) -{ - int i, j, m; - char buf[100]; - - for (i=0; iheight; i++) { - for (j=0; jwidth; j++) { - m = is_in_margin(l, mat, j); - if (m == 1) { - printf(" "); - } - else if (m == 0) { - 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); - } - - 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); - } - - 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]); - } - - 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); - } - - 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); - } - - 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]); - } - - 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]); - } - - printf("%s", buf); - } - } - buf[0] = 0; +void show_cal_matrix(struct cal_layout *l, struct cal_matrix *mat) { + int i, j, m; + char buf[100]; + + for (i = 0; i < mat->height; i++) { + for (j = 0; j < mat->width; j++) { + m = is_in_margin(l, mat, j); + if (m == 1) { + printf(" "); + } else if (m == 0) { + 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); + } + + 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); + } + + 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]); + } + + printf("%s ", buf); } - printf("\n"); + } 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); + } + + 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); + } + + 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]); + } + + 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]); + } + + printf("%s", buf); + } + } + buf[0] = 0; } + printf("\n"); + } } /* @@ -263,401 +229,382 @@ void show_cal_matrix(struct cal_layout* l, struct cal_matrix* mat) * and height according to number of calendars. */ -void create_cal_matrix(struct cal_layout* l, struct cal_matrix* mat) -{ - mat->width = (mat->n * 7) + ((mat->n - 1) * l->margin) ; - mat->height = 6; - mat->m = malloc(mat->height * sizeof(int*)); +void create_cal_matrix(struct cal_layout *l, struct cal_matrix *mat) { + mat->width = (mat->n * 7) + ((mat->n - 1) * l->margin); + mat->height = 6; + mat->m = malloc(mat->height * sizeof(int *)); - int i; + int i; - for (i=0; iheight; i++) { - mat->m[i] = malloc(mat->width * sizeof(int)); - memset(mat->m[i], 0, mat->width * sizeof(int)); - } + for (i = 0; i < mat->height; i++) { + mat->m[i] = malloc(mat->width * sizeof(int)); + memset(mat->m[i], 0, mat->width * sizeof(int)); + } } - /* * Frees the allocated calendar memory. */ -void destroy_cal_matrix(struct cal_matrix* mat) -{ - int i; +void destroy_cal_matrix(struct cal_matrix *mat) { + int i; - for (i=0; iheight; i++) { - free(mat->m[i]); - } + for (i = 0; i < mat->height; i++) { + free(mat->m[i]); + } - free(mat->m); + free(mat->m); } - /* * Displays calendar, including cal title and week days. */ -void show_cal(struct cal_layout* l, - struct cal_matrix* m, - struct jtm** _j) -{ - char** ptr_d; - - int i, k; - int cw = (l->farsi) ? 2 : 1; - int cal_width = (l->julian) ? 7 * 3 + 6 : 7 * 2 + 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; +void show_cal(struct cal_layout *l, struct cal_matrix *m, struct jtm **_j) { + char **ptr_d; + int i, k; + int cw = (l->farsi) ? 2 : 1; + int cal_width = (l->julian) ? 7 * 3 + 6 : 7 * 2 + 6; - for (i=0; in; 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)") : ""); - buf[0] = 0; - } + char cal_t[3][MAX_BUF_SIZE]; + char cal_y[3][100]; + int cal_tw[3]; + char buf[100]; - for (i=0; in; 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], - (l->syear) ? cal_y[i] : ""); - cal_tw[i] = (cal_width - (strlen(cal_t[i]) / cw)) / 2; - } + 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; in; i++) { - for (k=0; kn; 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)") : ""); + 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], + (l->syear) ? cal_y[i] : ""); + cal_tw[i] = (cal_width - (strlen(cal_t[i]) / cw)) / 2; + } + + for (i = 0; i < m->n; i++) { + for (k = 0; k < cal_tw[i]; k++) { + printf(" "); + } - if (l->color) { - printf("%s%s%s", TERM_WHITE, cal_t[i], TERM_RESET); - } else { - printf("%s", cal_t[i]); - } + if (l->color) { + printf("%s%s%s", TERM_WHITE, cal_t[i], TERM_RESET); + } else { + printf("%s", cal_t[i]); + } - for (k=0; - k<(cal_width - cal_tw[i] - - (strlen(cal_t[i]) / cw + ((cw > 1) ? 1 : 0))); - k++) { - printf(" "); - } + for (k = 0; k < (cal_width - cal_tw[i] - + (strlen(cal_t[i]) / cw + ((cw > 1) ? 1 : 0))); + k++) { + printf(" "); + } - if (i != m->n-1) { - for (k=0; kmargin; k++) { - printf(" "); - } - } + if (i != m->n - 1) { + for (k = 0; k < l->margin; k++) { + printf(" "); + } } + } - printf("\n"); + printf("\n"); - for (i=0; in; i++) { - for (k=0; k<6; k++) { - if (l->color) { - printf("%s%s%s ", TERM_WHITE, ptr_d[k], TERM_RESET); - } else { - printf("%s ", ptr_d[k]); - } - } + for (i = 0; i < m->n; i++) { + for (k = 0; k < 6; k++) { + if (l->color) { + printf("%s%s%s ", TERM_WHITE, ptr_d[k], TERM_RESET); + } else { + printf("%s ", ptr_d[k]); + } + } - if (l->color) - printf("%s%s%s", TERM_RED, ptr_d[6], TERM_RESET); - else - printf("%s", ptr_d[6]); + 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; kmargin; k++) { - printf(" "); - } - } + if (i != m->n - 1) { + for (k = 0; k < l->margin; k++) { + printf(" "); + } } + } - printf("\n"); + printf("\n"); - create_cal_matrix(l, m); + create_cal_matrix(l, m); - for (i=0; in; i++) { - set_cal_matrix(l, _j[i], m, i); - } + for (i = 0; i < m->n; i++) { + set_cal_matrix(l, _j[i], m, i); + } - show_cal_matrix(l, m); - destroy_cal_matrix(m); + show_cal_matrix(l, m); + destroy_cal_matrix(m); } - /* * Displays previous, current and next month's calendar on standard * screen according to a given jalali date. */ -void show_3(struct cal_layout* l, struct jtm* j) -{ - struct jtm** _j; - struct cal_matrix m; +void show_3(struct cal_layout *l, struct jtm *j) { + struct jtm **_j; + struct cal_matrix m; - int diff_p; - int diff_c; - int diff_n; + int diff_p; + int diff_c; + int diff_n; - int i; + int i; - m.n = 3; + m.n = 3; - _j = malloc(m.n * sizeof(struct jtm*)); + _j = malloc(m.n * sizeof(struct jtm *)); - for (i=0; itm_mday + 1); - diff_n = (jalali_is_jleap(_j[1]->tm_year) && _j[1]->tm_mon == 11) ? - diff_c + (30 - _j[1]->tm_mday + 1) : - diff_c + (jalali_month_len[_j[1]->tm_mon] - _j[1]->tm_mday + 1); + diff_c = jalali_get_diff(_j[1]); + diff_p = diff_c - (_j[1]->tm_mday + 1); + diff_n = + (jalali_is_jleap(_j[1]->tm_year) && _j[1]->tm_mon == 11) + ? diff_c + (30 - _j[1]->tm_mday + 1) + : diff_c + (jalali_month_len[_j[1]->tm_mon] - _j[1]->tm_mday + 1); - jalali_get_date(diff_p, _j[0]); - jalali_get_date(diff_n, _j[2]); - show_cal(l, &m, _j); + jalali_get_date(diff_p, _j[0]); + jalali_get_date(diff_n, _j[2]); + show_cal(l, &m, _j); - for (i=0; i<3; i++) { - free(_j[i]); - } + for (i = 0; i < 3; i++) { + free(_j[i]); + } - free(_j); + free(_j); } - /* * Displays a calendar on standard screen according to a given jalali date. */ -void show_1(struct cal_layout* l, struct jtm* j) -{ - struct jtm** _j; - struct cal_matrix m; +void show_1(struct cal_layout *l, struct jtm *j) { + struct jtm **_j; + struct cal_matrix m; - l->syear = 1; + l->syear = 1; - _j = malloc(sizeof(struct jtm*)); - _j[0] = malloc(sizeof(struct jtm)); + _j = malloc(sizeof(struct jtm *)); + _j[0] = malloc(sizeof(struct jtm)); - memcpy(_j[0], j, sizeof(struct jtm)); - m.n = 1; - show_cal(l, &m, _j); + memcpy(_j[0], j, sizeof(struct jtm)); + m.n = 1; + show_cal(l, &m, _j); - free(_j[0]); - free(_j); + free(_j[0]); + free(_j); } - /* * Displays a whole year calendar on standard screen according * to a given jalali date. */ -void show_year(struct cal_layout* l, struct jtm* j) -{ - struct jtm _j[4] = {{0}}; +void show_year(struct cal_layout *l, struct jtm *j) { + struct jtm _j[4] = {{0}}; - char title[100]; - char buf[100]; + char title[100]; + char buf[100]; - int cal_width = (((l->julian) ? (3 * 7 + 6) : (2 * 7 + 6)) * 3) + - (2 * l->margin); + int cal_width = + (((l->julian) ? (3 * 7 + 6) : (2 * 7 + 6)) * 3) + (2 * l->margin); - int cal_tw; - int i; + 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)); - } + 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(title, 100, "%s%s", buf, - (l->pahlavi) ? (l->farsi ? " پهلوی" : " (Pahlavi)") : ""); + snprintf(title, 100, "%s%s", buf, + (l->pahlavi) ? (l->farsi ? " پهلوی" : " (Pahlavi)") : ""); - cal_tw = (cal_width - strlen(title)) / 2; + cal_tw = (cal_width - strlen(title)) / 2; - for (i=0; isyear = 0; - - _j[0].tm_year = j->tm_year; - _j[0].tm_mon = 1; - _j[0].tm_mday = 1; - jalali_update(&_j[0]); - - _j[1].tm_year = j->tm_year; - _j[1].tm_mon = 4; - _j[1].tm_mday = 1; - jalali_update(&_j[1]); - - _j[2].tm_year = j->tm_year; - _j[2].tm_mon = 7; - _j[2].tm_mday = 1; - jalali_update(&_j[2]); - - _j[3].tm_year = j->tm_year; - _j[3].tm_mon = 10; - _j[3].tm_mday = 1; - jalali_update(&_j[3]); - - show_3(l, &_j[0]); - show_3(l, &_j[1]); - show_3(l, &_j[2]); - show_3(l, &_j[3]); + for (i = 0; i < cal_tw; i++) { + printf(" "); + } + printf("%s\n\n", title); + + l->syear = 0; + + _j[0].tm_year = j->tm_year; + _j[0].tm_mon = 1; + _j[0].tm_mday = 1; + jalali_update(&_j[0]); + + _j[1].tm_year = j->tm_year; + _j[1].tm_mon = 4; + _j[1].tm_mday = 1; + jalali_update(&_j[1]); + + _j[2].tm_year = j->tm_year; + _j[2].tm_mon = 7; + _j[2].tm_mday = 1; + jalali_update(&_j[2]); + + _j[3].tm_year = j->tm_year; + _j[3].tm_mon = 10; + _j[3].tm_mday = 1; + jalali_update(&_j[3]); + + show_3(l, &_j[0]); + show_3(l, &_j[1]); + show_3(l, &_j[2]); + show_3(l, &_j[3]); } -int main(int argc, char** argv) -{ - struct cal_layout l; - struct jtm j = {0}; - time_t t; - - int opt; - int i, c = 0; - int def_date[3]; - void (*show) (struct cal_layout*, struct jtm*); - - show = &show_1; - time(&t); - jlocaltime_r(&t, &j); - - /* Default values for display date */ - def_date[0] = 1; - def_date[1] = 1; - def_date[2] = j.tm_year; - - l.color = 1; - l.pahlavi = 0; - l.farsi = 0; - l.julian = 0; - l.english = 0; - l.margin = 3; - - /* Parsing date values. (YYYY MM DD) */ - for (i=1; i 0) { - def_date[2 - c] = opt; - c++; - } +int main(int argc, char **argv) { + struct cal_layout l; + struct jtm j = {0}; + time_t t; + + int opt; + int i, c = 0; + int def_date[3]; + void (*show)(struct cal_layout *, struct jtm *); + + show = &show_1; + time(&t); + jlocaltime_r(&t, &j); + + /* Default values for display date */ + def_date[0] = 1; + def_date[1] = 1; + def_date[2] = j.tm_year; + + l.color = 1; + l.pahlavi = 0; + l.farsi = 0; + l.julian = 0; + l.english = 0; + l.margin = 3; + + /* Parsing date values. (YYYY MM DD) */ + for (i = 1; i < argc && c < 3; i++) { + opt = atoi(argv[i]); + if (opt > 0) { + def_date[2 - c] = opt; + c++; } + } - if (c > 0) { - if (c == 1) - show = &show_year; - else - show = &show_1; - - if (def_date[0] > 31 || def_date[0] < 1) { - printf("%s: illegal day value: use 1-31\n", argv[0]); - exit(EXIT_FAILURE); - } + if (c > 0) { + if (c == 1) + show = &show_year; + else + show = &show_1; - if (def_date[1] > 12 || def_date[1] < 1) { - printf("%s: illegal month value: use 1-12\n", argv[0]); - exit(EXIT_FAILURE); - } + if (def_date[0] > 31 || def_date[0] < 1) { + printf("%s: illegal day value: use 1-31\n", argv[0]); + exit(EXIT_FAILURE); + } - j.tm_year = def_date[2]; - j.tm_mon = def_date[1] - 1; - j.tm_mday = def_date[0]; - jalali_update(&j); + if (def_date[1] > 12 || def_date[1] < 1) { + printf("%s: illegal month value: use 1-12\n", argv[0]); + exit(EXIT_FAILURE); } - /* Parsing short options. */ - while ((opt = getopt(argc, argv, JCAL_VALID_ARGS)) != -1) { - switch (opt) { - /* Using Pahlavi instead of Islamic Epoch. */ - case 'P': - 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; - break; - - /* - * Display previous, current and next month's calendar - * for the given date. - */ - case '3': - l.syear = 1; - show = &show_3; - break; - /* Whole-year calendar for a given date. */ - case 'y': - show = &show_year; - break; - - /* No-color. */ - case 'N': - l.color = 0; - break; - - /* Version information. */ - case 'V': - printf("jcal version %s (libjalali-%s)\n", - JCAL_VERSION, LIBJALALI_VERSION); - printf("Written by Ashkan Ghassemi.\n"); - exit(EXIT_SUCCESS); - break; - - /* Unknown parameter. */ - default: - printf("usage: jcal [-13jypPV] [year [month[day]]]\n"); - exit(EXIT_FAILURE); - } + j.tm_year = def_date[2]; + j.tm_mon = def_date[1] - 1; + j.tm_mday = def_date[0]; + jalali_update(&j); + } + + /* Parsing short options. */ + while ((opt = getopt(argc, argv, JCAL_VALID_ARGS)) != -1) { + switch (opt) { + /* Using Pahlavi instead of Islamic Epoch. */ + case 'P': + 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; + break; + + /* + * Display previous, current and next month's calendar + * for the given date. + */ + case '3': + l.syear = 1; + show = &show_3; + break; + /* Whole-year calendar for a given date. */ + case 'y': + show = &show_year; + break; + + /* No-color. */ + case 'N': + l.color = 0; + break; + + /* Version information. */ + case 'V': + printf("jcal version %s (libjalali-%s)\n", JCAL_VERSION, + LIBJALALI_VERSION); + printf("Written by Ashkan Ghassemi.\n"); + exit(EXIT_SUCCESS); + break; + + /* Unknown parameter. */ + default: + printf("usage: jcal [-13jypPV] [year [month[day]]]\n"); + exit(EXIT_FAILURE); } + } - show(&l, &j); - exit(EXIT_SUCCESS); + show(&l, &j); + exit(EXIT_SUCCESS); } diff --git a/sources/src/jcal.h b/sources/src/jcal.h index ec05676..e0980fd 100644 --- a/sources/src/jcal.h +++ b/sources/src/jcal.h @@ -30,45 +30,39 @@ #define JCAL_VERSION "0.5.1" 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. */ + 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. */ }; struct cal_matrix { - int n; /* Calendar numbers within matrix. */ - int** m; /* Calendar matrix. */ - int width; /* Matrix width. */ - int height; /* Matrix height. */ + int n; /* Calendar numbers within matrix. */ + int **m; /* Calendar matrix. */ + int width; /* Matrix width. */ + int height; /* Matrix height. */ }; -void set_cal_matrix(struct cal_layout* l, - struct jtm* ct, - struct cal_matrix* mat, - int prefix); +void set_cal_matrix(struct cal_layout *l, struct jtm *ct, + struct cal_matrix *mat, int prefix); -int is_in_margin(struct cal_layout* l, - struct cal_matrix* mat, - int c); +int is_in_margin(struct cal_layout *l, struct cal_matrix *mat, int c); -void show_cal_matrix(struct cal_layout* l, struct cal_matrix* mat); +void show_cal_matrix(struct cal_layout *l, struct cal_matrix *mat); -void create_cal_matrix(struct cal_layout* l, struct cal_matrix* mat); +void create_cal_matrix(struct cal_layout *l, struct cal_matrix *mat); -void destroy_cal_matrix(struct cal_matrix* mat); +void destroy_cal_matrix(struct cal_matrix *mat); -void show_cal(struct cal_layout* l, - struct cal_matrix* m, - struct jtm** _j); +void show_cal(struct cal_layout *l, struct cal_matrix *m, struct jtm **_j); -void show_3(struct cal_layout* l, struct jtm* j); +void show_3(struct cal_layout *l, struct jtm *j); -void show_1(struct cal_layout* l, struct jtm* j); +void show_1(struct cal_layout *l, struct jtm *j); -void show_year(struct cal_layout* l, struct jtm* j); +void show_year(struct cal_layout *l, struct jtm *j); #endif /* JCAL_H */ diff --git a/sources/src/jdate.c b/sources/src/jdate.c index 8a47e19..29094bd 100644 --- a/sources/src/jdate.c +++ b/sources/src/jdate.c @@ -22,19 +22,19 @@ #define _XOPEN_SOURCE #endif +#include #include -#include #include -#include +#include #include -#include +#include #include #include "../libjalali/jalali.h" #include "../libjalali/jtime.h" #include "jdate.h" -extern char* optarg; +extern char *optarg; /* * Unix timestamp of last modification/access time for a file. @@ -44,259 +44,254 @@ extern char* optarg; * otherwise: st_atime (last access time) */ -int mod_time(const char* path, time_t* t, int a) -{ - struct stat st; - int err; +int mod_time(const char *path, time_t *t, int a) { + struct stat st; + int err; - err = stat(path, &st); - if (err == -1) - return err; + err = stat(path, &st); + if (err == -1) + return err; - *t = (a == 0) ? st.st_mtime : st.st_atime; + *t = (a == 0) ? st.st_mtime : st.st_atime; - return 0; + return 0; } -int main(int argc, char** argv) -{ - int opt; - int i; - int err; - int option_index; - - char buf[MAX_BUF_SIZE]; - char date_format[MAX_BUF_SIZE]; - char date_string[MAX_BUF_SIZE]; - - struct jtm j; - struct tm g; - - struct jdate_action action = {0}; - - /* Long options, see 'jdate.h' for complete list. */ - struct option long_options[] = { - {DATE_OPT, 1, 0, 'd'}, - {REF_OPT, 1, 0, 'r'}, - {ACC_OPT, 1, 0, 'a'}, - {RFC2822_OPT, 0, 0, 'R'}, - {UTC_OPT, 0, 0, 'u'}, - {JALALI_OPT, 1, 0, 'j'}, - {GREGORIAN_OPT, 1, 0, 'g'}, - {UNIVERSAL_OPT, 0, 0, 'u'}, - {HELP_OPT, 0, 0, 'h'}, - {VERSION_OPT, 0, 0, 'V'}, - {0, 0, 0, 0} - }; - - - action.normal = 1; - - time_t t; - time(&t); - jlocaltime_r(&t, &j); - - while ((opt = getopt_long(argc, argv, JDATE_VALID_ARGS, - long_options, &option_index)) != -1) { - switch (opt) { - /* last access time. */ - case 'a': - action.access = 1; - action.access_ptr = optarg; - break; - - /* last modification time. */ - case 'r': - action.reference = 1; - action.reference_ptr = optarg; - break; - - /* display time described by FORMAT and DATE_STRING, not `now'. */ - case 'd': - action.date = 1; - action.date_ptr = optarg; - break; - - /* convert a jalali date to gregorian. */ - case 'g': - action.gregorian = 1; - action.gregorian_ptr = optarg; - break; - - /* convert a gregorian date to jalali. */ - case 'j': - action.jalali = 1; - action.jalali_ptr = optarg; - break; - - /* - * output date and time in RFC 2822 format. - * %h, %m %b %Y %H:%M:%S %z - */ - case 'R': - action.normal = 0; - action.format = 0; - action.rfc2822 = 1; - break; - - /* print Coordinated Universal Time */ - case 'u': - action.utc = 1; - break; - - /* help */ - case 'h': - action.help = 1; - action.normal = 0; - action.format = 0; - action.rfc2822 = 0; - break; - - /* version */ - case 'V': - action.version = 1; - action.help = 0; - action.normal = 0; - action.format = 0; - action.rfc2822 = 0; - break; - - default: - fprintf(stderr, "jdate: usage [OPTION]... [+FORMAT]\n"); - exit(EXIT_FAILURE); - } +int main(int argc, char **argv) { + int opt; + int i; + int err; + int option_index; + + char buf[MAX_BUF_SIZE]; + char date_format[MAX_BUF_SIZE]; + char date_string[MAX_BUF_SIZE]; + + struct jtm j; + struct tm g; + + struct jdate_action action = {0}; + + /* Long options, see 'jdate.h' for complete list. */ + struct option long_options[] = {{DATE_OPT, 1, 0, 'd'}, + {REF_OPT, 1, 0, 'r'}, + {ACC_OPT, 1, 0, 'a'}, + {RFC2822_OPT, 0, 0, 'R'}, + {UTC_OPT, 0, 0, 'u'}, + {JALALI_OPT, 1, 0, 'j'}, + {GREGORIAN_OPT, 1, 0, 'g'}, + {UNIVERSAL_OPT, 0, 0, 'u'}, + {HELP_OPT, 0, 0, 'h'}, + {VERSION_OPT, 0, 0, 'V'}, + {0, 0, 0, 0}}; + + action.normal = 1; + + time_t t; + time(&t); + jlocaltime_r(&t, &j); + + while ((opt = getopt_long(argc, argv, JDATE_VALID_ARGS, long_options, + &option_index)) != -1) { + switch (opt) { + /* last access time. */ + case 'a': + action.access = 1; + action.access_ptr = optarg; + break; + + /* last modification time. */ + case 'r': + action.reference = 1; + action.reference_ptr = optarg; + break; + + /* display time described by FORMAT and DATE_STRING, not `now'. */ + case 'd': + action.date = 1; + action.date_ptr = optarg; + break; + + /* convert a jalali date to gregorian. */ + case 'g': + action.gregorian = 1; + action.gregorian_ptr = optarg; + break; + + /* convert a gregorian date to jalali. */ + case 'j': + action.jalali = 1; + action.jalali_ptr = optarg; + break; + + /* + * output date and time in RFC 2822 format. + * %h, %m %b %Y %H:%M:%S %z + */ + case 'R': + action.normal = 0; + action.format = 0; + action.rfc2822 = 1; + break; + + /* print Coordinated Universal Time */ + case 'u': + action.utc = 1; + break; + + /* help */ + case 'h': + action.help = 1; + action.normal = 0; + action.format = 0; + action.rfc2822 = 0; + break; + + /* version */ + case 'V': + action.version = 1; + action.help = 0; + action.normal = 0; + action.format = 0; + action.rfc2822 = 0; + break; + + default: + fprintf(stderr, "jdate: usage [OPTION]... [+FORMAT]\n"); + exit(EXIT_FAILURE); } - - /* - * Format string handler. INPUT_FORMAT and DATE_STRING - * are separated using a semicolon. ';' - * e.g. "%Y/%m/%d %H:%M:%S;1390/03/06 18:35:41" - */ - for (i=1; i" *@action_handler */ struct jdate_action { - int normal; /* standard representation: %h %b %m %H:%M:%S %Z %Y */ - int reference; /* last modification time */ - char* reference_ptr; /* last modification time argument */ - int access; /* last access */ - char* access_ptr; /* last access argument */ - int date; /* use date string instead of 'now' */ - char* date_ptr; /* date string argument */ - int jalali; /* convert a gregorian date to jalali */ - char* jalali_ptr; /* jalali conversion argument */ - int gregorian; /* convert a jalali date to gregorian */ - char* gregorian_ptr; /* gregorian conversion argument */ - int format; /* +FORMAT. uses jstrftime() to format output */ - char* format_ptr; /* +FORMAT argument */ - int rfc2822; /* rfc2822 date and time: %h, %m %b %Y %H:%M:%S %z */ - int utc; /* Coordinated Universal Time */ - int help; /* help */ - int version; /* version */ + int normal; /* standard representation: %h %b %m %H:%M:%S %Z %Y */ + int reference; /* last modification time */ + char *reference_ptr; /* last modification time argument */ + int access; /* last access */ + char *access_ptr; /* last access argument */ + int date; /* use date string instead of 'now' */ + char *date_ptr; /* date string argument */ + int jalali; /* convert a gregorian date to jalali */ + char *jalali_ptr; /* jalali conversion argument */ + int gregorian; /* convert a jalali date to gregorian */ + char *gregorian_ptr; /* gregorian conversion argument */ + int format; /* +FORMAT. uses jstrftime() to format output */ + char *format_ptr; /* +FORMAT argument */ + int rfc2822; /* rfc2822 date and time: %h, %m %b %Y %H:%M:%S %z */ + int utc; /* Coordinated Universal Time */ + int help; /* help */ + int version; /* version */ }; #endif /* JDATE_H */ diff --git a/sources/test_kit/jalali/elc.c b/sources/test_kit/jalali/elc.c index 2d1d4e4..26fcd09 100644 --- a/sources/test_kit/jalali/elc.c +++ b/sources/test_kit/jalali/elc.c @@ -1,32 +1,32 @@ #include #include + #include "jalali.h" -int main(int argc, char** argv) -{ - if (argc != 3) { +int main(int argc, char **argv) { + if (argc != 3) { printf("wrong arguments given\n"); printf("elc: leap counter from YEAR1 to YEAR2\n"); printf("usage: elc YEAR1 YEAR2\n"); exit(1); - } + } - int i, s = atoi(argv[1]), e = atoi(argv[2]), c = 0; + int i, s = atoi(argv[1]), e = atoi(argv[2]), c = 0; - if (s > e) { + if (s > e) { /* tricky swap */ - s = s+e; - e = s-e; - s = s-e; - } + s = s + e; + e = s - e; + s = s - e; + } - printf("leap years from %d to %d... ", s, e); + printf("leap years from %d to %d... ", s, e); - for (i=s; i<=e; i++) { + for (i = s; i <= e; i++) { if (jalali_is_jleap(i)) - c++; - } + c++; + } - printf("%d.\n", c); - exit(0); + printf("%d.\n", c); + exit(0); } diff --git a/sources/test_kit/jalali/get_date.c b/sources/test_kit/jalali/get_date.c index 6fb74ea..8acb81f 100644 --- a/sources/test_kit/jalali/get_date.c +++ b/sources/test_kit/jalali/get_date.c @@ -1,25 +1,25 @@ #include #include + #include "jalali.h" -int main(int argc, char** argv) -{ - if (argc != 2) { +int main(int argc, char **argv) { + if (argc != 2) { printf("wrong arguments given\n"); printf("usage: get_date DIFF_FROM_EPOCH_BY_DAYS\n"); exit(1); - } + } - int p = atoi(argv[1]); - struct jtm j; - jalali_get_date(p, &j); - jalali_create_date_from_days(&j); + int p = atoi(argv[1]); + struct jtm j; + jalali_get_date(p, &j); + jalali_create_date_from_days(&j); - j.tm_hour = 0; - j.tm_min = 0; - j.tm_sec = 0; + j.tm_hour = 0; + j.tm_min = 0; + j.tm_sec = 0; - jalali_show_time(&j); + jalali_show_time(&j); - exit(0); + exit(0); } diff --git a/sources/test_kit/jalali/get_diff.c b/sources/test_kit/jalali/get_diff.c index 1e690cf..a9b54e2 100644 --- a/sources/test_kit/jalali/get_diff.c +++ b/sources/test_kit/jalali/get_diff.c @@ -1,31 +1,31 @@ #include #include + #include "jalali.h" -int main(int argc, char** argv) -{ - if (argc != 4) { +int main(int argc, char **argv) { + if (argc != 4) { printf("wrong arguments given\n"); printf("usage: get_diff DAY MONTH YEAR\n"); exit(1); - } + } - int d = atoi(argv[1]); - int m = atoi(argv[2]); - int y = atoi(argv[3]); + int d = atoi(argv[1]); + int m = atoi(argv[2]); + int y = atoi(argv[3]); - struct jtm j; - j.tm_mday = d; - j.tm_mon = m - 1; - j.tm_year = y; - j.tm_hour = 0; - j.tm_min = 0; - j.tm_sec = 0; + struct jtm j; + j.tm_mday = d; + j.tm_mon = m - 1; + j.tm_year = y; + j.tm_hour = 0; + j.tm_min = 0; + j.tm_sec = 0; - jalali_create_days_from_date(&j); - jalali_update(&j); - jalali_show_time(&j); - printf("diff = %d\n", jalali_get_diff(&j)); + jalali_create_days_from_date(&j); + jalali_update(&j); + jalali_show_time(&j); + printf("diff = %d\n", jalali_get_diff(&j)); - exit(0); + exit(0); } diff --git a/sources/test_kit/jalali/jalali_update.c b/sources/test_kit/jalali/jalali_update.c index 3c44ecd..eae2468 100644 --- a/sources/test_kit/jalali/jalali_update.c +++ b/sources/test_kit/jalali/jalali_update.c @@ -1,48 +1,72 @@ #include #include + #include "jalali.h" #include "jtime.h" -int main(int argc, char** argv) { - time_t t; - struct jtm j; - int mday_diff = 60; +int main(int argc, char **argv) { + time_t t; + struct jtm j; + int mday_diff = 60; - time(&t); - jlocaltime_r(&t, &j); - puts("Current time jtm:"); - jalali_show_time(&j); + time(&t); + jlocaltime_r(&t, &j); + puts("Current time jtm:"); + jalali_show_time(&j); - char ans; - int* mem_ref; - char* mem_name; - do { - printf(">> Reset tm_year [y], tm_mon [M], tm_mday [d], tm_hour [h], tm_min [m], tm_sec[s] to: ([e] for end) "); - scanf("%c", &ans); - switch (ans) { - case 'y': mem_ref = &j.tm_year; mem_name = "tm_year"; break; - case 'M': mem_ref = &j.tm_mon; mem_name = "tm_mon"; break; - case 'd': mem_ref = &j.tm_mday; mem_name = "tm_mday"; break; - case 'h': mem_ref = &j.tm_hour; mem_name = "tm_hour"; break; - case 'm': mem_ref = &j.tm_min; mem_name = "tm_min"; break; - case 's': mem_ref = &j.tm_sec; mem_name = "tm_sec"; break; - case 'e': break; - default: - printf("Unrecognized field `%c'. select from [yMdhmse] and provide a value.\n", ans); - ans = 0; - break; - } - if(ans && ans != 'e') { - scanf("%d%*c", mem_ref); - printf ("%s = %d\n", mem_name, *mem_ref); - } else getchar(); - } while (ans != 'e'); + char ans; + int *mem_ref; + char *mem_name; + do { + printf(">> Reset tm_year [y], tm_mon [M], tm_mday [d], tm_hour [h], tm_min " + "[m], tm_sec[s] to: ([e] for end) "); + scanf("%c", &ans); + switch (ans) { + case 'y': + mem_ref = &j.tm_year; + mem_name = "tm_year"; + break; + case 'M': + mem_ref = &j.tm_mon; + mem_name = "tm_mon"; + break; + case 'd': + mem_ref = &j.tm_mday; + mem_name = "tm_mday"; + break; + case 'h': + mem_ref = &j.tm_hour; + mem_name = "tm_hour"; + break; + case 'm': + mem_ref = &j.tm_min; + mem_name = "tm_min"; + break; + case 's': + mem_ref = &j.tm_sec; + mem_name = "tm_sec"; + break; + case 'e': + break; + default: + printf("Unrecognized field `%c'. select from [yMdhmse] and provide a " + "value.\n", + ans); + ans = 0; + break; + } + if (ans && ans != 'e') { + scanf("%d%*c", mem_ref); + printf("%s = %d\n", mem_name, *mem_ref); + } else + getchar(); + } while (ans != 'e'); - puts("Before update: "); - jalali_show_time(&j); + puts("Before update: "); + jalali_show_time(&j); - jalali_update(&j); - puts("After update: "); - jalali_show_time(&j); - return 0; + jalali_update(&j); + puts("After update: "); + jalali_show_time(&j); + return 0; } diff --git a/sources/test_kit/jalali/jyinfo.c b/sources/test_kit/jalali/jyinfo.c index c462288..0550aba 100644 --- a/sources/test_kit/jalali/jyinfo.c +++ b/sources/test_kit/jalali/jyinfo.c @@ -1,21 +1,22 @@ #include #include + #include "jalali.h" -int main(int argc, char** argv) -{ - struct jyinfo a; +int main(int argc, char **argv) { + struct jyinfo a; - if (argc != 2) { + if (argc != 2) { printf("wrong arguments given\n"); printf("usage: jyinfo YEAR\n"); exit(1); - } + } - a.y = atoi(argv[1]); - jalali_get_jyear_info(&a); - fprintf(stdout, "Year %d: lf = %d, apl = %d, pl = %d, rl = %d, p = %d, r = %d.\n", a.y, a.lf, - a.apl, a.pl, a.rl, a.p, a.r); + a.y = atoi(argv[1]); + jalali_get_jyear_info(&a); + fprintf(stdout, + "Year %d: lf = %d, apl = %d, pl = %d, rl = %d, p = %d, r = %d.\n", + a.y, a.lf, a.apl, a.pl, a.rl, a.p, a.r); - exit(0); + exit(0); } diff --git a/sources/test_kit/jalali/leap.c b/sources/test_kit/jalali/leap.c index 9fe6dea..cb77416 100644 --- a/sources/test_kit/jalali/leap.c +++ b/sources/test_kit/jalali/leap.c @@ -1,16 +1,17 @@ #include #include + #include "jalali.h" -int main(int argc, char** argv) -{ - if (argc != 2) { +int main(int argc, char **argv) { + if (argc != 2) { printf("wrong arguments given\n"); printf("usage: leap YEAR\n"); exit(1); - } + } - printf("year %d leap status: %d.\n", atoi(argv[1]), jalali_is_jleap(atoi(argv[1]))); + printf("year %d leap status: %d.\n", atoi(argv[1]), + jalali_is_jleap(atoi(argv[1]))); - exit(0); + exit(0); } diff --git a/sources/test_kit/jalali/sec_converter.c b/sources/test_kit/jalali/sec_converter.c index 99b6dcf..f3b9fc8 100644 --- a/sources/test_kit/jalali/sec_converter.c +++ b/sources/test_kit/jalali/sec_converter.c @@ -1,20 +1,21 @@ #include #include + #include "jalali.h" -int main(int argc, char** argv) -{ - if (argc != 2) { +int main(int argc, char **argv) { + if (argc != 2) { printf("wrong arguments given\n"); printf("usage: sec_converter SECONDS\n"); exit(1); - } + } - struct ab_jtm a; - int s; - s = atoi(argv[1]); - jalali_create_time_from_secs(s, &a); - printf("%d secs passed, time created: %d days, %02d:%02d:%02d.\n", s, a.ab_days, a.ab_hour, a.ab_min, a.ab_sec); + struct ab_jtm a; + int s; + s = atoi(argv[1]); + jalali_create_time_from_secs(s, &a); + printf("%d secs passed, time created: %d days, %02d:%02d:%02d.\n", s, + a.ab_days, a.ab_hour, a.ab_min, a.ab_sec); - exit(0); + exit(0); } diff --git a/sources/test_kit/jtime/jasctime.c b/sources/test_kit/jtime/jasctime.c index 156462e..e3770ba 100644 --- a/sources/test_kit/jtime/jasctime.c +++ b/sources/test_kit/jtime/jasctime.c @@ -1,19 +1,20 @@ #include #include + #include "jalali.h" #include "jtime.h" int main() { - time_t ltime; - time(<ime); - struct ab_jtm a; - struct jtm j; - jalali_create_time_from_secs(ltime, &a); - jalali_get_date(a.ab_days, &j); - j.tm_sec = a.ab_sec; - j.tm_min = a.ab_min; - j.tm_hour = a.ab_hour; - jalali_create_date_from_days(&j); - printf("%s", jasctime(&j)); - return 0; + time_t ltime; + time(<ime); + struct ab_jtm a; + struct jtm j; + jalali_create_time_from_secs(ltime, &a); + jalali_get_date(a.ab_days, &j); + j.tm_sec = a.ab_sec; + j.tm_min = a.ab_min; + j.tm_hour = a.ab_hour; + jalali_create_date_from_days(&j); + printf("%s", jasctime(&j)); + return 0; } diff --git a/sources/test_kit/jtime/jctime.c b/sources/test_kit/jtime/jctime.c index 8f63c4e..26ebb20 100644 --- a/sources/test_kit/jtime/jctime.c +++ b/sources/test_kit/jtime/jctime.c @@ -1,15 +1,16 @@ #include #include + #include "jalali.h" #include "jtime.h" int main() { - time_t t; - time(&t); - struct jtm j; - char buf[2048]; - printf("%s", jctime(&t)); - jctime_r(&t, buf); - printf("%s", buf); - return 0; + time_t t; + time(&t); + struct jtm j; + char buf[2048]; + printf("%s", jctime(&t)); + jctime_r(&t, buf); + printf("%s", buf); + return 0; } diff --git a/sources/test_kit/jtime/jgmtime.c b/sources/test_kit/jtime/jgmtime.c index a44d741..d9eb7bc 100644 --- a/sources/test_kit/jtime/jgmtime.c +++ b/sources/test_kit/jtime/jgmtime.c @@ -1,16 +1,17 @@ #include #include + #include "jalali.h" #include "jtime.h" int main() { - time_t t; - time(&t); - struct jtm j; - struct jtm* p; - p = jgmtime(&t); - jalali_show_time(p); - jgmtime_r(&t, &j); - jalali_show_time(&j); - return 0; + time_t t; + time(&t); + struct jtm j; + struct jtm *p; + p = jgmtime(&t); + jalali_show_time(p); + jgmtime_r(&t, &j); + jalali_show_time(&j); + return 0; } diff --git a/sources/test_kit/jtime/jlocaltime.c b/sources/test_kit/jtime/jlocaltime.c index b21205a..ce53a96 100644 --- a/sources/test_kit/jtime/jlocaltime.c +++ b/sources/test_kit/jtime/jlocaltime.c @@ -1,16 +1,17 @@ #include #include + #include "jalali.h" #include "jtime.h" int main() { - time_t t; - time(&t); - struct jtm* p; - struct jtm j; - p = jlocaltime(&t); - jalali_show_time(p); - jlocaltime_r(&t, &j); - jalali_show_time(&j); - return 0; + time_t t; + time(&t); + struct jtm *p; + struct jtm j; + p = jlocaltime(&t); + jalali_show_time(p); + jlocaltime_r(&t, &j); + jalali_show_time(&j); + return 0; } diff --git a/sources/test_kit/jtime/jmktime.c b/sources/test_kit/jtime/jmktime.c index 0883883..bbafe69 100644 --- a/sources/test_kit/jtime/jmktime.c +++ b/sources/test_kit/jtime/jmktime.c @@ -1,14 +1,15 @@ #include #include + #include "jalali.h" #include "jtime.h" int main() { - time_t t; - time(&t); - struct jtm j; - jlocaltime_r(&t, &j); - jalali_show_time(&j); - printf("%d <-> %d\n", (int) jmktime(&j), (int) t); - return 0; + time_t t; + time(&t); + struct jtm j; + jlocaltime_r(&t, &j); + jalali_show_time(&j); + printf("%d <-> %d\n", (int)jmktime(&j), (int)t); + return 0; } diff --git a/sources/test_kit/jtime/jstrftime.c b/sources/test_kit/jtime/jstrftime.c index 607f1a9..608107c 100644 --- a/sources/test_kit/jtime/jstrftime.c +++ b/sources/test_kit/jtime/jstrftime.c @@ -1,26 +1,27 @@ #include #include #include + #include "jalali.h" #include "jtime.h" -int main(int argc, char** argv) { - if (argc != 2) { +int main(int argc, char **argv) { + if (argc != 2) { printf("wrong arguments given\n"); printf("usage jstrftime FORMAT\n"); exit(1); - } + } - const char* fmt = argv[1]; - char buf[32]; - time_t t; - size_t s; - time(&t); - struct jtm j; - jlocaltime_r(&t, &j); - jalali_show_time(&j); - s = jstrftime(buf, 32, fmt, &j); - printf("%s:%d\n", buf, (int)s); + const char *fmt = argv[1]; + char buf[32]; + time_t t; + size_t s; + time(&t); + struct jtm j; + jlocaltime_r(&t, &j); + jalali_show_time(&j); + s = jstrftime(buf, 32, fmt, &j); + printf("%s:%d\n", buf, (int)s); - exit(0); + exit(0); } diff --git a/sources/test_kit/jtime/jstrptime.c b/sources/test_kit/jtime/jstrptime.c index 11fa109..86e7fea 100644 --- a/sources/test_kit/jtime/jstrptime.c +++ b/sources/test_kit/jtime/jstrptime.c @@ -1,17 +1,19 @@ #include #include -#include + #include +#include + #include "jalali.h" #include "jtime.h" int main() { - char *s; - char *fmt; - s = readline("string > "); - fmt = readline("format > "); - struct jtm j; - jstrptime(s, fmt, &j); - jalali_show_time(&j); - return 0; + char *s; + char *fmt; + s = readline("string > "); + fmt = readline("format > "); + struct jtm j; + jstrptime(s, fmt, &j); + jalali_show_time(&j); + return 0; }