iso7185.pp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {
  2. This file is part of the Free Pascal Run time library.
  3. Copyright (c) 2010 by Florian Klaempfl
  4. This unit contain procedures specific for iso pascal mode.
  5. It should be platform independant.
  6. See the file COPYING.FPC, included in this distribution,
  7. For details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit iso7185;
  13. interface
  14. const
  15. MaxInt = MaxLongint;
  16. type
  17. Integer = Longint;
  18. Procedure Rewrite(var t : Text);
  19. Procedure Reset(var t : Text);
  20. Procedure Reset(var f : TypedFile); [INTERNPROC: fpc_in_Reset_TypedFile];
  21. Procedure Rewrite(var f : TypedFile); [INTERNPROC: fpc_in_Rewrite_TypedFile];
  22. Function Eof(Var t: Text): Boolean;
  23. Function Eof:Boolean;
  24. Function Eoln(Var t: Text): Boolean;
  25. Function Eoln:Boolean;
  26. Procedure Page;
  27. Procedure Page(Var t: Text);
  28. Procedure Get(Var t: Text);
  29. Procedure Put(Var t: Text);
  30. Procedure Get(Var f: TypedFile);
  31. Procedure Put(Var f: TypedFile);
  32. Function Eof(var f:TypedFile): Boolean;
  33. implementation
  34. {$i-}
  35. procedure DoAssign(var t : Text);
  36. begin
  37. Assign(t,'fpc_'+HexStr(random(1000000000),8)+'.tmp');
  38. end;
  39. Procedure Rewrite(var t : Text);[IOCheck];
  40. Begin
  41. { create file name? }
  42. if Textrec(t).mode=0 then
  43. DoAssign(t);
  44. System.Rewrite(t);
  45. End;
  46. Procedure Reset(var t : Text);[IOCheck];
  47. Begin
  48. case Textrec(t).mode of
  49. { create file name? }
  50. 0:
  51. DoAssign(t);
  52. fmOutput:
  53. Write(t,#26);
  54. end;
  55. System.Reset(t);
  56. End;
  57. Function Eof(Var t: Text): Boolean;[IOCheck];
  58. var
  59. OldCtrlZMarksEof : Boolean;
  60. Begin
  61. { not sure if this is correct, but we are always at eof when
  62. writing to a file }
  63. if TextRec(t).mode=fmOutput then
  64. Eof:=true
  65. else
  66. begin
  67. OldCtrlZMarksEof:=CtrlZMarksEOF;
  68. CtrlZMarksEof:=false;
  69. Eof:=System.Eof(t);
  70. CtrlZMarksEof:=OldCtrlZMarksEOF;
  71. end;
  72. end;
  73. Function Eof:Boolean;
  74. Begin
  75. Eof:=Eof(Input);
  76. End;
  77. Function Eoln(Var t: Text): Boolean;[IOCheck];
  78. var
  79. OldCtrlZMarksEof : Boolean;
  80. Begin
  81. OldCtrlZMarksEof:=CtrlZMarksEOF;
  82. CtrlZMarksEof:=true;
  83. Eoln:=System.Eoln(t);
  84. CtrlZMarksEof:=OldCtrlZMarksEOF;
  85. end;
  86. Function Eoln:Boolean;
  87. Begin
  88. Eoln:=Eoln(Input);
  89. End;
  90. Procedure Page;[IOCheck];
  91. begin
  92. Page(Output);
  93. end;
  94. Procedure Page(var t : Text);[IOCheck];
  95. Begin
  96. write(#12);
  97. End;
  98. procedure Get(var t : Text);[IOCheck];
  99. var
  100. c : char;
  101. Begin
  102. Read(t,c);
  103. End;
  104. Procedure Put(var t : Text);[IOCheck];
  105. type
  106. FileFunc = Procedure(var t : TextRec);
  107. begin
  108. inc(TextRec(t).BufPos);
  109. If TextRec(t).BufPos>=TextRec(t).BufSize Then
  110. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  111. end;
  112. procedure Get(var f:TypedFile);[IOCheck];
  113. Begin
  114. if not(eof(f)) then
  115. BlockRead(f,(pbyte(@f)+sizeof(FileRec))^,1)
  116. End;
  117. Procedure Put(var f:TypedFile);[IOCheck];
  118. begin
  119. BlockWrite(f,(pbyte(@f)+sizeof(FileRec))^,1)
  120. end;
  121. Function Eof(var f:TypedFile): Boolean;[IOCheck];
  122. Type
  123. UnTypedFile = File;
  124. Begin
  125. Eof:=System.Eof(UnTypedFile(f));
  126. End;
  127. begin
  128. { we shouldn't do this because it might confuse user programs, but for now it
  129. is good enough to get pretty unique tmp file names }
  130. Randomize;
  131. { reset opens with read-only }
  132. Filemode:=0;
  133. end.