Re: [AD] allegro_message under X |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Peter Wang a écrit :
> If the child fails on the `execlp', you should use `_exit' instead of
> `exit'.
>
> It looks like the message will be written twice if `waitpid' fails.
Ok, modified patch attached.
--
Julien Cugnière
--- src/x/xsystem.c.old 2004-10-23 17:42:29.000000000 +0200
+++ src/x/xsystem.c 2004-10-24 12:01:21.000000000 +0200
@@ -24,6 +24,8 @@
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
@@ -37,6 +39,7 @@
static void _xwin_sysdrv_exit(void);
static void _xwin_sysdrv_set_window_title(AL_CONST char *name);
static int _xwin_sysdrv_set_close_button_callback(void (*proc)(void));
+static void _xwin_sysdrv_message(AL_CONST char *msg);
static int _xwin_sysdrv_display_switch_mode(int mode);
static int _xwin_sysdrv_desktop_color_depth(void);
static int _xwin_sysdrv_get_desktop_resolution(int *width, int *height);
@@ -65,7 +68,7 @@
_unix_find_resource,
_xwin_sysdrv_set_window_title,
_xwin_sysdrv_set_close_button_callback,
- NULL, /* message */
+ _xwin_sysdrv_message,
NULL, /* assert */
NULL, /* save_console_state */
NULL, /* restore_console_state */
@@ -274,6 +277,39 @@
+/* _xwin_sysdrv_message:
+ * Displays a message. Uses xmessage if possible, and stdout if not.
+ */
+static void _xwin_sysdrv_message(AL_CONST char *msg)
+{
+ int ret, status;
+ char *buf = malloc(ALLEGRO_MESSAGE_SIZE);
+ char *msg2 = uconvert(msg, U_CURRENT, buf, U_ASCII_CP, ALLEGRO_MESSAGE_SIZE);
+
+ pid_t pid = fork();
+ switch (pid) {
+ case -1: /* fork error */
+ fputs(msg2, stdout);
+ break;
+
+ case 0: /* child process */
+ execlp("xmessage", "xmessage", "-buttons", "OK", "-default", "OK", "-center", msg2, NULL);
+ /* if execution reaches here, it means execlp failed */
+ _exit(-1);
+ break;
+
+ default: /* parent process */
+ ret = waitpid(pid, &status, 0);
+ if (ret != pid || !WIFEXITED(status) || WEXITSTATUS(status) != 101)
+ fputs(msg2, stdout);
+ break;
+ }
+
+ free(buf);
+}
+
+
+
/* _xwin_sysdrv_gfx_drivers:
* Get the list of graphics drivers.
*/