home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / XREADDIR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-03  |  15.3 KB  |  618 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*   XBBS SOURCE CODE copyright (c) 1990 by M. Kimes                        */
  4. /*   All Rights Reserved                                                    */
  5. /*                                                                          */
  6. /*    For complete details of the licensing restrictions, please refer      */
  7. /*    to the License agreement, which is published in its entirety in       */
  8. /*    the in the file LICENSE.XBS.                                          */
  9. /*                                                                          */
  10. /*    USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE      */
  11. /*    XBBS LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF            */
  12. /*    THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO       */
  13. /*    NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES         */
  14. /*    AT THE ADDRESS LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO USE   */
  15. /*    THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING     */
  16. /*    AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH      */
  17. /*    M. KIMES                                                              */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /* You can contact M. Kimes at the following address:                       */
  21. /*                                                                          */
  22. /* M. Kimes                         1:380/16.0@FidoNet                      */
  23. /* 542 Merrick                      (318)222-3455 data                      */
  24. /* Shreveport, LA  71104                                                    */
  25. /*                                                                          */
  26. /*                                                                          */
  27. /* Please feel free to contact me at any time to share your comments about  */
  28. /* my software and/or licensing policies.                                   */
  29. /*                                                                          */
  30. /*--------------------------------------------------------------------------*/
  31. /*======================================================================*/
  32. /*  XBBS Bulletin Board System.....Paged read and dir routines          */
  33. /*======================================================================*/
  34.  
  35. #include "msg.h"
  36. #include "xext.h"
  37.  
  38.  
  39.  
  40. char * pascal saydate (struct date *a) {
  41.  
  42. static char xdate[11];
  43.  
  44.  sprintf(xdate,"%02hu/%02hu/%04u",a->da_mon,a->da_day,a->da_year);
  45.  return(xdate);
  46. }
  47.  
  48.  
  49.  
  50. char * pascal saytime (struct time *a) {
  51.  
  52. static char xtime[9];
  53.  
  54.  sprintf(xtime,"%02u:%02u:%02u",a->ti_hour,a->ti_min,a->ti_sec);
  55.  return(xtime);
  56. }
  57.  
  58.  
  59.  
  60. char * pascal getdttm (void) { /* Gets ANSI time&date */
  61.  
  62. time_t lt;
  63. struct tm *ptr;
  64.  
  65.  lt=time(NULL);
  66.  ptr=localtime(<);
  67.  return(asctime(ptr));
  68. }
  69.  
  70.  
  71.  
  72. void pascal rawdir (char *directory,char type) {
  73.  
  74.  word register x=0;
  75.  char b;
  76.  char temp;
  77.  char *noe;
  78.  char noext[10];
  79.  char a[124];
  80.  char mask[81];
  81.  struct ffblk f;
  82.  struct fdate {
  83.    bit day:   5;
  84.    bit month: 4;
  85.    bit year:  7;
  86.   };
  87.  union df {
  88.    struct fdate fd;
  89.    int x;
  90.   } fdf;
  91.  ulong total=0;
  92.  ulong transtime;
  93.  
  94.   if ((type!=0) and (type!=1)) {
  95.     sprintf(a,"%s",directory);
  96.     goto Skipask;
  97.    }
  98.  
  99.   say_prompt(196);
  100.   helpnum=535;
  101.   if (type==0) strcpy(mask,genin(12,0,1,0,FLEW));
  102.   else strcpy(mask,genin(80,0,1,0,FLEPW));
  103.   helpnum=0;
  104.  
  105.   if (!*mask) {
  106.     strcpy(mask,"*.*");
  107.     printm("*.*");
  108.   }
  109.  
  110.   printm("\n");
  111.  
  112.   sprintf(a,"%s%s",directory,mask);
  113.  
  114. Skipask:
  115.  
  116.   if (findfirst(a,&f,0)!=0) {
  117.     say_prompt(271);
  118.     return;
  119.   }
  120.  
  121.   pauser=1;
  122.  
  123.   do {
  124.     x++;
  125.     if ((type==0) or (type==1)) {
  126.       if ((x%2)==0) b='\n';
  127.       else b=' ';
  128.     }
  129.     else {
  130.        if ((x%3)==0) b='\n';
  131.        else b=' ';
  132.      }
  133.  
  134.      strcpy(noext,f.ff_name);
  135.      noe=strchr(noext,'.');
  136.      if (noe!=NULL) noe[0]=0;
  137.      total=total+f.ff_fsize;
  138.      fdf.x=f.ff_fdate;
  139.      if ((fdf.fd.year+80)>99) fdf.fd.year=fdf.fd.year-99;
  140.  
  141.      if (b==' ') lines--;
  142.      if (user.graphics) {
  143.        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);
  144.        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);
  145.      }
  146.      else {
  147.        if (type==2) temp=gprintf(0,"%-9s  %02u/%02u/%u  %c",noext,fdf.fd.month,fdf.fd.day,fdf.fd.year+80,b);
  148.        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);
  149.      }
  150.  
  151.     b=toupper(inkey());
  152.     if (b=='S' || temp) break;
  153.  
  154.   } while(findnext(&f)==0);
  155.  
  156.  
  157. donereading:
  158.  
  159.   pauser=0;
  160.   noext[0]=0;
  161.   if (user.graphics & GRAPHICS) strcpy(noext,"\x1b[0;1;32m");
  162.   gprintf(0,"\n%s%d%s(%lu bytes)",noext,x,say_prompt(197),total);
  163.   x=baud;
  164.   if (x==0) x=1200;
  165.   transtime=(long)((((total)/x)*1000)/80);
  166.   gprintf(0,say_prompt(207),(word)transtime/60,(word)transtime%60,x);
  167. }
  168.  
  169.  
  170. void pascal readany (char *directory,char *dext,char type) {
  171.  
  172.  char dir[104];
  173.  struct ffblk f;
  174.  char ddext[5];
  175.  char ext[5];
  176.  char filename[13];
  177.  char fullfile[124];
  178.  
  179.  strcpy(dir,directory);
  180.  strcpy(ddext,dext);
  181.  
  182. Askagain:
  183.  
  184.  say_prompt(199);
  185.  helpnum=536;
  186.  if (*ddext) strcpy(filename,genin(9,0,1,0,FLEX));
  187.  else strcpy(filename,genin(13,0,1,0,FLE));
  188.  helpnum=0;
  189.  
  190.   if (!*filename) return;
  191.  
  192.   right(ext,filename,4);
  193.   if (*ddext && ddext!=NULL) strcat(filename,ddext);
  194.   if ((!stricmp(ext,".COM")) || (!stricmp(ext,".EXE")) || (!stricmp(ext,".BIN"))) {
  195.     say_prompt(272);
  196.     goto Askagain;
  197.    }
  198.  
  199.   sprintf(fullfile,"%s%s",dir,filename);
  200.  
  201.   if (findfirst(fullfile,&f,0)!=0) {
  202.     say_prompt(200);
  203.     goto Askagain;
  204.   }
  205.   if (!type) readfile(fullfile,0,0,1);
  206.   else readtext(fullfile);
  207.  
  208.   goto Askagain;
  209. }
  210.  
  211.  
  212. void pascal readnew (char *directory,char type) {
  213.  
  214.  char *p;
  215.  char fullfile[124];
  216.  char dir[104];
  217.  struct ffblk f;
  218.  struct fdate {
  219.    bit day:   5;
  220.    bit month: 4;
  221.    bit year:  7;
  222.  };
  223.  union df {
  224.    struct fdate fd;
  225.    int x;
  226.  } fdu;
  227.  
  228.  strcpy(dir,directory);
  229.  if (findfirst(dir,&f,0)!=0) return;
  230.  fdu.fd.day=user.lastdate.da_day;
  231.  fdu.fd.month=user.lastdate.da_mon;
  232.  fdu.fd.year=(user.lastdate.da_year-1900)-80;
  233.  if (strrchr(dir,'\\')!=NULL) {
  234.    p=strrchr(dir,'\\');
  235.    p[1]=0;
  236.  }
  237.  
  238.   do {
  239.     if (f.ff_fdate>=fdu.x) {
  240.       sprintf(fullfile,"%s%s",dir,f.ff_name);
  241.       if (!type) readfile(fullfile,0,0,1);
  242.       else readtext(fullfile);
  243.     }
  244.   } while (findnext(&f)==0);
  245. }
  246.  
  247.  
  248.  
  249. void pascal readtext (char *s) {
  250.  
  251.     long place;
  252.     struct ffblk filestat;
  253.     char dostring[181];
  254.     char eoff=0;
  255.     word page;
  256.     char a;
  257.     long *pos;
  258.     word scratch;
  259.     int  fp;
  260.     register int x;
  261.     char prev=0;
  262.     char *p;
  263.     char *tempo;
  264.     char *here;
  265.     char temp='N';
  266.     char lastpage=0;
  267.     char searchstring[41];
  268.     char holdstring[41];
  269.     char teststring[81];
  270.     char findend=0;
  271.     char printanyway=0;
  272.     word linelen;
  273.     word lines=1;
  274.     static char comstring[26]="";
  275.  
  276.     *searchstring=0;
  277.     *holdstring=0;
  278.  
  279.   pauser=2;
  280.   if (findfirst(s,&filestat,0)) {
  281. Failed:
  282.     gprintf(0,say_prompt(201),s);
  283.     return;
  284.   }
  285.   if (!filestat.ff_fsize) {
  286.         goto Failed;
  287.   }
  288.   if ((fp=oopen(s,O_RDONLY | O_BINARY | O_DENYNONE))==-1) return;
  289.  
  290.   if(!*comstring) strncpy(comstring,say_prompt(267),26);
  291.   linelen=1024;
  292. TryAgain:
  293.   pos=(long *)mmalloc((word)(sizeof(long)*linelen));
  294.   if(!pos) {
  295.     if(linelen!=256) {
  296.         linelen=256;
  297.         goto TryAgain;
  298.     }
  299.     cclose(fp);
  300.     say_prompt(12);
  301.     return;
  302.   }
  303.  
  304.   cls();
  305.   page=0;
  306.   if(conf.logtext) gprintf(LOGONLY,"Read %s",s);
  307.  
  308.   p=strchr(s,':');            /* Strip path off filename for display */
  309.   here=strrchr(s,'\\');
  310.   if(!p && !here) here=s;
  311.   else if (!here) here=&p[1];
  312.   else if (p) here= (p<here) ? &here[1] : &p[1];
  313.   else here++;
  314.  
  315.   pauser=2;
  316.   printg("\x1b[0;1;33m");
  317.   gprintf(0,say_prompt(436),here,page+1);
  318.   printg("\x1b[0;1;32m");
  319.  
  320.   if(skip_blanks(fp)) goto Abort;
  321.   pos[0]=tell(fp);
  322.   lines=1;
  323.   while (!eof(fp)) {
  324.     if ((*searchstring && !printanyway) || findend) goto Searcher;
  325. Domore:
  326.     if (!fgetsx(dostring,181,fp)) {
  327.         eoff++;
  328.         goto EEOF;
  329.     }
  330.     stripcr(dostring);
  331.     while (p=strchr(dostring,'\xc')) memmove(p,&p[1],strlen(&p[1])+1);
  332.     while (p=strchr(dostring,'\x1b')) memmove(p,&p[1],strlen(&p[1])+1);
  333.     if (!*dostring) {
  334.         if (prev) {
  335.             prev=0;
  336.             eoff=skip_blanks(fp);
  337.             if (eoff) goto EEOF;
  338.             else goto Domore;
  339.         }
  340.         else prev++;
  341.     }
  342.     else prev=0;
  343.     if (*searchstring) {
  344.         strcpy(teststring,dostring);
  345.         if (stristr(teststring,searchstring)) {
  346.             printg("\x1b[0;1;37m");
  347.             fast=2;
  348.             pauser=2;
  349.             printm(dostring);
  350.             printg("\x1b[0;1;32m");
  351.             lines++;
  352.         }
  353.         else {
  354.             fast=1;
  355.             pauser=2;
  356.             printm(dostring);
  357.             lines++;
  358.         }
  359.     }
  360.     else {
  361.         fast=1;
  362.         pauser=2;
  363.         printm(dostring);
  364.         lines++;
  365.     }
  366.     scratch=strlen(dostring);
  367.     p=dostring;
  368.     while(tempo=strchr(p,'\t')) {
  369.         p=tempo+1;
  370.         scratch+=3;
  371.     }
  372.     if (scratch<79) {
  373.         printm("\n");
  374.         scratch++;
  375.     }
  376.     if (scratch>user.width) {
  377.         lines++;
  378.     }
  379.     a=toupper(inkey());
  380.     if(a) {
  381.         for(x=0;x<27;x++) {
  382.                 if(!comstring[x])break;
  383.                 if(a==comstring[x]) {
  384.                     a=(char)x+1;
  385.                     break;
  386.                 }
  387.             }
  388.         if (a==1 || a==' ') break;
  389.         if (a==7 || a==8) if (page) goto SkipThis;
  390.         if (a==9) goto Direct;
  391.     }
  392. Searcher:
  393.     if (lastpage) goto EEOF;
  394.     if ((a==5) || (*searchstring) || (findend)) {
  395.       if (findend) {
  396.         if (++page>linelen) page=1;
  397.         pos[page]=tell(fp);
  398.       }
  399.       place=tell(fp);
  400. Domore1:
  401.       while (!eof(fp)) {
  402. Domore2:
  403.         if (!fgetsx(dostring,181,fp)) {
  404.             eoff++;
  405.             break;
  406.         }
  407.         while (p=strchr(dostring,'\xc')) memmove(p,&p[1],strlen(&p[1])+1);
  408.         while (p=strchr(dostring,'\x1b')) memmove(p,&p[1],strlen(&p[1])+1);
  409.         if (!strcmp(dostring,"\n")) {
  410.             if (prev) {
  411.                 prev=0;
  412.                 eoff=skip_blanks(fp);
  413.                 if (eoff) break;
  414.                 else goto Domore2;
  415.             }
  416.             else prev++;
  417.         }
  418.         else prev=0;
  419.         if (*searchstring) {
  420.             if (stristr(dostring,searchstring)) {
  421.                 printanyway++;
  422.                 break;
  423.             }
  424.         }
  425.         lines++;
  426.         scratch=strlen(dostring);
  427.         p=dostring;
  428.         while(tempo=strchr(p,'\t')) {
  429.             p=tempo+1;
  430.             scratch+=3;
  431.         }
  432.         if (scratch<79) {
  433.             scratch++;
  434.         }
  435.         if (scratch>user.width) lines++;
  436.         if (user.length) if ((lines>=user.length-2) || (eof(fp)) || (eoff)) break;
  437.       }
  438.       fossil(PURGEIN,0);
  439.       eoff=skip_blanks(fp);
  440.       if (eof(fp) || eoff || printanyway) {
  441.         if (*searchstring && !printanyway) {
  442.             say_prompt(28);
  443.             goto EEOF;
  444.         }
  445.         lseek(fp,place,SEEK_SET);
  446.         cls();
  447.         pauser=2;
  448.         printg("\x1b[0;1;33m");
  449.         gprintf(0,say_prompt(436),here,page+1);
  450.         printg("\x1b[0;1;32m");
  451.         findend=prev=eoff=0;
  452.         lastpage=lines=1;
  453.         goto Domore;
  454.       }
  455.       if ((*searchstring || findend) && !eoff) {
  456.         if (++page>linelen) page=1;
  457.         pos[page]=place=tell(fp);
  458.         lines=1;
  459.         goto Domore1;
  460.       }
  461.     }
  462. EEOF:
  463.     if (user.length) if ((lines>=user.length-2) || (eof(fp)) || (eoff)) {
  464.         if(eof(fp) && findend) {
  465.             findend=0;
  466.             lseek(fp,pos[page],SEEK_SET);
  467.             goto Domore;
  468.         }
  469. Direct:
  470.         prev=0;
  471.         eoff=skip_blanks(fp);
  472.         if (eof(fp) || eoff) {
  473.             printg("\x1b[0;1;31m");
  474.             say_prompt(438);
  475.         }
  476.         else {
  477.             for(x=0;x<27;x++) {
  478.                 if(!comstring[x])break;
  479.                 if(a==comstring[x]) {
  480.                     a=(char)x+1;
  481.                     break;
  482.                 }
  483.             }
  484.             if (a==5 || a==9) goto SkipThis;
  485.         }
  486.         printg("\x1b[0;1;33m");
  487.         say_prompt(437);
  488.         fossil(FLUSHOUT,0);
  489.         fossil(PURGEIN,0);
  490.         pos[page+1]=tell(fp);
  491. Getitagain:
  492.         fossil(PURGEIN,0);
  493.         helpnum=533;
  494.         a=*genin(1,0,1,1,ALPHA+128);
  495.         helpnum=0;
  496.         if(a) {
  497.             for(x=0;x<27;x++) {
  498.                 if(!comstring[x])break;
  499.                 if(a==comstring[x]) {
  500.                     a=(char)x+1;
  501.                     break;
  502.                 }
  503.             }
  504.         }
  505. SkipThis:
  506.         findend=0;
  507.         lastpage=0;
  508.         printanyway=0;
  509.         *searchstring=0;
  510.         switch (a) {
  511.             case 1:     goto Abort;
  512.             case 2:     if (!page) {
  513.                             printm(BACKSPACE);
  514.                             printm("\x7");
  515.                             goto Getitagain;
  516.                         }
  517.                         page=0;
  518.                         lseek(fp,0,SEEK_SET);
  519.                         break;
  520.             case 3:     if (eof(fp) || eoff) {
  521.                             printm(BACKSPACE);
  522.                             printm("\x7");
  523.                             goto Getitagain;
  524.                         }
  525.                         findend++;
  526.                         break;
  527.             case 4:     if (eof(fp) || eoff) {
  528.                             printm(BACKSPACE);
  529.                             printm("\x7");
  530.                             goto Getitagain;
  531.                         }
  532.                         printg("\x1b[0;1;35m");
  533.                         gprintf(0,say_prompt(38),holdstring);
  534.                         printm("\n  -> ");
  535.                         strcpy(searchstring,genin(40,0,1,0,ALLL));
  536.                         if (!*searchstring) {
  537.                             if (*holdstring) {
  538.                                 strcpy(searchstring,holdstring);
  539.                                 if (++page>linelen) page=1;
  540.                                 pos[page]=tell(fp);
  541.                             }
  542.                         }
  543.                         else strcpy(holdstring,searchstring);
  544.                         lseek(fp,pos[page],SEEK_SET);
  545.                         eoff=skip_blanks(fp);
  546.                         break;
  547.             case 0:    if (eof(fp) || eoff) goto Abort;
  548.             case 5:     if (eof(fp) || eoff) {
  549.                             printm(BACKSPACE);
  550.                             printm("\x7");
  551.                             goto Getitagain;
  552.                         }
  553.                         a=0;
  554.                         if (++page>linelen) page=1;
  555.                         pos[page]=tell(fp);
  556.                         break;
  557.             case 6:     lseek(fp,pos[page],SEEK_SET);
  558.                         eoff=skip_blanks(fp);
  559.                         break;
  560.             case 7:
  561.             case 8:     if (page) {
  562.                             lseek(fp,pos[--page],SEEK_SET);
  563.                             eoff=skip_blanks(fp);
  564.                             break;
  565.                         }
  566.                         printm(BACKSPACE);
  567.                         printm("\x7");
  568.                         goto Getitagain;
  569.             case 9:     if (eof(fp) || eoff) {
  570.                             printm("\x7");
  571.                             printm(BACKSPACE);
  572.                             goto Getitagain;
  573.                         }
  574.                         if(user.graphics) {
  575.                             fputs("\r",stdout);
  576.                             if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
  577.                             printm("\x1b[K\x1b[0;1;32m");
  578.                         }
  579.                         else {
  580.                             temp=wherex();
  581.                             for(x=0;x<(temp+1);x++) printm(BACKSPACE);
  582.                         }
  583.                         if (user.length) lines=user.length-3;
  584.                         goto Domore;
  585.             default:    printm(BACKSPACE);
  586.                         goto Getitagain;
  587.         }
  588.         eoff=0;
  589.         cls();
  590.         pauser=2;
  591.         printg("\x1b[0;1;33m");
  592.         gprintf(0,say_prompt(436),here,page+1);
  593.         printg("\x1b[0;1;32m");
  594.         lines=1;
  595.       }
  596.   }
  597. Abort:
  598.   if(pos) ffree(pos);
  599.   cclose(fp);
  600.   return;
  601. }
  602.  
  603.  
  604. char pascal skip_blanks (int fp) {  /* Skips blank lines, what else? */
  605.  
  606.   ulong pos;
  607.   char temp[81];
  608.   char eoff=0;
  609.  
  610.   do {
  611.     pos=tell(fp);
  612.     if (!fgetsx(temp,81,fp)) eoff++;
  613.     stripcr(temp);
  614.   } while ((!eoff) && (!eof(fp)) && (!*temp));
  615.   if (!eoff && !eof(fp)) lseek(fp,pos,SEEK_SET);
  616.   return eoff;
  617. }
  618.