Or better, do it in `callback_parse_python_option.

On Mon, Aug 18, 2025 at 7:54 PM Hood Chatham <robert.hood.chat...@gmail.com>
wrote:

> Okay that also doesn't work. Third time is the charm I guess. Have to set
> fNoX after processing the options.
>
> On Mon, Aug 18, 2025 at 7:47 PM Hood Chatham <
> robert.hood.chat...@gmail.com> wrote:
>
>> And that patch is not good because true should be spelled TRUE oops.
>> Here's a correct one.
>>
>> On Mon, Aug 18, 2025 at 2:06 PM Hood Chatham <
>> robert.hood.chat...@gmail.com> wrote:
>>
>>> Without --tty, --python does nothing and there is no indication what is
>>> going wrong. Either `-p` should imply --tty (see attached patch) or passing
>>> one but not the other should print an error and exit with nonzero status.
>>>
>>
From 69b8985ce79d151488f7206a7afc5f87212985a1 Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchat...@gmail.com>
Date: Mon, 18 Aug 2025 14:03:04 +0200
Subject: [PATCH] Make -p/--python imply --tty

Without --tty, -p does nothing.
---
 gnubg.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gnubg.c b/gnubg.c
index 68a223cd..c0e3e95e 100644
--- a/gnubg.c
+++ b/gnubg.c
@@ -4586,6 +4586,7 @@ null_debug(const gchar * UNUSED(dom), GLogLevelFlags UNUSED(logflags), const gch
 
 static char *pchPythonScript = NULL;
 static int fPython = FALSE;
+static int fNoX = FALSE;
 
 static gboolean
 callback_parse_python_option(const gchar *UNUSED(name), const gchar *value, gpointer UNUSED(data), GError **UNUSED(error))
@@ -4596,6 +4597,7 @@ callback_parse_python_option(const gchar *UNUSED(name), const gchar *value, gpoi
         pchPythonScript = NULL;
 
     fPython = TRUE;
+    fNoX |= pchPythonScript != NULL;
 
     return TRUE;
 }
@@ -4612,7 +4614,7 @@ main(int argc, char *argv[])
     char *met = NULL;
 
     static char *pchCommands = NULL, *lang = NULL;
-    static int fNoBearoff = FALSE, fNoX = FALSE, fSplash = FALSE, fNoTTY = FALSE, show_version = FALSE, debug = FALSE;
+    static int fNoBearoff = FALSE, fSplash = FALSE, fNoTTY = FALSE, show_version = FALSE, debug = FALSE;
     GOptionEntry ao[] = {
         {"no-bearoff", 'b', 0, G_OPTION_ARG_NONE, &fNoBearoff,
          N_("Do not use bearoff database"), NULL},
@@ -4621,7 +4623,7 @@ main(int argc, char *argv[])
         {"lang", 'l', 0, G_OPTION_ARG_STRING, &lang,
          N_("Set language to LANG"), "LANG"},
         {"python", 'p', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, callback_parse_python_option,
-         N_("Start in Python mode or evaluate code in FILE and exit"), "FILE"},
+         N_("Start in Python mode or evaluate code in FILE and exit. Implies --tty if used with a FILE argument."), "FILE"},
         {"quiet", 'q', 0, G_OPTION_ARG_NONE, &fQuiet,
          N_("Disable sound effects"), NULL},
         {"no-rc", 'r', 0, G_OPTION_ARG_NONE, &fNoRC,
-- 
2.34.1

Reply via email to