Re: [AD] allegro_message under X

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Julien Cugnière wrote:

(Yet) another version of my patch for xmessage. The only difference is that
the message to display is now converted to U_ASCII instead of U_ASCII_CP.

I modified the patch so that it passes the string to xmessage via a pipe. This way the message doesn't show up on ps output.

Peter
Index: src/x/xsystem.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xsystem.c,v
retrieving revision 1.28
diff -u -r1.28 xsystem.c
--- src/x/xsystem.c	31 Aug 2004 07:29:29 -0000	1.28
+++ src/x/xsystem.c	28 Oct 2004 06:13:07 -0000
@@ -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,64 @@
 
 
 
+/* _xwin_sysdrv_message:
+ *  Displays a message. Uses xmessage if possible, and stdout if not.
+ */
+static void _xwin_sysdrv_message(AL_CONST char *msg)
+{
+   char buf[ALLEGRO_MESSAGE_SIZE];
+   char *msg2;
+   int fd[2];
+   pid_t pid;
+   int ret, status;
+   int err;
+
+   /* convert message to ASCII */
+   msg2 = uconvert(msg, U_CURRENT, buf, U_ASCII, ALLEGRO_MESSAGE_SIZE);
+
+   /* create a pipe */
+   if (pipe(fd) != 0) {
+      fputs(msg2, stdout);
+      return;
+   }
+
+   /* fork a child */
+   pid = fork();
+   switch (pid) {
+
+      case -1: /* fork error */
+	 close(fd[0]);
+	 close(fd[1]);
+	 fputs(msg2, stdout);
+	 break;
+
+      case 0: /* child process */
+	 if ((close(STDIN_FILENO) != -1)
+	     && (dup2(fd[0], STDIN_FILENO) != -1)
+	     && (close(fd[1]) != -1))
+	 {
+	    execlp("xmessage", "xmessage", "-buttons", "OK", "-default", "OK", "-center", "-file", "-", NULL);
+	 }
+	 /* if execution reaches here, it means execlp failed */
+	 _exit(EXIT_FAILURE);
+	 break;
+
+      default: /* parent process */
+	 if ((close(fd[0]) == -1)
+	     || (write(fd[1], msg2, strlen(msg2)) == -1)
+	     || (close(fd[1]) == -1)
+	     || (waitpid(pid, &status, 0) != pid)
+	     || (!WIFEXITED(status))
+	     || (WEXITSTATUS(status) != 101)) /* ok button */
+	 {
+	    fputs(msg2, stdout);
+	 }
+	 break;
+   }
+}
+
+
+
 /* _xwin_sysdrv_gfx_drivers:
  *  Get the list of graphics drivers.
  */


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/