sstrings.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 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. subroutines for string handling
  13. ****************************************************************************}
  14. {$I real2str.inc}
  15. function copy(const s : shortstring;index : StrLenInt;count : StrLenInt): shortstring;
  16. begin
  17. if count<0 then
  18. count:=0;
  19. if index>1 then
  20. dec(index)
  21. else
  22. index:=0;
  23. if index>length(s) then
  24. count:=0
  25. else
  26. if index+count>length(s) then
  27. count:=length(s)-index;
  28. Copy[0]:=chr(Count);
  29. Move(s[Index+1],Copy[1],Count);
  30. end;
  31. procedure delete(var s : shortstring;index : StrLenInt;count : StrLenInt);
  32. begin
  33. if index<=0 then
  34. begin
  35. inc(count,index-1);
  36. index:=1;
  37. end;
  38. if (Index<=Length(s)) and (Count>0) then
  39. begin
  40. if Count+Index>length(s) then
  41. Count:=length(s)-Index+1;
  42. s[0]:=Chr(length(s)-Count);
  43. if Index<=Length(s) then
  44. Move(s[Index+Count],s[Index],Length(s)-Index+1);
  45. end;
  46. end;
  47. procedure insert(const source : shortstring;var s : shortstring;index : StrLenInt);
  48. begin
  49. if index>1 then
  50. dec(index)
  51. else
  52. index:=0;
  53. s:=Copy(s,1,Index)+source+Copy(s,Index+1,length(s));
  54. end;
  55. function pos(const substr : shortstring;const s : shortstring):StrLenInt;
  56. var
  57. i,j : StrLenInt;
  58. e : boolean;
  59. begin
  60. i := 0;
  61. j := 0;
  62. e:=(length(SubStr)>0);
  63. while e and (i<=Length(s)-Length(SubStr)) do
  64. begin
  65. inc(i);
  66. if (SubStr[1]=s[i]) and (Substr=Copy(s,i,Length(SubStr))) then
  67. begin
  68. j:=i;
  69. e:=false;
  70. end;
  71. end;
  72. Pos:=j;
  73. end;
  74. {Faster when looking for a single char...}
  75. function pos(c:char;const s:shortstring):StrLenInt;
  76. var
  77. i : StrLenInt;
  78. begin
  79. for i:=1 to length(s) do
  80. if s[i]=c then
  81. begin
  82. pos:=i;
  83. exit;
  84. end;
  85. pos:=0;
  86. end;
  87. procedure SetLength(var s:shortstring;len:StrLenInt);
  88. begin
  89. if Len>255 then
  90. Len:=255;
  91. s[0]:=chr(len);
  92. end;
  93. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  94. begin
  95. if (index=1) and (Count>0) then
  96. Copy:=c
  97. else
  98. Copy:='';
  99. end;
  100. function pos(const substr : shortstring;c:char): StrLenInt;
  101. begin
  102. if (length(substr)=1) and (substr[1]=c) then
  103. Pos:=1
  104. else
  105. Pos:=0;
  106. end;
  107. { removed must be internal to be accepted in const expr !! PM
  108. function length(c:char):StrLenInt;
  109. begin
  110. Length:=1;
  111. end;
  112. }
  113. {$ifdef IBM_CHAR_SET}
  114. const
  115. UpCaseTbl : shortstring[7]=#154#142#153#144#128#143#165;
  116. LoCaseTbl : shortstring[7]=#129#132#148#130#135#134#164;
  117. {$endif}
  118. function upcase(c : char) : char;
  119. {$IFDEF IBM_CHAR_SET}
  120. var
  121. i : longint;
  122. {$ENDIF}
  123. begin
  124. if (c in ['a'..'z']) then
  125. upcase:=char(byte(c)-32)
  126. else
  127. {$IFDEF IBM_CHAR_SET}
  128. begin
  129. i:=Pos(c,LoCaseTbl);
  130. if i>0 then
  131. upcase:=UpCaseTbl[i]
  132. else
  133. upcase:=c;
  134. end;
  135. {$ELSE}
  136. upcase:=c;
  137. {$ENDIF}
  138. end;
  139. function upcase(const s : shortstring) : shortstring;
  140. var
  141. i : longint;
  142. begin
  143. upcase[0]:=s[0];
  144. for i := 1 to length (s) do
  145. upcase[i] := upcase (s[i]);
  146. end;
  147. {$ifndef RTLLITE}
  148. function lowercase(c : char) : char;
  149. {$IFDEF IBM_CHAR_SET}
  150. var
  151. i : longint;
  152. {$ENDIF}
  153. begin
  154. if (c in ['A'..'Z']) then
  155. lowercase:=char(byte(c)+32)
  156. else
  157. {$IFDEF IBM_CHAR_SET}
  158. begin
  159. i:=Pos(c,UpCaseTbl);
  160. if i>0 then
  161. lowercase:=LoCaseTbl[i]
  162. else
  163. lowercase:=c;
  164. end;
  165. {$ELSE}
  166. lowercase:=c;
  167. {$ENDIF}
  168. end;
  169. function lowercase(const s : shortstring) : shortstring;
  170. var
  171. i : longint;
  172. begin
  173. lowercase [0]:=s[0];
  174. for i:=1 to length(s) do
  175. lowercase[i]:=lowercase (s[i]);
  176. end;
  177. function hexstr(val : longint;cnt : byte) : shortstring;
  178. const
  179. HexTbl : array[0..15] of char='0123456789ABCDEF';
  180. var
  181. i : longint;
  182. begin
  183. hexstr[0]:=char(cnt);
  184. for i:=cnt downto 1 do
  185. begin
  186. hexstr[i]:=hextbl[val and $f];
  187. val:=val shr 4;
  188. end;
  189. end;
  190. function binstr(val : longint;cnt : byte) : shortstring;
  191. var
  192. i : longint;
  193. begin
  194. binstr[0]:=char(cnt);
  195. for i:=cnt downto 1 do
  196. begin
  197. binstr[i]:=char(48+val and 1);
  198. val:=val shr 1;
  199. end;
  200. end;
  201. {$endif RTLLITE}
  202. function space (b : byte): shortstring;
  203. begin
  204. space[0] := chr(b);
  205. FillChar (Space[1],b,' ');
  206. end;
  207. {*****************************************************************************
  208. Str() Helpers
  209. *****************************************************************************}
  210. procedure int_str_real(d : real;len,fr : longint;var s : shortstring);[public, alias : {$ifdef FPCNAMES}'FPC_STR_REAL'{$else}'STR_REAL'{$endif}];
  211. begin
  212. {$ifdef i386}
  213. str_real(len,fr,d,rt_s64real,s);
  214. {$else}
  215. str_real(len,fr,d,rt_s32real,s);
  216. {$endif}
  217. end;
  218. {$ifdef SUPPORT_SINGLE}
  219. procedure int_str_single(d : single;len,fr : longint;var s : shortstring);[public, alias : {$ifdef FPCNAMES}'FPC_STR_SINGLE'{$else}'STR_SINGLE'{$endif}];
  220. begin
  221. str_real(len,fr,d,rt_s32real,s);
  222. end;
  223. {$endif SUPPORT_SINGLE}
  224. {$ifdef SUPPORT_EXTENDED}
  225. procedure int_str_extended(d : extended;len,fr : longint;var s : shortstring);[public, alias : {$ifdef FPCNAMES}'FPC_STR_EXTENDED'{$else}'STR_EXTENDED'{$endif}];
  226. begin
  227. str_real(len,fr,d,rt_s80real,s);
  228. end;
  229. {$endif SUPPORT_EXTENDED}
  230. {$ifdef SUPPORT_COMP}
  231. procedure int_str_comp(d : comp;len,fr : longint;var s : shortstring);[public, alias : {$ifdef FPCNAMES}'FPC_STR_COMP'{$else}'STR_COMP'{$endif}];
  232. begin
  233. str_real(len,fr,d,rt_s64bit,s);
  234. end;
  235. {$endif SUPPORT_COMP}
  236. {$ifdef SUPPORT_FIXED}
  237. procedure int_str_fixed(d : fixed;len,fr : longint;var s : shortstring);[public, alias : {$ifdef FPCNAMES}'FPC_STR_FIXED'{$else}'STR_FIXED'{$endif}];
  238. begin
  239. str_real(len,fr,d,rt_f32bit,s);
  240. end;
  241. {$endif SUPPORT_FIXED}
  242. procedure int_str_longint(v : longint;len : longint;var s : shortstring);[public, alias : {$ifdef FPCNAMES}'FPC_STR_LONGINT'{$else}'STR_LONGINT'{$endif}];
  243. begin
  244. int_str(v,s);
  245. if length(s)<len then
  246. s:=space(len-length(s))+s;
  247. end;
  248. procedure int_str_cardinal(v : cardinal;len : longint;var s : shortstring);[public, alias : {$ifdef FPCNAMES}'FPC_STR_CARDINAL'{$else}'STR_CARDINAL'{$endif}];
  249. begin
  250. int_str(v,s);
  251. if length(s)<len then
  252. s:=space(len-length(s))+s;
  253. end;
  254. {*****************************************************************************
  255. Val() Functions
  256. *****************************************************************************}
  257. Function InitVal(const s:shortstring;var negativ:boolean;var base:byte):Word;
  258. var
  259. Code : Longint;
  260. begin
  261. {Skip Spaces and Tab}
  262. code:=1;
  263. while (code<=length(s)) and (s[code] in [' ',#9]) do
  264. inc(code);
  265. {Sign}
  266. negativ:=false;
  267. case s[code] of
  268. '-' : begin
  269. negativ:=true;
  270. inc(code);
  271. end;
  272. '+' : inc(code);
  273. end;
  274. {Base}
  275. base:=10;
  276. if code<=length(s) then
  277. begin
  278. case s[code] of
  279. '$' : begin
  280. base:=16;
  281. repeat
  282. inc(code);
  283. until (code>=length(s)) or (s[code]<>'0');
  284. if length(s)-code>7 then
  285. code:=code+8;
  286. end;
  287. '%' : begin
  288. base:=2;
  289. inc(code);
  290. end;
  291. end;
  292. end;
  293. InitVal:=code;
  294. end;
  295. procedure val(const s : shortstring;var l : longint;var code : word);
  296. var
  297. base,u : byte;
  298. negativ : boolean;
  299. begin
  300. l:=0;
  301. Code:=InitVal(s,negativ,base);
  302. if Code>length(s) then
  303. exit;
  304. if negativ and (s='-2147483648') then
  305. begin
  306. Code:=0;
  307. l:=$80000000;
  308. exit;
  309. end;
  310. while Code<=Length(s) do
  311. begin
  312. u:=ord(s[code]);
  313. case u of
  314. 48..57 : u:=u-48;
  315. 65..70 : u:=u-55;
  316. 97..104 : u:=u-87;
  317. else
  318. u:=16;
  319. end;
  320. l:=l*longint(base);
  321. if (u>=base) or ((base=10) and (2147483647-l<longint(u))) then
  322. begin
  323. l:=0;
  324. exit;
  325. end;
  326. l:=l+u;
  327. inc(code);
  328. end;
  329. code := 0;
  330. if negativ then
  331. l:=0-l;
  332. end;
  333. procedure val(const s : shortstring;var l : longint;var code : integer);
  334. begin
  335. val(s,l,word(code));
  336. end;
  337. procedure val(const s : shortstring;var l : longint;var code : longint);
  338. var
  339. cw : word;
  340. begin
  341. val (s,l,cw);
  342. code:=cw;
  343. end;
  344. procedure val(const s : shortstring;var l : longint);
  345. var
  346. code : word;
  347. begin
  348. val (s,l,code);
  349. end;
  350. procedure val(const s : shortstring;var b : byte);
  351. var
  352. l : longint;
  353. begin
  354. val(s,l);
  355. b:=l;
  356. end;
  357. procedure val(const s : shortstring;var b : byte;var code : word);
  358. var
  359. l : longint;
  360. begin
  361. val(s,l,code);
  362. b:=l;
  363. end;
  364. procedure val(const s : shortstring;var b : byte;var code : Integer);
  365. begin
  366. val(s,b,word(code));
  367. end;
  368. procedure val(const s : shortstring;var b : byte;var code : longint);
  369. var
  370. l : longint;
  371. begin
  372. val(s,l,code);
  373. b:=l;
  374. end;
  375. procedure val(const s : shortstring;var b : shortint);
  376. var
  377. l : longint;
  378. begin
  379. val(s,l);
  380. b:=l;
  381. end;
  382. procedure val(const s : shortstring;var b : shortint;var code : word);
  383. var
  384. l : longint;
  385. begin
  386. val(s,l,code);
  387. b:=l;
  388. end;
  389. procedure val(const s : shortstring;var b : shortint;var code : Integer);
  390. begin
  391. val(s,b,word(code));
  392. end;
  393. procedure val(const s : shortstring;var b : shortint;var code : longint);
  394. var
  395. l : longint;
  396. begin
  397. val(s,l,code);
  398. b:=l;
  399. end;
  400. procedure val(const s : shortstring;var b : word);
  401. var
  402. l : longint;
  403. begin
  404. val(s,l);
  405. b:=l;
  406. end;
  407. procedure val(const s : shortstring;var b : word;var code : word);
  408. var
  409. l : longint;
  410. begin
  411. val(s,l,code);
  412. b:=l;
  413. end;
  414. procedure val(const s : shortstring;var b : word;var code : Integer);
  415. begin
  416. val(s,b,word(code));
  417. end;
  418. procedure val(const s : shortstring;var b : word;var code : longint);
  419. var
  420. l : longint;
  421. begin
  422. val(s,l,code);
  423. b:=l;
  424. end;
  425. procedure val(const s : shortstring;var b : integer);
  426. var
  427. l : longint;
  428. begin
  429. val(s,l);
  430. b:=l;
  431. end;
  432. procedure val(const s : shortstring;var b : integer;var code : word);
  433. var
  434. l : longint;
  435. begin
  436. val(s,l,code);
  437. b:=l;
  438. end;
  439. procedure val(const s : shortstring;var b : integer;var code : Integer);
  440. begin
  441. val(s,b,word(code));
  442. end;
  443. procedure val(const s : shortstring;var b : integer;var code : longint);
  444. var
  445. l : longint;
  446. begin
  447. val(s,l,code);
  448. b:=l;
  449. end;
  450. procedure val(const s : shortstring;var v : cardinal;var code : word);
  451. var
  452. negativ : boolean;
  453. base,u : byte;
  454. begin
  455. v:=0;
  456. code:=InitVal(s,negativ,base);
  457. if (Code>length(s)) or negativ then
  458. exit;
  459. while Code<=Length(s) do
  460. begin
  461. u:=ord(s[code]);
  462. case u of
  463. 48..57 : u:=u-48;
  464. 65..70 : u:=u-55;
  465. 97..104 : u:=u-87;
  466. else
  467. u:=16;
  468. end;
  469. cardinal(v):=cardinal(v)*cardinal(longint(base));
  470. if (u>base) or (cardinal($ffffffff)-cardinal(v)>cardinal(longint(u))) then
  471. begin
  472. v:=0;
  473. exit;
  474. end;
  475. v:=v+u;
  476. inc(code);
  477. end;
  478. code:=0;
  479. end;
  480. procedure val(const s : shortstring;var v : cardinal);
  481. var
  482. code : word;
  483. begin
  484. val(s,v,code);
  485. end;
  486. procedure val(const s : shortstring;var v : cardinal;var code : integer);
  487. begin
  488. val(s,v,word(code));
  489. end;
  490. procedure val(const s : shortstring;var v : cardinal;var code : longint);
  491. var
  492. cw : word;
  493. begin
  494. val(s,v,cw);
  495. code:=cw;
  496. end;
  497. procedure val(const s : shortstring;var d : valreal;var code : word);
  498. var
  499. hd,
  500. esign,sign : valreal;
  501. exponent,i : longint;
  502. flags : byte;
  503. begin
  504. d:=0;
  505. code:=1;
  506. exponent:=0;
  507. esign:=1;
  508. flags:=0;
  509. sign:=1;
  510. while (code<=length(s)) and (s[code] in [' ',#9]) do
  511. inc(code);
  512. case s[code] of
  513. '+' : inc(code);
  514. '-' : begin
  515. sign:=-1.0;
  516. inc(code);
  517. end;
  518. end;
  519. while (Code<=Length(s)) and (s[code] in ['0'..'9']) do
  520. begin
  521. { Read integer part }
  522. flags:=flags or 1;
  523. d:=d*10;
  524. d:=d+(ord(s[code])-ord('0'));
  525. inc(code);
  526. end;
  527. { Decimal ? }
  528. if (s[code]='.') and (length(s)>=code) then
  529. begin
  530. hd:=0.1;
  531. inc(code);
  532. { After dot, a number is required. }
  533. if not(s[code] in ['0'..'9']) or (length(s)<code) then
  534. begin
  535. d:=0.0;
  536. exit;
  537. end;
  538. while (s[code] in ['0'..'9']) and (length(s)>=code) do
  539. begin
  540. { Read fractional part. }
  541. flags:=flags or 2;
  542. d:=d+hd*(ord(s[code])-ord('0'));
  543. hd:=hd/10.0;
  544. inc(code);
  545. end;
  546. end;
  547. { Again, read integer and fractional part}
  548. if flags=0 then
  549. begin
  550. d:=0.0;
  551. exit;
  552. end;
  553. { Exponent ? }
  554. if (upcase(s[code])='E') and (length(s)>=code) then
  555. begin
  556. inc(code);
  557. if s[code]='+' then
  558. inc(code)
  559. else
  560. if s[code]='-' then
  561. begin
  562. esign:=-1;
  563. inc(code);
  564. end;
  565. if not(s[code] in ['0'..'9']) or (length(s)<code) then
  566. begin
  567. d:=0.0;
  568. exit;
  569. end;
  570. while (s[code] in ['0'..'9']) and (length(s)>=code) do
  571. begin
  572. exponent:=exponent*10;
  573. exponent:=exponent+ord(s[code])-ord('0');
  574. inc(code);
  575. end;
  576. end;
  577. { Calculate Exponent }
  578. if esign>0 then
  579. for i:=1 to exponent do
  580. d:=d*10
  581. else
  582. for i:=1 to exponent do
  583. d:=d/10;
  584. { Not all characters are read ? }
  585. if length(s)>=code then
  586. begin
  587. d:=0.0;
  588. exit;
  589. end;
  590. { evalute sign }
  591. d:=d*sign;
  592. { success ! }
  593. code:=0;
  594. end;
  595. procedure val(const s : shortstring;var d : valreal;var code : integer);
  596. begin
  597. val(s,d,word(code));
  598. end;
  599. procedure val(const s : shortstring;var d : valreal;var code : longint);
  600. var
  601. cw : word;
  602. begin
  603. val(s,d,cw);
  604. code:=cw;
  605. end;
  606. procedure val(const s : shortstring;var d : valreal);
  607. var
  608. code : word;
  609. begin
  610. val(s,d,code);
  611. end;
  612. {$ifdef SUPPORT_SINGLE}
  613. procedure val(const s : shortstring;var d : single;var code : word);
  614. var
  615. e : valreal;
  616. begin
  617. val(s,e,code);
  618. d:=e;
  619. end;
  620. procedure val(const s : shortstring;var d : single;var code : integer);
  621. var
  622. e : valreal;
  623. begin
  624. val(s,e,word(code));
  625. d:=e;
  626. end;
  627. procedure val(const s : shortstring;var d : single;var code : longint);
  628. var
  629. cw : word;
  630. e : valreal;
  631. begin
  632. val(s,e,cw);
  633. d:=e;
  634. code:=cw;
  635. end;
  636. procedure val(const s : shortstring;var d : single);
  637. var
  638. code : word;
  639. e : valreal;
  640. begin
  641. val(s,e,code);
  642. d:=e;
  643. end;
  644. {$endif SUPPORT_SINGLE}
  645. {$ifdef DEFAULT_EXTENDED}
  646. { with extended as default the valreal is extended so for real there need
  647. to be a new val }
  648. procedure val(const s : shortstring;var d : real;var code : word);
  649. var
  650. e : valreal;
  651. begin
  652. val(s,e,code);
  653. d:=e;
  654. end;
  655. procedure val(const s : shortstring;var d : real;var code : integer);
  656. var
  657. e : valreal;
  658. begin
  659. val(s,e,word(code));
  660. d:=e;
  661. end;
  662. procedure val(const s : shortstring;var d : real;var code : longint);
  663. var
  664. cw : word;
  665. e : valreal;
  666. begin
  667. val(s,e,cw);
  668. d:=e;
  669. code:=cw;
  670. end;
  671. procedure val(const s : shortstring;var d : real);
  672. var
  673. code : word;
  674. e : valreal;
  675. begin
  676. val(s,e,code);
  677. d:=e;
  678. end;
  679. {$else DEFAULT_EXTENDED}
  680. { when extended is not the default it could still be supported }
  681. {$ifdef SUPPORT_EXTENDED}
  682. procedure val(const s : shortstring;var d : extended;var code : word);
  683. var
  684. e : valreal;
  685. begin
  686. val(s,e,code);
  687. d:=e;
  688. end;
  689. procedure val(const s : shortstring;var d : extended;var code : integer);
  690. var
  691. e : valreal;
  692. begin
  693. val(s,e,word(code));
  694. d:=e;
  695. end;
  696. procedure val(const s : shortstring;var d : extended;var code : longint);
  697. var
  698. cw : word;
  699. e : valreal;
  700. begin
  701. val(s,e,cw);
  702. d:=e;
  703. code:=cw;
  704. end;
  705. procedure val(const s : shortstring;var d : extended);
  706. var
  707. code : word;
  708. e : valreal;
  709. begin
  710. val(s,e,code);
  711. d:=e;
  712. end;
  713. {$endif SUPPORT_EXTENDED}
  714. {$endif DEFAULT_EXTENDED}
  715. {$ifdef SUPPORT_COMP}
  716. procedure val(const s : shortstring;var d : comp;var code : word);
  717. var
  718. e : valreal;
  719. begin
  720. val(s,e,code);
  721. d:=comp(e);
  722. end;
  723. procedure val(const s : shortstring;var d : comp;var code : integer);
  724. var
  725. e : valreal;
  726. begin
  727. val(s,e,word(code));
  728. d:=comp(e);
  729. end;
  730. procedure val(const s : shortstring;var d : comp;var code : longint);
  731. var
  732. cw : word;
  733. e : valreal;
  734. begin
  735. val(s,e,cw);
  736. d:=comp(e);
  737. code:=cw;
  738. end;
  739. procedure val(const s : shortstring;var d : comp);
  740. var
  741. code : word;
  742. e : valreal;
  743. begin
  744. val(s,e,code);
  745. d:=comp(e);
  746. end;
  747. {$endif SUPPORT_COMP}
  748. {$ifdef SUPPORT_FIXED}
  749. procedure val(const s : shortstring;var d : fixed;var code : word);
  750. var
  751. e : valreal;
  752. begin
  753. val(s,e,code);
  754. d:=fixed(e);
  755. end;
  756. procedure val(const s : shortstring;var d : fixed;var code : integer);
  757. var
  758. e : valreal;
  759. begin
  760. val(s,e,word(code));
  761. d:=fixed(e);
  762. end;
  763. procedure val(const s : shortstring;var d : fixed;var code : longint);
  764. var
  765. cw : word;
  766. e : valreal;
  767. begin
  768. val(s,e,cw);
  769. d:=fixed(e);
  770. code:=cw;
  771. end;
  772. procedure val(const s : shortstring;var d : fixed);
  773. var
  774. code : word;
  775. e : valreal;
  776. begin
  777. val(s,e,code);
  778. d:=fixed(e);
  779. end;
  780. {$endif SUPPORT_FIXED}
  781. {
  782. $Log$
  783. Revision 1.16 1998-11-05 10:29:34 pierre
  784. * fix for length(char) in const expressions
  785. Revision 1.15 1998/11/04 10:20:50 peter
  786. * ansistring fixes
  787. Revision 1.14 1998/10/11 14:30:19 peter
  788. * small typo :(
  789. Revision 1.13 1998/10/10 15:28:46 peter
  790. + read single,fixed
  791. + val with code:longint
  792. + val for fixed
  793. Revision 1.12 1998/09/14 10:48:19 peter
  794. * FPC_ names
  795. * Heap manager is now system independent
  796. Revision 1.11 1998/08/11 21:39:07 peter
  797. * splitted default_extended from support_extended
  798. Revision 1.10 1998/08/08 12:28:13 florian
  799. * a lot small fixes to the extended data type work
  800. Revision 1.9 1998/07/18 17:14:23 florian
  801. * strlenint type implemented
  802. Revision 1.8 1998/07/10 11:02:38 peter
  803. * support_fixed, becuase fixed is not 100% yet for the m68k
  804. Revision 1.7 1998/07/02 12:14:19 carl
  805. * No SINGLE type for non-intel processors!!
  806. Revision 1.6 1998/06/25 09:44:19 daniel
  807. + RTLLITE directive to compile minimal RTL.
  808. Revision 1.5 1998/06/04 23:45:59 peter
  809. * comp,extended are only i386 added support_comp,support_extended
  810. Revision 1.4 1998/05/31 14:14:52 peter
  811. * removed warnings using comp()
  812. Revision 1.3 1998/05/12 10:42:45 peter
  813. * moved getopts to inc/, all supported OS's need argc,argv exported
  814. + strpas, strlen are now exported in the systemunit
  815. * removed logs
  816. * removed $ifdef ver_above
  817. }