-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtkConfig.c
More file actions
2470 lines (2292 loc) · 73 KB
/
Copy pathtkConfig.c
File metadata and controls
2470 lines (2292 loc) · 73 KB
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
/*
* tkConfig.c --
*
* This file contains functions that manage configuration options for
* widgets and other things.
*
* Copyright © 1997-1998 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
/*
* Temporary flag for working on new config package.
*/
#if 0
/*
* used only for removing the old config code
*/
#define __NO_OLD_CONFIG
#endif
#include "tkInt.h"
#include "tkFont.h"
#ifdef _WIN32
#include "tkWinInt.h"
#endif
/*
* The following encoding is used in TK_OPTION_VAR:
*
* if sizeof(type) == sizeof(int) => TK_OPTION_VAR(type) = 0
* if sizeof(type) == 1 => TK_OPTION_VAR(type) = 64
* if sizeof(type) == 2 => TK_OPTION_VAR(type) = 128
* if sizeof(type) == sizeof(long long) => TK_OPTION_VAR(type) = 192
*/
#define TYPE_MASK (((((int)sizeof(int)-1))|3)<<6)
/*
* The following definition keeps track of all of
* the option tables that have been created for a thread.
*/
typedef struct {
bool initialized; /* false means table below needs initializing. */
Tcl_HashTable hashTable;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
/*
* The following two structures are used along with Tk_OptionSpec structures
* to manage configuration options. Tk_OptionSpec is static templates that are
* compiled into the code of a widget or other object manager. However, to
* look up options efficiently we need to supplement the static information
* with additional dynamic information, and this dynamic information may be
* different for each application. Thus we create structures of the following
* two types to hold all of the dynamic information; this is done by
* Tk_CreateOptionTable.
*
* One of the following structures corresponds to each Tk_OptionSpec. These
* structures exist as arrays inside TkOptionTable structures.
*/
typedef struct TkOption {
const Tk_OptionSpec *specPtr;
/* The original spec from the template passed
* to Tk_CreateOptionTable.*/
Tk_Uid dbNameUID; /* The Uid form of the option database
* name. */
Tk_Uid dbClassUID; /* The Uid form of the option database class
* name. */
Tcl_Obj *defaultPtr; /* Default value for this option. */
union {
Tcl_Obj *monoColorPtr; /* For color and border options, this is an
* alternate default value to use on
* monochrome displays. */
struct TkOption *synonymPtr;
/* For synonym options, this points to the
* original entry. */
const struct Tk_ObjCustomOption *custom;
/* For TK_OPTION_CUSTOM. */
} extra;
int flags; /* Miscellaneous flag values; see below for
* definitions. */
} Option;
/*
* Flag bits defined for Option structures:
*
* OPTION_NEEDS_FREEING - 1 means that FreeResources must be invoked to
* free resources associated with the option when
* it is no longer needed.
*/
#define OPTION_NEEDS_FREEING 1
/*
* One of the following exists for each Tk_OptionSpec array that has been
* passed to Tk_CreateOptionTable.
*/
typedef struct OptionTable {
size_t refCount; /* Counts the number of uses of this table
* (the number of times Tk_CreateOptionTable
* has returned it). This can be greater than
* 1 if it is shared along several option
* table chains, or if the same table is used
* for multiple purposes. */
Tcl_HashEntry *hashEntryPtr;/* Hash table entry that refers to this table;
* used to delete the entry. */
struct OptionTable *nextPtr;/* If templatePtr was part of a chain of
* templates, this points to the table
* corresponding to the next template in the
* chain. */
size_t numOptions; /* The number of items in the options array
* below. */
Option options[1]; /* Information about the individual options in
* the table. This must be the last field in
* the structure: the actual size of the array
* will be numOptions, not 1. */
} OptionTable;
/*
* Forward declarations for functions defined later in this file:
*/
static int DoObjConfig(Tcl_Interp *interp, void *recordPtr,
Option *optionPtr, Tcl_Obj *valuePtr,
Tk_Window tkwin, Tk_SavedOption *savePtr);
static void FreeResources(Option *optionPtr, Tcl_Obj *objPtr,
void *internalPtr, Tk_Window tkwin);
static Tcl_Obj * GetConfigList(void *recordPtr,
Option *optionPtr, Tk_Window tkwin);
static Tcl_Obj * GetObjectForOption(void *recordPtr,
Option *optionPtr, Tk_Window tkwin);
static Option * GetOption(const char *name, OptionTable *tablePtr);
static Option * GetOptionFromObj(Tcl_Interp *interp,
Tcl_Obj *objPtr, OptionTable *tablePtr);
static void FreeOptionInternalRep(Tcl_Obj *objPtr);
static void DupOptionInternalRep(Tcl_Obj *, Tcl_Obj *);
/*
* The structure below defines an object type that is used to cache the result
* of looking up an option name. If an object has this type, then its
* internalPtr1 field points to the OptionTable in which it was looked up, and
* the internalPtr2 field points to the entry that matched.
*/
static const Tcl_ObjType optionObjType = {
"option", /* name */
FreeOptionInternalRep, /* freeIntRepProc */
DupOptionInternalRep, /* dupIntRepProc */
NULL, /* updateStringProc */
NULL, /* setFromAnyProc */
TCL_OBJTYPE_V0
};
/*
*--------------------------------------------------------------
*
* Tk_CreateOptionTable --
*
* Given a template for configuration options, this function creates a
* table that may be used to look up options efficiently.
*
* Results:
* Returns a token to a structure that can be passed to functions such as
* Tk_InitOptions, Tk_SetOptions, and Tk_FreeConfigOptions.
*
* Side effects:
* Storage is allocated.
*
*--------------------------------------------------------------
*/
Tk_OptionTable
Tk_CreateOptionTable(
Tcl_Interp *interp, /* Interpreter associated with the application
* in which this table will be used. */
const Tk_OptionSpec *templatePtr)
/* Static information about the configuration
* options. */
{
Tcl_HashEntry *hashEntryPtr;
int newEntry;
OptionTable *tablePtr;
const Tk_OptionSpec *specPtr, *specPtr2;
Option *optionPtr;
size_t numOptions, i;
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
/*
* We use an TSD in the thread to keep a hash table of
* all the option tables we've created for this application. This is
* used for allowing us to share the tables (e.g. in several chains).
* The code below finds the hash table or creates a new one if it
* doesn't already exist.
*/
if (!tsdPtr->initialized) {
Tcl_InitHashTable(&tsdPtr->hashTable, TCL_ONE_WORD_KEYS);
tsdPtr->initialized = true;
}
/*
* See if a table has already been created for this template. If so, just
* reuse the existing table.
*/
hashEntryPtr = Tcl_CreateHashEntry(&tsdPtr->hashTable, (char *)templatePtr,
&newEntry);
if (!newEntry) {
tablePtr = (OptionTable *)Tcl_GetHashValue(hashEntryPtr);
tablePtr->refCount++;
return (Tk_OptionTable)tablePtr;
}
/*
* Count the number of options in the template, then create the table
* structure.
*/
numOptions = 0;
for (specPtr = templatePtr; specPtr->type != TK_OPTION_END; specPtr++) {
numOptions++;
}
tablePtr = (OptionTable *)ckalloc(sizeof(OptionTable) + (numOptions * sizeof(Option)));
tablePtr->refCount = 1;
tablePtr->hashEntryPtr = hashEntryPtr;
tablePtr->nextPtr = NULL;
tablePtr->numOptions = numOptions;
/*
* Initialize all of the Option structures in the table.
*/
for (specPtr = templatePtr, optionPtr = tablePtr->options;
specPtr->type != TK_OPTION_END; specPtr++, optionPtr++) {
optionPtr->specPtr = specPtr;
optionPtr->dbNameUID = NULL;
optionPtr->dbClassUID = NULL;
optionPtr->defaultPtr = NULL;
optionPtr->extra.monoColorPtr = NULL;
optionPtr->flags = 0;
if (specPtr->type == TK_OPTION_SYNONYM) {
/*
* This is a synonym option; find the original option that it refers
* to and create a pointer from the synonym to the origin.
*/
for (specPtr2 = templatePtr, i = 0; ; specPtr2++, i++) {
if (specPtr2->type == TK_OPTION_END) {
Tcl_Panic("Tk_CreateOptionTable couldn't find synonym");
}
if (strcmp(specPtr2->optionName,
(char *)specPtr->clientData) == 0) {
optionPtr->extra.synonymPtr = tablePtr->options + i;
break;
}
}
} else {
if (specPtr->dbName != NULL) {
optionPtr->dbNameUID = Tk_GetUid(specPtr->dbName);
}
if (specPtr->dbClass != NULL) {
optionPtr->dbClassUID = Tk_GetUid(specPtr->dbClass);
}
if (specPtr->defValue != NULL) {
optionPtr->defaultPtr = Tcl_NewStringObj(specPtr->defValue, TCL_INDEX_NONE);
Tcl_IncrRefCount(optionPtr->defaultPtr);
}
if (((specPtr->type == TK_OPTION_COLOR)
|| (specPtr->type == TK_OPTION_BORDER))
&& (specPtr->clientData != NULL)) {
optionPtr->extra.monoColorPtr =
Tcl_NewStringObj((const char *)specPtr->clientData, TCL_INDEX_NONE);
Tcl_IncrRefCount(optionPtr->extra.monoColorPtr);
}
if (specPtr->type == TK_OPTION_CUSTOM) {
/*
* Get the custom parsing, etc., functions.
*/
optionPtr->extra.custom = (const Tk_ObjCustomOption *)specPtr->clientData;
}
}
if (((specPtr->type == TK_OPTION_STRING)
&& (specPtr->internalOffset != TCL_INDEX_NONE))
|| (specPtr->type == TK_OPTION_COLOR)
|| (specPtr->type == TK_OPTION_FONT)
|| (specPtr->type == TK_OPTION_BITMAP)
|| (specPtr->type == TK_OPTION_BORDER)
|| (specPtr->type == TK_OPTION_CURSOR)
|| (specPtr->type == TK_OPTION_CUSTOM)) {
optionPtr->flags |= OPTION_NEEDS_FREEING;
}
}
tablePtr->hashEntryPtr = hashEntryPtr;
Tcl_SetHashValue(hashEntryPtr, tablePtr);
/*
* Finally, check to see if this template chains to another template with
* additional options. If so, call ourselves recursively to create the
* next table(s).
*/
if (specPtr->clientData != NULL) {
tablePtr->nextPtr = (OptionTable *)
Tk_CreateOptionTable(interp, (Tk_OptionSpec *)specPtr->clientData);
}
return (Tk_OptionTable)tablePtr;
}
/*
*----------------------------------------------------------------------
*
* Tk_DeleteOptionTable --
*
* Called to release resources used by an option table when the table is
* no longer needed.
*
* Results:
* None.
*
* Side effects:
* The option table and associated resources (such as additional option
* tables chained off it) are destroyed.
*
*----------------------------------------------------------------------
*/
void
Tk_DeleteOptionTable(
Tk_OptionTable optionTable) /* The option table to delete. */
{
OptionTable *tablePtr = (OptionTable *)optionTable;
Option *optionPtr;
size_t count;
if (tablePtr->refCount-- > 1) {
return;
}
if (tablePtr->nextPtr != NULL) {
Tk_DeleteOptionTable((Tk_OptionTable)tablePtr->nextPtr);
}
for (count = tablePtr->numOptions, optionPtr = tablePtr->options;
count > 0; count--, optionPtr++) {
if (optionPtr->defaultPtr != NULL) {
Tcl_DecrRefCount(optionPtr->defaultPtr);
}
if (((optionPtr->specPtr->type == TK_OPTION_COLOR)
|| (optionPtr->specPtr->type == TK_OPTION_BORDER))
&& (optionPtr->extra.monoColorPtr != NULL)) {
Tcl_DecrRefCount(optionPtr->extra.monoColorPtr);
}
}
Tcl_DeleteHashEntry(tablePtr->hashEntryPtr);
ckfree(tablePtr);
}
/*
*--------------------------------------------------------------
*
* Tk_InitOptions --
*
* This function is invoked when an object such as a widget is created.
* It supplies an initial value for each configuration option (the value
* may come from the option database, a system default, or the default in
* the option table).
*
* Results:
* The return value is TCL_OK if the function completed successfully, and
* TCL_ERROR if one of the initial values was bogus. If an error occurs
* and interp isn't NULL, then an error message will be left in its
* result.
*
* Side effects:
* Fields of recordPtr are filled in with initial values.
*
*--------------------------------------------------------------
*/
int
Tk_InitOptions(
Tcl_Interp *interp, /* Interpreter for error reporting. NULL means
* don't leave an error message. */
void *recordPtr, /* Pointer to the record to configure. Note:
* the caller should have properly initialized
* the record with NULL pointers for each
* option value. */
Tk_OptionTable optionTable, /* The token which matches the config specs
* for the widget in question. */
Tk_Window tkwin) /* Certain options types (such as
* TK_OPTION_COLOR) need fields out of the
* window they are used in to be able to
* calculate their values. Not needed unless
* one of these options is in the configSpecs
* record. */
{
OptionTable *tablePtr = (OptionTable *)optionTable;
Option *optionPtr;
size_t count;
Tk_Uid value;
Tcl_Obj *valuePtr;
enum {
OPTION_DATABASE, SYSTEM_DEFAULT, TABLE_DEFAULT
} source;
/*
* If this table chains to other tables, handle their initialization
* first. That way, if both tables refer to the same field of the record,
* the value in the first table will win.
*/
if (tablePtr->nextPtr != NULL) {
if (Tk_InitOptions(interp, recordPtr,
(Tk_OptionTable)tablePtr->nextPtr, tkwin) != TCL_OK) {
return TCL_ERROR;
}
}
/*
* Iterate over all of the options in the table, initializing each in
* turn.
*/
for (optionPtr = tablePtr->options, count = tablePtr->numOptions;
count > 0; optionPtr++, count--) {
/*
* If we specify TK_OPTION_DONT_SET_DEFAULT, then the user has
* processed and set a default for this already.
*/
if ((optionPtr->specPtr->type == TK_OPTION_SYNONYM) ||
(optionPtr->specPtr->flags & TK_OPTION_DONT_SET_DEFAULT)) {
continue;
}
source = TABLE_DEFAULT;
/*
* We look in three places for the initial value, using the first
* non-NULL value that we find. First, check the option database.
*/
valuePtr = NULL;
if (optionPtr->dbNameUID != NULL) {
value = Tk_GetOption(tkwin, optionPtr->dbNameUID,
optionPtr->dbClassUID);
if (value != NULL) {
valuePtr = Tcl_NewStringObj(value, TCL_INDEX_NONE);
source = OPTION_DATABASE;
}
}
/*
* Second, check for a system-specific default value.
*/
if ((valuePtr == NULL)
&& (optionPtr->dbNameUID != NULL)) {
valuePtr = Tk_GetSystemDefault(tkwin, optionPtr->dbNameUID,
optionPtr->dbClassUID);
if (valuePtr != NULL) {
source = SYSTEM_DEFAULT;
}
}
/*
* Third and last, use the default value supplied by the option table.
* In the case of color objects, we pick one of two values depending
* on whether the screen is mono or color.
*/
if (valuePtr == NULL) {
if ((tkwin != NULL)
&& ((optionPtr->specPtr->type == TK_OPTION_COLOR)
|| (optionPtr->specPtr->type == TK_OPTION_BORDER))
&& (Tk_Depth(tkwin) <= 1)
&& (optionPtr->extra.monoColorPtr != NULL)) {
valuePtr = optionPtr->extra.monoColorPtr;
} else {
valuePtr = optionPtr->defaultPtr;
}
}
if (valuePtr == NULL) {
continue;
}
/*
* Bump the reference count on valuePtr, so that it is strongly
* referenced here, and will be properly free'd when finished,
* regardless of what DoObjConfig does.
*/
Tcl_IncrRefCount(valuePtr);
if (DoObjConfig(interp, recordPtr, optionPtr, valuePtr, tkwin,
NULL) != TCL_OK) {
if (interp != NULL) {
char msg[200];
switch (source) {
case OPTION_DATABASE:
snprintf(msg, 200, "\n (database entry for \"%.50s\")",
optionPtr->specPtr->optionName);
break;
case SYSTEM_DEFAULT:
snprintf(msg, 200, "\n (system default for \"%.50s\")",
optionPtr->specPtr->optionName);
break;
case TABLE_DEFAULT:
snprintf(msg, 200, "\n (default value for \"%.50s\")",
optionPtr->specPtr->optionName);
}
if (tkwin != NULL) {
snprintf(msg + strlen(msg) - 1, 200 - (strlen(msg) - 1), " in widget \"%.50s\")",
Tk_PathName(tkwin));
}
Tcl_AddErrorInfo(interp, msg);
}
Tcl_DecrRefCount(valuePtr);
return TCL_ERROR;
}
Tcl_DecrRefCount(valuePtr);
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* DoObjConfig --
*
* This function applies a new value for a configuration option to the
* record being configured.
*
* Results:
* The return value is TCL_OK if the function completed successfully. If
* an error occurred then TCL_ERROR is returned and an error message is
* left in interp's result, if interp isn't NULL. In addition, if
* oldValuePtrPtr isn't NULL then it *oldValuePtrPtr is filled in with a
* pointer to the option's old value.
*
* Side effects:
* RecordPtr gets modified to hold the new value in the form of a
* Tcl_Obj, an internal representation, or both. The old value is freed
* if oldValuePtrPtr is NULL.
*
*--------------------------------------------------------------
*/
static int
DoObjConfig(
Tcl_Interp *interp, /* Interpreter for error reporting. If NULL,
* then no message is left if an error
* occurs. */
void *recordPtr, /* The record to modify to hold the new option
* value. */
Option *optionPtr, /* Pointer to information about the option. */
Tcl_Obj *valuePtr, /* New value for option. */
Tk_Window tkwin, /* Window in which option will be used (needed
* to allocate resources for some options).
* May be NULL if the option doesn't require
* window-related resources. */
Tk_SavedOption *savedOptionPtr)
/* If NULL, the old value for the option will
* be freed. If non-NULL, the old value will
* be stored here, and it becomes the property
* of the caller (the caller must eventually
* free the old value). */
{
Tcl_Obj **slotPtrPtr, *oldPtr;
void *internalPtr; /* Points to location in record where internal
* representation of value should be stored,
* or NULL. */
void *oldInternalPtr; /* Points to location in which to save old
* internal representation of value. */
Tk_SavedOption internal; /* Used to save the old internal
* representation of the value if
* savedOptionPtr is NULL. */
const Tk_OptionSpec *specPtr;
/*
* Save the old object form for the value, if there is one.
*/
specPtr = optionPtr->specPtr;
if (specPtr->objOffset != TCL_INDEX_NONE) {
slotPtrPtr = (Tcl_Obj **)((char *)recordPtr + specPtr->objOffset);
oldPtr = *slotPtrPtr;
} else {
slotPtrPtr = NULL;
oldPtr = NULL;
}
/*
* Apply the new value in a type-specific way. Also remember the old
* object and internal forms, if they exist.
*/
if (specPtr->internalOffset != TCL_INDEX_NONE) {
internalPtr = (char *)recordPtr + specPtr->internalOffset;
} else {
internalPtr = NULL;
}
if (savedOptionPtr != NULL) {
savedOptionPtr->optionPtr = optionPtr;
savedOptionPtr->valuePtr = oldPtr;
oldInternalPtr = (char *)&savedOptionPtr->internalForm;
} else {
oldInternalPtr = (char *)&internal.internalForm;
}
bool nullOK = (optionPtr->specPtr->flags & TCL_NULL_OK) != 0;
switch (optionPtr->specPtr->type) {
case TK_OPTION_BOOLEAN: {
int newBool;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newBool = -1;
} else if (Tcl_GetBooleanFromObj(nullOK ? NULL : interp, valuePtr, &newBool) != TCL_OK) {
if (nullOK && interp) {
Tcl_AppendResult(interp, "expected boolean value or \"\" but got \"",
Tcl_GetString(valuePtr), "\"", (char *)NULL);
}
return TCL_ERROR;
}
if (internalPtr != NULL) {
if (optionPtr->specPtr->flags & TYPE_MASK) {
if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
*((char *)oldInternalPtr) = *((char *)internalPtr);
*((char *)internalPtr) = (char)newBool;
} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
*((short *)oldInternalPtr) = *((short *)internalPtr);
*((short *)internalPtr) = (short)newBool;
} else {
Tcl_Panic("Invalid flags for %s", "TK_OPTION_BOOLEAN");
}
} else {
*((int *)oldInternalPtr) = *((int *)internalPtr);
*((int *)internalPtr) = newBool;
}
}
break;
}
case TK_OPTION_INT: {
int newInt;
if ((optionPtr->specPtr->flags & TYPE_MASK) == 0) {
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newInt = INT_MIN;
} else if (Tcl_GetIntFromObj(nullOK ? NULL : interp, valuePtr, &newInt) != TCL_OK) {
invalidIntValue:
if (nullOK && interp) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"expected integer or \"\" but got \"%.50s\"", Tcl_GetString(valuePtr)));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "NUMBER", (char *)NULL);
}
return TCL_ERROR;
}
if (internalPtr != NULL) {
*((int *)oldInternalPtr) = *((int *)internalPtr);
*((int *)internalPtr) = newInt;
}
} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TYPE_MASK) {
Tcl_WideInt newWideInt;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newWideInt = (sizeof(long) > sizeof(int)) ? LONG_MIN : LLONG_MIN;
} else if (Tcl_GetWideIntFromObj(nullOK ? NULL : interp, valuePtr, &newWideInt) != TCL_OK) {
goto invalidIntValue;
}
if (internalPtr != NULL) {
if (sizeof(long) > sizeof(int)) {
*((long *)oldInternalPtr) = *((long *)internalPtr);
*((long *)internalPtr) = (long)newWideInt;
} else {
*((long long *)oldInternalPtr) = *((long long *)internalPtr);
*((long long *)internalPtr) = (long long)newWideInt;
}
}
} else {
Tcl_Panic("Invalid flags for %s", "TK_OPTION_INT");
}
break;
}
case TK_OPTION_INDEX: {
Tcl_Size newIndex;
if (TkGetIntForIndex(valuePtr, TCL_INDEX_NONE, 0, &newIndex) != TCL_OK) {
if (interp) {
Tcl_AppendResult(interp, "bad index \"", Tcl_GetString(valuePtr),
"\": must be integer?[+-]integer?, end?[+-]integer?, or \"\"", (char *)NULL);
}
return TCL_ERROR;
}
if (newIndex < INT_MIN) {
newIndex = INT_MIN;
} else if (newIndex > INT_MAX) {
newIndex = INT_MAX;
}
if (internalPtr != NULL) {
*((int *)oldInternalPtr) = *((int *)internalPtr);
*((int *)internalPtr) = (int)newIndex;
}
break;
}
case TK_OPTION_DOUBLE: {
double newDbl;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
#if defined(NAN)
newDbl = NAN;
#else
newDbl = 0.0;
#endif
} else {
if (Tcl_GetDoubleFromObj(nullOK ? NULL : interp, valuePtr, &newDbl) != TCL_OK) {
if (nullOK && interp) {
Tcl_Obj *msg = Tcl_NewStringObj("expected floating-point number or \"\" but got \"", TCL_INDEX_NONE);
Tcl_AppendLimitedToObj(msg, Tcl_GetString(valuePtr), TCL_INDEX_NONE, 50, "");
Tcl_AppendToObj(msg, "\"", TCL_INDEX_NONE);
Tcl_SetObjResult(interp, msg);
Tcl_SetErrorCode(interp, "TCL", "VALUE", "NUMBER", (char *)NULL);
}
return TCL_ERROR;
}
}
if (internalPtr != NULL) {
*((double *)oldInternalPtr) = *((double *)internalPtr);
*((double *)internalPtr) = newDbl;
}
break;
}
case TK_OPTION_STRING: {
char *newStr;
const char *value;
Tcl_Size length;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
}
if (internalPtr != NULL) {
if (valuePtr != NULL) {
value = Tcl_GetStringFromObj(valuePtr, &length);
newStr = (char *)ckalloc(length + 1);
strcpy(newStr, value);
} else {
newStr = NULL;
}
*((char **)oldInternalPtr) = *((char **)internalPtr);
*((char **)internalPtr) = newStr;
}
break;
}
case TK_OPTION_STRING_TABLE: {
int newValue;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newValue = -1;
} else {
if (Tcl_GetIndexFromObjStruct(interp, valuePtr,
optionPtr->specPtr->clientData, sizeof(char *),
optionPtr->specPtr->optionName+1, (nullOK ? TCL_NULL_OK : 0), &newValue) != TCL_OK) {
return TCL_ERROR;
}
if (slotPtrPtr != NULL && valuePtr != NULL) {
valuePtr = Tcl_DuplicateObj(valuePtr);
Tcl_InvalidateStringRep(valuePtr);
}
}
if (internalPtr != NULL) {
if (optionPtr->specPtr->flags & TYPE_MASK) {
if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
*((char *)oldInternalPtr) = *((char *)internalPtr);
*((char *)internalPtr) = (char)newValue;
} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
*((short *)oldInternalPtr) = *((short *)internalPtr);
*((short *)internalPtr) = (short)newValue;
} else {
Tcl_Panic("Invalid flags for %s", "TK_OPTION_STRING_TABLE");
}
} else {
*((int *)oldInternalPtr) = *((int *)internalPtr);
*((int *)internalPtr) = newValue;
}
}
break;
}
case TK_OPTION_COLOR: {
XColor *newPtr;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newPtr = NULL;
} else {
newPtr = Tk_AllocColorFromObj(interp, tkwin, valuePtr);
if (newPtr == NULL) {
return TCL_ERROR;
}
}
if (internalPtr != NULL) {
*((XColor **)oldInternalPtr) = *((XColor **)internalPtr);
*((XColor **)internalPtr) = newPtr;
}
break;
}
case TK_OPTION_FONT: {
Tk_Font newFont;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newFont = NULL;
} else {
newFont = Tk_AllocFontFromObj(interp, tkwin, valuePtr);
if (newFont == NULL) {
return TCL_ERROR;
}
}
if (internalPtr != NULL) {
*((Tk_Font *)oldInternalPtr) = *((Tk_Font *)internalPtr);
*((Tk_Font *)internalPtr) = newFont;
}
break;
}
case TK_OPTION_STYLE: {
Tk_Style newStyle;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newStyle = NULL;
} else {
newStyle = Tk_AllocStyleFromObj(interp, valuePtr);
if (newStyle == NULL) {
return TCL_ERROR;
}
}
if (internalPtr != NULL) {
*((Tk_Style *)oldInternalPtr) = *((Tk_Style *)internalPtr);
*((Tk_Style *)internalPtr) = newStyle;
}
break;
}
case TK_OPTION_BITMAP: {
Pixmap newBitmap;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newBitmap = None;
} else {
newBitmap = Tk_AllocBitmapFromObj(interp, tkwin, valuePtr);
if (newBitmap == None) {
return TCL_ERROR;
}
}
if (internalPtr != NULL) {
*((Pixmap *)oldInternalPtr) = *((Pixmap *)internalPtr);
*((Pixmap *)internalPtr) = newBitmap;
}
break;
}
case TK_OPTION_BORDER: {
Tk_3DBorder newBorder;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newBorder = NULL;
} else {
newBorder = Tk_Alloc3DBorderFromObj(interp, tkwin, valuePtr);
if (newBorder == NULL) {
return TCL_ERROR;
}
}
if (internalPtr != NULL) {
*((Tk_3DBorder *)oldInternalPtr) = *((Tk_3DBorder *)internalPtr);
*((Tk_3DBorder *)internalPtr) = newBorder;
}
break;
}
case TK_OPTION_RELIEF: {
int newRelief;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newRelief = TK_RELIEF_NULL;
} else if (Tcl_GetIndexFromObj(interp, valuePtr, tkReliefStrings,
"relief", (nullOK ? TCL_NULL_OK : 0), &newRelief) != TCL_OK) {
return TCL_ERROR;
}
if (internalPtr != NULL) {
if (optionPtr->specPtr->flags & TYPE_MASK) {
if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
*((char *)oldInternalPtr) = *((char *)internalPtr);
*((char *)internalPtr) = (char)newRelief;
} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
*((short *)oldInternalPtr) = *((short *)internalPtr);
*((short *)internalPtr) = (short)newRelief;
} else {
Tcl_Panic("Invalid flags for %s", "TK_OPTION_RELIEF");
}
} else {
*((int *)oldInternalPtr) = *((int *)internalPtr);
*((int *)internalPtr) = newRelief;
}
}
if (slotPtrPtr != NULL && valuePtr != NULL) {
valuePtr = Tcl_DuplicateObj(valuePtr);
Tcl_InvalidateStringRep(valuePtr);
}
break;
}
case TK_OPTION_CURSOR: {
Tk_Cursor newCursor;
if (nullOK && TkObjIsEmpty(valuePtr)) {
newCursor = NULL;
valuePtr = NULL;
} else {
newCursor = Tk_AllocCursorFromObj(interp, tkwin, valuePtr);
if (newCursor == NULL) {
return TCL_ERROR;
}
}
if (internalPtr != NULL) {
*((Tk_Cursor *)oldInternalPtr) = *((Tk_Cursor *)internalPtr);
*((Tk_Cursor *)internalPtr) = newCursor;
}
Tk_DefineCursor(tkwin, newCursor);
break;
}
case TK_OPTION_JUSTIFY: {
int newJustify;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newJustify = -1;
} else if (Tcl_GetIndexFromObj(interp, valuePtr, tkJustifyStrings,
"justification", (nullOK ? TCL_NULL_OK : 0), &newJustify) != TCL_OK) {
return TCL_ERROR;
}
if (internalPtr != NULL) {
if (optionPtr->specPtr->flags & TYPE_MASK) {
if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
*((char *)oldInternalPtr) = *((char *)internalPtr);
*((char *)internalPtr) = (char)newJustify;
} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
*((short *)oldInternalPtr) = *((short *)internalPtr);
*((short *)internalPtr) = (short)newJustify;
} else {
Tcl_Panic("Invalid flags for %s", "TK_OPTION_JUSTIFY");
}
} else {
*((int *)oldInternalPtr) = *((int *)internalPtr);
*((int *)internalPtr) = newJustify;
}
}
if (slotPtrPtr != NULL && valuePtr != NULL) {
valuePtr = Tcl_DuplicateObj(valuePtr);
Tcl_InvalidateStringRep(valuePtr);
}
break;
}
case TK_OPTION_ANCHOR: {
int newAnchor;
if (nullOK && TkObjIsEmpty(valuePtr)) {
valuePtr = NULL;
newAnchor = -1;
} else if (Tcl_GetIndexFromObj(interp, valuePtr, tkAnchorStrings,
"anchor", (nullOK ? TCL_NULL_OK : 0), &newAnchor) != TCL_OK) {
return TCL_ERROR;
}
if (internalPtr != NULL) {
if (optionPtr->specPtr->flags & TYPE_MASK) {
if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
*((char *)oldInternalPtr) = *((char *)internalPtr);
*((char *)internalPtr) = (char)newAnchor;
} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
*((short *)oldInternalPtr) = *((short *)internalPtr);
*((short *)internalPtr) = (short)newAnchor;
} else {
Tcl_Panic("Invalid flags for %s", "TK_OPTION_JUSTIFY");
}