diff options
Diffstat (limited to 'generic/tclParse.c')
-rw-r--r-- | generic/tclParse.c | 221 |
1 files changed, 110 insertions, 111 deletions
diff --git a/generic/tclParse.c b/generic/tclParse.c index eac35be..5da1abb 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.44 2005/10/04 23:49:45 hobbs Exp $ + * RCS: @(#) $Id: tclParse.c,v 1.45 2005/11/02 14:51:04 dkf Exp $ */ #include "tclInt.h" @@ -171,12 +171,11 @@ static CONST char charTypeTable[] = { * Prototypes for local functions defined in this file: */ -static int CommandComplete _ANSI_ARGS_((CONST char *script, - int numBytes)); -static int ParseComment _ANSI_ARGS_((CONST char *src, - int numBytes, Tcl_Parse *parsePtr)); -static int ParseTokens _ANSI_ARGS_((CONST char *src, int numBytes, - int mask, int flags, Tcl_Parse *parsePtr)); +static int CommandComplete(CONST char *script, int numBytes); +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); /* *---------------------------------------------------------------------- @@ -195,13 +194,13 @@ static int ParseTokens _ANSI_ARGS_((CONST char *src, int numBytes, */ void -TclParseInit(interp, string, numBytes, parsePtr) - Tcl_Interp *interp; /* Interpreter to use for error reporting */ - CONST char *string; /* String to be parsed. */ - int numBytes; /* Total number of bytes in string. If < 0, +TclParseInit( + Tcl_Interp *interp, /* Interpreter to use for error reporting */ + CONST char *string, /* String to be parsed. */ + int numBytes, /* Total number of bytes in string. If < 0, * the script consists of all bytes up to the * first null character. */ - Tcl_Parse *parsePtr; /* Points to struct to initialize */ + Tcl_Parse *parsePtr) /* Points to struct to initialize */ { parsePtr->numWords = 0; parsePtr->tokenPtr = parsePtr->staticTokens; @@ -239,19 +238,19 @@ TclParseInit(interp, string, numBytes, parsePtr) */ int -Tcl_ParseCommand(interp, start, numBytes, nested, parsePtr) - Tcl_Interp *interp; /* Interpreter to use for error reporting; if +Tcl_ParseCommand( + Tcl_Interp *interp, /* Interpreter to use for error reporting; if * NULL, then no error message is provided. */ - CONST char *start; /* First character of string containing one or + CONST char *start, /* First character of string containing one or * more Tcl commands. */ - register int numBytes; /* Total number of bytes in string. If < 0, + register int numBytes, /* Total number of bytes in string. If < 0, * the script consists of all bytes up to the * first null character. */ - int nested; /* Non-zero means this is a nested command: + int nested, /* Non-zero means this is a nested command: * close bracket should be considered a * command terminator. If zero, then close * bracket has no special meaning. */ - register Tcl_Parse *parsePtr; + register Tcl_Parse *parsePtr) /* Structure to fill in with information about * the parsed command; any previous * information in the structure is ignored. */ @@ -499,13 +498,13 @@ Tcl_ParseCommand(interp, start, numBytes, nested, parsePtr) */ int -TclParseWhiteSpace(src, numBytes, parsePtr, typePtr) - CONST char *src; /* First character to parse. */ - register int numBytes; /* Max number of bytes to scan. */ - Tcl_Parse *parsePtr; /* Information about parse in progress. +TclParseWhiteSpace( + CONST char *src, /* First character to parse. */ + register int numBytes, /* Max number of bytes to scan. */ + Tcl_Parse *parsePtr, /* Information about parse in progress. * Updated if parsing indicates an incomplete * command. */ - char *typePtr; /* Points to location to store character type + char *typePtr) /* Points to location to store character type * of character that ends run of whitespace */ { register char type = TYPE_NORMAL; @@ -562,10 +561,10 @@ TclParseWhiteSpace(src, numBytes, parsePtr, typePtr) */ int -TclParseHex(src, numBytes, resultPtr) - CONST char *src; /* First character to parse. */ - int numBytes; /* Max number of byes to scan */ - Tcl_UniChar *resultPtr; /* Points to storage provided by caller where +TclParseHex( + CONST char *src, /* First character to parse. */ + int numBytes, /* Max number of byes to scan */ + Tcl_UniChar *resultPtr) /* Points to storage provided by caller where * the Tcl_UniChar resulting from the * conversion is to be written. */ { @@ -617,13 +616,13 @@ TclParseHex(src, numBytes, resultPtr) */ int -TclParseBackslash(src, numBytes, readPtr, dst) - CONST char *src; /* Points to the backslash character of a a +TclParseBackslash( + CONST char *src, /* Points to the backslash character of a a * backslash sequence. */ - int numBytes; /* Max number of bytes to scan. */ - int *readPtr; /* NULL, or points to storage where the number + int numBytes, /* Max number of bytes to scan. */ + int *readPtr, /* NULL, or points to storage where the number * of bytes scanned should be written. */ - char *dst; /* NULL, or points to buffer where the UTF-8 + char *dst) /* NULL, or points to buffer where the UTF-8 * encoding of the backslash sequence is to be * written. At most TCL_UTF_MAX bytes will be * written there. */ @@ -790,10 +789,10 @@ TclParseBackslash(src, numBytes, readPtr, dst) */ static int -ParseComment(src, numBytes, parsePtr) - CONST char *src; /* First character to parse. */ - register int numBytes; /* Max number of bytes to scan. */ - Tcl_Parse *parsePtr; /* Information about parse in progress. +ParseComment( + CONST char *src, /* First character to parse. */ + register int numBytes, /* Max number of bytes to scan. */ + Tcl_Parse *parsePtr) /* Information about parse in progress. * Updated if parsing indicates an incomplete * command. */ { @@ -872,18 +871,18 @@ ParseComment(src, numBytes, parsePtr) */ static int -ParseTokens(src, numBytes, mask, flags, parsePtr) - register CONST char *src; /* First character to parse. */ - register int numBytes; /* Max number of bytes to scan. */ - int flags; /* OR-ed bits indicating what substitutions to - perform: TCL_SUBST_COMMANDS, - TCL_SUBST_VARIABLES, and - TCL_SUBST_BACKSLASHES */ - int mask; /* Specifies when to stop parsing. The parse +ParseTokens( + register CONST char *src, /* First character to parse. */ + register int numBytes, /* Max number of bytes to scan. */ + int mask, /* Specifies when to stop parsing. The parse * stops at the first unquoted character whose * CHAR_TYPE contains any of the bits in * mask. */ - Tcl_Parse *parsePtr; /* Information about parse in progress. + int flags, /* OR-ed bits indicating what substitutions to + * perform: TCL_SUBST_COMMANDS, + * TCL_SUBST_VARIABLES, and + * TCL_SUBST_BACKSLASHES */ + Tcl_Parse *parsePtr) /* Information about parse in progress. * Updated with additional tokens and * termination information. */ { @@ -1071,8 +1070,8 @@ ParseTokens(src, numBytes, mask, flags, parsePtr) } if (parsePtr->numTokens == originalTokens) { /* - * There was nothing in this range of text. Add an empty token for - * the empty range, so that there is always at least one token added. + * There was nothing in this range of text. Add an empty token for the + * empty range, so that there is always at least one token added. */ if (parsePtr->numTokens == parsePtr->tokensAvailable) { @@ -1110,8 +1109,8 @@ ParseTokens(src, numBytes, mask, flags, parsePtr) */ void -Tcl_FreeParse(parsePtr) - Tcl_Parse *parsePtr; /* Structure that was filled in by a previous +Tcl_FreeParse( + Tcl_Parse *parsePtr) /* Structure that was filled in by a previous * call to Tcl_ParseCommand. */ { if (parsePtr->tokenPtr != parsePtr->staticTokens) { @@ -1140,8 +1139,8 @@ Tcl_FreeParse(parsePtr) */ void -TclExpandTokenArray(parsePtr) - Tcl_Parse *parsePtr; /* Parse structure whose token space has +TclExpandTokenArray( + Tcl_Parse *parsePtr) /* Parse structure whose token space has * overflowed. */ { int newCount; @@ -1164,7 +1163,7 @@ TclExpandTokenArray(parsePtr) * Tcl_ParseVarName -- * * Given a string starting with a $ sign, parse off a variable name and - * return information about the parse. No more than numBytes bytes will + * return information about the parse. No more than numBytes bytes will * be scanned. * * Results: @@ -1186,17 +1185,17 @@ TclExpandTokenArray(parsePtr) */ int -Tcl_ParseVarName(interp, start, numBytes, parsePtr, append) - Tcl_Interp *interp; /* Interpreter to use for error reporting; if +Tcl_ParseVarName( + Tcl_Interp *interp, /* Interpreter to use for error reporting; if * NULL, then no error message is provided. */ - CONST char *start; /* Start of variable substitution string. + CONST char *start, /* Start of variable substitution string. * First character must be "$". */ - register int numBytes; /* Total number of bytes in string. If < 0, + register int numBytes, /* Total number of bytes in string. If < 0, * the string consists of all bytes up to the * first null character. */ - Tcl_Parse *parsePtr; /* Structure to fill in with information about + Tcl_Parse *parsePtr, /* Structure to fill in with information about * the variable name. */ - int append; /* Non-zero means append tokens to existing + int append) /* Non-zero means append tokens to existing * information in parsePtr; zero means ignore * existing tokens in parsePtr and * reinitialize it. */ @@ -1248,12 +1247,12 @@ Tcl_ParseVarName(interp, start, numBytes, parsePtr, append) * 1. The $ sign is followed by an open curly brace. Then the variable * name is everything up to the next close curly brace, and the * variable is a scalar variable. - * 2. The $ sign is not followed by an open curly brace. Then the - * variable name is everything up to the next character that isn't a - * letter, digit, or underscore. :: sequences are also considered part - * of the variable name, in order to support namespaces. If the - * following character is an open parenthesis, then the information - * between parentheses is the array element name. + * 2. The $ sign is not followed by an open curly brace. Then the variable + * name is everything up to the next character that isn't a letter, + * digit, or underscore. :: sequences are also considered part of the + * variable name, in order to support namespaces. If the following + * character is an open parenthesis, then the information between + * parentheses is the array element name. * 3. The $ sign is followed by something that isn't a letter, digit, or * underscore: in this case, there is no variable name and the token is * just "$". @@ -1357,7 +1356,7 @@ Tcl_ParseVarName(interp, start, numBytes, parsePtr, append) return TCL_OK; /* - * The dollar sign isn't followed by a variable name. Replace the + * The dollar sign isn't followed by a variable name. Replace the * TCL_TOKEN_VARIABLE token with a TCL_TOKEN_TEXT token for the dollar * sign. */ @@ -1384,9 +1383,9 @@ Tcl_ParseVarName(interp, start, numBytes, parsePtr, append) * * Results: * The return value is the contents of the variable given by the leading - * characters of string. If termPtr isn't NULL, *termPtr gets filled in + * characters of string. If termPtr isn't NULL, *termPtr gets filled in * with the address of the character just after the last one in the - * variable specifier. If the variable doesn't exist, then the return + * variable specifier. If the variable doesn't exist, then the return * value is NULL and an error message will be left in interp's result. * * Side effects: @@ -1396,11 +1395,11 @@ Tcl_ParseVarName(interp, start, numBytes, parsePtr, append) */ CONST char * -Tcl_ParseVar(interp, start, termPtr) - Tcl_Interp *interp; /* Context for looking up variable. */ - register CONST char *start; /* Start of variable substitution. +Tcl_ParseVar( + Tcl_Interp *interp, /* Context for looking up variable. */ + register CONST char *start, /* Start of variable substitution. * First character must be "$". */ - CONST char **termPtr; /* If non-NULL, points to word to fill + CONST char **termPtr) /* If non-NULL, points to word to fill * in with character just after last * one in the variable specifier. */ { @@ -1476,22 +1475,22 @@ Tcl_ParseVar(interp, start, termPtr) */ int -Tcl_ParseBraces(interp, start, numBytes, parsePtr, append, termPtr) - Tcl_Interp *interp; /* Interpreter to use for error reporting; if +Tcl_ParseBraces( + Tcl_Interp *interp, /* Interpreter to use for error reporting; if * NULL, then no error message is provided. */ - CONST char *start; /* Start of string enclosed in braces. The + CONST char *start, /* Start of string enclosed in braces. The * first character must be {'. */ - register int numBytes; /* Total number of bytes in string. If < 0, + register int numBytes, /* Total number of bytes in string. If < 0, * the string consists of all bytes up to the * first null character. */ - register Tcl_Parse *parsePtr; + register Tcl_Parse *parsePtr, /* Structure to fill in with information about * the string. */ - int append; /* Non-zero means append tokens to existing + int append, /* Non-zero means append tokens to existing * information in parsePtr; zero means ignore * existing tokens in parsePtr and * reinitialize it. */ - CONST char **termPtr; /* If non-NULL, points to word in which to + CONST char **termPtr) /* If non-NULL, points to word in which to * store a pointer to the character just after * the terminating '}' if the parse was * successful. */ @@ -1683,22 +1682,22 @@ Tcl_ParseBraces(interp, start, numBytes, parsePtr, append, termPtr) */ int -Tcl_ParseQuotedString(interp, start, numBytes, parsePtr, append, termPtr) - Tcl_Interp *interp; /* Interpreter to use for error reporting; if +Tcl_ParseQuotedString( + Tcl_Interp *interp, /* Interpreter to use for error reporting; if * NULL, then no error message is provided. */ - CONST char *start; /* Start of the quoted string. The first + CONST char *start, /* Start of the quoted string. The first * character must be '"'. */ - register int numBytes; /* Total number of bytes in string. If < 0, + register int numBytes, /* Total number of bytes in string. If < 0, * the string consists of all bytes up to the * first null character. */ - register Tcl_Parse *parsePtr; + register Tcl_Parse *parsePtr, /* Structure to fill in with information about * the string. */ - int append; /* Non-zero means append tokens to existing + int append, /* Non-zero means append tokens to existing * information in parsePtr; zero means ignore * existing tokens in parsePtr and * reinitialize it. */ - CONST char **termPtr; /* If non-NULL, points to word in which to + CONST char **termPtr) /* If non-NULL, points to word in which to * store a pointer to the character just after * the quoted string's terminating close-quote * if the parse succeeds. */ @@ -1756,10 +1755,10 @@ Tcl_ParseQuotedString(interp, start, numBytes, parsePtr, append, termPtr) */ Tcl_Obj * -Tcl_SubstObj(interp, objPtr, flags) - Tcl_Interp *interp; /* Interpreter in which substitution occurs */ - Tcl_Obj *objPtr; /* The value to be substituted. */ - int flags; /* What substitutions to do. */ +Tcl_SubstObj( + Tcl_Interp *interp, /* Interpreter in which substitution occurs */ + Tcl_Obj *objPtr, /* The value to be substituted. */ + int flags) /* What substitutions to do. */ { int length, tokensLeft, code; Tcl_Parse parse; @@ -1867,15 +1866,15 @@ Tcl_SubstObj(interp, objPtr, flags) length = parse.end - p; if (length == 0) { /* - * No commands, just an unmatched [. As in previous cases, + * No commands, just an unmatched [. As in previous cases, * existing token stream is OK. */ } else { /* * We want to add the parsing of as many commands as we can * within that substitution until we reach the actual parse - * error. We'll do additional parsing to determine what - * length to claim for the final TCL_TOKEN_COMMAND token. + * error. We'll do additional parsing to determine what length + * to claim for the final TCL_TOKEN_COMMAND token. */ Tcl_Token *tokenPtr; @@ -1901,8 +1900,8 @@ Tcl_SubstObj(interp, objPtr, flags) if (lastTerm == parse.term) { /* - * Parse error in first command. No commands to subst, - * add no more tokens. + * Parse error in first command. No commands to subst, add + * no more tokens. */ break; } @@ -2005,15 +2004,15 @@ Tcl_SubstObj(interp, objPtr, flags) */ int -TclSubstTokens(interp, tokenPtr, count, tokensLeftPtr) - Tcl_Interp *interp; /* Interpreter in which to lookup variables, +TclSubstTokens( + Tcl_Interp *interp, /* Interpreter in which to lookup variables, * execute nested commands, and report * errors. */ - Tcl_Token *tokenPtr; /* Pointer to first in an array of tokens to + Tcl_Token *tokenPtr, /* Pointer to first in an array of tokens to * evaluate and concatenate. */ - int count; /* Number of tokens to consider at tokenPtr. + int count, /* Number of tokens to consider at tokenPtr. * Must be at least 1. */ - int *tokensLeftPtr; /* If not NULL, points to memory where an + int *tokensLeftPtr) /* If not NULL, points to memory where an * integer representing the number of tokens * left to be substituted will be written */ { @@ -2191,9 +2190,9 @@ TclSubstTokens(interp, tokenPtr, count, tokensLeftPtr) */ static int -CommandComplete(script, numBytes) - CONST char *script; /* Script to check. */ - int numBytes; /* Number of bytes in script. */ +CommandComplete( + CONST char *script, /* Script to check. */ + int numBytes) /* Number of bytes in script. */ { Tcl_Parse parse; CONST char *p, *end; @@ -2228,7 +2227,7 @@ CommandComplete(script, numBytes) * and quotes and brackets. * * Results: - * 1 is returned if the script is complete, 0 otherwise. 1 is also + * 1 is returned if the script is complete, 0 otherwise. 1 is also * returned if there is a parse error in the script other than unmatched * delimiters. * @@ -2239,8 +2238,8 @@ CommandComplete(script, numBytes) */ int -Tcl_CommandComplete(script) - CONST char *script; /* Script to check. */ +Tcl_CommandComplete( + CONST char *script) /* Script to check. */ { return CommandComplete(script, (int) strlen(script)); } @@ -2264,8 +2263,8 @@ Tcl_CommandComplete(script) */ int -TclObjCommandComplete(objPtr) - Tcl_Obj *objPtr; /* Points to object holding script to +TclObjCommandComplete( + Tcl_Obj *objPtr) /* Points to object holding script to * check. */ { CONST char *script; @@ -2293,9 +2292,9 @@ TclObjCommandComplete(objPtr) */ int -TclIsLocalScalar(src, len) - CONST char *src; - int len; +TclIsLocalScalar( + CONST char *src, + int len) { CONST char *p; CONST char *lastChar = src + (len - 1); @@ -2311,7 +2310,7 @@ TclIsLocalScalar(src, len) return 0; } - if (*p == '(') { + if (*p == '(') { if (*lastChar == ')') { /* we have an array element */ return 0; } |