/* ** === WTCFG.C - Configuration processing for WizTerm ** */ /*====================*/ /*===== Includes =====*/ /*====================*/ #include #include #include #include #include "wt.h" #include "wtbuf.h" #include "wtcfg.h" #include "wtppn.h" #include "wtcom.h" #include "wtscn.h" #include "wtsta.h" #include "wtwin.h" /* Configurable parameters */ static struct { int po; int sp; int da; int pa; int st; int watch; int ppnlog; int hdx; char *mac[26]; } cfg = { 1, 24, 7, 'E', 1, 0, 0, 0, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; int help_visible = 0; static char *help_msgs[] = { "'$' commands for configuration, etc.; must be typed at the beginning", "of the blue command line and ended with a carriage return (ENTER).", " ", "Function Command Default All options", "------------ ----- -------- -------------", "COM port: $PO $PO 1 1 2 3 4", "Baud rate: $SP $SP 2400 300 1200 2400 9600 19200", "Data bits: $DA $DA 7 7 8", "Parity: $PA $PA EV NO OD EV", "Stop bits: $ST $ST 1 1 2", " ", "Quit program: $Q (Exits from CIS, closes log, saves config)", " ", "Define macro: $MAC A text (substitute any letter for A;", " macro is activated by typing ALT-letter;", " include '^letter' for control chars (^M = ENTER);", " include '@letter' to include one macro in another,", " example: $MAC F Fodsick", " $MAC K Kill @F ^M ---> 'Kill Fodsick '", " ", NULL }; /*==============================*/ /*===== Internal functions =====*/ /*==============================*/ /****************************************************/ /* lookup(): look up a 2 character string in a list */ /****************************************************/ static int lookup(const char *str, const char *lst) { const char *pos; char key[4]; key[0] = str[0]; key[1] = str[1]; key[2] = '|'; key[3] = '\0'; pos = strstr((const char *) lst, (const char *) key); if (pos == NULL) { return 0; } else { return 1 + (word) ((pos-lst)/3); } } /* end lookup() */ /*============================*/ /*===== Global functions =====*/ /*============================*/ /**************************************/ /* scr_exec(): Execute script command */ /**************************************/ void scr_exec(char *inp_line) { char cmd[10], val[10]; char *parmp="", *valp=""; extern int quitting, back_visible; char **mp; /* macro table pointer */ int ml; /* macro length */ int ms; /* macro selector */ /* --- check for user commands --- */ sprintf(cmd, "%-0.5s", inp_line); strupr(cmd); if (scn_left(cmd, "BACK")) { if (buf_backswitch(-1)) { buf_position(POS_LAST); buf_display(); } return; } if (scn_left(cmd, "HELP")) { cfg_help(1); return; } if (scn_left(cmd, "HALF")) { set_watching(-1); return; } if (scn_left(cmd, "WATCH")) { cfg.watch = 1 - cfg.watch; scn_setwatch(cfg.watch); display("WATCH ", 0); display((cfg.watch ? "on" : "off"), 1); return; } if (scn_left(cmd, "PPNLOG")) { /* not implemented yet */ cfg.ppnlog = 1 - cfg.ppnlog; scn_setppnlog(cfg.ppnlog); display("PPNLOG", 1); return; } if (scn_left(cmd, "HDX")) { /* half duplex */ cfg.hdx = 1 - cfg.hdx; com_sethdx(cfg.hdx); display("Duplex: ", 0); display((cfg.hdx ? "Half" : "Full"), 1); } if (scn_left(cmd, "Q")) { quitting = 1; } if (scn_left(cmd, "MAC ") && cmd[4] >= 'A' && cmd[4] <= 'Z') { ms = cmd[4] - 'A'; inp_line += 5 + strspn(inp_line+5, " "); ml = strlen(inp_line) + 1; mp = &cfg.mac[ms]; if (ml > 1) { if (**mp == '\0') { *mp = (char *) malloc(ml); } else { *mp = (char *) realloc(*mp, ml); } strcpy(*mp, inp_line); } else { free(*mp); *mp = ""; } sprintf(cmd, "[%c] ", ms+'A'); display(cmd, 0); display(inp_line, 1); return; } /* --- Scan config command and parameter --- */ (void) strupr((char *) inp_line); valp = NULL; if (scn_left(inp_line, "ID ")) { ppn_lookup(inp_line+3); } if (sscanf((const char *) inp_line, "%2s %2s", &cmd, &val) == 2) { cmd[2] = ' '; cmd[3] = '\0'; val[2] = '\0'; } else { return; } /* --- Identify command and parameter --- */ switch (lookup((const char *) cmd, "PO|SP|DA|PA|ST|")) { case 1: /* PO */ parmp = "COM Port"; if (val[0] == '1') { com_setport(SER_COM1); cfg.po = 1; valp = "1"; } else if (val[0] == '2') { com_setport(SER_COM2); cfg.po = 2; valp = "2"; } else if (val[0] == '3') { com_setport(SER_COM3); cfg.po = 3; valp = "3"; } else if (val[0] == '4') { com_setport(SER_COM4); cfg.po = 4; valp = "4"; } break; case 2: /* SP */ parmp = "Speed"; switch (lookup((const char *) val, "30|12|24|48|96|19|")) { case 1: /* 300 */ com_setbaud(SER_BD300); cfg.sp = 30; valp = "300"; break; case 2: /* 1200 */ com_setbaud(SER_BD1200); cfg.sp = 12; valp = "1200"; break; case 3: /* 2400 */ com_setbaud(SER_BD2400); cfg.sp = 24; valp = "2400"; break; case 4: /* 4800 */ com_setbaud(SER_BD4800); cfg.sp = 48; valp = "4800"; break; case 5: /* 9600 */ com_setbaud(SER_BD9600); cfg.sp = 96; valp = "9600"; break; case 6: /* 19200 */ com_setbaud(SER_BD19200); cfg.sp = 19; valp = "19200"; break; } break; case 3: /* DA */ parmp = "Data bits"; if (val[0] == '7') { com_setdata(SER_WD7); cfg.da = 7; valp = "7"; } else if (val[0] == '8') { com_setdata(SER_WD8); cfg.da = 8; valp = "8"; } break; case 4: /* PA */ parmp = "Parity"; switch (lookup((const char *) val, "NO|EV|OD|")) { case 1: /* NOne */ com_setpari(SER_PANO); cfg.pa = 'N'; valp = "None"; break; case 2: /* EVen */ com_setpari(SER_PAEV); cfg.pa = 'E'; valp = "Even"; break; case 3: /* ODd */ com_setpari(SER_PAOD); cfg.pa = 'O'; valp = "Odd"; break; } break; case 5: /* ST */ parmp = "Stop bits"; if (val[0] == '1') { com_setstop(SER_ST1); cfg.st = 1; valp = "1"; } else if (val[0] == '2') { com_setstop(SER_ST2); cfg.st = 2; valp = "2"; } break; } /* end switch */ if (valp != NULL) { display(parmp, 0); display(": ", 0); display(valp, 1); } } /* end scr_exec() */ /****************************************/ /* cfg_help(): Show or hide HELP screen */ /****************************************/ void cfg_help(int on_off) { char **hp; if (!on_off) { win_select(WIN_HELP); win_hide(); help_visible = 0; } else if (!help_visible) { win_open(WIN_HELP, 0, 1, 75, 21, MK_ATT(WHITE,BROWN)); win_clear(); win_xy(0, 0); for (hp=help_msgs; *hp; hp++) { win_puts(" "); win_puts(*hp); win_puts("\r\n"); } win_fg(BLACK); win_puts(PROGVERS); win_x(44); win_fg(YELLOW); win_puts("Hit ESC to close this screen!"); win_show(); help_visible = 1; } } /* end cfg_help() */ /****************************************/ /* cfg_hidemac(): hide macro key window */ /****************************************/ void cfg_hidemac() { win_select(WIN_MACS); win_hide(); } /* end cfg_hidemac() */ /***********************************************/ /* cfg_load(): Read and process a script file */ /***********************************************/ int cfg_load(char *scr_filename) { FILE *inp_file; char inp_line[80]; char *crpos; inp_file = fopen(scr_filename, "rt"); if (inp_file == NULL) { sprintf(inp_line, ">>> Missing configuration file %s.", scr_filename); display(inp_line, 1); display(" It will be created automatically after you quit ($Q)", 1); display(" ", 1); display(" Type $HELP if you need to see configuration commands.", 1); return 1; } for (;;) { /* --- Get line of input --- */ if (fgets((char *) inp_line, 80, inp_file) == NULL) break; crpos = strchr(inp_line, '\n'); if (crpos != NULL) *crpos = '\0'; scr_exec(inp_line); } /* end while */ fclose(inp_file); return 0; } /* end cfg_load() */ /****************************************/ /* cfg_mkey: return macro key expansion */ /****************************************/ char *cfg_mkey(int k) { static char kexp[DPY_COLS+1]; int nk; char *kpo, *kps, *kpr; if (k < 0 || k > 25) return ""; kpo = cfg.mac[k]; kpr = kexp; kps = ""; nk = 0; while (nk>> Could not write config file!", 1); return 1; } fprintf(cfg_out, "PO %d\n", cfg.po); fprintf(cfg_out, "SP %d\n", cfg.sp); fprintf(cfg_out, "DA %d\n", cfg.da); fprintf(cfg_out, "PA %2.2s\n", strchr("OD|NO|EV", cfg.pa)); fprintf(cfg_out, "ST %d\n", cfg.st); if (cfg.watch) { fprintf(cfg_out, "WATCH\n"); } if (cfg.ppnlog) { fprintf(cfg_out, "PPNLOG\n"); } if (cfg.hdx) { fprintf(cfg_out, "HDX\n"); } for (jm=0; jm<26; jm++) { if (*(cfg.mac[jm])) { fprintf(cfg_out, "MAC %c %s\n", jm+'A', cfg.mac[jm]); } } fclose(cfg_out); unlink("WTSTART.WTS"); rename("WTSTART.TMP", "WTSTART.WTS"); return 0; } /* end cfg_save() */ /*******************************************/ /* cfg_showmac: return macro key expansion */ /*******************************************/ void cfg_showmac(void) { int jk, nmac; int wheight; int xpos, ypos; char kdef[DPY_COLS/2+1]; /* count number of defined macros */ nmac = 0; for (jk=0; jk<26; jk++) { if (*(cfg.mac[jk])) nmac++; } wheight = (nmac+1)/2; if (wheight < 10) wheight++; win_open(WIN_MACS, 0, 1, DPY_COLS, wheight, MK_ATT(LIGHTRED,BLACK)); xpos = 0; ypos = 0; for (jk=0; jk<26; jk++) { if (*(cfg.mac[jk])) { sprintf(kdef, "[%c] %-37.37s", 'A'+jk, cfg.mac[jk]); win_xy(xpos, ypos); win_puts(kdef); if (xpos == 0) { xpos = 40; } else { xpos = 0; ypos++; } } } win_show(); } /* end cfg_showmac() */ /* === EOF(WtCfg.C) === */