ppu.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 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. {$ifdef Test_Double_checksum}
  24. var
  25. CRCFile : text;
  26. const
  27. CRC_array_Size = 20000;
  28. type
  29. tcrc_array = array[0..crc_array_size] of longint;
  30. pcrc_array = ^tcrc_array;
  31. {$endif Test_Double_checksum}
  32. const
  33. {$ifndef Double_checksum}
  34. CurrentPPUVersion=15;
  35. {$else Double_checksum}
  36. CurrentPPUVersion=16;
  37. {$endif def Double_checksum}
  38. { buffer sizes }
  39. maxentrysize = 1024;
  40. {$ifdef TP}
  41. ppubufsize = 1024;
  42. {$else}
  43. ppubufsize = 16384;
  44. {$endif}
  45. {ppu entries}
  46. mainentryid = 1;
  47. subentryid = 2;
  48. {special}
  49. iberror = 0;
  50. ibstartdefs = 248;
  51. ibenddefs = 249;
  52. ibstartsyms = 250;
  53. ibendsyms = 251;
  54. ibendinterface = 252;
  55. ibendimplementation = 253;
  56. ibendbrowser = 254;
  57. ibend = 255;
  58. {general}
  59. ibmodulename = 1;
  60. ibsourcefiles = 2;
  61. ibloadunit = 3;
  62. ibinitunit = 5;
  63. iblinkofiles = 6;
  64. iblinksharedlibs = 7;
  65. iblinkstaticlibs = 8;
  66. ibdbxcount = 9;
  67. ibsymref = 10;
  68. ibdefref = 11;
  69. ibendsymtablebrowser = 12;
  70. ibbeginsymtablebrowser = 13;
  71. iblinkunitfiles = 14;
  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. ibstringdef = 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. ibfarpointerdef = 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_smartlink = $20; { the ppu is smartlinked }
  112. uf_in_library = $40; { is the file in another file than <ppufile>.* ? }
  113. uf_static_linked = $80; { the ppu is linked in a static library }
  114. uf_shared_linked = $100; { the ppu is linked in a shared library }
  115. uf_local_browser = $200;
  116. uf_obj_linked = $400; { the ppu is linked in a object file }
  117. type
  118. {$ifdef m68k}
  119. ppureal=single;
  120. {$else}
  121. ppureal=extended;
  122. {$endif}
  123. tppuerror=(ppuentrytoobig,ppuentryerror);
  124. tppuheader=packed record
  125. id : array[1..3] of char; { = 'PPU' }
  126. ver : array[1..3] of char;
  127. compiler : word;
  128. cpu : word;
  129. target : word;
  130. flags : longint;
  131. size : longint; { size of the ppufile without header }
  132. checksum : longint; { checksum for this ppufile }
  133. {$ifdef Double_checksum}
  134. interface_checksum : longint;
  135. {$endif def Double_checksum}
  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 Double_checksum}
  152. {$ifdef Test_Double_checksum}
  153. crcindex : longint;
  154. crc_index : longint;
  155. crc_test : pcrc_array;
  156. {$endif def Test_Double_checksum}
  157. interface_crc : longint;
  158. do_interface_crc : boolean;
  159. { used to calculate interface_crc
  160. before implementation }
  161. crc_only : boolean;
  162. {$endif def Double_checksum}
  163. do_crc,
  164. change_endian : boolean;
  165. buf : pchar;
  166. bufstart,
  167. bufsize,
  168. bufidx : longint;
  169. entrybufstart,
  170. entrystart,
  171. entryidx : longint;
  172. entry : tppuentry;
  173. entrytyp : byte;
  174. constructor init(fn:string);
  175. destructor done;
  176. procedure flush;
  177. procedure close;
  178. function CheckPPUId:boolean;
  179. function GetPPUVersion:longint;
  180. procedure NewHeader;
  181. procedure NewEntry;
  182. {read}
  183. function open:boolean;
  184. procedure reloadbuf;
  185. procedure readdata(var b;len:longint);
  186. procedure skipdata(len:longint);
  187. function readentry:byte;
  188. function EndOfEntry:boolean;
  189. procedure getdatabuf(var b;len:longint;var result:longint);
  190. procedure getdata(var b;len:longint);
  191. function getbyte:byte;
  192. function getword:word;
  193. function getlongint:longint;
  194. function getreal:ppureal;
  195. function getstring:string;
  196. function skipuntilentry(untilb:byte):boolean;
  197. {write}
  198. function create:boolean;
  199. procedure writeheader;
  200. procedure writebuf;
  201. procedure writedata(var b;len:longint);
  202. procedure writeentry(ibnr:byte);
  203. procedure putdata(var b;len:longint);
  204. procedure putbyte(b:byte);
  205. procedure putword(w:word);
  206. procedure putlongint(l:longint);
  207. procedure putreal(d:ppureal);
  208. procedure putstring(s:string);
  209. end;
  210. implementation
  211. {$ifdef Test_Double_checksum}
  212. uses
  213. comphook;
  214. {$endif def Test_Double_checksum}
  215. {*****************************************************************************
  216. Crc 32
  217. *****************************************************************************}
  218. var
  219. Crc32Tbl : array[0..255] of longint;
  220. procedure MakeCRC32Tbl;
  221. var
  222. crc : longint;
  223. i,n : byte;
  224. begin
  225. for i:=0 to 255 do
  226. begin
  227. crc:=i;
  228. for n:=1 to 8 do
  229. if odd(crc) then
  230. crc:=(crc shr 1) xor $edb88320
  231. else
  232. crc:=crc shr 1;
  233. Crc32Tbl[i]:=crc;
  234. end;
  235. end;
  236. {$ifopt R+}
  237. {$define Range_check_on}
  238. {$endif opt R+}
  239. {$R- needed here }
  240. {CRC 32}
  241. Function Crc32(Const HStr:String):longint;
  242. var
  243. i,InitCrc : longint;
  244. begin
  245. if Crc32Tbl[1]=0 then
  246. MakeCrc32Tbl;
  247. InitCrc:=$ffffffff;
  248. for i:=1to Length(Hstr) do
  249. InitCrc:=Crc32Tbl[byte(InitCrc) xor ord(Hstr[i])] xor (InitCrc shr 8);
  250. Crc32:=InitCrc;
  251. end;
  252. Function UpdateCrc32(InitCrc:longint;var InBuf;InLen:Longint):longint;
  253. var
  254. i : word;
  255. p : pchar;
  256. begin
  257. if Crc32Tbl[1]=0 then
  258. MakeCrc32Tbl;
  259. p:=@InBuf;
  260. for i:=1to InLen do
  261. begin
  262. InitCrc:=Crc32Tbl[byte(InitCrc) xor byte(p^)] xor (InitCrc shr 8);
  263. inc(longint(p));
  264. end;
  265. UpdateCrc32:=InitCrc;
  266. end;
  267. Function UpdCrc32(InitCrc:longint;b:byte):longint;
  268. begin
  269. if Crc32Tbl[1]=0 then
  270. MakeCrc32Tbl;
  271. UpdCrc32:=Crc32Tbl[byte(InitCrc) xor b] xor (InitCrc shr 8);
  272. end;
  273. {$ifdef Range_check_on}
  274. {$R+}
  275. {$undef Range_check_on}
  276. {$endif Range_check_on}
  277. {*****************************************************************************
  278. TPPUFile
  279. *****************************************************************************}
  280. constructor tppufile.init(fn:string);
  281. begin
  282. fname:=fn;
  283. change_endian:=false;
  284. {$ifdef Double_checksum}
  285. crc_only:=false;
  286. {$endif Double_checksum}
  287. Mode:=0;
  288. NewHeader;
  289. Error:=false;
  290. getmem(buf,ppubufsize);
  291. end;
  292. destructor tppufile.done;
  293. begin
  294. close;
  295. freemem(buf,ppubufsize);
  296. end;
  297. procedure tppufile.flush;
  298. begin
  299. if Mode=2 then
  300. writebuf;
  301. end;
  302. procedure tppufile.close;
  303. var
  304. i : word;
  305. begin
  306. if Mode<>0 then
  307. begin
  308. Flush;
  309. {$I-}
  310. system.close(f);
  311. {$I+}
  312. i:=ioresult;
  313. Mode:=0;
  314. end;
  315. end;
  316. function tppufile.CheckPPUId:boolean;
  317. begin
  318. CheckPPUId:=((Header.Id[1]='P') and (Header.Id[2]='P') and (Header.Id[3]='U'));
  319. end;
  320. function tppufile.GetPPUVersion:longint;
  321. var
  322. l : longint;
  323. code : word;
  324. begin
  325. Val(header.ver[1]+header.ver[2]+header.ver[3],l,code);
  326. if code=0 then
  327. GetPPUVersion:=l
  328. else
  329. GetPPUVersion:=0;
  330. end;
  331. procedure tppufile.NewHeader;
  332. begin
  333. fillchar(header,sizeof(tppuheader),0);
  334. with header do
  335. begin
  336. Id[1]:='P';
  337. Id[2]:='P';
  338. Id[3]:='U';
  339. Ver[1]:='0';
  340. Ver[2]:='1';
  341. {$ifndef Double_checksum}
  342. Ver[3]:='5';
  343. {$else Double_checksum}
  344. Ver[3]:='6';
  345. {$endif def Double_checksum}
  346. end;
  347. end;
  348. {*****************************************************************************
  349. TPPUFile Reading
  350. *****************************************************************************}
  351. function tppufile.open:boolean;
  352. var
  353. ofmode : byte;
  354. i : word;
  355. begin
  356. open:=false;
  357. assign(f,fname);
  358. ofmode:=filemode;
  359. filemode:=$0;
  360. {$I-}
  361. reset(f,1);
  362. {$I+}
  363. filemode:=ofmode;
  364. if ioresult<>0 then
  365. exit;
  366. {read ppuheader}
  367. fsize:=filesize(f);
  368. if fsize<sizeof(tppuheader) then
  369. exit;
  370. blockread(f,header,sizeof(tppuheader),i);
  371. {reset buffer}
  372. bufstart:=i;
  373. bufsize:=0;
  374. bufidx:=0;
  375. Mode:=1;
  376. FillChar(entry,sizeof(tppuentry),0);
  377. entryidx:=0;
  378. entrystart:=0;
  379. entrybufstart:=0;
  380. Error:=false;
  381. open:=true;
  382. end;
  383. procedure tppufile.reloadbuf;
  384. {$ifdef TP}
  385. var
  386. i : word;
  387. {$endif}
  388. begin
  389. inc(bufstart,bufsize);
  390. {$ifdef TP}
  391. blockread(f,buf^,ppubufsize,i);
  392. bufsize:=i;
  393. {$else}
  394. blockread(f,buf^,ppubufsize,bufsize);
  395. {$endif}
  396. bufidx:=0;
  397. end;
  398. procedure tppufile.readdata(var b;len:longint);
  399. var
  400. p : pchar;
  401. left,
  402. idx : longint;
  403. begin
  404. p:=pchar(@b);
  405. idx:=0;
  406. while len>0 do
  407. begin
  408. left:=bufsize-bufidx;
  409. if len>left then
  410. begin
  411. move(buf[bufidx],p[idx],left);
  412. dec(len,left);
  413. inc(idx,left);
  414. reloadbuf;
  415. if bufsize=0 then
  416. exit;
  417. end
  418. else
  419. begin
  420. move(buf[bufidx],p[idx],len);
  421. inc(bufidx,len);
  422. exit;
  423. end;
  424. end;
  425. end;
  426. procedure tppufile.skipdata(len:longint);
  427. var
  428. left : longint;
  429. begin
  430. while len>0 do
  431. begin
  432. left:=bufsize-bufidx;
  433. if len>left then
  434. begin
  435. dec(len,left);
  436. reloadbuf;
  437. if bufsize=0 then
  438. exit;
  439. end
  440. else
  441. begin
  442. inc(bufidx,len);
  443. exit;
  444. end;
  445. end;
  446. end;
  447. function tppufile.readentry:byte;
  448. begin
  449. if entryidx<entry.size then
  450. skipdata(entry.size-entryidx);
  451. readdata(entry,sizeof(tppuentry));
  452. entrystart:=bufstart+bufidx;
  453. entryidx:=0;
  454. if not(entry.id in [mainentryid,subentryid]) then
  455. begin
  456. readentry:=iberror;
  457. error:=true;
  458. exit;
  459. end;
  460. readentry:=entry.nr;
  461. end;
  462. function tppufile.endofentry:boolean;
  463. begin
  464. endofentry:=(entryidx>=entry.size);
  465. end;
  466. procedure tppufile.getdatabuf(var b;len:longint;var result:longint);
  467. begin
  468. if entryidx+len>entry.size then
  469. result:=entry.size-entryidx
  470. else
  471. result:=len;
  472. readdata(b,result);
  473. inc(entryidx,result);
  474. end;
  475. procedure tppufile.getdata(var b;len:longint);
  476. begin
  477. if entryidx+len>entry.size then
  478. begin
  479. error:=true;
  480. exit;
  481. end;
  482. readdata(b,len);
  483. inc(entryidx,len);
  484. end;
  485. function tppufile.getbyte:byte;
  486. var
  487. b : byte;
  488. begin
  489. if entryidx+1>entry.size then
  490. begin
  491. error:=true;
  492. getbyte:=0;
  493. exit;
  494. end;
  495. readdata(b,1);
  496. getbyte:=b;
  497. inc(entryidx);
  498. end;
  499. function tppufile.getword:word;
  500. type
  501. pword = ^word;
  502. var
  503. w : word;
  504. begin
  505. if entryidx+2>entry.size then
  506. begin
  507. error:=true;
  508. getword:=0;
  509. exit;
  510. end;
  511. readdata(w,2);
  512. if change_endian then
  513. getword:=swap(w)
  514. else
  515. getword:=w;
  516. inc(entryidx,2);
  517. end;
  518. function tppufile.getlongint:longint;
  519. type
  520. plongint = ^longint;
  521. var
  522. l : longint;
  523. begin
  524. if entryidx+4>entry.size then
  525. begin
  526. error:=true;
  527. getlongint:=0;
  528. exit;
  529. end;
  530. readdata(l,4);
  531. if change_endian then
  532. { someone added swap(l : longint) in system unit
  533. this broke the following code !! }
  534. getlongint:=swap(word(l shr 16)) or (longint(swap(word(l and $ffff))) shl 16)
  535. else
  536. getlongint:=l;
  537. inc(entryidx,4);
  538. end;
  539. function tppufile.getreal:ppureal;
  540. type
  541. pppureal = ^ppureal;
  542. var
  543. d : ppureal;
  544. begin
  545. if entryidx+sizeof(ppureal)>entry.size then
  546. begin
  547. error:=true;
  548. getreal:=0;
  549. exit;
  550. end;
  551. readdata(d,sizeof(ppureal));
  552. getreal:=d;
  553. inc(entryidx,sizeof(ppureal));
  554. end;
  555. function tppufile.getstring:string;
  556. var
  557. s : string;
  558. begin
  559. {$ifndef TP}
  560. {$ifopt H+}
  561. setlength(s,getbyte);
  562. {$else}
  563. s[0]:=chr(getbyte);
  564. {$endif}
  565. {$else}
  566. s[0]:=chr(getbyte);
  567. {$endif}
  568. if entryidx+length(s)>entry.size then
  569. begin
  570. error:=true;
  571. exit;
  572. end;
  573. ReadData(s[1],length(s));
  574. getstring:=s;
  575. inc(entryidx,length(s));
  576. end;
  577. function tppufile.skipuntilentry(untilb:byte):boolean;
  578. var
  579. b : byte;
  580. begin
  581. repeat
  582. b:=readentry;
  583. until (b in [ibend,iberror]) or ((b=untilb) and (entry.id=mainentryid));
  584. skipuntilentry:=(b=untilb);
  585. end;
  586. {*****************************************************************************
  587. TPPUFile Writing
  588. *****************************************************************************}
  589. function tppufile.create:boolean;
  590. begin
  591. create:=false;
  592. assign(f,fname);
  593. {$I-}
  594. rewrite(f,1);
  595. {$I+}
  596. if ioresult<>0 then
  597. exit;
  598. Mode:=2;
  599. {write header for sure}
  600. blockwrite(f,header,sizeof(tppuheader));
  601. bufsize:=ppubufsize;
  602. bufstart:=sizeof(tppuheader);
  603. bufidx:=0;
  604. {reset}
  605. crc:=$ffffffff;
  606. {$ifdef Double_checksum}
  607. interface_crc:=$ffffffff;
  608. do_interface_crc:=true;
  609. {$endif def Double_checksum}
  610. Error:=false;
  611. do_crc:=true;
  612. size:=0;
  613. entrytyp:=mainentryid;
  614. {start}
  615. NewEntry;
  616. create:=true;
  617. end;
  618. procedure tppufile.writeheader;
  619. var
  620. opos : longint;
  621. begin
  622. { flush buffer }
  623. writebuf;
  624. { update size (w/o header!) in the header }
  625. header.size:=bufstart-sizeof(tppuheader);
  626. { write header and restore filepos after it }
  627. opos:=filepos(f);
  628. seek(f,0);
  629. blockwrite(f,header,sizeof(tppuheader));
  630. seek(f,opos);
  631. end;
  632. procedure tppufile.writebuf;
  633. begin
  634. blockwrite(f,buf^,bufidx);
  635. inc(bufstart,bufidx);
  636. bufidx:=0;
  637. end;
  638. procedure tppufile.writedata(var b;len:longint);
  639. var
  640. p : pchar;
  641. left,
  642. idx : longint;
  643. begin
  644. p:=pchar(@b);
  645. idx:=0;
  646. while len>0 do
  647. begin
  648. left:=bufsize-bufidx;
  649. if len>left then
  650. begin
  651. move(p[idx],buf[bufidx],left);
  652. dec(len,left);
  653. inc(idx,left);
  654. inc(bufidx,left);
  655. writebuf;
  656. end
  657. else
  658. begin
  659. move(p[idx],buf[bufidx],len);
  660. inc(bufidx,len);
  661. exit;
  662. end;
  663. end;
  664. end;
  665. procedure tppufile.NewEntry;
  666. begin
  667. with entry do
  668. begin
  669. id:=entrytyp;
  670. nr:=ibend;
  671. size:=0;
  672. end;
  673. {Reset Entry State}
  674. entryidx:=0;
  675. entrybufstart:=bufstart;
  676. entrystart:=bufstart+bufidx;
  677. {Alloc in buffer}
  678. writedata(entry,sizeof(tppuentry));
  679. end;
  680. procedure tppufile.writeentry(ibnr:byte);
  681. var
  682. opos : longint;
  683. begin
  684. {create entry}
  685. entry.id:=entrytyp;
  686. entry.nr:=ibnr;
  687. entry.size:=entryidx;
  688. {it's already been sent to disk ?}
  689. if entrybufstart<>bufstart then
  690. begin
  691. {flush to be sure}
  692. WriteBuf;
  693. {write entry}
  694. opos:=filepos(f);
  695. seek(f,entrystart);
  696. blockwrite(f,entry,sizeof(tppuentry));
  697. seek(f,opos);
  698. entrybufstart:=bufstart;
  699. end
  700. else
  701. move(entry,buf[entrystart-bufstart],sizeof(entry));
  702. {Add New Entry, which is ibend by default}
  703. entrystart:=bufstart+bufidx; {next entry position}
  704. NewEntry;
  705. end;
  706. procedure tppufile.putdata(var b;len:longint);
  707. begin
  708. if do_crc then
  709. begin
  710. crc:=UpdateCrc32(crc,b,len);
  711. {$ifdef Double_checksum}
  712. if do_interface_crc then
  713. begin
  714. interface_crc:=UpdateCrc32(interface_crc,b,len);
  715. {$ifdef Test_Double_checksum}
  716. if crc_only then
  717. begin
  718. crc_test^[crc_index]:=interface_crc;
  719. {$ifdef Test_Double_checksum_write}
  720. Writeln(CRCFile,interface_crc);
  721. {$endif Test_Double_checksum_write}
  722. if crc_index<crc_array_size then
  723. inc(crc_index);
  724. end
  725. else
  726. begin
  727. if (crcindex<crc_array_size) and (crcindex<crc_index) and
  728. (crc_test^[crcindex]<>interface_crc) then
  729. Def_comment(V_Warning,'CRC changed');
  730. {$ifdef Test_Double_checksum_write}
  731. Writeln(CRCFile,interface_crc);
  732. {$endif Test_Double_checksum_write}
  733. inc(crcindex);
  734. end;
  735. {$endif def Test_Double_checksum}
  736. end;
  737. end;
  738. if not crc_only then
  739. {$else not def Double_checksum}
  740. end;
  741. {$endif def Double_checksum}
  742. writedata(b,len);
  743. inc(entryidx,len);
  744. end;
  745. procedure tppufile.putbyte(b:byte);
  746. begin
  747. writedata(b,1);
  748. inc(entryidx);
  749. end;
  750. procedure tppufile.putword(w:word);
  751. begin
  752. if change_endian then
  753. w:=swap(w);
  754. putdata(w,2);
  755. end;
  756. procedure tppufile.putlongint(l:longint);
  757. begin
  758. if change_endian then
  759. { someone added swap(l : longint) in system unit
  760. this broke the following code !! }
  761. l:=swap(word(l shr 16)) or (longint(swap(word(l and $ffff))) shl 16);
  762. putdata(l,4);
  763. end;
  764. procedure tppufile.putreal(d:ppureal);
  765. begin
  766. putdata(d,sizeof(ppureal));
  767. end;
  768. procedure tppufile.putstring(s:string);
  769. begin
  770. putdata(s,length(s)+1);
  771. end;
  772. end.
  773. {
  774. $Log$
  775. Revision 1.27 1999-04-17 13:16:20 peter
  776. * fixes for storenumber
  777. Revision 1.26 1999/04/07 15:39:31 pierre
  778. + double_checksum code added
  779. Revision 1.25 1999/03/02 13:49:18 peter
  780. * renamed loadunit_int -> loadunit
  781. Revision 1.24 1999/02/22 13:07:00 pierre
  782. + -b and -bl options work !
  783. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  784. is not enabled when quitting global section
  785. * local vars and procedures are not yet stored into PPU
  786. Revision 1.23 1999/02/16 00:48:24 peter
  787. * save in the ppu if linked with obj file instead of using the
  788. library flag, so the .inc files are also checked
  789. Revision 1.22 1999/02/05 08:54:29 pierre
  790. + linkofiles splitted inot linkofiles and linkunitfiles
  791. because linkofiles must be stored with directory
  792. to enabled linking of different objects with same name
  793. in a different directory
  794. Revision 1.21 1998/12/30 22:15:50 peter
  795. + farpointer type
  796. * absolutesym now also stores if its far
  797. Revision 1.20 1998/11/30 16:34:45 pierre
  798. * corrected problems with rangecheck
  799. + added needed code for no rangecheck in CRC32 functions in ppu unit
  800. * enumdef lso need its rangenr reset to zero
  801. when calling reset_global_defs
  802. Revision 1.19 1998/11/16 15:41:42 peter
  803. * tp7 didn't like my ifopt H+ :(
  804. Revision 1.18 1998/11/16 12:18:03 peter
  805. * H+ fixes
  806. Revision 1.17 1998/10/14 10:45:08 pierre
  807. * ppu problems for m68k fixed (at least in cross compiling)
  808. * one last memory leak for sysamiga fixed
  809. * the amiga RTL compiles now completely !!
  810. Revision 1.16 1998/09/24 23:49:14 peter
  811. + aktmodeswitches
  812. Revision 1.15 1998/09/23 15:39:10 pierre
  813. * browser bugfixes
  814. was adding a reference when looking for the symbol
  815. if -bSYM_NAME was used
  816. Revision 1.14 1998/09/21 10:00:07 peter
  817. * store number of defs in ppu file
  818. Revision 1.13 1998/09/21 08:45:18 pierre
  819. + added vmt_offset in tobjectdef.write for fututre use
  820. (first steps to have objects without vmt if no virtual !!)
  821. + added fpu_used field for tabstractprocdef :
  822. sets this level to 2 if the functions return with value in FPU
  823. (is then set to correct value at parsing of implementation)
  824. THIS MIGHT refuse some code with FPU expression too complex
  825. that were accepted before and even in some cases
  826. that don't overflow in fact
  827. ( like if f : float; is a forward that finally in implementation
  828. only uses one fpu register !!)
  829. Nevertheless I think that it will improve security on
  830. FPU operations !!
  831. * most other changes only for UseBrowser code
  832. (added symtable references for record and objects)
  833. local switch for refs to args and local of each function
  834. (static symtable still missing)
  835. UseBrowser still not stable and probably broken by
  836. the definition hash array !!
  837. Revision 1.12 1998/09/18 08:01:37 pierre
  838. + improvement on the usebrowser part
  839. (does not work correctly for now)
  840. Revision 1.11 1998/09/11 15:16:47 peter
  841. * merge fixes
  842. Revision 1.10.2.1 1998/09/11 15:15:04 peter
  843. * fixed not in [] bug
  844. Revision 1.10 1998/08/31 12:26:30 peter
  845. * m68k and palmos updates from surebugfixes
  846. Revision 1.9 1998/08/17 09:17:51 peter
  847. * static/shared linking updates
  848. Revision 1.8 1998/08/11 15:31:40 peter
  849. * write extended to ppu file
  850. * new version 0.99.7
  851. Revision 1.7 1998/06/25 10:51:01 pierre
  852. * removed a remaining ifndef NEWPPU
  853. replaced by ifdef OLDPPU
  854. * added uf_finalize to ppu unit
  855. Revision 1.6 1998/06/16 08:56:26 peter
  856. + targetcpu
  857. * cleaner pmodules for newppu
  858. Revision 1.5 1998/06/13 00:10:12 peter
  859. * working browser and newppu
  860. * some small fixes against crashes which occured in bp7 (but not in
  861. fpc?!)
  862. Revision 1.4 1998/06/09 16:01:48 pierre
  863. + added procedure directive parsing for procvars
  864. (accepted are popstack cdecl and pascal)
  865. + added C vars with the following syntax
  866. var C calias 'true_c_name';(can be followed by external)
  867. reason is that you must add the Cprefix
  868. which is target dependent
  869. Revision 1.3 1998/05/28 14:40:26 peter
  870. * fixes for newppu, remake3 works now with it
  871. Revision 1.2 1998/05/27 19:45:08 peter
  872. * symtable.pas splitted into includefiles
  873. * symtable adapted for $ifdef NEWPPU
  874. Revision 1.1 1998/05/12 10:56:07 peter
  875. + the ppufile object unit
  876. }