File fbiterm-exit-code.dif of Package xiterm

--- lib/src/unix/tty/ttyio.c-dist	2004-04-01 17:33:27.000000000 +0200
+++ lib/src/unix/tty/ttyio.c	2004-04-02 13:03:40.174666477 +0200
@@ -11,6 +11,7 @@
 
 #include "iterm/unix/ttyio.h"
 #include "iterm/io.h"
+#include <stdio.h>
 #include <termios.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
@@ -266,6 +267,7 @@ static int dup_fds(int slave_fd)
 }
 
 static pid_t child; /* child process id */
+static int exit_code;
 static char *tty_name; 
 static int tty_read(TerminalIO *tio,void *buf,int size)
 {
@@ -304,7 +306,8 @@ static int tty_tell_window_size(Terminal
 static void finish_child(int signal)
 {
   pid_t pid;
-  pid = wait(NULL);
+  int status;
+  pid = wait(&status);
 
   do {
     if(pid == child || pid == ECHILD)
@@ -313,7 +316,8 @@ static void finish_child(int signal)
       delete_utmp(tty_name);
       break;
     }
-  } while((pid = waitpid(child,NULL,WNOHANG)) > 0);
+  } while((pid = waitpid(child,&status,WNOHANG)) > 0);
+  exit_code = WEXITSTATUS(status);
 }
 
 /*
@@ -421,3 +425,8 @@ int TtyTerminalIO_get_associated_fd(Term
 {
   return tio->concrete_io->fd;
 }
+
+int TtyTerminalIO_get_exit_code(TerminalIO *tio)
+{
+	return exit_code;
+}
--- lib/src/unix/fribidi_layout/concrete_layout.c-dist	2004-04-01 17:34:20.000000000 +0200
+++ lib/src/unix/fribidi_layout/concrete_layout.c	2004-04-01 17:34:29.000000000 +0200
@@ -11,6 +11,7 @@
 #include <wchar.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <string.h>
 
 #include "iterm/vtlayout.h"
 
--- lib/include/iterm/unix/ttyio.h-dist	2004-04-02 12:42:15.104005614 +0200
+++ lib/include/iterm/unix/ttyio.h	2004-04-02 12:59:56.247384732 +0200
@@ -42,4 +42,6 @@ void TtyTerminalIO_destroy(TerminalIO *t
  * @param tio reference to ttyio object
  */
 int TtyTerminalIO_get_associated_fd(TerminalIO *tio);
+
+int TtyTerminalIO_get_exit_code(TerminalIO *tio);
 #endif
--- unix/fbiterm/src/fbiterm.h-dist	2004-04-01 17:09:59.000000000 +0200
+++ unix/fbiterm/src/fbiterm.h	2004-04-02 12:44:23.472248087 +0200
@@ -130,6 +128,7 @@ typedef struct _Iterm
   int termInitialized ;         /* flag to check if terminal is initialized */
   int fbInitialized;            /* flag to check if framebuffer is initialized */
   int inputInitialized;        /* flag to check if input is initialized */
+  int inheritExit;             /* inherit exit code */
 
 }
 Iterm;
--- unix/fbiterm/src/term.c-dist	2004-04-02 12:29:57.000000000 +0200
+++ unix/fbiterm/src/term.c	2004-04-02 13:03:24.370258881 +0200
@@ -12,6 +12,7 @@
 #include <errno.h>
 
 #include "fbiterm.h"		/* for iterm_struct */
+#include "iterm/unix/ttyio.h"
 
 void
 init_tty ()
@@ -96,9 +97,14 @@ setup_vt_handle (void)
 void
 clean_up ()
 {
+  int status = 0;
+
+  if (pIterm && pIterm->inheritExit) {
+    status = TtyTerminalIO_get_exit_code(pIterm->tio);
+  }
   /* set new keyboard control parameters for new terminal */
   write(STDOUT_FILENO, "\x1b>",2); /* to switch keypad numeric modes */
-  exitFbiterm(0);
+  exitFbiterm(status);
 }
 
 /* Initialize tty */
--- unix/fbiterm/src/vt.c-dist	2004-04-02 13:06:04.637758773 +0200
+++ unix/fbiterm/src/vt.c	2004-04-02 12:45:50.395542547 +0200
@@ -21,6 +21,7 @@
 
   putenv ("TERM=iterm");
   if (program_args) {
+	  pIterm->inheritExit = 1;
 	  return (TerminalIO *) TtyTerminalIO_new (pIterm->cols, pIterm->rows,
 						   program_args[0], program_args);
   }