Telemetry refactoring - Fixes #1634
This commit is contained in:
@@ -17,7 +17,6 @@ dups_name = []
|
||||
exports = []
|
||||
exports_multiple = []
|
||||
exports_script_outputs = []
|
||||
exports_extra = []
|
||||
|
||||
warning = None
|
||||
error = None
|
||||
@@ -51,13 +50,6 @@ def LEXP_MULTIPLE(nameFormat, descriptionFormat, valuesCount):
|
||||
checkName(name)
|
||||
exports_multiple.append( (CONSTANT_VALUE, nameFormat, descriptionFormat, valuesCount) )
|
||||
|
||||
def LEXP_EXTRA(name, description, value, condition = "true"):
|
||||
# print "LEXP_EXTRA %s, %s, %s, %s" % (name, description, value, condition)
|
||||
checkName(name)
|
||||
exports_extra.append( (CONSTANT_VALUE, name, description, value, condition) )
|
||||
# extra also added to normal items to enable searching
|
||||
exports.append( (CONSTANT_VALUE, name, description) )
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print "Error: not enough arguments!"
|
||||
print "Usage:"
|
||||
@@ -153,32 +145,6 @@ data = [" {%s, \"%s\", \"%s\", %d}" % export for export in exports_multiple]
|
||||
out.write(",\n".join(data))
|
||||
out.write("\n};\n\n")
|
||||
print "Generated %d items in luaMultipleFields[]" % len(exports_multiple)
|
||||
|
||||
#code generation for extra fields
|
||||
case = """ case %s:
|
||||
if (%s) {
|
||||
lua_pushnumber(L, %s);
|
||||
return 1;
|
||||
}
|
||||
break;"""
|
||||
case_clauses = [case % (cnst, condition, value) for (cnst, name, description, value, condition) in exports_extra]
|
||||
case_body = "\n".join(case_clauses)
|
||||
func_body = """
|
||||
extern lua_State *L;
|
||||
|
||||
// The handling of extra Lua fields that are not
|
||||
// accessible by the getValue()
|
||||
static int luaGetExtraValue(int src)
|
||||
{
|
||||
switch (src) {
|
||||
%s
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
""" % case_body
|
||||
out.write(func_body)
|
||||
print "Generated %d conditions in luaGetExtraValue()" % len(exports_extra)
|
||||
out.close()
|
||||
|
||||
if docFile:
|
||||
|
||||
+24
-16
@@ -128,27 +128,35 @@ if args.language not in translations:
|
||||
parser.error(args.language + ' is not a supported language. Try one of the supported ones: ' + str(translations.keys()))
|
||||
system.exit()
|
||||
|
||||
if args.reverse:
|
||||
for translation in translations:
|
||||
translations[translation] = [(after, before) for (before, after) in translations[translation]]
|
||||
|
||||
# Read the input file into a buffer
|
||||
in_file = codecs.open( args.input, "r", "utf-8" )
|
||||
text = in_file.read()
|
||||
in_file.close()
|
||||
|
||||
# Do the replacements
|
||||
for before, after in translations[args.language]:
|
||||
if args.reverse:
|
||||
text = text.replace(before, after)
|
||||
else:
|
||||
text = text.replace(after, before)
|
||||
|
||||
for before, after in translations["all"]:
|
||||
if args.reverse:
|
||||
text = text.replace(before, after)
|
||||
else:
|
||||
text = text.replace(after, before)
|
||||
|
||||
# Write the result to a temporary file
|
||||
out_file = codecs.open(args.output, 'w', 'utf-8')
|
||||
out_file.write( text )
|
||||
|
||||
for line in in_file.readlines():
|
||||
# Do the special chars replacements
|
||||
for after, before in translations[args.language] + translations["all"]:
|
||||
line = line.replace(before, after)
|
||||
if line.startswith("#define ZSTR_"):
|
||||
before = line[32:-2]
|
||||
after = ""
|
||||
for c in before:
|
||||
if ord(c) >= ord('A') and ord(c) <= ord('Z'):
|
||||
c = "\\%03o" % (ord(c) - ord('A') + 1)
|
||||
elif ord(c) >= ord('a') and ord(c) <= ord('z'):
|
||||
c = "\\%03o" % (-ord(c) + ord('a') + 255)
|
||||
elif ord(c) >= ord('0') and ord(c) <= ord('9'):
|
||||
c = "\\%03o" % (ord(c) - ord('0') + 27)
|
||||
after = after + c
|
||||
line = line[:32] + after + line[-2:]
|
||||
out_file.write(line)
|
||||
|
||||
out_file.close()
|
||||
in_file.close()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user