dummyas.pp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2007 by Pierre Muller
  4. member of the Free Pascal development team.
  5. Dummy assembler program to be able to easily test
  6. all FPC targets even without cross tools.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. program dummyas;
  14. var
  15. assembler_name : string;
  16. object_name : string;
  17. ofile : text;
  18. function RemoveSuffix(const st : string) : string;
  19. var
  20. i,last : longint;
  21. begin
  22. last:=length(st);
  23. for i:=length(st) downto 1 do
  24. begin
  25. if st[i]='.' then
  26. begin
  27. last:=i-1;
  28. break;
  29. end;
  30. end;
  31. RemoveSuffix:=Copy(st,1,last);
  32. end;
  33. var
  34. i : longint;
  35. param : string;
  36. skipnext : boolean;
  37. begin
  38. object_name:='';
  39. skipnext:=false;
  40. for i:=1 to ParamCount do
  41. begin
  42. param:=Paramstr(i);
  43. if skipnext or (length(Param)=0) then
  44. begin
  45. skipnext:=false;
  46. continue;
  47. end;
  48. if Param='-o' then
  49. begin
  50. skipnext:=true;
  51. object_name:=ParamStr(i+1);
  52. end
  53. else if (Param[1]='-') then
  54. begin
  55. { option Param not handled }
  56. { Shouldn't be a real problem }
  57. end
  58. else
  59. begin
  60. if assembler_name='' then
  61. assembler_name:=ParamStr(i)
  62. else
  63. begin
  64. Writeln(stderr,'two non option param found!');
  65. Writeln(stderr,'first non option param =',assembler_name);
  66. Writeln(stderr,'second non option param =',Param);
  67. Writeln(stderr,'Don''t know how to handle this!');
  68. halt(1);
  69. end;
  70. end;
  71. end;
  72. if assembler_name='' then
  73. begin
  74. Writeln(stderr,'Dummyas, no source file specified');
  75. halt(1);
  76. end;
  77. Assign(ofile,assembler_name);
  78. {$push}{$I-}
  79. Reset(ofile);
  80. if IOResult<>0 then
  81. begin
  82. Writeln(stderr,'Dummyas, source file not found ',assembler_name);
  83. halt(1);
  84. end;
  85. Close(ofile);
  86. if object_name='' then
  87. object_name:=RemoveSuffix(assembler_name)+'.o';
  88. Assign(ofile,object_name);
  89. Rewrite(ofile);
  90. if IOResult<>0 then
  91. begin
  92. Writeln(stderr,'Dummyas, object file not writable ',object_name);
  93. halt(1);
  94. end;
  95. Writeln(ofile,'Dummy as called');
  96. for i:=0 to Paramcount do
  97. Write(ofile,ParamStr(i),' ');
  98. Writeln(ofile);
  99. Writeln(ofile,'assembler file=',assembler_name);
  100. Writeln(ofile,'object file=',object_name);
  101. Close(ofile);
  102. {$pop}
  103. end.