home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TOOL_INC.ZIP / WILDCARD.INC < prev   
Encoding:
Text File  |  1988-01-29  |  1.7 KB  |  80 lines

  1. (*
  2.  * Wildcard match function
  3.  *
  4.  * S.H.Smith, rev. 04-Oct-87
  5.  *
  6.  *)
  7.  
  8. function wildcard_match(keyword,line:  anystring): boolean;
  9. var
  10.    keypos,linpos:  integer;
  11.  
  12. begin
  13.    if keyword = '*.*' then
  14.    begin
  15.       wildcard_match := true;
  16.       exit;
  17.    end;
  18.  
  19. if setdebug then
  20. writeln(dbfd,'match key=',keyword,' line=',line);
  21.    keypos := 1;
  22.    linpos := 1;
  23.  
  24.    (* do a "wildcard" filename scan *)
  25.    while true do
  26.    begin
  27.  
  28.       (* end of keyword?  we might have a match if so *)
  29.       if keypos > length(keyword) then
  30.       begin
  31.          wildcard_match := (linpos >= length(line)) or (line[linpos] = ' ');
  32. if setdebug then
  33. writeln(dbfd,'match=',(linpos >= length(line)) or (line[linpos] = ' '));
  34.          exit;
  35.       end
  36.       else
  37.  
  38.       (* end of line?  we missed a match if so *)
  39.       if linpos > length(line) then
  40.       begin
  41.          wildcard_match := false;
  42. if setdebug then
  43. writeln(dbfd,'no1');
  44.          exit;
  45.       end
  46.       else
  47.  
  48.       (* does line match keyword? (? matches anything); step forward if so *)
  49.       if (keyword[keypos] = upcase(line[linpos])) or 
  50.          (keyword[keypos] = '?') then
  51.       begin
  52.          inc(keypos);
  53.          inc(linpos);
  54.       end
  55.       else
  56.  
  57.       (* is keyword a *?  skip to . or end if so *)
  58.       if keyword[keypos] = '*' then
  59.       begin
  60.          while (line[linpos]<>' ') and (line[linpos]<>'.') and
  61.                (linpos < length(line)) do
  62.             inc(linpos);
  63.  
  64.          inc(keypos);
  65.       end
  66.       else
  67.  
  68.       (* else no match is possible; terminate scan *)
  69.       begin
  70.          wildcard_match := false;
  71. if setdebug then
  72. writeln(dbfd,'no1');
  73.          exit;
  74.       end;
  75.    end;
  76.  
  77. end;
  78.  
  79.  
  80.