Skip to content

Commit

Permalink
Call _main() running the script as __main__, cleanup and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Feb 1, 2018
1 parent d6d8263 commit 4d00b9b
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ def __iter__(self):

@property
def minimum_address(self):
"""The minimum address of the data.
"""The minimum address of the data, or ``None`` if no data is
available.
"""

Expand All @@ -318,7 +319,8 @@ def minimum_address(self):

@property
def maximum_address(self):
"""The maximum address of the data.
"""The maximum address of the data, or ``None`` if no data is
available.
"""

Expand Down Expand Up @@ -539,7 +541,7 @@ def __str__(self):

@property
def execution_start_address(self):
"""The execution start address.
"""The execution start address, or ``None`` if missing.
"""

Expand All @@ -551,7 +553,7 @@ def execution_start_address(self, address):

@property
def minimum_address(self):
"""The minimum address of the data.
"""The minimum address of the data, or ``None`` if the file is empty.
"""

Expand All @@ -564,7 +566,7 @@ def minimum_address(self):

@property
def maximum_address(self):
"""The maximum address of the data.
"""The maximum address of the data, or ``None`` if the file is empty.
"""

Expand All @@ -577,8 +579,9 @@ def maximum_address(self):

@property
def header(self):
"""The binary file header. See :class:`BinFile's<.BinFile>`
`header_encoding` argument for encoding options.
"""The binary file header, or ``None`` if missing. See
:class:`BinFile's<.BinFile>` `header_encoding` argument for
encoding options.
"""

Expand Down Expand Up @@ -666,28 +669,28 @@ def add_ihex(self, records, overwrite=False):
"""

extmaximum_addressed_segment_address = 0
extmaximum_addressed_linear_address = 0
extended_segment_address = 0
extended_linear_address = 0

for record in StringIO(records):
type_, address, size, data = unpack_ihex(record.strip())

if type_ == 0:
address = (address
+ extmaximum_addressed_segment_address
+ extmaximum_addressed_linear_address)
+ extended_segment_address
+ extended_linear_address)
address *= self.word_size_bytes
self._segments.add(_Segment(address, address + size,
bytearray(data)),
overwrite)
elif type_ == 1:
pass
elif type_ == 2:
extmaximum_addressed_segment_address = int(
binascii.hexlify(data), 16) * 16
extended_segment_address = int(binascii.hexlify(data), 16)
extended_segment_address *= 16
elif type_ == 4:
extmaximum_addressed_linear_address = (int(
binascii.hexlify(data), 16) * 65536)
extended_linear_address = int(binascii.hexlify(data), 16)
extended_linear_address <<= 16
elif type_ in [3, 5]:
self.execution_start_address = int(binascii.hexlify(data), 16)
else:
Expand Down Expand Up @@ -1217,3 +1220,7 @@ def _main():
args.func(args)
except BaseException as e:
sys.exit(str(e))


if __name__ == '__main__':
_main()

0 comments on commit 4d00b9b

Please sign in to comment.