Minor fixes to comments.
[AROS.git] / rom / dos / genstrings.py
blobebc42b006300b393ce4300fe49a69828f7dbc7fc
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 # Sorry for my awful Python knowledge - Sonic
7 import sys
9 def getline(f):
10 line = ";"
11 while line.startswith(';'):
12 line = f.readline()
14 return line.rstrip('\n')
16 f = open(sys.argv[1], 'r')
17 ids = []
18 numbers = []
19 strings = []
20 while True:
21 id_line = getline(f)
22 str_line = getline(f)
23 if (id_line == "") or (str_line == ""):
24 break
26 tmp = id_line.split()
27 ids.append(tmp[0])
29 tmp = tmp[1].split('(')
30 tmp = tmp[1].split('/')
31 numbers.append(tmp[0])
33 strings.append(str_line)
35 print "/* This file is automatically generated! Do not edit! */"
36 print
38 print "/*"
39 print " * Error codes index table."
40 print " * This table actually consists of pairs of values (begin, end)."
41 print " * One string in the table below corresponds to one error code"
42 print " * from the specified interval."
43 print " * The table is terminated by two zeros."
44 print " * This layout was recreated based on locale.library code brought from MorphOS."
45 print " */"
46 print "const ULONG err_Numbers[] ="
47 print "{"
48 first = ids[0]
49 last = ids[0]
50 n = 0
51 while (n < len(numbers) - 1):
52 prev = int(numbers[n])
53 n = n + 1
54 if (int(numbers[n]) == prev + 1):
55 last = ids[n]
56 else:
57 print " %s, %s," % (first, last)
58 first = ids[n]
59 last = ids[n]
60 print " 0, 0"
61 print "};"
62 print
64 print "/*"
65 print " * Strings follow each other."
66 print " * Every string is prefixed by length byte in BCPL manner. NULL terminator is counted too."
67 print " */"
68 print "const char err_Strings[] ="
69 print "{"
70 for str_line in strings:
71 print " %d," % (len(str_line) + 1)
72 for c in str_line:
73 print "'%s'," % c,
74 print "0,"
75 print "};"