Bulletproof the map detector logic a bit.
This commit is contained in:
parent
304e997edd
commit
f42f525f82
1 changed files with 28 additions and 19 deletions
|
@ -465,10 +465,15 @@ def validate_on_pop(tagstack, closer, filename, lineno):
|
|||
ancestors = map(lambda x: x[0], tagstack)
|
||||
if verbose >= 3:
|
||||
print '"%s", line %d: closing %s I see %s with %s' % (filename, lineno, closer, tag, attributes)
|
||||
# Detect a malformation that will cause the game to barf while attempting to
|
||||
# deserialize an empty unit.
|
||||
# Detect a malformation that will cause the game to barf while attempting
|
||||
# to deserialize an empty unit.
|
||||
if closer == "side" and "type" not in attributes and ("no_leader" not in attributes or attributes["no_leader"] != "yes") and "multiplayer" not in ancestors:
|
||||
print '"%s", line %d: [side] without type attribute' % (filename, lineno)
|
||||
if context(*suspicious_outermosts)
|
||||
if "radius" in attributes:
|
||||
logical = context("and", "or", "not")
|
||||
if suspicious_outermost and logical:
|
||||
print '"%s", line %d: order of radius predicate evaluation changed in 1.3.7' % (filename, lineno)
|
||||
|
||||
# Syntax transformations
|
||||
|
||||
|
@ -686,23 +691,27 @@ def is_map(filename):
|
|||
"Is this file a map in either old or new style?"
|
||||
if isresource(filename) or '{' in filename or '}' in filename:
|
||||
return False
|
||||
has_map_name = "maps" in filename or filename.endswith(".map")
|
||||
fp = open(filename)
|
||||
lines = fp.readlines()
|
||||
fp.close()
|
||||
has_map_content = False
|
||||
for i in range(len(lines)):
|
||||
if lines[i].endswith("\n"):
|
||||
lines[i] = lines[i][:-1]
|
||||
if lines[i].endswith("\r"):
|
||||
lines[i] = lines[i][:-1]
|
||||
w = len(lines[0])
|
||||
for line in lines:
|
||||
if len(line) != w:
|
||||
break
|
||||
else:
|
||||
has_map_content = len(lines) > 1
|
||||
return has_map_name or has_map_content
|
||||
if "map" in os.path.dirname(filename) or filename.endswith(".map"):
|
||||
return True
|
||||
try:
|
||||
fp = open(filename)
|
||||
lines = fp.readlines()
|
||||
fp.close()
|
||||
has_map_content = False
|
||||
for i in range(len(lines)):
|
||||
if lines[i].endswith("\n"):
|
||||
lines[i] = lines[i][:-1]
|
||||
if lines[i].endswith("\r"):
|
||||
lines[i] = lines[i][:-1]
|
||||
w = len(lines[0])
|
||||
for line in lines:
|
||||
if len(line) != w:
|
||||
break
|
||||
else:
|
||||
has_map_content = len(lines) > 1
|
||||
except OSError:
|
||||
has_map_content = False
|
||||
return has_map_content
|
||||
|
||||
class maptransform_error:
|
||||
"Error object to be thrown by maptransform."
|
||||
|
|
Loading…
Add table
Reference in a new issue