entfile.pas 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036
  1. {
  2. Copyright (c) 1998-2013 by Free Pascal development team
  3. Routines to read/write entry based files (ppu, pcp)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit entfile;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. systems,globtype,constexp,cstreams;
  22. const
  23. { buffer sizes }
  24. maxentrysize = 1024;
  25. // Unused, and wrong as there are entries that are larger then 1024 bytes
  26. entryfilebufsize = 16384;
  27. {ppu entries}
  28. mainentryid = 1;
  29. subentryid = 2;
  30. {special}
  31. iberror = 0;
  32. ibextraheader = 242;
  33. ibpputable = 243;
  34. ibstartrequireds = 244;
  35. ibendrequireds = 245;
  36. ibstartcontained = 246;
  37. ibendcontained = 247;
  38. ibstartdefs = 248;
  39. ibenddefs = 249;
  40. ibstartsyms = 250;
  41. ibendsyms = 251;
  42. ibendinterface = 252;
  43. ibendimplementation = 253;
  44. // ibendbrowser = 254;
  45. ibend = 255;
  46. {general}
  47. ibmodulename = 1;
  48. ibsourcefiles = 2;
  49. ibloadunit = 3;
  50. ibinitunit = 4;
  51. iblinkunitofiles = 5;
  52. iblinkunitstaticlibs = 6;
  53. iblinkunitsharedlibs = 7;
  54. iblinkotherofiles = 8;
  55. iblinkotherstaticlibs = 9;
  56. iblinkothersharedlibs = 10;
  57. ibImportSymbols = 11;
  58. ibsymref = 12;
  59. ibdefref = 13;
  60. ibfeatures = 14;
  61. {$IFDEF MACRO_DIFF_HINT}
  62. ibusedmacros = 16;
  63. {$ENDIF}
  64. ibderefdata = 17;
  65. ibexportedmacros = 18;
  66. ibderefmap = 19;
  67. {syms}
  68. ibtypesym = 20;
  69. ibprocsym = 21;
  70. ibstaticvarsym = 22;
  71. ibconstsym = 23;
  72. ibenumsym = 24;
  73. // ibtypedconstsym = 25;
  74. ibabsolutevarsym = 26;
  75. ibpropertysym = 27;
  76. ibfieldvarsym = 28;
  77. ibunitsym = 29;
  78. iblabelsym = 30;
  79. ibsyssym = 31;
  80. ibnamespacesym = 32;
  81. iblocalvarsym = 33;
  82. ibparavarsym = 34;
  83. ibmacrosym = 35;
  84. {definitions}
  85. iborddef = 40;
  86. ibpointerdef = 41;
  87. ibarraydef = 42;
  88. ibprocdef = 43;
  89. ibshortstringdef = 44;
  90. ibrecorddef = 45;
  91. ibfiledef = 46;
  92. ibformaldef = 47;
  93. ibobjectdef = 48;
  94. ibenumdef = 49;
  95. ibsetdef = 50;
  96. ibprocvardef = 51;
  97. ibfloatdef = 52;
  98. ibclassrefdef = 53;
  99. iblongstringdef = 54;
  100. ibansistringdef = 55;
  101. ibwidestringdef = 56;
  102. ibvariantdef = 57;
  103. ibundefineddef = 58;
  104. ibunicodestringdef = 59;
  105. {implementation/ObjData}
  106. ibnodetree = 80;
  107. ibasmsymbols = 81;
  108. ibresources = 82;
  109. ibcreatedobjtypes = 83;
  110. ibwpofile = 84;
  111. ibmoduleoptions = 85;
  112. ibunitimportsyms = 86;
  113. iborderedsymbols = 87;
  114. ibmainname = 90;
  115. ibsymtableoptions = 91;
  116. ibpackagefiles = 92;
  117. ibpackagename = 93;
  118. ibrecsymtableoptions = 94;
  119. { target-specific things }
  120. iblinkotherframeworks = 100;
  121. ibjvmnamespace = 101;
  122. {$ifdef generic_cpu}
  123. { We need to use the correct size of aint and pint for
  124. the target CPU }
  125. const
  126. CpuAddrBitSize : array[tsystemcpu] of longint =
  127. (
  128. { 0 } 32 {'none'},
  129. { 1 } 32 {'i386'},
  130. { 2 } 32 {'m68k'},
  131. { 3 } 32 {'alpha'},
  132. { 4 } 32 {'powerpc'},
  133. { 5 } 32 {'sparc'},
  134. { 6 } 32 {'vis'},
  135. { 7 } 64 {'ia64'},
  136. { 8 } 64 {'x86_64'},
  137. { 9 } 32 {'mipseb'},
  138. { 10 } 32 {'arm'},
  139. { 11 } 64 {'powerpc64'},
  140. { 12 } 16 {'avr'},
  141. { 13 } 32 {'mipsel'},
  142. { 14 } 32 {'jvm'},
  143. { 15 } 16 {'i8086'},
  144. { 16 } 64 {'aarch64'},
  145. { 17 } 32 {'wasm32'},
  146. { 18 } 64 {'sparc64'},
  147. { 19 } 32 {'riscv32'},
  148. { 20 } 64 {'riscv64'},
  149. { 21 } 32 {'xtensa'},
  150. { 22 } 16 {'z80'},
  151. { 23 } 64 {'mips64'},
  152. { 24 } 64 {'mips64el'},
  153. { 25 } 64 {'loongarch64'}
  154. );
  155. CpuAluBitSize : array[tsystemcpu] of longint =
  156. (
  157. { 0 } 32 {'none'},
  158. { 1 } 32 {'i386'},
  159. { 2 } 32 {'m68k'},
  160. { 3 } 32 {'alpha'},
  161. { 4 } 32 {'powerpc'},
  162. { 5 } 32 {'sparc'},
  163. { 6 } 32 {'vis'},
  164. { 7 } 64 {'ia64'},
  165. { 8 } 64 {'x86_64'},
  166. { 9 } 32 {'mipseb'},
  167. { 10 } 32 {'arm'},
  168. { 11 } 64 {'powerpc64'},
  169. { 12 } 8 {'avr'},
  170. { 13 } 32 {'mipsel'},
  171. { 14 } 64 {'jvm'},
  172. { 15 } 16 {'i8086'},
  173. { 16 } 64 {'aarch64'},
  174. { 17 } 64 {'wasm32'},
  175. { 18 } 64 {'sparc64'},
  176. { 19 } 32 {'riscv32'},
  177. { 20 } 64 {'riscv64'},
  178. { 21 } 32 {'xtensa'},
  179. { 22 } 8 {'z80'},
  180. { 23 } 64 {'mips64'},
  181. { 24 } 64 {'mips64el'},
  182. { 25 } 64 {'loongarch64'}
  183. );
  184. {$endif generic_cpu}
  185. type
  186. { bestreal is defined based on the target architecture }
  187. entryreal=bestreal;
  188. { common part of the header for all kinds of entry files }
  189. tentryheader=record
  190. id : array[1..3] of char;
  191. ver : array[1..3] of char;
  192. compiler : word;
  193. cpu : word;
  194. target : word;
  195. flags : dword;
  196. size : dword; { size of the ppufile without header }
  197. end;
  198. pentryheader=^tentryheader;
  199. tentry=packed record
  200. size : longint;
  201. id : byte;
  202. nr : byte;
  203. end;
  204. tentryfile=class
  205. private
  206. function getposition:longint;
  207. procedure setposition(value:longint);
  208. protected
  209. buf : pchar;
  210. bufstart,
  211. bufsize,
  212. bufidx : integer;
  213. entrybufstart,
  214. entrystart,
  215. entryidx : integer;
  216. entry : tentry;
  217. closed,
  218. tempclosed : boolean;
  219. closepos : integer;
  220. protected
  221. f : TCStream;
  222. {$ifdef DEBUG_PPU}
  223. flog : text;
  224. flog_open : boolean;
  225. ppu_log_level : longint;
  226. ppu_log_idx : integer;
  227. {$endif}
  228. mode : byte; {0 - Closed, 1 - Reading, 2 - Writing}
  229. fisfile : boolean;
  230. fname : string;
  231. fsize : integer;
  232. procedure newheader;virtual;abstract;
  233. function readheader:longint;virtual;abstract;
  234. function outputallowed:boolean;virtual;
  235. procedure resetfile;virtual;abstract;
  236. function getheadersize:longint;virtual;abstract;
  237. function getheaderaddr:pentryheader;virtual;abstract;
  238. procedure RaiseAssertion(Code: Longint); virtual;
  239. public
  240. entrytyp : byte;
  241. size : integer;
  242. change_endian : boolean; { Used in ppudump util }
  243. {$ifdef generic_cpu}
  244. has_more,
  245. {$endif not generic_cpu}
  246. error : boolean;
  247. constructor create(const fn:string);
  248. destructor destroy;override;
  249. function getversion:integer;
  250. procedure flush; {$ifdef USEINLINE}inline;{$endif}
  251. procedure closefile;virtual;
  252. procedure newentry;
  253. property position:longint read getposition write setposition;
  254. { Warning: don't keep the stream open during a tempclose! }
  255. function substream(ofs,len:longint):TCStream;
  256. { Warning: don't use the put* or write* functions anymore when writing through this }
  257. property stream:TCStream read f;
  258. {$ifdef DEBUG_PPU}
  259. procedure ppu_log(st :string);virtual;
  260. procedure ppu_log_val(st :string);virtual;
  261. procedure inc_log_level;
  262. procedure dec_log_level;
  263. {$endif}
  264. {read}
  265. function openfile:boolean;
  266. function openstream(strm:TCStream):boolean;
  267. procedure reloadbuf;
  268. procedure readdata(out b;len:integer);
  269. procedure skipdata(len:integer);
  270. function readentry:byte;
  271. function EndOfEntry:boolean; {$ifdef USEINLINE}inline;{$endif}
  272. function entrysize:longint; {$ifdef USEINLINE}inline;{$endif}
  273. function entryleft:longint; {$ifdef USEINLINE}inline;{$endif}
  274. procedure getdatabuf(out b;len:integer;out res:integer);
  275. procedure getdata(out b;len:integer);
  276. function getbyte:byte;
  277. function getword:word;
  278. function getdword:dword;
  279. function getlongint:longint;
  280. function getint64:int64;
  281. function getqword:qword;
  282. function getaint:{$ifdef generic_cpu}int64{$else}aint{$ifdef USEINLINE}; inline{$endif}{$endif};
  283. function getasizeint:{$ifdef generic_cpu}int64{$else}asizeint{$ifdef USEINLINE}; inline{$endif}{$endif};
  284. function getpuint:{$ifdef generic_cpu}qword{$else}puint{$ifdef USEINLINE}; inline{$endif}{$endif};
  285. function getptruint:{$ifdef generic_cpu}qword{$else}TConstPtrUInt{$ifdef USEINLINE}; inline{$endif}{$endif};
  286. function getaword:{$ifdef generic_cpu}qword{$else}aword{$ifdef USEINLINE}; inline{$endif}{$endif};
  287. function getreal:entryreal;
  288. function getrealsize(sizeofreal : longint):entryreal;
  289. function getboolean:boolean; {$ifdef USEINLINE}inline;{$endif}
  290. function getstring:string;
  291. function getpshortstring:pshortstring;
  292. function getansistring:ansistring;
  293. procedure getset(out arr: array of byte);
  294. function skipuntilentry(untilb:byte):boolean;
  295. {write}
  296. function createfile:boolean;virtual;
  297. function createstream(strm:TCStream):boolean;
  298. procedure writeheader;virtual;abstract;
  299. procedure writebuf;
  300. procedure writedata(const b;len:integer);
  301. procedure writeentry(ibnr:byte);
  302. procedure putdata(const b;len:integer);virtual;
  303. procedure putbyte(b:byte); {$ifdef USEINLINE}inline;{$endif}
  304. procedure putword(w:word); {$ifdef USEINLINE}inline;{$endif}
  305. procedure putdword(w:dword); {$ifdef USEINLINE}inline;{$endif}
  306. procedure putlongint(l:longint); {$ifdef USEINLINE}inline;{$endif}
  307. procedure putint64(i:int64); {$ifdef USEINLINE}inline;{$endif}
  308. procedure putqword(q:qword); {$ifdef USEINLINE}inline;{$endif}
  309. procedure putaint(i:aint); {$ifdef USEINLINE}inline;{$endif}
  310. procedure putasizeint(i:asizeint); {$ifdef USEINLINE}inline;{$endif}
  311. procedure putpuint(i:puint); {$ifdef USEINLINE}inline;{$endif}
  312. procedure putptruint(v:TConstPtrUInt); {$ifdef USEINLINE}inline;{$endif}
  313. procedure putaword(i:aword); {$ifdef USEINLINE}inline;{$endif}
  314. procedure putreal(d:entryreal);
  315. procedure putboolean(b:boolean); {$ifdef USEINLINE}inline;{$endif}
  316. procedure putstring(const s:string); {$ifdef USEINLINE}inline;{$endif}
  317. procedure putansistring(const s:ansistring);
  318. procedure putset(const arr: array of byte);
  319. procedure tempclose; // MG: not used, obsolete?
  320. function tempopen:boolean; // MG: not used, obsolete?
  321. end;
  322. implementation
  323. uses
  324. {$ifdef FPC_SOFT_FPUX80}
  325. sfpux80,
  326. {$endif FPC_SOFT_FPUX80}
  327. cutils;
  328. function swapendian_entryreal(d:entryreal):entryreal;
  329. type
  330. entryreal_bytes=array[0..sizeof(d)-1] of byte;
  331. var
  332. i:0..sizeof(d)-1;
  333. begin
  334. for i:=low(entryreal_bytes) to high(entryreal_bytes) do
  335. entryreal_bytes(result)[i]:=entryreal_bytes(d)[high(entryreal_bytes)-i];
  336. end;
  337. {*****************************************************************************
  338. tentryfile
  339. *****************************************************************************}
  340. function tentryfile.outputallowed: boolean;
  341. begin
  342. result:=true;
  343. end;
  344. constructor tentryfile.create(const fn:string);
  345. begin
  346. fname:=fn;
  347. fisfile:=false;
  348. change_endian:=false;
  349. mode:=0;
  350. newheader;
  351. error:=false;
  352. closed:=true;
  353. tempclosed:=false;
  354. getmem(buf,entryfilebufsize);
  355. {$ifdef DEBUG_PPU}
  356. assign(flog,fn+'.debug-log');
  357. flog_open:=false;
  358. {$endif DEBUG_PPU}
  359. end;
  360. destructor tentryfile.destroy;
  361. begin
  362. closefile;
  363. {$ifdef DEBUG_PPU}
  364. if flog_open then
  365. close(flog);
  366. flog_open:=false;
  367. {$endif DEBUG_PPU}
  368. if assigned(buf) then
  369. freemem(buf,entryfilebufsize);
  370. end;
  371. {$ifdef DEBUG_PPU}
  372. function entryid_name(nr : byte) : string;
  373. begin
  374. case nr of
  375. {ppu entries}
  376. mainentryid: entryid_name:='main_entry_id';
  377. subentryid: entryid_name:='sub_entry_id';
  378. else
  379. entryid_name:='unknown entryid '+tostr(nr);
  380. end;
  381. end;
  382. function entry_name(nr : byte) : string;
  383. begin
  384. case nr of
  385. {special}
  386. iberror: entry_name:='iberror';
  387. ibextraheader: entry_name:='ibextraheader';
  388. ibpputable: entry_name:='ibpputable';
  389. ibstartrequireds: entry_name:='ibstartrequireds';
  390. ibendrequireds: entry_name:='ibendrequireds';
  391. ibstartcontained: entry_name:='ibstartcontained';
  392. ibendcontained: entry_name:='ibendcontained';
  393. ibstartdefs: entry_name:='ibstartdefs';
  394. ibenddefs: entry_name:='ibenddefs';
  395. ibstartsyms: entry_name:='ibstartsyms';
  396. ibendsyms: entry_name:='ibendsyms';
  397. ibendinterface: entry_name:='ibendinterface';
  398. ibendimplementation: entry_name:='ibendimplementation';
  399. // ibendbrowser: entry_name:='ibendbrowser';
  400. ibend: entry_name:='ibend';
  401. {general}
  402. ibmodulename: entry_name:='ibmodulename';
  403. ibsourcefiles: entry_name:='ibsourcefiles';
  404. ibloadunit: entry_name:='ibloadunit';
  405. ibinitunit: entry_name:='ibinitunit';
  406. iblinkunitofiles: entry_name:='iblinkunitofiles';
  407. iblinkunitstaticlibs: entry_name:='iblinkunitstaticlibs';
  408. iblinkunitsharedlibs: entry_name:='iblinkunitsharedlibs';
  409. iblinkotherofiles: entry_name:='iblinkotherofiles';
  410. iblinkotherstaticlibs: entry_name:='iblinkotherstaticlibs';
  411. iblinkothersharedlibs: entry_name:='iblinkothersharedlibs';
  412. ibImportSymbols: entry_name:='ibImportSymbols';
  413. ibsymref: entry_name:='ibsymref';
  414. ibdefref: entry_name:='ibdefref';
  415. ibfeatures: entry_name:='ibfeatures';
  416. {$IFDEF MACRO_DIFF_HINT}
  417. ibusedmacros: entry_name:='ibusedmacros';
  418. {$ENDIF}
  419. ibderefdata: entry_name:='ibderefdata';
  420. ibexportedmacros: entry_name:='ibexportedmacros';
  421. ibderefmap: entry_name:='ibderefmap';
  422. {syms}
  423. ibtypesym: entry_name:='ibtypesym';
  424. ibprocsym: entry_name:='ibprocsym';
  425. ibstaticvarsym: entry_name:='ibstaticvarsym';
  426. ibconstsym: entry_name:='ibconstsym';
  427. ibenumsym: entry_name:='ibenumsym';
  428. // ibtypedconstsym: entry_name:='ibtypedconstsym';
  429. ibabsolutevarsym: entry_name:='ibabsolutevarsym';
  430. ibpropertysym: entry_name:='ibpropertysym';
  431. ibfieldvarsym: entry_name:='ibfieldvarsym';
  432. ibunitsym: entry_name:='ibunitsym';
  433. iblabelsym: entry_name:='iblabelsym';
  434. ibsyssym: entry_name:='ibsyssym';
  435. ibnamespacesym: entry_name:='ibnamespacesym';
  436. iblocalvarsym: entry_name:='iblocalvarsym';
  437. ibparavarsym: entry_name:='ibparavarsym';
  438. ibmacrosym: entry_name:='ibmacrosym';
  439. {definitions}
  440. iborddef: entry_name:='iborddef';
  441. ibpointerdef: entry_name:='ibpointerdef';
  442. ibarraydef: entry_name:='ibarraydef';
  443. ibprocdef: entry_name:='ibprocdef';
  444. ibshortstringdef: entry_name:='ibshortstringdef';
  445. ibrecorddef: entry_name:='ibrecorddef';
  446. ibfiledef: entry_name:='ibfiledef';
  447. ibformaldef: entry_name:='ibformaldef';
  448. ibobjectdef: entry_name:='ibobjectdef';
  449. ibenumdef: entry_name:='ibenumdef';
  450. ibsetdef: entry_name:='ibsetdef';
  451. ibprocvardef: entry_name:='ibprocvardef';
  452. ibfloatdef: entry_name:='ibfloatdef';
  453. ibclassrefdef: entry_name:='ibclassrefdef';
  454. iblongstringdef: entry_name:='iblongstringdef';
  455. ibansistringdef: entry_name:='ibansistringdef';
  456. ibwidestringdef: entry_name:='ibwidestringdef';
  457. ibvariantdef: entry_name:='ibvariantdef';
  458. ibundefineddef: entry_name:='ibundefineddef';
  459. ibunicodestringdef: entry_name:='ibunicodestringdef';
  460. {implementation/ObjData}
  461. ibnodetree: entry_name:='ibnodetree';
  462. ibasmsymbols: entry_name:='ibasmsymbols';
  463. ibresources: entry_name:='ibresources';
  464. ibcreatedobjtypes: entry_name:='ibcreatedobjtypes';
  465. ibwpofile: entry_name:='ibwpofile';
  466. ibmoduleoptions: entry_name:='ibmoduleoptions';
  467. ibunitimportsyms: entry_name:='ibunitimportsyms';
  468. iborderedsymbols: entry_name:='iborderedsymbols';
  469. ibmainname: entry_name:='ibmainname';
  470. ibsymtableoptions: entry_name:='ibsymtableoptions';
  471. // ibrecsymtableoptions: entry_name:='ibrecsymtableoptions';
  472. ibpackagefiles: entry_name:='ibpackagefiles';
  473. ibpackagename: entry_name:='ibpackagename';
  474. { target-specific things }
  475. iblinkotherframeworks: entry_name:='iblinkotherframeworks';
  476. ibjvmnamespace: entry_name:='ibjvmnamespace';
  477. else
  478. entry_name:='unknown entry '+tostr(nr);
  479. end;
  480. end;
  481. procedure tentryfile.ppu_log(st :string);
  482. begin
  483. if flog_open then
  484. begin
  485. writeln(flog,bufstart+bufidx,': ',st);
  486. end;
  487. {$ifdef IN_PPUDUMP}
  488. writeln(bufstart+bufidx,': ',st);
  489. {$endif}
  490. end;
  491. procedure tentryfile.inc_log_level;
  492. begin
  493. inc(ppu_log_level);
  494. end;
  495. procedure tentryfile.ppu_log_val(st :string);
  496. begin
  497. if flog_open then
  498. begin
  499. writeln(flog,'(',ppu_log_level,') value: ',st);
  500. end;
  501. {$ifdef IN_PPUDUMP}
  502. writeln('(',ppu_log_level,') value: ',st);
  503. {$endif}
  504. end;
  505. procedure tentryfile.dec_log_level;
  506. begin
  507. dec(ppu_log_level);
  508. end;
  509. {$endif}
  510. function tentryfile.getversion:integer;
  511. var
  512. l : integer;
  513. code : integer;
  514. header : pentryheader;
  515. begin
  516. header:=getheaderaddr;
  517. Val(header^.ver[1]+header^.ver[2]+header^.ver[3],l,code);
  518. if code=0 then
  519. result:=l
  520. else
  521. result:=0;
  522. end;
  523. procedure tentryfile.flush;
  524. begin
  525. if mode=2 then
  526. writebuf;
  527. end;
  528. procedure tentryfile.RaiseAssertion(Code: Longint);
  529. begin
  530. { It's down to descendent classes to raise an internal error as desired. [Kit] }
  531. error := true;
  532. end;
  533. procedure tentryfile.closefile;
  534. begin
  535. if mode<>0 then
  536. begin
  537. flush;
  538. {$ifdef DEBUG_PPU}
  539. if (entry.nr<>0) and (mode=1) then
  540. ppu_log('writeentry, id='+entryid_name(entry.id)+' nr='+entry_name(entry.nr)+' size='+tostr(entry.size));
  541. {$endif}
  542. if fisfile then
  543. f.Free;
  544. mode:=0;
  545. closed:=true;
  546. end;
  547. end;
  548. procedure tentryfile.setposition(value:longint);
  549. begin
  550. if assigned(f) then
  551. f.Position:=value
  552. else
  553. if tempclosed then
  554. closepos:=value;
  555. end;
  556. function tentryfile.getposition:longint;
  557. begin
  558. if assigned(f) then
  559. result:=f.Position
  560. else
  561. if tempclosed then
  562. result:=closepos
  563. else
  564. result:=0;
  565. end;
  566. function tentryfile.substream(ofs,len:longint):TCStream;
  567. begin
  568. result:=nil;
  569. if assigned(f) then
  570. result:=TCRangeStream.Create(f,ofs,len);
  571. end;
  572. {*****************************************************************************
  573. tentryfile Reading
  574. *****************************************************************************}
  575. function tentryfile.openfile:boolean;
  576. var
  577. strm : TCStream;
  578. begin
  579. openfile:=false;
  580. try
  581. strm:=CFileStreamClass.Create(fname,fmOpenRead)
  582. except
  583. exit;
  584. end;
  585. openfile:=openstream(strm);
  586. fisfile:=result;
  587. end;
  588. function tentryfile.openstream(strm:TCStream):boolean;
  589. var
  590. i : longint;
  591. begin
  592. openstream:=false;
  593. f:=strm;
  594. closed:=false;
  595. {$ifdef DEBUG_PPU}
  596. {$push}
  597. {$I-}
  598. assign(flog,fname+'.debug-read-log');
  599. rewrite(flog);
  600. if InOutRes=0 then
  601. flog_open:=true;
  602. {$pop}
  603. {$endif DEBUG_PPU}
  604. {read ppuheader}
  605. fsize:=f.Size;
  606. i:=readheader;
  607. if i<0 then
  608. exit;
  609. {reset buffer}
  610. bufstart:=i;
  611. bufsize:=0;
  612. bufidx:=0;
  613. mode:=1;
  614. FillChar(entry,sizeof(tentry),0);
  615. entryidx:=0;
  616. entrystart:=0;
  617. entrybufstart:=0;
  618. error:=false;
  619. openstream:=true;
  620. end;
  621. procedure tentryfile.reloadbuf;
  622. begin
  623. inc(bufstart,bufsize);
  624. bufsize:=f.Read(buf^,entryfilebufsize);
  625. bufidx:=0;
  626. end;
  627. procedure tentryfile.readdata(out b;len:integer);
  628. var
  629. p,pbuf : pchar;
  630. left : integer;
  631. {$ifdef DEBUG_PPU}
  632. i : integer;
  633. {$endif DEBUG_PPU}
  634. begin
  635. p:=pchar(@b);
  636. pbuf:=@buf[bufidx];
  637. repeat
  638. left:=bufsize-bufidx;
  639. if len<left then
  640. break;
  641. move(pbuf^,p^,left);
  642. dec(len,left);
  643. inc(p,left);
  644. reloadbuf;
  645. pbuf:=@buf[bufidx];
  646. if bufsize=0 then
  647. exit;
  648. until false;
  649. move(pbuf^,p^,len);
  650. {$ifdef DEBUG_PPU}
  651. if ppu_log_level <= 0 then
  652. begin
  653. ppu_log('writedata, length='+tostr(len)+' level='+tostr(ppu_log_level));
  654. for i:=0 to len-1 do
  655. ppu_log_val('p['+tostr(i)+']=$'+hexstr(byte(p[i]),2));
  656. end;
  657. {$endif DEBUG_PPU}
  658. inc(bufidx,len);
  659. end;
  660. procedure tentryfile.skipdata(len:integer);
  661. var
  662. left : integer;
  663. begin
  664. {$ifdef DEBUG_PPU}
  665. if len>0 then
  666. ppu_log('explicit skipdata '+tostr(len));
  667. {$endif}
  668. while len>0 do
  669. begin
  670. left:=bufsize-bufidx;
  671. if len>left then
  672. begin
  673. dec(len,left);
  674. reloadbuf;
  675. if bufsize=0 then
  676. exit;
  677. end
  678. else
  679. begin
  680. inc(bufidx,len);
  681. exit;
  682. end;
  683. end;
  684. end;
  685. function tentryfile.readentry:byte;
  686. begin
  687. if entryidx<entry.size then
  688. begin
  689. {$ifdef generic_cpu}
  690. has_more:=true;
  691. {$endif not generic_cpu}
  692. {$ifdef DEBUG_PPU}
  693. if entry.size-entryidx>0 then
  694. ppu_log('skipdata '+tostr(entry.size-entryidx));
  695. {$endif}
  696. skipdata(entry.size-entryidx);
  697. end;
  698. {$ifdef DEBUG_PPU}
  699. if entry.nr<>0 then
  700. ppu_log('writeentry, id='+entryid_name(entry.id)+' nr='+entry_name(entry.nr)+' size='+tostr(entry.size));
  701. ppu_log('entrystart');
  702. {$endif}
  703. readdata(entry,sizeof(tentry));
  704. if change_endian then
  705. entry.size:=swapendian(entry.size);
  706. entrystart:=bufstart+bufidx;
  707. entryidx:=0;
  708. {$ifdef generic_cpu}
  709. has_more:=false;
  710. {$endif not generic_cpu}
  711. if not(entry.id in [mainentryid,subentryid]) then
  712. begin
  713. readentry:=iberror;
  714. error:=true;
  715. exit;
  716. end;
  717. readentry:=entry.nr;
  718. end;
  719. function tentryfile.endofentry:boolean;
  720. begin
  721. {$ifdef generic_cpu}
  722. endofentry:=(entryidx=entry.size);
  723. {$else not generic_cpu}
  724. endofentry:=(entryidx>=entry.size);
  725. {$endif not generic_cpu}
  726. end;
  727. function tentryfile.entrysize:longint;
  728. begin
  729. entrysize:=entry.size;
  730. end;
  731. function tentryfile.entryleft:longint;
  732. begin
  733. entryleft:=entry.size-entryidx;
  734. end;
  735. procedure tentryfile.getdatabuf(out b;len:integer;out res:integer);
  736. begin
  737. if entryidx+len>entry.size then
  738. res:=entry.size-entryidx
  739. else
  740. res:=len;
  741. readdata(b,res);
  742. inc(entryidx,res);
  743. end;
  744. procedure tentryfile.getdata(out b;len:integer);
  745. begin
  746. if entryidx+len>entry.size then
  747. begin
  748. error:=true;
  749. exit;
  750. end;
  751. readdata(b,len);
  752. inc(entryidx,len);
  753. end;
  754. function tentryfile.getbyte:byte;
  755. begin
  756. if entryidx>=entry.size then
  757. begin
  758. error:=true;
  759. result:=0;
  760. exit;
  761. end;
  762. {$ifdef DEBUG_PPU}
  763. ppu_log('putbyte');
  764. inc_log_level;
  765. {$endif}
  766. if bufidx<bufsize then
  767. begin
  768. result:=pbyte(@buf[bufidx])^;
  769. inc(bufidx);
  770. end
  771. else
  772. readdata(result,1);
  773. {$ifdef DEBUG_PPU}
  774. ppu_log_val(tostr(result));
  775. dec_log_level;
  776. {$endif}
  777. inc(entryidx);
  778. end;
  779. function tentryfile.getword:word;
  780. begin
  781. if entryidx+2>entry.size then
  782. begin
  783. error:=true;
  784. result:=0;
  785. exit;
  786. end;
  787. {$ifdef DEBUG_PPU}
  788. ppu_log('putword');
  789. inc_log_level;
  790. {$endif}
  791. if bufsize-bufidx>=sizeof(word) then
  792. begin
  793. result:=Unaligned(pword(@buf[bufidx])^);
  794. inc(bufidx,sizeof(word));
  795. end
  796. else
  797. readdata(result,sizeof(word));
  798. if change_endian then
  799. result:=swapendian(result);
  800. {$ifdef DEBUG_PPU}
  801. ppu_log_val(tostr(result));
  802. dec_log_level;
  803. {$endif}
  804. inc(entryidx,2);
  805. end;
  806. function tentryfile.getlongint:longint;
  807. begin
  808. if entryidx+4>entry.size then
  809. begin
  810. error:=true;
  811. result:=0;
  812. exit;
  813. end;
  814. {$ifdef DEBUG_PPU}
  815. ppu_log('putlongint');
  816. inc_log_level;
  817. {$endif}
  818. if bufsize-bufidx>=sizeof(longint) then
  819. begin
  820. result:=Unaligned(plongint(@buf[bufidx])^);
  821. inc(bufidx,sizeof(longint));
  822. end
  823. else
  824. readdata(result,sizeof(longint));
  825. if change_endian then
  826. result:=swapendian(result);
  827. {$ifdef DEBUG_PPU}
  828. ppu_log_val(tostr(result));
  829. dec_log_level;
  830. {$endif}
  831. inc(entryidx,4);
  832. end;
  833. function tentryfile.getdword:dword;
  834. begin
  835. if entryidx+4>entry.size then
  836. begin
  837. error:=true;
  838. result:=0;
  839. exit;
  840. end;
  841. {$ifdef DEBUG_PPU}
  842. ppu_log('putdword');
  843. inc_log_level;
  844. {$endif}
  845. if bufsize-bufidx>=sizeof(dword) then
  846. begin
  847. result:=Unaligned(pdword(@buf[bufidx])^);
  848. inc(bufidx,sizeof(longint));
  849. end
  850. else
  851. readdata(result,sizeof(dword));
  852. if change_endian then
  853. result:=swapendian(result);
  854. {$ifdef DEBUG_PPU}
  855. ppu_log_val(tostr(result));
  856. dec_log_level;
  857. {$endif}
  858. inc(entryidx,4);
  859. end;
  860. function tentryfile.getint64:int64;
  861. begin
  862. if entryidx+8>entry.size then
  863. begin
  864. error:=true;
  865. result:=0;
  866. exit;
  867. end;
  868. {$ifdef DEBUG_PPU}
  869. ppu_log('putint64');
  870. inc_log_level;
  871. {$endif}
  872. if bufsize-bufidx>=sizeof(int64) then
  873. begin
  874. result:=Unaligned(pint64(@buf[bufidx])^);
  875. inc(bufidx,sizeof(int64));
  876. end
  877. else
  878. readdata(result,sizeof(int64));
  879. if change_endian then
  880. result:=swapendian(result);
  881. {$ifdef DEBUG_PPU}
  882. ppu_log_val(tostr(result));
  883. dec_log_level;
  884. {$endif}
  885. inc(entryidx,8);
  886. end;
  887. function tentryfile.getqword:qword;
  888. begin
  889. if entryidx+8>entry.size then
  890. begin
  891. error:=true;
  892. result:=0;
  893. exit;
  894. end;
  895. {$ifdef DEBUG_PPU}
  896. ppu_log('putqword');
  897. inc_log_level;
  898. {$endif}
  899. if bufsize-bufidx>=sizeof(qword) then
  900. begin
  901. result:=Unaligned(pqword(@buf[bufidx])^);
  902. inc(bufidx,sizeof(qword));
  903. end
  904. else
  905. readdata(result,sizeof(qword));
  906. if change_endian then
  907. result:=swapendian(result);
  908. {$ifdef DEBUG_PPU}
  909. ppu_log_val(tostr(result));
  910. dec_log_level;
  911. {$endif}
  912. inc(entryidx,8);
  913. end;
  914. function tentryfile.getaint:{$ifdef generic_cpu}int64{$else}aint{$endif};
  915. {$ifdef generic_cpu}
  916. var
  917. header : pentryheader;
  918. {$endif generic_cpu}
  919. begin
  920. {$ifdef DEBUG_PPU}
  921. ppu_log('putaint');
  922. inc_log_level;
  923. {$endif}
  924. {$ifdef generic_cpu}
  925. header:=getheaderaddr;
  926. if CpuAluBitSize[tsystemcpu(header^.cpu)]=64 then
  927. result:=getint64
  928. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=32 then
  929. result:=getlongint
  930. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=16 then
  931. result:=smallint(getword)
  932. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=8 then
  933. result:=shortint(getbyte)
  934. else
  935. begin
  936. error:=true;
  937. result:=0;
  938. end;
  939. {$else not generic_cpu}
  940. case sizeof(aint) of
  941. 8: result:=getint64;
  942. 4: result:=getlongint;
  943. 2: result:=smallint(getword);
  944. 1: result:=shortint(getbyte);
  945. else
  946. begin
  947. RaiseAssertion(2019041801);
  948. result:=0;
  949. end;
  950. end;
  951. {$endif not generic_cpu}
  952. {$ifdef DEBUG_PPU}
  953. ppu_log_val(tostr(result));
  954. dec_log_level;
  955. {$endif}
  956. end;
  957. function tentryfile.getasizeint:{$ifdef generic_cpu}int64{$else}asizeint{$endif};
  958. {$ifdef generic_cpu}
  959. var
  960. header : pentryheader;
  961. {$endif generic_cpu}
  962. begin
  963. {$ifdef DEBUG_PPU}
  964. ppu_log('putasizeint');
  965. inc_log_level;
  966. {$endif}
  967. {$ifdef generic_cpu}
  968. header:=getheaderaddr;
  969. if CpuAddrBitSize[tsystemcpu(header^.cpu)]=64 then
  970. result:=getint64
  971. else if CpuAddrBitSize[tsystemcpu(header^.cpu)]=32 then
  972. result:=getlongint
  973. else if CpuAddrBitSize[tsystemcpu(header^.cpu)]=16 then
  974. begin
  975. { result:=smallint(getword);
  976. would have been logical, but it contradicts
  977. definition of asizeint in globtype unit,
  978. which uses 32-bit lngint type even for 16-bit
  979. address size, to be able to cope with
  980. I8086 seg:ofs huge addresses }
  981. result:=getlongint;
  982. end
  983. else
  984. begin
  985. error:=true;
  986. result:=0;
  987. end;
  988. {$else not generic_cpu}
  989. case sizeof(asizeint) of
  990. 8: result:=asizeint(getint64);
  991. 4: result:=asizeint(getlongint);
  992. 2: result:=asizeint(getword);
  993. 1: result:=asizeint(getbyte);
  994. else
  995. begin
  996. RaiseAssertion(2019041802);
  997. result:=0;
  998. end;
  999. end;
  1000. {$endif not generic_cpu}
  1001. {$ifdef DEBUG_PPU}
  1002. ppu_log_val(tostr(result));
  1003. dec_log_level;
  1004. {$endif}
  1005. end;
  1006. function tentryfile.getpuint:{$ifdef generic_cpu}qword{$else}puint{$endif};
  1007. {$ifdef generic_cpu}
  1008. var
  1009. header : pentryheader;
  1010. {$endif generic_cpu}
  1011. begin
  1012. {$ifdef DEBUG_PPU}
  1013. ppu_log('putpuint');
  1014. inc_log_level;
  1015. {$endif}
  1016. {$ifdef generic_cpu}
  1017. header:=getheaderaddr;
  1018. if CpuAddrBitSize[tsystemcpu(header^.cpu)]=64 then
  1019. result:=getqword
  1020. else if CpuAddrBitSize[tsystemcpu(header^.cpu)]=32 then
  1021. result:=getdword
  1022. else if CpuAddrBitSize[tsystemcpu(header^.cpu)]=16 then
  1023. result:=getword
  1024. else
  1025. begin
  1026. error:=true;
  1027. result:=0;
  1028. end;
  1029. {$else not generic_cpu}
  1030. case sizeof(puint) of
  1031. 8: result:=getqword;
  1032. 4: result:=getdword;
  1033. 2: result:=getword;
  1034. 1: result:=getbyte;
  1035. else
  1036. begin
  1037. RaiseAssertion(2019041803);
  1038. result:=0;
  1039. end;
  1040. end;
  1041. {$endif not generic_cpu}
  1042. {$ifdef DEBUG_PPU}
  1043. ppu_log_val(tostr(result));
  1044. dec_log_level;
  1045. {$endif}
  1046. end;
  1047. function tentryfile.getptruint:{$ifdef generic_cpu}qword{$else}TConstPtrUInt{$endif};
  1048. {$ifdef generic_cpu}
  1049. var
  1050. header : pentryheader;
  1051. {$endif generic_cpu}
  1052. begin
  1053. {$ifdef DEBUG_PPU}
  1054. ppu_log('putptruint');
  1055. inc_log_level;
  1056. {$endif}
  1057. {$ifdef generic_cpu}
  1058. header:=getheaderaddr;
  1059. if CpuAddrBitSize[tsystemcpu(header^.cpu)]=64 then
  1060. result:=getqword
  1061. else result:=getdword;
  1062. {$else not generic_cpu}
  1063. {$if sizeof(TConstPtrUInt)=8}
  1064. result:=tconstptruint(getint64);
  1065. {$else}
  1066. result:=TConstPtrUInt(getlongint);
  1067. {$endif}
  1068. {$endif not generic_cpu}
  1069. {$ifdef DEBUG_PPU}
  1070. ppu_log_val(tostr(result));
  1071. dec_log_level;
  1072. {$endif}
  1073. end;
  1074. function tentryfile.getaword:{$ifdef generic_cpu}qword{$else}aword{$endif};
  1075. {$ifdef generic_cpu}
  1076. var
  1077. header : pentryheader;
  1078. {$endif generic_cpu}
  1079. begin
  1080. {$ifdef DEBUG_PPU}
  1081. ppu_log('putaword');
  1082. inc_log_level;
  1083. {$endif}
  1084. {$ifdef generic_cpu}
  1085. header:=getheaderaddr;
  1086. if CpuAluBitSize[tsystemcpu(header^.cpu)]=64 then
  1087. result:=getqword
  1088. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=32 then
  1089. result:=getdword
  1090. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=16 then
  1091. result:=getword
  1092. else if CpuAluBitSize[tsystemcpu(header^.cpu)]=8 then
  1093. result:=getbyte
  1094. else
  1095. begin
  1096. error:=true;
  1097. result:=0;
  1098. end;
  1099. {$else not generic_cpu}
  1100. case sizeof(aword) of
  1101. 8: result:=getqword;
  1102. 4: result:=getdword;
  1103. 2: result:=getword;
  1104. 1: result:=getbyte;
  1105. else
  1106. begin
  1107. RaiseAssertion(2019041804);
  1108. result:=0;
  1109. end;
  1110. end;
  1111. {$endif not generic_cpu}
  1112. {$ifdef DEBUG_PPU}
  1113. ppu_log_val(tostr(result));
  1114. dec_log_level;
  1115. {$endif}
  1116. end;
  1117. {$ifdef FPC_SOFT_FPUX80}
  1118. { i8086,i386 and x86_64 normally have 80bit float type for
  1119. entryreal, but this is not supported
  1120. on CPUs without 80bit floats.
  1121. Special code is required to handle this. }
  1122. const
  1123. sizeof_floatx80 = 10;
  1124. type
  1125. floatx80_byte_array=array[0..sizeof_floatx80-1] of byte;
  1126. pentryreal=^entryreal;
  1127. function swapendian_floatx80entryreal(d:floatx80_byte_array):floatx80_byte_array;
  1128. var
  1129. i:0..sizeof(d)-1;
  1130. begin
  1131. for i:=low(floatx80_byte_array) to high(floatx80_byte_array) do
  1132. result[i]:=d[high(floatx80_byte_array)-i];
  1133. end;
  1134. {$endif}
  1135. function tentryfile.getrealsize(sizeofreal : longint):entryreal;
  1136. var
  1137. e : entryreal;
  1138. d : double;
  1139. di : qword;{ integer of same size as double }
  1140. s : single;
  1141. si : dword; { integer of same size as single }
  1142. {$ifdef FPC_SOFT_FPUX80}
  1143. floatx80_ba : floatx80_byte_array;
  1144. floatx80_e: floatx80;
  1145. high : word;
  1146. qlow : qword;
  1147. f64 : float64;
  1148. i:byte;
  1149. {$endif}
  1150. begin
  1151. {$ifdef FPC_SOFT_FPUX80}
  1152. if sizeofreal=sizeof(floatx80_byte_array) then
  1153. begin
  1154. {$ifdef DEBUG_PPU}
  1155. ppu_log('getrealsize(sizeofreal='+tostr(sizeofreal)+')='));
  1156. inc_log_level;
  1157. {$endif}
  1158. if entryidx+sizeof(floatx80_e)>entry.size then
  1159. begin
  1160. error:=true;
  1161. result:=0;
  1162. {$ifdef DEBUG_PPU}
  1163. ppu_log_val(realtostr(result));
  1164. dec_log_level;
  1165. {$endif}
  1166. exit;
  1167. end;
  1168. readdata(floatx80_ba,sizeof(floatx80_ba));
  1169. if change_endian then
  1170. floatx80_ba:=swapendian_floatx80entryreal(floatx80_ba);
  1171. {$ifdef FPC_BIG_ENDIAN}
  1172. floatx80_e.high:=pword(@floatx80_ba[0])^;
  1173. floatx80_e.low:=pqword(@floatx80_ba[8])^;
  1174. {$else}
  1175. floatx80_e.high:=pword(@floatx80_ba[8])^;
  1176. floatx80_e.low:=pqword(@floatx80_ba[0])^;
  1177. {$endif}
  1178. f64:=floatx80_to_float64(floatx80_e);
  1179. result:=pentryreal(@f64)^;
  1180. inc(entryidx,sizeof(floatx80_ba));
  1181. {$ifdef DEBUG_PPU}
  1182. ppu_log_val(realtostr(result));
  1183. dec_log_level;
  1184. {$endif}
  1185. exit;
  1186. end;
  1187. {$endif}
  1188. if sizeofreal=sizeof(e) then
  1189. begin
  1190. {$ifdef DEBUG_PPU}
  1191. ppu_log('getrealsize(sizeofreal='+tostr(sizeofreal)+')='));
  1192. inc_log_level;
  1193. {$endif}
  1194. if entryidx+sizeof(e)>entry.size then
  1195. begin
  1196. error:=true;
  1197. result:=0;
  1198. {$ifdef DEBUG_PPU}
  1199. ppu_log_val(realtostr(result));
  1200. dec_log_level;
  1201. {$endif}
  1202. exit;
  1203. end;
  1204. readdata(e,sizeof(e));
  1205. if change_endian then
  1206. result:=swapendian_entryreal(e)
  1207. else
  1208. result:=e;
  1209. inc(entryidx,sizeof(e));
  1210. {$ifdef DEBUG_PPU}
  1211. ppu_log_val(realtostr(result));
  1212. dec_log_level;
  1213. {$endif}
  1214. exit;
  1215. end;
  1216. if sizeofreal=sizeof(d) then
  1217. begin
  1218. {$ifdef DEBUG_PPU}
  1219. ppu_log('getrealsize(sizeofreal='+tostr(sizeofreal)+')='));
  1220. inc_log_level;
  1221. {$endif}
  1222. if entryidx+sizeof(d)>entry.size then
  1223. begin
  1224. error:=true;
  1225. result:=0;
  1226. {$ifdef DEBUG_PPU}
  1227. ppu_log_val(realtostr(result));
  1228. dec_log_level;
  1229. {$endif}
  1230. exit;
  1231. end;
  1232. readdata(d,sizeof(d));
  1233. if change_endian then
  1234. begin
  1235. di:=swapendian(pqword(@d)^);
  1236. d:=pdouble(@di)^;
  1237. end;
  1238. result:=d;
  1239. inc(entryidx,sizeof(d));
  1240. result:=d;
  1241. {$ifdef DEBUG_PPU}
  1242. ppu_log_val(realtostr(result));
  1243. dec_log_level;
  1244. {$endif}
  1245. exit;
  1246. end;
  1247. if sizeofreal=sizeof(s) then
  1248. begin
  1249. {$ifdef DEBUG_PPU}
  1250. ppu_log('getrealsize(sizeofreal='+tostr(sizeofreal)+')='));
  1251. inc_log_level;
  1252. {$endif}
  1253. if entryidx+sizeof(s)>entry.size then
  1254. begin
  1255. error:=true;
  1256. result:=0;
  1257. {$ifdef DEBUG_PPU}
  1258. ppu_log_val(realtostr(result));
  1259. dec_log_level;
  1260. {$endif}
  1261. exit;
  1262. end;
  1263. readdata(s,sizeof(s));
  1264. if change_endian then
  1265. begin
  1266. si:=swapendian(pdword(@s)^);
  1267. s:=psingle(@si)^;
  1268. end;
  1269. result:=s;
  1270. inc(entryidx,sizeof(s));
  1271. result:=s;
  1272. {$ifdef DEBUG_PPU}
  1273. ppu_log_val(realtostr(result));
  1274. dec_log_level;
  1275. {$endif}
  1276. exit;
  1277. end;
  1278. error:=true;
  1279. result:=0.0;
  1280. end;
  1281. function tentryfile.getreal:entryreal;
  1282. var
  1283. d : entryreal;
  1284. hd : double;
  1285. begin
  1286. if target_info.system=system_x86_64_win64 then
  1287. begin
  1288. hd:=getrealsize(sizeof(hd));
  1289. getreal:=hd;
  1290. end
  1291. {$ifdef FPC_SOFT_FPUX80}
  1292. else
  1293. if target_info.cpu in [cpu_i8086, cpu_i386, cpu_x86_64] then
  1294. begin
  1295. d:=getrealsize(sizeof(floatx80_byte_array));
  1296. getreal:=d;
  1297. end
  1298. {$endif def FPC_SOFT_FPUX80}
  1299. else
  1300. begin
  1301. d:=getrealsize(sizeof(d));
  1302. getreal:=d;
  1303. end;
  1304. end;
  1305. function tentryfile.getboolean:boolean;
  1306. begin
  1307. {$ifdef DEBUG_PPU}
  1308. ppu_log('putboolean');
  1309. {$endif}
  1310. result:=boolean(getbyte);
  1311. end;
  1312. function tentryfile.getstring:string;
  1313. begin
  1314. result[0]:=chr(getbyte);
  1315. {$ifdef DEBUG_PPU}
  1316. ppu_log('putstring,size='+tostr(length(result)+1));
  1317. inc_log_level;
  1318. {$endif}
  1319. if entryidx+length(result)>entry.size then
  1320. begin
  1321. error:=true;
  1322. exit;
  1323. end;
  1324. ReadData(result[1],length(result));
  1325. {$ifdef DEBUG_PPU}
  1326. ppu_log_val(result);
  1327. dec_log_level;
  1328. {$endif}
  1329. inc(entryidx,length(result));
  1330. end;
  1331. function tentryfile.getpshortstring:pshortstring;
  1332. var
  1333. len: char;
  1334. begin
  1335. result:=nil;
  1336. len:=chr(getbyte);
  1337. {$ifdef DEBUG_PPU}
  1338. ppu_log('putstring,size='+tostr(ord(len)+1));
  1339. inc_log_level;
  1340. {$endif}
  1341. if entryidx+ord(len)>entry.size then
  1342. begin
  1343. error:=true;
  1344. exit;
  1345. end;
  1346. getmem(result,ord(len)+1);
  1347. result^[0]:=len;
  1348. ReadData(result^[1],ord(len));
  1349. inc(entryidx,ord(len));
  1350. {$ifdef DEBUG_PPU}
  1351. ppu_log_val(result^);
  1352. dec_log_level;
  1353. {$endif}
  1354. end;
  1355. function tentryfile.getansistring:ansistring;
  1356. var
  1357. len: longint;
  1358. begin
  1359. {$ifdef DEBUG_PPU}
  1360. ppu_log('putansistring');
  1361. inc_log_level;
  1362. {$endif}
  1363. len:=getlongint;
  1364. if entryidx+len>entry.size then
  1365. begin
  1366. error:=true;
  1367. result:='';
  1368. exit;
  1369. end;
  1370. setlength(result,len);
  1371. if len>0 then
  1372. getdata(result[1],len);
  1373. {$ifdef DEBUG_PPU}
  1374. ppu_log_val(result);
  1375. dec_log_level;
  1376. {$endif}
  1377. end;
  1378. procedure tentryfile.getset(out arr: array of byte);
  1379. var
  1380. i : longint;
  1381. begin
  1382. {$ifdef DEBUG_PPU}
  1383. ppu_log('putset');
  1384. inc_log_level;
  1385. {$endif}
  1386. getdata(arr,sizeof(arr));
  1387. if change_endian then
  1388. for i:=low(arr) to high(arr) do
  1389. arr[i]:=reverse_byte(arr[i]);
  1390. {$ifdef DEBUG_PPU}
  1391. for i:=low(arr) to high(arr) do
  1392. ppu_log_val('byte['+tostr(i)+']=$'+hexstr(arr[i],2));
  1393. dec_log_level;
  1394. {$endif}
  1395. end;
  1396. function tentryfile.skipuntilentry(untilb:byte):boolean;
  1397. var
  1398. b : byte;
  1399. begin
  1400. {$ifdef DEBUG_PPU}
  1401. ppu_log('skipuntilentry '+tostr(untilb));
  1402. {$endif}
  1403. repeat
  1404. b:=readentry;
  1405. until (b in [ibend,iberror]) or ((b=untilb) and (entry.id=mainentryid));
  1406. skipuntilentry:=(b=untilb);
  1407. end;
  1408. {*****************************************************************************
  1409. tentryfile Writing
  1410. *****************************************************************************}
  1411. function tentryfile.createfile:boolean;
  1412. var
  1413. ok: boolean;
  1414. strm : TCStream;
  1415. begin
  1416. createfile:=false;
  1417. strm:=nil;
  1418. if outputallowed then
  1419. begin
  1420. {$ifdef MACOS}
  1421. {FPas is FreePascal's creator code on MacOS. See systems/mac_crea.txt}
  1422. SetDefaultMacOSCreator('FPas');
  1423. SetDefaultMacOSFiletype('FPPU');
  1424. {$endif}
  1425. ok:=false;
  1426. try
  1427. strm:=CFileStreamClass.Create(fname,fmCreate);
  1428. ok:=true;
  1429. except
  1430. end;
  1431. {$ifdef MACOS}
  1432. SetDefaultMacOSCreator('MPS ');
  1433. SetDefaultMacOSFiletype('TEXT');
  1434. {$endif}
  1435. if not ok then
  1436. exit;
  1437. end;
  1438. createfile:=createstream(strm);
  1439. fisfile:=result;
  1440. end;
  1441. function tentryfile.createstream(strm:TCStream):boolean;
  1442. begin
  1443. createstream:=false;
  1444. if outputallowed then
  1445. begin
  1446. f:=strm;
  1447. mode:=2;
  1448. {write header for sure}
  1449. f.Write(getheaderaddr^,getheadersize);
  1450. end;
  1451. bufsize:=entryfilebufsize;
  1452. bufstart:=getheadersize;
  1453. bufidx:=0;
  1454. {reset}
  1455. resetfile;
  1456. error:=false;
  1457. size:=0;
  1458. entrytyp:=mainentryid;
  1459. {$ifdef DEBUG_PPU}
  1460. {$push}
  1461. {$I-}
  1462. assign(flog,fname+'.debug-write-log');
  1463. rewrite(flog);
  1464. if InOutRes=0 then
  1465. flog_open:=true;
  1466. {$pop}
  1467. {$endif DEBUG_PPU}
  1468. {start}
  1469. newentry;
  1470. createstream:=true;
  1471. end;
  1472. procedure tentryfile.writebuf;
  1473. begin
  1474. if outputallowed and
  1475. (bufidx <> 0) then
  1476. f.Write(buf^,bufidx);
  1477. inc(bufstart,bufidx);
  1478. bufidx:=0;
  1479. end;
  1480. procedure tentryfile.writedata(const b;len:integer);
  1481. var
  1482. p : pchar;
  1483. left,
  1484. idx : integer;
  1485. {$ifdef DEBUG_PPU}
  1486. start_len : integer;
  1487. {$endif}
  1488. begin
  1489. if not outputallowed then
  1490. exit;
  1491. {$ifdef DEBUG_PPU}
  1492. start_len:=len;
  1493. {$endif}
  1494. p:=pchar(@b);
  1495. idx:=0;
  1496. while len>0 do
  1497. begin
  1498. left:=bufsize-bufidx;
  1499. if len>left then
  1500. begin
  1501. move(p[idx],buf[bufidx],left);
  1502. dec(len,left);
  1503. inc(idx,left);
  1504. inc(bufidx,left);
  1505. writebuf;
  1506. end
  1507. else
  1508. begin
  1509. move(p[idx],buf[bufidx],len);
  1510. inc(bufidx,len);
  1511. {$ifdef DEBUG_PPU}
  1512. len:=0;
  1513. {$else}
  1514. exit;
  1515. {$endif}
  1516. end;
  1517. end;
  1518. {$ifdef DEBUG_PPU}
  1519. if (start_len > 0) and (ppu_log_level <= 0) then
  1520. begin
  1521. ppu_log('writedata, length='+tostr(start_len)+' level='+tostr(ppu_log_level));
  1522. for idx:=0 to start_len-1 do
  1523. ppu_log_val('p['+tostr(idx)+']=$'+hexstr(byte(p[idx]),2));
  1524. end;
  1525. {$endif DEBUG_PPU}
  1526. end;
  1527. procedure tentryfile.newentry;
  1528. begin
  1529. with entry do
  1530. begin
  1531. id:=entrytyp;
  1532. nr:=ibend;
  1533. size:=0;
  1534. end;
  1535. {Reset Entry State}
  1536. entryidx:=0;
  1537. entrybufstart:=bufstart;
  1538. entrystart:=bufstart+bufidx;
  1539. {$ifdef DEBUG_PPU}
  1540. ppu_log('entrystart');
  1541. {$endif}
  1542. {Alloc in buffer}
  1543. writedata(entry,sizeof(tentry));
  1544. end;
  1545. procedure tentryfile.writeentry(ibnr:byte);
  1546. var
  1547. opos : integer;
  1548. begin
  1549. {create entry}
  1550. entry.id:=entrytyp;
  1551. entry.nr:=ibnr;
  1552. entry.size:=entryidx;
  1553. {it's already been sent to disk ?}
  1554. if entrybufstart<>bufstart then
  1555. begin
  1556. if outputallowed then
  1557. begin
  1558. {flush to be sure}
  1559. WriteBuf;
  1560. {write entry}
  1561. opos:=f.Position;
  1562. f.Position:=entrystart;
  1563. f.write(entry,sizeof(tentry));
  1564. f.Position:=opos;
  1565. end;
  1566. entrybufstart:=bufstart;
  1567. end
  1568. else
  1569. move(entry,buf[entrystart-bufstart],sizeof(entry));
  1570. {$ifdef DEBUG_PPU}
  1571. ppu_log('writeentry, id='+entryid_name(entry.id)+' nr='+entry_name(entry.nr)+' size='+tostr(entry.size));
  1572. {$endif}
  1573. {Add New Entry, which is ibend by default}
  1574. entrystart:=bufstart+bufidx; {next entry position}
  1575. newentry;
  1576. end;
  1577. procedure tentryfile.putdata(const b;len:integer);
  1578. begin
  1579. if outputallowed then
  1580. writedata(b,len);
  1581. inc(entryidx,len);
  1582. end;
  1583. procedure tentryfile.putbyte(b:byte);
  1584. begin
  1585. {$ifdef DEBUG_PPU}
  1586. ppu_log('putbyte');
  1587. inc_log_level;
  1588. ppu_log_val(tostr(b));
  1589. {$endif}
  1590. putdata(b,1);
  1591. {$ifdef DEBUG_PPU}
  1592. dec_log_level;
  1593. {$endif}
  1594. end;
  1595. procedure tentryfile.putword(w:word);
  1596. begin
  1597. {$ifdef DEBUG_PPU}
  1598. ppu_log('putword');
  1599. inc_log_level;
  1600. ppu_log_val(tostr(w));
  1601. {$endif}
  1602. putdata(w,2);
  1603. {$ifdef DEBUG_PPU}
  1604. dec_log_level;
  1605. {$endif}
  1606. end;
  1607. procedure tentryfile.putdword(w:dword);
  1608. begin
  1609. {$ifdef DEBUG_PPU}
  1610. ppu_log('putdword');
  1611. inc_log_level;
  1612. ppu_log_val(tostr(w));
  1613. {$endif}
  1614. putdata(w,4);
  1615. {$ifdef DEBUG_PPU}
  1616. dec_log_level;
  1617. {$endif}
  1618. end;
  1619. procedure tentryfile.putlongint(l:longint);
  1620. begin
  1621. {$ifdef DEBUG_PPU}
  1622. ppu_log('putlongint');
  1623. inc_log_level;
  1624. ppu_log_val(tostr(l));
  1625. {$endif}
  1626. putdata(l,4);
  1627. {$ifdef DEBUG_PPU}
  1628. dec_log_level;
  1629. {$endif}
  1630. end;
  1631. procedure tentryfile.putint64(i:int64);
  1632. begin
  1633. {$ifdef DEBUG_PPU}
  1634. ppu_log('putint64');
  1635. inc_log_level;
  1636. ppu_log_val(tostr(i));
  1637. {$endif}
  1638. putdata(i,8);
  1639. {$ifdef DEBUG_PPU}
  1640. dec_log_level;
  1641. {$endif}
  1642. end;
  1643. procedure tentryfile.putqword(q:qword);
  1644. begin
  1645. {$ifdef DEBUG_PPU}
  1646. ppu_log('putqword');
  1647. inc_log_level;
  1648. ppu_log_val(tostr(q));
  1649. {$endif}
  1650. putdata(q,sizeof(qword));
  1651. {$ifdef DEBUG_PPU}
  1652. dec_log_level;
  1653. {$endif}
  1654. end;
  1655. procedure tentryfile.putaint(i:aint);
  1656. begin
  1657. {$ifdef DEBUG_PPU}
  1658. ppu_log('putaint');
  1659. inc_log_level;
  1660. case sizeof(aint) of
  1661. 8: ppu_log('putint64');
  1662. 4: ppu_log('putlongint');
  1663. 2: ppu_log('putword');
  1664. 1: ppu_log('putbyte');
  1665. end;
  1666. ppu_log_val(tostr(i));
  1667. {$endif}
  1668. putdata(i,sizeof(aint));
  1669. {$ifdef DEBUG_PPU}
  1670. dec_log_level;
  1671. {$endif}
  1672. end;
  1673. procedure tentryfile.putasizeint(i: asizeint);
  1674. begin
  1675. {$ifdef DEBUG_PPU}
  1676. ppu_log('putasizeint');
  1677. inc_log_level;
  1678. case sizeof(asizeint) of
  1679. 8: ppu_log('putint64');
  1680. 4: ppu_log('putlongint');
  1681. 2: ppu_log('putword');
  1682. 1: ppu_log('putbyte');
  1683. end;
  1684. ppu_log_val(tostr(i));
  1685. {$endif}
  1686. putdata(i,sizeof(asizeint));
  1687. {$ifdef DEBUG_PPU}
  1688. dec_log_level;
  1689. {$endif}
  1690. end;
  1691. procedure tentryfile.putpuint(i : puint);
  1692. begin
  1693. {$ifdef DEBUG_PPU}
  1694. ppu_log('putpuint');
  1695. inc_log_level;
  1696. ppu_log_val(tostr(i));
  1697. {$endif}
  1698. putdata(i,sizeof(puint));
  1699. {$ifdef DEBUG_PPU}
  1700. dec_log_level;
  1701. {$endif}
  1702. end;
  1703. procedure tentryfile.putptruint(v:TConstPtrUInt);
  1704. begin
  1705. {$ifdef DEBUG_PPU}
  1706. ppu_log('putptruint');
  1707. inc_log_level;
  1708. {$endif}
  1709. {$if sizeof(TConstPtrUInt)=8}
  1710. putint64(int64(v));
  1711. {$else}
  1712. putlongint(longint(v));
  1713. {$endif}
  1714. {$ifdef DEBUG_PPU}
  1715. dec_log_level;
  1716. {$endif}
  1717. end;
  1718. procedure tentryfile.putaword(i:aword);
  1719. begin
  1720. {$ifdef DEBUG_PPU}
  1721. ppu_log('putaword');
  1722. inc_log_level;
  1723. ppu_log_val(tostr(i));
  1724. {$endif}
  1725. putdata(i,sizeof(aword));
  1726. {$ifdef DEBUG_PPU}
  1727. dec_log_level;
  1728. {$endif}
  1729. end;
  1730. procedure tentryfile.putreal(d:entryreal);
  1731. var
  1732. hd : double;
  1733. {$ifdef FPC_SOFT_FPUX80}
  1734. floatx80_ba : floatx80_byte_array;
  1735. floatx80_e : floatx80;
  1736. f64 : float64;
  1737. i:byte;
  1738. {$endif}
  1739. begin
  1740. if target_info.system=system_x86_64_win64 then
  1741. begin
  1742. {$ifdef DEBUG_PPU}
  1743. ppu_log('putreal,size='+tostr(sizeof(hd)));
  1744. inc_log_level;
  1745. ppu_log_val(realtostr(d));
  1746. {$endif}
  1747. hd:=d;
  1748. putdata(hd,sizeof(hd));
  1749. end
  1750. {$ifdef FPC_SOFT_FPUX80}
  1751. else if target_info.cpu in [cpu_i8086, cpu_i386, cpu_x86_64] then
  1752. begin
  1753. {$ifdef DEBUG_PPU}
  1754. ppu_log('putreal,size='+tostr(sizeof(floatx80_e)));
  1755. inc_log_level;
  1756. {$endif}
  1757. f64:=float64(d);
  1758. floatx80_e:=float64_to_floatx80(f64);
  1759. {$ifdef FPC_BIG_ENDIAN}
  1760. pword(@floatx80_ba[0])^:=floatx80_e.high;
  1761. pqword(@floatx80_ba[8])^:=floatx80_e.low;
  1762. {$else}
  1763. pword(@floatx80_ba[8])^:=floatx80_e.high;
  1764. pqword(@floatx80_ba[0])^:=floatx80_e.low;
  1765. {$endif}
  1766. putdata(floatx80_ba,sizeof(floatx80_ba));
  1767. end
  1768. {$endif}
  1769. else
  1770. begin
  1771. {$ifdef DEBUG_PPU}
  1772. ppu_log('putreal,size='+tostr(sizeof(d)));
  1773. inc_log_level;
  1774. ppu_log_val(realtostr(d));
  1775. {$endif}
  1776. putdata(d,sizeof(entryreal));
  1777. end;
  1778. {$ifdef DEBUG_PPU}
  1779. dec_log_level;
  1780. {$endif}
  1781. end;
  1782. procedure tentryfile.putboolean(b:boolean);
  1783. begin
  1784. {$ifdef DEBUG_PPU}
  1785. ppu_log('putboolean');
  1786. inc_log_level;
  1787. {$endif}
  1788. putbyte(byte(b));
  1789. {$ifdef DEBUG_PPU}
  1790. dec_log_level;
  1791. {$endif}
  1792. end;
  1793. procedure tentryfile.putstring(const s:string);
  1794. begin
  1795. {$ifdef DEBUG_PPU}
  1796. { The reading method uses getbyte, so fake it here }
  1797. ppu_log('putbyte');
  1798. inc_log_level;
  1799. inc(bufidx);
  1800. ppu_log('putstring,size='+tostr(length(s)+1));
  1801. dec(bufidx);
  1802. ppu_log_val(s);
  1803. {$endif}
  1804. putdata(s,length(s)+1);
  1805. {$ifdef DEBUG_PPU}
  1806. dec_log_level;
  1807. {$endif}
  1808. end;
  1809. procedure tentryfile.putansistring(const s:ansistring);
  1810. var
  1811. len: longint;
  1812. begin
  1813. len:=length(s);
  1814. {$ifdef DEBUG_PPU}
  1815. ppu_log('putansistring');
  1816. inc_log_level;
  1817. ppu_log_val(s);
  1818. {$endif}
  1819. putlongint(len);
  1820. if len>0 then
  1821. putdata(s[1],len);
  1822. {$ifdef DEBUG_PPU}
  1823. dec_log_level;
  1824. {$endif}
  1825. end;
  1826. procedure tentryfile.putset(const arr: array of byte);
  1827. {$ifdef DEBUG_PPU}
  1828. var
  1829. i : byte;
  1830. {$endif}
  1831. begin
  1832. {$ifdef DEBUG_PPU}
  1833. ppu_log('putset');
  1834. inc_log_level;
  1835. {$endif}
  1836. putdata(arr,sizeof(arr));
  1837. {$ifdef DEBUG_PPU}
  1838. for i:=0 to sizeof(arr)-1 do
  1839. ppu_log_val('byte['+tostr(i)+']=$'+hexstr(arr[i],2));
  1840. dec_log_level;
  1841. {$endif}
  1842. end;
  1843. procedure tentryfile.tempclose;
  1844. begin
  1845. if not closed then
  1846. begin
  1847. closepos:=f.Position;
  1848. f.Free;
  1849. f:=nil;
  1850. closed:=true;
  1851. tempclosed:=true;
  1852. end;
  1853. end;
  1854. function tentryfile.tempopen:boolean;
  1855. begin
  1856. tempopen:=false;
  1857. if not closed or not tempclosed then
  1858. exit;
  1859. { MG: not sure, if this is correct
  1860. f.position:=0;
  1861. No, f was freed in tempclose above, we need to
  1862. recreate it. PM 2011/06/06 }
  1863. try
  1864. f:=CFileStreamClass.Create(fname,fmOpenRead);
  1865. except
  1866. exit;
  1867. end;
  1868. closed:=false;
  1869. tempclosed:=false;
  1870. { restore state }
  1871. f.Position:=closepos;
  1872. tempopen:=true;
  1873. end;
  1874. end.