From 8169fd625576cab2e038c659117f8cc26fd07fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1roly=20Balogh?= Date: Sat, 23 Aug 2014 14:03:51 +0000 Subject: [PATCH] amicommon: a better and less hacky way to retrive the path. additionally this variant also works properly on AROS git-svn-id: trunk@28513 - --- rtl/amicommon/dos.pp | 26 ++++++++++++++------------ rtl/amicommon/sysutils.pp | 26 ++++++++++++++------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/rtl/amicommon/dos.pp b/rtl/amicommon/dos.pp index 4266c53f60..7ed8b5c328 100644 --- a/rtl/amicommon/dos.pp +++ b/rtl/amicommon/dos.pp @@ -882,30 +882,32 @@ end; var strofpaths : string; +function SystemTags(const command: PChar; const tags: array of DWord): LongInt; +begin + SystemTags:=SystemTagList(command,@tags); +end; + function getpathstring: string; var f : text; s : string; found : boolean; temp : string[255]; - tmpBat: string[31]; - tmpList: string[31]; begin found := true; temp := ''; - tmpBat:='T:'+HexStr(FindTask(nil)); - tmpList:=tmpBat+'_path.tmp'; - tmpBat:=tmpBat+'_path.sh'; - - assign(f,tmpBat); + { Alternatively, this could use PIPE: handler on systems which + have this by default (not the case on classic Amiga), but then + the child process should be started async, which for a simple + Path command probably isn't worth the trouble. (KB) } + assign(f,'T:'+HexStr(FindTask(nil))+'_path.tmp'); rewrite(f); - writeln(f,'path >'+tmpList); + { This is a pretty ugly stunt, combining Pascal and Amiga system + functions, but works... } + SystemTags('C:Path',[SYS_Input, 0, SYS_Output, TextRec(f).Handle, TAG_END]); close(f); - exec('C:Execute',tmpBat); - erase(f); - assign(f,tmpList); reset(f); { skip the first line, garbage } if not eof(f) then readln(f,s); @@ -914,7 +916,7 @@ begin if found then begin temp := s; found := false; - end else begin; + end else begin if (length(s) + length(temp)) < 255 then temp := temp + ';' + s; end; diff --git a/rtl/amicommon/sysutils.pp b/rtl/amicommon/sysutils.pp index 7c3081ac98..3783308b3f 100644 --- a/rtl/amicommon/sysutils.pp +++ b/rtl/amicommon/sysutils.pp @@ -618,28 +618,30 @@ end; var StrOfPaths: String; +function SystemTags(const command: PChar; const tags: array of DWord): LongInt; +begin + SystemTags:=SystemTagList(command,@tags); +end; + function GetPathString: String; var f : text; s : string; - tmpBat: string; - tmpList: string; begin s := ''; result := ''; - tmpBat:='T:'+HexStr(FindTask(nil)); - tmpList:=tmpBat+'_path.tmp'; - tmpBat:=tmpBat+'_path.sh'; - - assign(f,tmpBat); + { Alternatively, this could use PIPE: handler on systems which + have this by default (not the case on classic Amiga), but then + the child process should be started async, which for a simple + Path command probably isn't worth the trouble. (KB) } + assign(f,'T:'+HexStr(FindTask(nil))+'_path.tmp'); rewrite(f); - writeln(f,'path >'+tmpList); + { This is a pretty ugly stunt, combining Pascal and Amiga system + functions, but works... } + SystemTags('C:Path',[SYS_Input, 0, SYS_Output, TextRec(f).Handle, TAG_END]); close(f); - exec('C:Execute',tmpBat); - erase(f); - assign(f,tmpList); reset(f); { skip the first line, garbage } if not eof(f) then readln(f,s); @@ -647,7 +649,7 @@ begin readln(f,s); if result = '' then result := s - else + else result := result + ';' + s; end; close(f);