home *** CD-ROM | disk | FTP | other *** search
- /*
- * Open a window to display the choices of file transfer protocols and
- * prompt for the file name(s). A return code of 1 means turn the
- * input routine back on.
- */
-
- #include <stdio.h>
- #include <curses.h>
- #include "misc.h"
- #include "xmodem.h"
-
- int
- xfer_menu(up)
- int up;
- {
- WINDOW *xm_win, *newwin();
- char *list, *get_names();
- int type, is_batch;
- extern char *null_ptr;
- void xfer_win(), xfer_ascii(), free_ptr();
-
- xm_win = newwin(15, 20, 2, 45);
-
- mvwaddstr(xm_win, 2, 3, "1) xmodem");
- mvwaddstr(xm_win, 3, 3, "2) xmodem-1k");
- mvwaddstr(xm_win, 4, 3, "3) modem7");
- mvwaddstr(xm_win, 5, 3, "4) ymodem");
- mvwaddstr(xm_win, 6, 3, "5) ymodem-g");
- mvwaddstr(xm_win, 7, 3, "6) ASCII");
- mvwaddstr(xm_win, 11, 3, "ESC to Abort");
- mvwaddstr(xm_win, 13, 3, "Protocol:");
- box(xm_win, '|', '-');
- if (up)
- mvwattrstr(xm_win, 0, 6, A_BOLD, " Upload ");
- else
- mvwattrstr(xm_win, 0, 5, A_BOLD, " Download ");
-
- wmove(xm_win, 13, 13);
- wrefresh(xm_win);
- /* get the protocol */
- while ((type = get_num(xm_win, 1)) != -1) {
- if (type >=1 && type <= PROTOCOLS)
- break;
- beep();
- mvwaddch(xm_win, 13, 13, ' ');
- wmove(xm_win, 13, 13);
- wrefresh(xm_win);
- }
- /* is a batch protocol ? */
- is_batch = 0;
- switch (type-1) {
- case MODEM7:
- case YMODEM:
- case YMODEM_G:
- is_batch++;
- break;
- default:
- break;
- }
- werase(xm_win);
- wrefresh(xm_win);
- delwin(xm_win);
-
- touchwin(stdscr);
- refresh();
-
- if (type == -1)
- return(0);
- type--;
-
- /*
- * When receiving files in one of the batch modes, there is
- * need to prompt for a list of file names.
- */
- list = null_ptr;
- if (up || !is_batch) {
- if (!(list = get_names(up, type, is_batch)))
- return(0);
- }
- /* if ascii transfer */
- if (type == XASCII) {
- xfer_ascii(list, up);
- free_ptr(list);
- if (up)
- return(0);
- return(1);
- }
- xfer_win(list, up, type);
- free_ptr(list);
- return(1);
- }
-
- /*
- * Prompt for a list of files for the transfer programs. A NULL return
- * code means you chickened out.
- */
-
- char *
- get_names(up, type, is_batch)
- int up, type, is_batch;
- {
- int can;
- WINDOW *gn_win, *newwin();
- char *ans, *list, *file, buf[40], *expand(), *get_str(), *strtok();
- static char *direction[2] = {"Receive", "Send"};
- static char *protocol[PROTOCOLS] = {"xmodem", "xmodem-1k", "modem7",
- "ymodem", "ymodem-g", "ASCII"};
- /* prompt for file spec */
- gn_win = newwin(7, 70, 5, 5);
-
- mvwaddstr(gn_win, 3, 4, "Enter filename: ");
- box(gn_win, '|', '-');
- sprintf(buf, " %s %s ", direction[up], protocol[type]);
-
- while (1) {
- mvwattrstr(gn_win, 0, 3, A_BOLD, buf);
- wmove(gn_win, 3, 20);
- wrefresh(gn_win);
- /* get the answers */
- if (is_batch)
- ans = get_str(gn_win, 60, NULL, NULL);
- else
- ans = get_str(gn_win, 60, NULL, " ");
-
- if (ans == NULL || *ans == NULL) {
- list = NULL;
- break;
- }
- list = expand(ans);
- /* batchs check "on the fly" */
- if (is_batch)
- break;
- /*
- * The non-batch protocols don't check read and write
- * permission on the fly, so we check 'em here. Since
- * they aren't batch, we use only one file.
- */
- file = strtok(list, " ");
- /* check read permission */
- if (up) {
- if (access(file, 4)) {
- beep();
- mvwattrstr(gn_win, 4, 15, A_BOLD, "Can't find or no read permission");
- wrefresh(gn_win);
- wait_key(gn_win, 3);
- clear_line(gn_win, 4, 15, 1);
- clear_line(gn_win, 3, 20, 1);
- wrefresh(gn_win);
- }
- else
- break;
- }
- /* check write permission */
- else {
- if (!(can = can_write(file))) {
- beep();
- clear_line(gn_win, 4, 15, 1);
- mvwattrstr(gn_win, 4, 15, A_BOLD, "No write permission");
- wrefresh(gn_win);
- wait_key(gn_win, 3);
- clear_line(gn_win, 4, 15, 1);
- clear_line(gn_win, 3, 20, 1);
- wrefresh(gn_win);
- }
- if (can == 2) {
- if (!yes_prompt(gn_win, 4, 15, A_BOLD, "File exists, overwrite")) {
- list = NULL;
- break;
- }
- }
- if (can)
- break;
- }
- }
- werase(gn_win);
- wrefresh(gn_win);
- delwin(gn_win);
-
- touchwin(stdscr);
- refresh();
- return(list);
- }
-