about summary refs log tree commit diff
path: root/datasrc/compile.py
diff options
context:
space:
mode:
authorSworddragon <sworddragon2@aol.com>2011-01-06 00:51:31 +0100
committeroy <Tom_Adams@web.de>2011-01-06 12:27:50 +0100
commit4ff61fcdaa84e874c862374976bf06bb1f367b7f (patch)
tree1698ad6869f97a8e6f7f12d4bb4fd6688f7d5eb6 /datasrc/compile.py
parentb90a015daff77074d9749585903c4d263cbadb88 (diff)
downloadzcatch-4ff61fcdaa84e874c862374976bf06bb1f367b7f.tar.gz
zcatch-4ff61fcdaa84e874c862374976bf06bb1f367b7f.zip
Made compiling process Python 3 compatible
Diffstat (limited to 'datasrc/compile.py')
-rw-r--r--datasrc/compile.py91
1 files changed, 45 insertions, 46 deletions
diff --git a/datasrc/compile.py b/datasrc/compile.py
index 4b7be441..1a726637 100644
--- a/datasrc/compile.py
+++ b/datasrc/compile.py
@@ -23,23 +23,22 @@ def create_flags_table(names):
 	return lines
 	
 def EmitEnum(names, num):
-	print "enum"
-	print "{"
-	print "\t%s=0,"%names[0]
+	print("enum")
+	print("{")
+	print("\t%s=0," % names[0])
 	for name in names[1:]:
-		print "\t%s,"%name
-	print "\t%s" % num
-	print "};"
+		print("\t%s," % name)
+	print("\t%s" % num)
+	print("};")
 
 def EmitFlags(names, num):
-	print "enum"
-	print "{"
+	print("enum")
+	print("{")
 	i = 0
 	for name in names:
-		print "\t%s = 1<<%d," % (name,i)
+		print("\t%s = 1<<%d," % (name,i))
 		i += 1
-	print "};"
-		
+	print("};")
 
 gen_network_header = False
 gen_network_source = False
@@ -56,28 +55,28 @@ if "server_content_header" in sys.argv: gen_server_content_header = True
 if "server_content_source" in sys.argv: gen_server_content_source = True
 
 if gen_client_content_header:
-	print "#ifndef CLIENT_CONTENT_HEADER"
-	print "#define CLIENT_CONTENT_HEADER"
+	print("#ifndef CLIENT_CONTENT_HEADER")
+	print("#define CLIENT_CONTENT_HEADER")
 
 if gen_server_content_header:
-	print "#ifndef SERVER_CONTENT_HEADER"
-	print "#define SERVER_CONTENT_HEADER"
+	print("#ifndef SERVER_CONTENT_HEADER")
+	print("#define SERVER_CONTENT_HEADER")
 
 
 if gen_client_content_header or gen_server_content_header:
 	# emit the type declarations
-	contentlines = file("datasrc/content.py").readlines()
+	contentlines = open("datasrc/content.py", "rb").readlines()
 	order = []
 	for line in contentlines:
-		line = line.strip()
+		line = line.decode("iso8859-1").strip()
 		if line[:6] == "class " and '(Struct)' in line:
 			order += [line.split()[1].split("(")[0]]
 	for name in order:
 		EmitTypeDeclaration(content.__dict__[name])
-		
+
 	# the container pointer
-	print 'extern DATACONTAINER *g_pData;';
-	
+	print('extern DATACONTAINER *g_pData;')
+
 	# enums
 	EmitEnum(["IMAGE_%s"%i.name.value.upper() for i in content.container.images.items], "NUM_IMAGES")
 	EmitEnum(["ANIM_%s"%i.name.value.upper() for i in content.container.animations.items], "NUM_ANIMS")
@@ -85,41 +84,41 @@ if gen_client_content_header or gen_server_content_header:
 
 if gen_client_content_source or gen_server_content_source:
 	if gen_client_content_source:
-		print '#include "client_data.h"'
+		print('#include "client_data.h"')
 	if gen_server_content_source:
-		print '#include "server_data.h"'
+		print('#include "server_data.h"')
 	EmitDefinition(content.container, "datacontainer")
-	print 'DATACONTAINER *g_pData = &datacontainer;';
+	print('DATACONTAINER *g_pData = &datacontainer;')
 
 # NETWORK
 if gen_network_header:
 	
-	print "#ifndef GAME_GENERATED_PROTOCOL_H"
-	print "#define GAME_GENERATED_PROTOCOL_H"
-	print network.RawHeader
+	print("#ifndef GAME_GENERATED_PROTOCOL_H")
+	print("#define GAME_GENERATED_PROTOCOL_H")
+	print(network.RawHeader)
 	
 	for e in network.Enums:
-		for l in create_enum_table(["%s_%s"%(e.name, v) for v in e.values], 'NUM_%sS'%e.name): print l
-		print ""
+		for l in create_enum_table(["%s_%s"%(e.name, v) for v in e.values], 'NUM_%sS'%e.name): print(l)
+		print("")
 
 	for e in network.Flags:
-		for l in create_flags_table(["%s_%s" % (e.name, v) for v in e.values]): print l
-		print ""
+		for l in create_flags_table(["%s_%s" % (e.name, v) for v in e.values]): print(l)
+		print("")
 		
-	for l in create_enum_table(["NETOBJ_INVALID"]+[o.enum_name for o in network.Objects], "NUM_NETOBJTYPES"): print l
-	print ""
-	for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print l
-	print ""
+	for l in create_enum_table(["NETOBJ_INVALID"]+[o.enum_name for o in network.Objects], "NUM_NETOBJTYPES"): print(l)
+	print("")
+	for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print(l)
+	print("")
 		
 	for item in network.Objects + network.Messages:
 		for line in item.emit_declaration():
-			print line
-		print ""
+			print(line)
+		print("")
 		
 	EmitEnum(["SOUND_%s"%i.name.value.upper() for i in content.container.sounds.items], "NUM_SOUNDS")
 	EmitEnum(["WEAPON_%s"%i.name.value.upper() for i in content.container.weapons.id.items], "NUM_WEAPONS")
 
-	print """
+	print("""
 
 class CNetObjHandler
 {
@@ -147,9 +146,9 @@ public:
 	const char *FailedMsgOn();
 };
 
-"""
+""")
 
-	print "#endif // GAME_GENERATED_PROTOCOL_H"
+	print("#endif // GAME_GENERATED_PROTOCOL_H")
 	
 
 if gen_network_source:
@@ -228,13 +227,13 @@ if gen_network_source:
 		
 	
 	for l in lines:
-		print l
+		print(l)
 
 	if 0:
 		for item in network.Objects:
 			for line in item.emit_validate():
-				print line
-			print ""
+				print(line)
+			print("")
 
 	# create validate tables
 		lines = []
@@ -271,8 +270,8 @@ if gen_network_source:
 	if 0:
 		for item in network.Messages:
 			for line in item.emit_unpack():
-				print line
-			print ""
+				print(line)
+			print("")
 
 		lines += ['static void *secure_unpack_invalid(CUnpacker *pUnpacker) { return 0; }']
 		lines += ['typedef void *(*SECUREUNPACKFUNC)(CUnpacker *pUnpacker);']
@@ -313,7 +312,7 @@ if gen_network_source:
 
 
 	for l in lines:
-		print l
+		print(l)
 	
 if gen_client_content_header or gen_server_content_header:
-	print "#endif"
+	print("#endif")