From 15e656c36eec4f1f0a2143f3c9d5857557a49284 Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 6 Oct 2018 16:28:19 +0000 Subject: [PATCH] + -x option to output all numeric constants as hex constants git-svn-id: trunk@39870 - --- utils/bin2obj.pp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/utils/bin2obj.pp b/utils/bin2obj.pp index 558ed34ef0..47abc5972b 100644 --- a/utils/bin2obj.pp +++ b/utils/bin2obj.pp @@ -26,7 +26,8 @@ var WriteAsciiData, CompressData, EnCodeData, - CompileUnit : Boolean; + CompileUnit, + WriteHex : Boolean; Cryptkey : IDEAcryptKey; InStream, MemStream, @@ -39,6 +40,7 @@ begin Writeln ('Usage: bin2obj [options] -c constname [infile] '); Writeln ('Where options is a combination of : '); Writeln (' -a write asciii data instead of bytes'); + Writeln (' -x write numerical values as hexadecimal numbers'); Writeln (' -z compress data.'); Writeln (' -e key encrypt data with key (must have 8 characters)'); Writeln (' -o output filename'); @@ -62,13 +64,15 @@ begin UnitName:=''; NeedUnitName:=False; WriteAsciiData:=False; + WriteHex:=False; Repeat - c:=GetOpt('ac:e:o:zhu::U::'); + c:=GetOpt('ac:e:o:zhu::U::x'); Case C of 'a' : WriteAsciiData:=True; 'c' : ConstName:=OptArg; 'h','?' : usage; 'z' : CompressData := True; + 'x' : WriteHex := True; 'e' : begin EncodeData:=True; If Length(OptArg)<8 then @@ -209,13 +213,23 @@ begin begin MemStream.Read(B,1); If Not WriteAsciiData then - ToAdd:=Format('%3d',[b]) + begin + if WriteHex then + ToAdd:=Format('$%2.2x',[b]) + else + ToAdd:=Format('%3d',[b]); + end else If (B in [32..127]) and not (B in [10,13,39]) then ToAdd:=''''+Chr(b)+'''' else // 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