diff options
author | Haruna <haru@dotalux.com> | 2014-12-04 00:16:42 +0100 |
---|---|---|
committer | Haruna <haru@dotalux.com> | 2014-12-04 00:16:42 +0100 |
commit | 3378fa7502f8504bf0566d9082b60e4cd7817798 (patch) | |
tree | 8677feb1604610ae9b0497660fd9afb41255432c | |
parent | d4e0689858b294260c610e77c27812797bbf26c0 (diff) | |
parent | 4d47b9b9a36c05744401df58efb76f1bd501a77f (diff) | |
download | hercules-3378fa7502f8504bf0566d9082b60e4cd7817798.tar.gz hercules-3378fa7502f8504bf0566d9082b60e4cd7817798.tar.bz2 hercules-3378fa7502f8504bf0566d9082b60e4cd7817798.tar.xz hercules-3378fa7502f8504bf0566d9082b60e4cd7817798.zip |
Merge pull request #393 from 4144/validateinterfaces
Improve validateinterfaces.py and replace some direct methods usage
-rw-r--r-- | src/map/script.c | 2 | ||||
-rw-r--r-- | src/map/unit.c | 2 | ||||
-rwxr-xr-x | tools/validateinterfaces.py | 102 |
3 files changed, 86 insertions, 20 deletions
diff --git a/src/map/script.c b/src/map/script.c index 6037c61fa..e04ba6f32 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -155,7 +155,7 @@ static void script_dump_stack(struct script_state* st) break; case C_NAME: - ShowMessage(" \"%s\" (id=%d ref=%p subtype=%s)\n", reference_getname(data), data->u.num, data->ref, script_op2name(script->str_data[data->u.num].type)); + ShowMessage(" \"%s\" (id=%d ref=%p subtype=%s)\n", reference_getname(data), data->u.num, data->ref, script->op2name(script->str_data[data->u.num].type)); break; case C_RETINFO: diff --git a/src/map/unit.c b/src/map/unit.c index 3962e771e..c78919f52 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2323,7 +2323,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i //Clear target even if there is no timer if (ud->target || ud->attacktimer != INVALID_TIMER) - unit_stop_attack(bl); + unit->stop_attack(bl); //Clear stepaction even if there is no timer if (ud->stepaction || ud->steptimer != INVALID_TIMER) diff --git a/tools/validateinterfaces.py b/tools/validateinterfaces.py index a4222adb5..b34bd6233 100755 --- a/tools/validateinterfaces.py +++ b/tools/validateinterfaces.py @@ -26,7 +26,7 @@ def searchStructStart(r, ifname): return True return False -def readCFile(cFile): +def readCFile(tracker, cFile): methods = Set() shortIfName = "" with open(cFile, "r") as r: @@ -38,7 +38,7 @@ def readCFile(cFile): ifname = m.group("name1") if searchDefault(r, ifname) == False: return (None, shortIfName, methods) - lineRe = re.compile("(?P<ifname>[a-z_]+)->(?P<method>[\w_]+) ") + lineRe = re.compile("(?P<ifname>[a-z_]+)->(?P<method>[\w_]+)[ ][=][ ](?P<fullmethod>[^;]+);") for line in r: # print "cline2: " + line test = line.strip() @@ -55,10 +55,12 @@ def readCFile(cFile): shortIfName = m.group("ifname") # print "{2}: add {0}, from: {1}".format(m.group("method"), line, ifname) methods.add(m.group("method")) + tracker.interfaces.add(ifname); + tracker.fullmethods.add(m.group("fullmethod")); return (ifname, shortIfName, methods) return (None, shortIfName, methods) -def readHFile(hFile, ifname): +def readHFile(tracker, hFile, ifname): methods = Set() with open(hFile, "r") as r: if searchStructStart(r, ifname) == False: @@ -75,15 +77,16 @@ def readHFile(hFile, ifname): if m != None: # print "{2}: add {0}, from: {1}".format(m.group("method"), line, ifname) methods.add(m.group("method")) + tracker.fullmethods.add(ifname + "_" + m.group("method")) return methods def checkIfFile(tracker, cFile, hFile): - data = readCFile(cFile) + data = readCFile(tracker, cFile) cMethods = data[2] ifname = data[0] shortIfName = data[1] if len(cMethods) > 0: - hMethods = readHFile(hFile, ifname) + hMethods = readHFile(tracker, hFile, ifname) for method in hMethods: tracker.arr[ifname + "_" + method] = list() tracker.methods.add(ifname + "_" + method) @@ -116,7 +119,7 @@ def checkChr(ch): return False def checkFile(tracker, cFile): - print "Checking: " + cFile +# print "Checking: " + cFile with open(cFile, "r") as r: for line in r: parts = re.findall(r'[\w_]+', line) @@ -130,8 +133,16 @@ def checkFile(tracker, cFile): continue if checkChr(line[idx - 1]): continue + if line[0:3] == " * ": + continue; if line[-1] == "\n": line = line[:-1] + text = line.strip() + if text[0:2] == "/*" or text[0:2] == "//": + continue + idx2 = line.find("//") + if idx2 > 0 and idx2 < idx: + continue tracker.arr[part].append(line) def processDir(tracker, srcDir): @@ -156,25 +167,80 @@ def reportMethods(tracker): print "\n" -tracker = Tracker() -tracker.arr = dict() -tracker.methods = Set() -tracker.retCode = 0 -if len(sys.argv) > 1 and sys.argv[1] == "silent": - processIfDir(tracker, "../src/char"); - processIfDir(tracker, "../src/map"); - processIfDir(tracker, "../src/login"); - processIfDir(tracker, "../src/common"); -else: - print "Checking initerfaces initialisation" +def checkLostFile(tracker, cFile): +# print "Checking: " + cFile + methodRe = re.compile("^([\w0-9* _]*)([ ]|[*])(?P<ifname>[a-z_]+)_(?P<method>[\w_]+)(|[ ])[(]") + with open(cFile, "r") as r: + for line in r: + if line.find("(") < 1 or len(line) < 3 or line[0] == "\t" or line[0] == " " or line.find("_defaults") > 0: + continue + m = methodRe.search(line) + if m != None: + name = "{0}_{1}".format(m.group("ifname"), m.group("method")) + if m.group("ifname") not in tracker.interfaces: + continue + if name not in tracker.fullmethods: +# print "src : " + line + print name + +def processLostDir(tracker, srcDir): + files = os.listdir(srcDir) + for file1 in files: + if file1[0] == '.' or file1 == "..": + continue + cPath = os.path.abspath(srcDir + os.path.sep + file1) + if not os.path.isfile(cPath): + processLostDir(tracker, cPath) + elif file1[-2:] == ".c": + checkLostFile(tracker, cPath) + +def runIf(): processIfDir(tracker, "../src/char"); processIfDir(tracker, "../src/map"); processIfDir(tracker, "../src/login"); processIfDir(tracker, "../src/common"); - print "Checking interfaces usage" + +def runLost(): + processLostDir(tracker, "../src/char"); + processLostDir(tracker, "../src/map"); + processLostDir(tracker, "../src/login"); + processLostDir(tracker, "../src/common"); + +def runLong(): processDir(tracker, "../src/char"); processDir(tracker, "../src/map"); processDir(tracker, "../src/login"); processDir(tracker, "../src/common"); reportMethods(tracker) + +tracker = Tracker() +tracker.arr = dict() +tracker.methods = Set() +tracker.fullmethods = Set() +tracker.interfaces = Set() +tracker.retCode = 0 + +if len(sys.argv) > 1: + cmd = sys.argv[1] +else: + cmd = "default" + +if cmd == "silent": + runIf() +elif cmd == "init": + print "Checking interfaces initialisation" + runIf() +elif cmd == "lost": + print "Checking not added functions to interfaces" + runLost(); +elif cmd == "long": + print "Checking interfaces usage" + runLong(); +else: + print "Checking interfaces initialisation" + runIf() + print "Checking not added functions to interfaces" + runLost(); + print "Checking interfaces usage" + runLong(); exit(tracker.retCode) |