Update coding style for hash_foreach_mem
[vpp.git] / build-root / emacs-lisp / fix-coding-style.el
1 #!/usr/bin/emacs --script
2
3 ;; Insert style boilerplate
4 ;;
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
8
9 (defun insert-style-boilerplate () (interactive)
10        (save-excursion (goto-char (point-max))
11                        (insert "
12 /*
13  * fd.io coding-style-patch-verification: ON
14  *
15  * Local Var" "iables:
16  * eval: (c-set-style \"gnu\")
17  * End:
18  */")))
19
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).
24
25 (defun fix-initializer (what) (interactive)
26        (save-excursion 
27          (goto-char (point-min))
28          (while (search-forward-regexp what (point-max) t)
29            (move-beginning-of-line nil)
30            (open-line 1)
31            (c-indent-line-or-region)
32            (insert "/* *INDENT-OFF* */")
33            (search-forward "{")
34            (backward-char)
35            (forward-sexp)
36            (move-end-of-line nil)
37            (newline 1)
38            (c-indent-line-or-region)
39            (insert "/* *INDENT-ON* */"))))
40
41 (defun fix-pool-foreach () (interactive)
42        (fix-initializer "pool_foreach *("))
43
44 (defun fix-hash-foreach () (interactive)
45        (fix-initializer "hash_foreach *("))
46
47 (defun fix-hash-foreach-pair () (interactive)
48        (fix-initializer "hash_foreach_pair *("))
49
50 (defun fix-hash-foreach-mem () (interactive)
51        (fix-initializer "hash_foreach_mem *("))
52
53 (defun fix-clib-fifo-foreach () (interactive)
54        (fix-initializer "clib_fifo_foreach *("))
55
56 (defun fix-clib-bitmap-foreach () (interactive)
57        (fix-initializer "clib_bitmap_foreach *("))
58
59 (defun fix-foreach-ip-interface-address () (interactive)
60        (fix-initializer "foreach_ip_interface_address *("))
61
62 (defun fix-vlib-register-thread () (interactive)
63        (fix-initializer "VLIB_REGISTER_THREAD *("))
64
65 (defun fix-vlib-cli-command () (interactive)
66        (fix-initializer "VLIB_CLI_COMMAND *("))
67
68 (defun fix-vlib-register-node () (interactive)
69        (fix-initializer "VLIB_REGISTER_NODE *("))
70
71
72 ;; Driver routine which runs the set of functions
73 ;; defined above, as well as the bottom boilerplate function
74
75 (defun fd-io-styleify () (interactive)
76        (fix-pool-foreach)
77        (fix-hash-foreach)
78        (fix-hash-foreach-pair)
79        (fix-hash-foreach-mem)
80        (fix-foreach-ip-interface-address)
81        (fix-clib-fifo-foreach)
82        (fix-clib-bitmap-foreach)
83        (fix-vlib-register-thread)
84        (fix-vlib-cli-command)
85        (fix-vlib-register-node)
86        (insert-style-boilerplate))
87
88
89 ;; When run as a script, this sexp
90 ;; walks the list of files supplied on the command line.
91 ;; 
92 ;; (elt argv index) returns nil if you M-x eval-buffer
93 ;; or M-x load-file the file, so we won't accidentally
94 ;; evaluate (save-buffers-kill-emacs)...
95
96 (let ((index 0))
97   (if (elt argv index)
98       (while (elt argv index)
99         (message "Processing %s..." (elt argv index))
100         (find-file (elt argv index))
101         (fd-io-styleify)
102         (setq index (1+ index))
103         (save-buffers-kill-emacs t))))