home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / pcomm2 / part05 / passthru.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-14  |  2.1 KB  |  117 lines

  1. /*
  2.  * A transparent "pass-thru" mode, designed to allow binary transfers
  3.  * between 3 machines (with the middle machine in the pass-thru mode).
  4.  * A non-zero return code means the input routine should be restarted.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <signal.h>
  9. #include <curses.h>
  10. #include "config.h"
  11. #include "misc.h"
  12.  
  13. int
  14. pass_thru()
  15. {
  16.     extern int fd;
  17.     WINDOW *pt_win, *newwin();
  18.     int num;
  19.     void cpio();
  20.  
  21.     pt_win = newwin(5, 70, 5, 5);
  22.  
  23.     mvwaddstr(pt_win, 2, 4, "Enter the expiration time (5-60 sec): ");
  24.     box(pt_win, VERT, HORZ);
  25.  
  26.     mvwattrstr(pt_win, 0, 3, A_BOLD, " Pass Through Mode ");
  27.     wmove(pt_win, 2, 43);
  28.     wrefresh(pt_win);
  29.                     /* get the answer */
  30.     while ((num = get_num(pt_win, 2)) != -1) {
  31.                     /* out of bounds */
  32.         if (num < 5 || num > 60) {
  33.             beep();
  34.             clear_line(pt_win, 2, 43, 1);
  35.             wmove(pt_win, 2, 43);
  36.             wrefresh(pt_win);
  37.         }
  38.         else {
  39.             werase(pt_win);
  40.             wrefresh(pt_win);
  41.             delwin(pt_win);
  42.  
  43.             touchwin(stdscr);
  44.             refresh();
  45.  
  46.             cpio((unsigned int) num);
  47.             return(1);
  48.         }
  49.     }
  50.     if (fd == -1) {
  51.         werase(pt_win);
  52.         wrefresh(pt_win);
  53.     }
  54.     delwin(pt_win);
  55.     return(0);
  56. }
  57.  
  58. /*
  59.  * Copy the stdin to the TTYout and copy the TTYin to the stdout.  Uses
  60.  * multi character reads.  I'm not too concerned about the excess bagage
  61.  * caused by the entire image being forked... this feature won't be used
  62.  * that often.
  63.  */
  64.  
  65. static int cp_flag;
  66.  
  67. static void
  68. cpio(num)
  69. unsigned int num;
  70. {
  71.     extern int fd;
  72.     int cpid, n, cp_force();
  73.     char buf[BUFSIZ];
  74.     unsigned int alarm(), sleep();
  75.     void line_set(), xmodem_mode(), input_off();
  76.  
  77.                     /* out of curses mode */
  78.     resetterm();
  79.  
  80.     input_off();
  81.     xmodem_mode(0);
  82.     xmodem_mode(fd);
  83.  
  84.                     /* copy the TTYin to stdout */
  85.     if (!(cpid = fork())) {
  86.         while (1) {
  87.             n = read(fd, buf, BUFSIZ);
  88.             write(1, buf, n);
  89.         }
  90.     }
  91.  
  92.     cp_flag = 0;
  93.     signal(SIGALRM, cp_force);
  94.                     /* copy the stdin to TTYout */
  95.     while (1) {
  96.         alarm(num);
  97.         n = read(0, buf, BUFSIZ);
  98.         if (cp_flag)
  99.             break;
  100.         write(fd, buf, n);
  101.     }
  102.     kill(cpid, SIGKILL);
  103.                     /* back to curses mode */
  104.     sleep(1);
  105.     fixterm();
  106.     beep();
  107.     line_set();
  108.     clearok(curscr, TRUE);
  109.     return;
  110. }
  111. /*ARGSUSED*/
  112. static int
  113. cp_force(dummy)
  114. {
  115.     cp_flag = 1;
  116. }
  117.