Index: head/deskutils/calendar/Makefile =================================================================== --- head/deskutils/calendar/Makefile (revision 553858) +++ head/deskutils/calendar/Makefile (revision 553859) @@ -1,31 +1,31 @@ # $FreeBSD$ PORTNAME= calendar -DISTVERSION= 0.7.1 +DISTVERSION= 0.7.2 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 553858) +++ head/deskutils/calendar/distinfo (revision 553859) @@ -1,3 +1,3 @@ -TIMESTAMP = 1604223089 -SHA256 (bsdimp-calendar-0.7.1-fcc5d31_GH0.tar.gz) = ad7d0b51c4b834241aebbf6c50d187e5720f6c46c02615b27841a923e082aebc -SIZE (bsdimp-calendar-0.7.1-fcc5d31_GH0.tar.gz) = 132824 +TIMESTAMP = 1604263248 +SHA256 (bsdimp-calendar-0.7.2-fcc5d31_GH0.tar.gz) = ad7d0b51c4b834241aebbf6c50d187e5720f6c46c02615b27841a923e082aebc +SIZE (bsdimp-calendar-0.7.2-fcc5d31_GH0.tar.gz) = 132824 Index: head/deskutils/calendar/files/patch-io.c =================================================================== --- head/deskutils/calendar/files/patch-io.c (revision 553858) +++ head/deskutils/calendar/files/patch-io.c (revision 553859) @@ -1,362 +1,374 @@ --- io.c.orig 2020-10-18 03:01:26 UTC +++ io.c @@ -71,10 +71,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; @@ -116,7 +120,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 +128,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 +141,130 @@ cal_fopen(const char *file) +@@ -133,60 +141,142 @@ cal_fopen(const char *file) return (NULL); } ++static char* ++cal_path(void) ++{ ++ static char buffer[MAXPATHLEN + 10]; ++ ++ 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/%s/%s line %d", cal_home, cal_dir, cal_file, cal_line) ++ warnx(format " in %s line %d", cal_path(), cal_line) +#define WARN1(format, arg1) \ -+ warnx(format " in %s/%s/%s line %d", arg1, cal_home, cal_dir, cal_file, cal_line) ++ warnx(format " in %s line %d", arg1, cal_path(), cal_line) + static int -token(char *line, FILE *out, bool *skip) +token(char *line, FILE *out, int *skip, int *unskip) { char *walk, c, a; + 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) { - *skip = false; + if (*skip > 0) + --*skip; + else if (*unskip > 0) + --*unskip; + else { + WARN0("#endif without prior #ifdef or #ifndef"); + return (T_ERR); + } + return (T_OK); } - if (*skip) + if (strncmp(line, "ifdef", 5) == 0) { + walk = line + 5; + trimlr(&walk); + + if (*walk == '\0') { + WARN0("Expecting arguments after #ifdef"); + 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; + trimlr(&walk); + + if (*walk == '\0') { + WARN0("Expecting arguments after #ifndef"); + 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; + trimlr(&walk); + + if (*walk != '\0') { + WARN0("Expecting no arguments after #else"); + 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; + } + + return (T_OK); + } + + if (*skip != 0) + return (T_OK); + if (strncmp(line, "include", 7) == 0) { walk = line + 7; 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); } -@@ -198,26 +276,29 @@ token(char *line, FILE *out, bool *skip) +@@ -198,26 +288,29 @@ token(char *line, FILE *out, bool *skip) trimlr(&walk); 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) { + if (definitions != NULL) { + walk = line + 5; + 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 (definitions != NULL && sl_find(definitions, walk) != NULL) - *skip = true; - + walk = sl_find(definitions, walk); + if (walk != NULL) + walk[0] = '\0'; + } return (T_OK); } -@@ -248,11 +329,14 @@ cal_parse(FILE *in, FILE *out) +@@ -248,11 +341,14 @@ cal_parse(FILE *in, FILE *out) int month[MAXCOUNT]; int day[MAXCOUNT]; int year[MAXCOUNT]; - bool skip = false; + int skip = 0; + int unskip = 0; char dbuf[80]; char *pp, p; struct tm tm; int flags; + char *c, *cc; + bool incomment = false; /* Unused */ tm.tm_sec = 0; -@@ -263,9 +347,61 @@ cal_parse(FILE *in, FILE *out) +@@ -263,9 +359,61 @@ cal_parse(FILE *in, FILE *out) 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 +414,9 @@ cal_parse(FILE *in, FILE *out) +@@ -278,18 +426,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 -@@ -353,7 +480,7 @@ cal_parse(FILE *in, FILE *out) +@@ -353,7 +492,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 +500,15 @@ cal_parse(FILE *in, FILE *out) +@@ -373,11 +512,15 @@ cal_parse(FILE *in, FILE *out) (void)strftime(dbuf, sizeof(dbuf), d_first ? "%e %b" : "%b %e", &tm); if (debug) - fprintf(stderr, "got %s\n", pp); + WARN1("got \"%s\"", pp); events[i] = event_add(year[i], month[i], day[i], dbuf, ((flags &= F_VARIABLE) != 0) ? 1 : 0, pp, extradata[i]); } + } + while (skip-- > 0 || unskip-- > 0) { + cal_line++; + WARN0("Missing #endif assumed"); } free(line); Index: head/deskutils/calendar/files/patch-pathnames.h =================================================================== --- head/deskutils/calendar/files/patch-pathnames.h (revision 553858) +++ head/deskutils/calendar/files/patch-pathnames.h (revision 553859) @@ -1,8 +1,7 @@ --- pathnames.h.orig 2020-10-18 03:01:26 UTC +++ pathnames.h -@@ -34,4 +34,5 @@ - +@@ -35,3 +35,4 @@ #include #define _PATH_INCLUDE "/usr/share/calendar" +#define _PATH_INCLUDE_LOCAL _PATH_LOCALBASE "/share/calendar"