[go: up one dir, main page]

Menu

[ab7a0e]: / doc / cparse.py  Maximize  Restore  History

Download this file

140 lines (125 with data), 3.9 kB

  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
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python
#
# Script to check GNUWorld's mod.cservice translations
# Episode 2 - Check for inconsistent translation strings
#
# (C) 2001 Alex Badea <vampire@go.ro>
#
# Change this to suit your system
gnuworld_home = "../"
# Language ID to check
language_id = "1"
# ---------------------------------------------------------------------------
import sys
import os
from string import *
responses = {}
resp_used = {}
trans = {}
trans_r = {}
alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
def read_language_table(fname):
f = open(fname, "r")
for line in f.readlines():
line = strip(line)
toks = split(line, '\t')
if len(toks) < 4: continue
if toks[0] != language_id: continue
if toks[len(toks)-1] != "31337": continue
if trans.has_key(toks[1]):
print "* Duplicate translation ID (%s) Text: '%s' conflicts with '%s' defined by ID %d" % (toks[1], toks[2], trans[toks[1]], trans_r[toks[2]])
if trans_r.has_key(toks[2]):
print "* Duplicate translation text '%s', ID %s already defined by ID %s" % (toks[2], toks[1], trans_r[toks[2]])
trans[toks[1]] = toks[2]
trans_r[toks[2]] = toks[1]
f.close()
print "* Read %d translations from %s" % (len(trans), fname)
def read_response_table(fname):
f = open(fname, "r")
for line in f.readlines():
line = strip(line)
toks = split(line)
if len(toks) < 2: continue
if toks[0] != "const": continue
if toks[1] != "int": continue
if responses.has_key(toks[2]):
print "* Duplicate response name (%s) ID: %s" % (toks[2], toks[4])
responses[toks[2]] = toks[4][:-1]
resp_used[toks[2]] = 0
f.close()
print "* Read %d responses from %s" % (len(responses), fname)
class Parser:
def __init__(self, fname):
self.fname = fname
f = open(os.path.join(gnuworld_home, "mod.cservice", fname), "r")
self.buf = f.read()
f.close()
def pos(self, sub, start=0):
try: return index(self.buf, sub, start)
except ValueError: return -1
def run(self):
idx = self.pos("getResponse", 0)
while idx != -1:
lineno = count(self.buf[:idx], '\n') + 1
idx = idx + len("getResponse")
while self.buf[idx] != "(":
idx = idx + 1
idx = idx + 1
para = 1
quote = 0
tok = ""
tokens = []
while 1:
ch = self.buf[idx]
if quote:
if ch == '"':
tok = replace(tok, '""', '')
quote = 0
else:
if ch == "(":
para = para + 1
elif ch == ")":
para = para - 1
if para == 0:
tokens.append(tok)
break
elif ch == "\"":
quote = 1
elif ch in " \n\t\r":
idx = idx + 1
continue
elif ch == ",":
tokens.append(tok)
tok = ""
idx = idx + 1
continue
elif ch == ";":
tokens.append(tok)
break
tok = tok + ch
idx = idx + 1
if len(tokens) < 3:
print "%s(%d): getResponse has less than 3 arguments" % (self.fname, lineno)
pass
elif len(tokens[1]) < 10 or tokens[1][:10] != "language::":
print "%s(%d): Second argument to getResponse doesn't start with 'language::'" % (self.fname, lineno)
else:
id = tokens[1][10:]
numeric = responses[id]
trans_text = trans[numeric]
text = tokens[2]
if text[:7] == "string(": text = text[7:]
if text[-1] == ")": text = text[:-1]
if text[0] == '"': text = text[1:]
if text[-1] == '"': text = text[:-1]
if len(tokens) > 2 and trans_text != text:
print "%s(%d): Default response doesn't match with translation:\n Def: %s\n Trans: %s" % (self.fname, lineno, text, trans_text)
idx = self.pos("getResponse", idx)
read_language_table(os.path.join(gnuworld_home, "doc", "language_table.sql"))
read_response_table(os.path.join(gnuworld_home, "mod.cservice", "responses.h"))
files = os.listdir(os.path.join(gnuworld_home, "mod.cservice"))
for file in files:
if len(file) < 4: continue
if file[-3:] != ".cc": continue
Parser(file).run()
print "* Done"