home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* XBBS SOURCE CODE copyright (c) 1990 by M. Kimes */
- /* All Rights Reserved */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the in the file LICENSE.XBS. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* XBBS LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES */
- /* AT THE ADDRESS LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO USE */
- /* THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING */
- /* AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH */
- /* M. KIMES */
- /* */
- /* */
- /* You can contact M. Kimes at the following address: */
- /* */
- /* M. Kimes 1:380/16.0@FidoNet */
- /* 542 Merrick (318)222-3455 data */
- /* Shreveport, LA 71104 */
- /* */
- /* */
- /* Please feel free to contact me at any time to share your comments about */
- /* my software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
- /*======================================================================*/
- /* XBBS Bulletin Board System.....Paged read and dir routines */
- /*======================================================================*/
-
- #include "msg.h"
- #include "xext.h"
-
-
-
- char * pascal saydate (struct date *a) {
-
- static char xdate[11];
-
- sprintf(xdate,"%02hu/%02hu/%04u",a->da_mon,a->da_day,a->da_year);
- return(xdate);
- }
-
-
-
- char * pascal saytime (struct time *a) {
-
- static char xtime[9];
-
- sprintf(xtime,"%02u:%02u:%02u",a->ti_hour,a->ti_min,a->ti_sec);
- return(xtime);
- }
-
-
-
- char * pascal getdttm (void) { /* Gets ANSI time&date */
-
- time_t lt;
- struct tm *ptr;
-
- lt=time(NULL);
- ptr=localtime(<);
- return(asctime(ptr));
- }
-
-
-
- void pascal rawdir (char *directory,char type) {
-
- word register x=0;
- char b;
- char temp;
- char *noe;
- char noext[10];
- char a[124];
- char mask[81];
- struct ffblk f;
- struct fdate {
- bit day: 5;
- bit month: 4;
- bit year: 7;
- };
- union df {
- struct fdate fd;
- int x;
- } fdf;
- ulong total=0;
- ulong transtime;
-
- if ((type!=0) and (type!=1)) {
- sprintf(a,"%s",directory);
- goto Skipask;
- }
-
- say_prompt(196);
- helpnum=535;
- if (type==0) strcpy(mask,genin(12,0,1,0,FLEW));
- else strcpy(mask,genin(80,0,1,0,FLEPW));
- helpnum=0;
-
- if (!*mask) {
- strcpy(mask,"*.*");
- printm("*.*");
- }
-
- printm("\n");
-
- sprintf(a,"%s%s",directory,mask);
-
- Skipask:
-
- if (findfirst(a,&f,0)!=0) {
- say_prompt(271);
- return;
- }
-
- pauser=1;
-
- do {
- x++;
- if ((type==0) or (type==1)) {
- if ((x%2)==0) b='\n';
- else b=' ';
- }
- else {
- if ((x%3)==0) b='\n';
- else b=' ';
- }
-
- strcpy(noext,f.ff_name);
- noe=strchr(noext,'.');
- if (noe!=NULL) noe[0]=0;
- total=total+f.ff_fsize;
- fdf.x=f.ff_fdate;
- if ((fdf.fd.year+80)>99) fdf.fd.year=fdf.fd.year-99;
-
- if (b==' ') lines--;
- if (user.graphics) {
- if (type==2) temp=gprintf(0,"\x1b[0;1;33m%-9s \x1b[34m%02u/%02u/%u %c",noext,fdf.fd.month,fdf.fd.day,fdf.fd.year+80,b);
- else temp=gprintf(0,"\x1b[0;1;33m%-13s \x1b[36m%6lu \x1b[34m%02u/%02u/%u %c",f.ff_name,f.ff_fsize,fdf.fd.month,fdf.fd.day,fdf.fd.year+80,b);
- }
- else {
- if (type==2) temp=gprintf(0,"%-9s %02u/%02u/%u %c",noext,fdf.fd.month,fdf.fd.day,fdf.fd.year+80,b);
- else temp=gprintf(0,"%-13s %6lu %02u/%02u/%u %c",f.ff_name,f.ff_fsize,fdf.fd.month,fdf.fd.day,fdf.fd.year+80,b);
- }
-
- b=toupper(inkey());
- if (b=='S' || temp) break;
-
- } while(findnext(&f)==0);
-
-
- donereading:
-
- pauser=0;
- noext[0]=0;
- if (user.graphics & GRAPHICS) strcpy(noext,"\x1b[0;1;32m");
- gprintf(0,"\n%s%d%s(%lu bytes)",noext,x,say_prompt(197),total);
- x=baud;
- if (x==0) x=1200;
- transtime=(long)((((total)/x)*1000)/80);
- gprintf(0,say_prompt(207),(word)transtime/60,(word)transtime%60,x);
- }
-
-
- void pascal readany (char *directory,char *dext,char type) {
-
- char dir[104];
- struct ffblk f;
- char ddext[5];
- char ext[5];
- char filename[13];
- char fullfile[124];
-
- strcpy(dir,directory);
- strcpy(ddext,dext);
-
- Askagain:
-
- say_prompt(199);
- helpnum=536;
- if (*ddext) strcpy(filename,genin(9,0,1,0,FLEX));
- else strcpy(filename,genin(13,0,1,0,FLE));
- helpnum=0;
-
- if (!*filename) return;
-
- right(ext,filename,4);
- if (*ddext && ddext!=NULL) strcat(filename,ddext);
- if ((!stricmp(ext,".COM")) || (!stricmp(ext,".EXE")) || (!stricmp(ext,".BIN"))) {
- say_prompt(272);
- goto Askagain;
- }
-
- sprintf(fullfile,"%s%s",dir,filename);
-
- if (findfirst(fullfile,&f,0)!=0) {
- say_prompt(200);
- goto Askagain;
- }
- if (!type) readfile(fullfile,0,0,1);
- else readtext(fullfile);
-
- goto Askagain;
- }
-
-
- void pascal readnew (char *directory,char type) {
-
- char *p;
- char fullfile[124];
- char dir[104];
- struct ffblk f;
- struct fdate {
- bit day: 5;
- bit month: 4;
- bit year: 7;
- };
- union df {
- struct fdate fd;
- int x;
- } fdu;
-
- strcpy(dir,directory);
- if (findfirst(dir,&f,0)!=0) return;
- fdu.fd.day=user.lastdate.da_day;
- fdu.fd.month=user.lastdate.da_mon;
- fdu.fd.year=(user.lastdate.da_year-1900)-80;
- if (strrchr(dir,'\\')!=NULL) {
- p=strrchr(dir,'\\');
- p[1]=0;
- }
-
- do {
- if (f.ff_fdate>=fdu.x) {
- sprintf(fullfile,"%s%s",dir,f.ff_name);
- if (!type) readfile(fullfile,0,0,1);
- else readtext(fullfile);
- }
- } while (findnext(&f)==0);
- }
-
-
-
- void pascal readtext (char *s) {
-
- long place;
- struct ffblk filestat;
- char dostring[181];
- char eoff=0;
- word page;
- char a;
- long *pos;
- word scratch;
- int fp;
- register int x;
- char prev=0;
- char *p;
- char *tempo;
- char *here;
- char temp='N';
- char lastpage=0;
- char searchstring[41];
- char holdstring[41];
- char teststring[81];
- char findend=0;
- char printanyway=0;
- word linelen;
- word lines=1;
- static char comstring[26]="";
-
- *searchstring=0;
- *holdstring=0;
-
- pauser=2;
- if (findfirst(s,&filestat,0)) {
- Failed:
- gprintf(0,say_prompt(201),s);
- return;
- }
- if (!filestat.ff_fsize) {
- goto Failed;
- }
- if ((fp=oopen(s,O_RDONLY | O_BINARY | O_DENYNONE))==-1) return;
-
- if(!*comstring) strncpy(comstring,say_prompt(267),26);
- linelen=1024;
- TryAgain:
- pos=(long *)mmalloc((word)(sizeof(long)*linelen));
- if(!pos) {
- if(linelen!=256) {
- linelen=256;
- goto TryAgain;
- }
- cclose(fp);
- say_prompt(12);
- return;
- }
-
- cls();
- page=0;
- if(conf.logtext) gprintf(LOGONLY,"Read %s",s);
-
- 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++;
-
- pauser=2;
- printg("\x1b[0;1;33m");
- gprintf(0,say_prompt(436),here,page+1);
- printg("\x1b[0;1;32m");
-
- if(skip_blanks(fp)) goto Abort;
- pos[0]=tell(fp);
- lines=1;
- while (!eof(fp)) {
- if ((*searchstring && !printanyway) || findend) goto Searcher;
- Domore:
- if (!fgetsx(dostring,181,fp)) {
- eoff++;
- goto EEOF;
- }
- 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;
- eoff=skip_blanks(fp);
- if (eoff) goto EEOF;
- else goto Domore;
- }
- else prev++;
- }
- else prev=0;
- if (*searchstring) {
- strcpy(teststring,dostring);
- if (stristr(teststring,searchstring)) {
- printg("\x1b[0;1;37m");
- fast=2;
- pauser=2;
- printm(dostring);
- printg("\x1b[0;1;32m");
- lines++;
- }
- else {
- fast=1;
- pauser=2;
- printm(dostring);
- lines++;
- }
- }
- else {
- fast=1;
- pauser=2;
- 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>user.width) {
- lines++;
- }
- a=toupper(inkey());
- if(a) {
- for(x=0;x<27;x++) {
- if(!comstring[x])break;
- if(a==comstring[x]) {
- a=(char)x+1;
- break;
- }
- }
- if (a==1 || a==' ') break;
- if (a==7 || a==8) if (page) goto SkipThis;
- if (a==9) goto Direct;
- }
- Searcher:
- if (lastpage) goto EEOF;
- if ((a==5) || (*searchstring) || (findend)) {
- if (findend) {
- if (++page>linelen) page=1;
- pos[page]=tell(fp);
- }
- place=tell(fp);
- Domore1:
- while (!eof(fp)) {
- Domore2:
- if (!fgetsx(dostring,181,fp)) {
- eoff++;
- break;
- }
- 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;
- eoff=skip_blanks(fp);
- if (eoff) break;
- else goto Domore2;
- }
- else prev++;
- }
- else prev=0;
- if (*searchstring) {
- if (stristr(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>user.width) lines++;
- if (user.length) if ((lines>=user.length-2) || (eof(fp)) || (eoff)) break;
- }
- fossil(PURGEIN,0);
- eoff=skip_blanks(fp);
- if (eof(fp) || eoff || printanyway) {
- if (*searchstring && !printanyway) {
- say_prompt(28);
- goto EEOF;
- }
- lseek(fp,place,SEEK_SET);
- cls();
- pauser=2;
- printg("\x1b[0;1;33m");
- gprintf(0,say_prompt(436),here,page+1);
- printg("\x1b[0;1;32m");
- findend=prev=eoff=0;
- lastpage=lines=1;
- goto Domore;
- }
- if ((*searchstring || findend) && !eoff) {
- if (++page>linelen) page=1;
- pos[page]=place=tell(fp);
- lines=1;
- goto Domore1;
- }
- }
- EEOF:
- if (user.length) if ((lines>=user.length-2) || (eof(fp)) || (eoff)) {
- if(eof(fp) && findend) {
- findend=0;
- lseek(fp,pos[page],SEEK_SET);
- goto Domore;
- }
- Direct:
- prev=0;
- eoff=skip_blanks(fp);
- if (eof(fp) || eoff) {
- printg("\x1b[0;1;31m");
- say_prompt(438);
- }
- else {
- for(x=0;x<27;x++) {
- if(!comstring[x])break;
- if(a==comstring[x]) {
- a=(char)x+1;
- break;
- }
- }
- if (a==5 || a==9) goto SkipThis;
- }
- printg("\x1b[0;1;33m");
- say_prompt(437);
- fossil(FLUSHOUT,0);
- fossil(PURGEIN,0);
- pos[page+1]=tell(fp);
- Getitagain:
- fossil(PURGEIN,0);
- helpnum=533;
- a=*genin(1,0,1,1,ALPHA+128);
- helpnum=0;
- if(a) {
- for(x=0;x<27;x++) {
- if(!comstring[x])break;
- if(a==comstring[x]) {
- a=(char)x+1;
- break;
- }
- }
- }
- SkipThis:
- findend=0;
- lastpage=0;
- printanyway=0;
- *searchstring=0;
- switch (a) {
- case 1: goto Abort;
- case 2: if (!page) {
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- }
- page=0;
- lseek(fp,0,SEEK_SET);
- break;
- case 3: if (eof(fp) || eoff) {
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- }
- findend++;
- break;
- case 4: if (eof(fp) || eoff) {
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- }
- printg("\x1b[0;1;35m");
- gprintf(0,say_prompt(38),holdstring);
- printm("\n -> ");
- strcpy(searchstring,genin(40,0,1,0,ALLL));
- if (!*searchstring) {
- if (*holdstring) {
- strcpy(searchstring,holdstring);
- if (++page>linelen) page=1;
- pos[page]=tell(fp);
- }
- }
- else strcpy(holdstring,searchstring);
- lseek(fp,pos[page],SEEK_SET);
- eoff=skip_blanks(fp);
- break;
- case 0: if (eof(fp) || eoff) goto Abort;
- case 5: if (eof(fp) || eoff) {
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- }
- a=0;
- if (++page>linelen) page=1;
- pos[page]=tell(fp);
- break;
- case 6: lseek(fp,pos[page],SEEK_SET);
- eoff=skip_blanks(fp);
- break;
- case 7:
- case 8: if (page) {
- lseek(fp,pos[--page],SEEK_SET);
- eoff=skip_blanks(fp);
- break;
- }
- printm(BACKSPACE);
- printm("\x7");
- goto Getitagain;
- case 9: if (eof(fp) || eoff) {
- printm("\x7");
- printm(BACKSPACE);
- goto Getitagain;
- }
- if(user.graphics) {
- fputs("\r",stdout);
- if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
- printm("\x1b[K\x1b[0;1;32m");
- }
- else {
- temp=wherex();
- for(x=0;x<(temp+1);x++) printm(BACKSPACE);
- }
- if (user.length) lines=user.length-3;
- goto Domore;
- default: printm(BACKSPACE);
- goto Getitagain;
- }
- eoff=0;
- cls();
- pauser=2;
- printg("\x1b[0;1;33m");
- gprintf(0,say_prompt(436),here,page+1);
- printg("\x1b[0;1;32m");
- lines=1;
- }
- }
- Abort:
- if(pos) ffree(pos);
- cclose(fp);
- return;
- }
-
-
- char pascal skip_blanks (int fp) { /* Skips blank lines, what else? */
-
- ulong pos;
- char temp[81];
- char eoff=0;
-
- do {
- pos=tell(fp);
- if (!fgetsx(temp,81,fp)) eoff++;
- stripcr(temp);
- } while ((!eoff) && (!eof(fp)) && (!*temp));
- if (!eoff && !eof(fp)) lseek(fp,pos,SEEK_SET);
- return eoff;
- }
-