home *** CD-ROM | disk | FTP | other *** search
/ Hot Shareware 32 / hot34.iso / ficheros / VUBBS / FBROW134.ZIP / FBROWSER.MEX < prev    next >
Text File  |  1998-03-25  |  30KB  |  984 lines

  1. //======================== Interface 1.34  ============================
  2. // Program: MEX Filebrowser
  3. //
  4. // Created in 1995 by Jonas Öberg, 2:204/466
  5. // Modified 2 Oct 1995 by Neil Walker, 2:2500/509
  6. //
  7. // Thanks to:
  8. //    The author of XGetCh() used by this program
  9. //    Werner Schlagnitweit for the mex program f-titles, great program
  10. //        although it's a little slow with the 3d stuff.
  11. //
  12. // -=Public Domain=-
  13. // Drastically altered by Jim Woodward 1:268/412, thus renamed
  14. //
  15. //  on 12/10/95 I, Jim Woodward, incorporated Herman Freeman's
  16. //              viewrar.mex program into fbrowser.mex
  17. //
  18. // on 12/19/95
  19. // Added: S for taglist  inspired by:  Ole Aggerholm, 2:238/11.0
  20. //
  21. // on 01/23/96  Redefined pageup/down keys to +/- keys, thus
  22. // enabling me to use 'q' for quitting the program.
  23. //
  24. // Check for empty filearea error corrected by: Ole Aggerholm
  25. //
  26. // on 03/02/96 added support for TTY users
  27. // ******** below lines refer to lines in your files.bbs file *****
  28. //
  29. // on 03/11/96:107 lines with a '-' or ' ' in column 1 will
  30. //      be a comment line that are printed on remote screen.
  31. //      with noted exception below!
  32. //
  33. // 0n 09/15/1996
  34. //      if column 1 is '-' and column2 is '!'
  35. //      the next line will be line 1 of a new page.
  36. //
  37. // fbrowser 1.13  now supports file areas of type: CD DateList
  38. //
  39. //  bug, when size of files.bbs=0, corrected by Richard Bermudez 6/20/96
  40. //
  41. //  Major change in the program, DOS compilation is at its limit,
  42. //  i.e. No more can be added to fbrowser without taking something out.
  43. //  Naturally fbrowser could be extended for OS/2 users, but I'm
  44. //  sticking with keeping it the same for both. I hope the next dos-mex
  45. //  compiler will allow more.
  46. //
  47. // *********                                                  ******
  48.  
  49. #include <\max\m\max.mh>
  50. #include <\max\m\max_menu.mh>
  51. #include <\max\m\prm.mh>
  52. #include <\max\m\xgetch.mh>
  53.  
  54. //below added by jaw from viewrar.mex
  55.  
  56. #define ARCH_SIGN              "\x52\x61\x72\x21\x1a\x07"
  57. #define ARCH_WHICH             "Display the contents of which archive? "
  58. #define ARCH_TITLE             " Name                Size   Packed   Date   Time"
  59. #define ARCH_LINE              "-------------------------------------------------"
  60.  
  61.   unsigned int:   HeadCRC;
  62.   unsigned char:  HeadType;
  63.   unsigned int:   Flags;
  64.   unsigned int:   HeadSize;
  65.   unsigned long:  PackSize;
  66.   unsigned long:  UnpSize;
  67.   unsigned char:  HostOS;
  68.   unsigned long:  FileCRC;
  69.   unsigned int:   FYear;
  70.   unsigned int:   FMonth;
  71.   unsigned int:   FDay;
  72.   unsigned int:   FHour;
  73.   unsigned int:   FMin;
  74.   unsigned int:   FSec;
  75.   unsigned char:  UnpVer;
  76.   unsigned char:  Method;
  77.   unsigned int:   NameSize;
  78.   unsigned long:  FileAttr;
  79.   unsigned long:  NBPos,nblock;
  80.   string:         Afname;
  81.  
  82. //    end of viewrar.mex's variables etc
  83.  
  84. //========================= Global variables =========================
  85. long: end;         // file variable, end of file
  86. array [1..500] of long: old;     //up to 500 pages allowed
  87. array [0..1] of string: descr_colour;
  88. int: act_page;     // active page, i.e. page on screen
  89. int: pages;       // Total # of FBrow pages for this file area
  90. int: linenumber;  // line number
  91. int: file_end;  //     0 means reached end of file
  92. int: fhandle;       // file handle
  93. int: stage;  // value 1024=0x0400 means Type CD or CD Datelist
  94. int: dequeue;
  95. int: start;
  96. int: offset;
  97. int: flength0;
  98. int: flength1;
  99. int: flength2;
  100. int: flength3;
  101. int: flength4;
  102. int: flength5;
  103.  
  104. //========================= Page structure ===========================
  105. struct _page
  106. // Filename: Contains the filename, BUT!  if filename="", <desc> contains
  107. //           a description that is continued from the last file.
  108. //           And, if filename="z", <desc> is a comment.
  109. // Size: Size of the file
  110. // Date: Date of file as a string
  111. // Desc: Description or comment
  112. // Tagged: TRUE if file is tagged and FALSE if not
  113. // tbfree: free download when tbfree=12
  114. {
  115.     array [1..53] of string: filename;
  116.     array [1..53] of long: size;
  117.     array [1..53] of string: date;
  118.     array [1..53] of string: desc;
  119.     array [1..53] of int: tagged;
  120.     array [1..53] of int: tbfree;
  121. } ;
  122. struct _page: p;
  123. int:    fnum;
  124. string: headstr;
  125. string: dline;
  126. string: helpline;
  127. // Functions
  128.  
  129. // main function
  130. void do_it();
  131. //
  132. void header();
  133. //
  134. void view_cont(string: filespec); // added by jaw 12/11/95
  135. //                                   from viewrar.mex
  136. void settagged();
  137. // Inserts tagged files in Maximus que.
  138.  
  139. void printpage();
  140. // Redraws screen
  141.  
  142. int getpage();
  143. // Reads Page of files
  144.  
  145. string filesbbspath();
  146. // Returns:  Path to files.bbs file
  147. // Description:  Also checks to see if files.bbs is valid (exists) and
  148. //               if not, returns ""
  149.  
  150. //
  151. void help();
  152. //
  153.  
  154. void clearscreen();
  155. // Clear display screen
  156.  
  157. void clearpage();
  158. // Clears page  variables
  159.  
  160.  
  161. int processcommands();
  162. // Processes keystrokes
  163. // Returns 0 if exit, 2 if new screen    etc
  164.  
  165. int processline();
  166. // Processes one line of text, checks filename etc
  167.  
  168.  
  169. string jimtrim(string: trimstr);
  170. //======================== Implementation ===========================
  171.  
  172. int processline(int: plinenumber,string: line)
  173. // Processes one line of text, checks filename etc
  174. {
  175.     int: pos,j, k,pos2;
  176.     string: fname,desc,temp,file_size,file_date,temp2;
  177.     struct _stamp: date;
  178.     char: c3, c2, c1;
  179.  
  180.  
  181.     if ((line[1]='-' or line[1]=' ') and ( farea.attribs<>7 or farea.attribs<>71 ))
  182.     {
  183.         p.filename[plinenumber]:="z";
  184.         if (line[2]='!')
  185.         {
  186.             p.desc[plinenumber]:="  ";
  187.             return flength1;
  188.         }
  189.         p.desc[plinenumber]:=substr(line,1,79);
  190.         plinenumber:=plinenumber+1;
  191. //        if (plinenumber=flength1)
  192. //        {
  193. //            plinenumber:=18;
  194. //        }
  195.         return plinenumber;
  196.     }
  197.     j:=strlen(line);
  198.     line[j+2]:=0;
  199.     line[j+1]:=' ';
  200.     k:=stridx(line,1,' ');
  201. if (k>13) k:=13;
  202.     if (k<>0)
  203.     {
  204.         fname:=substr(line,1,k-1);
  205.     }
  206.     else
  207.     {
  208.         fname:="Contact Sysop";
  209.     }
  210.     {
  211.         {
  212.             // This is a file!
  213.             p.filename[plinenumber]:=fname;
  214.             fnum:=plinenumber;
  215.             temp:=farea.downpath+fname;
  216.             if (farea.attribs=71)        // CD Datelist
  217.                 {
  218.                     file_size:=substr(line,1,33);
  219.                     file_size:=jimtrim(line);
  220.                     pos:=stridx(file_size,1,' ');
  221. if (pos>11) pos:=11;
  222.                     line:=substr(line,pos+1,strlen(line)-pos+1);
  223.                     line:=jimtrim(line);
  224.                     file_size:=substr(file_size,pos+2,30);
  225.                     file_size:=jimtrim(file_size);
  226.                     pos2:=stridx(file_size,2,' ');
  227.                     pos:=stridx(file_size,pos2+1,' ');
  228.                     file_date:=substr(file_size,pos2+2,18);
  229.                     file_date:=jimtrim(file_date);
  230.                     line:=substr(line,pos+1,strlen(line)-pos+1);
  231.                     pos:=stridx(file_size,2,',');
  232.                     if (pos>0)
  233.                     {
  234.                         file_size:=substr(file_size,1,pos-1) + substr(file_size,pos+1,3);
  235.                     }
  236.                      p.size[plinenumber]:=strtol(file_size);
  237.                     while (file_date[1]=' ')
  238.                     {
  239.                         file_date:=substr(file_date,2,strlen(file_date)-1);
  240.                     }
  241.                     pos:=stridx(file_date,2,' ');
  242.                     line:=substr(line,pos+1,strlen(line)+1-pos);
  243.                     file_date:=substr(file_date,1,8);
  244.                      p.date[plinenumber]:=file_date;
  245.                 }
  246.             else
  247.             {
  248.                 if (farea.attribs<>71 and fileexists(temp)=TRUE)
  249.                 {
  250.                     p.size[plinenumber]:=filesize(temp);
  251.                     filedate(temp,date);
  252. // ddmmyy             p.date[plinenumber]:=strpadleft(itostr(date.date.day),2,'0') + "/" + strpadleft(itostr(date.date.month),2,'0') + "/" +strpadleft(itostr(date.date.year+ 80),2,'0');
  253.                     p.date[plinenumber]:=strpadleft(itostr(date.date.month),2,'0') + "/" + strpadleft(itostr(date.date.day),2,'0') + "/" +strpadleft(itostr(date.date.year+ 80),2,'0');
  254.                 }
  255.  
  256.                 else
  257.                 {
  258.                     p.size[plinenumber]:=0; // Missing
  259.                     p.date[plinenumber]:=" Offline";
  260.                 }
  261.             }
  262.             if ((pos:=stridx(line,1,' '))>0)
  263.             {
  264.                 while (line[pos+1]=' ') pos:=pos+1;
  265.                 if (line[pos+1]='/')
  266.                 {
  267.                      c1:='a';
  268.                      c2:=line[pos+2];
  269.                      c3:=line[pos+3];
  270.                      p.tbfree[plinenumber]:=0;
  271.                      if (c2='t' or c3='t' or c2='T')
  272.                      {
  273.                         p.tbfree[plinenumber]:=p.tbfree[plinenumber]+4;
  274.                         c1:='x';
  275.                      }
  276.                      if (c2='b' or c3='b' or c3='B')
  277.                      {
  278.                         p.tbfree[plinenumber]:=p.tbfree[plinenumber]+8;
  279.                         c1:='x';
  280.                      }
  281.                      if (c1='x')
  282.                      {
  283.                         if (c3<>' ')
  284.                            pos:=pos+4;
  285.                         else
  286.                           if (c2<>' ') pos:=pos+3;
  287.                      }
  288.                 }
  289.                 p.desc[plinenumber]:=jimtrim(substr(line,pos+1,strlen(line)-pos+1));
  290.                 if ((strlen(p.desc[plinenumber]))<46)
  291.                 {
  292.                     plinenumber:=plinenumber+1;
  293.                 }
  294.                 else   // Split line
  295.                 {
  296.                     desc:=p.desc[plinenumber];
  297.                     do
  298.                     {
  299.                     pos:=stridx(desc,1,158);
  300.                     if (pos=0)
  301.                       {
  302.                         desc:=jimtrim(desc);
  303.                         pos:=1;
  304.                         if (desc[45]=' ' and desc[44]<>' ') pos:=44;
  305.                         else
  306.                         {
  307.                             pos:=45;
  308.                             do
  309.                             {
  310.                                 pos:=pos-1;
  311.                             }  while (pos>1 and desc[pos]<>' ');
  312.                             if (pos=1) pos:=44;
  313.                         }
  314.                         p.desc[plinenumber]:=substr(desc,1,pos);
  315.                         desc:=substr(desc,pos+1,strlen(desc)-pos);
  316.                         desc:=jimtrim(desc);
  317.                         plinenumber:=plinenumber+1;
  318.                       }
  319.                       else
  320.                       {
  321.                         while (pos>0 )
  322.                         {
  323.                             p.desc[plinenumber]:=substr(desc,1,pos-1);
  324.                             desc:=substr(desc,pos+1,strlen(desc)-pos+1);
  325.                             plinenumber:=plinenumber+1;
  326.                             pos:=stridx(desc,1,158);
  327.                         }
  328.                         if (plinenumber>flength0)
  329.                         {
  330.                             p.desc[plinenumber]:=desc;
  331.                             plinenumber:=flength2;
  332.                         }
  333.                       }
  334.                     } while (strlen(desc)>45 and plinenumber<flength1);
  335.                     if (strlen(desc)>0 and plinenumber<flength1)
  336.                     {
  337.                         p.desc[plinenumber]:=desc;
  338.                         plinenumber:=plinenumber+1;
  339.                     }
  340.                 }
  341.             }
  342.         }
  343.         if (plinenumber>flength1)
  344.         {
  345.                 p.filename[fnum]:="";
  346.                 plinenumber:=flength2;
  347.         }
  348.     }
  349.     return plinenumber;
  350. }
  351.  
  352. int getpage(int: rpage)
  353. {
  354.     int: result,i,j;
  355.     string: line, line2,line3;
  356.     long: first, tmp1,tmp2;
  357.     string: temp;
  358.  
  359.     fnum:=1;
  360.     stage:=0;
  361.     if ((rpage=2 and file_end=0 ) or (rpage=0 and act_page=1))    // already on last page
  362.     {
  363.         return 0;
  364.     }
  365.     clearpage();
  366.     linenumber:=1;
  367.     fhandle:=open(filesbbspath(), IOPEN_READ);
  368.     if (rpage = 2 )
  369.     {
  370.         act_page:=act_page+1;
  371.         seek(fhandle,end,SEEK_SET);
  372.         old[act_page]:=tell(fhandle);
  373.     }
  374.     else if (rpage=1 or rpage=3)
  375.     {
  376.         seek(fhandle,0,SEEK_SET);
  377.         act_page:=1;
  378.         old[1]:=tell(fhandle);
  379.     }
  380.     else if (rpage=7)
  381.     {
  382.         seek(fhandle,old[act_page],SEEK_SET);
  383.     }
  384.     else if (rpage=0)
  385.     {
  386.         act_page:=act_page-1;
  387.         seek(fhandle,old[act_page],SEEK_SET);
  388.     }
  389.     else if (rpage=4)
  390.     {
  391.         seek(fhandle,old[act_page],SEEK_SET);
  392.     }
  393.     file_end:=1;
  394.     i:=0;
  395.     do       // Until i >= (flength1-9)
  396.     {
  397.         first:=tell(fhandle);
  398.         result:=readln(fhandle, line);
  399.         if (result>511)
  400.         {
  401.             readln(fhandle,temp);
  402.         }
  403.         j:=4;
  404.         if (result=0)
  405.         {
  406.             line:="  ";
  407.             result:=2;
  408.         }
  409.     if(farea.attribs=7 or farea.attribs=71)       // CD
  410.     {
  411.         stage:=0x0400;
  412.         tmp1:=tell(fhandle);
  413.         tmp2:=readln(fhandle,line2);
  414.         while (line2[1]=' ' and strlen(line2)>0 )
  415.         {
  416.             line2:=jimtrim(line2);
  417.             line3:=strtrim(line2,"| ");
  418.             line3:=substr(line3,1,45);
  419.             line:=line+"\x9e"+line3;
  420.             tmp1:=tell(fhandle);
  421.             tmp2:=readln(fhandle,line2);
  422.         }
  423.           {
  424.             seek(fhandle,tmp1,SEEK_SET);
  425.           }
  426.           if (strlen(line)>511)
  427.           {
  428.             line:=substr(line,1,511);
  429.           }
  430.     }
  431.         if (result>0) // EOF?
  432.         {
  433.             i:=processline(linenumber,line);       //i is NOW the next free line
  434.             if (i<flength1)
  435.             {
  436.                 end:=tell(fhandle);
  437.                 linenumber:=i;
  438.             }
  439.             else if (i=flength1)
  440.             {
  441.                 result:=0;
  442.                 end:=tell(fhandle);
  443.                 linenumber:=flength1;
  444.                 result:=readln(fhandle, line);
  445.                 if (result<0)
  446.                 {
  447.                 file_end:=0;
  448.                 close(fhandle);
  449.                 return 1;
  450.                 }
  451.                 else  seek(fhandle, end, SEEK_SET);
  452.             }
  453.             else      // needed to keep last display to not overlap
  454.             {
  455.             result:=0;
  456.             linenumber:=linenumber-1;
  457.             }
  458.         }
  459.         else        // done with this screen
  460.         {
  461.             file_end:=0;
  462.             if (linenumber>flength1) linenumber:=flength1;
  463.             i:=flength1;
  464.         }
  465.     } while(i<flength1);
  466.     close(fhandle);
  467.     return 1;
  468. }
  469.  
  470. int processcommands()
  471. // Processes keystrokes
  472. {
  473.     int: exit,select,choice,num,posn,flags,i,j,ntag;
  474.     char: tempint;
  475.     string: filename,dpath,pagen,tagchar;
  476.  
  477.     exit:=FALSE;
  478.     tempint:=1;
  479.     choice:=1;
  480.  
  481.     if (p.filename[choice]<>"" and p.filename[choice]<>" ") num:=choice;
  482.     // Find first file in list.
  483.     while (p.filename[num]="z") num:=num+1;
  484.     if (num=flength1)
  485.     {
  486.         num:=flength1;
  487.         p.filename[num]:="";
  488.     }
  489.     do
  490.     {
  491.         tagchar:=" ";
  492.         filename:=p.filename[num];
  493.         // Print filename in Yellow with blue background
  494.         print (AVATAR_GOTO, (char)(num+2),(char)1, COL_YELLOWONBLUE, filename);
  495.         if (p.tagged[num]=TRUE)
  496.                 tagchar:="*";
  497.         print (AVATAR_GOTO, (char)(num+2),(char)13,COL_WHITE,tagchar);
  498.         // Get a key
  499. do {
  500.         choice:=xgetch();
  501. }while (choice=73 or choice=81);
  502.         if (choice=X_UP or choice='8')
  503.         // Up
  504.         {
  505.             print (AVATAR_GOTO, (char)(num+2),(char)1, COL_LGREEN,filename);
  506.             select:=num;
  507.             choice:=0;
  508.             do // Find the first file
  509.             {
  510.                 select:=select-1;
  511.                 if (select=0) return 0;
  512.                 if (p.filename[select]<>"" and p.filename[select]<>" " and p.filename[select]<>"z")
  513.                     choice:=select;
  514.             }
  515.             while (choice=0);
  516.             num:=choice;
  517.         }
  518.         else if (choice='c' or choice='C') // Chng protocol
  519.         {
  520.             clearscreen();
  521.             menu_cmd(MNU_CHG_PROTOCOL,"");
  522.             return 4;
  523.         }
  524.         else if (choice=X_DOWN or choice='2')
  525.         // Down
  526.         {
  527.             print (AVATAR_GOTO, (char)(num+2),(char)1, COL_LGREEN,filename);
  528.             select:=num;
  529.             choice:=0;
  530.             do // Find the first file
  531.             {
  532.                 select:=select+1;
  533.                 if (select=flength1) return 2;
  534.                 if (p.filename[select]<>"" and p.filename[select]<>" " and p.filename[select]<>"z")
  535.                         choice:=select;
  536.             }
  537.             while (choice=0);
  538.             num:=choice;
  539.         }
  540.         else if (choice=27 or choice='q' or choice='Q' ) exit:=TRUE;
  541.         // Escape
  542.         else if (choice=32) // Spacebar
  543.         {
  544.             if (p.tagged[num]=TRUE)
  545.             {
  546.                 p.tagged[num]:=FALSE;
  547.                 dequeue:=1;
  548.             }
  549.             else
  550.             {
  551.                 p.tagged[num]:=TRUE;
  552.             }
  553.             settagged();
  554.         }
  555.         else if (choice='+' or choice='3' or choice=13 or choice=77 or choice='6') // PgDn
  556.         {
  557.             return 2; // Draw next page
  558.         }
  559.         else if (choice='-' or choice='9' or choice=75 or choice='4') // PgUp
  560.         {
  561.             return 0; // Draw previous page
  562.         }
  563.         else if (choice=X_HOME or choice='7' or choice='*') // Home
  564.         {
  565.             act_page:=1;
  566.             return 7;
  567.         }
  568.         else if (choice=X_END or choice='1' or choice='!') // Home
  569.         {
  570.             act_page:=pages;
  571.             return 4; // Draw new page
  572.         }
  573.         else if (choice='h' or choice='H') //
  574.         {
  575.                 clearscreen();
  576.                 help();
  577.                 getch();
  578.                 return 4; //
  579.         }
  580.  
  581.         else if (choice='p' or choice='P') // GoTo page #
  582.         {
  583.             print( AVATAR_CLEOL, COL_LRED);
  584.             input_str(pagen,INPUT_WORD,0,4,"Please enter the page number. ");
  585.             select:=strtoi(pagen);
  586.             if (0<select and select <=pages)
  587.             {
  588.                 act_page:=select;
  589.                 return 7;
  590.             }
  591.             else return 4;
  592.         }
  593.         else if (choice='s' or choice='S') // List tagged files
  594.         {
  595.             clearscreen();
  596.             if ((ntag:=tag_queue_size())>0)
  597.             {
  598.                   menu_cmd(MNU_FILE_TAG,"");
  599.                   if (ntag>tag_queue_size())
  600.                       dequeue:=2;
  601.             }
  602.             else
  603.             {
  604.                 print (AVATAR_GOTO, (char)(4),(char)2,COL_WHITE,"Your Tag list is empty!");
  605.                 getch();
  606.             }
  607.             return 4;
  608.         }
  609.         else if (choice='v' or choice='V') //
  610.         {
  611.             clearscreen();
  612.             view_cont(filename);
  613.             getch();
  614.             return 4;
  615.         }
  616.         else if (choice='d' or choice='D')
  617.         {
  618.             clearscreen();
  619.             if ((j:=tag_queue_size())>0)
  620.             {
  621.                 if (usr.priv>89 and (id.port%256)=0)
  622.                 {
  623.                     input_str(dpath,INPUT_WORD,0,128,"Please Enter the directory to which the file will be copied.\n");
  624.                     i:=strlen(dpath);
  625.                     if (substr(dpath,i,1)="\\") dpath:=substr(dpath,1,i-1);
  626.                     filecopy(farea.downpath+filename, dpath +"\\" + filename);
  627.                     for (i:=1;i<=j;i:=i+1)
  628.                     {
  629.                         tag_dequeue_file(0);
  630.                     }
  631.                 }
  632.                 else
  633.                     {
  634.                         menu_cmd(MNU_FILE_DOWNLOAD,"");
  635.                     }
  636.             }
  637.             return 4;
  638.         }
  639.     }
  640.     while (exit=FALSE);
  641.     return -1;
  642. }
  643.  
  644. void clearscreen()
  645. // Clear display screen
  646. {
  647.     print (AVATAR_CLS);
  648.     print (AVATAR_GOTO, (char)3, (char)1); // Restore cursor
  649. }
  650.  
  651.  
  652. string filesbbspath()
  653. // Returns:  Path and filename of files.bbs compatible file
  654. // Description:  Also checks to see if files.bbs is valid (exists) and
  655. //               if not, returns ""
  656. // *** Modified function *** (Neil Walker 2 Oct 1995)
  657.  
  658. {
  659.     string: temp;
  660.  
  661.     if (farea.filesbbs="") temp:=farea.downpath+"files.bbs";
  662.     else temp:=farea.filesbbs;
  663.  
  664.     if (fileexists(temp)=FALSE or filesize(temp)=0) temp:="";
  665.     return temp;
  666. }
  667.  
  668. void printpage()
  669. // Redraws screen
  670. {
  671.     int: pos,i,j,ntag,flags;
  672.     string: colour,filename,dpath;
  673.     char: tempchar;
  674.  
  675.     clearscreen();
  676.     header();
  677.     i:=1;
  678.     ntag:=tag_queue_size();
  679.     dpath:=strupper(farea.downpath);
  680.     if (linenumber>flength1) linenumber:=flength1;
  681.     for (pos:=1;pos<=linenumber;pos:=pos+1)
  682.     {
  683. //        if (strlen(p.filename[pos])>0)
  684.         {
  685.         colour:=descr_colour[pos%2];      // alternates desc colours
  686.         }
  687.         if (p.filename[pos]="z")
  688.         {
  689.             print (COL_GRAY, p.desc[pos]);
  690.         }
  691.         else if (p.filename[pos]="") print (colour, AVATAR_GOTO, (char)(pos+2),(char)35,p.desc[pos]);
  692.         else
  693.         {
  694.            if (ntag>0)
  695.            {
  696.  
  697.                 for (j:=0;j<ntag;j:=j+1)
  698.                 {
  699.                     if (tag_get_name(j,flags,filename))
  700.                     {
  701.                         if (filename=dpath+p.filename[pos])
  702.                         {
  703.                             p.tagged[pos]:=TRUE;
  704.                         }
  705.                     }
  706.                 }
  707.             }
  708.             print (COL_LGREEN, p.filename[pos]);
  709.  
  710.         tempchar:=' ';
  711.         if (p.tagged[pos]=TRUE)  tempchar:='*';
  712.         print(AVATAR_GOTO, (char)(pos+2),(char)13,COL_WHITE, tempchar);
  713.             print (COL_YELLOW, strpadleft(ltostr(p.size[pos]),9,' '),"  ",
  714.             COL_LGREEN, p.date[pos],"  ",colour, p.desc[pos],);
  715.         }
  716.         print("\n");
  717.     }
  718.     print(AVATAR_GOTO, (char)(flength5-1), (char)1,COL_YELLOW, helpline, COL_LBLUE, timeleft());
  719.     print(AVATAR_GOTO, (char)(flength5-1), (char)22,COL_LRED,"H");
  720. }
  721.  
  722. void settagged()
  723. // Inserts tagged files in Maximus que.
  724. {
  725.     int: pos,i,flgs, ok,tag;
  726.     string: tagname,testname;
  727.  
  728.     ok:=tag_queue_size();
  729.     for (pos:=1;pos<flength1;pos:=pos+1)
  730.     {
  731.         if (dequeue=2)
  732.         {
  733.             dequeue:=0;
  734.             return;
  735.         }
  736.         tag:=0;
  737.         testname:="*";
  738.         if (strlen(p.filename[pos])>0)
  739.             testname:=strupper(farea.downpath+p.filename[pos]);
  740.         if (testname<>"*") for (i:=0;i<ok;i:=i+1)
  741.         {
  742.             tag_get_name(i, flgs,tagname);
  743.             if (tagname=testname )
  744.             {
  745.                 tag:=1;
  746.                 if (p.tagged[pos]=FALSE and dequeue=1) tag_dequeue_file(i);
  747.             }
  748.         }
  749.         if (tag=0 and p.tagged[pos]=TRUE) tag_queue_file(farea.downpath+p.filename[pos],p.tbfree[pos]+stage);
  750.     }
  751.     dequeue:=0;
  752. }
  753. void do_it()
  754. {
  755.     int: i,k;
  756.  
  757.     k:=1;
  758.     clearpage();
  759.     do {
  760. //        if (act_page=1 and pages=0 )
  761.         if (start=0)
  762.         {
  763.             act_page:=0;
  764.             print("Loading Data, please wait.");
  765.             while(getpage(2)>0);
  766.             pages:=act_page+offset;
  767.             start:=1;
  768.             getpage(1);
  769.             act_page:=1;
  770. //            start:=0;
  771.         }
  772.         else {
  773.             k:=getpage(k);
  774.         }
  775.  
  776.         printpage();
  777.         do
  778.         {
  779.             k:=processcommands();
  780.         }
  781.         while (k=1);
  782.     }
  783.     while (k>-1);
  784. }
  785.  
  786. void clearpage()     // initializes page variables
  787. {
  788.     int: i;
  789.     for (i:=1;i<flength3;i:=i+1)
  790.     {
  791.         p.filename[i]:="";
  792.         p.date[i]:="";
  793.         p.desc[i]:="";
  794.         p.size[i]:=0;
  795.         p.tagged[i]:=FALSE;
  796.         p.tbfree[i]:=0;
  797.     }
  798.  
  799. }
  800.  
  801. unsigned long hextoul(string: strinp, int: ofst)
  802. {
  803.   unsigned long: wlong;
  804.  
  805.   wlong := (unsigned char)strinp[ofst+3];
  806.   wlong := (wlong shl 8)+(unsigned char)strinp[ofst+2];
  807.   wlong := (wlong shl 8)+(unsigned char)strinp[ofst+1];
  808.   return (wlong shl 8)+(unsigned char)strinp[ofst];
  809. }
  810. int hextoi(string: strinp, int: ofst)
  811. {
  812.   int: wint;
  813.  
  814.   wint := (int)strinp[ofst+1];
  815.   return (wint shl 8) + (int)strinp[ofst];
  816. }
  817.  
  818. unsigned int hextoui(string: strinp, int: ofst)
  819. {
  820.   unsigned int: wint;
  821.  
  822.   wint := (unsigned char)strinp[ofst+1];
  823.   return (wint shl 8) + (unsigned char)strinp[ofst];
  824. }
  825.  
  826. unsigned long get_fblk(int: fh)
  827. {
  828.   unsigned long: rc;
  829.   string: gtmp;
  830.     rc := read(fh,gtmp,31);
  831.     HeadType := gtmp[2];
  832.     Flags    := hextoui(gtmp,3);
  833.     HeadSize := hextoui(gtmp,5);
  834.     PackSize := hextoul(gtmp,7);
  835.     UnpSize  := hextoul(gtmp,11);
  836.     HostOS   := gtmp[15];
  837.     FileCRC  := hextoul(gtmp,16);
  838.     FHour    := (hextoui(gtmp,20) shr 11);
  839.     if (FHour < 0) FHour := FHour - 65504;
  840.     FMin     := ((hextoui(gtmp,20) & 0x07e0) shr 5);
  841.     FSec     := (hextoui(gtmp,20) & 0x002f);
  842.     FYear    := (hextoui(gtmp,22) shr 9)+80;
  843.     FMonth   := ((hextoui(gtmp,22) & 0x01e0) shr 5);
  844.     FDay     := (hextoui(gtmp,22) & 0x001f);
  845.     UnpVer   := gtmp[24];
  846.     Method   := gtmp[25];
  847.     NameSize := hextoui(gtmp,26);
  848.     FileAttr := hextoul(gtmp,28);
  849.     NBPos := tell(fh) - rc + HeadSize;
  850.     if (Flags & 0x8000) NBPos := NBPos + PackSize;
  851.     if (rc = 0 or HeadType <> 0x74)
  852.     {
  853.       seek(fh,NBPos,SEEK_SET);
  854.     }
  855.   if (rc > 0 and HeadType = 0x74)
  856.   {
  857.     read(fh,Afname,NameSize);
  858.     seek(fh,NBPos,SEEK_SET);
  859.     rc := rc + NameSize;
  860.     if (HeadType = 0) return(0);
  861.   }
  862.   return(rc);
  863. }
  864.  
  865. unsigned int get_arch(int: fh)
  866. {
  867.   int:    rc;
  868.   string: ftmp;
  869.  
  870.   seek(fh,8,SEEK_SET);
  871.   rc := read(fh,ftmp,13);
  872.   seek(fh,hextoui(ftmp,5)+8,SEEK_SET);
  873.   return hextoui(ftmp,5);
  874. }
  875. void view_cont(string: filespec)
  876. {
  877.   int: Afs, I,  rc;
  878.   long: fsize;
  879.   string:  tmp;
  880.  
  881.   fhandle := open(farea.downpath+filespec,IOPEN_READ|IOPEN_BINARY);
  882.   if (fhandle = -1)
  883.   {
  884.     print(COL_WHITE,"Can't find Archive ",farea.downpath+filespec,"\n");
  885.     return;
  886.   }
  887.   rc := read(fhandle,tmp,6);
  888.   if (tmp <> ARCH_SIGN)
  889.   {
  890.     close(fhandle);
  891.     input := input + filespec ;
  892.     menu_cmd(MNU_FILE_CONTENTS,"");
  893.     return;
  894.   }
  895.   fsize := filesize(farea.downpath+filespec);
  896.   print("\nContents of Archive ",filespec,"\n\n",ARCH_TITLE,"\n",ARCH_LINE,"\n");
  897.   nblock := get_arch(fhandle);               // position to read first file block
  898.   if (nblock = 0)
  899.   {
  900.     print ("exit");
  901.     return;
  902.   }
  903.   while(get_fblk(fhandle) > 0)
  904.   {
  905.     if (nblock >= fsize) return;
  906.     if (HeadType = 0x74)
  907.     {
  908.     Afs := 0;
  909.     for ( I := 1 ; I <> strlen(Afname) ; I := I + 1 )
  910.       {
  911.         if (substr(Afname,I,1) = "\\" or substr(Afname,I,1) = "/") Afs := I;
  912.       }
  913.       Afname := substr(Afname,Afs+1,strlen(Afname)-Afs+1);
  914.       print(strpad(Afname,13,' '),strpadleft(ultostr(UnpSize),12,' '));
  915.       print(strpadleft(ultostr(PackSize),9,' ')," ",FYear,"/");
  916.       print(strpadleft(ultostr(FMonth),2,'0'),"/");
  917.       print(strpadleft(ultostr(FDay),2,'0')," ");
  918.       print(strpadleft(ultostr(FHour),2,'0'),":");
  919.       print(strpadleft(ultostr(FMin),2,'0'));
  920.       print("\n");
  921.     }
  922.   }
  923.   close(fhandle);
  924.   print("\n");
  925. }
  926.  
  927.  
  928. int main()
  929. {
  930. char: nonstop;
  931.  
  932. flength1:=term_length()-3;
  933. flength2:=flength1+1;
  934. flength3:=flength1+2;
  935. flength0:=flength1-1;
  936. flength4:=flength1+3;
  937. flength5:=flength1+4;
  938. reset_more(nonstop);
  939. headstr := " Filename        Size    Date    Description          Page ";
  940. dline :=" ═════════════════════════════════════════════════════════════════════════════ ";
  941. helpline :="For help, press the 'H' key               Minutes Remaining: ";
  942.     if (filesbbspath()="") // Too bad, files.bbs isn't there!
  943.         {
  944.                 print ("Files.bbs doesn't exist for this area!\nPlease inform sysop.");
  945.                 getch();
  946.         return 1;
  947.     }
  948.     file_end:=1;
  949.     start:=0;
  950.     pages:=0;
  951.     if (usr.video< (char) 1)
  952.     {
  953.         menu_cmd(MNU_FILE_TITLES,"");
  954.         return 0;
  955.     }
  956.     descr_colour[0]:=COL_WHITE;
  957.     descr_colour[1]:=COL_LCYAN;
  958.     do_it();
  959.     print(AVATAR_CLS);
  960.     return 0;
  961. }
  962. string jimtrim(string: trimstr)
  963. {
  964.     return strtrim(trimstr,"  ");
  965. }
  966. void header()
  967. {
  968.     print (COL_LBLUE,AVATAR_GOTO, (char)1, (char)1, COL_LBLUE, dline);
  969.     print (COL_LBLUE,AVATAR_GOTO, (char)1, (char)(38-strlen(farea.descript)/2), "╣ ", COL_LRED, farea.descript, COL_LBLUE, " ╠");
  970.     print ( COL_YELLOW, AVATAR_GOTO, (char)2, (char)2, headstr, COL_YELLOW, strpad(itostr(act_page),4,' '),"of ",pages,"\n");
  971.  
  972. }
  973. void help()
  974. {
  975.         print("\x16\x01\x0d Keyboard key                            Action\n\n  \x16\x01\x0b  q                              Quit file browser\n \x16\x01\x0e   h                              Get this screen\n");
  976.         print(" \x16\x01\x0c   s                              See list if tagged files\n \x16\x01\x0a   p                              Select page to be displayed\n");
  977.         print("\x16\x01\x0b  space bar        \x16\x02                Tag\x16\x01\x0b file for downloading\n \x16\x01\x0e   d                              Download tagged files\n");
  978.         print("\x16\x01\x0c    c                              Change protocol\n  \x16\x01\x0a  v                              View contents of compressed file\n");
  979.         print("\x16\x01\x0b    -> or +                        Next page of listings\n \x16\x01\x0e   <- or -                        Previous page of listings\n");
  980.         print(" \x16\x01\x0f down arrow                       Highlight next file\n  up arrow                         Highlight previous file\n");
  981.         print(" \x16\x01\x0c \n    If the arrow keys don't work, then use the number pad,\n    with NumLock on, as follows:\n\x16\x01\x0e    Keys 2 & 8 previous and next file\n    Keys 3 & 9 for previous and next page of files");
  982.         print(" \x16\x01\x0b \n    If number pad fails, then use the numbers below the F keys");
  983. }
  984.