ppu.pas 18 KB

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