summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-05-14 08:26:06 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-05-14 08:26:06 (GMT)
commit37d4aa08d3f40d35c2672d95935f59454f849b84 (patch)
tree678acacedb8ab68f7b04f677fbf2462d10599208 /generic/tclUtil.c
parentd3a24bbdf1e4e8f56b6c6c15e9886ed6320b890f (diff)
downloadtcl-37d4aa08d3f40d35c2672d95935f59454f849b84.zip
tcl-37d4aa08d3f40d35c2672d95935f59454f849b84.tar.gz
tcl-37d4aa08d3f40d35c2672d95935f59454f849b84.tar.bz2
Backout the "dullest commit ever" (not my words ....). It breaks the build.
JN: Many of those changes are actually good, but there are too many changes to be able to search for a bug somewhere. Feel free to re-apply, after assuring it's really only whitespace changes. (my advise: do that after 9.0b2)
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c412
1 files changed, 205 insertions, 207 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 33ff5d4..3043fed 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -124,11 +124,11 @@ static int FindElement(Tcl_Interp *interp, const char *string,
*/
static const Tcl_ObjType endOffsetType = {
- "end-offset", /* name */
- NULL, /* freeIntRepProc */
- NULL, /* dupIntRepProc */
- NULL, /* updateStringProc */
- NULL, /* setFromAnyProc */
+ "end-offset", /* name */
+ NULL, /* freeIntRepProc */
+ NULL, /* dupIntRepProc */
+ NULL, /* updateStringProc */
+ NULL, /* setFromAnyProc */
TCL_OBJTYPE_V1(TclLengthOne)
};
@@ -946,9 +946,9 @@ Tcl_SplitList(
Tcl_Size
Tcl_ScanElement(
- const char *src, /* String to convert to list element. */
- int *flagPtr) /* Where to store information to guide
- * Tcl_ConvertCountedElement. */
+ const char *src, /* String to convert to list element. */
+ int *flagPtr) /* Where to store information to guide
+ * Tcl_ConvertCountedElement. */
{
return Tcl_ScanCountedElement(src, TCL_INDEX_NONE, flagPtr);
}
@@ -1036,7 +1036,7 @@ TclScanElement(
Tcl_Size extra = 0; /* Count of number of extra bytes needed for
* formatted element, assuming we use escape
* sequences in formatting. */
- Tcl_Size bytesNeeded; /* Buffer length computed to complete the
+ Tcl_Size bytesNeeded; /* Buffer length computed to complete the
* element formatting in the selected mode. */
#if COMPAT
int preferEscape = 0; /* Use preferences to track whether to use */
@@ -1083,96 +1083,96 @@ TclScanElement(
}
while (length) {
- if (CHAR_TYPE(*p) != TYPE_NORMAL) {
- switch (*p) {
- case '{': /* TYPE_BRACE */
+ if (CHAR_TYPE(*p) != TYPE_NORMAL) {
+ switch (*p) {
+ case '{': /* TYPE_BRACE */
#if COMPAT
- braceCount++;
+ braceCount++;
#endif /* COMPAT */
- extra++; /* Escape '{' => '\{' */
- nestingLevel++;
- break;
- case '}': /* TYPE_BRACE */
+ extra++; /* Escape '{' => '\{' */
+ nestingLevel++;
+ break;
+ case '}': /* TYPE_BRACE */
#if COMPAT
- braceCount++;
+ braceCount++;
#endif /* COMPAT */
- extra++; /* Escape '}' => '\}' */
- if (nestingLevel-- < 1) {
- /*
- * Unbalanced braces! Cannot format with brace quoting.
- */
+ extra++; /* Escape '}' => '\}' */
+ if (nestingLevel-- < 1) {
+ /*
+ * Unbalanced braces! Cannot format with brace quoting.
+ */
- requireEscape = 1;
- }
- break;
- case ']': /* TYPE_CLOSE_BRACK */
- case '"': /* TYPE_SPACE */
+ requireEscape = 1;
+ }
+ break;
+ case ']': /* TYPE_CLOSE_BRACK */
+ case '"': /* TYPE_SPACE */
#if COMPAT
- forbidNone = 1;
- extra++; /* Escapes all just prepend a backslash */
- preferEscape = 1;
- break;
+ forbidNone = 1;
+ extra++; /* Escapes all just prepend a backslash */
+ preferEscape = 1;
+ break;
#else
- /* FLOW THROUGH */
+ /* FLOW THROUGH */
#endif /* COMPAT */
- case '[': /* TYPE_SUBS */
- case '$': /* TYPE_SUBS */
- case ';': /* TYPE_COMMAND_END */
- forbidNone = 1;
- extra++; /* Escape sequences all one byte longer. */
+ case '[': /* TYPE_SUBS */
+ case '$': /* TYPE_SUBS */
+ case ';': /* TYPE_COMMAND_END */
+ forbidNone = 1;
+ extra++; /* Escape sequences all one byte longer. */
#if COMPAT
- preferBrace = 1;
+ preferBrace = 1;
#endif /* COMPAT */
+ break;
+ case '\\': /* TYPE_SUBS */
+ extra++; /* Escape '\' => '\\' */
+ if ((length == 1) || ((length == TCL_INDEX_NONE) && (p[1] == '\0'))) {
+ /*
+ * Final backslash. Cannot format with brace quoting.
+ */
+
+ requireEscape = 1;
break;
- case '\\': /* TYPE_SUBS */
- extra++; /* Escape '\' => '\\' */
- if ((length == 1) || ((length == TCL_INDEX_NONE) && (p[1] == '\0'))) {
- /*
- * Final backslash. Cannot format with brace quoting.
- */
-
- requireEscape = 1;
- break;
- }
- if (p[1] == '\n') {
- extra++; /* Escape newline => '\n', one byte longer */
+ }
+ if (p[1] == '\n') {
+ extra++; /* Escape newline => '\n', one byte longer */
- /*
- * Backslash newline sequence. Brace quoting not permitted.
- */
+ /*
+ * Backslash newline sequence. Brace quoting not permitted.
+ */
- requireEscape = 1;
- length -= (length > 0);
- p++;
- break;
- }
- if ((p[1] == '{') || (p[1] == '}') || (p[1] == '\\')) {
- extra++; /* Escape sequences all one byte longer. */
- length -= (length > 0);
- p++;
- }
- forbidNone = 1;
+ requireEscape = 1;
+ length -= (length > 0);
+ p++;
+ break;
+ }
+ if ((p[1] == '{') || (p[1] == '}') || (p[1] == '\\')) {
+ extra++; /* Escape sequences all one byte longer. */
+ length -= (length > 0);
+ p++;
+ }
+ forbidNone = 1;
#if COMPAT
- preferBrace = 1;
+ preferBrace = 1;
#endif /* COMPAT */
- break;
- case '\0': /* TYPE_SUBS */
- if (length == TCL_INDEX_NONE) {
- goto endOfString;
- }
- /* TODO: Panic on improper encoding? */
- break;
- default:
- if (TclIsSpaceProcM(*p)) {
- forbidNone = 1;
- extra++; /* Escape sequences all one byte longer. */
+ break;
+ case '\0': /* TYPE_SUBS */
+ if (length == TCL_INDEX_NONE) {
+ goto endOfString;
+ }
+ /* TODO: Panic on improper encoding? */
+ break;
+ default:
+ if (TclIsSpaceProcM(*p)) {
+ forbidNone = 1;
+ extra++; /* Escape sequences all one byte longer. */
#if COMPAT
- preferBrace = 1;
+ preferBrace = 1;
#endif
- }
- break;
}
+ break;
}
+ }
length -= (length > 0);
p++;
}
@@ -1323,9 +1323,9 @@ TclScanElement(
Tcl_Size
Tcl_ConvertElement(
- const char *src, /* Source information for list element. */
- char *dst, /* Place to put list-ified element. */
- int flags) /* Flags produced by Tcl_ScanElement. */
+ const char *src, /* Source information for list element. */
+ char *dst, /* Place to put list-ified element. */
+ int flags) /* Flags produced by Tcl_ScanElement. */
{
return Tcl_ConvertCountedElement(src, TCL_INDEX_NONE, dst, flags);
}
@@ -1353,7 +1353,7 @@ Tcl_ConvertElement(
Tcl_Size
Tcl_ConvertCountedElement(
- const char *src, /* Source information for list element. */
+ const char *src, /* Source information for list element. */
Tcl_Size length, /* Number of bytes in src, or TCL_INDEX_NONE. */
char *dst, /* Place to put list-ified element. */
int flags) /* Flags produced by Tcl_ScanElement. */
@@ -1386,7 +1386,7 @@ Tcl_ConvertCountedElement(
Tcl_Size
TclConvertElement(
- const char *src, /* Source information for list element. */
+ const char *src, /* Source information for list element. */
Tcl_Size length, /* Number of bytes in src, or TCL_INDEX_NONE. */
char *dst, /* Place to put list-ified element. */
int flags) /* Flags produced by Tcl_ScanElement. */
@@ -1406,8 +1406,7 @@ TclConvertElement(
* No matter what the caller demands, empty string must be braced!
*/
- if ((src == NULL) || (length == 0)
- || (*src == '\0' && length == TCL_INDEX_NONE)) {
+ if ((src == NULL) || (length == 0) || (*src == '\0' && length == TCL_INDEX_NONE)) {
p[0] = '{';
p[1] = '}';
return 2;
@@ -1568,7 +1567,7 @@ TclConvertElement(
char *
Tcl_Merge(
- Tcl_Size argc, /* How many strings to merge. */
+ Tcl_Size argc, /* How many strings to merge. */
const char *const *argv) /* Array of string values. */
{
#define LOCAL_SIZE 64
@@ -1645,14 +1644,14 @@ Tcl_Merge(
Tcl_Size
TclTrimRight(
- const char *bytes, /* String to be trimmed... */
- Tcl_Size numBytes, /* ...and its length in bytes */
- /* Calls to TclUtfToUniChar() in this routine
- * rely on (bytes[numBytes] == '\0'). */
- const char *trim, /* String of trim characters... */
- Tcl_Size numTrim) /* ...and its length in bytes */
- /* Calls to TclUtfToUniChar() in this routine
- * rely on (trim[numTrim] == '\0'). */
+ const char *bytes, /* String to be trimmed... */
+ Tcl_Size numBytes, /* ...and its length in bytes */
+ /* Calls to TclUtfToUniChar() in this routine
+ * rely on (bytes[numBytes] == '\0'). */
+ const char *trim, /* String of trim characters... */
+ Tcl_Size numTrim) /* ...and its length in bytes */
+ /* Calls to TclUtfToUniChar() in this routine
+ * rely on (trim[numTrim] == '\0'). */
{
const char *pp, *p = bytes + numBytes;
int ch1, ch2;
@@ -1724,14 +1723,14 @@ TclTrimRight(
Tcl_Size
TclTrimLeft(
- const char *bytes, /* String to be trimmed... */
- Tcl_Size numBytes, /* ...and its length in bytes */
- /* Calls to TclUtfToUniChar() in this routine
- * rely on (bytes[numBytes] == '\0'). */
- const char *trim, /* String of trim characters... */
- Tcl_Size numTrim) /* ...and its length in bytes */
- /* Calls to TclUtfToUniChar() in this routine
- * rely on (trim[numTrim] == '\0'). */
+ const char *bytes, /* String to be trimmed... */
+ Tcl_Size numBytes, /* ...and its length in bytes */
+ /* Calls to TclUtfToUniChar() in this routine
+ * rely on (bytes[numBytes] == '\0'). */
+ const char *trim, /* String of trim characters... */
+ Tcl_Size numTrim) /* ...and its length in bytes */
+ /* Calls to TclUtfToUniChar() in this routine
+ * rely on (trim[numTrim] == '\0'). */
{
const char *p = bytes;
int ch1, ch2;
@@ -1798,14 +1797,14 @@ TclTrimLeft(
Tcl_Size
TclTrim(
- const char *bytes, /* String to be trimmed... */
- Tcl_Size numBytes, /* ...and its length in bytes */
- /* Calls in this routine
- * rely on (bytes[numBytes] == '\0'). */
- const char *trim, /* String of trim characters... */
- Tcl_Size numTrim, /* ...and its length in bytes */
- /* Calls in this routine
- * rely on (trim[numTrim] == '\0'). */
+ const char *bytes, /* String to be trimmed... */
+ Tcl_Size numBytes, /* ...and its length in bytes */
+ /* Calls in this routine
+ * rely on (bytes[numBytes] == '\0'). */
+ const char *trim, /* String of trim characters... */
+ Tcl_Size numTrim, /* ...and its length in bytes */
+ /* Calls in this routine
+ * rely on (trim[numTrim] == '\0'). */
Tcl_Size *trimRightPtr) /* Offset from the end of the string. */
{
Tcl_Size trimLeft = 0, trimRight = 0;
@@ -1860,7 +1859,7 @@ TclTrim(
char *
Tcl_Concat(
- Tcl_Size argc, /* Number of strings to concatenate. */
+ Tcl_Size argc, /* Number of strings to concatenate. */
const char *const *argv) /* Array of strings to concatenate. */
{
Tcl_Size i, needSpace = 0, bytesNeeded = 0;
@@ -2338,11 +2337,11 @@ Tcl_StringCaseMatch(
int
TclByteArrayMatch(
const unsigned char *string,/* String. */
- Tcl_Size strLen, /* Length of String */
+ Tcl_Size strLen, /* Length of String */
const unsigned char *pattern,
/* Pattern, which may contain special
* characters. */
- Tcl_Size ptnLen, /* Length of Pattern */
+ Tcl_Size ptnLen, /* Length of Pattern */
TCL_UNUSED(int) /*flags*/)
{
const unsigned char *stringEnd, *patternEnd;
@@ -2729,7 +2728,6 @@ Tcl_DStringAppendElement(
* Backtrack over all whitespace.
*/
while ((--dst >= dsPtr->string) && TclIsSpaceProcM(*dst)) {
- // empty body
}
/* Call again without whitespace to confound things. */
@@ -2811,7 +2809,7 @@ Tcl_DStringAppendElement(
void
Tcl_DStringSetLength(
Tcl_DString *dsPtr, /* Structure describing dynamic string. */
- Tcl_Size length) /* New length for dynamic string. */
+ Tcl_Size length) /* New length for dynamic string. */
{
Tcl_Size newsize;
@@ -3244,10 +3242,9 @@ TclNeedSpace(
*/
while ((--end >= start) && (*end == '{')) {
- // empty body
}
if (end < start) {
- return 0;
+ return 0;
}
/*
@@ -3301,7 +3298,7 @@ Tcl_Size
TclFormatInt(
char *buffer, /* Points to the storage into which the
* formatted characters are written. */
- Tcl_WideInt n) /* The integer to format. */
+ Tcl_WideInt n) /* The integer to format. */
{
Tcl_WideUInt intVal;
int i = 0, numFormatted, j;
@@ -3363,15 +3360,15 @@ TclFormatInt(
static int
GetWideForIndex(
- Tcl_Interp *interp, /* Interpreter to use for error reporting. If
+ Tcl_Interp *interp, /* Interpreter to use for error reporting. If
* NULL, then no error message is left after
* errors. */
- Tcl_Obj *objPtr, /* Points to the value to be parsed */
- Tcl_WideInt endValue, /* The value to be stored at *widePtr if
+ Tcl_Obj *objPtr, /* Points to the value to be parsed */
+ Tcl_WideInt endValue, /* The value to be stored at *widePtr if
* objPtr holds "end".
- * NOTE: this value may be TCL_INDEX_NONE. */
- Tcl_WideInt *widePtr) /* Location filled in with a wide integer
- * representing an index. */
+ * NOTE: this value may be TCL_INDEX_NONE. */
+ Tcl_WideInt *widePtr) /* Location filled in with a wide integer
+ * representing an index. */
{
int numType;
void *cd;
@@ -3381,7 +3378,7 @@ GetWideForIndex(
if (numType == TCL_NUMBER_INT) {
/* objPtr holds an integer in the signed wide range */
*widePtr = *(Tcl_WideInt *)cd;
- if ((*widePtr < 0)) {
+ if ((*widePtr < 0)) {
*widePtr = (endValue == -1) ? WIDE_MIN : -1;
}
return TCL_OK;
@@ -3412,7 +3409,7 @@ GetWideForIndex(
* TCL_SIZE_MAX. Negative values are returned as TCL_INDEX_NONE (-1).
*
* Callers should pass reasonable values for endValue - one in the
- * valid index range or TCL_INDEX_NONE (-1), for example for an empty
+ * valid index range or TCL_INDEX_NONE (-1), for example for an empty
* list.
*
* Results:
@@ -3456,10 +3453,10 @@ Tcl_GetIntForIndex(
} else if (wide > TCL_SIZE_MAX) {
*indexPtr = TCL_SIZE_MAX; /* Beyond max possible index */
} else if (wide < -1-TCL_SIZE_MAX) {
- *indexPtr = -1-TCL_SIZE_MAX; /* Below most negative index */
- } else if ((wide < 0) && (endValue >= 0)) {
- *indexPtr = TCL_INDEX_NONE; /* No clue why this special case */
- } else {
+ *indexPtr = -1-TCL_SIZE_MAX; /* Below most negative index */
+ } else if ((wide < 0) && (endValue >= 0)) {
+ *indexPtr = TCL_INDEX_NONE; /* No clue why this special case */
+ } else {
*indexPtr = (Tcl_Size) wide;
}
}
@@ -3483,7 +3480,7 @@ Tcl_GetIntForIndex(
* -1: Index "end"
* 0: Index "0"
* WIDE_MAX-1: Index "end+n", for any n > 1. Distinguish from end+1 for
- * commands like lset.
+ * commands like lset.
* WIDE_MAX: Index "end+1"
*
* Results:
@@ -3498,11 +3495,11 @@ Tcl_GetIntForIndex(
static int
GetEndOffsetFromObj(
Tcl_Interp *interp,
- Tcl_Obj *objPtr, /* Pointer to the object to parse */
- Tcl_WideInt endValue, /* The value to be stored at "widePtr" if
- * "objPtr" holds "end". */
- Tcl_WideInt *widePtr) /* Location filled in with an integer
- * representing an index. */
+ Tcl_Obj *objPtr, /* Pointer to the object to parse */
+ Tcl_WideInt endValue, /* The value to be stored at "widePtr" if
+ * "objPtr" holds "end". */
+ Tcl_WideInt *widePtr) /* Location filled in with an integer
+ * representing an index. */
{
Tcl_ObjInternalRep *irPtr;
Tcl_WideInt offset = -1; /* Offset in the "end-offset" expression - 1 */
@@ -3535,14 +3532,14 @@ GetEndOffsetFromObj(
*/
if ((TclMaxListLength(bytes, TCL_INDEX_NONE, NULL) > 1)
/* If it's possible, do the full list parse. */
- && (TCL_OK == TclListObjLength(NULL, objPtr, &length))
- && (length > 1)) {
- goto parseError;
+ && (TCL_OK == TclListObjLength(NULL, objPtr, &length))
+ && (length > 1)) {
+ goto parseError;
}
/* Passed the list screen, so parse for index arithmetic expression */
- if (TCL_OK == TclParseNumber(NULL, objPtr, NULL, NULL,
- TCL_INDEX_NONE, &opPtr, TCL_PARSE_INTEGER_ONLY)) {
+ if (TCL_OK == TclParseNumber(NULL, objPtr, NULL, NULL, TCL_INDEX_NONE, &opPtr,
+ TCL_PARSE_INTEGER_ONLY)) {
Tcl_WideInt w1=0, w2=0;
/* value starts with valid integer... */
@@ -3701,12 +3698,12 @@ GetEndOffsetFromObj(
if (offset == WIDE_MAX) {
/*
* Encodes end+1. This is distinguished from end+n as noted
- * in function header.
+ * in function header.
* NOTE: this may wrap around if the caller passes (as lset does)
* listLen-1 as endValue and and listLen is 0. The -1 will be
* interpreted as FF...FF and adding 1 will result in 0 which
* is what we want. Callers like lset which pass in listLen-1 == -1
- * as endValue will have to adjust accordingly.
+ * as endValue will have to adjust accordingly.
*/
*widePtr = (endValue == -1) ? WIDE_MAX : endValue + 1;
} else if (offset == WIDE_MIN) {
@@ -3727,14 +3724,14 @@ GetEndOffsetFromObj(
/* Report a parse error. */
parseError:
if (interp != NULL) {
- char * bytes = TclGetString(objPtr);
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "bad index \"%s\": must be integer?[+-]integer? or"
- " end?[+-]integer?", bytes));
- if (!strncmp(bytes, "end-", 4)) {
- bytes += 4;
- }
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX", (char *)NULL);
+ char * bytes = TclGetString(objPtr);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad index \"%s\": must be integer?[+-]integer? or"
+ " end?[+-]integer?", bytes));
+ if (!strncmp(bytes, "end-", 4)) {
+ bytes += 4;
+ }
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX", (char *)NULL);
}
return TCL_ERROR;
@@ -3744,68 +3741,68 @@ GetEndOffsetFromObj(
*----------------------------------------------------------------------
*
* TclIndexEncode --
- * IMPORTANT: function only encodes indices in the range that fits within
- * an "int" type. Do NOT change this as the byte code compiler and engine
- * which call this function cannot handle wider index types. Indices
- * outside the range will result in the function returning an error.
+ * IMPORTANT: function only encodes indices in the range that fits within
+ * an "int" type. Do NOT change this as the byte code compiler and engine
+ * which call this function cannot handle wider index types. Indices
+ * outside the range will result in the function returning an error.
*
- * Parse objPtr to determine if it is an index value. Two cases
+ * Parse objPtr to determine if it is an index value. Two cases
* are possible. The value objPtr might be parsed as an absolute
* index value in the Tcl_Size range. Note that this includes
* index values that are integers as presented and it includes index
- * arithmetic expressions.
+ * arithmetic expressions.
*
- * The largest string supported in Tcl 8 has byte length TCL_SIZE_MAX.
- * This means the largest supported character length is also TCL_SIZE_MAX,
- * and the index of the last character in a string of length TCL_SIZE_MAX
- * is TCL_SIZE_MAX-1. Thus the absolute index values that can be
+ * The largest string supported in Tcl 8 has byte length TCL_SIZE_MAX.
+ * This means the largest supported character length is also TCL_SIZE_MAX,
+ * and the index of the last character in a string of length TCL_SIZE_MAX
+ * is TCL_SIZE_MAX-1. Thus the absolute index values that can be
* directly meaningful as an index into either a list or a string are
* integer values in the range 0 to TCL_SIZE_MAX - 1.
*
- * This function however can only handle integer indices in the range
- * 0 : INT_MAX-1.
- *
- * Any absolute index value parsed outside that range is encoded
- * using the before and after values passed in by the
- * caller as the encoding to use for indices that are either
- * less than or greater than the usable index range. TCL_INDEX_NONE
- * is available as a good choice for most callers to use for
- * after. Likewise, the value TCL_INDEX_NONE is good for
- * most callers to use for before. Other values are possible
- * when the caller knows it is helpful in producing its own behavior
- * for indices before and after the indexed item.
- *
- * A token can also be parsed as an end-relative index expression.
- * All end-relative expressions that indicate an index larger
- * than end (end+2, end--5) point beyond the end of the indexed
- * collection, and can be encoded as after. The end-relative
- * expressions that indicate an index less than or equal to end
- * are encoded relative to the value TCL_INDEX_END (-2). The
- * index "end" is encoded as -2, down to the index "end-0x7FFFFFFE"
- * which is encoded as INT_MIN. Since the largest index into a
- * string possible in Tcl 8 is 0x7FFFFFFE, the interpretation of
- * "end-0x7FFFFFFE" for that largest string would be 0. Thus,
- * if the tokens "end-0x7FFFFFFF" or "end+-0x80000000" are parsed,
- * they can be encoded with the before value.
+ * This function however can only handle integer indices in the range
+ * 0 : INT_MAX-1.
+ *
+ * Any absolute index value parsed outside that range is encoded
+ * using the before and after values passed in by the
+ * caller as the encoding to use for indices that are either
+ * less than or greater than the usable index range. TCL_INDEX_NONE
+ * is available as a good choice for most callers to use for
+ * after. Likewise, the value TCL_INDEX_NONE is good for
+ * most callers to use for before. Other values are possible
+ * when the caller knows it is helpful in producing its own behavior
+ * for indices before and after the indexed item.
+ *
+ * A token can also be parsed as an end-relative index expression.
+ * All end-relative expressions that indicate an index larger
+ * than end (end+2, end--5) point beyond the end of the indexed
+ * collection, and can be encoded as after. The end-relative
+ * expressions that indicate an index less than or equal to end
+ * are encoded relative to the value TCL_INDEX_END (-2). The
+ * index "end" is encoded as -2, down to the index "end-0x7FFFFFFE"
+ * which is encoded as INT_MIN. Since the largest index into a
+ * string possible in Tcl 8 is 0x7FFFFFFE, the interpretation of
+ * "end-0x7FFFFFFE" for that largest string would be 0. Thus,
+ * if the tokens "end-0x7FFFFFFF" or "end+-0x80000000" are parsed,
+ * they can be encoded with the before value.
*
* Returns:
- * TCL_OK if parsing succeeded, and TCL_ERROR if it failed or the
- * index does not fit in an int type.
+ * TCL_OK if parsing succeeded, and TCL_ERROR if it failed or the
+ * index does not fit in an int type.
*
* Side effects:
- * When TCL_OK is returned, the encoded index value is written
- * to *indexPtr.
+ * When TCL_OK is returned, the encoded index value is written
+ * to *indexPtr.
*
*----------------------------------------------------------------------
*/
int
TclIndexEncode(
- Tcl_Interp *interp, /* For error reporting, may be NULL */
- Tcl_Obj *objPtr, /* Index value to parse */
- int before, /* Value to return for index before beginning */
- int after, /* Value to return for index after end */
- int *indexPtr) /* Where to write the encoded answer, not NULL */
+ Tcl_Interp *interp, /* For error reporting, may be NULL */
+ Tcl_Obj *objPtr, /* Index value to parse */
+ int before, /* Value to return for index before beginning */
+ int after, /* Value to return for index after end */
+ int *indexPtr) /* Where to write the encoded answer, not NULL */
{
Tcl_WideInt wide;
int idx;
@@ -3924,8 +3921,9 @@ TclIndexEncode(
rangeerror:
if (interp) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "index \"%s\" out of range", TclGetString(objPtr)));
+ Tcl_SetObjResult(
+ interp,
+ Tcl_ObjPrintf("index \"%s\" out of range", TclGetString(objPtr)));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX", "OUTOFRANGE", (void *)NULL);
}
return TCL_ERROR;
@@ -3948,8 +3946,8 @@ rangeerror:
Tcl_Size
TclIndexDecode(
- int encoded, /* Value to decode */
- Tcl_Size endValue) /* Meaning of "end" to use, > TCL_INDEX_END */
+ int encoded, /* Value to decode */
+ Tcl_Size endValue) /* Meaning of "end" to use, > TCL_INDEX_END */
{
if (encoded > TCL_INDEX_END) {
return encoded;
@@ -3978,8 +3976,8 @@ TclIndexDecode(
*/
int
TclCommandWordLimitError(
- Tcl_Interp *interp, /* May be NULL */
- Tcl_Size count) /* If <= 0, "unknown" */
+ Tcl_Interp *interp, /* May be NULL */
+ Tcl_Size count) /* If <= 0, "unknown" */
{
if (interp) {
if (count > 0) {
@@ -4045,11 +4043,11 @@ static Tcl_HashTable *
GetThreadHash(
Tcl_ThreadDataKey *keyPtr)
{
- Tcl_HashTable **tablePtrPtr = (Tcl_HashTable **)
- Tcl_GetThreadData(keyPtr, sizeof(Tcl_HashTable *));
+ Tcl_HashTable **tablePtrPtr =
+ (Tcl_HashTable **)Tcl_GetThreadData(keyPtr, sizeof(Tcl_HashTable *));
if (NULL == *tablePtrPtr) {
- *tablePtrPtr = (Tcl_HashTable *) Tcl_Alloc(sizeof(Tcl_HashTable));
+ *tablePtrPtr = (Tcl_HashTable *)Tcl_Alloc(sizeof(Tcl_HashTable));
Tcl_CreateThreadExitHandler(FreeThreadHash, *tablePtrPtr);
Tcl_InitHashTable(*tablePtrPtr, TCL_ONE_WORD_KEYS);
}
@@ -4242,7 +4240,7 @@ TclGetProcessGlobalValue(
Tcl_MutexLock(&pgvPtr->mutex);
if ((NULL == pgvPtr->value) && (pgvPtr->proc)) {
pgvPtr->epoch++;
- pgvPtr->proc(&pgvPtr->value, &pgvPtr->numBytes, &pgvPtr->encoding);
+ pgvPtr->proc(&pgvPtr->value,&pgvPtr->numBytes,&pgvPtr->encoding);
if (pgvPtr->value == NULL) {
Tcl_Panic("PGV Initializer did not initialize");
}