From 6fdf4cc2d0a48ffa0e61f085138471f43c2cb035 Mon Sep 17 00:00:00 2001 From: dkf Date: Fri, 19 Jul 2002 10:12:27 +0000 Subject: Cleanup and simplification (file-vars are private, loops are not done when effects are unobservable) FossilOrigin-Name: 2fd1bbe6855fd7aa94224e14c42eb5d3a3028b2d --- ChangeLog | 4 ++++ generic/tclParse.c | 52 ++++++++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index a5efe50..99893d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2002-07-19 Donal K. Fellows + * generic/tclParse.c (typeTable): Made this array static and const. + (Tcl_ParseBraces): Simplified error handling case so that scans + are only performed when needed, and flags are simpler too. + * license.terms: Added AS to list of copyright holders; it's only fair for the current gatekeepers to be listed here! diff --git a/generic/tclParse.c b/generic/tclParse.c index 19aa324..b22df23 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclParse.c,v 1.20 2002/04/12 06:28:33 hobbs Exp $ + * RCS: @(#) $Id: tclParse.c,v 1.21 2002/07/19 10:12:28 dkf Exp $ */ #include "tclInt.h" @@ -56,7 +56,7 @@ #define CHAR_TYPE(c) (typeTable+128)[(int)(c)] -char typeTable[] = { +static CONST char typeTable[] = { /* * Negative character values, from -128 to -1: */ @@ -1169,20 +1169,30 @@ Tcl_ParseBraces(interp, string, numBytes, parsePtr, append, termPtr) src += length; } } else if (src == end) { - int openBrace; + register int openBrace; /* bool-flag for when scanning back */ - if (interp != NULL) { - Tcl_SetResult(interp, "missing close-brace", TCL_STATIC); + parsePtr->errorType = TCL_PARSE_MISSING_BRACE; + parsePtr->term = string; + parsePtr->incomplete = 1; + if (interp == NULL) { + /* + * Skip straight to the exit code since we have no + * interpreter to put error messages in. + */ + goto error; } + + Tcl_SetResult(interp, "missing close-brace", TCL_STATIC); + /* - * Search the source string for a possible open - * brace within the context of a comment. Since we - * aren't performing a full Tcl parse, just look for - * an open brace preceeded by a '#' on - * the same line. + * Guess if the problem is due to comments by searching + * the source string for a possible open brace within the + * context of a comment. Since we aren't performing a + * full Tcl parse, just look for an open brace preceeded + * by a '#' on the same line. */ openBrace = 0; - while (src > string ) { + for (; src>string ; src--) { switch (*src) { case '{': openBrace = 1; @@ -1191,25 +1201,15 @@ Tcl_ParseBraces(interp, string, numBytes, parsePtr, append, termPtr) openBrace = 0; break; case '#': - if ((openBrace == 1) && (isspace(UCHAR(src[-1])))) { - if (interp != NULL) { - Tcl_AppendResult(interp, - ": possible unbalanced brace in comment", - (char *) NULL); - } - openBrace = -1; - break; + if (openBrace && (isspace(UCHAR(src[-1])))) { + Tcl_AppendResult(interp, + ": possible unbalanced brace in comment", + (char *) NULL); + goto error; } break; } - if (openBrace == -1) { - break; - } - src--; } - parsePtr->errorType = TCL_PARSE_MISSING_BRACE; - parsePtr->term = string; - parsePtr->incomplete = 1; goto error; } else { src++; -- cgit v0.12