[hackers] [scc] [cc1] Fix comments across several files || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 22 Jun 2016 09:09:36 +0200 (CEST)

commit 60560f4989f5e451ab2d1ad96bc6ebcab6337017
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Jun 22 09:07:00 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Jun 22 09:07:00 2016 +0200

    [cc1] Fix comments across several files
    
    If a comment finishes before of the end of its file then
    we have to continue from the previous file, and give
    a message error when we arrive to the end of the base
    file.

diff --git a/cc1/lex.c b/cc1/lex.c
index 84b691e..6f89352 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -127,13 +127,15 @@ newline(void)
                 die("error: input file '%s' too long", input->fname);
 }
 
-static char
+static int
 readchar(void)
 {
         int c;
         FILE *fp;
 
 repeat:
+ if (eof)
+ return 0;
         fp = input->fp;
 
         switch (c = getc(fp)) {
_AT_@ -157,21 +159,24 @@ repeat:
 }
 
 static void
-comment(char type)
+comment(int type)
 {
- if (type == '*') {
- while (!eof) {
- while (readchar() != '*' && !eof)
- /* nothing */;
- if (readchar() == '/')
- break;
- }
- } else {
- while (readchar() != '\n' && !eof)
- /* nothing */;
+ int c;
+
+ c = -1;
+repeat:
+ do {
+ if (!c)
+ delinput();
+ } while (!eof && (c = readchar()) != type);
+
+ if (eof) {
+ errorp("unterminated comment");
+ return;
         }
- if (eof)
- error("unterminated comment");
+
+ if (type == '*' && (c = readchar()) != '/')
+ goto repeat;
 }
 
 static int
_AT_@ -201,6 +206,8 @@ repeat:
                         peekc = c;
                         c = '/';
                 } else {
+ if (c == '/')
+ c = '\n';
                         comment(c);
                         c = ' ';
                 }
diff --git a/cc1/tests/test063.c b/cc1/tests/test063.c
new file mode 100644
index 0000000..b4d7f28
--- /dev/null
+++ b/cc1/tests/test063.c
_AT_@ -0,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+
+/*
+name: TEST063
+description: Test a comment that goes beyond of the end of an included file
+error:
+test063.c:12: error: unterminated comment
+test063.c:12: error: #endif expected
+output:
+*/
+
+#include "test063.h"
diff --git a/cc1/tests/test063.h b/cc1/tests/test063.h
new file mode 100644
index 0000000..3ec5025
--- /dev/null
+++ b/cc1/tests/test063.h
_AT_@ -0,0 +1,9 @@
+
+#ifndef TEST_H_
+#define TEST_H_
+
+/*
+ This is an unterminated comment.
+
+
+#endif
Received on Wed Jun 22 2016 - 09:09:36 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 22 2016 - 09:12:16 CEST