- added ability to use --backend=(curses|user) as wineconsole parameter
- rewrote wineconsole command line option parsing
This commit is contained in:
parent
c7b5d0aa58
commit
cdfcef2481
|
@ -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;
|
||||||
|
|
||||||
/* case of wineconsole <evt>, signal process that created us that we're up and running */
|
if (!WINECON_ParseOptions(lpCmdLine, &wci))
|
||||||
if (WINECON_HasEvent(lpCmdLine, &evt))
|
|
||||||
{
|
{
|
||||||
if (!(data = WINECON_Init(hInst, 0, NULL, WCUSER_InitBackend))) return 0;
|
WINE_ERR("Wrong command line options\n");
|
||||||
ret = SetEvent((HANDLE)evt);
|
return 0;
|
||||||
if (!ret)
|
|
||||||
{
|
|
||||||
WINE_ERR("SetEvent failed.\n");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
switch (wci.mode)
|
||||||
{
|
{
|
||||||
LPWSTR wcmdLine = GetCommandLine() /* we're unicode... */;
|
case from_event:
|
||||||
LPWSTR src, dst;
|
/* case of wineconsole <evt>, signal process that created us that we're up and running */
|
||||||
WCHAR buffer[256];
|
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:
|
||||||
|
{
|
||||||
|
const char* src;
|
||||||
|
LPWSTR dst;
|
||||||
|
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:
|
*dst = 0;
|
||||||
* 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 */
|
if (!(data = WINECON_Init(hInst, GetCurrentProcessId(), buffer, wci.backend)))
|
||||||
src = wcmdLine; dst = buffer;
|
return 0;
|
||||||
while (*src && *src != ' ') *dst++ = *src++;
|
ret = WINECON_Spawn(data, buffer);
|
||||||
*dst = 0;
|
if (!ret)
|
||||||
|
WINE_MESSAGE("wineconsole: spawning client program failed (%s), invalid/missing command line arguments ?\n", wine_dbgstr_w(buffer));
|
||||||
if (!(data = WINECON_Init(hInst, GetCurrentProcessId(), buffer, WCCURSES_InitBackend))) return 0;
|
}
|
||||||
ret = WINECON_Spawn(data, wcmdLine);
|
break;
|
||||||
if (!ret)
|
default:
|
||||||
{
|
return 0;
|
||||||
WINE_MESSAGE("wineconsole: spawning client program failed. Invalid/missing command line arguments ?\n");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
Loading…
Reference in New Issue