]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
script to fix macros
authorMartin Taibr <taibr.martin@gmail.com>
Thu, 21 Sep 2017 19:22:42 +0000 (21:22 +0200)
committerMartin Taibr <taibr.martin@gmail.com>
Thu, 21 Sep 2017 19:22:42 +0000 (21:22 +0200)
qcsrc/tools/unc-macro-fix.py [new file with mode: 0755]
qcsrc/uncrustify.cfg

diff --git a/qcsrc/tools/unc-macro-fix.py b/qcsrc/tools/unc-macro-fix.py
new file mode 100755 (executable)
index 0000000..c2ada26
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+# removes redundant { and } from macros because uncrustify is too dumb to indent them properly (or even not touch them)
+
+# all those fancy unix utilities like grep, sed and awk are either woefully inadequate for this or just completely
+# unreadable with their arcane syntaxes - and yes, the plural is intentional because why extend existing tools
+# when you can write your own with incompatible flags, commands and regex flavors, pass strings between them
+# and call it the unix "philosophy"
+
+import re
+import glob
+
+all_files = set(glob.glob("**/*.qc", recursive=True) + glob.glob("**/*.qh", recursive=True))
+all_files = {f for f in all_files if not f.startswith('qcsrc/dpdefs')}
+
+for file_name in all_files:
+       with open(file_name, "r+") as f:
+               s = f.read()
+               s = re.sub(r"MACRO_BEGIN *(?:\\\s*)?{((?:.|\n)*?)} *(?:\\\s*)?MACRO_END", r"MACRO_BEGIN\1MACRO_END", s)
+               f.seek(0)
+               f.truncate()
+               f.write(s)
index d07b9dc54cc8d267eec9d108a945663510078b87..2cbdc91e4a78b9200ab1ea7b39fe9edf24fa6637 100644 (file)
@@ -1819,6 +1819,9 @@ type .string
 macro-open CLASS
 macro-close ENDCLASS
 
+macro-open MACRO_BEGIN
+macro-close MACRO_END
+
 # translations
 set func_call_user _