2016-07-08 08:13:45 -04:00
|
|
|
#!/usr/bin/emacs --script
|
|
|
|
|
2016-07-17 11:52:10 -04:00
|
|
|
;; 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
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
(defun insert-style-boilerplate () (interactive)
|
|
|
|
(save-excursion (goto-char (point-max))
|
|
|
|
(insert "
|
|
|
|
/*
|
|
|
|
* fd.io coding-style-patch-verification: ON
|
|
|
|
*
|
2016-07-17 11:52:10 -04:00
|
|
|
* Local Var" "iables:
|
2016-07-08 08:13:45 -04:00
|
|
|
* eval: (c-set-style \"gnu\")
|
|
|
|
* End:
|
|
|
|
*/")))
|
|
|
|
|
2016-07-17 11:52:10 -04:00
|
|
|
;; 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).
|
2016-07-08 14:44:23 -04:00
|
|
|
|
|
|
|
(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* */"))))
|
|
|
|
|
2016-07-17 11:52:10 -04:00
|
|
|
(defun fix-pool-foreach () (interactive)
|
|
|
|
(fix-initializer "pool_foreach *("))
|
|
|
|
|
|
|
|
(defun fix-hash-foreach () (interactive)
|
|
|
|
(fix-initializer "hash_foreach *("))
|
|
|
|
|
|
|
|
(defun fix-hash-foreach-pair () (interactive)
|
|
|
|
(fix-initializer "hash_foreach_pair *("))
|
|
|
|
|
|
|
|
(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 *("))
|
|
|
|
|
2016-07-08 14:44:23 -04:00
|
|
|
(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 *("))
|
|
|
|
|
|
|
|
|
2016-07-17 11:52:10 -04:00
|
|
|
;; Driver routine which runs the set of functions
|
|
|
|
;; defined above, as well as the bottom boilerplate function
|
2016-07-08 08:13:45 -04:00
|
|
|
|
|
|
|
(defun fd-io-styleify () (interactive)
|
2016-07-17 11:52:10 -04:00
|
|
|
(fix-pool-foreach)
|
|
|
|
(fix-hash-foreach)
|
|
|
|
(fix-hash-foreach-pair)
|
|
|
|
(fix-foreach-ip-interface-address)
|
|
|
|
(fix-clib-fifo-foreach)
|
|
|
|
(fix-clib-bitmap-foreach)
|
2016-07-08 14:44:23 -04:00
|
|
|
(fix-vlib-register-thread)
|
|
|
|
(fix-vlib-cli-command)
|
|
|
|
(fix-vlib-register-node)
|
2016-07-08 08:13:45 -04:00
|
|
|
(insert-style-boilerplate))
|
|
|
|
|
2016-07-17 11:52:10 -04:00
|
|
|
|
|
|
|
;; 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))
|
|
|
|
(save-buffers-kill-emacs t))))
|