mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-10-31 10:11:27 +01:00 
			
		
		
		
	 7d8d0340b9
			
		
	
	
		7d8d0340b9
		
	
	
	
	
		
			
			Correctly parse the directives DenyPackageUnit and WeakPackageUnit ppu.pas: + add flags uf_packagedeny and uf_packageweak scandir.pas: + new procedure do_moduleflagswitch() which parses a ON/OFF/+/- argument and sets or clears a flag in the current module + new procedure dir_denypackageunit which handles DenyPackageUnit * implement dir_weakpackageunit (and move to the correct location ;) ) * InitScannerDirectives: add dir_denypackageunit handler ........ Respect DenyPackageUnit flag. pmodules.pas, proc_package: * check all contained units that are not already part of a package for their uf_package_deny flag and report an error for each that has it set ........ Do not check whether all units are used as by definition all units of a package are considered as used. pmodules.pas, proc_package: - remove call to current_module.allunitsused ........ Check whether a unit has been implicitely imported in a package. A unit is considered as implicitely imported if it is not part of a required package nor part of the units listed in the contains section. This note is useful (Delphi even provides a dialog in that case) as a package with implicitely imported units /might/ become incompatible with other packages (e.g. if another package includes that unit uses that package and includes that unit explicitely; of course that is the same as if both package included it explicitely, but with the hint one knows where to look). pmodules.pas, proc_package: * while walking the loaded units also check whether any of them not contained in a package was part of the contained units which are the same as the current module's used units ........ Generate CRC for package files pcp.pas, tpcpfile: + new field do_crc which controls CRC generation + override putdata() method to generate CRC when data is written * resetfile: enable do_crc by default ........fppu.pas, tppumodule: * loadfrompackage: mention if a unit is loaded from a package ........ fpkg.pas, tcontainedunit: + new fields offset and size for the PPU data stored inside the PCP fpcp.pas, tpcppackage: * readcontainedunits & addunit: correctly initialize offset and size to 0 ........ Store the modified PPU files directly inside the PCP and thus get finally rid of the .ppl.ppu files. entfile.pas: + new entry type ibpputable pkgutil.pas: * adjust RewritePPU to work on a stream as output instead of a filename fpcp.pas, tpcppackage: + new method writepputable() which writes the offsets and sizes of all contained units (not part of CRC!) + new method writeppudata() which rewrites all contained PPUs directly into the PCP after the ibend entry (Note: the data is written 16 Byte aligned to ease viewing of the PCP and its contained PPUs in a hex editor) + new method readpputable() which reads the offsets and sizes of all contained units + new method getmodulestream() which returns a substream for a contained module * loadpcp: also call readpputable() * writepcp: first write an empty pputable, then finish writing all data that requires the put*/write* methods of the pcpfile, then use writeppudata() to write all PPUs and finally write the correct pputable at the original location fppu.pas, tppumodule: * loadfrompackage: don't read the PPU from a file if it is contained in a package, but using the new tpcppackage.getmodulestream() and tppumodule.openppustream() methods pmodules.pas, proc_package: * don't rewrite the PPUs here pcp.pas: * increase CurrentPCPVersion ........ Fix cycling ........ git-svn-id: trunk@33514 -
		
			
				
	
	
		
			205 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
			
		
		
	
	
			205 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
| {
 | |
|     Copyright (c) 2013-2016 by Free Pascal development team
 | |
| 
 | |
|     Routines to read/write pcp files
 | |
| 
 | |
|     This program is free software; you can redistribute it and/or modify
 | |
|     it under the terms of the GNU General Public License as published by
 | |
|     the Free Software Foundation; either version 2 of the License, or
 | |
|     (at your option) any later version.
 | |
| 
 | |
|     This program is distributed in the hope that it will be useful,
 | |
|     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | |
|     GNU General Public License for more details.
 | |
| 
 | |
|     You should have received a copy of the GNU General Public License
 | |
|     along with this program; if not, write to the Free Software
 | |
|     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 | |
| 
 | |
|  ****************************************************************************
 | |
| }
 | |
| unit pcp;
 | |
| 
 | |
| {$mode objfpc}{$H+}
 | |
| 
 | |
| interface
 | |
| 
 | |
|   uses
 | |
|     cstreams,entfile;
 | |
| 
 | |
|   const
 | |
|     CurrentPCPVersion=3;
 | |
| 
 | |
|   { unit flags }
 | |
|     //uf_init                = $000001; { unit has initialization section }
 | |
|     //uf_finalize            = $000002; { unit has finalization section   }
 | |
|     pf_big_endian          = $000004;
 | |
|   //uf_has_browser         = $000010;
 | |
|     //uf_in_library          = $000020; { is the file in another file than <ppufile>.* ? }
 | |
|     //uf_smart_linked        = $000040; { the ppu can be smartlinked }
 | |
|     //uf_static_linked       = $000080; { the ppu can be linked static }
 | |
|     //uf_shared_linked       = $000100; { the ppu can be linked shared }
 | |
|   //uf_local_browser       = $000200;
 | |
|     //uf_no_link             = $000400; { unit has no .o generated, but can still have external linking! }
 | |
|     //uf_has_resourcestrings = $000800; { unit has resource string section }
 | |
|     pf_little_endian       = $001000;
 | |
| 
 | |
| 
 | |
|   type
 | |
|     tpcpheader=record
 | |
|       common   : tentryheader;
 | |
|       checksum : cardinal; { checksum for this pcpfile }
 | |
|       requiredlistsize, { number of entries for required packages }
 | |
|       ppulistsize : longint; { number of entries for contained PPUs }
 | |
|     end;
 | |
| 
 | |
|     tpcpfile=class(tentryfile)
 | |
|     public
 | |
|       header : tpcpheader;
 | |
|       { crc for the entire package }
 | |
|       crc : cardinal;
 | |
|       do_crc : boolean;
 | |
|     protected
 | |
|       function getheadersize:longint;override;
 | |
|       function getheaderaddr:pentryheader;override;
 | |
|       procedure newheader;override;
 | |
|       function readheader:longint;override;
 | |
|       procedure resetfile;override;
 | |
|     public
 | |
|       procedure writeheader;override;
 | |
|       function checkpcpid:boolean;
 | |
|       procedure putdata(const b;len:integer);override;
 | |
|     end;
 | |
| 
 | |
| implementation
 | |
| 
 | |
| uses
 | |
|   fpccrc;
 | |
| 
 | |
|   { tpcpfile }
 | |
| 
 | |
|   function tpcpfile.getheadersize: longint;
 | |
|     begin
 | |
|       result:=sizeof(tpcpheader);
 | |
|     end;
 | |
| 
 | |
|   function tpcpfile.getheaderaddr: pentryheader;
 | |
|     begin
 | |
|       result:=@header;
 | |
|     end;
 | |
| 
 | |
|   procedure tpcpfile.newheader;
 | |
|     var
 | |
|       s : string;
 | |
|     begin
 | |
|       fillchar(header,sizeof(tpcpheader),0);
 | |
|       str(CurrentPCPVersion,s);
 | |
|       while length(s)<3 do
 | |
|         s:='0'+s;
 | |
|       with header.common do
 | |
|         begin
 | |
|           id[1]:='P';
 | |
|           id[2]:='C';
 | |
|           id[3]:='P';
 | |
|           ver[1]:=s[1];
 | |
|           ver[2]:=s[2];
 | |
|           ver[3]:=s[3];
 | |
|         end;
 | |
|     end;
 | |
| 
 | |
|   function tpcpfile.readheader: longint;
 | |
|     begin
 | |
|       if fsize<sizeof(tpcpheader) then
 | |
|         exit(0);
 | |
|       result:=f.Read(header,sizeof(tpcpheader));
 | |
|       { The header is always stored in little endian order }
 | |
|       { therefore swap if on a big endian machine          }
 | |
|     {$IFDEF ENDIAN_BIG}
 | |
|       header.common.compiler := swapendian(header.common.compiler);
 | |
|       header.common.cpu := swapendian(header.common.cpu);
 | |
|       header.common.target := swapendian(header.common.target);
 | |
|       header.common.flags := swapendian(header.common.flags);
 | |
|       header.common.size := swapendian(header.common.size);
 | |
|       header.checksum := swapendian(header.checksum);
 | |
|       header.requiredlistsize:=swapendian(header.requiredlistsize);
 | |
|       header.ppulistsize:=swapendian(header.ppulistsize);
 | |
|     {$ENDIF}
 | |
|       { the PPU DATA is stored in native order }
 | |
|       if (header.common.flags and pf_big_endian) = pf_big_endian then
 | |
|        Begin
 | |
|     {$IFDEF ENDIAN_LITTLE}
 | |
|          change_endian := TRUE;
 | |
|     {$ELSE}
 | |
|          change_endian := FALSE;
 | |
|     {$ENDIF}
 | |
|        End
 | |
|       else if (header.common.flags and pf_little_endian) = pf_little_endian then
 | |
|        Begin
 | |
|     {$IFDEF ENDIAN_BIG}
 | |
|          change_endian := TRUE;
 | |
|     {$ELSE}
 | |
|          change_endian := FALSE;
 | |
|     {$ENDIF}
 | |
|        End;
 | |
|     end;
 | |
| 
 | |
|   procedure tpcpfile.resetfile;
 | |
|     begin
 | |
|       crc:=0;
 | |
|       do_crc:=true;
 | |
|     end;
 | |
| 
 | |
| 
 | |
|   procedure tpcpfile.writeheader;
 | |
|     var
 | |
|       opos : integer;
 | |
|     begin
 | |
|       { flush buffer }
 | |
|       writebuf;
 | |
|       { update size (w/o header!) in the header }
 | |
|       header.common.size:=bufstart-sizeof(tpcpheader);
 | |
|       { set the endian flag }
 | |
| {$ifndef FPC_BIG_ENDIAN}
 | |
|       header.common.flags:=header.common.flags or pf_little_endian;
 | |
| {$else not FPC_BIG_ENDIAN}
 | |
|       header.common.flags:=header.common.flags or pf_big_endian;
 | |
|       { Now swap the header in the correct endian (always little endian) }
 | |
|       header.common.compiler:=swapendian(header.common.compiler);
 | |
|       header.common.cpu:=swapendian(header.common.cpu);
 | |
|       header.common.target:=swapendian(header.common.target);
 | |
|       header.common.flags:=swapendian(header.common.flags);
 | |
|       header.common.size:=swapendian(header.common.size);
 | |
|       header.checksum:=swapendian(header.checksum);
 | |
|       header.requiredlistsize:=swapendian(header.requiredlistsize);
 | |
|       header.ppulistsize:=swapendian(header.ppulistsize);
 | |
| {$endif not FPC_BIG_ENDIAN}
 | |
|     { write header and restore filepos after it }
 | |
|       opos:=f.Position;
 | |
|       f.Position:=0;
 | |
|       f.Write(header,sizeof(tpcpheader));
 | |
|       f.Position:=opos;
 | |
|   end;
 | |
| 
 | |
| 
 | |
|   function tpcpfile.checkpcpid:boolean;
 | |
|     begin
 | |
|       result:=((Header.common.Id[1]='P') and
 | |
|                 (Header.common.Id[2]='C') and
 | |
|                 (Header.common.Id[3]='P'));
 | |
|     end;
 | |
| 
 | |
| 
 | |
|   procedure tpcpfile.putdata(const b;len:integer);
 | |
|     begin
 | |
|       if do_crc then
 | |
|         begin
 | |
|           crc:=UpdateCrc32(crc,b,len);
 | |
|         end;
 | |
|       inherited putdata(b, len);
 | |
|     end;
 | |
| 
 | |
| 
 | |
| end.
 | |
| 
 |