From 9d93ffefb7405f7a6e3bebaf60e1d2be41e5392b Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 15 Apr 2018 13:14:03 +0200 Subject: [PATCH] enum-NSRCS.cocci, coccinelle semantic patch --- enum-NSRCS.cocci | 13 +++++++++++++ enum-NSRCS.el | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 enum-NSRCS.cocci create mode 100644 enum-NSRCS.el diff --git a/enum-NSRCS.cocci b/enum-NSRCS.cocci new file mode 100644 index 000000000..7c9527921 --- /dev/null +++ b/enum-NSRCS.cocci @@ -0,0 +1,13 @@ +// (compile "git grep -l -e 'NSRCS' -- '*.h' | xargs -n1 spatch --sp-file enum-NSRCS.cocci --in-place && emacs -q --no-site-file --batch --load enum-NSRCS.el && git commit -am 'execute enum-NSRCS.cocci'") +// (compile "spatch --sp-file enum-NSRCS.cocci src/spicelib/devices/jfet/jfetdefs.h") + + +@nsrcs@ +identifier nsrcs =~ "NSRCS$"; +@@ + enum { + ..., +- nsrcs, ++ /* finally, the number of noise sources */ ++ nsrcs + } diff --git a/enum-NSRCS.el b/enum-NSRCS.el new file mode 100644 index 000000000..7caf9cb67 --- /dev/null +++ b/enum-NSRCS.el @@ -0,0 +1,36 @@ +;;; (load (buffer-file-name)) + +(require 'cl-lib) + +(defun enum-NSRCS () + (goto-char (point-min)) + (while (re-search-forward (rx (*? (any "\n" space)) + (group "/* finally, the number of noise sources */") + (*? (any "\n" space)) + (group (*? alnum) "NSRCS") + (*? (any "\n" space)) + "};" + (? (*? (any "\n" space)) + "/* the number of " + (+? print) + " noise sources" (*? space) "*/" + (*? space)) + ) + nil t) + (let ((p0 (copy-marker (match-beginning 0))) + (p1 (copy-marker (match-end 0)))) + (replace-match "\n \\1\n \\2\n};") + (indent-region p0 p1)))) + +(cl-loop with files = (process-lines "git" "grep" + "-l" "-e" "NSRCS") + for file in files + do + (progn + (with-temp-file file + (insert-file-contents file) + (c-mode) + (setq c-file-style "BSD") + (setq c-basic-offset 4) + (enum-NSRCS)))) +