2015-04-17 20:45:00 +00:00
|
|
|
|
#!/usr/bin/env python3
|
2015-04-16 15:18:30 +00:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2015-10-12 21:14:35 +00:00
|
|
|
|
srch = re.compile('(?<![_a-zA-Z0-9])(_[a-zA-Z0-9]*?)[ ,\}\]\)";]')
|
2015-04-16 15:46:11 +00:00
|
|
|
|
priv_split = srch.findall(priv_dec_str)
|
|
|
|
|
priv_split = sorted(set(priv_split))
|
|
|
|
|
priv_declared += priv_split;
|
|
|
|
|
|
2015-08-08 18:42:05 +00:00
|
|
|
|
srch = re.compile('params \[.*\]|PARAMS_[0-9].*|EXPLODE_[0-9]_PVT.*|DEFAULT_PARAM.*|KEY_PARAM.*|IGNORE_PRIVATE_WARNING.*')
|
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-10-12 21:14:35 +00:00
|
|
|
|
srch = re.compile('(?<![_a-zA-Z0-9])(_[a-zA-Z0-9]*?)[ ,\}\]\)";]')
|
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;
|
|
|
|
|
|
2015-10-12 21:14:35 +00:00
|
|
|
|
srch = re.compile('(?i)[\s]*local[\s]+(_[\w\d]*)[\s]*=.*')
|
|
|
|
|
priv_local = srch.findall(content)
|
|
|
|
|
priv_local_declared = sorted(set(priv_local))
|
|
|
|
|
|
|
|
|
|
priv_declared += priv_local_declared;
|
|
|
|
|
|
2015-04-16 15:46:11 +00:00
|
|
|
|
|
|
|
|
|
return priv_declared
|
|
|
|
|
|
2015-04-16 15:18:30 +00:00
|
|
|
|
def check_privates(filepath):
|
2015-04-17 20:45:00 +00:00
|
|
|
|
bad_count_file = 0
|
2015-04-16 15:18:30 +00:00
|
|
|
|
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
|
2015-10-12 21:14:35 +00:00
|
|
|
|
srch = re.compile('(?<![_a-zA-Z0-9])(_[a-zA-Z0-9]*?)[ =,\^\-\+\/\*\%\}\]\)";]')
|
2015-04-16 15:18:30 +00:00
|
|
|
|
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-17 23:13:09 +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:
|
2015-04-17 21:51:27 +00:00
|
|
|
|
if s.lower() not in map(str.lower,priv_declared):
|
|
|
|
|
if s.lower() not in map(str.lower,missing):
|
2015-04-16 15:18:30 +00:00
|
|
|
|
missing.append(s)
|
|
|
|
|
|
|
|
|
|
if len(missing) > 0:
|
2015-04-16 16:29:23 +00:00
|
|
|
|
print (filepath)
|
2015-04-18 17:50:16 +00:00
|
|
|
|
|
|
|
|
|
private_output = 'private[';
|
|
|
|
|
first = True
|
|
|
|
|
for bad_priv in missing:
|
|
|
|
|
if first:
|
|
|
|
|
first = False
|
|
|
|
|
private_output = private_output + '"' + bad_priv
|
|
|
|
|
else:
|
|
|
|
|
private_output = private_output + '", "' + bad_priv
|
|
|
|
|
|
|
|
|
|
private_output = private_output + '"];';
|
2015-04-18 18:20:10 +00:00
|
|
|
|
print (private_output)
|
2015-04-18 17:50:16 +00:00
|
|
|
|
|
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-17 20:45:00 +00:00
|
|
|
|
bad_count_file = bad_count_file + 1
|
2015-04-18 17:50:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-17 20:45:00 +00:00
|
|
|
|
return bad_count_file
|
2015-04-16 15:18:30 +00:00
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
print("#########################")
|
|
|
|
|
print("# Search your Privates #")
|
|
|
|
|
print("#########################")
|
|
|
|
|
|
|
|
|
|
sqf_list = []
|
2015-04-17 20:45:00 +00:00
|
|
|
|
bad_count = 0
|
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:
|
2015-04-17 20:45:00 +00:00
|
|
|
|
bad_count = bad_count + check_privates(filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print ("Bad Count {0}".format(bad_count))
|
2015-04-16 15:18:30 +00:00
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-04-16 16:29:23 +00:00
|
|
|
|
main()
|