]> xenbits.xensource.com Git - people/royger/freebsd.git/commitdiff
usr.bin/calendar: do not treat // in text as comment
authorStefan Eßer <se@FreeBSD.org>
Mon, 7 Jun 2021 13:46:24 +0000 (15:46 +0200)
committerStefan Eßer <se@FreeBSD.org>
Fri, 4 Mar 2022 19:41:02 +0000 (20:41 +0100)
The C++-style comment marker "//" has been added with the rewrite of
the preprocessor features. Since this character sequence occurs in
ULRS, the reminder of the URL was considered a comment and stripped
from the calendar line.

Change parsing of "//" to only start a comment at the begin of a line
or when preceeded by a white-space character.

(cherry picked from commit 35b8fd0b699a20f71d5636069347b243eb336979)

usr.bin/calendar/io.c
usr.bin/calendar/tests/calendar.comment
usr.bin/calendar/tests/regress.comment.out

index 24966399c179688319785cc0f18a84c5dbcaf5e1..5afcb1a3331454cfb93140839192c8c87ea8f71e 100644 (file)
@@ -405,7 +405,7 @@ cal_parse(FILE *in, FILE *out)
 {
        char *mylocale = NULL;
        char *line = NULL;
-       char *buf;
+       char *buf, *bufp;
        size_t linecap = 0;
        ssize_t linelen;
        ssize_t l;
@@ -443,21 +443,27 @@ cal_parse(FILE *in, FILE *out)
                        }
                }
                if (!incomment) {
+                       bufp = buf;
                        do {
-                               c = strstr(buf, "//");
-                               cc = strstr(buf, "/*");
+                               c = strstr(bufp, "//");
+                               cc = strstr(bufp, "/*");
                                if (c != NULL && (cc == NULL || c - cc < 0)) {
-                                       /* single line comment */
-                                       *c = '\0';
-                                       linelen = c - buf;
-                                       break;
+                                       bufp = c + 2;
+                                       /* ignore "//" within string to allow it in an URL */
+                                       if (c == buf || isspace(c[-1])) {
+                                               /* single line comment */
+                                               *c = '\0';
+                                               linelen = c - buf;
+                                               break;
+                                       }
                                } else if (cc != NULL) {
                                        c = strstr(cc + 2, "*/");
-                                       if (c != NULL) {
+                                       if (c != NULL) { // 'a /* b */ c' -- cc=2, c=7+2
                                                /* multi-line comment ending on same line */
                                                c += 2;
                                                memmove(cc, c, buf + linelen + 1 - c);
                                                linelen -= c - cc;
+                                               bufp = cc;
                                        } else {
                                                /* multi-line comment */
                                                *cc = '\0';
index 6af037ec7e9d8f880be1c0c5fe877283bf76b7fd..837e5af9e89e3485b1cc117e858c1758cd12163c 100644 (file)
@@ -7,4 +7,5 @@
 1/* comment */ 6       jan 6
 1 7    jan 7 // /* comment */ comment
 1 1/* comment */1      jan /* comment */11 // comment
-
+1 12   http://localhost.local/
+1 13   http://localhost.local/ // URL with additional comment
index 1ba3d8cc640ef5a0d49e07ec3fb89e375c7838b7..fb58fd29ff05659640d897160653f8a1b81a24d2 100644 (file)
@@ -6,3 +6,5 @@ Jan  5  jan 5
 Jan  6         jan 6
 Jan  7         jan 7
 Jan 11         jan 11
+Jan 12         http://localhost.local/
+Jan 13         http://localhost.local/