* rewrote glob to be much simpler and cleaner, the old code did

strange complex things with pointers which was unnecessary
This commit is contained in:
peter 2000-02-09 23:09:13 +00:00
parent f3f3fceb02
commit d45719bba6

View File

@ -3364,11 +3364,11 @@ Procedure Globfree(var p : pglob);
var var
temp : pglob; temp : pglob;
begin begin
while p<>nil do while assigned(p) do
begin begin
temp:=p^.next; temp:=p^.next;
if p^.name<>nil then if assigned(p^.name) then
freemem(p^.name,strlen(p^.name)+1); freemem(p^.name);
dispose(p); dispose(p);
p:=temp; p:=temp;
end; end;
@ -3383,16 +3383,17 @@ Function Glob(Const path:pathstr):pglob;
linuxerror is set accordingly. linuxerror is set accordingly.
} }
var var
temp : string[255]; temp,
thedir : pdir; temp2 : string[255];
buffer : pdirent; thedir : pdir;
root,run : pglob; buffer : pdirent;
root,
current : pglob;
begin begin
{ Get directory } { Get directory }
if dirname(path)='' then temp:=dirname(path);
temp:='.' if temp='' then
else temp:='.';
temp:=dirname(path);
temp:=temp+#0; temp:=temp+#0;
thedir:=opendir(@temp[1]); thedir:=opendir(@temp[1]);
if thedir=nil then if thedir=nil then
@ -3401,7 +3402,7 @@ begin
linuxerror:=errno; linuxerror:=errno;
exit; exit;
end; end;
temp:=basename(path,'');{ get the pattern } temp:=basename(path,''); { get the pattern }
if thedir^.fd<0 then if thedir^.fd<0 then
begin begin
linuxerror:=errno; linuxerror:=errno;
@ -3409,62 +3410,44 @@ begin
exit; exit;
end; end;
{get the entries} {get the entries}
new(root); root:=nil;
root^.next:=nil; current:=nil;
root^.name:=nil;
run:=root;
repeat repeat
buffer:=Sys_readdir(thedir); buffer:=Sys_readdir(thedir);
if buffer<>nil then if buffer=nil then
break;
temp2:=strpas(@(buffer^.name[0]));
if fnmatch(temp,temp2) then
begin begin
if fnmatch(temp,strpas(@(buffer^.name[0]))) then if root=nil then
begin begin
{ get memory for pglob } new(root);
new(run^.next); current:=root;
if run^.next=nil then end
begin else
linuxerror:=Sys_ENOMEM;
globfree(root);
glob:=nil;
exit;
end
else
begin
run:=run^.next;
run^.next:=nil;
end;
{ Get memory for name }
getmem(run^.name,strlen(@(buffer^.name[0]))+1);
if run^.name=nil then
begin
linuxerror:=Sys_ENOMEM;
globfree(root);
glob:=nil;
exit;
end;
move(buffer^.name[0],run^.name^,strlen(@(buffer^.name[0]))+1);
end;{ if fnmatch }
end { buffer <> nil }
else
begin
run:=root;
if root^.next<>nil then
root:=root^.next;{ put root on first entry}
if run<>nil then
begin begin
run^.next:=nil; new(current^.next);
globfree(run); current:=current^.next;
end; end;
if current=nil then
begin
linuxerror:=Sys_ENOMEM;
globfree(root);
break;
end;
current^.next:=nil;
getmem(current^.name,length(temp2)+1);
if current^.name=nil then
begin
linuxerror:=Sys_ENOMEM;
globfree(root);
break;
end;
move(buffer^.name[0],current^.name^,length(temp2)+1);
end; end;
until buffer=nil; until false;
if root^.name=nil then closedir(thedir);
begin glob:=root;
dispose(root);
linuxerror:=0;
glob:=nil;
end
else
glob:=root;
end; end;
@ -3848,7 +3831,11 @@ End.
{ {
$Log$ $Log$
Revision 1.61 2000-02-09 16:59:31 peter Revision 1.62 2000-02-09 23:09:13 peter
* rewrote glob to be much simpler and cleaner, the old code did
strange complex things with pointers which was unnecessary
Revision 1.61 2000/02/09 16:59:31 peter
* truncated log * truncated log
Revision 1.60 2000/02/08 12:05:58 peter Revision 1.60 2000/02/08 12:05:58 peter