[hackers] [scc] Add cpperror() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 11 Aug 2015 22:04:26 +0200 (CEST)

commit 38e6f6b3509088e152f21f77b97f75ba5a4309ed
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 11 22:02:15 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Aug 11 22:02:15 2015 +0200

    Add cpperror()
    
    This function is like printerr(), but it also discards the
    rest of the line, and calls to next() to obtain a EOF in yytoken.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 17c23ac..c13b9b0 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -291,6 +291,7 @@ extern void error(char *fmt, ...);
 extern void warn(char *fmt, ...);
 extern void unexpected(void);
 extern void printerr(char *fmt, ...);
+extern void cpperror(char *fmt, ...);
 
 /* types.c */
 extern bool eqtype(Type *tp1, Type *tp2);
diff --git a/cc1/cpp.c b/cc1/cpp.c
index d864fe9..d3856b2 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -244,11 +244,11 @@ getpars(Symbol *args[NR_MACROARG])
 
         do {
                 if (n == NR_MACROARG) {
- printerr("too much parameters in macro");
+ cpperror("too much parameters in macro");
                         return NR_MACROARG;
                 }
                 if (yytoken != IDEN) {
- printerr("macro arguments must be identifiers");
+ cpperror("macro arguments must be identifiers");
                         return NR_MACROARG;
                 }
                 args[n++] = yylval.sym;
_AT_@ -279,14 +279,14 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *bp, size_t bufsiz)
                         }
                 }
                 if (prevc == '#' && !ispar) {
- printerr("'#' is not followed by a macro parameter");
+ cpperror("'#' is not followed by a macro parameter");
                         return 0;
                 }
                 if (yytoken == EOFTOK)
                         break;
 
                 if ((len = strlen(yytext)) >= bufsiz) {
- printerr("too long macro");
+ cpperror("too long macro");
                         return 0;
                 }
                 memcpy(bp, yytext, len);
_AT_@ -391,15 +391,15 @@ include(void)
         }
 
         if (*bp)
- printerr("included file '%s' not found", file);
+ cpperror("included file '%s' not found", file);
 
         return;
 
 bad_include:
- printerr("#include expects \"FILENAME\" or <FILENAME>");
+ cpperror("#include expects \"FILENAME\" or <FILENAME>");
         return;
 too_long:
- printerr("#include FILENAME too long");
+ cpperror("#include FILENAME too long");
         return;
 }
 
_AT_@ -412,11 +412,10 @@ line(void)
         if (cppoff)
                 return;
 
- setnamespace(NS_IDEN);
         next();
         n = strtol(yytext, &endp, 10);
         if (n <= 0 || n > USHRT_MAX || *endp != '\0') {
- printerr("first parameter of #line is not a positive integer");
+ cpperror("first parameter of #line is not a positive integer");
                 return;
         }
 
_AT_@ -425,7 +424,7 @@ line(void)
                 goto set_line;
 
         if (*yytext != '\"' || yylen == 1) {
- printerr("second parameter of #line is not a valid filename");
+ cpperror("second parameter of #line is not a valid filename");
                 return;
         }
 
_AT_@ -434,7 +433,7 @@ line(void)
         next();
 
 set_line:
- input->nline = yylval.sym->u.i;
+ input->nline = n;
 }
 
 static void
_AT_@ -451,7 +450,7 @@ usererr(void)
 {
         if (cppoff)
                 return;
- printerr("#error %s", input->p);
+ cpperror("#error %s", input->p);
         *input->p = '\0';
         next();
 }
_AT_@ -470,7 +469,7 @@ ifclause(int negate, int isifdef)
 
         if (isifdef) {
                 if (yytoken != IDEN) {
- printerr("no macro name given in #%s directive",
+ cpperror("no macro name given in #%s directive",
                                  (negate) ? "ifndef" : "ifdef");
                         return;
                 }
_AT_@ -482,7 +481,7 @@ ifclause(int negate, int isifdef)
         } else {
                 /* TODO: catch recovery here */
                 if ((expr = iconstexpr()) == NULL) {
- printerr("parameter of #if is not an integer constant expression");
+ cpperror("parameter of #if is not an integer constant expression");
                         return;
                 }
                 status = expr->sym->u.i != 0;
diff --git a/cc1/error.c b/cc1/error.c
index 9c6c7ea..6bbb4e5 100644
--- a/cc1/error.c
+++ b/cc1/error.c
_AT_@ -13,7 +13,7 @@ extern int failure;
 static unsigned nerrors;
 
 static void
-warn_helper(int flag, char *fmt, va_list va)
+warn_error(int flag, char *fmt, va_list va)
 {
         if (flag == 0)
                 return;
_AT_@ -39,7 +39,7 @@ warn(char *fmt, ...)
 
         va_list va;
         va_start(va, fmt);
- warn_helper(warnings, fmt, va);
+ warn_error(warnings, fmt, va);
         va_end(va);
 }
 
_AT_@ -49,7 +49,7 @@ error(char *fmt, ...)
         va_list va;
 
         va_start(va, fmt);
- warn_helper(-1, fmt, va);
+ warn_error(-1, fmt, va);
         va_end(va);
         exit(1);
         discard();
_AT_@ -60,11 +60,24 @@ printerr(char *fmt, ...)
 {
         va_list va;
         va_start(va, fmt);
- warn_helper(-1, fmt, va);
+ warn_error(-1, fmt, va);
         va_end(va);
 }
 
 void
+cpperror(char *fmt, ...)
+{
+ va_list va;
+ va_start(va, fmt);
+ warn_error(-1, fmt, va);
+ va_end(va);
+
+ /* discard input until the end of the line */
+ *input->p = '\0';
+ next();
+}
+
+void
 unexpected(void)
 {
         error("unexpected '%s'", yytext);
Received on Tue Aug 11 2015 - 22:04:26 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 11 2015 - 22:12:13 CEST