PR gas/14201
[deliverable/binutils-gdb.git] / gdb / observer.sh
... / ...
CommitLineData
1#!/bin/sh -e
2
3# Make certain that the script is not running in an internationalized
4# environment.
5LANG=C ; export LANG
6LC_ALL=C ; export LC_ALL
7
8if test $# -ne 3
9then
10 echo "Usage: $0 <h|inc> <observer.texi> <observer.out>" 1>&2
11 exit 0
12fi
13
14lang=$1 ; shift
15texi=$1 ; shift
16o=$1
17case $lang in
18 h) tmp=htmp ;;
19 inc) tmp=itmp ;;
20esac
21otmp="`echo $1 | sed -e 's,\.[^.]*$,,'`.$tmp"; shift
22echo "Creating ${otmp}" 1>&2
23rm -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
29cat <<EOF >>${otmp}
30/* GDB Notifications to Observers.
31
32 Copyright (C) 2004-2005, 2007-2012 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
53EOF
54
55
56case $lang in
57 h) cat <<EOF >>${otmp}
58#ifndef OBSERVER_H
59#define OBSERVER_H
60
61struct observer;
62struct bpstats;
63struct so_list;
64struct objfile;
65struct thread_info;
66struct inferior;
67EOF
68 ;;
69esac
70
71# We are about to set IFS=:, so DOS-style file names with a drive
72# letter and a colon will be in trouble.
73
74if test -n "$DJGPP"
75then
76 texi=`echo $texi | sed -e 's,^\([a-zA-Z]\):/,/dev/\1/,'`
77fi
78
79# generate a list of events that can be observed
80
81IFS=:
82sed -n '
83/@deftypefun void/{
84# Save original line for later processing into the actual parameter
85 h
86# Convert from: @deftypefun void EVENT (TYPE @var{PARAM},...)
87# to event and formals: EVENT:TYPE PARAM, ...:
88 s/^.* void \([a-z_][a-z_]*\) (\(.*\))$/\1:\2/
89 s/@var{//g
90 s/}//g
91# Switch to held
92 x
93# Convert from: @deftypefun void FUNC (TYPE @var{PARAM},...)
94# to actuals: PARAM, ...
95 s/^[^{]*[{]*//
96 s/[}]*[^}]*$//
97 s/}[^{]*{/, /g
98# Combine held (EVENT:TYPE PARAM, ...:) and pattern (PARAM, ...) into
99# FUNC:TYPE PARAM, ...:PARAM, ...
100 H
101 x
102 s/\n/:/g
103 p
104}
105' $texi | while read event formal actual
106do
107 case $lang in
108 h) cat <<EOF >>${otmp}
109
110/* ${event} notifications. */
111
112typedef void (observer_${event}_ftype) (${formal});
113
114extern struct observer *observer_attach_${event} (observer_${event}_ftype *f);
115extern void observer_detach_${event} (struct observer *observer);
116extern void observer_notify_${event} (${formal});
117EOF
118 ;;
119
120 inc)
121 cat <<EOF >>${otmp}
122
123/* ${event} notifications. */
124
125static struct observer_list *${event}_subject = NULL;
126
127EOF
128 if test "$formal" != "void"; then
129 cat<<EOF >>${otmp}
130struct ${event}_args { `echo "${formal}" | sed -e 's/,/;/g'`; };
131
132EOF
133 fi
134 cat <<EOF >>${otmp}
135static void
136observer_${event}_notification_stub (const void *data, const void *args_data)
137{
138 observer_${event}_ftype *notify = (observer_${event}_ftype *) data;
139EOF
140
141 notify_args=`echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args->\1/g'`
142
143 if test ! -z "${notify_args}"; then
144 cat<<EOF >>${otmp}
145 const struct ${event}_args *args = args_data;
146EOF
147 fi
148 cat <<EOF >>${otmp}
149 notify (${notify_args});
150}
151
152struct observer *
153observer_attach_${event} (observer_${event}_ftype *f)
154{
155 return generic_observer_attach (&${event}_subject,
156 &observer_${event}_notification_stub,
157 (void *) f);
158}
159
160void
161observer_detach_${event} (struct observer *observer)
162{
163 generic_observer_detach (&${event}_subject, observer);
164}
165
166void
167observer_notify_${event} (${formal})
168{
169EOF
170 if test "$formal" != "void"; then
171 cat<<EOF >>${otmp}
172 struct ${event}_args args;
173 `echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args.\1 = \1/g'`;
174
175EOF
176 else
177 echo "char *args = NULL;" >> ${otmp}
178 fi
179 cat<<EOF >>${otmp}
180 if (observer_debug)
181 fprintf_unfiltered (gdb_stdlog, "observer_notify_${event}() called\n");
182 generic_observer_notify (${event}_subject, &args);
183}
184EOF
185 ;;
186 esac
187done
188
189
190case $lang in
191 h) cat <<EOF >>${otmp}
192
193#endif /* OBSERVER_H */
194EOF
195esac
196
197
198echo Moving ${otmp} to ${o}
199mv ${otmp} ${o}
This page took 0.023332 seconds and 4 git commands to generate.