Browse Source

rtl/amiga: added minimalistic #?.<ext> and *.<ext> pattern matching to legacy MatchFirst

Karoly Balogh 3 years ago
parent
commit
cbc8aa63c8
1 changed files with 21 additions and 1 deletions
  1. 21 1
      rtl/amiga/m68k/legacydos.inc

+ 21 - 1
rtl/amiga/m68k/legacydos.inc

@@ -230,11 +230,31 @@ end;
 
 { helper function used by MatchFirst, all input is expected to be lowercase }
 function NameMatchesPattern(pattern: AnsiString; filename: AnsiString): boolean;
+var
+  ofs: longint;
 begin
   NameMatchesPattern:=(pattern = '*') or (pattern = '#?') or (pattern = filename);
   if not NameMatchesPattern then
   begin
-    // TODO: pattern detection
+    { handle the simple case of #?.<ext> and *.<ext>, which is one of the most often used }
+    ofs:=Pos('#?',pattern);
+    if (ofs = 1) then
+    begin
+      Delete(pattern,1,length('#?'));
+      ofs:=Pos(pattern,filename);
+      NameMatchesPattern:=(ofs > 0) and ((ofs - 1) = length(filename) - length(pattern));
+      if NameMatchesPattern then
+        exit;
+    end;
+    ofs:=Pos('*',pattern);
+    if (ofs = 1) then
+    begin
+      Delete(pattern,1,length('*'));
+      ofs:=Pos(pattern,filename);
+      NameMatchesPattern:=(ofs > 0) and ((ofs - 1) = length(filename) - length(pattern));
+      if NameMatchesPattern then
+        exit;
+    end;
   end;
 end;