# HG changeset patch # User Dan Drogichen # Date 1405881475 25200 # Sun Jul 20 11:37:55 2014 -0700 # Node ID 206be2932de1c1f402d35b16fae646eb1d7dde54 # Parent 63094859903e2c464d9a1bdb6e444b11d0d2c879 Allow specification of the hexdump address format Further edits to patch from Dan Smith # Fri Jul 18 07:58:00 2014 -0700 Change default addrfmt to %(addr)03i as discussed. Catch several exceptions resulting from format string errors observed in testing, and use the default format, as discussed. Revised the README.developers entry for hexdump_addrfmt as discussed. Alphabetized the README.developers directive descriptions, and made a few other minor edits as per the related 1767 patch submitted # Tue Jul 15 11:40:21 2014 -0700 diff -r 63094859903e -r 206be2932de1 README.developers --- a/README.developers Fri Jul 18 07:58:00 2014 -0700 +++ b/README.developers Sun Jul 20 11:37:55 2014 -0700 @@ -5,7 +5,7 @@ The Developer Functions are enabled in the GUI by checking the box in the "Help" tab. They enable the Image Browser tab in the left -sidebar, and several tools under the View -> Developer tab. +sidebar, several tools under the View -> Developer tab, and some others. These directives are similar to other chirp.config entries in syntax. They reside in the [developer] section in chirp.config. @@ -19,20 +19,9 @@ [developer] diff_fontsize = 16 browser_fontsize = 13 -hexdump_addrfmt = %(addr)03i +hexdump_addrfmt = %(addr)04i x%(addr)04X =================================== - -diff_fontize = -This specifies the fontsize used in the hex dump/diff display which is -invoked by selecting View -> Developer -> Diff tabs, and then in the -"Diff Radios" popup, selecting < 0 for either or both memory locations. - -The default size is 11. Values less than 4, greater than 144, or not -recognized as an integer will result in a log message and the default -size will be used. - -======== browser_fontsize = This specifies the fontsize used in the file browser, invoked by selecting the "Browser" tab in the left sidebar, which is visible when the Developer @@ -43,12 +32,33 @@ size will be used. ======== -hexdump_addrfmt = %(addr)03i -This specifies the format of the address used during some hexdump -operations. You can specify an alternate format, such as the following -for hex: +diff_fontize = +This specifies the fontsize used in the hex dump/diff display which is +invoked by selecting View -> Developer -> Diff tabs. - hexdump_addrfmt = 0x%(addr)04x +The default size is 11. Values less than 4, greater than 144, or not +recognized as an integer will result in a log message and the default +size will be used. -Any of the variables in local scope of chirp/util.py::hexdump.py are -valid for substitution, including block and block_size. +======== +hexdump_addrfmt = +This specifies the format of the address printed during some hexdump +operations. The default is %(addr)03i which prints the byte offset +of the first byte of each line in decimal, producing lines such as + 064: 00 00 00 ... + +Any of the variables in local scope of chirp/util.py::hexdump() are +valid for substitution, including block and block_size. Any may +be used more than once. The example above, %(addr)04i x%(addr)04X +produces lines such as + 0064 x0040: 00 00 00 ... + +0x%(addr)04x specifies lower case hex, and wwould produce lines such as + 0x0040: 00 00 00 ... + +Exceptions that have been observed in testing formats which are +invalid in this context are caught, and the default format is used. + +======== + + diff -r 63094859903e -r 206be2932de1 chirp/util.py --- a/chirp/util.py Fri Jul 18 07:58:00 2014 -0700 +++ b/chirp/util.py Sun Jul 20 11:37:55 2014 -0700 @@ -18,7 +18,7 @@ def hexprint(data, addrfmt=None): """Return a hexdump-like encoding of @data""" if addrfmt is None: - addrfmt = '%(block)03i' + addrfmt = '%(addr)03i' block_size = 8 @@ -32,7 +32,10 @@ for block in range(0, (len(data)/block_size)): addr = block * block_size - out += addrfmt % locals() + try: + out += addrfmt % locals() + except (OverflowError, ValueError, TypeError, KeyError): + out += "%03i" % addr out += ': ' left = len(data) - (block * block_size)