diff options
author | dgp <dgp@users.sourceforge.net> | 2016-06-27 20:29:46 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-06-27 20:29:46 (GMT) |
commit | 73124928ba9d5134012c0c7bdfcd02dcf876d7cf (patch) | |
tree | 76364e7783a55e5d61302cf633f023c50f4094d7 /generic/tclParse.c | |
parent | cc2f6f6a7d3968e4411d45a4d5ee62b390bb3f4e (diff) | |
download | tcl-73124928ba9d5134012c0c7bdfcd02dcf876d7cf.zip tcl-73124928ba9d5134012c0c7bdfcd02dcf876d7cf.tar.gz tcl-73124928ba9d5134012c0c7bdfcd02dcf876d7cf.tar.bz2 |
Re-order loop for fewer gotos.
Diffstat (limited to 'generic/tclParse.c')
-rw-r--r-- | generic/tclParse.c | 82 |
1 files changed, 36 insertions, 46 deletions
diff --git a/generic/tclParse.c b/generic/tclParse.c index 3372318..568024b 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -294,21 +294,49 @@ Tcl_ParseCommand( } } - /* Jump to where we check for command termination */ - - parsePtr->commandStart = src; - type = CHAR_TYPE(*src); - scanned = 1; - goto start; - /* * The following loop parses the words of the command, one word in each * iteration through the loop. */ + parsePtr->commandStart = src; + type = CHAR_TYPE(*src); + scanned = 1; /* Can't have missing whitepsace before first word. */ while (1) { int expandWord = 0; + /* Are we at command termination? */ + + if ((numBytes == 0) || (type & terminators) != 0) { + parsePtr->term = src; + parsePtr->commandSize = src + (numBytes != 0) + - parsePtr->commandStart; + return TCL_OK; + } + + /* Are we missing white space after previous word? */ + + if (scanned == 0) { + if (src[-1] == '"') { + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "extra characters after close-quote", -1)); + } + parsePtr->errorType = TCL_PARSE_QUOTE_EXTRA; + } else { + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "extra characters after close-brace", -1)); + } + parsePtr->errorType = TCL_PARSE_BRACE_EXTRA; + } + parsePtr->term = src; + error: + Tcl_FreeParse(parsePtr); + parsePtr->commandSize = parsePtr->end - parsePtr->commandStart; + return TCL_ERROR; + } + /* * Create the token for the word. */ @@ -537,50 +565,12 @@ Tcl_ParseCommand( tokenPtr->type = TCL_TOKEN_SIMPLE_WORD; } - /* - * Do two additional checks: (a) make sure we're really at the end of - * a word (there might have been garbage left after a quoted or braced - * word), and (b) check for the end of the command. - */ + /* Parse the whitespace between words. */ scanned = ParseWhiteSpace(src,numBytes, &parsePtr->incomplete, &type); src += scanned; numBytes -= scanned; - - start: - if (numBytes == 0) { - parsePtr->term = src; - break; - } - if ((type & terminators) != 0) { - parsePtr->term = src; - src++; - break; - } - if (scanned == 0) { - if (src[-1] == '"') { - if (interp != NULL) { - Tcl_SetObjResult(interp, Tcl_NewStringObj( - "extra characters after close-quote", -1)); - } - parsePtr->errorType = TCL_PARSE_QUOTE_EXTRA; - } else { - if (interp != NULL) { - Tcl_SetObjResult(interp, Tcl_NewStringObj( - "extra characters after close-brace", -1)); - } - parsePtr->errorType = TCL_PARSE_BRACE_EXTRA; - } - parsePtr->term = src; - error: - Tcl_FreeParse(parsePtr); - parsePtr->commandSize = parsePtr->end - parsePtr->commandStart; - return TCL_ERROR; - } } - - parsePtr->commandSize = src - parsePtr->commandStart; - return TCL_OK; } /* |