- added ability to use --backend=(curses|user) as wineconsole parameter

- rewrote wineconsole command line option parsing
This commit is contained in:
Eric Pouech 2003-03-04 02:13:25 +00:00 committed by Alexandre Julliard
parent c7b5d0aa58
commit cdfcef2481
1 changed files with 74 additions and 41 deletions

View File

@ -661,16 +661,54 @@ static BOOL WINECON_Spawn(struct inner_data* data, LPWSTR cmdLine)
return done; return done;
} }
struct wc_init {
LPCSTR ptr;
enum {from_event, from_process_name} mode;
BOOL (*backend)(struct inner_data*);
HANDLE event;
};
/****************************************************************** /******************************************************************
* WINECON_HasEvent * WINECON_ParseOptions
* *
* *
*/ */
static BOOL WINECON_HasEvent(LPCSTR ptr, unsigned* evt) static BOOL WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci)
{ {
while (*ptr == ' ' || *ptr == '\t') ptr++; memset(wci, 0, sizeof(*wci));
if (strncmp(ptr, "--use-event=", 12)) return FALSE; wci->ptr = lpCmdLine;
return sscanf(ptr + 12, "%d", evt) == 1; wci->mode = from_process_name;
wci->backend = WCCURSES_InitBackend;
for (;;)
{
while (*wci->ptr == ' ' || *wci->ptr == '\t') wci->ptr++;
if (wci->ptr[0] != '-') break;
if (strncmp(wci->ptr, "--use-event=", 12) == 0)
{
char* end;
wci->event = (HANDLE)strtol(wci->ptr + 12, &end, 10);
if (end == wci->ptr + 12) return FALSE;
wci->mode = from_event;
wci->ptr = end;
}
else if (strncmp(wci->ptr, "--backend=", 10) == 0)
{
if (strncmp(wci->ptr + 10, "user", 4) == 0)
{
wci->backend = WCUSER_InitBackend;
wci->ptr += 14;
}
else if (strncmp(wci->ptr + 10, "curses", 6) == 0)
{
wci->ptr += 16;
}
else
return FALSE;
}
}
return TRUE;
} }
/****************************************************************** /******************************************************************
@ -680,52 +718,48 @@ static BOOL WINECON_HasEvent(LPCSTR ptr, unsigned* evt)
* wineconsole --use-event=<int> used when a new console is created (AllocConsole) * wineconsole --use-event=<int> used when a new console is created (AllocConsole)
* wineconsole <pgm> <arguments> used to start the program <pgm> from the command line in * wineconsole <pgm> <arguments> used to start the program <pgm> from the command line in
* a freshly created console * a freshly created console
* --backend=(curses|user) can also be used to select the desired backend
*/ */
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdShow) int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdShow)
{ {
struct inner_data* data; struct inner_data* data;
int ret = 1; int ret = 1;
unsigned evt; struct wc_init wci;
if (!WINECON_ParseOptions(lpCmdLine, &wci))
{
WINE_ERR("Wrong command line options\n");
return 0;
}
switch (wci.mode)
{
case from_event:
/* case of wineconsole <evt>, signal process that created us that we're up and running */ /* case of wineconsole <evt>, signal process that created us that we're up and running */
if (WINECON_HasEvent(lpCmdLine, &evt)) if (!(data = WINECON_Init(hInst, 0, NULL, wci.backend))) return 0;
ret = SetEvent(wci.event);
if (!ret) WINE_ERR("SetEvent failed.\n");
break;
case from_process_name:
{ {
if (!(data = WINECON_Init(hInst, 0, NULL, WCUSER_InitBackend))) return 0; const char* src;
ret = SetEvent((HANDLE)evt); LPWSTR dst;
if (!ret)
{
WINE_ERR("SetEvent failed.\n");
goto cleanup;
}
}
else
{
LPWSTR wcmdLine = GetCommandLine() /* we're unicode... */;
LPWSTR src, dst;
WCHAR buffer[256]; WCHAR buffer[256];
/* remove wineconsole from commandline... src = wci.ptr; dst = buffer;
* we could have several ' ' in process command line... so try first space... while (*src && *src != ' ' && (dst - buffer < sizeof(buffer) / sizeof(WCHAR) - 1))
*/ *dst++ = *src++;
/* FIXME:
* the correct way would be to check the existence of the left part of ptr
* (to be a file)
*/
/* FIXME: could also add an option to choose another backend if needed */
while (*wcmdLine && *wcmdLine++ != ' ');
/* FIXME: see above */
src = wcmdLine; dst = buffer;
while (*src && *src != ' ') *dst++ = *src++;
*dst = 0; *dst = 0;
if (!(data = WINECON_Init(hInst, GetCurrentProcessId(), buffer, WCCURSES_InitBackend))) return 0; if (!(data = WINECON_Init(hInst, GetCurrentProcessId(), buffer, wci.backend)))
ret = WINECON_Spawn(data, wcmdLine); return 0;
ret = WINECON_Spawn(data, buffer);
if (!ret) if (!ret)
{ WINE_MESSAGE("wineconsole: spawning client program failed (%s), invalid/missing command line arguments ?\n", wine_dbgstr_w(buffer));
WINE_MESSAGE("wineconsole: spawning client program failed. Invalid/missing command line arguments ?\n");
goto cleanup;
} }
break;
default:
return 0;
} }
if (ret) if (ret)
@ -734,7 +768,6 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdSh
ret = data->fnMainLoop(data); ret = data->fnMainLoop(data);
} }
cleanup:
WINECON_Delete(data); WINECON_Delete(data);
return ret; return ret;