Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1 | #!/usr/bin/emacs --script |
| 2 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 3 | ;; insert style boilerplate |
| 4 | (defun insert-style-boilerplate () (interactive) |
| 5 | (save-excursion (goto-char (point-max)) |
| 6 | (insert " |
| 7 | /* |
| 8 | * fd.io coding-style-patch-verification: ON |
| 9 | * |
| 10 | * Local Variables: |
| 11 | * eval: (c-set-style \"gnu\") |
| 12 | * End: |
| 13 | */"))) |
| 14 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame^] | 15 | ;; |
| 16 | (defun fix-foreach () (interactive) |
| 17 | (save-excursion (goto-char (point-min)) |
| 18 | (while (search-forward-regexp |
| 19 | "[pool|hash|clib_fifo|clib_bitmap]_foreach" |
| 20 | (point-max) t) |
| 21 | (move-beginning-of-line nil) |
| 22 | (open-line 1) |
| 23 | (c-indent-line-or-region) |
| 24 | (insert "/* *INDENT-OFF* */") |
| 25 | (search-forward "{") |
| 26 | (backward-char) |
| 27 | (forward-sexp) |
| 28 | (move-end-of-line nil) |
| 29 | (newline 1) |
| 30 | (c-indent-line-or-region) |
| 31 | (insert "/* *INDENT-ON* */")))) |
| 32 | |
| 33 | (defun fix-initializer (what) (interactive) |
| 34 | (save-excursion |
| 35 | (goto-char (point-min)) |
| 36 | (while (search-forward-regexp what (point-max) t) |
| 37 | (move-beginning-of-line nil) |
| 38 | (open-line 1) |
| 39 | (c-indent-line-or-region) |
| 40 | (insert "/* *INDENT-OFF* */") |
| 41 | (search-forward "{") |
| 42 | (backward-char) |
| 43 | (forward-sexp) |
| 44 | (move-end-of-line nil) |
| 45 | (newline 1) |
| 46 | (c-indent-line-or-region) |
| 47 | (insert "/* *INDENT-ON* */")))) |
| 48 | |
| 49 | (defun fix-vlib-register-thread () (interactive) |
| 50 | (fix-initializer "VLIB_REGISTER_THREAD *(")) |
| 51 | |
| 52 | (defun fix-vlib-cli-command () (interactive) |
| 53 | (fix-initializer "VLIB_CLI_COMMAND *(")) |
| 54 | |
| 55 | (defun fix-vlib-register-node () (interactive) |
| 56 | (fix-initializer "VLIB_REGISTER_NODE *(")) |
| 57 | |
| 58 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 59 | ;; Driver routine which runs the set of keyboard macros |
| 60 | ;; defined above, as well as the bottom boilerplate lisp fn. |
| 61 | |
| 62 | (defun fd-io-styleify () (interactive) |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame^] | 63 | (fix-foreach) |
| 64 | (fix-vlib-register-thread) |
| 65 | (fix-vlib-cli-command) |
| 66 | (fix-vlib-register-node) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 67 | (insert-style-boilerplate)) |
| 68 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame^] | 69 | (setq index 0) |
| 70 | (while (elt argv index) |
| 71 | (message "Processing %s..." (elt argv index)) |
| 72 | (find-file (elt argv index)) |
| 73 | (fd-io-styleify) |
| 74 | (setq index (1+ index))) |
| 75 | (save-buffers-kill-emacs t) |