aboutsummaryrefslogtreecommitdiffstats
path: root/build-root/emacs-lisp/fix-coding-style.el
blob: aebf27bc0a08ab773761d718d7c200d83f7c5ab3 (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
#!/usr/bin/emacs --script

;; insert style boilerplate
(defun insert-style-boilerplate () (interactive)
       (save-excursion (goto-char (point-max))
                       (insert "
/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style \"gnu\")
 * End:
 */")))

;;
(defun fix-foreach () (interactive)
       (save-excursion (goto-char (point-min))
                       (while (search-forward-regexp 
                               "[pool|hash|clib_fifo|clib_bitmap]_foreach"
                               (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-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-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 *("))


;; Driver routine which runs the set of keyboard macros
;; defined above, as well as the bottom boilerplate lisp fn.

(defun fd-io-styleify () (interactive)
       (fix-foreach)
       (fix-vlib-register-thread)
       (fix-vlib-cli-command)
       (fix-vlib-register-node)
       (insert-style-boilerplate))

(setq index 0)
(while (elt argv index)
  (message "Processing %s..." (elt argv index))
  (find-file (elt argv index))
  (fd-io-styleify)
  (setq index (1+ index)))
(save-buffers-kill-emacs t)