home *** CD-ROM | disk | FTP | other *** search
/ RBBS in a Box Volume 1 #2 / RBBS_vol1_no2.iso / 050z / listwild.pas < prev    next >
Pascal/Delphi Source File  |  1985-11-17  |  6KB  |  245 lines

  1. {This program accesses files using command line wild-cards. It works
  2.  with MS-DOS (or PC-DOS) versions 1 and 2. }
  3.  
  4. {As Published in "Turbo Pascal Corner" in 
  5.                   Micro/Systems Journal
  6.                   November/December 1985 issue}
  7.  
  8. {Copyright 1985 by David W. Carroll}
  9. {All commercial rights reserved.}
  10.  
  11. {This program can be used as a form for programs which must process
  12.  a group of files specified by wild card characters. Just substitute 
  13.  your file processing procedure for the function "LISTPROC" and use 
  14.  a heading similar to:
  15.                function listproc(fname:strtype) : byte;
  16.  "fname" will contain each file name found to match the specified mask
  17.  and your function should return 0 if no error otherwise an error code.}
  18.  
  19. {This program and some 300+ other programs are available on:
  20.             The High Sierra RBBS-PC
  21.                 209-296-3534
  22. }
  23.  
  24. program listwild;
  25.  
  26. type
  27.   regpack = record
  28.               case integer of
  29.                 1: (ax,bx,cx,dx,bp,si,di,ds,es,flags: integer);
  30.                 2: (al,ah,bl,bh,cl,ch,dl,dh         : byte)
  31.             end;
  32.  
  33.   fcbarray =    array[0..36] of char;
  34.   strtype  =    string [14];
  35.   comstr   =    string[127];
  36.  
  37.  
  38. const
  39.    getdta =       $1a;
  40.    get1stdir =    $11;
  41.    getnextdir =   $12;
  42.    parsename =    $29;
  43.  
  44. var
  45.   buffer  : comstr;
  46.   comline : comstr absolute cseg:$80;
  47.   inch    : char;
  48.   filestr,
  49.   filename: strtype;
  50.   dfcb,
  51.   dta,
  52.   dta2    : fcbarray;
  53.   user_input : boolean;
  54.  
  55. function listproc(fname:strtype) : byte;
  56.  
  57. const
  58.   lines_per_page = 66;
  59.   chars_per_line = 79;
  60.   bottom_margin = 8;
  61. var
  62.   infile       :  text;
  63.   time1,
  64.   date1        :  string[8];
  65.   infname      :  string[20];
  66.   max_lines    :  integer;
  67.   goodfile     :  boolean;
  68.  
  69.  
  70. procedure open_file;
  71. const
  72.   bell = 07;
  73.  
  74. begin
  75.     infname := fname;
  76.     assign(infile,infname);
  77.     {$I-} reset(infile) {$I+};
  78.     goodfile := (IOresult = 0);
  79.     if not goodfile then
  80.     begin
  81.       write (chr(bell));
  82.       writeln ('FILE ',infname,' NOT FOUND');
  83.       delay(2000)
  84.     end;
  85. end;
  86.  
  87. procedure list;
  88. var
  89.   p,
  90.   line  : integer;
  91.   txtline,
  92.   printline  : string[255];
  93.  
  94. procedure print_heading(page:integer);
  95. const
  96.   space = ' ';
  97. begin
  98.   if page <> 1 then writeln(lst,chr(12));
  99.   write(lst,'File: ',infname,space:(60-(5+length(infname))));
  100.   writeln(lst,'Page #',page:3);
  101.   writeln(lst);
  102.   writeln(lst);
  103. end;
  104.  
  105. begin     {list}
  106.   p := 0;
  107.   while not eof(infile) do
  108.   begin
  109.     p := p + 1;
  110.     print_heading(p);
  111.     line := 4;
  112.     while (not eof(infile)) and (line < max_lines) do
  113.     begin
  114.       readln(infile,txtline);
  115.       writeln(lst,txtline);
  116.       line := line + 1;
  117.     end;
  118.   end;
  119.   writeln(lst,chr(12));    {form feed}
  120. end;     {list}
  121.  
  122. begin     {listproc}
  123.   max_lines  := lines_per_page - bottom_margin;
  124.   open_file;
  125.   if goodfile then
  126.   begin
  127.     list;
  128.     close(infile);
  129.     listproc := 0;    {no error} 
  130.     writeln;
  131.     writeln(' - listing done -');
  132.   end
  133.   else
  134.     listproc := 1;    {error code}
  135. end;    {listproc}
  136.  
  137. procedure setDTA(num:byte);      {set Disk Transfer Address}
  138. var
  139.   regs:       regpack;
  140.  
  141. begin
  142.   with regs do begin
  143.     ah := getdta;
  144.     case num of
  145.     1:  begin
  146.          ds := seg(dta);
  147.          dx := ofs(dta);
  148.         end;
  149.     2:  begin
  150.          ds := seg(dta2);
  151.          dx := ofs(dta2);
  152.         end;
  153.     end;
  154.     MSDOS(regs)
  155.   end
  156. end; {setDTA}
  157.  
  158. procedure calldir(calltype : byte; var errflag : byte);
  159. var
  160.   regs:       regpack;
  161.  
  162. begin
  163.   with regs do begin
  164.     ah := calltype;
  165.     cx := 0;
  166.     ds := seg(dfcb);
  167.     dx := ofs(dfcb);
  168.     MSDOS(regs);
  169.     errflag:= al
  170.   end
  171. end; {calldir}
  172.  
  173. procedure parse(var errflag:byte);
  174. var
  175.   regs : regpack;
  176. begin
  177.   with regs do begin
  178.     ah := parsename;
  179.     ds := seg(buffer[1]);
  180.     si := ofs(buffer[1]);
  181.     es := seg(dfcb);
  182.     di := ofs(dfcb);
  183.     al := $0F;
  184.     MSDOS(regs);
  185.     errflag := al;
  186.   end;
  187. end;  {parse}
  188.  
  189. procedure find;
  190. const
  191.   space  = ' ';
  192.   period = '.';
  193. var
  194.    i,
  195.    err:    byte;
  196.  
  197. begin
  198.   for i := 0 to 36 do dfcb[i] := chr(0);
  199.   if not user_input then
  200.     writeln('Search mask: ',buffer:15);
  201.   writeln;
  202.   parse(err);
  203.   setDTA(1);                          { set 1st DTA for get func.}
  204.   calldir(get1stdir, err);            { get first entry matching mask }
  205.   while err = 0 do
  206.   begin
  207.     filename:= '';
  208.     for i:= 1 to 11 do
  209.     begin
  210.       if dta[i] <> space then
  211.         filename := filename + dta[i];
  212.       if i = 8 then filename := filename + period;
  213.     end;
  214.     writeln(filename);
  215.     setDTA(2);                        { set 2nd DTA for file processing }
  216.     err := listproc(filename);        { process file }
  217.     if err = 0 then
  218.     begin
  219.       setDTA(1);
  220.       calldir(getnextdir, err);          { get next entry }
  221.     end;
  222.   end;
  223.   writeln;
  224. end; {find}
  225.  
  226. begin  {listwild}
  227.   buffer := comline;
  228.   user_input := false;
  229.   writeln('Wild card program lister');
  230.   writeln('This program formats and lists all specified files on the');
  231.   writeln('default drive to the system printer.');
  232.   writeln;
  233.   if length(buffer) < 1 then
  234.   begin
  235.     write('Enter search mask: ');
  236.     readln(buffer);
  237.     user_input := true;
  238.   end;
  239.   if length(buffer) > 0 then
  240.     find
  241.   else
  242.     writeln('Program Terminated');
  243. end.   {listwild}
  244.  
  245.