]> granicus.if.org Git - strace/blob - xlate.el
Fix decoding of file descriptors
[strace] / xlate.el
1 ;; Copyright (c) 1993, 1994, 1995 Rick Sladkey <jrs@world.std.com>
2 ;; All rights reserved.
3 ;;
4 ;; Redistribution and use in source and binary forms, with or without
5 ;; modification, are permitted provided that the following conditions
6 ;; are met:
7 ;; 1. Redistributions of source code must retain the above copyright
8 ;;    notice, this list of conditions and the following disclaimer.
9 ;; 2. Redistributions in binary form must reproduce the above copyright
10 ;;    notice, this list of conditions and the following disclaimer in the
11 ;;    documentation and/or other materials provided with the distribution.
12 ;; 3. The name of the author may not be used to endorse or promote products
13 ;;    derived from this software without specific prior written permission.
14 ;;
15 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 ;; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 ;; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 ;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 ;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ;;
26 ;; $Id$
27
28 ;; Description: Automate the construction of strace xlat tables.
29
30 ;; Usage: Put point and mark around a set of definitions in a header
31 ;; file.  Then grab them with C-c G.  Switch to the strace source file
32 ;; and build the xlat table with C-c B.  Then type the name of the table.
33
34 (global-set-key "\C-cG" 'grab-xlate)
35 (global-set-key "\C-cB" 'build-xlate)
36
37 (defvar xlate-list nil
38   "See grab-xlate and build-xlate.")
39
40 (defun grab-xlate (beg end)
41   "Grab all of the defined names in the region and save them in xlate-list."
42   (interactive "r")
43   (save-excursion
44     (setq xlate-list nil)
45     (goto-char beg)
46     (beginning-of-line)
47     (while (< (point) end)
48       (and (looking-at "^#[ \t]*define[ \t]+\\([A-Za-z0-9_]+\\)[ \t]+")
49            (setq xlate-list (cons (buffer-substring (match-beginning 1)
50                                                     (match-end 1))
51                                   xlate-list)))
52       (forward-line)))
53   (and (fboundp 'deactivate-mark)
54        (deactivate-mark))
55   (setq xlate-list (nreverse xlate-list)))
56
57 (defun build-xlate (&optional list)
58   "Build and insert an strace xlat table based on the last grab."
59   (interactive)
60   (or list
61       (setq list xlate-list))
62   (beginning-of-line)
63   (save-excursion
64     (insert "static struct xlat ?[] = {\n")
65     (while list
66       (insert "\t{ " (car list) ",\n")
67       (backward-char)
68       (move-to-column 24 'force)
69       (end-of-line)
70       (insert "\"" (car list) "\"")
71       (move-to-column 40 'force)
72       (end-of-line)
73       (insert "},")
74       (forward-line)
75       (setq list (cdr list)))
76     (insert "   { 0,            NULL            },\n")
77     (insert "};\n")
78     (insert "\n"))
79   (search-forward "?")
80   (delete-backward-char 1))