home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / fbrow105.zip / FBROWSER.MEX < prev    next >
Text File  |  1996-03-05  |  23KB  |  760 lines

  1. //======================== Interface 1.05 ============================
  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. // on 02/29/96 fbrowser will now skip blank lines in files.bbs
  26. // on 03/02/96 added support for TTY users
  27. // on 03/05/96 lines with something in first column and a blank (space)
  28. //             in the 2nd column will be treated as comment lines.
  29. //
  30.  
  31. #include <\max\m\max.mh>
  32. #include <\max\m\max_menu.mh>
  33. #include <\max\m\prm.mh>
  34. #include <\max\m\xgetch.mh>
  35.  
  36. //below added by jaw from viewrar.mex
  37.  
  38. #define ARCH_SIGN              "\x52\x61\x72\x21\x1a\x07"
  39. #define ARCH_WHICH             "Display the contents of which archive? "
  40. #define ARCH_TITLE             " Name                Size   Packed   Date   Time"
  41. #define ARCH_LINE              "-------------------------------------------------"
  42.  
  43.   unsigned int:   HeadCRC;
  44.   unsigned char:  HeadType;
  45.   unsigned int:   Flags;
  46.   unsigned int:   HeadSize;
  47.   unsigned long:  PackSize;
  48.   unsigned long:  UnpSize;
  49.   unsigned char:  HostOS;
  50.   unsigned long:  FileCRC;
  51.   unsigned int:   FYear;
  52.   unsigned int:   FMonth;
  53.   unsigned int:   FDay;
  54.   unsigned int:   FHour;
  55.   unsigned int:   FMin;
  56.   unsigned int:   FSec;
  57.   unsigned char:  UnpVer;
  58.   unsigned char:  Method;
  59.   unsigned int:   NameSize;
  60.   unsigned long:  FileAttr;
  61.   unsigned long:  NBPos,nblock;
  62.   string:         Afname;
  63.  
  64. //    end of viewrar.mex's variables etc
  65.  
  66. //========================= Global variables =========================
  67. int:     page,fhandle;
  68. // Page: The page number we're currently working on
  69. // Fhandle: File handle for files.bbs
  70. long: end;         // file variable, end of file
  71. array [1..100] of long: old;     //up to 100 pages allowed
  72. array [0..1] of string: descr_colour;
  73. int: act_page;     // active page, i.e. page on screen
  74. int: linenumber;  // line number
  75. int: file_end;  //     0 means reached end of file
  76. int: fd;       // file handle
  77.  
  78. //========================= Page structure ===========================
  79. struct _page
  80. // Lastfile: This integer defines the last file on this page, in most cases
  81. //           this should equal to 16, except for the last page
  82. // Filename: Contains the filename, BUT!  if filename="", <desc> contains
  83. //           a description that is continued from the last file.
  84. //           And, if filename=" ", <desc> is a comment.
  85. // Size: Size of the file
  86. // Date: Date of file as a string
  87. // Desc: Description or comment
  88. // Tagged: TRUE if file is tagged and FALSE if not
  89. {
  90.     array [1..28] of string: filename;
  91.     array [1..28] of long: size;
  92.     array [1..28] of string: date;
  93.     array [1..28] of string: desc;
  94.     array [1..28] of int: tagged;
  95. } ;
  96. struct _page: p;
  97.  
  98. // Functions
  99.  
  100. // main function
  101. void do_it();
  102. //
  103. void view_cont(string: filespec); // added by jaw 12/11/95
  104. //                                   from viewrar.mex
  105. void settagged();
  106. // Inserts tagged files in Maximus que.
  107.  
  108. void printpage();
  109. // Redraws screen
  110.  
  111. int getpage();
  112. // Reads Page of files
  113.  
  114. int validfilename(string:s);
  115. // Returns:  TRUE if file
  116.  
  117. string filesbbspath();
  118. // Returns:  Path to files.bbs file
  119. // Description:  Also checks to see if files.bbs is valid (exists) and
  120. //               if not, returns ""
  121.  
  122.  
  123. void clearscreen();
  124. // Clear display screen
  125.  
  126. void clearpage();
  127. // Clear page
  128.  
  129.  
  130. int processcommands();
  131. // Processes keystrokes
  132. // Returns 0 if exit, 2 if new screen    etc
  133.  
  134. int readline(int: rpage);
  135. // Reads a line from fhandle and processes it if ok.
  136. // Returns 0 if Ok, 1 if EOF.
  137.  
  138. int processline();
  139. // Processes one line of text, checks filename etc
  140.  
  141. //======================== Implementation ===========================
  142.  
  143. int processline(int: plinenumber,string: line)
  144. // Processes one line of text, checks filename etc
  145. {
  146.     int: len,pos, k, fnum;
  147.     string: fname,desc,temp;
  148.     struct _stamp: date;
  149.  
  150.     if (strlen(line)<3 ) return plinenumber;
  151.     k:=stridx(line,1,' ');
  152.     if (k=2) return plinenumber;
  153.     if (k =0)
  154.     {
  155.         fname:=line;     // Checks for desc.
  156.         temp:=line + " No description given to File Browser!";
  157.         line:=temp;
  158.     }
  159.     else fname:=substr(line,1,k-1);
  160.     if (strlen(line)>2)
  161.     {
  162.         if (validfilename(fname)=TRUE)
  163.         {
  164.             // This is a file!
  165.             p.filename[plinenumber]:=fname;
  166.             temp:=farea.downpath+fname;
  167.             if (fileexists(temp)=TRUE)
  168.             {
  169.                 p.size[plinenumber]:=filesize(temp);
  170.                 filedate(temp,date);
  171.                 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');
  172.             }
  173.             else
  174.             {
  175.                 p.size[plinenumber]:=0; // Missing
  176.             }
  177.             fnum:=plinenumber;    // line# where file name is.
  178.             if ((pos:=stridx(line,1,' '))>0)
  179.             {
  180.                 p.desc[plinenumber]:=substr(line,pos+1,strlen(line)-pos+1);
  181.                 p.desc[plinenumber]:=strtrim(p.desc[plinenumber],"    ");
  182.                 if (strlen(p.desc[plinenumber])<46)
  183.                     plinenumber:=plinenumber+1;
  184.                 else   // Split line
  185.                 {
  186.                     desc:=p.desc[plinenumber];
  187.                     do
  188.                     {
  189.                     pos:=stridx(desc,1,158);
  190.                     if (pos=0)
  191.                       {
  192.                         desc:=strtrim(desc,"    ");
  193.                         pos:=1;
  194.                         if (desc[45]=' ' and desc[44]<>' ') pos:=44;
  195.                         else
  196.                         {
  197.                             pos:=45;
  198.                             do
  199.                             {
  200.                                 pos:=pos-1;
  201.                             }  while (pos>1 and desc[pos]<>' ');
  202.                             if (pos=1) pos:=44;
  203.                         }
  204.                         p.desc[plinenumber]:=substr(desc,1,pos);
  205.                         desc:=substr(desc,pos+1,strlen(desc)-pos);
  206.                         desc:=strtrim(desc,"    ");
  207.                         plinenumber:=plinenumber+1;
  208.                       }
  209.                       else
  210.                       {
  211.                         p.desc[plinenumber]:=substr(desc,1,pos-1);
  212.                         desc:=substr(desc,pos+1,strlen(desc)-pos+1);
  213.                         plinenumber:=plinenumber+1;
  214.                       }
  215.                     } while (strlen(desc)>45 and plinenumber<18);
  216.                     if (strlen(desc)>0 and plinenumber<16)
  217.                     {
  218.                         p.desc[plinenumber]:=desc;
  219.                         plinenumber:=plinenumber+1;
  220.                     }
  221.                 }
  222.             }
  223.         }
  224.         else // This is a ?
  225.         {
  226.             p.filename[plinenumber]:=fname;
  227.             p.desc[plinenumber]:="File no longer in this directory!";
  228.             plinenumber:=plinenumber+1;
  229.         }
  230.         if (plinenumber>17)  p.filename[fnum]:="";
  231.     }
  232.     return plinenumber;
  233. }
  234.  
  235. int getpage(int: rpage)     // a blank line within files.bbs
  236. {                           // will cause display to stop there
  237.     int: result,i;
  238.     string: line, line2,line3;
  239.     long: first, tmp1,tmp2;
  240.  
  241.     if (rpage=2 and file_end=0)    // already on last page
  242.     {
  243.         return 0;
  244.     }
  245.     if (act_page=1 and rpage=0)    // already at the first file
  246.     {
  247.         return 0;
  248.     }
  249.     settagged();
  250.     linenumber:=1;
  251.     clearscreen();
  252.     clearpage();
  253.     fhandle:=open(filesbbspath(), IOPEN_READ);
  254.     if (rpage = 2 )
  255.     {
  256.         act_page:=act_page+1;
  257.         seek(fhandle,end,SEEK_SET);
  258.         old[act_page]:=tell(fhandle);
  259.     }
  260.     else if (rpage=1 or rpage=3)
  261.     {
  262.         seek(fhandle,0,SEEK_SET);
  263.         act_page:=1;
  264.         old[1]:=tell(fhandle);
  265.     }
  266.     else if (rpage=0)
  267.     {
  268.         if (act_page>1)    act_page:=act_page-1;
  269.         seek(fhandle,old[act_page],SEEK_SET);
  270.     }
  271.     else if (rpage=4)
  272.     {
  273.         seek(fhandle,old[act_page],SEEK_SET);
  274.     }
  275.     file_end:=1;
  276.     i:=0;
  277.     do       // Until i >= 16
  278.     {
  279.         first:=tell(fhandle);
  280.         result:=readln(fhandle, line);
  281.         while (result<>-1 and strlen(line)=0)
  282.         {
  283.             result:=readln(fhandle, line);
  284.         }
  285.         tmp1:=tell(fhandle);
  286.         tmp2:=readln(fhandle,line2);
  287.         while (line2[1]=' ' and strlen(line2)>0)
  288.         {
  289.             line3:=strtrim(line2,"             ");
  290.             line:=line+"₧"+line3;
  291.             tmp1:=tell(fhandle);
  292.             tmp2:=readln(fhandle,line2);
  293.         }
  294.           {
  295.             seek(fhandle,tmp1,SEEK_SET);
  296.           }
  297.         if (result>0) // EOF?
  298.         {
  299.             i:=processline(linenumber,line);       //i is NOW the next free line
  300.             if (i<17)
  301.             {
  302.                 end:=tell(fhandle);
  303.                 linenumber:=i;
  304.             }
  305.             else if (i=17)
  306.             {
  307.                 result:=0;
  308.                 end:=tell(fhandle);
  309.                 linenumber:=17;
  310.                 result:=readln(fhandle, line);
  311.                 if (result<1)
  312.                 {
  313.                 file_end:=0;
  314.                 close(fhandle);
  315.                 return 1;
  316.                 }
  317.                 else  seek(fhandle, end, SEEK_SET);
  318.             }
  319.             else      // needed to keep last display to not overlap
  320.             {
  321.             result:=0;
  322.             linenumber:=linenumber-1;
  323.             }
  324.         }
  325.         else        // done with this screen
  326.         {
  327.             file_end:=0;
  328.             if (linenumber>16) linenumber:=16;
  329.             i:=17;
  330.         }
  331.     } while(i<17 and result>0);
  332.     close(fhandle);
  333.     return 1;
  334. }
  335.  
  336. int processcommands()
  337. // Processes keystrokes
  338. {
  339.     int: exit,select,choice,num,posn,flags;
  340.     char: tempint;
  341.     string: filename;
  342.  
  343.     exit:=FALSE;
  344.     tempint:=1;
  345.     choice:=1;
  346.  
  347.     if (p.filename[choice]<>"" and p.filename[choice]<>" ") num:=choice;
  348.     // Find first file in list.
  349.     do
  350.     {
  351.         // Print filename in Yellow with blue background
  352.         print (AVATAR_GOTO, (char)(num+2),(char)1, COL_YELLOWONBLUE, p.filename[num]);
  353.         if (p.tagged[num]=TRUE) print(COL_WHITE, " *");
  354.         else print (COL_WHITE, "  ");
  355.  
  356.         // Get a key
  357.         choice:=xgetch();
  358.  
  359.         if (choice=X_UP or choice='8')
  360.         // Up
  361.         {
  362.             print (AVATAR_GOTO, (char)(num+2),(char)1, COL_LGREEN,p.filename[num]);
  363.             select:=num;
  364.             choice:=0;
  365.             do // Find the first file
  366.             {
  367.                 select:=select-1;
  368.                 if (select=0) return 0;
  369.                 if (p.filename[select]<>"" and p.filename[select]<>" ")
  370.                 choice:=select;
  371.             }
  372.             while (choice=0);
  373.             num:=choice;
  374.         }
  375.         else if (choice=X_DOWN or choice='2')
  376.         // Down
  377.         {
  378.             print (AVATAR_GOTO, (char)(num+2),(char)1, COL_LGREEN,p.filename[num]);
  379.             select:=num;
  380.             choice:=0;
  381.             do // Find the first file
  382.             {
  383.                 select:=select+1;
  384.                 if (select=17) return 2;
  385.                 if (p.filename[select]<>"" and p.filename[select]<>" ")
  386.                 choice:=select;
  387.             }
  388.             while (choice=0);
  389.             num:=choice;
  390.         }
  391.         else if (choice=27 or choice='q' or choice='Q' or choice='n' or choice='N') exit:=TRUE;
  392.         // Escape
  393.         else if (choice=32) // Spacebar
  394.         if (p.tagged[num]=TRUE) p.tagged[num]:=FALSE;
  395.         else p.tagged[num]:=TRUE;
  396.  
  397.  
  398.         else if (choice='+' or choice='3' or choice=13) // PgDn
  399.         {
  400.             return 2; // Draw next page
  401.         }
  402.         else if (choice='-' or choice='9') // PgUp
  403.         {
  404.             return 0; // Draw previous page
  405.         }
  406.         else if (choice=X_HOME or choice='7') // Home
  407.         {
  408.             return 3; // Draw new page
  409.         }
  410.         else if (choice='U' or choice='u') // Upload
  411.         {
  412.             print(AVATAR_CLS);
  413.             menu_cmd(MNU_FILE_UPLOAD,"");
  414.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  415.             return 4;
  416.         }
  417.         else if (choice='S' or choice='s') // List tagged files
  418.         {
  419.             print(AVATAR_CLS);
  420.             settagged();
  421.             if (tag_queue_size()<>0)
  422.             {
  423.          //       TagList();
  424.                   menu_cmd(MNU_FILE_TAG,"");
  425.             }
  426.             else
  427.             {
  428.                 display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  429.                 print (AVATAR_GOTO, (char)(4),(char)2,COL_WHITE,"Your Tag list is empty!");
  430.                 getch();
  431.             }
  432.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  433.             return 4;
  434.         }
  435.         else if (choice='V' or choice='v') //
  436.         {
  437.             print(AVATAR_CLS);
  438.             filename:=p.filename[num];
  439.             view_cont(filename);
  440.             print( COL_LRED, "Tap a key to continue");
  441.             getch();
  442.             close(fd);
  443.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  444.             return 4;
  445.         }
  446.         else if (choice='P' or choice='p') // Chng protocol
  447.         {
  448.             print(AVATAR_CLS);
  449.             menu_cmd(MNU_CHG_PROTOCOL,"");
  450.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  451.             return 4;
  452.         }
  453.         else if (choice='D' or choice='d')
  454.         {
  455.             print(AVATAR_CLS);
  456.             settagged();
  457.             if (tag_queue_size()<>0)
  458.             {
  459.                 menu_cmd(MNU_FILE_DOWNLOAD,"");
  460.             }
  461.             else
  462.             {
  463.                 tag_queue_file(farea.downpath+p.filename[num],0);
  464.                 menu_cmd(MNU_FILE_DOWNLOAD,"");
  465.             }
  466.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempint);
  467.             return 4;
  468.         }
  469.     }
  470.     while (exit=FALSE);
  471.     return -1;
  472. }
  473.  
  474. void clearscreen()
  475. // Clear display screen
  476. {
  477.     int: count;
  478.     
  479.     print (AVATAR_GOTO, (char)2, (char)1);
  480.     for (count:=0;count<16;count:=count+1) print(AVATAR_DOWN AVATAR_CLEOL);
  481.     
  482.     print (AVATAR_GOTO, (char)3, (char)1); // Restore cursor
  483. }
  484.  
  485.  
  486. string filesbbspath()
  487. // Returns:  Path and filename of files.bbs compatible file
  488. // Description:  Also checks to see if files.bbs is valid (exists) and
  489. //               if not, returns ""
  490. // *** Modified function *** (Neil Walker 2 Oct 1995)
  491.  
  492. {
  493.     string: temp;
  494.     
  495.     if (farea.filesbbs="") temp:=farea.downpath+"files.bbs";
  496.     else temp:=farea.filesbbs;
  497.     
  498.     if (fileexists(temp)=FALSE) temp:="";
  499.  
  500.     return temp;
  501. }
  502.  
  503. int validfilename(string:s)
  504. // Returns:  TRUE if file
  505. {
  506. //    if (stridx(s,1,'.')>0) return TRUE; else return FALSE;
  507.  return       fileexists( farea.downpath+ s);
  508. }
  509.  
  510. void printpage()
  511. // Redraws screen
  512. {
  513.     int: pos,i;
  514.     string: colour;
  515.  
  516.     clearscreen();
  517.     i:=1;
  518.     if (linenumber>16) linenumber:=16;
  519.     print (COL_LBLUE,AVATAR_GOTO, (char)1, (char)(38-strlen(farea.descript)/2), "╣ ", COL_LRED, farea.descript, COL_LBLUE, " ╠", AVATAR_GOTO, (char)3, (char)1);
  520.     print (COL_LBLUE,AVATAR_GOTO, (char)19, (char)46,COL_LGREEN,strpad(ltostr(timeleft()),4,' ')," ");
  521.     print (AVATAR_GOTO, (char)2, (char)61, COL_YELLOW, strpad(itostr(act_page),3,' '),"\n");
  522.     for (pos:=1;pos<=linenumber;pos:=pos+1)
  523.     {
  524.         if (strlen(p.filename[pos])>0)
  525.         {
  526.         i:=i+1;
  527.         colour:=descr_colour[i%2];
  528.         }
  529.         if (p.filename[pos]=" ") print (COL_GRAY, p.desc[pos]);
  530.         else if (p.filename[pos]="") print (colour, AVATAR_GOTO, (char)(pos+2),(char)35,p.desc[pos]);
  531.         else
  532.         {
  533.             print (COL_LGREEN, p.filename[pos],strpad("",13-strlen(p.filename[pos]),' '));
  534.             if (p.tagged[pos]=TRUE) print (COL_WHITE,"*");
  535.             else print (" ");
  536.             if (p.size[pos]>0)
  537.             print (COL_YELLOW, strpadleft(ltostr(p.size[pos]),8,' '),"  ",
  538.             COL_LGREEN, p.date[pos],"  ",colour, p.desc[pos]);
  539.             else print(COL_YELLOW,"     <MISSING>      ",colour,p.desc[pos]);
  540.  
  541.         }
  542.         print("\n");
  543.     }
  544. }
  545.  
  546. void settagged()
  547. // Inserts tagged files in Maximus que.
  548. {
  549.     int: pos,i,flgs, ok;
  550.     string: tagname,testname;
  551.     
  552.     for (pos:=1;pos<17;pos:=pos+1)
  553.     if (p.tagged[pos]=TRUE)
  554.     {
  555.         ok:=0;
  556.         for (i:=0;i<tag_queue_size();i:=i+1)
  557.         {
  558.             tag_get_name(i, flgs,tagname);
  559.             testname:=strupper(farea.downpath+p.filename[pos]);
  560.             if (tagname=testname) ok:=1;
  561.         }
  562.         if (ok=0) tag_queue_file(farea.downpath+p.filename[pos],0);
  563.     }
  564. }
  565. void do_it()
  566. {
  567.     int: k;
  568.  
  569.     k:=1;
  570.     do {
  571.         k:=getpage(k);
  572.         if (k=1) printpage();
  573.         do
  574.         {
  575.             k:=processcommands();
  576.         }
  577.         while (k=1);
  578.     }
  579.     while (k>-1);
  580.     settagged();   // for last screen
  581. }
  582.  
  583. void clearpage()     // initializes page variables
  584. {
  585.     int: i;
  586.     for (i:=1;i<29;i:=i+1)
  587.     {
  588.         p.filename[i]:="";
  589.         p.date[i]:="";
  590.         p.desc[i]:="";
  591.         p.size[i]:=0;
  592.         p.tagged[i]:=FALSE;
  593.     }
  594.  
  595. }
  596.  
  597. unsigned long hextoul(string: strinp, int: ofst)
  598. {
  599.   unsigned long: wlong;
  600.  
  601.   wlong := (unsigned char)strinp[ofst+3];
  602.   wlong := (wlong shl 8)+(unsigned char)strinp[ofst+2];
  603.   wlong := (wlong shl 8)+(unsigned char)strinp[ofst+1];
  604.   return (wlong shl 8)+(unsigned char)strinp[ofst];
  605. }
  606. int hextoi(string: strinp, int: ofst)
  607. {
  608.   int: wint;
  609.  
  610.   wint := (int)strinp[ofst+1];
  611.   return (wint shl 8) + (int)strinp[ofst];
  612. }
  613.  
  614. unsigned int hextoui(string: strinp, int: ofst)
  615. {
  616.   unsigned int: wint;
  617.  
  618.   wint := (unsigned char)strinp[ofst+1];
  619.   return (wint shl 8) + (unsigned char)strinp[ofst];
  620. }
  621.  
  622. unsigned long get_fblk(int: fh)
  623. {
  624.   unsigned long: rc;
  625.   string: gtmp;
  626.     rc := read(fh,gtmp,31);
  627.     HeadType := gtmp[2];
  628.     Flags    := hextoui(gtmp,3);
  629.     HeadSize := hextoui(gtmp,5);
  630.     PackSize := hextoul(gtmp,7);
  631.     UnpSize  := hextoul(gtmp,11);
  632.     HostOS   := gtmp[15];
  633.     FileCRC  := hextoul(gtmp,16);
  634.     FHour    := (hextoui(gtmp,20) shr 11);
  635.     if (FHour < 0) FHour := FHour - 65504;
  636.     FMin     := ((hextoui(gtmp,20) & 0x07e0) shr 5);
  637.     FSec     := (hextoui(gtmp,20) & 0x002f);
  638.     FYear    := (hextoui(gtmp,22) shr 9)+80;
  639.     FMonth   := ((hextoui(gtmp,22) & 0x01e0) shr 5);
  640.     FDay     := (hextoui(gtmp,22) & 0x001f);
  641.     UnpVer   := gtmp[24];
  642.     Method   := gtmp[25];
  643.     NameSize := hextoui(gtmp,26);
  644.     FileAttr := hextoul(gtmp,28);
  645.     NBPos := tell(fh) - rc + HeadSize;
  646.     if (Flags & 0x8000) NBPos := NBPos + PackSize;
  647.     if (rc = 0 or HeadType <> 0x74)
  648.     {
  649.       seek(fh,NBPos,SEEK_SET);
  650.     }
  651.   if (rc > 0 and HeadType = 0x74)
  652.   {
  653.     read(fh,Afname,NameSize);
  654.     seek(fh,NBPos,SEEK_SET);
  655.     rc := rc + NameSize;
  656.     if (HeadType = 0) return(0);
  657.   }
  658.   return(rc);
  659. }
  660.  
  661. unsigned int get_arch(int: fh)
  662. {
  663.   int:    rc;
  664.   string: ftmp;
  665.  
  666.   seek(fh,8,SEEK_SET);
  667.   rc := read(fh,ftmp,13);
  668.   seek(fh,hextoui(ftmp,5)+8,SEEK_SET);
  669.   return hextoui(ftmp,5);
  670. }
  671. void view_cont(string: filespec)
  672. {
  673.   int: Afs, I,  rc;
  674.   long: fsize;
  675.   string:  tmp;
  676.  
  677.   fd := open(farea.downpath+filespec,IOPEN_READ|IOPEN_BINARY);
  678.   if (fd = -1)
  679.   {
  680.     print(COL_WHITE,"Can't find Archive ",farea.downpath+filespec,"\n");
  681.     return;
  682.   }
  683.   rc := read(fd,tmp,6);
  684.   if (tmp <> ARCH_SIGN)
  685.   {
  686.     close(fd);
  687.     input := input + filespec ;
  688.     menu_cmd(MNU_FILE_CONTENTS,"");
  689.     return;
  690.   }
  691.   fsize := filesize(farea.downpath+filespec);
  692.   print("\n");
  693.   print("Contents of Archive ",filespec,"\n\n");
  694.   print(ARCH_TITLE,"\n");
  695.   print(ARCH_LINE,"\n");
  696.   nblock := get_arch(fd);               // position to read first file block
  697.   if (nblock = 0)
  698.   {
  699.     print ("exit");
  700.     return;
  701.   }
  702.   while(get_fblk(fd) > 0)
  703.   {
  704.     if (nblock >= fsize) return;
  705.     if (HeadType = 0x74)
  706.     {
  707.     Afs := 0;
  708.     for ( I := 1 ; I <> strlen(Afname) ; I := I + 1 )
  709.       {
  710.         if (substr(Afname,I,1) = "\\" or substr(Afname,I,1) = "/") Afs := I;
  711.       }
  712.       Afname := substr(Afname,Afs+1,strlen(Afname)-Afs+1);
  713.       print(strpad(Afname,13,' '),strpadleft(ultostr(UnpSize),12,' '));
  714.       print(strpadleft(ultostr(PackSize),9,' ')," ");
  715.       print(FYear,"/",strpadleft(ultostr(FMonth),2,'0'),"/");
  716.       print(strpadleft(ultostr(FDay),2,'0')," ");
  717.       print(strpadleft(ultostr(FHour),2,'0'),":");
  718.       print(strpadleft(ultostr(FMin),2,'0'));
  719.       print("\n");
  720.     }
  721.   }
  722.   close(fd);
  723.   print("\n");
  724. }
  725.  
  726.  
  727. int main()
  728. {
  729.     int: count;
  730.     char: tempchar;
  731.  
  732.     if (filesbbspath()="") // Too bad, files.bbs isn't there!
  733.         {
  734.                 print ("Files.bbs doesn't exist!");
  735.         return 1;
  736.     }
  737.     if (usr.video< (char) 1)
  738.     {
  739.         menu_cmd(MNU_FILE_TITLES,"");
  740.         return 0;
  741.     }
  742.     if (filesize(filesbbspath()) < 10)  // files.bbs is les than 10 bytes
  743.         {                                   // so it is probably empty
  744.             display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempchar);
  745.             print (AVATAR_GOTO, (char)(4),(char)2,COL_WHITE,"This filearea is empty!");
  746.             getch();
  747.         return 1;
  748.         }
  749.     descr_colour[0]:=COL_WHITE;
  750.     descr_colour[1]:=COL_LCYAN;
  751.     // Opens Files.BBS for reading, filehandle fhandle.
  752.     print (COL_WHITE,"Reading Files.BBS...");
  753.     display_file(prm_string(PRM_MISCPATH)+"fbrowser.bbs",tempchar);
  754.     do_it();
  755.  
  756.     print(AVATAR_CLS); // CLS on exit
  757.  
  758.     return 0;
  759. }
  760.