summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroy <tom_adams@web.de>2023-06-16 20:56:33 +0200
committerGitHub <noreply@github.com>2023-06-16 20:56:33 +0200
commitbf6624b01397090b9ce1eff45c1e3e714ed5bdb6 (patch)
treec5f198bf088ee52ecee18ebd79bd07d58ecc1667
parent64cdbc1a3d2d5934f7142459917fb5d6bd387c2a (diff)
parent7d8cbb15d1daae81c38d9ea62f3b732af2fd729d (diff)
Merge pull request #3082 from Robyt3/scripts-identifier-check
Add scripts to detect variable name style violations, remove old script and obsolete ignore_convention comments
-rw-r--r--scripts/check_identifiers.py73
-rw-r--r--scripts/extract_identifiers.py170
-rw-r--r--scripts/refactor_count.py351
-rw-r--r--src/engine/client/client.cpp18
-rw-r--r--src/engine/client/graphics_threaded.cpp26
-rw-r--r--src/engine/client/input.cpp22
-rw-r--r--src/engine/client/sound.cpp12
-rw-r--r--src/engine/client/textrender.cpp8
-rw-r--r--src/engine/server/server.cpp16
-rw-r--r--src/engine/shared/datafile.cpp6
-rw-r--r--src/engine/shared/storage.cpp2
11 files changed, 298 insertions, 406 deletions
diff --git a/scripts/check_identifiers.py b/scripts/check_identifiers.py
new file mode 100644
index 000000000..7ad727506
--- /dev/null
+++ b/scripts/check_identifiers.py
@@ -0,0 +1,73 @@
+import csv
+import sys
+import re
+
+def check_name(kind, qualifiers, type, name):
+ if kind == "variable":
+ return check_variable_name(qualifiers, type, name)
+ elif kind in "class struct".split():
+ if name[0] not in "CI":
+ return "should start with 'C' (or 'I' for interfaces)"
+ if len(name) < 2:
+ return "must be at least two characters long"
+ if not name[1].isupper():
+ return "must start with an uppercase letter"
+ elif kind == "enum_constant":
+ if not name.isupper():
+ return "must only contain uppercase letters, digits and underscores"
+ return None
+
+ALLOW = set("""
+ dx dy
+ fx fy
+ mx my
+ ix iy
+ px py
+ sx sy
+ wx wy
+ x0 x1
+ y0 y1
+""".split())
+def check_variable_name(qualifiers, type, name):
+ if qualifiers == "" and type == "" and name == "argc":
+ return None
+ if qualifiers == "" and type == "pp" and name == "argv":
+ return None
+ if qualifiers == "cs":
+ # Allow all uppercase names for constant statics.
+ if name.isupper():
+ return None
+ qualifiers = "s"
+ # Allow single lowercase letters as member and variable names.
+ if qualifiers in ["m", ""] and len(name) == 1 and name.islower():
+ return None
+ prefix = "".join([qualifiers, "_" if qualifiers else "", type])
+ if not name.startswith(prefix):
+ return "should start with {!r}".format(prefix)
+ if name in ALLOW:
+ return None
+ name = name[len(prefix):]
+ if not name[0].isupper():
+ if prefix:
+ return "should start with an uppercase letter after the prefix {!r}".format(prefix)
+ else:
+ return "should start with an uppercase letter"
+ return None
+
+def main():
+ import argparse
+ p = argparse.ArgumentParser(description="Check identifiers (input via stdin in CSV format from extract_identifiers.py) for naming style in Teeworlds code")
+ args = p.parse_args()
+
+ identifiers = list(csv.DictReader(sys.stdin))
+
+ unclean = False
+ for i in identifiers:
+ error = check_name(i["kind"], i["qualifiers"], i["type"], i["name"])
+ if error:
+ unclean = True
+ print("{}:{}:{}: {}: {}".format(i["file"], i["line"], i["column"], i["name"], error))
+ return unclean
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/scripts/extract_identifiers.py b/scripts/extract_identifiers.py
new file mode 100644
index 000000000..99f2ed77c
--- /dev/null
+++ b/scripts/extract_identifiers.py
@@ -0,0 +1,170 @@
+import clang.cindex
+import csv
+import enum
+import os
+import sys
+
+from clang.cindex import CursorKind, LinkageKind, StorageClass, TypeKind
+from collections import Counter
+
+try:
+ from tqdm import tqdm
+except ImportError:
+ def tqdm(it, *args, **kwargs):
+ return it
+
+def traverse_namespaced(root, filter_files=None, skip_namespaces=1, namespace=()):
+ if root.location.file is not None and root.location.file.name not in filter_files:
+ return
+ yield namespace, root
+ if root.displayname != "":
+ if skip_namespaces > 0:
+ skip_namespaces -= 1
+ else:
+ namespace += (root.spelling,)
+ for node in root.get_children():
+ yield from traverse_namespaced(node, filter_files, skip_namespaces, namespace)
+
+INTERESTING_NODE_KINDS = {
+ CursorKind.CLASS_DECL: "class",
+ CursorKind.CLASS_TEMPLATE: "class",
+ CursorKind.ENUM_DECL: "enum",
+ CursorKind.ENUM_CONSTANT_DECL: "enum_constant",
+ CursorKind.FIELD_DECL: "variable",
+ CursorKind.PARM_DECL: "variable",
+ CursorKind.STRUCT_DECL: "struct",
+ CursorKind.UNION_DECL: "union",
+ CursorKind.VAR_DECL: "variable",
+ CursorKind.FUNCTION_DECL: "function",
+}
+
+def is_array_type(type):
+ return type.kind in (TypeKind.CONSTANTARRAY, TypeKind.DEPENDENTSIZEDARRAY, TypeKind.INCOMPLETEARRAY)
+
+def get_complex_type(type):
+ if type.spelling in ("IOHANDLE", "LOCK"):
+ return ""
+ if type.kind == TypeKind.AUTO:
+ return get_complex_type(type.get_canonical())
+ if type.kind == TypeKind.LVALUEREFERENCE:
+ return get_complex_type(type.get_pointee())
+ if type.kind == TypeKind.POINTER:
+ return "p" + get_complex_type(type.get_pointee())
+ if is_array_type(type):
+ return "a" + get_complex_type(type.element_type)
+ if type.kind == TypeKind.FUNCTIONPROTO:
+ return "fn"
+ if type.kind == TypeKind.TYPEDEF:
+ return get_complex_type(type.get_declaration().underlying_typedef_type)
+ if type.kind == TypeKind.ELABORATED:
+ return get_complex_type(type.get_named_type())
+ if type.kind in (TypeKind.UNEXPOSED, TypeKind.RECORD):
+ if type.get_declaration().spelling in "shared_ptr unique_ptr".split():
+ return "p" + get_complex_type(type.get_template_argument_type(0))
+ if type.get_declaration().spelling in "array sorted_array".split():
+ return "a" + get_complex_type(type.get_template_argument_type(0))
+ return ""
+
+def is_static_member_definition_hack(node):
+ last_colons = False
+ for t in node.get_tokens():
+ t = t.spelling
+ if t == "::":
+ last_colons = True
+ elif last_colons:
+ if t.startswith("ms_"):
+ return True
+ last_colons = False
+ if t == "=":
+ return False
+ return False
+
+def is_const(type):
+ if type.is_const_qualified():
+ return True
+ if is_array_type(type):
+ return is_const(type.element_type)
+ return False
+
+class ParseError(RuntimeError):
+ pass
+
+def process_source_file(out, file, extra_args, break_on):
+ args = extra_args + ["-Isrc"]
+ if file.endswith(".c"):
+ header = "{}.h".format(file[:-2])
+ elif file.endswith(".cpp"):
+ header = "{}.h".format(file[:-4])
+ else:
+ raise ValueError("unrecognized source file: {}".format(file))
+
+ index = clang.cindex.Index.create()
+ unit = index.parse(file, args=args)
+ errors = list(unit.diagnostics)
+ if errors:
+ for error in errors:
+ print("{}: {}".format(file, error.format()), file=sys.stderr)
+ print(args, file=sys.stderr)
+ raise ParseError("failed parsing {}".format(file))
+
+ filter_files = frozenset([file, header])
+
+ for namespace, node in traverse_namespaced(unit.cursor, filter_files=filter_files):
+ cur_file = None
+ if node.location.file is not None:
+ cur_file = node.location.file.name
+ if cur_file is None or (cur_file != file and cur_file != header):
+ continue
+ if node.kind in INTERESTING_NODE_KINDS and node.spelling:
+ type = get_complex_type(node.type)
+ qualifiers = ""
+ if INTERESTING_NODE_KINDS[node.kind] in {"variable", "function"}:
+ is_member = node.semantic_parent.kind in {CursorKind.CLASS_DECL, CursorKind.CLASS_TEMPLATE, CursorKind.STRUCT_DECL, CursorKind.UNION_DECL}
+ is_static = node.storage_class == StorageClass.STATIC or is_static_member_definition_hack(node)
+ if is_static:
+ qualifiers = "s" + qualifiers
+ if is_member:
+ qualifiers = "m" + qualifiers
+ if is_static and not is_member and is_const(node.type):
+ qualifiers = "c" + qualifiers
+ if node.linkage == LinkageKind.EXTERNAL and not is_member:
+ qualifiers = "g" + qualifiers
+ out.writerow({
+ "file": cur_file,
+ "line": node.location.line,
+ "column": node.location.column,
+ "kind": INTERESTING_NODE_KINDS[node.kind],
+ "path": "::".join(namespace),
+ "qualifiers": qualifiers,
+ "type": type,
+ "name": node.spelling,
+ })
+ if node.spelling == break_on:
+ breakpoint()
+
+def main():
+ import argparse
+ p = argparse.ArgumentParser(description="Extracts identifier data from a Teeworlds source file and its header, outputting the data as CSV to stdout")
+ p.add_argument("file", metavar="FILE", nargs="+", help="Source file to analyze")
+ p.add_argument("--break-on", help="Break on a specific variable name, useful to debug issues with the script")
+ args = p.parse_args()
+
+ extra_args = []
+ if "CXXFLAGS" in os.environ:
+ extra_args = os.environ["CXXFLAGS"].split()
+
+ out = csv.DictWriter(sys.stdout, "file line column kind path qualifiers type name".split())
+ out.writeheader()
+ files = args.file
+ if len(files) > 1:
+ files = tqdm(files, leave=False)
+ error = False
+ for file in files:
+ try:
+ process_source_file(out, file, extra_args, args.break_on)
+ except ParseError:
+ error = True
+ return int(error)
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/scripts/refactor_count.py b/scripts/refactor_count.py
deleted file mode 100644
index dac42e2b8..000000000
--- a/scripts/refactor_count.py
+++ /dev/null
@@ -1,351 +0,0 @@
-import os, re, sys
-
-alphanum = "0123456789abcdefghijklmnopqrstuvwzyxABCDEFGHIJKLMNOPQRSTUVWXYZ_"
-cpp_keywords = ["auto", "const", "double", "float", "int", "short", "struct", "unsigned", # C
-"break", "continue", "else", "for", "long", "signed", "switch", "void",
-"case", "default", "enum", "goto", "register", "sizeof", "typedef", "volatile",
-"char", "do", "extern", "if", "return", "static", "union", "while",
-
-"asm", "dynamic_cast", "namespace", "reinterpret_cast", "try", # C++
-"bool", "explicit", "new", "static_cast", "typeid",
-"catch", "false", "operator", "template", "typename",
-"class", "friend", "private", "this", "using",
-"const_cast", "inline", "public", "throw", "virtual",
-"delete", "mutable", "protected", "true", "wchar_t"]
-
-allowed_words = []
-
-#allowed_words += ["bitmap_left", "advance", "glyph"] # ft2
-
-
-allowed_words += ["qsort"] # stdio / stdlib
-allowed_words += ["size_t", "cosf", "sinf", "asinf", "acosf", "atanf", "powf", "fabs", "rand", "powf", "fmod", "sqrtf"] # math.h
-allowed_words += ["time_t", "time", "strftime", "localtime"] # time.h
-allowed_words += [ # system.h
- "int64",
- "dbg_assert", "dbg_msg", "dbg_break", "dbg_logger_stdout", "dbg_logger_debugger", "dbg_logger_file",
- "mem_alloc", "mem_zero", "mem_free", "mem_copy", "mem_move", "mem_comp", "mem_stats", "total_allocations", "allocated",
- "thread_create", "thread_sleep", "lock_wait", "lock_create", "lock_release", "lock_destroy", "swap_endian",
- "io_open", "io_read", "io_read", "io_write", "io_flush", "io_close", "io_seek", "io_skip", "io_tell", "io_length",
- "str_comp", "str_length", "str_quickhash", "str_format", "str_copy", "str_comp_nocase", "str_sanitize", "str_append",
- "str_comp_num", "str_find_nocase", "str_sanitize_strong", "str_uppercase", "str_toint", "str_tofloat",
- "str_utf8_encode", "str_utf8_rewind", "str_utf8_forward", "str_utf8_decode", "str_sanitize_cc", "str_skip_whitespaces",
- "fs_makedir", "fs_listdir", "fs_storage_path", "fs_is_dir",
- "net_init", "net_addr_comp", "net_host_lookup", "net_addr_str", "type", "port", "net_addr_from_str",
- "net_udp_create", "net_udp_send", "net_udp_recv", "net_udp_close", "net_socket_read_wait",
- "net_stats", "sent_bytes", "recv_bytes", "recv_packets", "sent_packets",
- "time_get", "time_freq", "time_timestamp"]
-
-allowed_words += ["vec2", "vec3", "vec4", "round", "clamp", "length", "dot", "normalize", "random_float", "mix", "distance", "min",
- "closest_point_on_line", "max", "absolute"] # math.hpp
-allowed_words += [ # tl
- "array", "sorted_array", "string",
- "all", "sort", "add", "remove_index", "remove", "delete_all", "set_size",
- "base_ptr", "size", "swap", "empty", "front", "pop_front", "find_binary", "find_linear", "clear", "range", "end", "cstr",
- "partition_linear", "partition_binary"]
-allowed_words += ["fx2f", "f2fx"] # fixed point math
-
-def CheckIdentifier(ident):
- return False
-
-class Checker:
- def CheckStart(self, checker, filename):
- pass
- def CheckLine(self, checker, line):
- pass
- def CheckEnd(self, checker):
- pass
-
-class FilenameExtentionChecker(Checker):
- def __init__(self):
- self.allowed = [".cpp", ".h"]
- def CheckStart(self, checker, filename):
- ext = os.path.splitext(filename)[1]
- if not ext in self.allowed:
- checker.Error("file extention '%s' is not allowed" % ext)
-
-class IncludeChecker(Checker):
- def __init__(self):
- self.disallowed_headers = ["stdio.h", "stdlib.h", "string.h", "memory.h"]
- def CheckLine(self, checker, line):
- if "#include" in line:
- include_file = ""
- if '<' in line:
- include_file = line.split('<')[1].split(">")[0]
- #if not "/" in include_file:
- # checker.Error("%s is not allowed" % include_file)
- elif '"' in line:
- include_file = line.split('"')[1]
-
- #print include_file
- if include_file in self.disallowed_headers:
- checker.Error("%s is not allowed" % include_file)
-
-class HeaderGuardChecker(Checker):
- def CheckStart(self, checker, filename):
- self.check = ".h" in filename
- self.guard = "#ifndef " + filename[4:].replace("/", "_").replace(".hpp", "").replace(".h", "").upper() + "_H"
- def CheckLine(self, checker, line):
- if self.check:
- #if "#" in line:
- self.check = False
- #if not self.check:
- if line.strip() == self.guard:
- pass
- else:
- checker.Error("malformed or missing header guard. Should be '%s'" % self.guard)
-
-class CommentChecker(Checker):
- def CheckLine(self, checker, line):
- if line.strip()[-2:] == "*/" and "/*" in line:
- checker.Error("single line multiline comment")
-
-class FileChecker:
- def __init__(self):
- self.checkers = []
- self.checkers += [FilenameExtentionChecker()]
- self.checkers += [HeaderGuardChecker()]
- self.checkers += [IncludeChecker()]
- self.checkers += [CommentChecker()]
-
- def Error(self, errormessage):
- self.current_errors += [(self.current_line, errormessage)]
-
- def CheckLine(self, line):
- for c in self.checkers:
- c.CheckLine(self, line)
- return True
-
- def CheckFile(self, filename):
- self.current_file = filename
- self.current_line = 0
- self.current_errors = []
- for c in self.checkers:
- c.CheckStart(self, filename)
-
- for line in file(filename).readlines():
- self.current_line += 1
- if "ignore_check" in line:
- continue
- self.CheckLine(line)
-
- for c in self.checkers:
- c.CheckEnd(self)
-
- def GetErrors(self):
- return self.current_errors
-
-def cstrip(lines):
- d = ""
- for l in lines:
- if "ignore_convention" in l:
- continue
- l = re.sub("^[\t ]*#.*", "", l)
- l = re.sub("//.*", "", l)
- l = re.sub('\".*?\"', '"String"', l) # remove strings
- d += l.strip() + " "
- d = re.sub('\/\*.*?\*\/', "", d) # remove /* */ comments
- d = d.replace("\t", " ") # tab to space
- d = re.sub(" *", " ", d) # remove double spaces
- #d = re.sub("", "", d) # remove /* */ comments
-
- d = d.strip()
-
- # this eats up cases like 'n {'
- i = 1
- while i < len(d)-2:
- if d[i] == ' ':
- if not (d[i-1] in alphanum and d[i+1] in alphanum):
- d = d[:i] + d[i+1:]
- i += 1
- return d
-
-#def stripstrings(data):
-# return re.sub('\".*?\"', 'STRING', data)
-
-def get_identifiers(data):
- idents = {}
- data = " "+data+" "
- regexp = re.compile("[^a-zA-Z0-9_][a-zA-Z_][a-zA-Z0-9_]+[^a-zA-Z0-9_]")
- start = 0
- while 1:
- m = regexp.search(data, start)
-
- if m == None:
- break
- start = m.end()-1
- name = data[m.start()+1:m.end()-1]
- if name in idents:
- idents[name] += 1
- else:
- idents[name] = 1
- return idents
-
-grand_total = 0
-grand_offenders = 0
-
-gen_html = 1
-
-if gen_html:
- print "<head>"
- print '<link href="/style.css" rel="stylesheet" type="text/css" />'
- print "</head>"
- print "<body>"
-
-
-
- print '<div id="outer">'
-
- print '<div id="top_left"><div id="top_right"><div id="top_mid">'
- print '<a href="/"><img src="/images/twlogo.png" alt="teeworlds logo" /></a>'
- print '</div></div></div>'
-
- print '<div id="menu_left"><div id="menu_right"><div id="menu_mid">'
- print '</div></div></div>'
-
- print '<div id="tlc"><div id="trc"><div id="tb">&nbsp;</div></div></div>'
- print '<div id="lb"><div id="rb"><div id="mid">'
- print '<div id="container">'
-
- print '<p class="topic_text">'
- print '<h1>Code Refactoring Progress</h1>'
- print '''This is generated by a script that find identifiers in the code
- that doesn't conform to the code standard. Right now it only shows headers
- because they need to be fixed before we can do the rest of the source.
- This is a ROUGH estimate of the progress'''
- print '</p>'
-
- print '<p class="topic_text">'
- print '<table>'
- #print "<tr><td><b>%</b></td><td><b>#</b></td><td><b>File</b></td><td><b>Offenders</b></td></tr>"
-
-line_order = 1
-total_files = 0
-complete_files = 0
-total_errors = 0
-
-for (root,dirs,files) in os.walk("src"):
- for filename in files:
- filename = os.path.join(root, filename)
- if "/." in filename or "/external/" in filename or "/base/" in filename or "/generated/" in filename:
- continue
- if "src/osxlaunch/client.h" in filename: # ignore this file, ObjC file
- continue
- if "e_config_variables.h" in filename: # ignore config files
- continue
- if "src/game/variables.hpp" in filename: # ignore config files
- continue
-
- if not (".hpp" in filename or ".h" in filename or ".cpp" in filename):
- continue
-
- #total_files += 1
-
- #if not "src/engine/client/ec_client.cpp" in filename:
- # continue
-
- f = FileChecker()
- f.CheckFile(filename)
- num_errors = len(f.GetErrors())
- total_errors += num_errors
-
- if num_errors:
- print '<tr style="background: #e0e0e0"><td colspan="2">%s, %d errors</td></tr>' % (filename, num_errors),
- for line, msg in f.GetErrors():
- print '<tr"><td>%d</td><td>%s</td></tr>' % (line, msg)
- #print '<table>'
- #GetErrors()
-
-
-
-
- if 0:
- text = cstrip(file(filename).readlines()) # remove all preprocessor stuff and comments
- #text = stripstrings(text) # remove strings (does not solve all cases however)
- #print text
-
- idents = get_identifiers(text)
- offenders = 0
- total = 0
- offender_list = {}
- for name in idents:
- #print name
- if len(name) <= 2: # skip things that are too small
- continue
- if name in cpp_keywords: # skip keywords
- continue
- if name in allowed_words: # skip allowed keywords
- continue
-
- total += idents[name]
- if name != name.lower(): # strip names that are not only lower case
- continue
- offender_list[name] = idents[name]
- if not gen_html:
- print "[%d] %s"%(idents[name], name)
- offenders += idents[name]
-
- grand_total += total
- grand_offenders += offenders
-
- if total == 0:
- total = 1
-
- line_order = -line_order
-
-
- done = int((1-(offenders / float(total))) * 100)
- if done == 100:
- complete_files += 1
-
- if done != 100 and gen_html:
- color = "#ffa0a0"
- if done > 20:
- color = "#ffd080"
- if done > 50:
- color = "#ffff80"
- if done > 75:
- color = "#e0ff80"
- if done == 100:
- color = "#80ff80"
-
- line_color = "#f0efd5"
- if line_order > 0:
- line_color = "#ffffff"
-
- offender_string = ""
- count = 0
- for name in offender_list:
- count += 1
- offender_string += "[%d]%s " % (offender_list[name], name)
-
- if count%5 == 0:
- offender_string += "<br/>"
-
- print '<tr style="background: %s">' % line_color,
- print '<td style="text-align: right; background: %s"><b>%d%%</b></td><td style="text-align: center">%d</td><td>%s</td>' % (color, done, offenders, filename),
- print '<td style="text-align: right">%s</td>' % offender_string
- print "</tr>"
- count = 0
-
-if gen_html:
- print "</table>"
-
- print "<h1>%d errors</h1>" % total_errors
-
-
- if 0:
- print "<h1>%.1f%% Identifiers done</h1>" % ((1-(grand_offenders / float(grand_total))) * 100)
- print "%d left of %d" % (grand_offenders, grand_total)
- print "<h1>%.1f%% Files done</h1>" % ((complete_files / float(total_files)) * 100)
- print "%d left of %d" % (total_files-complete_files, total_files)
-
- print "</p>"
- print "<div style='clear:both;'></div>"
- print '</div>'
- print '</div></div></div>'
-
- print '<div id="blc"><div id="brc"><div id="bb">&nbsp;</div></div></div>'
- print '</div>'
-
- print "</body>"
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp
index 04e6e127e..39ca1cb73 100644
--- a/src/engine/client/client.cpp
+++ b/src/engine/client/client.cpp
@@ -1922,7 +1922,7 @@ void CClient::Run()
return;
}
- atexit(SDL_Quit); // ignore_convention
+ atexit(SDL_Quit);
}
// init graphics
@@ -2546,17 +2546,17 @@ void CClient::DoVersionSpecificActions()
Upstream latency
*/
#if defined(CONF_PLATFORM_MACOS)
-extern "C" int TWMain(int argc, const char **argv) // ignore_convention
+extern "C" int TWMain(int argc, const char **argv)
#else
-int main(int argc, const char **argv) // ignore_convention
+int main(int argc, const char **argv)
#endif
{
cmdline_fix(&argc, &argv);
#if defined(CONF_FAMILY_WINDOWS)
bool QuickEditMode = false;
- for(int i = 1; i < argc; i++) // ignore_convention
+ for(int i = 1; i < argc; i++)
{
- if(str_comp("--quickeditmode", argv[i]) == 0) // ignore_convention
+ if(str_comp("--quickeditmode", argv[i]) == 0)
{
QuickEditMode = true;
}
@@ -2564,9 +2564,9 @@ int main(int argc, const char **argv) // ignore_convention
#endif
bool UseDefaultConfig = false;
- for(int i = 1; i < argc; i++) // ignore_convention
+ for(int i = 1; i < argc; i++)
{
- if(str_comp("-d", argv[i]) == 0 || str_comp("--default", argv[i]) == 0) // ignore_convention
+ if(str_comp("-d", argv[i]) == 0 || str_comp("--default", argv[i]) == 0)
{
UseDefaultConfig = true;
break;
@@ -2584,7 +2584,7 @@ int main(int argc, const char **argv) // ignore_convention
int FlagMask = CFGFLAG_CLIENT;
IEngine *pEngine = CreateEngine("Teeworlds");
IConsole *pConsole = CreateConsole(FlagMask);
- IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_CLIENT, argc, argv); // ignore_convention
+ IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_CLIENT, argc, argv);
IConfigManager *pConfigManager = CreateConfigManager();
IEngineSound *pEngineSound = CreateEngineSound();
IEngineInput *pEngineInput = CreateEngineInput();
@@ -2655,7 +2655,7 @@ int main(int argc, const char **argv) // ignore_convention
pConsole->ExecuteFile("autoexec.cfg");
// parse the command line arguments
- if(argc > 1) // ignore_convention
+ if(argc > 1)
{
const char *pAddress = 0;
if(argc == 2)
diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp
index 00be6121c..b9f7125b5 100644
--- a/src/engine/client/graphics_threaded.cpp
+++ b/src/engine/client/graphics_threaded.cpp
@@ -408,9 +408,9 @@ int CGraphics_Threaded::LoadPNG(CImageInfo *pImg, const char *pFilename, int Sto
return 0;
}
- png_init(0, 0); // ignore_convention
- png_t Png; // ignore_convention
- int Error = png_open_read(&Png, 0, File); // ignore_convention
+ png_init(0, 0);
+ png_t Png;
+ int Error = png_open_read(&Png, 0, File);
if(Error != PNG_NO_ERROR)
{
dbg_msg("game/png", "failed to read file. filename='%s'", aCompleteFilename);
@@ -418,22 +418,22 @@ int CGraphics_Threaded::LoadPNG(CImageInfo *pImg, const char *pFilename, int Sto
return 0;
}
- if(Png.depth != 8 || (Png.color_type != PNG_TRUECOLOR && Png.color_type != PNG_TRUECOLOR_ALPHA) || Png.width > (2<<12) || Png.height > (2<<12)) // ignore_convention
+ if(Png.depth != 8 || (Png.color_type != PNG_TRUECOLOR && Png.color_type != PNG_TRUECOLOR_ALPHA) || Png.width > (2<<12) || Png.height > (2<<12))
{
dbg_msg("game/png", "invalid format. filename='%s'", aCompleteFilename);
io_close(File);
return 0;
}
- unsigned char *pBuffer = (unsigned char *)mem_alloc(Png.width * Png.height * Png.bpp); // ignore_convention
- png_get_data(&Png, pBuffer); // ignore_convention
+ unsigned char *pBuffer = (unsigned char *)mem_alloc(Png.width * Png.height * Png.bpp);
+ png_get_data(&Png, pBuffer);
io_close(File);
- pImg->m_Width = Png.width; // ignore_convention
- pImg->m_Height = Png.height; // ignore_convention
- if(Png.color_type == PNG_TRUECOLOR) // ignore_convention
+ pImg->m_Width = Png.width;
+ pImg->m_Height = Png.height;
+ if(Png.color_type == PNG_TRUECOLOR)
pImg->m_Format = CImageInfo::FORMAT_RGB;
- else if(Png.color_type == PNG_TRUECOLOR_ALPHA) // ignore_convention
+ else if(Png.color_type == PNG_TRUECOLOR_ALPHA)
pImg->m_Format = CImageInfo::FORMAT_RGBA;
pImg->m_pData = pBuffer;
return 1;
@@ -474,9 +474,9 @@ void CGraphics_Threaded::ScreenshotDirect(const char *pFilename)
if(File)
{
// save png
- png_t Png; // ignore_convention
- png_open_write(&Png, 0, File); // ignore_convention
- png_set_data(&Png, Image.m_Width, Image.m_Height, 8, PNG_TRUECOLOR, (unsigned char *)Image.m_pData); // ignore_convention
+ png_t Png;
+ png_open_write(&Png, 0, File);
+ png_set_data(&Png, Image.m_Width, Image.m_Height, 8, PNG_TRUECOLOR, (unsigned char *)Image.m_pData);
io_close(File);
str_format(aBuf, sizeof(aBuf), "saved screenshot to '%s'", aWholePath);
}
diff --git a/src/engine/client/input.cpp b/src/engine/client/input.cpp
index 06e9df9c9..4969696b3 100644
--- a/src/engine/client/input.cpp
+++ b/src/engine/client/input.cpp
@@ -593,7 +593,7 @@ int CInput::Update()
// fall through
case SDL_MOUSEBUTTONDOWN:
- if(Event.button.button == SDL_BUTTON_LEFT) // ignore_convention
+ if(Event.button.button == SDL_BUTTON_LEFT)
{
Key = KEY_MOUSE_1;
if(Event.button.clicks%2 == 0)
@@ -601,20 +601,20 @@ int CInput::Update()
else if(Event.button.clicks == 1)
m_MouseDoubleClick = false;
}
- else if(Event.button.button == SDL_BUTTON_RIGHT) Key = KEY_MOUSE_2; // ignore_convention
- else if(Event.button.button == SDL_BUTTON_MIDDLE) Key = KEY_MOUSE_3; // ignore_convention
- else if(Event.button.button == SDL_BUTTON_X1) Key = KEY_MOUSE_4; // ignore_convention
- else if(Event.button.button == SDL_BUTTON_X2) Key = KEY_MOUSE_5; // ignore_convention
- else if(Event.button.button == 6) Key = KEY_MOUSE_6; // ignore_convention
- else if(Event.button.button == 7) Key = KEY_MOUSE_7; // ignore_convention
- else if(Event.button.button == 8) Key = KEY_MOUSE_8; // ignore_convention
- else if(Event.button.button == 9) Key = KEY_MOUSE_9; // ignore_convention
+ else if(Event.button.button == SDL_BUTTON_RIGHT) Key = KEY_MOUSE_2;
+ else if(Event.button.button == SDL_BUTTON_MIDDLE) Key = KEY_MOUSE_3;
+ else if(Event.button.button == SDL_BUTTON_X1) Key = KEY_MOUSE_4;
+ else if(Event.button.button == SDL_BUTTON_X2) Key = KEY_MOUSE_5;
+ else if(Event.button.button == 6) Key = KEY_MOUSE_6;
+ else if(Event.button.button == 7) Key = KEY_MOUSE_7;
+ else if(Event.button.button == 8) Key = KEY_MOUSE_8;
+ else if(Event.button.button == 9) Key = KEY_MOUSE_9;
Scancode = Key;
break;
case SDL_MOUSEWHEEL:
- if(Event.wheel.y > 0) Key = KEY_MOUSE_WHEEL_UP; // ignore_convention
- else if(Event.wheel.y < 0) Key = KEY_MOUSE_WHEEL_DOWN; // ignore_convention
+ if(Event.wheel.y > 0) Key = KEY_MOUSE_WHEEL_UP;
+ else if(Event.wheel.y < 0) Key = KEY_MOUSE_WHEEL_DOWN;
else break;
Action |= IInput::FLAG_RELEASE;
Scancode = Key;
diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp
index 9f59a6c2f..c8184b925 100644
--- a/src/engine/client/sound.cpp
+++ b/src/engine/client/sound.cpp
@@ -221,12 +221,12 @@ int CSound::Init()
m_MixingRate = m_pConfig->m_SndRate;
// Set 16-bit stereo audio at 22Khz
- Format.freq = m_pConfig->m_SndRate; // ignore_convention
- Format.format = AUDIO_S16; // ignore_convention
- Format.channels = 2; // ignore_convention
- Format.samples = m_pConfig->m_SndBufferSize; // ignore_convention
- Format.callback = SdlCallback; // ignore_convention
- Format.userdata = NULL; // ignore_convention
+ Format.freq = m_pConfig->m_SndRate;
+ Format.format = AUDIO_S16;
+ Format.channels = 2;
+ Format.samples = m_pConfig->m_SndBufferSize;
+ Format.callback = SdlCallback;
+ Format.userdata = NULL;
// Open the audio device and start playing sound!
if(SDL_OpenAudio(&Format, NULL) < 0)
diff --git a/src/engine/client/textrender.cpp b/src/engine/client/textrender.cpp
index 1a3c99bf2..255216825 100644
--- a/src/engine/client/textrender.cpp
+++ b/src/engine/client/textrender.cpp
@@ -388,7 +388,7 @@ bool CGlyphMap::RenderGlyph(CGlyph *pGlyph, bool Render)
return false;
}
- pBitmap = &GlyphFace->glyph->bitmap; // ignore_convention
+ pBitmap = &GlyphFace->glyph->bitmap;
// adjust spacing
int OutlineThickness = AdjustOutlineThicknessToFontSize(1, FontSize);
@@ -452,9 +452,9 @@ bool CGlyphMap::RenderGlyph(CGlyph *pGlyph, bool Render)
pGlyph->m_Face = GlyphFace;
pGlyph->m_Height = OutlinedHeight * Scale;
pGlyph->m_Width = OutlinedWidth * Scale;
- pGlyph->m_BearingX = (GlyphFace->glyph->bitmap_left-OutlineThickness/2) * Scale; // ignore_convention
- pGlyph->m_BearingY = (FontSize - GlyphFace->glyph->bitmap_top-OutlineThickness/2) * Scale; // ignore_convention
- pGlyph->m_AdvanceX = (GlyphFace->glyph->advance.x>>6) * Scale; // ignore_convention
+ pGlyph->m_BearingX = (GlyphFace->glyph->bitmap_left-OutlineThickness/2) * Scale;
+ pGlyph->m_BearingY = (FontSize - GlyphFace->glyph->bitmap_top-OutlineThickness/2) * Scale;
+ pGlyph->m_AdvanceX = (GlyphFace->glyph->advance.x>>6) * Scale;
pGlyph->m_Rendered = Render;
return true;
diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp
index 4aedd51c9..6ec222e21 100644
--- a/src/engine/server/server.cpp
+++ b/src/engine/server/server.cpp
@@ -1809,13 +1809,13 @@ void HandleSigIntTerm(int Param)
signal(SIGTERM, SIG_DFL);
}
-int main(int argc, const char **argv) // ignore_convention
+int main(int argc, const char **argv)
{
cmdline_fix(&argc, &argv);
#if defined(CONF_FAMILY_WINDOWS)
- for(int i = 1; i < argc; i++) // ignore_convention
+ for(int i = 1; i < argc; i++)
{
- if(str_comp("-s", argv[i]) == 0 || str_comp("--silent", argv[i]) == 0) // ignore_convention
+ if(str_comp("-s", argv[i]) == 0 || str_comp("--silent", argv[i]) == 0)
{
dbg_console_hide();
break;
@@ -1824,9 +1824,9 @@ int main(int argc, const char **argv) // ignore_convention
#endif
bool UseDefaultConfig = false;
- for(int i = 1; i < argc; i++) // ignore_convention
+ for(int i = 1; i < argc; i++)
{
- if(str_comp("-d", argv[i]) == 0 || str_comp("--default", argv[i]) == 0) // ignore_convention
+ if(str_comp("-d", argv[i]) == 0 || str_comp("--default", argv[i]) == 0)
{
UseDefaultConfig = true;
break;
@@ -1853,7 +1853,7 @@ int main(int argc, const char **argv) // ignore_convention
IGameServer *pGameServer = CreateGameServer();
IConsole *pConsole = CreateConsole(CFGFLAG_SERVER|CFGFLAG_ECON);
IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer();
- IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_SERVER, argc, argv); // ignore_convention
+ IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_SERVER, argc, argv);
IConfigManager *pConfigManager = CreateConfigManager();
pServer->InitRegister(&pServer->m_NetServer, pEngineMasterServer, pConfigManager->Values(), pConsole);
@@ -1893,8 +1893,8 @@ int main(int argc, const char **argv) // ignore_convention
pConsole->ExecuteFile("autoexec.cfg");
// parse the command line arguments
- if(argc > 1) // ignore_convention
- pConsole->ParseArguments(argc-1, &argv[1]); // ignore_convention
+ if(argc > 1)
+ pConsole->ParseArguments(argc-1, &argv[1]);
}
// restore empty config strings to their defaults
diff --git a/src/engine/shared/datafile.cpp b/src/engine/shared/datafile.cpp
index d0b88376f..bc6b5a69e 100644
--- a/src/engine/shared/datafile.cpp
+++ b/src/engine/shared/datafile.cpp
@@ -100,7 +100,7 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
if(Bytes == 0)
break;
sha256_update(&Sha256Ctx, aBuffer, Bytes);
- Crc = crc32(Crc, aBuffer, Bytes); // ignore_convention
+ Crc = crc32(Crc, aBuffer, Bytes);
}
io_seek(File, 0, IOSEEK_START);
@@ -309,7 +309,7 @@ void *CDataFileReader::GetDataImpl(int Index, int Swap)
// decompress the data, TODO: check for errors
s = UncompressedSize;
- uncompress((Bytef*)m_pDataFile->m_ppDataPtrs[Index], &s, (Bytef*)pTemp, DataSize); // ignore_convention
+ uncompress((Bytef*)m_pDataFile->m_ppDataPtrs[Index], &s, (Bytef*)pTemp, DataSize);
#if defined(CONF_ARCH_ENDIAN_BIG)
SwapSize = s;
#endif
@@ -586,7 +586,7 @@ int CDataFileWriter::AddData(int Size, const void *pData)
unsigned long s = compressBound(Size);
void *pCompData = mem_alloc(s); // temporary buffer that we use during compression
- int Result = compress((Bytef*)pCompData, &s, (Bytef*)pData, Size); // ignore_convention
+ int Result = compress((Bytef*)pCompData, &s, (Bytef*)pData, Size);
if(Result != Z_OK)
{
dbg_msg("datafile", "compression error %d", Result);
diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp
index 993f58bf6..4c2605a17 100644
--- a/src/engine/shared/storage.cpp
+++ b/src/engine/shared/storage.cpp
@@ -586,7 +586,7 @@ public:
if(Bytes <= 0)
break;
sha256_update(&Sha256Ctx, aBuffer, Bytes);
- Crc = crc32(Crc, aBuffer, Bytes); // ignore_convention
+ Crc = crc32(Crc, aBuffer, Bytes);
Size += Bytes;
}