enum-NSRCS.cocci, coccinelle semantic patch

This commit is contained in:
rlar 2018-04-15 13:14:03 +02:00
parent d5f6c3fa18
commit 9d93ffefb7
2 changed files with 49 additions and 0 deletions

13
enum-NSRCS.cocci Normal file
View File

@ -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
}

36
enum-NSRCS.el Normal file
View File

@ -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))))