home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part06 / x_win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-18  |  2.7 KB  |  113 lines

  1. /*
  2.  * Display the file transfer window, and invoke the transfer protocol.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "dial_dir.h"
  8. #include "misc.h"
  9. #include "status.h"
  10. #include "xmodem.h"
  11.  
  12. void
  13. xfer_win(list, up, type)
  14. char *list;
  15. int up, type;
  16. {
  17.     WINDOW *xf_win, *newwin();
  18.     int ret_code, fast, my_speed;
  19.     void xmodem_mode(), input_off(), line_set(), error_win();
  20.     struct termio tbuf;
  21.  
  22.     if (status->fd == -1) {
  23.         error_win(0, "Not currently connected to any host", NULL);
  24.         return;
  25.     }
  26.  
  27.     xf_win = newwin(15, 44, 2, 30);
  28.     /*
  29.      * This window should be in the non-blocking mode, so we can
  30.      * scan the keyboard for input while transferring a file.
  31.      */
  32.     nodelay(xf_win, 1);
  33.                     /* basic window stuff */
  34.     mvwaddstr(xf_win, 2, 14, "Protocol:");
  35.     mvwaddstr(xf_win, 3, 13, "File name:");
  36.     mvwaddstr(xf_win, 4, 13, "File size:");
  37.     mvwaddstr(xf_win, 5, 4, "Error check method:");
  38.     mvwaddstr(xf_win, 6, 5, "Est transfer time:");
  39.     mvwaddstr(xf_win, 7, 11, "Block count:");
  40.     mvwaddstr(xf_win, 8, 6, "Percent complete:");
  41.     mvwaddstr(xf_win, 9, 5, "Bytes transferred:");
  42.     mvwaddstr(xf_win, 10, 5, "Errors this block:");
  43.     mvwaddstr(xf_win, 11, 5, "Total error count:");
  44.     mvwaddstr(xf_win, 12, 10, "Last message: NONE");
  45.     box(xf_win, '|', '-');
  46.  
  47.     if (up)
  48.         mvwattrstr(xf_win, 0, 17, A_BOLD, " Uploading ");
  49.     else
  50.         mvwattrstr(xf_win, 0, 16, A_BOLD, " Downloading ");
  51.     mvwaddstr(xf_win, 14, 12, " Press ESC to abort ");
  52.     wrefresh(xf_win);
  53.                     /* fix up the terminal mode */
  54.     input_off();
  55.     xmodem_mode(status->fd);
  56.  
  57.     /*
  58.      * Is your terminal slower than the xfer baud rate?  For example:
  59.      * I'm at home with my PC and 1200 baud modem, I call my system
  60.      * at work so I can use their 2400 baud modems to call some other
  61.      * system.  In this case, I don't wanna spend too much time updating
  62.      * my screen at 1200 baud, when I'm transferring the file at 2400 baud.
  63.      */
  64.     my_speed = 0;
  65.     fast = 0;
  66.  
  67.     ioctl(0, TCGETA, &tbuf);
  68.                     /* only reasonable values are here */
  69.     switch(tbuf.c_cflag & CBAUD) {
  70.         case B300:
  71.             my_speed = 300;
  72.             break;
  73.         case B1200:
  74.             my_speed = 1200;
  75.             break;
  76.         case B2400:
  77.             my_speed = 2400;
  78.             break;
  79.         case B4800:
  80.             my_speed = 4800;
  81.             break;
  82.         case B9600:
  83.             my_speed = 9600;
  84.             break;
  85.         case B19200:
  86.             my_speed = 19200;
  87.             break;
  88.     }
  89.     if (my_speed >= dir->baud[dir->d_cur])
  90.         fast++;
  91.  
  92.     if (up)
  93.         ret_code = send_xmodem(xf_win, list, type, fast);
  94.     else
  95.         ret_code = rcv_xmodem(xf_win, list, type, fast);
  96.  
  97.     nodelay(xf_win, 0);
  98.                     /* prompt for a key on errors */
  99.     if (ret_code) {
  100.         beep();
  101.         clear_line(xf_win, 13, 9, 1);
  102.         wattrstr(xf_win, A_BOLD, "Press any key to continue");
  103.         wrefresh(xf_win);
  104.         wgetch(xf_win);
  105.     }
  106.     werase(xf_win);
  107.     wrefresh(xf_win);
  108.     delwin(xf_win);
  109.                     /* undo what xmodem_mode() did */
  110.     line_set();
  111.     return;
  112. }
  113.