iso7185.pp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. Procedure Rewrite(var t : Text;const filename : string);
  23. Procedure Reset(var t : Text;const filename : string);
  24. Procedure Reset(var f : TypedFile;const filename : string); [INTERNPROC: fpc_in_Reset_TypedFile_Name];
  25. Procedure Rewrite(var f : TypedFile;const filename : string); [INTERNPROC: fpc_in_Rewrite_TypedFile_Name];
  26. Function Eof(Var t: Text): Boolean;
  27. Function Eof:Boolean;
  28. Function Eoln(Var t: Text): Boolean;
  29. Function Eoln:Boolean;
  30. Procedure Page;
  31. Procedure Page(Var t: Text);
  32. Procedure Get(Var t: Text);
  33. Procedure Put(Var t: Text);
  34. Procedure Get(Var f: TypedFile);
  35. Procedure Put(Var f: TypedFile);
  36. Function Eof(var f:TypedFile): Boolean;
  37. implementation
  38. {$i isotmp.inc}
  39. {$i-}
  40. procedure DoAssign(var t : Text);
  41. {$ifndef FPC_HAS_FEATURE_RANDOM}
  42. const
  43. NextIndex : Word = 1;
  44. {$endif FPC_HAS_FEATURE_RANDOM}
  45. begin
  46. {$ifdef FPC_HAS_FEATURE_RANDOM}
  47. Assign(t,getTempDir+'fpc_'+HexStr(random(1000000000),8)+'.tmp');
  48. {$else FPC_HAS_FEATURE_RANDOM}
  49. Assign(t,getTempDir+'fpc_'+HexStr(NextIndex,4)+'.tmp');
  50. Inc(NextIndex);
  51. {$endif FPC_HAS_FEATURE_RANDOM}
  52. end;
  53. Procedure Rewrite(var t : Text);[IOCheck];
  54. Begin
  55. { create file name? }
  56. if Textrec(t).mode=0 then
  57. DoAssign(t);
  58. System.Rewrite(t);
  59. End;
  60. Procedure Reset(var t : Text);[IOCheck];
  61. Begin
  62. case Textrec(t).mode of
  63. { create file name? }
  64. 0:
  65. DoAssign(t);
  66. fmOutput:
  67. Write(t,#26);
  68. end;
  69. System.Reset(t);
  70. End;
  71. Procedure Rewrite(var t : Text;const filename : string);[IOCheck];
  72. Begin
  73. { create file name? }
  74. if Textrec(t).mode=0 then
  75. Assign(t,filename);
  76. System.Rewrite(t);
  77. End;
  78. Procedure Reset(var t : Text;const filename : string);[IOCheck];
  79. Begin
  80. case Textrec(t).mode of
  81. { create file name? }
  82. 0:
  83. Assign(t,filename);
  84. fmOutput:
  85. Write(t,#26);
  86. end;
  87. System.Reset(t);
  88. End;
  89. Function Eof(Var t: Text): Boolean;[IOCheck];
  90. var
  91. OldCtrlZMarksEof : Boolean;
  92. Begin
  93. { not sure if this is correct, but we are always at eof when
  94. writing to a file }
  95. if TextRec(t).mode=fmOutput then
  96. Eof:=true
  97. else
  98. begin
  99. OldCtrlZMarksEof:=CtrlZMarksEOF;
  100. CtrlZMarksEof:=false;
  101. Eof:=System.Eof(t);
  102. CtrlZMarksEof:=OldCtrlZMarksEOF;
  103. end;
  104. end;
  105. Function Eof:Boolean;
  106. Begin
  107. Eof:=Eof(Input);
  108. End;
  109. Function Eoln(Var t: Text): Boolean;[IOCheck];
  110. var
  111. OldCtrlZMarksEof : Boolean;
  112. Begin
  113. OldCtrlZMarksEof:=CtrlZMarksEOF;
  114. CtrlZMarksEof:=true;
  115. Eoln:=System.Eoln(t);
  116. CtrlZMarksEof:=OldCtrlZMarksEOF;
  117. end;
  118. Function Eoln:Boolean;
  119. Begin
  120. Eoln:=Eoln(Input);
  121. End;
  122. Procedure Page;[IOCheck];
  123. begin
  124. Page(Output);
  125. end;
  126. Procedure Page(var t : Text);[IOCheck];
  127. Begin
  128. write(#12);
  129. End;
  130. procedure Get(var t : Text);[IOCheck];
  131. var
  132. c : char;
  133. Begin
  134. Read(t,c);
  135. End;
  136. Procedure Put(var t : Text);[IOCheck];
  137. type
  138. FileFunc = Procedure(var t : TextRec);
  139. begin
  140. inc(TextRec(t).BufPos);
  141. If TextRec(t).BufPos>=TextRec(t).BufSize Then
  142. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  143. end;
  144. procedure Get(var f:TypedFile);[IOCheck];
  145. Begin
  146. if not(eof(f)) then
  147. BlockRead(f,(pbyte(@f)+sizeof(FileRec))^,1)
  148. End;
  149. Procedure Put(var f:TypedFile);[IOCheck];
  150. begin
  151. BlockWrite(f,(pbyte(@f)+sizeof(FileRec))^,1)
  152. end;
  153. Function Eof(var f:TypedFile): Boolean;[IOCheck];
  154. Begin
  155. Eof:=FileRec(f)._private[1]=1;
  156. End;
  157. begin
  158. { we shouldn't do this because it might confuse user programs, but for now it
  159. is good enough to get pretty unique tmp file names }
  160. {$ifdef FPC_HAS_FEATURE_RANDOM}
  161. Randomize;
  162. {$endif FPC_HAS_FEATURE_RANDOM}
  163. { reset opens with read-only }
  164. Filemode:=0;
  165. end.