[BACK]Return to fep_main.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / fep

Diff for /OpenXM_contrib2/fep/fep_main.c between version 1.3 and 1.13

version 1.3, 2002/09/18 10:03:28 version 1.13, 2021/03/24 06:22:04
Line 1 
Line 1 
 /*      Copyright (c) 1987, 1988 by Software Research Associates, Inc.  */  /*      Copyright (c) 1987, 1988 by Software Research Associates, Inc.  */
   
   #if defined(ANDROID)
   #include <strings.h>
   #define index(s,c) strchr(s,c)
   #define rindex(s,c) strrchr(s,c)
   #endif
   
 #ifndef lint  #ifndef lint
 static char rcsid[]=  static char rcsid[]=
 "$Id$ (SRA)";  "$Id$ (SRA)";
 #endif /* lint */  #endif /* lint */
   
 #include <stdio.h>  #include <stdio.h>
   #include <unistd.h>
   #include <stdlib.h>
   #include <string.h>
 #include <signal.h>  #include <signal.h>
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/stat.h>  #include <sys/stat.h>
Line 128  struct cmdinfo {
Line 137  struct cmdinfo {
         {0,                     0}          {0,                     0}
 };  };
   
 main(argc, argv)  int main(int argc, char *argv[])
     int argc;  
     char *argv[];  
 {  {
     int     i;      int     i;
     char    *cp;      char    *cp;
Line 246  DEFAULT:
Line 253  DEFAULT:
      * Set variable of command name.       * Set variable of command name.
      */       */
     {      {
   #if defined(ANDROID)
           char *cp = argv[1];
   #else
         char *cp = argv[1], *rindex();          char *cp = argv[1], *rindex();
   #endif
   
         if (any ('/', cp))          if (any ('/', cp))
             cp = rindex (cp, '/') + 1;              cp = rindex (cp, '/') + 1;
Line 257  DEFAULT:
Line 268  DEFAULT:
     commandv = &argv[1];      commandv = &argv[1];
   
     if (! isatty (0)) {      if (! isatty (0)) {
         execvp (*commandv, commandv, 0);  #if defined(__INTERIX)
           execvp (*commandv, commandv);
   #else
           execvp (*commandv, commandv);
   #endif
         perror (*commandv);          perror (*commandv);
         exit (1);          exit (1);
     }      }
Line 305  DEFAULT:
Line 320  DEFAULT:
     input_handler ();      input_handler ();
 }  }
   
 fix_signal ()  void fix_signal ()
 {  {
 #ifdef SIGWINCH  #ifdef SIGWINCH
 #if defined(sun)  #if defined(sun)
Line 324  fix_signal ()
Line 339  fix_signal ()
 #endif  #endif
 }  }
   
 recover_signal ()  void recover_signal ()
 {  {
   
     (void) signal (SIGHUP, sighup);      (void) signal (SIGHUP, sighup);
Line 332  recover_signal ()
Line 347  recover_signal ()
     (void) signal (SIGTSTP, sigtstp);      (void) signal (SIGTSTP, sigtstp);
 }  }
   
 input_handler()  void input_handler()
 {  {
     char   *inputline;      char   *inputline;
     char   *getline ();      char   *mygetline ();
   
     /*      /*
      * Get slave tty descriptor for auto-tty-fix       * Get slave tty descriptor for auto-tty-fix
Line 343  input_handler()
Line 358  input_handler()
     if ((slave = open (slave_tty, O_RDONLY)) < 0)      if ((slave = open (slave_tty, O_RDONLY)) < 0)
         perror ("open");          perror ("open");
   
     while (inputline = getline ()) {      while (inputline = mygetline ()) {
         /*          /*
          * XXX: nbyte should be greater than 0 only for ^@ input in emacs.           * XXX: nbyte should be greater than 0 only for ^@ input in emacs.
          * This solution is very ugly.. but it will takes a half day           * This solution is very ugly.. but it will takes a half day
Line 359  input_handler()
Line 374  input_handler()
   
         /*          /*
          * NOTE:           * 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.           * Because inputline here is converted by alias.
          */           */
   
Line 417  struct timeval *notimeout[] = {
Line 432  struct timeval *notimeout[] = {
         TIMEOUT_FOREVER          TIMEOUT_FOREVER
 };  };
   
 getcharacter()  int getcharacter()
 {  {
     char c;      char c;
     int n;      int n;
Line 537  RETRY:
Line 552  RETRY:
     goto RETRY;      goto RETRY;
 }  }
   
 int set_buffer (bp, size)  int set_buffer (BUFFER *bp, int size)
     BUFFER *bp;  
     int size;  
 {  {
     char *newbuf, *malloc(), *realloc();      char *newbuf;
   
     if (bp->b_buf)      if (bp->b_buf)
         newbuf = (char *) realloc (bp->b_buf, size);          newbuf = (char *) realloc (bp->b_buf, size);
Line 564  int set_buffer (bp, size)
Line 577  int set_buffer (bp, size)
     return (1);      return (1);
 }  }
   
 int buf_read (fd, bp)  /*    int fd;                   file discriptor */
     int fd;                     /* file discriptor */  /*    BUFFER *bp;               buffer pointer */
     BUFFER *bp;                 /* buffer pointer */  
   int buf_read (int fd, BUFFER *bp)
 {  {
     int nbyte;      int nbyte;
   
Line 604  int buf_read (fd, bp)
Line 618  int buf_read (fd, bp)
     return (nbyte);      return (nbyte);
 }  }
   
 buf_put (bp, s)  /*
     BUFFER *bp;                 /* buffer pointer */      BUFFER *bp;                 buffer pointer
     char *s;                    /* string pointer */      char *s;                    string pointer
   */
   
   void buf_put (BUFFER *bp, char *s)
 {  {
     int nbyte;      int nbyte;
     int slen;      int slen;
Line 631  buf_put (bp, s)
Line 648  buf_put (bp, s)
     }      }
 }  }
   
 swallow_output()  void swallow_output()
 {  {
     fd_set readfd = mastermask;      fd_set readfd = mastermask;
     int r;      int r;
Line 673  swallow_output()
Line 690  swallow_output()
 #include <sys/m_wait.h>  #include <sys/m_wait.h>
 #endif  #endif
   
 void  #if defined(__INTERIX) || defined(ANDROID)
 catchsig(n)  #define wait3(s,opt,rp)   (waitpid((-1),(s),(opt)))
     int n;  #endif
   
   void catchsig(int n)
 {  {
     int status;      int status;
     struct rusage   ru;      struct rusage   ru;
Line 692  catchsig(n)
Line 711  catchsig(n)
     terminate (0);      terminate (0);
 }  }
   
 exec_to_command(argv)  void exec_to_command(char *argv[])
     char *argv[];  
 {  {
     int t;      int t;
   
Line 702  exec_to_command(argv)
Line 720  exec_to_command(argv)
      */       */
     t = open ("/dev/tty", 2);      t = open ("/dev/tty", 2);
     if (t >= 0) {      if (t >= 0) {
 #ifndef __CYGWIN32__  #if !defined(__CYGWIN32__) && !defined(__INTERIX)
         ioctl (t, TIOCNOTTY, (char *) 0);          ioctl (t, TIOCNOTTY, (char *) 0);
 #endif  #endif
         (void) close (t);          (void) close (t);
Line 721  exec_to_command(argv)
Line 739  exec_to_command(argv)
 #elif defined(TIOCSETN)  #elif defined(TIOCSETN)
     ioctl (0, TIOCSETN, (char *) & slave_ttymode);      ioctl (0, TIOCSETN, (char *) & slave_ttymode);
 #endif  #endif
     execvp (*argv, argv, 0);  #if defined(__INTERIX)
       execvp (*argv, argv);
   #else
       execvp (*argv, argv);
   #endif
     perror (*argv);      perror (*argv);
     exit (1);      exit (1);
 }  }
   
 #ifdef TERMIOS  #ifdef TERMIOS
 fix_tty()  void fix_tty()
 {  {
     int i;      int i;
     master_ttymode = initial_ttymode;      master_ttymode = initial_ttymode;
Line 747  fix_tty()
Line 769  fix_tty()
   
 #elif defined(TIOCSETN)  #elif defined(TIOCSETN)
   
 fix_tty()  void fix_tty()
 {  {
     struct tchars tcbuf;      struct tchars tcbuf;
     struct ltchars lcbuf;      struct ltchars lcbuf;
Line 786  fix_tty()
Line 808  fix_tty()
 }  }
 #endif  #endif
   
 kill_process()  void kill_process()
 {  {
   
     if (child_pid)      if (child_pid)
         (void) killpg (child_pid, SIGTERM);          (void) killpg (child_pid, SIGTERM);
 }  }
   
 void  void terminate(int n)
 terminate(n)  
     int n;  
 {  {
     extern int errno;      extern int errno;
   
Line 837  terminate(n)
Line 857  terminate(n)
     exit (0);      exit (0);
 }  }
   
 send_int_sig() {  int send_int_sig() {
 #ifndef __CYGWIN__  #ifndef __CYGWIN__
     kill(child_pid,SIGINT);      kill(child_pid,SIGINT);
 #endif  #endif
         return 0;          return 0;
 }  }
   
 get_pty_master()  void get_pty_master()
 {  {
     char    c;      char    c;
     struct stat stb;      struct stat stb;
Line 854  get_pty_master()
Line 874  get_pty_master()
         master = 1;          master = 1;
         return;          return;
     }      }
 #ifdef __CYGWIN32__  #if defined(__CYGWIN32__) || defined(__linux__) || defined(__APPLE__)
     sprintf (master_tty, "/dev/ptmx");      sprintf (master_tty, "/dev/ptmx");
     master = open (master_tty, O_RDWR);      master = open (master_tty, O_RDWR);
     if (master >= 0) {      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;
           }
   #elif defined(__APPLE__)
           char *name;
           grantpt(master);
           unlockpt(master);
           if ( name = (char *)ptsname(master) ) {
               strcpy(slave_tty, name);
               goto FOUND;
           }
   #else
         char *name;          char *name;
         name = (char *)ptsname(master);          name = (char *)ptsname(master);
         if ( name != 0 ) {          if ( name != 0 ) {
             strcpy(slave_tty, name);              strcpy(slave_tty, name);
             goto FOUND;              goto FOUND;
         }          }
   #endif
     }      }
 #else  #else
     for (c = 'p'; c <= 's'; c++) {      for (c = 'p'; c <= 's'; c++) {
Line 929  get_pty_master()
Line 967  get_pty_master()
     return;      return;
 }  }
   
 get_pty_slave()  void get_pty_slave()
 {  {
   
     slave = open (slave_tty, 2);      slave = open (slave_tty, 2);
Line 967  get_pty_slave()
Line 1005  get_pty_slave()
 #endif  #endif
 }  }
   
 recover_tty()  void recover_tty()
 {  {
 #ifdef TERMIOS  #ifdef TERMIOS
     tcsetattr(0, TCSANOW, &initial_ttymode);      tcsetattr(0, TCSANOW, &initial_ttymode);
Line 978  recover_tty()
Line 1016  recover_tty()
 #endif  #endif
 }  }
   
 suspend()  int suspend()
 {  {
     long        pid;      long        pid;
 #if defined(sun)  #if defined(sun)
Line 1018  suspend()
Line 1056  suspend()
         fep_repaint(0);          fep_repaint(0);
 }  }
   
 look_cmdinfo (command)  void look_cmdinfo (char *command)
     char *command;  
 {  {
     struct cmdinfo *p;      struct cmdinfo *p;
     char *allocAndCopyThere();      char *allocAndCopyThere();
Line 1038  look_cmdinfo (command)
Line 1075  look_cmdinfo (command)
 }  }
   
   
 usageAndExit()  void usageAndExit()
 {  {
   
     printf ("Usage: %s [-emacs|-vi] command\n", myself);      printf ("Usage: %s [-emacs|-vi] command\n", myself);
Line 1049  usageAndExit()
Line 1086  usageAndExit()
 /*  /*
  * Propagate window size changes to the slave tty.   * Propagate window size changes to the slave tty.
  */   */
 sigwinch()  void sigwinch(int dummy)
 {  {
       char *itoa(int i);
 #ifdef TIOCGWINSZ                       /* 4.3BSD */  #ifdef TIOCGWINSZ                       /* 4.3BSD */
     struct winsize win;      struct winsize win;
   

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.13

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>