From 7be2ef2b6c8c491781251a5023db48d7690f5fa8 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Wed, 4 Nov 2009 00:21:35 +0000 Subject: [PATCH] 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. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23125 dc483132-0cff-0310-8789-dd5450dbe970 --- src/Makefile.in | 74 +++++++++++++++++++++--------------- src/util/krb5-c-style.el | 4 +- src/util/krb5-mark-cstyle.py | 47 +++++++++++++++++++++++ 3 files changed, 92 insertions(+), 33 deletions(-) create mode 100644 src/util/krb5-mark-cstyle.py diff --git a/src/Makefile.in b/src/Makefile.in index 4ed577330..7bb6f6340 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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)) diff --git a/src/util/krb5-c-style.el b/src/util/krb5-c-style.el index b060e8803..f99791719 100644 --- a/src/util/krb5-c-style.el +++ b/src/util/krb5-c-style.el @@ -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 index 000000000..f4b4a83e6 --- /dev/null +++ b/src/util/krb5-mark-cstyle.py @@ -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]) -- 2.26.2