1 #!/usr/bin/emacs --script
3 ;; Insert style boilerplate
5 ;; Breaking the string in half keeps emacs
6 ;; from trying to interpret the local variable
7 ;; settings e.g. when it reads the lisp source code
9 (defun insert-style-boilerplate () (interactive)
10 (save-excursion (goto-char (point-max))
13 * fd.io coding-style-patch-verification: ON
16 * eval: (c-set-style \"gnu\")
20 ;; Insert indent-off ... indent-on brackets around
21 ;; a certain xxx_foreach macro, etc. which "indent"
22 ;; completely screws up. Doesn't handle nesting, of which there
23 ;; are few examples (fortunately).
25 (defun fix-initializer (what) (interactive)
27 (goto-char (point-min))
28 (while (search-forward-regexp what (point-max) t)
29 (move-beginning-of-line nil)
31 (c-indent-line-or-region)
32 (insert "/* *INDENT-OFF* */")
36 (move-end-of-line nil)
38 (c-indent-line-or-region)
39 (insert "/* *INDENT-ON* */"))))
41 (defun fix-pool-foreach () (interactive)
42 (fix-initializer "pool_foreach *("))
44 (defun fix-pool-foreach-index () (interactive)
45 (fix-initializer "pool_foreach_index *("))
47 (defun fix-hash-foreach () (interactive)
48 (fix-initializer "hash_foreach *("))
50 (defun fix-hash-foreach-pair () (interactive)
51 (fix-initializer "hash_foreach_pair *("))
53 (defun fix-hash-foreach-mem () (interactive)
54 (fix-initializer "hash_foreach_mem *("))
56 (defun fix-clib-fifo-foreach () (interactive)
57 (fix-initializer "clib_fifo_foreach *("))
59 (defun fix-clib-bitmap-foreach () (interactive)
60 (fix-initializer "clib_bitmap_foreach *("))
62 (defun fix-foreach-ip-interface-address () (interactive)
63 (fix-initializer "foreach_ip_interface_address *("))
65 (defun fix-vlib-register-thread () (interactive)
66 (fix-initializer "VLIB_REGISTER_THREAD *("))
68 (defun fix-vlib-cli-command () (interactive)
69 (fix-initializer "VLIB_CLI_COMMAND *("))
71 (defun fix-vlib-register-node () (interactive)
72 (fix-initializer "VLIB_REGISTER_NODE *("))
74 (defun fix-reply-macro2 () (interactive)
75 (fix-initializer "REPLY_MACRO2 *("))
77 ;; Driver routine which runs the set of functions
78 ;; defined above, as well as the bottom boilerplate function
80 (defun fd-io-styleify () (interactive)
82 (fix-pool-foreach-index)
84 (fix-hash-foreach-pair)
85 (fix-hash-foreach-mem)
86 (fix-foreach-ip-interface-address)
87 (fix-clib-fifo-foreach)
88 (fix-clib-bitmap-foreach)
89 (fix-vlib-register-thread)
90 (fix-vlib-cli-command)
91 (fix-vlib-register-node)
93 (insert-style-boilerplate))
96 ;; When run as a script, this sexp
97 ;; walks the list of files supplied on the command line.
99 ;; (elt argv index) returns nil if you M-x eval-buffer
100 ;; or M-x load-file the file, so we won't accidentally
101 ;; evaluate (save-buffers-kill-emacs)...
105 (while (elt argv index)
106 (message "Processing %s..." (elt argv index))
107 (find-file (elt argv index))
109 (setq index (1+ index))))
111 (save-buffers-kill-emacs t)))