enum-NSRCS.cocci, coccinelle semantic patch
This commit is contained in:
parent
d5f6c3fa18
commit
9d93ffefb7
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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))))
|
||||
|
||||
Loading…
Reference in New Issue