summaryrefslogtreecommitdiffstats
path: root/generic/tkText.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkText.c')
-rw-r--r--generic/tkText.c248
1 files changed, 123 insertions, 125 deletions
diff --git a/generic/tkText.c b/generic/tkText.c
index 67232fb..ee19f8a 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkText.c,v 1.2 1998/09/14 18:23:17 stanton Exp $
+ * RCS: @(#) $Id: tkText.c,v 1.3 1999/04/16 01:51:23 stanton Exp $
*/
#include "default.h"
@@ -134,16 +134,6 @@ static Tk_ConfigSpec configSpecs[] = {
};
/*
- * Tk_Uid's used to represent text states:
- */
-
-Tk_Uid tkTextCharUid = NULL;
-Tk_Uid tkTextDisabledUid = NULL;
-Tk_Uid tkTextNoneUid = NULL;
-Tk_Uid tkTextNormalUid = NULL;
-Tk_Uid tkTextWordUid = NULL;
-
-/*
* Boolean variable indicating whether or not special debugging code
* should be executed.
*/
@@ -232,18 +222,6 @@ Tk_TextCmd(clientData, interp, argc, argv)
}
/*
- * Perform once-only initialization:
- */
-
- if (tkTextNormalUid == NULL) {
- tkTextCharUid = Tk_GetUid("char");
- tkTextDisabledUid = Tk_GetUid("disabled");
- tkTextNoneUid = Tk_GetUid("none");
- tkTextNormalUid = Tk_GetUid("normal");
- tkTextWordUid = Tk_GetUid("word");
- }
-
- /*
* Create the window.
*/
@@ -265,7 +243,7 @@ Tk_TextCmd(clientData, interp, argc, argv)
Tcl_InitHashTable(&textPtr->markTable, TCL_STRING_KEYS);
Tcl_InitHashTable(&textPtr->windowTable, TCL_STRING_KEYS);
Tcl_InitHashTable(&textPtr->imageTable, TCL_STRING_KEYS);
- textPtr->state = tkTextNormalUid;
+ textPtr->state = Tk_GetUid("normal");
textPtr->border = NULL;
textPtr->borderWidth = 0;
textPtr->padX = 0;
@@ -283,14 +261,14 @@ Tk_TextCmd(clientData, interp, argc, argv)
textPtr->spacing3 = 0;
textPtr->tabOptionString = NULL;
textPtr->tabArrayPtr = NULL;
- textPtr->wrapMode = tkTextCharUid;
+ textPtr->wrapMode = Tk_GetUid("char");
textPtr->width = 0;
textPtr->height = 0;
textPtr->setGrid = 0;
textPtr->prevWidth = Tk_Width(new);
textPtr->prevHeight = Tk_Height(new);
TkTextCreateDInfo(textPtr);
- TkTextMakeIndex(textPtr->tree, 0, 0, &startIndex);
+ TkTextMakeByteIndex(textPtr->tree, 0, 0, &startIndex);
TkTextSetYView(textPtr, &startIndex, 0);
textPtr->selTagPtr = NULL;
textPtr->selBorder = NULL;
@@ -322,7 +300,8 @@ Tk_TextCmd(clientData, interp, argc, argv)
*/
textPtr->selTagPtr = TkTextCreateTag(textPtr, "sel");
- textPtr->selTagPtr->reliefString = (char *) ckalloc(7);
+ textPtr->selTagPtr->reliefString =
+ (char *) ckalloc(sizeof(DEF_TEXT_SELECT_RELIEF));
strcpy(textPtr->selTagPtr->reliefString, DEF_TEXT_SELECT_RELIEF);
textPtr->selTagPtr->relief = TK_RELIEF_RAISED;
textPtr->currentMarkPtr = TkTextSetMark(textPtr, "current", &startIndex);
@@ -343,7 +322,7 @@ Tk_TextCmd(clientData, interp, argc, argv)
Tk_DestroyWindow(textPtr->tkwin);
return TCL_ERROR;
}
- interp->result = Tk_PathName(textPtr->tkwin);
+ Tcl_SetResult(interp, Tk_PathName(textPtr->tkwin), TCL_STATIC);
return TCL_OK;
}
@@ -401,7 +380,10 @@ TextWidgetCmd(clientData, interp, argc, argv)
goto done;
}
if (TkTextCharBbox(textPtr, &index1, &x, &y, &width, &height) == 0) {
- sprintf(interp->result, "%d %d %d %d", x, y, width, height);
+ char buf[TCL_INTEGER_SPACE * 4];
+
+ sprintf(buf, "%d %d %d %d", x, y, width, height);
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
}
} else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)
&& (length >= 2)) {
@@ -459,7 +441,7 @@ TextWidgetCmd(clientData, interp, argc, argv)
} else {
goto compareError;
}
- interp->result = (value) ? "1" : "0";
+ Tcl_SetResult(interp, ((value) ? "1" : "0"), TCL_STATIC);
} else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)
&& (length >= 3)) {
if (argc == 2) {
@@ -481,7 +463,7 @@ TextWidgetCmd(clientData, interp, argc, argv)
goto done;
}
if (argc == 2) {
- interp->result = (tkBTreeDebug) ? "1" : "0";
+ Tcl_SetResult(interp, ((tkBTreeDebug) ? "1" : "0"), TCL_STATIC);
} else {
if (Tcl_GetBoolean(interp, argv[2], &tkBTreeDebug) != TCL_OK) {
result = TCL_ERROR;
@@ -497,7 +479,7 @@ TextWidgetCmd(clientData, interp, argc, argv)
result = TCL_ERROR;
goto done;
}
- if (textPtr->state == tkTextNormalUid) {
+ if (textPtr->state == Tk_GetUid("normal")) {
result = DeleteChars(textPtr, argv[2],
(argc == 4) ? argv[3] : (char *) NULL);
}
@@ -517,8 +499,10 @@ TextWidgetCmd(clientData, interp, argc, argv)
}
if (TkTextDLineInfo(textPtr, &index1, &x, &y, &width, &height, &base)
== 0) {
- sprintf(interp->result, "%d %d %d %d %d", x, y, width,
- height, base);
+ char buf[TCL_INTEGER_SPACE * 5];
+
+ sprintf(buf, "%d %d %d %d %d", x, y, width, height, base);
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
}
} else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) {
if ((argc != 3) && (argc != 4)) {
@@ -551,10 +535,10 @@ TextWidgetCmd(clientData, interp, argc, argv)
if (index1.linePtr == index2.linePtr) {
int last2;
- if (index2.charIndex == index1.charIndex) {
+ if (index2.byteIndex == index1.byteIndex) {
break;
}
- last2 = index2.charIndex - index1.charIndex + offset;
+ last2 = index2.byteIndex - index1.byteIndex + offset;
if (last2 < last) {
last = last2;
}
@@ -566,10 +550,12 @@ TextWidgetCmd(clientData, interp, argc, argv)
(char *) NULL);
segPtr->body.chars[last] = savedChar;
}
- TkTextIndexForwChars(&index1, last-offset, &index1);
+ TkTextIndexForwBytes(&index1, last-offset, &index1);
}
} else if ((c == 'i') && (strncmp(argv[1], "index", length) == 0)
&& (length >= 3)) {
+ char buf[200];
+
if (argc != 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"",
argv[0], " index index\"",
@@ -581,7 +567,8 @@ TextWidgetCmd(clientData, interp, argc, argv)
result = TCL_ERROR;
goto done;
}
- TkTextPrintIndex(&index1, interp->result);
+ TkTextPrintIndex(&index1, buf);
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
} else if ((c == 'i') && (strncmp(argv[1], "insert", length) == 0)
&& (length >= 3)) {
int i, j, numTags;
@@ -600,11 +587,11 @@ TextWidgetCmd(clientData, interp, argc, argv)
result = TCL_ERROR;
goto done;
}
- if (textPtr->state == tkTextNormalUid) {
+ if (textPtr->state == Tk_GetUid("normal")) {
for (j = 3; j < argc; j += 2) {
InsertChars(textPtr, &index1, argv[j]);
if (argc > (j+1)) {
- TkTextIndexForwChars(&index1, (int) strlen(argv[j]),
+ TkTextIndexForwBytes(&index1, (int) strlen(argv[j]),
&index2);
oldTagArrayPtr = TkBTreeGetTags(&index1, &numTags);
if (oldTagArrayPtr != NULL) {
@@ -745,7 +732,7 @@ DestroyText(memPtr)
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
- * returned, then interp->result contains an error message.
+ * returned, then the interp's result contains an error message.
*
* Side effects:
* Configuration information, such as text string, colors, font,
@@ -776,20 +763,20 @@ ConfigureText(interp, textPtr, argc, argv, flags)
* the geometry and setting the background from a 3-D border.
*/
- if ((textPtr->state != tkTextNormalUid)
- && (textPtr->state != tkTextDisabledUid)) {
+ if ((textPtr->state != Tk_GetUid("normal"))
+ && (textPtr->state != Tk_GetUid("disabled"))) {
Tcl_AppendResult(interp, "bad state value \"", textPtr->state,
"\": must be normal or disabled", (char *) NULL);
- textPtr->state = tkTextNormalUid;
+ textPtr->state = Tk_GetUid("normal");
return TCL_ERROR;
}
- if ((textPtr->wrapMode != tkTextCharUid)
- && (textPtr->wrapMode != tkTextNoneUid)
- && (textPtr->wrapMode != tkTextWordUid)) {
+ if ((textPtr->wrapMode != Tk_GetUid("char"))
+ && (textPtr->wrapMode != Tk_GetUid("none"))
+ && (textPtr->wrapMode != Tk_GetUid("word"))) {
Tcl_AppendResult(interp, "bad wrap mode \"", textPtr->wrapMode,
"\": must be char, none, or word", (char *) NULL);
- textPtr->wrapMode = tkTextCharUid;
+ textPtr->wrapMode = Tk_GetUid("char");
return TCL_ERROR;
}
@@ -882,8 +869,8 @@ ConfigureText(interp, textPtr, argc, argv, flags)
TkTextSearch search;
TkTextIndex first, last;
- TkTextMakeIndex(textPtr->tree, 0, 0, &first);
- TkTextMakeIndex(textPtr->tree,
+ TkTextMakeByteIndex(textPtr->tree, 0, 0, &first);
+ TkTextMakeByteIndex(textPtr->tree,
TkBTreeNumLines(textPtr->tree), 0, &last);
TkBTreeStartSearch(&first, &last, textPtr->selTagPtr, &search);
if (TkBTreeCharTagged(&first, textPtr->selTagPtr)
@@ -1114,7 +1101,7 @@ InsertChars(textPtr, indexPtr, string)
lineIndex = TkBTreeLineIndex(indexPtr->linePtr);
if (lineIndex == TkBTreeNumLines(textPtr->tree)) {
lineIndex--;
- TkTextMakeIndex(textPtr->tree, lineIndex, 1000000, indexPtr);
+ TkTextMakeByteIndex(textPtr->tree, lineIndex, 1000000, indexPtr);
}
/*
@@ -1127,16 +1114,16 @@ InsertChars(textPtr, indexPtr, string)
resetView = offset = 0;
if (indexPtr->linePtr == textPtr->topIndex.linePtr) {
resetView = 1;
- offset = textPtr->topIndex.charIndex;
- if (offset > indexPtr->charIndex) {
+ offset = textPtr->topIndex.byteIndex;
+ if (offset > indexPtr->byteIndex) {
offset += strlen(string);
}
}
TkTextChanged(textPtr, indexPtr, indexPtr);
TkBTreeInsertChars(indexPtr, string);
if (resetView) {
- TkTextMakeIndex(textPtr->tree, lineIndex, 0, &newTop);
- TkTextIndexForwChars(&newTop, offset, &newTop);
+ TkTextMakeByteIndex(textPtr->tree, lineIndex, 0, &newTop);
+ TkTextIndexForwBytes(&newTop, offset, &newTop);
TkTextSetYView(textPtr, &newTop, 0);
}
@@ -1175,7 +1162,7 @@ DeleteChars(textPtr, index1String, index2String)
* delete the one character given by
* index1String. */
{
- int line1, line2, line, charIndex, resetView;
+ int line1, line2, line, byteIndex, resetView;
TkTextIndex index1, index2;
/*
@@ -1226,7 +1213,7 @@ DeleteChars(textPtr, index1String, index2String)
oldIndex2 = index2;
TkTextIndexBackChars(&oldIndex2, 1, &index2);
line2--;
- if ((index1.charIndex == 0) && (line1 != 0)) {
+ if ((index1.byteIndex == 0) && (line1 != 0)) {
TkTextIndexBackChars(&index1, 1, &index1);
line1--;
}
@@ -1249,7 +1236,9 @@ DeleteChars(textPtr, index1String, index2String)
*/
TkTextChanged(textPtr, &index1, &index2);
- resetView = line = charIndex = 0;
+ resetView = 0;
+ line = 0;
+ byteIndex = 0;
if (TkTextIndexCmp(&index2, &textPtr->topIndex) >= 0) {
if (TkTextIndexCmp(&index1, &textPtr->topIndex) <= 0) {
/*
@@ -1259,7 +1248,7 @@ DeleteChars(textPtr, index1String, index2String)
resetView = 1;
line = line1;
- charIndex = index1.charIndex;
+ byteIndex = index1.byteIndex;
} else if (index1.linePtr == textPtr->topIndex.linePtr) {
/*
* Deletion range starts on top line but after topIndex.
@@ -1268,7 +1257,7 @@ DeleteChars(textPtr, index1String, index2String)
resetView = 1;
line = line1;
- charIndex = textPtr->topIndex.charIndex;
+ byteIndex = textPtr->topIndex.byteIndex;
}
} else if (index2.linePtr == textPtr->topIndex.linePtr) {
/*
@@ -1279,16 +1268,16 @@ DeleteChars(textPtr, index1String, index2String)
resetView = 1;
line = line2;
- charIndex = textPtr->topIndex.charIndex;
+ byteIndex = textPtr->topIndex.byteIndex;
if (index1.linePtr != index2.linePtr) {
- charIndex -= index2.charIndex;
+ byteIndex -= index2.byteIndex;
} else {
- charIndex -= (index2.charIndex - index1.charIndex);
+ byteIndex -= (index2.byteIndex - index1.byteIndex);
}
}
TkBTreeDeleteChars(&index1, &index2);
if (resetView) {
- TkTextMakeIndex(textPtr->tree, line, charIndex, &index1);
+ TkTextMakeByteIndex(textPtr->tree, line, byteIndex, &index1);
TkTextSetYView(textPtr, &index1, 0);
}
@@ -1352,12 +1341,12 @@ TextFetchSelection(clientData, offset, buffer, maxBytes)
*/
if (offset == 0) {
- TkTextMakeIndex(textPtr->tree, 0, 0, &textPtr->selIndex);
+ TkTextMakeByteIndex(textPtr->tree, 0, 0, &textPtr->selIndex);
textPtr->abortSelections = 0;
} else if (textPtr->abortSelections) {
return 0;
}
- TkTextMakeIndex(textPtr->tree, TkBTreeNumLines(textPtr->tree), 0, &eof);
+ TkTextMakeByteIndex(textPtr->tree, TkBTreeNumLines(textPtr->tree), 0, &eof);
TkBTreeStartSearch(&textPtr->selIndex, &eof, textPtr->selTagPtr, &search);
if (!TkBTreeCharTagged(&textPtr->selIndex, textPtr->selTagPtr)) {
if (!TkBTreeNextTag(&search)) {
@@ -1404,8 +1393,8 @@ TextFetchSelection(clientData, offset, buffer, maxBytes)
if (textPtr->selIndex.linePtr == search.curIndex.linePtr) {
int leftInRange;
- leftInRange = search.curIndex.charIndex
- - textPtr->selIndex.charIndex;
+ leftInRange = search.curIndex.byteIndex
+ - textPtr->selIndex.byteIndex;
if (leftInRange < chunkSize) {
chunkSize = leftInRange;
if (chunkSize <= 0) {
@@ -1420,7 +1409,7 @@ TextFetchSelection(clientData, offset, buffer, maxBytes)
maxBytes -= chunkSize;
count += chunkSize;
}
- TkTextIndexForwChars(&textPtr->selIndex, chunkSize,
+ TkTextIndexForwBytes(&textPtr->selIndex, chunkSize,
&textPtr->selIndex);
}
@@ -1477,8 +1466,8 @@ TkTextLostSelection(clientData)
* just remove the "sel" tag from everything in the widget.
*/
- TkTextMakeIndex(textPtr->tree, 0, 0, &start);
- TkTextMakeIndex(textPtr->tree, TkBTreeNumLines(textPtr->tree), 0, &end);
+ TkTextMakeByteIndex(textPtr->tree, 0, 0, &start);
+ TkTextMakeByteIndex(textPtr->tree, TkBTreeNumLines(textPtr->tree), 0, &end);
TkTextRedrawTag(textPtr, &start, &end, textPtr->selTagPtr, 1);
TkBTreeTag(&start, &end, textPtr->selTagPtr, 0);
#endif
@@ -1556,8 +1545,8 @@ TextSearchCmd(textPtr, interp, argc, argv)
{
int backwards, exact, c, i, argsLeft, noCase, leftToScan;
size_t length;
- int numLines, startingLine, startingChar, lineNum, firstChar, lastChar;
- int code, matchLength, matchChar, passes, stopLine, searchWholeText;
+ int numLines, startingLine, startingByte, lineNum, firstByte, lastByte;
+ int code, matchLength, matchByte, passes, stopLine, searchWholeText;
int patLength;
char *arg, *pattern, *varName, *p, *startOfLine;
char buffer[20];
@@ -1594,7 +1583,8 @@ TextSearchCmd(textPtr, interp, argc, argv)
backwards = 1;
} else if ((c == 'c') && (strncmp(argv[i], "-count", length) == 0)) {
if (i >= (argc-1)) {
- interp->result = "no value given for \"-count\" option";
+ Tcl_SetResult(interp, "no value given for \"-count\" option",
+ TCL_STATIC);
return TCL_ERROR;
}
i++;
@@ -1631,11 +1621,7 @@ TextSearchCmd(textPtr, interp, argc, argv)
Tcl_DStringInit(&patDString);
Tcl_DStringAppend(&patDString, pattern, -1);
pattern = Tcl_DStringValue(&patDString);
- for (p = pattern; *p != 0; p++) {
- if (isupper(UCHAR(*p))) {
- *p = tolower(UCHAR(*p));
- }
- }
+ Tcl_UtfToLower(pattern);
}
if (TkTextGetIndex(interp, textPtr, argv[i+1], &index) != TCL_OK) {
@@ -1643,15 +1629,15 @@ TextSearchCmd(textPtr, interp, argc, argv)
}
numLines = TkBTreeNumLines(textPtr->tree);
startingLine = TkBTreeLineIndex(index.linePtr);
- startingChar = index.charIndex;
+ startingByte = index.byteIndex;
if (startingLine >= numLines) {
if (backwards) {
startingLine = TkBTreeNumLines(textPtr->tree) - 1;
- startingChar = TkBTreeCharsInLine(TkBTreeFindLine(textPtr->tree,
+ startingByte = TkBTreeBytesInLine(TkBTreeFindLine(textPtr->tree,
startingLine));
} else {
startingLine = 0;
- startingChar = 0;
+ startingByte = 0;
}
}
if (argsLeft == 1) {
@@ -1719,11 +1705,8 @@ TextSearchCmd(textPtr, interp, argc, argv)
*/
if (noCase) {
- for (p = Tcl_DStringValue(&line); *p != 0; p++) {
- if (isupper(UCHAR(*p))) {
- *p = tolower(UCHAR(*p));
- }
- }
+ Tcl_DStringSetLength(&line,
+ Tcl_UtfToLower(Tcl_DStringValue(&line)));
}
/*
@@ -1732,9 +1715,9 @@ TextSearchCmd(textPtr, interp, argc, argv)
* in the line.
*/
- matchChar = -1;
- firstChar = 0;
- lastChar = INT_MAX;
+ matchByte = -1;
+ firstByte = 0;
+ lastByte = INT_MAX;
if (lineNum == startingLine) {
int indexInDString;
@@ -1748,8 +1731,8 @@ TextSearchCmd(textPtr, interp, argc, argv)
* character.
*/
- indexInDString = startingChar;
- for (segPtr = linePtr->segPtr, leftToScan = startingChar;
+ indexInDString = startingByte;
+ for (segPtr = linePtr->segPtr, leftToScan = startingByte;
leftToScan > 0; segPtr = segPtr->nextPtr) {
if (segPtr->typePtr != &tkTextCharType) {
indexInDString -= segPtr->size;
@@ -1763,8 +1746,8 @@ TextSearchCmd(textPtr, interp, argc, argv)
* Only use the last part of the line.
*/
- firstChar = indexInDString;
- if (firstChar >= Tcl_DStringLength(&line)) {
+ firstByte = indexInDString;
+ if (firstByte >= Tcl_DStringLength(&line)) {
goto nextLine;
}
} else {
@@ -1772,13 +1755,16 @@ TextSearchCmd(textPtr, interp, argc, argv)
* Use only the first part of the line.
*/
- lastChar = indexInDString;
+ lastByte = indexInDString;
}
}
do {
int thisLength;
+ Tcl_UniChar ch;
+
if (exact) {
- p = strstr(startOfLine + firstChar, pattern);
+ p = strstr(startOfLine + firstByte, /* INTL: Native. */
+ pattern);
if (p == NULL) {
break;
}
@@ -1789,7 +1775,7 @@ TextSearchCmd(textPtr, interp, argc, argv)
int match;
match = Tcl_RegExpExec(interp, regexp,
- startOfLine + firstChar, startOfLine);
+ startOfLine + firstByte, startOfLine);
if (match < 0) {
code = TCL_ERROR;
goto done;
@@ -1801,12 +1787,12 @@ TextSearchCmd(textPtr, interp, argc, argv)
i = start - startOfLine;
thisLength = end - start;
}
- if (i >= lastChar) {
+ if (i >= lastByte) {
break;
}
- matchChar = i;
+ matchByte = i;
matchLength = thisLength;
- firstChar = matchChar+1;
+ firstByte += Tcl_UtfToUniChar(startOfLine + matchByte, &ch);
} while (backwards);
/*
@@ -1815,7 +1801,16 @@ TextSearchCmd(textPtr, interp, argc, argv)
* specified.
*/
- if (matchChar >= 0) {
+ if (matchByte >= 0) {
+ int numChars;
+
+ /*
+ * Convert the byte length to a character count.
+ */
+
+ numChars = Tcl_NumUtfChars(startOfLine + matchByte,
+ matchLength);
+
/*
* The index information returned by the regular expression
* parser only considers textual information: it doesn't
@@ -1824,10 +1819,10 @@ TextSearchCmd(textPtr, interp, argc, argv)
* matchChar and matchCount.
*/
- for (segPtr = linePtr->segPtr, leftToScan = matchChar;
+ for (segPtr = linePtr->segPtr, leftToScan = matchByte;
leftToScan >= 0; segPtr = segPtr->nextPtr) {
if (segPtr->typePtr != &tkTextCharType) {
- matchChar += segPtr->size;
+ matchByte += segPtr->size;
continue;
}
leftToScan -= segPtr->size;
@@ -1835,12 +1830,12 @@ TextSearchCmd(textPtr, interp, argc, argv)
for (leftToScan += matchLength; leftToScan > 0;
segPtr = segPtr->nextPtr) {
if (segPtr->typePtr != &tkTextCharType) {
- matchLength += segPtr->size;
+ numChars += segPtr->size;
continue;
}
leftToScan -= segPtr->size;
}
- TkTextMakeIndex(textPtr->tree, lineNum, matchChar, &index);
+ TkTextMakeByteIndex(textPtr->tree, lineNum, matchByte, &index);
if (!searchWholeText) {
if (!backwards && (TkTextIndexCmp(&index, &stopIndex) >= 0)) {
goto done;
@@ -1850,14 +1845,15 @@ TextSearchCmd(textPtr, interp, argc, argv)
}
}
if (varName != NULL) {
- sprintf(buffer, "%d", matchLength);
+ sprintf(buffer, "%d", numChars);
if (Tcl_SetVar(interp, varName, buffer, TCL_LEAVE_ERR_MSG)
== NULL) {
code = TCL_ERROR;
goto done;
}
}
- TkTextPrintIndex(&index, interp->result);
+ TkTextPrintIndex(&index, buffer);
+ Tcl_SetResult(interp, buffer, TCL_VOLATILE);
goto done;
}
@@ -1906,7 +1902,7 @@ TextSearchCmd(textPtr, interp, argc, argv)
* The return value is a pointer to a malloc'ed structure holding
* parsed information about the tab stops. If an error occurred
* then the return value is NULL and an error message is left in
- * interp->result.
+ * the interp's result.
*
* Side effects:
* Memory is allocated for the structure that is returned. It is
@@ -1928,6 +1924,7 @@ TkTextGetTabs(interp, tkwin, string)
char **argv;
TkTextTabArray *tabArrayPtr;
TkTextTab *tabPtr;
+ Tcl_UniChar ch;
if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
return NULL;
@@ -1970,11 +1967,12 @@ TkTextGetTabs(interp, tkwin, string)
if ((i+1) == argc) {
continue;
}
- c = UCHAR(argv[i+1][0]);
- if (!isalpha(c)) {
+ Tcl_UtfToUniChar(argv[i+1], &ch);
+ if (!Tcl_UniCharIsAlpha(ch)) {
continue;
}
i += 1;
+ c = argv[i][0];
if ((c == 'l') && (strncmp(argv[i], "left",
strlen(argv[i])) == 0)) {
tabPtr->alignment = LEFT;
@@ -2104,10 +2102,10 @@ TextDumpCmd(textPtr, interp, argc, argv)
}
if (index1.linePtr == index2.linePtr) {
DumpLine(interp, textPtr, what, index1.linePtr,
- index1.charIndex, index2.charIndex, lineno, command);
+ index1.byteIndex, index2.byteIndex, lineno, command);
} else {
DumpLine(interp, textPtr, what, index1.linePtr,
- index1.charIndex, 32000000, lineno, command);
+ index1.byteIndex, 32000000, lineno, command);
linePtr = index1.linePtr;
while ((linePtr = TkBTreeNextLine(linePtr)) != (TkTextLine *)NULL) {
lineno++;
@@ -2118,14 +2116,14 @@ TextDumpCmd(textPtr, interp, argc, argv)
lineno, command);
}
DumpLine(interp, textPtr, what, index2.linePtr, 0,
- index2.charIndex, lineno, command);
+ index2.byteIndex, lineno, command);
}
/*
* Special case to get the leftovers hiding at the end mark.
*/
if (atEnd) {
DumpLine(interp, textPtr, what & ~TK_DUMP_TEXT, index2.linePtr,
- 0, 1, lineno, command);
+ 0, 1, lineno, command);
}
return TCL_OK;
@@ -2143,12 +2141,12 @@ TextDumpCmd(textPtr, interp, argc, argv)
* None, but see DumpSegment.
*/
static void
-DumpLine(interp, textPtr, what, linePtr, start, end, lineno, command)
+DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command)
Tcl_Interp *interp;
TkText *textPtr;
int what; /* bit flags to select segment types */
TkTextLine *linePtr; /* The current line */
- int start, end; /* Character range to dump */
+ int startByte, endByte; /* Byte range to dump */
int lineno; /* Line number for indices dump */
char *command; /* Script to apply to the segment */
{
@@ -2163,25 +2161,25 @@ DumpLine(interp, textPtr, what, linePtr, start, end, lineno, command)
* window
*/
for (offset = 0, segPtr = linePtr->segPtr ;
- (offset < end) && (segPtr != (TkTextSegment *)NULL) ;
+ (offset < endByte) && (segPtr != (TkTextSegment *)NULL) ;
offset += segPtr->size, segPtr = segPtr->nextPtr) {
if ((what & TK_DUMP_TEXT) && (segPtr->typePtr == &tkTextCharType) &&
- (offset + segPtr->size > start)) {
+ (offset + segPtr->size > startByte)) {
char savedChar; /* Last char used in the seg */
int last = segPtr->size; /* Index of savedChar */
int first = 0; /* Index of first char in seg */
- if (offset + segPtr->size > end) {
- last = end - offset;
+ if (offset + segPtr->size > endByte) {
+ last = endByte - offset;
}
- if (start > offset) {
- first = start - offset;
+ if (startByte > offset) {
+ first = startByte - offset;
}
savedChar = segPtr->body.chars[last];
segPtr->body.chars[last] = '\0';
DumpSegment(interp, "text", segPtr->body.chars + first,
command, lineno, offset + first, what);
segPtr->body.chars[last] = savedChar;
- } else if ((offset >= start)) {
+ } else if ((offset >= startByte)) {
if ((what & TK_DUMP_MARK) && (segPtr->typePtr->name[0] == 'm')) {
TkTextMark *markPtr = (TkTextMark *)&segPtr->body;
char *name = Tcl_GetHashKey(&textPtr->markTable, markPtr->hPtr);
@@ -2237,11 +2235,11 @@ DumpSegment(interp, key, value, command, lineno, offset, what)
char *value; /* Segment value */
char *command; /* Script callback */
int lineno; /* Line number for indices dump */
- int offset; /* Character position */
+ int offset; /* Byte position */
int what; /* Look for TK_DUMP_INDEX bit */
{
char buffer[30];
- sprintf(buffer, "%d.%d", lineno, offset);
+ sprintf(buffer, "%d.%d", lineno, offset);
if (command == (char *) NULL) {
Tcl_AppendElement(interp, key);
Tcl_AppendElement(interp, value);