<commit_before>#!/usr/bin/env python
"""
This is a little tool to generate hex dumps from .a43, .text, .elf or binary
files.

(C) 2009-2010 <NAME> <<EMAIL>>
this is distributed under a free software license, see LICENSE.txt.
"""

import sys
import msp430.memory


def hexdump( (adr, memstr), output=sys.stdout ):
    """Print a hex dump.
    arg1: tuple with address, memory
    return None"""
    count = 0
    ascii = ''
    for value in map(ord, memstr):
        if not count: output.write("%04x:  " % adr)
        output.write("%02x " % value)
        ascii += (32 <= value < 128) and chr(value) or '.'
        count += 1
        adr += 1
        if count == 16:
            count = 0
            output.write("   %s\n" % ascii)
            ascii = ''
    if count < 16: output.write("%s   %s\n" % ("   "*(16-count), ascii))


def save(memory, filelike):
    """output a hexdump to given file object"""
    for n, segment in enumerate(sorted(memory.segments)):
        if n: filelike.write('....:\n')
        hexdump((segment.startaddress, segment.data), output=filelike)


debug = False

def main():
    from optparse import OptionParser<commit_msg>fine tune appearance of hexdump (no "jump" between 0xffff, 0x10000)<commit_after>#!/usr/bin/env python
"""
This is a little tool to generate hex dumps from .a43, .text, .elf or binary
files.

(C) 2009-2010 <NAME> <<EMAIL>>
this is distributed under a free software license, see LICENSE.txt.
"""

import sys
import msp430.memory


def hexdump( (adr, memstr), output=sys.stdout ):
    """Print a hex dump.
    arg1: tuple with address, memory
    return None"""
    count = 0
    ascii = ''
    for value in map(ord, memstr):
        if not count: output.write("%08x: " % adr)
        output.write("%02x " % value)
        ascii += (32 <= value < 128) and chr(value) or '.'
        count += 1
        adr += 1
        if count == 16:
            count = 0
            output.write("  %s\n" % ascii)
            ascii = ''
    if count < 16: output.write("%s  %s\n" % ("   "*(16-count), ascii))


def save(memory, filelike):
    """output a hexdump to given file object"""
    for n, segment in enumerate(sorted(memory.segments)):
        if n: filelike.write('....:\n')
        hexdump((segment.startaddress, segment.data), output=filelike)


debug = False

def main():
    from optparse import OptionParser
{'fraction_non_alphanumeric': 0.14455277660025434, 'fraction_numerical': 0.030945315811784654, 'mean_word_length': 2.5066864784546805, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '85032', 'n_tokens_mistral': 837, 'n_tokens_neox': 742, 'n_words': 254}