Correct regexps for matching emacs and cc-mode versions. In reindent
authorTom Yu <tlyu@mit.edu>
Wed, 4 Nov 2009 00:21:35 +0000 (00:21 +0000)
committerTom Yu <tlyu@mit.edu>
Wed, 4 Nov 2009 00:21:35 +0000 (00:21 +0000)
targets, chdir to SRCTOP to avoid excessive references to $(SRCTOP) in
the find script.  Define new variables to avoid errors when creating
exception lists for find scripts.

Use a python script instead of elisp to mark files.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23125 dc483132-0cff-0310-8789-dd5450dbe970

src/Makefile.in
src/util/krb5-c-style.el
src/util/krb5-mark-cstyle.py [new file with mode: 0644]

index 4ed5773302540aee05f03dc7fa41f869e12c198d..7bb6f6340de07460e0961e2f3e15b2dc1f769fb9 100644 (file)
@@ -658,41 +658,53 @@ coverity prevent cov: Makefiles
 FIND = find
 XARGS = xargs
 EMACS = emacs
+PYTHON = python
+
+BSDFILES = \
+       kadmin/cli/strftime.c \
+       kadmin/server/ipropd_svc.c \
+       kadmin/server/kadm_rpc_svc.c \
+       lib/kadm5/admin_xdr.h \
+       lib/kadm5/clnt/client_rpc.c \
+       lib/kadm5/kadm_rpc.h \
+       lib/kadm5/kadm_rpc_xdr.c \
+       lib/kadm5/srv/adb_xdr.c \
+       lib/krb5/krb/strftime.c \
+       lib/krb5/krb/strptime.c
+
+OTHEREXCLUDES = \
+       lib/krb5/asn.1 \
+       lib/krb5/krb/deltat.c \
+       lib/krb5/krb/preauth.c \
+       lib/krb5/krb/ser_ctx.c \
+       lib/krb5/unicode
+
+EXCLUDES = `for i in $(BSDFILES) $(OTHEREXCLUDES); do echo $$i; done | $(AWK) '{ print "-path", $$1, "-o" }'` -path /dev/null
 
 reindent::
-       $(FIND) $(SRCTOP) \
+       (cd $(SRCTOP) && \
+       $(FIND) . \
        \( -name '*.[ch]' -o -name '*.hin' -o -name '*.[ch].in' \) \
        -print0 | $(XARGS) -0 $(EMACS) -q -batch \
-       -l $(SRCTOP)/util/krb5-c-style.el \
-       -l $(SRCTOP)/util/krb5-batch-reindent.el
+       -l util/krb5-c-style.el \
+       -l util/krb5-batch-reindent.el)
 
-mark-cstyle::
+mark-cstyle:: mark-cstyle-krb5 mark-cstyle-bsd
+
+mark-cstyle-krb5::
+       (cd $(SRCTOP) && \
        $(FIND) \
-       $(SRCTOP)/clients \
-       $(SRCTOP)/lib/kadm5 \
-       $(SRCTOP)/lib/kdb \
-       $(SRCTOP)/lib/krb5 \
-       $(SRCTOP)/kadmin \
-       $(SRCTOP)/kdc \
-       \( \
-       -path $(SRCTOP)/kadmin/cli/strftime.c -o \
-       -path $(SRCTOP)/kadmin/server/ipropd_svc.c -o \
-       -path $(SRCTOP)/kadmin/server/kadm_rpc_svc.c -o \
-       -path $(SRCTOP)/lib/kadm5/admin_xdr.h -o \
-       -path $(SRCTOP)/lib/kadm5/client/client_rpc.c -o \
-       -path $(SRCTOP)/lib/kadm5/kadm_rpc.h -o \
-       -path $(SRCTOP)/lib/kadm5/kadm_rpc_xdr.c -o \
-       -path $(SRCTOP)/lib/kadm5/srv/adm_xdr.c -o \
-       -path $(SRCTOP)/lib/krb5/asn.1 -o \
-       -path $(SRCTOP)/lib/krb5/ccche/cc_file.c -o \
-       -path $(SRCTOP)/lib/krb5/krb/deltat.c -o \
-       -path $(SRCTOP)/lib/krb5/krb/preauth.c -o \
-       -path $(SRCTOP)/lib/krb5/krb/ser_ctx.c -o \
-       -path $(SRCTOP)/lib/krb5/krb/strftime.c -o \
-       -path $(SRCTOP)/lib/krb5/krb/strptime.c -o \
-       -path $(SRCTOP)/lib/krb5/unicode \
-       \) -prune -o \
+       clients \
+       lib/kadm5 \
+       lib/kdb \
+       lib/krb5 \
+       kadmin \
+       kdc \
+       \( $(EXCLUDES) \) -prune -o \
        -name '*.[ch]' \
-       -print0 | $(XARGS) -0 $(EMACS) -q -batch \
-       -l $(SRCTOP)/util/krb5-c-style.el \
-       -l $(SRCTOP)/util/krb5-mark-cstyle.el -cstyle-krb5
+       -print0 | $(XARGS) -0 $(PYTHON) util/krb5-mark-cstyle.py \
+       --cstyle=krb5)
+
+mark-cstyle-bsd::
+       (cd $(SRCTOP) && \
+       $(PYTHON) util/krb5-mark-cstyle.py --cstyle=bsd $(BSDFILES))
index b060e8803a73306c83a1c01cf27f61e5e52a3ccb..f99791719c5c68afec14d9c2fb5bace971bb0e78 100644 (file)
@@ -48,8 +48,8 @@
 
 ;; emacs-23.x has a buggy cc-mode that incorrectly deals with case
 ;; labels with character constants.
-(if (and (string-match "^23\." emacs-version)
+(if (and (string-match "^23\\." emacs-version)
          (require 'cc-defs)
-         (string-match "5.31.[0-7]" c-version))
+         (string-match "5\\.31\\.[0-7]" c-version))
     (let ((load-path (cons (file-name-directory load-file-name) load-path)))
       (load "krb5-hack-cc-mode-caselabel")))
diff --git a/src/util/krb5-mark-cstyle.py b/src/util/krb5-mark-cstyle.py
new file mode 100644 (file)
index 0000000..f4b4a83
--- /dev/null
@@ -0,0 +1,47 @@
+from optparse import OptionParser
+import os
+import re
+import sys
+
+styles = {
+    "bsd":
+        "/* -*- mode: c; c-file-style: \"bsd\"; indent-tabs-mode: t -*- */\n",
+    "krb5":
+        "/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */\n"
+    }
+
+def dofile(fname, style):
+    changed = False
+    newname = fname + ".new"
+    infile = open(fname)
+    outfile = open(newname, "w")
+    first = infile.next()
+    if (first != style):
+        changed = True
+        outfile.write(style)
+        if re.match(r"""\s*/\*\s*-\*-.*-\*-\s*\*/""", first):
+            # Replace first line if it was already a local variables line.
+            pass
+        else:
+            outfile.write(first)
+
+        # Simply copy remaining lines.
+        for line in infile:
+            outfile.write(line)
+
+    infile.close()
+    outfile.close()
+
+    if changed:
+        os.rename(newname, fname)
+    else:
+        os.remove(newname)
+
+parser = OptionParser()
+parser.add_option("--cstyle", action="store", dest="style",
+                  choices=("bsd", "krb5"), default="krb5")
+(options, args) = parser.parse_args()
+
+for fname in args:
+    print fname
+    dofile(fname, styles[options.style])