1
Author: Sergei Golovan <sgolovan@debian.org>
2
Description: Fixes Tk intialization by calling Tk_Init instead of using
3
copied&pasted Tk_Init from older Tk.
4
Bug: https://sourceforge.net/tracker/?func=detail&aid=2585764&group_id=13179&atid=113179
5
Last-Update: 2009-11-12
7
--- expect-5.44.1.15.orig/exp_main_tk.c
8
+++ expect-5.44.1.15/exp_main_tk.c
13
-static char sccsid[] = "@(#) tkAppInit.c 1.19 95/12/23 17:09:24";
14
+/* static char sccsid[] = "@(#) tkAppInit.c 1.19 95/12/23 17:09:24"; */
17
/* Don't use stubs since we are in the main application. */
24
- * Count of number of main windows currently open in this process.
27
-static int numMainWindows;
30
* The variables and table below are used to parse arguments from
31
* the "argv" variable in Tk_Init.
34
-static int synchronize;
35
-static CONST char *name;
36
-static char *display;
37
-static char *geometry;
38
-static char *colormap;
44
static int optcmd_eval();
46
int print_version = 0;
48
static Tk_ArgvInfo argTable[] = {
49
- {"-colormap", TK_ARGV_STRING, (char *) NULL, (char *) &colormap,
50
- "Colormap for main window"},
51
- {"-display", TK_ARGV_STRING, (char *) NULL, (char *) &display,
53
- {"-geometry", TK_ARGV_STRING, (char *) NULL, (char *) &geometry,
54
- "Initial geometry for window"},
55
- {"-name", TK_ARGV_STRING, (char *) NULL, (char *) &name,
56
- "Name to use for application"},
57
- {"-sync", TK_ARGV_CONSTANT, (char *) 1, (char *) &synchronize,
58
- "Use synchronous mode for display server"},
59
- {"-visual", TK_ARGV_STRING, (char *) NULL, (char *) &visual,
60
- "Visual for main window"},
61
- {"--", TK_ARGV_REST, (char *) 1, (char *) &rest,
62
- "Pass all remaining arguments through to script"},
64
{"-command", TK_ARGV_GENFUNC, (char *) optcmd_eval, (char *)0,
65
"Command(s) to execute immediately"},
66
{"-diag", TK_ARGV_CONSTANT, (char *) optcmd_diagToStderr, (char *)0,
68
{"-Debug", TK_ARGV_GENFUNC, (char *) optcmd_debug, (char *)0,
71
+ {"--", TK_ARGV_REST, (char *) 1, (char *) &rest,
72
+ "Pass all remaining arguments through to script"},
73
{(char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
77
Tcl_Interp *interp; /* Interpreter to initialize. */
82
- char **argv, *args[20];
85
+ int argc, length, i, j;
86
+ char **argv, **newargv;
91
* If there is an "argv" variable, get its value, extract out
93
* the arguments that we used.
97
- name = display = geometry = colormap = visual = NULL;
99
p = Tcl_GetVar2(interp, "argv", (char *) NULL, TCL_GLOBAL_ONLY);
102
@@ -299,115 +272,57 @@
106
- alist = Tcl_Merge(argc, argv);
107
- Tcl_SetVar2(interp, "argv", (char *) NULL, alist, TCL_GLOBAL_ONLY);
108
- sprintf(buffer, "%d", argc);
109
- Tcl_SetVar2(interp, "argc", (char *) NULL, buffer, TCL_GLOBAL_ONLY);
114
- * Figure out the application's name and class.
117
+ /* Resore '--' in arguments list
120
- if (name == NULL) {
121
- name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY);
122
- if ((name == NULL) || (*name == 0)) {
125
- p = (char *)strrchr(name, '/'); /* added cast - DEL */
129
+ for (i = 0; i < argc; i++) {
130
+ length += strlen(argv[i]) + 1;
134
- Tcl_DStringInit(&class);
135
- Tcl_DStringAppend(&class, name, -1);
136
- cstr = Tcl_DStringValue(&class);
137
- if (islower(*cstr)) {
138
- *cstr = toupper((unsigned char) *cstr);
142
- * Create an argument list for creating the top-level window,
143
- * using the information parsed from argv, if any.
145
+ newargv = (char **) ckalloc((unsigned) ((argc+2)*sizeof(char *)) + length + 3);
147
- args[0] = "toplevel";
149
- args[2] = "-class";
150
- args[3] = Tcl_DStringValue(&class);
152
- if (display != NULL) {
153
- args[argc] = "-screen";
154
- args[argc+1] = display;
158
- * If this is the first application for this process, save
159
- * the display name in the DISPLAY environment variable so
160
- * that it will be available to subprocesses created by us.
162
+ pp = ((char *) newargv) + (argc+2)*sizeof(char *);
164
+ for (i = 0; i < argc; i++) {
166
+ memcpy(pp, "--", 3);
171
+ len = strlen(argv[i]) + 1;
172
+ memcpy(pp, argv[i], len);
178
- if (numMainWindows == 0) {
179
- Tcl_SetVar2(interp, "env", "DISPLAY", display, TCL_GLOBAL_ONLY);
180
+ alist = Tcl_Merge(argc+1, newargv);
183
+ alist = Tcl_Merge(argc, argv);
186
- if (colormap != NULL) {
187
- args[argc] = "-colormap";
188
- args[argc+1] = colormap;
191
- if (visual != NULL) {
192
- args[argc] = "-visual";
193
- args[argc+1] = visual;
197
- code = TkCreateFrame((ClientData) NULL, interp, argc, args, 1, name);
198
- Tcl_DStringFree(&class);
199
- if (code != TCL_OK) {
202
- Tcl_ResetResult(interp);
205
- XSynchronize(Tk_Display(Tk_MainWindow(interp)), True);
210
- * Set the geometry of the main window, if requested. Put the
211
- * requested geometry into the "geometry" variable.
214
- if (geometry != NULL) {
215
- Tcl_SetVar(interp, "geometry", geometry, TCL_GLOBAL_ONLY);
216
- code = Tcl_VarEval(interp, "wm geometry . ", geometry, (char *) NULL);
217
- if (code != TCL_OK) {
221
- if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 1) == NULL) {
225
- code = Tcl_PkgProvide(interp, "Tk", TK_VERSION);
226
- if (code != TCL_OK) {
228
+ Tcl_SetVar2(interp, "argv", (char *) NULL, alist, TCL_GLOBAL_ONLY);
229
+ sprintf(buffer, "%d", argc);
230
+ Tcl_SetVar2(interp, "argc", (char *) NULL, buffer, TCL_GLOBAL_ONLY);
235
- * Invoke platform-specific initialization.
238
- code = TkpInit(interp, 0);
239
+ if (Tk_Init(interp) == TCL_ERROR) {
245
ckfree((char *) argv);
248
+ if (newargv != NULL) {
249
+ ckfree((char *) newargv);