text.inc 32 KB

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