Tk Source Code

Check-in [243a1376]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:New files provided by René Zaumseil: elimination of the use of RbcList*() functions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-510
Files: files | file ages | folders
SHA3-256: 243a1376020cb291f442a8713859d10c7ec4079d1cb09556efb23f025df96856
User & Date: fvogel 2018-08-19 14:06:51
References
2018-10-16
20:43
In checkin [243a1376] the file generic/rbc/rbcInt.c was accidentaly overwritten with rbcInt.h (this was noticed by René Zaumseil). Fix that. check-in: 28031ee8 user: fvogel tags: tip-510
Context
2018-08-19
14:11
New files provided by René Zaumseil: some more clean up in generic/rbc, and file generic/rbc/rbcAlloc.c is no more needed check-in: 072b83be user: fvogel tags: tip-510
14:06
New files provided by René Zaumseil: elimination of the use of RbcList*() functions check-in: 243a1376 user: fvogel tags: tip-510
2018-07-05
11:24
Remove debug code check-in: c77f765d user: fvogel tags: tip-510
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/rbc/rbcBind.c.

69
70
71
72
73
74
75
















76
77
78
79
80
81
82
..
88
89
90
91
92
93
94
95
96





97
98
99
100
101
102
103
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140














141
142
143
144
145
146
147
...
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
 *
 * DoEvent --
 *
 *      This procedure is called to invoke binding processing
 *      for a new event that is associated with the current item
 *      for a legend.
 *
















 * Results:
 *      None.
 *
 * Side effects:
 *      Depends on the bindings for the legend.  A binding script
 *      could delete an entry, so callers should protect themselves
 *      with Tcl_Preserve and Tcl_Release.
................................................................................
    RbcBindTable * bindPtr,     /* Binding information for widget in
                                 * which event occurred. */
    XEvent * eventPtr,          /* Real or simulated X event that
                                 * is to be processed. */
    ClientData item,            /* Item picked. */
    ClientData context)
{                               /* Context of item.  */
    RbcList        *bindIds;
    int             nIds;






    if ((bindPtr->tkwin == NULL) || (bindPtr->bindingTable == NULL)) {
        return;
    }
    if ((eventPtr->type == KeyPress) || (eventPtr->type == KeyRelease)) {
        item = bindPtr->focusItem;
        context = bindPtr->focusContext;
................................................................................
    if (item == NULL) {
        return;
    }

    /*
     * Invoke the binding system.
     */
    bindIds = RbcListCreate(TCL_ONE_WORD_KEYS);
    if (bindPtr->tagProc == NULL) {
        RbcListAppend(bindIds, (char *) Tk_GetUid("all"), 0);
        RbcListAppend(bindIds, (char *) item, 0);
    } else {
        (*bindPtr->tagProc) (bindPtr, item, context, bindIds);
    }
    nIds = RbcListGetLength(bindIds);
    if (nIds > 0) {
        ClientData     *idArray;
        ClientData      tags[32];
        register RbcListNode *node;

        idArray = tags;
        if (nIds >= 32) {
            idArray = (ClientData *) ckalloc(sizeof(ClientData) * nIds);
        }
        nIds = 0;
        for (node = RbcListFirstNode(bindIds); node != NULL;
            node = RbcListNextNode(node)) {
            idArray[nIds++] = (ClientData) RbcListGetKey(node);
        }
        Tk_BindEvent(bindPtr->bindingTable, eventPtr, bindPtr->tkwin, nIds,
            idArray);
        if (nIds >= 32) {
            ckfree((char *) idArray);
        }
    }
    RbcListDestroy(bindIds);














}

/*
 *--------------------------------------------------------------
 *
 * PickCurrentItem --
 *
................................................................................
 *--------------------------------------------------------------
 */
RbcBindTable   *
RbcCreateBindingTable(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData,
    RbcBindPickProc * pickProc,
    RbcBindTagProc * tagProc)
{
    unsigned int    mask;
    RbcBindTable   *bindPtr;

    bindPtr = RbcCalloc(1, sizeof(RbcBindTable));
    assert(bindPtr);
    bindPtr->clientData = clientData;
    bindPtr->pickProc = pickProc;
    bindPtr->tagProc = tagProc;
    bindPtr->tkwin = tkwin;
    bindPtr->bindingTable = Tk_CreateBindingTable(interp);
    mask =
        (KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
        EnterWindowMask | LeaveWindowMask | PointerMotionMask);
    Tk_CreateEventHandler(tkwin, mask, BindProc, bindPtr);
    return bindPtr;






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
>
>
>
>
>







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
<








<







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
653
654
655
656
657
658
659
660

661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
 *
 * DoEvent --
 *
 *      This procedure is called to invoke binding processing
 *      for a new event that is associated with the current item
 *      for a legend.
 *
 *      Sets the binding tags for a graph object. This routine is
 *      called by Tk when an event occurs in the graph.  It fills
 *      an array of pointers with bind tag addresses.
 *
 *      The object addresses are strings hashed in one of two tag
 *      tables: one for elements and the another for markers.  Note
 *      that there's only one binding table for elements and markers.
 *      [We don't want to trigger both a marker and element bind
 *      command for the same event.]  But we don't want a marker and
 *      element with the same tag name to activate the others
 *      bindings. A tag "all" for markers should mean all markers, not
 *      all markers and elements.  As a result, element and marker
 *      tags are stored in separate hash tables, which means we can't
 *      generate the same tag address for both an elements and marker,
 *      even if they have the same name.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Depends on the bindings for the legend.  A binding script
 *      could delete an entry, so callers should protect themselves
 *      with Tcl_Preserve and Tcl_Release.
................................................................................
    RbcBindTable * bindPtr,     /* Binding information for widget in
                                 * which event occurred. */
    XEvent * eventPtr,          /* Real or simulated X event that
                                 * is to be processed. */
    ClientData item,            /* Item picked. */
    ClientData context)
{                               /* Context of item.  */
    RbcElement     *elemPtr;
    MakeTagProc    *tagProc;
    RbcGraph       *graphPtr;
    ClientData     *idArray;
    ClientData      tags[32];
    int nIds = 2; /* Always add the name of the object to the tag array. */
    register char **p;

    if ((bindPtr->tkwin == NULL) || (bindPtr->bindingTable == NULL)) {
        return;
    }
    if ((eventPtr->type == KeyPress) || (eventPtr->type == KeyRelease)) {
        item = bindPtr->focusItem;
        context = bindPtr->focusContext;
................................................................................
    if (item == NULL) {
        return;
    }

    /*
     * Invoke the binding system.
     */
    graphPtr = (RbcGraph *) RbcGetBindingData(bindPtr);
    /*
     * Trick:   Markers, elements, and axes have the same first few
     *          fields in their structures, such as "type", "name", or
     *          "tags".  This is so we can look at graph objects
     *          interchangably.  It doesn't matter what we cast the
     *          object to.
     */
    elemPtr = (RbcElement *) item;

    if ((elemPtr->classUid == rbcLineElementUid)
        || (elemPtr->classUid == rbcStripElementUid)
        || (elemPtr->classUid == rbcBarElementUid)) {
        tagProc = RbcMakeElementTag;
    } else if ((elemPtr->classUid == rbcXAxisUid)
        || (elemPtr->classUid == rbcYAxisUid)) {
        tagProc = RbcMakeAxisTag;
    } else {
        tagProc = RbcMakeMarkerTag;
    }

    if (elemPtr->tags != NULL) {
        for (p = elemPtr->tags; *p != NULL; p++) {
            nIds++;
        }
    }
    if (nIds > 32) {
        idArray = (ClientData *) ckalloc(sizeof(ClientData) * nIds);
    } else {
        idArray = tags;
    }
    idArray[0] = (ClientData) (*tagProc) (graphPtr, elemPtr->name);
    idArray[1] = (ClientData)  (*tagProc) (graphPtr, elemPtr->classUid);
    if (nIds > 2) {
        for (p = elemPtr->tags; *p != NULL; p++) {
            idArray[nIds++] = (ClientData) (*tagProc) (graphPtr, *p);
        }
    }
    Tk_BindEvent(bindPtr->bindingTable, eventPtr, bindPtr->tkwin, nIds,idArray);
    if (nIds >= 32) {
        ckfree((char *) idArray);
    }

}

/*
 *--------------------------------------------------------------
 *
 * PickCurrentItem --
 *
................................................................................
 *--------------------------------------------------------------
 */
RbcBindTable   *
RbcCreateBindingTable(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData,
    RbcBindPickProc * pickProc)

{
    unsigned int    mask;
    RbcBindTable   *bindPtr;

    bindPtr = RbcCalloc(1, sizeof(RbcBindTable));
    assert(bindPtr);
    bindPtr->clientData = clientData;
    bindPtr->pickProc = pickProc;

    bindPtr->tkwin = tkwin;
    bindPtr->bindingTable = Tk_CreateBindingTable(interp);
    mask =
        (KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
        EnterWindowMask | LeaveWindowMask | PointerMotionMask);
    Tk_CreateEventHandler(tkwin, mask, BindProc, bindPtr);
    return bindPtr;

Changes to generic/rbc/rbcGrLegd.c.

1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
    legendPtr->padY.side1 = legendPtr->padY.side2 = 1;
    legendPtr->anchor = TK_ANCHOR_N;
    legendPtr->site = RBC_LEGEND_RIGHT;
    RbcInitTextStyle(&(legendPtr->style));
    legendPtr->style.justify = TK_JUSTIFY_LEFT;
    legendPtr->style.anchor = TK_ANCHOR_NW;
    legendPtr->bindTable = RbcCreateBindingTable(graphPtr->interp,
        graphPtr->tkwin, graphPtr, PickLegendEntry, RbcGraphTags);

    if (RbcConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
            "legend", "Legend", configSpecs, 0, (const char **) NULL,
            (char *) legendPtr, 0) != TCL_OK) {
        return TCL_ERROR;
    }
    ConfigureLegend(graphPtr, legendPtr);






|







1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
    legendPtr->padY.side1 = legendPtr->padY.side2 = 1;
    legendPtr->anchor = TK_ANCHOR_N;
    legendPtr->site = RBC_LEGEND_RIGHT;
    RbcInitTextStyle(&(legendPtr->style));
    legendPtr->style.justify = TK_JUSTIFY_LEFT;
    legendPtr->style.anchor = TK_ANCHOR_NW;
    legendPtr->bindTable = RbcCreateBindingTable(graphPtr->interp,
        graphPtr->tkwin, graphPtr, PickLegendEntry);

    if (RbcConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
            "legend", "Legend", configSpecs, 0, (const char **) NULL,
            (char *) legendPtr, 0) != TCL_OK) {
        return TCL_ERROR;
    }
    ConfigureLegend(graphPtr, legendPtr);

Changes to generic/rbc/rbcGraph.c.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
...
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
....
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
 * rbcGraph.c --
 *
 *      This module implements a graph widget for the rbc toolkit.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * To do:
 *
................................................................................

    if (graphPtr->tkwin != NULL) {      /* NULL indicates window has
                                         * already been destroyed. */
        Tk_Window       tkwin;

        tkwin = graphPtr->tkwin;
        graphPtr->tkwin = NULL;
#ifdef ITCL_NAMESPACES
        Itk_SetWidgetCommand(tkwin, (Tcl_Command) NULL);
#endif /* ITCL_NAMESPACES */
        RbcDeleteWindowInstanceData(tkwin);
        Tk_DestroyWindow(tkwin);
    }
}

/*
 *----------------------------------------------------------------------
................................................................................
    if (RbcCreatePen(graphPtr, "activeBar", rbcBarElementUid, 0,
            (const char **) NULL) == NULL) {
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGraphTags --
 *
 *      Sets the binding tags for a graph object. This routine is
 *      called by Tk when an event occurs in the graph.  It fills
 *      an array of pointers with bind tag addresses.
 *
 *      The object addresses are strings hashed in one of two tag
 *      tables: one for elements and the another for markers.  Note
 *      that there's only one binding table for elements and markers.
 *      [We don't want to trigger both a marker and element bind
 *      command for the same event.]  But we don't want a marker and
 *      element with the same tag name to activate the others
 *      bindings. A tag "all" for markers should mean all markers, not
 *      all markers and elements.  As a result, element and marker
 *      tags are stored in separate hash tables, which means we can't
 *      generate the same tag address for both an elements and marker,
 *      even if they have the same name.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      This information will be used by the binding code in rbcUtil.c
 *      to determine what graph objects match the current event.  The
 *      tags are placed in tagArr and *nTagsPtr is set with the
 *      number of tags found.
 *
 *----------------------------------------------------------------------
 */
void
RbcGraphTags(
    RbcBindTable * table,
    ClientData object,
    ClientData context,         /* Not used. */
    RbcList * list)
{
    RbcElement     *elemPtr;
    MakeTagProc    *tagProc;
    RbcGraph       *graphPtr;

    graphPtr = (RbcGraph *) RbcGetBindingData(table);
    /*
     * Trick:   Markers, elements, and axes have the same first few
     *          fields in their structures, such as "type", "name", or
     *          "tags".  This is so we can look at graph objects
     *          interchangably.  It doesn't matter what we cast the
     *          object to.
     */
    elemPtr = (RbcElement *) object;

    if ((elemPtr->classUid == rbcLineElementUid)
        || (elemPtr->classUid == rbcStripElementUid)
        || (elemPtr->classUid == rbcBarElementUid)) {
        tagProc = RbcMakeElementTag;
    } else if ((elemPtr->classUid == rbcXAxisUid)
        || (elemPtr->classUid == rbcYAxisUid)) {
        tagProc = RbcMakeAxisTag;
    } else {
        tagProc = RbcMakeMarkerTag;
    }
    /*
     * Always add the name of the object to the tag array.
     */
    RbcListAppend(list, (*tagProc) (graphPtr, elemPtr->name), 0);
    RbcListAppend(list, (*tagProc) (graphPtr, elemPtr->classUid), 0);
    if (elemPtr->tags != NULL) {
        register char **p;

        for (p = elemPtr->tags; *p != NULL; p++) {
            RbcListAppend(list, (*tagProc) (graphPtr, *p), 0);
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PickEntry --
 *
 *      Find the closest point from the set of displayed elements,
 *      searching the display list from back to front.  That way, if
................................................................................
    Tk_CreateEventHandler(graphPtr->tkwin,
        ExposureMask | StructureNotifyMask | FocusChangeMask, GraphEventProc,
        graphPtr);

    graphPtr->cmdToken =
        Tcl_CreateCommand(interp, argv[1], RbcGraphInstCmdProc, graphPtr,
        GraphInstCmdDeleteProc);
#ifdef ITCL_NAMESPACES
    Itk_SetWidgetCommand(graphPtr->tkwin, graphPtr->cmdToken);
#endif
    ConfigureGraph(graphPtr);
    graphPtr->bindTable =
        RbcCreateBindingTable(interp, tkwin, graphPtr, PickEntry, RbcGraphTags);
    return graphPtr;

  error:
    DestroyGraph((char *) graphPtr);
    return NULL;
}







|







 







<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<


|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
479
480
481
482
483
484
485



486
487
488
489
490
491
492
...
576
577
578
579
580
581
582













































































583
584
585
586
587
588
589
...
992
993
994
995
996
997
998



999
1000
1001
1002
1003
1004
1005
1006
1007
1008
 * rbcGraph.c --
 *
 *      This module implements a graph widget for the rbc toolkit.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * To do:
 *
................................................................................

    if (graphPtr->tkwin != NULL) {      /* NULL indicates window has
                                         * already been destroyed. */
        Tk_Window       tkwin;

        tkwin = graphPtr->tkwin;
        graphPtr->tkwin = NULL;



        RbcDeleteWindowInstanceData(tkwin);
        Tk_DestroyWindow(tkwin);
    }
}

/*
 *----------------------------------------------------------------------
................................................................................
    if (RbcCreatePen(graphPtr, "activeBar", rbcBarElementUid, 0,
            (const char **) NULL) == NULL) {
        return TCL_ERROR;
    }
    return TCL_OK;
}














































































/*
 *----------------------------------------------------------------------
 *
 * PickEntry --
 *
 *      Find the closest point from the set of displayed elements,
 *      searching the display list from back to front.  That way, if
................................................................................
    Tk_CreateEventHandler(graphPtr->tkwin,
        ExposureMask | StructureNotifyMask | FocusChangeMask, GraphEventProc,
        graphPtr);

    graphPtr->cmdToken =
        Tcl_CreateCommand(interp, argv[1], RbcGraphInstCmdProc, graphPtr,
        GraphInstCmdDeleteProc);



    ConfigureGraph(graphPtr);
    graphPtr->bindTable =
        RbcCreateBindingTable(interp, tkwin, graphPtr, PickEntry);
    return graphPtr;

  error:
    DestroyGraph((char *) graphPtr);
    return NULL;
}

Changes to generic/rbc/rbcInt.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70








































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































/*
 * rbcInt.c --
 *
 *      This file constructs the basic functionality of the
 *      rbc commands.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"

/*
 * -----------------------------------------------------------------------
 *
 * Rbc_Init --
 *
 *      This procedure is invoked to initialize the "rbc" commands.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Creates the new commands and adds a new entry into a global Tcl
 *      associative array.
 *
 * ------------------------------------------------------------------------
 */
MODULE_SCOPE int
Rbc_Init(
    Tcl_Interp * interp)
{                               /* Base interpreter to return results to. */
    Tcl_Namespace  *nsPtr;

    nsPtr = Tcl_CreateNamespace(interp, "::rbc", NULL, NULL);
    if (nsPtr == NULL) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "vector", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "graph", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "stripchart", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "barchart", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    RbcVectorInit(interp);
    RbcGraphInit(interp);

    if (Tcl_PkgProvide(interp, "rbc", RBC_VERSION) == TCL_ERROR) {
        return TCL_ERROR;
    }

    return TCL_OK;
}

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */








































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
/*
 * rbcInt.h --
 *
 *      This file constructs the basic functionality of the
 *      rbc commands.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _RBCINT
#define _RBCINT

#include <tcl.h>
#include <tclInt.h>             /* only #define's and inline functions */

#include <tk.h>
#include <tkInt.h>

#ifndef _WIN32
#include <X11/Xproto.h>
#endif

#if defined(_WIN32)
#include "tkWinInt.h"
#elif defined(MAC_OSX_TK)
#include "tkMacOSXInt.h"
#else
#include "tkUnixInt.h"
#endif

#include "tk3d.h"
#include "tkFont.h"

#include <assert.h>

/*
 * Mathematical functions
 */
#undef ABS
#define ABS(x)		(((x)<0)?(-(x)):(x))

#undef EXP10
#define EXP10(x)	(pow(10.0,(x)))

#undef FABS
#define FABS(x) 	(((x)<0.0)?(-(x)):(x))

#undef SIGN
#define SIGN(x)		(((x) < 0.0) ? -1 : 1)

#undef MIN
#define MIN(a,b)	(((a)<(b))?(a):(b))

#undef MAX
#define MAX(a,b)	(((a)>(b))?(a):(b))

#undef MIN3
#define MIN3(a,b,c)	(((a)<(b))?(((a)<(c))?(a):(c)):(((b)<(c))?(b):(c)))

#undef MAX3
#define MAX3(a,b,c)	(((a)>(b))?(((a)>(c))?(a):(c)):(((b)>(c))?(b):(c)))

#define CLAMP(val,low,high)	\
	(((val) < (low)) ? (low) : ((val) > (high)) ? (high) : (val))

/*
 * Be careful when using the next two macros.  They both assume the floating
 * point number is less than the size of an int.  That means, for example, you
 * can't use these macros with numbers bigger than than 2^31-1.
 */
#undef FMOD
#define FMOD(x,y) 	((x)-(((int)((x)/(y)))*y))

#undef ROUND
#define ROUND(x) 	((int)((x) + (((x)<0.0) ? -0.5 : 0.5)))

/*
 * RBC defines start here
 */
#define RBC_VERSION "0.2"
#define RBC_MAJOR_VERSION 0
#define RBC_MINOR_VERSION 2

/*
 * Used standard values
 */
#define RBC_NORMAL_BG_MONO	    "white"
#define RBC_NORMAL_FG_MONO	    "black"
#define RBC_ACTIVE_BG_MONO	    "black"
#define RBC_ACTIVE_FG_MONO	    "white"
#define RBC_SELECT_BG_MONO	    "black"
#define RBC_SELECT_FG_MONO      "black"
#define RBC_SELECT_BORDERWIDTH  "2"
#define RBC_BORDERWIDTH 	    "2"
#define RBC_FONT                "TkDefaultFont 10"
#define RBC_FONT_HUGE           "TkDefaultFontArial 16"
#define RBC_FONT_LARGE          "TkDefaultFontArial 12"
#define RBC_FONT_SMALL          "TkDefaultFontArial 8"
#define RBC_NORMAL_BACKGROUND   "gray85"
#define RBC_NORMAL_FOREGROUND   "black"
#define RBC_ACTIVE_BACKGROUND   "gray64"
#define RBC_ACTIVE_FOREGROUND   "black"
#define RBC_SELECT_BACKGROUND   "lightblue1"
#define RBC_SELECT_FOREGROUND   "black"
#define RBC_INDICATOR_COLOR	    "maroon"

#define RBC_OP_LINEAR_SEARCH	1
#define RBC_OP_BINARY_SEARCH	0

#define RBC_STATIC_STRING_SPACE 150

#define RBC_NS_SEARCH_NONE		(0)
#define RBC_NS_SEARCH_CURRENT	(1<<0)
#define RBC_NS_SEARCH_GLOBAL	(1<<1)
#define RBC_NS_SEARCH_BOTH		(RBC_NS_SEARCH_GLOBAL | RBC_NS_SEARCH_CURRENT)

/* Recognize "min", "max", and "++end" as valid indices */
#define RBC_INDEX_SPECIAL	(1<<0)

/* Also recognize a range of indices separated by a colon */
#define RBC_INDEX_COLON	(1<<1)

/* Verify that the specified index or range of indices are within limits */
#define RBC_INDEX_CHECK	(1<<2)
#define RBC_INDEX_ALL_FLAGS    (RBC_INDEX_SPECIAL | RBC_INDEX_COLON | RBC_INDEX_CHECK)
#define RBC_SPECIAL_INDEX		-2

/* The data of the vector has changed.  Update the min and max limits when they are needed */
#define RBC_UPDATE_RANGE		(1<<9)

#define RBC_COLOR_NONE		    (XColor *)0
#define RBC_COLOR_DEFAULT		(XColor *)1
#define RBC_COLOR_ALLOW_DEFAULTS	1

#define RBC_STATE_NORMAL	0
#define RBC_STATE_ACTIVE	(1<<0)
#define RBC_STATE_DISABLED	(1<<1)
#define RBC_STATE_EMPHASIS	(1<<2)

#define RBC_ROTATE_0	0
#define RBC_ROTATE_90	1
#define RBC_ROTATE_180	2
#define RBC_ROTATE_270	3

#define RBC_SEARCH_X	0
#define RBC_SEARCH_Y	1
#define RBC_SEARCH_BOTH	2

#define RBC_SHOW_NONE	0
#define RBC_SHOW_X		1
#define RBC_SHOW_Y		2
#define RBC_SHOW_BOTH	3

#define RBC_SEARCH_POINTS	0       /* Search for closest data point. */
#define RBC_SEARCH_TRACES	1       /* Search for closest point on trace.
                                         * Interpolate the connecting line segments
                                         * if necessary. */
#define RBC_SEARCH_AUTO	2       /* Automatically determine whether to search
                                 * for data points or traces.  Look for
                                 * traces if the linewidth is > 0 and if
                                 * there is more than one data point. */

#define	RBC_ELEM_ACTIVE	(1<<8)  /* Non-zero indicates that the element
                                 * should be drawn in its active
                                 * foreground and background
                                 * colors. */
#define	RBC_ACTIVE_PENDING	(1<<7)

#define	RBC_LABEL_ACTIVE 	(1<<9)  /* Non-zero indicates that the
                                         * element's entry in the legend
                                         * should be drawn in its active
                                         * foreground and background
                                         * colors. */
#define RBC_SCALE_SYMBOL	(1<<10)

#define RBC_SWITCH_ARGV_ONLY		(1<<0)
#define RBC_SWITCH_OBJV_ONLY		(1<<0)
#define RBC_SWITCH_ARGV_PARTIAL		(1<<1)
#define RBC_SWITCH_OBJV_PARTIAL		(1<<1)

/*
 * Possible flag values for RbcSwitchSpec structures.  Any bits at
 * or above RBC_SWITCH_USER_BIT may be used by clients for selecting
 * certain entries.
 */
#define RBC_SWITCH_NULL_OK		(1<<0)
#define RBC_SWITCH_DONT_SET_DEFAULT	(1<<3)
#define RBC_SWITCH_SPECIFIED		(1<<4)
#define RBC_SWITCH_USER_BIT		(1<<8)

/*
 * Bit flags definitions:
 *
 * 	All kinds of state information kept here.  All these
 *	things happen when the window is available to draw into
 *	(DisplayGraph). Need the window width and height before
 *	we can calculate graph layout (i.e. the screen coordinates
 *	of the axes, elements, titles, etc). But we want to do this
 *	only when we have to, not every time the graph is redrawn.
 *
 *	Same goes for maintaining a pixmap to double buffer graph
 *	elements.  Need to mark when the pixmap needs to updated.
 *
 *
 *	MAP_ITEM		Indicates that the element/marker/axis
 *				configuration has changed such that
 *				its layout of the item (i.e. its
 *				position in the graph window) needs
 *				to be recalculated.
 *
 *	MAP_ALL			Indicates that the layout of the axes and
 *				all elements and markers and the graph need
 *				to be recalculated. Otherwise, the layout
 *				of only those markers and elements that
 *				have changed will be reset.
 *
 *	GET_AXIS_GEOMETRY	Indicates that the size of the axes needs
 *				to be recalculated.
 *
 *	RESET_AXES		Flag to call to RbcResetAxes routine.
 *				This routine recalculates the scale offset
 *				(used for mapping coordinates) of each axis.
 *				If an axis limit has changed, then it sets
 *				flags to re-layout and redraw the entire
 *				graph.  This needs to happend before the axis
 *				can compute transformations between graph and
 *				screen coordinates.
 *
 *	LAYOUT_NEEDED
 *
 *	REDRAW_BACKING_STORE	If set, redraw all elements into the pixmap
 *				used for buffering elements.
 *
 *	REDRAW_PENDING		Non-zero means a DoWhenIdle handler has
 *				already been queued to redraw this window.
 *
 *	DRAW_LEGEND		Non-zero means redraw the legend. If this is
 *				the only DRAW_* flag, the legend display
 *				routine is called instead of the graph
 *				display routine.
 *
 *	DRAW_MARGINS		Indicates that the margins bordering
 *				the plotting area need to be redrawn.
 *				The possible reasons are:
 *
 *				1) an axis configuration changed
 *				2) an axis limit changed
 *				3) titles have changed
 *				4) window was resized.
 *
 *	GRAPH_FOCUS
 */
#define	RBC_MAP_ITEM		(1<<0)  /* 0x0001 */
#define	RBC_MAP_ALL			(1<<1)  /* 0x0002 */
#define	RBC_GET_AXIS_GEOMETRY	(1<<2)  /* 0x0004 */
#define RBC_RESET_AXES		(1<<3)  /* 0x0008 */
#define RBC_LAYOUT_NEEDED		(1<<4)  /* 0x0010 */

#define RBC_REDRAW_PENDING		(1<<8)  /* 0x0100 */
#define RBC_DRAW_LEGEND		(1<<9)  /* 0x0200 */
#define RBC_DRAW_MARGINS		(1<<10) /* 0x0400 */
#define	RBC_REDRAW_BACKING_STORE	(1<<11) /* 0x0800 */

#define RBC_GRAPH_FOCUS		(1<<12) /* 0x1000 */
#define RBC_DATA_CHANGED		(1<<13) /* 0x2000 */

#define	RBC_MAP_WORLD		(RBC_MAP_ALL|RBC_RESET_AXES|RBC_GET_AXIS_GEOMETRY)
#define RBC_REDRAW_WORLD	(RBC_DRAW_MARGINS | RBC_DRAW_LEGEND)
#define RBC_RESET_WORLD		(RBC_REDRAW_WORLD | RBC_MAP_WORLD)

/* Legend */
#define RBC_LEGEND_RIGHT	(1<<0)  /* Right margin */
#define RBC_LEGEND_LEFT	(1<<1)  /* Left margin */
#define RBC_LEGEND_BOTTOM	(1<<2)  /* Bottom margin */
#define RBC_LEGEND_TOP	(1<<3)  /* Top margin, below the graph title. */
#define RBC_LEGEND_PLOT	(1<<4)  /* Plot area */
#define RBC_LEGEND_XY	(1<<5)  /* Screen coordinates in the plotting
                                 * area. */
#define RBC_LEGEND_WINDOW	(1<<6)  /* External window. */
#define RBC_LEGEND_IN_MARGIN \
	(RBC_LEGEND_RIGHT | RBC_LEGEND_LEFT | RBC_LEGEND_BOTTOM | RBC_LEGEND_TOP)
#define RBC_LEGEND_IN_PLOT  (RBC_LEGEND_PLOT | RBC_LEGEND_XY)

#define RBC_MARKER_UNDER	1       /* Draw markers designated to lie underneath
                                         * elements, grids, legend, etc. */
#define RBC_MARKER_ABOVE	0       /* Draw markers designated to rest above
                                         * elements, grids, legend, etc. */

/*
 * Mask values used to selectively enable GRAPH or BARCHART entries in
 * the various configuration specs.
 */
#define RBC_GRAPH		(TK_CONFIG_USER_BIT << 1)
#define RBC_STRIPCHART	(TK_CONFIG_USER_BIT << 2)
#define RBC_BARCHART	(TK_CONFIG_USER_BIT << 3)
#define RBC_LINE_GRAPHS	(RBC_GRAPH | RBC_STRIPCHART)
#define RBC_ALL_GRAPHS	(RBC_GRAPH | RBC_BARCHART | RBC_STRIPCHART)

#define RBC_PEN_DELETE_PENDING	(1<<0)
#define RBC_ACTIVE_PEN		(TK_CONFIG_USER_BIT << 6)
#define RBC_NORMAL_PEN		(TK_CONFIG_USER_BIT << 7)
#define RBC_ALL_PENS		(RBC_NORMAL_PEN | RBC_ACTIVE_PEN)

#define RBC_MARGIN_NONE     -1
#define RBC_MARGIN_BOTTOM   0
#define RBC_MARGIN_LEFT     1
#define RBC_MARGIN_TOP      2
#define RBC_MARGIN_RIGHT    3

/* forward references, defined later */
typedef struct RbcGraph RbcGraph;
typedef struct RbcElement RbcElement;
typedef struct RbcLegend RbcLegend;
typedef struct RbcBindTable RbcBindTable;
typedef struct RbcChainLink RbcChainLink;
typedef struct RbcTileClient *RbcTile;  /* Opaque type for tiles */
typedef struct RbcPsToken RbcPsToken;
typedef struct RbcPen RbcPen;
typedef struct RbcMarker RbcMarker;
typedef struct RbcCrosshairs RbcCrosshairs;
typedef struct RbcParseValue RbcParseValue;

/*
 * RbcUid --
 */
typedef const char *RbcUid;

/*
 * RbcPad --
 *
 * 	Specifies vertical and horizontal padding.
 *
 *	Padding can be specified on a per side basis.  The fields
 *	side1 and side2 refer to the opposite sides, either
 *	horizontally or vertically.
 *
 *		side1	side2
 *              -----   -----
 *      x | left    right
 *	    y | top     bottom
 */
typedef struct {
    short int       side1;
    short int       side2;
} RbcPad;

/*
 * RbcTextFragment --
 */
typedef struct {
    char           *text;       /* Text to be displayed */
    short int       x, y;       /* X-Y offset of the baseline from the
                                 * upper-left corner of the bbox. */
    short int       sx, sy;     /* See rbcWinUtil.c */
    short int       count;      /* Number of bytes in text. The actual
                                 * character count may differ because of
                                 * multi-byte UTF encodings. */
    short int       width;      /* Width of segment in pixels. This
                                 * information is used to draw
                                 * PostScript strings the same width
                                 * as X. */
} RbcTextFragment;

/*
 * RbcTextLayout --
 */
typedef struct {
    int             nFrags;     /* # fragments of text */
    short int       width, height;      /* Dimensions of text bounding box */
    RbcTextFragment fragArr[1]; /* Information about each fragment of text */
} RbcTextLayout;

/*
 * RbcShadow --
 */
typedef struct {
    XColor         *color;
    int             offset;
} RbcShadow;

/*
 * RbcTextStyle --
 *
 * 	Represents a convenient structure to hold text attributes
 *	which determine how a text string is to be displayed on the
 *	window, or drawn with PostScript commands.  The alternative
 *	is to pass lots of parameters to the drawing and printing
 *	routines. This seems like a more efficient and less cumbersome
 *	way of passing parameters.
 */
typedef struct {
    unsigned int    state;      /* If non-zero, indicates to draw text
                                 * in the active color */
    short int       width, height;      /* Extents of text */
    XColor         *color;      /* Normal color */
    XColor         *activeColor;        /* Active color */
    Tk_Font         font;       /* Font to use to draw text */
    Tk_3DBorder     border;     /* Background color of text.  This is also
                                 * used for drawing disabled text. */
    RbcShadow       shadow;     /* Drop shadow color and offset */
    Tk_Justify      justify;    /* Justification of the text string. This
                                 * only matters if the text is composed
                                 * of multiple lines. */
    GC              gc;         /* GC used to draw the text */
    double          theta;      /* Rotation of text in degrees. */
    Tk_Anchor       anchor;     /* Indicates how the text is anchored around
                                 * its x and y coordinates. */
    RbcPad          padX, padY; /* # pixels padding of around text region */
    short int       leader;     /* # pixels spacing between lines of text */
} RbcTextStyle;

/*
 *
 */
typedef ClientData(
    RbcBindPickProc) (
    ClientData clientData,
    int x,
    int y,
    ClientData * contextPtr);

/*
 * RbcBindTable --
 *
 * Binding structure information:
 */
typedef struct RbcBindTable {
    unsigned int    flags;
    Tk_BindingTable bindingTable;       /* Table of all bindings currently defined.
                                         * NULL means that no bindings exist, so the
                                         * table hasn't been created.  Each "object"
                                         * used for this table is either a Tk_Uid for
                                         * a tag or the address of an item named by
                                         * id. */
    ClientData      currentItem;        /* The item currently containing the mouse
                                         * pointer, or NULL if none. */
    ClientData      currentContext;     /* One word indicating what kind of object
                                         * was picked. */
    ClientData      newItem;    /* The item that is about to become the
                                 * current one, or NULL.  This field is
                                 * used to detect deletions of the new
                                 * current item pointer that occur during
                                 * Leave processing of the previous current
                                 * tab.  */
    ClientData      newContext; /* One-word indicating what kind of object
                                 * was just picked. */
    ClientData      focusItem;
    ClientData      focusContext;
    XEvent          pickEvent;  /* The event upon which the current choice
                                 * of the current tab is based.  Must be saved
                                 * so that if the current item is deleted,
                                 * we can pick another. */
    int             activePick; /* The pick event has been initialized so
                                 * that we can repick it */
    int             state;      /* Last known modifier state.  Used to
                                 * defer picking a new current object
                                 * while buttons are down. */
    ClientData      clientData;
    Tk_Window       tkwin;
    RbcBindPickProc *pickProc;  /* Routine to report the item the mouse is
                                 * currently over. */
} RbcBindTable;

/*
 * RbcChainLink --
 *
 * A RbcChainLink is the container structure for the RbcChain.
 */
typedef struct RbcChainLink {
    RbcChainLink   *prevPtr;    /* Link to the previous link */
    RbcChainLink   *nextPtr;    /* Link to the next link */
    ClientData      clientData; /* Pointer to the data object */
} RbcChainLink;

typedef int     (RbcChainCompareProc) (
    RbcChainLink ** l1PtrPtr,
    RbcChainLink ** l2PtrPtr);

/*
 * RbcChain --
 *
 * A RbcChain is a doubly chained list structure.
 */
typedef struct {
    RbcChainLink   *headPtr;    /* Pointer to first element in chain */
    RbcChainLink   *tailPtr;    /* Pointer to last element in chain */
    int             nLinks;     /* Number of elements in chain */
} RbcChain;

/*
 * RbcVector --
 */
typedef struct {
    double         *valueArr;   /* Array of values (possibly malloc-ed) */
    int             numValues;  /* Number of values in the array */
    int             arraySize;  /* Size of the allocated space */
    double          min, max;   /* Minimum and maximum values in the vector */
    int             dirty;      /* Indicates if the vector has been updated */
    int             reserved;   /* Reserved for future use */
} RbcVector;

/*
 * RbcVectorInterpData --
 */
typedef struct {
    Tcl_HashTable   vectorTable;        /* Table of vectors */
    Tcl_HashTable   mathProcTable;      /* Table of vector math functions */
    Tcl_HashTable   indexProcTable;
    Tcl_Interp     *interp;
    unsigned int    nextId;
} RbcVectorInterpData;

/*
 * RbcVectorObject --
 *
 *	A vector is an array of double precision values.  It can be
 *	accessed through a Tcl command, a Tcl array variable, or C
 *	API. The storage for the array points initially to a
 *	statically allocated buffer, but to malloc-ed memory if more
 *	is necessary.
 *
 *	Vectors can be shared by several clients (for example, two
 *	different graph widgets).  The data is shared. When a client
 *	wants to use a vector, it allocates a vector identifier, which
 *	identifies the client.  Clients use this ID to specify a
 *	callback routine to be invoked whenever the vector is modified
 *	or destroyed.  Whenever the vector is updated or destroyed,
 *	each client is notified of the change by their callback
 *	routine.
 */
typedef struct {
    /*
     * If you change these fields, make sure you change the definition
     * of RbcVector in rbcVector.h too.
     */
    double         *valueArr;   /* Array of values (malloc-ed) */
    int             length;     /* Current number of values in the array. */
    int             size;       /* Maximum number of values that can be stored
                                 * in the value array. */
    double          min, max;   /* Minimum and maximum values in the vector */
    int             dirty;      /* Indicates if the vector has been updated */
    int             reserved;
    /* The following fields are local to this module  */
    char           *name;       /* The namespace-qualified name of the vector command.
                                 * It points to the hash key allocated for the
                                 * entry in the vector hash table. */
    RbcVectorInterpData *dataPtr;
    Tcl_Interp     *interp;     /* Interpreter associated with the vector */
    Tcl_HashEntry  *hashPtr;    /* If non-NULL, pointer in a hash table to
                                 * track the vectors in use. */
    Tcl_FreeProc   *freeProc;   /* Address of procedure to call to
                                 * release storage for the value
                                 * array, Optionally can be one of the
                                 * following: TCL_STATIC, TCL_DYNAMIC,
                                 * or TCL_VOLATILE. */
    char           *arrayName;  /* The namespace-qualified name of the
                                 * Tcl array variable
                                 * mapped to the vector
                                 * (malloc'ed). If NULL, indicates
                                 * that the vector isn't mapped to any variable */
    int             offset;     /* Offset from zero of the vector's
                                 * starting index */
    Tcl_Command     cmdToken;   /* Token for vector's Tcl command. */
    RbcChain       *chainPtr;   /* List of clients using this vector */
    int             notifyFlags;        /* Notification flags. See definitions
                                         * below */
    int             varFlags;   /* Indicate if the variable is global,
                                 * namespace, or local */
    int             freeOnUnset;        /* For backward compatibility only: If
                                         * non-zero, free the vector when its
                                         * variable is unset. */
    int             flush;
    int             first, last;        /* Selected region of vector. This is used
                                         * mostly for the math routines */
} RbcVectorObject;

typedef struct RbcVectorIdStruct *RbcVectorId;

/*
 * RbcVectorNotify --
 */
typedef enum {
    RBC_VECTOR_NOTIFY_UPDATE = 1,       /* The vector's values has been updated */
    RBC_VECTOR_NOTIFY_DESTROY   /* The vector has been destroyed and the client
                                 * should no longer use its data (calling
                                 * RbcFreeVectorId) */
} RbcVectorNotify;

typedef void    (RbcVectorChangedProc) (
    Tcl_Interp * interp,
    ClientData clientData,
    RbcVectorNotify notify);
typedef double  (RbcVectorIndexProc) (
    RbcVector * vecPtr);

/*
 * RbcParseValue --
 *
 *	The following data structure is used by various parsing
 *	procedures to hold information about where to store the
 *	results of parsing (e.g. the substituted contents of a quoted
 *	argument, or the result of a nested command).  At any given
 *	time, the space available for output is fixed, but a procedure
 *	may be called to expand the space available if the current
 *	space runs out.
 */
typedef struct RbcParseValue {
    char           *buffer;     /* Address of first character in
                                 * output buffer. */
    char           *next;       /* Place to store next character in
                                 * output buffer. */
    char           *end;        /* Address of the last usable character
                                 * in the buffer. */
    void            (
        *expandProc)    (
        RbcParseValue * pvPtr,
        int needed);
    /* Procedure to call when space runs out;
     * it will make more space. */
    ClientData      clientData; /* Arbitrary information for use of
                                 * expandProc. */
} RbcParseValue;

/*
 * RbcParseVector --
 */
typedef struct {
    RbcVectorObject *vPtr;
    char            staticSpace[RBC_STATIC_STRING_SPACE];
    RbcParseValue   pv;         /* Used to hold a string value, if any. */
} RbcParseVector;

/*
 * RbcOp --
 *
 * 	Generic function prototype of CmdOptions.
 */
typedef int     (*RbcOp)         ();

/*
 * RbcOpSpec --
 *
 * 	Structure to specify a set of operations for a Tcl command.
 *      This is passed to the RbcGetOp procedure to look
 *      for a function pointer associated with the operation name.
 */
    typedef struct {
    const char     *name;       /* Name of operation */
    int             minChars;   /* Minimum # characters to disambiguate */
    RbcOp           proc;
    int             minArgs;    /* Minimum # args required */
    int             maxArgs;    /* Maximum # args required */
    const char     *usage;      /* Usage message */
} RbcOpSpec;

/*
 * RbcOpIndex --
 */
typedef enum {
    RBC_OP_ARG0,                /* Op is the first argument. */
    RBC_OP_ARG1,                /* Op is the second argument. */
    RBC_OP_ARG2,                /* Op is the third argument. */
    RBC_OP_ARG3,                /* Op is the fourth argument. */
    RBC_OP_ARG4                 /* Op is the fifth argument. */
} RbcOpIndex;

typedef int     (QSortCompareProc) (
    const void *,
    const void *);

/*
 * RbcDashes --
 *
 * 	List of dash values (maximum 11 based upon PostScript limit).
 */
typedef struct {
    char            values[12];
    int             offset;
} RbcDashes;
#define RbcLineIsDashed(d) ((d).values[0] != 0)

/*
 * RbcPoint2D --
 *
 *	2-D coordinate.
 */
typedef struct {
    double          x;
    double          y;
} RbcPoint2D;

/*
 * RbcPoint3D --
 *
 *	3-D coordinate.
 */
typedef struct {
    double          x;
    double          y;
    double          z;
} RbcPoint3D;

/*
 * RbcSegment2D --
 *
 *	2-D line segment.
 */
typedef struct {
    RbcPoint2D      p;       /* First end point of the segment. */
    RbcPoint2D      q;       /* Last end point of the segment. */
} RbcSegment2D;

/*
 * RbcDim2D --
 *
 *	2-D dimension.
 */
typedef struct {
    short int       width;
    short int       height;
} RbcDim2D;

/*
 * RbcRegion2D --
 *
 *      2-D region.  Used to copy parts of images.
 */
typedef struct {
    int             left;
    int             right;
    int             top;
    int             bottom;
} RbcRegion2D;

/*
 * RbcExtents2D --
 */
typedef struct {
    double          left;
    double          right;
    double          top;
    double          bottom;
} RbcExtents2D;

/*
 * RbcExtents3D --
 */
typedef struct {
    double          left;
    double          right;
    double          top;
    double          bottom;
    double          front;
    double          back;
} RbcExtents3D;

/* int RbcPointInRegion(RbcRegion2D e, int x, int y) */
#define RbcPointInRegion(e,x,y) \
	(((x) <= (e)->right) && ((x) >= (e)->left) && \
	 ((y) <= (e)->bottom) && ((y) >= (e)->top))

/*
 * RbcColorPair --
 *
 *	Holds a pair of foreground, background colors.
 */
typedef struct {
    XColor         *fgColor, *bgColor;
} RbcColorPair;

typedef void    (
    RbcTileChangedProc) (
    ClientData clientData,
    RbcTile tile);

/*
 * RbcPix32 --
 *
 *      A union representing either a pixel as a RGB triplet or a
 *	single word value.
 */
typedef union {
    unsigned int    value;      /* Lookup table address */
    struct RGBA {
        unsigned char   red;    /* Red intensity 0..255 */
        unsigned char   green;  /* Green intensity 0.255 */
        unsigned char   blue;   /* Blue intensity 0..255 */
        unsigned char   alpha;  /* Alpha-channel for compositing. 0..255 */
    } rgba;
    unsigned char   channel[4];
} RbcPix32;

/*
 * RbcColorImage --
 *
 *      The structure below represents a color image.  Each pixel
 *	occupies a 32-bit word of memory: one byte for each of the
 *	red, green, and blue color intensities, and another for
 *	alpha-channel image compositing (e.g. transparency).
 */
typedef struct RbcColorImage {
    int             width;      /* Dimensions of the image */
    int             height;     /* Dimensions of the image */
    RbcPix32       *bits;       /* Array of pixels representing the image. */
} RbcColorImage;

/*
 * ResampleFilterProc --
 *
 *      A function implementing a 1-D filter.
 */
typedef double  (
    ResampleFilterProc) (
    double value);

/*
 * RbcFilter2D --
 *
 *      Defines a convolution mask for a 2-D filter.  Used to smooth or
 *	enhance images.
 */
typedef struct {
    double          support;    /* Radius of filter */
    double          sum, scale; /* Sum of kernel */
    double         *kernel;     /* Array of values (malloc-ed) representing
                                 * the discrete 2-D filter. */
} RbcFilter2D;

/*
 * RbcPsColorMode --
 */
typedef enum {
    PS_MODE_MONOCHROME,         /* Only black and white. */
    PS_MODE_GREYSCALE,          /* Color converted to greyscale. */
    PS_MODE_COLOR               /* Full color */
} RbcPsColorMode;

/*
 * RbcPsToken --
 */
typedef struct RbcPsToken {
    Tcl_Interp     *interp;     /* Interpreter to report errors to. */
    Tk_Window       tkwin;      /* Tk_Window used to get font and color
                                 * information */
    Tcl_DString     dString;    /* Dynamic string used to contain the
                                 * PostScript generated. */
    char           *fontVarName;        /* Name of a Tcl array variable to convert
                                         * X font names to PostScript fonts. */
    char           *colorVarName;       /* Name of a Tcl array variable to convert
                                         * X color names to PostScript. */
    RbcPsColorMode  colorMode;  /* Mode: color or greyscale */
    /*
     * Utility space for building strings.  Currently used to create
     * PostScript output for the "postscript" command.
     */
    char            scratchArr[BUFSIZ*2];
} RbcPsToken;

/*
 * RbxAxisRange --
 *
 *	Designates a range of values by a minimum and maximum limit.
 */
typedef struct {
    double          min;
    double          max;
    double          range;
    double          scale;
} RbcAxisRange;

/*
 * RbcTicks --
 *
 * 	Structure containing information where the ticks (major or
 *	minor) will be displayed on the graph.
 */
typedef struct {
    int             nTicks;     /* # of ticks on axis */
    double          values[1];  /* Array of tick values (malloc-ed). */
} RbcTicks;

/*
 * RbcTickSweep --
 *
 * 	Structure containing information where the ticks (major or
 *	minor) will be displayed on the graph.
 */
typedef struct {
    double          initial;    /* Initial value */
    double          step;       /* Size of interval */
    int             nSteps;     /* Number of intervals. */
} RbcTickSweep;

/*
 * RbcAxis --
 *
 * 	Structure contains options controlling how the axis will be
 * 	displayed.
 */
typedef struct {
    char           *name;       /* Identifier to refer the element.
                                 * Used in the "insert", "delete", or
                                 * "show", commands. */
    RbcUid          classUid;   /* Type of axis. */
    RbcGraph       *graphPtr;   /* Graph widget of element */
    unsigned int    flags;      /* Set bit field definitions below */
    /*
     * AXIS_DRAWN               Axis is designated as a logical axis
     * AXIS_DIRTY
     *
     * AXIS_CONFIG_MAJOR        User specified major ticks.
     * AXIS_CONFIG_MINOR        User specified minor ticks.
     */
    char          **tags;
    const char     *detail;
    int             deletePending;      /* Indicates that the axis was
                                         * scheduled for deletion. The actual
                                         * deletion may be deferred until the
                                         * axis is no longer in use.  */
    int             refCount;   /* Number of elements referencing this
                                 * axis. */
    Tcl_HashEntry  *hashPtr;    /* Points to axis entry in hash
                                 * table. Used to quickly remove axis
                                 * entries. */
    int             logScale;   /* If non-zero, scale the axis values
                                 * logarithmically. */
    int             hidden;     /* If non-zero, don't display the
                                 * axis title, ticks, or line. */
    int             showTicks;  /* If non-zero, display tick marks and
                                 * labels. */
    int             descending; /* If non-zero, display the range of
                                 * values on the axis in descending
                                 * order, from high to low. */
    int             looseMin, looseMax; /* If non-zero, axis range extends to
                                         * the outer major ticks, otherwise at
                                         * the limits of the data values. This
                                         * is overriddened by setting the -min
                                         * and -max options.  */
    char           *title;      /* Title of the axis. */
    RbcTextStyle    titleTextStyle;     /* Text attributes (color, font,
                                         * rotation, etc.)  of the axis
                                         * title. */
    int             titleAlternate;     /* Indicates whether to position the
                                         * title above/left of the axis. */
    RbcPoint2D      titlePos;   /* Position of the title */
    unsigned short int titleWidth, titleHeight;
    int             lineWidth;  /* Width of lines representing axis
                                 * (including ticks).  If zero, then
                                 * no axis lines or ticks are
                                 * drawn. */
    const char    **limitsFormats;      /* One or two strings of sprintf-like
                                         * formats describing how to display
                                         * virtual axis limits. If NULL,
                                         * display no limits. */
    int             nFormats;
    RbcTextStyle    limitsTextStyle;    /* Text attributes (color, font,
                                         * rotation, etc.)  of the limits. */
    double          windowSize; /* Size of a sliding window of values
                                 * used to scale the axis automatically
                                 * as new data values are added. The axis
                                 * will always display the latest values
                                 * in this range. */
    double          shiftBy;    /* Shift maximum by this interval. */
    int             tickLength; /* Length of major ticks in pixels */
    RbcTextStyle    tickTextStyle;      /* Text attributes (color, font, rotation,
                                         * etc.) for labels at each major tick. */
    char           *formatCmd;  /* Specifies a Tcl command, to be invoked
                                 * by the axis whenever it has to generate
                                 * tick labels. */
    char           *scrollCmdPrefix;
    int             scrollUnits;
    double          min, max;   /* The actual axis range. */
    double          reqMin, reqMax;     /* Requested axis bounds. Consult the
                                         * axisPtr->flags field for
                                         * AXIS_CONFIG_MIN and AXIS_CONFIG_MAX
                                         * to see if the requested bound have
                                         * been set.  They override the
                                         * computed range of the axis
                                         * (determined by auto-scaling). */
    double          scrollMin, scrollMax;       /* Defines the scrolling reqion of the axis.
                                                 * Normally the region is determined from
                                                 * the data limits. If specified, these
                                                 * values override the data-range. */
    RbcAxisRange    valueRange; /* Range of data values of elements mapped
                                 * to this axis. This is used to auto-scale
                                 * the axis in "tight" mode. */
    RbcAxisRange    axisRange;  /* Smallest and largest major tick values
                                 * for the axis.  The tick values lie outside
                                 * the range of data values.  This is used to
                                 * auto-scale the axis in "loose" mode. */
    double          prevMin, prevMax;
    double          reqStep;    /* If > 0.0, overrides the computed major
                                 * tick interval.  Otherwise a stepsize
                                 * is automatically calculated, based
                                 * upon the range of elements mapped to the
                                 * axis. The default value is 0.0. */
    double          tickZoom;   /* If > 0.0, overrides the computed major
                                 * tick interval.  Otherwise a stepsize
                                 * is automatically calculated, based
                                 * upon the range of elements mapped to the
                                 * axis. The default value is 0.0. */
    GC              tickGC;     /* Graphics context for axis and tick labels */
    RbcTicks       *t1Ptr;      /* Array of major tick positions. May be
                                 * set by the user or generated from the
                                 * major sweep below. */
    RbcTicks       *t2Ptr;      /* Array of minor tick positions. May be
                                 * set by the user or generated from the
                                 * minor sweep below. */
    RbcTickSweep    minorSweep, majorSweep;
    int             reqNumMinorTicks;   /* If non-zero, represents the
                                         * requested the number of minor ticks
                                         * to be uniformally displayed along
                                         * each major tick. */
    int             labelOffset;        /* If non-zero, indicates that the tick
                                         * label should be offset to sit in the
                                         * middle of the next interval. */
    /* The following fields are specific to logical axes */
    RbcChainLink   *linkPtr;    /* Axis link in margin list. */
    RbcChain       *chainPtr;
    short int       width, height;      /* Extents of axis */
    RbcSegment2D   *segments;   /* Array of line segments representing
                                 * the major and minor ticks, but also
                                 * the axis line itself. The segment
                                 * coordinates are relative to the
                                 * axis. */
    int             nSegments;  /* Number of segments in the above array. */
    RbcChain       *tickLabels; /* Contains major tick label strings
                                 * and their offsets along the axis. */
    RbcRegion2D     region;
    Tk_3DBorder     border;
    int             borderWidth;
    int             relief;
} RbcAxis;

/*
 * RbcAxis2D --
 *
 *	The pair of axes mapping a point onto the graph.
 */
typedef struct {
    RbcAxis        *x;
    RbcAxis        *y;
} RbcAxis2D;

/*
* RbcElemWeight --
*
*	Designates a range of values by a minimum and maximum limit.
*/
typedef struct {
    double          min;
    double          max;
    double          range;
} RbcElemWeight;

/*
 * RbcPenStyle --
 *
 * An element has one or more vectors plus several attributes, such as
 * line style, thickness, color, and symbol type.  It has an
 * identifier which distinguishes it among the list of all elements.
 */
typedef struct {
    RbcElemWeight   weight;     /* Weight range where this pen is valid. */
    RbcPen         *penPtr;     /* Pen to use. */
    RbcSegment2D   *xErrorBars; /* Point to start of this pen's X-error bar
                                 * segments in the element's array. */
    RbcSegment2D   *yErrorBars; /* Point to start of this pen's Y-error bar
                                 * segments in the element's array. */
    int             xErrorBarCnt;       /* # of error bars for this pen. */
    int             yErrorBarCnt;       /* # of error bars for this pen. */
    int             errorBarCapWidth;   /* Length of the cap ends on each
                                         * error bar. */
    int             symbolSize; /* Size of the pen's symbol scaled to
                                 * the current graph size. */
} RbcPenStyle;

typedef struct {
    int             halo;       /* Maximal distance a candidate point
                                 * can be from the sample window
                                 * coordinate */
    int             mode;       /* Indicates whether to find the closest
                                 * data point or the closest point on the
                                 * trace by interpolating the line segments.
                                 * Can also be SEARCH_AUTO, indicating to
                                 * choose how to search.*/
    int             x, y;       /* Screen coordinates of test point */
    int             along;      /* Indicates to let search run along a
                                 * particular axis: x, y, or both. */
    /* Output */
    RbcElement     *elemPtr;    /* Name of the closest element */
    RbcPoint2D      point;      /* Graph coordinates of closest point */
    int             index;      /* Index of closest data point */
    double          dist;       /* Distance in screen coordinates */
} RbcClosestSearch;

typedef void    (
    RbcElementDrawProc) (
    RbcGraph * graphPtr,
    Drawable drawable,
    RbcElement * elemPtr);
typedef void    (
    RbcElementToPostScriptProc) (
    RbcGraph * graphPtr,
    RbcPsToken * psToken,
    RbcElement * elemPtr);
typedef void    (
    RbcElementDestroyProc) (
    RbcGraph * graphPtr,
    RbcElement * elemPtr);
typedef int     (
    RbcElementConfigProc) (
    RbcGraph * graphPtr,
    RbcElement * elemPtr);
typedef void    (
    RbcElementMapProc) (
    RbcGraph * graphPtr,
    RbcElement * elemPtr);
typedef void    (
    RbcElementExtentsProc) (
    RbcElement * elemPtr,
    RbcExtents2D * extsPtr);
typedef void    (
    RbcElementClosestProc) (
    RbcGraph * graphPtr,
    RbcElement * elemPtr,
    RbcClosestSearch * searchPtr);
typedef void    (
    RbcElementDrawSymbolProc) (
    RbcGraph * graphPtr,
    Drawable drawable,
    RbcElement * elemPtr,
    int x,
    int y,
    int symbolSize);
typedef void    (
    RbcElementSymbolToPostScriptProc) (
    RbcGraph * graphPtr,
    RbcPsToken * psToken,
    RbcElement * elemPtr,
    double x,
    double y,
    int symSize);

/*
 * RbcElementProcs --
 */
typedef struct {
    RbcElementClosestProc *closestProc;
    RbcElementConfigProc *configProc;
    RbcElementDestroyProc *destroyProc;
    RbcElementDrawProc *drawActiveProc;
    RbcElementDrawProc *drawNormalProc;
    RbcElementDrawSymbolProc *drawSymbolProc;
    RbcElementExtentsProc *extentsProc;
    RbcElementToPostScriptProc *printActiveProc;
    RbcElementToPostScriptProc *printNormalProc;
    RbcElementSymbolToPostScriptProc *printSymbolProc;
    RbcElementMapProc *mapProc;
} RbcElementProcs;

/*
 * RbcElemVector --
 *
 * The data structure below contains information pertaining to a line
 * vector.  It consists of an array of floating point data values and
 * for convenience, the number and minimum/maximum values.
 */
typedef struct {
    RbcVector      *vecPtr;
    double         *valueArr;
    int             nValues;
    int             arraySize;
    double          min, max;
    RbcVectorId     clientId;   /* If non-NULL, a client token identifying the
                                 * external vector. */
    RbcElement     *elemPtr;    /* Element associated with vector. */
} RbcElemVector;

/*
 * RbcElement --
 */
typedef struct RbcElement {
    char           *name;       /* Identifier to refer the element.
                                 * Used in the "insert", "delete", or
                                 * "show", commands. */
    RbcUid          classUid;   /* Type of element */
    RbcGraph       *graphPtr;   /* Graph widget of element */
    unsigned int    flags;      /* Indicates if the entire element is
                                 * active, or if coordinates need to
                                 * be calculated */
    char          **tags;
    int             hidden;     /* If non-zero, don't display the element. */
    Tcl_HashEntry  *hashPtr;
    char           *label;      /* Label displayed in legend */
    int             labelRelief;        /* Relief of label in legend. */
    RbcAxis2D       axes;       /* X-axis and Y-axis mapping the element */
    RbcElemVector   x, y, w;    /* Contains array of floating point
                                 * graph coordinate values. Also holds
                                 * min/max and the number of
                                 * coordinates */
    RbcElemVector   xError;     /* Relative/symmetric X error values. */
    RbcElemVector   yError;     /* Relative/symmetric Y error values. */
    RbcElemVector   xHigh, xLow;        /* Absolute/asymmetric X-coordinate high/low
                                           error values. */
    RbcElemVector   yHigh, yLow;        /* Absolute/asymmetric Y-coordinate high/low
                                           error values. */
    int            *activeIndices;      /* Array of indices (malloc-ed) which
                                         * indicate which data points are
                                         * active (drawn with "active"
                                         * colors). */
    int             nActiveIndices;     /* Number of active data points.
                                         * Special case: if nActiveIndices < 0
                                         * and the active bit is set in
                                         * "flags", then all data points are
                                         * drawn active. */
    RbcElementProcs *procsPtr;
    Tk_ConfigSpec  *specsPtr;   /* Configuration specifications. */
    RbcSegment2D   *xErrorBars; /* Point to start of this pen's X-error bar
                                 * segments in the element's array. */
    RbcSegment2D   *yErrorBars; /* Point to start of this pen's Y-error bar
                                 * segments in the element's array. */
    int             xErrorBarCnt;       /* # of error bars for this pen. */
    int             yErrorBarCnt;       /* # of error bars for this pen. */
    int            *xErrorToData;       /* Maps error bar segments back to the data
                                         * point. */
    int            *yErrorToData;       /* Maps error bar segments back to the data
                                         * point. */
    int             errorBarCapWidth;   /* Length of cap on error bars */
    RbcPen         *activePenPtr;       /* Standard Pens */
    RbcPen         *normalPenPtr;
    RbcChain       *palette;    /* Palette of pens. */
    /* Symbol scaling */
    int             scaleSymbols;       /* If non-zero, the symbols will scale
                                         * in size as the graph is zoomed
                                         * in/out.  */
    double          xRange, yRange;     /* Initial X-axis and Y-axis ranges:
                                         * used to scale the size of element's
                                         * symbol. */
    int             state;
} RbcElement;

/*
 * RbcFreqInfo --
 */
typedef struct {
    int             freq;       /* Number of occurrences of x-coordinate */
    RbcAxis2D       axes;       /* Indicates which x and y axis are mapped to
                                 * the x-value */
    double          sum;        /* Sum of the ordinates of each duplicate
                                 * abscissa */
    int             count;
    double          lastY;

} RbcFreqInfo;

/*
 * RbcBarMode --
 *
 *	Bar elements are displayed according to their x-y coordinates.
 *	If two bars have the same abscissa (x-coordinate), the bar
 *	segments will be drawn according to one of the following
 *	modes:
 */
typedef enum {
    MODE_INFRONT,               /* Each successive segment is drawn in
                                 * front of the previous. */
    MODE_STACKED,               /* Each successive segment is drawn
                                 * stacked above the previous. */
    MODE_ALIGNED,               /* Each successive segment is drawn
                                 * aligned to the previous from
                                 * right-to-left. */
    MODE_OVERLAP                /* Like "aligned", each successive segment
                                 * is drawn from right-to-left. In addition
                                 * the segments will overlap each other
                                 * by a small amount */
} RbcBarMode;

typedef RbcPen *(
    PenCreateProc)  (
    void);
typedef int     (
    PenConfigureProc) (
    RbcGraph * graphPtr,
    RbcPen * penPtr);
typedef void    (
    PenDestroyProc) (
    RbcGraph * graphPtr,
    RbcPen * penPtr);

/*
 * RbcPen --
 */
typedef struct RbcPen {
    char           *name;       /* Pen style identifier.  If NULL pen
                                 * was statically allocated. */
    RbcUid          classUid;   /* Type of pen */
    char           *typeId;     /* String token identifying the type of pen */
    unsigned int    flags;      /* Indicates if the pen element is active or
                                 * normal */
    int             refCount;   /* Reference count for elements using
                                 * this pen. */
    Tcl_HashEntry  *hashPtr;

    Tk_ConfigSpec  *configSpecs;        /* Configuration specifications */

    PenConfigureProc *configProc;
    PenDestroyProc *destroyProc;

} RbcPen;

/*
 * RbcPostScript --
 *
 * 	Structure contains information specific to the outputting of
 *	PostScript commands to print the graph.
 *
 */
typedef struct {
    /* User configurable fields */

    int             decorations;        /* If non-zero, print graph with
                                         * color background and 3D borders */

    int             reqWidth, reqHeight;        /* If greater than zero, represents the
                                                 * requested dimensions of the printed graph */
    int             reqPaperWidth;
    int             reqPaperHeight;     /* Requested dimensions for the PostScript
                                         * page. Can constrain the size of the graph
                                         * if the graph (plus padding) is larger than
                                         * the size of the page. */
    RbcPad          padX, padY; /* Requested padding on the exterior of the
                                 * graph. This forms the bounding box for
                                 * the page. */
    RbcPsColorMode  colorMode;  /* Selects the color mode for PostScript page
                                 * (0=monochrome, 1=greyscale, 2=color) */
    char           *colorVarName;       /* If non-NULL, is the name of a Tcl array
                                         * variable containing X to PostScript color
                                         * translations */
    char           *fontVarName;        /* If non-NULL, is the name of a Tcl array
                                         * variable containing X to PostScript font
                                         * translations */
    int             landscape;  /* If non-zero, orient the page 90 degrees */
    int             center;     /* If non-zero, center the graph on the page */
    int             maxpect;    /* If non-zero, indicates to scale the graph
                                 * so that it fills the page (maintaining the
                                 * aspect ratio of the graph) */
    int             addPreview; /* If non-zero, generate a preview image and
                                 * add it to the PostScript output */
    int             footer;     /* If non-zero, a footer with the title, date
                                 * and user will be added to the PostScript
                                 * output outside of the bounding box. */
    int             previewFormat;      /* Format of EPS preview:
                                         * PS_PREVIEW_WMF, PS_PREVIEW_EPSI, or
                                         * PS_PREVIEW_TIFF. */

    /* Computed fields */

    int             left, bottom;       /* Bounding box of PostScript plot. */
    int             right, top;

    double          pageScale;  /* Scale of page. Set if "-maxpect" option
                                 * is set, otherwise 1.0. */
} RbcPostScript;

/*
 * RbcGrid --
 *
 *	Contains attributes of describing how to draw grids (at major
 *	ticks) in the graph.  Grids may be mapped to either/both x and
 *	y axis.
 */
typedef struct {
    GC              gc;         /* Graphics context for the grid. */
    RbcAxis2D       axes;
    int             hidden;     /* If non-zero, grid isn't displayed. */
    int             minorGrid;  /* If non-zero, draw grid line for minor
                                 * axis ticks too */
    RbcDashes       dashes;     /* Dashstyle of the grid. This represents
                                 * an array of alternatingly drawn pixel
                                 * values. */
    int             lineWidth;  /* Width of the grid lines */
    XColor         *colorPtr;   /* Color of the grid lines */

    struct GridSegments {
        RbcSegment2D   *segments;       /* Array of line segments representing the
                                         * x or y grid lines */
        int             nSegments;      /* # of axis segments. */
    } x            ,
                    y;

} RbcGrid;

/*
 * RbcMargin --
 */
typedef struct {
    short int       width, height;      /* Extents of the margin */

    short int       axesOffset;
    short int       axesTitleLength;    /* Width of the widest title to be shown.
                                         * Multiple titles are displayed in
                                         * another margin. This is the minimum
                                         * space requirement. */
    unsigned int    nAxes;      /* Number of axes to be displayed */
    RbcChain       *axes;       /* Extra axes associated with this margin */

    char           *varName;    /* If non-NULL, name of variable to be
                                 * updated when the margin size changes */

    int             reqSize;    /* Requested size of margin */
    int             site;       /* Indicates where margin is located:
                                 * left/right/top/bottom. */
} RbcMargin;

/*
 * RbcGraph --
 *
 *	Top level structure containing everything pertaining to
 *	the graph.
 */
typedef struct RbcGraph {
    unsigned int    flags;      /* Flags;  see below for definitions. */
    Tcl_Interp     *interp;     /* Interpreter associated with graph */
    Tk_Window       tkwin;      /* Window that embodies the graph.  NULL
                                 * means that the window has been
                                 * destroyed but the data structures
                                 * haven't yet been cleaned up. */
    Display        *display;    /* Display containing widget; needed,
                                 * among other things, to release
                                 * resources after tkwin has already gone
                                 * away. */
    Tcl_Command     cmdToken;   /* Token for graph's widget command. */
    char           *data;       /* This value isn't used in C code.
                                 * It may be used in Tcl bindings to
                                 * associate extra data. */
    Tk_Cursor       cursor;
    int             inset;      /* Sum of focus highlight and 3-D
                                 * border.  Indicates how far to
                                 * offset the graph from outside
                                 * edge of the window. */
    int             borderWidth;        /* Width of the exterior border */
    int             relief;     /* Relief of the exterior border */
    Tk_3DBorder     border;     /* 3-D border used to delineate the plot
                                 * surface and outer edge of window */
    int             highlightWidth;     /* Width in pixels of highlight to draw
                                         * around widget when it has the focus.
                                         * <= 0 means don't draw a highlight. */
    XColor         *highlightBgColor;   /* Color for drawing traversal highlight
                                         * area when highlight is off. */
    XColor         *highlightColor;     /* Color for drawing traversal highlight. */
    char           *title;
    short int       titleX, titleY;
    RbcTextStyle    titleTextStyle;     /* Graph title */
    char           *takeFocus;
    int             reqWidth, reqHeight;        /* Requested size of graph window */
    int             width, height;      /* Size of graph window or PostScript
                                         * page */
    Tcl_HashTable   penTable;   /* Table of pens */
    struct Component {
        Tcl_HashTable   table;  /* Hash table of ids. */
        RbcChain       *displayList;    /* Display list. */
        Tcl_HashTable   tagTable;       /* Table of bind tags. */
    } elements     ,
                    markers,
                    axes;
    RbcUid          classUid;   /* Default element type */
    RbcBindTable   *bindTable;
    int             nextMarkerId;       /* Tracks next marker identifier available */
    RbcChain       *axisChain[4];       /* Chain of axes for each of the
                                         * margins.  They're separate from the
                                         * margin structures to make it easier
                                         * to invert the X-Y axes by simply
                                         * switching chain pointers.
                                         */
    RbcMargin          margins[4];
    RbcPostScript  *postscript; /* PostScript options: see rbcGrPS.c */
    RbcLegend      *legend;     /* Legend information: see rbcGrLegd.c */
    RbcCrosshairs  *crosshairs; /* Crosshairs information: see rbcGrHairs.c */
    RbcGrid        *gridPtr;    /* Grid attribute information */
    int             halo;       /* Maximum distance allowed between points
                                 * when searching for a point */
    int             inverted;   /* If non-zero, indicates the x and y axis
                                 * positions should be inverted. */
    RbcTile         tile;
    GC              drawGC;     /* Used for drawing on the margins. This
                                 * includes the axis lines */
    GC              fillGC;     /* Used to fill the background of the
                                 * margins. The fill is governed by
                                 * the background color or the tiled
                                 * pixmap. */
    int             plotBorderWidth;    /* Width of interior 3-D border. */
    int             plotRelief; /* 3-d effect: TK_RELIEF_RAISED etc. */
    XColor         *plotBg;     /* Color of plotting surface */
    GC              plotFillGC; /* Used to fill the plotting area with a
                                 * solid background color. The fill color
                                 * is stored in "plotBg". */
    /* If non-zero, force plot to conform to aspect ratio W/H */
    double          aspect;
    short int       left, right;        /* Coordinates of plot bbox */
    short int       top, bottom;
    RbcPad          padX;       /* Vertical padding for plotarea */
    int             vRange, vOffset;    /* Vertical axis range and offset from the
                                         * left side of the graph window. Used to
                                         * transform coordinates to vertical
                                         * axes. */
    RbcPad          padY;       /* Horizontal padding for plotarea */
    int             hRange, hOffset;    /* Horizontal axis range and offset from
                                         * the top of the graph window. Used to
                                         * transform horizontal axes */
    double          vScale, hScale;
    int             doubleBuffer;       /* If non-zero, draw the graph into a pixmap
                                         * first to reduce flashing. */
    int             backingStore;       /* If non-zero, cache elements by drawing
                                         * them into a pixmap */
    Pixmap          backPixmap; /* Pixmap used to cache elements
                                 * displayed.  If *backingStore* is
                                 * non-zero, each element is drawn
                                 * into this pixmap before it is
                                 * copied onto the screen.  The pixmap
                                 * then acts as a cache (only the
                                 * pixmap is redisplayed if the none
                                 * of elements have changed). This is
                                 * done so that markers can be redrawn
                                 * quickly over elements without
                                 * redrawing each element. */
    int             backWidth, backHeight;      /* Size of element backing store pixmap. */
    /*
     * barchart specific information
     */
    double          baseline;   /* Baseline from bar chart.  */
    double          barWidth;   /* Default width of each bar in graph units.
                                 * The default width is 1.0 units. */
    RbcBarMode      mode;       /* Mode describing how to display bars
                                 * with the same x-coordinates. Mode can
                                 * be "stack", "align", or "normal" */
    RbcFreqInfo    *freqArr;    /* Contains information about duplicate
                                 * x-values in bar elements (malloc-ed).
                                 * This information can also be accessed
                                 * by the frequency hash table */
    Tcl_HashTable   freqTable;  /* */
    int             nStacks;    /* Number of entries in frequency array.
                                 * If zero, indicates nothing special needs
                                 * to be done for "stack" or "align" modes */
    char           *dataCmd;    /* New data callback? */
} RbcGraph;

typedef         ClientData(
    MakeTagProc)    (
    RbcGraph * graphPtr,
    const char *tagName);

typedef int     (
    RbcSwitchParseProc) (
    ClientData clientData,
    Tcl_Interp * interp,
    char *switchName,
    char *value,
    char *record,
    int offset);

typedef void    (
    RbcSwitchFreeProc) (
    char *ptr);

/*
 * RbcSwitchCustom --
 */
typedef struct {
    RbcSwitchParseProc *parseProc;      /* Procedure to parse a switch value
                                         * and store it in its converted
                                         * form in the data record. */
    RbcSwitchFreeProc *freeProc;        /* Procedure to free a switch. */
    ClientData      clientData; /* Arbitrary one-word value
                                 * used by switch parser,
                                 * passed to parseProc. */
} RbcSwitchCustom;

/*
 * Type values for RbcSwitchSpec structures.  See the user
 * documentation for details.
 */
typedef enum {
    RBC_SWITCH_BOOLEAN, RBC_SWITCH_INT, RBC_SWITCH_INT_POSITIVE,
    RBC_SWITCH_INT_NONNEGATIVE, RBC_SWITCH_DOUBLE, RBC_SWITCH_STRING,
    RBC_SWITCH_LIST, RBC_SWITCH_FLAG, RBC_SWITCH_VALUE, RBC_SWITCH_CUSTOM,
    RBC_SWITCH_END
} RbcSwitchTypes;

typedef struct {
    RbcSwitchTypes  type;       /* Type of option, such as RBC_SWITCH_DOUBLE;
                                 * see definitions above.  Last option in
                                 * table must have type RBC_SWITCH_END. */
    const char     *switchName; /* Switch used to specify option in argv.
                                 * NULL means this spec is part of a group. */
    int             offset;     /* Where in widget record to store value;
                                 * use RbcOffset macro to generate values
                                 * for this. */
    int             flags;      /* Any combination of the values defined
                                 * below. */
    RbcSwitchCustom *customPtr; /* If type is RBC_SWITCH_CUSTOM then this is
                                 * a pointer to info about how to parse and
                                 * print the option.  Otherwise it is
                                 * irrelevant. */
    int             value;
} RbcSwitchSpec;

/*
 * RbcResampleFilter --
 *
 *      Contains information about a 1-D filter (its support and
 *	the procedure implementing the filter).
 */
typedef struct {
    const char     *name;       /* Name of the filter */
    ResampleFilterProc *proc;   /* 1-D filter procedure. */
    double          support;    /* Width of 1-D filter */
} RbcResampleFilter;

/*
 * Data declarations:
 */
extern double   rbcNaN;
extern RbcResampleFilter *rbcBoxFilterPtr;      /* The ubiquitous box filter */
extern RbcUid   rbcBarElementUid;
extern RbcUid   rbcLineElementUid;
extern RbcUid   rbcStripElementUid;
extern RbcUid   rbcLineMarkerUid;
extern RbcUid   rbcBitmapMarkerUid;
extern RbcUid   rbcImageMarkerUid;
extern RbcUid   rbcTextMarkerUid;
extern RbcUid   rbcPolygonMarkerUid;
extern RbcUid   rbcWindowMarkerUid;
extern RbcUid   rbcXAxisUid;
extern RbcUid   rbcYAxisUid;

/*
 * Inline function declarations:
 */

/* int RbcNumberOfPoints(RbcAxis2D e); */
#define RbcNumberOfPoints(e)	MIN((e)->x.nValues, (e)->y.nValues)

/* int RbcLineWidth(int w); */
#define RbcLineWidth(w)	(((w) > 1) ? (w) : 0)

/* int RbcPadding(RbcPad w); */
#define RbcPadding(x)	((x).side1 + (x).side2)

/* ClientData RbcGetCurrentItem(RbcBindTable *bindPtr); */
#define RbcGetCurrentItem(bindPtr)  ((bindPtr)->currentItem)
/* */
/* ClientData RbcGetBindingData(RbcBindTable *bindPtr); */
#define RbcGetBindingData(bindPtr)  ((bindPtr)->clientData)
/* int RbcChainGetLength(RbcChain *c); */
#define RbcChainGetLength(c)	(((c) == NULL) ? 0 : (c)->nLinks)
/* RbcChainLink *RbcChainFirstLink(RbcChain *c); */
#define RbcChainFirstLink(c)	(((c) == NULL) ? NULL : (c)->headPtr)
/* */
/* RbcChainLink *RbcChainLastLink(RbcChain *c); */
#define RbcChainLastLink(c)	(((c) == NULL) ? NULL : (c)->tailPtr)
/* RbcChainLink *RbcChainPrevLink(RbcChainLink *l); */
#define RbcChainPrevLink(l)	((l)->prevPtr)
/* RbcChainLink *RbcChainNextLink(RbcChainLink *l); */
#define RbcChainNextLink(l) 	((l)->nextPtr)
/* ClientData RbcChainGetValue(RbcChainLink *l); */
#define RbcChainGetValue(l)  	((l)->clientData)
/* void RbcChainSetValue(RbcChainLink *l, ClientData value); */
#define RbcChainSetValue(l, value) ((l)->clientData = (ClientData)(value))

/*
 * Function declarations:
 */

/* rbcAlloc.c */
MODULE_SCOPE void *RbcCalloc(
    unsigned int nElem,
    size_t size);
MODULE_SCOPE char *RbcStrdup(
    const char *ptr);

/* rbcBind.c */
MODULE_SCOPE int RbcConfigureBindings(
    Tcl_Interp * interp,
    RbcBindTable * table,
    ClientData item,
    int argc,
    const char **argv);
MODULE_SCOPE int RbcConfigureBindingsFromObj(
    Tcl_Interp * interp,
    RbcBindTable * table,
    ClientData item,
    int objc,
    Tcl_Obj * const *objv);
MODULE_SCOPE RbcBindTable *RbcCreateBindingTable(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData,
    RbcBindPickProc * pickProc);
MODULE_SCOPE void RbcDestroyBindingTable(
    RbcBindTable * table);
MODULE_SCOPE void RbcPickCurrentItem(
    RbcBindTable * table);
MODULE_SCOPE void RbcDeleteBindings(
    RbcBindTable * table,
    ClientData object);
MODULE_SCOPE void RbcMoveBindingTable(
    RbcBindTable * table,
    Tk_Window tkwin);

/* rbcChain,c */
MODULE_SCOPE RbcChain *RbcChainCreate(
    );
MODULE_SCOPE void RbcChainInit(
    RbcChain * chainPtr);
MODULE_SCOPE void RbcChainLinkAfter(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr,
    RbcChainLink * afterLinkPtr);
MODULE_SCOPE void RbcChainLinkBefore(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr,
    RbcChainLink * beforeLinkPtr);
MODULE_SCOPE RbcChainLink *RbcChainNewLink(
    void);
MODULE_SCOPE void RbcChainReset(
    RbcChain * chainPtr);
MODULE_SCOPE void RbcChainDestroy(
    RbcChain * chainPtr);
MODULE_SCOPE void RbcChainUnlinkLink(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr);
MODULE_SCOPE void RbcChainDeleteLink(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr);
MODULE_SCOPE RbcChainLink *RbcChainAppend(
    RbcChain * chainPtr,
    ClientData clientData);
MODULE_SCOPE RbcChainLink *RbcChainPrepend(
    RbcChain * chainPtr,
    ClientData clientData);
MODULE_SCOPE RbcChainLink *RbcChainAllocLink(
    unsigned int size);

/* rbcConfig.c */
MODULE_SCOPE int RbcGetPixels(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    int check,
    int *valuePtr);
MODULE_SCOPE int RbcConfigModified(
    Tk_ConfigSpec * specs,
    ...);
MODULE_SCOPE int RbcConfigureWidgetComponent(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *name,
    const char *class,
    const Tk_ConfigSpec * specs,
    int argc,
    const char **argv,
    char *widgRec,
    int flags);

/* rbcGraph.c */
MODULE_SCOPE void RbcEventuallyRedrawGraph(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcGraphInstCmdProc(
    ClientData clientData,
    Tcl_Interp * interp,
    int argc,
    const char *argv[]);
MODULE_SCOPE void RbcLayoutGraph(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawGraph(
    RbcGraph * graphPtr,
    Drawable drawable,
    int backingStore);
MODULE_SCOPE int RbcGraphInit(
    Tcl_Interp * interp);
MODULE_SCOPE RbcGraph *RbcGetGraphFromWindowData(
    Tk_Window tkwin);
MODULE_SCOPE int RbcGraphType(
    RbcGraph * graphPtr);

/* rbcGrAxis.c */
MODULE_SCOPE double RbcInvHMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcInvVMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcHMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x);
MODULE_SCOPE double RbcVMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double y);
MODULE_SCOPE RbcPoint2D RbcMap2D(
    RbcGraph * graphPtr,
    double x,
    double y,
    RbcAxis2D * pairPtr);
MODULE_SCOPE RbcPoint2D RbcInvMap2D(
    RbcGraph * graphPtr,
    double x,
    double y,
    RbcAxis2D * pairPtr);
MODULE_SCOPE void RbcResetAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcGetAxisSegments(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    RbcSegment2D ** segPtrPtr,
    int *nSegmentsPtr);
MODULE_SCOPE void RbcLayoutMargins(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcDefaultAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcVirtualAxisOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
MODULE_SCOPE int RbcAxisOp(
    RbcGraph * graphPtr,
    int margin,
    int argc,
    const char **argv);
MODULE_SCOPE void RbcMapAxes(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawAxes(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcAxesToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE void RbcDrawAxisLimits(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcAxisLimitsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE RbcAxis *RbcGetFirstAxis(
    RbcChain * chainPtr);
MODULE_SCOPE RbcAxis *RbcNearestAxis(
    RbcGraph * graphPtr,
    int x,
    int y);
MODULE_SCOPE ClientData RbcMakeAxisTag(
    RbcGraph * graphPtr,
    const char *tagName);

/* rbcGrBar.c */
MODULE_SCOPE RbcPen *RbcBarPen(
    const char *penName);
MODULE_SCOPE RbcElement *RbcBarElement(
    RbcGraph * graphPtr,
    const char *name,
    RbcUid type);
MODULE_SCOPE void RbcInitFreqTable(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcComputeStacks(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcResetStacks(
    RbcGraph * graphPtr);

/* rbcGrElem.c */
MODULE_SCOPE double RbcFindElemVectorMinimum(
    RbcElemVector * vecPtr,
    double minLimit);
MODULE_SCOPE void RbcFreePalette(
    RbcGraph * graphPtr,
    RbcChain * palette);
MODULE_SCOPE int RbcStringToStyles(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int offset);
MODULE_SCOPE const char *RbcStylesToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);
MODULE_SCOPE RbcPenStyle **RbcStyleMap(
    RbcElement * elemPtr);
MODULE_SCOPE void RbcMapErrorBars(
    RbcGraph * graphPtr,
    RbcElement * elemPtr,
    RbcPenStyle ** dataToStyle);
MODULE_SCOPE void RbcDestroyElements(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcMapElements(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawElements(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcDrawActiveElements(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcElementsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE void RbcActiveElementsToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE int RbcGraphUpdateNeeded(
    RbcGraph * graphPtr);
MODULE_SCOPE ClientData RbcMakeElementTag(
    RbcGraph * graphPtr,
    const char *tagName);
MODULE_SCOPE int RbcElementOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv,
    RbcUid classUid);

/* rbcGrGrid.c */
MODULE_SCOPE void RbcMapGrid(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDrawGrid(
    RbcGraph * graphPtr,
    Drawable drawable);
MODULE_SCOPE void RbcGridToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken);
MODULE_SCOPE void RbcDestroyGrid(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreateGrid(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcGridOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);

/* rbcGrHairs.c */
MODULE_SCOPE void RbcConfigureCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcEnableCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDisableCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcUpdateCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreateCrosshairs(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCrosshairsOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);

/* rbcGrLegd.c */
MODULE_SCOPE void RbcMapLegend(
    RbcLegend * legendPtr,
    int width,
    int height);
MODULE_SCOPE void RbcDrawLegend(
    RbcLegend * legendPtr,
    Drawable drawable);
MODULE_SCOPE void RbcLegendToPostScript(
    RbcLegend * legendPtr,
    RbcPsToken * psToken);
MODULE_SCOPE void RbcDestroyLegend(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreateLegend(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcLegendOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
MODULE_SCOPE int RbcLegendSite(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendWidth(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendHeight(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendIsHidden(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendIsRaised(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendX(
    RbcLegend * legendPtr);
MODULE_SCOPE int RbcLegendY(
    RbcLegend * legendPtr);
MODULE_SCOPE void RbcLegendRemoveElement(
    RbcLegend * legendPtr,
    RbcElement * elemPtr);

/* rbcGrLine.c */
MODULE_SCOPE RbcPen *RbcLinePen(
    const char *penName);
MODULE_SCOPE RbcElement *RbcLineElement(
    RbcGraph *graphPtr,
    const char *name,
    RbcUid classUid);

/* rbcGrMarker.c */
MODULE_SCOPE ClientData RbcMakeMarkerTag(
    RbcGraph * graphPtr,
    const char *tagName);
MODULE_SCOPE int RbcMarkerOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
MODULE_SCOPE void RbcMarkersToPostScript(
    RbcGraph * graphPtr,
    RbcPsToken * psToken,
    int under);
MODULE_SCOPE void RbcDrawMarkers(
    RbcGraph * graphPtr,
    Drawable drawable,
    int under);
MODULE_SCOPE void RbcMapMarkers(
    RbcGraph * graphPtr);
MODULE_SCOPE void RbcDestroyMarkers(
    RbcGraph * graphPtr);
MODULE_SCOPE RbcMarker *RbcNearestMarker(
    RbcGraph * graphPtr,
    int x,
    int y,
    int under);

/* rbcGrMisc.c */
MODULE_SCOPE int RbcGetXY(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    int *x,
    int *y);
MODULE_SCOPE void RbcFreeColorPair(
    RbcColorPair * pairPtr);
MODULE_SCOPE int RbcPointInSegments(
    RbcPoint2D * samplePtr,
    RbcSegment2D * segments,
    int nSegments,
    double halo);
MODULE_SCOPE int RbcPointInPolygon(
    RbcPoint2D * samplePtr,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE int RbcRegionInPolygon(
    RbcExtents2D * extsPtr,
    RbcPoint2D * points,
    int nPoints,
    int enclosed);
MODULE_SCOPE void RbcGraphExtents(
    RbcGraph * graphPtr,
    RbcExtents2D * extsPtr);
MODULE_SCOPE int RbcLineRectClip(
    RbcExtents2D * extsPtr,
    RbcPoint2D * p,
    RbcPoint2D * q);
MODULE_SCOPE int RbcPolyRectClip(
    RbcExtents2D * extsPtr,
    RbcPoint2D * inputPts,
    int nInputPts,
    RbcPoint2D * outputPts);
MODULE_SCOPE RbcPoint2D RbcGetProjection(
    int x,
    int y,
    RbcPoint2D * p,
    RbcPoint2D * q);
MODULE_SCOPE int RbcAdjustViewport(
    int offset,
    int worldSize,
    int windowSize,
    int scrollUnits,
    int scrollMode);
MODULE_SCOPE int RbcGetScrollInfo(
    Tcl_Interp * interp,
    int argc,
    char **argv,
    int *offsetPtr,
    int worldSize,
    int windowSize,
    int scrollUnits,
    int scrollMode);
MODULE_SCOPE int RbcGetScrollInfoFromObj(
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const *objv,
    int *offsetPtr,
    int worldSize,
    int windowSize,
    int scrollUnits,
    int scrollMode);
MODULE_SCOPE void RbcUpdateScrollbar(
    Tcl_Interp * interp,
    char *scrollCmd,
    double firstFract,
    double lastFract);
MODULE_SCOPE GC RbcGetPrivateGCFromDrawable(
    Display * display,
    Drawable drawable,
    unsigned long gcMask,
    XGCValues * valuePtr);
MODULE_SCOPE GC RbcGetPrivateGC(
    Tk_Window tkwin,
    unsigned long gcMask,
    XGCValues * valuePtr);
MODULE_SCOPE void RbcFreePrivateGC(
    Display * display,
    GC gc);
MODULE_SCOPE void RbcSetDashes(
    Display * display,
    GC gc,
    RbcDashes * dashesPtr);
MODULE_SCOPE int RbcSimplifyLine(
    RbcPoint2D * origPts,
    int low,
    int high,
    double tolerance,
    int indices[]);
MODULE_SCOPE void RbcDraw2DSegments(
    Display * display,
    Drawable drawable,
    GC gc,
    RbcSegment2D * segments,
    int nSegments);
MODULE_SCOPE int RbcMaxRequestSize(
    Display * display,
    unsigned int elemSize);

/* rbcPen.c */
MODULE_SCOPE void RbcFreePen(
    RbcGraph * graphPtr,
    RbcPen * penPtr);
MODULE_SCOPE RbcPen *RbcCreatePen(
    RbcGraph * graphPtr,
    const char *penName,
    RbcUid classUid,
    int nOpts,
    const char **options);
MODULE_SCOPE int RbcGetPen(
    RbcGraph * graphPtr,
    const char *name,
    RbcUid classUid,
    RbcPen ** penPtrPtr);
MODULE_SCOPE void RbcDestroyPens(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcPenOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);

/* rbcGrPs.c */
MODULE_SCOPE void RbcDestroyPostScript(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcCreatePostScript(
    RbcGraph * graphPtr);
MODULE_SCOPE int RbcPostScriptOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char *argv[]);

/* rbcImage.c */
MODULE_SCOPE RbcColorImage *RbcCreateColorImage(
    int width,
    int height);
MODULE_SCOPE void RbcFreeColorImage(
    RbcColorImage * image);
MODULE_SCOPE void RbcGammaCorrectColorImage(
    RbcColorImage * src,
    double newGamma);
MODULE_SCOPE void RbcColorImageToGreyscale(
    RbcColorImage * image);
MODULE_SCOPE void RbcColorImageToPhoto(
    Tcl_Interp * interp,
    RbcColorImage * image,
    Tk_PhotoHandle photo);
MODULE_SCOPE RbcColorImage *RbcPhotoRegionToColorImage(
    Tk_PhotoHandle photo,
    int x,
    int y,
    int width,
    int height);
MODULE_SCOPE RbcColorImage *RbcPhotoToColorImage(
    Tk_PhotoHandle photo);
MODULE_SCOPE int RbcGetResampleFilter(
    Tcl_Interp * interp,
    char *filterName,
    RbcResampleFilter ** filterPtrPtr);
MODULE_SCOPE RbcColorImage *RbcResampleColorImage(
    RbcColorImage * image,
    int destWidth,
    int destHeight,
    RbcResampleFilter * horzFilterPtr,
    RbcResampleFilter * vertFilterPtr);
MODULE_SCOPE void RbcResamplePhoto(
    Tcl_Interp * interp,
    Tk_PhotoHandle srcPhoto,
    int x,
    int y,
    int width,
    int height,
    Tk_PhotoHandle destPhoto,
    RbcResampleFilter * horzFilterPtr,
    RbcResampleFilter * vertFilterPtr);
MODULE_SCOPE void RbcResizePhoto(
    Tcl_Interp * interp,
    Tk_PhotoHandle srcPhoto,
    int x,
    int y,
    int width,
    int height,
    Tk_PhotoHandle destPhoto);
MODULE_SCOPE RbcColorImage *RbcResizeColorImage(
    RbcColorImage * src,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
    int destHeight);
MODULE_SCOPE RbcColorImage *RbcResizeColorSubimage(
    RbcColorImage * src,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
    int destHeight);
MODULE_SCOPE RbcColorImage *RbcConvolveColorImage(
    RbcColorImage * srcImage,
    RbcFilter2D * filter);
MODULE_SCOPE int RbcSnapPhoto(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    Drawable drawable,
    int x,
    int y,
    int width,
    int height,
    int destWidth,
    int destHeight,
    const char *photoName,
    double inputGamma);
MODULE_SCOPE RbcColorImage *RbcRotateColorImage(
    RbcColorImage * image,
    double theta);
MODULE_SCOPE int RbcQuantizeColorImage(
    RbcColorImage * src,
    RbcColorImage * dest,
    int nColors);
MODULE_SCOPE RbcRegion2D *RbcSetRegion(
    int x,
    int y,
    int width,
    int height,
    RbcRegion2D * regionPtr);
MODULE_SCOPE Tk_Image RbcCreateTemporaryImage(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData);
MODULE_SCOPE int RbcDestroyTemporaryImage(
    Tcl_Interp * interp,
    Tk_Image tkImage);
MODULE_SCOPE const char *RbcNameOfImage(
    Tk_Image tkImage);
MODULE_SCOPE int RbcImageIsDeleted(
    Tk_Image tkImage);

/* rbcParse.c */
MODULE_SCOPE void RbcExpandParseValue(
    RbcParseValue * parsePtr,
    int needed);
MODULE_SCOPE int RbcParseNestedCmd(
    Tcl_Interp * interp,
    char *string,
    int flags,
    char **termPtr,
    RbcParseValue * parsePtr);
MODULE_SCOPE int RbcParseBraces(
    Tcl_Interp * interp,
    char *string,
    char **termPtr,
    RbcParseValue * parsePtr);
MODULE_SCOPE int RbcParseQuotes(
    Tcl_Interp * interp,
    char *string,
    int termChar,
    int flags,
    char **termPtr,
    RbcParseValue * parsePtr);

/* rbcPs.c */
MODULE_SCOPE RbcPsToken *RbcGetPsToken(
    Tcl_Interp * interp,
    Tk_Window tkwin);
MODULE_SCOPE void RbcReleasePsToken(
    RbcPsToken * psToken);
MODULE_SCOPE char *RbcPostScriptFromToken(
    RbcPsToken * psToken);
MODULE_SCOPE char *RbcScratchBufferFromToken(
    RbcPsToken * psToken);
MODULE_SCOPE void RbcAppendToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE void RbcFormatToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE int RbcFileToPostScript(
    RbcPsToken * psToken,
    const char *fileName);
MODULE_SCOPE void RbcBackgroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcForegroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcBitmapDataToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap,
    int width,
    int height);
MODULE_SCOPE int RbcColorImageToPsData(
    RbcColorImage * image,
    int nComponents,
    Tcl_DString * resultPtr,
    const char *prefix);
MODULE_SCOPE void RbcClearBackgroundToPostScript(
    RbcPsToken * psToken);
MODULE_SCOPE void RbcLineWidthToPostScript(
    RbcPsToken * psToken,
    int lineWidth);
MODULE_SCOPE void RbcLineDashesToPostScript(
    RbcPsToken * psToken,
    RbcDashes * dashesPtr);
MODULE_SCOPE void RbcLineAttributesToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr,
    int lineWidth,
    RbcDashes * dashesPtr,
    int capStyle,
    int joinStyle);
MODULE_SCOPE void RbcRectangleToPostScript(
    RbcPsToken * psToken,
    double x,
    double y,
    int width,
    int height);
MODULE_SCOPE void RbcRegionToPostScript(
    RbcPsToken * psToken,
    double x,
    double y,
    int width,
    int height);
MODULE_SCOPE void RbcPathToPostScript(
    RbcPsToken * psToken,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE void RbcPolygonToPostScript(
    RbcPsToken * psToken,
    RbcPoint2D * screenPts,
    int nScreenPts);
MODULE_SCOPE void RbcSegmentsToPostScript(
    RbcPsToken * psToken,
    XSegment * segArr,
    int nSegs);
MODULE_SCOPE void RbcRectanglesToPostScript(
    RbcPsToken * psToken,
    XRectangle * rectArr,
    int nRects);
MODULE_SCOPE void RbcDraw3DRectangleToPostScript(
    RbcPsToken * psToken,
    Tk_3DBorder border,
    double x,
    double y,
    int width,
    int height,
    int borderWidth,
    int relief);
MODULE_SCOPE void RbcFill3DRectangleToPostScript(
    RbcPsToken * psToken,
    Tk_3DBorder border,
    double x,
    double y,
    int width,
    int height,
    int borderWidth,
    int relief);
MODULE_SCOPE void RbcStippleToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap);
MODULE_SCOPE void RbcColorImageToPostScript(
    RbcPsToken * psToken,
    RbcColorImage * image,
    double x,
    double y);
MODULE_SCOPE void RbcWindowToPostScript(
    RbcPsToken * psToken,
    Tk_Window tkwin,
    double x,
    double y);
MODULE_SCOPE void RbcPhotoToPostScript(
    RbcPsToken * psToken,
    Tk_PhotoHandle photoToken,
    double x,
    double y);
MODULE_SCOPE void RbcFontToPostScript(
    RbcPsToken * psToken,
    Tk_Font font);
MODULE_SCOPE void RbcTextToPostScript(
    RbcPsToken * psToken,
    char *string,
    RbcTextStyle * attrPtr,
    double x,
    double y);
MODULE_SCOPE void RbcLineToPostScript(
    RbcPsToken * psToken,
    XPoint * pointArr,
    int nPoints);
MODULE_SCOPE void RbcBitmapToPostScript(
    RbcPsToken * psToken,
    Display * display,
    Pixmap bitmap,
    double scaleX,
    double scaleY);
MODULE_SCOPE void Rbc2DSegmentsToPostScript(
    RbcPsToken * psToken,
    RbcSegment2D * segments,
    int nSegments);

/* rbcSpline.c */
MODULE_SCOPE int RbcQuadraticSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcNaturalSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcSplineInit(
    Tcl_Interp * interp);
MODULE_SCOPE int RbcNaturalParametricSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcExtents2D * extsPtr,
    int isClosed,
    RbcPoint2D * intpPts,
    int nIntpPts);
MODULE_SCOPE int RbcCatromParametricSpline(
    RbcPoint2D * origPts,
    int nOrigPts,
    RbcPoint2D * intpPts,
    int nIntpPts);

/* rbcSwitch.c */
MODULE_SCOPE int RbcProcessSwitches(
    Tcl_Interp * interp,
    RbcSwitchSpec * specs,
    int argc,
    const char **argv,
    char *record,
    int flags);
MODULE_SCOPE int RbcProcessObjSwitches(
    Tcl_Interp * interp,
    RbcSwitchSpec * specPtr,
    int objc,
    Tcl_Obj * const *objv,
    char *record,
    int flags);
MODULE_SCOPE void RbcFreeSwitches(
    RbcSwitchSpec * specs,
    char *record,
    int flags);
MODULE_SCOPE int RbcSwitchChanged(
    RbcSwitchSpec * specs,
    ...);

/* rbcText.c */
MODULE_SCOPE RbcTextLayout *RbcGetTextLayout(
    char *string,
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcGetTextExtents(
    RbcTextStyle * stylePtr,
    char *text,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE void RbcGetBoundingBox(
    int width,
    int height,
    double theta,
    double *widthPtr,
    double *heightPtr,
    RbcPoint2D * points);
MODULE_SCOPE void RbcTranslateAnchor(
    int x,
    int y,
    int width,
    int height,
    Tk_Anchor anchor,
    int *transXPtr,
    int *transYPtr);
MODULE_SCOPE RbcPoint2D RbcTranslatePoint(
    RbcPoint2D * pointPtr,
    int width,
    int height,
    Tk_Anchor anchor);
MODULE_SCOPE Pixmap RbcCreateTextBitmap(
    Tk_Window tkwin,
    RbcTextLayout * textPtr,
    RbcTextStyle * stylePtr,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE void RbcInitTextStyle(
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcSetDrawTextStyle(
    RbcTextStyle * stylePtr,
    Tk_Font font,
    GC gc,
    XColor * normalColor,
    XColor * activeColor,
    XColor * shadowColor,
    double theta,
    Tk_Anchor anchor,
    Tk_Justify justify,
    int leader,
    int shadowOffset);
MODULE_SCOPE void RbcSetPrintTextStyle(
    RbcTextStyle * stylePtr,
    Tk_Font font,
    XColor * fgColor,
    XColor * bgColor,
    XColor * shadowColor,
    double theta,
    Tk_Anchor anchor,
    Tk_Justify justify,
    int leader,
    int shadowOffset);
MODULE_SCOPE void RbcDrawTextLayout(
    Tk_Window tkwin,
    Drawable drawable,
    RbcTextLayout * textPtr,
    RbcTextStyle * stylePtr,
    int x,
    int y);
MODULE_SCOPE void RbcDrawText2(
    Tk_Window tkwin,
    Drawable drawable,
    char *string,
    RbcTextStyle * stylePtr,
    int x,
    int y,
    RbcDim2D * dimPtr);
MODULE_SCOPE void RbcDrawText(
    Tk_Window tkwin,
    Drawable drawable,
    char *string,
    RbcTextStyle * stylePtr,
    int x,
    int y);
MODULE_SCOPE GC RbcGetBitmapGC(
    Tk_Window tkwin);
MODULE_SCOPE void RbcResetTextStyle(
    Tk_Window tkwin,
    RbcTextStyle * stylePtr);
MODULE_SCOPE void RbcFreeTextStyle(
    Display * display,
    RbcTextStyle * stylePtr);

/* rbcTile.c */
MODULE_SCOPE int RbcGetTile(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *imageName,
    RbcTile * tilePtr);
MODULE_SCOPE void RbcFreeTile(
    RbcTile tile);
MODULE_SCOPE const char *RbcNameOfTile(
    RbcTile tile);
Pixmap          RbcPixmapOfTile(
    RbcTile tile);
MODULE_SCOPE void RbcSizeOfTile(
    RbcTile tile,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE void RbcSetTileChangedProc(
    RbcTile tile,
    RbcTileChangedProc * changeProc,
    ClientData clientData);
MODULE_SCOPE void RbcSetTileOrigin(
    Tk_Window tkwin,
    RbcTile tile,
    int x,
    int y);
MODULE_SCOPE void RbcSetTSOrigin(
    Tk_Window tkwin,
    RbcTile tile,
    int x,
    int y);
MODULE_SCOPE void RbcTilePolygon(
    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    XPoint * pointArr,
    int nPoints);
MODULE_SCOPE void RbcTileRectangle(
    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    int x,
    int y,
    unsigned int width,
    unsigned int height);
MODULE_SCOPE void RbcTileRectangles(
    Tk_Window tkwin,
    Drawable drawable,
    RbcTile tile,
    XRectangle * rectArr,
    int nRects);

/* rbcUtil.c */
MODULE_SCOPE char *RbcItoa(
    int value);
MODULE_SCOPE char *RbcUtoa(
    unsigned int value);
MODULE_SCOPE char *RbcDtoa(
    Tcl_Interp * interp,
    double value);
MODULE_SCOPE RbcUid RbcGetUid(
    const char *string);
MODULE_SCOPE void RbcFreeUid(
    RbcUid uid);
MODULE_SCOPE RbcUid RbcFindUid(
    char *string);
MODULE_SCOPE RbcOp RbcGetOp(
    Tcl_Interp * interp,
    int nSpecs,
    RbcOpSpec * specArr,
    int operPos,
    int argc,
    const char **argv,
    int flags);
MODULE_SCOPE RbcOp RbcGetOpFromObj(
    Tcl_Interp * interp,
    int nSpecs,
    RbcOpSpec * specArr,
    int operPos,
    int objc,
    Tcl_Obj * const *objv,
    int flags);

/* rbcVecMath.c */
MODULE_SCOPE void RbcVectorInstallMathFunctions(
    Tcl_HashTable * tablePtr);
MODULE_SCOPE void RbcVectorInstallSpecialIndices(
    Tcl_HashTable * tablePtr);
MODULE_SCOPE double RbcVecMin(
    RbcVector * vecPtr);
MODULE_SCOPE double RbcVecMax(
    RbcVector * vecPtr);
MODULE_SCOPE int RbcExprVector(
    Tcl_Interp * interp,
    char *string,
    RbcVector * vecPtr);

/* rbcVecObjCmd.c */
MODULE_SCOPE int RbcAppendOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcArithOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcBinreadOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcClearOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcDeleteOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcDupOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcExprOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcIndexOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcLengthOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcMergeOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcNormalizeOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcOffsetOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcPopulateOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcRandomOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcRangeOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcSearchOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcSeqOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcSetOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcSortOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcSplitOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int RbcVariableOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
MODULE_SCOPE int *RbcVectorSortIndex(
    RbcVectorObject ** vPtrPtr,
    int nVectors);

/* rbcVector.c */
MODULE_SCOPE double Rbcdrand48(
    void);
MODULE_SCOPE int RbcVectorInit(
    Tcl_Interp * interp);
MODULE_SCOPE RbcVectorInterpData *RbcVectorGetInterpData(
    Tcl_Interp * interp);
MODULE_SCOPE RbcVectorObject *RbcVectorNew(
    RbcVectorInterpData * dataPtr);
MODULE_SCOPE RbcVectorObject *RbcVectorCreate(
    RbcVectorInterpData * dataPtr,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int *newPtr);
MODULE_SCOPE void RbcVectorFree(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorDuplicate(
    RbcVectorObject * destPtr,
    RbcVectorObject * srcPtr);
MODULE_SCOPE void RbcVectorFlushCache(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorMapVariable(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *name);
MODULE_SCOPE int RbcVectorReset(
    RbcVectorObject * vPtr,
    double *valueArr,
    int length,
    int size,
    Tcl_FreeProc * freeProc);
MODULE_SCOPE int RbcVectorNotifyPending(
    RbcVectorId clientId);
MODULE_SCOPE int RbcVectorChangeLength(
    RbcVectorObject * vPtr,
    int length);
MODULE_SCOPE int RbcVectorLookupName(
    RbcVectorInterpData * dataPtr,
    const char *vecName,
    RbcVectorObject ** vPtrPtr);
MODULE_SCOPE void RbcVectorUpdateRange(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorGetIndex(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int *indexPtr,
    int flags,
    RbcVectorIndexProc ** procPtrPtr);
MODULE_SCOPE int RbcVectorGetIndexRange(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int flags,
    RbcVectorIndexProc ** procPtrPtr);
RbcVectorObject *RbcVectorParseElement(
    Tcl_Interp * interp,
    RbcVectorInterpData * dataPtr,
    const char *start,
    char **endPtr,
    int flags);
MODULE_SCOPE void RbcVectorUpdateClients(
    RbcVectorObject * vPtr);
MODULE_SCOPE Tcl_Obj *RbcGetValues(
    RbcVectorObject * vPtr,
    int first,
    int last);
MODULE_SCOPE void RbcReplicateValue(
    RbcVectorObject * vPtr,
    int first,
    int last,
    double value);
MODULE_SCOPE int RbcGetDouble(
    Tcl_Interp * interp,
    Tcl_Obj * objPtr,
    double *valuePtr);
MODULE_SCOPE void RbcFreeVectorId(
    RbcVectorId clientId);
MODULE_SCOPE int RbcGetVectorById(
    Tcl_Interp * interp,
    RbcVectorId clientId,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcVectorExists2(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE RbcVectorId RbcAllocVectorId(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE void RbcSetVectorChangedProc(
    RbcVectorId clientId,
    RbcVectorChangedProc * proc,
    ClientData clientData);
MODULE_SCOPE char *RbcNameOfVectorId(
    RbcVectorId clientId);
MODULE_SCOPE int RbcGetVector(
    Tcl_Interp * interp,
    const char *vecName,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcCreateVector2(
    Tcl_Interp * interp,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int initialSize,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcCreateVector(
    Tcl_Interp * interp,
    const char *vecName,
    int size,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcResizeVector(
    RbcVector * vecPtr,
    int nValues);
MODULE_SCOPE char *RbcNameOfVector(
    RbcVector * vecPtr);
MODULE_SCOPE int RbcResetVector(
    RbcVector * vecPtr,
    double *dataArr,
    int nValues,
    int arraySize,
    Tcl_FreeProc * freeProc);

/* rbcWindow.c */
MODULE_SCOPE Tk_Window RbcFindChild(
    Tk_Window parent,
    char *name);
MODULE_SCOPE void RbcSetWindowInstanceData(
    Tk_Window tkwin,
    ClientData instanceData);
MODULE_SCOPE ClientData RbcGetWindowInstanceData(
    Tk_Window tkwin);
MODULE_SCOPE void RbcDeleteWindowInstanceData(
    Tk_Window tkwin);

/* rbcWinImage.c rbcUnixImage.c */
MODULE_SCOPE RbcColorImage *RbcDrawableToColorImage(
    Tk_Window tkwin,
    Drawable drawable,
    int x,
    int y,
    int width,
    int height,
    double inputGamma);
MODULE_SCOPE Pixmap RbcPhotoImageMask(
    Tk_Window tkwin,
    Tk_PhotoImageBlock src);
MODULE_SCOPE Pixmap RbcRotateBitmap(
    Tk_Window tkwin,
    Pixmap bitmap,
    int width,
    int height,
    double theta,
    int *widthPtr,
    int *heightPtr);
MODULE_SCOPE Pixmap RbcScaleBitmap(
    Tk_Window tkwin,
    Pixmap srcBitmap,
    int srcWidth,
    int srcHeight,
    int scaledWidth,
    int scaledHeight);
MODULE_SCOPE Pixmap RbcScaleRotateBitmapRegion(
    Tk_Window tkwin,
    Pixmap srcBitmap,
    unsigned int srcWidth,
    unsigned int srcHeight,
    int regionX,
    int regionY,
    unsigned int regionWidth,
    unsigned int regionHeight,
    unsigned int virtWidth,
    unsigned int virtHeight,
    double theta);

/* rbcScrollbar.c */
#include <tclOO.h>
MODULE_SCOPE int RbcScrollbarInit(
    Tcl_Interp *interp);
MODULE_SCOPE int RbcScrollbarConstructor(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarDestructor(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarActivate(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarCget(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarConfigure(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarDelta(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarFraction(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarGet(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarIdentify(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarSet(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);

/* Windows */
#ifdef _WIN32
#include "rbcWin.h"
#endif

#ifndef _WIN32
#define PurifyPrintf  printf
#endif /* _WIN32 */

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

#endif /* _RBCINT */

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */

Deleted generic/rbc/rbcList.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/*
 * rbcList.c --
 *
 *      The module implements generic linked lists.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"

/* ClientData RbcListGetValue((RbcListNode *node); */
#define RbcListGetValue(node)  	((node)->clientData)
/* void RbcListSetValue((RbcListNode *node, ClientData value); */
#define RbcListSetValue(node, value) \
	((node)->clientData = (ClientData)(value))

#define RbcListAppendNode(list, node) \
	(RbcListLinkBefore((list), (node), (RbcListNode *)NULL))

#define RbcListPrependNode(list, node) \
	(RbcListLinkAfter((list), (node), (RbcListNode *)NULL))

static RbcListNode *FindString(
    RbcList * listPtr,
    const char *key);
static RbcListNode *FindOneWord(
    RbcList * listPtr,
    const char *key);
static RbcListNode *FindArray(
    RbcList * listPtr,
    const char *key);
static void     FreeNode(
    RbcListNode * nodePtr);

/*
 *--------------------------------------------------------------
 *
 * FindString --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static RbcListNode *
FindString(
    RbcList * listPtr,          /* List to search */
    const char *key)
{                               /* Key to match */
    register RbcListNode *nodePtr;
    char            c;

    c = key[0];
    for (nodePtr = listPtr->headPtr; nodePtr != NULL;
        nodePtr = nodePtr->nextPtr) {
        if ((c == nodePtr->key.string[0]) &&
            (strcmp(key, nodePtr->key.string) == 0)) {
            return nodePtr;
        }
    }
    return NULL;
}

/*
 *--------------------------------------------------------------
 *
 * FindOneWord --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static RbcListNode *
FindOneWord(
    RbcList * listPtr,          /* List to search */
    const char *key)
{                               /* Key to match */
    register RbcListNode *nodePtr;

    for (nodePtr = listPtr->headPtr; nodePtr != NULL;
        nodePtr = nodePtr->nextPtr) {
        if (key == nodePtr->key.oneWordValue) {
            return nodePtr;
        }
    }
    return NULL;
}

/*
 *--------------------------------------------------------------
 *
 * FindArray --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static RbcListNode *
FindArray(
    RbcList * listPtr,          /* List to search */
    const char *key)
{                               /* Key to match */
    register RbcListNode *nodePtr;
    int             nBytes;

    nBytes = sizeof(int) * listPtr->type;
    for (nodePtr = listPtr->headPtr; nodePtr != NULL;
        nodePtr = nodePtr->nextPtr) {
        if (memcmp(key, nodePtr->key.words, nBytes) == 0) {
            return nodePtr;
        }
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeNode --
 *
 *      Free the memory allocated for the node.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
FreeNode(
    RbcListNode * nodePtr)
{
    ckfree((char *) nodePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListCreate --
 *
 *      Creates a new linked list structure and initializes its pointers
 *
 * Results:
 *      Returns a pointer to the newly created list structure.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
RbcList        *
RbcListCreate(
    int type)
{
    RbcList        *listPtr;

    listPtr = (RbcList *) ckalloc(sizeof(RbcList));
    if (listPtr != NULL) {
        RbcListInit(listPtr, type);
    }
    return listPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListCreateNode --
 *
 *      Creates a list node holder.  This routine does not insert
 *      the node into the list, nor does it no attempt to maintain
 *      consistency of the keys.  For example, more than one node
 *      may use the same key.
 *
 * Results:
 *      The return value is the pointer to the newly created node.
 *
 * Side Effects:
 *      The key is not copied, only the Uid is kept.  It is assumed
 *      this key will not change in the life of the node.
 *
 *----------------------------------------------------------------------
 */
RbcListNode    *
RbcListCreateNode(
    RbcList * listPtr,
    const char *key)
{                               /* Unique key to reference object */
    register RbcListNode *nodePtr;
    int             keySize;

    if (listPtr->type == TCL_STRING_KEYS) {
        keySize = strlen(key) + 1;
    } else if (listPtr->type == TCL_ONE_WORD_KEYS) {
        keySize = sizeof(int);
    } else {
        keySize = sizeof(int) * listPtr->type;
    }
    nodePtr = RbcCalloc(1, sizeof(RbcListNode) + keySize - 4);
    assert(nodePtr);
    nodePtr->clientData = NULL;
    nodePtr->nextPtr = nodePtr->prevPtr = NULL;
    nodePtr->listPtr = listPtr;
    switch (listPtr->type) {
    case TCL_STRING_KEYS:
        strcpy(nodePtr->key.string, key);
        break;
    case TCL_ONE_WORD_KEYS:
        nodePtr->key.oneWordValue = key;
        break;
    default:
        memcpy(nodePtr->key.words, key, keySize);
        break;
    }
    return nodePtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListReset --
 *
 *      Removes all the entries from a list, removing pointers to the
 *      objects and keys (not the objects or keys themselves).  The
 *      node counter is reset to zero.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcListReset(
    RbcList * listPtr)
{                               /* List to clear */
    if (listPtr != NULL) {
        register RbcListNode *oldPtr;
        register RbcListNode *nodePtr = listPtr->headPtr;

        while (nodePtr != NULL) {
            oldPtr = nodePtr;
            nodePtr = nodePtr->nextPtr;
            FreeNode(oldPtr);
        }
        RbcListInit(listPtr, listPtr->type);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListDestroy
 *
 *     Frees all list structures
 *
 * Results:
 *      Returns a pointer to the newly created list structure.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcListDestroy(
    RbcList * listPtr)
{
    if (listPtr != NULL) {
        RbcListReset(listPtr);
        ckfree((char *) listPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListInit --
 *
 *      Initializes a linked list.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcListInit(
    RbcList * listPtr,
    int type)
{
    listPtr->nNodes = 0;
    listPtr->headPtr = listPtr->tailPtr = NULL;
    listPtr->type = type;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListLinkAfter --
 *
 *      Inserts an node following a given node.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcListLinkAfter(
    RbcList * listPtr,
    RbcListNode * nodePtr,
    RbcListNode * afterPtr)
{
    if (listPtr->headPtr == NULL) {
        listPtr->tailPtr = listPtr->headPtr = nodePtr;
    } else {
        if (afterPtr == NULL) {
            /* Prepend to the front of the list */
            nodePtr->nextPtr = listPtr->headPtr;
            nodePtr->prevPtr = NULL;
            listPtr->headPtr->prevPtr = nodePtr;
            listPtr->headPtr = nodePtr;
        } else {
            nodePtr->nextPtr = afterPtr->nextPtr;
            nodePtr->prevPtr = afterPtr;
            if (afterPtr == listPtr->tailPtr) {
                listPtr->tailPtr = nodePtr;
            } else {
                afterPtr->nextPtr->prevPtr = nodePtr;
            }
            afterPtr->nextPtr = nodePtr;
        }
    }
    nodePtr->listPtr = listPtr;
    listPtr->nNodes++;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListLinkBefore --
 *
 *      Inserts an node preceding a given node.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcListLinkBefore(
    RbcList * listPtr,          /* List to contain new node */
    RbcListNode * nodePtr,      /* New node to be inserted */
    RbcListNode * beforePtr)
{                               /* Node to link before */
    if (listPtr->headPtr == NULL) {
        listPtr->tailPtr = listPtr->headPtr = nodePtr;
    } else {
        if (beforePtr == NULL) {
            /* Append onto the end of the list */
            nodePtr->nextPtr = NULL;
            nodePtr->prevPtr = listPtr->tailPtr;
            listPtr->tailPtr->nextPtr = nodePtr;
            listPtr->tailPtr = nodePtr;
        } else {
            nodePtr->prevPtr = beforePtr->prevPtr;
            nodePtr->nextPtr = beforePtr;
            if (beforePtr == listPtr->headPtr) {
                listPtr->headPtr = nodePtr;
            } else {
                beforePtr->prevPtr->nextPtr = nodePtr;
            }
            beforePtr->prevPtr = nodePtr;
        }
    }
    nodePtr->listPtr = listPtr;
    listPtr->nNodes++;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListUnlinkNode --
 *
 *      Unlinks an node from the given list. The node itself is
 *      not deallocated, but only removed from the list.
 *
 * Results:
 *      None.
 *
 *----------------------------------------------------------------------
 */
void
RbcListUnlinkNode(
    RbcListNode * nodePtr)
{
    RbcList        *listPtr;

    listPtr = nodePtr->listPtr;
    if (listPtr != NULL) {
        if (listPtr->headPtr == nodePtr) {
            listPtr->headPtr = nodePtr->nextPtr;
        }
        if (listPtr->tailPtr == nodePtr) {
            listPtr->tailPtr = nodePtr->prevPtr;
        }
        if (nodePtr->nextPtr != NULL) {
            nodePtr->nextPtr->prevPtr = nodePtr->prevPtr;
        }
        if (nodePtr->prevPtr != NULL) {
            nodePtr->prevPtr->nextPtr = nodePtr->nextPtr;
        }
        nodePtr->listPtr = NULL;
        listPtr->nNodes--;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListGetNode --
 *
 *      Find the first node matching the key given.
 *
 * Results:
 *      Returns the pointer to the node.  If no node matching
 *      the key given is found, then NULL is returned.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
RbcListNode    *
RbcListGetNode(
    RbcList * listPtr,          /* List to search */
    const char *key)
{                               /* Key to match */
    if (listPtr != NULL) {
        switch (listPtr->type) {
        case TCL_STRING_KEYS:
            return FindString(listPtr, key);
        case TCL_ONE_WORD_KEYS:
            return FindOneWord(listPtr, key);
        default:
            return FindArray(listPtr, key);
        }
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListDeleteNode --
 *
 *      Unlinks and deletes the given node.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcListDeleteNode(
    RbcListNode * nodePtr)
{
    RbcListUnlinkNode(nodePtr);
    FreeNode(nodePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Rb_ListDeleteNodeByKey --
 *
 *      Find the node and free the memory allocated for the node.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
Rb_ListDeleteNodeByKey(
    RbcList * listPtr,
    const char *key)
{
    RbcListNode    *nodePtr;

    nodePtr = RbcListGetNode(listPtr, key);
    if (nodePtr != NULL) {
        RbcListDeleteNode(nodePtr);
    }
}

/*
 *--------------------------------------------------------------
 *
 * RbcListAppend --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
RbcListNode    *
RbcListAppend(
    RbcList * listPtr,
    const char *key,
    ClientData clientData)
{
    RbcListNode    *nodePtr;

    nodePtr = RbcListCreateNode(listPtr, key);
    RbcListSetValue(nodePtr, clientData);
    RbcListAppendNode(listPtr, nodePtr);
    return nodePtr;
}

/*
 *--------------------------------------------------------------
 *
 * RbcListPrepend --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
RbcListNode    *
RbcListPrepend(
    RbcList * listPtr,
    const char *key,
    ClientData clientData)
{
    RbcListNode    *nodePtr;

    nodePtr = RbcListCreateNode(listPtr, key);
    RbcListSetValue(nodePtr, clientData);
    RbcListPrependNode(listPtr, nodePtr);
    return nodePtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListGetNthNode --
 *
 *      Find the node based upon a given position in list.
 *
 * Results:
 *      Returns the pointer to the node, if that numbered element
 *      exists. Otherwise NULL.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
RbcListNode    *
RbcListGetNthNode(
    RbcList * listPtr,          /* List to traverse */
    int position,               /* Index of node to select from front
                                 * or back of the list. */
    int direction)
{
    register RbcListNode *nodePtr;

    if (listPtr != NULL) {
        if (direction > 0) {
            for (nodePtr = listPtr->headPtr; nodePtr != NULL;
                nodePtr = nodePtr->nextPtr) {
                if (position == 0) {
                    return nodePtr;
                }
                position--;
            }
        } else {
            for (nodePtr = listPtr->tailPtr; nodePtr != NULL;
                nodePtr = nodePtr->prevPtr) {
                if (position == 0) {
                    return nodePtr;
                }
                position--;
            }
        }
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcListSort --
 *
 *      Find the node based upon a given position in list.
 *
 * Results:
 *      Returns the pointer to the node, if that numbered element
 *      exists. Otherwise NULL.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcListSort(
    RbcList * listPtr,          /* List to traverse */
    RbcListCompareProc * proc)
{
    RbcListNode   **nodeArr;
    register RbcListNode *nodePtr;
    register int    i;

    if (listPtr->nNodes < 2) {
        return;
    }
    nodeArr =
        (RbcListNode **) ckalloc(sizeof(RbcList *) * (listPtr->nNodes + 1));
    if (nodeArr == NULL) {
        return;                 /* Out of memory. */
    }
    i = 0;
    for (nodePtr = listPtr->headPtr; nodePtr != NULL;
        nodePtr = nodePtr->nextPtr) {
        nodeArr[i++] = nodePtr;
    }
    qsort((char *) nodeArr, listPtr->nNodes,
        sizeof(RbcListNode *), (QSortCompareProc *) proc);

    /* Rethread the list. */
    nodePtr = nodeArr[0];
    listPtr->headPtr = nodePtr;
    nodePtr->prevPtr = NULL;
    for (i = 1; i < listPtr->nNodes; i++) {
        nodePtr->nextPtr = nodeArr[i];
        nodePtr->nextPtr->prevPtr = nodePtr;
        nodePtr = nodePtr->nextPtr;
    }
    listPtr->tailPtr = nodePtr;
    nodePtr->nextPtr = NULL;
    ckfree((char *) nodeArr);
}

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Changes to unix/Makefile.in.

1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
rbcImage.o: $(RBC_DIR)/rbcImage.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcImage.c

rbcInt.o: $(RBC_DIR)/rbcInt.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcInt.c

rbcList.o: $(RBC_DIR)/rbcList.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcList.c

rbcParse.o: $(RBC_DIR)/rbcParse.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcParse.c

rbcPs.o: $(RBC_DIR)/rbcPs.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcPs.c

rbcSpline.o: $(RBC_DIR)/rbcSpline.c






<
<
<







1581
1582
1583
1584
1585
1586
1587



1588
1589
1590
1591
1592
1593
1594
rbcImage.o: $(RBC_DIR)/rbcImage.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcImage.c

rbcInt.o: $(RBC_DIR)/rbcInt.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcInt.c




rbcParse.o: $(RBC_DIR)/rbcParse.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcParse.c

rbcPs.o: $(RBC_DIR)/rbcPs.c
	$(CC) -c $(CC_SWITCHES) $(RBC_DIR)/rbcPs.c

rbcSpline.o: $(RBC_DIR)/rbcSpline.c

Changes to win/Makefile.in.

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
	rbcGrLine.$(OBJEXT) \
	rbcGrMarker.$(OBJEXT) \
	rbcGrMisc.$(OBJEXT) \
	rbcGrPen.$(OBJEXT) \
	rbcGrPs.$(OBJEXT) \
	rbcImage.$(OBJEXT) \
	rbcInt.$(OBJEXT) \
	rbcList.$(OBJEXT) \
	rbcParse.$(OBJEXT) \
	rbcPs.$(OBJEXT) \
	rbcSpline.$(OBJEXT) \
	rbcSwitch.$(OBJEXT) \
	rbcText.$(OBJEXT) \
	rbcTile.$(OBJEXT) \
	rbcUtil.$(OBJEXT) \






<







412
413
414
415
416
417
418

419
420
421
422
423
424
425
	rbcGrLine.$(OBJEXT) \
	rbcGrMarker.$(OBJEXT) \
	rbcGrMisc.$(OBJEXT) \
	rbcGrPen.$(OBJEXT) \
	rbcGrPs.$(OBJEXT) \
	rbcImage.$(OBJEXT) \
	rbcInt.$(OBJEXT) \

	rbcParse.$(OBJEXT) \
	rbcPs.$(OBJEXT) \
	rbcSpline.$(OBJEXT) \
	rbcSwitch.$(OBJEXT) \
	rbcText.$(OBJEXT) \
	rbcTile.$(OBJEXT) \
	rbcUtil.$(OBJEXT) \