ppu.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Routines to read/write ppu files
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ppu;
  19. {$i defines.inc}
  20. interface
  21. { Also write the ppu if only crc if done, this can be used with ppudump to
  22. see the differences between the intf and implementation }
  23. { define INTFPPU}
  24. {$ifdef Test_Double_checksum}
  25. var
  26. CRCFile : text;
  27. const
  28. CRC_array_Size = 200000;
  29. type
  30. tcrc_array = array[0..crc_array_size] of longint;
  31. pcrc_array = ^tcrc_array;
  32. {$endif Test_Double_checksum}
  33. const
  34. {$ifdef newcg}
  35. CurrentPPUVersion=102;
  36. {$else newcg}
  37. CurrentPPUVersion=22;
  38. {$endif newcg}
  39. { buffer sizes }
  40. maxentrysize = 1024;
  41. ppubufsize = 16384;
  42. {ppu entries}
  43. mainentryid = 1;
  44. subentryid = 2;
  45. {special}
  46. iberror = 0;
  47. ibstartdefs = 248;
  48. ibenddefs = 249;
  49. ibstartsyms = 250;
  50. ibendsyms = 251;
  51. ibendinterface = 252;
  52. ibendimplementation = 253;
  53. ibendbrowser = 254;
  54. ibend = 255;
  55. {general}
  56. ibmodulename = 1;
  57. ibsourcefiles = 2;
  58. ibloadunit = 3;
  59. ibinitunit = 4;
  60. iblinkunitofiles = 5;
  61. iblinkunitstaticlibs = 6;
  62. iblinkunitsharedlibs = 7;
  63. iblinkotherofiles = 8;
  64. iblinkotherstaticlibs = 9;
  65. iblinkothersharedlibs = 10;
  66. ibdbxcount = 11;
  67. ibsymref = 12;
  68. ibdefref = 13;
  69. ibendsymtablebrowser = 14;
  70. ibbeginsymtablebrowser = 15;
  71. ibusedmacros = 16;
  72. {syms}
  73. ibtypesym = 20;
  74. ibprocsym = 21;
  75. ibvarsym = 22;
  76. ibconstsym = 23;
  77. ibenumsym = 24;
  78. ibtypedconstsym = 25;
  79. ibabsolutesym = 26;
  80. ibpropertysym = 27;
  81. ibvarsym_C = 28;
  82. ibunitsym = 29; { needed for browser }
  83. iblabelsym = 30;
  84. ibfuncretsym = 31;
  85. ibsyssym = 32;
  86. {definitions}
  87. iborddef = 40;
  88. ibpointerdef = 41;
  89. ibarraydef = 42;
  90. ibprocdef = 43;
  91. ibshortstringdef = 44;
  92. ibrecorddef = 45;
  93. ibfiledef = 46;
  94. ibformaldef = 47;
  95. ibobjectdef = 48;
  96. ibenumdef = 49;
  97. ibsetdef = 50;
  98. ibprocvardef = 51;
  99. ibfloatdef = 52;
  100. ibclassrefdef = 53;
  101. iblongstringdef = 54;
  102. ibansistringdef = 55;
  103. ibwidestringdef = 56;
  104. { unit flags }
  105. uf_init = $1;
  106. uf_finalize = $2;
  107. uf_big_endian = $4;
  108. uf_has_dbx = $8;
  109. uf_has_browser = $10;
  110. uf_in_library = $20; { is the file in another file than <ppufile>.* ? }
  111. uf_smart_linked = $40; { the ppu can be smartlinked }
  112. uf_static_linked = $80; { the ppu can be linked static }
  113. uf_shared_linked = $100; { the ppu can be linked shared }
  114. uf_local_browser = $200;
  115. uf_no_link = $400; { unit has no .o generated, but can still have
  116. external linking! }
  117. uf_has_resources = $800; { unit has resource section }
  118. type
  119. {$ifdef m68k}
  120. ppureal=single;
  121. {$else}
  122. ppureal=extended;
  123. {$endif}
  124. tppuerror=(ppuentrytoobig,ppuentryerror);
  125. tppuheader=packed record { 40 bytes }
  126. id : array[1..3] of char; { = 'PPU' }
  127. ver : array[1..3] of char;
  128. compiler : word;
  129. cpu : word;
  130. target : word;
  131. flags : longint;
  132. size : longint; { size of the ppufile without header }
  133. checksum : longint; { checksum for this ppufile }
  134. interface_checksum : longint;
  135. future : array[0..2] of longint;
  136. end;
  137. tppuentry=packed record
  138. id : byte;
  139. nr : byte;
  140. size : longint;
  141. end;
  142. pppufile=^tppufile;
  143. tppufile=object
  144. f : file;
  145. mode : byte; {0 - Closed, 1 - Reading, 2 - Writing}
  146. error : boolean;
  147. fname : string;
  148. fsize : longint;
  149. header : tppuheader;
  150. size,crc : longint;
  151. {$ifdef Test_Double_checksum}
  152. crcindex : longint;
  153. crc_index : longint;
  154. crcindex2 : longint;
  155. crc_index2 : longint;
  156. crc_test,crc_test2 : pcrc_array;
  157. {$endif def Test_Double_checksum}
  158. interface_crc : longint;
  159. do_interface_crc : boolean;
  160. crc_only : boolean; { used to calculate interface_crc before implementation }
  161. do_crc,
  162. change_endian : boolean;
  163. buf : pchar;
  164. bufstart,
  165. bufsize,
  166. bufidx : longint;
  167. entrybufstart,
  168. entrystart,
  169. entryidx : longint;
  170. entry : tppuentry;
  171. entrytyp : byte;
  172. closed,
  173. tempclosed : boolean;
  174. closepos : longint;
  175. constructor init(fn:string);
  176. destructor done;
  177. procedure flush;
  178. procedure close;
  179. function CheckPPUId:boolean;
  180. function GetPPUVersion:longint;
  181. procedure NewHeader;
  182. procedure NewEntry;
  183. {read}
  184. function open:boolean;
  185. procedure reloadbuf;
  186. procedure readdata(var b;len:longint);
  187. procedure skipdata(len:longint);
  188. function readentry:byte;
  189. function EndOfEntry:boolean;
  190. procedure getdatabuf(var b;len:longint;var result:longint);
  191. procedure getdata(var b;len:longint);
  192. function getbyte:byte;
  193. function getword:word;
  194. function getlongint:longint;
  195. function getreal:ppureal;
  196. function getstring:string;
  197. procedure getnormalset(var b);
  198. procedure getsmallset(var b);
  199. function skipuntilentry(untilb:byte):boolean;
  200. {write}
  201. function create:boolean;
  202. procedure writeheader;
  203. procedure writebuf;
  204. procedure writedata(var b;len:longint);
  205. procedure writeentry(ibnr:byte);
  206. procedure putdata(var b;len:longint);
  207. procedure putbyte(b:byte);
  208. procedure putword(w:word);
  209. procedure putlongint(l:longint);
  210. procedure putreal(d:ppureal);
  211. procedure putstring(s:string);
  212. procedure putnormalset(var b);
  213. procedure putsmallset(var b);
  214. procedure tempclose;
  215. function tempopen:boolean;
  216. end;
  217. implementation
  218. uses
  219. {$ifdef Test_Double_checksum}
  220. comphook,
  221. {$endif def Test_Double_checksum}
  222. crc;
  223. {*****************************************************************************
  224. TPPUFile
  225. *****************************************************************************}
  226. constructor tppufile.init(fn:string);
  227. begin
  228. fname:=fn;
  229. change_endian:=false;
  230. crc_only:=false;
  231. Mode:=0;
  232. NewHeader;
  233. Error:=false;
  234. closed:=true;
  235. tempclosed:=false;
  236. getmem(buf,ppubufsize);
  237. end;
  238. destructor tppufile.done;
  239. begin
  240. close;
  241. if assigned(buf) then
  242. freemem(buf,ppubufsize);
  243. end;
  244. procedure tppufile.flush;
  245. begin
  246. if Mode=2 then
  247. writebuf;
  248. end;
  249. procedure tppufile.close;
  250. begin
  251. if Mode<>0 then
  252. begin
  253. Flush;
  254. {$I-}
  255. system.close(f);
  256. {$I+}
  257. if ioresult<>0 then;
  258. Mode:=0;
  259. closed:=true;
  260. end;
  261. end;
  262. function tppufile.CheckPPUId:boolean;
  263. begin
  264. CheckPPUId:=((Header.Id[1]='P') and (Header.Id[2]='P') and (Header.Id[3]='U'));
  265. end;
  266. function tppufile.GetPPUVersion:longint;
  267. var
  268. l : longint;
  269. code : integer;
  270. begin
  271. Val(header.ver[1]+header.ver[2]+header.ver[3],l,code);
  272. if code=0 then
  273. GetPPUVersion:=l
  274. else
  275. GetPPUVersion:=0;
  276. end;
  277. procedure tppufile.NewHeader;
  278. var
  279. s : string;
  280. begin
  281. fillchar(header,sizeof(tppuheader),0);
  282. str(currentppuversion,s);
  283. while length(s)<3 do
  284. s:='0'+s;
  285. with header do
  286. begin
  287. Id[1]:='P';
  288. Id[2]:='P';
  289. Id[3]:='U';
  290. Ver[1]:=s[1];
  291. Ver[2]:=s[2];
  292. Ver[3]:=s[3];
  293. end;
  294. end;
  295. {*****************************************************************************
  296. TPPUFile Reading
  297. *****************************************************************************}
  298. function tppufile.open:boolean;
  299. var
  300. ofmode : byte;
  301. i : longint;
  302. begin
  303. open:=false;
  304. assign(f,fname);
  305. ofmode:=filemode;
  306. filemode:=$0;
  307. {$I-}
  308. reset(f,1);
  309. {$I+}
  310. filemode:=ofmode;
  311. if ioresult<>0 then
  312. exit;
  313. closed:=false;
  314. {read ppuheader}
  315. fsize:=filesize(f);
  316. if fsize<sizeof(tppuheader) then
  317. exit;
  318. blockread(f,header,sizeof(tppuheader),i);
  319. {reset buffer}
  320. bufstart:=i;
  321. bufsize:=0;
  322. bufidx:=0;
  323. Mode:=1;
  324. FillChar(entry,sizeof(tppuentry),0);
  325. entryidx:=0;
  326. entrystart:=0;
  327. entrybufstart:=0;
  328. Error:=false;
  329. open:=true;
  330. end;
  331. procedure tppufile.reloadbuf;
  332. begin
  333. inc(bufstart,bufsize);
  334. blockread(f,buf^,ppubufsize,bufsize);
  335. bufidx:=0;
  336. end;
  337. procedure tppufile.readdata(var b;len:longint);
  338. var
  339. p : pchar;
  340. left,
  341. idx : longint;
  342. begin
  343. p:=pchar(@b);
  344. idx:=0;
  345. while len>0 do
  346. begin
  347. left:=bufsize-bufidx;
  348. if len>left then
  349. begin
  350. move(buf[bufidx],p[idx],left);
  351. dec(len,left);
  352. inc(idx,left);
  353. reloadbuf;
  354. if bufsize=0 then
  355. exit;
  356. end
  357. else
  358. begin
  359. move(buf[bufidx],p[idx],len);
  360. inc(bufidx,len);
  361. exit;
  362. end;
  363. end;
  364. end;
  365. procedure tppufile.skipdata(len:longint);
  366. var
  367. left : longint;
  368. begin
  369. while len>0 do
  370. begin
  371. left:=bufsize-bufidx;
  372. if len>left then
  373. begin
  374. dec(len,left);
  375. reloadbuf;
  376. if bufsize=0 then
  377. exit;
  378. end
  379. else
  380. begin
  381. inc(bufidx,len);
  382. exit;
  383. end;
  384. end;
  385. end;
  386. function tppufile.readentry:byte;
  387. begin
  388. if entryidx<entry.size then
  389. skipdata(entry.size-entryidx);
  390. readdata(entry,sizeof(tppuentry));
  391. entrystart:=bufstart+bufidx;
  392. entryidx:=0;
  393. if not(entry.id in [mainentryid,subentryid]) then
  394. begin
  395. readentry:=iberror;
  396. error:=true;
  397. exit;
  398. end;
  399. readentry:=entry.nr;
  400. end;
  401. function tppufile.endofentry:boolean;
  402. begin
  403. endofentry:=(entryidx>=entry.size);
  404. end;
  405. procedure tppufile.getdatabuf(var b;len:longint;var result:longint);
  406. begin
  407. if entryidx+len>entry.size then
  408. result:=entry.size-entryidx
  409. else
  410. result:=len;
  411. readdata(b,result);
  412. inc(entryidx,result);
  413. end;
  414. procedure tppufile.getdata(var b;len:longint);
  415. begin
  416. if entryidx+len>entry.size then
  417. begin
  418. error:=true;
  419. exit;
  420. end;
  421. readdata(b,len);
  422. inc(entryidx,len);
  423. end;
  424. function tppufile.getbyte:byte;
  425. var
  426. b : byte;
  427. begin
  428. if entryidx+1>entry.size then
  429. begin
  430. error:=true;
  431. getbyte:=0;
  432. exit;
  433. end;
  434. readdata(b,1);
  435. getbyte:=b;
  436. inc(entryidx);
  437. end;
  438. function tppufile.getword:word;
  439. type
  440. pword = ^word;
  441. var
  442. w : word;
  443. begin
  444. if entryidx+2>entry.size then
  445. begin
  446. error:=true;
  447. getword:=0;
  448. exit;
  449. end;
  450. readdata(w,2);
  451. if change_endian then
  452. getword:=swap(w)
  453. else
  454. getword:=w;
  455. inc(entryidx,2);
  456. end;
  457. function tppufile.getlongint:longint;
  458. type
  459. plongint = ^longint;
  460. var
  461. l : longint;
  462. begin
  463. if entryidx+4>entry.size then
  464. begin
  465. error:=true;
  466. getlongint:=0;
  467. exit;
  468. end;
  469. readdata(l,4);
  470. if change_endian then
  471. { someone added swap(l : longint) in system unit
  472. this broke the following code !! }
  473. getlongint:=swap(word(l shr 16)) or (longint(swap(word(l and $ffff))) shl 16)
  474. else
  475. getlongint:=l;
  476. inc(entryidx,4);
  477. end;
  478. function tppufile.getreal:ppureal;
  479. type
  480. pppureal = ^ppureal;
  481. var
  482. d : ppureal;
  483. begin
  484. if entryidx+sizeof(ppureal)>entry.size then
  485. begin
  486. error:=true;
  487. getreal:=0;
  488. exit;
  489. end;
  490. readdata(d,sizeof(ppureal));
  491. getreal:=d;
  492. inc(entryidx,sizeof(ppureal));
  493. end;
  494. function tppufile.getstring:string;
  495. var
  496. s : string;
  497. begin
  498. s[0]:=chr(getbyte);
  499. if entryidx+length(s)>entry.size then
  500. begin
  501. error:=true;
  502. exit;
  503. end;
  504. ReadData(s[1],length(s));
  505. getstring:=s;
  506. inc(entryidx,length(s));
  507. end;
  508. procedure tppufile.getsmallset(var b);
  509. begin
  510. getdata(b,4);
  511. end;
  512. procedure tppufile.getnormalset(var b);
  513. begin
  514. getdata(b,32);
  515. end;
  516. function tppufile.skipuntilentry(untilb:byte):boolean;
  517. var
  518. b : byte;
  519. begin
  520. repeat
  521. b:=readentry;
  522. until (b in [ibend,iberror]) or ((b=untilb) and (entry.id=mainentryid));
  523. skipuntilentry:=(b=untilb);
  524. end;
  525. {*****************************************************************************
  526. TPPUFile Writing
  527. *****************************************************************************}
  528. function tppufile.create:boolean;
  529. begin
  530. create:=false;
  531. {$ifdef INTFPPU}
  532. if crc_only then
  533. begin
  534. fname:=fname+'.intf';
  535. crc_only:=false;
  536. end;
  537. {$endif}
  538. if not crc_only then
  539. begin
  540. assign(f,fname);
  541. {$I-}
  542. rewrite(f,1);
  543. {$I+}
  544. if ioresult<>0 then
  545. exit;
  546. Mode:=2;
  547. {write header for sure}
  548. blockwrite(f,header,sizeof(tppuheader));
  549. end;
  550. bufsize:=ppubufsize;
  551. bufstart:=sizeof(tppuheader);
  552. bufidx:=0;
  553. {reset}
  554. crc:=longint($ffffffff);
  555. interface_crc:=longint($ffffffff);
  556. do_interface_crc:=true;
  557. Error:=false;
  558. do_crc:=true;
  559. size:=0;
  560. entrytyp:=mainentryid;
  561. {start}
  562. NewEntry;
  563. create:=true;
  564. end;
  565. procedure tppufile.writeheader;
  566. var
  567. opos : longint;
  568. begin
  569. { flush buffer }
  570. writebuf;
  571. { update size (w/o header!) in the header }
  572. header.size:=bufstart-sizeof(tppuheader);
  573. { write header and restore filepos after it }
  574. opos:=filepos(f);
  575. seek(f,0);
  576. blockwrite(f,header,sizeof(tppuheader));
  577. seek(f,opos);
  578. end;
  579. procedure tppufile.writebuf;
  580. begin
  581. if not crc_only then
  582. blockwrite(f,buf^,bufidx);
  583. inc(bufstart,bufidx);
  584. bufidx:=0;
  585. end;
  586. procedure tppufile.writedata(var b;len:longint);
  587. var
  588. p : pchar;
  589. left,
  590. idx : longint;
  591. begin
  592. if crc_only then
  593. exit;
  594. p:=pchar(@b);
  595. idx:=0;
  596. while len>0 do
  597. begin
  598. left:=bufsize-bufidx;
  599. if len>left then
  600. begin
  601. move(p[idx],buf[bufidx],left);
  602. dec(len,left);
  603. inc(idx,left);
  604. inc(bufidx,left);
  605. writebuf;
  606. end
  607. else
  608. begin
  609. move(p[idx],buf[bufidx],len);
  610. inc(bufidx,len);
  611. exit;
  612. end;
  613. end;
  614. end;
  615. procedure tppufile.NewEntry;
  616. begin
  617. with entry do
  618. begin
  619. id:=entrytyp;
  620. nr:=ibend;
  621. size:=0;
  622. end;
  623. {Reset Entry State}
  624. entryidx:=0;
  625. entrybufstart:=bufstart;
  626. entrystart:=bufstart+bufidx;
  627. {Alloc in buffer}
  628. writedata(entry,sizeof(tppuentry));
  629. end;
  630. procedure tppufile.writeentry(ibnr:byte);
  631. var
  632. opos : longint;
  633. begin
  634. {create entry}
  635. entry.id:=entrytyp;
  636. entry.nr:=ibnr;
  637. entry.size:=entryidx;
  638. {it's already been sent to disk ?}
  639. if entrybufstart<>bufstart then
  640. begin
  641. if not crc_only then
  642. begin
  643. {flush to be sure}
  644. WriteBuf;
  645. {write entry}
  646. opos:=filepos(f);
  647. seek(f,entrystart);
  648. blockwrite(f,entry,sizeof(tppuentry));
  649. seek(f,opos);
  650. end;
  651. entrybufstart:=bufstart;
  652. end
  653. else
  654. move(entry,buf[entrystart-bufstart],sizeof(entry));
  655. {Add New Entry, which is ibend by default}
  656. entrystart:=bufstart+bufidx; {next entry position}
  657. NewEntry;
  658. end;
  659. procedure tppufile.putdata(var b;len:longint);
  660. begin
  661. if do_crc then
  662. begin
  663. crc:=UpdateCrc32(crc,b,len);
  664. {$ifdef Test_Double_checksum}
  665. if crc_only then
  666. begin
  667. crc_test2^[crc_index2]:=crc;
  668. {$ifdef Test_Double_checksum_write}
  669. Writeln(CRCFile,crc);
  670. {$endif Test_Double_checksum_write}
  671. if crc_index2<crc_array_size then
  672. inc(crc_index2);
  673. end
  674. else
  675. begin
  676. if (crcindex2<crc_array_size) and (crcindex2<crc_index2) and
  677. (crc_test2^[crcindex2]<>crc) then
  678. Do_comment(V_Warning,'impl CRC changed');
  679. {$ifdef Test_Double_checksum_write}
  680. Writeln(CRCFile,crc);
  681. {$endif Test_Double_checksum_write}
  682. inc(crcindex2);
  683. end;
  684. {$endif def Test_Double_checksum}
  685. if do_interface_crc then
  686. begin
  687. interface_crc:=UpdateCrc32(interface_crc,b,len);
  688. {$ifdef Test_Double_checksum}
  689. if crc_only then
  690. begin
  691. crc_test^[crc_index]:=interface_crc;
  692. {$ifdef Test_Double_checksum_write}
  693. Writeln(CRCFile,interface_crc);
  694. {$endif Test_Double_checksum_write}
  695. if crc_index<crc_array_size then
  696. inc(crc_index);
  697. end
  698. else
  699. begin
  700. if (crcindex<crc_array_size) and (crcindex<crc_index) and
  701. (crc_test^[crcindex]<>interface_crc) then
  702. Do_comment(V_Warning,'CRC changed');
  703. {$ifdef Test_Double_checksum_write}
  704. Writeln(CRCFile,interface_crc);
  705. {$endif Test_Double_checksum_write}
  706. inc(crcindex);
  707. end;
  708. {$endif def Test_Double_checksum}
  709. end;
  710. end;
  711. if not crc_only then
  712. writedata(b,len);
  713. inc(entryidx,len);
  714. end;
  715. procedure tppufile.putbyte(b:byte);
  716. begin
  717. putdata(b,1);
  718. { inc(entryidx);}
  719. end;
  720. procedure tppufile.putword(w:word);
  721. begin
  722. if change_endian then
  723. w:=swap(w);
  724. putdata(w,2);
  725. end;
  726. procedure tppufile.putlongint(l:longint);
  727. begin
  728. if change_endian then
  729. { someone added swap(l : longint) in system unit
  730. this broke the following code !! }
  731. l:=swap(word(l shr 16)) or (longint(swap(word(l and $ffff))) shl 16);
  732. putdata(l,4);
  733. end;
  734. procedure tppufile.putreal(d:ppureal);
  735. begin
  736. putdata(d,sizeof(ppureal));
  737. end;
  738. procedure tppufile.putstring(s:string);
  739. begin
  740. putdata(s,length(s)+1);
  741. end;
  742. procedure tppufile.putsmallset(var b);
  743. begin
  744. putdata(b,4);
  745. end;
  746. procedure tppufile.putnormalset(var b);
  747. begin
  748. putdata(b,32);
  749. end;
  750. procedure tppufile.tempclose;
  751. begin
  752. if not closed then
  753. begin
  754. closepos:=filepos(f);
  755. {$I-}
  756. system.close(f);
  757. {$I+}
  758. if ioresult<>0 then;
  759. closed:=true;
  760. tempclosed:=true;
  761. end;
  762. end;
  763. function tppufile.tempopen:boolean;
  764. var
  765. ofm : byte;
  766. begin
  767. tempopen:=false;
  768. if not closed or not tempclosed then
  769. exit;
  770. ofm:=filemode;
  771. filemode:=0;
  772. {$I-}
  773. reset(f,1);
  774. {$I+}
  775. filemode:=ofm;
  776. if ioresult<>0 then
  777. exit;
  778. closed:=false;
  779. tempclosed:=false;
  780. { restore state }
  781. seek(f,closepos);
  782. tempopen:=true;
  783. end;
  784. end.
  785. {
  786. $Log$
  787. Revision 1.6 2000-12-07 17:19:43 jonas
  788. * new constant handling: from now on, hex constants >$7fffffff are
  789. parsed as unsigned constants (otherwise, $80000000 got sign extended
  790. and became $ffffffff80000000), all constants in the longint range
  791. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  792. are cardinals and the rest are int64's.
  793. * added lots of longint typecast to prevent range check errors in the
  794. compiler and rtl
  795. * type casts of symbolic ordinal constants are now preserved
  796. * fixed bug where the original resulttype wasn't restored correctly
  797. after doing a 64bit rangecheck
  798. Revision 1.5 2000/10/31 22:02:50 peter
  799. * symtable splitted, no real code changes
  800. Revision 1.4 2000/09/24 15:06:24 peter
  801. * use defines.inc
  802. Revision 1.3 2000/08/13 13:04:38 peter
  803. * new ppu version
  804. Revision 1.2 2000/07/13 11:32:45 michael
  805. + removed logs
  806. }