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))
;; 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")))
--- /dev/null
+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])