From 865c8e4bbf765e56852ec1aa74e7d9f7d8db63f5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 5 Sep 2016 18:52:54 +0300 Subject: servergreps: move all header manipulation code into python script. --- servergreps/hercules/packets.py | 12 ++++++------ servergreps/hercules/src/hercules.py | 19 +++++++++++++++++++ servergreps/hercules/src/preproc.py | 26 ++++++++++++++++++++++++++ servergreps/hercules/update.sh | 21 +-------------------- 4 files changed, 52 insertions(+), 26 deletions(-) create mode 100755 servergreps/hercules/src/preproc.py (limited to 'servergreps/hercules') diff --git a/servergreps/hercules/packets.py b/servergreps/hercules/packets.py index b5fea2c..ea3ee56 100755 --- a/servergreps/hercules/packets.py +++ b/servergreps/hercules/packets.py @@ -12,23 +12,23 @@ from src.reporter import Reporter def showHelp(): - print("Usage: packets.py version") + print("Usage: packets.py hercules dir version") exit(1) -if len(sys.argv) != 2: +if len(sys.argv) != 4: showHelp() -packetVersion = sys.argv[1] -packetDir = packetVersion -while len(packetDir) < 8: - packetDir = "0" + packetDir +codeDir = sys.argv[1] +packetDir = sys.argv[2] +packetVersion = sys.argv[3] hercules = Hercules() manaplus = ManaPlus() reporter = Reporter() reporter.packetDir = packetDir; +hercules.prepareTempFiles(codeDir, packetDir, packetVersion) hercules.processPackets(packetDir, packetVersion) manaplus.processPackets(packetVersion); reporter.reportManaplus(hercules, manaplus) diff --git a/servergreps/hercules/src/hercules.py b/servergreps/hercules/src/hercules.py index ad82b4e..b910929 100755 --- a/servergreps/hercules/src/hercules.py +++ b/servergreps/hercules/src/hercules.py @@ -7,6 +7,8 @@ import os import re +from src.preproc import PreProc + filt = re.compile(".+[.](c|h)", re.IGNORECASE) class Hercules: @@ -167,3 +169,20 @@ class Hercules: self.collectInPackets(serverInPacketsHPath, serverLoginInPackets) self.sortInPackets() self.sortOutPackets() + + + def prepareTempFiles(self, codeDir, packetDir, packetVersion): + proc = PreProc() + proc.init(packetDir + "/src/hercules") + proc.defines = "-DPACKETVER=" + packetVersion + " -DCOMMON_SOCKET_H -DWFIFOW\\(fd,pos\\)=WFIFOW\\(fd,pos\\) -DWBUFW\\(p,pos\\)=WBUFW\\(p,pos\\)" + proc.includes = "-I../links/" + codeDir + "/src -I../links/" + codeDir + "/3rdparty" + proc.inDir = "../links/" + codeDir + "/src/" + proc.outDir = packetDir + "/src/hercules/" + proc.run("map", "packets_struct.h"); + proc.run("char", "char.c"); + proc.run("login", "login.c"); + proc.run("map", "clif.c"); + proc.run("login", "lclif.p.h"); + proc.run("login", "lclif.c"); + proc.defines = "-DPACKETVER=" + packetVersion + " -Dpacket\\(id,size,...\\)=packet\\(id,size,__VA_ARGS__\\)" + proc.run("map", "packets.h"); diff --git a/servergreps/hercules/src/preproc.py b/servergreps/hercules/src/preproc.py new file mode 100755 index 0000000..23735c9 --- /dev/null +++ b/servergreps/hercules/src/preproc.py @@ -0,0 +1,26 @@ +#! /usr/bin/env python2 +# -*- coding: utf8 -*- +# +# Copyright (C) 2015-2016 Evol Online +# Author: Andrei Karas (4144) + +import os +import re +import sys +import shutil + +class PreProc: + def init(self, tmpDir): + if os.path.exists(tmpDir): + shutil.rmtree(tmpDir) + os.makedirs(tmpDir) + + + def run(self, subDir, outFile): + os.system( + "cpp {defines} {includes} {subDir}/{inFile} {outFile}".format( + defines = self.defines, + includes = self.includes, + subDir = self.inDir + subDir, + inFile = outFile, + outFile = self.outDir + outFile)) diff --git a/servergreps/hercules/update.sh b/servergreps/hercules/update.sh index a668a86..66401a8 100755 --- a/servergreps/hercules/update.sh +++ b/servergreps/hercules/update.sh @@ -1,26 +1,7 @@ #!/bin/bash -function preproc { - cpp -DPACKETVER=$3 \ - -DCOMMON_SOCKET_H \ - "-DWFIFOW(fd,pos)=WFIFOW(fd,pos)" \ - "-DWBUFW(p,pos)=WBUFW(p,pos)" \ - -I../links/$1/src -I../links/$1/3rdparty \ - ../links/$1/src/$4/$5 \ - $2/src/hercules/$5 -} - function genpackets { - rm -rf "$2/src" - mkdir -p "$2/src/hercules" - cpp -DPACKETVER=$3 "-Dpacket(id,size,...)=packet(id,size,__VA_ARGS__)" ../links/$1/src/map/packets.h $2/src/hercules/packets.h - preproc $1 $2 $3 map packets_struct.h - preproc $1 $2 $3 char char.c - preproc $1 $2 $3 login login.c - preproc $1 $2 $3 map clif.c - preproc $1 $2 $3 login lclif.p.h - preproc $1 $2 $3 login lclif.c - ./packets.py $3 + ./packets.py $1 $2 $3 } genpackets hercules 00000000 0 -- cgit v1.2.3-70-g09d2