-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline.py
More file actions
35 lines (27 loc) · 1 KB
/
line.py
File metadata and controls
35 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import re
def align_macros(lines):
pattern = re.compile(r'^\s*#define\s+(\w+)\s+(.*)$')
matches = [pattern.match(line) for line in lines]
max_macro_len = max((len(m.group(1)) for m in matches if m), default=0)
aligned_lines = []
for line in lines:
match = pattern.match(line)
if match:
name, value = match.groups()
padding = ' ' * (max_macro_len - len(name) + 1)
aligned_lines.append(f"#define {name}{padding}{value}")
else:
aligned_lines.append(line)
return aligned_lines
if __name__ == "__main__":
import sys
if len(sys.argv) < 2:
print("Usage: python align_macros.py <filename>")
sys.exit(1)
filename = sys.argv[1]
with open(filename, 'r') as f:
lines = f.readlines()
aligned = align_macros(lines)
with open(filename, 'w') as f:
f.writelines(line + '\n' if not line.endswith('\n') else line for line in aligned)
print(f"✅ Done aligning macros in: {filename}")