Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1 | #!/usr/bin/emacs --script |
| 2 | |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 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 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 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 | * |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 15 | * Local Var" "iables: |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 16 | * eval: (c-set-style \"gnu\") |
| 17 | * End: |
| 18 | */"))) |
| 19 | |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 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). |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 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 | |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 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 | |
Keith Burns (alagalah) | 114e8a9 | 2016-08-04 09:27:23 -0700 | [diff] [blame^] | 50 | (defun fix-hash-foreach-mem () (interactive) |
| 51 | (fix-initializer "hash_foreach_mem *(")) |
| 52 | |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 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 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 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 | |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 72 | ;; Driver routine which runs the set of functions |
| 73 | ;; defined above, as well as the bottom boilerplate function |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 74 | |
| 75 | (defun fd-io-styleify () (interactive) |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 76 | (fix-pool-foreach) |
| 77 | (fix-hash-foreach) |
| 78 | (fix-hash-foreach-pair) |
Keith Burns (alagalah) | 114e8a9 | 2016-08-04 09:27:23 -0700 | [diff] [blame^] | 79 | (fix-hash-foreach-mem) |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 80 | (fix-foreach-ip-interface-address) |
| 81 | (fix-clib-fifo-foreach) |
| 82 | (fix-clib-bitmap-foreach) |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 83 | (fix-vlib-register-thread) |
| 84 | (fix-vlib-cli-command) |
| 85 | (fix-vlib-register-node) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 86 | (insert-style-boilerplate)) |
| 87 | |
Dave Barach | 987fdfa | 2016-07-17 11:52:10 -0400 | [diff] [blame] | 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)))) |