sstrings.inc 19 KB

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