home *** CD-ROM | disk | FTP | other *** search
- #include "crcpchdr.h"
-
- /* Adaptation of standard newline() and spout(); open() used inst.of. sopen() */
-
- int newline()
- {
- spout("\r\n",0,1);
- return quit;
- }
-
- spout(line,arg1,arg2)
- char *line;
- int arg1, arg2;
- {
- static int linectr;
- char yesno[5], c;
-
- if (arg1==0) linectr = 0;
- if (line[0]=='\0') return;
- linectr += mputs(line);
- if (utlength) {
- if (linectr>=utlength) {
- c=*disp_reply("More?",yesno,sizeof(yesno));
- if (stpchr("NnQq",*yesno)!=NULL) quit = TRUE;
- linectr = 0;
- }
- }
- else linectr = 0;
- }
-
- /* Chop off the last node level in a DOS pathname */
- up_node(innode)
- char *innode;
- {
- int l;
-
- if (l=strlen(innode)) {
- while(--l) if (innode[l]==ESCSYM) {
- innode[l] = '\0'; /* Zap it */
- break;
- }
- }
- }
-
- ubeep(times)
- int times;
- {
- while(times--) {
- if (sys_test) pch(BEEP);
- else mcharout(BEEP);
- }
- }
-
- int int14h(port,function,value,reg)
- int port;
- char function;
- char value;
- int reg;
- {
- rmodem.x.dx = port;
- rmodem.h.ah = function;
- rmodem.h.al = value;
- rmodem.x.cx = reg;
- int86(com_inttype,&rmodem,&rmodem);
- return rmodem.x.ax;
- }
-
- minprdy() { return(int14h(port_used,TEST_COM,NA,NA)); }
- purgeline() { int14h(port_used,FLUSH_COM,NA,NA); }
-
- int mcharinp()
- {
- while(!minprdy() && rdsr()); /* Do nothing until ready or hangup */
- if (!rdsr()) return 0; /* Leave if hangup */
- return(int14h(port_used,READ_COM,NA,NA) & 0xFF);
- }
-
- mcharout(c)
- char c;
- {
- if (!rdsr()) return;
- int14h(port_used,WRITE_COM,c,NA);
- }
-
- prmodm(string) /* SPECIAL OUTPUT RTN, FOR 1200B - DTR ALWAYS ON */
- bhar *string;
- { /* Partly my slop, but DREAD I have to do it ! */
- while (*string) {
- mcharout(*string++);
- }
- }
-
- rdsr() { return(int14h(port_used,STATS_COM,NA,NA)&B7); } /* Use RLSD */
-
- drop_carrier() /* Should work on most modems. General */
- { /* Drop DTR & RTS for BRKTIM "for" loops */
- int c, i;
- c = int14h(port_used,READ_UART,NA,MCR); /* Read the MCR register */
- int14h(port_used,WRITE_UART,c&(B2|B3|B4|B5|B6|B7),MCR); /* Off DTR & RTS */
- for (i=0;i<BRKTIM;i++) ; /* Keep "OFF" for duration */
- int14h(port_used,WRITE_UART,c,MCR); /* Restore DTR & RTS */
- }
-
- reset_h1200b()
- {
- int c, i;
- c = int14h(port_used,READ_UART,NA,MCR); /* Read the MCR register */
- int14h(port_used,WRITE_UART,c | B2,MCR); /* Set OUT1 on H1200b = "OFF" */
- for (i=0;i<BRKTIM;i++) ; /* Keep "OFF" for duration */
- int14h(port_used,WRITE_UART,c,MCR); /* Switch modem back on */
- }
-
- int hs1200b()
- {
- return(!(int14h(port_used,READ_UART,NA,HSR)&B0)); /* TRUE iff (xFF).B0 FALSE */
- }
-
- waitterm()
- {
- while(dsr() && int14h(port_used,CHECK_OQ,NA,NA)); /* Wait for output queue */
- }
-
- /* hangup: tell the modem (if modem is in answer mode) to hangup the phone. */
- /* We wait until the output buffer is empty, however */
- hangup()
- {
- waitterm(); /* wait till all characters in queue are sent */
- drop_carrier(); /* Reset DTR, RTS on MODEM */
- }
-
- /*
- (int) parsetok(s, argcptr, argv)
- char *s; /* Input string to be parsed in place */
- int *argcptr; /* Pointer to input/output integer */
- char *argv[]; /* String token array */
-
- This function parses the input string (in place by placing \0's
- after 'tokens' in string) and returning token addresses in 'argv'
- array. Must set '*argcptr' to maximum size of string array 'argv[]'.
- '*argcptr' will be set to number of tokens actually parsed at exit,
- in addition, NULL (0) will be written to first invalid token ptr.
- Note therefore that size of array must be one larger than maximum
- number of tokens allowed (as defined by '*argcptr' at start).
-
- returns: 0 parse went well, *argcptr = # tokens
- !0 error, probably too may tokens in string
-
- */
-
- int parsetok(s,argcptr,argv)
- char s[];
- int *argcptr;
- char *argv[];
- {
- int maxarg;
-
- if ((maxarg=(*argcptr)-1)<0) return -1; /* Must provide n+1 pointers */
- *argcptr = 0;
- while (isspace(*s)) s++;
- while (*s != '\0' && *argcptr < maxarg) {
- argv[(*argcptr)++] = s;
- while (*s != '\0' && isspace(*s) == 0) s++;
- if (*s == '\0') break;
- *s++ = '\0';
- while (isspace(*s)) s++;
- }
- argv[*argcptr] = NULL; /* End list with NULL */
- return(*s != '\0'); /* Did we quit other than because of end ? */
- }
-
- char *input_pw(len)
- int len;
- {
- char *string;
- int what_it_used_to_be;
-
- what_it_used_to_be = silence ;
- silence = TRUE;
- string = rtrim(stpblk(uppercase(lineinput(len))));
- silence = what_it_used_to_be;
- return(string);
- }
-
- long timesec(hh,mm,ss)
- int hh,mm,ss;
- {
- return((long)hh*(long)SECPERHR+(long)mm*(long)SECPERMIN+(long)ss);
- }
-
- /* TIME DIFF: Returns time (in seconds) difference between mm1/dd1/yy1 & -2 */
- /* I.E. TIME1 is start time, TIME2 is end time. */
- long time_diff(hh1,mm1,ss1,hh2,mm2,ss2)
- int hh1,mm1,ss1,hh2,mm2,ss2;
- {
- long diff, timesec();
- diff = timesec(hh2,mm2,ss2)-timesec(hh1,mm1,ss1);
- if (diff<0) diff+=((long)HRS_IN_DAY*(long)SECPERHR); /* NOTE: Only ONE day grace given! */
- return(diff);
- }
-
-
- /* WAIT_SEC(nsec): This routine waits at least (nsec) seconds before returning
- (timing loop) */
- wait_sec(nsec)
- int nsec;
- {
- int hh1,mm1,ss1,ms1;
- int hh2,mm2,ss2,ms2;
- systime(&hh1,&mm1,&ss1,&ms1);
- do systime(&hh2,&mm2,&ss2,&ms2);
- while(time_diff(hh1,mm1,ss1,hh2,mm2,ss2)<=nsec);
- }
-
- char *elapsed_time(diff)
- long diff;
- {
- static char eltime[25];
- char workstr[25];
- long hh,mm,ss;
-
- if (diff<0) diff+=(long)HRS_IN_DAY*(long)SECPERHR; /* NOTE: Only ONE day grace given! */
-
- hh = diff / (long)(SECPERHR);
- mm = (diff-(hh*(long)(SECPERHR))) / (long)(SECPERMIN);
- ss = diff - hh*(long)(SECPERHR) - mm*(long)(SECPERMIN);
- workstr[0] = '\0';
- eltime[0] = '\0';
- if (hh>0L) {
- sprintf(eltime,"%ld hr",hh);
- strcat(workstr,eltime);
- }
- if (mm>0L) {
- sprintf(eltime," %ld min",mm);
- strcat(workstr,eltime);
- }
- if ((hh==0L && mm==0L) || ss>0L) {
- sprintf(eltime," %ld sec",ss);
- strcat(workstr,eltime);
- }
- strcpy(eltime,workstr);
- return(stpblk(eltime));
- }
-
- char *date()
- {
- static char datestr[12];
- int mo,dy,yr;
- sysdate(&mo,&dy,&yr);
- sprintf(datestr,"%02d/%02d/%02d",mo,dy,yr-BASEYEAR);
- return(datestr);
- }
-
- char *time()
- {
- static char timestr[9];
- int hh,mm,ss,ms;
- systime(&hh,&mm,&ss,&ms);
- sprintf(timestr,"%d:%02d%c",hh>12?hh-12:hh,mm,hh>11?'p':'a');
- return(timestr);
- }
-
- int abbrev(s,w,l)
- char s[], w[];
- int l;
- {
- int i,wl;
-
- for (i=0,wl=strlen(w);i<wl;i++) {
- if (s[i]!=w[i]) return 0;
- }
- return (i>=l);
- }
-
- dupchar(n,c)
- int n;
- char c;
- {
- while(n-->0) pch(c);
- }
-
- /*
- find_option: Returns TRUE if character OP found in string OPTS.
- Performs upper case conversion if necessary on OP.
- */
- int find_option(opts,op)
- char *opts, op;
- {
- if (stpchr(opts,op)!=NULL) return(TRUE);
- else return(stpchr(opts,toupper(op))!=NULL);
- }
-
- /*
- strip_options: We write to the 20 character array OPTS the
- option string we find in the first token position
- of ARGS. If the first token does not begin with
- a '-', then OPTS gets zapped and we return the
- left justified ARGS string.
- If args are found, they are left in OPTS -- WITHOUT the
- negative sign. Use routine 'FIND_OPTION' to test for
- presence of options.
- */
- char *strip_options(args,opts)
- char *args, opts[];
- {
- char *op, *ap;
- opts[0] = '\0';
- if (args==NULL||!*args) return(args); /* Should never be null, but ... */
- op = stpblk(args); /* Start of arg list should be option(s) */
- ap = stptok(op,opts,20," "); /* Break out options, if present */
-
- if (op[0]=='-') return(stpblk(ap)); /* Return, pointing to args */
- else {
- opts[0]='\0'; /* No arguments, not recognized first token */
- return(op); /* Return left trimmed argument pointer */
- }
- }
-
- char yesno()
- {
- char c;
- c = *lineinput(4);
- c = toupper(c);
- return(c);
- }
-
- char *itos(val)
- int val;
- {
- static char buf[10];
- sprintf(buf,"%d",val);
- return(buf);
- }
-
- char *ftos(fval)
- float fval;
- {
- static char floatbuf[20];
- sprintf(floatbuf,"%f",fval);
- return(floatbuf);
- }
-
- nothing_done() { printf("Nothing done\r\n"); }
-
- char *uppercase(s)
- char s[];
- {
- int i;
- for(i=0;s[i];i++) s[i]=toupper(s[i]);
- return(s);
- }
-
- char *rtrim(s)
- char s[];
- {
- int i;
- i = strlen(s); /* Find end of string */
- if (i) {
- while(s[--i]==' ' && i>=0); /* Back up over spaces until start */
- s[++i] = '\0'; /* Put null where last space was */
- }
- return(s);
- }
-
- char *lineinput(maxl)
- int maxl;
- {
- char *string;
- static char conbuff[STR_SIZE];
- output = TRUE;
- if (maxl>STR_SIZE) conbuff[0] = STR_SIZE;
- else conbuff[0] = maxl; /* inform it of its own limits */
- string = mgets(conbuff);
- cr();
- return (string);
- }
-
- char *disp_reply(outstr,instr,maxlen)
- char outstr[], instr[];
- int maxlen;
- {
- printf(outstr);
- strcpy(instr,rtrim(ltrim(lineinput(maxlen))));
- return(instr);
- }
-
- int sysdir(dirname,rootname)
- char *dirname, *rootname;
- {
- static char curdir[DIRSIZE];
- static char curroot[ROOTSIZE];
- int rc;
- /* Attempt to normalize (standardize) dir */
- uppercase(dirname);
- if (*dirname==ESCSYM) dirname++;
- zaphesc(dirname);
- if (!strcmp(curdir,dirname) && !strcmp(curroot,rootname)) return(0);
- if ((rc=dos_dir_int(dirname,DOS_CHDIR,rootname))==0) {
- strcpy(curdir,dirname);
- strcpy(curroot,rootname);
- }
- return(rc);
- }
-
- int typefile(filename,opts)
- char *filename;
- char *opts;
- {
- FILE *fp ;
- int quiet;
-
- quiet = find_option(opts,'q');
- if (!dsr()) return;
- if (*filename=='\0') return(1);
- else if ((fp=fopen(filename,"r")) == NULL) {
- printf("FILE '%s' NOT FOUND.\r\n",filename);
- return(2);
- }
- else {
- if (beginner && !quiet) ctlsctlk();
- fileterm(fp,opts); /* type out the file onto the terminal */
- fclose(fp);
- return(0);
- }
- }
-
- cls() { if (*utcls) printf(utcls); }
- /* Print user clear screen sequence */
-
- fileterm(fp,opts) /* Type a disk file onto the local terminal */
- FILE *fp;
- char *opts;
- {
- char *cp, c;
- char file_buff[LINESIZE+1];
- int page, lc;
-
- output = TRUE;
- quit = FALSE;
- page = find_option(opts,'p');
- if (find_option(opts,'t')) page = FALSE; /* Text override */
- lc = 0;
- /* Don't force users off while they are reading a file */
- noforcenow = TRUE;
-
- while(fgets(file_buff,termwidth,fp)!=NULL && !quit && dsr()) {
- if ((cp=stpchr(file_buff,CTLZ))!=NULL) {
- *cp = '\0';
- lc += mputs(file_buff);
- break;
- }
- else lc += mputs(file_buff);
- if (utlength && lc>=utlength && page) {
- if (beginner) printf("<ENTER> for more, Q to abort: ");
- else printf("More? ");
- quit |= ((c=yesno())=='Q' || c=='N');
- lc = 0;
- if (!quit) cls();
- }
- }
-
- noforcenow = FALSE;
- }
-
- ctlsctlk() { mputs("\r\nUse CTL-S or S to pause, CTL-K or K to abort.\r\n"); }
-
- char *skptok(str)
- char *str;
- {
- char *ans;
-
- ans = stpbrk(str," \r");
- return(ans==NULL?"":stpblk(ans));
- }
-
- long stol(s)
- char *s;
- {
- long n;
- n = 0;
- s = stpblk(s);
- while(*s >= '0' && *s <= '9') n=10*n+*s++-'0';
- return(n);
- }
-
- int stoi(s)
- char *s;
- {
- return((int)stol(s));
- }
-
- iputs(s) char *s; { int i; while(*s++) pch(' '); }
-
- esc() { printf("\\\r\n"); }
-
- bs() { pch(BS); pch(' '); pch(BS); }
- /* Should be smart or dumb: need flag */
- cr() { mputs("\r\n"); }
-
- warn_omem() { printf("Out of memory!\r\n"); }
-
- pch(c) char c; { bdos(OUTMODE,c); }
-
- int badfile(filename)
- char *filename;
- {
- printf("Can't open file %s\r\n",uppercase(filename));
- return(4);
- }
-
- /* Zap Hanging ESCape symbol - so can be sloppy about path specifications */
- char *zaphesc(str)
- char *str;
- {
- int i;
-
- if (i=strlen(str)) {
- if (str[--i]==ESCSYM) {
- if (i==0 || str[i-1]==DRVSYM) ;
- else str[i] = '\0';
- }
- }
- return str;
- }
-
- /* Preliminery subroutines for directory handling functions */
- /* NOTE: Caller to PREFIX_DIR MUST TAKE CARE OF OWN OUTPUT BUFFER ! */
- char *prefix_dir(buffer,dirname,rootname)
- char buffer[], *dirname, *rootname;
- {
- strcpy(buffer,rootname);
- if (!buffer[0] || dirname[0]) {
- if (!strcmp(dirname,"..")) { /* Back up one node if possible */
- up_node(buffer);
- return(buffer);
- }
- else if (!strcmp(dirname,".")) return(buffer);
- /* Make sure is ESCSYM between root & dir */
- if (buffer[0] && buffer[strlen(buffer)-1]==ESCSYM) ;
- else strcat(buffer,ESCSTR);
- if (*dirname==ESCSYM) dirname++; /* strip leading ESCSYM from dir */
- strcat(buffer,dirname);
- }
- zaphesc(buffer); /* Zap hanging esc sym if possible */
- return(buffer);
- }
-
- int dos_dir_int(dirname,function,rootname)
- char dirname[], rootname[];
- int function;
- {
- char buffer[2*(DIRSIZE+1)];
- return(bdos(function,prefix_dir(buffer,dirname,rootname)));
- }
-
- badnum(s)
- char *s;
- {
- printf("Number expected but read '%s'\r\n",s);
- }
-
-
- /*
- mputs: General output driver. Returns number of physical lines taken
- */
- int mputs(s)
- char *s;
- {
- char c,f;
- int wait_flg;
- int i,j;
-
- for (j=0,i=1,wait_flg=FALSE;*s && dsr() && !quit;++s) {
- do {
- if (bdos(KBHIT)) {
- c = bdos(CONSINP);
- c = toupper(c);
- switch(c) {
- case NULL:
- local_function(bdos(CONSINP));
- i = 0;
- break;
- case 'O':
- case CTL_O: output = FALSE;
- i = 0;
- j++;
- printf("\r\n");
- break;
- case 'P':
- case CTL_P: output = TRUE;
- break;
- /* case 'S':
- case CTL_S: wait_flg = TRUE;
- break;
- case 'Q':
- case CTL_Q: wait_flg = FALSE;
- output = TRUE;
- break;
- */ case 'K':
- case CTL_K: quit = TRUE;
- i = 0;
- j++;
- printf("\r\n");
- break;
- default: wait_flg = FALSE;
- }
- }
- } while(wait_flg && dsr()); /* End WHILE */
- if (output && !quit) {
- bdos(OUTMODE,*s);
- /* Do our best to anticipate horizontal cursor movement in 'i' */
- if (i && *s=='\b') i--;
- else if (*s=='\n') j++;
- else if (*s=='\r') i=0;
- else if (*s=='\t') i=i+9-i%8; /* assume tabs are *8 */
- else i++;
- }
- if (utwidth && i>utwidth) { /* Insert auto-CRLF on line wrap */
- printf("\r\n");
- i = 0;
- j++;
- }
- } /* End FOR */
- return(j);
- }
-
- char *mgets(string)
- char string[];
- {
- char c;
- int i; /* Index to STRING (current buffer). Starts=2 */
- int k; /* Index to LASTBUF for CTL_B function */
- static char lastbuf[LSTCSIZE];
- unsigned loops, secs, mins;
- long remaining;
- long cnct_seconds();
-
- i=2; k=0;
- quit = FALSE;
- output = TRUE;
- if (!beingforced) {
- remaining=((long)maxconnect*(long)SECPERMIN)-cnct_seconds();
- if (remaining>0L && remaining<=(long)WARN_TIME && !noforcenow) {
- printf("\r\nNOTE: Please finish up now; only %s left\r\n",elapsed_time(remaining));
- }
- else if (remaining<=0L && !noforcenow) {
- ubeep(1);
- printf("\r\nMaximum visiting time has been exceeded.\r\n");
- printf("Please limit your sessions to %d minutes\r\n",maxconnect);
- if (!no_account) printf("Leave feedback if you need an extension\r\n");
- ubeep(1);
- beingforced = TRUE;
- goto putnil;
- }
- if (string[0]>1) do {
- tryagain:
- for (mins=0;mins<MAXINPUTTIME;++mins) {
- if (!notimeout && mins==MAXINPUTTIME-1) {
- ubeep(2);
- printf("\r\n** One minute until input timeout -> forced hangup **\r\n");
- ubeep(2);
- }
- for (secs=0;secs<SECSPERMIN;++secs) {
- for (loops=0;loops<LOOPSPERSEC;++loops) {
- if (!dsr()) goto abortinp;
- if (bdos(KBHIT)) goto got_chr;
- }
- }
- }
- if (notimeout) goto tryagain;
- printf("\r\n*USER INPUT TIMEOUT*\r\n");
- hangup();
-
- abortinp: i = 2 ;
- break; /* Timeout */
-
- got_chr:
- c = bdos(CONSINP);
- chkc: switch(c) {
- case NULL: local_function(bdos(CONSINP));
- break;
- case CTL_A: /* Instant recall of last line */
- if (lastbuf[k] && string[0] > strlen(lastbuf+k)+i) {
- strcpy(string+i,lastbuf+k);
- i += strlen(lastbuf+k);
- if (silence) iputs(lastbuf+k);
- else mputs(lastbuf+k); /* Echo it */
- }
- else ubeep(1);
- k = 0; /* Reset lastbuf pointer */
- break;
- case CTL_B: /* One char at a time recall */
- c = lastbuf[k];
- if (c) {
- k++;
- goto chkc; /* I hope this is cool w/C */
- }
- else {
- ubeep(1);
- k = 0; /* Reset lastbuf ptr for nxtme */
- }
- break;
- case CTL_C:
- string[1]=0;
- string[2]='\0';
- c = '\r';
- break;
- case BEEP:
- ubeep(1);
- break;
- case '\b':
- if (i>2) {
- if (string[i-1]=='\n') ubeep(1);
- else {
- bs();
- if (string[--i]<=CTLZ) bs();
- }
- }
- else ubeep(1);
- break;
- case CTL_U:
- case ESC: esc(); i=2; break;
- case CTL_R:
- string[i] = '\0';
- esc();
- if (silence) iputs(string+2);
- else mputs(string+2);
- break;
- case '\r': bdos(OUTMODE,c); break;
- default:
- if (i>string[0]) ubeep(1);
- else {
- if (c<=CTLZ && c!='\n') {
- bdos(OUTMODE,'^');
- bdos(OUTMODE,c+'A'-1);
- }
- else if (duplex==HALF) ;
- else if (silence) bdos(OUTMODE,' ');
- else bdos(OUTMODE,c);
- string[i++] = c;
- }
- } /* End SWITCH */
- } while(c!='\r');
- } /* End !beingforced */
- putnil:
- string[i] = '\0';
- string[1] = i-2;
- stptok(string+2,lastbuf,sizeof(lastbuf),"");
- return(string+2);
- }
-