OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [generic/] [tkTextMark.c] - Diff between revs 579 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/*
/*
 * tkTextMark.c --
 * tkTextMark.c --
 *
 *
 *      This file contains the procedure that implement marks for
 *      This file contains the procedure that implement marks for
 *      text widgets.
 *      text widgets.
 *
 *
 * Copyright (c) 1994 The Regents of the University of California.
 * Copyright (c) 1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 *
 *
 * See the file "license.terms" for information on usage and redistribution
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 *
 * RCS: @(#) $Id: tkTextMark.c,v 1.1.1.1 2002-01-16 10:25:53 markom Exp $
 * RCS: @(#) $Id: tkTextMark.c,v 1.1.1.1 2002-01-16 10:25:53 markom Exp $
 */
 */
 
 
#include "tkInt.h"
#include "tkInt.h"
#include "tkText.h"
#include "tkText.h"
#include "tkPort.h"
#include "tkPort.h"
 
 
/*
/*
 * Macro that determines the size of a mark segment:
 * Macro that determines the size of a mark segment:
 */
 */
 
 
#define MSEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \
#define MSEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \
        + sizeof(TkTextMark)))
        + sizeof(TkTextMark)))
 
 
/*
/*
 * Forward references for procedures defined in this file:
 * Forward references for procedures defined in this file:
 */
 */
 
 
static void             InsertUndisplayProc _ANSI_ARGS_((TkText *textPtr,
static void             InsertUndisplayProc _ANSI_ARGS_((TkText *textPtr,
                            TkTextDispChunk *chunkPtr));
                            TkTextDispChunk *chunkPtr));
static int              MarkDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr,
static int              MarkDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr,
                            TkTextLine *linePtr, int treeGone));
                            TkTextLine *linePtr, int treeGone));
static TkTextSegment *  MarkCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr,
static TkTextSegment *  MarkCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr,
                            TkTextLine *linePtr));
                            TkTextLine *linePtr));
static void             MarkCheckProc _ANSI_ARGS_((TkTextSegment *segPtr,
static void             MarkCheckProc _ANSI_ARGS_((TkTextSegment *segPtr,
                            TkTextLine *linePtr));
                            TkTextLine *linePtr));
static int              MarkLayoutProc _ANSI_ARGS_((TkText *textPtr,
static int              MarkLayoutProc _ANSI_ARGS_((TkText *textPtr,
                            TkTextIndex *indexPtr, TkTextSegment *segPtr,
                            TkTextIndex *indexPtr, TkTextSegment *segPtr,
                            int offset, int maxX, int maxChars,
                            int offset, int maxX, int maxChars,
                            int noCharsYet, Tk_Uid wrapMode,
                            int noCharsYet, Tk_Uid wrapMode,
                            TkTextDispChunk *chunkPtr));
                            TkTextDispChunk *chunkPtr));
static int              MarkFindNext _ANSI_ARGS_((Tcl_Interp *interp,
static int              MarkFindNext _ANSI_ARGS_((Tcl_Interp *interp,
                            TkText *textPtr, char *markName));
                            TkText *textPtr, char *markName));
static int              MarkFindPrev _ANSI_ARGS_((Tcl_Interp *interp,
static int              MarkFindPrev _ANSI_ARGS_((Tcl_Interp *interp,
                            TkText *textPtr, char *markName));
                            TkText *textPtr, char *markName));
 
 
 
 
/*
/*
 * The following structures declare the "mark" segment types.
 * The following structures declare the "mark" segment types.
 * There are actually two types for marks, one with left gravity
 * There are actually two types for marks, one with left gravity
 * and one with right gravity.  They are identical except for
 * and one with right gravity.  They are identical except for
 * their gravity property.
 * their gravity property.
 */
 */
 
 
Tk_SegType tkTextRightMarkType = {
Tk_SegType tkTextRightMarkType = {
    "mark",                                     /* name */
    "mark",                                     /* name */
    0,                                           /* leftGravity */
    0,                                           /* leftGravity */
    (Tk_SegSplitProc *) NULL,                   /* splitProc */
    (Tk_SegSplitProc *) NULL,                   /* splitProc */
    MarkDeleteProc,                             /* deleteProc */
    MarkDeleteProc,                             /* deleteProc */
    MarkCleanupProc,                            /* cleanupProc */
    MarkCleanupProc,                            /* cleanupProc */
    (Tk_SegLineChangeProc *) NULL,              /* lineChangeProc */
    (Tk_SegLineChangeProc *) NULL,              /* lineChangeProc */
    MarkLayoutProc,                             /* layoutProc */
    MarkLayoutProc,                             /* layoutProc */
    MarkCheckProc                               /* checkProc */
    MarkCheckProc                               /* checkProc */
};
};
 
 
Tk_SegType tkTextLeftMarkType = {
Tk_SegType tkTextLeftMarkType = {
    "mark",                                     /* name */
    "mark",                                     /* name */
    1,                                          /* leftGravity */
    1,                                          /* leftGravity */
    (Tk_SegSplitProc *) NULL,                   /* splitProc */
    (Tk_SegSplitProc *) NULL,                   /* splitProc */
    MarkDeleteProc,                             /* deleteProc */
    MarkDeleteProc,                             /* deleteProc */
    MarkCleanupProc,                            /* cleanupProc */
    MarkCleanupProc,                            /* cleanupProc */
    (Tk_SegLineChangeProc *) NULL,              /* lineChangeProc */
    (Tk_SegLineChangeProc *) NULL,              /* lineChangeProc */
    MarkLayoutProc,                             /* layoutProc */
    MarkLayoutProc,                             /* layoutProc */
    MarkCheckProc                               /* checkProc */
    MarkCheckProc                               /* checkProc */
};
};


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * TkTextMarkCmd --
 * TkTextMarkCmd --
 *
 *
 *      This procedure is invoked to process the "mark" options of
 *      This procedure is invoked to process the "mark" options of
 *      the widget command for text widgets. See the user documentation
 *      the widget command for text widgets. See the user documentation
 *      for details on what it does.
 *      for details on what it does.
 *
 *
 * Results:
 * Results:
 *      A standard Tcl result.
 *      A standard Tcl result.
 *
 *
 * Side effects:
 * Side effects:
 *      See the user documentation.
 *      See the user documentation.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
int
int
TkTextMarkCmd(textPtr, interp, argc, argv)
TkTextMarkCmd(textPtr, interp, argc, argv)
    register TkText *textPtr;   /* Information about text widget. */
    register TkText *textPtr;   /* Information about text widget. */
    Tcl_Interp *interp;         /* Current interpreter. */
    Tcl_Interp *interp;         /* Current interpreter. */
    int argc;                   /* Number of arguments. */
    int argc;                   /* Number of arguments. */
    char **argv;                /* Argument strings.  Someone else has already
    char **argv;                /* Argument strings.  Someone else has already
                                 * parsed this command enough to know that
                                 * parsed this command enough to know that
                                 * argv[1] is "mark". */
                                 * argv[1] is "mark". */
{
{
    int c, i;
    int c, i;
    size_t length;
    size_t length;
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *hPtr;
    TkTextSegment *markPtr;
    TkTextSegment *markPtr;
    Tcl_HashSearch search;
    Tcl_HashSearch search;
    TkTextIndex index;
    TkTextIndex index;
    Tk_SegType *newTypePtr;
    Tk_SegType *newTypePtr;
 
 
    if (argc < 3) {
    if (argc < 3) {
        Tcl_AppendResult(interp, "wrong # args: should be \"",
        Tcl_AppendResult(interp, "wrong # args: should be \"",
                argv[0], " mark option ?arg arg ...?\"", (char *) NULL);
                argv[0], " mark option ?arg arg ...?\"", (char *) NULL);
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    c = argv[2][0];
    c = argv[2][0];
    length = strlen(argv[2]);
    length = strlen(argv[2]);
    if ((c == 'g') && (strncmp(argv[2], "gravity", length) == 0)) {
    if ((c == 'g') && (strncmp(argv[2], "gravity", length) == 0)) {
        if (argc < 4 || argc > 5) {
        if (argc < 4 || argc > 5) {
            Tcl_AppendResult(interp, "wrong # args: should be \"",
            Tcl_AppendResult(interp, "wrong # args: should be \"",
                    argv[0], " mark gravity markName ?gravity?\"",
                    argv[0], " mark gravity markName ?gravity?\"",
                    (char *) NULL);
                    (char *) NULL);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        hPtr = Tcl_FindHashEntry(&textPtr->markTable, argv[3]);
        hPtr = Tcl_FindHashEntry(&textPtr->markTable, argv[3]);
        if (hPtr == NULL) {
        if (hPtr == NULL) {
            Tcl_AppendResult(interp, "there is no mark named \"",
            Tcl_AppendResult(interp, "there is no mark named \"",
                    argv[3], "\"", (char *) NULL);
                    argv[3], "\"", (char *) NULL);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
        markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
        if (argc == 4) {
        if (argc == 4) {
            if (markPtr->typePtr == &tkTextRightMarkType) {
            if (markPtr->typePtr == &tkTextRightMarkType) {
                interp->result = "right";
                interp->result = "right";
            } else {
            } else {
                interp->result = "left";
                interp->result = "left";
            }
            }
            return TCL_OK;
            return TCL_OK;
        }
        }
        length = strlen(argv[4]);
        length = strlen(argv[4]);
        c = argv[4][0];
        c = argv[4][0];
        if ((c == 'l') && (strncmp(argv[4], "left", length) == 0)) {
        if ((c == 'l') && (strncmp(argv[4], "left", length) == 0)) {
            newTypePtr = &tkTextLeftMarkType;
            newTypePtr = &tkTextLeftMarkType;
        } else if ((c == 'r') && (strncmp(argv[4], "right", length) == 0)) {
        } else if ((c == 'r') && (strncmp(argv[4], "right", length) == 0)) {
            newTypePtr = &tkTextRightMarkType;
            newTypePtr = &tkTextRightMarkType;
        } else {
        } else {
            Tcl_AppendResult(interp, "bad mark gravity \"",
            Tcl_AppendResult(interp, "bad mark gravity \"",
                    argv[4], "\": must be left or right", (char *) NULL);
                    argv[4], "\": must be left or right", (char *) NULL);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        TkTextMarkSegToIndex(textPtr, markPtr, &index);
        TkTextMarkSegToIndex(textPtr, markPtr, &index);
        TkBTreeUnlinkSegment(textPtr->tree, markPtr,
        TkBTreeUnlinkSegment(textPtr->tree, markPtr,
                markPtr->body.mark.linePtr);
                markPtr->body.mark.linePtr);
        markPtr->typePtr = newTypePtr;
        markPtr->typePtr = newTypePtr;
        TkBTreeLinkSegment(markPtr, &index);
        TkBTreeLinkSegment(markPtr, &index);
    } else if ((c == 'n') && (strncmp(argv[2], "names", length) == 0)) {
    } else if ((c == 'n') && (strncmp(argv[2], "names", length) == 0)) {
        if (argc != 3) {
        if (argc != 3) {
            Tcl_AppendResult(interp, "wrong # args: should be \"",
            Tcl_AppendResult(interp, "wrong # args: should be \"",
                    argv[0], " mark names\"", (char *) NULL);
                    argv[0], " mark names\"", (char *) NULL);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        for (hPtr = Tcl_FirstHashEntry(&textPtr->markTable, &search);
        for (hPtr = Tcl_FirstHashEntry(&textPtr->markTable, &search);
                hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
                hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
            Tcl_AppendElement(interp,
            Tcl_AppendElement(interp,
                    Tcl_GetHashKey(&textPtr->markTable, hPtr));
                    Tcl_GetHashKey(&textPtr->markTable, hPtr));
        }
        }
    } else if ((c == 'n') && (strncmp(argv[2], "next", length) == 0)) {
    } else if ((c == 'n') && (strncmp(argv[2], "next", length) == 0)) {
        if (argc != 4) {
        if (argc != 4) {
            Tcl_AppendResult(interp, "wrong # args: should be \"",
            Tcl_AppendResult(interp, "wrong # args: should be \"",
                    argv[0], " mark next index\"", (char *) NULL);
                    argv[0], " mark next index\"", (char *) NULL);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        return MarkFindNext(interp, textPtr, argv[3]);
        return MarkFindNext(interp, textPtr, argv[3]);
    } else if ((c == 'p') && (strncmp(argv[2], "previous", length) == 0)) {
    } else if ((c == 'p') && (strncmp(argv[2], "previous", length) == 0)) {
        if (argc != 4) {
        if (argc != 4) {
            Tcl_AppendResult(interp, "wrong # args: should be \"",
            Tcl_AppendResult(interp, "wrong # args: should be \"",
                    argv[0], " mark previous index\"", (char *) NULL);
                    argv[0], " mark previous index\"", (char *) NULL);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        return MarkFindPrev(interp, textPtr, argv[3]);
        return MarkFindPrev(interp, textPtr, argv[3]);
    } else if ((c == 's') && (strncmp(argv[2], "set", length) == 0)) {
    } else if ((c == 's') && (strncmp(argv[2], "set", length) == 0)) {
        if (argc != 5) {
        if (argc != 5) {
            Tcl_AppendResult(interp, "wrong # args: should be \"",
            Tcl_AppendResult(interp, "wrong # args: should be \"",
                    argv[0], " mark set markName index\"", (char *) NULL);
                    argv[0], " mark set markName index\"", (char *) NULL);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        if (TkTextGetIndex(interp, textPtr, argv[4], &index) != TCL_OK) {
        if (TkTextGetIndex(interp, textPtr, argv[4], &index) != TCL_OK) {
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        TkTextSetMark(textPtr, argv[3], &index);
        TkTextSetMark(textPtr, argv[3], &index);
    } else if ((c == 'u') && (strncmp(argv[2], "unset", length) == 0)) {
    } else if ((c == 'u') && (strncmp(argv[2], "unset", length) == 0)) {
        for (i = 3; i < argc; i++) {
        for (i = 3; i < argc; i++) {
            hPtr = Tcl_FindHashEntry(&textPtr->markTable, argv[i]);
            hPtr = Tcl_FindHashEntry(&textPtr->markTable, argv[i]);
            if (hPtr != NULL) {
            if (hPtr != NULL) {
                markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
                markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
                if ((markPtr == textPtr->insertMarkPtr)
                if ((markPtr == textPtr->insertMarkPtr)
                        || (markPtr == textPtr->currentMarkPtr)) {
                        || (markPtr == textPtr->currentMarkPtr)) {
                    continue;
                    continue;
                }
                }
                TkBTreeUnlinkSegment(textPtr->tree, markPtr,
                TkBTreeUnlinkSegment(textPtr->tree, markPtr,
                        markPtr->body.mark.linePtr);
                        markPtr->body.mark.linePtr);
                Tcl_DeleteHashEntry(hPtr);
                Tcl_DeleteHashEntry(hPtr);
                ckfree((char *) markPtr);
                ckfree((char *) markPtr);
            }
            }
        }
        }
    } else {
    } else {
        Tcl_AppendResult(interp, "bad mark option \"", argv[2],
        Tcl_AppendResult(interp, "bad mark option \"", argv[2],
                "\": must be gravity, names, next, previous, set, or unset",
                "\": must be gravity, names, next, previous, set, or unset",
                (char *) NULL);
                (char *) NULL);
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkTextSetMark --
 * TkTextSetMark --
 *
 *
 *      Set a mark to a particular position, creating a new mark if
 *      Set a mark to a particular position, creating a new mark if
 *      one doesn't already exist.
 *      one doesn't already exist.
 *
 *
 * Results:
 * Results:
 *      The return value is a pointer to the mark that was just set.
 *      The return value is a pointer to the mark that was just set.
 *
 *
 * Side effects:
 * Side effects:
 *      A new mark is created, or an existing mark is moved.
 *      A new mark is created, or an existing mark is moved.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
TkTextSegment *
TkTextSegment *
TkTextSetMark(textPtr, name, indexPtr)
TkTextSetMark(textPtr, name, indexPtr)
    TkText *textPtr;            /* Text widget in which to create mark. */
    TkText *textPtr;            /* Text widget in which to create mark. */
    char *name;                 /* Name of mark to set. */
    char *name;                 /* Name of mark to set. */
    TkTextIndex *indexPtr;      /* Where to set mark. */
    TkTextIndex *indexPtr;      /* Where to set mark. */
{
{
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *hPtr;
    TkTextSegment *markPtr;
    TkTextSegment *markPtr;
    TkTextIndex insertIndex;
    TkTextIndex insertIndex;
    int new;
    int new;
 
 
    hPtr = Tcl_CreateHashEntry(&textPtr->markTable, name, &new);
    hPtr = Tcl_CreateHashEntry(&textPtr->markTable, name, &new);
    markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
    markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
    if (!new) {
    if (!new) {
        /*
        /*
         * If this is the insertion point that's being moved, be sure
         * If this is the insertion point that's being moved, be sure
         * to force a display update at the old position.  Also, don't
         * to force a display update at the old position.  Also, don't
         * let the insertion cursor be after the final newline of the
         * let the insertion cursor be after the final newline of the
         * file.
         * file.
         */
         */
 
 
        if (markPtr == textPtr->insertMarkPtr) {
        if (markPtr == textPtr->insertMarkPtr) {
            TkTextIndex index, index2;
            TkTextIndex index, index2;
            TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index);
            TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index);
            TkTextIndexForwChars(&index, 1, &index2);
            TkTextIndexForwChars(&index, 1, &index2);
            TkTextChanged(textPtr, &index, &index2);
            TkTextChanged(textPtr, &index, &index2);
            if (TkBTreeLineIndex(indexPtr->linePtr)
            if (TkBTreeLineIndex(indexPtr->linePtr)
                    == TkBTreeNumLines(textPtr->tree))  {
                    == TkBTreeNumLines(textPtr->tree))  {
                TkTextIndexBackChars(indexPtr, 1, &insertIndex);
                TkTextIndexBackChars(indexPtr, 1, &insertIndex);
                indexPtr = &insertIndex;
                indexPtr = &insertIndex;
            }
            }
        }
        }
        TkBTreeUnlinkSegment(textPtr->tree, markPtr,
        TkBTreeUnlinkSegment(textPtr->tree, markPtr,
                markPtr->body.mark.linePtr);
                markPtr->body.mark.linePtr);
    } else {
    } else {
        markPtr = (TkTextSegment *) ckalloc(MSEG_SIZE);
        markPtr = (TkTextSegment *) ckalloc(MSEG_SIZE);
        markPtr->typePtr = &tkTextRightMarkType;
        markPtr->typePtr = &tkTextRightMarkType;
        markPtr->size = 0;
        markPtr->size = 0;
        markPtr->body.mark.textPtr = textPtr;
        markPtr->body.mark.textPtr = textPtr;
        markPtr->body.mark.linePtr = indexPtr->linePtr;
        markPtr->body.mark.linePtr = indexPtr->linePtr;
        markPtr->body.mark.hPtr = hPtr;
        markPtr->body.mark.hPtr = hPtr;
        Tcl_SetHashValue(hPtr, markPtr);
        Tcl_SetHashValue(hPtr, markPtr);
    }
    }
    TkBTreeLinkSegment(markPtr, indexPtr);
    TkBTreeLinkSegment(markPtr, indexPtr);
 
 
    /*
    /*
     * If the mark is the insertion cursor, then update the screen at the
     * If the mark is the insertion cursor, then update the screen at the
     * mark's new location.
     * mark's new location.
     */
     */
 
 
    if (markPtr == textPtr->insertMarkPtr) {
    if (markPtr == textPtr->insertMarkPtr) {
        TkTextIndex index2;
        TkTextIndex index2;
 
 
        TkTextIndexForwChars(indexPtr, 1, &index2);
        TkTextIndexForwChars(indexPtr, 1, &index2);
        TkTextChanged(textPtr, indexPtr, &index2);
        TkTextChanged(textPtr, indexPtr, &index2);
    }
    }
    return markPtr;
    return markPtr;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * TkTextMarkSegToIndex --
 * TkTextMarkSegToIndex --
 *
 *
 *      Given a segment that is a mark, create an index that
 *      Given a segment that is a mark, create an index that
 *      refers to the next text character (or other text segment
 *      refers to the next text character (or other text segment
 *      with non-zero size) after the mark.
 *      with non-zero size) after the mark.
 *
 *
 * Results:
 * Results:
 *      *IndexPtr is filled in with index information.
 *      *IndexPtr is filled in with index information.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
void
void
TkTextMarkSegToIndex(textPtr, markPtr, indexPtr)
TkTextMarkSegToIndex(textPtr, markPtr, indexPtr)
    TkText *textPtr;            /* Text widget containing mark. */
    TkText *textPtr;            /* Text widget containing mark. */
    TkTextSegment *markPtr;     /* Mark segment. */
    TkTextSegment *markPtr;     /* Mark segment. */
    TkTextIndex *indexPtr;      /* Index information gets stored here.  */
    TkTextIndex *indexPtr;      /* Index information gets stored here.  */
{
{
    TkTextSegment *segPtr;
    TkTextSegment *segPtr;
 
 
    indexPtr->tree = textPtr->tree;
    indexPtr->tree = textPtr->tree;
    indexPtr->linePtr = markPtr->body.mark.linePtr;
    indexPtr->linePtr = markPtr->body.mark.linePtr;
    indexPtr->charIndex = 0;
    indexPtr->charIndex = 0;
    for (segPtr = indexPtr->linePtr->segPtr; segPtr != markPtr;
    for (segPtr = indexPtr->linePtr->segPtr; segPtr != markPtr;
            segPtr = segPtr->nextPtr) {
            segPtr = segPtr->nextPtr) {
        indexPtr->charIndex += segPtr->size;
        indexPtr->charIndex += segPtr->size;
    }
    }
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * TkTextMarkNameToIndex --
 * TkTextMarkNameToIndex --
 *
 *
 *      Given the name of a mark, return an index corresponding
 *      Given the name of a mark, return an index corresponding
 *      to the mark name.
 *      to the mark name.
 *
 *
 * Results:
 * Results:
 *      The return value is TCL_OK if "name" exists as a mark in
 *      The return value is TCL_OK if "name" exists as a mark in
 *      the text widget.  In this case *indexPtr is filled in with
 *      the text widget.  In this case *indexPtr is filled in with
 *      the next segment whose after the mark whose size is
 *      the next segment whose after the mark whose size is
 *      non-zero.  TCL_ERROR is returned if the mark doesn't exist
 *      non-zero.  TCL_ERROR is returned if the mark doesn't exist
 *      in the text widget.
 *      in the text widget.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
int
int
TkTextMarkNameToIndex(textPtr, name, indexPtr)
TkTextMarkNameToIndex(textPtr, name, indexPtr)
    TkText *textPtr;            /* Text widget containing mark. */
    TkText *textPtr;            /* Text widget containing mark. */
    char *name;                 /* Name of mark. */
    char *name;                 /* Name of mark. */
    TkTextIndex *indexPtr;      /* Index information gets stored here. */
    TkTextIndex *indexPtr;      /* Index information gets stored here. */
{
{
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *hPtr;
 
 
    hPtr = Tcl_FindHashEntry(&textPtr->markTable, name);
    hPtr = Tcl_FindHashEntry(&textPtr->markTable, name);
    if (hPtr == NULL) {
    if (hPtr == NULL) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    TkTextMarkSegToIndex(textPtr, (TkTextSegment *) Tcl_GetHashValue(hPtr),
    TkTextMarkSegToIndex(textPtr, (TkTextSegment *) Tcl_GetHashValue(hPtr),
            indexPtr);
            indexPtr);
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * MarkDeleteProc --
 * MarkDeleteProc --
 *
 *
 *      This procedure is invoked by the text B-tree code whenever
 *      This procedure is invoked by the text B-tree code whenever
 *      a mark lies in a range of characters being deleted.
 *      a mark lies in a range of characters being deleted.
 *
 *
 * Results:
 * Results:
 *      Returns 1 to indicate that deletion has been rejected.
 *      Returns 1 to indicate that deletion has been rejected.
 *
 *
 * Side effects:
 * Side effects:
 *      None (even if the whole tree is being deleted we don't
 *      None (even if the whole tree is being deleted we don't
 *      free up the mark;  it will be done elsewhere).
 *      free up the mark;  it will be done elsewhere).
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
        /* ARGSUSED */
        /* ARGSUSED */
static int
static int
MarkDeleteProc(segPtr, linePtr, treeGone)
MarkDeleteProc(segPtr, linePtr, treeGone)
    TkTextSegment *segPtr;              /* Segment being deleted. */
    TkTextSegment *segPtr;              /* Segment being deleted. */
    TkTextLine *linePtr;                /* Line containing segment. */
    TkTextLine *linePtr;                /* Line containing segment. */
    int treeGone;                       /* Non-zero means the entire tree is
    int treeGone;                       /* Non-zero means the entire tree is
                                         * being deleted, so everything must
                                         * being deleted, so everything must
                                         * get cleaned up. */
                                         * get cleaned up. */
{
{
    return 1;
    return 1;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * MarkCleanupProc --
 * MarkCleanupProc --
 *
 *
 *      This procedure is invoked by the B-tree code whenever a
 *      This procedure is invoked by the B-tree code whenever a
 *      mark segment is moved from one line to another.
 *      mark segment is moved from one line to another.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      The linePtr field of the segment gets updated.
 *      The linePtr field of the segment gets updated.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
static TkTextSegment *
static TkTextSegment *
MarkCleanupProc(markPtr, linePtr)
MarkCleanupProc(markPtr, linePtr)
    TkTextSegment *markPtr;             /* Mark segment that's being moved. */
    TkTextSegment *markPtr;             /* Mark segment that's being moved. */
    TkTextLine *linePtr;                /* Line that now contains segment. */
    TkTextLine *linePtr;                /* Line that now contains segment. */
{
{
    markPtr->body.mark.linePtr = linePtr;
    markPtr->body.mark.linePtr = linePtr;
    return markPtr;
    return markPtr;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * MarkLayoutProc --
 * MarkLayoutProc --
 *
 *
 *      This procedure is the "layoutProc" for mark segments.
 *      This procedure is the "layoutProc" for mark segments.
 *
 *
 * Results:
 * Results:
 *      If the mark isn't the insertion cursor then the return
 *      If the mark isn't the insertion cursor then the return
 *      value is -1 to indicate that this segment shouldn't be
 *      value is -1 to indicate that this segment shouldn't be
 *      displayed.  If the mark is the insertion character then
 *      displayed.  If the mark is the insertion character then
 *      1 is returned and the chunkPtr structure is filled in.
 *      1 is returned and the chunkPtr structure is filled in.
 *
 *
 * Side effects:
 * Side effects:
 *      None, except for filling in chunkPtr.
 *      None, except for filling in chunkPtr.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
        /*ARGSUSED*/
        /*ARGSUSED*/
static int
static int
MarkLayoutProc(textPtr, indexPtr, segPtr, offset, maxX, maxChars,
MarkLayoutProc(textPtr, indexPtr, segPtr, offset, maxX, maxChars,
        noCharsYet, wrapMode, chunkPtr)
        noCharsYet, wrapMode, chunkPtr)
    TkText *textPtr;            /* Text widget being layed out. */
    TkText *textPtr;            /* Text widget being layed out. */
    TkTextIndex *indexPtr;      /* Identifies first character in chunk. */
    TkTextIndex *indexPtr;      /* Identifies first character in chunk. */
    TkTextSegment *segPtr;      /* Segment corresponding to indexPtr. */
    TkTextSegment *segPtr;      /* Segment corresponding to indexPtr. */
    int offset;                 /* Offset within segPtr corresponding to
    int offset;                 /* Offset within segPtr corresponding to
                                 * indexPtr (always 0). */
                                 * indexPtr (always 0). */
    int maxX;                   /* Chunk must not occupy pixels at this
    int maxX;                   /* Chunk must not occupy pixels at this
                                 * position or higher. */
                                 * position or higher. */
    int maxChars;               /* Chunk must not include more than this
    int maxChars;               /* Chunk must not include more than this
                                 * many characters. */
                                 * many characters. */
    int noCharsYet;             /* Non-zero means no characters have been
    int noCharsYet;             /* Non-zero means no characters have been
                                 * assigned to this line yet. */
                                 * assigned to this line yet. */
    Tk_Uid wrapMode;            /* Not used. */
    Tk_Uid wrapMode;            /* Not used. */
    register TkTextDispChunk *chunkPtr;
    register TkTextDispChunk *chunkPtr;
                                /* Structure to fill in with information
                                /* Structure to fill in with information
                                 * about this chunk.  The x field has already
                                 * about this chunk.  The x field has already
                                 * been set by the caller. */
                                 * been set by the caller. */
{
{
    if (segPtr != textPtr->insertMarkPtr) {
    if (segPtr != textPtr->insertMarkPtr) {
        return -1;
        return -1;
    }
    }
 
 
    chunkPtr->displayProc = TkTextInsertDisplayProc;
    chunkPtr->displayProc = TkTextInsertDisplayProc;
    chunkPtr->undisplayProc = InsertUndisplayProc;
    chunkPtr->undisplayProc = InsertUndisplayProc;
    chunkPtr->measureProc = (Tk_ChunkMeasureProc *) NULL;
    chunkPtr->measureProc = (Tk_ChunkMeasureProc *) NULL;
    chunkPtr->bboxProc = (Tk_ChunkBboxProc *) NULL;
    chunkPtr->bboxProc = (Tk_ChunkBboxProc *) NULL;
    chunkPtr->numChars = 0;
    chunkPtr->numChars = 0;
    chunkPtr->minAscent = 0;
    chunkPtr->minAscent = 0;
    chunkPtr->minDescent = 0;
    chunkPtr->minDescent = 0;
    chunkPtr->minHeight = 0;
    chunkPtr->minHeight = 0;
    chunkPtr->width = 0;
    chunkPtr->width = 0;
 
 
    /*
    /*
     * Note: can't break a line after the insertion cursor:  this
     * Note: can't break a line after the insertion cursor:  this
     * prevents the insertion cursor from being stranded at the end
     * prevents the insertion cursor from being stranded at the end
     * of a line.
     * of a line.
     */
     */
 
 
    chunkPtr->breakIndex = -1;
    chunkPtr->breakIndex = -1;
    chunkPtr->clientData = (ClientData) textPtr;
    chunkPtr->clientData = (ClientData) textPtr;
    return 1;
    return 1;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * TkTextInsertDisplayProc --
 * TkTextInsertDisplayProc --
 *
 *
 *      This procedure is called to display the insertion
 *      This procedure is called to display the insertion
 *      cursor.
 *      cursor.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Graphics are drawn.
 *      Graphics are drawn.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
        /* ARGSUSED */
        /* ARGSUSED */
void
void
TkTextInsertDisplayProc(chunkPtr, x, y, height, baseline, display, dst, screenY)
TkTextInsertDisplayProc(chunkPtr, x, y, height, baseline, display, dst, screenY)
    TkTextDispChunk *chunkPtr;          /* Chunk that is to be drawn. */
    TkTextDispChunk *chunkPtr;          /* Chunk that is to be drawn. */
    int x;                              /* X-position in dst at which to
    int x;                              /* X-position in dst at which to
                                         * draw this chunk (may differ from
                                         * draw this chunk (may differ from
                                         * the x-position in the chunk because
                                         * the x-position in the chunk because
                                         * of scrolling). */
                                         * of scrolling). */
    int y;                              /* Y-position at which to draw this
    int y;                              /* Y-position at which to draw this
                                         * chunk in dst (x-position is in
                                         * chunk in dst (x-position is in
                                         * the chunk itself). */
                                         * the chunk itself). */
    int height;                         /* Total height of line. */
    int height;                         /* Total height of line. */
    int baseline;                       /* Offset of baseline from y. */
    int baseline;                       /* Offset of baseline from y. */
    Display *display;                   /* Display to use for drawing. */
    Display *display;                   /* Display to use for drawing. */
    Drawable dst;                       /* Pixmap or window in which to draw
    Drawable dst;                       /* Pixmap or window in which to draw
                                         * chunk. */
                                         * chunk. */
    int screenY;                        /* Y-coordinate in text window that
    int screenY;                        /* Y-coordinate in text window that
                                         * corresponds to y. */
                                         * corresponds to y. */
{
{
    TkText *textPtr = (TkText *) chunkPtr->clientData;
    TkText *textPtr = (TkText *) chunkPtr->clientData;
    int halfWidth = textPtr->insertWidth/2;
    int halfWidth = textPtr->insertWidth/2;
 
 
    if ((x + halfWidth) < 0) {
    if ((x + halfWidth) < 0) {
        /*
        /*
         * The insertion cursor is off-screen.  Just return.
         * The insertion cursor is off-screen.  Just return.
         */
         */
 
 
        return;
        return;
    }
    }
 
 
    /*
    /*
     * As a special hack to keep the cursor visible on mono displays
     * As a special hack to keep the cursor visible on mono displays
     * (or anywhere else that the selection and insertion cursors
     * (or anywhere else that the selection and insertion cursors
     * have the same color) write the default background in the cursor
     * have the same color) write the default background in the cursor
     * area (instead of nothing) when the cursor isn't on.  Otherwise
     * area (instead of nothing) when the cursor isn't on.  Otherwise
     * the selection might hide the cursor.
     * the selection might hide the cursor.
     */
     */
 
 
    if (textPtr->flags & INSERT_ON) {
    if (textPtr->flags & INSERT_ON) {
        Tk_Fill3DRectangle(textPtr->tkwin, dst, textPtr->insertBorder,
        Tk_Fill3DRectangle(textPtr->tkwin, dst, textPtr->insertBorder,
                x - textPtr->insertWidth/2, y, textPtr->insertWidth,
                x - textPtr->insertWidth/2, y, textPtr->insertWidth,
                height, textPtr->insertBorderWidth, TK_RELIEF_RAISED);
                height, textPtr->insertBorderWidth, TK_RELIEF_RAISED);
    } else if (textPtr->selBorder == textPtr->insertBorder) {
    } else if (textPtr->selBorder == textPtr->insertBorder) {
        Tk_Fill3DRectangle(textPtr->tkwin, dst, textPtr->border,
        Tk_Fill3DRectangle(textPtr->tkwin, dst, textPtr->border,
                x - textPtr->insertWidth/2, y, textPtr->insertWidth,
                x - textPtr->insertWidth/2, y, textPtr->insertWidth,
                height, 0, TK_RELIEF_FLAT);
                height, 0, TK_RELIEF_FLAT);
    }
    }
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * InsertUndisplayProc --
 * InsertUndisplayProc --
 *
 *
 *      This procedure is called when the insertion cursor is no
 *      This procedure is called when the insertion cursor is no
 *      longer at a visible point on the display.  It does nothing
 *      longer at a visible point on the display.  It does nothing
 *      right now.
 *      right now.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
        /* ARGSUSED */
        /* ARGSUSED */
static void
static void
InsertUndisplayProc(textPtr, chunkPtr)
InsertUndisplayProc(textPtr, chunkPtr)
    TkText *textPtr;                    /* Overall information about text
    TkText *textPtr;                    /* Overall information about text
                                         * widget. */
                                         * widget. */
    TkTextDispChunk *chunkPtr;          /* Chunk that is about to be freed. */
    TkTextDispChunk *chunkPtr;          /* Chunk that is about to be freed. */
{
{
    return;
    return;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * MarkCheckProc --
 * MarkCheckProc --
 *
 *
 *      This procedure is invoked by the B-tree code to perform
 *      This procedure is invoked by the B-tree code to perform
 *      consistency checks on mark segments.
 *      consistency checks on mark segments.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      The procedure panics if it detects anything wrong with
 *      The procedure panics if it detects anything wrong with
 *      the mark.
 *      the mark.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
static void
static void
MarkCheckProc(markPtr, linePtr)
MarkCheckProc(markPtr, linePtr)
    TkTextSegment *markPtr;             /* Segment to check. */
    TkTextSegment *markPtr;             /* Segment to check. */
    TkTextLine *linePtr;                /* Line containing segment. */
    TkTextLine *linePtr;                /* Line containing segment. */
{
{
    Tcl_HashSearch search;
    Tcl_HashSearch search;
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *hPtr;
 
 
    if (markPtr->body.mark.linePtr != linePtr) {
    if (markPtr->body.mark.linePtr != linePtr) {
        panic("MarkCheckProc: markPtr->body.mark.linePtr bogus");
        panic("MarkCheckProc: markPtr->body.mark.linePtr bogus");
    }
    }
 
 
    /*
    /*
     * Make sure that the mark is still present in the text's mark
     * Make sure that the mark is still present in the text's mark
     * hash table.
     * hash table.
     */
     */
 
 
    for (hPtr = Tcl_FirstHashEntry(&markPtr->body.mark.textPtr->markTable,
    for (hPtr = Tcl_FirstHashEntry(&markPtr->body.mark.textPtr->markTable,
            &search); hPtr != markPtr->body.mark.hPtr;
            &search); hPtr != markPtr->body.mark.hPtr;
            hPtr = Tcl_NextHashEntry(&search)) {
            hPtr = Tcl_NextHashEntry(&search)) {
        if (hPtr == NULL) {
        if (hPtr == NULL) {
            panic("MarkCheckProc couldn't find hash table entry for mark");
            panic("MarkCheckProc couldn't find hash table entry for mark");
        }
        }
    }
    }
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * MarkFindNext --
 * MarkFindNext --
 *
 *
 *      This procedure searches forward for the next mark.
 *      This procedure searches forward for the next mark.
 *
 *
 * Results:
 * Results:
 *      A standard Tcl result, which is a mark name or an empty string.
 *      A standard Tcl result, which is a mark name or an empty string.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
static int
static int
MarkFindNext(interp, textPtr, string)
MarkFindNext(interp, textPtr, string)
    Tcl_Interp *interp;                 /* For error reporting */
    Tcl_Interp *interp;                 /* For error reporting */
    TkText *textPtr;                    /* The widget */
    TkText *textPtr;                    /* The widget */
    char *string;                       /* The starting index or mark name */
    char *string;                       /* The starting index or mark name */
{
{
    TkTextIndex index;
    TkTextIndex index;
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *hPtr;
    register TkTextSegment *segPtr;
    register TkTextSegment *segPtr;
    int offset;
    int offset;
 
 
 
 
    hPtr = Tcl_FindHashEntry(&textPtr->markTable, string);
    hPtr = Tcl_FindHashEntry(&textPtr->markTable, string);
    if (hPtr != NULL) {
    if (hPtr != NULL) {
        /*
        /*
         * If given a mark name, return the next mark in the list of
         * If given a mark name, return the next mark in the list of
         * segments, even if it happens to be at the same character position.
         * segments, even if it happens to be at the same character position.
         */
         */
        segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
        segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
        TkTextMarkSegToIndex(textPtr, segPtr, &index);
        TkTextMarkSegToIndex(textPtr, segPtr, &index);
        segPtr = segPtr->nextPtr;
        segPtr = segPtr->nextPtr;
    } else {
    } else {
        /*
        /*
         * For non-mark name indices we want to return any marks that
         * For non-mark name indices we want to return any marks that
         * are right at the index.
         * are right at the index.
         */
         */
        if (TkTextGetIndex(interp, textPtr, string, &index) != TCL_OK) {
        if (TkTextGetIndex(interp, textPtr, string, &index) != TCL_OK) {
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        for (offset = 0, segPtr = index.linePtr->segPtr;
        for (offset = 0, segPtr = index.linePtr->segPtr;
                segPtr != NULL && offset < index.charIndex;
                segPtr != NULL && offset < index.charIndex;
                offset += segPtr->size, segPtr = segPtr->nextPtr) {
                offset += segPtr->size, segPtr = segPtr->nextPtr) {
            /* Empty loop body */ ;
            /* Empty loop body */ ;
        }
        }
    }
    }
    while (1) {
    while (1) {
        /*
        /*
         * segPtr points at the first possible candidate,
         * segPtr points at the first possible candidate,
         * or NULL if we ran off the end of the line.
         * or NULL if we ran off the end of the line.
         */
         */
        for ( ; segPtr != NULL ; segPtr = segPtr->nextPtr) {
        for ( ; segPtr != NULL ; segPtr = segPtr->nextPtr) {
            if (segPtr->typePtr == &tkTextRightMarkType ||
            if (segPtr->typePtr == &tkTextRightMarkType ||
                    segPtr->typePtr == &tkTextLeftMarkType) {
                    segPtr->typePtr == &tkTextLeftMarkType) {
                Tcl_SetResult(interp,
                Tcl_SetResult(interp,
                    Tcl_GetHashKey(&textPtr->markTable, segPtr->body.mark.hPtr),
                    Tcl_GetHashKey(&textPtr->markTable, segPtr->body.mark.hPtr),
                    TCL_STATIC);
                    TCL_STATIC);
                return TCL_OK;
                return TCL_OK;
            }
            }
        }
        }
        index.linePtr = TkBTreeNextLine(index.linePtr);
        index.linePtr = TkBTreeNextLine(index.linePtr);
        if (index.linePtr == (TkTextLine *) NULL) {
        if (index.linePtr == (TkTextLine *) NULL) {
            return TCL_OK;
            return TCL_OK;
        }
        }
        index.charIndex = 0;
        index.charIndex = 0;
        segPtr = index.linePtr->segPtr;
        segPtr = index.linePtr->segPtr;
    }
    }
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * MarkFindPrev --
 * MarkFindPrev --
 *
 *
 *      This procedure searches backwards for the previous mark.
 *      This procedure searches backwards for the previous mark.
 *
 *
 * Results:
 * Results:
 *      A standard Tcl result, which is a mark name or an empty string.
 *      A standard Tcl result, which is a mark name or an empty string.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
static int
static int
MarkFindPrev(interp, textPtr, string)
MarkFindPrev(interp, textPtr, string)
    Tcl_Interp *interp;                 /* For error reporting */
    Tcl_Interp *interp;                 /* For error reporting */
    TkText *textPtr;                    /* The widget */
    TkText *textPtr;                    /* The widget */
    char *string;                       /* The starting index or mark name */
    char *string;                       /* The starting index or mark name */
{
{
    TkTextIndex index;
    TkTextIndex index;
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *hPtr;
    register TkTextSegment *segPtr, *seg2Ptr, *prevPtr;
    register TkTextSegment *segPtr, *seg2Ptr, *prevPtr;
    int offset;
    int offset;
 
 
 
 
    hPtr = Tcl_FindHashEntry(&textPtr->markTable, string);
    hPtr = Tcl_FindHashEntry(&textPtr->markTable, string);
    if (hPtr != NULL) {
    if (hPtr != NULL) {
        /*
        /*
         * If given a mark name, return the previous mark in the list of
         * If given a mark name, return the previous mark in the list of
         * segments, even if it happens to be at the same character position.
         * segments, even if it happens to be at the same character position.
         */
         */
        segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
        segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
        TkTextMarkSegToIndex(textPtr, segPtr, &index);
        TkTextMarkSegToIndex(textPtr, segPtr, &index);
    } else {
    } else {
        /*
        /*
         * For non-mark name indices we do not return any marks that
         * For non-mark name indices we do not return any marks that
         * are right at the index.
         * are right at the index.
         */
         */
        if (TkTextGetIndex(interp, textPtr, string, &index) != TCL_OK) {
        if (TkTextGetIndex(interp, textPtr, string, &index) != TCL_OK) {
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        for (offset = 0, segPtr = index.linePtr->segPtr;
        for (offset = 0, segPtr = index.linePtr->segPtr;
                segPtr != NULL && offset < index.charIndex;
                segPtr != NULL && offset < index.charIndex;
                offset += segPtr->size, segPtr = segPtr->nextPtr) {
                offset += segPtr->size, segPtr = segPtr->nextPtr) {
            /* Empty loop body */ ;
            /* Empty loop body */ ;
        }
        }
    }
    }
    while (1) {
    while (1) {
        /*
        /*
         * segPtr points just past the first possible candidate,
         * segPtr points just past the first possible candidate,
         * or at the begining of the line.
         * or at the begining of the line.
         */
         */
        for (prevPtr = NULL, seg2Ptr = index.linePtr->segPtr;
        for (prevPtr = NULL, seg2Ptr = index.linePtr->segPtr;
                seg2Ptr != NULL && seg2Ptr != segPtr;
                seg2Ptr != NULL && seg2Ptr != segPtr;
                seg2Ptr = seg2Ptr->nextPtr) {
                seg2Ptr = seg2Ptr->nextPtr) {
            if (seg2Ptr->typePtr == &tkTextRightMarkType ||
            if (seg2Ptr->typePtr == &tkTextRightMarkType ||
                    seg2Ptr->typePtr == &tkTextLeftMarkType) {
                    seg2Ptr->typePtr == &tkTextLeftMarkType) {
                prevPtr = seg2Ptr;
                prevPtr = seg2Ptr;
            }
            }
        }
        }
        if (prevPtr != NULL) {
        if (prevPtr != NULL) {
            Tcl_SetResult(interp,
            Tcl_SetResult(interp,
                Tcl_GetHashKey(&textPtr->markTable, prevPtr->body.mark.hPtr),
                Tcl_GetHashKey(&textPtr->markTable, prevPtr->body.mark.hPtr),
                TCL_STATIC);
                TCL_STATIC);
            return TCL_OK;
            return TCL_OK;
        }
        }
        index.linePtr = TkBTreePreviousLine(index.linePtr);
        index.linePtr = TkBTreePreviousLine(index.linePtr);
        if (index.linePtr == (TkTextLine *) NULL) {
        if (index.linePtr == (TkTextLine *) NULL) {
            return TCL_OK;
            return TCL_OK;
        }
        }
        segPtr = NULL;
        segPtr = NULL;
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.