iso7185.pp 4.2 KB

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