/* TERM module File #1 */ #include "zmp.h" #include #define autolen 6 /* length of ZRQINIT required for auto rx */ static short Chpos, Locpos, Keycount, Keypoint; static char Keybuf[25]; ovmain() { static short i, mdmdata, dolabel; static short lastkey = '\0', fkey, autopos; static char autoseq[] = { '*','*',CTRLX,'B','0','0' }; static char kbdata, *p; if (FirsTerm) { locate(0,0); /* print header if first time*/ prompt(FALSE); /* but don't clear screen */ locate(15,0); /* then put cursor near bottom */ printf("Ready. \n"); /* overwrite 'wait' */ Chpos = Locpos = 0; /* clear character position */ FirsTerm = FALSE; /* don't come here again */ } else prompt(TRUE); printf(Message); /* print any message */ *Message = '\0'; /* once only */ startcapture(); autopos = Keycount = Keypoint = 0; /* no remote xfer, no keys in buffer */ Zmodem = FALSE; /* ensure we don't auto zmodem */ purgeline(); /* get rid of any junk */ /* Main loop: */ while (TRUE) { if (Keycount) { /* get any buffered keys */ kbdata = Keybuf[Keypoint++]; Keycount--; if (kbdata == RET) { /* Translate ! to CR/LF */ kbdata = CR; Keybuf[--Keypoint] = LF; Keycount++; /* get LF next time */ } if (kbdata == WAITASEC) { /* handle pause */ wait(1); kbdata = '\0'; /* that's it for this loop */ } } else kbdata = getch(); /* if none, any at keyboard */ if (kbdata) { if (lastkey == ESC) { fkey = toupper(kbdata); /* allow ESC ESC without complications */ lastkey = (kbdata == ESC) ? '\0' : kbdata; dolabel = TRUE; flush(); switch (fkey) { case RECEIVE: case SEND: case CONFIG: keep(Lastlog,FALSE); return fkey; break; case USER: keep(Lastlog, FALSE); printf("\nEnter overlay name: zm"); scanf("%s", Buf); strcpy(Pathname, "zm"); strcat(Pathname, Buf); if (p = index(Pathname, '.')) *p = '\0'; return fkey; break; case CAPTURE: capturetog(Logfile); dolabel = FALSE; Chpos = Locpos = 0; break; case DIR: killlabel(); keep(Lastlog,FALSE); directory(); startcapture(); Chpos = Locpos = 0; dolabel = FALSE; break; case PRTSCRN: screenprint(); dolabel = FALSE; Chpos = Locpos = 0; break; case HANGUP: hangup(); dolabel = FALSE; Chpos = Locpos = 0; break; case COMMAND: docmd(); break; case DIAL: keep(Lastlog,FALSE); dial(); dolabel = FALSE; Chpos = Locpos = 0; purgeline(); startcapture(); break; #ifdef HOSTON case HOST: keep(Lastlog,TRUE); QuitFlag = FALSE; Inhost = TRUE; while (!QuitFlag) dohost(); Inhost = FALSE; flush(); cls(); startcapture(); break; #endif case TOGPRT: toggleprt(); dolabel = FALSE; Chpos = Locpos = 0; break; case DISK: diskstuff(); Chpos = Locpos = 0; break; case HELP: if (Keybuf[0] = help()) { lastkey = ESC; Keycount = 1; Keypoint = 0; dolabel = FALSE; } Chpos = Locpos = 0; break; case QUIT: doexit(); break; case CLRSCR: cls(); break; case BRK: sendbrk(); printf("\nBreak sent.\n"); dolabel = FALSE; Chpos = Locpos = 0; break; case DISPKEYS: keydisp(); dolabel = FALSE; Chpos = Locpos = 0; break; default: dolabel = FALSE; i = fkey - '0'; if ((i >= 0) && (i <= 9)) { strcpy(Keybuf,KbMacro[i]); Keycount = strlen(Keybuf); Keypoint = 0; } else mcharout(kbdata); /* send it if not anything else */ break; } /* end of switch*/ if (dolabel) prompt(TRUE); /* print header */ } /* end of if lastkey == ESC */ else if ((lastkey = kbdata) != ESC) { if (WordWrap && Locpos > 72 && kbdata != CR) { if (kbdata == ' ') { /* newline on space */ newline(NULL); goto charin; /* no char */ } else if (Locpos >= 78) { newline(kbdata); kbdata = '-'; /* hyphenate */ } } mcharout(kbdata); /* Not a function key */ if (kbdata == CR) /* CR resets it */ Locpos = 0; else if (kbdata >= ' ') /* if ~ctl char, */ Locpos++; /* bump it */ else if (kbdata == '\b' && Locpos) Locpos--; /* backspace */ ilfloop: if (!FDx) { prtchr(kbdata); if (kbdata == CR) { kbdata = LF; if (RemEcho) mcharout(kbdata); goto ilfloop; } } } } /* end of if char at kbd */ charin: if (minprdy()) { mdmdata = mcharinp(); /* Character at modem */ if (mdmdata == autoseq[autopos++]) { /* ZRQINIT? */ if (autopos == autolen) { printf("\nZMP: Zmodem receive.\n"); keep(Lastlog,FALSE); Zmodem = TRUE; /* yes, do auto.. */ return RECEIVE; /* ..zmodem receive */ } } else /* no, reset ZRQINIT sequence test */ autopos = (mdmdata == '*') ? 1 : 0; if (ParityMask) /* if flag on, */ mdmdata &= 0x7f; /* remove parity */ if (Filter && (mdmdata > '\r') && (mdmdata < ' ')) goto endloop; /* filter control chars */ olfloop: prtchr(mdmdata); /* print the character */ tobuffer(mdmdata); toprinter(mdmdata); if (RemEcho) { mcharout(mdmdata); if (mdmdata == CR) { mdmdata = LF; goto olfloop; } } } endloop: prtservice(); /* service printer at the end of each loop */ } /* end of while */ }/* end of main */ /* Force a new line for wordwrap (only on locally entered characters) */ newline(c) char c; { Keycount = Keypoint = 0; Keybuf[Keycount++] = '\r'; /* do cr */ Keybuf[Keycount++] = c; /* add the character (may be null) */ Keybuf[Keycount] = '\0'; /* terminate */ } /* print character, handling tabs (can't use bdos 2 as it reacts to ctl-s) */ prtchr(c) char c; { if (c == '\t') { /* process tabs */ bdos(DIRCTIO,' '); /* do at least one */ while (++Chpos % 8) bdos (DIRCTIO,' '); /* pad with space */ } else { bdos(DIRCTIO,c); /* just print it */ if (c >= ' ') /* if printable, */ Chpos++; /* bump character position */ else if (c == '\r') /* cr resets both */ Locpos = Chpos = 0; } } tobuffer(c) int c; { if (BFlag) { MainBuffer[TxtPtr++] = (char)c; if (TxtPtr > Buftop) { keep(Lastlog,TRUE); /* must be true since remote */ startcapture(); /* is probably still going */ } } } /* Print message at top of page. Clear screen first if clear set */ prompt(clear) short clear; { if (clear) cls(); printf("\rTerminal Mode: ESC H for help. "); printf("Drive %c%d: %u baud Port <%c> %s\n", Currdrive,Curruser,Baudtable[Current.cbaudindex], Port ? 'B' : 'A', RemEcho ? "Echo" : (FDx ? "Fdx" : "Hdx")); if (BFlag) printf("\t\t\tCapture ON: %s\n", Lastlog); Chpos = Locpos = 0; /* reset character position */ } toprinter(i) int i; { char c; c = (char) i; if (PFlag && (c != '\f')) { /* don't print form feeds */ *Prthead++ = c; adjustprthead(); } } toggleprt() { PFlag = !PFlag; if (PFlag) { if (getprtbuf() != OK) PFlag = FALSE; else printf("\nPrinter ON\n"); } else { while (prtservice()) ; /* Empty the buffer */ bdos(5,'\r'); /* do final cr/lf */ bdos(5,'\n'); free(Prtbuf); printf("\nPrinter OFF\n"); } } getprtbuf() { keep(Lastlog,TRUE); /* need to steal some of the buffer */ Prtbuf = malloc(Pbufsiz); if (allocerror(Prtbuf)) return NERROR; Prthead = Prttail = Prtbottom = Prtbuf; Prttop = Prtbuf + Pbufsiz - 1; startcapture(); #ifdef DEBUG printf("\nPrtbuf = %x\n",Prtbuf); #endif return OK; } /* Quit. */ doexit() { static char c; killlabel(); putlabel("Are you SURE you want to exit ZMP? (Y/N) "); if (c = toupper(dio()) == 'N') return; keep(Lastlog,FALSE); reset(Invokdrive,Invokuser); deinitvector(); /*restore interrupt vector*/ cls(); userout(); /* user-defined exit routine */ exit(0); /* and quit */ } prtservice() /*printer service routine*/ { if (PFlag) { if (pready()) { if (Prthead != Prttail) { bdos(5,*Prttail++); /* write list byte */ if (Prttail > Prttop) Prttail = Prtbottom; } return (Prthead != Prttail); /* Return true if buffer full */ } } } pready() /*get printer status using bios call*/ { return (bios(14 + 1)); } adjustprthead() { if (Prthead > Prttop) Prthead = Prtbottom; } setace(n) /* for a particular phone call */ int n; { Current.cbaudindex = Book[n].pbaudindex; Current.cparity = Book[n].pparity; Current.cdatabits = Book[n].pdatabits; Current.cstopbits = Book[n].pstopbits; updateace(); } dial() { static char *number; /* buffer for number to be sent to modem */ static char *result; /* buffer for responses from modem */ static char *instr; /* buffer for numbers entered at keyboard */ static int connect, oldbaud, oldparity, olddata, oldstop; static int status, i, j, n, nocnt, action, c; static char *p, ch; static char dialprog[] = "\nDialling %s..."; if (allocerror(number = malloc(128))) return; if (allocerror(result = malloc(128))) { free(number); return; } if (allocerror(instr = malloc(128))) { free(number); free(result); return; } oldbaud = Current.cbaudindex; /* save current values */ oldparity = Current.cparity; olddata = Current.cdatabits; oldstop = Current.cstopbits; for (i = 0; i < 40; i++) { /* wait for key for 4 secs */ if (ch = getch()) break; mswait(100); } Book = (struct phonebook *) MEMORY_FULL; /* prepare for abort */ if (ch == ESC) goto abort; /* quit if escape */ instr[0] = ch; /* else put key (if any) in string */ instr[1] = '\0'; if (!ch) { /* if he didn't enter one, */ status = shownos(); /* read and display numbers */ printf("\nEnter letters and/or numbers, separated by commas..\n: "); getline(instr, 80); /* read a line */ } else status = loadnos(); /* just read if he entered one */ QuitFlag = connect = FALSE; Dialing = TRUE; if (j = strlen(instr)) { putlabel("Automatic Redial: Press ESC to stop"); for (i = 0, nocnt = 1; instr[i]; i++) if (instr[i] == ',') { instr[i] = 0; nocnt++; } i = nocnt; while (TRUE) { p = instr; nocnt = i; while (nocnt--) { n = -1; strcpy(number,Modem.dialcmd); if (*p == '+') { strcat(number,Sprint); p++; } else if (*p == '-') { strcat(number,Mci); p++; } if ((status == OK) && (j=strlen(p))==1) { if (isalpha(n = *p)) { n = toupper(n) - 'A'; setace(n); strcat(number,Book[n].number); strcat(number,Modem.dialsuffix); mstrout(number,FALSE); /* Dialling... */ printf(dialprog,Book[n].name); } else { printf("\nInvalid Number\n"); goto abort; } } else { strcat(number,p); strcat(number,Modem.dialsuffix); mstrout(number,FALSE); printf(dialprog,p); /* Dialling... */ } /*flush modem input*/ while (readline(10) != TIMEOUT); do { action = readstr(result,Modem.timeout); if (action == TIMEOUT) goto abort; printf("%s\n",result); } while (!(c=isin(result,Modem.connect)) && !isin(result,Modem.busy1) && !isin(result,Modem.busy2) && !isin(result,Modem.busy3) && !isin(result,Modem.busy4)); if (c) { /* got connect string */ printf("\007\nOn Line to %s\n", n >= 0 ? Book[n].name : p); if (n >= 0) FDx = !Book[n].echo; connect = TRUE; goto done; } mcharout(CR); /* wait for modem */ while (readline(10) != TIMEOUT); p += j+1; } if (kbwait(Modem.pause)) goto abort; } } abort: printf("Call Aborted.\n"); mcharout(CR); readstr(result,1); /*gobble last result*/ initace(oldbaud, oldparity, olddata, oldstop); /* restore old rate */ done: flush(); if (Book != (struct phonebook *) MEMORY_FULL) free(Book); free(instr); free(result); free(number); Dialing = FALSE; return connect; } shownos() { static int i, j, status; cls(); if ((status=loadnos()) == OK) { stndout(); printf(" NAME NUMBER B P D S E"); stndend(); for (i=0,j=1; i<20; i++,j++) { LOCATE(i+1,0); printf("%c - %s",i+'A',Book[i].name); LOCATE(i+1,41-strlen(Book[i].number)); printf(Book[i].number); LOCATE(i+1,44); printf("%4d %c",Baudtable[Book[i].pbaudindex], Book[i].pparity); printf(" %d %d %c\n",Book[i].pdatabits, Book[i].pstopbits,Book[i].echo?'H':'F'); } } return status; } loadnos() { static unsigned amount; char dummy; int i,result; FILE *fd; result = NERROR; amount = 21 * sizeof(struct phonebook); Book = (struct phonebook *) malloc(amount); if (!allocerror(Book)) { strcpy(Pathname,Phonefile); addu(Pathname,Overdrive,Overuser); fd = fopen(Pathname,"r"); if (fd) { for (i = 0; i < 20; i++) { fgets(Book[i].name,17,fd); fscanf(fd,"%c %s %d %c", &dummy, Book[i].number, &Book[i].pbaudindex, &Book[i].pparity); fscanf(fd,"%d %d %d", &Book[i].pdatabits, &Book[i].pstopbits, &Book[i].echo); fgetc(fd); /* remove LF */ } fclose(fd); result = OK; } } return result; } /* End of TERM module File 1 */