Index: head/deskutils/calendar/Makefile =================================================================== --- head/deskutils/calendar/Makefile (revision 554324) +++ head/deskutils/calendar/Makefile (revision 554325) @@ -1,31 +1,31 @@ # $FreeBSD$ PORTNAME= calendar -DISTVERSION= 0.8 +DISTVERSION= 0.9 CATEGORIES= deskutils MAINTAINER= se@FreeBSD.org COMMENT= Port of the FreeBSD calendar program LICENSE= BSD3CLAUSE RUN_DEPENDS= ${LOCALBASE}/share/calendar/calendar.all:deskutils/calendar-data USE_GITHUB= yes GH_ACCOUNT= bsdimp GH_TAGNAME= fcc5d31 CFLAGS+= -D_PATH_LOCALBASE='\"${LOCALBASE}\"' LDFLAGS+= -lm -lutil PLIST_FILES= bin/calendar \ share/man/man1/calendar.1.gz OPTIONS_DEFINE= NLS NLS_CFLAGS= -DWITH_ICONV do-install: ${INSTALL_PROGRAM} ${WRKSRC}/calendar ${STAGEDIR}${PREFIX}/bin ${INSTALL_DATA} ${WRKSRC}/calendar.1 ${STAGEDIR}${PREFIX}/share/man/man1 .include Index: head/deskutils/calendar/distinfo =================================================================== --- head/deskutils/calendar/distinfo (revision 554324) +++ head/deskutils/calendar/distinfo (revision 554325) @@ -1,3 +1,3 @@ -TIMESTAMP = 1604437341 -SHA256 (bsdimp-calendar-0.8-fcc5d31_GH0.tar.gz) = ad7d0b51c4b834241aebbf6c50d187e5720f6c46c02615b27841a923e082aebc -SIZE (bsdimp-calendar-0.8-fcc5d31_GH0.tar.gz) = 132824 +TIMESTAMP = 1604699934 +SHA256 (bsdimp-calendar-0.9-fcc5d31_GH0.tar.gz) = ad7d0b51c4b834241aebbf6c50d187e5720f6c46c02615b27841a923e082aebc +SIZE (bsdimp-calendar-0.9-fcc5d31_GH0.tar.gz) = 132824 Index: head/deskutils/calendar/files/patch-calendar.1 =================================================================== --- head/deskutils/calendar/files/patch-calendar.1 (revision 554324) +++ head/deskutils/calendar/files/patch-calendar.1 (revision 554325) @@ -1,77 +1,101 @@ --- calendar.1.orig 2020-10-18 03:01:26 UTC +++ calendar.1 @@ -28,7 +28,7 @@ .\" @(#)calendar.1 8.1 (Berkeley) 6/29/93 .\" $FreeBSD$ .\" -.Dd September 29, 2020 -+.Dd October 28, 2020 ++.Dd November 5, 2020 .Dt CALENDAR 1 .Os .Sh NAME -@@ -198,7 +198,13 @@ file is preprocessed by a limited subset of +@@ -198,18 +198,35 @@ file is preprocessed by a limited subset of .Xr cpp 1 internally, allowing the inclusion of shared files such as lists of company holidays or meetings. -This limited subset consists of \fB#include #ifndef #endif\fR and \fB#define\fR. -+This limited subset consists of \fB#include #ifdef #ifndef #else -+#endif\fR and \fB#define\fR. Conditions can be nested, but not check -+for matching begin and end directives is performed. -+Included files are parsed in their own scope. -+They have no read or write access to condition variables defined in -+an outer scope and open conditional blocks are implicitly closed. ++This limited subset consists of \fB#include\fR, \fB#define\fR, ++\fB#undef\fR, \fB#ifdef\fR, \fB#ifndef\fR, \fB#else\fR, \fB#warning\fR, ++and \fB#error\fR. +.Pp ++Conditions can be nested and the consistency of opening and closing ++instructions is checked. ++Only the first word after #define is used as the name of the ++condition variable being defined. ++More than word following #ifdef, #ifndef, or #undef is considered a syntax ++error, since names cannot include white-space. ++Included files are parsed in a global scope with regard to the condition ++variables being defined or tested therein. ++All conditional blocks are implicitly closed at the end of a file, ++and missing #endif instructions are assumed to be present on implied ++succeeding lines. ++.Pp If the shared file is not referenced by a full pathname, .Nm searches in the current (or home) directory first, and then in the -@@ -245,11 +251,19 @@ A chdir is done into this directory if it exists. + directory + .Pa /usr/share/calendar . +-Empty lines and lines protected by the C commenting syntax ++Empty lines and text protected by the C commenting syntax + .Pq Li /* ... */ ++or ++.Pq Li // + are ignored. + .Pp + Some possible calendar entries ( characters highlighted by +-\fB\et\fR sequence) ++\fB\et\fR sequence): + .Bd -unfilled -offset indent + LANG=C + Easter=Ostern +@@ -245,11 +262,19 @@ A chdir is done into this directory if it exists. calendar file to use if no calendar file exists in the current directory. .It Pa ~/.calendar/nomail do not send mail if this file exists. +.It Pa /usr/share/calendar +system wide location of calendar files provided as part of the base system. +.It Pa /usr/local/share/calendar +system wide location for calendar files provided by a port or package. .El .Pp -The following default calendar files are provided in -.Pa /usr/share/calendar : +The order of precedence in searches for a calendar file is: +current directory, ~/.calendar, /usr/local/share/calendar, /usr/share/calendar. +Files of similar names are ignored in lower precedence locations. .Pp +The following default calendar files are provided by the +deskutils/calendar-data port. +.Pp .Bl -tag -width calendar.southafrica -compact .It Pa calendar.all File which includes all the default files. -@@ -283,8 +297,8 @@ Other holidays, including the not-well-known, obscure, +@@ -283,8 +308,8 @@ Other holidays, including the not-well-known, obscure, obscure. .It Pa calendar.judaic Jewish holidays. -The entries for this calendar have been obtained from the port -deskutils/hebcal. +The entries for this calendar have been obtained from the +deskutils/hebcal port. .It Pa calendar.music Musical events, births, and deaths. Strongly oriented toward rock 'n' roll. -@@ -338,11 +352,12 @@ double-check the start and end time of solar and lunar +@@ -338,11 +363,12 @@ double-check the start and end time of solar and lunar .Sh BUGS The .Nm -internal cpp does not correctly do #ifndef and will discard the rest -of the file if a #ifndef is triggered. -It also has a maximum of 50 include file and/or 100 #defines -and only recognises #include, #define and -#ifndef. +does only recognise the cpp directives #include, #define, #ifdef, +#ifndef and #else. +It supports nested conditions, but does not perform any validation +on the correct use and nesting of conditions. +#endif without prior #ifdef or #define is ignored and #else outside +a conditional section skips input lines up to the next #endif. .Pp There is no possibility to properly specify the local position needed for solar and lunar calculations. Index: head/deskutils/calendar/files/patch-calendar.h =================================================================== --- head/deskutils/calendar/files/patch-calendar.h (nonexistent) +++ head/deskutils/calendar/files/patch-calendar.h (revision 554325) @@ -0,0 +1,28 @@ +--- calendar.h.orig 2020-10-18 03:01:26 UTC ++++ calendar.h +@@ -122,7 +122,7 @@ 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(int, int, int, char *, int, char *, char *); ++struct event *event_add(int, int, int, int, char *, char *); + void event_continue(struct event *events, char *txt); + void event_print_all(FILE *fp); + struct event { +@@ -130,7 +130,6 @@ struct event { + int month; + int day; + int var; +- char *date; + char *text; + char *extra; + struct event *next; +@@ -189,7 +188,7 @@ 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); ++void addtodate(struct event *e); + + /* pom.c */ + #define MAXMOONS 18 Property changes on: head/deskutils/calendar/files/patch-calendar.h ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/deskutils/calendar/files/patch-dates.c =================================================================== --- head/deskutils/calendar/files/patch-dates.c (revision 554324) +++ head/deskutils/calendar/files/patch-dates.c (revision 554325) @@ -1,35 +1,31 @@ --- dates.c.orig 2020-10-18 03:01:26 UTC +++ dates.c -@@ -28,7 +28,7 @@ - */ - - #include --__FBSDID("$FreeBSD$"); -+__FBSDID("$FreeBSD: head/usr.bin/calendar/dates.c 367173 2020-10-30 15:43:52Z se $"); - - #include - #include @@ -64,6 +64,7 @@ struct cal_day { struct cal_month *month; /* points back */ struct cal_year *year; /* points back */ struct event *events; + struct event *lastevent; }; int debug_remember = 0; -@@ -446,8 +447,13 @@ void - addtodate(struct event *e, int year, int month, int day) +@@ -443,11 +444,16 @@ find_day(int yy, int mm, int dd) + } + + void +-addtodate(struct event *e, int year, int month, int day) ++addtodate(struct event *e) { struct cal_day *d; + struct event *ee; - d = find_day(year, month, day); +- d = find_day(year, month, day); - e->next = d->events; - d->events = e; ++ d = find_day(e->year, e->month, e->day); + ee = d->lastevent; + if (ee != NULL) + ee->next = e; + else + d->events = e; + d->lastevent = e; } Index: head/deskutils/calendar/files/patch-events.c =================================================================== --- head/deskutils/calendar/files/patch-events.c (revision 554324) +++ head/deskutils/calendar/files/patch-events.c (revision 554325) @@ -1,14 +1,75 @@ --- events.c.orig 2020-10-18 03:01:26 UTC +++ events.c -@@ -207,8 +207,9 @@ event_print_all(FILE *fp) +@@ -150,8 +150,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 +158,22 @@ event_add(int year, int month, int day, char *date, in + * 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,19 +200,31 @@ void + event_print_all(FILE *fp) + { + struct event *e; ++ struct tm tm; ++ char dbuf[80]; ++ static int d_first; + ++ d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); ++ while (walkthrough_dates(&e) != 0) { ++ if (e) { #ifdef DEBUG - fprintf(stderr, "event_print_allmonth: %d, day: %d\n", - month, day); -+ 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 : "", Index: head/deskutils/calendar/files/patch-io.c =================================================================== --- head/deskutils/calendar/files/patch-io.c (revision 554324) +++ head/deskutils/calendar/files/patch-io.c (revision 554325) @@ -1,442 +1,547 @@ --- io.c.orig 2020-10-18 03:01:26 UTC +++ io.c -@@ -71,10 +71,14 @@ enum { +@@ -50,7 +50,6 @@ __FBSDID("$FreeBSD$"); + #include + #include + #include +-#include + #include + #include + #include +@@ -71,10 +70,14 @@ enum { }; const char *calendarFile = "calendar"; /* default calendar file */ -static const char *calendarHomes[] = {".calendar", _PATH_INCLUDE}; /* HOME */ +static const char *calendarHomes[] = {".calendar", _PATH_INCLUDE_LOCAL, _PATH_INCLUDE}; /* HOME */ static const char *calendarNoMail = "nomail";/* don't sent mail if file exist */ static char path[MAXPATHLEN]; +static const char *cal_home; +static const char *cal_dir; +static const char *cal_file; +static int cal_line; struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon; struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice; -@@ -85,22 +89,29 @@ static StringList *definitions = NULL; +@@ -85,22 +88,29 @@ static StringList *definitions = NULL; static struct event *events[MAXCOUNT]; static char *extradata[MAXCOUNT]; -static void +static char * trimlr(char **buf) { char *walk = *buf; + char *sep; char *last; while (isspace(*walk)) walk++; - if (*walk != '\0') { - last = walk + strlen(walk) - 1; + *buf = walk; + + sep = walk; + while (*sep != '\0' && !isspace(*sep)) + sep++; + + if (*sep != '\0') { + last = sep + strlen(sep) - 1; while (last > walk && isspace(*last)) last--; *(last+1) = 0; } - *buf = walk; + return (sep); } static FILE * -@@ -116,7 +127,7 @@ cal_fopen(const char *file) +@@ -116,7 +126,7 @@ cal_fopen(const char *file) } if (chdir(home) != 0) { - warnx("Cannot enter home directory"); + warnx("Cannot enter home directory \"%s\"", home); return (NULL); } -@@ -124,8 +135,12 @@ cal_fopen(const char *file) +@@ -124,8 +134,12 @@ cal_fopen(const char *file) if (chdir(calendarHomes[i]) != 0) continue; - if ((fp = fopen(file, "r")) != NULL) + if ((fp = fopen(file, "r")) != NULL) { + cal_home = home; + cal_dir = calendarHomes[i]; + cal_file = file; return (fp); + } } warnx("can't open calendar file \"%s\"", file); -@@ -133,60 +148,154 @@ cal_fopen(const char *file) +@@ -133,96 +147,236 @@ cal_fopen(const char *file) return (NULL); } +static char* +cal_path(void) +{ + static char buffer[MAXPATHLEN + 10]; + -+ if (cal_dir[0] == '/') ++ if (cal_dir == NULL) ++ snprintf(buffer, sizeof(buffer), "%s", cal_file); ++ else if (cal_dir[0] == '/') + snprintf(buffer, sizeof(buffer), "%s/%s", cal_dir, cal_file); + else + snprintf(buffer, sizeof(buffer), "%s/%s/%s", cal_home, cal_dir, cal_file); + return (buffer); +} + +#define WARN0(format) \ + warnx(format " in %s line %d", cal_path(), cal_line) +#define WARN1(format, arg1) \ + warnx(format " in %s line %d", arg1, cal_path(), cal_line) + ++static char* ++cmptoken(char *line, const char* token) ++{ ++ char len = strlen(token); ++ ++ if (strncmp(line, token, len) != 0) ++ return NULL; ++ return (line + len); ++} ++ static int -token(char *line, FILE *out, bool *skip) +token(char *line, FILE *out, int *skip, int *unskip) { - char *walk, c, a; + char *walk, *sep, a, c; + const char *this_cal_home; + const char *this_cal_dir; + const char *this_cal_file; + int this_cal_line; - if (strncmp(line, "endif", 5) == 0) { +- if (strncmp(line, "endif", 5) == 0) { - *skip = false; -+ if (*skip > 0) -+ --*skip; -+ else if (*unskip > 0) -+ --*unskip; -+ else { ++ while (isspace(*line)) ++ line++; ++ ++ if (cmptoken(line, "endif")) { ++ if (*skip + *unskip == 0) { + WARN0("#endif without prior #ifdef or #ifndef"); + return (T_ERR); + } ++ if (*skip > 0) ++ --*skip; ++ else ++ --*unskip; + return (T_OK); } - if (*skip) -+ if (strncmp(line, "ifdef", 5) == 0) { -+ walk = line + 5; ++ walk = cmptoken(line, "ifdef"); ++ if (walk != NULL) { + sep = trimlr(&walk); + + if (*walk == '\0') { + WARN0("Expecting arguments after #ifdef"); + return (T_ERR); + } + if (*sep != '\0') { + WARN1("Expecting a single word after #ifdef " + "but got \"%s\"", walk); + return (T_ERR); + } + + if (*skip != 0 || + definitions == NULL || sl_find(definitions, walk) == NULL) + ++*skip; + else + ++*unskip; + return (T_OK); + } -+ if (strncmp(line, "ifndef", 6) == 0) { -+ walk = line + 6; +- if (strncmp(line, "include", 7) == 0) { +- walk = line + 7; ++ walk = cmptoken(line, "ifndef"); ++ if (walk != NULL) { + sep = trimlr(&walk); -+ + +- trimlr(&walk); + if (*walk == '\0') { + WARN0("Expecting arguments after #ifndef"); + return (T_ERR); + } + if (*sep != '\0') { + WARN1("Expecting a single word after #ifndef " + "but got \"%s\"", walk); + return (T_ERR); + } -+ + + if (*skip != 0 || + (definitions != NULL && sl_find(definitions, walk) != NULL)) + ++*skip; + else + ++*unskip; + + return (T_OK); + } + -+ if (strncmp(line, "else", 4) == 0) { -+ walk = line + 4; ++ walk = cmptoken(line, "else"); ++ if (walk != NULL) { + (void)trimlr(&walk); + + if (*walk != '\0') { + WARN0("Expecting no arguments after #else"); + return (T_ERR); + } ++ if (*skip + *unskip == 0) { ++ WARN0("#else without prior #ifdef or #ifndef"); ++ return (T_ERR); ++ } + -+ if (*unskip == 0) { -+ if (*skip == 0) { -+ WARN0("#else without prior #ifdef or #ifndef"); -+ return (T_ERR); -+ } else if (*skip == 1) { -+ *skip = 0; -+ *unskip = 1; -+ } -+ } else if (*unskip == 1) { -+ *skip = 1; -+ *unskip = 0; ++ if (*skip == 0) { ++ ++*skip; ++ --*unskip; ++ } else if (*skip == 1) { ++ --*skip; ++ ++*unskip; + } + + return (T_OK); + } + + if (*skip != 0) + return (T_OK); + - if (strncmp(line, "include", 7) == 0) { - walk = line + 7; - -- trimlr(&walk); ++ walk = cmptoken(line, "include"); ++ if (walk != NULL) { + (void)trimlr(&walk); - ++ if (*walk == '\0') { - warnx("Expecting arguments after #include"); + WARN0("Expecting arguments after #include"); return (T_ERR); } if (*walk != '<' && *walk != '\"') { - warnx("Excecting '<' or '\"' after #include"); + WARN0("Excecting '<' or '\"' after #include"); return (T_ERR); } - a = *walk; + a = *walk == '<' ? '>' : '\"'; walk++; c = walk[strlen(walk) - 1]; - switch(c) { - case '>': - if (a != '<') { - warnx("Unterminated include expecting '\"'"); - return (T_ERR); - } - break; - case '\"': - if (a != '\"') { - warnx("Unterminated include expecting '>'"); - return (T_ERR); - } - break; - default: - warnx("Unterminated include expecting '%c'", - a == '<' ? '>' : '\"' ); + if (a != c) { + WARN1("Unterminated include expecting '%c'", a); return (T_ERR); } walk[strlen(walk) - 1] = '\0'; + this_cal_home = cal_home; + this_cal_dir = cal_dir; + this_cal_file = cal_file; + this_cal_line = cal_line; if (cal_parse(cal_fopen(walk), out)) return (T_ERR); + cal_home = this_cal_home; + cal_dir = this_cal_dir; + cal_file = this_cal_file; + cal_line = this_cal_line; return (T_OK); } -@@ -195,29 +304,38 @@ token(char *line, FILE *out, bool *skip) + +- if (strncmp(line, "define", 6) == 0) { ++ walk = cmptoken(line, "define"); ++ if (walk != NULL) { if (definitions == NULL) definitions = sl_init(); - walk = line + 6; +- walk = line + 6; - trimlr(&walk); + sep = trimlr(&walk); + *sep = '\0'; if (*walk == '\0') { - warnx("Expecting arguments after #define"); + WARN0("Expecting arguments after #define"); return (T_ERR); } - sl_add(definitions, strdup(walk)); + if (sl_find(definitions, walk) == NULL) + sl_add(definitions, strdup(walk)); return (T_OK); } - if (strncmp(line, "ifndef", 6) == 0) { - walk = line + 6; - trimlr(&walk); -+ if (strncmp(line, "undef", 5) == 0) { ++ walk = cmptoken(line, "undef"); ++ if (walk != NULL) { + if (definitions != NULL) { -+ walk = line + 5; + sep = trimlr(&walk); - if (*walk == '\0') { - warnx("Expecting arguments after #ifndef"); - return (T_ERR); -- } + if (*walk == '\0') { + WARN0("Expecting arguments after #undef"); + return (T_ERR); + } + if (*sep != '\0') { + WARN1("Expecting a single word after #undef " + "but got \"%s\"", walk); + return (T_ERR); + } - -- if (definitions != NULL && sl_find(definitions, walk) != NULL) -- *skip = true; -- ++ + walk = sl_find(definitions, walk); + if (walk != NULL) + walk[0] = '\0'; -+ } - return (T_OK); + } ++ return (T_OK); ++ } + +- if (definitions != NULL && sl_find(definitions, walk) != NULL) +- *skip = true; ++ walk = cmptoken(line, "warning"); ++ if (walk != NULL) { ++ (void)trimlr(&walk); ++ WARN1("Warning: %s", walk); ++ } + +- return (T_OK); ++ walk = cmptoken(line, "error"); ++ if (walk != NULL) { ++ (void)trimlr(&walk); ++ WARN1("Error: %s", walk); ++ return (T_ERR); } -@@ -248,11 +366,14 @@ cal_parse(FILE *in, FILE *out) +- return (T_PROCESS); ++ WARN1("Undefined pre-processor command \"#%s\"", line); ++ return (T_ERR); ++} + ++static void ++setup_locale(const char *locale) ++{ ++ (void)setlocale(LC_ALL, locale); ++#ifdef WITH_ICONV ++ if (!doall) ++ set_new_encoding(); ++#endif ++ setnnames(); + } + + #define REPLACE(string, slen, struct_) \ +@@ -237,35 +391,82 @@ token(char *line, FILE *out, bool *skip) + static int + cal_parse(FILE *in, FILE *out) + { ++ char *mylocale = NULL; + char *line = NULL; + char *buf; + size_t linecap = 0; + ssize_t linelen; + ssize_t l; +- static int d_first = -1; + static int count = 0; + int i; int month[MAXCOUNT]; int day[MAXCOUNT]; int year[MAXCOUNT]; - bool skip = false; +- char dbuf[80]; + int skip = 0; + int unskip = 0; - char dbuf[80]; char *pp, p; - struct tm tm; +- struct tm tm; int flags; + char *c, *cc; + bool incomment = false; - /* Unused */ - tm.tm_sec = 0; -@@ -263,9 +384,61 @@ cal_parse(FILE *in, FILE *out) +- /* Unused */ +- tm.tm_sec = 0; +- tm.tm_min = 0; +- tm.tm_hour = 0; +- tm.tm_wday = 0; +- if (in == NULL) return (1); + cal_line = 0; while ((linelen = getline(&line, &linecap, in)) > 0) { - if (*line == '#') { - switch (token(line+1, out, &skip)) { + cal_line++; + buf = line; + if (buf[linelen - 1] == '\n') + buf[--linelen] = '\0'; + + if (incomment) { + c = strstr(buf, "*/"); + if (c) { + c += 2; + linelen -= c - buf; + buf = c; + incomment = false; + } else { + continue; + } + } + if (!incomment) { + do { + c = strstr(buf, "//"); + cc = strstr(buf, "/*"); + if (c != NULL && (cc == NULL || c - cc < 0)) { + /* single line comment */ + *c = '\0'; + linelen = c - buf; + break; + } else if (cc != NULL) { + c = strstr(cc + 2, "*/"); + if (c != NULL) { + /* multi-line comment ending on same line */ + c += 2; + memmove(cc, c, buf + linelen + 1 - c); + linelen -= c - cc; + } else { + /* multi-line comment */ + *cc = '\0'; + linelen = cc - buf; + incomment = true; + break; + } + } + } while (c != NULL || cc != NULL); + } + + for (l = linelen; + l > 0 && isspace((unsigned char)buf[l - 1]); + l--) + ; + buf[l] = '\0'; + if (buf[0] == '\0') + continue; + + if (buf == line && *buf == '#') { + switch (token(buf+1, out, &skip, &unskip)) { case T_ERR: free(line); return (1); -@@ -278,18 +451,9 @@ cal_parse(FILE *in, FILE *out) +@@ -278,18 +479,9 @@ cal_parse(FILE *in, FILE *out) } } - if (skip) + if (skip != 0) continue; - buf = line; - for (l = linelen; - l > 0 && isspace((unsigned char)buf[l - 1]); - l--) - ; - buf[l] = '\0'; - if (buf[0] == '\0') - continue; - /* * Setting LANG in user's calendar was an old workaround * for 'calendar -a' being run with C locale to properly -@@ -298,8 +462,7 @@ cal_parse(FILE *in, FILE *out) +@@ -298,13 +490,9 @@ cal_parse(FILE *in, FILE *out) * and does not run iconv(), this variable has little use. */ if (strncmp(buf, "LANG=", 5) == 0) { - (void)setlocale(LC_ALL, buf + 5); - d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); -+ (void)setlocale(LC_CTYPE, buf + 5); - #ifdef WITH_ICONV - if (!doall) - set_new_encoding(); -@@ -353,7 +516,7 @@ cal_parse(FILE *in, FILE *out) +-#ifdef WITH_ICONV +- if (!doall) +- set_new_encoding(); +-#endif +- setnnames(); ++ if (mylocale == NULL) ++ mylocale = strdup(setlocale(LC_ALL, NULL)); ++ setup_locale(buf + 5); + continue; + } + /* Parse special definitions: Easter, Paskha etc */ +@@ -353,7 +541,7 @@ cal_parse(FILE *in, FILE *out) if (count < 0) { /* Show error status based on return value */ if (debug) - fprintf(stderr, "Ignored: %s\n", buf); + WARN1("Ignored: \"%s\"", buf); if (count == -1) continue; count = -count + 1; -@@ -373,11 +536,15 @@ cal_parse(FILE *in, FILE *out) - (void)strftime(dbuf, sizeof(dbuf), - d_first ? "%e %b" : "%b %e", &tm); +@@ -363,25 +551,25 @@ cal_parse(FILE *in, FILE *out) + while (pp[1] == '\t') + pp++; + +- if (d_first < 0) +- d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); +- + for (i = 0; i < count; i++) { +- tm.tm_mon = month[i] - 1; +- tm.tm_mday = day[i]; +- tm.tm_year = year[i] - 1900; +- (void)strftime(dbuf, sizeof(dbuf), +- d_first ? "%e %b" : "%b %e", &tm); if (debug) - fprintf(stderr, "got %s\n", pp); +- events[i] = event_add(year[i], month[i], day[i], dbuf, + WARN1("got \"%s\"", pp); - events[i] = event_add(year[i], month[i], day[i], dbuf, ++ events[i] = event_add(year[i], month[i], day[i], ((flags &= F_VARIABLE) != 0) ? 1 : 0, pp, extradata[i]); } -+ } + } + while (skip-- > 0 || unskip-- > 0) { + cal_line++; + WARN0("Missing #endif assumed"); - } ++ } free(line); + fclose(in); ++ if (mylocale != NULL) { ++ setup_locale(mylocale); ++ free(mylocale); ++ } + + return (0); + } +@@ -419,6 +607,7 @@ opencalin(void) + FILE *fpin; + + /* open up calendar file */ ++ cal_file = calendarFile; + if ((fpin = fopen(calendarFile, "r")) == NULL) { + if (doall) { + if (chdir(calendarHomes[0]) != 0) Index: head/deskutils/calendar/files/patch-parsedata.c =================================================================== --- head/deskutils/calendar/files/patch-parsedata.c (nonexistent) +++ head/deskutils/calendar/files/patch-parsedata.c (revision 554325) @@ -0,0 +1,23 @@ +--- parsedata.c.orig 2020-10-18 03:01:26 UTC ++++ parsedata.c +@@ -28,7 +28,7 @@ + */ + + #include +-__FBSDID("$FreeBSD$"); ++__FBSDID("$FreeBSD: head/usr.bin/calendar/parsedata.c 367203 2020-10-31 13:32:08Z se $"); + + #include + #include +@@ -312,10 +312,7 @@ allfine: + + } + +-void +-remember(int *rememberindex, int *y, int *m, int *d, char **ed, int yy, int mm, +- int dd, char *extra); +-void ++static void + remember(int *rememberindex, int *y, int *m, int *d, char **ed, int yy, int mm, + int dd, char *extra) + { Property changes on: head/deskutils/calendar/files/patch-parsedata.c ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/deskutils/calendar/files/patch-tests_Makefile =================================================================== --- head/deskutils/calendar/files/patch-tests_Makefile (nonexistent) +++ head/deskutils/calendar/files/patch-tests_Makefile (revision 554325) @@ -0,0 +1,21 @@ +--- tests/Makefile.orig 2020-10-18 03:01:26 UTC ++++ tests/Makefile +@@ -2,9 +2,17 @@ + + PACKAGE= tests + +-TAP_TESTS_SH= legacy_test ++TAP_TESTS_SH= comment_test cond_test legacy_test + ++TEST_METADATA.comment_test+= timeout="600" ++TEST_METADATA.cond_test+= timeout="600" + TEST_METADATA.legacy_test+= timeout="600" ++ ++${PACKAGE}FILES+= calendar.comment ++${PACKAGE}FILES+= regress.comment.out ++ ++${PACKAGE}FILES+= calendar.cond ++${PACKAGE}FILES+= regress.cond.out + + ${PACKAGE}FILES+= calendar.calibrate + ${PACKAGE}FILES+= regress.a1.out Property changes on: head/deskutils/calendar/files/patch-tests_Makefile ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property