Fixed some issues found by winapi_check.
[wine] / programs / wineconsole / wineconsole.c
1 /*
2  * an application for displaying Win32 console
3  *
4  * Copyright 2001, 2002 Eric Pouech
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdio.h>
25 #include "wine/server.h"
26 #include "wine/unicode.h"
27 #include "winecon_private.h"
28
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(wineconsole);
32
33 void WINECON_Fatal(const char* msg)
34 {
35     WINE_ERR("%s\n", msg);
36     ExitProcess(0);
37 }
38
39 /******************************************************************
40  *              WINECON_FetchCells
41  *
42  * updates the local copy of cells (band to update)
43  */
44 void WINECON_FetchCells(struct inner_data* data, int upd_tp, int upd_bm)
45 {
46     SERVER_START_REQ( read_console_output )
47     {
48         req->handle = (obj_handle_t)data->hConOut;
49         req->x      = 0;
50         req->y      = upd_tp;
51         req->mode   = CHAR_INFO_MODE_TEXTATTR;
52         req->wrap   = TRUE;
53         wine_server_set_reply( req, &data->cells[upd_tp * data->curcfg.sb_width],
54                                (upd_bm-upd_tp+1) * data->curcfg.sb_width * sizeof(CHAR_INFO) );
55         wine_server_call( req );
56     }
57     SERVER_END_REQ;
58     data->fnRefresh(data, upd_tp, upd_bm);
59 }
60
61 /******************************************************************
62  *              WINECON_NotifyWindowChange
63  *
64  * Inform server that visible window on sb has changed
65  */
66 void WINECON_NotifyWindowChange(struct inner_data* data)
67 {
68     SERVER_START_REQ( set_console_output_info )
69     {
70         req->handle       = (obj_handle_t)data->hConOut;
71         req->win_left     = data->curcfg.win_pos.X;
72         req->win_top      = data->curcfg.win_pos.Y;
73         req->win_right    = data->curcfg.win_pos.X + data->curcfg.win_width - 1;
74         req->win_bottom   = data->curcfg.win_pos.Y + data->curcfg.win_height - 1;
75         req->mask         = SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW;
76         wine_server_call( req );
77     }
78     SERVER_END_REQ;
79 }
80
81 /******************************************************************
82  *              WINECON_GetHistorySize
83  *
84  *
85  */
86 int     WINECON_GetHistorySize(HANDLE hConIn)
87 {
88     int ret = 0;
89
90     SERVER_START_REQ(get_console_input_info)
91     {
92         req->handle = (obj_handle_t)hConIn;
93         if (!wine_server_call_err( req )) ret = reply->history_size;
94     }
95     SERVER_END_REQ;
96     return ret;
97 }
98
99 /******************************************************************
100  *              WINECON_SetHistorySize
101  *
102  *
103  */
104 BOOL    WINECON_SetHistorySize(HANDLE hConIn, int size)
105 {
106     BOOL        ret;
107
108     SERVER_START_REQ(set_console_input_info)
109     {
110         req->handle = (obj_handle_t)hConIn;
111         req->mask = SET_CONSOLE_INPUT_INFO_HISTORY_SIZE;
112         req->history_size = size;
113         ret = !wine_server_call_err( req );
114     }
115     SERVER_END_REQ;
116     return ret;
117 }
118
119
120 /******************************************************************
121  *              WINECON_GetHistoryMode
122  *
123  *
124  */
125 int     WINECON_GetHistoryMode(HANDLE hConIn)
126 {
127     int ret = 0;
128
129     SERVER_START_REQ(get_console_input_info)
130     {
131         req->handle = (obj_handle_t)hConIn;
132         if (!wine_server_call_err( req )) ret = reply->history_mode;
133     }
134     SERVER_END_REQ;
135     return ret;
136 }
137
138 /******************************************************************
139  *              WINECON_SetHistoryMode
140  *
141  *
142  */
143 BOOL    WINECON_SetHistoryMode(HANDLE hConIn, int mode)
144 {
145     BOOL        ret;
146
147     SERVER_START_REQ(set_console_input_info)
148     {
149         req->handle = (obj_handle_t)hConIn;
150         req->mask = SET_CONSOLE_INPUT_INFO_HISTORY_MODE;
151         req->history_mode = mode;
152         ret = !wine_server_call_err( req );
153     }
154     SERVER_END_REQ;
155     return ret;
156 }
157
158 /******************************************************************
159  *              WINECON_GetConsoleTitle
160  *
161  *
162  */
163 BOOL WINECON_GetConsoleTitle(HANDLE hConIn, WCHAR* buffer, size_t len)
164 {
165     BOOL ret;
166
167     if (len < sizeof(WCHAR)) return FALSE;
168
169     SERVER_START_REQ( get_console_input_info )
170     {
171         req->handle = (obj_handle_t)hConIn;
172         wine_server_set_reply( req, buffer, len - sizeof(WCHAR) );
173         if ((ret = !wine_server_call_err( req )))
174         {
175             len = wine_server_reply_size( reply );
176             buffer[len / sizeof(WCHAR)] = 0;
177         }
178     }
179     SERVER_END_REQ;
180     return ret;
181 }
182
183 /******************************************************************
184  *              WINECON_GrabChanges
185  *
186  * A change occurs, try to figure out which
187  */
188 int     WINECON_GrabChanges(struct inner_data* data)
189 {
190     struct console_renderer_event       evts[256];
191     int i, num, curs = -1;
192     HANDLE h;
193
194     SERVER_START_REQ( get_console_renderer_events )
195     {
196         wine_server_set_reply( req, evts, sizeof(evts) );
197         req->handle = (obj_handle_t)data->hSynchro;
198         if (!wine_server_call_err( req )) num = wine_server_reply_size(reply) / sizeof(evts[0]);
199         else num = 0;
200     }
201     SERVER_END_REQ;
202     if (!num) {WINE_WARN("hmm renderer signaled but no events available\n"); return 1;}
203
204     /* FIXME: should do some event compression here (cursor pos, update) */
205     /* step 1: keep only last cursor pos event */
206     for (i = num - 1; i >= 0; i--)
207     {
208         if (evts[i].event == CONSOLE_RENDERER_CURSOR_POS_EVENT)
209         {
210             if (curs == -1)
211                 curs = i;
212             else
213             {
214                 memmove(&evts[i], &evts[i+1], (num - i - 1) * sizeof(evts[0]));
215                 num--;
216             }
217         }
218     }
219     /* step 2: manage update events */
220     for (i = 0; i < num - 1; i++)
221     {
222         if (evts[i].event == CONSOLE_RENDERER_UPDATE_EVENT &&
223             evts[i+1].event == CONSOLE_RENDERER_UPDATE_EVENT)
224         {
225             /* contiguous */
226             if (evts[i].u.update.bottom + 1 == evts[i+1].u.update.top)
227             {
228                 evts[i].u.update.bottom = evts[i+1].u.update.bottom;
229                 memmove(&evts[i+1], &evts[i+2], (num - i - 2) * sizeof(evts[0]));
230                 num--; i--;
231             }
232             /* already handled cases */
233             else if (evts[i].u.update.top <= evts[i+1].u.update.top &&
234                      evts[i].u.update.bottom >= evts[i+1].u.update.bottom)
235             {
236                 memmove(&evts[i+1], &evts[i+2], (num - i - 2) * sizeof(evts[0]));
237                 num--; i--;
238             }
239         }
240     }
241
242     WINE_TRACE("Events:");
243     for (i = 0; i < num; i++)
244     {
245         switch (evts[i].event)
246         {
247         case CONSOLE_RENDERER_TITLE_EVENT:
248             data->fnSetTitle(data);
249             break;
250         case CONSOLE_RENDERER_ACTIVE_SB_EVENT:
251             SERVER_START_REQ( open_console )
252             {
253                 req->from    = (int)data->hConIn;
254                 req->access  = GENERIC_READ | GENERIC_WRITE;
255                 req->share   = FILE_SHARE_READ | FILE_SHARE_WRITE;
256                 req->inherit = FALSE;
257                 h = wine_server_call_err( req ) ? 0 : (HANDLE)reply->handle;
258             }
259             SERVER_END_REQ;
260             if (WINE_TRACE_ON(wineconsole))
261                 WINE_DPRINTF(" active(%d)", (int)h);
262             if (h)
263             {
264                 CloseHandle(data->hConOut);
265                 data->hConOut = h;
266             }
267             break;
268         case CONSOLE_RENDERER_SB_RESIZE_EVENT:
269             if (data->curcfg.sb_width != evts[i].u.resize.width ||
270                 data->curcfg.sb_height != evts[i].u.resize.height || !data->cells)
271             {
272                 if (WINE_TRACE_ON(wineconsole))
273                     WINE_DPRINTF(" resize(%d,%d)", evts[i].u.resize.width, evts[i].u.resize.height);
274                 data->curcfg.sb_width  = evts[i].u.resize.width;
275                 data->curcfg.sb_height = evts[i].u.resize.height;
276
277                 data->cells = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, data->cells,
278                                           data->curcfg.sb_width * data->curcfg.sb_height * sizeof(CHAR_INFO));
279                 if (!data->cells) WINECON_Fatal("OOM\n");
280                 data->fnResizeScreenBuffer(data);
281                 data->fnComputePositions(data);
282             }
283             break;
284         case CONSOLE_RENDERER_UPDATE_EVENT:
285             if (WINE_TRACE_ON(wineconsole))
286                 WINE_DPRINTF(" update(%d,%d)", evts[i].u.update.top, evts[i].u.update.bottom);
287             WINECON_FetchCells(data, evts[i].u.update.top, evts[i].u.update.bottom);
288             break;
289         case CONSOLE_RENDERER_CURSOR_POS_EVENT:
290             if (evts[i].u.cursor_pos.x != data->cursor.X || evts[i].u.cursor_pos.y != data->cursor.Y)
291             {
292                 data->cursor.X = evts[i].u.cursor_pos.x;
293                 data->cursor.Y = evts[i].u.cursor_pos.y;
294                 data->fnPosCursor(data);
295                 if (WINE_TRACE_ON(wineconsole))
296                     WINE_DPRINTF(" curs-pos(%d,%d)",evts[i].u.cursor_pos.x, evts[i].u.cursor_pos.y);
297             }
298             break;
299         case CONSOLE_RENDERER_CURSOR_GEOM_EVENT:
300             if (evts[i].u.cursor_geom.size != data->curcfg.cursor_size ||
301                 evts[i].u.cursor_geom.visible != data->curcfg.cursor_visible)
302             {
303                 data->fnShapeCursor(data, evts[i].u.cursor_geom.size,
304                                     evts[i].u.cursor_geom.visible, FALSE);
305                 if (WINE_TRACE_ON(wineconsole))
306                     WINE_DPRINTF(" curs-geom(%d,%d)",
307                                  evts[i].u.cursor_geom.size, evts[i].u.cursor_geom.visible);
308             }
309             break;
310         case CONSOLE_RENDERER_DISPLAY_EVENT:
311             if (evts[i].u.display.left != data->curcfg.win_pos.X)
312             {
313                 data->fnScroll(data, evts[i].u.display.left, TRUE);
314                 data->fnPosCursor(data);
315                 if (WINE_TRACE_ON(wineconsole))
316                     WINE_DPRINTF(" h-scroll(%d)", evts[i].u.display.left);
317             }
318             if (evts[i].u.display.top != data->curcfg.win_pos.Y)
319             {
320                 data->fnScroll(data, evts[i].u.display.top, FALSE);
321                 data->fnPosCursor(data);
322                 if (WINE_TRACE_ON(wineconsole))
323                     WINE_DPRINTF(" v-scroll(%d)", evts[i].u.display.top);
324             }
325             if (evts[i].u.display.width != data->curcfg.win_width ||
326                 evts[i].u.display.height != data->curcfg.win_height)
327             {
328                 if (WINE_TRACE_ON(wineconsole))
329                     WINE_DPRINTF(" win-size(%d,%d)", evts[i].u.display.width, evts[i].u.display.height);
330                 data->curcfg.win_width = evts[i].u.display.width;
331                 data->curcfg.win_height = evts[i].u.display.height;
332                 data->fnComputePositions(data);
333             }
334             break;
335         case CONSOLE_RENDERER_EXIT_EVENT:
336             if (WINE_TRACE_ON(wineconsole)) WINE_DPRINTF(". Exit!!\n");
337             return 0;
338         default:
339             WINE_FIXME("Unknown event type (%d)\n", evts[i].event);
340         }
341     }
342
343     if (WINE_TRACE_ON(wineconsole)) WINE_DPRINTF(".\n");
344     return 1;
345 }
346
347 /******************************************************************
348  *              WINECON_SetConfig
349  *
350  * Apply to data all the configuration elements from cfg. This includes modification
351  * of server side equivalent and visual parts.
352  * If force is FALSE, only the changed items are modified.
353  */
354 void     WINECON_SetConfig(struct inner_data* data,
355                            const struct config_data* cfg, BOOL force)
356 {
357     if (force || data->curcfg.cursor_size != cfg->cursor_size ||
358         data->curcfg.cursor_visible != cfg->cursor_visible)
359     {
360         CONSOLE_CURSOR_INFO cinfo;
361         cinfo.dwSize = cfg->cursor_size;
362         /* <FIXME>: this hack is needed to pass thru the invariant test operation on server side
363          * (no notification is sent when invariant operation is requested
364          */
365         cinfo.bVisible = !cfg->cursor_visible;
366         SetConsoleCursorInfo(data->hConOut, &cinfo);
367         /* </FIXME> */
368         cinfo.bVisible = cfg->cursor_visible;
369         /* this shall update (through notif) curcfg */
370         SetConsoleCursorInfo(data->hConOut, &cinfo);
371     }
372     if (force || data->curcfg.history_size != cfg->history_size)
373     {
374         data->curcfg.history_size = cfg->history_size;
375         WINECON_SetHistorySize(data->hConIn, cfg->history_size);
376     }
377     if (force || data->curcfg.history_nodup != cfg->history_nodup)
378     {
379         data->curcfg.history_nodup = cfg->history_nodup;
380         WINECON_SetHistoryMode(data->hConIn, cfg->history_nodup);
381     }
382     data->curcfg.menu_mask = cfg->menu_mask;
383     data->curcfg.quick_edit = cfg->quick_edit;
384     if (force || 1 /* FIXME: font info has changed */)
385     {
386         data->fnSetFont(data, cfg->face_name, cfg->cell_height, cfg->font_weight);
387     }
388     if (force || data->curcfg.def_attr != cfg->def_attr)
389     {
390         data->curcfg.def_attr = cfg->def_attr;
391         SetConsoleTextAttribute(data->hConOut, cfg->def_attr);
392     }
393     if (force || data->curcfg.sb_width != cfg->sb_width ||
394         data->curcfg.sb_height != cfg->sb_height)
395     {
396         COORD       c;
397
398         c.X = cfg->sb_width;
399         c.Y = cfg->sb_height;
400
401         /* this shall update (through notif) curcfg */
402         SetConsoleScreenBufferSize(data->hConOut, c);
403     }
404     if (force || data->curcfg.win_width != cfg->win_width ||
405         data->curcfg.win_height != cfg->win_height)
406     {
407         SMALL_RECT  pos;
408
409         pos.Left = pos.Top = 0;
410         pos.Right = cfg->win_width - 1;
411         pos.Bottom = cfg->win_height - 1;
412         /* this shall update (through notif) curcfg */
413         SetConsoleWindowInfo(data->hConOut, FALSE, &pos);
414     }
415     data->curcfg.exit_on_die = cfg->exit_on_die;
416     /* we now need to gather all events we got from the operations above,
417      * in order to get data correctly updated
418      */
419     WINECON_GrabChanges(data);
420 }
421
422 /******************************************************************
423  *              WINECON_Delete
424  *
425  * Destroy wineconsole internal data
426  */
427 static void WINECON_Delete(struct inner_data* data)
428 {
429     if (!data) return;
430
431     if (data->hConIn)           CloseHandle(data->hConIn);
432     if (data->hConOut)          CloseHandle(data->hConOut);
433     if (data->hSynchro)         CloseHandle(data->hSynchro);
434     if (data->cells)            HeapFree(GetProcessHeap(), 0, data->cells);
435     if (data->fnDeleteBackend)  data->fnDeleteBackend(data);
436     HeapFree(GetProcessHeap(), 0, data);
437 }
438
439 /******************************************************************
440  *              WINECON_Init
441  *
442  * Initialisation part I. Creation of server object (console input and
443  * active screen buffer)
444  */
445 static struct inner_data* WINECON_Init(HINSTANCE hInst, void* pid, LPCWSTR appname,
446                                        BOOL (*backend)(struct inner_data*))
447 {
448     struct inner_data*  data = NULL;
449     DWORD               ret;
450     struct config_data  cfg;
451     STARTUPINFOW        si;
452
453     data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
454     if (!data) return 0;
455
456     GetStartupInfo(&si);
457
458     if (pid == 0)
459     {
460         if (!si.lpTitle) WINECON_Fatal("Should have a title set");
461         appname = si.lpTitle;
462     }
463
464     /* load settings */
465     WINECON_RegLoad(appname, &cfg);
466
467     /* some overrides */
468     if (pid == 0)
469     {
470         if (si.dwFlags & STARTF_USECOUNTCHARS)
471         {
472             cfg.sb_width  = si.dwXCountChars;
473             cfg.sb_height = si.dwYCountChars;
474         }
475         if (si.dwFlags & STARTF_USEFILLATTRIBUTE)
476             cfg.def_attr = si.dwFillAttribute;
477         /* should always be defined */
478     }
479
480     /* the handles here are created without the whistles and bells required by console
481      * (mainly because wineconsole doesn't need it)
482      * - they are not inheritable
483      * - hConIn is not synchronizable
484      */
485     SERVER_START_REQ(alloc_console)
486     {
487         req->access  = GENERIC_READ | GENERIC_WRITE;
488         req->inherit = FALSE;
489         req->pid     = pid;
490         ret = !wine_server_call_err( req );
491         data->hConIn = (HANDLE)reply->handle_in;
492         data->hSynchro = (HANDLE)reply->event;
493     }
494     SERVER_END_REQ;
495     if (!ret) goto error;
496     WINE_TRACE("using hConIn %p, hSynchro event %p\n", data->hConIn, data->hSynchro);
497
498     SERVER_START_REQ( set_console_input_info )
499     {
500         req->handle = (obj_handle_t)data->hConIn;
501         req->mask = SET_CONSOLE_INPUT_INFO_TITLE;
502         wine_server_add_data( req, appname, strlenW(appname) * sizeof(WCHAR) );
503         ret = !wine_server_call_err( req );
504     }
505     SERVER_END_REQ;
506     if (!ret) goto error;
507
508     SERVER_START_REQ(create_console_output)
509     {
510         req->handle_in = (obj_handle_t)data->hConIn;
511         req->access    = GENERIC_WRITE|GENERIC_READ;
512         req->share     = FILE_SHARE_READ|FILE_SHARE_WRITE;
513         req->inherit   = FALSE;
514         ret = !wine_server_call_err( req );
515         data->hConOut  = (HANDLE)reply->handle_out;
516     }
517     SERVER_END_REQ;
518     if (!ret) goto error;
519     WINE_TRACE("using hConOut %p\n", data->hConOut);
520
521     /* filling data->curcfg from cfg */
522     if ((*backend)(data))
523     {
524         WINECON_SetConfig(data, &cfg, TRUE);
525         data->curcfg.registry = cfg.registry;
526         WINECON_DumpConfig("fint", &data->curcfg);
527         return data;
528     }
529
530  error:
531     WINE_ERR("failed to init.\n");
532
533     WINECON_Delete(data);
534     return NULL;
535 }
536
537 /******************************************************************
538  *              WINECON_Spawn
539  *
540  * Spawn the child process when invoked with wineconsole foo bar
541  */
542 static BOOL WINECON_Spawn(struct inner_data* data, LPWSTR cmdLine)
543 {
544     PROCESS_INFORMATION info;
545     STARTUPINFO         startup;
546     BOOL                done;
547
548     /* we're in the case wineconsole <exe> <options>... spawn the new process */
549     memset(&startup, 0, sizeof(startup));
550     startup.cb          = sizeof(startup);
551     startup.dwFlags     = STARTF_USESTDHANDLES;
552
553     /* the attributes of wineconsole's handles are not adequate for inheritance, so
554      * get them with the correct attributes before process creation
555      */
556     if (!DuplicateHandle(GetCurrentProcess(), data->hConIn,  GetCurrentProcess(),
557                          &startup.hStdInput, GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE, TRUE, 0) ||
558         !DuplicateHandle(GetCurrentProcess(), data->hConOut, GetCurrentProcess(),
559                          &startup.hStdOutput, GENERIC_READ|GENERIC_WRITE, TRUE, 0) ||
560         !DuplicateHandle(GetCurrentProcess(), data->hConOut, GetCurrentProcess(),
561                          &startup.hStdError, GENERIC_READ|GENERIC_WRITE, TRUE, 0))
562     {
563         WINE_ERR("Can't dup handles\n");
564         /* no need to delete handles, we're exiting the programm anyway */
565         return FALSE;
566     }
567
568     done = CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, 0L, NULL, NULL, &startup, &info);
569
570     /* we no longer need the handles passed to the child for the console */
571     CloseHandle(startup.hStdInput);
572     CloseHandle(startup.hStdOutput);
573     CloseHandle(startup.hStdError);
574
575     return done;
576 }
577
578 /******************************************************************
579  *               WINECON_HasEvent
580  *
581  *
582  */
583 static BOOL WINECON_HasEvent(LPCSTR ptr, unsigned *evt)
584 {
585     while (*ptr == ' ' || *ptr == '\t') ptr++;
586     if (strncmp(ptr, "--use-event=", 12)) return FALSE;
587     return sscanf(ptr + 12, "%d", evt) == 1;
588 }
589
590 /******************************************************************
591  *              WinMain
592  *
593  * wineconsole can either be started as:
594  *      wineconsole --use-event=<int>   used when a new console is created (AllocConsole)
595  *      wineconsole <pgm> <arguments>   used to start the program <pgm> from the command line in
596  *                                      a freshly created console
597  */
598 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdShow)
599 {
600     struct inner_data*  data;
601     int                 ret = 1;
602     unsigned            evt;
603     BOOL                (*backend)(struct inner_data*);
604
605     backend = WCUSER_InitBackend;
606
607     /* case of wineconsole <evt>, signal process that created us that we're up and running */
608     if (WINECON_HasEvent(lpCmdLine, &evt))
609     {
610         if (!(data = WINECON_Init(hInst, 0, NULL, backend))) return 0;
611         ret = SetEvent((HANDLE)evt);
612         if (!ret)
613         {
614             WINE_ERR("SetEvent failed.\n");
615             goto cleanup;
616         }
617     }
618     else
619     {
620         LPWSTR          wcmdLine = GetCommandLine() /* we're unicode... */;
621         LPWSTR          src, dst;
622         WCHAR           buffer[256];
623
624         /* remove wineconsole from commandline...
625          * we could have several ' ' in process command line... so try first space...
626          */
627         /* FIXME:
628          * the correct way would be to check the existence of the left part of ptr
629          * (to be a file)
630          */
631         while (*wcmdLine && *wcmdLine++ != ' ');
632
633         /* FIXME: see above */
634         src = wcmdLine; dst = buffer;
635         while (*src && *src != ' ') *dst++ = *src++;
636         *dst = 0;
637
638         if (!(data = WINECON_Init(hInst, (void*)GetCurrentProcessId(), buffer, backend))) return 0;
639         ret = WINECON_Spawn(data, wcmdLine);
640         if (!ret)
641         {
642             WINE_MESSAGE("wineconsole: spawning client program failed. Invalid/missing command line arguments ?\n");
643             goto cleanup;
644         }
645     }
646
647     if (ret)
648     {
649         WINE_TRACE("calling MainLoop.\n");
650         ret = data->fnMainLoop(data);
651     }
652
653 cleanup:
654     WINECON_Delete(data);
655
656     return ret;
657 }