#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mfjterm.h" #include "file.h" #include "scrollback.h" #include "misc.h" #include "inout.h" #include "opmode.h" int chk_environment(void) { char *p1 = NULL, *p2 = NULL, *p3 = NULL, *p4 = NULL; if (! (p1 = getenv("MFJTERM_DEV"))) printf("Error: Environment variable MFJTERM_DEV not set\n"); if (! (p2 = getenv("MFJTERM_LIB"))) printf("Error: Environment variable MFJTERM_LIB not set\n"); if (! (p3 = getenv("EDITOR"))) printf("Error: Environment variable EDITOR not set\n"); if ((p1 == NULL) || (p2 == NULL) || (p3 == NULL)) return 0; if (! (p4 = getenv("MFJTERM_PAGER"))) { printf("Environment variable MFJTERM_PAGER not set; help disabled.\n"); pager[0] = 0; sleep(2); } else strcpy(pager, p4); strcpy(tnc_dev, p1); strcpy(lib_path, p2); strcpy(editor, p3); return 1; } int getopts(int argc, char **argv) { int c; opterr = 0; while ((c = getopt(argc, argv, "s")) != -1) { switch(c) { case 's': use_dsp_as_alarm = FALSE; break; case '?': if (isprint(optopt)) fprintf(stderr, "Unknown option '-%c'.\n", optopt); else fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt); return 0; default: abort(); } } return 1; } void ctrlc(int sig) { write_tnc(0x03); signal(SIGINT, ctrlc); } void draw_screen(void) { attrset(A_NORMAL); erase(); attrset(A_REVERSE); move(0, 0); addstr(" "); move(19, 0); addstr(" "); attrset(A_NORMAL); move(20, 0); clrtobot(); refresh(); } void quit(int no_set_params) { int res; attrset(A_REVERSE); move(19, 1); curs_set(0); addstr("Quit (y/n)?"); res = yesno(stdscr); move(19, 1); addstr(" "); curs_set(1); move(tnc_y, tnc_x); refresh(); if (! res) return; if (cap) fclose(capf); if (! no_set_params) { opmode = VPKT; set_tnc_params(); sleep(1); } while (chk_incoming()) read_tnc(); tcsetattr(tnc, TCSAFLUSH, &tnc_old_settings); close(tnc); exit_scrollback(); attrset(A_NORMAL); erase(); refresh(); exit(0); } void init(int argc, char **argv) { int i; if (! chk_environment()) exit(1); if (! getopts(argc, argv)) exit(1); if ((tnc = open(tnc_dev, O_RDWR)) == -1) { perror("Error opening tnc device"); exit(1); } if (! read_settings()) { strcpy(callsign, "SM5SXL"); strcpy(my_selcall, "SSXL"); bps = B9600; opmode = VPKT; for (i = 0; i < 12; i++) strcpy(fkstr[i], ""); } init_scrollback(); atexit((void*)endwin); initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); nodelay(stdscr, TRUE); scrollok(stdscr, TRUE); draw_screen(); tcgetattr(tnc, &tnc_old_settings); tcgetattr(tnc, &tnc_settings); tnc_settings.c_iflag &= ~(ICRNL | IXOFF | IXON); tnc_settings.c_iflag |= IGNCR; tnc_settings.c_lflag &= ~(ECHO | ICANON | ISIG); tnc_settings.c_cflag |= CRTSCTS; /* Hardware flow control */ tnc_settings.c_cflag |= CLOCAL; /* Ignore modem status */ tnc_settings.c_oflag &= ~OPOST; tnc_settings.c_cc[VMIN] = 1; tnc_settings.c_cc[VTIME] = 0; cfsetispeed(&tnc_settings, bps); cfsetospeed(&tnc_settings, bps); if (tcsetattr(tnc, TCSAFLUSH, &tnc_settings) == -1) perror ("tcsetattr"); signal(SIGINT, ctrlc); ascii_spd = 5; rtty_spd = 0; pactor_spd = 1; ascii_inv = 0; rtty_inv = 0; ascii_shift = 0; rtty_shift = 0; amtor_inv = 0; usos = 0; set_tnc_params(); strcpy(scanstr," "); strcpy(destcall,""); strcpy(scancrit,""); move(console_y, console_x); } .