Commit | Line | Data |
---|---|---|
7a464420 AC |
1 | #!/bin/sh -e |
2 | ||
3 | if test $# -ne 3 | |
4 | then | |
5 | echo "Usage: $0 <h|inc> <observer.texi> <observer.out>" 1>&2 | |
6 | exit 0 | |
7 | fi | |
8 | ||
9 | lang=$1 ; shift | |
10 | texi=$1 ; shift | |
15c3c5c6 | 11 | o=$1 |
99efcb59 AS |
12 | case $lang in |
13 | h) tmp=htmp ;; | |
14 | inc) tmp=itmp ;; | |
15 | esac | |
16 | otmp="`echo $1 | sed -e 's,\.[^.]*$,,'`.$tmp"; shift | |
15c3c5c6 EZ |
17 | echo "Creating ${otmp}" 1>&2 |
18 | rm -f ${otmp} | |
7a464420 AC |
19 | |
20 | # Can use any of the following: cat cmp cp diff echo egrep expr false | |
21 | # grep install-info ln ls mkdir mv pwd rm rmdir sed sleep sort tar | |
22 | # test touch true | |
23 | ||
15c3c5c6 | 24 | cat <<EOF >>${otmp} |
7a464420 AC |
25 | /* GDB Notifications to Observers. |
26 | ||
15c3c5c6 | 27 | Copyright 2004, 2005 Free Software Foundation, Inc. |
7a464420 AC |
28 | |
29 | This file is part of GDB. | |
30 | ||
31 | This program is free software; you can redistribute it and/or modify | |
32 | it under the terms of the GNU General Public License as published by | |
33 | the Free Software Foundation; either version 2 of the License, or | |
34 | (at your option) any later version. | |
35 | ||
36 | This program is distributed in the hope that it will be useful, | |
37 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
38 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
39 | GNU General Public License for more details. | |
40 | ||
41 | You should have received a copy of the GNU General Public License | |
42 | along with this program; if not, write to the Free Software | |
43 | Foundation, Inc., 59 Temple Place - Suite 330, | |
44 | Boston, MA 02111-1307, USA. | |
45 | ||
46 | -- | |
47 | ||
48 | This file was generated using observer.sh and observer.texi. */ | |
49 | ||
50 | EOF | |
51 | ||
52 | ||
53 | case $lang in | |
15c3c5c6 | 54 | h) cat <<EOF >>${otmp} |
7a464420 AC |
55 | #ifndef OBSERVER_H |
56 | #define OBSERVER_H | |
57 | ||
58 | struct observer; | |
59 | struct bpstats; | |
84acb35a | 60 | struct so_list; |
7a464420 AC |
61 | EOF |
62 | ;; | |
63 | esac | |
64 | ||
5711a8b0 EZ |
65 | # We are about to set IFS=:, so DOS-style file names with a drive |
66 | # letter and a colon will be in trouble. | |
67 | ||
f3e25dcb | 68 | if test -n "$DJGPP" |
5711a8b0 EZ |
69 | then |
70 | texi=`echo $texi | sed -e 's,^\([a-zA-Z]\):/,/dev/\1/,'` | |
71 | fi | |
7a464420 AC |
72 | |
73 | # generate a list of events that can be observed | |
74 | ||
75 | IFS=: | |
76 | sed -n ' | |
77 | /@deftypefun void/{ | |
350c2e5b | 78 | # Save original line for later processing into the actual parameter |
7a464420 | 79 | h |
350c2e5b JB |
80 | # Convert from: @deftypefun void EVENT (TYPE @var{PARAM},...) |
81 | # to event and formals: EVENT:TYPE PARAM, ...: | |
7a464420 AC |
82 | s/^.* void \([a-z_][a-z_]*\) (\(.*\))$/\1:\2/ |
83 | s/@var{//g | |
84 | s/}//g | |
350c2e5b | 85 | # Switch to held |
7a464420 | 86 | x |
350c2e5b JB |
87 | # Convert from: @deftypefun void FUNC (TYPE @var{PARAM},...) |
88 | # to actuals: PARAM, ... | |
7a464420 AC |
89 | s/^[^{]*[{]*// |
90 | s/[}]*[^}]*$// | |
91 | s/}[^{]*{/, /g | |
350c2e5b JB |
92 | # Combine held (EVENT:TYPE PARAM, ...:) and pattern (PARAM, ...) into |
93 | # FUNC:TYPE PARAM, ...:PARAM, ... | |
7a464420 AC |
94 | H |
95 | x | |
96 | s/\n/:/g | |
97 | p | |
98 | } | |
99 | ' $texi | while read event formal actual | |
100 | do | |
101 | case $lang in | |
15c3c5c6 | 102 | h) cat <<EOF >>${otmp} |
7a464420 AC |
103 | |
104 | /* ${event} notifications. */ | |
105 | ||
106 | typedef void (observer_${event}_ftype) (${formal}); | |
107 | ||
108 | extern struct observer *observer_attach_${event} (observer_${event}_ftype *f); | |
109 | extern void observer_detach_${event} (struct observer *observer); | |
110 | extern void observer_notify_${event} (${formal}); | |
111 | EOF | |
112 | ;; | |
113 | ||
114 | inc) | |
15c3c5c6 | 115 | cat <<EOF >>${otmp} |
7a464420 AC |
116 | |
117 | /* ${event} notifications. */ | |
118 | ||
119 | static struct observer_list *${event}_subject = NULL; | |
120 | ||
121 | struct ${event}_args { `echo "${formal}" | sed -e 's/,/;/g'`; }; | |
122 | ||
123 | static void | |
124 | observer_${event}_notification_stub (const void *data, const void *args_data) | |
125 | { | |
126 | observer_${event}_ftype *notify = (observer_${event}_ftype *) data; | |
127 | const struct ${event}_args *args = args_data; | |
128 | notify (`echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args->\1/g'`); | |
129 | } | |
130 | ||
131 | struct observer * | |
132 | observer_attach_${event} (observer_${event}_ftype *f) | |
133 | { | |
134 | return generic_observer_attach (&${event}_subject, | |
135 | &observer_${event}_notification_stub, | |
136 | (void *) f); | |
137 | } | |
138 | ||
139 | void | |
140 | observer_detach_${event} (struct observer *observer) | |
141 | { | |
142 | generic_observer_detach (&${event}_subject, observer); | |
143 | } | |
144 | ||
145 | void | |
146 | observer_notify_${event} (${formal}) | |
147 | { | |
148 | struct ${event}_args args; | |
149 | `echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args.\1 = \1/g'`; | |
2b4855ab AC |
150 | if (observer_debug) |
151 | fprintf_unfiltered (gdb_stdlog, "observer_notify_${event}() called\n"); | |
7a464420 AC |
152 | generic_observer_notify (${event}_subject, &args); |
153 | } | |
154 | EOF | |
155 | ;; | |
156 | esac | |
157 | done | |
158 | ||
159 | ||
160 | case $lang in | |
15c3c5c6 | 161 | h) cat <<EOF >>${otmp} |
7a464420 AC |
162 | |
163 | #endif /* OBSERVER_H */ | |
164 | EOF | |
165 | esac | |
166 | ||
167 | ||
15c3c5c6 EZ |
168 | echo Moving ${otmp} to ${o} |
169 | mv ${otmp} ${o} |