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