2 # -*- coding: utf-8 -*-
4 # file unciodesymbols.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
10 # Full author contact details are available in file CREDITS
12 # This script reads a unicode symbol file and completes it in the given range
15 import os, re, string, sys, unicodedata
19 return ("Usage: %s start stop inputfile outputfile\n" % prog_name +
20 "or %s start stop <inputfile >outputfile" % prog_name)
24 sys.stderr.write(message + '\n')
29 " Remove end of line char(s)."
33 # file with no EOL in last line
38 " Read input file and strip lineendings."
41 line = input.readline()
48 if tokens[0][0:2] == "0x":
49 char = int(tokens[0][2:], 16)
50 elif tokens[0][0:3] == "#0x":
51 char = int(tokens[0][3:], 16)
52 lines.append([char, line])
56 def write(output, lines):
59 output.write(line[1] + '\n')
62 def complete(lines, start, stop):
64 for i in range(start, stop):
65 # This catches both comments (lines[l][0] == -1) and code points less than i
66 while l < len(lines) and lines[l][0] < i:
70 if l >= len(lines) or lines[l][0] != i:
71 if sys.version_info[0] < 3:
75 name = unicodedata.name(c, "")
77 if unicodedata.combining(c):
78 combining = "combining"
81 line = [i, '#0x%04x "" "" "%s" "" "" # %s' % (i, combining, name)]
94 input = io.open(argv[3], 'r', encoding='utf_8')
95 output = io.open(argv[4], 'w', encoding='utf_8')
98 if argv[1][:2] == "0x":
99 start = int(argv[1][2:], 16)
102 if argv[2][:2] == "0x":
103 stop = int(argv[2][2:], 16)
109 complete(lines, start, stop)
120 if __name__ == "__main__":