ppu.pas 19 KB

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