svn commit: r367161 - head/usr.bin/calendar
Stefan Eßer
se at FreeBSD.org
Fri Oct 30 10:44:47 UTC 2020
Author: se
Date: Fri Oct 30 10:44:46 2020
New Revision: 367161
URL: https://svnweb.freebsd.org/changeset/base/367161
Log:
Re-implement comment parsing missing in the internal pre-processor
The internal pre-processor ignored lines that did not parse a calendar
entries, but did not support multi-line comments in the way the external
cpp did.
The calendar files distributed with the base system (now in a port) do
use comments, though.
Implement comment processing for single-line (//) and multi-line comments
(/* */) with same semantics as in a standard C pre-processor.
All tests pass with this version, but there are no tests that specifically
verify comment processing.
Reported by: jhs at berklix.com (Julian H. Stacey)
MFC after: 3 days
Modified:
head/usr.bin/calendar/io.c
Modified: head/usr.bin/calendar/io.c
==============================================================================
--- head/usr.bin/calendar/io.c Fri Oct 30 09:48:41 2020 (r367160)
+++ head/usr.bin/calendar/io.c Fri Oct 30 10:44:46 2020 (r367161)
@@ -278,6 +278,8 @@ cal_parse(FILE *in, FILE *out)
char *pp, p;
struct tm tm;
int flags;
+ char *c, *cc;
+ bool incomment = false;
/* Unused */
tm.tm_sec = 0;
@@ -289,8 +291,55 @@ cal_parse(FILE *in, FILE *out)
return (1);
while ((linelen = getline(&line, &linecap, in)) > 0) {
- if (*line == '#') {
- switch (token(line+1, out, &skip)) {
+ 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)) {
+ *c = '\0';
+ linelen = c - buf;
+ break;
+ } else if (cc != NULL) {
+ c = strstr(cc + 2, "*/");
+ if (c != NULL) {
+ c += 2;
+ memmove(cc, c, c - buf + linelen);
+ linelen -= c - cc;
+ } else {
+ *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)) {
case T_ERR:
free(line);
return (1);
@@ -304,15 +353,6 @@ cal_parse(FILE *in, FILE *out)
}
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;
/*
More information about the svn-src-head
mailing list