aboutsummaryrefslogtreecommitdiff
path: root/checklines.py3
blob: e38bba1c9a0801c7dc59a9b3860bf4d4326b83c8 (plain)
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
#!/usr/bin/env python3
 
# From purpleposeidon!
 
from unicodedata import name
import re
import sys
 
for line in sys.stdin:
  line=line.strip()
  if not line or line[0]=="#":
    continue
  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)
  if not nummatch:
    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))