home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / rvi / part3 / rv_shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-09  |  2.0 KB  |  113 lines

  1. #include "rv.h"
  2. #include <signal.h>
  3.  
  4. #ifndef USG
  5. #  define strchr index
  6. #endif
  7.  
  8. /*
  9.  * This entire module is a hack
  10.  */
  11.  
  12. extern boolean    scrolled;
  13.  
  14. extern char *strchr();
  15.  
  16. rv_shell(cmd)
  17. char *cmd;
  18. {
  19.     INT cpid, len, infd, outfd;
  20.     char buf[513], *s;
  21.     int (*prev_func)();
  22. #ifdef USG
  23.     struct termio tm;
  24. #endif
  25.     
  26.     xmit_sync();
  27.     (void) recv_sync(FALSE);
  28.     xmit_ed("!sh -c '%s' ; echo '@''$''#'\n", cmd);
  29.     fflush(file.fi_fpout);
  30.     if (file.fi_modified)
  31.         botprint(FALSE, "[No write since last change]");
  32.     move(LINES-1, 0);
  33.     rv_fscroll(1);
  34.     move(LINES-1, 0);
  35.     refresh();
  36.  
  37.     /* prev_func = signal(SIGINT, SIG_IGN);  Use at your own risk */
  38.     if (use_linemode) {
  39. #ifdef USG
  40.         nocbreak();
  41. #else
  42.         nocrmode();
  43. #endif
  44.         nl();
  45.         echo();
  46. #ifdef TCGETA             /* Echo doesn't in System V, sigh */
  47.         ioctl(0, TCGETA, &tm);
  48.         tm.c_lflag |= ECHO;
  49.         ioctl(0, TCSETA, &tm);
  50. #endif
  51.         if (set_debug > 2)
  52.             printf("Using line mode.\n");
  53.     }
  54.     infd = atoi(Argv[1]);
  55.     outfd = atoi(Argv[2]);
  56.     if ((cpid = fork()) < 0)
  57.         panic("Can't fork");
  58.     if (cpid == 0) { /* Child */
  59.         for (;;) {
  60.             if ((len = read(0, buf, 512)) < 0)
  61.                 _exit(0);
  62.             if (len == 0)
  63.                 write(outfd, "\004\n", 2);
  64.             else
  65.                 write(outfd, buf, len);
  66.         }
  67.         /*NOTREACHED*/
  68.     }
  69.     for (;;) { /*  Parent */
  70.         if ((len = read(infd, buf, 512)) <= 0)
  71.             panic("EOF on read from pipe");
  72.         if ((s = strchr(buf, '@')) != NULL) {
  73.             if (s-buf+1 >= len) {
  74.                 write(1, buf, len);
  75.                 len = read(infd, buf, 512);
  76.                 s = buf;
  77.             }
  78.             if (*++s == '$') {
  79.                 if (s-buf+1 >= len) { 
  80.                     write(1, buf, len);
  81.                     len = read(infd, buf, 512);
  82.                     s = buf;
  83.                 }
  84.                 if (*++s == '#') {
  85.                     if (s-buf >= 3)
  86.                         write(1, buf, s-buf-2);
  87.                     kill(cpid, 9);
  88.                     while (wait((int *)0) != cpid)
  89.                         ;
  90.                     break;
  91.                 }
  92.             }
  93.         }
  94.         write(1, buf, len);
  95.     }
  96.     if (use_linemode) {
  97. #ifdef USG
  98.         cbreak();
  99. #else
  100.         crmode();
  101. #endif
  102.         nonl();
  103.         noecho();
  104.     }
  105.     /* (void) signal(SIGINT, prev_func);  Use at your own risk */
  106.     refresh();
  107.     scrolled = TRUE;
  108.     hitcr_continue();
  109.     clearok(curscr, TRUE);
  110.     redraw_screen((struct li_line *)0);
  111.     move_cursor(screen.sc_lineno, screen.sc_column);
  112. }
  113.