-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathchecklines.py3
executable file
·38 lines (34 loc) · 1 KB
/
checklines.py3
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
35
36
37
38
#!/usr/bin/env python3
# From purpleposeidon!
from unicodedata import name
import re
import sys
linecount = 0
for line in sys.stdin:
line=line.strip()
if not line or line[0]=="#":
continue
linecount += 1
match=re.match(r'\s*(.*):\s*"(.*?)"\s*(\S*)\s*(#.*)?', line)
if not match:
print("({0})".format(line))
continue
(keystrokes, char, num, comments)=match.groups()
nummatch=re.match(r'^U([0-9A-Fa-f]+)$', num)
# There's no number for multichar strings
if not nummatch:
if len(char) == 1:
print("Number not parsed: {0}".format(line))
continue
x=int(nummatch.group(1),0x10)
c=chr(x)
try:
if c != char:
print(line)
print("\tLine's char: {0} ({1})".format(char, name(char)))
print("\tLine's number: {0:X}".format(x))
print("\tChar gives number: {0:X}".format(ord(char)))
print("\tNumber gives character: {0} ({1})".format(c, name(c)))
except Exception as e:
print("{0}\n\t{1}".format(line, e))
print("Done. Checked %d lines."%linecount)