File: defs2magic.py

package info (click to toggle)
ckb-next 0.5.0%2Bdfsg.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,292 kB
  • sloc: cpp: 17,632; ansic: 12,820; sh: 221; xml: 121; python: 53; makefile: 9
file content (28 lines) | stat: -rwxr-xr-x 688 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python3
import sys
import re
import os

defs = "../src/daemon/protocol.h"
defspath = os.path.dirname(__file__) + "/" + defs
defs_file = open(defspath, "r")
defs_list = defs_file.readlines()

cmds = []
for cmd in defs_list:
    match = re.match("#define[\s]+([\S]+)[\s]+(0x[\da-f]+|\d+)", cmd)
    if match:
        cmds.append((match.group(1), match.group(2)))
#print(str(cmds))
defs_file.close()

# Sort the list by string len desc
cmds.sort(key = lambda i: len(i[0]), reverse = True)

stdin = sys.stdin.readlines()
print()
for stdline in stdin:
    finalstr = stdline
    for cmd in cmds:
        finalstr = finalstr.replace(cmd[0], cmd[1])
    print(finalstr, end = "")