text.inc 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  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,Longint(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,Longint(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. procedure fpc_write_text_qword(len : longint;var t : text;q : qword); iocheck; [public,alias:'FPC_WRITE_TEXT_QWORD']; {$ifdef hascompilerproc} compilerproc; {$endif}
  570. var
  571. s : string;
  572. begin
  573. if (InOutRes<>0) then
  574. exit;
  575. qword_str(q,s);
  576. write_str(len,t,s);
  577. end;
  578. procedure fpc_write_text_int64(len : longint;var t : text;i : int64); iocheck; [public,alias:'FPC_WRITE_TEXT_INT64']; {$ifdef hascompilerproc} compilerproc; {$endif}
  579. var
  580. s : string;
  581. begin
  582. if (InOutRes<>0) then
  583. exit;
  584. int64_str(i,s);
  585. write_str(len,t,s);
  586. end;
  587. 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}
  588. var
  589. s : String;
  590. Begin
  591. If (InOutRes<>0) then
  592. exit;
  593. Str_real(Len,fixkomma,r,treal_type(rt),s);
  594. Write_Str(Len,t,s);
  595. End;
  596. Procedure fpc_Write_Text_Boolean(Len : Longint;var t : Text;b : Boolean); iocheck; [Public,Alias:'FPC_WRITE_TEXT_BOOLEAN']; {$ifdef hascompilerproc} compilerproc; {$endif}
  597. Begin
  598. If (InOutRes<>0) then
  599. exit;
  600. { Can't use array[boolean] because b can be >0 ! }
  601. if b then
  602. Write_Str(Len,t,'TRUE')
  603. else
  604. Write_Str(Len,t,'FALSE');
  605. End;
  606. Procedure fpc_Write_Text_Char(Len : Longint;var t : Text;c : Char); iocheck; [Public,Alias:'FPC_WRITE_TEXT_CHAR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  607. Begin
  608. If (InOutRes<>0) then
  609. exit;
  610. if (TextRec(t).mode<>fmOutput) Then
  611. begin
  612. if TextRec(t).mode=fmClosed then
  613. InOutRes:=103
  614. else
  615. InOutRes:=105;
  616. exit;
  617. end;
  618. If Len>1 Then
  619. WriteBlanks(t,Len-1);
  620. If TextRec(t).BufPos+1>=TextRec(t).BufSize Then
  621. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  622. TextRec(t).Bufptr^[TextRec(t).BufPos]:=c;
  623. Inc(TextRec(t).BufPos);
  624. End;
  625. {$ifdef HASWIDECHAR}
  626. Procedure fpc_Write_Text_WideChar(Len : Longint;var t : Text;c : WideChar); iocheck; [Public,Alias:'FPC_WRITE_TEXT_WIDECHAR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  627. var
  628. ch : char;
  629. Begin
  630. If (InOutRes<>0) then
  631. exit;
  632. if (TextRec(t).mode<>fmOutput) Then
  633. begin
  634. if TextRec(t).mode=fmClosed then
  635. InOutRes:=103
  636. else
  637. InOutRes:=105;
  638. exit;
  639. end;
  640. If Len>1 Then
  641. WriteBlanks(t,Len-1);
  642. If TextRec(t).BufPos+1>=TextRec(t).BufSize Then
  643. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  644. ch:=c;
  645. TextRec(t).Bufptr^[TextRec(t).BufPos]:=ch;
  646. Inc(TextRec(t).BufPos);
  647. End;
  648. {$endif HASWIDECHAR}
  649. {*****************************************************************************
  650. Read(Ln)
  651. *****************************************************************************}
  652. Function NextChar(var f:Text;var s:string):Boolean;
  653. begin
  654. if TextRec(f).BufPos<TextRec(f).BufEnd then
  655. begin
  656. if length(s)<high(s) then
  657. begin
  658. inc(s[0]);
  659. s[length(s)]:=TextRec(f).BufPtr^[TextRec(f).BufPos];
  660. end;
  661. Inc(TextRec(f).BufPos);
  662. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  663. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  664. NextChar:=true;
  665. end
  666. else
  667. NextChar:=false;
  668. end;
  669. Function IgnoreSpaces(var f:Text):Boolean;
  670. {
  671. Removes all leading spaces,tab,eols from the input buffer, returns true if
  672. the buffer is empty
  673. }
  674. var
  675. s : string;
  676. begin
  677. s:='';
  678. IgnoreSpaces:=false;
  679. { Return false when already at EOF }
  680. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  681. exit;
  682. while (TextRec(f).Bufptr^[TextRec(f).BufPos] in [#9,#10,#13,' ']) do
  683. begin
  684. if not NextChar(f,s) then
  685. exit;
  686. { EOF? }
  687. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  688. break;
  689. end;
  690. IgnoreSpaces:=true;
  691. end;
  692. procedure ReadNumeric(var f:Text;var s:string);
  693. {
  694. Read numeric input, if buffer is empty then return True
  695. }
  696. begin
  697. repeat
  698. if not NextChar(f,s) then
  699. exit;
  700. until (length(s)=high(s)) or (TextRec(f).BufPtr^[TextRec(f).BufPos] in [#9,#10,#13,' ']);
  701. end;
  702. Procedure fpc_Read_End(var f:Text);[Public,Alias:'FPC_READ_END']; iocheck; {$ifdef hascompilerproc} compilerproc; {$endif}
  703. begin
  704. if TextRec(f).FlushFunc<>nil then
  705. FileFunc(TextRec(f).FlushFunc)(TextRec(f));
  706. end;
  707. Procedure fpc_ReadLn_End(var f : Text);[Public,Alias:'FPC_READLN_END']; iocheck; {$ifdef hascompilerproc} compilerproc; {$endif}
  708. var prev: char;
  709. Begin
  710. { Check error and if file is open and load buf if empty }
  711. If (InOutRes<>0) then
  712. exit;
  713. if (TextRec(f).mode<>fmInput) Then
  714. begin
  715. case TextRec(f).mode of
  716. fmOutPut,fmAppend:
  717. InOutRes:=104
  718. else
  719. InOutRes:=103;
  720. end;
  721. exit;
  722. end;
  723. if TextRec(f).BufPos>=TextRec(f).BufEnd Then
  724. begin
  725. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  726. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  727. { Flush if set }
  728. begin
  729. if (TextRec(f).FlushFunc<>nil) then
  730. FileFunc(TextRec(f).FlushFunc)(TextRec(f));
  731. exit;
  732. end;
  733. end;
  734. repeat
  735. prev := TextRec(f).BufPtr^[TextRec(f).BufPos];
  736. inc(TextRec(f).BufPos);
  737. { no system uses #10#13 as line seperator (#10 = *nix, #13 = Mac, }
  738. { #13#10 = Dos), so if we've got #10, we can safely exit }
  739. if prev = #10 then
  740. exit;
  741. if TextRec(f).BufPos>=TextRec(f).BufEnd Then
  742. begin
  743. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  744. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  745. { Flush if set }
  746. begin
  747. if (TextRec(f).FlushFunc<>nil) then
  748. FileFunc(TextRec(f).FlushFunc)(TextRec(f));
  749. exit;
  750. end;
  751. end;
  752. if (prev=#13) then
  753. { is there also a #10 after it? }
  754. begin
  755. if (TextRec(f).BufPtr^[TextRec(f).BufPos]=#10) then
  756. { yes, skip that one as well }
  757. inc(TextRec(f).BufPos);
  758. exit;
  759. end;
  760. until false;
  761. End;
  762. Function ReadPCharLen(var f:Text;s:pchar;maxlen:longint):longint;
  763. var
  764. sPos,len : Longint;
  765. p,startp,maxp : pchar;
  766. Begin
  767. ReadPCharLen:=0;
  768. { Check error and if file is open }
  769. If (InOutRes<>0) then
  770. exit;
  771. if (TextRec(f).mode<>fmInput) Then
  772. begin
  773. case TextRec(f).mode of
  774. fmOutPut,fmAppend:
  775. InOutRes:=104
  776. else
  777. InOutRes:=103;
  778. end;
  779. exit;
  780. end;
  781. { Read maximal until Maxlen is reached }
  782. sPos:=0;
  783. repeat
  784. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  785. begin
  786. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  787. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  788. break;
  789. end;
  790. p:=@TextRec(f).Bufptr^[TextRec(f).BufPos];
  791. if SPos+TextRec(f).BufEnd-TextRec(f).BufPos>MaxLen then
  792. maxp:=@TextRec(f).BufPtr^[TextRec(f).BufPos+MaxLen-SPos]
  793. else
  794. maxp:=@TextRec(f).Bufptr^[TextRec(f).BufEnd];
  795. startp:=p;
  796. { search linefeed }
  797. while (p<maxp) and not(P^ in [#10,#13]) do
  798. inc(p);
  799. { calculate read bytes }
  800. len:=p-startp;
  801. inc(TextRec(f).BufPos,Len);
  802. Move(startp^,s[sPos],Len);
  803. inc(sPos,Len);
  804. { was it a LF or CR? then leave }
  805. if (spos=MaxLen) or
  806. ((p<maxp) and (p^ in [#10,#13])) then
  807. break;
  808. until false;
  809. ReadPCharLen:=spos;
  810. End;
  811. Procedure fpc_Read_Text_ShortStr(var f : Text;var s : String); iocheck; [Public,Alias:'FPC_READ_TEXT_SHORTSTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  812. Begin
  813. s[0]:=chr(ReadPCharLen(f,pchar(@s[1]),high(s)));
  814. End;
  815. 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}
  816. Begin
  817. pchar(s+ReadPCharLen(f,s,$7fffffff))^:=#0;
  818. End;
  819. 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}
  820. var
  821. len: longint;
  822. Begin
  823. len := ReadPCharLen(f,pchar(@s),high(s)+1);
  824. if len <= high(s) then
  825. s[len] := #0;
  826. End;
  827. Procedure fpc_Read_Text_AnsiStr(var f : Text;var s : AnsiString); iocheck; [Public,Alias:'FPC_READ_TEXT_ANSISTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  828. var
  829. slen,len : longint;
  830. Begin
  831. slen:=0;
  832. Repeat
  833. // SetLength will reallocate the length.
  834. SetLength(S,slen+255);
  835. len:=ReadPCharLen(f,pchar(Pointer(S)+slen),255);
  836. inc(slen,len);
  837. Until len<255;
  838. // Set actual length
  839. SetLength(S,Slen);
  840. End;
  841. {$ifdef hascompilerproc}
  842. procedure fpc_Read_Text_Char(var f : Text; var c: char); iocheck; [Public,Alias:'FPC_READ_TEXT_CHAR'];compilerproc;
  843. {$else hascompilerproc}
  844. Function fpc_Read_Text_Char(var f : Text):char;[Public,Alias:'FPC_READ_TEXT_CHAR'];
  845. {$endif hascompilerproc}
  846. Begin
  847. {$ifdef hascompilerproc}
  848. c:=#0;
  849. {$else hascompilerproc}
  850. fpc_Read_Text_Char:=#0;
  851. {$endif hascompilerproc}
  852. { Check error and if file is open }
  853. If (InOutRes<>0) then
  854. exit;
  855. if (TextRec(f).mode<>fmInput) Then
  856. begin
  857. case TextRec(f).mode of
  858. fmOutPut,fmAppend:
  859. InOutRes:=104
  860. else
  861. InOutRes:=103;
  862. end;
  863. exit;
  864. end;
  865. { Read next char or EOF }
  866. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  867. begin
  868. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  869. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  870. {$ifdef hascompilerproc}
  871. begin
  872. c := #26;
  873. exit;
  874. end;
  875. {$else hascompilerproc}
  876. exit(#26);
  877. {$endif hascompilerproc}
  878. end;
  879. {$ifdef hascompilerproc}
  880. c:=TextRec(f).Bufptr^[TextRec(f).BufPos];
  881. {$else hascompilerproc}
  882. fpc_Read_Text_Char:=TextRec(f).Bufptr^[TextRec(f).BufPos];
  883. {$endif hascompilerproc}
  884. inc(TextRec(f).BufPos);
  885. end;
  886. {$ifdef hascompilerproc}
  887. Procedure fpc_Read_Text_SInt(var f : Text; var l : ValSInt); iocheck; [Public,Alias:'FPC_READ_TEXT_SINT']; compilerproc;
  888. {$else hascompilerproc}
  889. Function fpc_Read_Text_SInt(var f : Text):ValSInt;[Public,Alias:'FPC_READ_TEXT_SINT'];
  890. {$endif hascompilerproc}
  891. var
  892. hs : String;
  893. code : Longint;
  894. Begin
  895. {$ifdef hascompilerproc}
  896. l:=0;
  897. {$else hascompilerproc}
  898. fpc_Read_Text_SInt:=0;
  899. {$endif hascompilerproc}
  900. { Leave if error or not open file, else check for empty buf }
  901. If (InOutRes<>0) then
  902. exit;
  903. if (TextRec(f).mode<>fmInput) Then
  904. begin
  905. case TextRec(f).mode of
  906. fmOutPut,fmAppend:
  907. InOutRes:=104
  908. else
  909. InOutRes:=103;
  910. end;
  911. exit;
  912. end;
  913. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  914. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  915. hs:='';
  916. if IgnoreSpaces(f) then
  917. begin
  918. { When spaces were found and we are now at EOF,
  919. then we return 0 }
  920. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  921. exit;
  922. ReadNumeric(f,hs);
  923. end;
  924. {$ifdef hascompilerproc}
  925. Val(hs,l,code);
  926. {$else hascompilerproc}
  927. Val(hs,fpc_Read_Text_SInt,code);
  928. {$endif hascompilerproc}
  929. If code<>0 Then
  930. InOutRes:=106;
  931. End;
  932. {$ifdef hascompilerproc}
  933. Procedure fpc_Read_Text_UInt(var f : Text; var u : ValUInt); iocheck; [Public,Alias:'FPC_READ_TEXT_UINT']; compilerproc;
  934. {$else hascompilerproc}
  935. Function fpc_Read_Text_UInt(var f : Text):ValUInt;[Public,Alias:'FPC_READ_TEXT_UINT'];
  936. {$endif hascompilerproc}
  937. var
  938. hs : String;
  939. code : longint;
  940. Begin
  941. {$ifdef hascompilerproc}
  942. u:=0;
  943. {$else hascompilerproc}
  944. fpc_Read_Text_UInt:=0;
  945. {$endif hascompilerproc}
  946. { Leave if error or not open file, else check for empty buf }
  947. If (InOutRes<>0) then
  948. exit;
  949. if (TextRec(f).mode<>fmInput) Then
  950. begin
  951. case TextRec(f).mode of
  952. fmOutPut,fmAppend:
  953. InOutRes:=104
  954. else
  955. InOutRes:=103;
  956. end;
  957. exit;
  958. end;
  959. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  960. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  961. hs:='';
  962. if IgnoreSpaces(f) then
  963. begin
  964. { When spaces were found and we are now at EOF,
  965. then we return 0 }
  966. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  967. exit;
  968. ReadNumeric(f,hs);
  969. end;
  970. {$ifdef hascompilerproc}
  971. val(hs,u,code);
  972. {$else hascompilerproc}
  973. val(hs,fpc_Read_Text_UInt,code);
  974. {$endif hascompilerproc}
  975. If code<>0 Then
  976. InOutRes:=106;
  977. End;
  978. {$ifdef hascompilerproc}
  979. procedure fpc_Read_Text_Float(var f : Text; var v : ValReal); iocheck; [Public,Alias:'FPC_READ_TEXT_FLOAT']; compilerproc;
  980. {$else hascompilerproc}
  981. Function fpc_Read_Text_Float(var f : Text):ValReal;[Public,Alias:'FPC_READ_TEXT_FLOAT'];
  982. {$endif hascompilerproc}
  983. var
  984. hs : string;
  985. code : Word;
  986. begin
  987. {$ifdef hascompilerproc}
  988. v:=0.0;
  989. {$else hascompilerproc}
  990. fpc_Read_Text_Float:=0.0;
  991. {$endif hascompilerproc}
  992. { Leave if error or not open file, else check for empty buf }
  993. If (InOutRes<>0) then
  994. exit;
  995. if (TextRec(f).mode<>fmInput) Then
  996. begin
  997. case TextRec(f).mode of
  998. fmOutPut,fmAppend:
  999. InOutRes:=104
  1000. else
  1001. InOutRes:=103;
  1002. end;
  1003. exit;
  1004. end;
  1005. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  1006. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  1007. hs:='';
  1008. if IgnoreSpaces(f) then
  1009. begin
  1010. { When spaces were found and we are now at EOF,
  1011. then we return 0 }
  1012. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  1013. exit;
  1014. ReadNumeric(f,hs);
  1015. end;
  1016. {$ifdef hascompilerproc}
  1017. val(hs,v,code);
  1018. {$else hascompilerproc}
  1019. val(hs,fpc_Read_Text_Float,code);
  1020. {$endif hascompilerproc}
  1021. If code<>0 Then
  1022. InOutRes:=106;
  1023. end;
  1024. {$ifdef hascompilerproc}
  1025. procedure fpc_Read_Text_QWord(var f : text; var q : qword); iocheck; [public,alias:'FPC_READ_TEXT_QWORD']; compilerproc;
  1026. {$else hascompilerproc}
  1027. function fpc_Read_Text_QWord(var f : text) : qword;[public,alias:'FPC_READ_TEXT_QWORD'];
  1028. {$endif hascompilerproc}
  1029. var
  1030. hs : String;
  1031. code : longint;
  1032. Begin
  1033. {$ifdef hascompilerproc}
  1034. q:=0;
  1035. {$else hascompilerproc}
  1036. fpc_Read_Text_QWord:=0;
  1037. {$endif hascompilerproc}
  1038. { Leave if error or not open file, else check for empty buf }
  1039. If (InOutRes<>0) then
  1040. exit;
  1041. if (TextRec(f).mode<>fmInput) Then
  1042. begin
  1043. case TextRec(f).mode of
  1044. fmOutPut,fmAppend:
  1045. InOutRes:=104
  1046. else
  1047. InOutRes:=103;
  1048. end;
  1049. exit;
  1050. end;
  1051. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  1052. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  1053. hs:='';
  1054. if IgnoreSpaces(f) then
  1055. begin
  1056. { When spaces were found and we are now at EOF,
  1057. then we return 0 }
  1058. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  1059. exit;
  1060. ReadNumeric(f,hs);
  1061. end;
  1062. {$ifdef hascompilerproc}
  1063. val(hs,q,code);
  1064. {$else hascompilerproc}
  1065. val(hs,fpc_Read_Text_QWord,code);
  1066. {$endif hascompilerproc}
  1067. If code<>0 Then
  1068. InOutRes:=106;
  1069. End;
  1070. {$ifdef hascompilerproc}
  1071. procedure fpc_Read_Text_Int64(var f : text; var i : int64); iocheck; [public,alias:'FPC_READ_TEXT_INT64']; compilerproc;
  1072. {$else hascompilerproc}
  1073. function fpc_Read_Text_Int64(var f : text) : int64;[public,alias:'FPC_READ_TEXT_INT64']; {$ifdef hascompilerproc} compilerproc; {$endif}
  1074. {$endif hascompilerproc}
  1075. var
  1076. hs : String;
  1077. code : Longint;
  1078. Begin
  1079. {$ifdef hascompilerproc}
  1080. i:=0;
  1081. {$else hascompilerproc}
  1082. fpc_Read_Text_Int64:=0;
  1083. {$endif hascompilerproc}
  1084. { Leave if error or not open file, else check for empty buf }
  1085. If (InOutRes<>0) then
  1086. exit;
  1087. if (TextRec(f).mode<>fmInput) Then
  1088. begin
  1089. case TextRec(f).mode of
  1090. fmOutPut,fmAppend:
  1091. InOutRes:=104
  1092. else
  1093. InOutRes:=103;
  1094. end;
  1095. exit;
  1096. end;
  1097. If TextRec(f).BufPos>=TextRec(f).BufEnd Then
  1098. FileFunc(TextRec(f).InOutFunc)(TextRec(f));
  1099. hs:='';
  1100. if IgnoreSpaces(f) then
  1101. begin
  1102. { When spaces were found and we are now at EOF,
  1103. then we return 0 }
  1104. if (TextRec(f).BufPos>=TextRec(f).BufEnd) then
  1105. exit;
  1106. ReadNumeric(f,hs);
  1107. end;
  1108. {$ifdef hascompilerproc}
  1109. Val(hs,i,code);
  1110. {$else hascompilerproc}
  1111. Val(hs,fpc_Read_Text_Int64,code);
  1112. {$endif hascompilerproc}
  1113. If code<>0 Then
  1114. InOutRes:=106;
  1115. End;
  1116. {*****************************************************************************
  1117. Initializing
  1118. *****************************************************************************}
  1119. procedure OpenStdIO(var f:text;mode,hdl:longint);
  1120. begin
  1121. Assign(f,'');
  1122. TextRec(f).Handle:=hdl;
  1123. TextRec(f).Mode:=mode;
  1124. TextRec(f).Closefunc:=@FileCloseFunc;
  1125. case mode of
  1126. fmInput :
  1127. TextRec(f).InOutFunc:=@FileReadFunc;
  1128. fmOutput :
  1129. begin
  1130. TextRec(f).InOutFunc:=@FileWriteFunc;
  1131. TextRec(f).FlushFunc:=@FileWriteFunc;
  1132. end;
  1133. else
  1134. HandleError(102);
  1135. end;
  1136. end;
  1137. {
  1138. $Log$
  1139. Revision 1.20 2002-11-29 16:26:52 peter
  1140. * fixed ignorespaces which was broken by the previous commit
  1141. when a line started with spaces
  1142. Revision 1.19 2002/11/29 15:50:27 peter
  1143. * fix for tw1896
  1144. Revision 1.18 2002/09/07 15:07:46 peter
  1145. * old logs removed and tabs fixed
  1146. Revision 1.17 2002/07/01 16:29:05 peter
  1147. * sLineBreak changed to normal constant like Kylix
  1148. }