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