+ -x option to output all numeric constants as hex constants

git-svn-id: trunk@39870 -
This commit is contained in:
florian 2018-10-06 16:28:19 +00:00
parent 19fa828466
commit 15e656c36e

View File

@ -26,7 +26,8 @@ var
WriteAsciiData, WriteAsciiData,
CompressData, CompressData,
EnCodeData, EnCodeData,
CompileUnit : Boolean; CompileUnit,
WriteHex : Boolean;
Cryptkey : IDEAcryptKey; Cryptkey : IDEAcryptKey;
InStream, InStream,
MemStream, MemStream,
@ -39,6 +40,7 @@ begin
Writeln ('Usage: bin2obj [options] -c constname [infile] '); Writeln ('Usage: bin2obj [options] -c constname [infile] ');
Writeln ('Where options is a combination of : '); Writeln ('Where options is a combination of : ');
Writeln (' -a write asciii data instead of bytes'); Writeln (' -a write asciii data instead of bytes');
Writeln (' -x write numerical values as hexadecimal numbers');
Writeln (' -z compress data.'); Writeln (' -z compress data.');
Writeln (' -e key encrypt data with key (must have 8 characters)'); Writeln (' -e key encrypt data with key (must have 8 characters)');
Writeln (' -o output filename'); Writeln (' -o output filename');
@ -62,13 +64,15 @@ begin
UnitName:=''; UnitName:='';
NeedUnitName:=False; NeedUnitName:=False;
WriteAsciiData:=False; WriteAsciiData:=False;
WriteHex:=False;
Repeat Repeat
c:=GetOpt('ac:e:o:zhu::U::'); c:=GetOpt('ac:e:o:zhu::U::x');
Case C of Case C of
'a' : WriteAsciiData:=True; 'a' : WriteAsciiData:=True;
'c' : ConstName:=OptArg; 'c' : ConstName:=OptArg;
'h','?' : usage; 'h','?' : usage;
'z' : CompressData := True; 'z' : CompressData := True;
'x' : WriteHex := True;
'e' : begin 'e' : begin
EncodeData:=True; EncodeData:=True;
If Length(OptArg)<8 then If Length(OptArg)<8 then
@ -209,13 +213,23 @@ begin
begin begin
MemStream.Read(B,1); MemStream.Read(B,1);
If Not WriteAsciiData then If Not WriteAsciiData then
ToAdd:=Format('%3d',[b]) begin
if WriteHex then
ToAdd:=Format('$%2.2x',[b])
else
ToAdd:=Format('%3d',[b]);
end
else else
If (B in [32..127]) and not (B in [10,13,39]) then If (B in [32..127]) and not (B in [10,13,39]) then
ToAdd:=''''+Chr(b)+'''' ToAdd:=''''+Chr(b)+''''
else else
// ToAdd:=Format('''%s''',[Chr(b)]); // ToAdd:=Format('''%s''',[Chr(b)]);
ToAdd:=Format('#%d',[B]); begin
if WriteHex then
ToAdd:=Format('#$%x',[B])
else
ToAdd:=Format('#%d',[B]);
end;
If I<Count then If I<Count then
ToAdd:=ToAdd+','; ToAdd:=ToAdd+',';
Line:=Line+ToAdd; Line:=Line+ToAdd;