home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / pcomm2 / part08 / x_win.c < prev    next >
C/C++ Source or Header  |  1988-09-14  |  3KB  |  98 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 "config.h"
  8. #ifdef OLDCURSES
  9. #include <termio.h>
  10. #endif /* OLDCURSES */
  11. #include "dial_dir.h"
  12. #include "misc.h"
  13. #include "xmodem.h"
  14.  
  15. void
  16. xfer_win(list, up, type)
  17. char *list;
  18. int up, type;
  19. {
  20.     extern int fd;
  21.     WINDOW *xf_win, *newwin();
  22.     int ret_code, fast, my_speed;
  23.     void xmodem_mode(), input_off(), line_set(), error_win(), st_line();
  24.     static int speed[15] = {0, 50, 75, 110, 134, 150, 200, 300, 600,
  25.     1200, 1800, 2400, 4800, 9600, 19200};
  26.     struct termio tbuf;
  27.  
  28.     touchwin(stdscr);
  29.     refresh();
  30.     st_line("");
  31.  
  32.     xf_win = newwin(15, 44, 2, 30);
  33.     /*
  34.      * This window should be in the non-blocking mode, so we can
  35.      * scan the keyboard for input while transferring a file.
  36.      */
  37.     nodelay(xf_win, 1);
  38.                     /* basic window stuff */
  39.     mvwaddstr(xf_win, 2, 14, "Protocol:");
  40.     mvwaddstr(xf_win, 3, 13, "File name:");
  41.     mvwaddstr(xf_win, 4, 13, "File size:");
  42.     mvwaddstr(xf_win, 5, 4, "Error check method:");
  43.     mvwaddstr(xf_win, 6, 5, "Est transfer time:");
  44.     mvwaddstr(xf_win, 7, 11, "Block count:");
  45.     mvwaddstr(xf_win, 8, 6, "Percent complete:");
  46.     mvwaddstr(xf_win, 9, 5, "Bytes transferred:");
  47.     mvwaddstr(xf_win, 10, 5, "Errors this block:");
  48.     mvwaddstr(xf_win, 11, 5, "Total error count:");
  49.     mvwaddstr(xf_win, 12, 10, "Last message: NONE");
  50.     box(xf_win, VERT, HORZ);
  51.  
  52.     if (up)
  53.         mvwattrstr(xf_win, 0, 17, A_BOLD, " Uploading ");
  54.     else
  55.         mvwattrstr(xf_win, 0, 16, A_BOLD, " Downloading ");
  56.     mvwaddstr(xf_win, 14, 11, " Press <ESC> to abort ");
  57.     wrefresh(xf_win);
  58.                     /* fix up the terminal mode */
  59.     input_off();
  60.     xmodem_mode(fd);
  61.  
  62.     /*
  63.      * Is your terminal slower than the xfer baud rate?  For example:
  64.      * I'm at home with my PC and 1200 baud modem, I call my system
  65.      * at work so I can use their 2400 baud modems to call some other
  66.      * system.  In this case, I don't wanna spend too much time updating
  67.      * my screen at 1200 baud, when I'm transferring the file at 2400 baud.
  68.      */
  69.     fast = 0;
  70.  
  71.     ioctl(0, TCGETA, &tbuf);
  72.     my_speed = speed[tbuf.c_cflag & CBAUD];
  73.  
  74.     if (my_speed >= dir->baud[dir->d_cur])
  75.         fast++;
  76.  
  77.     if (up)
  78.         ret_code = send_xmodem(xf_win, list, type, fast);
  79.     else
  80.         ret_code = rcv_xmodem(xf_win, list, type, fast);
  81.  
  82.     nodelay(xf_win, 0);
  83.                     /* prompt for a key on errors */
  84.     if (ret_code) {
  85.         beep();
  86.         clear_line(xf_win, 13, 9, 1);
  87.         wattrstr(xf_win, A_BOLD, "Press any key to continue");
  88.         wrefresh(xf_win);
  89.         wgetch(xf_win);
  90.     }
  91.     werase(xf_win);
  92.     wrefresh(xf_win);
  93.     delwin(xf_win);
  94.                     /* undo what xmodem_mode() did */
  95.     line_set();
  96.     return;
  97. }
  98.