X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fauxiliar%2Ffixcc.py;h=7ed9271acc386462bc782b571d7f615e11645630;hb=029145b3b50c435a7e699b9c600edaf219cee73b;hp=ca7806fe58bfdd8f93402ee9d6ecc4193e915cec;hpb=ce4579d52589eea2d01717ee8362fe851fb9a295;p=lilypond.git diff --git a/scripts/auxiliar/fixcc.py b/scripts/auxiliar/fixcc.py index ca7806fe58..7ed9271acc 100755 --- a/scripts/auxiliar/fixcc.py +++ b/scripts/auxiliar/fixcc.py @@ -31,6 +31,7 @@ import re import string import sys import time +import subprocess COMMENT = 'COMMENT' STRING = 'STRING' @@ -38,6 +39,8 @@ GLOBAL_CXX = 'GC++' CXX = 'C++' verbose_p = 0 indent_p = 1 +PREFERRED_ASTYLE_VERSION = "Artistic Style Version 2.04" + rules = { GLOBAL_CXX: @@ -47,7 +50,7 @@ rules = { ], CXX: [ - # space before parenthesis open + # space before parenthesis open; astyle -xd does this except for foo(). ('([\w\)\]])\(', '\\1 ('), # delete inline double spaces ('(\S) +', '\\1 '), @@ -67,7 +70,7 @@ rules = { ('([\w\(\)\]]) +(&&|\|\||<=|>=|!=|\|=|==|\+=|-=|\*=|/=|\?|<|>|\+|-|=|/|:|&|\||\*) +([\w\(\)])', '\\1 \\2 \\3'), # trailing operator, but don't un-trail close angle-braces > nor pointer *, and not before a preprocessor line - (' (::|&&|\|\||<=|>=|!=|\|=|==|\+=|-=|\*=|/=|\?|<|\+|-|=|/|:|&XXX|\||\*XXX) *\n( *)([^\s#])', '\n\\2\\1 \\3'), + ('(?=|!=|\|=|==|\+=|-=|\*=|/=|\?|<|\+|-|=|/|:|&XXX|\||\*XXX) *\n( *)([^\s#])', '\n\\2\\1 \\3'), # space after `operator' ('(\Woperator) *([^\w\s])', '\\1 \\2'), # trailing parenthesis open @@ -133,9 +136,10 @@ snippet_res = { 'string': r'''(?x) + " # leave the leading " character visible to CXX rules (?P (?P - "([^"\n]|\\")*"))''', + ([^"\n]|\\")*"))''', 'char': r'''(?x) @@ -334,6 +338,10 @@ def nitpick_file (outdir, file): indent_file (fixt) def indent_file (file): + # Astyle aborts on unrecognized options, + # so wait until everyone has 2.04 before considering: + # --attach-namespaces --indent-namespaces \ + # --max-code-length=80 --pad-first-paren-out \ astyle = '''astyle\ --options=none --quiet -n \ --style=gnu --indent=spaces=2 \ @@ -357,6 +365,7 @@ fixcc [OPTION]... FILE... Options: --help --lazy skip astyle, if no changes + --sloppy accept any astyle version --verbose --test @@ -379,6 +388,8 @@ def do_options (): indent_p = 0 elif o == '--outdir': outdir = a + elif o == '--sloppy': + PREFERRED_ASTYLE_VERSION = "Artistic Style" elif o == '--verbose': verbose_p = 1 elif o == '--test': @@ -391,6 +402,14 @@ def do_options (): sys.exit (2) return files +def check_astyle_version(): + cmd = "astyle --version" + process = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + if PREFERRED_ASTYLE_VERSION in stderr: + return True + return False + outdir = 0 format = CXX @@ -399,6 +418,12 @@ socketname = 'fixcc%d' % os.getpid () def main (): files = do_options () + if not check_astyle_version(): + print "Warning: try to use %s." % PREFERRED_ASTYLE_VERSION + print "Please limit use of this version to files with changed code." + if len(files) > 4: + print "Too many files with this version. See `astyle --help`" + sys.exit(1) if outdir and not os.path.isdir (outdir): os.makedirs (outdir) for i in files: @@ -434,7 +459,7 @@ typedef struct _t_ligature typedef std::map < AFM_Ligature const *, int > Bar; /** - Copyright (C) 1997--2011 Han-Wen Nienhuys + Copyright (C) 1997--2015 Han-Wen Nienhuys */ /* || @@ -473,7 +498,7 @@ i while (foe); squiggle. extent; - 1 && * unsmob_moment (lf); + 1 && * Moment::unsmob (lf); line_spanner_ = make_spanner ("DynamicLineSpanner", rq ? rq->*self_scm (): SCM_EOL); case foo: k;