summaryrefslogtreecommitdiffstats
path: root/generic/tclParse.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclParse.c')
-rw-r--r--generic/tclParse.c64
1 files changed, 48 insertions, 16 deletions
diff --git a/generic/tclParse.c b/generic/tclParse.c
index 5da1abb..9800537 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.45 2005/11/02 14:51:04 dkf Exp $
+ * RCS: @(#) $Id: tclParse.c,v 1.46 2006/07/05 05:34:45 dgp Exp $
*/
#include "tclInt.h"
@@ -176,6 +176,9 @@ static int ParseComment(CONST char *src, int numBytes,
Tcl_Parse *parsePtr);
static int ParseTokens(CONST char *src, int numBytes,
int mask, int flags, Tcl_Parse *parsePtr);
+static int ParseWhiteSpace(CONST char *src, int numBytes,
+ Tcl_Parse *parsePtr, char *typePtr);
+
/*
*----------------------------------------------------------------------
@@ -325,7 +328,7 @@ Tcl_ParseCommand(
* sequence: it should be treated just like white space.
*/
- scanned = TclParseWhiteSpace(src, numBytes, parsePtr, &type);
+ scanned = ParseWhiteSpace(src, numBytes, parsePtr, &type);
src += scanned;
numBytes -= scanned;
if (numBytes == 0) {
@@ -390,8 +393,7 @@ Tcl_ParseCommand(
)
/* Is the prefix */
&& (numBytes > 0)
- && (TclParseWhiteSpace(termPtr, numBytes, parsePtr,
- &type) == 0)
+ && (ParseWhiteSpace(termPtr, numBytes, parsePtr, &type) == 0)
&& (type != TYPE_COMMAND_END)
/* Non-whitespace follows */
) {
@@ -435,7 +437,7 @@ Tcl_ParseCommand(
* word), and (b) check for the end of the command.
*/
- scanned = TclParseWhiteSpace(src, numBytes, parsePtr, &type);
+ scanned = ParseWhiteSpace(src, numBytes, parsePtr, &type);
if (scanned) {
src += scanned;
numBytes -= scanned;
@@ -480,10 +482,10 @@ Tcl_ParseCommand(
/*
*----------------------------------------------------------------------
*
- * TclParseWhiteSpace --
+ * ParseWhiteSpace --
*
- * Scans up to numBytes bytes starting at src, consuming white space as
- * defined by Tcl's parsing rules.
+ * Scans up to numBytes bytes starting at src, consuming white space
+ * between words as defined by Tcl's parsing rules.
*
* Results:
* Returns the number of bytes recognized as white space. Records at
@@ -497,8 +499,8 @@ Tcl_ParseCommand(
*----------------------------------------------------------------------
*/
-int
-TclParseWhiteSpace(
+static int
+ParseWhiteSpace(
CONST char *src, /* First character to parse. */
register int numBytes, /* Max number of bytes to scan. */
Tcl_Parse *parsePtr, /* Information about parse in progress.
@@ -541,6 +543,38 @@ TclParseWhiteSpace(
/*
*----------------------------------------------------------------------
*
+ * TclParseAllWhiteSpace --
+ *
+ * Scans up to numBytes bytes starting at src, consuming all white space
+ * including the command-terminating newline characters.
+ *
+ * Results:
+ * Returns the number of bytes recognized as white space.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclParseAllWhiteSpace(
+ CONST char *src, /* First character to parse. */
+ int numBytes) /* Max number of byes to scan */
+{
+ Tcl_Parse dummy; /* Since we know ParseWhiteSpace() generates
+ * no tokens, there's no need for a call to
+ * Tcl_FreeParse() in this routine */
+ char type;
+ CONST char *p = src;
+ do {
+ int scanned = ParseWhiteSpace(p, numBytes, &dummy, &type);
+ p += scanned;
+ numBytes -= scanned;
+ } while (numBytes && (*p == '\n') && (p++, --numBytes));
+ return (p-src);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* TclParseHex --
*
* Scans a hexadecimal number as a Tcl_UniChar value (e.g., for parsing
@@ -801,11 +835,9 @@ ParseComment(
char type;
int scanned;
- do {
- scanned = TclParseWhiteSpace(p, numBytes, parsePtr, &type);
- p += scanned;
- numBytes -= scanned;
- } while (numBytes && (*p == '\n') && (p++,numBytes--));
+ scanned = TclParseAllWhiteSpace(p, numBytes);
+ p += scanned;
+ numBytes -= scanned;
if ((numBytes == 0) || (*p != '#')) {
break;
@@ -816,7 +848,7 @@ ParseComment(
while (numBytes) {
if (*p == '\\') {
- scanned = TclParseWhiteSpace(p, numBytes, parsePtr, &type);
+ scanned = ParseWhiteSpace(p, numBytes, parsePtr, &type);
if (scanned) {
p += scanned;
numBytes -= scanned;