getret.pp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. { return the error code of the compiled file }
  2. { checks also if first line of source contains
  3. $OPT= command line options needed }
  4. program getret;
  5. uses dos;
  6. var com,args : string;
  7. filename,firstline : string;
  8. i : byte;
  9. ppfile, retfile : text;
  10. exefile : file;
  11. begin
  12. assign(retfile,'retcode');
  13. rewrite(retfile);
  14. args:='';
  15. if paramcount>1 then
  16. begin
  17. filename:=paramstr(paramcount);
  18. if pos('.',filename)=0 then
  19. filename:=filename+'.pp';
  20. assign(ppfile,filename);
  21. {$I-}
  22. reset(ppfile);
  23. if ioresult=0 then
  24. begin
  25. {$I+}
  26. readln(ppfile,firstline);
  27. if pos('$OPT=',firstline)>0 then
  28. args:=copy(Firstline,pos('=',Firstline)+1,255);
  29. if pos('}',args)>0 then
  30. args:=copy(args,1,pos('}',args)-1);
  31. close(ppfile);
  32. end;
  33. end;
  34. for i:=2 to paramcount do
  35. args:=args+' '+paramstr(i);
  36. com:=paramstr(1);
  37. {$ifndef linux}
  38. if pos('.',com)=0 then
  39. com:=com+'.exe';
  40. {$endif not linux}
  41. assign(exefile,com);
  42. {$I-}
  43. Writeln('testing ',com);
  44. reset(exefile,1);
  45. if ioresult<>0 then
  46. begin
  47. com:=fsearch(com,getenv('PATH'));
  48. end
  49. else
  50. close(exefile);
  51. {$I+}
  52. Writeln('Executing "',com,' ',args,'"');
  53. Flush(output);
  54. swapvectors;
  55. exec(com,args);
  56. swapvectors;
  57. if doserror<>0 then
  58. write(retfile,512+doserror)
  59. else
  60. write(retfile,dosexitcode);
  61. close(retfile);
  62. {$ifdef CPU86}
  63. { reset the FPU to avoid crashing make }
  64. {$asmmode att}
  65. asm
  66. fninit
  67. end;
  68. {$endif CPU86}
  69. end.