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