revert between 56095 -> 55830 in arch
[AROS.git] / rom / dos / genstrings.py
blob6a19643955c10b16a951909d417dad4474a1c52e
1 #!/usr/bin/python
3 """ This script is used to generate built-in string tables for dos.library
4 They use very own format which is impossible to generate with FlexCat.
5 """
7 import sys
9 def getline(fhandle):
10 line = ";"
11 while line.startswith(';'):
12 line = fhandle.readline()
14 return line.rstrip('\n')
17 def main():
18 fhandle = open(sys.argv[1], 'r')
19 ids = []
20 numbers = []
21 strings = []
22 while True:
23 id_line = getline(fhandle)
24 str_line = getline(fhandle)
25 if (id_line == "") or (str_line == ""):
26 break
28 tmp = id_line.split()
29 ids.append(tmp[0])
31 tmp = tmp[1].split('(')
32 tmp = tmp[1].split('/')
33 numbers.append(tmp[0])
35 strings.append(str_line)
37 print "/* This file is automatically generated! Do not edit! */"
38 print
40 print "/*"
41 print " * Error codes index table."
42 print " * This table actually consists of pairs of values (begin, end)."
43 print " * One string in the table below corresponds to one error code"
44 print " * from the specified interval."
45 print " * The table is terminated by two zeros."
46 print " * This layout was recreated based on locale.library code brought from MorphOS."
47 print " */"
48 print "const ULONG err_Numbers[] ="
49 print "{"
50 first = ids[0]
51 last = ids[0]
52 n = 0
53 while n < len(numbers) - 1:
54 prev = int(numbers[n])
55 n = n + 1
56 if int(numbers[n]) == prev + 1:
57 last = ids[n]
58 else:
59 print " %s, %s," % (first, last)
60 first = ids[n]
61 last = ids[n]
62 print " 0, 0"
63 print "};"
64 print
66 print "/*"
67 print " * Strings follow each other."
68 print " * Every string is prefixed by length byte in BCPL manner. NULL terminator is counted too."
69 print " */"
70 print "const char err_Strings[] ="
71 print "{"
72 for str_line in strings:
73 print " %d," % (len(str_line) + 1)
74 for c in str_line:
75 print "'%s'," % c,
76 print "0,"
77 print "};"
78 fhandle.close()
81 if __name__ == "__main__":
82 main()