From 754f9ce45deb20c9bc780ccb7ac79993e0352d2d Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 20 Aug 1987 18:12:31 +0000 Subject: [PATCH] fixed a problem with the ifdef-stack --- util/cpp/domacro.c | 12 ++++++++---- util/cpp/file_info.h | 2 -- util/cpp/input.c | 6 +++++- util/cpp/main.c | 1 - 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/util/cpp/domacro.c b/util/cpp/domacro.c index 665233e2f..aa8cd716f 100644 --- a/util/cpp/domacro.c +++ b/util/cpp/domacro.c @@ -30,6 +30,10 @@ PRIVATE char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ /* 1 if a corresponding ELSE has been */ /* encountered. */ +int nestlevel = -1; +int svnestlevel[30] = {-1}; +int nestcount; + PRIVATE char * GetIdentifier() { @@ -261,7 +265,7 @@ do_include() } else { WorkingDir = getwdir(result); - nestlevel = -1; + svnestlevel[++nestcount] = nestlevel; FileName = result; LineNumber = 1; } @@ -331,7 +335,7 @@ push_if() PRIVATE do_elif() { - if (nestlevel < 0 || (ifstack[nestlevel])) { + if (nestlevel <= svnestlevel[nestcount] || (ifstack[nestlevel])) { error("#elif without corresponding #if"); PushBack(); skipline(); @@ -348,7 +352,7 @@ do_else() { PushBack(); skipline(); - if (nestlevel < 0 || (ifstack[nestlevel])) + if (nestlevel <= svnestlevel[nestcount] || (ifstack[nestlevel])) error("#else without corresponding #if"); else { /* mark this level as else-d */ ++(ifstack[nestlevel]); @@ -361,7 +365,7 @@ do_endif() { PushBack(); skipline(); - if (nestlevel-- < 0) + if (nestlevel-- <= svnestlevel[nestcount]) error("#endif without corresponding #if"); } diff --git a/util/cpp/file_info.h b/util/cpp/file_info.h index cc6c663ce..241c8de6b 100644 --- a/util/cpp/file_info.h +++ b/util/cpp/file_info.h @@ -9,12 +9,10 @@ struct file_info { unsigned int fil_lino; char *fil_name; char *fil_wdir; - int fil_nestlevel; }; #define LineNumber finfo.fil_lino #define FileName finfo.fil_name #define WorkingDir finfo.fil_wdir -#define nestlevel finfo.fil_nestlevel extern struct file_info finfo; /* input.c */ diff --git a/util/cpp/input.c b/util/cpp/input.c index 78aca5b6a..55789caed 100644 --- a/util/cpp/input.c +++ b/util/cpp/input.c @@ -47,8 +47,12 @@ AtEoIT() AtEoIF() { + extern int nestlevel; + extern int nestcount; + extern int svnestlevel[]; - if (nestlevel != -1) warning("missing #endif"); + if (nestlevel > svnestlevel[nestcount]) warning("missing #endif"); else if (NoUnstack) warning("unexpected EOF"); + nestlevel = svnestlevel[nestcount--]; return 0; } diff --git a/util/cpp/main.c b/util/cpp/main.c index ac04bca59..e9585cf9c 100644 --- a/util/cpp/main.c +++ b/util/cpp/main.c @@ -78,6 +78,5 @@ compile(argc, argv) fatal("%s: no source file %s\n", prog_name, source ? source : "stdin"); if (source) WorkingDir = getwdir(dummy); - nestlevel = -1; preprocess(source); } -- 2.34.1