diff --git a/c_util b/c_util index 1482ea1d..955e9d88 100755 --- a/c_util +++ b/c_util @@ -531,6 +531,12 @@ def parse_function(lines_info, start_idx): } +def line_checksum(line): + """Calculate checksum: sum of all character codes modulo 256, as 2 hex digits.""" + checksum = sum(ord(c) for c in line) % 256 + return f"{checksum:02X}" + + def normalize_whitespace(text): """Normalize whitespace: replace multiple spaces/newlines with single space.""" # Replace all whitespace (spaces, tabs, newlines) with single space @@ -774,13 +780,26 @@ def main(): # Print declarations with full formatting for start, end, decl_type, content, extra in declarations: if decl_type == 'function': - # Print comments first if any + # Print comments first if any (without line numbers) if extra: print(extra) - print(f"[{start + 1}-{end + 1}] {content}") + # Print function signature with line number and checksum + lines = contents[f] + for line_idx in range(start, end + 1): + if line_idx < len(lines): + line = lines[line_idx] + line_num = line_idx + 1 + checksum = line_checksum(line) + print(f"{line_num} {checksum}: {line}") else: - # struct or enum - print with preserved formatting on multiple lines - print(f"[{start + 1}-{end + 1}] {extra}") + # struct or enum - print with line numbers and checksums + lines = contents[f] + for line_idx in range(start, end + 1): + if line_idx < len(lines): + line = lines[line_idx] + line_num = line_idx + 1 + checksum = line_checksum(line) + print(f"{line_num} {checksum}: {line}") elif cmd == 'show': if len(sys.argv) < 3: @@ -830,14 +849,25 @@ def main(): # Print filename header print(f"{f}:") - # Print items + # Print items with line numbers and checksums for item_type, item in items: lines = contents[f] + start = item['start'] + end = item['end'] + + # Print pre lines (comments) without line numbers pre = item['pre'] - body = lines[item['start']:item['end'] + 1] if pre: - print('\n'.join(pre)) - print('\n'.join(body)) + for pre_line in pre: + print(pre_line) + + # Print body with line numbers and checksums + for line_idx in range(start, end + 1): + if line_idx < len(lines): + line = lines[line_idx] + line_num = line_idx + 1 + checksum = line_checksum(line) + print(f"{line_num} {checksum}: {line}") if not found_any: print("Not found")