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