From 2de5dc5a1cd27185e8bd403993caa00c7b34720b Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Thu, 21 Sep 2017 21:22:42 +0200 Subject: [PATCH] script to fix macros --- qcsrc/tools/unc-macro-fix.py | 22 ++++++++++++++++++++++ qcsrc/uncrustify.cfg | 3 +++ 2 files changed, 25 insertions(+) create mode 100755 qcsrc/tools/unc-macro-fix.py diff --git a/qcsrc/tools/unc-macro-fix.py b/qcsrc/tools/unc-macro-fix.py new file mode 100755 index 000000000..c2ada261f --- /dev/null +++ b/qcsrc/tools/unc-macro-fix.py @@ -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) diff --git a/qcsrc/uncrustify.cfg b/qcsrc/uncrustify.cfg index d07b9dc54..2cbdc91e4 100644 --- a/qcsrc/uncrustify.cfg +++ b/qcsrc/uncrustify.cfg @@ -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 _ -- 2.39.2