=================================================================== RCS file: /home/cvs/OpenXM_contrib2/fep/fep_main.c,v retrieving revision 1.1 retrieving revision 1.9 diff -u -p -r1.1 -r1.9 --- OpenXM_contrib2/fep/fep_main.c 2002/09/03 00:41:44 1.1 +++ OpenXM_contrib2/fep/fep_main.c 2012/05/14 12:52:08 1.9 @@ -2,14 +2,20 @@ #ifndef lint static char rcsid[]= -"$Id: fep_main.c,v 1.1 2002/09/03 00:41:44 noro Exp $ (SRA)"; +"$Id: fep_main.c,v 1.9 2012/05/14 12:52:08 ohara Exp $ (SRA)"; #endif /* lint */ #include +#include +#include #include #include #include #include +#if defined(sun) +#include +#include +#endif #ifdef TERMIOS #include #if defined(__linux__) || defined(__CYGWIN__) @@ -57,7 +63,11 @@ int histlen = -1; /* history length */ int debug = OFF; /* debug switch */ int auto_tty_fix = ON; /* fix tty mode automaticaly */ FILE *script_fp = NULL; /* script file pointer */ +#if defined(sun) +void catchsig (int); /* function take care SIGCHILD */ +#else void catchsig __P((int)); /* function take care SIGCHILD */ +#endif #ifdef TERMIOS #define ttystruct termios @@ -72,7 +82,11 @@ int lines; /* terminal line size */ int columns; /* terminal coulumn size */ char *term_clear; /* terminal clear code */ +#if defined(sun) +void (*sighup)(int), (*sigchld)(int), (*sigtstp)(int); +#else void (*sighup) __P((int)), (*sigchld) __P((int)), (*sigtstp) __P((int)); +#endif /* function buffer for signal */ #ifdef TIOCSETN @@ -245,7 +259,11 @@ DEFAULT: commandv = &argv[1]; if (! isatty (0)) { +#if defined(__INTERIX) + execvp (*commandv, commandv); +#else execvp (*commandv, commandv, 0); +#endif perror (*commandv); exit (1); } @@ -296,8 +314,12 @@ DEFAULT: fix_signal () { #ifdef SIGWINCH +#if defined(sun) + void sigwinch (int); +#else void sigwinch __P((int)); #endif +#endif sighup = signal (SIGHUP, terminate); sigchld = signal (SIGCHLD, catchsig); @@ -319,7 +341,7 @@ recover_signal () input_handler() { char *inputline; - char *getline (); + char *mygetline (); /* * Get slave tty descriptor for auto-tty-fix @@ -327,7 +349,7 @@ input_handler() if ((slave = open (slave_tty, O_RDONLY)) < 0) perror ("open"); - while (inputline = getline ()) { + while (inputline = mygetline ()) { /* * XXX: nbyte should be greater than 0 only for ^@ input in emacs. * This solution is very ugly.. but it will takes a half day @@ -343,7 +365,7 @@ input_handler() /* * NOTE: - * Saving command line to output buffer is done in getline(). + * Saving command line to output buffer is done in mygetline(). * Because inputline here is converted by alias. */ @@ -525,7 +547,7 @@ int set_buffer (bp, size) BUFFER *bp; int size; { - char *newbuf, *malloc(), *realloc(); + char *newbuf; if (bp->b_buf) newbuf = (char *) realloc (bp->b_buf, size); @@ -657,6 +679,10 @@ swallow_output() #include #endif +#if defined(__INTERIX) +#define wait3(s,opt,rp) (waitpid((-1),(s),(opt))) +#endif + void catchsig(n) int n; @@ -686,7 +712,7 @@ exec_to_command(argv) */ t = open ("/dev/tty", 2); if (t >= 0) { -#ifndef __CYGWIN32__ +#if !defined(__CYGWIN32__) && !defined(__INTERIX) ioctl (t, TIOCNOTTY, (char *) 0); #endif (void) close (t); @@ -705,7 +731,11 @@ exec_to_command(argv) #elif defined(TIOCSETN) ioctl (0, TIOCSETN, (char *) & slave_ttymode); #endif +#if defined(__INTERIX) + execvp (*argv, argv); +#else execvp (*argv, argv, 0); +#endif perror (*argv); exit (1); } @@ -838,14 +868,26 @@ get_pty_master() master = 1; return; } -#ifdef __CYGWIN32__ - for (i = 0; i < 16; i++) { - sprintf (master_tty, "/dev/ptmx"); - master = open (master_tty, O_RDWR); - if (master >= 0) { - sprintf (slave_tty, "/dev/tty%x",i); +#if defined(__CYGWIN32__) || defined(__linux__) + sprintf (master_tty, "/dev/ptmx"); + master = open (master_tty, O_RDWR); + if (master >= 0) { +#if defined(__linux__) + char name[BUFSIZ]; + grantpt(master); + unlockpt(master); + if ( !ptsname_r(master,name,sizeof(name)) ) { + strcpy(slave_tty, name); goto FOUND; } +#else + char *name; + name = (char *)ptsname(master); + if ( name != 0 ) { + strcpy(slave_tty, name); + goto FOUND; + } +#endif } #else for (c = 'p'; c <= 's'; c++) { @@ -963,7 +1005,11 @@ recover_tty() suspend() { long pid; +#if defined(sun) + void (*func) (int); +#else void (*func) __P((int)); +#endif #ifndef __CYGWIN32__ int omask; #endif @@ -975,7 +1021,7 @@ suspend() signal (SIGTSTP, SIG_DFL); recover_tty(); #define mask(s) (1 << ((s)-1)) -#ifndef __CYGWIN32__ +#if !defined(__CYGWIN32__) && !defined(sun) omask = sigsetmask (sigblock (0) & ~mask (SIGTSTP)); #endif kill (0, SIGTSTP); @@ -988,7 +1034,7 @@ suspend() kill (0, SIGCONT); signal (SIGCHLD, func); signal (SIGTSTP, SIG_IGN); -#ifndef __CYGWIN32__ +#if !defined(__CYGWIN32__) && !defined(sun) sigblock (mask (SIGTSTP)); #endif fix_tty (); @@ -1027,8 +1073,9 @@ usageAndExit() /* * Propagate window size changes to the slave tty. */ -sigwinch() +void sigwinch(int dummy) { + char *itoa(int i); #ifdef TIOCGWINSZ /* 4.3BSD */ struct winsize win;