* Allow sourcing program from stdn with -- option (bug ID 35945)

git-svn-id: trunk@43026 -
This commit is contained in:
michael 2019-09-17 10:35:36 +00:00
parent ccfe575645
commit 9aa024c7df

View File

@ -65,6 +65,8 @@ begin
writeln; writeln;
writeln('Options:'); writeln('Options:');
writeln; writeln;
writeln(' --');
Writeln(' Read program from standard input');
writeln(' --set-cache=<path to cache>'); writeln(' --set-cache=<path to cache>');
writeln(' Set the cache to be used. Otherwise using environment variable'); writeln(' Set the cache to be used. Otherwise using environment variable');
writeln(' INSTANTFPCCACHE.'); writeln(' INSTANTFPCCACHE.');
@ -95,7 +97,8 @@ var
CacheDir: String; CacheDir: String;
CacheFilename: String; CacheFilename: String;
OutputFilename: String; OutputFilename: String;
E : String; S,E : String;
DeleteCache : Boolean = False;
RunIt: boolean = true; RunIt: boolean = true;
// Return true if filename found. // Return true if filename found.
@ -131,6 +134,11 @@ begin
begin begin
Filename:=p; Filename:=p;
Result:=True; Result:=True;
end
else if (p='--') then
begin
Filename:='--';
Result:=True;
end; end;
end; end;
@ -173,7 +181,18 @@ begin
CheckSourceName(Filename); CheckSourceName(Filename);
Src:=TStringList.Create; Src:=TStringList.Create;
try try
Src.LoadFromFile(Filename); if FileName<>'--' then
Src.LoadFromFile(Filename)
else
begin
While not EOF do
begin
Readln(S);
Src.Add(S);
end;
FileName:=ChangeFileExt(GetTempFileName,'.pp');
DeleteCache:=true;
end;
CommentShebang(Src); CommentShebang(Src);
CacheDir:=GetCacheDir; CacheDir:=GetCacheDir;
@ -187,10 +206,14 @@ begin
// save source in cache to find out next time if something changed // save source in cache to find out next time if something changed
Src.SaveToFile(CacheFilename); Src.SaveToFile(CacheFilename);
Compile(Filename,CacheFilename,OutputFilename); Compile(Filename,CacheFilename,OutputFilename);
if deleteCache then
DeleteFile(CacheFileName);
end; end;
// run // run
if RunIt then if RunIt then
Run(OutputFilename); Run(OutputFilename);
if DeleteCache then
DeleteFile(OutputFileName);
finally finally
// memory is freed by OS, but for debugging puposes you can do it manually // memory is freed by OS, but for debugging puposes you can do it manually
{$IFDEF IFFreeMem} {$IFDEF IFFreeMem}