From owner-svn-src-head@freebsd.org Fri Oct 30 10:44:47 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6C13744E9A4; Fri, 30 Oct 2020 10:44:47 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CMzTW2G8Gz3Yr3; Fri, 30 Oct 2020 10:44:47 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 16BEE150F0; Fri, 30 Oct 2020 10:44:47 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09UAikvg037002; Fri, 30 Oct 2020 10:44:46 GMT (envelope-from se@FreeBSD.org) Received: (from se@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09UAikd8037001; Fri, 30 Oct 2020 10:44:46 GMT (envelope-from se@FreeBSD.org) Message-Id: <202010301044.09UAikd8037001@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: se set sender to se@FreeBSD.org using -f From: =?UTF-8?Q?Stefan_E=c3=9fer?= Date: Fri, 30 Oct 2020 10:44:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367161 - head/usr.bin/calendar X-SVN-Group: head X-SVN-Commit-Author: se X-SVN-Commit-Paths: head/usr.bin/calendar X-SVN-Commit-Revision: 367161 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Oct 2020 10:44:47 -0000 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@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; /*