text.inc 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  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. {
  12. Possible Defines:
  13. EOF_CTRLZ Is Ctrl-Z (#26) a EOF mark for textfiles
  14. SHORT_LINEBREAK Use short Linebreaks #10 instead of #10#13
  15. MAC_LINEBREAK Use Mac Linebreaks: #13 instead of #10 or #10#13
  16. SHORT_LINEBREAK is defined in the Linux system unit (syslinux.pp)
  17. }
  18. {****************************************************************************
  19. subroutines For TextFile handling
  20. ****************************************************************************}
  21. Procedure FileCloseFunc(Var t:TextRec);
  22. Begin
  23. Do_Close(t.Handle);
  24. t.Handle:=UnusedHandle;
  25. End;
  26. Procedure FileReadFunc(var t:TextRec);
  27. Begin
  28. t.BufEnd:=Do_Read(t.Handle,t.Bufptr,t.BufSize);
  29. t.BufPos:=0;
  30. End;
  31. Procedure FileWriteFunc(var t:TextRec);
  32. var
  33. i : longint;
  34. Begin
  35. i:=Do_Write(t.Handle,t.Bufptr,t.BufPos);
  36. if i<>t.BufPos then
  37. InOutRes:=101;
  38. t.BufPos:=0;
  39. End;
  40. Procedure FileOpenFunc(var t:TextRec);
  41. var
  42. Flags : Longint;
  43. Begin
  44. Case t.mode Of
  45. fmInput : Flags:=$10000;
  46. fmOutput : Flags:=$11001;
  47. fmAppend : Flags:=$10101;
  48. else
  49. begin
  50. InOutRes:=102;
  51. exit;
  52. end;
  53. End;
  54. Do_Open(t,PChar(@t.Name),Flags);
  55. t.CloseFunc:=@FileCloseFunc;
  56. t.FlushFunc:=nil;
  57. if t.Mode=fmInput then
  58. t.InOutFunc:=@FileReadFunc
  59. else
  60. begin
  61. t.InOutFunc:=@FileWriteFunc;
  62. { Only install flushing if its a NOT a file, and only check if there
  63. was no error opening the file, becuase else we always get a bad
  64. file handle error 6 (PFV) }
  65. if (InOutRes=0) and
  66. Do_Isdevice(t.Handle) then
  67. t.FlushFunc:=@FileWriteFunc;
  68. end;
  69. End;
  70. Procedure assign(var t:Text;const s:String);
  71. Begin
  72. FillChar(t,SizEof(TextRec),0);
  73. { only set things that are not zero }
  74. TextRec(t).Handle:=UnusedHandle;
  75. TextRec(t).mode:=fmClosed;
  76. TextRec(t).BufSize:=TextRecBufSize;
  77. TextRec(t).Bufptr:=@TextRec(t).Buffer;
  78. TextRec(t).OpenFunc:=@FileOpenFunc;
  79. Move(s[1],TextRec(t).Name,Length(s));
  80. End;
  81. Procedure assign(var t:Text;p:pchar);
  82. begin
  83. Assign(t,StrPas(p));
  84. end;
  85. Procedure assign(var t:Text;c:char);
  86. begin
  87. Assign(t,string(c));
  88. end;
  89. Procedure Close(var t : Text);[IOCheck];
  90. Begin
  91. if InOutRes<>0 then
  92. Exit;
  93. case TextRec(t).mode of
  94. fmInput,fmOutPut,fmAppend:
  95. Begin
  96. { Write pending buffer }
  97. If Textrec(t).Mode=fmoutput then
  98. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  99. { Only close functions not connected to stdout.}
  100. If ((TextRec(t).Handle<>StdInputHandle) and
  101. (TextRec(t).Handle<>StdOutputHandle) and
  102. (TextRec(t).Handle<>StdErrorHandle)) Then
  103. FileFunc(TextRec(t).CloseFunc)(TextRec(t));
  104. TextRec(t).mode := fmClosed;
  105. { Reset buffer for safety }
  106. TextRec(t).BufPos:=0;
  107. TextRec(t).BufEnd:=0;
  108. End
  109. else inOutRes := 103;
  110. End;
  111. End;
  112. Procedure OpenText(var t : Text;mode,defHdl:Longint);
  113. Begin
  114. Case TextRec(t).mode Of {This gives the fastest code}
  115. fmInput,fmOutput,fmInOut : Close(t);
  116. fmClosed : ;
  117. else
  118. Begin
  119. InOutRes:=102;
  120. exit;
  121. End;
  122. End;
  123. TextRec(t).mode:=mode;
  124. TextRec(t).bufpos:=0;
  125. TextRec(t).bufend:=0;
  126. FileFunc(TextRec(t).OpenFunc)(TextRec(t));
  127. { reset the mode to closed when an error has occured }
  128. if InOutRes<>0 then
  129. TextRec(t).mode:=fmClosed;
  130. End;
  131. Procedure Rewrite(var t : Text);[IOCheck];
  132. Begin
  133. If InOutRes<>0 then
  134. exit;
  135. OpenText(t,fmOutput,1);
  136. End;
  137. Procedure Reset(var t : Text);[IOCheck];
  138. Begin
  139. If InOutRes<>0 then
  140. exit;
  141. OpenText(t,fmInput,0);
  142. End;
  143. Procedure Append(var t : Text);[IOCheck];
  144. Begin
  145. If InOutRes<>0 then
  146. exit;
  147. OpenText(t,fmAppend,1);
  148. End;
  149. Procedure Flush(var t : Text);[IOCheck];
  150. Begin
  151. If InOutRes<>0 then
  152. exit;
  153. if TextRec(t).mode<>fmOutput then
  154. begin
  155. if TextRec(t).mode=fmInput then
  156. InOutRes:=105
  157. else
  158. InOutRes:=103;
  159. exit;
  160. end;
  161. { Not the flushfunc but the inoutfunc should be used, becuase that
  162. writes the data, flushfunc doesn't need to be assigned }
  163. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  164. End;
  165. Procedure Erase(var t:Text);[IOCheck];
  166. Begin
  167. If InOutRes <> 0 then
  168. exit;
  169. If TextRec(t).mode=fmClosed Then
  170. Do_Erase(PChar(@TextRec(t).Name));
  171. End;
  172. Procedure Rename(var t : text;p:pchar);[IOCheck];
  173. Begin
  174. If InOutRes <> 0 then
  175. exit;
  176. If TextRec(t).mode=fmClosed Then
  177. Begin
  178. Do_Rename(PChar(@TextRec(t).Name),p);
  179. { check error code of do_rename }
  180. If InOutRes = 0 then
  181. Move(p^,TextRec(t).Name,StrLen(p)+1);
  182. End;
  183. End;
  184. Procedure Rename(var t : Text;const s : string);[IOCheck];
  185. var
  186. p : array[0..255] Of Char;
  187. Begin
  188. If InOutRes <> 0 then
  189. exit;
  190. Move(s[1],p,Length(s));
  191. p[Length(s)]:=#0;
  192. Rename(t,Pchar(@p));
  193. End;
  194. Procedure Rename(var t : Text;c : char);[IOCheck];
  195. var
  196. p : array[0..1] Of Char;
  197. Begin
  198. If InOutRes <> 0 then
  199. exit;
  200. p[0]:=c;
  201. p[1]:=#0;
  202. Rename(t,Pchar(@p));
  203. End;
  204. Function Eof(Var t: Text): Boolean;[IOCheck];
  205. Begin
  206. If (InOutRes<>0) then
  207. exit(true);
  208. if (TextRec(t).mode<>fmInput) Then
  209. begin
  210. if TextRec(t).mode=fmOutput then
  211. InOutRes:=104
  212. else
  213. InOutRes:=103;
  214. exit(true);
  215. end;
  216. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  217. begin
  218. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  219. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  220. exit(true);
  221. end;
  222. {$ifdef EOF_CTRLZ}
  223. Eof:=(TextRec(t).Bufptr^[TextRec(t).BufPos]=#26);
  224. {$else}
  225. Eof:=false;
  226. {$endif EOL_CTRLZ}
  227. end;
  228. Function Eof:Boolean;
  229. Begin
  230. Eof:=Eof(Input);
  231. End;
  232. Function SeekEof (Var t : Text) : Boolean;
  233. var
  234. oldfilepos, oldbufpos, oldbufend, reads: longint;
  235. isdevice: boolean;
  236. Begin
  237. If (InOutRes<>0) then
  238. exit(true);
  239. if (TextRec(t).mode<>fmInput) Then
  240. begin
  241. if TextRec(t).mode=fmOutPut then
  242. InOutRes:=104
  243. else
  244. InOutRes:=103;
  245. exit(true);
  246. end;
  247. { try to save the current position in the file, seekeof() should not move }
  248. { the current file position (JM) }
  249. oldbufpos := TextRec(t).BufPos;
  250. oldbufend := TextRec(t).BufEnd;
  251. reads := 0;
  252. oldfilepos := -1;
  253. isdevice := Do_IsDevice(TextRec(t).handle);
  254. repeat
  255. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  256. begin
  257. { signal that the we will have to do a seek }
  258. inc(reads);
  259. if not isdevice and
  260. (reads = 1) then
  261. begin
  262. oldfilepos := Do_FilePos(TextRec(t).handle) - TextRec(t).BufEnd;
  263. InOutRes:=0;
  264. end;
  265. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  266. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  267. begin
  268. { if we only did a read in which we didn't read anything, the }
  269. { old buffer is still valid and we can simply restore the }
  270. { pointers (JM) }
  271. dec(reads);
  272. SeekEof := true;
  273. break;
  274. end;
  275. end;
  276. case TextRec(t).Bufptr^[TextRec(t).BufPos] of
  277. {$ifdef EOF_CTRLZ}
  278. #26 :
  279. begin
  280. SeekEof := true;
  281. break;
  282. end;
  283. {$endif EOF_CTRLZ}
  284. #10,#13,
  285. #9,' ' : ;
  286. else
  287. begin
  288. SeekEof := false;
  289. break;
  290. end;
  291. end;
  292. inc(TextRec(t).BufPos);
  293. until false;
  294. { restore file position if not working with a device }
  295. if not isdevice then
  296. { if we didn't modify the buffer, simply restore the BufPos and BufEnd }
  297. { (the latter becuase it's now probably set to zero because nothing was }
  298. { was read anymore) }
  299. if (reads = 0) then
  300. begin
  301. TextRec(t).BufPos:=oldbufpos;
  302. TextRec(t).BufEnd:=oldbufend;
  303. end
  304. { otherwise return to the old filepos and reset the buffer }
  305. else
  306. begin
  307. do_seek(TextRec(t).handle,oldfilepos);
  308. InOutRes:=0;
  309. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  310. TextRec(t).BufPos:=oldbufpos;
  311. end;
  312. End;
  313. Function SeekEof : Boolean;
  314. Begin
  315. SeekEof:=SeekEof(Input);
  316. End;
  317. Function Eoln(var t:Text) : Boolean;
  318. Begin
  319. If (InOutRes<>0) then
  320. exit(true);
  321. if (TextRec(t).mode<>fmInput) Then
  322. begin
  323. if TextRec(t).mode=fmOutPut then
  324. InOutRes:=104
  325. else
  326. InOutRes:=103;
  327. exit(true);
  328. end;
  329. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  330. begin
  331. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  332. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  333. exit(true);
  334. end;
  335. Eoln:=(TextRec(t).Bufptr^[TextRec(t).BufPos] in [#10,#13]);
  336. End;
  337. Function Eoln : Boolean;
  338. Begin
  339. Eoln:=Eoln(Input);
  340. End;
  341. Function SeekEoln (Var t : Text) : Boolean;
  342. Begin
  343. If (InOutRes<>0) then
  344. exit(true);
  345. if (TextRec(t).mode<>fmInput) Then
  346. begin
  347. if TextRec(t).mode=fmOutput then
  348. InOutRes:=104
  349. else
  350. InOutRes:=103;
  351. exit(true);
  352. end;
  353. repeat
  354. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  355. begin
  356. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  357. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  358. exit(true);
  359. end;
  360. case TextRec(t).Bufptr^[TextRec(t).BufPos] of
  361. #26,
  362. #10,#13 : exit(true);
  363. #9,' ' : ;
  364. else
  365. exit(false);
  366. end;
  367. inc(TextRec(t).BufPos);
  368. until false;
  369. End;
  370. Function SeekEoln : Boolean;
  371. Begin
  372. SeekEoln:=SeekEoln(Input);
  373. End;
  374. Procedure SetTextBuf(Var F : Text; Var Buf);[INTERNPROC: In_settextbuf_file_x];
  375. Procedure SetTextBuf(Var F : Text; Var Buf; Size : Longint);
  376. Begin
  377. TextRec(f).BufPtr:=@Buf;
  378. TextRec(f).BufSize:=Size;
  379. TextRec(f).BufPos:=0;
  380. TextRec(f).BufEnd:=0;
  381. End;
  382. {*****************************************************************************
  383. Write(Ln)
  384. *****************************************************************************}
  385. Procedure WriteBuffer(var f:Text;const b;len:longint);
  386. var
  387. p : pchar;
  388. left,
  389. idx : longint;
  390. begin
  391. p:=pchar(@b);
  392. idx:=0;
  393. left:=TextRec(f).BufSize-TextRec(f).BufPos;
  394. while len>left do
  395. begin
  396. move(p[idx],TextRec(f).Bufptr^[TextRec(f).BufPos],left);
  397. dec(len,left);
  398. inc(idx,left);
  399. inc(TextRec(f).BufPos,left);
  400. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  401. left:=TextRec(f).BufSize-TextRec(f).BufPos;
  402. end;
  403. move(p[idx],TextRec(f).Bufptr^[TextRec(f).BufPos],len);
  404. inc(TextRec(f).BufPos,len);
  405. end;
  406. Procedure WriteBlanks(var f:Text;len:longint);
  407. var
  408. left : longint;
  409. begin
  410. left:=TextRec(f).BufSize-TextRec(f).BufPos;
  411. while len>left do
  412. begin
  413. FillChar(TextRec(f).Bufptr^[TextRec(f).BufPos],left,' ');
  414. dec(len,left);
  415. inc(TextRec(f).BufPos,left);
  416. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  417. left:=TextRec(f).BufSize-TextRec(f).BufPos;
  418. end;
  419. FillChar(TextRec(f).Bufptr^[TextRec(f).BufPos],len,' ');
  420. inc(TextRec(f).BufPos,len);
  421. end;
  422. Procedure fpc_Write_End(var f:Text);[Public,Alias:'FPC_WRITE_END']; iocheck; {$ifdef hascompilerproc} compilerproc; {$endif}
  423. begin
  424. if TextRec(f).FlushFunc<>nil then
  425. FileFunc(TextRec(f).FlushFunc)(TextRec(f));
  426. end;
  427. Procedure fpc_Writeln_End(var f:Text);[Public,Alias:'FPC_WRITELN_END']; iocheck; {$ifdef hascompilerproc} compilerproc; {$endif}
  428. var
  429. eol : array[0..3] of char;
  430. begin
  431. If InOutRes <> 0 then exit;
  432. case TextRec(f).mode of
  433. fmOutput { fmAppend gets changed to fmOutPut in do_open (JM) }:
  434. begin
  435. eol:=sLineBreak;
  436. { Write EOL }
  437. WriteBuffer(f,eol,length(sLineBreak));
  438. { Flush }
  439. if TextRec(f).FlushFunc<>nil then
  440. FileFunc(TextRec(f).FlushFunc)(TextRec(f));
  441. end;
  442. fmInput: InOutRes:=105
  443. else InOutRes:=103;
  444. end;
  445. end;
  446. Procedure fpc_Write_Text_ShortStr(Len : Longint;var f : Text;const s : String); iocheck; [Public,Alias:'FPC_WRITE_TEXT_SHORTSTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  447. Begin
  448. If (InOutRes<>0) then
  449. exit;
  450. case TextRec(f).mode of
  451. fmOutput { fmAppend gets changed to fmOutPut in do_open (JM) }:
  452. begin
  453. If Len>Length(s) Then
  454. WriteBlanks(f,Len-Length(s));
  455. WriteBuffer(f,s[1],Length(s));
  456. end;
  457. fmInput: InOutRes:=105
  458. else InOutRes:=103;
  459. end;
  460. End;
  461. { provide local access to write_str }
  462. procedure Write_Str(Len : Longint;var f : Text;const s : String); iocheck; [external name 'FPC_WRITE_TEXT_SHORTSTR'];
  463. Procedure fpc_Write_Text_Pchar_as_Array(Len : Longint;var f : Text;const s : array of char); iocheck; [Public,Alias:'FPC_WRITE_TEXT_PCHAR_AS_ARRAY']; {$ifdef hascompilerproc} compilerproc; {$endif}
  464. var
  465. ArrayLen : longint;
  466. p : pchar;
  467. Begin
  468. If (InOutRes<>0) then
  469. exit;
  470. case TextRec(f).mode of
  471. fmOutput { fmAppend gets changed to fmOutPut in do_open (JM) }:
  472. begin
  473. p:=pchar(@s);
  474. { can't use StrLen, since that one could try to read past the end }
  475. { of the heap (JM) }
  476. ArrayLen:=IndexByte(p^,high(s)+1,0);
  477. { IndexByte returns -1 if not found (JM) }
  478. if ArrayLen = -1 then
  479. ArrayLen := high(s)+1;
  480. If Len>ArrayLen Then
  481. WriteBlanks(f,Len-ArrayLen);
  482. WriteBuffer(f,p^,ArrayLen);
  483. end;
  484. fmInput: InOutRes:=105
  485. else InOutRes:=103;
  486. end;
  487. End;
  488. Procedure fpc_Write_Text_PChar_As_Pointer(Len : Longint;var f : Text;p : PChar); iocheck; [Public,Alias:'FPC_WRITE_TEXT_PCHAR_AS_POINTER']; {$ifdef hascompilerproc} compilerproc; {$endif}
  489. var
  490. PCharLen : longint;
  491. Begin
  492. If (p=nil) or (InOutRes<>0) then
  493. exit;
  494. case TextRec(f).mode of
  495. fmOutput { fmAppend gets changed to fmOutPut in do_open (JM) }:
  496. begin
  497. PCharLen:=StrLen(p);
  498. If Len>PCharLen Then
  499. WriteBlanks(f,Len-PCharLen);
  500. WriteBuffer(f,p^,PCharLen);
  501. end;
  502. fmInput: InOutRes:=105
  503. else InOutRes:=103;
  504. end;
  505. End;
  506. Procedure fpc_Write_Text_AnsiStr (Len : Longint; Var f : Text; S : AnsiString); iocheck; [Public,alias:'FPC_WRITE_TEXT_ANSISTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  507. {
  508. Writes a AnsiString to the Text file T
  509. }
  510. var
  511. SLen : longint;
  512. begin
  513. If (InOutRes<>0) then
  514. exit;
  515. case TextRec(f).mode of
  516. fmOutput { fmAppend gets changed to fmOutPut in do_open (JM) }:
  517. begin
  518. SLen:=Length(s);
  519. If Len>SLen Then
  520. WriteBlanks(f,Len-SLen);
  521. if slen > 0 then
  522. WriteBuffer(f,PChar(S)^,SLen);
  523. end;
  524. fmInput: InOutRes:=105
  525. else InOutRes:=103;
  526. end;
  527. end;
  528. {$ifdef HASWIDESTRING}
  529. Procedure fpc_Write_Text_WideStr (Len : Longint; Var f : Text; S : WideString); iocheck; [Public,alias:'FPC_WRITE_TEXT_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  530. {
  531. Writes a WideString to the Text file T
  532. }
  533. var
  534. SLen : longint;
  535. begin
  536. If (pointer(S)=nil) or (InOutRes<>0) then
  537. exit;
  538. case TextRec(f).mode of
  539. fmOutput { fmAppend gets changed to fmOutPut in do_open (JM) }:
  540. begin
  541. SLen:=Length(s);
  542. If Len>SLen Then
  543. WriteBlanks(f,Len-SLen);
  544. WriteBuffer(f,PChar(AnsiString(S))^,SLen);
  545. end;
  546. fmInput: InOutRes:=105
  547. else InOutRes:=103;
  548. end;
  549. end;
  550. {$endif HASWIDESTRING}
  551. Procedure fpc_Write_Text_SInt(Len : Longint;var t : Text;l : ValSInt); iocheck; [Public,Alias:'FPC_WRITE_TEXT_SINT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  552. var
  553. s : String;
  554. Begin
  555. If (InOutRes<>0) then
  556. exit;
  557. Str(l,s);
  558. Write_Str(Len,t,s);
  559. End;
  560. Procedure fpc_Write_Text_UInt(Len : Longint;var t : Text;l : ValUInt); iocheck; [Public,Alias:'FPC_WRITE_TEXT_UINT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  561. var
  562. s : String;
  563. Begin
  564. If (InOutRes<>0) then
  565. exit;
  566. Str(L,s);
  567. Write_Str(Len,t,s);
  568. End;
  569. {$ifndef CPU64}
  570. procedure fpc_write_text_qword(len : longint;var t : text;q : qword); iocheck; [public,alias:'FPC_WRITE_TEXT_QWORD']; {$ifdef hascompilerproc} compilerproc; {$endif}
  571. var
  572. s : string;
  573. begin
  574. if (InOutRes<>0) then
  575. exit;
  576. str(q,s);
  577. write_str(len,t,s);
  578. end;
  579. procedure fpc_write_text_int64(len : longint;var t : text;i : int64); iocheck; [public,alias:'FPC_WRITE_TEXT_INT64']; {$ifdef hascompilerproc} compilerproc; {$endif}
  580. var
  581. s : string;
  582. begin
  583. if (InOutRes<>0) then
  584. exit;
  585. str(i,s);
  586. write_str(len,t,s);
  587. end;
  588. {$endif CPU64}
  589. Procedure fpc_Write_Text_Float(rt,fixkomma,Len : Longint;var t : Text;r : ValReal); iocheck; [Public,Alias:'FPC_WRITE_TEXT_FLOAT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  590. var
  591. s : String;
  592. Begin
  593. If (InOutRes<>0) then
  594. exit;
  595. Str_real(Len,fixkomma,r,treal_type(rt),s);
  596. Write_Str(Len,t,s);
  597. End;
  598. Procedure fpc_Write_Text_Boolean(Len : Longint;var t : Text;b : Boolean); iocheck; [Public,Alias:'FPC_WRITE_TEXT_BOOLEAN']; {$ifdef hascompilerproc} compilerproc; {$endif}
  599. Begin
  600. If (InOutRes<>0) then
  601. exit;
  602. { Can't use array[boolean] because b can be >0 ! }
  603. if b then
  604. Write_Str(Len,t,'TRUE')
  605. else
  606. Write_Str(Len,t,'FALSE');
  607. End;
  608. Procedure fpc_Write_Text_Char(Len : Longint;var t : Text;c : Char); iocheck; [Public,Alias:'FPC_WRITE_TEXT_CHAR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  609. Begin
  610. If (InOutRes<>0) then
  611. exit;
  612. if (TextRec(t).mode<>fmOutput) Then
  613. begin
  614. if TextRec(t).mode=fmClosed then
  615. InOutRes:=103
  616. else
  617. InOutRes:=105;
  618. exit;
  619. end;
  620. If Len>1 Then
  621. WriteBlanks(t,Len-1);
  622. If TextRec(t).BufPos+1>=TextRec(t).BufSize Then
  623. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  624. TextRec(t).Bufptr^[TextRec(t).BufPos]:=c;
  625. Inc(TextRec(t).BufPos);
  626. End;
  627. {$ifdef HASWIDECHAR}
  628. Procedure fpc_Write_Text_WideChar(Len : Longint;var t : Text;c : WideChar); iocheck; [Public,Alias:'FPC_WRITE_TEXT_WIDECHAR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  629. var
  630. ch : char;
  631. Begin
  632. If (InOutRes<>0) then
  633. exit;
  634. if (TextRec(t).mode<>fmOutput) Then
  635. begin
  636. if TextRec(t).mode=fmClosed then
  637. InOutRes:=103
  638. else
  639. InOutRes:=105;
  640. exit;
  641. end;
  642. If Len>1 Then
  643. WriteBlanks(t,Len-1);
  644. If TextRec(t).BufPos+1>=TextRec(t).BufSize Then
  645. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  646. ch:=c;
  647. TextRec(t).Bufptr^[TextRec(t).BufPos]:=ch;
  648. Inc(TextRec(t).BufPos);
  649. End;
  650. {$endif HASWIDECHAR}
  651. {*****************************************************************************
  652. Read(Ln)
  653. *****************************************************************************}
  654. Function NextChar(var f:Text;var s:string):Boolean;
  655. begin
  656. if TextRec(f).BufPos<TextRec(f).BufEnd then
  657. begin
  658. if length(s)<high(s) then
  659. begin
  660. inc(s[0]);
  661. s[length(s)]:=TextRec(f).BufPtr^[TextRec(f).BufPos];
  662. end;
  663. Inc(TextRec(f).BufPos);
  664. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  665. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  666. NextChar:=true;
  667. end
  668. else
  669. NextChar:=false;
  670. end;
  671. Function IgnoreSpaces(var f:Text):Boolean;
  672. {
  673. Removes all leading spaces,tab,eols from the input buffer, returns true if
  674. the buffer is empty
  675. }
  676. var
  677. s : string;
  678. begin
  679. s:='';
  680. IgnoreSpaces:=false;
  681. { Return false when already at EOF }
  682. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  683. exit;
  684. while (TextRec(f).Bufptr^[TextRec(f).BufPos] in [#9,#10,#13,' ']) do
  685. begin
  686. if not NextChar(f,s) then
  687. exit;
  688. { EOF? }
  689. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  690. break;
  691. end;
  692. IgnoreSpaces:=true;
  693. end;
  694. procedure ReadNumeric(var f:Text;var s:string);
  695. {
  696. Read numeric input, if buffer is empty then return True
  697. }
  698. begin
  699. repeat
  700. if not NextChar(f,s) then
  701. exit;
  702. until (length(s)=high(s)) or (TextRec(f).BufPtr^[TextRec(f).BufPos] in [#9,#10,#13,' ']);
  703. end;
  704. Procedure fpc_Read_End(var f:Text);[Public,Alias:'FPC_READ_END']; iocheck; {$ifdef hascompilerproc} compilerproc; {$endif}
  705. begin
  706. if TextRec(f).FlushFunc<>nil then
  707. FileFunc(TextRec(f).FlushFunc)(TextRec(f));
  708. end;
  709. Procedure fpc_ReadLn_End(var f : Text);[Public,Alias:'FPC_READLN_END']; iocheck; {$ifdef hascompilerproc} compilerproc; {$endif}
  710. var prev: char;
  711. Begin
  712. { Check error and if file is open and load buf if empty }
  713. If (InOutRes<>0) then
  714. exit;
  715. if (TextRec(f).mode<>fmInput) Then
  716. begin
  717. case TextRec(f).mode of
  718. fmOutPut,fmAppend:
  719. InOutRes:=104
  720. else
  721. InOutRes:=103;
  722. end;
  723. exit;
  724. end;
  725. if TextRec(f).BufPos>=TextRec(f).BufEnd Then
  726. begin
  727. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  728. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  729. { Flush if set }
  730. begin
  731. if (TextRec(f).FlushFunc<>nil) then
  732. FileFunc(TextRec(f).FlushFunc)(TextRec(f));
  733. exit;
  734. end;
  735. end;
  736. repeat
  737. prev := TextRec(f).BufPtr^[TextRec(f).BufPos];
  738. inc(TextRec(f).BufPos);
  739. { no system uses #10#13 as line seperator (#10 = *nix, #13 = Mac, }
  740. { #13#10 = Dos), so if we've got #10, we can safely exit }
  741. if prev = #10 then
  742. exit;
  743. if TextRec(f).BufPos>=TextRec(f).BufEnd Then
  744. begin
  745. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  746. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  747. { Flush if set }
  748. begin
  749. if (TextRec(f).FlushFunc<>nil) then
  750. FileFunc(TextRec(f).FlushFunc)(TextRec(f));
  751. exit;
  752. end;
  753. end;
  754. if (prev=#13) then
  755. { is there also a #10 after it? }
  756. begin
  757. if (TextRec(f).BufPtr^[TextRec(f).BufPos]=#10) then
  758. { yes, skip that one as well }
  759. inc(TextRec(f).BufPos);
  760. exit;
  761. end;
  762. until false;
  763. End;
  764. Function ReadPCharLen(var f:Text;s:pchar;maxlen:longint):longint;
  765. var
  766. sPos,len : Longint;
  767. p,startp,maxp : pchar;
  768. Begin
  769. ReadPCharLen:=0;
  770. { Check error and if file is open }
  771. If (InOutRes<>0) then
  772. exit;
  773. if (TextRec(f).mode<>fmInput) Then
  774. begin
  775. case TextRec(f).mode of
  776. fmOutPut,fmAppend:
  777. InOutRes:=104
  778. else
  779. InOutRes:=103;
  780. end;
  781. exit;
  782. end;
  783. { Read maximal until Maxlen is reached }
  784. sPos:=0;
  785. repeat
  786. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  787. begin
  788. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  789. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  790. break;
  791. end;
  792. p:=@TextRec(f).Bufptr^[TextRec(f).BufPos];
  793. if SPos+TextRec(f).BufEnd-TextRec(f).BufPos>MaxLen then
  794. maxp:=@TextRec(f).BufPtr^[TextRec(f).BufPos+MaxLen-SPos]
  795. else
  796. maxp:=@TextRec(f).Bufptr^[TextRec(f).BufEnd];
  797. startp:=p;
  798. { search linefeed }
  799. while (p<maxp) and not(P^ in [#10,#13]) do
  800. inc(p);
  801. { calculate read bytes }
  802. len:=p-startp;
  803. inc(TextRec(f).BufPos,Len);
  804. Move(startp^,s[sPos],Len);
  805. inc(sPos,Len);
  806. { was it a LF or CR? then leave }
  807. if (spos=MaxLen) or
  808. ((p<maxp) and (p^ in [#10,#13])) then
  809. break;
  810. until false;
  811. ReadPCharLen:=spos;
  812. End;
  813. Procedure fpc_Read_Text_ShortStr(var f : Text;var s : String); iocheck; [Public,Alias:'FPC_READ_TEXT_SHORTSTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  814. Begin
  815. s[0]:=chr(ReadPCharLen(f,pchar(@s[1]),high(s)));
  816. End;
  817. Procedure fpc_Read_Text_PChar_As_Pointer(var f : Text;var s : PChar); iocheck; [Public,Alias:'FPC_READ_TEXT_PCHAR_AS_POINTER']; {$ifdef hascompilerproc} compilerproc; {$endif}
  818. Begin
  819. pchar(s+ReadPCharLen(f,s,$7fffffff))^:=#0;
  820. End;
  821. Procedure fpc_Read_Text_PChar_As_Array(var f : Text;var s : array of char); iocheck; [Public,Alias:'FPC_READ_TEXT_PCHAR_AS_ARRAY']; {$ifdef hascompilerproc} compilerproc; {$endif}
  822. var
  823. len: longint;
  824. Begin
  825. len := ReadPCharLen(f,pchar(@s),high(s)+1);
  826. if len <= high(s) then
  827. s[len] := #0;
  828. End;
  829. Procedure fpc_Read_Text_AnsiStr(var f : Text;var s : AnsiString); iocheck; [Public,Alias:'FPC_READ_TEXT_ANSISTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  830. var
  831. slen,len : longint;
  832. Begin
  833. slen:=0;
  834. Repeat
  835. // SetLength will reallocate the length.
  836. SetLength(S,slen+255);
  837. len:=ReadPCharLen(f,pchar(Pointer(S)+slen),255);
  838. inc(slen,len);
  839. Until len<255;
  840. // Set actual length
  841. SetLength(S,Slen);
  842. End;
  843. {$ifdef hascompilerproc}
  844. procedure fpc_Read_Text_Char(var f : Text; var c: char); iocheck; [Public,Alias:'FPC_READ_TEXT_CHAR'];compilerproc;
  845. {$else hascompilerproc}
  846. Function fpc_Read_Text_Char(var f : Text):char;[Public,Alias:'FPC_READ_TEXT_CHAR'];
  847. {$endif hascompilerproc}
  848. Begin
  849. {$ifdef hascompilerproc}
  850. c:=#0;
  851. {$else hascompilerproc}
  852. fpc_Read_Text_Char:=#0;
  853. {$endif hascompilerproc}
  854. { Check error and if file is open }
  855. If (InOutRes<>0) then
  856. exit;
  857. if (TextRec(f).mode<>fmInput) Then
  858. begin
  859. case TextRec(f).mode of
  860. fmOutPut,fmAppend:
  861. InOutRes:=104
  862. else
  863. InOutRes:=103;
  864. end;
  865. exit;
  866. end;
  867. { Read next char or EOF }
  868. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  869. begin
  870. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  871. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  872. {$ifdef hascompilerproc}
  873. begin
  874. c := #26;
  875. exit;
  876. end;
  877. {$else hascompilerproc}
  878. exit(#26);
  879. {$endif hascompilerproc}
  880. end;
  881. {$ifdef hascompilerproc}
  882. c:=TextRec(f).Bufptr^[TextRec(f).BufPos];
  883. {$else hascompilerproc}
  884. fpc_Read_Text_Char:=TextRec(f).Bufptr^[TextRec(f).BufPos];
  885. {$endif hascompilerproc}
  886. inc(TextRec(f).BufPos);
  887. end;
  888. {$ifdef hascompilerproc}
  889. Procedure fpc_Read_Text_SInt(var f : Text; var l : ValSInt); iocheck; [Public,Alias:'FPC_READ_TEXT_SINT']; compilerproc;
  890. {$else hascompilerproc}
  891. Function fpc_Read_Text_SInt(var f : Text):ValSInt;[Public,Alias:'FPC_READ_TEXT_SINT'];
  892. {$endif hascompilerproc}
  893. var
  894. hs : String;
  895. code : Longint;
  896. Begin
  897. {$ifdef hascompilerproc}
  898. l:=0;
  899. {$else hascompilerproc}
  900. fpc_Read_Text_SInt:=0;
  901. {$endif hascompilerproc}
  902. { Leave if error or not open file, else check for empty buf }
  903. If (InOutRes<>0) then
  904. exit;
  905. if (TextRec(f).mode<>fmInput) Then
  906. begin
  907. case TextRec(f).mode of
  908. fmOutPut,fmAppend:
  909. InOutRes:=104
  910. else
  911. InOutRes:=103;
  912. end;
  913. exit;
  914. end;
  915. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  916. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  917. hs:='';
  918. if IgnoreSpaces(f) then
  919. begin
  920. { When spaces were found and we are now at EOF,
  921. then we return 0 }
  922. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  923. exit;
  924. ReadNumeric(f,hs);
  925. end;
  926. {$ifdef hascompilerproc}
  927. Val(hs,l,code);
  928. {$else hascompilerproc}
  929. Val(hs,fpc_Read_Text_SInt,code);
  930. {$endif hascompilerproc}
  931. If code<>0 Then
  932. InOutRes:=106;
  933. End;
  934. {$ifdef hascompilerproc}
  935. Procedure fpc_Read_Text_UInt(var f : Text; var u : ValUInt); iocheck; [Public,Alias:'FPC_READ_TEXT_UINT']; compilerproc;
  936. {$else hascompilerproc}
  937. Function fpc_Read_Text_UInt(var f : Text):ValUInt;[Public,Alias:'FPC_READ_TEXT_UINT'];
  938. {$endif hascompilerproc}
  939. var
  940. hs : String;
  941. code : longint;
  942. Begin
  943. {$ifdef hascompilerproc}
  944. u:=0;
  945. {$else hascompilerproc}
  946. fpc_Read_Text_UInt:=0;
  947. {$endif hascompilerproc}
  948. { Leave if error or not open file, else check for empty buf }
  949. If (InOutRes<>0) then
  950. exit;
  951. if (TextRec(f).mode<>fmInput) Then
  952. begin
  953. case TextRec(f).mode of
  954. fmOutPut,fmAppend:
  955. InOutRes:=104
  956. else
  957. InOutRes:=103;
  958. end;
  959. exit;
  960. end;
  961. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  962. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  963. hs:='';
  964. if IgnoreSpaces(f) then
  965. begin
  966. { When spaces were found and we are now at EOF,
  967. then we return 0 }
  968. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  969. exit;
  970. ReadNumeric(f,hs);
  971. end;
  972. {$ifdef hascompilerproc}
  973. val(hs,u,code);
  974. {$else hascompilerproc}
  975. val(hs,fpc_Read_Text_UInt,code);
  976. {$endif hascompilerproc}
  977. If code<>0 Then
  978. InOutRes:=106;
  979. End;
  980. {$ifdef hascompilerproc}
  981. procedure fpc_Read_Text_Float(var f : Text; var v : ValReal); iocheck; [Public,Alias:'FPC_READ_TEXT_FLOAT']; compilerproc;
  982. {$else hascompilerproc}
  983. Function fpc_Read_Text_Float(var f : Text):ValReal;[Public,Alias:'FPC_READ_TEXT_FLOAT'];
  984. {$endif hascompilerproc}
  985. var
  986. hs : string;
  987. code : Word;
  988. begin
  989. {$ifdef hascompilerproc}
  990. v:=0.0;
  991. {$else hascompilerproc}
  992. fpc_Read_Text_Float:=0.0;
  993. {$endif hascompilerproc}
  994. { Leave if error or not open file, else check for empty buf }
  995. If (InOutRes<>0) then
  996. exit;
  997. if (TextRec(f).mode<>fmInput) Then
  998. begin
  999. case TextRec(f).mode of
  1000. fmOutPut,fmAppend:
  1001. InOutRes:=104
  1002. else
  1003. InOutRes:=103;
  1004. end;
  1005. exit;
  1006. end;
  1007. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  1008. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  1009. hs:='';
  1010. if IgnoreSpaces(f) then
  1011. begin
  1012. { When spaces were found and we are now at EOF,
  1013. then we return 0 }
  1014. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  1015. exit;
  1016. ReadNumeric(f,hs);
  1017. end;
  1018. {$ifdef hascompilerproc}
  1019. val(hs,v,code);
  1020. {$else hascompilerproc}
  1021. val(hs,fpc_Read_Text_Float,code);
  1022. {$endif hascompilerproc}
  1023. If code<>0 Then
  1024. InOutRes:=106;
  1025. end;
  1026. {$ifdef hascompilerproc}
  1027. procedure fpc_Read_Text_QWord(var f : text; var q : qword); iocheck; [public,alias:'FPC_READ_TEXT_QWORD']; compilerproc;
  1028. {$else hascompilerproc}
  1029. function fpc_Read_Text_QWord(var f : text) : qword;[public,alias:'FPC_READ_TEXT_QWORD'];
  1030. {$endif hascompilerproc}
  1031. var
  1032. hs : String;
  1033. code : longint;
  1034. Begin
  1035. {$ifdef hascompilerproc}
  1036. q:=0;
  1037. {$else hascompilerproc}
  1038. fpc_Read_Text_QWord:=0;
  1039. {$endif hascompilerproc}
  1040. { Leave if error or not open file, else check for empty buf }
  1041. If (InOutRes<>0) then
  1042. exit;
  1043. if (TextRec(f).mode<>fmInput) Then
  1044. begin
  1045. case TextRec(f).mode of
  1046. fmOutPut,fmAppend:
  1047. InOutRes:=104
  1048. else
  1049. InOutRes:=103;
  1050. end;
  1051. exit;
  1052. end;
  1053. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  1054. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  1055. hs:='';
  1056. if IgnoreSpaces(f) then
  1057. begin
  1058. { When spaces were found and we are now at EOF,
  1059. then we return 0 }
  1060. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  1061. exit;
  1062. ReadNumeric(f,hs);
  1063. end;
  1064. {$ifdef hascompilerproc}
  1065. val(hs,q,code);
  1066. {$else hascompilerproc}
  1067. val(hs,fpc_Read_Text_QWord,code);
  1068. {$endif hascompilerproc}
  1069. If code<>0 Then
  1070. InOutRes:=106;
  1071. End;
  1072. {$ifdef hascompilerproc}
  1073. procedure fpc_Read_Text_Int64(var f : text; var i : int64); iocheck; [public,alias:'FPC_READ_TEXT_INT64']; compilerproc;
  1074. {$else hascompilerproc}
  1075. function fpc_Read_Text_Int64(var f : text) : int64;[public,alias:'FPC_READ_TEXT_INT64']; {$ifdef hascompilerproc} compilerproc; {$endif}
  1076. {$endif hascompilerproc}
  1077. var
  1078. hs : String;
  1079. code : Longint;
  1080. Begin
  1081. {$ifdef hascompilerproc}
  1082. i:=0;
  1083. {$else hascompilerproc}
  1084. fpc_Read_Text_Int64:=0;
  1085. {$endif hascompilerproc}
  1086. { Leave if error or not open file, else check for empty buf }
  1087. If (InOutRes<>0) then
  1088. exit;
  1089. if (TextRec(f).mode<>fmInput) Then
  1090. begin
  1091. case TextRec(f).mode of
  1092. fmOutPut,fmAppend:
  1093. InOutRes:=104
  1094. else
  1095. InOutRes:=103;
  1096. end;
  1097. exit;
  1098. end;
  1099. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  1100. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  1101. hs:='';
  1102. if IgnoreSpaces(f) then
  1103. begin
  1104. { When spaces were found and we are now at EOF,
  1105. then we return 0 }
  1106. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  1107. exit;
  1108. ReadNumeric(f,hs);
  1109. end;
  1110. {$ifdef hascompilerproc}
  1111. Val(hs,i,code);
  1112. {$else hascompilerproc}
  1113. Val(hs,fpc_Read_Text_Int64,code);
  1114. {$endif hascompilerproc}
  1115. If code<>0 Then
  1116. InOutRes:=106;
  1117. End;
  1118. {*****************************************************************************
  1119. Initializing
  1120. *****************************************************************************}
  1121. procedure OpenStdIO(var f:text;mode,hdl:longint);
  1122. begin
  1123. Assign(f,'');
  1124. TextRec(f).Handle:=hdl;
  1125. TextRec(f).Mode:=mode;
  1126. TextRec(f).Closefunc:=@FileCloseFunc;
  1127. case mode of
  1128. fmInput :
  1129. TextRec(f).InOutFunc:=@FileReadFunc;
  1130. fmOutput :
  1131. begin
  1132. TextRec(f).InOutFunc:=@FileWriteFunc;
  1133. TextRec(f).FlushFunc:=@FileWriteFunc;
  1134. end;
  1135. else
  1136. HandleError(102);
  1137. end;
  1138. end;
  1139. {
  1140. $Log$
  1141. Revision 1.22 2004-04-29 18:59:43 peter
  1142. * str() helpers now also use valint/valuint
  1143. * int64/qword helpers disabled for cpu64
  1144. Revision 1.21 2004/04/22 21:10:56 peter
  1145. * do_read/do_write addr argument changed to pointer
  1146. Revision 1.20 2002/11/29 16:26:52 peter
  1147. * fixed ignorespaces which was broken by the previous commit
  1148. when a line started with spaces
  1149. Revision 1.19 2002/11/29 15:50:27 peter
  1150. * fix for tw1896
  1151. Revision 1.18 2002/09/07 15:07:46 peter
  1152. * old logs removed and tabs fixed
  1153. Revision 1.17 2002/07/01 16:29:05 peter
  1154. * sLineBreak changed to normal constant like Kylix
  1155. }