blob: aebf27bc0a08ab773761d718d7c200d83f7c5ab3 [file] [log] [blame]
Dave Barach9b8ffd92016-07-08 08:13:45 -04001#!/usr/bin/emacs --script
2
Dave Barach9b8ffd92016-07-08 08:13:45 -04003;; insert style boilerplate
4(defun insert-style-boilerplate () (interactive)
5 (save-excursion (goto-char (point-max))
6 (insert "
7/*
8 * fd.io coding-style-patch-verification: ON
9 *
10 * Local Variables:
11 * eval: (c-set-style \"gnu\")
12 * End:
13 */")))
14
Dave Barach8a7fb0c2016-07-08 14:44:23 -040015;;
16(defun fix-foreach () (interactive)
17 (save-excursion (goto-char (point-min))
18 (while (search-forward-regexp
19 "[pool|hash|clib_fifo|clib_bitmap]_foreach"
20 (point-max) t)
21 (move-beginning-of-line nil)
22 (open-line 1)
23 (c-indent-line-or-region)
24 (insert "/* *INDENT-OFF* */")
25 (search-forward "{")
26 (backward-char)
27 (forward-sexp)
28 (move-end-of-line nil)
29 (newline 1)
30 (c-indent-line-or-region)
31 (insert "/* *INDENT-ON* */"))))
32
33(defun fix-initializer (what) (interactive)
34 (save-excursion
35 (goto-char (point-min))
36 (while (search-forward-regexp what (point-max) t)
37 (move-beginning-of-line nil)
38 (open-line 1)
39 (c-indent-line-or-region)
40 (insert "/* *INDENT-OFF* */")
41 (search-forward "{")
42 (backward-char)
43 (forward-sexp)
44 (move-end-of-line nil)
45 (newline 1)
46 (c-indent-line-or-region)
47 (insert "/* *INDENT-ON* */"))))
48
49(defun fix-vlib-register-thread () (interactive)
50 (fix-initializer "VLIB_REGISTER_THREAD *("))
51
52(defun fix-vlib-cli-command () (interactive)
53 (fix-initializer "VLIB_CLI_COMMAND *("))
54
55(defun fix-vlib-register-node () (interactive)
56 (fix-initializer "VLIB_REGISTER_NODE *("))
57
58
Dave Barach9b8ffd92016-07-08 08:13:45 -040059;; Driver routine which runs the set of keyboard macros
60;; defined above, as well as the bottom boilerplate lisp fn.
61
62(defun fd-io-styleify () (interactive)
Dave Barach8a7fb0c2016-07-08 14:44:23 -040063 (fix-foreach)
64 (fix-vlib-register-thread)
65 (fix-vlib-cli-command)
66 (fix-vlib-register-node)
Dave Barach9b8ffd92016-07-08 08:13:45 -040067 (insert-style-boilerplate))
68
Dave Barach8a7fb0c2016-07-08 14:44:23 -040069(setq index 0)
70(while (elt argv index)
71 (message "Processing %s..." (elt argv index))
72 (find-file (elt argv index))
73 (fd-io-styleify)
74 (setq index (1+ index)))
75(save-buffers-kill-emacs t)