svn rev #23125: trunk/src/ util/

tlyu@MIT.EDU tlyu at MIT.EDU
Tue Nov 3 19:21:35 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=23125
Commit By: tlyu
Log Message:
Correct regexps for matching emacs and cc-mode versions.  In reindent
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.


Changed Files:
U   trunk/src/Makefile.in
U   trunk/src/util/krb5-c-style.el
A   trunk/src/util/krb5-mark-cstyle.py
Modified: trunk/src/Makefile.in
===================================================================
--- trunk/src/Makefile.in	2009-11-03 18:52:01 UTC (rev 23124)
+++ trunk/src/Makefile.in	2009-11-04 00:21:35 UTC (rev 23125)
@@ -658,41 +658,53 @@
 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))

Modified: trunk/src/util/krb5-c-style.el
===================================================================
--- trunk/src/util/krb5-c-style.el	2009-11-03 18:52:01 UTC (rev 23124)
+++ trunk/src/util/krb5-c-style.el	2009-11-04 00:21:35 UTC (rev 23125)
@@ -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")))

Added: trunk/src/util/krb5-mark-cstyle.py
===================================================================
--- trunk/src/util/krb5-mark-cstyle.py	                        (rev 0)
+++ trunk/src/util/krb5-mark-cstyle.py	2009-11-04 00:21:35 UTC (rev 23125)
@@ -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])




More information about the cvs-krb5 mailing list