home *** CD-ROM | disk | FTP | other *** search
- /* XBBS Door Skeleton -- TC 2.0 code
- Copyright (c) 1990 by M. Kimes
- All Rights Reserved
- May be freely used for >>>FREE<<< programs */
-
- /* Miscellaneous notes:
- #define XBBS and the program will be compiled to read ONLINE.XBS
- #define DORINFO and the program will be compiled to read DORINFO?.DEF
- #define both and first ONLINE.XBS will be read, then DORINFO?.DEF
- #define neither and all info must come from command line
- #define FINDUSER and a routine to find a given user (by name) will
- be compiled in (finduser())
- #define NOREADFILE and the file reader routine (readtext()) will NOT
- be compiled
- */
-
-
- #include "msgg.h" /* XBBS include file */
-
-
- /* Change these to suit your Door */
-
- #define PROGRAM_NAME "Generic XBBS Door Skeleton v1.0"
- #define COPY_RIGHT "Copyright (c) 1990 by M. Kimes -- All Rights Reserved"
-
-
- /* #define DORINFO "UseIt" */
- /* #define XBBS "UseIt" */ /* Pick your interface */
-
-
- /* Function declarations */
-
- #ifdef XBBS
- void pascal getonline(void);
- void pascal readconfig(void);
- void pascal prepare(void);
- void pascal saveconfig(void);
- #endif
-
- #ifndef NOREADFILE
- char pascal readtext(char *,char);
- char * pascal write_line (char **text,word linelen);
- void pascal strip_blanklines (char *hold);
- #endif
-
- #ifdef FINDUSER
- struct _user *other pascal finduser(char *);
- #endif
-
- #ifdef DORINFO
- void pascal readinfo(void);
- #endif
-
- void pascal hitreturn(void);
- void pascal cls (void);
- void cdecl debug_print(char *,...);
- char * pascal addtolog(char *);
- char pascal inkey (void);
- char pascal carrchk (void);
- char pascal fossil (char function, char arg);
- char pascal printm (char *text);
- void pascal checkpos(void);
- void cdecl deinitialize (void);
- char * pascal genin (char length,char password,char caps,char hot,char type);
- void pascal print_stat();
- char * pascal fidodate (void);
- ulong pascal getxbbstime(void);
- char pascal specialkey(char);
- int cdecl break_handler(void);
- char pascal printg(char *);
- char pascal skip_blanks(FILE *fp);
- void pascal chat(void);
- void pascal printinfo(void);
- void pascal printhelp(void);
- char * pascal lstrip(char *);
- char * pascal rstrip(char *);
- int cdecl printfm(char *,...);
- char * pascal stripcr(char *);
-
- void pascal mainloop(void); /* Change as required */
-
-
- /* Global variables */
-
-
- #ifdef XBBS
- struct _config conf;
- struct _user user;
- word userno;
- struct time timeon;
- char timer_off;
- word hold_time;
- char age;
- char pages;
- struct _mboard mboard;
- struct _fboard fboard;
- struct _events event[10];
- char variable[10][82];
- #endif
-
- /* NOTE DEFAULTS! */
-
- char debug_mode=0;
- char graphics=0;
- word timelimit=30;
- word baud=0;
- char numlines=24;
- word seclvl=5;
- ulong startt=0;
- char sysopin=0;
- char fastANSI=0;
- char commport=0;
- struct time starter;
- union REGS rg;
- char logfile[133]="XBBS.LOG";
- char username[36]="A. Ghost";
- char width=80;
- char fast=0;
- char chatting=0;
- char chatted=0;
- char nodenumber=1;
- char system_name[64]="";
- char sysop[36]="";
-
-
-
- void cdecl main (argc,argv)
-
- int argc;
- char *argv[];
-
- {
-
- register word x;
- char *p;
-
- /* Please leave this next line in...thanks */
- fputs("\x1b[2J\x1b[0;2;37m\x1b[1;1H\04 Made using M. Kimes' DOORSKEL.C\n",stdout);
-
- directvideo=0;
- gettime(&starter);
- ctrlbrk(break_handler);
-
- if (argc==2 && !strcmp(strupr(argv[1]),"H")) {
- printinfo();
- printhelp();
- exit(0);
- }
- rg.x.ax=0x4400; /* Set console in raw mode */
- rg.x.bx=1;
- int86(33,&rg,&rg);
- rg.h.dh=0;
- rg.h.dl=rg.h.dl|0x20;
- rg.x.ax=0x4401;
- int86(33,&rg,&rg);
-
- atexit(deinitialize);
-
- #ifdef XBBS
- readconfig();
- getonline();
- #endif
-
- #ifdef DORINFO
- readinfo();
- #endif
-
- for (x=1;x<argc;x++) {
- strupr(argv[x]);
- switch (*argv[x]) {
- case 'F': fastANSI=1;
- break;
- case 'U': strncpy(username,&argv[x][1],36);
- username[35]=0;
- break;
- case 'N': nodenumber=(char)atoi(&argv[x][1]);
- break;
- case 'L': numlines=(char)atoi(&argv[x][1]);
- break;
- case 'W': width=(char)atoi(&argv[x][1]);
- break;
- case 'B': baud=(word)atoi(&argv[x][1]);
- break;
- case 'G': if(atoi(&argv[x][1])) graphics=1;
- break;
- case 'C': commport=(char)atoi(&argv[x][1]);
- break;
- case 'S': seclvl=atoi(&argv[x][1]);
- break;
- case 'T': timelimit=atoi(&argv[x][1]);
- break;
- case 'M': directvideo=atoi(&argv[x][1]);
- break;
- case '!': debug_mode=1;
- break;
- case 'X': strcpy(logfile,&argv[x][1]);
- break;
- default: fputs("\nUnknown argument `",stdout);
- fputs(argv[x],stdout);
- fputs("'\n",stdout);
- sleep(1);
- }
- }
- fossil(INIT,0);
- cls();
-
- printg("\x1b[0;1;37m");
- p=PROGRAM_NAME;
- if(baud) while (*p++) while(!fossil(TRANSMIT,*p)) carrchk();
- printinfo();
- printm("\n");
-
- mainloop();
-
- /* If you want to change parameters in CONFIG.BBS or ONLINE.XBS,
- change them, then call saveconfig() or prepare() here or in
- deinitialize() */
-
- }
-
-
-
- void pascal mainloop (void) {
-
- /* Here's where your main program goes. Change declaration as req'd */
-
-
- }
-
-
-
- void pascal printhelp (void) { /* Print help screen--edit to taste
- Add to as required */
-
- fputs("L<screen lines>\n",stdout);
- fputs("N<nodenumber>\n",stdout);
- fputs("U<user name>\n",stdout);
- fputs("W<screen width>\n",stdout);
- fputs("T<time in minutes>\n",stdout);
- fputs("B<baudrate (0-38400...?)>\n",stdout);
- fputs("G<graphics (0 or 1)>\n",stdout);
- fputs("C<commport (0=COM1)>\n",stdout);
- fputs("S<security level>\n",stdout);
- fputs("M<mode (0=direct video, 1=BIOS, 2=DOS)>\n",stdout);
- fputs("X<filename> (Log File)\n",stdout);
- fputs("F (Fast ANSI writes)\n",stdout);
- fputs("! (Debug mode on)\n",stdout);
- }
-
-
-
-
- int cdecl break_handler (void) { /* Diables ctrl-break */
-
- return 1;
-
- }
-
- void pascal chat (void) { /* Cheap chat-mode */
-
- char a[3];
-
- printg("\x1b[0;1;33m");
- printm("\n\nChat mode engaged\n\n");
- while (chatting) {
- *a=inkey();
- a[1]=0;
- if (chatting) {
- _AH=3;
- _BH=0;
- geninterrupt(16);
- if (*a==13) printm("\n");
- if ((*a==13) || (*a==' ' && _DL>70)) printm("\n");
- else printm(a);
- }
- }
- printm("\n\nChat mode ended\n\n");
- chatted++;
- }
-
-
-
- #ifndef NOREADFILE
-
- char pascal readtext (char *s,char paged) { /* Displays a text file
- This thing's got all
- sorts of fancy stuff
- in it if you set paged=1
- Otherwise it does a pretty
- dumb dump (ok for ANSI
- files) */
-
- long place2;
- long place;
- struct ffblk filestat;
- char dostring[181];
- char eof=0;
- word page;
- char a;
- long *pos;
- word scratch;
- FILE *fp;
- register int x;
- char prev=0;
- char *here;
- char *p;
- char *tempo;
- char temp='N';
- char lastpage=0;
- char searchstring[41];
- char holdstring[41];
- char teststring[81];
- char findend=0;
- char printanyway=0;
- char linelen;
- word lines=1;
-
- *searchstring=0;
- *holdstring=0;
-
- if (findfirst(s,&filestat,0)) return 1;
- if (!filestat.ff_fsize) return 1;
- if (!(fp=fopen(s,"rt"))) return 1;
- cls();
- printg("\x1b[0;1;33m");
- page=0;
- place2=ftell(fp);
- if (!paged) {
- printm("\n");
- while (!feof(fp) && !ferror(fp)) {
- if (!fgets(dostring,181,fp)) break;
- if(ftell(fp)<=place2) {
- while(fgetc(fp)=='\n'); /* Guard against Unix files & TC bug */
- continue;
- }
- place2=ftell(fp);
- printm(dostring);
- if(numlines) {
- lines++;
- if(lines>numlines+1) {
- lines=1;
- printm("More? (Y/n) ");
- fossil(FLUSHOUT,0);
- fossil(PURGEIN,0);
- linelen=*genin(1,0,1,1,YESNOM);
- for (x=0;x<12;x++) printm(BACKSPACE);
- if (linelen == 'N') break;
- }
- }
- a=toupper(inkey());
- if (a=='S' || a==' ') break;
- if (a=='P') sleep(5);
- }
- fclose(fp);
- if (numlines) if (lines>numlines-11) hitreturn();
- return 0;
- }
-
- /*
- if (!baud && *reader) {
- fclose(fp);
- sprintf(dostring,"%s %s",reader,s);
- system(dostring);
- return 0;
- }
- */
-
- p=strchr(s,':'); /* Strip path off filename for display */
- here=strrchr(s,'\\');
- if(!p && !here) here=s;
- else if (!here) here=&p[1];
- else if (p) here= (p<here) ? &here[1] : &p[1];
- else here++;
-
- pos=(long *)malloc((word)(sizeof(long)*1024));
- if(!pos) {
- fclose(fp);
- printm("\nOut of memory\n");
- exit(4);
- }
-
- printfm(" -=-=Reading: %s=-=- Page #%u\n",here,page+1);
-
- printg("\x1b[0;1;32m");
- if(skip_blanks(fp)) goto Abort;
- place2=pos[0]=ftell(fp);
- lines=1;
- while (!feof(fp) && !ferror(fp)) {
- if ((*searchstring && !printanyway) || findend) goto Searcher;
- Domore:
- if (!fgets(dostring,181,fp)) {
- eof++;
- goto EEOF;
- }
- if(ftell(fp)<=place2) {
- while(fgetc(fp)=='\n'); /* Guard against Unix files & TC bug */
- continue;
- }
- place2=ftell(fp);
- stripcr(dostring);
- while (p=strchr(dostring,'\xc')) memmove(p,&p[1],strlen(&p[1])+1);
- while (p=strchr(dostring,'\x1b')) memmove(p,&p[1],strlen(&p[1])+1);
- if (!*dostring) {
- if (prev) {
- prev=0;
- eof=skip_blanks(fp);
- if (eof) goto EEOF;
- else goto Domore;
- }
- else prev++;
- }
- else prev=0;
- if (*searchstring) {
- strcpy(teststring,dostring);
- strupr(teststring);
- if (strstr(teststring,searchstring)) {
- printg("\x1b[0;1;37m");
- fast=2;
- printm(dostring);
- printg("\x1b[0;1;32m");
- lines++;
- }
- else {
- fast=1;
- printm(dostring);
- lines++;
- }
- }
- else {
- fast=1;
- printm(dostring);
- lines++;
- }
- scratch=strlen(dostring);
- p=dostring;
- while(tempo=strchr(p,'\t')) {
- p=tempo+1;
- scratch+=3;
- }
- if (scratch<79) {
- printm("\n");
- scratch++;
- }
- if (scratch>width) {
- lines++;
- }
- a=toupper(inkey());
- if (a=='S' || a==' ') break;
- if (a=='P' || a=='-') if (page) goto SkipThis;
- if (a=='M') goto Direct;
- Searcher:
- if (lastpage) goto EEOF;
- if ((a=='N') || (*searchstring) || (findend)) {
- if (findend) {
- if (++page>1024) page=1;
- pos[page]=ftell(fp);
- }
- place2=place=ftell(fp);
- Domore1:
- while (!feof(fp) && !ferror(fp)) {
- Domore2:
- if (!fgets(dostring,181,fp)) {
- eof++;
- break;
- }
- if(ftell(fp)<=place2) {
- while(fgetc(fp)=='\n'); /* Guard against Unix files & TC bug */
- continue;
- }
- place2=ftell(fp);
- while (p=strchr(dostring,'\xc')) memmove(p,&p[1],strlen(&p[1])+1);
- while (p=strchr(dostring,'\x1b')) memmove(p,&p[1],strlen(&p[1])+1);
- if (!strcmp(dostring,"\n")) {
- if (prev) {
- prev=0;
- eof=skip_blanks(fp);
- if (eof) break;
- else goto Domore2;
- }
- else prev++;
- }
- else prev=0;
- if (*searchstring) {
- if (strstr(strupr(dostring),searchstring)) {
- printanyway++;
- break;
- }
- }
- lines++;
- scratch=strlen(dostring);
- p=dostring;
- while(tempo=strchr(p,'\t')) {
- p=tempo+1;
- scratch+=3;
- }
- if (scratch<79) {
- scratch++;
- }
- if (scratch>width) lines++;
- if (numlines) if ((lines>=numlines-2) || (feof(fp)) || (eof)) break;
- }
- fossil(PURGEIN,0);
- eof=skip_blanks(fp);
- if (feof(fp) || eof || printanyway) {
- if (*searchstring && !printanyway) {
- printm("\nNot found...\n");
- goto EEOF;
- }
- fseek(fp,place,SEEK_SET);
- clearerr(fp);
- cls();
- printg("\x1b[0;1;33m");
- printfm(" -=-=Reading: %s=-=- Page #%u\n",here,page+1);
- printg("\x1b[0;1;32m");
- findend=prev=eof=0;
- lastpage=lines=1;
- goto Domore;
- }
- if ((*searchstring || findend) && !eof) {
- if (++page>1024) page=1;
- pos[page]=place=place2=ftell(fp);
- lines=1;
- goto Domore1;
- }
- }
- EEOF:
- if (numlines) if ((lines>=numlines-2) || (feof(fp)) || (eof)) {
- Direct:
- linelen=0;
- prev=0;
- eof=skip_blanks(fp);
- if (feof(fp) || eof) {
- printg("\x1b[0;1;31m");
- printm(" (END)");
- linelen+=6;
- printg("\x1b[0;1;33m");
- temp='S';
- }
- else {
- if (a=='M' || a=='N') goto SkipThis;
- temp='N';
- printg("\x1b[0;1;33m");
- printm(" [F]ind [E]nd [N]ext [M]ore");
- linelen+=27;
- }
- if (page) {
- printm(" [H]ome [P]rior");
- linelen+=15;
- }
- linelen+=sprintf(dostring," [O]ver [S]top: [%c] ",temp);
- printm(dostring);
- fossil(FLUSHOUT,0);
- pos[page+1]=ftell(fp);
- Getitagain:
- fossil(PURGEIN,0);
- a=*genin(1,0,1,1,ALLL);
- SkipThis:
- findend=0;
- lastpage=0;
- printanyway=0;
- *searchstring=0;
- switch (a) {
- case 'S': goto Abort;
- case 'H': if (!page) {
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- }
- page=0;
- fseek(fp,0,SEEK_SET);
- break;
- case 'E': if (feof(fp) || eof) {
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- }
- findend++;
- break;
- case 'F': if (feof(fp) || eof) {
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- }
- printg("\x1b[0;1;35m");
- printfm("\n Search string: [%s]\n -> ",holdstring);
- strcpy(searchstring,genin(40,0,1,0,ALLL));
- if (!*searchstring) {
- if (*holdstring) {
- strcpy(searchstring,holdstring);
- if (++page>1024) page=1;
- pos[page]=ftell(fp);
- }
- }
- else strcpy(holdstring,searchstring);
- fseek(fp,pos[page],SEEK_SET);
- eof=skip_blanks(fp);
- break;
- case 0: if (feof(fp) || eof) goto Abort;
- case 'N': if (feof(fp) || eof) {
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- }
- a=0;
- if (++page>1024) page=1;
- pos[page]=ftell(fp);
- break;
- case 'O': fseek(fp,pos[page],SEEK_SET);
- eof=skip_blanks(fp);
- break;
- case 'P':
- case '-': if (page) {
- fseek(fp,pos[--page],SEEK_SET);
- eof=skip_blanks(fp);
- break;
- }
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- case 'M': if (feof(fp) || eof) {
- printm("\x7");
- printm(BACKSPACE);
- goto Getitagain;
- }
- for (x=0;x<linelen;x++) printm(BACKSPACE);
- printg("\x1b[0;1;32m");
- if (numlines) lines=numlines-3;
- goto Domore;
- default: printm(BACKSPACE);
- goto Getitagain;
- }
- place2=ftell(fp);
- eof=0;
- cls();
- printg("\x1b[0;1;33m");
- if (findend || *searchstring) strcpy(teststring,"Scanning");
- else strcpy(teststring,"Reading");
- printfm(" -=-=%s: %s=-=- Page #%u\n",teststring,here,page+1);
- printg("\x1b[0;1;32m");
- lines=1;
- }
- }
- Abort:
- if(pos) free(pos);
- fclose(fp);
- return 0;
-
- }
-
-
-
- /*
-
- char * pascal write_line (char **text,word linelen) {
-
- static char line[81];
- word register x=0;
- char *p;
- char *pp;
-
- p=*text;
- pp=line;
- *pp=0;
- while(++x<linelen && *p && *p!='\r') {
- *pp++=*p++;
- *pp=0;
- }
- while(*pp==' ' && pp>line) {
- *pp=0;
- --pp;
- }
- if(*p==' ' || *p=='\r') {
- if(*p==' ') *pp=0;
- else p++;
- while(*p==' ') p++;
- }
- else if(x==linelen) {
- while(p>*text && *pp!=' ') {
- *pp=0;
- pp--;
- p--;
- }
- if(p==*text) {
- strncpy(line,*text,linelen);
- line[linelen]=0;
- p=text[linelen];
- }
- else p++;
- }
- *text=p;
- return line;
- }
-
-
- void pascal strip_blanklines (char *hold) {
-
- char *p;
-
- p=&hold[strlen(hold)-1];
- while(*p=='\r' && p>hold) {
- *p=0;
- p--;
- }
- }
-
- */
-
- #endif
-
-
-
- char pascal skip_blanks (FILE *fp) { /* Skips blank lines, what else? */
-
- ulong pos;
- char temp[81];
- char eof=0;
-
- do {
- pos=ftell(fp);
- if (!fgets(temp,81,fp)) eof++;
- stripcr(temp);
- } while ((!eof) && (!feof(fp)) && (!*temp));
- if (!eof && !feof(fp)) fseek(fp,pos,SEEK_SET);
- return eof;
-
- }
-
-
-
- char pascal printg (text) /* Print only if user has graphics set */
-
- char *text;
-
- {
-
- if (graphics) return (printm(text));
-
- }
-
-
-
- char pascal inkey (void) /* MIMICS BASIC'S INKEY$ FUNCTION */
-
- {
-
- char arg=0;
- static int check=0;
-
- rg.h.ah=11;
- int86(33,&rg,&rg);
- if (rg.h.al!=0) {
- rg.h.ah=8;
- int86(33,&rg,&rg);
- if (rg.h.al!=0)return((char)(rg.h.al));
- rg.h.ah=8;
- int86(33,&rg,&rg);
- arg=specialkey(rg.h.al);
- if (arg) return (arg);
- }
- if (baud) {
- arg=carrchk();
- if (!(arg & 1)) return (0);
- return (fossil(RECVWAIT,arg));
- }
- if (check!=(int)(timelimit-(getxbbstime()/60))) {
- check=(int)(timelimit-(getxbbstime()/60));
- }
- return (0);
- }
-
-
-
- char pascal specialkey (a) /* Handles special local-only keys
- Add anything you like (extended keys) */
-
- char a;
-
- {
-
- char middle[82];
- int drive;
- char dir[MAXDIR];
-
- switch (a) {
- case 45:exit (0); /* QUIT DOOR */
- case 46:if (!chatting) { /* CHAT */
- chatting++;
- chat();
- }
- else chatting=0;
- break;
- case 35: /* HANG UP */
- fossil(DTR,DOWN);
- exit(1);
- case 36: /* SysOp SHELL */
- printm("\nThe SysOp has jumped to DOS...please wait...\n");
- fossil(FLUSHOUT,0);
- drive=getdisk();
- getcurdir(++drive,dir);
- fossil(DEINIT,0);
- fputs("\nEXIT to return\n",stdout);
- system ("");
- fossil(INIT,0);
- setdisk (--drive);
- strcpy(middle,"\\");
- strcat(middle,dir);
- chdir(middle);
- printm("\nThe SysOp has returned...please continue...\n");
- chatted++;
- break;
- case 72: /* MORE TIME */
- timelimit++;
- break;
- case 80: /* LESS TIME */
- if (timelimit<1) timelimit=0;
- else timelimit--;
- break;
- case 73:return 'P';
- case 81:return 'N';
- case 71:return 'H';
- }
- startt=getxbbstime();
- return 0;
- }
-
-
-
- void pascal cls (void) { /* MIMICS BASIC'S CLS FUNCTION LOCAL & REMOTE */
-
- char clr_string[]="\x1b[0m\x1b[2J";
- char *p;
-
- if(!graphics)strcpy(clr_string,"\xc");
- p=clr_string;
- if(baud) while (*p++) while(!fossil(TRANSMIT,*p)) carrchk();
- fputs("\x1b[0;2m\x1b[2J",stdout);
- print_stat();
- }
-
-
- char pascal fossil (function,arg) /* HANDLES MOST USEFUL FOSSIL CALLS */
-
- char function;
- char arg;
-
- {
-
- if(!baud) return 0;
- if ((function == FLUSHOUT) && (baud>0))
- {
- do {
- carrchk();
- rg.h.ah=3;
- rg.x.dx=commport;
- int86(20,&rg,&rg);
- }
- while ((rg.h.ah & 64)==0);
- return(0);
- }
-
- if (function == WATCHDOG) rg.h.al = arg;
- if (function == DTR) rg.h.al = arg;
- if (function == TRANSWAIT) rg.h.al = arg;
- if (function == TRANSMIT) rg.h.al = arg;
- if (function == ONOFF) rg.h.al = arg;
-
- rg.x.dx=commport;
- rg.h.ah=function;
- int86(20,&rg,&rg);
-
- if (function == INIT)
- {
- if (rg.x.ax != INITOK)
- {
- fputs("\nFossil not responding...RTFM.\n",stdout);
- exit (3);
- }
- return (0);
- }
-
- if (function == GETSTAT)
- {
- arg = rg.h.ah;
- if (rg.h.al & 128)
- {
- arg |= 128;
- return (arg);
- }
- arg &= 127;
- return (arg);
- }
-
- if (function == RECVWAIT) return (rg.h.al);
- if (function == TRANSMIT) return (rg.x.ax);
-
- return (0);
-
- }
-
-
-
- void cdecl deinitialize (void) /* DEINITIALIZES FOSSIL ON EXIT */
-
- {
-
- register word x;
-
- fossil(FLUSHOUT,0);
- fossil (DEINIT,0);
- fcloseall();
- rg.x.ax=0x4400; /* Set console in (std) cooked mode */
- rg.x.bx=1;
- int86(33,&rg,&rg);
- rg.h.dh=0;
- rg.h.dl=rg.h.dl&(~0x20);
- rg.x.ax=0x4401;
- int86(33,&rg,&rg);
- printm("\n");
- fputs("\x1b[0;2;37m\n",stdout);
- }
-
-
-
- char * pascal genin (length,password,caps,hot,type) /* GENERIC INPUT ROUTINE */
-
- char length;
- char password;
- char caps;
- char hot;
- char type;
-
- {
-
- static char input[257];
- int x=0;
- char one=0;
- char randchr[2];
-
- length--;
-
- AfterChat:
-
- strset(input,0);
- startt=getxbbstime();
-
- while ((getxbbstime()-startt)<241 || (chatted!=0)) {
-
- one=inkey();
- if (one == '\r') break;
-
- Nogo:
-
- if (one == 8) {
- if (x>0) {
- printm(BACKSPACE);
- input [--x]=0;
- if ((type==PHONE) && ((x==2) or (x==5))) printm(BACKSPACE);
- if ((type==DATE) && ((x==1) or (x==3))) printm(BACKSPACE);
- }
- continue;
- }
- if ((caps) or (type==YESNO) or (type==YESNOM) or (type==FLE) or (type==FLEW) or (type==FLEPW) or (type==FLEP)) one=toupper(one);
- if (x <= length) {
- if (type==NAME) {
- if((isalpha(one)==0) && (one!=' ') && (one!='.') && (one!='-') or (x==0 && one==' ')) continue;
- if ((one==' ') && (strchr(input,' ')!=NULL)) continue;
- }
- if (type==NEAT) {
- if((isalnum(one)==0) && (one!=' ') or (x==0 && one==' ')) continue;
- }
- if ((type==NEAT) or (type==NAME)) {
- if(x==0) {
- one=toupper(one);
- }
- else one=tolower(one);
- }
- if((type==NEAT) or (type==NAME)) {
- if((x>0) && ((input[x-1]==' ') or (input[x-1]=='.') or (input[x-1]=='-'))) one=toupper(one);
- }
- if ((type==SUBJECT) && (x==0)) one=toupper(one);
- if ((type==SUBJECT) && (isprint(one)==0)) continue;
- if ((type==ALLL) && (isprint(one)==0)) continue;
- if ((type==ALLL) && (one==127)) one=8;
- if ((type==ALPHA) && (isalpha(one)==0) && (one!=' ')) continue;
- if (((type==NUM) or (type==PHONE) or (type==DATE)) and (isdigit(one)==0)) continue;
- if ((type==ALPHANUM) and (isalnum(one)==0) and (one!=' ')) continue;
- if (((type==YESNO) or (type==YESNOM)) and (one!='Y' and one!='N')) continue;
- if (type==FLE) {
- if ((isalnum(one)==0) and (!strchr("._-+=!@#$%^&<>/",one))) continue;
- }
- if (type==FLEP) {
- if ((isalnum(one)==0) and (!strchr("._-+=!@#$%^&<>/\\:",one))) continue;
- }
- if (type==FLEW) {
- if ((isalnum(one)==0) and (!strchr("._-+=!@#$%^&<>/?*",one))) continue;
- }
- if (type==FLEPW) {
- if ((isalnum(one)==0) and (!strchr("._-+=!@#$%^&<>/?*\\:",one))) continue;
- }
- if ((type==FLE) or (type==FLEP) or (type==FLEW) or (type==FLEPW)) {
- if ((one=='.') and (strchr(input,'.')!=NULL)) continue;
- }
- }
- if (chatted>0) {
- chatted=0;
- goto AfterChat;
- }
-
- if ((one!=0) and (x <= length)) {
- input[x]=one;
- input[++x]=0;
- if (type==YESNOM) {
- return(input);
- }
- if (password==0) printm(&input[x-1]);
- if (password!=0) {
- randchr[0]=random(10)+33;
- randchr[1]=0;
- printm(randchr);
- }
- if ((type==PHONE) and ((x==3) or (x==6))) printm("-");
- if ((type==DATE) and ((x==2) or (x==4))) printm("/");
- AfterCtrl:
- if ((hot!=0)and(x >= length)) {
- return (input);
- }
- startt=getxbbstime();
- }
-
- }
- if (chatted) {
- chatted=0;
- goto AfterChat;
- }
- if ((getxbbstime()-startt)>240) {
- fputs("\nUser time-out...\n",stdout);
- exit (2);
- }
- return (input);
- }
-
-
- char pascal carrchk (void) /* Checks for carrier */
-
- {
- if (baud) {
- rg.x.dx=commport;
- rg.h.ah=GETSTAT;
- int86(20,&rg,&rg);
- if (!(rg.h.al & 128)) {
- sleep(1);
- rg.x.dx=commport;
- rg.h.ah=GETSTAT;
- int86(20,&rg,&rg);
- if (!(rg.h.al & 128)) {
- fossil(DTR,DOWN);
- baud=0;
- fputs("\n\04 Lost carrier...\n",stdout);
- exit (1);
- }
- }
- return (rg.h.ah);
- }
- return 0;
- }
-
-
- void pascal hitreturn (void) /* Pause until [Enter] is pressed */
-
- {
-
- register word x;
-
- startt=getxbbstime();
- printm("\n[Enter] to continue...");
- while ((getxbbstime()-startt)<241) {
- if (inkey()==13) goto hedid;
- }
- fputs("\n\x4 User time-out...\n",stdout);
- exit (2);
- hedid:
- for(x=0;x<22;x++) printm(BACKSPACE);
- }
-
-
- ulong pascal getxbbstime (void) { /* GP User Timer */
-
- static int hour;
- static int min;
- static int sec;
- static int lastsec;
- static int x;
- static int y;
- static struct time dos_time;
- static ulong xbbs_time;
- static char byebye=0;
- static int warned;
-
- gettime(&dos_time);
-
- hour=dos_time.ti_hour-starter.ti_hour;
- min=dos_time.ti_min-starter.ti_min;
- sec=dos_time.ti_sec-starter.ti_sec;
-
- if (dos_time.ti_hour<starter.ti_hour) hour=hour+24;
-
- xbbs_time=(long)(hour*3600)+(min*60)+sec;
- if(byebye) return xbbs_time;
-
- if (((timelimit*60)<(xbbs_time+120)) && (warned==0)) {
- warned++;
- printfm("\nWARNING: %u minutes remaining.",(timelimit-(xbbs_time)/60));
- }
-
- if (((timelimit*60) > ((xbbs_time+1L)+120L)) && (warned!=0)) warned=0;
-
- if ((timelimit*60) < (xbbs_time+1)) {
- byebye=1;
- timelimit=(word)(xbbs_time/60L)+4;
- printm("\nSorry, time to logoff...\n");
- fossil(FLUSHOUT,0);
- exit(0);
- }
-
- juststarting:
-
- if(dos_time.ti_sec!=lastsec) {
- lastsec=dos_time.ti_sec;
- x=wherex();
- y=wherey();
- gotoxy(68,25);
- textbackground(7);
- textcolor(0);
- cprintf("%02d:%02d:%02d|%03u",dos_time.ti_hour,dos_time.ti_min,dos_time.ti_sec,(word)(timelimit-(word)(xbbs_time/60L)));
- gotoxy(x,y);
- }
- return(xbbs_time);
- }
-
-
- void pascal printinfo (void) /* Just prints prog info locally */
-
- {
-
- printf(" %s\n\04 %s\n\04 Compiled: %s %s\n",PROGRAM_NAME,COPY_RIGHT,__DATE__,__TIME__);
-
- }
-
-
-
- char * pascal fidodate (void) /* Builds a Fido(tm) datestring */
-
- {
-
- char months[12][4]={
- "Jan",
- "Feb",
- "Mar",
- "Apr",
- "May",
- "Jun",
- "Jul",
- "Aug",
- "Sep",
- "Oct",
- "Nov",
- "Dec"
- };
- static char fdate[20];
- struct date dos_date;
- struct time dos_time;
-
- /* 26 Jul 89 06:23:47 */
-
- getdate(&dos_date);
- gettime(&dos_time);
-
- sprintf(fdate,"%02hu %s %02d %02hu:%02hu:%02hu",dos_date.da_day,months[dos_date.da_mon-1],dos_date.da_year%100,dos_time.ti_hour,dos_time.ti_min,dos_time.ti_sec);
- return(fdate);
-
- }
-
-
-
- char * pascal stripcr (char *a) /* Strips trailing CR's & LF's */
-
- {
-
- while (a[strlen(a)-1]=='\n' || a[strlen(a)-1]=='\r') a[strlen(a)-1]=0;
- return a;
-
- }
-
-
-
-
- char * pascal lstrip (char *a) { /* Strips leading blanks */
-
- while (*a==' ') memmove (a,(a+1),strlen(a));
- return (a);
- }
-
-
-
- char * pascal rstrip (char *a) { /* Strips trailing blanks */
-
- while (*a && a[strlen(a)-1]==' ') a[strlen(a)-1]=0;
- return a;
- }
-
-
-
- void cdecl debug_print (char *string,...) { /* Local-only messages only
- displayed if debug-mode is
- turned on by ! argument */
-
- word tempbaud;
- static char buffer[318];
-
- va_list ap;
- va_start(ap,string);
- vsprintf(buffer,string,ap);
- va_end(ap);
- if(debug_mode){
- tempbaud=baud;
- baud=0;
- printm(buffer);
- baud=tempbaud;
- }
- }
-
-
-
- int cdecl printfm (char *string,...) { /* Like printf() for local
- and remote */
-
- static char buffer[318];
-
- va_list ap;
- va_start(ap,string);
- vsprintf(buffer,string,ap);
- va_end(ap);
- return(printm(buffer));
- }
-
-
-
- char pascal printm (char *text) { /* Prints local and remote */
-
- char *p;
-
- while ((p=strstr(text,"\x1b[2J"))!=NULL) {
- memmove(&p[1],&p[4],strlen(&p[4])+1);
- *p='\xc';
- }
- while ((p=strchr(text,'\x7')) && !sysopin) memmove(p,&p[1],strlen(&p[1])+1);
- while (p=strchr(text,'\r')) *p='\n';
- if (fast) {
- if(fast==1) {
- textbackground(0);
- textcolor(10);
- }
- if(fast==2) {
- textbackground(10);
- textcolor(0);
- }
- }
- while(*text) {
- if (*text=='\xc') { /* Clear screen */
- cls();
- text++;
- continue;
- }
- if(*text=='\t') {
- text++;
- printm(" ");
- continue;
- }
- if (fast && *text!='\n') {
- putch(*text);
- }
- else if (fastANSI) {
- Again1:
- _AX=(int)*text;
- geninterrupt(0x29);
- if(baud) while (!fossil(TRANSMIT,*text)) carrchk();
- if (*text=='\n') {
- *text='\r';
- goto Again1;
- }
- }
- else {
- Again2:
- _DL=*text;
- _AH=2;
- geninterrupt(33);
- if(baud) while (!fossil(TRANSMIT,*text)) carrchk();
- if (*text=='\n') {
- *text='\r';
- goto Again2;
- }
- }
- text++;
- _AH=3;
- _BH=0;
- geninterrupt(16);
- if (_DH>23) checkpos();
- }
- getxbbstime();
- fast=0;
- }
-
-
- void pascal checkpos (void) { /* Protect status line */
-
- _AH=3;
- _BH=0;
- geninterrupt(16);
- if (_DH>23) {
- _AH=6;
- _AL=1;
- _BH=7;
- _CH=0;
- _CL=0;
- _DH=23;
- _DL=79;
- geninterrupt(16);
- _AH=2;
- _BH=0;
- _DL=0;
- _DH=23;
- geninterrupt(16);
- }
- }
-
-
-
-
- void pascal print_stat (void) { /* Print status line */
-
- int x;
- int y;
-
- x=wherex();
- y=wherey();
- gotoxy(1,25);
- textbackground(7);
- textcolor(0);
- cprintf("%-31.31s \04 %31.31s\04 ",PROGRAM_NAME,username);
- gotoxy(x,y);
- }
-
-
-
- char * pascal addtolog (text) /* WRITE LOGFILE ENTRIES */
-
- char *text;
-
- {
-
- FILE *pf;
- char p[127];
-
- pf = fopen(logfile,"a");
- if (pf == NULL) return text;
- fseek(pf,0,SEEK_END);
- if (text[0]!='*') {
- strcpy(p,fidodate());
- p[16]=0;
- strcat(p," ");
- strncat(p,text,126-strlen(p));
- p[126]=0;
- }
- else {
- strncpy(p,text,79);
- p[79]=0;
- }
- fputs(p,pf);
- fputs("\n",pf);
- fclose(pf);
- return text;
-
- }
-
-
-
- #ifdef XBBS
-
- void pascal readconfig (void) /* Read CONFIG.BBS */
-
- {
-
- FILE *fp;
- char s[15];
-
- if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
- else strcpy(s,"config.bbs");
-
- if(!(fp=fopen(s,"rb"))) {
- Fatal:
- perror("\nCONFIG ERROR");
- #ifndef DORINFO
- exit(1);
- #endif
- }
- if (fread(&conf,sizeof(conf),1,fp)!=1) goto Fatal;
- fclose(fp);
- strcpy(system_name,conf.system);
- strcpy(sysop,conf.sysop);
- commport=conf.commport;
- strcpy(logfile,conf.logfile);
- sysopin=conf.sysopin;
- fastANSI=conf.fastANSI;
- directvideo=conf.dvideo;
- }
-
-
-
- void pascal getonline (void) /* Read ONLINE.XBS */
-
- {
-
- FILE *fp;
- char s[90];
- char numnode[4]="";
-
- if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
- sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
-
- if (!((fp=fopen(s,"rb")))) {
- printf("Can't open %s!\n",s);
- goto FatalError;
- }
- else {
- fread(&user,sizeof(struct _user),1,fp);
- fread(&userno,sizeof(userno),1,fp);
- fread(&timelimit,sizeof(timelimit),1,fp);
- fread(&timeon,sizeof(timeon),1,fp);
- fread(&starter,sizeof(starter),1,fp);
- fread(&baud,sizeof(baud),1,fp);
- fread(&pages,sizeof(pages),1,fp);
- fread(&age,sizeof(age),1,fp);
- fread(&timer_off,sizeof(timer_off),1,fp);
- fread(&hold_time,sizeof(hold_time),1,fp);
- fread(variable,(sizeof(variable[0])*10),1,fp);
- fread(&mboard,sizeof(mboard),1,fp);
- fread(&fboard,sizeof(fboard),1,fp);
- if (fread(event,(sizeof(struct _events)*10),1,fp)<1) {
- printf("Came up short!\n");
- goto FatalError;
- }
- }
- if (ferror(fp)) {
- FatalError:
- perror("ONLINE READ");
- fclose(fp);
- #ifndef DORINFO
- exit(1);
- #endif
- }
- fclose(fp);
- strcpy(username,user.name);
- seclvl=user.stat[0];
- width=user.width;
- numlines=user.length;
- graphics=user.graphics;
- }
-
-
-
- void pascal prepare (void) /* Rewrite ONLINE.XBS */
-
- {
-
- FILE *fp;
- char s[90];
- char numnode[4]="";
-
- if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
- sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
- if(!(fp=fopen(s,"wb"))) perror("ONLINE OPEN");
- else {
- fwrite(&user,sizeof(struct _user),1,fp);
- fwrite(&userno,sizeof(userno),1,fp);
- fwrite(&timelimit,sizeof(timelimit),1,fp);
- fwrite(&timeon,sizeof(timeon),1,fp);
- fwrite(&starter,sizeof(starter),1,fp);
- fwrite(&baud,sizeof(baud),1,fp);
- fwrite(&pages,sizeof(pages),1,fp);
- fwrite(&age,sizeof(age),1,fp);
- fwrite(&timer_off,sizeof(timer_off),1,fp);
- fwrite(&hold_time,sizeof(hold_time),1,fp);
- fwrite(variable,sizeof(variable[0]),10,fp);
- fwrite(&mboard,sizeof(struct _mboard),1,fp);
- fwrite(&fboard,sizeof(struct _fboard),1,fp);
- fwrite(event,sizeof(struct _events),10,fp);
- if (ferror(fp)) perror("ONLINE WRITE");
- fclose(fp);
- }
- }
-
-
-
- void pascal saveconfig (void) /* Rewrite CONFIG.BBS */
-
- {
-
- FILE *fp;
- char s[14];
-
- if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
- else strcpy(s,"config.bbs");
-
- if (!(fp=fopen(s,"wb"))) perror("CONFIG OPEN");
- else {
- fwrite(&conf,sizeof(conf),1,fp);
- fclose(fp);
- }
- }
-
- #endif
-
-
-
-
- #ifdef DORINFO
-
- void pascal readinfo (void) { /* Read DORINFO?.DEF */
-
- register int x;
- FILE *fp;
- char s[81];
-
- sprintf(s,"DORINFO%hu.DEF",nodenumber);
- if(!((fp=fopen(s,"rt")))) return;
- if(!fgets(s,81,fp)) goto EndIt;
- stripcr(s);
- s[63]=0;
- strcpy(system_name,s);
- if(!fgets(s,81,fp)) goto EndIt;
- stripcr(s);
- s[35]=0;
- strcpy(sysop,s);
- if(!fgets(s,81,fp)) goto EndIt;
- stripcr(s);
- s[35]=0;
- x=strlen(sysop);
- if(x<35) strcat(sysop," ");
- if(x<36) strncat(sysop,s,36-x);
- sysop[35]=0;
- if(!fgets(s,81,fp)) goto EndIt;
- if(atoi(&s[3])) commport=(char)atoi(&s[3]);
- if(commport)commport--;
- if(!fgets(s,81,fp)) goto EndIt;
- baud=(word)atol(s);
- if(!fgets(s,81,fp)) goto EndIt;
- if(!fgets(s,81,fp)) goto EndIt;
- stripcr(s);
- s[35]=0;
- strcpy(username,s);
- if(!fgets(s,81,fp)) goto EndIt;
- stripcr(s);
- s[35]=0;
- x=strlen(username);
- if(x<35) strcat(username," ");
- if(x<36)strncat(username,s,36-x);
- if(!fgets(s,81,fp)) goto EndIt;
- if(!fgets(s,81,fp)) goto EndIt;
- if(atoi(s)) graphics=1;
- if(!fgets(s,81,fp)) goto EndIt;
- seclvl=(word)atol(s);
- if(!fgets(s,81,fp)) goto EndIt;
- timelimit=(word)atol(s);
- EndIt:
- fclose(fp);
- }
-
- #endif
-
-
- #ifdef FINDUSER
-
- word pascal finduser (char *users_name,struct _user *other) {
-
- /* Finds user named users_name in users.bbs unless user isn't there
- or user is locked out. Returns user # and alters structure other
- to contain user's info. Info is undefined if 0 is returned. */
-
- FILE *fp;
- int handle;
- register word xx;
- word tempuserno=0;
-
- if(findfirst(searchpath("users.bbs"),&f,0)) {
- printm("\nCan't find userfile.\n");
- return 0;
- }
- printfm("\nSearching for %s...",users_name);
- strupr(users_name);
- xx=0;
- if (!f.ff_fsize) {
- printm("\nNull-length userfile.\n");
- return 0;
- }
- if ((handle=_open(searchpath("USERS.BBS"),O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- printm("\nError opening userfile\n");
- return 0;
- }
- fp=fdopen(handle,"rb");
- rewind(fp);
- while (!feof(fp) && !ferror(fp)) {
- xx++;
- if (!(xx%50)) printm(".");
- if (fread(other,sizeof(struct _user),1,fp)!=1) break;
- strupr(other->name);
- strupr(other->handle);
- if (!(strcmp(other->name,users_name)) && (!other->deleted)) break;
- if (!(strcmp(other->handle,users_name)) && (!other->deleted)) break;
- }
- if (((strcmp(other->name,users_name)) && (strcmp(other->handle,users_name))) || (other->deleted)) goto notfound;
- if (!other->stat[0]) goto notfound;
- tempuserno=(word)(ftell(fp)/(long)sizeof(struct _user));
- fclose(fp);
- _close(handle);
-
- if (!tempuserno) {
- notfound:
- fclose(fp);
- _close(handle);
- printfm("\n%s not found.\n",users_name);
- return 0;
- }
- return tempuserno;
- }
-
- #endif
-