Re: [hatari-devel] Seeing Hatari help on Windows? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] Seeing Hatari help on Windows?
- From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
- Date: Wed, 4 Jun 2025 23:28:32 +0300
- Dkim-filter: OpenDKIM Filter v2.11.0 smtp.dnamail.fi 0E2502113FF0
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=helsinkinet.fi; s=2025-03; t=1749068913; bh=eghApby//MC9IrT3O4s+ekSPPeMkbb1v0aSJP7RaGvM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Xi3BTRcuIg7HQ8pxupDXN5JZzydvYAC/m6mWn25gTnDJJmY0wMK9in3t9ZClW9v70 L99WfyfLhob1bEz6REZJ+4AC6Fp0hztR/fa8rkPRbKpQWJkllbAuzQn09zJBvr5vnk XmnjMUEmzl6Jedy7PgOWxxwOLO8ngexjrsxSfOdmR7t2uKyXURAl4r8HSX/6ZClkEJ m3L5Bc098RudQax1QmOjmkAUTQkVXMqYz22NdTMVfkYNtmh+uKs0RcoE7OhpDAyfKm 2U26Qb4B1LI23eM/KWudzjOCzIAuq5czfWcZbStPvhnNcv5yEKaeRsjK+L7uvKLJHj olkd20/uMthIg==
Hi,
On 3.6.2025 22.35, Christian Zietz wrote:
Eero Tamminen schrieb:
Would e.g. console window disappear immediately on program exit, or e.g.
wait for a key press?
I managed to test your patch in the meantime. When running...
hatari --help
... from the console, a new console window opens, the text scrolls past
(too fast to read), then the new console window immediately closes
again. In other words: As it is, this patch does not really help Windows
users.
Ok, thanks for testing!
If you have time, could you try a second patch (attached)?
On Windows it should open console for some additional error exit cases
(not yet all), and wait for a key press, before exiting on errors.
Simplest test-case for it could be a Hatari shortcut with some unknown
option specified as parameter for it.
- Eero
From c2c9ce5e92eb4f3905f164ff483de5ba0142f71d Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Wed, 4 Jun 2025 23:24:23 +0300
Subject: [PATCH] Open Windows console to show error + wait a key press before
exiting
---
src/gui-win/opencon.c | 24 ++++++++++++++++------
src/gui-win/opencon.h | 1 +
src/includes/main.h | 1 +
src/main.c | 48 +++++++++++++++++++++++++++++++++++--------
src/options.c | 21 +++++++++----------
5 files changed, 69 insertions(+), 26 deletions(-)
diff --git a/src/gui-win/opencon.c b/src/gui-win/opencon.c
index f245cf63..60147444 100644
--- a/src/gui-win/opencon.c
+++ b/src/gui-win/opencon.c
@@ -17,14 +17,26 @@
#include "opencon.h"
#include "../includes/configuration.h"
+static void Win_OpenInternal(void)
+{
+ static bool opened;
+ if (opened)
+ return;
+ opened = true;
+
+ AllocConsole();
+ freopen("CON", "w", stdout);
+ freopen("CON", "r", stdin);
+ freopen("CON", "w", stderr);
+}
void Win_OpenCon(void)
{
if (ConfigureParams.Log.bConsoleWindow)
- {
- AllocConsole();
- freopen("CON", "w", stdout);
- freopen("CON", "r", stdin);
- freopen("CON", "w", stderr);
- }
+ Win_OpenInternal();
+}
+
+void Win_ForceCon(void)
+{
+ Win_OpenInternal();
}
diff --git a/src/gui-win/opencon.h b/src/gui-win/opencon.h
index 76ce8d43..6fb8433e 100644
--- a/src/gui-win/opencon.h
+++ b/src/gui-win/opencon.h
@@ -1,2 +1,3 @@
extern void Win_OpenCon(void);
+extern void Win_ForceCon(void);
diff --git a/src/includes/main.h b/src/includes/main.h
index 8638025e..0312b6fd 100644
--- a/src/includes/main.h
+++ b/src/includes/main.h
@@ -68,5 +68,6 @@ extern void Main_WarpMouse(int x, int y, bool restore);
extern bool Main_ShowCursor(bool show);
extern void Main_EventHandler(void);
extern void Main_SetTitle(const char *title);
+extern void Main_ErrorExit(const char *msg1, const char *msg2, int errval);
#endif /* ifndef HATARI_MAIN_H */
diff --git a/src/main.c b/src/main.c
index cc64f6bd..1ffbf21a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -778,8 +778,7 @@ static void Main_Init(void)
/* Open debug log file */
if (!Log_Init())
{
- fprintf(stderr, "ERROR: logging/tracing initialization failed\n");
- exit(-1);
+ Main_ErrorExit("logging/tracing initialization failed", NULL, -1);
}
Log_Printf(LOG_INFO, PROG_NAME ", compiled on: " __DATE__ ", " __TIME__ "\n");
@@ -787,13 +786,12 @@ static void Main_Init(void)
will be initialized later (failure not fatal). */
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
- fprintf(stderr, "ERROR: could not initialize the SDL library:\n %s\n", SDL_GetError() );
- exit(-1);
+ Main_ErrorExit("could not initialize the SDL library:", SDL_GetError(), -1);
}
if ( IPF_Init() != true )
{
- fprintf(stderr, "ERROR: could not initialize the IPF support\n" );
+ Main_ErrorExit("could not initialize the IPF support", NULL, -1);
exit(-1);
}
@@ -841,10 +839,11 @@ static void Main_Init(void)
}
if (!bTosImageLoaded || bQuitProgram)
{
- if (!bTosImageLoaded)
- fprintf(stderr, "ERROR: failed to load TOS image!\n");
SDL_Quit();
- exit(-2);
+ if (!bTosImageLoaded)
+ Main_ErrorExit("failed to load TOS image", NULL, -2);
+ else
+ exit(-2);
}
IoMem_Init();
@@ -980,6 +979,37 @@ static void Main_StatusbarSetup(void)
Statusbar_UpdateInfo();
}
+/**
+ * Error exit wrapper, to make sure user sees the error messages
+ * also on Windows.
+ *
+ * If message is given, Windows console is opened to show it,
+ * otherwise it's assumed to be already open and relevant
+ * messages shown before calling this.
+ *
+ * User input is waited on Windows, to make sure user sees
+ * the message before console closes.
+ *
+ * Value overrides nQuitValue as process exit/return value.
+ */
+void Main_ErrorExit(const char *msg1, const char *msg2, int errval)
+{
+ if (msg1)
+ {
+#ifdef WIN32
+ Win_ForceCon();
+#endif
+ if (msg2)
+ fprintf(stderr, "ERROR: %s\n\t%s\n", msg1, msg2);
+ else
+ fprintf(stderr, "ERROR: %s!\n", msg1);
+ }
+#ifdef WIN32
+ fputs("<press a key to exit>\n", stderr);
+ (void)fgetc(stdin);
+#endif
+ exit(errval);
+}
/**
* Main
@@ -1010,7 +1040,7 @@ int main(int argc, char *argv[])
if (!Opt_ParseParameters(argc, (const char * const *)argv))
{
Control_RemoveFifo();
- return 1;
+ Main_ErrorExit(NULL, NULL, 1);
}
/* monitor type option might require "reset" -> true */
Configuration_Apply(true);
diff --git a/src/options.c b/src/options.c
index d1b160b9..1af9d29e 100644
--- a/src/options.c
+++ b/src/options.c
@@ -537,6 +537,13 @@ static const opt_t HatariOptions[] = {
*/
static void Opt_ShowVersion(void)
{
+#ifdef WIN32
+ /* Opt_ShowVersion() is called for all info exit paths,
+ * so having this here should enable console for everything
+ * relevant on Windows.
+ */
+ Win_ForceCon();
+#endif
printf("\n" PROG_NAME
" - the Atari ST, STE, TT and Falcon emulator.\n\n"
"Hatari is free software licensed under the GNU General"
@@ -1040,7 +1047,7 @@ static bool Opt_HandleArgument(const char *path)
path = dir;
}
- /* GEMDOS HDD directory (as argument, or for the Atari program)? */
+ /* GEMDOS HDD directory (as path arg, or dir for the Atari program)? */
if (File_DirExists(path))
{
Log_Printf(LOG_DEBUG, "ARG = GEMDOS HD dir: %s\n", path);
@@ -1058,16 +1065,8 @@ static bool Opt_HandleArgument(const char *path)
}
return true;
}
- else
- {
- if (dir)
- {
- /* if dir is set, it should be valid... */
- Log_Printf(LOG_ERROR, "Given atari program path '%s' doesn't exist (anymore?)!\n", dir);
- free(dir);
- exit(1);
- }
- }
+ /* something wrong if path to an existing prg has no valid dir */
+ assert(!dir);
/* disk image? */
if (Floppy_SetDiskFileName(0, path, NULL))
--
2.39.5