Commit 9d6761bd authored by Mikołaj Zalewski's avatar Mikołaj Zalewski Committed by Alexandre Julliard

wineconsole: Add usage message and more specific error messages.

parent 18aafc27
...@@ -22,9 +22,11 @@ ...@@ -22,9 +22,11 @@
#include "wine/port.h" #include "wine/port.h"
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
#include "wine/server.h" #include "wine/server.h"
#include "winecon_private.h" #include "winecon_private.h"
#include "winnls.h" #include "winnls.h"
#include "winuser.h"
#include "wine/debug.h" #include "wine/debug.h"
...@@ -36,6 +38,27 @@ void WINECON_Fatal(const char* msg) ...@@ -36,6 +38,27 @@ void WINECON_Fatal(const char* msg)
ExitProcess(0); ExitProcess(0);
} }
static void printf_res(UINT uResId, ...)
{
WCHAR buffer[1024];
CHAR ansi[1024];
va_list args;
va_start(args, uResId);
LoadStringW(GetModuleHandle(NULL), uResId, buffer, sizeof(buffer)/sizeof(WCHAR));
WideCharToMultiByte(CP_UNIXCP, 0, buffer, -1, ansi, sizeof(ansi), NULL, NULL);
vprintf(ansi, args);
va_end(args);
}
static void WINECON_Usage()
{
printf_res(IDS_USAGE_HEADER);
printf_res(IDS_USAGE_BACKEND);
printf_res(IDS_USAGE_COMMAND);
printf_res(IDS_USAGE_FOOTER);
}
/****************************************************************** /******************************************************************
* WINECON_FetchCells * WINECON_FetchCells
* *
...@@ -729,12 +752,16 @@ struct wc_init { ...@@ -729,12 +752,16 @@ struct wc_init {
HANDLE event; HANDLE event;
}; };
#define WINECON_CMD_SHOW_USAGE 0x10000
/****************************************************************** /******************************************************************
* WINECON_ParseOptions * WINECON_ParseOptions
* *
* * RETURNS
* On success: 0
* On error: error string id optionaly with the CMD_SHOW_USAGE flag
*/ */
static BOOL WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci) static UINT WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci)
{ {
memset(wci, 0, sizeof(*wci)); memset(wci, 0, sizeof(*wci));
wci->ptr = lpCmdLine; wci->ptr = lpCmdLine;
...@@ -749,7 +776,7 @@ static BOOL WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci) ...@@ -749,7 +776,7 @@ static BOOL WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci)
{ {
char* end; char* end;
wci->event = (HANDLE)strtol(wci->ptr + 12, &end, 10); wci->event = (HANDLE)strtol(wci->ptr + 12, &end, 10);
if (end == wci->ptr + 12) return FALSE; if (end == wci->ptr + 12) return IDS_CMD_INVALID_EVENT_ID;
wci->mode = from_event; wci->mode = from_event;
wci->ptr = end; wci->ptr = end;
wci->backend = WCUSER_InitBackend; wci->backend = WCUSER_InitBackend;
...@@ -766,13 +793,20 @@ static BOOL WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci) ...@@ -766,13 +793,20 @@ static BOOL WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci)
wci->ptr += 16; wci->ptr += 16;
} }
else else
return FALSE; return IDS_CMD_INVALID_BACKEND;
} }
else else
return FALSE; return IDS_CMD_INVALID_OPTION|WINECON_CMD_SHOW_USAGE;
} }
return TRUE; if (wci->mode == from_event)
return 0;
while (*wci->ptr == ' ' || *wci->ptr == '\t') wci->ptr++;
if (*wci->ptr == 0)
return IDS_CMD_ABOUT|WINECON_CMD_SHOW_USAGE;
return 0;
} }
/****************************************************************** /******************************************************************
...@@ -790,9 +824,11 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdSh ...@@ -790,9 +824,11 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdSh
int ret = 1; int ret = 1;
struct wc_init wci; struct wc_init wci;
if (!WINECON_ParseOptions(lpCmdLine, &wci)) if ((ret = WINECON_ParseOptions(lpCmdLine, &wci)) != 0)
{ {
WINE_ERR("Wrong command line options\n"); printf_res(ret & 0xffff);
if (ret & WINECON_CMD_SHOW_USAGE)
WINECON_Usage();
return 0; return 0;
} }
...@@ -814,7 +850,11 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdSh ...@@ -814,7 +850,11 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdSh
return 0; return 0;
ret = WINECON_Spawn(data, buffer); 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)); {
WINECON_Delete(data);
printf_res(IDS_CMD_LAUNCH_FAILED, wine_dbgstr_a(wci.ptr));
return 0;
}
} }
break; break;
default: default:
......
...@@ -36,6 +36,20 @@ IDS_DLG_TIT_DEFAULT, "Setup - Default settings" ...@@ -36,6 +36,20 @@ IDS_DLG_TIT_DEFAULT, "Setup - Default settings"
IDS_DLG_TIT_CURRENT, "Setup - Current settings" IDS_DLG_TIT_CURRENT, "Setup - Current settings"
IDS_DLG_TIT_ERROR, "Configuration error" IDS_DLG_TIT_ERROR, "Configuration error"
IDS_DLG_ERR_SBWINSIZE, "Screen buffer size must be greater or equal to the window's one" IDS_DLG_ERR_SBWINSIZE, "Screen buffer size must be greater or equal to the window's one"
IDS_CMD_INVALID_EVENT_ID "wineconsole: Couldn't parse event id\n"
IDS_CMD_INVALID_BACKEND "wineconsole: Invalid backend\n"
IDS_CMD_INVALID_OPTION "wineconsole: Unrecognized command line option\n"
IDS_CMD_ABOUT "Starts a program in a Wine console\n"
IDS_CMD_LAUNCH_FAILED "wineconsole: Starting program %s failed.\n"\
"The command is invalid.\n"
IDS_USAGE_HEADER "\nUsage:\n wineconsole [options] <command>\n\nOptions:\n"
IDS_USAGE_BACKEND " --backend={user|ncurses} Choosing user will spawn a new window, ncurses will\n"\
" try to setup the current terminal as a Wine console\n"
IDS_USAGE_COMMAND " <command> The Wine program to launch in the console\n"
IDS_USAGE_FOOTER "\nExample:\n wineconsole cmd\nStarts the Wine command prompt in a Wine console\n\n"
END END
IDD_OPTION DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 140, 105 IDD_OPTION DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 140, 105
......
...@@ -37,6 +37,20 @@ IDS_DLG_TIT_DEFAULT, "Setup - Domylne ustawienia" ...@@ -37,6 +37,20 @@ IDS_DLG_TIT_DEFAULT, "Setup - Domylne ustawienia"
IDS_DLG_TIT_CURRENT, "Setup - Wybrane ustawienia" IDS_DLG_TIT_CURRENT, "Setup - Wybrane ustawienia"
IDS_DLG_TIT_ERROR, "Bd konfiguracji" IDS_DLG_TIT_ERROR, "Bd konfiguracji"
IDS_DLG_ERR_SBWINSIZE, "Wielko bufora ekranu musi by wiksza ni wielko bufora okna." IDS_DLG_ERR_SBWINSIZE, "Wielko bufora ekranu musi by wiksza ni wielko bufora okna."
IDS_CMD_INVALID_EVENT_ID "wineconsole: Zy format 'event id'\n"
IDS_CMD_INVALID_BACKEND "wineconsole: Niewaciwa warto opcji 'backend'\n"
IDS_CMD_INVALID_OPTION "wineconsole: Nieznana opcja na linii polece\n"
IDS_CMD_ABOUT "Uruchamia program w konsoli Wine\n"
IDS_CMD_LAUNCH_FAILED "wineconsole: Nie udao si uruchomi programu %s.\n"\
"Polecenie jest niewaciwe.\n"
IDS_USAGE_HEADER "\nUycie:\n wineconsole [opcje] <polecenie>\n\nOpcje:\n"
IDS_USAGE_BACKEND " --backend={user|ncurses} Wybr 'user' spowoduje wywietlenie nowego okna, 'ncurses'\n"\
" sprbuje przerobi aktualnie uywany terminal na konsol Wine\n"
IDS_USAGE_COMMAND " <command> Program Wine ktry naley uruchomi\n"
IDS_USAGE_FOOTER "\nPrzykad:\n wineconsole cmd\nUruchamia wiersz polece Wine w konsoli Wine\n\n"
END END
IDD_OPTION DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 140, 105 IDD_OPTION DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 140, 105
......
...@@ -40,6 +40,17 @@ ...@@ -40,6 +40,17 @@
#define IDS_FNT_PREVIEW_1 0x201 #define IDS_FNT_PREVIEW_1 0x201
#define IDS_FNT_PREVIEW_2 0x202 #define IDS_FNT_PREVIEW_2 0x202
#define IDS_CMD_INVALID_EVENT_ID 0x300
#define IDS_CMD_INVALID_BACKEND 0x301
#define IDS_CMD_INVALID_OPTION 0x302
#define IDS_CMD_ABOUT 0x303
#define IDS_CMD_LAUNCH_FAILED 0x304
#define IDS_USAGE_HEADER 0x310
#define IDS_USAGE_BACKEND 0x311
#define IDS_USAGE_COMMAND 0x312
#define IDS_USAGE_FOOTER 0x313
/* dialog boxes */ /* dialog boxes */
#define IDD_OPTION 0x0100 #define IDD_OPTION 0x0100
#define IDD_FONT 0x0200 #define IDD_FONT 0x0200
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment