]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/auxiliar/fixcc.py
Run grand replace for 2015.
[lilypond.git] / scripts / auxiliar / fixcc.py
index ca7806fe58bfdd8f93402ee9d6ecc4193e915cec..0ecbf8cd6a698c2e9aed2c43099730f1d156715a 100755 (executable)
@@ -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
+REQUIRED_ASTYLE_VERSION = "Artistic Style Version 2.02"
+
 
 rules = {
     GLOBAL_CXX:
@@ -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'),
+    ('(?<!\s) (::|&&|\|\||<=|>=|!=|\|=|==|\+=|-=|\*=|/=|\?|<|\+|-|=|/|:|&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<match>
     (?P<code>
-    "([^"\n]|\\")*"))''',
+    ([^"\n]|\\")*"))''',
     
     'char':
     r'''(?x)
@@ -391,6 +395,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 REQUIRED_ASTYLE_VERSION in stderr:
+        return True
+    return False
+
 
 outdir = 0
 format = CXX
@@ -398,6 +410,10 @@ socketdir = '/tmp/fixcc'
 socketname = 'fixcc%d' % os.getpid ()
 
 def main ():
+    if not check_astyle_version():
+        print "Error: we require %s" % REQUIRED_ASTYLE_VERSION
+        print "Sorry, no higher (or lower) versions allowed"
+        sys.exit(1)
     files = do_options ()
     if outdir and not os.path.isdir (outdir):
         os.makedirs (outdir)
@@ -434,7 +450,7 @@ typedef struct _t_ligature
 typedef std::map < AFM_Ligature const *, int > Bar;
 
  /**
- Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@cs.uu.nl>
  */
  
 /*      ||
@@ -473,7 +489,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;