home *** CD-ROM | disk | FTP | other *** search
- /*
- * Display the TTY setup, query for changes. A return code of 1
- * means something was changed.
- */
-
- #include <stdio.h>
- #include <curses.h>
- #include "config.h"
- #include "misc.h"
- #include "modem.h"
-
- int
- tty_setup()
- {
- extern char *null_ptr;
- WINDOW *tt_win, *newwin();
- char *strdup(), message[80];
- int num, i, j, ret_code;
- void disp_tty(), create_modem(), del_modem(), error_win();
- void del_tty();
-
- tt_win = newwin(23, 80, 0, 0);
-
- horizontal(tt_win, 0, 0, 34);
- mvwattrstr(tt_win, 0, 35, A_BOLD, "TTY Setup");
- horizontal(tt_win, 0, 45, 34);
- mvwaddstr(tt_win, 2, 22, "TTY name");
- mvwaddstr(tt_win, 2, 37, "Modem name");
- mvwaddstr(tt_win, 2, 51, "Init speed");
- /* display the current TTY list */
- disp_tty(tt_win);
- /* prompt for options */
- mvwprintw(tt_win, 15, 20, "%d) Add a TTY entry", NUM_TTY+1);
- mvwprintw(tt_win, 16, 20, "%d) Delete a TTY entry", NUM_TTY+2);
- horizontal(tt_win, 19, 0, 80);
- mvwattrstr(tt_win, 20, 0, A_BOLD, "OPTION ==> ");
- mvwaddstr(tt_win, 20, 58, "Press <ESC> to return");
- wmove(tt_win, 20, 12);
- touchwin(tt_win);
- wrefresh(tt_win);
- /* get the option number */
- ret_code = 0;
- while ((i = get_num(tt_win, 2)) != -1) {
- /* if beyond t_entries, fake it */
- if (i > modem->t_entries && i <= NUM_TTY)
- i=999;
- /* change an entry */
- if (i >= 1 && i <= NUM_TTY) {
- if (tty_prompt(tt_win, i-1))
- break;
- /* requires modem update? */
- create_modem(modem->tname[i-1]);
- del_modem();
-
- ret_code++;
- }
- /* add a entry */
- if (i == NUM_TTY+1) {
- if (modem->t_entries == NUM_TTY) {
- sprintf(message, "'%s'", modem->m_path);
- error_win(0, "No empty TTY slots in modem/TTY database", message);
- continue;
- }
- /* prompt for info */
- j = modem->t_entries;
- if (tty_prompt(tt_win, j))
- break;
- /* add modem entry? */
- modem->t_entries++;
- create_modem(modem->tname[j]);
-
- ret_code++;
- }
- /* delete an entry */
- if (i == NUM_TTY+2) {
- mvwaddstr(tt_win, 21, 0, "Entry number to delete: ");
- wrefresh(tt_win);
- while ((num = get_num(tt_win, 4)) != -1) {
- /* valid range */
- if (!num || num>modem->t_entries) {
- beep();
- mvwaddstr(tt_win, 21, 24, " ");
- wmove(tt_win, 21, 24);
- wrefresh(tt_win);
- continue;
- }
- del_tty(num-1);
- del_modem();
-
- /* show the new list */
- disp_tty(tt_win);
- ret_code++;
- break;
- }
- }
- if (i == 0 || i>NUM_TTY+2)
- beep();
- mvwaddstr(tt_win, 20, 12, " ");
- clear_line(tt_win, 21, 0, 0);
- clear_line(tt_win, 22, 0, 0);
- wmove(tt_win, 20, 12);
- wrefresh(tt_win);
- }
- delwin(tt_win);
- return(ret_code);
- }
-
- /*
- * Display the current TTY list. No scrolling yet, so if your NUM_TTY is
- * greater than ten, this routine will need some work.
- */
-
- static void
- disp_tty(win)
- WINDOW *win;
- {
- int i;
-
- for (i=0; i<NUM_TTY; i++)
- mvwprintw(win, i+4, 20, "%2d) %-14.14s %-14.14s %d\n",
- i+1, modem->tty[i], modem->tname[i], modem->init_sp[i]);
- return;
- }
-
- /*
- * Prompt the user for the TTY database info. A return code of 1 means a
- * user abort. The second argument is the zero based index.
- */
-
- static int
- tty_prompt(win, i)
- WINDOW *win;
- int i;
- {
- char *ans, *temp_tty, *temp_tname, *str_prompt(), *menu_prompt();
- void free_ptr();
- static char *v_baud[8] = {"0", "300", "1200", "2400", "4800", "9600",
- "19200", NULL};
- /* get temp TTY */
- if ((ans = str_prompt(win, i+4, 24, "TTY name", "")) == NULL)
- return(1);
-
- temp_tty = strdup(ans);
- clear_line(win, 21, 0, 0);
-
- /* get temp tname */
- if ((ans = str_prompt(win, i+4, 39, "Modem name", "")) == NULL)
- return(1);
-
- temp_tname = strdup(ans);
- clear_line(win, 21, 0, 0);
-
- /* get maximum baud */
- if ((ans = menu_prompt(win, i+4, 55, "Init speed", v_baud)) == NULL)
- return(1);
-
- wrefresh(win);
- /* store 'em for real */
- free_ptr(modem->tty[i]);
- free_ptr(modem->tname[i]);
-
- modem->tty[i] = strdup(temp_tty);
- modem->tname[i] = strdup(temp_tname);
- modem->init_sp[i] = atoi(ans);
-
- free_ptr(temp_tty);
- free_ptr(temp_tname);
- return(0);
- }
-
- /*
- * Delete a TTY entry. Since the list must be contiguous, we collapse the
- * list to cover the hole we made.
- */
-
- static void
- del_tty(i)
- int i;
- {
- extern char *null_ptr;
- int j;
- char *strdup();
- void free_ptr();
- /* collapse the list */
- for (j=i; j<modem->t_entries-1; j++) {
- free_ptr(modem->tty[j]);
- free_ptr(modem->tname[j]);
- modem->tty[j] = strdup(modem->tty[j+1]);
- modem->tname[j] = strdup(modem->tname[j+1]);
- modem->init_sp[j] = modem->init_sp[j+1];
- }
- j = modem->t_entries-1;
- /* zap the entry */
- free_ptr(modem->tty[j]);
- free_ptr(modem->tname[j]);
- modem->tty[j] = null_ptr;
- modem->tname[j] = null_ptr;
- modem->init_sp[j] = 0;
- /* update the count */
- modem->t_entries--;
- if (modem->t_cur >= modem->t_entries)
- modem->t_cur = -1;
- return;
- }
-