ppu.pas 19 KB

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