diff options
Diffstat (limited to 'usr.bin/calendar/events.c')
-rw-r--r-- | usr.bin/calendar/events.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/usr.bin/calendar/events.c b/usr.bin/calendar/events.c index 39ede509e4db..9d4dce97e6e0 100644 --- a/usr.bin/calendar/events.c +++ b/usr.bin/calendar/events.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include <iconv.h> #include <errno.h> #include <langinfo.h> +#include <locale.h> static iconv_t conv = (iconv_t)-1; static char *currentEncoding = NULL; @@ -150,8 +151,7 @@ convert(char *input) } struct event * -event_add(int year, int month, int day, char *date, int var, char *txt, - char *extra) +event_add(int year, int month, int day, int var, char *txt, char *extra) { struct event *e; @@ -159,25 +159,22 @@ event_add(int year, int month, int day, char *date, int var, char *txt, * Creating a new event: * - Create a new event * - Copy the machine readable day and month - * - Copy the human readable and language specific date * - Copy the text of the event */ e = (struct event *)calloc(1, sizeof(struct event)); if (e == NULL) errx(1, "event_add: cannot allocate memory"); + e->year = year; e->month = month; e->day = day; e->var = var; - e->date = convert(date); - if (e->date == NULL) - errx(1, "event_add: cannot allocate memory"); e->text = convert(txt); if (e->text == NULL) errx(1, "event_add: cannot allocate memory"); e->extra = NULL; if (extra != NULL && extra[0] != '\0') e->extra = convert(extra); - addtodate(e, year, month, day); + addtodate(e); return (e); } @@ -204,20 +201,37 @@ void event_print_all(FILE *fp) { struct event *e; + struct tm tm; + char dbuf[80]; + static int d_first; + const char *lang; + + lang = getenv("LANG"); + if (lang == NULL) + lang = "C"; + if (setlocale(LC_ALL, lang) == NULL) + (void)setlocale(LC_ALL, "C"); + d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); while (walkthrough_dates(&e) != 0) { + if (e) { #ifdef DEBUG - if (e) fprintf(stderr, "event_print_all month: %d, day: %d\n", e->month, e->day); #endif + memset(&tm, 0, sizeof(struct tm)); + tm.tm_mday = e->day; + tm.tm_mon = e->month - 1; + tm.tm_year = e->year - 1900; + (void)strftime(dbuf, sizeof(dbuf), d_first ? "%e %b" : "%b %e", &tm); + } /* * Go through all events and print the text of the matching * dates */ while (e != NULL) { - (void)fprintf(fp, "%s%c%s%s%s%s\n", e->date, + (void)fprintf(fp, "%s%c%s%s%s%s\n", dbuf, e->var ? '*' : ' ', e->text, e->extra != NULL ? " (" : "", e->extra != NULL ? e->extra : "", |