source: branches/blt4/lang/tcl/src/Switch.h @ 2170

Last change on this file since 2170 was 1383, checked in by gah, 15 years ago

add switch parser to encoding routines

File size: 3.9 KB
Line 
1
2/*
3 * Switch.h --
4 *
5 *      Copyright 1993-2004 George A Howlett.
6 *
7 *      Permission is hereby granted, free of charge, to any person
8 *      obtaining a copy of this software and associated documentation
9 *      files (the "Software"), to deal in the Software without
10 *      restriction, including without limitation the rights to use,
11 *      copy, modify, merge, publish, distribute, sublicense, and/or
12 *      sell copies of the Software, and to permit persons to whom the
13 *      Software is furnished to do so, subject to the following
14 *      conditions:
15 *
16 *      The above copyright notice and this permission notice shall be
17 *      included in all copies or substantial portions of the
18 *      Software.
19 *
20 *      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
21 *      KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
22 *      WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 *      PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
24 *      OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 *      OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
26 *      OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 *      SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30#ifndef SWITCH_H
31#define SWITCH_H
32
33#ifdef HAVE_STDDEF_H
34#  include <stddef.h>
35#endif /* HAVE_STDDEF_H */
36
37#ifndef Offset
38#ifdef offsetof
39#define Offset(type, field) ((int) offsetof(type, field))
40#else
41#define Offset(type, field) ((int) ((char *) &((type *) 0)->field))
42#endif
43#endif /* Offset */
44
45
46typedef int (SwitchParseProc)(ClientData clientData, Tcl_Interp *interp,
47        const char *switchName, Tcl_Obj *valueObjPtr, char *record, int offset,
48        int flags);
49typedef void (SwitchFreeProc)(char *record, int offset, int flags);
50
51typedef struct {
52    SwitchParseProc *parseProc; /* Procedure to parse a switch
53                                 * value and store it in its *
54                                 * converted form in the data *
55                                 * record. */
56
57    SwitchFreeProc *freeProc;   /* Procedure to free a switch. */
58
59    ClientData clientData;      /* Arbitrary one-word value used by
60                                 * switch parser, passed to
61                                 * parseProc. */
62} SwitchCustom;
63
64
65/*
66 * Type values for SwitchSpec structures.  See the user
67 * documentation for details.
68 */
69typedef enum {
70    SWITCH_BOOLEAN,
71    SWITCH_DOUBLE,
72    SWITCH_BITMASK,
73    SWITCH_BITMASK_NEG,
74    SWITCH_FLOAT,
75    SWITCH_INT,
76    SWITCH_INT_NNEG,
77    SWITCH_INT_POS,
78    SWITCH_LIST,
79    SWITCH_LONG,
80    SWITCH_LONG_NNEG,
81    SWITCH_LONG_POS,
82    SWITCH_OBJ,
83    SWITCH_STRING,
84    SWITCH_VALUE,
85    SWITCH_CUSTOM,
86    SWITCH_END
87} SwitchTypes;
88
89
90typedef struct {
91    SwitchTypes type;           /* Type of option, such as
92                                 * SWITCH_COLOR; see definitions
93                                 * below.  Last option in table must
94                                 * have type SWITCH_END. */
95
96    const char *switchName;     /* Switch used to specify option in
97                                 * argv.  NULL means this spec is part
98                                 * of a group. */
99
100    const char *help;           /* Help string. */
101    int offset;                 /* Where in widget record to store
102                                 * value; use Blt_Offset macro to
103                                 * generate values for this. */
104
105    int flags;                  /* Any combination of the values
106                                 * defined below. */
107
108    unsigned int mask;
109
110    SwitchCustom *customPtr;    /* If type is SWITCH_CUSTOM then
111                                 * this is a pointer to info about how
112                                 * to parse and print the option.
113                                 * Otherwise it is irrelevant. */
114} SwitchSpec;
115
116#define SWITCH_DEFAULTS         (0) 
117#define SWITCH_ARGV_PARTIAL     (1<<1)
118#define SWITCH_OBJV_PARTIAL     (1<<1)
119
120/*
121 * Possible flag values for Blt_SwitchSpec structures.  Any bits at or
122 * above BLT_SWITCH_USER_BIT may be used by clients for selecting
123 * certain entries.
124 */
125#define SWITCH_NULL_OK          (1<<0)
126#define SWITCH_DONT_SET_DEFAULT (1<<3)
127#define SWITCH_SPECIFIED        (1<<4)
128#define SWITCH_USER_BIT         (1<<8)
129
130extern int Rp_ParseSwitches(Tcl_Interp *interp, SwitchSpec *specPtr,
131        int objc, Tcl_Obj *const *objv, void *rec, int flags);
132
133extern void Rp_FreeSwitches(SwitchSpec *specs, void *rec, int flags);
134
135extern int Rp_SwitchChanged TCL_VARARGS(SwitchSpec *, specs);
136 
137#endif /* BLT_SWITCH_H */
Note: See TracBrowser for help on using the repository browser.