15dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; Copyright (c) 1993, 1994, 1995 Rick Sladkey <jrs@world.std.com>
25dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; All rights reserved.
35dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;;
45dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; Redistribution and use in source and binary forms, with or without
55dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; modification, are permitted provided that the following conditions
65dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; are met:
75dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; 1. Redistributions of source code must retain the above copyright
85dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;;    notice, this list of conditions and the following disclaimer.
95dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; 2. Redistributions in binary form must reproduce the above copyright
105dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;;    notice, this list of conditions and the following disclaimer in the
115dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;;    documentation and/or other materials provided with the distribution.
125dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; 3. The name of the author may not be used to endorse or promote products
135dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;;    derived from this software without specific prior written permission.
145dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;;
155dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
165dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
175dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
185dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
195dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
205dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
215dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
225dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
235dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
245dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
255dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes
265dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; Description: Automate the construction of strace xlat tables.
275dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes
285dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; Usage: Put point and mark around a set of definitions in a header
295dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; file.  Then grab them with C-c G.  Switch to the strace source file
305dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes;; and build the xlat table with C-c B.  Then type the name of the table.
315dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes
325dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes(global-set-key "\C-cG" 'grab-xlate)
335dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes(global-set-key "\C-cB" 'build-xlate)
345dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes
355dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes(defvar xlate-list nil
365dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  "See grab-xlate and build-xlate.")
375dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes
385dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes(defun grab-xlate (beg end)
395dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  "Grab all of the defined names in the region and save them in xlate-list."
405dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (interactive "r")
415dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (save-excursion
425dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (setq xlate-list nil)
435dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (goto-char beg)
445dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (beginning-of-line)
455dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (while (< (point) end)
465dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (and (looking-at "^#[ \t]*define[ \t]+\\([A-Za-z0-9_]+\\)[ \t]+")
475dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes	   (setq xlate-list (cons (buffer-substring (match-beginning 1)
485dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes						    (match-end 1))
495dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes				  xlate-list)))
505dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (forward-line)))
515dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (and (fboundp 'deactivate-mark)
525dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes       (deactivate-mark))
535dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (setq xlate-list (nreverse xlate-list)))
545dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes
555dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes(defun build-xlate (&optional list)
565dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  "Build and insert an strace xlat table based on the last grab."
575dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (interactive)
585dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (or list
595dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (setq list xlate-list))
605dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (beginning-of-line)
615dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (save-excursion
625dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (insert "static struct xlat ?[] = {\n")
635dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (while list
645dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (insert "\t{ " (car list) ",\n")
655dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (backward-char)
665dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (move-to-column 24 'force)
675dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (end-of-line)
685dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (insert "\"" (car list) "\"")
695dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (move-to-column 40 'force)
705dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (end-of-line)
715dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (insert "},")
725dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (forward-line)
735dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes      (setq list (cdr list)))
745dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (insert "	{ 0,		NULL		},\n")
755dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (insert "};\n")
765dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes    (insert "\n"))
775dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (search-forward "?")
785dec78d0c2663930cd1bbcecbbcee47f68bc52f3Elliott Hughes  (delete-backward-char 1))
79