consoleio.pp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2011 by the Free Pascal development team.
  4. Console i/o for the FPC embedded target
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$mode objfpc}
  12. Unit consoleio;
  13. interface
  14. implementation
  15. procedure SysInitStdIO;
  16. begin
  17. // OpenStdIO(Input,fmInput,0);
  18. // OpenStdIO(Output,fmOutput,0);
  19. // OpenStdIO(ErrOutput,fmOutput,0);
  20. // OpenStdIO(StdOut,fmOutput,0);
  21. // OpenStdIO(StdErr,fmOutput,0);
  22. end;
  23. procedure SysFlushStdIO;
  24. begin
  25. { Make sure that all output is written to the redirected file }
  26. {!!!!!!!! if Textrec(Output).Mode=fmOutput then
  27. Flush(Output);
  28. if Textrec(ErrOutput).Mode=fmOutput then
  29. Flush(ErrOutput);
  30. if Textrec(stdout).Mode=fmOutput then
  31. Flush(stdout);
  32. if Textrec(StdErr).Mode=fmOutput then
  33. Flush(StdErr); }
  34. end;
  35. var
  36. ErrorBase : Pointer;external name 'FPC_ERRORBASE';
  37. var
  38. pstdout : ^Text;
  39. initialization
  40. { Setup stdin, stdout and stderr }
  41. SysInitStdIO;
  42. finalization
  43. { Show runtime error and exit }
  44. pstdout:=@stdout;
  45. If erroraddr<>nil Then
  46. Begin
  47. Writeln(pstdout^,'Runtime error ',Errorcode,' at $',hexstr(erroraddr));
  48. { to get a nice symify }
  49. Writeln(pstdout^,BackTraceStrFunc(Erroraddr));
  50. dump_stack(pstdout^,ErrorBase);
  51. Writeln(pstdout^,'');
  52. End;
  53. SysFlushStdIO;
  54. end.