Browse Source

rtl/amiga: added some basic infrastructure to MatchFirst to improve pattern matching in the future

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

+ 11 - 3
rtl/amiga/m68k/legacydos.inc

@@ -228,8 +228,16 @@ begin
   NextDosEntry:=dlist;
 end;
 
-// Very first dirty version of MatchFirst/Next/End)
-//TODO: pattern detection, for now only simple "*" or "#?" or full name  (without patterns) is supported
+{ helper function used by MatchFirst, all input is expected to be lowercase }
+function NameMatchesPattern(pattern: AnsiString; filename: AnsiString): boolean;
+begin
+  NameMatchesPattern:=(pattern = '*') or (pattern = '#?') or (pattern = filename);
+  if not NameMatchesPattern then
+  begin
+    // TODO: pattern detection
+  end;
+end;
+
 function MatchFirst(pat   : PChar;
                     anchor: PAnchorPath): LongInt; public name '_fpc_amiga_matchfirst';
 var
@@ -310,7 +318,7 @@ begin
     if Res = 0 then
       break;
     // include some nifty pattern compare here? later maybe!
-    if (FileN = '*') or (FileN = '#?') or (FileN = lowercase(AnsiString(ib.fib_FileName))) then
+    if NameMatchesPattern(FileN, lowercase(AnsiString(fib^.fib_FileName))) then
     begin
       // Match found
       // new chain