From owner-svn-src-user@FreeBSD.ORG Mon Jan 4 20:55:47 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B3FA31065695; Mon, 4 Jan 2010 20:55:47 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A2EF08FC15; Mon, 4 Jan 2010 20:55:47 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o04KtlQG077077; Mon, 4 Jan 2010 20:55:47 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o04KtlAL077066; Mon, 4 Jan 2010 20:55:47 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <201001042055.o04KtlAL077066@svn.freebsd.org> From: Edwin Groothuis Date: Mon, 4 Jan 2010 20:55:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r201531 - user/edwin/calendar X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jan 2010 20:55:47 -0000 Author: edwin Date: Mon Jan 4 20:55:47 2010 New Revision: 201531 URL: http://svn.freebsd.org/changeset/base/201531 Log: Behold! Calendar prints events again, even over multiple years. Modified: user/edwin/calendar/calendar.c user/edwin/calendar/calendar.h user/edwin/calendar/dates.c user/edwin/calendar/day.c user/edwin/calendar/events.c user/edwin/calendar/io.c user/edwin/calendar/ostern.c user/edwin/calendar/parsedata.c user/edwin/calendar/paskha.c user/edwin/calendar/pathnames.h Modified: user/edwin/calendar/calendar.c ============================================================================== --- user/edwin/calendar/calendar.c Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/calendar.c Mon Jan 4 20:55:47 2010 (r201531) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. All rights reserved. * Modified: user/edwin/calendar/calendar.h ============================================================================== --- user/edwin/calendar/calendar.h Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/calendar.h Mon Jan 4 20:55:47 2010 (r201531) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. All rights reserved. * @@ -83,10 +83,11 @@ extern int year1, year2; * - Use event_continue() to add more text to the last added event * - Use event_print_all() to display them in time chronological order */ -struct event *event_add(struct event *, int, int, char *, int, char *); +struct event *event_add(int, int, int, char *, int, char *); void event_continue(struct event *events, char *txt); -void event_print_all(FILE *fp, struct event *events); +void event_print_all(FILE *fp); struct event { + int year; int month; int day; int var; @@ -140,3 +141,5 @@ int remember_ymd(int y, int m, int d); int remember_yd(int y, int d, int *rm, int *rd); int first_dayofweek_of_year(int y); int first_dayofweek_of_month(int y, int m); +int walkthrough_dates(struct event **e); +void addtodate(struct event *e, int year, int month, int day); Modified: user/edwin/calendar/dates.c ============================================================================== --- user/edwin/calendar/dates.c Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/dates.c Mon Jan 4 20:55:47 2010 (r201531) @@ -79,6 +79,8 @@ int mondaytab[][14] = { {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30}, }; +static struct cal_day * find_day(int yy, int mm, int dd); + static void createdate(int y, int m, int d) { @@ -282,7 +284,7 @@ remember_ymd(int yy, int mm, int dd) if (d->dayofmonth == dd) return (1); d = d->nextday; - continue;; + continue; } return (0); } @@ -366,3 +368,85 @@ first_dayofweek_of_month(int yy, int mm) /* Should not happen */ return (-1); } + +int +walkthrough_dates(struct event **e) +{ + static struct cal_year *y = NULL; + static struct cal_month *m = NULL; + static struct cal_day *d = NULL; + + if (y == NULL) { + y = hyear; + m = y->months; + d = m->days; + *e = d->events; + return (1); + }; + if (d->nextday != NULL) { + d = d->nextday; + *e = d->events; + return (1); + } + if (m->nextmonth != NULL) { + m = m->nextmonth; + d = m->days; + *e = d->events; + return (1); + } + if (y->nextyear != NULL) { + y = y->nextyear; + m = y->months; + d = m->days; + *e = d->events; + return (1); + } + + return (0); +} + +static struct cal_day * +find_day(int yy, int mm, int dd) +{ + struct cal_year *y; + struct cal_month *m; + struct cal_day *d; + + if (debug_remember) + printf("remember_ymd: %d - %d - %d\n", yy, mm, dd); + + y = hyear; + while (y != NULL) { + if (y->year != yy) { + y = y->nextyear; + continue; + } + m = y->months; + while (m != NULL) { + if (m->month != mm) { + m = m->nextmonth; + continue; + } + d = m->days; + while (d != NULL) { + if (d->dayofmonth == dd) + return (d); + d = d->nextday; + continue; + } + return (NULL); + } + return (NULL); + } + return (NULL); +} + +void +addtodate(struct event *e, int year, int month, int day) +{ + struct cal_day *d; + + d = find_day(year, month, day); + e->next = d->events; + d->events = e; +} Modified: user/edwin/calendar/day.c ============================================================================== --- user/edwin/calendar/day.c Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/day.c Mon Jan 4 20:55:47 2010 (r201531) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. All rights reserved. * Modified: user/edwin/calendar/events.c ============================================================================== --- user/edwin/calendar/events.c Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/events.c Mon Jan 4 20:55:47 2010 (r201531) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. All rights reserved. * @@ -44,8 +44,7 @@ __FBSDID("$FreeBSD: user/edwin/calendar/ #include "calendar.h" struct event * -event_add(struct event *events, int month, int day, - char *date, int var, char *txt) +event_add(int year, int month, int day, char *date, int var, char *txt) { struct event *e; @@ -68,9 +67,8 @@ event_add(struct event *events, int mont e->text = strdup(txt); if (e->text == NULL) errx(1, "event_add: cannot allocate memory"); - e->next = events; - - return e; + addtodate(e, year, month, day); + return (e); } void @@ -102,42 +100,11 @@ event_continue(struct event *e, char *tx } void -event_print_all(FILE *fp, struct event *events) +event_print_all(FILE *fp) { - struct event *e, *e_next; - int daycounter; - int day, month; - - /* - * Print all events: - * - We know the number of days to be counted (f_dayAfter + f_dayBefore) - * - We know the current day of the year ("now" - f_dayBefore + counter) - * - We know the number of days in the year (yrdays, set in settime()) - * - So we know the date on which the current daycounter is on the - * calendar in days and months. - * - Go through the list of events, and print all matching dates - */ - for (daycounter = 0; daycounter <= f_dayAfter + f_dayBefore; - daycounter++) { - day = tp1.tm_yday - f_dayBefore + daycounter; -// if (day < 0) -// day += yrdays; -// if (day >= yrdays) -// day -= yrdays; - - /* - * When we know the day of the year, we can determine the day - * of the month and the month. - */ -// month = 1; -// while (month <= 12) { -// if (day <= cumdays[month]) -// break; -// month++; -// } -// month--; -// day -= cumdays[month]; + struct event *e; + while (walkthrough_dates(&e) != 0) { #ifdef DEBUG fprintf(stderr, "event_print_allmonth: %d, day: %d\n", month, day); @@ -147,14 +114,10 @@ event_print_all(FILE *fp, struct event * * Go through all events and print the text of the matching * dates */ - for (e = events; e != NULL; e = e_next) { - e_next = e->next; - - if (month != e->month || day != e->day) - continue; - + while (e != NULL) { (void)fprintf(fp, "%s%c%s\n", e->date, e->var ? '*' : ' ', e->text); + e = e->next; } } } Modified: user/edwin/calendar/io.c ============================================================================== --- user/edwin/calendar/io.c Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/io.c Mon Jan 4 20:55:47 2010 (r201531) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. All rights reserved. * @@ -96,7 +96,6 @@ cal(void) static int d_first = -1; char buf[2048 + 1]; struct event *events[MAXCOUNT]; - struct event *eventshead = NULL; struct tm tm; char dbuf[80]; @@ -167,12 +166,14 @@ cal(void) /* Trim spaces in front of the tab */ while (isspace(pp[-1])) pp--; + p = *pp; *pp = '\0'; if ((count = parsedaymonth(buf, year, month, day, &flags)) == 0) continue; printf("%s - count: %d\n", buf, count); *pp = p; + /* Find the last tab */ while (pp[1] == '\t') pp++; @@ -183,91 +184,18 @@ cal(void) for (i = 0; i < count; i++) { tm.tm_mon = month[i] - 1; tm.tm_mday = day[i]; - tm.tm_year = tp1.tm_year; /* unused */ + tm.tm_year = year[i] - 1900; (void)strftime(dbuf, sizeof(dbuf), d_first ? "%e %b" : "%b %e", &tm); - eventshead = event_add(eventshead, month[i], day[i], - dbuf, (flags &= F_VARIABLE != 0) ? 1 : 0, pp); - events[i] = eventshead; + events[i] = event_add(year[i], month[i], day[i], dbuf, + ((flags &= F_VARIABLE) != 0) ? 1 : 0, pp); } } - event_print_all(fp, eventshead); + event_print_all(fp); closecal(fp); } -#ifdef NOTDEF -//int -//getfield(char *p, int *flags) -//{ -// int val, var; -// char *start, savech; -// -// if (*p == '\0') -// return(0); -// -// /* Find the first digit, alpha or * */ -// for (; !isdigit((unsigned char)*p) && !isalpha((unsigned char)*p) -// && *p != '*'; ++p) -// ; -// if (*p == '*') { /* `*' is current month */ -// *flags |= F_ISMONTH; -// return (tp->tm_mon + 1); -// } -// if (isdigit((unsigned char)*p)) { -// val = strtol(p, &p, 10); /* if 0, it's failure */ -// for (; !isdigit((unsigned char)*p) -// && !isalpha((unsigned char)*p) && *p != '*'; ++p); -// return (val); -// } -// for (start = p; isalpha((unsigned char)*++p);); -// -// /* Sunday-1 */ -// if (*p == '+' || *p == '-') -// for(; isdigit((unsigned char)*++p);) -// ; -// -// savech = *p; -// *p = '\0'; -// -// /* Month */ -// if ((val = getmonth(start)) != 0) -// *flags |= F_ISMONTH; -// -// /* Day */ -// else if ((val = getday(start)) != 0) { -// *flags |= F_ISDAY; -// -// /* variable weekday */ -// if ((var = getdayvar(start)) != 0) { -// if (var <= 5 && var >= -4) -// val += var * 10; -//#ifdef DEBUG -// printf("var: %d\n", var); -//#endif -// } -// } -// -// /* Easter */ -// else if ((val = geteaster(start, tp->tm_year + 1900)) != 0) -// *flags |= F_EASTER; -// -// /* Paskha */ -// else if ((val = getpaskha(start, tp->tm_year + 1900)) != 0) -// *flags |= F_EASTER; -// -// /* undefined rest */ -// else { -// *p = savech; -// return (0); -// } -// for (*p = savech; !isdigit((unsigned char)*p) -// && !isalpha((unsigned char)*p) && *p != '*'; ++p) -// ; -// return (val); -//} -#endif - FILE * opencal(void) { Modified: user/edwin/calendar/ostern.c ============================================================================== --- user/edwin/calendar/ostern.c Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/ostern.c Mon Jan 4 20:55:47 2010 (r201531) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1996 Wolfram Schneider . Berlin. * All rights reserved. * Modified: user/edwin/calendar/parsedata.c ============================================================================== --- user/edwin/calendar/parsedata.c Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/parsedata.c Mon Jan 4 20:55:47 2010 (r201531) @@ -424,7 +424,7 @@ parsedaymonth(char *date, int *yearp, in && remember_ymd(year, imonth, d)) { remember(index++, yearp, monthp, dayp, year, imonth, - rd); + d); continue; } d += 7; @@ -440,8 +440,7 @@ parsedaymonth(char *date, int *yearp, in } if (remember_ymd(year, imonth, d)) remember(index++, yearp, - monthp, dayp, year, imonth, - rd); + monthp, dayp, year, imonth, d); continue; } continue; @@ -454,7 +453,7 @@ parsedaymonth(char *date, int *yearp, in while (d <= mondays[imonth]) { if (remember_ymd(year, imonth, d)) remember(index++, yearp, monthp, dayp, - year, imonth, rd); + year, imonth, d); d += 7; } continue; Modified: user/edwin/calendar/paskha.c ============================================================================== --- user/edwin/calendar/paskha.c Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/paskha.c Mon Jan 4 20:55:47 2010 (r201531) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (C) 1993-1996 by Andrey A. Chernov, Moscow, Russia. * All rights reserved. * Modified: user/edwin/calendar/pathnames.h ============================================================================== --- user/edwin/calendar/pathnames.h Mon Jan 4 20:34:15 2010 (r201530) +++ user/edwin/calendar/pathnames.h Mon Jan 4 20:55:47 2010 (r201531) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. *