From efbff81b258e3d7abbadce170d1d4cce39d0d562 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 11 May 2005 03:00:03 +0000 Subject: [PATCH] * webcit.c: fixed a string bug that caused the whole system to not work * messages.c: fullname only and brief date in summary view, so that it doesn't wrap onto two lines quite as often --- webcit/ChangeLog | 6 ++++- webcit/calendar.c | 4 ++-- webcit/calendar_view.c | 2 +- webcit/messages.c | 13 ++++++----- webcit/tools.c | 50 ++++++++++++++++++++++++++++++++---------- webcit/webcit.c | 2 +- webcit/webcit.h | 2 +- 7 files changed, 55 insertions(+), 24 deletions(-) diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 461541b40..1af6a2f8e 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,9 @@ $Log$ +Revision 610.4 2005/05/11 03:00:03 ajc +* webcit.c: fixed a string bug that caused the whole system to not work +* messages.c: fullname only and brief date in summary view, so that it + doesn't wrap onto two lines quite as often + Revision 610.3 2005/04/11 20:09:33 ajc * Began an assault on strcpy() @@ -2512,4 +2517,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/calendar.c b/webcit/calendar.c index 07221154d..ed46e30ba 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -169,7 +169,7 @@ void cal_process_object(icalcomponent *cal, } else { tt = icaltime_as_timet(t); - fmt_date(buf, tt); + fmt_date(buf, tt, 0); wprintf("Starting date/time:" "" "%s", buf @@ -181,7 +181,7 @@ void cal_process_object(icalcomponent *cal, if (p != NULL) { t = icalproperty_get_dtend(p); tt = icaltime_as_timet(t); - fmt_date(buf, tt); + fmt_date(buf, tt, 0); wprintf("Ending date/time:" "%s", buf ); diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index b18090900..f5ec03b6f 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -649,7 +649,7 @@ void do_tasks_view(void) { wprintf("\n"); due = get_task_due_date(WC->disp_cal[i].cal); - fmt_date(buf, due); + fmt_date(buf, due, 0); wprintf(""); - } + } */ if (!strncasecmp(buf, "node=", 5)) { if ( ((WC->room_flags & QR_NETWORK) @@ -763,7 +764,7 @@ void summarize_message(long msgnum, int is_new) { } if (!strncasecmp(buf, "time=", 5)) { - fmt_date(summ.date, atol(&buf[5])); + fmt_date(summ.date, atol(&buf[5]), 1); /* brief */ } } @@ -1642,7 +1643,7 @@ void display_enter(void) } now = time(NULL); - fmt_date(buf, now); + fmt_date(buf, now, 0); strcat(&buf[strlen(buf)], " from "); stresc(&buf[strlen(buf)], WC->wc_username, 1, 1); if (strlen(bstr("recp")) > 0) { diff --git a/webcit/tools.c b/webcit/tools.c index 3f445c9b0..de89c9fbd 100644 --- a/webcit/tools.c +++ b/webcit/tools.c @@ -195,25 +195,51 @@ char ch; /* * Format a date/time stamp for output */ -void fmt_date(char *buf, time_t thetime) +void fmt_date(char *buf, time_t thetime, int brief) { - struct tm *tm; + struct tm tm; + struct tm today_tm; + time_t today_timet; int hour; - buf[0] = 0; - tm = localtime(&thetime); - hour = tm->tm_hour; + today_timet = time(NULL); + localtime_r(&today_timet, &today_tm); + + localtime_r(&thetime, &tm); + hour = tm.tm_hour; if (hour == 0) hour = 12; else if (hour > 12) hour = hour - 12; - sprintf(buf, "%s %d %d %2d:%02d%s", - ascmonths[tm->tm_mon], - tm->tm_mday, - tm->tm_year + 1900, - hour, tm->tm_min, ((tm->tm_hour >= 12) ? "pm" : "am") - ); + buf[0] = 0; + + if (brief) { + + if ((tm.tm_year == today_tm.tm_year) + &&(tm.tm_mon == today_tm.tm_mon) + &&(tm.tm_mday == today_tm.tm_mday)) { + sprintf(buf, "%2d:%02d%s", + hour, tm.tm_min, + ((tm.tm_hour >= 12) ? "pm" : "am") + ); + } + else { + sprintf(buf, "%s %d %d", + ascmonths[tm.tm_mon], + tm.tm_mday, + tm.tm_year + 1900 + ); + } + } + else { + sprintf(buf, "%s %d %d %2d:%02d%s", + ascmonths[tm.tm_mon], + tm.tm_mday, + tm.tm_year + 1900, + hour, tm.tm_min, ((tm.tm_hour >= 12) ? "pm" : "am") + ); + } } @@ -525,7 +551,7 @@ int CtdlDecodeBase64(char *dest, const char *source, size_t length) return (dpos); } if (dtable[c] & 0x80) { - /* Ignoring errors: discard invalid character. */ + /* Ignoring errors: discard invalid character */ i--; continue; } diff --git a/webcit/webcit.c b/webcit/webcit.c index 5e8568cf6..b27dcc5ec 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -109,7 +109,7 @@ void addurls(char *url) strcpy(ptr, ""); u->url_data = malloc(strlen(up) + 2); - safestrncpy(u->url_data, up, sizeof u->url_data); + safestrncpy(u->url_data, up, strlen(up) + 1); u->url_data[b] = 0; unescape_input(u->url_data); up = ptr; diff --git a/webcit/webcit.h b/webcit/webcit.h index b4cb23beb..b35db8e4c 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -374,7 +374,7 @@ void display_menubar(int); void smart_goto(char *); void worker_entry(void); void session_loop(struct httprequest *); -void fmt_date(char *buf, time_t thetime); +void fmt_date(char *buf, time_t thetime, int brief); void fmt_time(char *buf, time_t thetime); void httpdate(char *buf, time_t thetime); void end_webcit_session(void); -- 2.39.2