Prechádzať zdrojové kódy

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

git-svn-id: trunk@43026 -
michael 5 rokov pred
rodič
commit
9aa024c7df
1 zmenil súbory, kde vykonal 25 pridanie a 2 odobranie
  1. 25 2
      utils/instantfpc/instantfpc.pas

+ 25 - 2
utils/instantfpc/instantfpc.pas

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