Mikołaj Zalewski : wineconsole: Add usage message and more specific error messages.
Alexandre Julliard
julliard at wine.codeweavers.com
Fri Oct 20 08:00:34 CDT 2006
Module: wine
Branch: master
Commit: 9d6761bd0c9d5b0d306cadf85a991fdeef8920b2
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9d6761bd0c9d5b0d306cadf85a991fdeef8920b2
Author: MikoÅaj Zalewski <mikolaj at zalewski.pl>
Date: Thu Oct 19 19:21:17 2006 +0200
wineconsole: Add usage message and more specific error messages.
---
programs/wineconsole/wineconsole.c | 58 +++++++++++++++++++++++++++-----
programs/wineconsole/wineconsole_En.rc | 14 ++++++++
programs/wineconsole/wineconsole_Pl.rc | 14 ++++++++
programs/wineconsole/wineconsole_res.h | 11 ++++++
4 files changed, 88 insertions(+), 9 deletions(-)
diff --git a/programs/wineconsole/wineconsole.c b/programs/wineconsole/wineconsole.c
index edf0fa8..434bac5 100644
--- a/programs/wineconsole/wineconsole.c
+++ b/programs/wineconsole/wineconsole.c
@@ -22,9 +22,11 @@ #include "config.h"
#include "wine/port.h"
#include <stdio.h>
+#include <stdarg.h>
#include "wine/server.h"
#include "winecon_private.h"
#include "winnls.h"
+#include "winuser.h"
#include "wine/debug.h"
@@ -36,6 +38,27 @@ void WINECON_Fatal(const char* msg)
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
*
@@ -729,12 +752,16 @@ struct wc_init {
HANDLE event;
};
+#define WINECON_CMD_SHOW_USAGE 0x10000
+
/******************************************************************
* 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));
wci->ptr = lpCmdLine;
@@ -749,7 +776,7 @@ static BOOL WINECON_ParseOptions(const c
{
char* end;
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->ptr = end;
wci->backend = WCUSER_InitBackend;
@@ -766,13 +793,20 @@ static BOOL WINECON_ParseOptions(const c
wci->ptr += 16;
}
else
- return FALSE;
+ return IDS_CMD_INVALID_BACKEND;
}
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, HINS
int ret = 1;
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;
}
@@ -814,7 +850,11 @@ int PASCAL WinMain(HINSTANCE hInst, HINS
return 0;
ret = WINECON_Spawn(data, buffer);
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;
default:
diff --git a/programs/wineconsole/wineconsole_En.rc b/programs/wineconsole/wineconsole_En.rc
index 7ecbf7c..2b159f7 100644
--- a/programs/wineconsole/wineconsole_En.rc
+++ b/programs/wineconsole/wineconsole_En.rc
@@ -36,6 +36,20 @@ IDS_DLG_TIT_DEFAULT, "Setup - Default
IDS_DLG_TIT_CURRENT, "Setup - Current settings"
IDS_DLG_TIT_ERROR, "Configuration error"
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
IDD_OPTION DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 140, 105
diff --git a/programs/wineconsole/wineconsole_Pl.rc b/programs/wineconsole/wineconsole_Pl.rc
index 693ee73..2ca4e48 100644
--- a/programs/wineconsole/wineconsole_Pl.rc
+++ b/programs/wineconsole/wineconsole_Pl.rc
@@ -37,6 +37,20 @@ IDS_DLG_TIT_DEFAULT, "Setup - Domyln
IDS_DLG_TIT_CURRENT, "Setup - Wybrane ustawienia"
IDS_DLG_TIT_ERROR, "B³¹d konfiguracji"
IDS_DLG_ERR_SBWINSIZE, "Wielkoæ bufora ekranu musi byæ wiêksza ni¿ wielkoæ bufora okna."
+
+IDS_CMD_INVALID_EVENT_ID "wineconsole: Z³y format 'event id'\n"
+IDS_CMD_INVALID_BACKEND "wineconsole: Niew³aciwa 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 uda³o siê uruchomiæ programu %s.\n"\
+ "Polecenie jest niew³aciwe.\n"
+
+IDS_USAGE_HEADER "\nU¿ycie:\n wineconsole [opcje] <polecenie>\n\nOpcje:\n"
+IDS_USAGE_BACKEND " --backend={user|ncurses} Wybór 'user' spowoduje wywietlenie nowego okna, 'ncurses'\n"\
+ " spróbuje przerobiæ aktualnie u¿ywany terminal na konsolê Wine\n"
+IDS_USAGE_COMMAND " <command> Program Wine który nale¿y uruchomiæ\n"
+IDS_USAGE_FOOTER "\nPrzyk³ad:\n wineconsole cmd\nUruchamia wiersz poleceñ Wine w konsoli Wine\n\n"
+
END
IDD_OPTION DIALOG LOADONCALL MOVEABLE DISCARDABLE 36, 24, 140, 105
diff --git a/programs/wineconsole/wineconsole_res.h b/programs/wineconsole/wineconsole_res.h
index beef81d..b5518fc 100644
--- a/programs/wineconsole/wineconsole_res.h
+++ b/programs/wineconsole/wineconsole_res.h
@@ -40,6 +40,17 @@ #define IDS_FNT_DISPLAY 0x200
#define IDS_FNT_PREVIEW_1 0x201
#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 */
#define IDD_OPTION 0x0100
#define IDD_FONT 0x0200
More information about the wine-cvs
mailing list