text.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. { $Id$
  2. This file is part of the Free Pascal Run time library.
  3. Copyright (c) 1993,97 by the Free Pascal development team
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {
  11. Possible Defines:
  12. EXTENDED_EOF Use extended EOF checking for textfile, necessary for
  13. Pipes and Sockets under Linux
  14. EOF_CTRLZ Is Ctrl-Z (#26) a EOF mark for textfiles
  15. SHORT_LINEBREAK Use short Linebreaks #10 instead of #10#13
  16. Both EXTENDED_EOF and SHORT_LINEBREAK are defined in the Linux system
  17. unit (syslinux.pp)
  18. }
  19. {****************************************************************************
  20. subroutines For TextFile handling
  21. ****************************************************************************}
  22. Procedure FileCloseFunc(Var t:TextRec);
  23. Begin
  24. Do_Close(t.Handle);
  25. t.Handle:=UnusedHandle;
  26. End;
  27. Procedure FileInOutFunc(var t:TextRec);
  28. Begin
  29. Case t.mode Of
  30. fmoutput : Do_Write(t.Handle,Longint(t.Bufptr),t.BufPos);
  31. fminput : t.BufEnd:=Do_Read(t.Handle,Longint(t.Bufptr),t.BufSize);
  32. else
  33. RunError(102);
  34. End;
  35. t.BufPos:=0;
  36. End;
  37. Procedure FileOpenFunc(var t:TextRec);
  38. var
  39. Flags : Longint;
  40. Begin
  41. t.InOutFunc:=@FileInOutFunc;
  42. t.FlushFunc:=@FileInOutFunc;
  43. t.CloseFunc:=@FileCloseFunc;
  44. Case t.mode Of
  45. fmInput : Flags:=$1000;
  46. fmOutput : Flags:=$1101;
  47. fmAppend : Flags:=$1011;
  48. End;
  49. Do_Open(t,PChar(@TextRec(t).Name),Flags);
  50. End;
  51. Procedure assign(var t:Text;const s:String);
  52. Begin
  53. FillChar(t,SizEof(TextRec),0);
  54. TextRec(t).Handle:=UnusedHandle;
  55. TextRec(t).mode:=fmClosed;
  56. TextRec(t).BufSize:=128;
  57. TextRec(t).Bufpos:=0;
  58. TextRec(T).Bufend:=0;
  59. TextRec(t).Bufptr:=@TextRec(t).Buffer;
  60. TextRec(t).OpenFunc:=@FileOpenFunc;
  61. Move(s[1],TextRec(t).Name,Length(s));
  62. End;
  63. Procedure Close(var t : Text);[Public,Alias: 'CLOSE_TEXT',IOCheck];
  64. Begin
  65. If (TextRec(t).mode<>fmClosed) Then
  66. Begin
  67. FileFunc(TextRec(t).FlushFunc)(TextRec(t));
  68. TextRec(t).mode:=fmClosed;
  69. { Only close functions not connected to stdout.}
  70. If ((TextRec(t).Handle<>StdInputHandle) or
  71. (TextRec(t).Handle<>StdOutputHandle) or
  72. (TextRec(t).Handle<>StdErrorHandle)) Then
  73. FileFunc(TextRec(t).CloseFunc)(TextRec(t));
  74. End;
  75. End;
  76. Procedure OpenText(var t : Text;mode,defHdl:Longint);
  77. Begin
  78. Case TextRec(t).mode Of {This gives the fastest code}
  79. fmInput,fmOutput,fmInOut : Close(t);
  80. fmClosed : ;
  81. else
  82. Begin
  83. InOutRes:=102;
  84. exit;
  85. End;
  86. End;
  87. TextRec(t).mode:=mode;
  88. If TextRec(t).Name[0]<>#0 Then
  89. FileFunc(TextRec(t).OpenFunc)(TextRec(t))
  90. else
  91. Begin
  92. TextRec(t).Handle:=defHdl;
  93. TextRec(t).InOutFunc:=@FileInOutFunc;
  94. TextRec(t).FlushFunc:=@FileInOutFunc;
  95. TextRec(t).CloseFunc:=@FileCloseFunc;
  96. End;
  97. End;
  98. Procedure Rewrite(var t : Text);[IOCheck];
  99. Begin
  100. OpenText(t,fmOutput,1);
  101. End;
  102. Procedure Reset(var t : Text);[IOCheck];
  103. Begin
  104. OpenText(t,fmInput,0);
  105. End;
  106. Procedure Append(var t : Text);[IOCheck];
  107. Begin
  108. OpenText(t,fmAppend,1);
  109. End;
  110. Procedure Flush(var t : Text);[IOCheck];
  111. Begin
  112. If TextRec(t).mode<>fmOutput Then
  113. exit;
  114. FileFunc(TextRec(t).FlushFunc)(TextRec(t));
  115. End;
  116. Procedure Erase(var t:Text);[IOCheck];
  117. Begin
  118. If TextRec(t).mode=fmClosed Then
  119. Do_Erase(PChar(@TextRec(t).Name));
  120. End;
  121. Procedure Rename(var t:Text;const s:String);[IOCheck];
  122. var
  123. p : array[0..255] Of Char;
  124. Begin
  125. If TextRec(t).mode=fmClosed Then
  126. Begin
  127. Move(s[1],p,Length(s));
  128. p[Length(s)]:=#0;
  129. Do_Rename(PChar(@TextRec(t).Name),PChar(@p));
  130. Move(p,TextRec(t).Name,Length(s)+1);
  131. End;
  132. End;
  133. Function Eof(Var t: Text): Boolean;[IOCheck];
  134. Begin
  135. {$IFNDEF EXTENDED_EOF}
  136. {$IFDEF EOF_CTRLZ}
  137. Eof:=TextRec(t).Buffer[TextRec(t).BufPos]=#26;
  138. If Eof Then
  139. Exit;
  140. {$ENDIF EOL_CTRLZ}
  141. Eof:=(Do_FileSize(TextRec(t).Handle)<=Do_FilePos(TextRec(t).Handle));
  142. If Eof Then
  143. Eof:=TextRec(t).BufEnd <= TextRec(t).BufPos;
  144. {$ELSE EXTENDED_EOF}
  145. { The previous method will NOT work on stdin and pipes or sockets.
  146. So how to do it ?
  147. 1) Check if characters in buffer - Yes ? Eof=false;
  148. 2) Read buffer full. If 0 Chars Read : Eof !
  149. Michael.}
  150. If TextRec(T).mode=fmClosed Then { Sanity Check }
  151. Begin
  152. Eof:=True;
  153. Exit;
  154. End;
  155. If (TextRec(T).BufPos < TextRec(T).BufEnd) Then
  156. Begin
  157. Eof:=False;
  158. Exit
  159. End;
  160. TextRec(T).BufPos:=0;
  161. TextRec(T).BufEnd:=Do_Read(TextRec(T).Handle,Longint(TextRec(T).BufPtr),TextRec(T).BufSize);
  162. If TextRec(T).BufEnd<0 Then
  163. TextRec(T).BufEnd:=0;
  164. Eof:=(TextRec(T).BufEnd=0);
  165. {$ENDIF EXTENDED_EOF}
  166. End;
  167. Function Eof:Boolean;
  168. Begin
  169. Eof:=Eof(Input);
  170. End;
  171. Function SeekEof (Var F : Text) : Boolean;
  172. Var
  173. TR : ^TextRec;
  174. Temp : Longint;
  175. Begin
  176. TR:=@TextRec(f);
  177. If TR^.mode<>fmInput Then exit (true);
  178. SeekEof:=True;
  179. {No data in buffer ? Fill it }
  180. If TR^.BufPos>=TR^.BufEnd Then
  181. FileFunc(TR^.InOutFunc)(TR^);
  182. Temp:=TR^.BufPos;
  183. while (TR^.BufPos<TR^.BufEnd) Do
  184. Begin
  185. If (TR^.Bufptr^[Temp] In [#9,#10,#13,' ']) Then
  186. Inc(Temp)
  187. else
  188. Begin
  189. SeekEof:=False;
  190. TR^.BufPos:=Temp;
  191. exit;
  192. End;
  193. If Temp>=TR^.BufEnd Then
  194. Begin
  195. FileFunc(TR^.InOutFunc)(TR^);
  196. Temp:=TR^.BufPos+1;
  197. End;
  198. End;
  199. End;
  200. Function SeekEof : Boolean;
  201. Begin
  202. SeekEof:=SeekEof(Input);
  203. End;
  204. Function Eoln(var t:Text) : Boolean;
  205. Begin
  206. { maybe we need new data }
  207. If TextRec(t).BufPos>=TextRec(t).BufEnd Then
  208. FileFunc(TextRec(t).InOutFunc)(TextRec(t));
  209. Eoln:=Eof(t) or (TextRec(t).Bufptr^[TextRec(t).BufPos] In [#10,#13]);
  210. End;
  211. Function Eoln : Boolean;
  212. Begin
  213. Eoln:=Eoln(Input);
  214. End;
  215. Function SeekEoln (Var F : Text) : Boolean;
  216. Var
  217. TR : ^TextRec;
  218. Temp : Longint;
  219. Begin
  220. TR:=@TextRec(f);
  221. If TR^.mode<>fmInput Then
  222. exit (true);
  223. SeekEoln:=True;
  224. {No data in buffer ? Fill it }
  225. If TR^.BufPos>=TR^.BufEnd Then
  226. FileFunc(TR^.InOutFunc)(TR^);
  227. Temp:=TR^.BufPos;
  228. while (TR^.BufPos<TR^.BufEnd) Do
  229. Begin
  230. Case (TR^.Bufptr^[Temp]) Of
  231. #10 : Exit;
  232. #9,' ' : Inc(Temp)
  233. else
  234. Begin
  235. SeekEoln:=False;
  236. TR^.BufPos:=Temp;
  237. exit;
  238. End;
  239. End;
  240. If Temp>=TR^.BufEnd Then
  241. Begin
  242. FileFunc(TR^.InOutFunc)(TR^);
  243. Temp:=TR^.BufPos+1;
  244. End;
  245. End;
  246. End;
  247. Function SeekEoln : Boolean;
  248. Begin
  249. SeekEoln:=SeekEoln(Input);
  250. End;
  251. Procedure SetTextBuf(Var F : Text; Var Buf);[INTERNPROC: In_settextbuf_file_x];
  252. Procedure SetTextBuf(Var F : Text; Var Buf; Size : Word);
  253. Begin
  254. TextRec(f).BufPtr:=@Buf;
  255. TextRec(f).BufSize:=Size;
  256. TextRec(f).BufPos:=0;
  257. TextRec(f).BufEnd:=0;
  258. End;
  259. {*****************************************************************************
  260. Write(Ln)
  261. *****************************************************************************}
  262. Procedure w(Len : Longint;var f : TextRec;var s : String);[Public,Alias: 'WRITE_TEXT_STRING'];
  263. var
  264. hbytes,Pos,copybytes : Longint;
  265. hs : String;
  266. Begin
  267. If f.mode<>fmOutput Then
  268. exit;
  269. copybytes:=Length(s);
  270. If Len>copybytes Then
  271. Begin
  272. hs:=Space(Len-copybytes);
  273. w(0,f,hs);
  274. End;
  275. Pos:=1;
  276. hbytes:=f.BufSize-f.BufPos;
  277. { If no room in Buffer, do a flush. }
  278. If hbytes=0 Then
  279. FileFunc(f.FlushFunc)(f);
  280. while copybytes>hbytes Do
  281. Begin
  282. Move(s[Pos],f.Bufptr^[f.BufPos],hbytes);
  283. f.BufPos:=f.BufPos+hbytes;
  284. dec(copybytes,hbytes);
  285. Inc(Pos,hbytes);
  286. FileFunc(f.InOutFunc)(f);
  287. hbytes:=f.BufSize-f.BufPos;
  288. End;
  289. Move(s[Pos],f.Bufptr^[f.BufPos],copybytes);
  290. f.BufPos:=f.BufPos+copybytes;
  291. End;
  292. Procedure w(var t : TextRec);[Public,Alias: 'WRITELN_TEXT'];
  293. var
  294. hs : String;
  295. Begin
  296. {$IFDEF SHORT_LINEBREAK}
  297. hs:=#10;
  298. {$ELSE}
  299. hs:=#13#10;
  300. {$ENDIF}
  301. w(0,t,hs);
  302. End;
  303. Type
  304. array00 = array[0..0] Of Char;
  305. Procedure w(Len : Longint;var f : TextRec;const p : array00);[Public,Alias: 'WRITE_TEXT_PCHAR_AS_ARRAY'];
  306. var
  307. hbytes,Pos,copybytes : Longint;
  308. hs : String;
  309. Begin
  310. If f.mode<>fmOutput Then
  311. exit;
  312. copybytes:=StrLen(p);
  313. If Len>copybytes Then
  314. Begin
  315. hs:=Space(Len-copybytes);
  316. w(0,f,hs);
  317. End;
  318. Pos:=0;
  319. hbytes:=f.BufSize-f.BufPos;
  320. { If no room in buffer , do a flush. }
  321. If hbytes=0 Then
  322. FileFunc(f.FlushFunc)(f);
  323. while copybytes>hbytes Do
  324. Begin
  325. Move(p[Pos],f.Bufptr^[f.BufPos],hbytes);
  326. f.BufPos:=f.BufPos+hbytes;
  327. dec(copybytes,hbytes);
  328. Inc(Pos,hbytes);
  329. FileFunc(f.InOutFunc)(f);
  330. hbytes:=f.BufSize-f.BufPos;
  331. End;
  332. Move(p[Pos],f.Bufptr^[f.BufPos],copybytes);
  333. f.BufPos:=f.BufPos+copybytes;
  334. End;
  335. Procedure wa(Len : Longint;var f : TextRec;p : PChar);[Public,Alias: 'WRITE_TEXT_PCHAR_AS_POINTER'];
  336. Begin
  337. w(Len,f,p);
  338. End;
  339. Procedure w(Len : Longint;var t : TextRec;l : Longint);[Public,Alias: 'WRITE_TEXT_LONGINT'];
  340. var
  341. s : String;
  342. Begin
  343. Str(l,s);
  344. w(Len,t,s);
  345. End;
  346. Procedure w(fixkomma,Len : Longint;var t : TextRec;r : real);[Public,Alias: 'WRITE_TEXT_REAL'];
  347. var
  348. s : String;
  349. Begin
  350. {$ifdef i386}
  351. Str_real(Len,fixkomma,r,rt_s64real,s);
  352. {$else}
  353. Str_real(Len,fixkomma,r,rt_s32real,s);
  354. {$endif}
  355. w(Len,t,s);
  356. End;
  357. Procedure w(Len : Longint;var t : TextRec;l : cardinal);[Public,Alias: 'WRITE_TEXT_CARDINAL'];
  358. var
  359. s : String;
  360. Begin
  361. Str(L,s);
  362. w(Len,t,s);
  363. End;
  364. Procedure w(fixkomma,Len : Longint;var t : TextRec;r : single);[Public,Alias: 'WRITE_TEXT_SINGLE'];
  365. var
  366. s : String;
  367. Begin
  368. Str_real(Len,fixkomma,r,rt_s32real,s);
  369. w(Len,t,s);
  370. End;
  371. Procedure w(fixkomma,Len : Longint;var t : TextRec;r : extended);[Public,Alias: 'WRITE_TEXT_EXTENDED'];
  372. var
  373. s : String;
  374. Begin
  375. Str_real(Len,fixkomma,r,rt_s80real,s);
  376. w(Len,t,s);
  377. End;
  378. Procedure w(fixkomma,Len : Longint;var t : TextRec;r : comp);[Public,Alias: 'WRITE_TEXT_COMP'];
  379. var
  380. s : String;
  381. Begin
  382. Str_real(Len,fixkomma,r,rt_s64bit,s);
  383. w(Len,t,s);
  384. End;
  385. Procedure w(fixkomma,Len : Longint;var t : TextRec;r : fixed);[Public,Alias: 'WRITE_TEXT_FIXED'];
  386. var
  387. s : String;
  388. Begin
  389. Str_real(Len,fixkomma,r,rt_f32bit,s);
  390. w(Len,t,s);
  391. End;
  392. { Is called wc to avoid recursive calling. }
  393. Procedure wc(Len : Longint;var t : TextRec;b : Boolean);[Public,Alias: 'WRITE_TEXT_BOOLEAN'];
  394. const
  395. BoolString:array[0..1] Of String[5]=('False','True');
  396. Begin
  397. w(Len,t,String(BoolString[byte(b)]));
  398. End;
  399. Procedure wc(Len : Longint;var t : TextRec;c : Char);[Public,Alias: 'WRITE_TEXT_CHAR'];
  400. var
  401. hs : String;
  402. Begin
  403. If t.mode<>fmOutput Then
  404. exit;
  405. If Len>1 Then
  406. Begin
  407. hs:=Space(Len-1);
  408. w(0,t,hs);
  409. End;
  410. If t.BufPos+1>=t.BufSize Then
  411. FileFunc(t.FlushFunc)(t);
  412. t.Bufptr^[t.BufPos]:=c;
  413. Inc(t.BufPos);
  414. End;
  415. {*****************************************************************************
  416. Read(Ln)
  417. *****************************************************************************}
  418. Function OpenInput(var f:TextRec):boolean;
  419. begin
  420. If f.mode=fmInput Then
  421. begin
  422. { No characters in the buffer? Load them ! }
  423. If f.BufPos>=f.BufEnd Then
  424. FileFunc(f.InOutFunc)(f);
  425. OpenInput:=true;
  426. end
  427. else
  428. OpenInput:=false;
  429. end;
  430. Function NextChar(var f:TextRec;var s:string):Boolean;
  431. begin
  432. if f.BufPos<f.BufEnd then
  433. begin
  434. s:=s+f.BufPtr^[f.BufPos];
  435. Inc(f.BufPos);
  436. If f.BufPos>=f.BufEnd Then
  437. FileFunc(f.InOutFunc)(f);
  438. NextChar:=true;
  439. end
  440. else
  441. NextChar:=false;
  442. end;
  443. Function IgnoreSpaces(var f:TextRec):Boolean;
  444. {
  445. Removes all leading spaces,tab,eols from the input buffer, returns true if
  446. the buffer is empty
  447. }
  448. var
  449. s : string;
  450. begin
  451. s:='';
  452. IgnoreSpaces:=false;
  453. while f.Bufptr^[f.BufPos] in [#9,#10,#13,' '] do
  454. if not NextChar(f,s) then
  455. exit;
  456. IgnoreSpaces:=true;
  457. end;
  458. Function ReadSign(var f:TextRec;var s:string):Boolean;
  459. {
  460. Read + and - sign, return true if buffer is empty
  461. }
  462. begin
  463. ReadSign:=(not (f.Bufptr^[f.BufPos] in ['-','+'])) or NextChar(f,s);
  464. end;
  465. Function ReadBase(var f:TextRec;var s:string;var Base:longint):boolean;
  466. {
  467. Read the base $ For 16 and % For 2, if buffer is empty return true
  468. }
  469. begin
  470. case f.BufPtr^[f.BufPos] of
  471. '$' : Base:=16;
  472. '%' : Base:=2;
  473. else
  474. Base:=10;
  475. end;
  476. ReadBase:=(Base=10) or NextChar(f,s);
  477. end;
  478. Function ReadNumeric(var f:TextRec;var s:string;base:longint):Boolean;
  479. {
  480. Read numeric input, if buffer is empty then return True
  481. }
  482. var
  483. c : char;
  484. begin
  485. ReadNumeric:=false;
  486. c:=f.BufPtr^[f.BufPos];
  487. while ((base>=10) and (c in ['0'..'9'])) or
  488. ((base=16) and (c in ['A'..'F','a'..'f'])) or
  489. ((base=2) and (c in ['0'..'1'])) do
  490. begin
  491. if not NextChar(f,s) then
  492. exit;
  493. c:=f.BufPtr^[f.BufPos];
  494. end;
  495. ReadNumeric:=true;
  496. end;
  497. Procedure r(var f : TextRec);[Public,Alias: 'READLN_TEXT'];
  498. Begin
  499. if not OpenInput(f) then
  500. exit;
  501. while (f.BufPos<f.BufEnd) do
  502. begin
  503. inc(f.BufPos);
  504. if (f.BufPtr^[f.BufPos-1]=#10) then
  505. exit;
  506. If f.BufPos>=f.BufEnd Then
  507. FileFunc(f.InOutFunc)(f);
  508. end;
  509. End;
  510. Procedure r(var f : TextRec;var s : String);[Public,Alias: 'READ_TEXT_STRING'];
  511. var
  512. Temp,sPos : Word;
  513. Begin
  514. { Delete the string }
  515. s:='';
  516. if not OpenInput(f) then
  517. exit;
  518. Temp:=f.BufPos;
  519. sPos:=1;
  520. while (f.BufPos<f.BufEnd) and (f.Bufptr^[Temp]<>#10) Do
  521. Begin
  522. { search linefeed }
  523. while (f.Bufptr^[Temp]<>#10) and (Temp<f.BufEnd) Do
  524. Inc(Temp);
  525. { copy String. Take 255 char limit in account.}
  526. If sPos+Temp-f.BufPos<=255 Then
  527. Begin
  528. Move (f.Bufptr^[f.BufPos],s[sPos],Temp-f.BufPos);
  529. sPos:=sPos+Temp-f.BufPos;
  530. If s[sPos-1]=#13 Then
  531. dec(sPos);
  532. End
  533. else
  534. Begin
  535. If (sPos<=255) Then
  536. Move(f.Bufptr^[f.BufPos],s[sPos],256-sPos);
  537. sPos:=256
  538. End;
  539. { update f.BufPos }
  540. f.BufPos:=Temp;
  541. If Temp>=f.BufEnd Then
  542. Begin
  543. FileFunc(f.InOutFunc)(f);
  544. Temp:=f.BufPos;
  545. End
  546. End;
  547. s[0]:=chr(sPos-1);
  548. End;
  549. Procedure r(var f : TextRec;var c : Char);[Public,Alias: 'READ_TEXT_CHAR'];
  550. Begin
  551. c:=#0;
  552. if not OpenInput(f) then
  553. exit;
  554. If f.BufPos>=f.BufEnd Then
  555. c:=#26
  556. else
  557. c:=f.Bufptr^[f.BufPos];
  558. Inc(f.BufPos);
  559. End;
  560. Procedure r(var f : TextRec;var s : PChar);[Public,Alias:'READ_TEXT_PCHAR_AS_POINTER'];
  561. var
  562. p : PChar;
  563. Temp : byte;
  564. Begin
  565. { Delete the string }
  566. s^:=#0;
  567. p:=s;
  568. if not OpenInput(f) then
  569. exit;
  570. Temp:=f.BufPos;
  571. while (f.BufPos<f.BufEnd) and (f.Bufptr^[Temp]<>#10) Do
  572. Begin
  573. { search linefeed }
  574. while (f.Bufptr^[Temp]<>#10) and (Temp<f.BufEnd) Do
  575. inc(Temp);
  576. { copy string. }
  577. Move (f.Bufptr^[f.BufPos],p^,Temp-f.BufPos);
  578. Inc(Longint(p),Temp-f.BufPos);
  579. If p^=#13 Then
  580. dec(Longint(p));
  581. { update f.BufPos }
  582. f.BufPos:=Temp;
  583. If Temp>=f.BufEnd Then
  584. Begin
  585. FileFunc(f.InOutFunc)(f);
  586. Temp:=f.BufPos;
  587. End
  588. End;
  589. p^:=#0;
  590. End;
  591. Procedure r(var f : TextRec;var l : Longint);[Public,Alias: 'READ_TEXT_LONGINT'];
  592. var
  593. hs : String;
  594. code : Word;
  595. base : longint;
  596. Begin
  597. l:=0;
  598. hs:='';
  599. if not OpenInput(f) then
  600. exit;
  601. if IgnoreSpaces(f) and ReadSign(f,hs) and ReadBase(f,hs,Base) then
  602. ReadNumeric(f,hs,Base);
  603. Val(hs,l,code);
  604. If code<>0 Then
  605. RunError(106);
  606. End;
  607. Procedure r(var f : TextRec;var l : Integer);[Public,Alias: 'READ_TEXT_INTEGER'];
  608. var
  609. ll : Longint;
  610. Begin
  611. r(f,ll);
  612. l:=0;
  613. If (ll<-32768) or (ll>32767) Then
  614. RunError(106);
  615. l:=ll;
  616. End;
  617. Procedure r(var f : TextRec;var l : Word);[Public,Alias: 'READ_TEXT_WORD'];
  618. var
  619. ll : Longint;
  620. Begin
  621. r(f,ll);
  622. l:=0;
  623. If (ll<0) or (ll>$ffff) Then
  624. RunError(106);
  625. l:=ll;
  626. End;
  627. Procedure r(var f : TextRec;var l : byte);[Public,Alias: 'READ_TEXT_BYTE'];
  628. var
  629. ll : Longint;
  630. Begin
  631. r(f,ll);
  632. l:=0;
  633. If (ll<0) or (ll>255) Then
  634. RunError(106);
  635. l:=ll;
  636. End;
  637. Procedure r(var f : TextRec;var l : shortint);[Public,Alias: 'READ_TEXT_SHORTINT'];
  638. var
  639. ll : Longint;
  640. Begin
  641. r(f,ll);
  642. l:=0;
  643. If (ll<-128) or (ll>127) Then
  644. RunError(106);
  645. l:=ll;
  646. End;
  647. Procedure r(var f : TextRec;var l : cardinal);[Public,Alias: 'READ_TEXT_CARDINAL'];
  648. var
  649. hs : String;
  650. code : Word;
  651. base : longint;
  652. Begin
  653. l:=0;
  654. hs:='';
  655. if not OpenInput(f) then
  656. exit;
  657. if IgnoreSpaces(f) and ReadSign(f,hs) and ReadBase(f,hs,Base) then
  658. ReadNumeric(f,hs,Base);
  659. val(hs,l,code);
  660. If code<>0 Then
  661. RunError(106);
  662. End;
  663. Procedure r(var f : TextRec;var d : Real);[Public,Alias: 'READ_TEXT_REAL'];
  664. var
  665. hs : String;
  666. code : Word;
  667. Begin
  668. d:=0.0;
  669. hs:='';
  670. if not OpenInput(f) then
  671. exit;
  672. if IgnoreSpaces(f) and ReadSign(f,hs) and ReadNumeric(f,hs,10) then
  673. begin
  674. { First check for a . }
  675. if (f.Bufptr^[f.BufPos]='.') and (f.BufPos<f.BufEnd) Then
  676. begin
  677. hs:=hs+'.';
  678. Inc(f.BufPos);
  679. If f.BufPos>=f.BufEnd Then
  680. FileFunc(f.InOutFunc)(f);
  681. ReadNumeric(f,hs,10);
  682. end;
  683. { Also when a point is found check for a E }
  684. if (f.Bufptr^[f.BufPos] in ['e','E']) and (f.BufPos<f.BufEnd) Then
  685. begin
  686. hs:=hs+'E';
  687. Inc(f.BufPos);
  688. If f.BufPos>=f.BufEnd Then
  689. FileFunc(f.InOutFunc)(f);
  690. if ReadSign(f,hs) then
  691. ReadNumeric(f,hs,10);
  692. end;
  693. end;
  694. val(hs,d,code);
  695. If code<>0 Then
  696. RunError(106);
  697. End;
  698. Procedure r(var f : TextRec;var d : extended);[Public,Alias: 'READ_TEXT_EXTENDED'];
  699. var
  700. hs : String;
  701. code : Word;
  702. Begin
  703. d:=0.0;
  704. hs:='';
  705. if not OpenInput(f) then
  706. exit;
  707. if IgnoreSpaces(f) and ReadSign(f,hs) and ReadNumeric(f,hs,10) then
  708. begin
  709. { First check for a . }
  710. if (f.Bufptr^[f.BufPos]='.') and (f.BufPos<f.BufEnd) Then
  711. begin
  712. hs:=hs+'.';
  713. Inc(f.BufPos);
  714. If f.BufPos>=f.BufEnd Then
  715. FileFunc(f.InOutFunc)(f);
  716. ReadNumeric(f,hs,10);
  717. end;
  718. { Also when a point is found check for a E }
  719. if (f.Bufptr^[f.BufPos] in ['e','E']) and (f.BufPos<f.BufEnd) Then
  720. begin
  721. hs:=hs+'E';
  722. Inc(f.BufPos);
  723. If f.BufPos>=f.BufEnd Then
  724. FileFunc(f.InOutFunc)(f);
  725. if ReadSign(f,hs) then
  726. ReadNumeric(f,hs,10);
  727. end;
  728. end;
  729. val(hs,d,code);
  730. If code<>0 Then
  731. RunError(106);
  732. End;
  733. Procedure r(var f : TextRec;var d : comp);[Public,Alias: 'READ_TEXT_COMP'];
  734. var
  735. hs : String;
  736. code : Word;
  737. Begin
  738. d:=0.0;
  739. hs:='';
  740. if not OpenInput(f) then
  741. exit;
  742. if IgnoreSpaces(f) and ReadSign(f,hs) and ReadNumeric(f,hs,10) then
  743. begin
  744. { First check for a . }
  745. if (f.Bufptr^[f.BufPos]='.') and (f.BufPos<f.BufEnd) Then
  746. begin
  747. hs:=hs+'.';
  748. Inc(f.BufPos);
  749. If f.BufPos>=f.BufEnd Then
  750. FileFunc(f.InOutFunc)(f);
  751. ReadNumeric(f,hs,10);
  752. end;
  753. { Also when a point is found check for a E }
  754. if (f.Bufptr^[f.BufPos] in ['e','E']) and (f.BufPos<f.BufEnd) Then
  755. begin
  756. hs:=hs+'E';
  757. Inc(f.BufPos);
  758. If f.BufPos>=f.BufEnd Then
  759. FileFunc(f.InOutFunc)(f);
  760. if ReadSign(f,hs) then
  761. ReadNumeric(f,hs,10);
  762. end;
  763. end;
  764. val(hs,d,code);
  765. If code<>0 Then
  766. RunError(106);
  767. End;
  768. {
  769. $Log$
  770. Revision 1.5 1998-05-12 10:42:45 peter
  771. * moved getopts to inc/, all supported OS's need argc,argv exported
  772. + strpas, strlen are now exported in the systemunit
  773. * removed logs
  774. * removed $ifdef ver_above
  775. Revision 1.4 1998/04/07 22:40:46 florian
  776. * final fix of comp writing
  777. }