2015-04-16 15:18:30 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import fnmatch
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import ntpath
|
2015-04-16 15:46:11 +00:00
|
|
|
import sys
|
|
|
|
import argparse
|
2015-04-16 15:18:30 +00:00
|
|
|
|
2015-04-16 15:46:11 +00:00
|
|
|
def get_private_declare(content):
|
|
|
|
priv_declared = []
|
|
|
|
|
|
|
|
srch = re.compile('private.*')
|
|
|
|
priv_srch_declared = srch.findall(content)
|
|
|
|
priv_srch_declared = sorted(set(priv_srch_declared))
|
|
|
|
|
|
|
|
priv_dec_str = ''.join(priv_srch_declared)
|
|
|
|
|
|
|
|
srch = re.compile('')
|
|
|
|
priv_split = srch.findall(priv_dec_str)
|
|
|
|
priv_split = sorted(set(priv_split))
|
|
|
|
priv_declared += priv_split;
|
|
|
|
|
2015-04-16 16:00:22 +00:00
|
|
|
srch = re.compile('PARAMS_[0-9].*|EXPLODE_[0-9]_PVT.*')
|
2015-04-16 15:46:11 +00:00
|
|
|
priv_srch_declared = srch.findall(content)
|
|
|
|
priv_srch_declared = sorted(set(priv_srch_declared))
|
|
|
|
|
|
|
|
priv_dec_str = ''.join(priv_srch_declared)
|
|
|
|
|
2015-04-16 16:22:11 +00:00
|
|
|
srch = re.compile('(?<![_a-zA-Z0-9])(_[a-zA-Z]*?)[ ,\}\]\)";]')
|
2015-04-16 15:46:11 +00:00
|
|
|
priv_split = srch.findall(priv_dec_str)
|
|
|
|
priv_split = sorted(set(priv_split))
|
2015-04-16 15:18:30 +00:00
|
|
|
|
2015-04-16 15:46:11 +00:00
|
|
|
priv_declared += priv_split;
|
|
|
|
|
|
|
|
|
|
|
|
return priv_declared
|
|
|
|
|
2015-04-16 15:18:30 +00:00
|
|
|
def check_privates(filepath):
|
|
|
|
|
|
|
|
def pushClosing(t):
|
|
|
|
closingStack.append(closing.expr)
|
|
|
|
closing << Literal( closingFor[t[0]] )
|
|
|
|
|
|
|
|
def popClosing():
|
|
|
|
closing << closingStack.pop()
|
|
|
|
|
|
|
|
with open(filepath, 'r') as file:
|
|
|
|
content = file.read()
|
|
|
|
|
|
|
|
priv_use = []
|
|
|
|
priv_use = []
|
2015-04-16 15:46:11 +00:00
|
|
|
|
2015-04-16 15:18:30 +00:00
|
|
|
|
|
|
|
# Regex search privates
|
|
|
|
srch = re.compile('(?<![_a-zA-Z])(_[a-zA-Z]*?)[ ,\}\]\)";]')
|
|
|
|
priv_use = srch.findall(content)
|
|
|
|
priv_use = sorted(set(priv_use))
|
|
|
|
|
|
|
|
# Private declaration search
|
2015-04-16 15:46:11 +00:00
|
|
|
priv_declared = get_private_declare(content)
|
2015-04-16 15:18:30 +00:00
|
|
|
|
|
|
|
if '_this' in priv_declared: priv_declared.remove('_this')
|
|
|
|
if '_this' in priv_use: priv_use.remove('_this')
|
|
|
|
|
|
|
|
if '_x' in priv_declared: priv_declared.remove('_x')
|
|
|
|
if '_x' in priv_use: priv_use.remove('_x')
|
|
|
|
|
|
|
|
if '_forEachIndex' in priv_declared: priv_declared.remove('_forEachIndex')
|
|
|
|
if '_forEachIndex' in priv_use: priv_use.remove('_forEachIndex')
|
2015-04-16 15:46:11 +00:00
|
|
|
if '_foreachIndex' in priv_declared: priv_declared.remove('_foreachIndex')
|
|
|
|
if '_foreachIndex' in priv_use: priv_use.remove('_foreachIndex')
|
2015-04-16 15:18:30 +00:00
|
|
|
|
|
|
|
missing = []
|
|
|
|
for s in priv_use:
|
|
|
|
if s not in priv_declared:
|
|
|
|
if s not in missing:
|
|
|
|
missing.append(s)
|
|
|
|
|
|
|
|
if len(missing) > 0:
|
2015-04-16 16:29:23 +00:00
|
|
|
print (filepath)
|
2015-04-16 15:18:30 +00:00
|
|
|
for bad_priv in missing:
|
2015-04-16 16:29:23 +00:00
|
|
|
print ('\t' + bad_priv)
|
2015-04-16 15:18:30 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
print("#########################")
|
|
|
|
print("# Search your Privates #")
|
|
|
|
print("#########################")
|
|
|
|
|
|
|
|
sqf_list = []
|
2015-04-16 16:00:22 +00:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('-m','--module', help='only search specified module addon folder', required=False, default=".")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
for root, dirnames, filenames in os.walk('../addons' + '/' + args.module):
|
2015-04-16 15:18:30 +00:00
|
|
|
for filename in fnmatch.filter(filenames, '*.sqf'):
|
|
|
|
sqf_list.append(os.path.join(root, filename))
|
|
|
|
|
|
|
|
for filename in sqf_list:
|
|
|
|
check_privates(filename)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-04-16 16:29:23 +00:00
|
|
|
main()
|