summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclFileName.c15
-rw-r--r--generic/tclIOCmd.c14
-rw-r--r--generic/tclParse.c251
-rw-r--r--generic/tclPathObj.c12
-rw-r--r--generic/tclPkg.c148
-rwxr-xr-xgeneric/tclStrToD.c235
-rw-r--r--generic/tclStringObj.c143
7 files changed, 414 insertions, 404 deletions
diff --git a/generic/tclFileName.c b/generic/tclFileName.c
index 6705866..dc58199 100644
--- a/generic/tclFileName.c
+++ b/generic/tclFileName.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclFileName.c,v 1.84 2007/06/20 18:46:12 dgp Exp $
+ * RCS: @(#) $Id: tclFileName.c,v 1.85 2007/11/18 22:32:47 dkf Exp $
*/
#include "tclInt.h"
@@ -1154,7 +1154,7 @@ DoTildeSubst(
if (interp) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "couldn't find HOME environment "
- "variable to expand path", (char *) NULL);
+ "variable to expand path", NULL);
}
return NULL;
}
@@ -1164,7 +1164,7 @@ DoTildeSubst(
if (interp) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "user \"", user, "\" doesn't exist",
- (char *) NULL);
+ NULL);
}
return NULL;
}
@@ -1598,19 +1598,18 @@ Tcl_GlobObjCmd(
if (length == 0) {
Tcl_AppendResult(interp, "no files matched glob pattern",
- (join || (objc == 1)) ? " \"" : "s \"", (char *) NULL);
+ (join || (objc == 1)) ? " \"" : "s \"", NULL);
if (join) {
- Tcl_AppendResult(interp, Tcl_DStringValue(&prefix),
- (char *) NULL);
+ Tcl_AppendResult(interp, Tcl_DStringValue(&prefix), NULL);
} else {
const char *sep = "";
for (i = 0; i < objc; i++) {
string = Tcl_GetString(objv[i]);
- Tcl_AppendResult(interp, sep, string, (char *) NULL);
+ Tcl_AppendResult(interp, sep, string, NULL);
sep = " ";
}
}
- Tcl_AppendResult(interp, "\"", (char *) NULL);
+ Tcl_AppendResult(interp, "\"", NULL);
result = TCL_ERROR;
}
}
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index f69506c..cc01b91 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIOCmd.c,v 1.45 2007/11/11 19:32:15 msofer Exp $
+ * RCS: @(#) $Id: tclIOCmd.c,v 1.46 2007/11/18 22:32:47 dkf Exp $
*/
#include "tclInt.h"
@@ -265,18 +265,18 @@ Tcl_GetsObjCmd(
}
linePtr = Tcl_NewObj();
-
lineLen = Tcl_GetsObj(chan, linePtr);
if (lineLen < 0) {
if (!Tcl_Eof(chan) && !Tcl_InputBlocked(chan)) {
Tcl_DecrRefCount(linePtr);
/*
- * TIP #219.
- * Capture error messages put by the driver into the bypass area
- * and put them into the regular interpreter result. Fall back to
- * the regular message if nothing was found in the bypass.
+ * TIP #219. Capture error messages put by the driver into the
+ * bypass area and put them into the regular interpreter result.
+ * Fall back to the regular message if nothing was found in the
+ * bypass.
*/
+
if (!TclChanCaughtErrorBypass(interp, chan)) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "error reading \"", name, "\": ",
@@ -1665,7 +1665,7 @@ TclChanPendingObjCmd(
Tcl_Channel chan;
int index, mode;
char *arg;
- static const char *options[] = {"input", "output", (char *) NULL};
+ static const char *options[] = {"input", "output", NULL};
enum options {PENDING_INPUT, PENDING_OUTPUT};
if (objc != 3) {
diff --git a/generic/tclParse.c b/generic/tclParse.c
index ba1198a..211a10b 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.58 2007/11/11 19:32:17 msofer Exp $
+ * RCS: @(#) $Id: tclParse.c,v 1.59 2007/11/18 22:30:10 dkf Exp $
*/
#include "tclInt.h"
@@ -54,7 +54,7 @@
#define CHAR_TYPE(c) (charTypeTable+128)[(int)(c)]
-static CONST char charTypeTable[] = {
+static const char charTypeTable[] = {
/*
* Negative character values, from -128 to -1:
*/
@@ -171,12 +171,12 @@ static CONST char charTypeTable[] = {
* Prototypes for local functions defined in this file:
*/
-static int CommandComplete(CONST char *script, int numBytes);
-static int ParseComment(CONST char *src, int numBytes,
+static inline 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,
+static int ParseTokens(const char *src, int numBytes, int mask,
int flags, Tcl_Parse *parsePtr);
-static int ParseWhiteSpace(CONST char *src, int numBytes,
+static int ParseWhiteSpace(const char *src, int numBytes,
int *incompletePtr, char *typePtr);
/*
@@ -198,7 +198,7 @@ static int ParseWhiteSpace(CONST char *src, int numBytes,
void
TclParseInit(
Tcl_Interp *interp, /* Interpreter to use for error reporting */
- CONST char *string, /* String to be parsed. */
+ 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. */
@@ -243,7 +243,7 @@ int
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,
* the script consists of all bytes up to the
@@ -257,14 +257,14 @@ Tcl_ParseCommand(
* the parsed command; any previous
* information in the structure is ignored. */
{
- register CONST char *src; /* Points to current character in the
+ register const char *src; /* Points to current character in the
* command. */
char type; /* Result returned by CHAR_TYPE(*src). */
Tcl_Token *tokenPtr; /* Pointer to token being filled in. */
int wordIndex; /* Index of word token for current word. */
int terminators; /* CHAR_TYPE bits that indicate the end of a
* command. */
- CONST char *termPtr; /* Set by Tcl_ParseBraces/QuotedString to
+ const char *termPtr; /* Set by Tcl_ParseBraces/QuotedString to
* point to char after terminating one. */
int scanned;
@@ -327,7 +327,7 @@ Tcl_ParseCommand(
* sequence: it should be treated just like white space.
*/
- scanned = ParseWhiteSpace(src, numBytes, &(parsePtr->incomplete), &type);
+ scanned = ParseWhiteSpace(src,numBytes, &parsePtr->incomplete, &type);
src += scanned;
numBytes -= scanned;
if (numBytes == 0) {
@@ -351,8 +351,8 @@ Tcl_ParseCommand(
parseWord:
if (*src == '"') {
- if (Tcl_ParseQuotedString(interp, src, numBytes,
- parsePtr, 1, &termPtr) != TCL_OK) {
+ if (Tcl_ParseQuotedString(interp, src, numBytes, parsePtr, 1,
+ &termPtr) != TCL_OK) {
goto error;
}
src = termPtr;
@@ -361,33 +361,31 @@ Tcl_ParseCommand(
int expIdx = wordIndex + 1;
Tcl_Token *expPtr;
- if (Tcl_ParseBraces(interp, src, numBytes,
- parsePtr, 1, &termPtr) != TCL_OK) {
+ if (Tcl_ParseBraces(interp, src, numBytes, parsePtr, 1,
+ &termPtr) != TCL_OK) {
goto error;
}
src = termPtr;
numBytes = parsePtr->end - src;
/*
- * Check whether the braces contained the word expansion prefix {*}
+ * Check whether the braces contained the word expansion prefix
+ * {*}
*/
expPtr = &parsePtr->tokenPtr[expIdx];
- if (
- (0 == expandWord)
- /* Haven't seen prefix already */
- && (1 == parsePtr->numTokens - expIdx)
- /* Only one token */
- && (((1 == (size_t) expPtr->size)
+ if ((0 == expandWord)
+ /* Haven't seen prefix already */
+ && (1 == parsePtr->numTokens - expIdx)
+ /* Only one token */
+ && (((1 == (size_t) expPtr->size)
/* Same length as prefix */
- && (expPtr->start[0] == '*'))
- )
- /* Is the prefix */
- && (numBytes > 0) && (0 ==
- ParseWhiteSpace(termPtr, numBytes, &(parsePtr->incomplete), &type))
- && (type != TYPE_COMMAND_END)
- /* Non-whitespace follows */
- ) {
+ && (expPtr->start[0] == '*')))
+ /* Is the prefix */
+ && (numBytes > 0) && (0 == ParseWhiteSpace(termPtr,
+ numBytes, &parsePtr->incomplete, &type))
+ && (type != TYPE_COMMAND_END)
+ /* Non-whitespace follows */) {
expandWord = 1;
parsePtr->numTokens--;
goto parseWord;
@@ -417,12 +415,12 @@ Tcl_ParseCommand(
if (expandWord) {
int i, isLiteral = 1;
- /*
- * When a command includes a word that is an expanded literal;
- * for example, {*}{1 2 3}, the parser performs that expansion
+ /*
+ * When a command includes a word that is an expanded literal; for
+ * example, {*}{1 2 3}, the parser performs that expansion
* immediately, generating several TCL_TOKEN_SIMPLE_WORDs instead
* of a single TCL_TOKEN_EXPAND_WORD that the Tcl_ParseCommand()
- * caller might have to expand. This notably makes it simpler for
+ * caller might have to expand. This notably makes it simpler for
* those callers that wish to track line endings, such as those
* that implement key parts of TIP 280.
*
@@ -442,12 +440,12 @@ Tcl_ParseCommand(
int elemCount = 0, code = TCL_OK;
const char *nextElem, *listEnd, *elemStart;
- /*
+ /*
* The word to be expanded is a literal, so determine the
* boundaries of the literal string to be treated as a list
- * and expanded. That literal string starts at
- * tokenPtr[1].start, and includes all bytes up to, but
- * not including (tokenPtr[tokenPtr->numComponents].start +
+ * and expanded. That literal string starts at
+ * tokenPtr[1].start, and includes all bytes up to, but not
+ * including (tokenPtr[tokenPtr->numComponents].start +
* tokenPtr[tokenPtr->numComponents].size)
*/
@@ -455,11 +453,11 @@ Tcl_ParseCommand(
tokenPtr[tokenPtr->numComponents].size);
nextElem = tokenPtr[1].start;
- /*
- * Step through the literal string, parsing and counting
- * list elements.
+ /*
+ * Step through the literal string, parsing and counting list
+ * elements.
*/
-
+
while (nextElem < listEnd) {
code = TclFindElement(NULL, nextElem, listEnd - nextElem,
&elemStart, &nextElem, NULL, NULL);
@@ -470,29 +468,26 @@ Tcl_ParseCommand(
}
if (code != TCL_OK) {
-
/*
- * Some list element could not be parsed. This means
- * the literal string was not in fact a valid list.
- * Defer the handling of this to compile/eval time, where
- * code is already in place to report the "attempt to
- * expand a non-list" error.
+ * Some list element could not be parsed. This means the
+ * literal string was not in fact a valid list. Defer the
+ * handling of this to compile/eval time, where code is
+ * already in place to report the "attempt to expand a
+ * non-list" error.
*/
tokenPtr->type = TCL_TOKEN_EXPAND_WORD;
} else if (elemCount == 0) {
-
/*
- * We are expanding a literal empty list. This means
- * that the expanding word completely disappears, leaving
- * no word generated this pass through the loop. Adjust
+ * We are expanding a literal empty list. This means that
+ * the expanding word completely disappears, leaving no
+ * word generated this pass through the loop. Adjust
* accounting appropriately.
*/
parsePtr->numWords--;
parsePtr->numTokens = wordIndex;
} else {
-
/*
* Recalculate the number of Tcl_Tokens needed to store
* tokens representing the expanded list.
@@ -508,9 +503,9 @@ Tcl_ParseCommand(
/*
* Generate a TCL_TOKEN_SIMPLE_WORD token sequence for
* each element of the literal list we are expanding in
- * place. Take care with the start and size fields of
- * each token so they point to the right literal characters
- * in the original script to represent the right expanded
+ * place. Take care with the start and size fields of each
+ * token so they point to the right literal characters in
+ * the original script to represent the right expanded
* word value.
*/
@@ -542,8 +537,7 @@ Tcl_ParseCommand(
}
}
} else {
-
- /*
+ /*
* The word to be expanded is not a literal, so defer
* expansion to compile/eval time by marking with a
* TCL_TOKEN_EXPAND_WORD token.
@@ -562,7 +556,7 @@ Tcl_ParseCommand(
* word), and (b) check for the end of the command.
*/
- scanned = ParseWhiteSpace(src, numBytes, &(parsePtr->incomplete), &type);
+ scanned = ParseWhiteSpace(src,numBytes, &parsePtr->incomplete, &type);
if (scanned) {
src += scanned;
numBytes -= scanned;
@@ -626,7 +620,7 @@ Tcl_ParseCommand(
static int
ParseWhiteSpace(
- CONST char *src, /* First character to parse. */
+ const char *src, /* First character to parse. */
register int numBytes, /* Max number of bytes to scan. */
int *incompletePtr, /* Set this boolean memory to true if parsing
* indicates an incomplete command. */
@@ -634,7 +628,7 @@ ParseWhiteSpace(
* of character that ends run of whitespace */
{
register char type = TYPE_NORMAL;
- register CONST char *p = src;
+ register const char *p = src;
while (1) {
while (numBytes && ((type = CHAR_TYPE(*p)) & TYPE_SPACE)) {
@@ -680,12 +674,12 @@ ParseWhiteSpace(
int
TclParseAllWhiteSpace(
- CONST char *src, /* First character to parse. */
+ const char *src, /* First character to parse. */
int numBytes) /* Max number of byes to scan */
{
int dummy;
char type;
- CONST char *p = src;
+ const char *p = src;
do {
int scanned = ParseWhiteSpace(p, numBytes, &dummy, &type);
@@ -720,14 +714,14 @@ TclParseAllWhiteSpace(
int
TclParseHex(
- CONST char *src, /* First character to parse. */
+ 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. */
{
Tcl_UniChar result = 0;
- register CONST char *p = src;
+ register const char *p = src;
while (numBytes--) {
unsigned char digit = UCHAR(*p);
@@ -775,7 +769,7 @@ TclParseHex(
int
TclParseBackslash(
- CONST char *src, /* Points to the backslash character of a a
+ 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
@@ -785,7 +779,7 @@ TclParseBackslash(
* written. At most TCL_UTF_MAX bytes will be
* written there. */
{
- register CONST char *p = src+1;
+ register const char *p = src+1;
Tcl_UniChar result;
int count;
char buf[TCL_UTF_MAX];
@@ -948,13 +942,14 @@ TclParseBackslash(
static int
ParseComment(
- CONST char *src, /* First character to parse. */
+ 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. */
{
- register CONST char *p = src;
+ register const char *p = src;
+
while (numBytes) {
char type;
int scanned;
@@ -972,7 +967,8 @@ ParseComment(
while (numBytes) {
if (*p == '\\') {
- scanned = ParseWhiteSpace(p, numBytes, &(parsePtr->incomplete), &type);
+ scanned = ParseWhiteSpace(p, numBytes, &parsePtr->incomplete,
+ &type);
if (scanned) {
p += scanned;
numBytes -= scanned;
@@ -1028,7 +1024,7 @@ ParseComment(
static int
ParseTokens(
- register CONST char *src, /* First character to parse. */
+ 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
@@ -1094,8 +1090,8 @@ ParseTokens(
*/
varToken = parsePtr->numTokens;
- if (Tcl_ParseVarName(parsePtr->interp, src, numBytes,
- parsePtr, 1) != TCL_OK) {
+ if (Tcl_ParseVarName(parsePtr->interp, src, numBytes, parsePtr,
+ 1) != TCL_OK) {
return TCL_ERROR;
}
src += parsePtr->tokenPtr[varToken].size;
@@ -1123,8 +1119,8 @@ ParseTokens(
nestedPtr = (Tcl_Parse *)
TclStackAlloc(parsePtr->interp, sizeof(Tcl_Parse));
while (1) {
- if (Tcl_ParseCommand(parsePtr->interp, src,
- numBytes, 1, nestedPtr) != TCL_OK) {
+ if (Tcl_ParseCommand(parsePtr->interp, src, numBytes, 1,
+ nestedPtr) != TCL_OK) {
parsePtr->errorType = nestedPtr->errorType;
parsePtr->term = nestedPtr->term;
parsePtr->incomplete = nestedPtr->incomplete;
@@ -1141,7 +1137,8 @@ ParseTokens(
* parsed command.
*/
- if ((nestedPtr->term < parsePtr->end) && (*(nestedPtr->term) == ']')
+ if ((nestedPtr->term < parsePtr->end)
+ && (*(nestedPtr->term) == ']')
&& !(nestedPtr->incomplete)) {
break;
}
@@ -1300,13 +1297,14 @@ TclExpandTokenArray(
int newCount = parsePtr->tokensAvailable*2;
if (parsePtr->tokenPtr != parsePtr->staticTokens) {
- parsePtr->tokenPtr = (Tcl_Token *) ckrealloc ((char *)
- (parsePtr->tokenPtr), newCount * sizeof(Tcl_Token));
+ parsePtr->tokenPtr = (Tcl_Token *) ckrealloc((char *)
+ parsePtr->tokenPtr, newCount * sizeof(Tcl_Token));
} else {
- Tcl_Token *newPtr = (Tcl_Token *) ckalloc(
- newCount * sizeof(Tcl_Token));
+ Tcl_Token *newPtr = (Tcl_Token *)
+ ckalloc(newCount * sizeof(Tcl_Token));
+
memcpy(newPtr, parsePtr->tokenPtr,
- (size_t) (parsePtr->tokensAvailable * sizeof(Tcl_Token)));
+ (size_t) parsePtr->tokensAvailable * sizeof(Tcl_Token));
parsePtr->tokenPtr = newPtr;
}
parsePtr->tokensAvailable = newCount;
@@ -1343,7 +1341,7 @@ int
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,
* the string consists of all bytes up to the
@@ -1356,7 +1354,7 @@ Tcl_ParseVarName(
* reinitialize it. */
{
Tcl_Token *tokenPtr;
- register CONST char *src;
+ register const char *src;
unsigned char c;
int varIndex, offset;
Tcl_UniChar ch;
@@ -1379,7 +1377,7 @@ Tcl_ParseVarName(
*/
src = start;
- if ((parsePtr->numTokens + 2) > parsePtr->tokensAvailable) {
+ if (parsePtr->numTokens+2 > parsePtr->tokensAvailable) {
TclExpandTokenArray(parsePtr);
}
tokenPtr = &parsePtr->tokenPtr[parsePtr->numTokens];
@@ -1454,7 +1452,7 @@ Tcl_ParseVarName(
offset = Tcl_UtfToUniChar(utfBytes, &ch);
}
c = UCHAR(ch);
- if (isalnum(c) || (c == '_')) { /* INTL: ISO only, UCHAR. */
+ if (isalnum(c) || (c == '_')) { /* INTL: ISO only, UCHAR. */
src += offset;
numBytes -= offset;
continue;
@@ -1492,7 +1490,7 @@ Tcl_ParseVarName(
TCL_SUBST_ALL, parsePtr)) {
goto error;
}
- if ((parsePtr->term == src+numBytes) || (*parsePtr->term != ')')) {
+ if ((parsePtr->term == src+numBytes) || (*parsePtr->term != ')')){
if (parsePtr->interp != NULL) {
Tcl_SetResult(parsePtr->interp, "missing )",
TCL_STATIC);
@@ -1549,18 +1547,19 @@ Tcl_ParseVarName(
*----------------------------------------------------------------------
*/
-CONST char *
+const char *
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
- * in with character just after last
- * one in the variable specifier. */
+ 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 in with
+ * character just after last one in the
+ * variable specifier. */
{
register Tcl_Obj *objPtr;
int code;
- Tcl_Parse *parsePtr = (Tcl_Parse *) TclStackAlloc(interp, sizeof(Tcl_Parse));
+ Tcl_Parse *parsePtr = (Tcl_Parse *)
+ TclStackAlloc(interp, sizeof(Tcl_Parse));
if (Tcl_ParseVarName(interp, start, -1, parsePtr, 0) != TCL_OK) {
TclStackFree(interp, parsePtr);
@@ -1579,7 +1578,8 @@ Tcl_ParseVar(
return "$";
}
- code = TclSubstTokens(interp, parsePtr->tokenPtr, parsePtr->numTokens, NULL, 1);
+ code = TclSubstTokens(interp, parsePtr->tokenPtr, parsePtr->numTokens,
+ NULL, 1);
TclStackFree(interp, parsePtr);
if (code != TCL_OK) {
return NULL;
@@ -1636,7 +1636,7 @@ int
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,
* the string consists of all bytes up to the
@@ -1648,13 +1648,13 @@ Tcl_ParseBraces(
* 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. */
{
Tcl_Token *tokenPtr;
- register CONST char *src;
+ register const char *src;
int startIndex, level, length;
if ((numBytes == 0) || (start == NULL)) {
@@ -1794,10 +1794,9 @@ Tcl_ParseBraces(
openBrace = 0;
break;
case '#' :
- if (openBrace && (isspace(UCHAR(src[-1])))) {
+ if (openBrace && isspace(UCHAR(src[-1]))) {
Tcl_AppendResult(parsePtr->interp,
- ": possible unbalanced brace in comment",
- (char *) NULL);
+ ": possible unbalanced brace in comment", NULL);
goto error;
}
break;
@@ -1842,7 +1841,7 @@ int
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,
* the string consists of all bytes up to the
@@ -1854,7 +1853,7 @@ Tcl_ParseQuotedString(
* 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. */
@@ -1870,8 +1869,8 @@ Tcl_ParseQuotedString(
TclParseInit(interp, start, numBytes, parsePtr);
}
- if (TCL_OK != ParseTokens(start+1, numBytes-1, TYPE_QUOTE,
- TCL_SUBST_ALL, parsePtr)) {
+ if (TCL_OK != ParseTokens(start+1, numBytes-1, TYPE_QUOTE, TCL_SUBST_ALL,
+ parsePtr)) {
goto error;
}
if (*parsePtr->term != '"') {
@@ -1919,10 +1918,10 @@ Tcl_SubstObj(
{
int length, tokensLeft, code;
Tcl_Token *endTokenPtr;
- Tcl_Obj *result;
- Tcl_Obj *errMsg = NULL;
+ Tcl_Obj *result, *errMsg = NULL;
CONST char *p = TclGetStringFromObj(objPtr, &length);
- Tcl_Parse *parsePtr = (Tcl_Parse *) TclStackAlloc(interp, sizeof(Tcl_Parse));
+ Tcl_Parse *parsePtr = (Tcl_Parse *)
+ TclStackAlloc(interp, sizeof(Tcl_Parse));
TclParseInit(interp, p, length, parsePtr);
@@ -2036,9 +2035,9 @@ Tcl_SubstObj(
*/
Tcl_Token *tokenPtr;
- CONST char *lastTerm = parsePtr->term;
- Tcl_Parse *nestedPtr =
- (Tcl_Parse *) TclStackAlloc(interp, sizeof(Tcl_Parse));
+ const char *lastTerm = parsePtr->term;
+ Tcl_Parse *nestedPtr = (Tcl_Parse *)
+ TclStackAlloc(interp, sizeof(Tcl_Parse));
while (TCL_OK ==
Tcl_ParseCommand(NULL, p, length, 0, nestedPtr)) {
@@ -2178,7 +2177,7 @@ TclSubstTokens(
int *tokensLeftPtr, /* If not NULL, points to memory where an
* integer representing the number of tokens
* left to be substituted will be written */
- int line) /* The line the script starts on. */
+ int line) /* The line the script starts on. */
{
Tcl_Obj *result;
int code = TCL_OK;
@@ -2196,7 +2195,7 @@ TclSubstTokens(
result = NULL;
for (; count>0 && code==TCL_OK ; count--, tokenPtr++) {
Tcl_Obj *appendObj = NULL;
- CONST char *append = NULL;
+ const char *append = NULL;
int appendByteLength = 0;
char utfCharBytes[TCL_UTF_MAX];
@@ -2207,7 +2206,7 @@ TclSubstTokens(
break;
case TCL_TOKEN_BS:
- appendByteLength = Tcl_UtfBackslash(tokenPtr->start, (int *) NULL,
+ appendByteLength = Tcl_UtfBackslash(tokenPtr->start, NULL,
utfCharBytes);
append = utfCharBytes;
break;
@@ -2354,19 +2353,18 @@ TclSubstTokens(
*----------------------------------------------------------------------
*/
-static int
+static inline int
CommandComplete(
- CONST char *script, /* Script to check. */
+ const char *script, /* Script to check. */
int numBytes) /* Number of bytes in script. */
{
Tcl_Parse parse;
- CONST char *p, *end;
+ const char *p, *end;
int result;
p = script;
end = p + numBytes;
- while (Tcl_ParseCommand((Tcl_Interp *) NULL, p, end - p, 0, &parse)
- == TCL_OK) {
+ while (Tcl_ParseCommand(NULL, p, end - p, 0, &parse) == TCL_OK) {
p = parse.commandStart + parse.commandSize;
if (p >= end) {
break;
@@ -2404,7 +2402,7 @@ CommandComplete(
int
Tcl_CommandComplete(
- CONST char *script) /* Script to check. */
+ const char *script) /* Script to check. */
{
return CommandComplete(script, (int) strlen(script));
}
@@ -2432,10 +2430,9 @@ TclObjCommandComplete(
Tcl_Obj *objPtr) /* Points to object holding script to
* check. */
{
- CONST char *script;
int length;
+ const char *script = Tcl_GetStringFromObj(objPtr, &length);
- script = TclGetStringFromObj(objPtr, &length);
return CommandComplete(script, length);
}
@@ -2458,11 +2455,11 @@ TclObjCommandComplete(
int
TclIsLocalScalar(
- CONST char *src,
+ const char *src,
int len)
{
- CONST char *p;
- CONST char *lastChar = src + (len - 1);
+ const char *p;
+ const char *lastChar = src + (len - 1);
for (p=src ; p<=lastChar ; p++) {
if ((CHAR_TYPE(*p) != TYPE_NORMAL) &&
@@ -2476,11 +2473,11 @@ TclIsLocalScalar(
return 0;
}
if (*p == '(') {
- if (*lastChar == ')') { /* we have an array element */
+ if (*lastChar == ')') { /* We have an array element */
return 0;
}
} else if (*p == ':') {
- if ((p != lastChar) && *(p+1) == ':') { /* qualified name */
+ if ((p != lastChar) && *(p+1) == ':') { /* qualified name */
return 0;
}
}
diff --git a/generic/tclPathObj.c b/generic/tclPathObj.c
index b86c728..f0aa398 100644
--- a/generic/tclPathObj.c
+++ b/generic/tclPathObj.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclPathObj.c,v 1.63 2007/05/02 21:30:36 kennykb Exp $
+ * RCS: @(#) $Id: tclPathObj.c,v 1.64 2007/11/18 22:31:09 dkf Exp $
*/
#include "tclInt.h"
@@ -1332,7 +1332,7 @@ TclFSMakePathRelative(
if (interp != NULL) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "can't find object"
- "string representation", (char *) NULL);
+ "string representation", NULL);
}
return NULL;
}
@@ -1454,7 +1454,7 @@ TclFSMakePathFromNormalized(
if (interp != NULL) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "can't find object"
- "string representation", (char *) NULL);
+ "string representation", NULL);
}
return TCL_ERROR;
}
@@ -2326,7 +2326,7 @@ SetFsPathFromAny(
if (interp) {
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "couldn't find HOME environment "
- "variable to expand path", (char *) NULL);
+ "variable to expand path", NULL);
}
return TCL_ERROR;
}
@@ -2342,8 +2342,8 @@ SetFsPathFromAny(
if (TclpGetUserHome(name+1, &temp) == NULL) {
if (interp != NULL) {
Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "user \"", (name+1),
- "\" doesn't exist", (char *) NULL);
+ Tcl_AppendResult(interp, "user \"", name+1,
+ "\" doesn't exist", NULL);
}
Tcl_DStringFree(&temp);
if (split != len) {
diff --git a/generic/tclPkg.c b/generic/tclPkg.c
index 8d30b08..abc0070 100644
--- a/generic/tclPkg.c
+++ b/generic/tclPkg.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclPkg.c,v 1.31 2007/09/19 15:29:21 dgp Exp $
+ * RCS: @(#) $Id: tclPkg.c,v 1.32 2007/11/18 22:30:10 dkf Exp $
*
* TIP #268.
* Heavily rewritten to handle the extend version numbers, and extended
@@ -44,8 +44,8 @@ typedef struct PkgAvail {
typedef struct Package {
char *version; /* Version that has been supplied in this
* interpreter via "package provide"
- * (malloc'ed). NULL means the package
- * doesn't exist in this interpreter yet. */
+ * (malloc'ed). NULL means the package doesn't
+ * exist in this interpreter yet. */
PkgAvail *availPtr; /* First in list of all available versions of
* this package. */
ClientData clientData; /* Client data. */
@@ -56,23 +56,23 @@ typedef struct Package {
*/
static int CheckVersionAndConvert(Tcl_Interp *interp,
- CONST char *string, char **internal, int *stable);
+ const char *string, char **internal, int *stable);
static int CompareVersions(char *v1i, char *v2i,
int *isMajorPtr);
static int CheckRequirement(Tcl_Interp *interp,
- CONST char *string);
+ const char *string);
static int CheckAllRequirements(Tcl_Interp *interp, int reqc,
- Tcl_Obj *CONST reqv[]);
-static int RequirementSatisfied(char *havei, CONST char *req);
+ Tcl_Obj *const reqv[]);
+static int RequirementSatisfied(char *havei, const char *req);
static int SomeRequirementSatisfied(char *havei, int reqc,
- Tcl_Obj *CONST reqv[]);
+ Tcl_Obj *const reqv[]);
static void AddRequirementsToResult(Tcl_Interp *interp, int reqc,
- Tcl_Obj *CONST reqv[]);
+ Tcl_Obj *const reqv[]);
static void AddRequirementsToDString(Tcl_DString *dstring,
- int reqc, Tcl_Obj *CONST reqv[]);
-static Package * FindPackage(Tcl_Interp *interp, CONST char *name);
-static const char * PkgRequireCore(Tcl_Interp *interp, CONST char *name,
- int reqc, Tcl_Obj *CONST reqv[],
+ int reqc, Tcl_Obj *const reqv[]);
+static Package * FindPackage(Tcl_Interp *interp, const char *name);
+static const char * PkgRequireCore(Tcl_Interp *interp, const char *name,
+ int reqc, Tcl_Obj *const reqv[],
ClientData *clientDataPtr);
/*
@@ -112,8 +112,8 @@ int
Tcl_PkgProvide(
Tcl_Interp *interp, /* Interpreter in which package is now
* available. */
- CONST char *name, /* Name of package. */
- CONST char *version) /* Version string for package. */
+ const char *name, /* Name of package. */
+ const char *version) /* Version string for package. */
{
return Tcl_PkgProvideEx(interp, name, version, NULL);
}
@@ -122,8 +122,8 @@ int
Tcl_PkgProvideEx(
Tcl_Interp *interp, /* Interpreter in which package is now
* available. */
- CONST char *name, /* Name of package. */
- CONST char *version, /* Version string for package. */
+ const char *name, /* Name of package. */
+ const char *version, /* Version string for package. */
ClientData clientData) /* clientdata for this package (normally used
* for C callback function table) */
{
@@ -188,12 +188,12 @@ Tcl_PkgProvideEx(
*----------------------------------------------------------------------
*/
-CONST char *
+const char *
Tcl_PkgRequire(
Tcl_Interp *interp, /* Interpreter in which package is now
* available. */
- CONST char *name, /* Name of desired package. */
- CONST char *version, /* Version string for desired version; NULL
+ const char *name, /* Name of desired package. */
+ const char *version, /* Version string for desired version; NULL
* means use the latest version available. */
int exact) /* Non-zero means that only the particular
* version given is acceptable. Zero means use
@@ -202,12 +202,12 @@ Tcl_PkgRequire(
return Tcl_PkgRequireEx(interp, name, version, exact, NULL);
}
-CONST char *
+const char *
Tcl_PkgRequireEx(
Tcl_Interp *interp, /* Interpreter in which package is now
* available. */
- CONST char *name, /* Name of desired package. */
- CONST char *version, /* Version string for desired version; NULL
+ const char *name, /* Name of desired package. */
+ const char *version, /* Version string for desired version; NULL
* means use the latest version available. */
int exact, /* Non-zero means that only the particular
* version given is acceptable. Zero means use
@@ -291,12 +291,14 @@ Tcl_PkgRequireEx(
return NULL;
}
- /* Translate between old and new API, and defer to the new function. */
+ /*
+ * Translate between old and new API, and defer to the new function.
+ */
if (version == NULL) {
result = PkgRequireCore(interp, name, 0, NULL, clientDataPtr);
} else {
- if (exact && TCL_OK
+ if (exact && TCL_OK
!= CheckVersionAndConvert(interp, version, NULL, NULL)) {
return NULL;
}
@@ -316,10 +318,10 @@ int
Tcl_PkgRequireProc(
Tcl_Interp *interp, /* Interpreter in which package is now
* available. */
- CONST char *name, /* Name of desired package. */
+ const char *name, /* Name of desired package. */
int reqc, /* Requirements constraining the desired
* version. */
- Tcl_Obj *CONST reqv[], /* 0 means to use the latest version
+ Tcl_Obj *const reqv[], /* 0 means to use the latest version
* available. */
ClientData *clientDataPtr)
{
@@ -337,10 +339,10 @@ static const char *
PkgRequireCore(
Tcl_Interp *interp, /* Interpreter in which package is now
* available. */
- CONST char *name, /* Name of desired package. */
+ const char *name, /* Name of desired package. */
int reqc, /* Requirements constraining the desired
* version. */
- Tcl_Obj *CONST reqv[], /* 0 means to use the latest version
+ Tcl_Obj *const reqv[], /* 0 means to use the latest version
* available. */
ClientData *clientDataPtr)
{
@@ -349,11 +351,9 @@ PkgRequireCore(
PkgAvail *availPtr, *bestPtr, *bestStablePtr;
char *availVersion, *bestVersion;
/* Internal rep. of versions */
- int availStable;
- char *script;
- int code, satisfies, pass;
+ int availStable, code, satisfies, pass;
+ char *script, *pkgVersionI;
Tcl_DString command;
- char *pkgVersionI;
/*
* It can take up to three passes to find the package: one pass to run the
@@ -368,9 +368,9 @@ PkgRequireCore(
break;
}
- /*
- * Check whether we're already attempting to load some version
- * of this package (circular dependency detection).
+ /*
+ * Check whether we're already attempting to load some version of this
+ * package (circular dependency detection).
*/
if (pkgPtr->clientData != NULL) {
@@ -408,7 +408,10 @@ PkgRequireCore(
if (bestPtr != NULL) {
int res = CompareVersions(availVersion, bestVersion, NULL);
- /* Note: Use internal reps! */
+ /*
+ * Note: Use internal reps!
+ */
+
if (res <= 0) {
/*
* The version of the package sought is not as good as the
@@ -474,7 +477,7 @@ PkgRequireCore(
* will still exist when the script completes.
*/
- CONST char *versionToProvide = bestPtr->version;
+ const char *versionToProvide = bestPtr->version;
script = bestPtr->script;
pkgPtr->clientData = (ClientData) versionToProvide;
@@ -494,7 +497,6 @@ PkgRequireCore(
" provided", NULL);
} else {
char *pvi, *vi;
- int res;
if (CheckVersionAndConvert(interp, pkgPtr->version, &pvi,
NULL) != TCL_OK) {
@@ -504,10 +506,10 @@ PkgRequireCore(
ckfree(pvi);
code = TCL_ERROR;
} else {
- res = CompareVersions(pvi, vi, NULL);
+ int res = CompareVersions(pvi, vi, NULL);
+
ckfree(pvi);
ckfree(vi);
-
if (res != 0) {
code = TCL_ERROR;
Tcl_AppendResult(interp,
@@ -520,10 +522,11 @@ PkgRequireCore(
}
} else if (code != TCL_ERROR) {
Tcl_Obj *codePtr = Tcl_NewIntObj(code);
+
Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "attempt to provide package ",
- name, " ", versionToProvide, " failed: "
- "bad return code: ", TclGetString(codePtr), NULL);
+ Tcl_AppendResult(interp, "attempt to provide package ", name,
+ " ", versionToProvide, " failed: bad return code: ",
+ TclGetString(codePtr), NULL);
TclDecrRefCount(codePtr);
code = TCL_ERROR;
}
@@ -650,12 +653,12 @@ PkgRequireCore(
*----------------------------------------------------------------------
*/
-CONST char *
+const char *
Tcl_PkgPresent(
Tcl_Interp *interp, /* Interpreter in which package is now
* available. */
- CONST char *name, /* Name of desired package. */
- CONST char *version, /* Version string for desired version; NULL
+ const char *name, /* Name of desired package. */
+ const char *version, /* Version string for desired version; NULL
* means use the latest version available. */
int exact) /* Non-zero means that only the particular
* version given is acceptable. Zero means use
@@ -664,12 +667,12 @@ Tcl_PkgPresent(
return Tcl_PkgPresentEx(interp, name, version, exact, NULL);
}
-CONST char *
+const char *
Tcl_PkgPresentEx(
Tcl_Interp *interp, /* Interpreter in which package is now
* available. */
- CONST char *name, /* Name of desired package. */
- CONST char *version, /* Version string for desired version; NULL
+ const char *name, /* Name of desired package. */
+ const char *version, /* Version string for desired version; NULL
* means use the latest version available. */
int exact, /* Non-zero means that only the particular
* version given is acceptable. Zero means use
@@ -731,9 +734,9 @@ Tcl_PackageObjCmd(
ClientData dummy, /* Not used. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
+ Tcl_Obj *const objv[]) /* Argument objects. */
{
- static CONST char *pkgOptions[] = {
+ static const char *pkgOptions[] = {
"forget", "ifneeded", "names", "prefer", "present",
"provide", "require", "unknown", "vcompare", "versions",
"vsatisfies", NULL
@@ -750,7 +753,7 @@ Tcl_PackageObjCmd(
Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
Tcl_HashTable *tablePtr;
- CONST char *version;
+ const char *version;
char *argv2, *argv3, *argv4, *iva = NULL, *ivb = NULL;
if (objc < 2) {
@@ -815,7 +818,6 @@ Tcl_PackageObjCmd(
for (availPtr = pkgPtr->availPtr, prevPtr = NULL; availPtr != NULL;
prevPtr = availPtr, availPtr = availPtr->nextPtr) {
-
if (CheckVersionAndConvert(interp, availPtr->version, &avi,
NULL) != TCL_OK) {
ckfree(argv3i);
@@ -1007,7 +1009,7 @@ Tcl_PackageObjCmd(
break;
}
case PKG_PREFER: {
- static CONST char *pkgPreferOptions[] = {
+ static const char *pkgPreferOptions[] = {
"latest", "stable", NULL
};
@@ -1137,7 +1139,7 @@ Tcl_PackageObjCmd(
static Package *
FindPackage(
Tcl_Interp *interp, /* Interpreter to use for package lookup. */
- CONST char *name) /* Name of package to fine. */
+ const char *name) /* Name of package to fine. */
{
Interp *iPtr = (Interp *) interp;
Tcl_HashEntry *hPtr;
@@ -1227,13 +1229,13 @@ TclFreePackageInfo(
static int
CheckVersionAndConvert(
Tcl_Interp *interp, /* Used for error reporting. */
- CONST char *string, /* Supposedly a version number, which is
+ const char *string, /* Supposedly a version number, which is
* groups of decimal digits separated by
* dots. */
char **internal, /* Internal normalized representation */
int *stable) /* Flag: Version is (un)stable. */
{
- CONST char *p = string;
+ const char *p = string;
char prevChar;
int hasunstable = 0;
/*
@@ -1481,7 +1483,10 @@ CompareVersions(
if (*s1 != 0) {
s1++;
} else if (*s2 == 0) {
- /* s1, s2 both at the end => identical */
+ /*
+ * s1, s2 both at the end => identical
+ */
+
res = 0;
break;
}
@@ -1520,7 +1525,7 @@ static int
CheckAllRequirements(
Tcl_Interp *interp,
int reqc, /* Requirements to check. */
- Tcl_Obj *CONST reqv[])
+ Tcl_Obj *const reqv[])
{
int i;
@@ -1553,7 +1558,7 @@ CheckAllRequirements(
static int
CheckRequirement(
Tcl_Interp *interp, /* Used for error reporting. */
- CONST char *string) /* Supposedly a requirement. */
+ const char *string) /* Supposedly a requirement. */
{
/*
* Syntax of requirement = version
@@ -1566,7 +1571,7 @@ CheckRequirement(
dash = strchr(string, '-');
if (dash == NULL) {
/*
- * no dash found, has to be a simple version.
+ * No dash found, has to be a simple version.
*/
return CheckVersionAndConvert(interp, string, NULL, NULL);
@@ -1585,7 +1590,8 @@ CheckRequirement(
/*
* Exactly one dash is present. Copy the string, split at the location of
* dash and check that both parts are versions. Note that the max part can
- * be empty.
+ * be empty. Also note that the string allocated with strdup() must be
+ * freed with free() and not ckfree().
*/
DupString(buf, string);
@@ -1625,7 +1631,7 @@ AddRequirementsToResult(
Tcl_Interp *interp,
int reqc, /* Requirements constraining the desired
* version. */
- Tcl_Obj *CONST reqv[]) /* 0 means to use the latest version
+ Tcl_Obj *const reqv[]) /* 0 means to use the latest version
* available. */
{
if (reqc > 0) {
@@ -1666,7 +1672,7 @@ AddRequirementsToDString(
Tcl_DString *dsPtr,
int reqc, /* Requirements constraining the desired
* version. */
- Tcl_Obj *CONST reqv[]) /* 0 means to use the latest version
+ Tcl_Obj *const reqv[]) /* 0 means to use the latest version
* available. */
{
if (reqc > 0) {
@@ -1706,7 +1712,7 @@ SomeRequirementSatisfied(
* requirements. */
int reqc, /* Requirements constraining the desired
* version. */
- Tcl_Obj *CONST reqv[]) /* 0 means to use the latest version
+ Tcl_Obj *const reqv[]) /* 0 means to use the latest version
* available. */
{
int i;
@@ -1741,7 +1747,7 @@ static int
RequirementSatisfied(
char *havei, /* Version string, of candidate package we
* have. */
- CONST char *req) /* Requirement string the candidate has to
+ const char *req) /* Requirement string the candidate has to
* satisfy. */
{
/*
@@ -1839,16 +1845,16 @@ RequirementSatisfied(
*----------------------------------------------------------------------
*/
-CONST char *
+const char *
Tcl_PkgInitStubsCheck(
Tcl_Interp *interp,
- CONST char * version,
+ const char * version,
int exact)
{
- CONST char *actualVersion = Tcl_PkgPresent(interp, "Tcl", version, 0);
+ const char *actualVersion = Tcl_PkgPresent(interp, "Tcl", version, 0);
if (exact && actualVersion) {
- CONST char *p = version;
+ const char *p = version;
int count = 0;
while (*p) {
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index dc19855..a719556 100755
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -9,12 +9,12 @@
* into strings of digits, and procedures for interconversion among
* 'double' and 'mp_int' types.
*
- * Copyright (c) 2005 by Kevin B. Kenny. All rights reserved.
+ * Copyright (c) 2005 by Kevin B. Kenny. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStrToD.c,v 1.30 2007/04/23 17:34:07 kennykb Exp $
+ * RCS: @(#) $Id: tclStrToD.c,v 1.31 2007/11/18 22:30:10 dkf Exp $
*
*----------------------------------------------------------------------
*/
@@ -146,22 +146,21 @@ static double SafeLdExp(double fraction, int exponent);
*
* TclParseNumber --
*
- * Scans bytes, interpreted as characters in Tcl's internal encoding,
- * and parses the longest prefix that is the string representation of
- * a number in a format recognized by Tcl.
+ * Scans bytes, interpreted as characters in Tcl's internal encoding, and
+ * parses the longest prefix that is the string representation of a
+ * number in a format recognized by Tcl.
*
* The arguments bytes, numBytes, and objPtr are the inputs which
- * determine the string to be parsed. If bytes is non-NULL, it
- * points to the first byte to be scanned. If bytes is NULL, then objPtr
- * must be non-NULL, and the string representation of objPtr will be
- * scanned (generated first, if necessary). The numBytes argument
- * determines the number of bytes to be scanned. If numBytes is
- * negative, the first NUL byte encountered will terminate the scan.
- * If numBytes is non-negative, then no more than numBytes bytes will
- * be scanned.
+ * determine the string to be parsed. If bytes is non-NULL, it points to
+ * the first byte to be scanned. If bytes is NULL, then objPtr must be
+ * non-NULL, and the string representation of objPtr will be scanned
+ * (generated first, if necessary). The numBytes argument determines the
+ * number of bytes to be scanned. If numBytes is negative, the first NUL
+ * byte encountered will terminate the scan. If numBytes is non-negative,
+ * then no more than numBytes bytes will be scanned.
*
* The argument flags is an input that controls the numeric formats
- * recognized by the parser. The flag bits are:
+ * recognized by the parser. The flag bits are:
*
* - TCL_PARSE_INTEGER_ONLY: accept only integer values; reject
* strings that denote floating point values (or accept only the
@@ -170,70 +169,72 @@ static double SafeLdExp(double fraction, int exponent);
* not part of the [scan] command's vocabulary. Use only in
* combination with TCL_PARSE_INTEGER_ONLY.
* - TCL_PARSE_OCTAL_ONLY: parse only in the octal format, whether
- * or not a prefix is present that would lead to octal parsing. Use
- * only in combination with TCL_PARSE_INTEGER_ONLY.
+ * or not a prefix is present that would lead to octal parsing.
+ * Use only in combination with TCL_PARSE_INTEGER_ONLY.
* - TCL_PARSE_HEXADECIMAL_ONLY: parse only in the hexadecimal format,
* whether or not a prefix is present that would lead to
* hexadecimal parsing. Use only in combination with
* TCL_PARSE_INTEGER_ONLY.
* - TCL_PARSE_DECIMAL_ONLY: parse only in the decimal format, no
- * matter whether a 0 prefix would normally force a different base.
+ * matter whether a 0 prefix would normally force a different
+ * base.
* - TCL_PARSE_NO_WHITESPACE: reject any leading/trailing whitespace
*
- * The arguments interp and expected are inputs that control error message
- * generation. If interp is NULL, no error message will be generated.
- * If interp is non-NULL, then expected must also be non-NULL. When
- * TCL_ERROR is returned, an error message will be left in the result
- * of interp, and the expected argument will appear in the error message
- * as the thing TclParseNumber expected, but failed to find in the string.
+ * The arguments interp and expected are inputs that control error
+ * message generation. If interp is NULL, no error message will be
+ * generated. If interp is non-NULL, then expected must also be non-NULL.
+ * When TCL_ERROR is returned, an error message will be left in the
+ * result of interp, and the expected argument will appear in the error
+ * message as the thing TclParseNumber expected, but failed to find in
+ * the string.
*
* The arguments objPtr and endPtrPtr as well as the return code are the
* outputs.
*
* When the parser cannot find any prefix of the string that matches a
* format it is looking for, TCL_ERROR is returned and an error message
- * may be generated and returned as described above. The contents of
- * objPtr will not be changed. If endPtrPtr is non-NULL, a pointer to
- * the character in the string that terminated the scan will be written
- * to *endPtrPtr.
- *
- * When the parser determines that the entire string matches a format
- * it is looking for, TCL_OK is returned, and if objPtr is non-NULL,
- * then the internal rep and Tcl_ObjType of objPtr are set to the
- * "canonical" numeric value that matches the scanned string. If
- * endPtrPtr is non-NULL, a pointer to the end of the string will be
- * written to *endPtrPtr (that is, either bytes+numBytes or a pointer
- * to a terminating NUL byte).
- *
- * When the parser determines that a partial string matches a format
- * it is looking for, the value of endPtrPtr determines what happens:
+ * may be generated and returned as described above. The contents of
+ * objPtr will not be changed. If endPtrPtr is non-NULL, a pointer to the
+ * character in the string that terminated the scan will be written to
+ * *endPtrPtr.
+ *
+ * When the parser determines that the entire string matches a format it
+ * is looking for, TCL_OK is returned, and if objPtr is non-NULL, then
+ * the internal rep and Tcl_ObjType of objPtr are set to the "canonical"
+ * numeric value that matches the scanned string. If endPtrPtr is not
+ * NULL, a pointer to the end of the string will be written to *endPtrPtr
+ * (that is, either bytes+numBytes or a pointer to a terminating NUL
+ * byte).
+ *
+ * When the parser determines that a partial string matches a format it
+ * is looking for, the value of endPtrPtr determines what happens:
*
* - If endPtrPtr is NULL, then TCL_ERROR is returned, with error message
* generation as above.
*
* - If endPtrPtr is non-NULL, then TCL_OK is returned and objPtr
- * internals are set as above. Also, a pointer to the first
- * character following the parsed numeric string is written
- * to *endPtrPtr.
+ * internals are set as above. Also, a pointer to the first
+ * character following the parsed numeric string is written to
+ * *endPtrPtr.
*
* In some cases where the string being scanned is the string rep of
- * objPtr, this routine can leave objPtr in an inconsistent state
- * where its string rep and its internal rep do not agree. In these
- * cases the internal rep will be in agreement with only some substring
- * of the string rep. This might happen if the caller passes in a
- * non-NULL bytes value that points somewhere into the string rep. It
- * might happen if the caller passes in a numBytes value that limits the
- * scan to only a prefix of the string rep. Or it might happen if a
- * non-NULL value of endPtrPtr permits a TCL_OK return from only a partial
- * string match. It is the responsibility of the caller to detect and
- * correct such inconsistencies when they can and do arise.
+ * objPtr, this routine can leave objPtr in an inconsistent state where
+ * its string rep and its internal rep do not agree. In these cases the
+ * internal rep will be in agreement with only some substring of the
+ * string rep. This might happen if the caller passes in a non-NULL bytes
+ * value that points somewhere into the string rep. It might happen if
+ * the caller passes in a numBytes value that limits the scan to only a
+ * prefix of the string rep. Or it might happen if a non-NULL value of
+ * endPtrPtr permits a TCL_OK return from only a partial string match. It
+ * is the responsibility of the caller to detect and correct such
+ * inconsistencies when they can and do arise.
*
* Results:
* Returns a standard Tcl result.
*
* Side effects:
* The string representaton of objPtr may be generated.
- *
+ *
* The internal representation and Tcl_ObjType of objPtr may be changed.
* This may involve allocation and/or freeing of memory.
*
@@ -242,21 +243,23 @@ static double SafeLdExp(double fraction, int exponent);
int
TclParseNumber(
- Tcl_Interp *interp, /* Used for error reporting. May be NULL */
- Tcl_Obj *objPtr, /* Object to receive the internal rep */
- const char *expected, /* Description of the type of number the caller
- * expects to be able to parse ("integer",
- * "boolean value", etc.). */
- const char *bytes, /* Pointer to the start of the string to scan */
- int numBytes, /* Maximum number of bytes to scan, see above */
+ Tcl_Interp *interp, /* Used for error reporting. May be NULL. */
+ Tcl_Obj *objPtr, /* Object to receive the internal rep. */
+ const char *expected, /* Description of the type of number the
+ * caller expects to be able to parse
+ * ("integer", "boolean value", etc.). */
+ const char *bytes, /* Pointer to the start of the string to
+ * scan. */
+ int numBytes, /* Maximum number of bytes to scan, see
+ * above. */
const char **endPtrPtr, /* Place to store pointer to the character
- * that terminated the scan */
- int flags) /* Flags governing the parse */
+ * that terminated the scan. */
+ int flags) /* Flags governing the parse. */
{
enum State {
- INITIAL, SIGNUM, ZERO, ZERO_X,
+ INITIAL, SIGNUM, ZERO, ZERO_X,
ZERO_O, ZERO_B, BINARY,
- HEXADECIMAL, OCTAL, BAD_OCTAL, DECIMAL,
+ HEXADECIMAL, OCTAL, BAD_OCTAL, DECIMAL,
LEADING_RADIX_POINT, FRACTION,
EXPONENT_START, EXPONENT_SIGNUM, EXPONENT,
sI, sIN, sINF, sINFI, sINFIN, sINFINI, sINFINIT, sINFINITY
@@ -306,7 +309,7 @@ TclParseNumber(
#define ALL_BITS (~(Tcl_WideUInt)0)
#define MOST_BITS (ALL_BITS >> 1)
- /*
+ /*
* Initialize bytes to start of the object's string rep if the caller
* didn't pass anything else.
*/
@@ -341,9 +344,9 @@ TclParseNumber(
signum = 1;
state = SIGNUM;
break;
- }
+ }
/* FALLTHROUGH */
-
+
case SIGNUM:
/*
* Scanned a leading + or -. Acceptable characters are digits,
@@ -449,10 +452,11 @@ TclParseNumber(
* too large shifts first.
*/
- if ((octalSignificandWide != 0)
- && (((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt))
- || (octalSignificandWide
- > (~(Tcl_WideUInt)0 >> shift)))) {
+ if ((octalSignificandWide != 0)
+ && (((size_t)shift >=
+ CHAR_BIT*sizeof(Tcl_WideUInt))
+ || (octalSignificandWide >
+ (~(Tcl_WideUInt)0 >> shift)))) {
octalSignificandOverflow = 1;
TclBNInitBignumFromWideUInt(&octalSignificandBig,
octalSignificandWide);
@@ -482,8 +486,7 @@ TclParseNumber(
case BAD_OCTAL:
if (explicitOctal) {
/*
- * No forgiveness for bad digits in explicitly octal
- * numbers.
+ * No forgiveness for bad digits in explicitly octal numbers.
*/
goto endgame;
@@ -528,7 +531,7 @@ TclParseNumber(
} else if (c == 'E' || c == 'e') {
state = EXPONENT_START;
break;
- }
+ }
#endif
goto endgame;
@@ -646,8 +649,8 @@ TclParseNumber(
} else if (isdigit(UCHAR(c))) {
if (objPtr != NULL) {
significandOverflow = AccumulateDecimalDigit(
- (unsigned)(c - '0'), numTrailZeros,
- &significandWide, &significandBig,
+ (unsigned)(c - '0'), numTrailZeros,
+ &significandWide, &significandBig,
significandOverflow);
}
numSigDigs += numTrailZeros+1;
@@ -665,7 +668,7 @@ TclParseNumber(
}
goto endgame;
- /*
+ /*
* Found a decimal point. If no digits have yet been scanned, E is
* not allowed; otherwise, it introduces the exponent. If at least
* one digit has been found, we have a possible complete number.
@@ -691,8 +694,8 @@ TclParseNumber(
++numDigitsAfterDp;
if (objPtr != NULL) {
significandOverflow = AccumulateDecimalDigit(
- (unsigned)(c-'0'), numTrailZeros,
- &significandWide, &significandBig,
+ (unsigned)(c-'0'), numTrailZeros,
+ &significandWide, &significandBig,
significandOverflow);
}
if (numSigDigs != 0) {
@@ -707,7 +710,7 @@ TclParseNumber(
goto endgame;
case EXPONENT_START:
- /*
+ /*
* Scanned the E at the start of an exponent. Make sure a legal
* character follows before using the C library strtol routine,
* which allows whitespace.
@@ -737,7 +740,7 @@ TclParseNumber(
goto endgame;
case EXPONENT:
- /*
+ /*
* Found an exponent with at least one digit. Accumulate it,
* making sure to hard-pin it to LONG_MAX on overflow.
*/
@@ -765,13 +768,13 @@ TclParseNumber(
if (c == 'n' || c == 'N') {
state = sIN;
break;
- }
+ }
goto endgame;
case sIN:
if (c == 'f' || c == 'F') {
state = sINF;
break;
- }
+ }
goto endgame;
case sINF:
acceptState = state;
@@ -868,23 +871,32 @@ TclParseNumber(
acceptLen = len;
goto endgame;
}
- ++p;
+ ++p;
--len;
}
endgame:
if (acceptState == INITIAL) {
- /* No numeric string at all found */
+ /*
+ * No numeric string at all found.
+ */
+
status = TCL_ERROR;
if (endPtrPtr != NULL) {
*endPtrPtr = p;
}
} else {
- /* Back up to the last accepting state in the lexer. */
+ /*
+ * Back up to the last accepting state in the lexer.
+ */
+
p = acceptPoint;
len = acceptLen;
if (!(flags & TCL_PARSE_NO_WHITESPACE)) {
- /* Accept trailing whitespace */
+ /*
+ * Accept trailing whitespace.
+ */
+
while (len != 0 && isspace(UCHAR(*p))) {
++p;
--len;
@@ -987,7 +999,7 @@ TclParseNumber(
}
}
if (!octalSignificandOverflow) {
- if (octalSignificandWide >
+ if (octalSignificandWide >
(Tcl_WideUInt)(((~(unsigned long)0) >> 1) + signum)) {
#ifndef NO_WIDE_TYPE
if (octalSignificandWide <= (MOST_BITS + signum)) {
@@ -1021,7 +1033,7 @@ TclParseNumber(
mp_neg(&octalSignificandBig, &octalSignificandBig);
}
TclSetBignumIntRep(objPtr, &octalSignificandBig);
- }
+ }
break;
case ZERO:
@@ -1034,7 +1046,7 @@ TclParseNumber(
}
returnInteger:
if (!significandOverflow) {
- if (significandWide >
+ if (significandWide >
(Tcl_WideUInt)(((~(unsigned long)0) >> 1) + signum)) {
#ifndef NO_WIDE_TYPE
if (significandWide <= MOST_BITS+signum) {
@@ -1194,6 +1206,7 @@ AccumulateDecimalDigit(
/*
* There's no need to multiply if the multiplicand is zero.
*/
+
*wideRepPtr = digit;
return 0;
} else if (numZeros >= maxpow10_wide
@@ -1202,7 +1215,7 @@ AccumulateDecimalDigit(
* Wide multiplication will overflow. Expand the
* number to a bignum and fall through into the bignum case.
*/
-
+
TclBNInitBignumFromWideUInt (bignumRepPtr, w);
} else {
/*
@@ -1226,7 +1239,7 @@ AccumulateDecimalDigit(
bignumRepPtr);
mp_add_d(bignumRepPtr, (mp_digit) digit, bignumRepPtr);
} else {
- /*
+ /*
* More than single digit multiplication. Multiply by the appropriate
* small powers of 5, and then shift. Large strings of zeroes are
* eaten 256 at a time; this is less efficient than it could be, but
@@ -1304,7 +1317,7 @@ MakeLowPrecisionDouble(
if (numSigDigs <= DBL_DIG) {
if (exponent >= 0) {
if (exponent <= mmaxpow) {
- /*
+ /*
* The significand is an exact integer, and so is
* 10**exponent. The product will be correct to within 1/2 ulp
* without special handling.
@@ -1315,7 +1328,7 @@ MakeLowPrecisionDouble(
} else {
int diff = DBL_DIG - numSigDigs;
if (exponent-diff <= mmaxpow) {
- /*
+ /*
* 10**exponent is not an exact integer, but
* 10**(exponent-diff) is exact, and so is
* significand*10**diff, so we can still compute the value
@@ -1330,7 +1343,7 @@ MakeLowPrecisionDouble(
}
} else {
if (exponent >= -mmaxpow) {
- /*
+ /*
* 10**-exponent is an exact integer, and so is the
* significand. Compute the result by one division, again with
* only one rounding.
@@ -1351,7 +1364,7 @@ MakeLowPrecisionDouble(
retval = MakeHighPrecisionDouble(0, &significandBig, numSigDigs,
exponent);
mp_clear(&significandBig);
-
+
/*
* Come here to return the computed value.
*/
@@ -1428,7 +1441,7 @@ MakeHighPrecisionDouble(
goto returnValue;
}
- /*
+ /*
* Develop a first approximation to the significand. It is tempting simply
* to force bignum to double, but that will overflow on input numbers like
* 1.[string repeat 0 1000]1; while this is a not terribly likely
@@ -1448,7 +1461,7 @@ MakeHighPrecisionDouble(
retval = tiny;
}
- /*
+ /*
* Refine the result twice. (The second refinement should be necessary
* only if the best approximation is a power of 2 minus 1/2 ulp).
*/
@@ -1585,7 +1598,7 @@ RefineApproximation(
}
}
- /*
+ /*
* The floating point number is significand*2**binExponent. Compute the
* large integer significand*2**(binExponent+M2+1). The 2**-1 bit of the
* significand (the most significant) corresponds to the
@@ -1610,8 +1623,8 @@ RefineApproximation(
mp_mul(&twoMv, pow5+i, &twoMv);
}
}
-
- /*
+
+ /*
* Collect the decimal significand as a high precision integer. The least
* significant bit corresponds to bit M2+exponent+1 so it will need to be
* shifted left by that many bits after being multiplied by
@@ -1659,7 +1672,7 @@ RefineApproximation(
return approxResult;
}
- /*
+ /*
* Convert the numerator and denominator of the corrector term accurately
* to floating point numbers.
*/
@@ -1752,8 +1765,8 @@ TclDoubleDigits(
return 1;
}
- /*
- * Find a large integer r, and integer e, such that
+ /*
+ * Find a large integer r, and integer e, such that
* v = r * FLT_RADIX**e
* and r is as small as possible. Also determine whether the significand
* is the smallest possible.
@@ -2153,7 +2166,7 @@ TclInitDoubleConversion(void)
mantBits = DBL_MANT_DIG * log2FLT_RADIX;
d = 1.0;
- /*
+ /*
* Initialize a table of powers of ten that can be exactly represented
* in a double.
*/
@@ -2181,10 +2194,10 @@ TclInitDoubleConversion(void)
mp_sqr(pow5+i, pow5+i+1);
}
- /*
+ /*
* Determine the number of decimal digits to the left and right of the
* decimal point in the largest and smallest double, the smallest double
- * that differs from zero, and the number of mp_digits needed to represent
+ * that differs from zero, and the number of mp_digits needed to represent
* the significand of a double.
*/
@@ -2197,8 +2210,8 @@ TclInitDoubleConversion(void)
log10_DIGIT_MAX = (int) floor(DIGIT_BIT * log(2.) / log(10.));
/*
- * Nokia 770's software-emulated floating point is "middle endian":
- * the bytes within a 32-bit word are little-endian (like the native
+ * Nokia 770's software-emulated floating point is "middle endian": the
+ * bytes within a 32-bit word are little-endian (like the native
* integers), but the two words of a 'double' are presented most
* significant word first.
*/
@@ -2255,8 +2268,8 @@ TclFinalizeDoubleConversion(void)
* None.
*
* Side effects:
- * Initializes the bignum supplied, and stores the converted number
- * in it.
+ * Initializes the bignum supplied, and stores the converted number in
+ * it.
*
*----------------------------------------------------------------------
*/
@@ -2557,7 +2570,7 @@ Pow10TimesFrExp(
/*
* Multiply by 10**exponent
*/
-
+
retval = frexp(retval * pow10[exponent&0xf], &j);
expt += j;
for (i=4; i<9; ++i) {
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index bdfe6f2..c21c22b 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -33,7 +33,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStringObj.c,v 1.66 2007/11/11 19:32:17 msofer Exp $ */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.67 2007/11/18 22:30:10 dkf Exp $ */
#include "tclInt.h"
#include "tommath.h"
@@ -43,16 +43,16 @@
*/
static void AppendUnicodeToUnicodeRep(Tcl_Obj *objPtr,
- CONST Tcl_UniChar *unicode, int appendNumChars);
+ const Tcl_UniChar *unicode, int appendNumChars);
static void AppendUnicodeToUtfRep(Tcl_Obj *objPtr,
- CONST Tcl_UniChar *unicode, int numChars);
+ const Tcl_UniChar *unicode, int numChars);
static void AppendUtfToUnicodeRep(Tcl_Obj *objPtr,
- CONST char *bytes, int numBytes);
+ const char *bytes, int numBytes);
static void AppendUtfToUtfRep(Tcl_Obj *objPtr,
- CONST char *bytes, int numBytes);
+ const char *bytes, int numBytes);
static void FillUnicodeRep(Tcl_Obj *objPtr);
static void AppendPrintfToObjVA(Tcl_Obj *objPtr,
- CONST char *format, va_list argList);
+ const char *format, va_list argList);
static void FreeStringInternalRep(Tcl_Obj *objPtr);
static void DupStringInternalRep(Tcl_Obj *objPtr,
Tcl_Obj *copyPtr);
@@ -183,7 +183,7 @@ typedef struct String {
#undef Tcl_NewStringObj
Tcl_Obj *
Tcl_NewStringObj(
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the new object. */
int length) /* The number of bytes to copy from "bytes"
* when initializing the new object. If
@@ -195,7 +195,7 @@ Tcl_NewStringObj(
#else /* if not TCL_MEM_DEBUG */
Tcl_Obj *
Tcl_NewStringObj(
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the new object. */
int length) /* The number of bytes to copy from "bytes"
* when initializing the new object. If
@@ -244,13 +244,13 @@ Tcl_NewStringObj(
#ifdef TCL_MEM_DEBUG
Tcl_Obj *
Tcl_DbNewStringObj(
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the new object. */
int length, /* The number of bytes to copy from "bytes"
* when initializing the new object. If
* negative, use bytes up to the first NUL
* byte. */
- CONST char *file, /* The name of the source file calling this
+ const char *file, /* The name of the source file calling this
* function; used for debugging. */
int line) /* Line number in the source file; used for
* debugging. */
@@ -267,13 +267,13 @@ Tcl_DbNewStringObj(
#else /* if not TCL_MEM_DEBUG */
Tcl_Obj *
Tcl_DbNewStringObj(
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the new object. */
register int length, /* The number of bytes to copy from "bytes"
* when initializing the new object. If
* negative, use bytes up to the first NUL
* byte. */
- CONST char *file, /* The name of the source file calling this
+ const char *file, /* The name of the source file calling this
* function; used for debugging. */
int line) /* Line number in the source file; used for
* debugging. */
@@ -303,7 +303,7 @@ Tcl_DbNewStringObj(
Tcl_Obj *
Tcl_NewUnicodeObj(
- CONST Tcl_UniChar *unicode, /* The unicode string used to initialize the
+ const Tcl_UniChar *unicode, /* The unicode string used to initialize the
* new object. */
int numChars) /* Number of characters in the unicode
* string. */
@@ -335,7 +335,7 @@ Tcl_NewUnicodeObj(
stringPtr->uallocated = uallocated;
stringPtr->hasUnicode = (numChars > 0);
stringPtr->allocated = 0;
- memcpy((void *) stringPtr->unicode, (void *) unicode, uallocated);
+ memcpy(stringPtr->unicode, unicode, uallocated);
stringPtr->unicode[numChars] = 0;
SET_STRING(objPtr, stringPtr);
return objPtr;
@@ -686,7 +686,7 @@ Tcl_GetRange(
void
Tcl_SetStringObj(
register Tcl_Obj *objPtr, /* Object whose internal rep to init. */
- CONST char *bytes, /* Points to the first of the length bytes
+ const char *bytes, /* Points to the first of the length bytes
* used to initialize the object. */
register int length) /* The number of bytes to copy from "bytes"
* when initializing the object. If negative,
@@ -761,23 +761,22 @@ Tcl_SetObjLength(
if (length > (int) stringPtr->allocated &&
(objPtr->bytes != NULL || stringPtr->hasUnicode == 0)) {
-
/*
* Not enough space in current string. Reallocate the string space and
* free the old string.
*/
if (objPtr->bytes != tclEmptyStringRep) {
- objPtr->bytes = ckrealloc((char *)objPtr->bytes,
- (unsigned)(length+1));
+ objPtr->bytes = ckrealloc((char *) objPtr->bytes,
+ (unsigned) (length + 1));
} else {
- char *new = ckalloc((unsigned) (length+1));
+ char *newBytes = ckalloc((unsigned) (length+1));
+
if (objPtr->bytes != NULL && objPtr->length != 0) {
- memcpy((void *) new, (void *) objPtr->bytes,
- (size_t) objPtr->length);
+ memcpy(newBytes, objPtr->bytes, (size_t) objPtr->length);
Tcl_InvalidateStringRep(objPtr);
}
- objPtr->bytes = new;
+ objPtr->bytes = newBytes;
}
stringPtr->allocated = length;
@@ -876,7 +875,7 @@ Tcl_AttemptSetObjLength(
if (length > (int) stringPtr->allocated &&
(objPtr->bytes != NULL || stringPtr->hasUnicode == 0)) {
- char *new;
+ char *newBytes;
/*
* Not enough space in current string. Reallocate the string space and
@@ -884,22 +883,22 @@ Tcl_AttemptSetObjLength(
*/
if (objPtr->bytes != tclEmptyStringRep) {
- new = attemptckrealloc(objPtr->bytes, (unsigned)(length+1));
- if (new == NULL) {
+ newBytes = attemptckrealloc(objPtr->bytes,
+ (unsigned)(length + 1));
+ if (newBytes == NULL) {
return 0;
}
} else {
- new = attemptckalloc((unsigned) (length+1));
- if (new == NULL) {
+ newBytes = attemptckalloc((unsigned) (length + 1));
+ if (newBytes == NULL) {
return 0;
}
if (objPtr->bytes != NULL && objPtr->length != 0) {
- memcpy((void *) new, (void *) objPtr->bytes,
- (size_t) objPtr->length);
+ memcpy(newBytes, objPtr->bytes, (size_t) objPtr->length);
Tcl_InvalidateStringRep(objPtr);
}
}
- objPtr->bytes = new;
+ objPtr->bytes = newBytes;
stringPtr->allocated = length;
/*
@@ -974,7 +973,7 @@ Tcl_AttemptSetObjLength(
void
Tcl_SetUnicodeObj(
Tcl_Obj *objPtr, /* The object to set the string of. */
- CONST Tcl_UniChar *unicode, /* The unicode string used to initialize the
+ const Tcl_UniChar *unicode, /* The unicode string used to initialize the
* object. */
int numChars) /* Number of characters in the unicode
* string. */
@@ -1008,7 +1007,7 @@ Tcl_SetUnicodeObj(
stringPtr->uallocated = uallocated;
stringPtr->hasUnicode = (numChars > 0);
stringPtr->allocated = 0;
- memcpy((void *) stringPtr->unicode, (void *) unicode, uallocated);
+ memcpy(stringPtr->unicode, unicode, uallocated);
stringPtr->unicode[numChars] = 0;
SET_STRING(objPtr, stringPtr);
@@ -1037,14 +1036,14 @@ Tcl_SetUnicodeObj(
void
Tcl_AppendLimitedToObj(
register Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST char *bytes, /* Points to the bytes to append to the
+ const char *bytes, /* Points to the bytes to append to the
* object. */
register int length, /* The number of bytes available to be
* appended from "bytes". If < 0, then all
* bytes up to a NUL byte are available. */
register int limit, /* The maximum number of bytes to append to
* the object. */
- CONST char *ellipsis) /* Ellipsis marker string, appended to the
+ const char *ellipsis) /* Ellipsis marker string, appended to the
* object to indicate not all available bytes
* at "bytes" were appended. */
{
@@ -1118,7 +1117,7 @@ Tcl_AppendLimitedToObj(
void
Tcl_AppendToObj(
register Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST char *bytes, /* Points to the bytes to append to the
+ const char *bytes, /* Points to the bytes to append to the
* object. */
register int length) /* The number of bytes to append from "bytes".
* If < 0, then append all bytes up to NUL
@@ -1147,7 +1146,7 @@ Tcl_AppendToObj(
void
Tcl_AppendUnicodeToObj(
register Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST Tcl_UniChar *unicode, /* The unicode string to append to the
+ const Tcl_UniChar *unicode, /* The unicode string to append to the
* object. */
int length) /* Number of chars in "unicode". */
{
@@ -1283,7 +1282,7 @@ Tcl_AppendObjToObj(
static void
AppendUnicodeToUnicodeRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST Tcl_UniChar *unicode, /* String to append. */
+ const Tcl_UniChar *unicode, /* String to append. */
int appendNumChars) /* Number of chars of "unicode" to append. */
{
String *stringPtr, *tmpString;
@@ -1334,7 +1333,7 @@ AppendUnicodeToUnicodeRep(
* trailing null.
*/
- memcpy((void*) (stringPtr->unicode + stringPtr->numChars), unicode,
+ memcpy(stringPtr->unicode + stringPtr->numChars, unicode,
appendNumChars * sizeof(Tcl_UniChar));
stringPtr->unicode[numChars] = 0;
stringPtr->numChars = numChars;
@@ -1362,11 +1361,11 @@ AppendUnicodeToUnicodeRep(
static void
AppendUnicodeToUtfRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST Tcl_UniChar *unicode, /* String to convert to UTF. */
+ const Tcl_UniChar *unicode, /* String to convert to UTF. */
int numChars) /* Number of chars of "unicode" to convert. */
{
Tcl_DString dsPtr;
- CONST char *bytes;
+ const char *bytes;
if (numChars < 0) {
numChars = 0;
@@ -1407,7 +1406,7 @@ AppendUnicodeToUtfRep(
static void
AppendUtfToUnicodeRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST char *bytes, /* String to convert to Unicode. */
+ const char *bytes, /* String to convert to Unicode. */
int numBytes) /* Number of bytes of "bytes" to convert. */
{
Tcl_DString dsPtr;
@@ -1448,7 +1447,7 @@ AppendUtfToUnicodeRep(
static void
AppendUtfToUtfRep(
Tcl_Obj *objPtr, /* Points to the object to append to. */
- CONST char *bytes, /* String to append. */
+ const char *bytes, /* String to append. */
int numBytes) /* Number of bytes of "bytes" to append. */
{
String *stringPtr;
@@ -1492,8 +1491,7 @@ AppendUtfToUtfRep(
stringPtr->numChars = -1;
stringPtr->hasUnicode = 0;
- memcpy((void *) (objPtr->bytes + oldLength), (void *) bytes,
- (size_t) numBytes);
+ memcpy(objPtr->bytes + oldLength, bytes, (size_t) numBytes);
objPtr->bytes[newLength] = 0;
objPtr->length = newLength;
}
@@ -1636,7 +1634,7 @@ Tcl_AppendStringsToObjVA(
*/
if (args != static_list) {
- ckfree((void *)args);
+ ckfree((void *) args);
}
#undef STATIC_LIST_SIZE
}
@@ -1695,19 +1693,16 @@ int
Tcl_AppendFormatToObj(
Tcl_Interp *interp,
Tcl_Obj *appendObj,
- CONST char *format,
+ const char *format,
int objc,
- Tcl_Obj *CONST objv[])
+ Tcl_Obj *const objv[])
{
- CONST char *span = format;
- int numBytes = 0;
- int objIndex = 0;
- int gotXpg = 0, gotSequential = 0;
+ const char *span = format, *msg;
+ int numBytes = 0, objIndex = 0, gotXpg = 0, gotSequential = 0;
int originalLength;
- CONST char *msg;
- CONST char *mixedXPG =
+ static const char *mixedXPG =
"cannot mix \"%\" and \"%n$\" conversion specifiers";
- CONST char *badIndex[2] = {
+ static const char *badIndex[2] = {
"not enough arguments for all format specifiers",
"\"%n$\" argument index out of range"
};
@@ -1930,6 +1925,7 @@ Tcl_AppendFormatToObj(
case 'c': {
char buf[TCL_UTF_MAX];
int code, length;
+
if (TclGetIntFromObj(interp, segment, &code) != TCL_OK) {
goto error;
}
@@ -2028,7 +2024,7 @@ Tcl_AppendFormatToObj(
case 'd': {
int length;
Tcl_Obj *pure;
- CONST char *bytes;
+ const char *bytes;
if (useShort) {
pure = Tcl_NewIntObj((int)(s));
@@ -2143,8 +2139,9 @@ Tcl_AppendFormatToObj(
int digitOffset;
if (useBig) {
- if ((size_t)shift<CHAR_BIT*sizeof(Tcl_WideUInt)-DIGIT_BIT) {
- bits |= (((Tcl_WideUInt)big.dp[index++]) << shift);
+ if ((size_t) shift <
+ CHAR_BIT*sizeof(Tcl_WideUInt) - DIGIT_BIT) {
+ bits |= (((Tcl_WideUInt)big.dp[index++]) <<shift);
shift += DIGIT_BIT;
}
shift -= numBits;
@@ -2303,9 +2300,9 @@ Tcl_AppendFormatToObj(
Tcl_Obj *
Tcl_Format(
Tcl_Interp *interp,
- CONST char *format,
+ const char *format,
int objc,
- Tcl_Obj *CONST objv[])
+ Tcl_Obj *const objv[])
{
int result;
Tcl_Obj *objPtr = Tcl_NewObj();
@@ -2332,12 +2329,12 @@ Tcl_Format(
static void
AppendPrintfToObjVA(
Tcl_Obj *objPtr,
- CONST char *format,
+ const char *format,
va_list argList)
{
int code, objc;
Tcl_Obj **objv, *list = Tcl_NewObj();
- CONST char *p;
+ const char *p;
char *end;
p = format;
@@ -2360,13 +2357,13 @@ AppendPrintfToObjVA(
seekingConversion = 0;
break;
case 's': {
- CONST char *q, *end, *bytes = va_arg(argList, char *);
+ const char *q, *end, *bytes = va_arg(argList, char *);
seekingConversion = 0;
/*
- * The buffer to copy characters from starts at bytes
- * and ends at either the first NUL byte, or after
- * lastNum bytes, when caller has indicated a limit.
+ * The buffer to copy characters from starts at bytes and ends
+ * at either the first NUL byte, or after lastNum bytes, when
+ * caller has indicated a limit.
*/
end = bytes;
@@ -2375,9 +2372,9 @@ AppendPrintfToObjVA(
}
/*
- * Within that buffer, we trim both ends if needed so that
- * we copy only whole characters, and avoid copying any
- * partial multi-byte characters.
+ * Within that buffer, we trim both ends if needed so that we
+ * copy only whole characters, and avoid copying any partial
+ * multi-byte characters.
*/
q = Tcl_UtfPrev(end, bytes);
@@ -2478,7 +2475,7 @@ AppendPrintfToObjVA(
void
Tcl_AppendPrintfToObj(
Tcl_Obj *objPtr,
- CONST char *format,
+ const char *format,
...)
{
va_list argList;
@@ -2504,7 +2501,7 @@ Tcl_AppendPrintfToObj(
Tcl_Obj *
Tcl_ObjPrintf(
- CONST char *format,
+ const char *format,
...)
{
va_list argList;
@@ -2622,9 +2619,8 @@ FillUnicodeRep(
{
String *stringPtr;
size_t uallocated;
- char *src, *srcEnd;
+ char *srcEnd, *src = objPtr->bytes;
Tcl_UniChar *dst;
- src = objPtr->bytes;
stringPtr = GET_STRING(objPtr);
if (stringPtr->numChars == -1) {
@@ -2709,8 +2705,7 @@ DupStringInternalRep(
STRING_SIZE(srcStringPtr->uallocated));
copyStringPtr->uallocated = srcStringPtr->uallocated;
- memcpy((void *) copyStringPtr->unicode,
- (void *) srcStringPtr->unicode,
+ memcpy(copyStringPtr->unicode, srcStringPtr->unicode,
(size_t) srcStringPtr->numChars * sizeof(Tcl_UniChar));
copyStringPtr->unicode[srcStringPtr->numChars] = 0;
}