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-hash-foreach () (interactive)
45 (fix-initializer "hash_foreach *("))
47 (defun fix-hash-foreach-pair () (interactive)
48 (fix-initializer "hash_foreach_pair *("))
50 (defun fix-clib-fifo-foreach () (interactive)
51 (fix-initializer "clib_fifo_foreach *("))
53 (defun fix-clib-bitmap-foreach () (interactive)
54 (fix-initializer "clib_bitmap_foreach *("))
56 (defun fix-foreach-ip-interface-address () (interactive)
57 (fix-initializer "foreach_ip_interface_address *("))
59 (defun fix-vlib-register-thread () (interactive)
60 (fix-initializer "VLIB_REGISTER_THREAD *("))
62 (defun fix-vlib-cli-command () (interactive)
63 (fix-initializer "VLIB_CLI_COMMAND *("))
65 (defun fix-vlib-register-node () (interactive)
66 (fix-initializer "VLIB_REGISTER_NODE *("))
69 ;; Driver routine which runs the set of functions
70 ;; defined above, as well as the bottom boilerplate function
72 (defun fd-io-styleify () (interactive)
75 (fix-hash-foreach-pair)
76 (fix-foreach-ip-interface-address)
77 (fix-clib-fifo-foreach)
78 (fix-clib-bitmap-foreach)
79 (fix-vlib-register-thread)
80 (fix-vlib-cli-command)
81 (fix-vlib-register-node)
82 (insert-style-boilerplate))
85 ;; When run as a script, this sexp
86 ;; walks the list of files supplied on the command line.
88 ;; (elt argv index) returns nil if you M-x eval-buffer
89 ;; or M-x load-file the file, so we won't accidentally
90 ;; evaluate (save-buffers-kill-emacs)...
94 (while (elt argv index)
95 (message "Processing %s..." (elt argv index))
96 (find-file (elt argv index))
98 (setq index (1+ index))
99 (save-buffers-kill-emacs t))))