summaryrefslogtreecommitdiffstats
path: root/win/tkWinDialog.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-05 10:05:02 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-05 10:05:02 (GMT)
commit8d84051f94d4f786e546b07381f88715511179ad (patch)
treedaeb6810272d6fa838bbedee63814ddb0f8c2021 /win/tkWinDialog.c
parent25bbe5d885af812ffc67b6ad658b483b214044c3 (diff)
downloadtk-8d84051f94d4f786e546b07381f88715511179ad.zip
tk-8d84051f94d4f786e546b07381f88715511179ad.tar.gz
tk-8d84051f94d4f786e546b07381f88715511179ad.tar.bz2
[Bug 3540127]: Better solution, using Tcl_GetIndexFromObj in stead of Tcl_GetIndexFromObjStruct
Diffstat (limited to 'win/tkWinDialog.c')
-rw-r--r--win/tkWinDialog.c53
1 files changed, 19 insertions, 34 deletions
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index a09980a..4d60105 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -585,37 +585,18 @@ GetFileName(
Tcl_DString extString, filterString, dirString, titleString;
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
- enum options {
- FILE_DEFAULT, FILE_TYPES, FILE_INITDIR, FILE_INITFILE, FILE_PARENT,
- FILE_TITLE, FILE_TYPEVARIABLE, FILE_MULTIPLE, FILE_CONFIRMOW
- };
- struct Options {
- const char *name;
- enum options value;
+ static const char *const saveOptionStrings[] = {
+ "-confirmoverwrite", "-defaultextension", "-filetypes", "-initialdir",
+ "-initialfile", "", "-parent", "-title", "-typevariable", NULL
};
- static const struct Options saveOptions[] = {
- {"-confirmoverwrite", FILE_CONFIRMOW},
- {"-defaultextension", FILE_DEFAULT},
- {"-filetypes", FILE_TYPES},
- {"-initialdir", FILE_INITDIR},
- {"-initialfile", FILE_INITFILE},
- {"-parent", FILE_PARENT},
- {"-title", FILE_TITLE},
- {"-typevariable", FILE_TYPEVARIABLE},
- {NULL, FILE_DEFAULT/*ignored*/ }
+ static const char *const openOptionStrings[] = {
+ "", "-defaultextension", "-filetypes", "-initialdir", "-initialfile",
+ "-multiple", "-parent", "-title", "-typevariable", NULL
};
- static const struct Options openOptions[] = {
- {"-defaultextension", FILE_DEFAULT},
- {"-filetypes", FILE_TYPES},
- {"-initialdir", FILE_INITDIR},
- {"-initialfile", FILE_INITFILE},
- {"-multiple", FILE_MULTIPLE},
- {"-parent", FILE_PARENT},
- {"-title", FILE_TITLE},
- {"-typevariable", FILE_TYPEVARIABLE},
- {NULL, FILE_DEFAULT/*ignored*/ }
+ enum options {
+ FILE_CONFIRMOW, FILE_DEFAULT, FILE_TYPES, FILE_INITDIR, FILE_INITFILE,
+ FILE_MULTIPLE, FILE_PARENT, FILE_TITLE, FILE_TYPEVARIABLE
};
- const struct Options *const options = open ? openOptions : saveOptions;
file[0] = '\0';
ZeroMemory(&ofnData, sizeof(OFNData));
@@ -631,17 +612,21 @@ GetFileName(
const char *string;
Tcl_Obj *valuePtr = objv[i + 1];
- if (Tcl_GetIndexFromObjStruct(interp, objv[i], options,
- sizeof(struct Options), "option", 0, &index) != TCL_OK) {
+ if (Tcl_GetIndexFromObj(interp, objv[i],
+ open ? openOptionStrings : saveOptionStrings,
+ "option", 0, &index) != TCL_OK) {
goto end;
- } else if (i + 1 == objc) {
- Tcl_AppendResult(interp, "value for \"", options[index].name,
- "\" missing", NULL);
+ }
+
+ if (i + 1 == objc) {
+ string = Tcl_GetString(objv[i]);
+ Tcl_AppendResult(interp, "value for \"", string, "\" missing",
+ NULL);
goto end;
}
string = Tcl_GetString(valuePtr);
- switch (options[index].value) {
+ switch ((enum options) index) {
case FILE_DEFAULT:
if (string[0] == '.') {
string++;