Browse Source

Add line numbers and checksums to show/description output

Format: "line_num checksum: line_content"
Checksum: sum of character codes modulo 256 as 2 hex digits
Pre-comments printed without line numbers (as before)
nodeinfo-routing-update
Evgeny 8 months ago
parent
commit
02a97805f4
  1. 46
      c_util

46
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): def normalize_whitespace(text):
"""Normalize whitespace: replace multiple spaces/newlines with single space.""" """Normalize whitespace: replace multiple spaces/newlines with single space."""
# Replace all whitespace (spaces, tabs, newlines) with single space # Replace all whitespace (spaces, tabs, newlines) with single space
@ -774,13 +780,26 @@ def main():
# Print declarations with full formatting # Print declarations with full formatting
for start, end, decl_type, content, extra in declarations: for start, end, decl_type, content, extra in declarations:
if decl_type == 'function': if decl_type == 'function':
# Print comments first if any # Print comments first if any (without line numbers)
if extra: if extra:
print(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: else:
# struct or enum - print with preserved formatting on multiple lines # struct or enum - print with line numbers and checksums
print(f"[{start + 1}-{end + 1}] {extra}") 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': elif cmd == 'show':
if len(sys.argv) < 3: if len(sys.argv) < 3:
@ -830,14 +849,25 @@ def main():
# Print filename header # Print filename header
print(f"{f}:") print(f"{f}:")
# Print items # Print items with line numbers and checksums
for item_type, item in items: for item_type, item in items:
lines = contents[f] lines = contents[f]
start = item['start']
end = item['end']
# Print pre lines (comments) without line numbers
pre = item['pre'] pre = item['pre']
body = lines[item['start']:item['end'] + 1]
if pre: if pre:
print('\n'.join(pre)) for pre_line in pre:
print('\n'.join(body)) 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: if not found_any:
print("Not found") print("Not found")

Loading…
Cancel
Save