2 match
= re
.search('(.*)/', sys
.argv
[0])
4 os
.chdir(match
.group(1))
7 notice
= [b
"/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */\n", b
"/* If you are missing that file, acquire a complete release at teeworlds.com. */\n"]
8 exclude
= ["src%sengine%sexternal" % (os
.sep
, os
.sep
), "src%sosxlaunch" % os
.sep
]
11 def fix_copyright_notice(filename
):
13 f
= open(filename
, "rb")
18 length_lines
= len(lines
)
20 while i
<= length_lines
and (lines
[i
].decode("utf-8").lstrip()[:2] == "//" or lines
[i
].decode("utf-8").lstrip()[:2] == "/*" and lines
[i
].decode("utf-8").rstrip()[-2:] == "*/") and ("Magnus" in lines
[i
].decode("utf-8") or "magnus" in lines
[i
].decode("utf-8") or "Auvinen" in lines
[i
].decode("utf-8") or "auvinen" in lines
[i
].decode("utf-8") or "license" in lines
[i
].decode("utf-8") or "teeworlds" in lines
[i
].decode("utf-8")):
22 length_notice
= len(notice
)
25 while lines
[j
] == notice
[j
]:
27 if j
== length_notice
:
31 while j
< length_notice
-1 - k
:
32 lines
= [notice
[j
]] + lines
34 while j
< length_notice
:
37 if length_lines
== 0 or i
== 0:
40 lines
= [notice
[j
]] + lines
42 open(filename
, "wb").writelines(lines
)
46 for root
, dirs
, files
in os
.walk("src"):
47 for excluding
in exclude
:
48 if root
[:len(excluding
)] == excluding
:
55 filename
= os
.path
.join(root
, name
)
57 if filename
[-2:] != ".c" and filename
[-4:] != ".cpp" and filename
[-2:] != ".h":
60 fix_copyright_notice(filename
)
63 if updated_files
!= 1:
65 print("*** updated %d %s ***" % (updated_files
, output
))