diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2007-02-22 13:56:32 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2007-02-22 13:56:32 (GMT) |
commit | dde89e53698859ca30c7ef441d2b64350d2a8187 (patch) | |
tree | d27aec929ff20b2ab6ba34faa14bd56439bf1d33 /generic | |
parent | 18bcf9971777b9bf6d2eacd064c42f0f7e58ae47 (diff) | |
download | tk-dde89e53698859ca30c7ef441d2b64350d2a8187.zip tk-dde89e53698859ca30c7ef441d2b64350d2a8187.tar.gz tk-dde89e53698859ca30c7ef441d2b64350d2a8187.tar.bz2 |
Less of that K&R or wrongly indented function header style!
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tkText.c | 816 | ||||
-rw-r--r-- | generic/tkTextBTree.c | 652 | ||||
-rw-r--r-- | generic/tkTextDisp.c | 462 | ||||
-rw-r--r-- | generic/tkTextIndex.c | 275 | ||||
-rw-r--r-- | generic/tkTextMark.c | 24 | ||||
-rw-r--r-- | generic/tkTextTag.c | 67 | ||||
-rw-r--r-- | generic/tkTextWind.c | 42 |
7 files changed, 1163 insertions, 1175 deletions
diff --git a/generic/tkText.c b/generic/tkText.c index 77b30e5..fd65352 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.72 2007/01/03 05:06:27 nijtmans Exp $ + * RCS: @(#) $Id: tkText.c,v 1.73 2007/02/22 13:56:32 dkf Exp $ */ #include "default.h" @@ -66,9 +66,9 @@ static char *wrapStrings[] = { }; /* - * The 'TkTextTabStyle' enum in tkText.h is used to define a type for - * the -tabstyle option of the Text widget. These values are used as - * indices into the string table below. + * The 'TkTextTabStyle' enum in tkText.h is used to define a type for the + * -tabstyle option of the Text widget. These values are used as indices into + * the string table below. */ static char *tabStyleStrings[] = { @@ -91,8 +91,9 @@ static int SetLineStartEnd(ClientData clientData, Tcl_Obj **value, char *recordPtr, int internalOffset, char *oldInternalPtr, int flags); -static Tcl_Obj* GetLineStartEnd(ClientData clientData, Tk_Window tkwin, - char *recordPtr, int internalOffset); +static Tcl_Obj * GetLineStartEnd(ClientData clientData, + Tk_Window tkwin, char *recordPtr, + int internalOffset); static void RestoreLineStartEnd(ClientData clientData, Tk_Window tkwin, char *internalPtr, char *oldInternalPtr); @@ -158,7 +159,7 @@ static const Tk_OptionSpec optionSpecs[] = { {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness", "HighlightThickness", DEF_TEXT_HIGHLIGHT_WIDTH, -1, Tk_Offset(TkText, highlightWidth), 0, 0, TK_TEXT_LINE_GEOMETRY}, - {TK_OPTION_BORDER, "-inactiveselectbackground", "inactiveSelectBackground", + {TK_OPTION_BORDER, "-inactiveselectbackground","inactiveSelectBackground", "Foreground", DEF_TEXT_INACTIVE_SELECT_COLOR, -1, Tk_Offset(TkText, inactiveSelBorder), @@ -270,7 +271,7 @@ typedef int SearchLineIndexProc(Tcl_Interp *interp, int *linePosPtr, int *offsetPosPtr); typedef struct SearchSpec { - int exact; /* Whether search is exact or regexp */ + int exact; /* Whether search is exact or regexp. */ int noCase; /* Case-insenstivive? */ int noLineStop; /* If not set, a regexp search will use the * TCL_REG_NLSTOP flag. */ @@ -287,7 +288,7 @@ typedef struct SearchSpec { int stopLine; /* Last line to examine, or -1 when we search * all available text. */ int stopOffset; /* Index to stop at, provided stopLine is not - * -1 */ + * -1. */ int numLines; /* Total lines which are available. */ int backwards; /* Searching forwards or backwards. */ Tcl_Obj *varPtr; /* If non-NULL, store length(s) of match(es) @@ -332,8 +333,8 @@ int tkTextDebug = 0; static int ConfigureText(Tcl_Interp *interp, TkText *textPtr, int objc, Tcl_Obj *CONST objv[]); -static int DeleteIndexRange(TkSharedText *sharedPtr, TkText *textPtr, - CONST TkTextIndex *indexPtr1, +static int DeleteIndexRange(TkSharedText *sharedPtr, + TkText *textPtr, CONST TkTextIndex *indexPtr1, CONST TkTextIndex *indexPtr2, int viewUpdate); static int CountIndices(CONST TkText *textPtr, CONST TkTextIndex *indexPtr1, @@ -348,11 +349,12 @@ static void TextCmdDeletedProc(ClientData clientData); static int CreateWidget(TkSharedText *sharedPtr, Tk_Window tkwin, Tcl_Interp *interp, CONST TkText *parent, int objc, Tcl_Obj *CONST objv[]); -static void TextEventProc(ClientData clientData, XEvent *eventPtr); +static void TextEventProc(ClientData clientData, + XEvent *eventPtr); static int TextFetchSelection(ClientData clientData, int offset, char *buffer, int maxBytes); -static int TextIndexSortProc(CONST VOID *first, - CONST VOID *second); +static int TextIndexSortProc(CONST void *first, + CONST void *second); static int TextInsertCmd(TkSharedText *sharedTextPtr, TkText *textPtr, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], @@ -375,8 +377,8 @@ static void TextWorldChangedCallback(ClientData instanceData); static void TextWorldChanged(TkText *textPtr, int mask); static int TextDumpCmd(TkText *textPtr, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); -static int DumpLine(Tcl_Interp *interp, TkText *textPtr, int what, - TkTextLine *linePtr, int start, int end, +static int DumpLine(Tcl_Interp *interp, TkText *textPtr, + int what, TkTextLine *linePtr, int start, int end, int lineno, Tcl_Obj *command); static int DumpSegment(TkText *textPtr, Tcl_Interp *interp, CONST char *key, CONST char *value, @@ -435,11 +437,11 @@ static Tk_ClassProcs textClass = { */ int -Tk_TextObjCmd(clientData, interp, objc, objv) - ClientData clientData; /* Main window associated with interpreter. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +Tk_TextObjCmd( + ClientData clientData, /* Main window associated with interpreter. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { Tk_Window tkwin = (Tk_Window) clientData; @@ -473,14 +475,14 @@ Tk_TextObjCmd(clientData, interp, objc, objv) */ static int -CreateWidget(sharedPtr, tkwin, interp, parent, objc, objv) - TkSharedText *sharedPtr; /* Shared widget info, or null */ - Tk_Window tkwin; /* Main window associated with interpreter. */ - Tcl_Interp *interp; /* Current interpreter. */ - CONST TkText *parent; /* If non-NULL then take default start, end +CreateWidget( + TkSharedText *sharedPtr, /* Shared widget info, or NULL. */ + Tk_Window tkwin, /* Main window associated with interpreter. */ + Tcl_Interp *interp, /* Current interpreter. */ + CONST TkText *parent, /* If non-NULL then take default start, end * from this parent. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { register TkText *textPtr; Tk_OptionTable optionTable; @@ -504,7 +506,7 @@ CreateWidget(sharedPtr, tkwin, interp, parent, objc, objv) */ textPtr = (TkText *) ckalloc(sizeof(TkText)); - memset((VOID *) textPtr, 0, sizeof(TkText)); + memset(textPtr, 0, sizeof(TkText)); textPtr->tkwin = newWin; textPtr->display = Tk_Display(newWin); @@ -515,7 +517,7 @@ CreateWidget(sharedPtr, tkwin, interp, parent, objc, objv) if (sharedPtr == NULL) { sharedPtr = (TkSharedText *) ckalloc(sizeof(TkSharedText)); - memset((VOID *) sharedPtr, 0, sizeof(TkSharedText)); + memset(sharedPtr, 0, sizeof(TkSharedText)); sharedPtr->refCount = 0; sharedPtr->peers = NULL; @@ -614,7 +616,7 @@ CreateWidget(sharedPtr, tkwin, interp, parent, objc, objv) textPtr->selTagPtr->reliefString = (char *) ckalloc(sizeof(DEF_TEXT_SELECT_RELIEF)); strcpy(textPtr->selTagPtr->reliefString, DEF_TEXT_SELECT_RELIEF); - Tk_GetRelief(interp, DEF_TEXT_SELECT_RELIEF, &(textPtr->selTagPtr->relief)); + Tk_GetRelief(interp, DEF_TEXT_SELECT_RELIEF, &textPtr->selTagPtr->relief); textPtr->currentMarkPtr = TkTextSetMark(textPtr, "current", &startIndex); textPtr->insertMarkPtr = TkTextSetMark(textPtr, "insert", &startIndex); @@ -673,21 +675,21 @@ CreateWidget(sharedPtr, tkwin, interp, parent, objc, objv) */ static int -TextWidgetObjCmd(clientData, interp, objc, objv) - ClientData clientData; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +TextWidgetObjCmd( + ClientData clientData, /* Information about text widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { register TkText *textPtr = (TkText *) clientData; int result = TCL_OK; int index; static CONST char *optionStrings[] = { - "bbox", "cget", "compare", "configure", "count", "debug", - "delete", "dlineinfo", "dump", "edit", "get", "image", "index", - "insert", "mark", "peer", "replace", "scan", "search", "see", - "tag", "window", "xview", "yview", NULL + "bbox", "cget", "compare", "configure", "count", "debug", "delete" + "dlineinfo", "dump", "edit", "get", "image", "index", "insert", + "mark", "peer", "replace", "scan", "search", "see", "tag", "window", + "xview", "yview", NULL }; enum options { TEXT_BBOX, TEXT_CGET, TEXT_COMPARE, TEXT_CONFIGURE, TEXT_COUNT, @@ -862,7 +864,7 @@ TextWidgetObjCmd(clientData, interp, objc, objv) value = CountIndices(textPtr, indexFromPtr, indexToPtr, COUNT_DISPLAY_CHARS); } else if (c == 'd' && (length > 8) - && !strncmp("-displayindices", option, (unsigned)length)) { + && !strncmp("-displayindices", option,(unsigned)length)) { value = CountIndices(textPtr, indexFromPtr, indexToPtr, COUNT_DISPLAY_INDICES); } else if (c == 'd' && (length > 8) @@ -899,16 +901,16 @@ TextWidgetObjCmd(clientData, interp, objc, objv) index = *indexFromPtr; index.byteIndex = 0; - + /* - * We're going to count up all display lines in the - * logical line of 'indexFromPtr' up to, but not - * including the logical line of 'indexToPtr', and - * then subtract off what we didn't what from 'from' - * and add on what we didn't count from 'to. + * We're going to count up all display lines in the logical + * line of 'indexFromPtr' up to, but not including the logical + * line of 'indexToPtr', and then subtract off what we didn't + * what from 'from' and add on what we didn't count from 'to. */ + while (index.linePtr != indexToPtr->linePtr) { - value += TkTextUpdateOneLine(textPtr, fromPtr, 0,&index,0); + value += TkTextUpdateOneLine(textPtr, fromPtr,0,&index,0); /* * We might have skipped past indexToPtr, if we have @@ -1004,9 +1006,10 @@ TextWidgetObjCmd(clientData, interp, objc, objv) } else { if (found == 2) { /* - * Move the first item we put into the result into - * the first element of the list object. + * Move the first item we put into the result into the + * first element of the list object. */ + objPtr = Tcl_NewObj(); Tcl_ListObjAppendElement(NULL, objPtr, Tcl_GetObjResult(interp)); @@ -1022,6 +1025,7 @@ TextWidgetObjCmd(clientData, interp, objc, objv) int value = CountIndices(textPtr, indexFromPtr, indexToPtr, COUNT_INDICES); + Tcl_SetObjResult(interp, Tcl_NewIntObj(value)); } else if (found > 1) { Tcl_SetObjResult(interp, objPtr); @@ -1070,8 +1074,8 @@ TextWidgetObjCmd(clientData, interp, objc, objv) goto done; } if (objc == 4) { - indexPtr2 = TkTextGetIndexFromObj(textPtr->interp, textPtr, - objv[3]); + indexPtr2 = TkTextGetIndexFromObj(textPtr->interp, + textPtr, objv[3]); if (indexPtr2 == NULL) { result = TCL_ERROR; goto done; @@ -1132,7 +1136,7 @@ TextWidgetObjCmd(clientData, interp, objc, objv) * first to maintain index consistency. */ - qsort((VOID *) indices, (unsigned) (objc / 2), + qsort(indices, (unsigned) objc / 2, 2 * sizeof(TkTextIndex), TextIndexSortProc); lastStart = NULL; @@ -1184,8 +1188,8 @@ TextWidgetObjCmd(clientData, interp, objc, objv) * indices are preparsed above. */ - DeleteIndexRange(NULL, textPtr, &indices[i], &indices[i+1], - 1); + DeleteIndexRange(NULL, textPtr, &indices[i], + &indices[i+1], 1); } } ckfree((char *) indices); @@ -1522,11 +1526,11 @@ TextWidgetObjCmd(clientData, interp, objc, objv) */ static int -SharedTextObjCmd(clientData, interp, objc, objv) - ClientData clientData; /* Information about shared test B-tree. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +SharedTextObjCmd( + ClientData clientData, /* Information about shared test B-tree. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { register TkSharedText *sharedPtr = (TkSharedText *) clientData; int result = TCL_OK; @@ -1628,11 +1632,11 @@ SharedTextObjCmd(clientData, interp, objc, objv) */ static int -TextPeerCmd(textPtr, interp, objc, objv) - TkText *textPtr; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +TextPeerCmd( + TkText *textPtr, /* Information about text widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { Tk_Window tkwin = textPtr->tkwin; int index; @@ -1703,24 +1707,23 @@ TextPeerCmd(textPtr, interp, objc, objv) */ static int -TextReplaceCmd(textPtr, interp, indexFromPtr, indexToPtr, objc, objv, - viewUpdate) - TkText *textPtr; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - CONST TkTextIndex *indexFromPtr; - /* Index from which to replace */ - CONST TkTextIndex *indexToPtr; - /* Index to which to replace */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ - int viewUpdate; /* Update vertical view if set. */ +TextReplaceCmd( + TkText *textPtr, /* Information about text widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + CONST TkTextIndex *indexFromPtr, + /* Index from which to replace. */ + CONST TkTextIndex *indexToPtr, + /* Index to which to replace. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[], /* Argument objects. */ + int viewUpdate) /* Update vertical view if set. */ { /* * Perform the deletion and insertion, but ensure no undo-separator is * placed between the two operations. Since we are using the helper - * functions 'DeleteIndexRange' and 'TextInsertCmd' we have to pretend that the - * autoSeparators setting is off, so that we don't get an undo-separator - * between the delete and insert. + * functions 'DeleteIndexRange' and 'TextInsertCmd' we have to pretend + * that the autoSeparators setting is off, so that we don't get an + * undo-separator between the delete and insert. */ int origAutoSep = textPtr->sharedTextPtr->autoSeparators; @@ -1729,7 +1732,7 @@ TextReplaceCmd(textPtr, interp, indexFromPtr, indexToPtr, objc, objv, if (textPtr->sharedTextPtr->undo) { textPtr->sharedTextPtr->autoSeparators = 0; if (origAutoSep && - textPtr->sharedTextPtr->lastEditMode != TK_TEXT_EDIT_REPLACE) { + textPtr->sharedTextPtr->lastEditMode!=TK_TEXT_EDIT_REPLACE) { TkUndoInsertUndoSeparator(textPtr->sharedTextPtr->undoStack); } } @@ -1766,8 +1769,9 @@ TextReplaceCmd(textPtr, interp, indexFromPtr, indexToPtr, objc, objv, */ static int -TextIndexSortProc(first, second) - CONST VOID *first, *second; /* Elements to be compared. */ +TextIndexSortProc( + CONST void *first, /* Elements to be compared. */ + CONST void *second) { TkTextIndex *pair1 = (TkTextIndex *) first; TkTextIndex *pair2 = (TkTextIndex *) second; @@ -1814,8 +1818,8 @@ TextIndexSortProc(first, second) */ static void -DestroyText(textPtr) - TkText *textPtr; /* Info about text widget. */ +DestroyText( + TkText *textPtr) /* Info about text widget. */ { Tcl_HashSearch search; Tcl_HashEntry *hPtr; @@ -1834,7 +1838,7 @@ DestroyText(textPtr) textPtr->dInfoPtr = NULL; /* - * Remove ourselves from the peer list + * Remove ourselves from the peer list. */ if (sharedTextPtr->peers == textPtr) { @@ -1871,7 +1875,7 @@ DestroyText(textPtr) * disassociate outselves from it. * * When the refCount reaches zero, it's time to clean up the shared - * portion of the text widget + * portion of the text widget. */ sharedTextPtr->refCount--; @@ -1922,7 +1926,7 @@ DestroyText(textPtr) /* * No need to use 'TkTextDeleteTag' since we've already removed - * the B-tree completely + * the B-tree completely. */ TkTextFreeTag(textPtr, tagPtr); @@ -1978,18 +1982,18 @@ DestroyText(textPtr) */ static int -ConfigureText(interp, textPtr, objc, objv) - Tcl_Interp *interp; /* Used for error reporting. */ - register TkText *textPtr; /* Information about widget; may or may not +ConfigureText( + Tcl_Interp *interp, /* Used for error reporting. */ + register TkText *textPtr, /* Information about widget; may or may not * already have values for some fields. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { Tk_SavedOptions savedOptions; int oldExport = textPtr->exportSelection; int mask = 0; - if (Tk_SetOptions(interp, (char*)textPtr, textPtr->optionTable, + if (Tk_SetOptions(interp, (char *) textPtr, textPtr->optionTable, objc, objv, textPtr->tkwin, &savedOptions, &mask) != TCL_OK) { return TCL_ERROR; } @@ -2034,7 +2038,8 @@ ConfigureText(interp, textPtr, objc, objv) } if (start > end) { Tcl_AppendResult(interp, - "-startline must be less than or equal to -endline", NULL); + "-startline must be less than or equal to -endline", + NULL); Tk_RestoreSavedOptions(&savedOptions); return TCL_ERROR; } @@ -2234,8 +2239,8 @@ ConfigureText(interp, textPtr, objc, objv) */ static void -TextWorldChangedCallback(instanceData) - ClientData instanceData; /* Information about widget. */ +TextWorldChangedCallback( + ClientData instanceData) /* Information about widget. */ { TkText *textPtr; @@ -2264,9 +2269,10 @@ TextWorldChangedCallback(instanceData) */ static void -TextWorldChanged(textPtr, mask) - TkText *textPtr; /* Information about widget. */ - int mask; /* OR'd collection of bits showing what has changed */ +TextWorldChanged( + TkText *textPtr, /* Information about widget. */ + int mask) /* OR'd collection of bits showing what has + * changed. */ { Tk_FontMetrics fm; int border; @@ -2284,7 +2290,7 @@ TextWorldChanged(textPtr, mask) border = textPtr->borderWidth + textPtr->highlightWidth; Tk_GeometryRequest(textPtr->tkwin, textPtr->width * textPtr->charWidth + 2*textPtr->padX + 2*border, - textPtr->height* (fm.linespace+textPtr->spacing1+textPtr->spacing3) + textPtr->height*(fm.linespace+textPtr->spacing1+textPtr->spacing3) + 2*textPtr->padY + 2*border); Tk_SetInternalBorderEx(textPtr->tkwin, @@ -2320,9 +2326,9 @@ TextWorldChanged(textPtr, mask) */ static void -TextEventProc(clientData, eventPtr) - ClientData clientData; /* Information about window. */ - register XEvent *eventPtr; /* Information about event. */ +TextEventProc( + ClientData clientData, /* Information about window. */ + register XEvent *eventPtr) /* Information about event. */ { register TkText *textPtr = (TkText *) clientData; TkTextIndex index, index2; @@ -2400,7 +2406,7 @@ TextEventProc(clientData, eventPtr) /* * While we wish to redisplay, no heights have changed, so no need - * to call TkTextInvalidateLineMetrics + * to call TkTextInvalidateLineMetrics. */ TkTextChanged(NULL, textPtr, &index, &index2); @@ -2431,8 +2437,8 @@ TextEventProc(clientData, eventPtr) */ static void -TextCmdDeletedProc(clientData) - ClientData clientData; /* Pointer to widget record for widget. */ +TextCmdDeletedProc( + ClientData clientData) /* Pointer to widget record for widget. */ { TkText *textPtr = (TkText *) clientData; Tk_Window tkwin = textPtr->tkwin; @@ -2476,15 +2482,15 @@ TextCmdDeletedProc(clientData) */ static int -InsertChars(sharedTextPtr, textPtr, indexPtr, stringPtr, viewUpdate) - TkSharedText *sharedTextPtr; - TkText *textPtr; /* Overall information about text widget. */ - TkTextIndex *indexPtr; /* Where to insert new characters. May be +InsertChars( + TkSharedText *sharedTextPtr, + TkText *textPtr, /* Overall information about text widget. */ + TkTextIndex *indexPtr, /* Where to insert new characters. May be * modified if the index is not valid for * insertion (e.g. if at "end"). */ - Tcl_Obj *stringPtr; /* Null-terminated string containing new + Tcl_Obj *stringPtr, /* Null-terminated string containing new * information to add to text. */ - int viewUpdate; /* Update the view if set */ + int viewUpdate) /* Update the view if set. */ { int lineIndex, length; TkText *tPtr; @@ -2544,28 +2550,27 @@ InsertChars(sharedTextPtr, textPtr, indexPtr, stringPtr, viewUpdate) TkBTreeInsertChars(sharedTextPtr->tree, indexPtr, string); /* - * Push the insertion on the undo stack, and update - * the modified status of the widget + * Push the insertion on the undo stack, and update the modified status of + * the widget. */ if (length > 0) { if (sharedTextPtr->undo) { TkTextIndex toIndex; - + if (sharedTextPtr->autoSeparators && sharedTextPtr->lastEditMode != TK_TEXT_EDIT_INSERT) { TkUndoInsertUndoSeparator(sharedTextPtr->undoStack); } - + sharedTextPtr->lastEditMode = TK_TEXT_EDIT_INSERT; - + TkTextIndexForwBytes(textPtr, indexPtr, length, &toIndex); TextPushUndoAction(textPtr, stringPtr, 1, indexPtr, &toIndex); } UpdateDirtyFlag(sharedTextPtr); } - resetViewCount = 0; for (tPtr = sharedTextPtr->peers; tPtr != NULL ; tPtr = tPtr->next) { @@ -2583,7 +2588,7 @@ InsertChars(sharedTextPtr, textPtr, indexPtr, stringPtr, viewUpdate) resetViewCount += 2; } if (sharedTextPtr->refCount > PIXEL_CLIENTS) { - ckfree((char*)lineAndByteIndex); + ckfree((char *) lineAndByteIndex); } /* @@ -2621,14 +2626,14 @@ InsertChars(sharedTextPtr, textPtr, indexPtr, stringPtr, viewUpdate) */ static void -TextPushUndoAction (textPtr, undoString, insert, index1Ptr, index2Ptr) - TkText *textPtr; /* Overall information about text widget. */ - Tcl_Obj *undoString; /* New text */ - int insert; /* 1 if insert, else delete */ - CONST TkTextIndex *index1Ptr; - /* Index describing first location */ - CONST TkTextIndex *index2Ptr; - /* Index describing second location */ +TextPushUndoAction( + TkText *textPtr, /* Overall information about text widget. */ + Tcl_Obj *undoString, /* New text. */ + int insert, /* 1 if insert, else delete. */ + CONST TkTextIndex *index1Ptr, + /* Index describing first location. */ + CONST TkTextIndex *index2Ptr) + /* Index describing second location. */ { TkUndoSubAtom *iAtom, *dAtom; @@ -2675,7 +2680,8 @@ TextPushUndoAction (textPtr, undoString, insert, index1Ptr, index2Ptr) Tcl_ListObjAppendElement(NULL, markSet1InsertObj, index1Obj); Tcl_ListObjAppendElement(NULL, markSet2InsertObj, index2Obj); - Tcl_ListObjAppendElement(NULL, insertCmdObj, Tcl_NewStringObj("insert",6)); + Tcl_ListObjAppendElement(NULL, insertCmdObj, + Tcl_NewStringObj("insert", 6)); Tcl_ListObjAppendElement(NULL, insertCmdObj, index1Obj); /* @@ -2684,7 +2690,8 @@ TextPushUndoAction (textPtr, undoString, insert, index1Ptr, index2Ptr) Tcl_ListObjAppendElement(NULL, insertCmdObj, undoString); - Tcl_ListObjAppendElement(NULL, deleteCmdObj, Tcl_NewStringObj("delete",6)); + Tcl_ListObjAppendElement(NULL, deleteCmdObj, + Tcl_NewStringObj("delete", 6)); Tcl_ListObjAppendElement(NULL, deleteCmdObj, index1Obj); Tcl_ListObjAppendElement(NULL, deleteCmdObj, index2Obj); @@ -2692,7 +2699,7 @@ TextPushUndoAction (textPtr, undoString, insert, index1Ptr, index2Ptr) * Note: we don't wish to use textPtr->widgetCmd in these callbacks * because if we delete the textPtr, but peers still exist, we will then * have references to a non-existent Tcl_Command in the undo stack, which - * will lead to crashes later. Also, the behaviour of the widget wrt + * will lead to crashes later. Also, the behaviour of the widget w.r.t. * bindings (%W substitutions) always uses the widget path name, so there * is no good reason the undo stack should do otherwise. * @@ -2749,17 +2756,16 @@ TextPushUndoAction (textPtr, undoString, insert, index1Ptr, index2Ptr) */ int -TextUndoRedoCallback(interp, clientData, objPtr) - Tcl_Interp *interp; /* Current interpreter. */ - ClientData clientData; /* Passed from undo code, but contains our +TextUndoRedoCallback( + Tcl_Interp *interp, /* Current interpreter. */ + ClientData clientData, /* Passed from undo code, but contains our * shared text data structure. */ - Tcl_Obj *objPtr; /* Arguments of a command to be handled by the + Tcl_Obj *objPtr) /* Arguments of a command to be handled by the * shared text data structure. */ { - TkSharedText *sharedPtr = (TkSharedText*)clientData; - int objc; + TkSharedText *sharedPtr = (TkSharedText *) clientData; + int res, objc; Tcl_Obj **objv; - int res; TkText *textPtr; res = Tcl_ListObjGetElements(interp, objPtr, &objc, &objv); @@ -2847,16 +2853,16 @@ TextUndoRedoCallback(interp, clientData, objPtr) */ static int -CountIndices(textPtr, indexPtr1, indexPtr2, type) - CONST TkText *textPtr; /* Overall information about text widget. */ - CONST TkTextIndex *indexPtr1; +CountIndices( + CONST TkText *textPtr, /* Overall information about text widget. */ + CONST TkTextIndex *indexPtr1, /* Index describing location of first * character to delete. */ - CONST TkTextIndex *indexPtr2; + CONST TkTextIndex *indexPtr2, /* Index describing location of last character * to delete. NULL means just delete the one * character given by indexPtr1. */ - TkTextCountType type; /* The kind of indices to count */ + TkTextCountType type) /* The kind of indices to count. */ { /* * Order the starting and stopping indices. @@ -2885,8 +2891,8 @@ CountIndices(textPtr, indexPtr1, indexPtr2, type) * Returns a standard Tcl result, currently always TCL_OK. * * Side effects: - * Characters and other entities (windows, images) get deleted - * from the text. + * Characters and other entities (windows, images) get deleted from the + * text. * * If 'viewUpdate' is true, we may adjust the window contents' * y-position, and scrollbar setting. @@ -2902,18 +2908,18 @@ CountIndices(textPtr, indexPtr1, indexPtr2, type) */ static int -DeleteIndexRange(sharedTextPtr, textPtr, indexPtr1, indexPtr2, viewUpdate) - TkSharedText *sharedTextPtr;/* Shared portion of peer widgets. */ - TkText *textPtr; /* Overall information about text widget. */ - CONST TkTextIndex *indexPtr1; +DeleteIndexRange( + TkSharedText *sharedTextPtr,/* Shared portion of peer widgets. */ + TkText *textPtr, /* Overall information about text widget. */ + CONST TkTextIndex *indexPtr1, /* Index describing location of first * character (or other entity) to delete. */ - CONST TkTextIndex *indexPtr2; + CONST TkTextIndex *indexPtr2, /* Index describing location of last * character (or other entity) to delete. * NULL means just delete the one character - * given by indexPtr1. */ - int viewUpdate; /* Update vertical view if set. */ + * given by indexPtr1. */ + int viewUpdate) /* Update vertical view if set. */ { int line1, line2; TkTextIndex index1, index2; @@ -2955,9 +2961,8 @@ DeleteIndexRange(sharedTextPtr, textPtr, indexPtr1, indexPtr2, viewUpdate) * even number of lines gets deleted. Furthermore, remove any tags that * are present on the newline that isn't going to be deleted after all * (this simulates deleting the newline and then adding a "clean" one back - * again). - * Note that index1 and index2 might now be equal again which means that - * no text will be deleted but tags might be removed. + * again). Note that index1 and index2 might now be equal again which + * means that no text will be deleted but tags might be removed. */ line1 = TkBTreeLinesTo(textPtr, index1.linePtr); @@ -3089,27 +3094,27 @@ DeleteIndexRange(sharedTextPtr, textPtr, indexPtr1, indexPtr2, viewUpdate) } /* - * Push the deletion on the undo stack if something was actually deleted + * Push the deletion on the undo stack if something was actually deleted. */ if (TkTextIndexCmp(&index1, &index2) < 0) { if (sharedTextPtr->undo) { Tcl_Obj *get; - + if (sharedTextPtr->autoSeparators && (sharedTextPtr->lastEditMode != TK_TEXT_EDIT_DELETE)) { TkUndoInsertUndoSeparator(sharedTextPtr->undoStack); } - + sharedTextPtr->lastEditMode = TK_TEXT_EDIT_DELETE; - + get = TextGetText(textPtr, &index1, &index2, 0); TextPushUndoAction(textPtr, get, 0, &index1, &index2); } UpdateDirtyFlag(sharedTextPtr); - + sharedTextPtr->stateEpoch++; - + TkBTreeDeleteIndexRange(sharedTextPtr->tree, &index1, &index2); } @@ -3135,7 +3140,7 @@ DeleteIndexRange(sharedTextPtr, textPtr, indexPtr1, indexPtr2, viewUpdate) resetViewCount += 2; } if (sharedTextPtr->refCount > PIXEL_CLIENTS) { - ckfree((char*)lineAndByteIndex); + ckfree((char *) lineAndByteIndex); } if (line1 >= line2) { @@ -3175,12 +3180,12 @@ DeleteIndexRange(sharedTextPtr, textPtr, indexPtr1, indexPtr2, viewUpdate) */ static int -TextFetchSelection(clientData, offset, buffer, maxBytes) - ClientData clientData; /* Information about text widget. */ - int offset; /* Offset within selection of first character +TextFetchSelection( + ClientData clientData, /* Information about text widget. */ + int offset, /* Offset within selection of first character * to be returned. */ - char *buffer; /* Location in which to place selection. */ - int maxBytes; /* Maximum number of bytes to place at buffer, + char *buffer, /* Location in which to place selection. */ + int maxBytes) /* Maximum number of bytes to place at buffer, * not including terminating NULL * character. */ { @@ -3267,8 +3272,8 @@ TextFetchSelection(clientData, offset, buffer, maxBytes) } if ((segPtr->typePtr == &tkTextCharType) && !TkTextIsElided(textPtr, &textPtr->selIndex, NULL)) { - memcpy((VOID *) buffer, (VOID *) (segPtr->body.chars - + offsetInSeg), (size_t) chunkSize); + memcpy(buffer, segPtr->body.chars + offsetInSeg, + (size_t) chunkSize); buffer += chunkSize; maxBytes -= chunkSize; count += chunkSize; @@ -3312,8 +3317,8 @@ TextFetchSelection(clientData, offset, buffer, maxBytes) */ void -TkTextLostSelection(clientData) - ClientData clientData; /* Information about text widget. */ +TkTextLostSelection( + ClientData clientData) /* Information about text widget. */ { register TkText *textPtr = (TkText *) clientData; @@ -3367,8 +3372,8 @@ TkTextLostSelection(clientData) */ void -TkTextSelectionEvent(textPtr) - TkText *textPtr; +TkTextSelectionEvent( + TkText *textPtr) { /* * Send an event that the selection changed. This is equivalent to: @@ -3377,7 +3382,7 @@ TkTextSelectionEvent(textPtr) XEvent event; - memset((VOID *) &event, 0, sizeof(event)); + memset(&event, 0, sizeof(event)); event.xany.type = VirtualEvent; event.xany.serial = NextRequest(Tk_Display(textPtr->tkwin)); event.xany.send_event = False; @@ -3406,8 +3411,8 @@ TkTextSelectionEvent(textPtr) */ static void -TextBlinkProc(clientData) - ClientData clientData; /* Pointer to record describing text. */ +TextBlinkProc( + ClientData clientData) /* Pointer to record describing text. */ { register TkText *textPtr = (TkText *) clientData; TkTextIndex index; @@ -3471,14 +3476,14 @@ TextBlinkProc(clientData) */ static int -TextInsertCmd(sharedTextPtr, textPtr, interp, objc, objv, indexPtr, viewUpdate) - TkSharedText *sharedTextPtr;/* Shared portion of peer widgets. */ - TkText *textPtr; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ - CONST TkTextIndex *indexPtr;/* Index at which to insert */ - int viewUpdate; /* Update the view if set */ +TextInsertCmd( + TkSharedText *sharedTextPtr,/* Shared portion of peer widgets. */ + TkText *textPtr, /* Information about text widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[], /* Argument objects. */ + CONST TkTextIndex *indexPtr,/* Index at which to insert. */ + int viewUpdate) /* Update the view if set. */ { TkTextIndex index1, index2; int j; @@ -3551,25 +3556,24 @@ TextInsertCmd(sharedTextPtr, textPtr, interp, objc, objv, indexPtr, viewUpdate) */ static int -TextSearchCmd(textPtr, interp, objc, objv) - TkText *textPtr; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +TextSearchCmd( + TkText *textPtr, /* Information about text widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { int i, argsLeft, code; SearchSpec searchSpec; static CONST char *switchStrings[] = { - "--", "-all", "-backwards", "-count", "-elide", "-exact", - "-forwards", "-hidden", "-nocase", "-nolinestop", - "-overlap", "-regexp", "-strictlimits", NULL + "--", "-all", "-backwards", "-count", "-elide", "-exact", "-forwards", + "-hidden", "-nocase", "-nolinestop", "-overlap", "-regexp", + "-strictlimits", NULL }; enum SearchSwitches { SEARCH_END, SEARCH_ALL, SEARCH_BACK, SEARCH_COUNT, SEARCH_ELIDE, SEARCH_EXACT, SEARCH_FWD, SEARCH_HIDDEN, SEARCH_NOCASE, - SEARCH_NOLINESTOP, SEARCH_OVERLAP, SEARCH_REGEXP, - SEARCH_STRICTLIMITS + SEARCH_NOLINESTOP, SEARCH_OVERLAP, SEARCH_REGEXP, SEARCH_STRICTLIMITS }; /* @@ -3608,7 +3612,7 @@ TextSearchCmd(textPtr, interp, objc, objv) if (Tcl_GetIndexFromObj(interp, objv[i], switchStrings, "switch", 0, &index) != TCL_OK) { /* - * Hide the -hidden option + * Hide the -hidden option. */ Tcl_ResetResult(interp); @@ -3720,7 +3724,7 @@ TextSearchCmd(textPtr, interp, objc, objv) } /* - * Set the result + * Set the result. */ if (searchSpec.resPtr != NULL) { @@ -3763,18 +3767,19 @@ TextSearchCmd(textPtr, interp, objc, objv) * *---------------------------------------------------------------------- */ + static int -TextSearchGetLineIndex(interp, objPtr, searchSpecPtr, linePosPtr, offsetPosPtr) - Tcl_Interp *interp; /* For error messages */ - Tcl_Obj *objPtr; /* Contains a textual index like "1.2" */ - SearchSpec *searchSpecPtr; /* Contains other search parameters */ - int *linePosPtr; /* For returning the line number. */ - int *offsetPosPtr; /* For returning the text offset in the +TextSearchGetLineIndex( + Tcl_Interp *interp, /* For error messages. */ + Tcl_Obj *objPtr, /* Contains a textual index like "1.2" */ + SearchSpec *searchSpecPtr, /* Contains other search parameters. */ + int *linePosPtr, /* For returning the line number. */ + int *offsetPosPtr) /* For returning the text offset in the * line. */ { CONST TkTextIndex *indexPtr; int line; - TkText *textPtr = (TkText*)(searchSpecPtr->clientData); + TkText *textPtr = (TkText *) searchSpecPtr->clientData; indexPtr = TkTextGetIndexFromObj(interp, textPtr, objPtr); if (indexPtr == NULL) { @@ -3799,8 +3804,8 @@ TextSearchGetLineIndex(interp, objPtr, searchSpecPtr, linePosPtr, offsetPosPtr) } *offsetPosPtr = TextSearchIndexInLine(searchSpecPtr, linePtr, count); } else { - *offsetPosPtr = TextSearchIndexInLine(searchSpecPtr, indexPtr->linePtr, - indexPtr->byteIndex); + *offsetPosPtr = TextSearchIndexInLine(searchSpecPtr, + indexPtr->linePtr, indexPtr->byteIndex); } *linePosPtr = line; @@ -3830,16 +3835,16 @@ TextSearchGetLineIndex(interp, objPtr, searchSpecPtr, linePosPtr, offsetPosPtr) */ static int -TextSearchIndexInLine(searchSpecPtr, linePtr, byteIndex) - CONST SearchSpec *searchSpecPtr; - /* Search parameters */ - TkTextLine *linePtr; /* The line we're looking at */ - int byteIndex; /* Index into the line */ +TextSearchIndexInLine( + CONST SearchSpec *searchSpecPtr, + /* Search parameters. */ + TkTextLine *linePtr, /* The line we're looking at. */ + int byteIndex) /* Index into the line. */ { TkTextSegment *segPtr; TkTextIndex curIndex; int index, leftToScan; - TkText *textPtr = (TkText*)(searchSpecPtr->clientData); + TkText *textPtr = (TkText *) searchSpecPtr->clientData; index = 0; curIndex.tree = textPtr->sharedTextPtr->tree; @@ -3896,20 +3901,20 @@ TextSearchIndexInLine(searchSpecPtr, linePtr, byteIndex) */ static ClientData -TextSearchAddNextLine(lineNum, searchSpecPtr, theLine, lenPtr, extraLinesPtr) - int lineNum; /* Line we must add */ - SearchSpec *searchSpecPtr; /* Search parameters */ - Tcl_Obj *theLine; /* Object to append to */ - int *lenPtr; /* For returning the total length */ - int *extraLinesPtr; /* If non-NULL, will have its value +TextSearchAddNextLine( + int lineNum, /* Line we must add. */ + SearchSpec *searchSpecPtr, /* Search parameters. */ + Tcl_Obj *theLine, /* Object to append to. */ + int *lenPtr, /* For returning the total length. */ + int *extraLinesPtr) /* If non-NULL, will have its value * incremented by the number of additional * logical lines which are merged into this - * one by newlines being elided */ + * one by newlines being elided. */ { TkTextLine *linePtr, *thisLinePtr; TkTextIndex curIndex; TkTextSegment *segPtr; - TkText *textPtr = (TkText*)(searchSpecPtr->clientData); + TkText *textPtr = (TkText *) searchSpecPtr->clientData; int nothingYet = 1; /* @@ -4010,20 +4015,19 @@ TextSearchAddNextLine(lineNum, searchSpecPtr, theLine, lenPtr, extraLinesPtr) */ static int -TextSearchFoundMatch(lineNum, searchSpecPtr, clientData, theLine, matchOffset, - matchLength) - int lineNum; /* Line on which match was found. */ - SearchSpec *searchSpecPtr; /* Search parameters. */ - ClientData clientData; /* Token returned by the 'addNextLineProc', +TextSearchFoundMatch( + int lineNum, /* Line on which match was found. */ + SearchSpec *searchSpecPtr, /* Search parameters. */ + ClientData clientData, /* Token returned by the 'addNextLineProc', * TextSearchAddNextLine. May be NULL, in * which we case we must generate it (from * lineNum). */ - Tcl_Obj *theLine; /* Text from current line, only accessed for + Tcl_Obj *theLine, /* Text from current line, only accessed for * exact searches, and is allowed to be NULL * for regexp searches. */ - int matchOffset; /* Offset of found item in utf-8 bytes for - * exact search, Unicode chars for regexp */ - int matchLength; /* Length also in bytes/chars as per search + int matchOffset, /* Offset of found item in utf-8 bytes for + * exact search, Unicode chars for regexp. */ + int matchLength) /* Length also in bytes/chars as per search * type. */ { int numChars; @@ -4031,7 +4035,7 @@ TextSearchFoundMatch(lineNum, searchSpecPtr, clientData, theLine, matchOffset, TkTextIndex curIndex, foundIndex; TkTextSegment *segPtr; TkTextLine *linePtr; - TkText *textPtr = (TkText*)(searchSpecPtr->clientData); + TkText *textPtr = (TkText *) searchSpecPtr->clientData; if (lineNum == searchSpecPtr->stopLine) { /* @@ -4060,10 +4064,10 @@ TextSearchFoundMatch(lineNum, searchSpecPtr, clientData, theLine, matchOffset, } /* - * If we're using strict limits checking, ensure that the match with - * its full length fits inside the given range. + * If we're using strict limits checking, ensure that the match with its + * full length fits inside the given range. */ - + if (searchSpecPtr->strictLimits && lineNum == searchSpecPtr->stopLine) { if (searchSpecPtr->backwards ^ ((matchOffset + numChars) > searchSpecPtr->stopOffset)) { @@ -4248,10 +4252,10 @@ TextSearchFoundMatch(lineNum, searchSpecPtr, clientData, theLine, matchOffset, */ TkTextTabArray * -TkTextGetTabs(interp, textPtr, stringPtr) - Tcl_Interp *interp; /* Used for error reporting. */ - TkText *textPtr; /* Information about the text widget. */ - Tcl_Obj *stringPtr; /* Description of the tab stops. See the text +TkTextGetTabs( + Tcl_Interp *interp, /* Used for error reporting. */ + TkText *textPtr, /* Information about the text widget. */ + Tcl_Obj *stringPtr) /* Description of the tab stops. See the text * manual entry for details. */ { int objc, i, count; @@ -4292,8 +4296,7 @@ TkTextGetTabs(interp, textPtr, stringPtr) tabArrayPtr->numTabs = 0; prevStop = 0.0; lastStop = 0.0; - for (i = 0, tabPtr = &tabArrayPtr->tabs[0]; i < objc; - i++, tabPtr++) { + for (i = 0, tabPtr = &tabArrayPtr->tabs[0]; i < objc; i++, tabPtr++) { int index; /* @@ -4414,21 +4417,21 @@ TkTextGetTabs(interp, textPtr, stringPtr) */ static int -TextDumpCmd(textPtr, interp, objc, objv) - register TkText *textPtr; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. Someone else has already +TextDumpCmd( + register TkText *textPtr, /* Information about text widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. Someone else has already * parsed this command enough to know that * objv[1] is "dump". */ { TkTextIndex index1, index2; int arg; - int lineno; /* Current line number */ - int what = 0; /* bitfield to select segment types */ - int atEnd; /* True if dumping up to logical end */ + int lineno; /* Current line number. */ + int what = 0; /* bitfield to select segment types. */ + int atEnd; /* True if dumping up to logical end. */ TkTextLine *linePtr; - Tcl_Obj *command = NULL; /* Script callback to apply to segments */ + Tcl_Obj *command = NULL; /* Script callback to apply to segments. */ #define TK_DUMP_TEXT 0x1 #define TK_DUMP_MARK 0x2 #define TK_DUMP_TAG 0x4 @@ -4525,13 +4528,15 @@ TextDumpCmd(textPtr, interp, objc, objv) int textChanged; int lineend = TkBTreeLinesTo(textPtr, index2.linePtr); int endByteIndex = index2.byteIndex; - + textChanged = DumpLine(interp, textPtr, what, index1.linePtr, index1.byteIndex, 32000000, lineno, command); if (textChanged) { - if (textPtr->flags & DESTROYED) return TCL_OK; - linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, - textPtr, lineno); + if (textPtr->flags & DESTROYED) { + return TCL_OK; + } + linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, + textPtr, lineno); textChanged = 0; } else { linePtr = index1.linePtr; @@ -4544,16 +4549,20 @@ TextDumpCmd(textPtr, interp, objc, objv) textChanged = DumpLine(interp, textPtr, what, linePtr, 0, 32000000, lineno, command); if (textChanged) { - if (textPtr->flags & DESTROYED) return TCL_OK; - linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, - textPtr, lineno); + if (textPtr->flags & DESTROYED) { + return TCL_OK; + } + linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, + textPtr, lineno); textChanged = 0; } } if (linePtr != NULL) { - DumpLine(interp, textPtr, what, linePtr, 0, - endByteIndex, lineno, command); - if (textPtr->flags & DESTROYED) return TCL_OK; + DumpLine(interp, textPtr, what, linePtr, 0, endByteIndex, lineno, + command); + if (textPtr->flags & DESTROYED) { + return TCL_OK; + } } } @@ -4562,8 +4571,14 @@ TextDumpCmd(textPtr, interp, objc, objv) */ if (atEnd) { - if (textPtr->flags & DESTROYED) return TCL_OK; - /* Re-get the end index, in case it has changed */ + if (textPtr->flags & DESTROYED) { + return TCL_OK; + } + + /* + * Re-get the end index, in case it has changed. + */ + if (TkTextGetObjIndex(interp, textPtr, objv[arg], &index2) != TCL_OK) { return TCL_ERROR; } @@ -4582,29 +4597,31 @@ TextDumpCmd(textPtr, interp, objc, objv) * "start" up to, but not including, "end". * * Results: - * Returns 1 if the command callback made any changes to the text - * widget which will have invalidated internal structures such as - * TkTextSegment, TkTextIndex, pointers. Our caller can then take - * action to recompute such entities. Returns 0 otherwise. + * Returns 1 if the command callback made any changes to the text widget + * which will have invalidated internal structures such as TkTextSegment, + * TkTextIndex, pointers. Our caller can then take action to recompute + * such entities. Returns 0 otherwise. * * Side effects: * None, but see DumpSegment which can have arbitrary side-effects * *---------------------------------------------------------------------- */ + static int -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 startByte, endByte; /* Byte range to dump */ - int lineno; /* Line number for indices dump */ - Tcl_Obj *command; /* Script to apply to the segment */ +DumpLine( + Tcl_Interp *interp, + TkText *textPtr, + int what, /* Bit flags to select segment types. */ + TkTextLine *linePtr, /* The current line. */ + int startByte, int endByte, /* Byte range to dump. */ + int lineno, /* Line number for indices dump. */ + Tcl_Obj *command) /* Script to apply to the segment. */ { - int offset = 0; TkTextSegment *segPtr; TkTextIndex index; + int offset = 0, textChanged = 0; + /* * Must loop through line looking at its segments. * character @@ -4614,17 +4631,15 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command) * window */ - int textChanged = 0; - segPtr = linePtr->segPtr; while ((offset < endByte) && (segPtr != NULL)) { int lineChanged = 0; int currentSize = segPtr->size; - + if ((what & TK_DUMP_TEXT) && (segPtr->typePtr == &tkTextCharType) && (offset + segPtr->size > startByte)) { - int last = segPtr->size; /* Index of last char in seg */ - int first = 0; /* Index of first char in seg */ + int last = segPtr->size; /* Index of last char in seg. */ + int first = 0; /* Index of first char in seg. */ if (offset + segPtr->size > endByte) { last = endByte - offset; @@ -4634,27 +4649,29 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command) } if (last != segPtr->size) { /* - * To avoid modifying the string in place we copy over - * just the segment that we want. Since DumpSegment can - * modify the text, we could not confidently revert the - * modification here. + * To avoid modifying the string in place we copy over just + * the segment that we want. Since DumpSegment can modify the + * text, we could not confidently revert the modification + * here. */ + int length = last - first; - - char *range = (char*) ckalloc((length + 1) * sizeof(char)); - memcpy(range, segPtr->body.chars + first, length * sizeof(char)); + char *range = ckalloc((length + 1) * sizeof(char)); + + memcpy(range, segPtr->body.chars + first, + length * sizeof(char)); range[length] = '\0'; - TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, lineno, - offset + first, &index); + TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, + lineno, offset + first, &index); lineChanged = DumpSegment(textPtr, interp, "text", range, command, &index, what); ckfree(range); } else { - TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, lineno, - offset + first, &index); - lineChanged = DumpSegment(textPtr, interp, "text", segPtr->body.chars + first, - command, &index, what); + TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, + lineno, offset + first, &index); + lineChanged = DumpSegment(textPtr, interp, "text", + segPtr->body.chars + first, command, &index, what); } } else if ((offset >= startByte)) { if ((what & TK_DUMP_MARK) && (segPtr->typePtr->name[0] == 'm')) { @@ -4671,7 +4688,8 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command) } TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, lineno, offset, &index); - lineChanged = DumpSegment(textPtr, interp, "mark", name, command, &index, what); + lineChanged = DumpSegment(textPtr, interp, "mark", name, + command, &index, what); } else if ((what & TK_DUMP_TAG) && (segPtr->typePtr == &tkTextToggleOnType)) { TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, @@ -4693,8 +4711,8 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command) TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, lineno, offset, &index); - lineChanged = DumpSegment(textPtr, interp, "image", name, command, &index, - what); + lineChanged = DumpSegment(textPtr, interp, "image", name, + command, &index, what); } else if ((what & TK_DUMP_WIN) && (segPtr->typePtr->name[0] == 'w')) { TkTextEmbWindow *ewPtr = (TkTextEmbWindow *)&segPtr->body; @@ -4707,34 +4725,42 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command) } TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, lineno, offset, &index); - lineChanged = DumpSegment(textPtr, interp, "window", pathname, command, - &index, what); + lineChanged = DumpSegment(textPtr, interp, "window", pathname, + command, &index, what); } } offset += currentSize; if (lineChanged) { - TkTextSegment * newSegPtr; + TkTextSegment *newSegPtr; int newOffset = 0; + textChanged = 1; - /* Our indices are no longer valid */ + + /* + * Our indices are no longer valid. + */ + if (textPtr->flags & DESTROYED) { return textChanged; } - linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, - textPtr, lineno); + linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, + textPtr, lineno); newSegPtr = linePtr->segPtr; if (segPtr == newSegPtr) { segPtr = segPtr->nextPtr; } else { - while ((newOffset < endByte) && (newOffset < offset) - && (newSegPtr != NULL)) { + while ((newOffset < endByte) && (newOffset < offset) + && (newSegPtr != NULL)) { newOffset += segPtr->size; newSegPtr = newSegPtr->nextPtr; - if (segPtr == newSegPtr) break; + if (segPtr == newSegPtr) { + break; + } } - if (segPtr != newSegPtr && newOffset == offset - && currentSize == 0) { + if (segPtr != newSegPtr && newOffset == offset + && currentSize == 0) { TkTextSegment *searchPtr = newSegPtr; + while (searchPtr != NULL && searchPtr->size == 0) { if (searchPtr == segPtr) { newSegPtr = searchPtr; @@ -4764,10 +4790,10 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command) * make a script callback with that information as arguments. * * Results: - * Returns 1 if the command callback made any changes to the text - * widget which will have invalidated internal structures such as - * TkTextSegment, TkTextIndex, pointers. Our caller can then take - * action to recompute such entities. Returns 0 otherwise. + * Returns 1 if the command callback made any changes to the text widget + * which will have invalidated internal structures such as TkTextSegment, + * TkTextIndex, pointers. Our caller can then take action to recompute + * such entities. Returns 0 otherwise. * * Side effects: * Either evals the callback or appends elements to the result string. @@ -4777,14 +4803,14 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command) */ static int -DumpSegment(textPtr, interp, key, value, command, index, what) - TkText *textPtr; - Tcl_Interp *interp; - CONST char *key; /* Segment type key */ - CONST char *value; /* Segment value */ - Tcl_Obj *command; /* Script callback */ - CONST TkTextIndex *index; /* index with line/byte position info */ - int what; /* Look for TK_DUMP_INDEX bit */ +DumpSegment( + TkText *textPtr, + Tcl_Interp *interp, + CONST char *key, /* Segment type key. */ + CONST char *value, /* Segment value. */ + Tcl_Obj *command, /* Script callback. */ + CONST TkTextIndex *index, /* index with line/byte position info. */ + int what) /* Look for TK_DUMP_INDEX bit. */ { char buffer[TK_POS_CHARS]; @@ -4798,7 +4824,7 @@ DumpSegment(textPtr, interp, key, value, command, index, what) CONST char *argv[4]; char *list; int oldStateEpoch = TkBTreeEpoch(textPtr->sharedTextPtr->tree); - + argv[0] = key; argv[1] = value; argv[2] = buffer; @@ -4806,8 +4832,8 @@ DumpSegment(textPtr, interp, key, value, command, index, what) list = Tcl_Merge(3, argv); Tcl_VarEval(interp, Tcl_GetString(command), " ", list, NULL); ckfree(list); - if ((textPtr->flags & DESTROYED) - || (TkBTreeEpoch(textPtr->sharedTextPtr->tree) != oldStateEpoch)) { + if ((textPtr->flags & DESTROYED) || + TkBTreeEpoch(textPtr->sharedTextPtr->tree) != oldStateEpoch) { return 1; } else { return 0; @@ -4833,8 +4859,8 @@ DumpSegment(textPtr, interp, key, value, command, index, what) */ static int -TextEditUndo(textPtr) - TkText *textPtr; /* Overall information about text widget. */ +TextEditUndo( + TkText *textPtr) /* Overall information about text widget. */ { int status; @@ -4876,8 +4902,8 @@ TextEditUndo(textPtr) */ static int -TextEditRedo(textPtr) - TkText *textPtr; /* Overall information about text widget. */ +TextEditRedo( + TkText *textPtr) /* Overall information about text widget. */ { int status; @@ -4916,11 +4942,11 @@ TextEditRedo(textPtr) */ static int -TextEditCmd(textPtr, interp, objc, objv) - TkText *textPtr; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +TextEditCmd( + TkText *textPtr, /* Information about text widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { int index; @@ -4975,7 +5001,7 @@ TextEditCmd(textPtr, interp, objc, objv) * "event generate $textWidget <<Modified>>" */ - memset((VOID *) &event, 0, sizeof(event)); + memset(&event, 0, sizeof(event)); event.xany.type = VirtualEvent; event.xany.serial = NextRequest(Tk_Display(textPtr->tkwin)); event.xany.send_event = False; @@ -5056,14 +5082,14 @@ TextEditCmd(textPtr, interp, objc, objv) *---------------------------------------------------------------------- */ -static Tcl_Obj* -TextGetText(textPtr, indexPtr1,indexPtr2, visibleOnly) - CONST TkText *textPtr; /* Information about text widget. */ - CONST TkTextIndex *indexPtr1; +static Tcl_Obj * +TextGetText( + CONST TkText *textPtr, /* Information about text widget. */ + CONST TkTextIndex *indexPtr1, /* Get text from this index... */ - CONST TkTextIndex *indexPtr2; + CONST TkTextIndex *indexPtr2, /* ...to this index. */ - int visibleOnly; /* If non-zero, then only return non-elided + int visibleOnly) /* If non-zero, then only return non-elided * characters. */ { TkTextIndex tmpIndex; @@ -5090,8 +5116,8 @@ TextGetText(textPtr, indexPtr1,indexPtr2, visibleOnly) if (indexPtr2->byteIndex == tmpIndex.byteIndex) { break; } else { - int last2 = - indexPtr2->byteIndex - tmpIndex.byteIndex + offset; + int last2 = indexPtr2->byteIndex - tmpIndex.byteIndex + + offset; if (last2 < last) { last = last2; @@ -5127,8 +5153,8 @@ TextGetText(textPtr, indexPtr1,indexPtr2, visibleOnly) */ static void -UpdateDirtyFlag(sharedTextPtr) - TkSharedText *sharedTextPtr;/* Information about text widget. */ +UpdateDirtyFlag( + TkSharedText *sharedTextPtr)/* Information about text widget. */ { int oldDirtyFlag; @@ -5148,7 +5174,7 @@ UpdateDirtyFlag(sharedTextPtr) XEvent event; - memset((VOID *) &event, 0, sizeof(event)); + memset(&event, 0, sizeof(event)); event.xany.type = VirtualEvent; event.xany.serial = NextRequest(Tk_Display(textPtr->tkwin)); event.xany.send_event = False; @@ -5182,15 +5208,15 @@ UpdateDirtyFlag(sharedTextPtr) */ static int -SearchPerform(interp, searchSpecPtr, patObj, fromPtr, toPtr) - Tcl_Interp *interp; /* For error messages */ - SearchSpec *searchSpecPtr; /* Search parameters */ - Tcl_Obj *patObj; /* Contains an exact string or a regexp - * pattern. Must have a refCount > 0 */ - Tcl_Obj *fromPtr; /* Contains information describing the first - * index */ - Tcl_Obj *toPtr; /* NULL or information describing the last - * index */ +SearchPerform( + Tcl_Interp *interp, /* For error messages. */ + SearchSpec *searchSpecPtr, /* Search parameters. */ + Tcl_Obj *patObj, /* Contains an exact string or a regexp + * pattern. Must have a refCount > 0. */ + Tcl_Obj *fromPtr, /* Contains information describing the first + * index. */ + Tcl_Obj *toPtr) /* NULL or information describing the last + * index. */ { /* * Find the starting line and starting offset (measured in Unicode chars @@ -5209,7 +5235,7 @@ SearchPerform(interp, searchSpecPtr, patObj, fromPtr, toPtr) if (toPtr != NULL) { CONST TkTextIndex *indexToPtr, *indexFromPtr; - TkText *textPtr = (TkText*)(searchSpecPtr->clientData); + TkText *textPtr = (TkText *) searchSpecPtr->clientData; indexToPtr = TkTextGetIndexFromObj(interp, textPtr, toPtr); if (indexToPtr == NULL) { @@ -5284,11 +5310,11 @@ SearchPerform(interp, searchSpecPtr, patObj, fromPtr, toPtr) */ static int -SearchCore(interp, searchSpecPtr, patObj) - Tcl_Interp *interp; /* For error messages */ - SearchSpec *searchSpecPtr; /* Search parameters */ - Tcl_Obj *patObj; /* Contains an exact string or a regexp - * pattern. Must have a refCount > 0 */ +SearchCore( + Tcl_Interp *interp, /* For error messages. */ + SearchSpec *searchSpecPtr, /* Search parameters. */ + Tcl_Obj *patObj) /* Contains an exact string or a regexp + * pattern. Must have a refCount > 0. */ { /* * For exact searches these are utf-8 char* offsets, for regexp searches @@ -5569,6 +5595,7 @@ SearchCore(interp, searchSpecPtr, patObj) /* * No match. */ + break; } else { int extraLines = 1; @@ -5687,7 +5714,7 @@ SearchCore(interp, searchSpecPtr, patObj) searchSpecPtr, lineInfo, theLine, matchOffset, matchLength)) { /* - * We reached the end of the search + * We reached the end of the search. */ goto searchDone; @@ -5730,13 +5757,11 @@ SearchCore(interp, searchSpecPtr, patObj) } } else { firstOffset = p - startOfLine + - Tcl_UtfToUniChar(startOfLine+matchOffset, &ch); + Tcl_UtfToUniChar(startOfLine+matchOffset,&ch); } } } while (searchSpecPtr->all); - } else { - int maxExtraLines = 0; int matches = 0; int lastNonOverlap = -1; @@ -5746,8 +5771,8 @@ SearchCore(interp, searchSpecPtr, patObj) int match; int lastFullLine = lastOffset; - match = Tcl_RegExpExecObj(interp, regexp, theLine, firstOffset, - 1, ((firstOffset > 0) ? TCL_REG_NOTBOL : 0)); + match = Tcl_RegExpExecObj(interp, regexp, theLine, + firstOffset, 1, (firstOffset>0 ? TCL_REG_NOTBOL : 0)); if (match < 0) { code = TCL_ERROR; goto searchDone; @@ -5798,7 +5823,7 @@ SearchCore(interp, searchSpecPtr, patObj) prevFullLine = lastTotal; /* - * Move firstOffset to first possible start + * Move firstOffset to first possible start. */ if (!match) { @@ -5896,7 +5921,7 @@ SearchCore(interp, searchSpecPtr, patObj) if (match && ((firstOffset + info.matches[0].end) >= prevFullLine)) { if (extraLines > 0) { - extraLinesSearched = extraLines - 1; + extraLinesSearched = extraLines - 1; } lastFullLine = prevFullLine; } @@ -5948,7 +5973,7 @@ SearchCore(interp, searchSpecPtr, patObj) */ if (thisOffset-lastNonOverlap >= - lastBackwardsMatchOffset+matchLength) { + lastBackwardsMatchOffset+matchLength){ /* * Totally encloses previous match, so * forget the previous match. @@ -6078,7 +6103,7 @@ SearchCore(interp, searchSpecPtr, patObj) searchSpecPtr, lineInfo, theLine, matchOffset, matchLength)) { /* - * We reached the end of the search + * We reached the end of the search. */ goto searchDone; @@ -6213,7 +6238,7 @@ SearchCore(interp, searchSpecPtr, patObj) while (linesSearched-- > 0) { /* - * If we have just completed the 'stopLine', we are done + * If we have just completed the 'stopLine', we are done. */ if (lineNum == searchSpecPtr->stopLine) { @@ -6277,18 +6302,18 @@ SearchCore(interp, searchSpecPtr, patObj) } /* - * Free up the cached line and pattern + * Free up the cached line and pattern. */ Tcl_DecrRefCount(theLine); Tcl_DecrRefCount(patObj); /* - * Free up any extra space we allocated + * Free up any extra space we allocated. */ if (storeMatch != smArray) { - ckfree((char*)storeMatch); + ckfree((char *) storeMatch); } return code; @@ -6312,11 +6337,11 @@ SearchCore(interp, searchSpecPtr, patObj) */ static Tcl_Obj * -GetLineStartEnd(clientData, tkwin, recordPtr, internalOffset) - ClientData clientData; - Tk_Window tkwin; - char *recordPtr; /* Pointer to widget record. */ - int internalOffset; /* Offset within *recordPtr containing the +GetLineStartEnd( + ClientData clientData, + Tk_Window tkwin, + char *recordPtr, /* Pointer to widget record. */ + int internalOffset) /* Offset within *recordPtr containing the * line value. */ { TkTextLine *linePtr = *(TkTextLine **)(recordPtr + internalOffset); @@ -6348,23 +6373,22 @@ GetLineStartEnd(clientData, tkwin, recordPtr, internalOffset) */ static int -SetLineStartEnd(clientData, interp, tkwin, value, recordPtr, internalOffset, - oldInternalPtr, flags) - ClientData clientData; - Tcl_Interp *interp; /* Current interp; may be used for errors. */ - Tk_Window tkwin; /* Window for which option is being set. */ - Tcl_Obj **value; /* Pointer to the pointer to the value object. +SetLineStartEnd( + ClientData clientData, + Tcl_Interp *interp, /* Current interp; may be used for errors. */ + Tk_Window tkwin, /* Window for which option is being set. */ + Tcl_Obj **value, /* Pointer to the pointer to the value object. * We use a pointer to the pointer because we * may need to return a value (NULL). */ - char *recordPtr; /* Pointer to storage for the widget record. */ - int internalOffset; /* Offset within *recordPtr at which the + char *recordPtr, /* Pointer to storage for the widget record. */ + int internalOffset, /* Offset within *recordPtr at which the * internal value is to be stored. */ - char *oldInternalPtr; /* Pointer to storage for the old value. */ - int flags; /* Flags for the option, set Tk_SetOptions. */ + char *oldInternalPtr, /* Pointer to storage for the old value. */ + int flags) /* Flags for the option, set Tk_SetOptions. */ { TkTextLine *linePtr = NULL; char *internalPtr; - TkText *textPtr = (TkText*)recordPtr; + TkText *textPtr = (TkText *) recordPtr; if (internalOffset >= 0) { internalPtr = recordPtr + internalOffset; @@ -6408,11 +6432,11 @@ SetLineStartEnd(clientData, interp, tkwin, value, recordPtr, internalOffset, */ static void -RestoreLineStartEnd(clientData, tkwin, internalPtr, oldInternalPtr) - ClientData clientData; - Tk_Window tkwin; - char *internalPtr; /* Pointer to storage for value. */ - char *oldInternalPtr; /* Pointer to old value. */ +RestoreLineStartEnd( + ClientData clientData, + Tk_Window tkwin, + char *internalPtr, /* Pointer to storage for value. */ + char *oldInternalPtr) /* Pointer to old value. */ { *(TkTextLine **)internalPtr = *(TkTextLine **)oldInternalPtr; } @@ -6436,8 +6460,8 @@ RestoreLineStartEnd(clientData, tkwin, internalPtr, oldInternalPtr) */ static int -ObjectIsEmpty(objPtr) - Tcl_Obj *objPtr; /* Object to test. May be NULL. */ +ObjectIsEmpty( + Tcl_Obj *objPtr) /* Object to test. May be NULL. */ { int length; @@ -6493,7 +6517,7 @@ TkpTesttextCmd( if (info.isNativeObjectProc) { textPtr = (TkText *) info.objClientData; } else { - textPtr = (TkText *) info.clientData; + textPtr = (TkText *) info.clientData; } len = strlen(argv[2]); if (strncmp(argv[2], "byteindex", len) == 0) { @@ -6534,3 +6558,11 @@ TkpTesttextCmd( return TCL_OK; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c index e8f0112..9b104c6 100644 --- a/generic/tkTextBTree.c +++ b/generic/tkTextBTree.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkTextBTree.c,v 1.23 2007/01/18 23:20:37 nijtmans Exp $ + * RCS: @(#) $Id: tkTextBTree.c,v 1.24 2007/02/22 13:56:33 dkf Exp $ */ #include "tkInt.h" @@ -66,7 +66,7 @@ typedef struct Node { Summary *summaryPtr; /* First in malloc-ed list of info about tags * in this subtree (NULL if no tag info in the * subtree). */ - int level; /* Level of this node in the B-tree. 0 refers + int level; /* Level of this node in the B-tree. 0 refers * to the bottom of the tree (children are * lines, not nodes). */ union { /* First in linked list of children. */ @@ -76,7 +76,7 @@ typedef struct Node { int numChildren; /* Number of children of this node. */ int numLines; /* Total number of lines (leaves) in the * subtree rooted here. */ - int* numPixels; /* Array containing total number of vertical + int *numPixels; /* Array containing total number of vertical * display pixels in the subtree rooted here, * one entry for each peer widget. */ } Node; @@ -108,8 +108,8 @@ typedef struct BTree { int clients; /* Number of clients of this B-tree. */ int pixelReferences; /* Number of clients of this B-tree which care * about pixel heights. */ - int stateEpoch; /* Updated each time any aspect of the B-tree - * changes. */ + int stateEpoch; /* Updated each time any aspect of the B-tree + * changes. */ TkSharedText *sharedTextPtr;/* Used to find tagTable in consistency * checking code, and to access list of all * B-tree clients. */ @@ -134,8 +134,7 @@ typedef struct TagInfo { } TagInfo; /* - * Variable that indicates whether to enable consistency checks for - * debugging. + * Variable that indicates whether to enable consistency checks for debugging. */ int tkBTreeDebug = 0; @@ -153,47 +152,44 @@ int tkBTreeDebug = 0; * Forward declarations for functions defined in this file: */ -static int AdjustPixelClient _ANSI_ARGS_((BTree *treePtr, - int defaultHeight, Node *nodePtr, TkTextLine *start, - TkTextLine *end, int useReference, - int newPixelReferences, int *counting)); -static void ChangeNodeToggleCount _ANSI_ARGS_((Node *nodePtr, - TkTextTag *tagPtr, int delta)); -static void CharCheckProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr)); -static int CharDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr, int treeGone)); -static TkTextSegment * CharCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr)); -static TkTextSegment * CharSplitProc _ANSI_ARGS_((TkTextSegment *segPtr, - int index)); -static void CheckNodeConsistency _ANSI_ARGS_((Node *nodePtr, - int references)); -static void CleanupLine _ANSI_ARGS_((TkTextLine *linePtr)); -static void DeleteSummaries _ANSI_ARGS_((Summary *tagPtr)); -static void DestroyNode _ANSI_ARGS_((Node *nodePtr)); -static TkTextSegment * FindTagEnd _ANSI_ARGS_((TkTextBTree tree, - TkTextTag *tagPtr, TkTextIndex *indexPtr)); -static void IncCount _ANSI_ARGS_((TkTextTag *tagPtr, int inc, - TagInfo *tagInfoPtr)); -static void Rebalance _ANSI_ARGS_((BTree *treePtr, Node *nodePtr)); -static void RecomputeNodeCounts _ANSI_ARGS_((BTree *treePtr, - Node *nodePtr)); -static void RemovePixelClient _ANSI_ARGS_((BTree *treePtr, - Node *nodePtr, int overwriteWithLast)); -static TkTextSegment * SplitSeg _ANSI_ARGS_((TkTextIndex *indexPtr)); -static void ToggleCheckProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr)); -static TkTextSegment * ToggleCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr)); -static int ToggleDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr, int treeGone)); -static void ToggleLineChangeProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr)); -static TkTextSegment * FindTagStart _ANSI_ARGS_((TkTextBTree tree, - TkTextTag *tagPtr, TkTextIndex *indexPtr)); -static void AdjustStartEndRefs _ANSI_ARGS_((BTree *treePtr, - TkText *textPtr, int action)); +static int AdjustPixelClient(BTree *treePtr, int defaultHeight, + Node *nodePtr, TkTextLine *start, TkTextLine *end, + int useReference, int newPixelReferences, + int *counting); +static void ChangeNodeToggleCount(Node *nodePtr, + TkTextTag *tagPtr, int delta); +static void CharCheckProc(TkTextSegment *segPtr, + TkTextLine *linePtr); +static int CharDeleteProc(TkTextSegment *segPtr, + TkTextLine *linePtr, int treeGone); +static TkTextSegment * CharCleanupProc(TkTextSegment *segPtr, + TkTextLine *linePtr); +static TkTextSegment * CharSplitProc(TkTextSegment *segPtr, int index); +static void CheckNodeConsistency(Node *nodePtr, int references); +static void CleanupLine(TkTextLine *linePtr); +static void DeleteSummaries(Summary *tagPtr); +static void DestroyNode(Node *nodePtr); +static TkTextSegment * FindTagEnd(TkTextBTree tree, TkTextTag *tagPtr, + TkTextIndex *indexPtr); +static void IncCount(TkTextTag *tagPtr, int inc, + TagInfo *tagInfoPtr); +static void Rebalance(BTree *treePtr, Node *nodePtr); +static void RecomputeNodeCounts(BTree *treePtr, Node *nodePtr); +static void RemovePixelClient(BTree *treePtr, Node *nodePtr, + int overwriteWithLast); +static TkTextSegment * SplitSeg(TkTextIndex *indexPtr); +static void ToggleCheckProc(TkTextSegment *segPtr, + TkTextLine *linePtr); +static TkTextSegment * ToggleCleanupProc(TkTextSegment *segPtr, + TkTextLine *linePtr); +static int ToggleDeleteProc(TkTextSegment *segPtr, + TkTextLine *linePtr, int treeGone); +static void ToggleLineChangeProc(TkTextSegment *segPtr, + TkTextLine *linePtr); +static TkTextSegment * FindTagStart(TkTextBTree tree, TkTextTag *tagPtr, + TkTextIndex *indexPtr); +static void AdjustStartEndRefs(BTree *treePtr, TkText *textPtr, + int action); /* * Actions for use by AdjustStartEndRefs @@ -265,8 +261,8 @@ const Tk_SegType tkTextToggleOffType = { */ TkTextBTree -TkBTreeCreate(sharedTextPtr) - TkSharedText *sharedTextPtr; +TkBTreeCreate( + TkSharedText *sharedTextPtr) { register BTree *treePtr; register Node *rootPtr; @@ -294,7 +290,7 @@ TkBTreeCreate(sharedTextPtr) /* * The tree currently has no registered clients, so all pixel count - * pointers are simply NULL + * pointers are simply NULL. */ rootPtr->numPixels = NULL; @@ -357,8 +353,8 @@ TkBTreeCreate(sharedTextPtr) * * Results: * The return value is the pixelReference used by the B-tree to refer to - * pixel counts for the new client. It should be stored by the caller. - * If defaultHeight was negative, then the return value will be -1. + * pixel counts for the new client. It should be stored by the caller. If + * defaultHeight was negative, then the return value will be -1. * * Side effects: * Memory may be allocated and initialized. @@ -367,13 +363,13 @@ TkBTreeCreate(sharedTextPtr) */ void -TkBTreeAddClient(tree, textPtr, defaultHeight) - TkTextBTree tree; /* B-tree to add a client to */ - TkText *textPtr; /* Client to add */ - int defaultHeight; /* Default line height for the new client, or +TkBTreeAddClient( + TkTextBTree tree, /* B-tree to add a client to. */ + TkText *textPtr, /* Client to add. */ + int defaultHeight) /* Default line height for the new client, or * -1 if no pixel heights are to be kept. */ { - register BTree *treePtr = (BTree*) tree; + register BTree *treePtr = (BTree *) tree; if (treePtr == NULL) { Tcl_Panic("NULL treePtr in TkBTreeAddClient"); @@ -427,13 +423,13 @@ TkBTreeAddClient(tree, textPtr, defaultHeight) */ void -TkBTreeClientRangeChanged(textPtr, defaultHeight) - TkText *textPtr; /* Client whose start, end have changed. */ - int defaultHeight; /* Default line height for the new client, or +TkBTreeClientRangeChanged( + TkText *textPtr, /* Client whose start, end have changed. */ + int defaultHeight) /* Default line height for the new client, or * -1 if no pixel heights are to be kept. */ { TkTextLine *end; - BTree *treePtr = (BTree*) textPtr->sharedTextPtr->tree; + BTree *treePtr = (BTree *) textPtr->sharedTextPtr->tree; int counting = (textPtr->start == NULL ? 1 : 0); int useReference = textPtr->pixelReference; @@ -472,8 +468,8 @@ TkBTreeClientRangeChanged(textPtr, defaultHeight) */ void -TkBTreeDestroy(tree) - TkTextBTree tree; /* Tree to clean up */ +TkBTreeDestroy( + TkTextBTree tree) /* Tree to clean up. */ { BTree *treePtr = (BTree *) tree; @@ -496,8 +492,8 @@ TkBTreeDestroy(tree) * * TkBTreeEpoch -- * - * Return the epoch for the B-tree. This number is incremented - * any time anything changes in the tree. + * Return the epoch for the B-tree. This number is incremented any time + * anything changes in the tree. * * Results: * The epoch number. @@ -509,8 +505,8 @@ TkBTreeDestroy(tree) */ int -TkBTreeEpoch(tree) - TkTextBTree tree; /* Tree to get epoch for */ +TkBTreeEpoch( + TkTextBTree tree) /* Tree to get epoch for. */ { BTree *treePtr = (BTree *) tree; return treePtr->stateEpoch; @@ -537,9 +533,9 @@ TkBTreeEpoch(tree) */ void -TkBTreeRemoveClient(tree, textPtr) - TkTextBTree tree; /* Tree to remove client from. */ - TkText *textPtr; /* Client to remove. */ +TkBTreeRemoveClient( + TkTextBTree tree, /* Tree to remove client from. */ + TkText *textPtr) /* Client to remove. */ { BTree *treePtr = (BTree *) tree; int pixelReference = textPtr->pixelReference; @@ -582,7 +578,7 @@ TkBTreeRemoveClient(tree, textPtr) adjustPtr = treePtr->sharedTextPtr->peers; while (adjustPtr != NULL) { - if (adjustPtr->pixelReference == (treePtr->pixelReferences-1)) { + if (adjustPtr->pixelReference == treePtr->pixelReferences-1) { adjustPtr->pixelReference = pixelReference; break; } @@ -618,11 +614,11 @@ TkBTreeRemoveClient(tree, textPtr) */ static void -AdjustStartEndRefs(treePtr, textPtr, action) - BTree *treePtr; /* The entire B-tree */ - TkText *textPtr; /* The text widget for which we want to adjust +AdjustStartEndRefs( + BTree *treePtr, /* The entire B-tree. */ + TkText *textPtr, /* The text widget for which we want to adjust * it's start and end cache. */ - int action; /* Action to perform */ + int action) /* Action to perform. */ { if (action & TEXT_REMOVE_REFS) { int i = 0; @@ -688,9 +684,9 @@ AdjustStartEndRefs(treePtr, textPtr, action) * of a new peer widget based on this B-tree, or for the modification of * the start, end lines of an existing peer widget. * - * Immediately _after_ calling this, treePtr->clients and - * treePtr->pixelReferences should be adjusted if needed (i.e. if this is - * a new peer). + * Immediately _after_ calling this, treePtr->pixelReferences and + * treePtr->clients should be adjusted if needed (i.e. if this is a new + * peer). * * Results: * None. @@ -702,19 +698,18 @@ AdjustStartEndRefs(treePtr, textPtr, action) */ static int -AdjustPixelClient(treePtr, defaultHeight, nodePtr, start, end, - useReference, newPixelReferences, counting) - BTree *treePtr; /* Pointer to tree */ - int defaultHeight; /* Default pixel line height, which can be +AdjustPixelClient( + BTree *treePtr, /* Pointer to tree. */ + int defaultHeight, /* Default pixel line height, which can be * zero. */ - Node *nodePtr; /* Adjust from this node downwards */ - TkTextLine *start; /* First line for this pixel client */ - TkTextLine *end; /* Last line for this pixel client */ - int useReference; /* pixel reference for the client we are - * adding or changing */ - int newPixelReferences; /* New number of pixel references to this - * B-tree */ - int *counting; /* References an integer which is zero if + Node *nodePtr, /* Adjust from this node downwards. */ + TkTextLine *start, /* First line for this pixel client. */ + TkTextLine *end, /* Last line for this pixel client. */ + int useReference, /* pixel reference for the client we are + * adding or changing. */ + int newPixelReferences, /* New number of pixel references to this + * B-tree. */ + int *counting) /* References an integer which is zero if * we're outside the relevant range for this * client, and 1 if we're inside. */ { @@ -730,6 +725,7 @@ AdjustPixelClient(treePtr, defaultHeight, nodePtr, start, end, if (nodePtr->level != 0) { Node *loopPtr = nodePtr->children.nodePtr; + while (loopPtr != NULL) { pixelCount += AdjustPixelClient(treePtr, defaultHeight, loopPtr, start, end, useReference, newPixelReferences, counting); @@ -756,7 +752,7 @@ AdjustPixelClient(treePtr, defaultHeight, nodePtr, start, end, */ linePtr->pixels[2*useReference] = (*counting ? defaultHeight : 0); - linePtr->pixels[1+2*useReference] = (*counting ? 0 : 1); + linePtr->pixels[2*useReference+1] = (*counting ? 0 : 1); pixelCount += linePtr->pixels[2*useReference]; linePtr = linePtr->nextPtr; @@ -791,18 +787,18 @@ AdjustPixelClient(treePtr, defaultHeight, nodePtr, start, end, */ static void -RemovePixelClient(treePtr, nodePtr, overwriteWithLast) - BTree *treePtr; /* Pointer to tree */ - Node *nodePtr; /* Adjust from this node downwards */ - int overwriteWithLast; /* Over-write this peer widget's information +RemovePixelClient( + BTree *treePtr, /* Pointer to tree. */ + Node *nodePtr, /* Adjust from this node downwards. */ + int overwriteWithLast) /* Over-write this peer widget's information * with the last one. */ { /* * Traverse entire tree down from nodePtr, reallocating pixel structures - * for each Node and TkTextLine, removing space allocated for one peer. - * If 'overwriteWithLast' is not -1, then copy the information which was - * in the last slot on top of one of the others (i.e. it's not the last - * one we're deleting). + * for each Node and TkTextLine, removing space allocated for one peer. If + * 'overwriteWithLast' is not -1, then copy the information which was in + * the last slot on top of one of the others (i.e. it's not the last one + * we're deleting). */ if (overwriteWithLast != -1) { @@ -859,8 +855,8 @@ RemovePixelClient(treePtr, nodePtr, overwriteWithLast) */ static void -DestroyNode(nodePtr) - register Node *nodePtr; /* Destroy from this node downwards */ +DestroyNode( + register Node *nodePtr) /* Destroy from this node downwards. */ { if (nodePtr->level == 0) { TkTextLine *linePtr; @@ -909,11 +905,12 @@ DestroyNode(nodePtr) */ static void -DeleteSummaries(summaryPtr) - register Summary *summaryPtr; +DeleteSummaries( + register Summary *summaryPtr) /* First in list of node's tag summaries. */ { register Summary *nextPtr; + while (summaryPtr != NULL) { nextPtr = summaryPtr->nextPtr; ckfree((char *) summaryPtr); @@ -939,23 +936,24 @@ DeleteSummaries(summaryPtr) */ int -TkBTreeAdjustPixelHeight(textPtr, linePtr, newPixelHeight, mergedLogicalLines) - const TkText *textPtr; /* Client of the B-tree */ - register TkTextLine *linePtr; +TkBTreeAdjustPixelHeight( + const TkText *textPtr, /* Client of the B-tree. */ + register TkTextLine *linePtr, /* The logical line to update. */ - int newPixelHeight; /* The line's known height in pixels. */ - int mergedLogicalLines; /* The number of extra logical lines which + int newPixelHeight, /* The line's known height in pixels. */ + int mergedLogicalLines) /* The number of extra logical lines which * have been merged with this one (due to * elided eols). They will have their pixel * height set to zero, and the total pixel - * height associated with the given linePtr */ + * height associated with the given + * linePtr. */ { register Node *nodePtr; int changeToPixelCount; /* Counts change to total number of pixels in * file. */ int pixelReference = textPtr->pixelReference; - changeToPixelCount = newPixelHeight - linePtr->pixels[2*pixelReference]; + changeToPixelCount = newPixelHeight - linePtr->pixels[2 * pixelReference]; /* * Increment the pixel counts in all the parent nodes of the current line, @@ -970,7 +968,7 @@ TkBTreeAdjustPixelHeight(textPtr, linePtr, newPixelHeight, mergedLogicalLines) nodePtr->numPixels[pixelReference] += changeToPixelCount; } - linePtr->pixels[2*pixelReference] = newPixelHeight; + linePtr->pixels[2 * pixelReference] = newPixelHeight; /* * Any merged logical lines must have their height set to zero. @@ -1007,14 +1005,14 @@ TkBTreeAdjustPixelHeight(textPtr, linePtr, newPixelHeight, mergedLogicalLines) */ void -TkBTreeInsertChars(tree, indexPtr, string) - TkTextBTree tree; /* Tree to insert into */ - register TkTextIndex *indexPtr; +TkBTreeInsertChars( + TkTextBTree tree, /* Tree to insert into. */ + register TkTextIndex *indexPtr, /* Indicates where to insert text. When the * function returns, this index is no longer * valid because of changes to the segment * structure. */ - const char *string; /* Pointer to bytes to insert (may contain + const char *string) /* Pointer to bytes to insert (may contain * newlines, must be null-terminated). */ { register Node *nodePtr; @@ -1039,7 +1037,7 @@ TkBTreeInsertChars(tree, indexPtr, string) int ref; int pixels[PIXEL_CLIENTS]; - BTree *treePtr = (BTree*)tree; + BTree *treePtr = (BTree *) tree; treePtr->stateEpoch++; prevPtr = SplitSeg(indexPtr); linePtr = indexPtr->linePtr; @@ -1093,7 +1091,7 @@ TkBTreeInsertChars(tree, indexPtr, string) newLinePtr = (TkTextLine *) ckalloc(sizeof(TkTextLine)); newLinePtr->pixels = (int *) - ckalloc(sizeof(int)*2*treePtr->pixelReferences); + ckalloc(sizeof(int) * 2 * treePtr->pixelReferences); newLinePtr->parentPtr = linePtr->parentPtr; newLinePtr->nextPtr = linePtr->nextPtr; @@ -1101,14 +1099,14 @@ TkBTreeInsertChars(tree, indexPtr, string) newLinePtr->segPtr = segPtr->nextPtr; /* - * Set up a starting default height, which will be re-adjusted - * later. We need to do this for each referenced widget + * Set up a starting default height, which will be re-adjusted later. + * We need to do this for each referenced widget. */ for (ref = 0; ref < treePtr->pixelReferences; ref++) { - newLinePtr->pixels[2*ref] = linePtr->pixels[2*ref]; - newLinePtr->pixels[1+2*ref] = 0; - changeToPixelCount[ref] += newLinePtr->pixels[2*ref]; + newLinePtr->pixels[2 * ref] = linePtr->pixels[2 * ref]; + newLinePtr->pixels[2 * ref + 1] = 0; + changeToPixelCount[ref] += newLinePtr->pixels[2 * ref]; } segPtr->nextPtr = NULL; @@ -1152,7 +1150,7 @@ TkBTreeInsertChars(tree, indexPtr, string) } } if (treePtr->pixelReferences > PIXEL_CLIENTS) { - ckfree((char*)changeToPixelCount); + ckfree((char *) changeToPixelCount); } nodePtr = linePtr->parentPtr; @@ -1193,14 +1191,14 @@ TkBTreeInsertChars(tree, indexPtr, string) */ static TkTextSegment * -SplitSeg(indexPtr) - TkTextIndex *indexPtr; /* Index identifying position at which to +SplitSeg( + TkTextIndex *indexPtr) /* Index identifying position at which to * split a segment. */ { TkTextSegment *prevPtr, *segPtr; TkTextLine *linePtr; - int count = indexPtr->byteIndex; + linePtr = indexPtr->linePtr; prevPtr = NULL; segPtr = linePtr->segPtr; @@ -1228,12 +1226,14 @@ SplitSeg(indexPtr) if (segPtr == NULL) { /* * Two logical lines merged into one display line through eliding - * of a newline + * of a newline. */ linePtr = TkBTreeNextLine(NULL, linePtr); if (linePtr == NULL) { - /* Reached end of the text */ + /* + * Reached end of the text. + */ } segPtr = linePtr->segPtr; } @@ -1262,8 +1262,8 @@ SplitSeg(indexPtr) */ static void -CleanupLine(linePtr) - TkTextLine *linePtr; /* Line to be cleaned up. */ +CleanupLine( + TkTextLine *linePtr) /* Line to be cleaned up. */ { TkTextSegment *segPtr, **prevPtrPtr; int anyChanges; @@ -1316,12 +1316,12 @@ CleanupLine(linePtr) */ void -TkBTreeDeleteIndexRange(tree, index1Ptr, index2Ptr) - TkTextBTree tree; /* Tree to delete from */ - register TkTextIndex *index1Ptr; +TkBTreeDeleteIndexRange( + TkTextBTree tree, /* Tree to delete from. */ + register TkTextIndex *index1Ptr, /* Indicates first character that is to be * deleted. */ - register TkTextIndex *index2Ptr; + register TkTextIndex *index2Ptr) /* Indicates character just after the last one * that is to be deleted. */ { @@ -1334,7 +1334,8 @@ TkBTreeDeleteIndexRange(tree, index1Ptr, index2Ptr) Node *curNodePtr, *nodePtr; int changeToLineCount = 0; int ref; - BTree *treePtr = (BTree*)tree; + BTree *treePtr = (BTree *) tree; + treePtr->stateEpoch++; /* @@ -1345,7 +1346,7 @@ TkBTreeDeleteIndexRange(tree, index1Ptr, index2Ptr) lastPtr = SplitSeg(index2Ptr); if (lastPtr != NULL) { lastPtr = lastPtr->nextPtr; - } else { + } else { lastPtr = index2Ptr->linePtr->segPtr; } prevPtr = SplitSeg(index1Ptr); @@ -1426,8 +1427,8 @@ TkBTreeDeleteIndexRange(tree, index1Ptr, index2Ptr) segPtr = curLinePtr->segPtr; /* - * If the node is empty then delete it and its parents, - * recursively upwards until a non-empty node is found. + * If the node is empty then delete it and its parents recursively + * upwards until a non-empty node is found. */ while (curNodePtr->numChildren == 0) { @@ -1591,10 +1592,10 @@ TkBTreeDeleteIndexRange(tree, index1Ptr, index2Ptr) */ TkTextLine * -TkBTreeFindLine(tree, textPtr, line) - TkTextBTree tree; /* B-tree in which to find line. */ - const TkText *textPtr; /* Relative to this client of the B-tree */ - int line; /* Index of desired line. */ +TkBTreeFindLine( + TkTextBTree tree, /* B-tree in which to find line. */ + const TkText *textPtr, /* Relative to this client of the B-tree. */ + int line) /* Index of desired line. */ { BTree *treePtr = (BTree *) tree; register Node *nodePtr; @@ -1610,7 +1611,7 @@ TkBTreeFindLine(tree, textPtr, line) } /* - * Check for the any start/end offset for this text widget + * Check for the any start/end offset for this text widget. */ if (textPtr != NULL) { @@ -1680,11 +1681,11 @@ TkBTreeFindLine(tree, textPtr, line) */ TkTextLine * -TkBTreeFindPixelLine(tree, textPtr, pixels, pixelOffset) - TkTextBTree tree; /* B-tree to use. */ - const TkText *textPtr; /* Relative to this client of the B-tree */ - int pixels; /* Pixel index of desired line. */ - int *pixelOffset; /* Used to return offset */ +TkBTreeFindPixelLine( + TkTextBTree tree, /* B-tree to use. */ + const TkText *textPtr, /* Relative to this client of the B-tree. */ + int pixels, /* Pixel index of desired line. */ + int *pixelOffset) /* Used to return offset. */ { BTree *treePtr = (BTree *) tree; register Node *nodePtr; @@ -1721,12 +1722,12 @@ TkBTreeFindPixelLine(tree, textPtr, pixels, pixelOffset) */ for (linePtr = nodePtr->children.linePtr; - linePtr->pixels[2*pixelReference] < pixels; + linePtr->pixels[2 * pixelReference] < pixels; linePtr = linePtr->nextPtr) { if (linePtr == NULL) { Tcl_Panic("TkBTreeFindPixelLine ran out of lines"); } - pixels -= linePtr->pixels[2*pixelReference]; + pixels -= linePtr->pixels[2 * pixelReference]; } if (pixelOffset != NULL && linePtr != NULL) { *pixelOffset = pixels; @@ -1754,9 +1755,9 @@ TkBTreeFindPixelLine(tree, textPtr, pixels, pixelOffset) */ TkTextLine * -TkBTreeNextLine(textPtr, linePtr) - const TkText *textPtr; /* Next line in the context of this client */ - register TkTextLine *linePtr; +TkBTreeNextLine( + const TkText *textPtr, /* Next line in the context of this client. */ + register TkTextLine *linePtr) /* Pointer to existing line in B-tree. */ { register Node *nodePtr; @@ -1810,9 +1811,9 @@ TkBTreeNextLine(textPtr, linePtr) */ TkTextLine * -TkBTreePreviousLine(textPtr, linePtr) - TkText *textPtr; /* Relative to this client of the B-tree */ - register TkTextLine *linePtr; +TkBTreePreviousLine( + TkText *textPtr /* Relative to this client of the B-tree. */ + register TkTextLine *linePtr) /* Pointer to existing line in B-tree. */ { register Node *nodePtr; @@ -1827,7 +1828,7 @@ TkBTreePreviousLine(textPtr, linePtr) * Find the line under this node just before the starting line. */ - prevPtr = linePtr->parentPtr->children.linePtr; /* First line at leaf */ + prevPtr = linePtr->parentPtr->children.linePtr; /* First line at leaf. */ while (prevPtr != linePtr) { if (prevPtr->nextPtr == linePtr) { return prevPtr; @@ -1893,9 +1894,9 @@ TkBTreePreviousLine(textPtr, linePtr) */ int -TkBTreePixelsTo(textPtr, linePtr) - const TkText *textPtr; /* Relative to this client of the B-tree */ - TkTextLine *linePtr; /* Pointer to existing line in B-tree. */ +TkBTreePixelsTo( + const TkText *textPtr, /* Relative to this client of the B-tree. */ + TkTextLine *linePtr) /* Pointer to existing line in B-tree. */ { register TkTextLine *linePtr2; register Node *nodePtr, *parentPtr; @@ -1913,7 +1914,7 @@ TkBTreePixelsTo(textPtr, linePtr) if (linePtr2 == NULL) { Tcl_Panic("TkBTreePixelsTo couldn't find line"); } - index += linePtr2->pixels[2*pixelReference]; + index += linePtr2->pixels[2 * pixelReference]; } /* @@ -1924,6 +1925,7 @@ TkBTreePixelsTo(textPtr, linePtr) for (parentPtr = nodePtr->parentPtr ; parentPtr != NULL; nodePtr = parentPtr, parentPtr = parentPtr->parentPtr) { register Node *nodePtr2; + for (nodePtr2 = parentPtr->children.nodePtr; nodePtr2 != nodePtr; nodePtr2 = nodePtr2->nextPtr) { if (nodePtr2 == NULL) { @@ -1954,9 +1956,9 @@ TkBTreePixelsTo(textPtr, linePtr) */ int -TkBTreeLinesTo(textPtr, linePtr) - const TkText *textPtr; /* Relative to this client of the B-tree */ - TkTextLine *linePtr; /* Pointer to existing line in B-tree. */ +TkBTreeLinesTo( + const TkText *textPtr, /* Relative to this client of the B-tree. */ + TkTextLine *linePtr) /* Pointer to existing line in B-tree. */ { register TkTextLine *linePtr2; register Node *nodePtr, *parentPtr, *nodePtr2; @@ -2015,11 +2017,11 @@ TkBTreeLinesTo(textPtr, linePtr) /* ARGSUSED */ void -TkBTreeLinkSegment(segPtr, indexPtr) - TkTextSegment *segPtr; /* Pointer to new segment to be added to +TkBTreeLinkSegment( + TkTextSegment *segPtr, /* Pointer to new segment to be added to * B-tree. Should be completely initialized by * caller except for nextPtr field. */ - TkTextIndex *indexPtr; /* Where to add segment: it gets linked in + TkTextIndex *indexPtr) /* Where to add segment: it gets linked in * just before the segment indicated here. */ { register TkTextSegment *prevPtr; @@ -2036,7 +2038,7 @@ TkBTreeLinkSegment(segPtr, indexPtr) if (tkBTreeDebug) { TkBTreeCheck(indexPtr->tree); } - ((BTree*)indexPtr->tree)->stateEpoch++; + ((BTree *)indexPtr->tree)->stateEpoch++; } /* @@ -2058,9 +2060,9 @@ TkBTreeLinkSegment(segPtr, indexPtr) /* ARGSUSED */ void -TkBTreeUnlinkSegment(segPtr, linePtr) - TkTextSegment *segPtr; /* Segment to be unlinked. */ - TkTextLine *linePtr; /* Line that currently contains segment. */ +TkBTreeUnlinkSegment( + TkTextSegment *segPtr, /* Segment to be unlinked. */ + TkTextLine *linePtr) /* Line that currently contains segment. */ { register TkTextSegment *prevPtr; @@ -2074,7 +2076,7 @@ TkBTreeUnlinkSegment(segPtr, linePtr) if (prevPtr == NULL) { /* * Two logical lines merged into one display line through - * eliding of a newline + * eliding of a newline. */ linePtr = TkBTreeNextLine(NULL, linePtr); @@ -2110,23 +2112,21 @@ TkBTreeUnlinkSegment(segPtr, linePtr) */ int -TkBTreeTag(index1Ptr, index2Ptr, tagPtr, add) - register TkTextIndex *index1Ptr; +TkBTreeTag( + register TkTextIndex *index1Ptr, /* Indicates first character in range. */ - register TkTextIndex *index2Ptr; + register TkTextIndex *index2Ptr, /* Indicates character just after the last one * in range. */ - TkTextTag *tagPtr; /* Tag to add or remove. */ - int add; /* One means add tag to the given range of + TkTextTag *tagPtr, /* Tag to add or remove. */ + int add) /* One means add tag to the given range of * characters; zero means remove the tag from * the range. */ { TkTextSegment *segPtr, *prevPtr; TkTextSearch search; TkTextLine *cleanupLinePtr; - int oldState; - int changed; - int anyChanges = 0; + int oldState, changed, anyChanges = 0; /* * See whether the tag is present at the start of the range. If the state @@ -2232,7 +2232,7 @@ TkBTreeTag(index1Ptr, index2Ptr, tagPtr, add) if (cleanupLinePtr != index2Ptr->linePtr) { CleanupLine(index2Ptr->linePtr); } - ((BTree*)index1Ptr->tree)->stateEpoch++; + ((BTree *)index1Ptr->tree)->stateEpoch++; } if (tkBTreeDebug) { @@ -2262,16 +2262,16 @@ TkBTreeTag(index1Ptr, index2Ptr, tagPtr, add) */ static void -ChangeNodeToggleCount(nodePtr, tagPtr, delta) - register Node *nodePtr; /* Node whose toggle count for a tag must be +ChangeNodeToggleCount( + register Node *nodePtr, /* Node whose toggle count for a tag must be * changed. */ - TkTextTag *tagPtr; /* Information about tag. */ - int delta; /* Amount to add to current toggle count for + TkTextTag *tagPtr, /* Information about tag. */ + int delta) /* Amount to add to current toggle count for * tag (may be negative). */ { register Summary *summaryPtr, *prevPtr; register Node *node2Ptr; - int rootLevel; /* Level of original tag root */ + int rootLevel; /* Level of original tag root. */ tagPtr->toggleCount += delta; if (tagPtr->tagRootPtr == NULL) { @@ -2323,7 +2323,7 @@ ChangeNodeToggleCount(nodePtr, tagPtr, delta) } /* - * Zero toggle count; must remove this tag from the list. + * Zero toggle count; must remove this tag from the list. */ if (prevPtr == NULL) { @@ -2338,7 +2338,6 @@ ChangeNodeToggleCount(nodePtr, tagPtr, delta) */ if (rootLevel == nodePtr->level) { - /* * The old tag root is at the same level in the tree as this * node, but it isn't at this node. Move the tag root up a @@ -2350,6 +2349,7 @@ ChangeNodeToggleCount(nodePtr, tagPtr, delta) */ Node *rootNodePtr = tagPtr->tagRootPtr; + summaryPtr = (Summary *) ckalloc(sizeof(Summary)); summaryPtr->tagPtr = tagPtr; summaryPtr->toggleCount = tagPtr->toggleCount - delta; @@ -2444,10 +2444,10 @@ ChangeNodeToggleCount(nodePtr, tagPtr, delta) */ static TkTextSegment * -FindTagStart(tree, tagPtr, indexPtr) - TkTextBTree tree; /* Tree to search within */ - TkTextTag *tagPtr; /* Tag to search for. */ - TkTextIndex *indexPtr; /* Return - index information */ +FindTagStart( + TkTextBTree tree, /* Tree to search within. */ + TkTextTag *tagPtr, /* Tag to search for. */ + TkTextIndex *indexPtr) /* Return - index information. */ { register Node *nodePtr; register TkTextLine *linePtr; @@ -2525,10 +2525,10 @@ FindTagStart(tree, tagPtr, indexPtr) */ static TkTextSegment * -FindTagEnd(tree, tagPtr, indexPtr) - TkTextBTree tree; /* Tree to search within */ - TkTextTag *tagPtr; /* Tag to search for. */ - TkTextIndex *indexPtr; /* Return - index information */ +FindTagEnd( + TkTextBTree tree, /* Tree to search within. */ + TkTextTag *tagPtr, /* Tag to search for. */ + TkTextIndex *indexPtr) /* Return - index information. */ { register Node *nodePtr, *lastNodePtr; register TkTextLine *linePtr ,*lastLinePtr; @@ -2615,20 +2615,20 @@ FindTagEnd(tree, tagPtr, indexPtr) */ void -TkBTreeStartSearch(index1Ptr, index2Ptr, tagPtr, searchPtr) - TkTextIndex *index1Ptr; /* Search starts here. Tag toggles at this +TkBTreeStartSearch( + TkTextIndex *index1Ptr, /* Search starts here. Tag toggles at this * position will not be returned. */ - TkTextIndex *index2Ptr; /* Search stops here. Tag toggles at this + TkTextIndex *index2Ptr, /* Search stops here. Tag toggles at this * position *will* be returned. */ - TkTextTag *tagPtr; /* Tag to search for. NULL means search for + TkTextTag *tagPtr, /* Tag to search for. NULL means search for * any tag. */ - register TkTextSearch *searchPtr; + register TkTextSearch *searchPtr) /* Where to store information about search's * progress. */ { int offset; - TkTextIndex index0; /* First index of the tag */ - TkTextSegment *seg0Ptr; /* First segment of the tag */ + TkTextIndex index0; /* First index of the tag. */ + TkTextSegment *seg0Ptr; /* First segment of the tag. */ /* * Find the segment that contains the first toggle for the tag. This may @@ -2650,12 +2650,12 @@ TkBTreeStartSearch(index1Ptr, index2Ptr, tagPtr, searchPtr) } if (TkTextIndexCmp(index1Ptr, &index0) < 0) { /* - * Adjust start of search up to the first range of the tag + * Adjust start of search up to the first range of the tag. */ searchPtr->curIndex = index0; searchPtr->segPtr = NULL; - searchPtr->nextPtr = seg0Ptr; /* Will be returned by NextTag */ + searchPtr->nextPtr = seg0Ptr; /* Will be returned by NextTag. */ index1Ptr = &index0; } else { searchPtr->curIndex = *index1Ptr; @@ -2711,21 +2711,21 @@ TkBTreeStartSearch(index1Ptr, index2Ptr, tagPtr, searchPtr) */ void -TkBTreeStartSearchBack(index1Ptr, index2Ptr, tagPtr, searchPtr) - TkTextIndex *index1Ptr; /* Search starts here. Tag toggles at this +TkBTreeStartSearchBack( + TkTextIndex *index1Ptr, /* Search starts here. Tag toggles at this * position will not be returned. */ - TkTextIndex *index2Ptr; /* Search stops here. Tag toggles at this + TkTextIndex *index2Ptr, /* Search stops here. Tag toggles at this * position *will* be returned. */ - TkTextTag *tagPtr; /* Tag to search for. NULL means search for + TkTextTag *tagPtr, /* Tag to search for. NULL means search for * any tag. */ - register TkTextSearch *searchPtr; - /* Where to store information about - * search's progress. */ + register TkTextSearch *searchPtr) + /* Where to store information about search's + * progress. */ { int offset; - TkTextIndex index0; /* Last index of the tag */ - TkTextIndex backOne; /* One character before starting index */ - TkTextSegment *seg0Ptr; /* Last segment of the tag */ + TkTextIndex index0; /* Last index of the tag. */ + TkTextIndex backOne; /* One character before starting index. */ + TkTextSegment *seg0Ptr; /* Last segment of the tag. */ /* * Find the segment that contains the last toggle for the tag. This may @@ -2770,7 +2770,7 @@ TkBTreeStartSearchBack(index1Ptr, index2Ptr, tagPtr, searchPtr) if ((TkBTreeLinesTo(NULL, index2Ptr->linePtr) == 0) && (index2Ptr->byteIndex == 0)) { backOne = *index2Ptr; - searchPtr->lastPtr = NULL; /* Signals special case for 1.0 */ + searchPtr->lastPtr = NULL; /* Signals special case for 1.0. */ } else { TkTextIndexBackChars(NULL, index2Ptr, 1, &backOne, COUNT_INDICES); searchPtr->lastPtr = TkTextIndexToSeg(&backOne, NULL); @@ -2818,8 +2818,8 @@ TkBTreeStartSearchBack(index1Ptr, index2Ptr, tagPtr, searchPtr) */ int -TkBTreeNextTag(searchPtr) - register TkTextSearch *searchPtr; +TkBTreeNextTag( + register TkTextSearch *searchPtr) /* Information about search in progress; must * have been set up by call to * TkBTreeStartSearch. */ @@ -2983,8 +2983,8 @@ TkBTreeNextTag(searchPtr) */ int -TkBTreePrevTag(searchPtr) - register TkTextSearch *searchPtr; +TkBTreePrevTag( + register TkTextSearch *searchPtr) /* Information about search in progress; must * have been set up by call to * TkBTreeStartSearch. */ @@ -2993,9 +2993,8 @@ TkBTreePrevTag(searchPtr) register TkTextLine *linePtr, *prevLinePtr; register Node *nodePtr, *node2Ptr, *prevNodePtr; register Summary *summaryPtr; - int byteIndex; - int pastLast; /* Saw last marker during scan */ - int linesSkipped; + int byteIndex, linesSkipped; + int pastLast; /* Saw last marker during scan. */ if (searchPtr->linesLeft <= 0) { goto searchOver; @@ -3035,7 +3034,8 @@ TkBTreePrevTag(searchPtr) searchPtr->curIndex.byteIndex = byteIndex; } if (segPtr == searchPtr->lastPtr) { - prevPtr = NULL; /* Segments earlier than last don't count */ + prevPtr = NULL; /* Segments earlier than last don't + * count. */ pastLast = 1; } byteIndex += segPtr->size; @@ -3197,10 +3197,10 @@ TkBTreePrevTag(searchPtr) */ int -TkBTreeCharTagged(indexPtr, tagPtr) - const TkTextIndex *indexPtr;/* Indicates a character position at which to +TkBTreeCharTagged( + const TkTextIndex *indexPtr,/* Indicates a character position at which to * check for a tag. */ - TkTextTag *tagPtr; /* Tag of interest. */ + TkTextTag *tagPtr) /* Tag of interest. */ { register Node *nodePtr; register TkTextLine *siblingLinePtr; @@ -3308,13 +3308,13 @@ TkBTreeCharTagged(indexPtr, tagPtr) /* ARGSUSED */ TkTextTag ** -TkBTreeGetTags(indexPtr, textPtr, numTagsPtr) - const TkTextIndex *indexPtr;/* Indicates a particular position in the +TkBTreeGetTags( + const TkTextIndex *indexPtr,/* Indicates a particular position in the * B-tree. */ - const TkText *textPtr; /* If non-NULL, then only return tags for this + const TkText *textPtr, /* If non-NULL, then only return tags for this * text widget (when there are peer * widgets). */ - int *numTagsPtr; /* Store number of tags found at this + int *numTagsPtr) /* Store number of tags found at this * location. */ { register Node *nodePtr; @@ -3327,10 +3327,10 @@ TkBTreeGetTags(indexPtr, textPtr, numTagsPtr) tagInfo.numTags = 0; tagInfo.arraySize = NUM_TAG_INFOS; - tagInfo.tagPtrs = (TkTextTag **) ckalloc((unsigned) - NUM_TAG_INFOS*sizeof(TkTextTag *)); - tagInfo.counts = (int *) ckalloc((unsigned) - NUM_TAG_INFOS*sizeof(int)); + tagInfo.tagPtrs = (TkTextTag **) + ckalloc((unsigned) NUM_TAG_INFOS * sizeof(TkTextTag *)); + tagInfo.counts = (int *) + ckalloc((unsigned) NUM_TAG_INFOS * sizeof(int)); /* * Record tag toggles within the line of indexPtr but preceding indexPtr. @@ -3407,7 +3407,8 @@ TkBTreeGetTags(indexPtr, textPtr, numTagsPtr) for (src = 0, dst = 0; src < tagInfo.numTags; src++) { if (tagInfo.counts[src] & 1) { const TkText *tagTextPtr = tagInfo.tagPtrs[src]->textPtr; - if (tagTextPtr == NULL || textPtr == NULL || tagTextPtr == textPtr) { + + if (tagTextPtr==NULL || textPtr==NULL || tagTextPtr==textPtr) { tagInfo.tagPtrs[dst] = tagInfo.tagPtrs[src]; dst++; } @@ -3455,11 +3456,11 @@ TkBTreeGetTags(indexPtr, textPtr, numTagsPtr) /* ARGSUSED */ int -TkTextIsElided(textPtr, indexPtr, elideInfo) - const TkText *textPtr; /* Overall information about text widget. */ - const TkTextIndex *indexPtr;/* The character in the text for which display +TkTextIsElided( + const TkText *textPtr, /* Overall information about text widget. */ + const TkTextIndex *indexPtr,/* The character in the text for which display * information is wanted. */ - TkTextElideInfo *elideInfo; /* NULL or a pointer to a structure in which + TkTextElideInfo *elideInfo) /* NULL or a pointer to a structure in which * indexPtr's elide state will be stored and * returned. */ { @@ -3473,12 +3474,13 @@ TkTextIsElided(textPtr, indexPtr, elideInfo) int elide; if (elideInfo == NULL) { - infoPtr = (TkTextElideInfo*)ckalloc((unsigned)sizeof(TkTextElideInfo)); + infoPtr = (TkTextElideInfo *) + ckalloc((unsigned) sizeof(TkTextElideInfo)); } else { infoPtr = elideInfo; } - infoPtr->elide = 0; /* if nobody says otherwise, it's visible */ + infoPtr->elide = 0; /* If nobody says otherwise, it's visible. */ infoPtr->tagCnts = infoPtr->deftagCnts; infoPtr->tagPtrs = infoPtr->deftagPtrs; infoPtr->numTags = textPtr->sharedTextPtr->numTags; @@ -3491,7 +3493,7 @@ TkTextIsElided(textPtr, indexPtr, elideInfo) infoPtr->tagCnts = (int *) ckalloc((unsigned) sizeof(int) * infoPtr->numTags); infoPtr->tagPtrs = (TkTextTag **) - ckalloc((unsigned)sizeof(TkTextTag *) * infoPtr->numTags); + ckalloc((unsigned) sizeof(TkTextTag *) * infoPtr->numTags); } for (i=0; i<infoPtr->numTags; i++) { @@ -3585,7 +3587,7 @@ TkTextIsElided(textPtr, indexPtr, elideInfo) /* * Now traverse from highest priority to lowest, take elided value from - * first odd count (= on) + * first odd count (= on). */ infoPtr->elidePriority = -1; @@ -3624,7 +3626,7 @@ TkTextIsElided(textPtr, indexPtr, elideInfo) ckfree((char *) infoPtr->tagPtrs); } - ckfree((char*) infoPtr); + ckfree((char *) infoPtr); } return elide; @@ -3648,13 +3650,13 @@ TkTextIsElided(textPtr, indexPtr, elideInfo) */ void -TkTextFreeElideInfo(elideInfo) - TkTextElideInfo *elideInfo; /* Free any allocated memory in this +TkTextFreeElideInfo( + TkTextElideInfo *elideInfo) /* Free any allocated memory in this * structure. */ { if (LOTSA_TAGS < elideInfo->numTags) { - ckfree((char*)elideInfo->tagCnts); - ckfree((char*)elideInfo->tagPtrs); + ckfree((char *) elideInfo->tagCnts); + ckfree((char *) elideInfo->tagPtrs); } } @@ -3678,10 +3680,10 @@ TkTextFreeElideInfo(elideInfo) */ static void -IncCount(tagPtr, inc, tagInfoPtr) - TkTextTag *tagPtr; /* Handle for tag. */ - int inc; /* Amount by which to increment tag count. */ - TagInfo *tagInfoPtr; /* Holds cumulative information about tags; +IncCount( + TkTextTag *tagPtr, /* Handle for tag. */ + int inc, /* Amount by which to increment tag count. */ + TagInfo *tagInfoPtr) /* Holds cumulative information about tags; * increment count here. */ { register TkTextTag **tagPtrPtr; @@ -3704,15 +3706,15 @@ IncCount(tagPtr, inc, tagInfoPtr) TkTextTag **newTags; int *newCounts, newSize; - newSize = 2*tagInfoPtr->arraySize; - newTags = (TkTextTag **) ckalloc((unsigned) - (newSize * sizeof(TkTextTag *))); - memcpy((VOID *) newTags, (VOID *) tagInfoPtr->tagPtrs, + newSize = 2 * tagInfoPtr->arraySize; + newTags = (TkTextTag **) + ckalloc((unsigned) newSize * sizeof(TkTextTag *)); + memcpy(newTags, tagInfoPtr->tagPtrs, tagInfoPtr->arraySize * sizeof(TkTextTag *)); ckfree((char *) tagInfoPtr->tagPtrs); tagInfoPtr->tagPtrs = newTags; - newCounts = (int *) ckalloc((unsigned) (newSize*sizeof(int))); - memcpy((VOID *) newCounts, (VOID *) tagInfoPtr->counts, + newCounts = (int *) ckalloc((unsigned) newSize * sizeof(int)); + memcpy(newCounts, tagInfoPtr->counts, tagInfoPtr->arraySize * sizeof(int)); ckfree((char *) tagInfoPtr->counts); tagInfoPtr->counts = newCounts; @@ -3743,8 +3745,8 @@ IncCount(tagPtr, inc, tagInfoPtr) */ void -TkBTreeCheck(tree) - TkTextBTree tree; /* Tree to check. */ +TkBTreeCheck( + TkTextBTree tree) /* Tree to check. */ { BTree *treePtr = (BTree *) tree; register Summary *summaryPtr; @@ -3769,7 +3771,7 @@ TkBTreeCheck(tree) Tcl_Panic("TkBTreeCheck found \"%s\" with toggles (%d) but no root", tagPtr->name, tagPtr->toggleCount); } - continue; /* no ranges for the tag */ + continue; /* No ranges for the tag. */ } else if (tagPtr->toggleCount == 0) { Tcl_Panic("TkBTreeCheck found root for \"%s\" with no toggles", tagPtr->name); @@ -3885,9 +3887,9 @@ TkBTreeCheck(tree) */ static void -CheckNodeConsistency(nodePtr, references) - register Node *nodePtr; /* Node whose subtree should be checked. */ - int references; /* Number of referring widgets which have +CheckNodeConsistency( + register Node *nodePtr, /* Node whose subtree should be checked. */ + int references) /* Number of referring widgets which have * pixel counts. */ { register Node *childNodePtr; @@ -3902,7 +3904,7 @@ CheckNodeConsistency(nodePtr, references) minChildren = MIN_CHILDREN; } else if (nodePtr->level > 0) { minChildren = 2; - } else { + } else { minChildren = 1; } if ((nodePtr->numChildren < minChildren) @@ -3914,7 +3916,7 @@ CheckNodeConsistency(nodePtr, references) numChildren = 0; numLines = 0; if (references > PIXEL_CLIENTS) { - numPixels = (int*)ckalloc(sizeof(int)*references); + numPixels = (int *) ckalloc(sizeof(int) * references); } else { numPixels = pixels; } @@ -3950,7 +3952,7 @@ CheckNodeConsistency(nodePtr, references) numChildren++; numLines++; for (i = 0; i<references; i++) { - numPixels[i] += linePtr->pixels[2*i]; + numPixels[i] += linePtr->pixels[2 * i]; } } } else { @@ -3999,18 +4001,18 @@ CheckNodeConsistency(nodePtr, references) for (i = 0; i<references; i++) { if (numPixels[i] != nodePtr->numPixels[i]) { Tcl_Panic("CheckNodeConsistency: mismatch in numPixels (%d %d) for widget (%d)", - numPixels[i], nodePtr->numPixels[i], i); + numPixels[i], nodePtr->numPixels[i], i); } } if (references > PIXEL_CLIENTS) { - ckfree((char*)numPixels); + ckfree((char *) numPixels); } for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; summaryPtr = summaryPtr->nextPtr) { if (summaryPtr->tagPtr->toggleCount == summaryPtr->toggleCount) { Tcl_Panic("CheckNodeConsistency: found unpruned root for \"%s\"", - summaryPtr->tagPtr->name); + summaryPtr->tagPtr->name); } toggleCount = 0; if (nodePtr->level == 0) { @@ -4023,7 +4025,7 @@ CheckNodeConsistency(nodePtr, references) continue; } if (segPtr->body.toggle.tagPtr == summaryPtr->tagPtr) { - toggleCount ++; + toggleCount++; } } } @@ -4073,9 +4075,9 @@ CheckNodeConsistency(nodePtr, references) */ static void -Rebalance(treePtr, nodePtr) - BTree *treePtr; /* Tree that is being rebalanced. */ - register Node *nodePtr; /* Node that may be out of balance. */ +Rebalance( + BTree *treePtr, /* Tree that is being rebalanced. */ + register Node *nodePtr) /* Node that may be out of balance. */ { /* * Loop over the entire ancestral chain of the node, working up through @@ -4270,8 +4272,8 @@ Rebalance(treePtr, nodePtr) } /* - * The siblings can't be merged, so just divide their - * children evenly between them. + * The siblings can't be merged, so just divide their children + * evenly between them. */ if (nodePtr->level == 0) { @@ -4309,9 +4311,9 @@ Rebalance(treePtr, nodePtr) */ static void -RecomputeNodeCounts(treePtr, nodePtr) - register BTree *treePtr; /* The whole B-tree */ - register Node *nodePtr; /* Node whose tag summary information must be +RecomputeNodeCounts( + register BTree *treePtr, /* The whole B-tree. */ + register Node *nodePtr) /* Node whose tag summary information must be * recomputed. */ { register Summary *summaryPtr, *summaryPtr2; @@ -4347,7 +4349,7 @@ RecomputeNodeCounts(treePtr, nodePtr) nodePtr->numChildren++; nodePtr->numLines++; for (ref = 0; ref<treePtr->pixelReferences; ref++) { - nodePtr->numPixels[ref] += linePtr->pixels[2*ref]; + nodePtr->numPixels[ref] += linePtr->pixels[2 * ref]; } linePtr->parentPtr = nodePtr; for (segPtr = linePtr->segPtr; segPtr != NULL; @@ -4430,8 +4432,8 @@ RecomputeNodeCounts(treePtr, nodePtr) } if (summaryPtr->toggleCount == summaryPtr->tagPtr->toggleCount) { /* - * A node merge has collected all the toggles under one node. - * Push the root down to this level. + * A node merge has collected all the toggles under one node. Push + * the root down to this level. */ summaryPtr->tagPtr->tagRootPtr = nodePtr; @@ -4468,9 +4470,9 @@ RecomputeNodeCounts(treePtr, nodePtr) */ int -TkBTreeNumLines(tree, textPtr) - TkTextBTree tree; /* Information about tree. */ - const TkText *textPtr; /* Relative to this client of the B-tree */ +TkBTreeNumLines( + TkTextBTree tree, /* Information about tree. */ + const TkText *textPtr) /* Relative to this client of the B-tree. */ { BTree *treePtr = (BTree *) tree; int count; @@ -4509,9 +4511,9 @@ TkBTreeNumLines(tree, textPtr) */ int -TkBTreeNumPixels(tree, textPtr) - TkTextBTree tree; /* The B-tree */ - const TkText *textPtr; /* Relative to this client of the B-tree */ +TkBTreeNumPixels( + TkTextBTree tree, /* The B-tree. */ + const TkText *textPtr) /* Relative to this client of the B-tree. */ { BTree *treePtr = (BTree *) tree; return treePtr->rootPtr->numPixels[textPtr->pixelReference]; @@ -4535,9 +4537,9 @@ TkBTreeNumPixels(tree, textPtr) */ static TkTextSegment * -CharSplitProc(segPtr, index) - TkTextSegment *segPtr; /* Pointer to segment to split. */ - int index; /* Position within segment at which to +CharSplitProc( + TkTextSegment *segPtr, /* Pointer to segment to split. */ + int index) /* Position within segment at which to * split. */ { TkTextSegment *newPtr1, *newPtr2; @@ -4554,7 +4556,7 @@ CharSplitProc(segPtr, index) newPtr2->nextPtr = segPtr->nextPtr; newPtr2->size = segPtr->size - index; strcpy(newPtr2->body.chars, segPtr->body.chars + index); - ckfree((char*) segPtr); + ckfree((char *) segPtr); return newPtr1; } @@ -4578,10 +4580,10 @@ CharSplitProc(segPtr, index) /* ARGSUSED */ static TkTextSegment * -CharCleanupProc(segPtr, linePtr) - TkTextSegment *segPtr; /* Pointer to first of two adjacent segments +CharCleanupProc( + TkTextSegment *segPtr, /* Pointer to first of two adjacent segments * to join. */ - TkTextLine *linePtr; /* Line containing segments (not used). */ + TkTextLine *linePtr) /* Line containing segments (not used). */ { TkTextSegment *segPtr2, *newPtr; @@ -4596,8 +4598,8 @@ CharCleanupProc(segPtr, linePtr) newPtr->size = segPtr->size + segPtr2->size; strcpy(newPtr->body.chars, segPtr->body.chars); strcpy(newPtr->body.chars + segPtr->size, segPtr2->body.chars); - ckfree((char*) segPtr); - ckfree((char*) segPtr2); + ckfree((char *) segPtr); + ckfree((char *) segPtr2); return newPtr; } @@ -4619,14 +4621,14 @@ CharCleanupProc(segPtr, linePtr) /* ARGSUSED */ static int -CharDeleteProc(segPtr, linePtr, treeGone) - TkTextSegment *segPtr; /* Segment to delete. */ - TkTextLine *linePtr; /* Line containing segment. */ - int treeGone; /* Non-zero means the entire tree is being +CharDeleteProc( + TkTextSegment *segPtr, /* Segment to delete. */ + TkTextLine *linePtr, /* Line containing segment. */ + int treeGone) /* Non-zero means the entire tree is being * deleted, so everything must get cleaned * up. */ { - ckfree((char*) segPtr); + ckfree((char *) segPtr); return 0; } @@ -4649,9 +4651,9 @@ CharDeleteProc(segPtr, linePtr, treeGone) /* ARGSUSED */ static void -CharCheckProc(segPtr, linePtr) - TkTextSegment *segPtr; /* Segment to check. */ - TkTextLine *linePtr; /* Line containing segment. */ +CharCheckProc( + TkTextSegment *segPtr, /* Segment to check. */ + TkTextLine *linePtr) /* Line containing segment. */ { /* * Make sure that the segment contains the number of characters indicated @@ -4694,10 +4696,10 @@ CharCheckProc(segPtr, linePtr) */ static int -ToggleDeleteProc(segPtr, linePtr, treeGone) - TkTextSegment *segPtr; /* Segment to check. */ - TkTextLine *linePtr; /* Line containing segment. */ - int treeGone; /* Non-zero means the entire tree is being +ToggleDeleteProc( + TkTextSegment *segPtr, /* Segment to check. */ + TkTextLine *linePtr, /* Line containing segment. */ + int treeGone) /* Non-zero means the entire tree is being * deleted, so everything must get cleaned * up. */ { @@ -4745,9 +4747,9 @@ ToggleDeleteProc(segPtr, linePtr, treeGone) */ static TkTextSegment * -ToggleCleanupProc(segPtr, linePtr) - TkTextSegment *segPtr; /* Segment to check. */ - TkTextLine *linePtr; /* Line that now contains segment. */ +ToggleCleanupProc( + TkTextSegment *segPtr, /* Segment to check. */ + TkTextLine *linePtr) /* Line that now contains segment. */ { TkTextSegment *segPtr2, *prevPtr; int counts; @@ -4809,9 +4811,9 @@ ToggleCleanupProc(segPtr, linePtr) */ static void -ToggleLineChangeProc(segPtr, linePtr) - TkTextSegment *segPtr; /* Segment to check. */ - TkTextLine *linePtr; /* Line that used to contain segment. */ +ToggleLineChangeProc( + TkTextSegment *segPtr, /* Segment to check. */ + TkTextLine *linePtr) /* Line that used to contain segment. */ { if (segPtr->body.toggle.inNodeCounts) { ChangeNodeToggleCount(linePtr->parentPtr, @@ -4838,9 +4840,9 @@ ToggleLineChangeProc(segPtr, linePtr) */ static void -ToggleCheckProc(segPtr, linePtr) - TkTextSegment *segPtr; /* Segment to check. */ - TkTextLine *linePtr; /* Line containing segment. */ +ToggleCheckProc( + TkTextSegment *segPtr, /* Segment to check. */ + TkTextLine *linePtr) /* Line containing segment. */ { register Summary *summaryPtr; int needSummary; @@ -4851,7 +4853,7 @@ ToggleCheckProc(segPtr, linePtr) if (!segPtr->body.toggle.inNodeCounts) { Tcl_Panic("ToggleCheckProc: toggle counts not updated in nodes"); } - needSummary = (segPtr->body.toggle.tagPtr->tagRootPtr != linePtr->parentPtr); + needSummary = (segPtr->body.toggle.tagPtr->tagRootPtr!=linePtr->parentPtr); for (summaryPtr = linePtr->parentPtr->summaryPtr; ; summaryPtr = summaryPtr->nextPtr) { if (summaryPtr == NULL) { @@ -4869,3 +4871,11 @@ ToggleCheckProc(segPtr, linePtr) } } } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index b96542e..64e1021 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.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: tkTextDisp.c,v 1.61 2007/01/11 15:35:39 dkf Exp $ + * RCS: @(#) $Id: tkTextDisp.c,v 1.62 2007/02/22 13:56:33 dkf Exp $ */ #include "tkPort.h" @@ -74,44 +74,44 @@ /* * TK_LAYOUT_WITH_BASE_CHUNKS: * - * With this macro set, collect all char chunks that have no holes between - * them, that are on the same line and use the same font and font size. - * Allocate the chars of all these chunks, the so-called "stretch", in a - * DString in the first chunk, the so-called "base chunk". Use the base - * chunk string for measuring and drawing, so that these actions are always - * performed with maximum context. + * With this macro set, collect all char chunks that have no holes + * between them, that are on the same line and use the same font and font + * size. Allocate the chars of all these chunks, the so-called "stretch", + * in a DString in the first chunk, the so-called "base chunk". Use the + * base chunk string for measuring and drawing, so that these actions are + * always performed with maximum context. * - * This is necessary for text rendering engines that provide ligatures and - * sub-pixel layout, like ATSU on Mac. If we don't do this, the measuring - * will change all the time, leading to an ugly "tremble and shiver" - * effect. This is because of the continuous splitting and re-merging of - * chunks that goes on in a text widget, when the cursor or the selection - * move. + * This is necessary for text rendering engines that provide ligatures + * and sub-pixel layout, like ATSU on Mac. If we don't do this, the + * measuring will change all the time, leading to an ugly "tremble and + * shiver" effect. This is because of the continuous splitting and + * re-merging of chunks that goes on in a text widget, when the cursor or + * the selection move. * * Side effects: * - * Memory management changes. Instead of attaching the character data to - * the clientData structures of the char chunks, an additional DString is - * used. The collection process will even lead to resizing this DString - * for large stretches (> TCL_DSTRING_STATIC_SIZE == 200). We could reduce - * the overall memory footprint by copying the result to a plain char array - * after the line breaking process, but that would complicate the code and - * make performance even worse speedwise. See also TODOs. + * Memory management changes. Instead of attaching the character data to + * the clientData structures of the char chunks, an additional DString is + * used. The collection process will even lead to resizing this DString + * for large stretches (> TCL_DSTRING_STATIC_SIZE == 200). We could + * reduce the overall memory footprint by copying the result to a plain + * char array after the line breaking process, but that would complicate + * the code and make performance even worse speedwise. See also TODOs. * * TODOs: * - * - Move the character collection process from the LayoutProc into - * LayoutDLine(), so that the collection can be done before actual - * layout. In this way measuring can look at the following text, too, - * right from the beginning. Memory handling can also be improved with - * this. Problem: We don't easily know which chunks are adjacent until - * all the other chunks have calculated their width. Apparently marks - * would return width==0. A separate char collection loop would have to - * know these things. - * - * - Use a new context parameter to pass the context from LayoutDLine() to - * the LayoutProc instead of using a global variable like now. Not - * pressing until the previous point gets implemented. + * - Move the character collection process from the LayoutProc into + * LayoutDLine(), so that the collection can be done before actual + * layout. In this way measuring can look at the following text, too, + * right from the beginning. Memory handling can also be improved with + * this. Problem: We don't easily know which chunks are adjacent until + * all the other chunks have calculated their width. Apparently marks + * would return width==0. A separate char collection loop would have to + * know these things. + * + * - Use a new context parameter to pass the context from LayoutDLine() to + * the LayoutProc instead of using a global variable like now. Not + * pressing until the previous point gets implemented. */ /* @@ -150,7 +150,7 @@ typedef struct StyleValues { int tabStyle; /* One of TABULAR or WORDPROCESSOR. */ int underline; /* Non-zero means draw underline underneath * text. */ - int elide; /* Zero means draw text, otherwise not */ + int elide; /* Zero means draw text, otherwise not. */ TkWrapMode wrapMode; /* How to handle wrap-around for this tag. * One of TEXT_WRAPMODE_CHAR, * TEXT_WRAPMODE_NONE or TEXT_WRAPMODE_WORD.*/ @@ -429,10 +429,9 @@ typedef struct CharInfo { * baseChars. */ int numBytes; /* Number of bytes that belong to this * chunk. */ - const char *chars; /* UTF characters to display. Actually - * points into the baseChars of the base - * chunk. Only valid after - * FinalizeBaseChunk(). */ + const char *chars; /* UTF characters to display. Actually points + * into the baseChars of the base chunk. Only + * valid after FinalizeBaseChunk(). */ } CharInfo; /* @@ -444,7 +443,7 @@ typedef struct BaseCharInfo { Tcl_DString baseChars; /* Actual characters for the stretch of text * represented by this base chunk. */ int width; /* Width in pixels of the whole string, if - * known, else -1. Valid during + * known, else -1. Valid during * LayoutDLine(). */ } BaseCharInfo; @@ -508,64 +507,51 @@ static void AdjustForTab(TkText *textPtr, TkTextTabArray *tabArrayPtr, int index, TkTextDispChunk *chunkPtr); static void CharBboxProc(TkText *textPtr, - TkTextDispChunk *chunkPtr, - int index, int y, int lineHeight, int baseline, - int *xPtr, int *yPtr, int *widthPtr, - int *heightPtr); -static int CharChunkMeasureChars( - TkTextDispChunk *chunkPtr, + TkTextDispChunk *chunkPtr, int index, int y, + int lineHeight, int baseline, int *xPtr, + int *yPtr, int *widthPtr, int *heightPtr); +static int CharChunkMeasureChars(TkTextDispChunk *chunkPtr, const char *chars, int charsLen, int start, int end, int startX, int maxX, int flags, int *nextX); static void CharDisplayProc(TkText *textPtr, - TkTextDispChunk *chunkPtr, - int x, int y, int height, int baseline, - Display *display, Drawable dst, int screenY); + TkTextDispChunk *chunkPtr, int x, int y, + int height, int baseline, Display *display, + Drawable dst, int screenY); static int CharMeasureProc(TkTextDispChunk *chunkPtr, int x); static void CharUndisplayProc(TkText *textPtr, TkTextDispChunk *chunkPtr); - - #if TK_LAYOUT_WITH_BASE_CHUNKS - -static void FinalizeBaseChunk( - TkTextDispChunk *additionalChunkPtr); -static void FreeBaseChunk( - TkTextDispChunk *baseChunkPtr); -static int IsSameFGStyle( - TextStyle *style1, TextStyle *style2); -static void RemoveFromBaseChunk( - TkTextDispChunk *chunkPtr); - +static void FinalizeBaseChunk(TkTextDispChunk *additionalChunkPtr); +static void FreeBaseChunk(TkTextDispChunk *baseChunkPtr); +static int IsSameFGStyle(TextStyle *style1, TextStyle *style2); +static void RemoveFromBaseChunk(TkTextDispChunk *chunkPtr); #endif - /* * Definitions of elided procs. Compiler can't inline these since we use - * pointers to these functions. ElideDisplayProc, ElideUndisplayProc + * pointers to these functions. ElideDisplayProc and ElideUndisplayProc are * special-cased for speed, as potentially many elided DLine chunks if large, * tag toggle-filled elided region. */ - static void ElideBboxProc(TkText *textPtr, - TkTextDispChunk *chunkPtr, - int index, int y, int lineHeight, int baseline, - int *xPtr, int *yPtr, int *widthPtr, - int *heightPtr); + TkTextDispChunk *chunkPtr, int index, int y, + int lineHeight, int baseline, int *xPtr, + int *yPtr, int *widthPtr, int *heightPtr); static int ElideMeasureProc(TkTextDispChunk *chunkPtr, int x); -static void DisplayDLine(TkText *textPtr, - DLine *dlPtr, DLine *prevPtr, Pixmap pixmap); -static void DisplayLineBackground(TkText *textPtr, - DLine *dlPtr, DLine *prevPtr, Pixmap pixmap); +static void DisplayDLine(TkText *textPtr, DLine *dlPtr, + DLine *prevPtr, Pixmap pixmap); +static void DisplayLineBackground(TkText *textPtr, DLine *dlPtr, + DLine *prevPtr, Pixmap pixmap); static void DisplayText(ClientData clientData); static DLine * FindDLine(DLine *dlPtr, CONST TkTextIndex *indexPtr); static void FreeDLines(TkText *textPtr, DLine *firstPtr, DLine *lastPtr, int action); static void FreeStyle(TkText *textPtr, TextStyle *stylePtr); static TextStyle * GetStyle(TkText *textPtr, CONST TkTextIndex *indexPtr); -static void GetXView(Tcl_Interp *interp, - TkText *textPtr, int report); -static void GetYView(Tcl_Interp *interp, - TkText *textPtr, int report); +static void GetXView(Tcl_Interp *interp, TkText *textPtr, + int report); +static void GetYView(Tcl_Interp *interp, TkText *textPtr, + int report); static int GetYPixelCount(TkText *textPtr, DLine *dlPtr); static DLine * LayoutDLine(TkText *textPtr, CONST TkTextIndex *indexPtr); @@ -768,12 +754,10 @@ GetStyle( int numTags, isNew, i; XGCValues gcValues; unsigned long mask; - /* * The variables below keep track of the highest-priority specification * that has occurred for each of the various fields of the StyleValues. */ - int borderPrio, borderWidthPrio, reliefPrio, bgStipplePrio; int fgPrio, fontPrio, fgStipplePrio; int underlinePrio, elidePrio, justifyPrio, offsetPrio; @@ -794,7 +778,7 @@ GetStyle( lMargin1Prio = lMargin2Prio = rMarginPrio = -1; spacing1Prio = spacing2Prio = spacing3Prio = -1; overstrikePrio = tabPrio = tabStylePrio = wrapPrio = -1; - memset((VOID *) &styleValues, 0, sizeof(StyleValues)); + memset(&styleValues, 0, sizeof(StyleValues)); styleValues.relief = TK_RELIEF_FLAT; styleValues.fgColor = textPtr->fgColor; styleValues.tkfont = textPtr->tkfont; @@ -815,8 +799,8 @@ GetStyle( /* * If this is the selection tag, and inactiveSelBorder is NULL (the - * default on Windows), then we need to skip it if we don't - * have focus. + * default on Windows), then we need to skip it if we don't have the + * focus. */ if ((tagPtr == textPtr->selTagPtr) && !(textPtr->flags & GOT_FOCUS)) { @@ -1116,7 +1100,7 @@ LayoutDLine( * from the end of the line. */ int byteOffset, ascent, descent, code, elide, elidesize; StyleValues *sValuePtr; - TkTextElideInfo info; /* Keep track of elide state */ + TkTextElideInfo info; /* Keep track of elide state. */ /* * Create and initialize a new DLine structure. @@ -1126,7 +1110,7 @@ LayoutDLine( dlPtr->index = *indexPtr; dlPtr->byteCount = 0; dlPtr->y = 0; - dlPtr->oldY = 0; /* Only set to avoid compiler warnings */ + dlPtr->oldY = 0; /* Only set to avoid compiler warnings. */ dlPtr->height = 0; dlPtr->baseline = 0; dlPtr->chunkPtr = NULL; @@ -1143,7 +1127,7 @@ LayoutDLine( paragraphStart = (indexPtr->byteIndex == 0); /* - * Special case entirely elide line as there may be 1000s or more + * Special case entirely elide line as there may be 1000s or more. */ elide = TkTextIsElided(textPtr, indexPtr, &info); @@ -1442,7 +1426,7 @@ LayoutDLine( #if TK_LAYOUT_WITH_BASE_CHUNKS if (baseCharChunkPtr != NULL) { int expectedX = - ((BaseCharInfo*) baseCharChunkPtr->clientData)->width + ((BaseCharInfo *) baseCharChunkPtr->clientData)->width + baseCharChunkPtr->x; if ((expectedX != x) || !IsSameFGStyle( @@ -1643,7 +1627,6 @@ LayoutDLine( wholeLine = 0; } - /* * Make tab adjustments for the last tab stop, if there is one. */ @@ -2021,7 +2004,7 @@ UpdateDisplayInfo( */ lineNum = -1; - bytesToCount = 0; /* Stop compiler warning */ + bytesToCount = 0; /* Stop compiler warning. */ } else { lineNum = TkBTreeLinesTo(textPtr, dInfoPtr->dLinePtr->index.linePtr); @@ -2423,8 +2406,8 @@ DisplayDLine( } /* - * Don't call if elide. This tax ok since not very many visible - * DLine's in an area, but potentially many elide ones + * Don't call if elide. This tax OK since not very many visible DLines + * in an area, but potentially many elide ones. */ if (chunkPtr->displayProc != NULL) { @@ -2973,8 +2956,8 @@ AsyncUpdateLineMetrics( int TkTextUpdateLineMetrics( TkText *textPtr, /* Information about widget. */ - int lineNum, /* Start at this line */ - int endLine, /* Go no further than this line */ + int lineNum, /* Start at this line. */ + int endLine, /* Go no further than this line. */ int doThisMuch) /* How many lines to check, or how many 10s of * lines to recalculate. If '-1' then do * everything in the range (which may take a @@ -2985,7 +2968,10 @@ TkTextUpdateLineMetrics( int totalLines = TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr); if (totalLines == 0) { - /* Empty peer widget */ + /* + * Empty peer widget. + */ + return endLine; } @@ -3312,7 +3298,7 @@ TextInvalidateLineMetrics( } /* - * Now re-set the current update calculations + * Now re-set the current update calculations. */ if (dInfoPtr->lineUpdateTimer == NULL) { @@ -3746,6 +3732,7 @@ TkTextUpdateOneLine( */ TkTextIndex idx; + TkTextIndexBackChars(textPtr, indexPtr, 1, &idx, COUNT_INDICES); if (!TkTextIsElided(textPtr, &idx, NULL)) { /* @@ -4071,10 +4058,9 @@ DisplayText( */ damageRgn = TkCreateRegion(); - if (TkScrollWindow(textPtr->tkwin, dInfoPtr->scrollGC, - dInfoPtr->x, oldY, - (dInfoPtr->maxX - dInfoPtr->x), height, - 0, y - oldY, damageRgn)) { + if (TkScrollWindow(textPtr->tkwin, dInfoPtr->scrollGC, dInfoPtr->x, + oldY, dInfoPtr->maxX-dInfoPtr->x, height, 0, y-oldY, + damageRgn)) { TextInvalidateRegion(textPtr, damageRgn); } numCopies++; @@ -4194,7 +4180,9 @@ DisplayText( for (prevPtr = NULL, dlPtr = textPtr->dInfoPtr->dLinePtr; (dlPtr != NULL) && (dlPtr->y < dInfoPtr->maxY); prevPtr = dlPtr, dlPtr = dlPtr->nextPtr) { - if (dlPtr->chunkPtr == NULL) continue; + if (dlPtr->chunkPtr == NULL) { + continue; + } if ((dlPtr->flags & OLD_Y_INVALID) || dlPtr->oldY != dlPtr->y) { if (tkTextDebug) { char string[TK_POS_CHARS]; @@ -4252,9 +4240,8 @@ DisplayText( TkTextEmbWinDisplayProc(textPtr, chunkPtr, x, dlPtr->spaceAbove, dlPtr->height-dlPtr->spaceAbove-dlPtr->spaceBelow, - dlPtr->baseline - dlPtr->spaceAbove, - NULL, (Drawable) None, - dlPtr->y + dlPtr->spaceAbove); + dlPtr->baseline - dlPtr->spaceAbove, NULL, + (Drawable) None, dlPtr->y + dlPtr->spaceAbove); } } @@ -4292,14 +4279,13 @@ DisplayText( } dInfoPtr->topOfEof = bottomY; - doScrollbars: - /* * Update the vertical scrollbar, if there is one. Note: it's important to * clear REDRAW_PENDING here, just in case the scroll function does * something that requires redisplay. */ + doScrollbars: if (textPtr->flags & UPDATE_SCROLLBARS) { textPtr->flags &= ~UPDATE_SCROLLBARS; if (textPtr->yScrollCmd != NULL) { @@ -4344,7 +4330,6 @@ DisplayText( *---------------------------------------------------------------------- */ - /* ARGSUSED */ void TkTextEventuallyRepick( TkText *textPtr) /* Widget record for text widget. */ @@ -4376,7 +4361,6 @@ TkTextEventuallyRepick( *---------------------------------------------------------------------- */ - /* ARGSUSED */ void TkTextRedrawRegion( TkText *textPtr, /* Widget record for text widget. */ @@ -4491,7 +4475,7 @@ TextInvalidateRegion( void TkTextChanged( - TkSharedText *sharedTextPtr,/* Shared widget section, or NULL */ + TkSharedText *sharedTextPtr,/* Shared widget section, or NULL. */ TkText *textPtr, /* Widget record for text widget, or NULL. */ CONST TkTextIndex*index1Ptr,/* Index of first character to redisplay. */ CONST TkTextIndex*index2Ptr)/* Index of character just after last one to @@ -4590,7 +4574,7 @@ TextChanged( void TkTextRedrawTag( - TkSharedText *sharedTextPtr,/* Shared widget section, or NULL */ + TkSharedText *sharedTextPtr,/* Shared widget section, or NULL. */ TkText *textPtr, /* Widget record for text widget. */ TkTextIndex *index1Ptr, /* First character in range to consider for * redisplay. NULL means start at beginning of @@ -4811,7 +4795,7 @@ void TkTextRelayoutWindow( TkText *textPtr, /* Widget record for text widget. */ int mask) /* OR'd collection of bits showing what has - * changed */ + * changed. */ { TextDInfo *dInfoPtr = textPtr->dInfoPtr; GC newGC; @@ -4979,7 +4963,7 @@ TkTextSetYView( if (pickPlace == TK_TEXT_NOPIXELADJUST) { if (textPtr->topIndex.linePtr == indexPtr->linePtr - && textPtr->topIndex.byteIndex == indexPtr->byteIndex) { + && textPtr->topIndex.byteIndex == indexPtr->byteIndex) { pickPlace = dInfoPtr->topPixelOffset; } else { pickPlace = 0; @@ -5022,8 +5006,7 @@ TkTextSetYView( dlPtr = NULL; } else if ((dlPtr->index.linePtr == indexPtr->linePtr) && (dlPtr->index.byteIndex <= indexPtr->byteIndex)) { - if (dInfoPtr->dLinePtr == dlPtr - && dInfoPtr->topPixelOffset != 0) { + if (dInfoPtr->dLinePtr == dlPtr && dInfoPtr->topPixelOffset != 0) { /* * It is on the top line, but that line is hanging off the top * of the screen. Change the top overlap to zero and update. @@ -5355,7 +5338,7 @@ TkTextSeeCmd( byteCount = index.byteIndex - dlPtr->index.byteIndex; for (chunkPtr = dlPtr->chunkPtr; chunkPtr != NULL ; - chunkPtr = chunkPtr->nextPtr) { + chunkPtr = chunkPtr->nextPtr) { if (byteCount < chunkPtr->numBytes) { break; } @@ -5652,8 +5635,8 @@ YScrollByLines( * top window border. */ - TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, - 0, 0, &textPtr->topIndex); + TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, 0, 0, + &textPtr->topIndex); dInfoPtr->newTopPixelOffset = 0; } else { /* @@ -6028,7 +6011,7 @@ GetXView( last = 1.0; } if (!report) { - listObj = Tcl_NewListObj(0,NULL); + listObj = Tcl_NewListObj(0, NULL); Tcl_ListObjAppendElement(interp, listObj, Tcl_NewDoubleObj(first)); Tcl_ListObjAppendElement(interp, listObj, Tcl_NewDoubleObj(last)); Tcl_SetObjResult(interp, listObj); @@ -6093,9 +6076,10 @@ static int GetYPixelCount( TkText *textPtr, /* Information about text widget. */ DLine *dlPtr) /* Information about the layout of a given - * index */ + * index. */ { TkTextLine *linePtr = dlPtr->index.linePtr; + int count; /* * Get the pixel count to the top of dlPtr's logical line. The rest of the @@ -6103,7 +6087,7 @@ GetYPixelCount( * between the top of the logical line and the display line. */ - int count = TkBTreePixelsTo(textPtr, linePtr); + count = TkBTreePixelsTo(textPtr, linePtr); /* * For the common case where this dlPtr is also the start of the logical @@ -6137,10 +6121,10 @@ GetYPixelCount( if (dlPtr->nextPtr == NULL) { /* * We've run out of pre-calculated display lines, so we have to - * lay them out ourselves until the end of the logical line. - * Here's where we could be clever and ask: what's faster, to - * layout all lines from here to line-end, or all lines from the - * original dlPtr to the line-start? We just assume the former. + * lay them out ourselves until the end of the logical line. Here + * is where we could be clever and ask: what's faster, to layout + * all lines from here to line-end, or all lines from the original + * dlPtr to the line-start? We just assume the former. */ TkTextIndex index; @@ -6250,8 +6234,8 @@ GetYView( while (1) { int extra; - count += dlPtr->height; + count += dlPtr->height; extra = dlPtr->y + dlPtr->height - dInfoPtr->maxY; if (extra > 0) { /* @@ -6528,9 +6512,11 @@ TkTextPixelIndex( return; } else { for (dlPtr = validDlPtr = dInfoPtr->dLinePtr; - y >= (dlPtr->y + dlPtr->height); - dlPtr = dlPtr->nextPtr) { - if (dlPtr->chunkPtr !=NULL) validDlPtr = dlPtr; + y >= (dlPtr->y + dlPtr->height); + dlPtr = dlPtr->nextPtr) { + if (dlPtr->chunkPtr != NULL) { + validDlPtr = dlPtr; + } if (dlPtr->nextPtr == NULL) { /* * Y-coordinate is off the bottom of the displayed text. Use @@ -6663,7 +6649,7 @@ void TkTextIndexOfX( TkText *textPtr, /* Widget record for text widget. */ int x, /* The x coordinate for which we want the - * index */ + * index. */ TkTextIndex *indexPtr) /* Index of display line start, which will be * adjusted to the index under the given x * coordinate. */ @@ -6709,7 +6695,9 @@ DlineXOfIndex( register TkTextDispChunk *chunkPtr = dlPtr->chunkPtr; int x; - if (byteIndex == 0 || chunkPtr == NULL) return 0; + if (byteIndex == 0 || chunkPtr == NULL) { + return 0; + } /* * Scan through the line's chunks to find the one that contains the @@ -6749,9 +6737,9 @@ DlineXOfIndex( * the entity (character, window, image) at that index. * * Results: - * Zero is returned if the index is on the screen. -1 means the index - * isn't on the screen. If the return value is 0, then the bounding box - * of the part of the index that's visible on the screen is returned to + * Zero is returned if the index is on the screen. -1 means the index is + * not on the screen. If the return value is 0, then the bounding box of + * the part of the index that's visible on the screen is returned to * *xPtr, *yPtr, *widthPtr, and *heightPtr. * * Side effects: @@ -6937,7 +6925,7 @@ TkTextDLineInfo( } /* - * Get bounding-box information about an elided chunk + * Get bounding-box information about an elided chunk. */ static void @@ -6965,7 +6953,7 @@ ElideBboxProc( } /* - * Measure an elided chunk + * Measure an elided chunk. */ static int @@ -7050,17 +7038,16 @@ TkTextCharLayoutProc( #if TK_LAYOUT_WITH_BASE_CHUNKS if (baseCharChunkPtr == NULL) { - baseCharChunkPtr = chunkPtr; - bciPtr = (BaseCharInfo*) ckalloc(sizeof(BaseCharInfo)); + bciPtr = (BaseCharInfo *) ckalloc(sizeof(BaseCharInfo)); baseString = &bciPtr->baseChars; Tcl_DStringInit(baseString); bciPtr->width = 0; ciPtr = &bciPtr->ci; } else { - bciPtr = (BaseCharInfo*) baseCharChunkPtr->clientData; - ciPtr = (CharInfo*) ckalloc(sizeof(CharInfo)); + bciPtr = (BaseCharInfo *) baseCharChunkPtr->clientData; + ciPtr = (CharInfo *) ckalloc(sizeof(CharInfo)); baseString = &bciPtr->baseChars; } @@ -7076,7 +7063,7 @@ TkTextCharLayoutProc( bytesThatFit = CharChunkMeasureChars(chunkPtr, line, lineOffset + maxBytes, lineOffset, -1, chunkPtr->x, maxX, TK_ISOLATE_END, &nextX); -#else /* !TK_LAYOUT_WITH_BASE_CHUNKS */ +#else /* !TK_LAYOUT_WITH_BASE_CHUNKS */ bytesThatFit = CharChunkMeasureChars(chunkPtr, p, maxBytes, 0, -1, chunkPtr->x, maxX, TK_ISOLATE_END, &nextX); #endif /* TK_LAYOUT_WITH_BASE_CHUNKS */ @@ -7087,13 +7074,12 @@ TkTextCharLayoutProc( int chLen = Tcl_UtfToUniChar(p, &ch); #if TK_LAYOUT_WITH_BASE_CHUNKS - bytesThatFit = CharChunkMeasureChars( - chunkPtr, line, lineOffset + chLen, lineOffset, -1, - chunkPtr->x, -1, 0, &nextX); -#else /* !TK_LAYOUT_WITH_BASE_CHUNKS */ - bytesThatFit = CharChunkMeasureChars( - chunkPtr, p, chLen, 0, -1, - chunkPtr->x, -1, 0, &nextX); + bytesThatFit = CharChunkMeasureChars(chunkPtr, line, + lineOffset+chLen, lineOffset, -1, chunkPtr->x, -1, 0, + &nextX); +#else /* !TK_LAYOUT_WITH_BASE_CHUNKS */ + bytesThatFit = CharChunkMeasureChars(chunkPtr, p, chLen, 0, -1, + chunkPtr->x, -1, 0, &nextX); #endif /* TK_LAYOUT_WITH_BASE_CHUNKS */ } if ((nextX < maxX) && ((p[bytesThatFit] == ' ') @@ -7124,7 +7110,7 @@ TkTextCharLayoutProc( } else { Tcl_DStringSetLength(baseString,lineOffset); } - ckfree((char*)ciPtr); + ckfree((char *) ciPtr); #endif /* TK_LAYOUT_WITH_BASE_CHUNKS */ return 0; } @@ -7162,7 +7148,6 @@ TkTextCharLayoutProc( } #if TK_LAYOUT_WITH_BASE_CHUNKS - /* * Final update for the current base chunk data. */ @@ -7178,7 +7163,6 @@ TkTextCharLayoutProc( if (ciPtr->numBytes > 0 && p[ciPtr->numBytes - 1] == '\t') { FinalizeBaseChunk(chunkPtr); } - #endif /* TK_LAYOUT_WITH_BASE_CHUNKS */ /* @@ -7215,21 +7199,21 @@ TkTextCharLayoutProc( /* *--------------------------------------------------------------------------- * - * CharChunkMeasureChars -- + * CharChunkMeasureChars -- * * Determine the number of characters from a char chunk that will fit in * the given horizontal span. * * This is the same as MeasureChars (which see), but in the context of a - * char chunk, i.e. on a higher level of abstraction. Use this function + * char chunk, i.e. on a higher level of abstraction. Use this function * whereever possible instead of plain MeasureChars, so that the right * context is used automatically. * * Results: - * The return value is the number of bytes from the range of start to - * end in source that fit in the span given by startX and maxX. - * *nextXPtr is filled in with the x-coordinate at which the first - * character that didn't fit would be drawn, if it were to be drawn. + * The return value is the number of bytes from the range of start to end + * in source that fit in the span given by startX and maxX. *nextXPtr is + * filled in with the x-coordinate at which the first character that + * didn't fit would be drawn, if it were to be drawn. * * Side effects: * None. @@ -7241,15 +7225,15 @@ CharChunkMeasureChars( TkTextDispChunk *chunkPtr, /* Chunk from which to measure. */ const char *chars, /* Chars to use, instead of the chunk's own. * Used by the layoutproc during chunk setup. - * All other callers use NULL. Not + * All other callers use NULL. Not * NUL-terminated. */ int charsLen, /* Length of the "chars" parameter. */ int start, int end, /* The range of chars to measure inside the * chunk (or inside the additional chars). */ int startX, /* Starting x coordinate where the measured * span will begin. */ - int maxX, /* Maximum pixel width of the span. May be - * -1 for unlimited. */ + int maxX, /* Maximum pixel width of the span. May be -1 + * for unlimited. */ int flags, /* Flags to pass to MeasureChars. */ int *nextXPtr) /* The function puts the newly calculated * right border x-position of the span @@ -7275,8 +7259,9 @@ CharChunkMeasureChars( int fit, bstart = start, bend = end; if (chars == NULL) { - Tcl_DString *baseChars = - &((BaseCharInfo *)ciPtr->baseChunkPtr->clientData)->baseChars; + Tcl_DString *baseChars = &((BaseCharInfo *) + ciPtr->baseChunkPtr->clientData)->baseChars; + chars = Tcl_DStringValue(baseChars); charsLen = Tcl_DStringLength(baseChars); bstart += ciPtr->baseOffset; @@ -7285,16 +7270,15 @@ CharChunkMeasureChars( } else { bend += ciPtr->baseOffset; } - } else { - if (bend == -1) { - bend = charsLen; - } + } else if (bend == -1) { + bend = charsLen; } if (bstart == ciPtr->baseOffset) { xDisplacement = startX - chunkPtr->x; } else { int widthUntilStart = 0; + MeasureChars(tkfont, chars, charsLen, 0, bstart, 0, -1, 0, &widthUntilStart); xDisplacement = startX - widthUntilStart - chunkPtr->x; @@ -7352,7 +7336,7 @@ CharDisplayProc( int numBytes, offsetBytes, offsetX; #if TK_DRAW_IN_CONTEXT BaseCharInfo *bciPtr; -#endif +#endif /* TK_DRAW_IN_CONTEXT */ if ((x + chunkPtr->width) <= 0) { /* @@ -7363,13 +7347,11 @@ CharDisplayProc( } #if TK_DRAW_IN_CONTEXT - - bciPtr = (BaseCharInfo*) ciPtr->baseChunkPtr->clientData; + bciPtr = (BaseCharInfo *) ciPtr->baseChunkPtr->clientData; numBytes = Tcl_DStringLength(&bciPtr->baseChars); string = Tcl_DStringValue(&bciPtr->baseChars); #elif TK_LAYOUT_WITH_BASE_CHUNKS - if (ciPtr->baseChunkPtr != chunkPtr) { /* * Without context drawing only base chunks display their foreground. @@ -7378,14 +7360,12 @@ CharDisplayProc( return; } - numBytes = Tcl_DStringLength(&((BaseCharInfo*) ciPtr)->baseChars); + numBytes = Tcl_DStringLength(&((BaseCharInfo *) ciPtr)->baseChars); string = ciPtr->chars; #else /* !TK_LAYOUT_WITH_BASE_CHUNKS */ - numBytes = ciPtr->numBytes; string = ciPtr->chars; - #endif /* TK_LAYOUT_WITH_BASE_CHUNKS */ stylePtr = chunkPtr->stylePtr; @@ -7410,8 +7390,8 @@ CharDisplayProc( * Draw the text, underline, and overstrike for this chunk. */ - if (!sValuePtr->elide && (numBytes > offsetBytes) - && (stylePtr->fgGC != None)) { + if (!sValuePtr->elide && (numBytes > offsetBytes) + && (stylePtr->fgGC != None)) { #if TK_DRAW_IN_CONTEXT int start = ciPtr->baseOffset + offsetBytes; int len = ciPtr->numBytes - offsetBytes; @@ -7438,7 +7418,7 @@ CharDisplayProc( } if (sValuePtr->overstrike) { Tk_FontMetrics fm; - + Tk_GetFontMetrics(sValuePtr->tkfont, &fm); TkUnderlineCharsInContext(display, dst, stylePtr->fgGC, sValuePtr->tkfont, string, numBytes, @@ -7447,7 +7427,7 @@ CharDisplayProc( - fm.descent - (fm.ascent * 3) / 10, start, start+len); } -#else +#else /* !TK_DRAW_IN_CONTEXT */ string += offsetBytes; numBytes -= offsetBytes; @@ -7473,7 +7453,7 @@ CharDisplayProc( - fm.descent - (fm.ascent * 3) / 10, 0, numBytes); } -#endif +#endif /* TK_DRAW_IN_CONTEXT */ } } @@ -7504,7 +7484,6 @@ CharUndisplayProc( #if TK_LAYOUT_WITH_BASE_CHUNKS if (chunkPtr == ciPtr->baseChunkPtr) { - /* * Basechunks are undisplayed first, when DLines are freed or * partially freed, so this makes sure we don't access their data any @@ -7512,13 +7491,11 @@ CharUndisplayProc( */ FreeBaseChunk(chunkPtr); - } else if (ciPtr->baseChunkPtr != NULL) { - /* * When other char chunks are undisplayed, drop their characters from - * the base chunk. This usually happens, when they are last in a - * line and need to be re-layed out. + * the base chunk. This usually happens, when they are last in a line + * and need to be re-layed out. */ RemoveFromBaseChunk(chunkPtr); @@ -7559,9 +7536,8 @@ CharMeasureProc( { int endX; - return CharChunkMeasureChars( - chunkPtr, NULL, 0, 0, chunkPtr->numBytes - 1, chunkPtr->x, x, 0, - &endX); /* CHAR OFFSET */ + return CharChunkMeasureChars(chunkPtr, NULL, 0, 0, chunkPtr->numBytes-1, + chunkPtr->x, x, 0, &endX); /* CHAR OFFSET */ } /* @@ -7881,7 +7857,7 @@ SizeOfTab( tabWidth = 1; } } else { - tabWidth = 0; /* Avoid compiler error */ + tabWidth = 0; /* Avoid compiler error. */ } do { @@ -8029,10 +8005,10 @@ NextTabStop( * that point. * * Results: - * The return value is the number of bytes from the range of start to - * end in source that fit in the span given by startX and maxX. - * *nextXPtr is filled in with the x-coordinate at which the first - * character that didn't fit would be drawn, if it were to be drawn. + * The return value is the number of bytes from the range of start to end + * in source that fit in the span given by startX and maxX. *nextXPtr is + * filled in with the x-coordinate at which the first character that + * didn't fit would be drawn, if it were to be drawn. * * Side effects: * None. @@ -8095,7 +8071,7 @@ MeasureChars( (void) maxBytes; start += Tk_MeasureChars(tkfont, start, special - start, maxX >= 0 ? maxX - curX : -1, flags, &width); -#endif +#endif /* TK_DRAW_IN_CONTEXT */ curX += width; if (start < special) { /* @@ -8224,8 +8200,8 @@ TextGetScrollInfoObj( * FinalizeBaseChunk -- * * This procedure makes sure that all the chunks of the stretch are - * up-to-date. It is invoked when the LayoutProc has been called for - * all chunks and the base chunk is stable. + * up-to-date. It is invoked when the LayoutProc has been called for all + * chunks and the base chunk is stable. * * Results: * None. @@ -8239,33 +8215,32 @@ TextGetScrollInfoObj( static void FinalizeBaseChunk( - TkTextDispChunk *addChunkPtr) /* An additional chunk to add to the - * stretch, even though it may not be - * in the linked list yet. Used by - * the LayoutProc, otherwise NULL. */ + TkTextDispChunk *addChunkPtr) + /* An additional chunk to add to the stretch, + * even though it may not be in the linked + * list yet. Used by the LayoutProc, otherwise + * NULL. */ { const char *baseChars; TkTextDispChunk *chunkPtr; - CharInfo * ciPtr; + CharInfo *ciPtr; #if TK_DRAW_IN_CONTEXT int widthAdjust = 0; int newwidth; -#endif +#endif /* TK_DRAW_IN_CONTEXT */ if (baseCharChunkPtr == NULL) { return; } baseChars = Tcl_DStringValue( - &((BaseCharInfo*) baseCharChunkPtr->clientData)->baseChars); - - for (chunkPtr = baseCharChunkPtr; - chunkPtr != NULL; - chunkPtr = chunkPtr->nextPtr) { + &((BaseCharInfo *) baseCharChunkPtr->clientData)->baseChars); + for (chunkPtr = baseCharChunkPtr; chunkPtr != NULL; + chunkPtr = chunkPtr->nextPtr) { #if TK_DRAW_IN_CONTEXT chunkPtr->x += widthAdjust; -#endif +#endif /* TK_DRAW_IN_CONTEXT */ if (chunkPtr->displayProc != CharDisplayProc) { continue; @@ -8278,27 +8253,23 @@ FinalizeBaseChunk( #if TK_DRAW_IN_CONTEXT newwidth = 0; - CharChunkMeasureChars( - chunkPtr, NULL, 0, 0, -1, 0, -1, 0, &newwidth); + CharChunkMeasureChars(chunkPtr, NULL, 0, 0, -1, 0, -1, 0, &newwidth); if (newwidth != chunkPtr->width) { widthAdjust += newwidth - chunkPtr->width; chunkPtr->width = newwidth; } -#endif - +#endif /* TK_DRAW_IN_CONTEXT */ } if (addChunkPtr != NULL) { - ciPtr = (CharInfo *)addChunkPtr->clientData; ciPtr->chars = baseChars + ciPtr->baseOffset; #if TK_DRAW_IN_CONTEXT addChunkPtr->x += widthAdjust; - CharChunkMeasureChars( - addChunkPtr, NULL, 0, 0, -1, 0, -1, 0, &addChunkPtr->width); -#endif - + CharChunkMeasureChars(addChunkPtr, NULL, 0, 0, -1, 0, -1, 0, + &addChunkPtr->width); +#endif /* TK_DRAW_IN_CONTEXT */ } baseCharChunkPtr = NULL; @@ -8311,7 +8282,7 @@ FinalizeBaseChunk( * * This procedure makes sure that all the chunks of the stretch are * disconnected from the base chunk and the base chunk specific data is - * freed. It is invoked from the UndisplayProc. The procedure doesn't + * freed. It is invoked from the UndisplayProc. The procedure doesn't * ckfree the base chunk clientData itself, that's up to the main * UndisplayProc. * @@ -8319,7 +8290,7 @@ FinalizeBaseChunk( * None. * * Side effects: - * The CharInfo.chars of all dependent chunks are set to NULL. Memory + * The CharInfo.chars of all dependent chunks are set to NULL. Memory * that belongs specifically to the base chunk is freed. * *---------------------------------------------------------------------- @@ -8327,8 +8298,9 @@ FinalizeBaseChunk( static void FreeBaseChunk( - TkTextDispChunk * baseChunkPtr) /* The base chunk of the stretch and - * head of the linked list. */ + TkTextDispChunk *baseChunkPtr) + /* The base chunk of the stretch and head of + * the linked list. */ { TkTextDispChunk *chunkPtr; CharInfo *ciPtr; @@ -8337,10 +8309,7 @@ FreeBaseChunk( baseCharChunkPtr = NULL; } - for (chunkPtr = baseChunkPtr; - chunkPtr != NULL; - chunkPtr = chunkPtr->nextPtr) { - + for (chunkPtr=baseChunkPtr; chunkPtr!=NULL; chunkPtr=chunkPtr->nextPtr) { if (chunkPtr->undisplayProc != CharUndisplayProc) { continue; } @@ -8353,7 +8322,7 @@ FreeBaseChunk( ciPtr->chars = NULL; } - Tcl_DStringFree(&((BaseCharInfo*)baseChunkPtr->clientData)->baseChars); + Tcl_DStringFree(&((BaseCharInfo *) baseChunkPtr->clientData)->baseChars); } /* @@ -8361,9 +8330,9 @@ FreeBaseChunk( * * IsSameFGStyle -- * - * Compare the foreground attributes of two styles. Specifically - * consider: Foreground color, font, font style and font decorations, - * elide, "offset" and foreground stipple. *Don't* consider: Background + * Compare the foreground attributes of two styles. Specifically must + * consider: foreground color, font, font style and font decorations, + * elide, "offset" and foreground stipple. Do *not* consider: background * color, border, relief or background stipple. * * If we use TkpDrawCharsInContext(), we also don't need to check @@ -8383,7 +8352,7 @@ FreeBaseChunk( static int IsSameFGStyle( TextStyle *style1, - TextStyle *style2) + TextStyle *style2) { StyleValues *sv1; StyleValues *sv2; @@ -8393,36 +8362,31 @@ IsSameFGStyle( } #if !TK_DRAW_IN_CONTEXT - if ( #ifdef MAC_OSX_TK !TkMacOSXCompareColors(style1->fgGC->foreground, - style2->fgGC->foreground) + style2->fgGC->foreground) #else style1->fgGC->foreground != style2->fgGC->foreground #endif ) { return 0; } - -#endif +#endif /* !TK_DRAW_IN_CONTEXT */ sv1 = style1->sValuePtr; sv2 = style2->sValuePtr; #if TK_DRAW_IN_CONTEXT - return sv1->tkfont == sv2->tkfont - && sv1->offset == sv2->offset - ; + return sv1->tkfont == sv2->tkfont && sv1->offset == sv2->offset; #else - return sv1->tkfont == sv2->tkfont - && sv1->underline == sv2->underline - && sv1->overstrike == sv2->overstrike - && sv1->elide == sv2->elide - && sv1->offset == sv2->offset - && sv1->fgStipple == sv1->fgStipple - ; -#endif + return sv1->tkfont == sv2->tkfont + && sv1->underline == sv2->underline + && sv1->overstrike == sv2->overstrike + && sv1->elide == sv2->elide + && sv1->offset == sv2->offset + && sv1->fgStipple == sv1->fgStipple; +#endif /* TK_DRAW_IN_CONTEXT */ } /* @@ -8431,29 +8395,29 @@ IsSameFGStyle( * RemoveFromBaseChunk -- * * This procedure removes a chunk from the stretch as a result of - * UndisplayProc. The chunk in question should be the last in a - * stretch. This happens during re-layouting of the break position. + * UndisplayProc. The chunk in question should be the last in a stretch. + * This happens during re-layouting of the break position. * * Results: * None. * * Side effects: * The characters that belong to this chunk are removed from the base - * chunk. It is assumed that LayoutProc and FinalizeBaseChunk are - * called next to repair any damage that this causes to the integrity of - * the stretch and the other chunks. For that reason the base chunk is - * also put into baseCharChunkPtr automatically, so that LayoutProc can - * resume correctly. + * chunk. It is assumed that LayoutProc and FinalizeBaseChunk are called + * next to repair any damage that this causes to the integrity of the + * stretch and the other chunks. For that reason the base chunk is also + * put into baseCharChunkPtr automatically, so that LayoutProc can resume + * correctly. * *---------------------------------------------------------------------- */ static void RemoveFromBaseChunk( - TkTextDispChunk *chunkPtr) /* The chunk to remove from the end - * of the stretch. */ + TkTextDispChunk *chunkPtr) /* The chunk to remove from the end of the + * stretch. */ { - CharInfo *ciPtr; + CharInfo *ciPtr; BaseCharInfo *bciPtr; if (chunkPtr->displayProc != CharDisplayProc) { @@ -8465,14 +8429,14 @@ RemoveFromBaseChunk( * Reinstitute this base chunk for re-layout. */ - ciPtr = (CharInfo*) chunkPtr->clientData; + ciPtr = (CharInfo *) chunkPtr->clientData; baseCharChunkPtr = ciPtr->baseChunkPtr; /* * Remove the chunk data from the base chunk data. */ - bciPtr = (BaseCharInfo*) baseCharChunkPtr->clientData; + bciPtr = (BaseCharInfo *) baseCharChunkPtr->clientData; if ((ciPtr->baseOffset + ciPtr->numBytes) != Tcl_DStringLength(&bciPtr->baseChars)) { diff --git a/generic/tkTextIndex.c b/generic/tkTextIndex.c index 970c414..511806b 100644 --- a/generic/tkTextIndex.c +++ b/generic/tkTextIndex.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: tkTextIndex.c,v 1.24 2005/11/17 16:21:56 dkf Exp $ + * RCS: @(#) $Id: tkTextIndex.c,v 1.25 2007/02/22 13:56:33 dkf Exp $ */ #include "default.h" @@ -82,8 +82,8 @@ Tcl_ObjType tkTextIndexType = { }; static void -FreeTextIndexInternalRep(indexObjPtr) - Tcl_Obj *indexObjPtr; /* TextIndex object with internal rep to +FreeTextIndexInternalRep( + Tcl_Obj *indexObjPtr) /* TextIndex object with internal rep to * free. */ { TkTextIndex *indexPtr = GET_TEXTINDEX(indexObjPtr); @@ -96,17 +96,18 @@ FreeTextIndexInternalRep(indexObjPtr) ckfree((char *) (indexPtr->textPtr)); } } - ckfree((char*)indexPtr); + ckfree((char *) indexPtr); } static void -DupTextIndexInternalRep(srcPtr, copyPtr) - Tcl_Obj *srcPtr; /* TextIndex obj with internal rep to copy. */ - Tcl_Obj *copyPtr; /* TextIndex obj with internal rep to set. */ +DupTextIndexInternalRep( + Tcl_Obj *srcPtr, /* TextIndex obj with internal rep to copy. */ + Tcl_Obj *copyPtr) /* TextIndex obj with internal rep to set. */ { int epoch; TkTextIndex *dupIndexPtr, *indexPtr; - dupIndexPtr = (TkTextIndex*) ckalloc(sizeof(TkTextIndex)); + + dupIndexPtr = (TkTextIndex *) ckalloc(sizeof(TkTextIndex)); indexPtr = GET_TEXTINDEX(srcPtr); epoch = GET_INDEXEPOCH(srcPtr); @@ -125,8 +126,8 @@ DupTextIndexInternalRep(srcPtr, copyPtr) */ static void -UpdateStringOfTextIndex(objPtr) - Tcl_Obj *objPtr; +UpdateStringOfTextIndex( + Tcl_Obj *objPtr) { char buffer[TK_POS_CHARS]; register int len; @@ -141,9 +142,9 @@ UpdateStringOfTextIndex(objPtr) } static int -SetTextIndexFromAny(interp, objPtr) - Tcl_Interp *interp; /* Used for error reporting if not NULL. */ - Tcl_Obj *objPtr; /* The object to convert. */ +SetTextIndexFromAny( + Tcl_Interp *interp, /* Used for error reporting if not NULL. */ + Tcl_Obj *objPtr) /* The object to convert. */ { Tcl_AppendToObj(Tcl_GetObjResult(interp), "can't convert value to textindex except via TkTextGetIndexFromObj API", @@ -164,7 +165,7 @@ SetTextIndexFromAny(interp, objPtr) * very temporary (like @0,0 or the name of a mark or tag). The mapping * from such strings/objects to actual TkTextIndex pointers is not stable * to minor text widget changes which we do not track (we track - * insertions/deletions). + * insertions and deletions). * * Results: * A pointer to an allocated TkTextIndex which will be freed @@ -177,11 +178,11 @@ SetTextIndexFromAny(interp, objPtr) */ static TkTextIndex * -MakeObjIndex(textPtr, objPtr, origPtr) - TkText *textPtr; /* Information about text widget. */ - Tcl_Obj *objPtr; /* Object containing description of +MakeObjIndex( + TkText *textPtr, /* Information about text widget. */ + Tcl_Obj *objPtr, /* Object containing description of * position. */ - CONST TkTextIndex *origPtr; /* Pointer to index. */ + CONST TkTextIndex *origPtr) /* Pointer to index. */ { TkTextIndex *indexPtr = (TkTextIndex *) ckalloc(sizeof(TkTextIndex)); @@ -201,11 +202,11 @@ MakeObjIndex(textPtr, objPtr, origPtr) return indexPtr; } -CONST TkTextIndex* -TkTextGetIndexFromObj(interp, textPtr, objPtr) - Tcl_Interp *interp; /* Use this for error reporting. */ - TkText *textPtr; /* Information about text widget. */ - Tcl_Obj *objPtr; /* Object containing description of +CONST TkTextIndex * +TkTextGetIndexFromObj( + Tcl_Interp *interp, /* Use this for error reporting. */ + TkText *textPtr, /* Information about text widget. */ + Tcl_Obj *objPtr) /* Object containing description of * position. */ { TkTextIndex index; @@ -245,11 +246,7 @@ TkTextGetIndexFromObj(interp, textPtr, objPtr) } } - if (cache) { - return MakeObjIndex(textPtr, objPtr, &index); - } else { - return MakeObjIndex(NULL, objPtr, &index); - } + return MakeObjIndex((cache ? textPtr : NULL), objPtr, &index); } /* @@ -270,10 +267,10 @@ TkTextGetIndexFromObj(interp, textPtr, objPtr) *--------------------------------------------------------------------------- */ -Tcl_Obj* -TkTextNewIndexObj(textPtr, indexPtr) - TkText *textPtr; /* Text widget for this index */ - CONST TkTextIndex *indexPtr;/* Pointer to index. */ +Tcl_Obj * +TkTextNewIndexObj( + TkText *textPtr, /* Text widget for this index */ + CONST TkTextIndex *indexPtr)/* Pointer to index. */ { Tcl_Obj *retVal; @@ -326,11 +323,11 @@ TkTextNewIndexObj(textPtr, indexPtr) */ int -TkTextMakePixelIndex(textPtr, pixelIndex, indexPtr) - TkText* textPtr; /* The Text Widget */ - int pixelIndex; /* Pixel-index of desired line (0 means first +TkTextMakePixelIndex( + TkText *textPtr, /* The Text Widget */ + int pixelIndex, /* Pixel-index of desired line (0 means first * pixel of first line of text). */ - TkTextIndex *indexPtr; /* Structure to fill in. */ + TkTextIndex *indexPtr) /* Structure to fill in. */ { int pixelOffset = 0; @@ -345,7 +342,7 @@ TkTextMakePixelIndex(textPtr, pixelIndex, indexPtr) /* * 'pixelIndex' was too large, so we try again, just to find the last - * pixel in the window + * pixel in the window. */ if (indexPtr->linePtr == NULL) { @@ -386,14 +383,14 @@ TkTextMakePixelIndex(textPtr, pixelIndex, indexPtr) */ TkTextIndex * -TkTextMakeByteIndex(tree, textPtr, lineIndex, byteIndex, indexPtr) - TkTextBTree tree; /* Tree that lineIndex and byteIndex refer +TkTextMakeByteIndex( + TkTextBTree tree, /* Tree that lineIndex and byteIndex refer * to. */ - CONST TkText *textPtr; - int lineIndex; /* Index of desired line (0 means first line + CONST TkText *textPtr, + int lineIndex, /* Index of desired line (0 means first line * of text). */ - int byteIndex; /* Byte index of desired character. */ - TkTextIndex *indexPtr; /* Structure to fill in. */ + int byteIndex, /* Byte index of desired character. */ + TkTextIndex *indexPtr) /* Structure to fill in. */ { TkTextSegment *segPtr; int index; @@ -479,14 +476,14 @@ TkTextMakeByteIndex(tree, textPtr, lineIndex, byteIndex, indexPtr) */ TkTextIndex * -TkTextMakeCharIndex(tree, textPtr, lineIndex, charIndex, indexPtr) - TkTextBTree tree; /* Tree that lineIndex and charIndex refer +TkTextMakeCharIndex( + TkTextBTree tree, /* Tree that lineIndex and charIndex refer * to. */ - TkText *textPtr; - int lineIndex; /* Index of desired line (0 means first line + TkText *textPtr, + int lineIndex, /* Index of desired line (0 means first line * of text). */ - int charIndex; /* Index of desired character. */ - TkTextIndex *indexPtr; /* Structure to fill in. */ + int charIndex, /* Index of desired character. */ + TkTextIndex *indexPtr) /* Structure to fill in. */ { register TkTextSegment *segPtr; char *p, *start, *end; @@ -574,9 +571,9 @@ TkTextMakeCharIndex(tree, textPtr, lineIndex, charIndex, indexPtr) */ TkTextSegment * -TkTextIndexToSeg(indexPtr, offsetPtr) - CONST TkTextIndex *indexPtr;/* Text index. */ - int *offsetPtr; /* Where to store offset within segment, or +TkTextIndexToSeg( + CONST TkTextIndex *indexPtr,/* Text index. */ + int *offsetPtr) /* Where to store offset within segment, or * NULL if offset isn't wanted. */ { TkTextSegment *segPtr; @@ -612,14 +609,13 @@ TkTextIndexToSeg(indexPtr, offsetPtr) */ int -TkTextSegToOffset(segPtr, linePtr) - CONST TkTextSegment *segPtr;/* Segment whose offset is desired. */ - CONST TkTextLine *linePtr; /* Line containing segPtr. */ +TkTextSegToOffset( + CONST TkTextSegment *segPtr,/* Segment whose offset is desired. */ + CONST TkTextLine *linePtr) /* Line containing segPtr. */ { CONST TkTextSegment *segPtr2; - int offset; + int offset = 0; - offset = 0; for (segPtr2 = linePtr->segPtr; segPtr2 != segPtr; segPtr2 = segPtr2->nextPtr) { offset += segPtr2->size; @@ -645,12 +641,12 @@ TkTextSegToOffset(segPtr, linePtr) */ int -TkTextGetObjIndex(interp, textPtr, idxObj, indexPtr) - Tcl_Interp *interp; /* Use this for error reporting. */ - TkText *textPtr; /* Information about text widget. */ - Tcl_Obj *idxObj; /* Object containing textual description of +TkTextGetObjIndex( + Tcl_Interp *interp, /* Use this for error reporting. */ + TkText *textPtr, /* Information about text widget. */ + Tcl_Obj *idxObj, /* Object containing textual description of * position. */ - TkTextIndex *indexPtr; /* Index structure to fill in. */ + TkTextIndex *indexPtr) /* Index structure to fill in. */ { return GetIndex(interp, NULL, textPtr, Tcl_GetString(idxObj), indexPtr, NULL); @@ -674,12 +670,12 @@ TkTextGetObjIndex(interp, textPtr, idxObj, indexPtr) */ int -TkTextSharedGetObjIndex(interp, sharedTextPtr, idxObj, indexPtr) - Tcl_Interp *interp; /* Use this for error reporting. */ - TkSharedText *sharedTextPtr;/* Information about text widget. */ - Tcl_Obj *idxObj; /* Object containing textual description of +TkTextSharedGetObjIndex( + Tcl_Interp *interp, /* Use this for error reporting. */ + TkSharedText *sharedTextPtr,/* Information about text widget. */ + Tcl_Obj *idxObj, /* Object containing textual description of * position. */ - TkTextIndex *indexPtr; /* Index structure to fill in. */ + TkTextIndex *indexPtr) /* Index structure to fill in. */ { return GetIndex(interp, sharedTextPtr, NULL, Tcl_GetString(idxObj), indexPtr, NULL); @@ -705,11 +701,11 @@ TkTextSharedGetObjIndex(interp, sharedTextPtr, idxObj, indexPtr) */ int -TkTextGetIndex(interp, textPtr, string, indexPtr) - Tcl_Interp *interp; /* Use this for error reporting. */ - TkText *textPtr; /* Information about text widget. */ - CONST char *string; /* Textual description of position. */ - TkTextIndex *indexPtr; /* Index structure to fill in. */ +TkTextGetIndex( + Tcl_Interp *interp, /* Use this for error reporting. */ + TkText *textPtr, /* Information about text widget. */ + CONST char *string, /* Textual description of position. */ + TkTextIndex *indexPtr) /* Index structure to fill in. */ { return GetIndex(interp, NULL, textPtr, string, indexPtr, NULL); } @@ -738,13 +734,13 @@ TkTextGetIndex(interp, textPtr, string, indexPtr) */ static int -GetIndex(interp, sharedPtr, textPtr, string, indexPtr, canCachePtr) - Tcl_Interp *interp; /* Use this for error reporting. */ - TkSharedText *sharedPtr; - TkText *textPtr; /* Information about text widget. */ - CONST char *string; /* Textual description of position. */ - TkTextIndex *indexPtr; /* Index structure to fill in. */ - int *canCachePtr; /* Pointer to integer to store whether we can +GetIndex( + Tcl_Interp *interp, /* Use this for error reporting. */ + TkSharedText *sharedPtr, + TkText *textPtr, /* Information about text widget. */ + CONST char *string, /* Textual description of position. */ + TkTextIndex *indexPtr, /* Index structure to fill in. */ + int *canCachePtr) /* Pointer to integer to store whether we can * cache the index (or NULL). */ { char *p, *end, *endOfBase; @@ -948,7 +944,7 @@ GetIndex(interp, sharedPtr, textPtr, string, indexPtr, canCachePtr) } /* - * See if the base position is the name of an embedded image + * See if the base position is the name of an embedded image. */ c = *endOfBase; @@ -1026,10 +1022,10 @@ GetIndex(interp, sharedPtr, textPtr, string, indexPtr, canCachePtr) */ int -TkTextPrintIndex(textPtr, indexPtr, string) - CONST TkText *textPtr; - CONST TkTextIndex *indexPtr;/* Pointer to index. */ - char *string; /* Place to store the position. Must have at +TkTextPrintIndex( + CONST TkText *textPtr, + CONST TkTextIndex *indexPtr,/* Pointer to index. */ + char *string) /* Place to store the position. Must have at * least TK_POS_CHARS characters. */ { TkTextSegment *segPtr; @@ -1090,9 +1086,9 @@ TkTextPrintIndex(textPtr, indexPtr, string) */ int -TkTextIndexCmp(index1Ptr, index2Ptr) - CONST TkTextIndex *index1Ptr; /* First index. */ - CONST TkTextIndex *index2Ptr; /* Second index. */ +TkTextIndexCmp( + CONST TkTextIndex*index1Ptr,/* First index. */ + CONST TkTextIndex*index2Ptr)/* Second index. */ { int line1, line2; @@ -1145,12 +1141,12 @@ TkTextIndexCmp(index1Ptr, index2Ptr) */ static CONST char * -ForwBack(textPtr, string, indexPtr) - TkText *textPtr; /* Information about text widget. */ - CONST char *string; /* String to parse for additional info about +ForwBack( + TkText *textPtr, /* Information about text widget. */ + CONST char *string, /* String to parse for additional info about * modifier (count and units). Points to "+" * or "-" that starts modifier. */ - TkTextIndex *indexPtr; /* Index to update as specified in string. */ + TkTextIndex *indexPtr) /* Index to update as specified in string. */ { register CONST char *p, *units; char *end; @@ -1188,8 +1184,8 @@ ForwBack(textPtr, string, indexPtr) p++; } length = p - units; - if ((*units == 'd') && (strncmp(units, "display", - (length > 7 ? 7 : length)) == 0)) { + if ((*units == 'd') && + (strncmp(units, "display", (length > 7 ? 7 : length)) == 0)) { modifier = TKINDEX_DISPLAY; if (length > 7) { p -= (length - 7); @@ -1313,7 +1309,7 @@ ForwBack(textPtr, string, indexPtr) while (count-- > 0) { /* * Go to the beginning of the line, then backward one - * char/byte to get to the end of the previous line + * char/byte to get to the end of the previous line. */ TkTextFindDisplayLineEnd(textPtr, indexPtr, 0, NULL); @@ -1391,12 +1387,12 @@ ForwBack(textPtr, string, indexPtr) */ int -TkTextIndexForwBytes(textPtr, srcPtr, byteCount, dstPtr) - CONST TkText *textPtr; - CONST TkTextIndex *srcPtr; /* Source index. */ - int byteCount; /* How many bytes forward to move. May be +TkTextIndexForwBytes( + CONST TkText *textPtr, + CONST TkTextIndex *srcPtr, /* Source index. */ + int byteCount, /* How many bytes forward to move. May be * negative. */ - TkTextIndex *dstPtr; /* Destination index: gets modified. */ + TkTextIndex *dstPtr) /* Destination index: gets modified. */ { TkTextLine *linePtr; TkTextSegment *segPtr; @@ -1463,13 +1459,13 @@ TkTextIndexForwBytes(textPtr, srcPtr, byteCount, dstPtr) */ void -TkTextIndexForwChars(textPtr, srcPtr, charCount, dstPtr, type) - CONST TkText *textPtr; /* Overall information about text widget. */ - CONST TkTextIndex *srcPtr; /* Source index. */ - int charCount; /* How many characters forward to move. May +TkTextIndexForwChars( + CONST TkText *textPtr, /* Overall information about text widget. */ + CONST TkTextIndex *srcPtr, /* Source index. */ + int charCount, /* How many characters forward to move. May * be negative. */ - TkTextIndex *dstPtr; /* Destination index: gets modified. */ - TkTextCountType type; /* The type of item to count */ + TkTextIndex *dstPtr, /* Destination index: gets modified. */ + TkTextCountType type) /* The type of item to count */ { TkTextLine *linePtr; TkTextSegment *segPtr; @@ -1485,7 +1481,8 @@ TkTextIndexForwChars(textPtr, srcPtr, charCount, dstPtr, type) return; } if (checkElided) { - infoPtr = (TkTextElideInfo*)ckalloc((unsigned)sizeof(TkTextElideInfo)); + infoPtr = (TkTextElideInfo *) + ckalloc((unsigned) sizeof(TkTextElideInfo)); elide = TkTextIsElided(textPtr, srcPtr, infoPtr); } @@ -1518,7 +1515,7 @@ TkTextIndexForwChars(textPtr, srcPtr, charCount, dstPtr, type) /* * If we do need to pay attention to the visibility of * characters/indices, check that first. If the current segment - * isn't visible, then we simply continue the loop + * isn't visible, then we simply continue the loop. */ if (checkElided && ((segPtr->typePtr == &tkTextToggleOffType) @@ -1613,7 +1610,7 @@ TkTextIndexForwChars(textPtr, srcPtr, charCount, dstPtr, type) forwardCharDone: if (infoPtr != NULL) { TkTextFreeElideInfo(infoPtr); - ckfree((char*) infoPtr); + ckfree((char *) infoPtr); } } @@ -1642,22 +1639,20 @@ TkTextIndexForwChars(textPtr, srcPtr, charCount, dstPtr, type) */ int -TkTextIndexCount(textPtr, indexPtr1, indexPtr2, type) - CONST TkText *textPtr; /* Overall information about text widget. */ - CONST TkTextIndex *indexPtr1; +TkTextIndexCount( + CONST TkText *textPtr, /* Overall information about text widget. */ + CONST TkTextIndex *indexPtr1, /* Index describing location of character from * which to count. */ - CONST TkTextIndex *indexPtr2; + CONST TkTextIndex *indexPtr2, /* Index describing location of last character * at which to stop the count. */ - TkTextCountType type; /* The kind of indices to count. */ + TkTextCountType type) /* The kind of indices to count. */ { TkTextLine *linePtr1; TkTextSegment *segPtr, *seg2Ptr = NULL; TkTextElideInfo *infoPtr = NULL; - int byteOffset, maxBytes; - int count = 0; - int elide = 0; + int byteOffset, maxBytes, count = 0, elide = 0; int checkElided = (type & COUNT_DISPLAY); /* @@ -1671,7 +1666,8 @@ TkTextIndexCount(textPtr, indexPtr1, indexPtr2, type) seg2Ptr = TkTextIndexToSeg(indexPtr2, &maxBytes); if (checkElided) { - infoPtr = (TkTextElideInfo*)ckalloc((unsigned)sizeof(TkTextElideInfo)); + infoPtr = (TkTextElideInfo *) + ckalloc((unsigned) sizeof(TkTextElideInfo)); elide = TkTextIsElided(textPtr, indexPtr1, infoPtr); } @@ -1811,7 +1807,7 @@ TkTextIndexCount(textPtr, indexPtr1, indexPtr2, type) countDone: if (infoPtr != NULL) { TkTextFreeElideInfo(infoPtr); - ckfree((char*) infoPtr); + ckfree((char *) infoPtr); } return count; } @@ -1839,12 +1835,12 @@ TkTextIndexCount(textPtr, indexPtr1, indexPtr2, type) */ int -TkTextIndexBackBytes(textPtr, srcPtr, byteCount, dstPtr) - CONST TkText *textPtr; - CONST TkTextIndex *srcPtr; /* Source index. */ - int byteCount; /* How many bytes backward to move. May be +TkTextIndexBackBytes( + CONST TkText *textPtr, + CONST TkTextIndex *srcPtr, /* Source index. */ + int byteCount, /* How many bytes backward to move. May be * negative. */ - TkTextIndex *dstPtr; /* Destination index: gets modified. */ + TkTextIndex *dstPtr) /* Destination index: gets modified. */ { TkTextSegment *segPtr; int lineIndex; @@ -1909,13 +1905,13 @@ TkTextIndexBackBytes(textPtr, srcPtr, byteCount, dstPtr) */ void -TkTextIndexBackChars(textPtr, srcPtr, charCount, dstPtr, type) - CONST TkText *textPtr; /* Overall information about text widget. */ - CONST TkTextIndex *srcPtr; /* Source index. */ - int charCount; /* How many characters backward to move. May +TkTextIndexBackChars( + CONST TkText *textPtr, /* Overall information about text widget. */ + CONST TkTextIndex *srcPtr, /* Source index. */ + int charCount, /* How many characters backward to move. May * be negative. */ - TkTextIndex *dstPtr; /* Destination index: gets modified. */ - TkTextCountType type; /* The type of item to count */ + TkTextIndex *dstPtr, /* Destination index: gets modified. */ + TkTextCountType type) /* The type of item to count */ { TkTextSegment *segPtr, *oldPtr; TkTextElideInfo *infoPtr = NULL; @@ -1967,7 +1963,7 @@ TkTextIndexBackChars(textPtr, srcPtr, charCount, dstPtr, type) } /* - * Now segPtr points to the segment containing the starting index + * Now segPtr points to the segment containing the starting index. */ while (1) { @@ -2095,7 +2091,7 @@ TkTextIndexBackChars(textPtr, srcPtr, charCount, dstPtr, type) backwardCharDone: if (infoPtr != NULL) { TkTextFreeElideInfo(infoPtr); - ckfree((char*) infoPtr); + ckfree((char *) infoPtr); } } @@ -2120,12 +2116,12 @@ TkTextIndexBackChars(textPtr, srcPtr, charCount, dstPtr, type) */ static CONST char * -StartEnd(textPtr, string, indexPtr) - TkText *textPtr; /* Information about text widget. */ - CONST char *string; /* String to parse for additional info about +StartEnd( + TkText *textPtr, /* Information about text widget. */ + CONST char *string, /* String to parse for additional info about * modifier (count and units). Points to first * character of modifer word. */ - TkTextIndex *indexPtr; /* Index to modify based on string. */ + TkTextIndex *indexPtr) /* Index to modify based on string. */ { CONST char *p; size_t length; @@ -2274,7 +2270,6 @@ StartEnd(textPtr, string, indexPtr) segPtr->body.chars)); } firstChar = 0; - } else { } offset -= chSize; indexPtr->byteIndex -= chSize; @@ -2303,3 +2298,11 @@ StartEnd(textPtr, string, indexPtr) done: return p; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkTextMark.c b/generic/tkTextMark.c index e386c0a..d1b5b87 100644 --- a/generic/tkTextMark.c +++ b/generic/tkTextMark.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: tkTextMark.c,v 1.17 2007/01/18 23:20:37 nijtmans Exp $ + * RCS: @(#) $Id: tkTextMark.c,v 1.18 2007/02/22 13:56:33 dkf Exp $ */ #include "tkInt.h" @@ -47,10 +47,9 @@ static int MarkFindPrev(Tcl_Interp *interp, /* - * The following structures declare the "mark" segment types. - * There are actually two types for marks, one with left gravity - * and one with right gravity. They are identical except for - * their gravity property. + * The following structures declare the "mark" segment types. There are + * actually two types for marks, one with left gravity and one with right + * gravity. They are identical except for their gravity property. */ const Tk_SegType tkTextRightMarkType = { @@ -107,16 +106,13 @@ TkTextMarkCmd( Tcl_HashSearch search; TkTextIndex index; const Tk_SegType *newTypePtr; - int optionIndex; - static const char *markOptionStrings[] = { - "gravity", "names", "next", "previous", "set", - "unset", NULL + "gravity", "names", "next", "previous", "set", "unset", NULL }; enum markOptions { - MARK_GRAVITY, MARK_NAMES, MARK_NEXT, MARK_PREVIOUS, - MARK_SET, MARK_UNSET + MARK_GRAVITY, MARK_NAMES, MARK_NEXT, MARK_PREVIOUS, MARK_SET, + MARK_UNSET }; if (objc < 3) { @@ -128,7 +124,7 @@ TkTextMarkCmd( return TCL_ERROR; } - switch ((enum markOptions)optionIndex) { + switch ((enum markOptions) optionIndex) { case MARK_GRAVITY: { char c; int length; @@ -267,8 +263,7 @@ TkTextSetMark( Tcl_HashEntry *hPtr = NULL; TkTextSegment *markPtr; TkTextIndex insertIndex; - int isNew; - int widgetSpecific; + int isNew, widgetSpecific; if (!strcmp(name, "insert")) { widgetSpecific = 1; @@ -506,7 +501,6 @@ MarkCleanupProc( *-------------------------------------------------------------- */ - /*ARGSUSED*/ static int MarkLayoutProc( TkText *textPtr, /* Text widget being layed out. */ diff --git a/generic/tkTextTag.c b/generic/tkTextTag.c index 32fa3d8..c3552c8 100644 --- a/generic/tkTextTag.c +++ b/generic/tkTextTag.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkTextTag.c,v 1.24 2007/01/03 05:06:27 nijtmans Exp $ + * RCS: @(#) $Id: tkTextTag.c,v 1.25 2007/02/22 13:56:33 dkf Exp $ */ #include "default.h" @@ -31,10 +31,10 @@ static char *wrapStrings[] = { }; /* - * The 'TkTextTabStyle' enum in tkText.h is used to define a type for - * the -tabstyle option of the Text widget. These values are used as - * indices into the string table below. Tags are allowed an empty wrap - * value, but the widget as a whole is not. + * The 'TkTextTabStyle' enum in tkText.h is used to define a type for the + * -tabstyle option of the Text widget. These values are used as indices into + * the string table below. Tags are allowed an empty wrap value, but the + * widget as a whole is not. */ static char *tabStyleStrings[] = { @@ -133,20 +133,16 @@ TkTextTagCmd( * parsed this command enough to know that * objv[1] is "tag". */ { - int optionIndex; - static CONST char *tagOptionStrings[] = { - "add", "bind", "cget", "configure", "delete", "lower", - "names", "nextrange", "prevrange", "raise", "ranges", - "remove", NULL + "add", "bind", "cget", "configure", "delete", "lower", "names", + "nextrange", "prevrange", "raise", "ranges", "remove", NULL }; enum tagOptions { - TAG_ADD, TAG_BIND, TAG_CGET, TAG_CONFIGURE, TAG_DELETE, - TAG_LOWER, TAG_NAMES, TAG_NEXTRANGE, TAG_PREVRANGE, - TAG_RAISE, TAG_RANGES, TAG_REMOVE + TAG_ADD, TAG_BIND, TAG_CGET, TAG_CONFIGURE, TAG_DELETE, TAG_LOWER, + TAG_NAMES, TAG_NEXTRANGE, TAG_PREVRANGE, TAG_RAISE, TAG_RANGES, + TAG_REMOVE }; - - int i; + int optionIndex, i; register TkTextTag *tagPtr; TkTextIndex index1, index2; @@ -306,9 +302,8 @@ TkTextTagCmd( if (string[0] != '\0') { return TCL_ERROR; - } else { - Tcl_ResetResult(interp); } + Tcl_ResetResult(interp); } else { Tcl_SetResult(interp, (char *) command, TCL_STATIC); } @@ -332,10 +327,9 @@ TkTextTagCmd( tagPtr->optionTable, objv[4], textPtr->tkwin); if (objPtr == NULL) { return TCL_ERROR; - } else { - Tcl_SetObjResult(interp, objPtr); - return TCL_OK; } + Tcl_SetObjResult(interp, objPtr); + return TCL_OK; } break; case TAG_CONFIGURE: { @@ -354,10 +348,9 @@ TkTextTagCmd( if (objPtr == NULL) { return TCL_ERROR; - } else { - Tcl_SetObjResult(interp, objPtr); - return TCL_OK; } + Tcl_SetObjResult(interp, objPtr); + return TCL_OK; } else { int result = TCL_OK; @@ -594,8 +587,7 @@ TkTextTagCmd( * for all peers. */ - TkTextRedrawTag(textPtr->sharedTextPtr, NULL, NULL, - NULL, tagPtr, 1); + TkTextRedrawTag(textPtr->sharedTextPtr, NULL, NULL, NULL, tagPtr, 1); break; } case TAG_NAMES: { @@ -866,8 +858,7 @@ TkTextTagCmd( * for all peers. */ - TkTextRedrawTag(textPtr->sharedTextPtr, NULL, NULL, - NULL, tagPtr, 1); + TkTextRedrawTag(textPtr->sharedTextPtr, NULL, NULL, NULL, tagPtr, 1); break; } case TAG_RANGES: { @@ -953,10 +944,9 @@ TkTextCreateTag( *newTag = 0; } return textPtr->selTagPtr; - } else { - if (newTag != NULL) { - *newTag = 1; - } + } + if (newTag != NULL) { + *newTag = 1; } name = "sel"; } else { @@ -1138,8 +1128,7 @@ TkTextDeleteTag( * Update the tag priorities to reflect the deletion of this tag. */ - ChangeTagPriority(textPtr, tagPtr, - textPtr->sharedTextPtr->numTags-1); + ChangeTagPriority(textPtr, tagPtr, textPtr->sharedTextPtr->numTags-1); textPtr->sharedTextPtr->numTags -= 1; TkTextFreeTag(textPtr, tagPtr); } @@ -1265,8 +1254,7 @@ SortTags( *tagArrayPtr = tmp; } } else { - qsort((VOID *) tagArrayPtr, (unsigned) numTags, sizeof (TkTextTag *), - TagSortProc); + qsort(tagArrayPtr,(unsigned)numTags,sizeof(TkTextTag *),TagSortProc); } } @@ -1341,7 +1329,8 @@ ChangeTagPriority( } if (prio == tagPtr->priority) { return; - } else if (prio < tagPtr->priority) { + } + if (prio < tagPtr->priority) { low = prio; high = tagPtr->priority-1; delta = 1; @@ -1605,7 +1594,7 @@ TkTextPickCurrent( if (numNewTags > 0) { size = numNewTags * sizeof(TkTextTag *); copyArrayPtr = (TkTextTag **) ckalloc((unsigned) size); - memcpy((VOID *) copyArrayPtr, (VOID *) newArrayPtr, (size_t) size); + memcpy(copyArrayPtr, newArrayPtr, (size_t) size); for (i = 0; i < textPtr->numCurTags; i++) { for (j = 0; j < numNewTags; j++) { if (textPtr->curTagArrayPtr[i] == copyArrayPtr[j]) { @@ -1708,7 +1697,7 @@ TagBindEvent( */ if (numTags > NUM_BIND_TAGS) { - nameArrPtr = (CONST char**) ckalloc (numTags * sizeof(CONST char*)); + nameArrPtr = (CONST char **) ckalloc(numTags * sizeof(CONST char *)); } else { nameArrPtr = nameArray; } @@ -1737,7 +1726,7 @@ TagBindEvent( textPtr->tkwin, numTags, (ClientData *) nameArrPtr); if (numTags > NUM_BIND_TAGS) { - ckfree((char*)nameArrPtr); + ckfree((char *) nameArrPtr); } } diff --git a/generic/tkTextWind.c b/generic/tkTextWind.c index b85852a..62d8b72 100644 --- a/generic/tkTextWind.c +++ b/generic/tkTextWind.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkTextWind.c,v 1.20 2007/01/18 23:20:37 nijtmans Exp $ + * RCS: @(#) $Id: tkTextWind.c,v 1.21 2007/02/22 13:56:33 dkf Exp $ */ #include "tk.h" @@ -50,10 +50,9 @@ static TkTextSegment * EmbWinCleanupProc(TkTextSegment *segPtr, static void EmbWinCheckProc(TkTextSegment *segPtr, TkTextLine *linePtr); static void EmbWinBboxProc(TkText *textPtr, - TkTextDispChunk *chunkPtr, - int index, int y, int lineHeight, int baseline, - int *xPtr, int *yPtr, int *widthPtr, - int *heightPtr); + TkTextDispChunk *chunkPtr, int index, int y, + int lineHeight, int baseline, int *xPtr,int *yPtr, + int *widthPtr, int *heightPtr); static int EmbWinConfigure(TkText *textPtr, TkTextSegment *ewPtr, int objc, Tcl_Obj *const objv[]); static void EmbWinDelayedUnmap(ClientData clientData); @@ -61,9 +60,8 @@ static int EmbWinDeleteProc(TkTextSegment *segPtr, TkTextLine *linePtr, int treeGone); static int EmbWinLayoutProc(TkText *textPtr, TkTextIndex *indexPtr, TkTextSegment *segPtr, - int offset, int maxX, int maxChars, - int noCharsYet, TkWrapMode wrapMode, - TkTextDispChunk *chunkPtr); + int offset, int maxX, int maxChars,int noCharsYet, + TkWrapMode wrapMode, TkTextDispChunk *chunkPtr); static void EmbWinStructureProc(ClientData clientData, XEvent *eventPtr); static void EmbWinUndisplayProc(TkText *textPtr, @@ -146,14 +144,12 @@ TkTextWindowCmd( * objv[1] is "window". */ { int optionIndex; - static const char *windOptionStrings[] = { "cget", "configure", "create", "names", NULL }; enum windOptions { WIND_CGET, WIND_CONFIGURE, WIND_CREATE, WIND_NAMES }; - register TkTextSegment *ewPtr; if (objc < 3) { @@ -164,7 +160,7 @@ TkTextWindowCmd( "window option", 0, &optionIndex) != TCL_OK) { return TCL_ERROR; } - switch ((enum windOptions)optionIndex) { + switch ((enum windOptions) optionIndex) { case WIND_CGET: { TkTextIndex index; TkTextSegment *ewPtr; @@ -648,7 +644,7 @@ EmbWinLostSlaveProc( } loop->next = client->next; } - ckfree((char *)client); + ckfree((char *) client); index.tree = ewPtr->body.ew.sharedTextPtr->tree; index.linePtr = ewPtr->body.ew.linePtr; @@ -765,7 +761,7 @@ EmbWinDeleteProc( NULL); /* - * Free up all memory allocated + * Free up all memory allocated. */ ckfree((char *) ewPtr); @@ -853,13 +849,10 @@ EmbWinLayoutProc( if ((ewPtr->body.ew.tkwin == NULL) && (ewPtr->body.ew.create != NULL)) { int code, isNew; - Tcl_DString name; Tk_Window ancestor; Tcl_HashEntry *hPtr; - const char *before; - const char *string; - Tcl_DString buf; - Tcl_DString *dsPtr = NULL; + const char *before, *string; + Tcl_DString name, buf, *dsPtr = NULL; before = ewPtr->body.ew.create; @@ -1130,7 +1123,7 @@ TkTextEmbWinDisplayProc( */ EmbWinBboxProc(textPtr, chunkPtr, 0, screenY, lineHeight, baseline, - &lineX, &windowY, &width, &height); + &lineX, &windowY, &width, &height); windowX = lineX - chunkPtr->x + x; if (textPtr->tkwin == Tk_Parent(tkwin)) { @@ -1141,8 +1134,8 @@ TkTextEmbWinDisplayProc( } Tk_MapWindow(tkwin); } else { - Tk_MaintainGeometry(tkwin, textPtr->tkwin, - windowX, windowY, width, height); + Tk_MaintainGeometry(tkwin, textPtr->tkwin, windowX, windowY, + width, height); } /* @@ -1178,7 +1171,9 @@ EmbWinUndisplayProc( TkTextSegment *ewPtr = (TkTextSegment*) chunkPtr->clientData; TkTextEmbWindowClient *client = EmbWinGetClient(textPtr, ewPtr); - if (client == NULL) return; + if (client == NULL) { + return; + } client->chunkCount--; if (client->chunkCount == 0) { @@ -1236,7 +1231,7 @@ EmbWinBboxProc( * pixels. */ { Tk_Window tkwin; - TkTextSegment *ewPtr = (TkTextSegment*) chunkPtr->clientData; + TkTextSegment *ewPtr = (TkTextSegment *) chunkPtr->clientData; TkTextEmbWindowClient *client = EmbWinGetClient(textPtr, ewPtr); if (client == NULL) { @@ -1379,6 +1374,7 @@ EmbWinGetClient( TkTextSegment *ewPtr) /* Segment containing embedded window. */ { TkTextEmbWindowClient *client = ewPtr->body.ew.clients; + while (client != NULL) { if (client->textPtr == textPtr) { return client; |