fb92b635673cbc5f8f21b2b006ede012528dfc72
[deliverable/binutils-gdb.git] / gdb / observer.sh
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
11 o=$1
12 otmp="`echo $1 | sed -e 's,\.[^.]*$,,'`.tmp"; shift
13 echo "Creating ${otmp}" 1>&2
14 rm -f ${otmp}
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
20 cat <<EOF >>${otmp}
21 /* GDB Notifications to Observers.
22
23 Copyright 2004, 2005 Free Software Foundation, Inc.
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
46 EOF
47
48
49 case $lang in
50 h) cat <<EOF >>${otmp}
51 #ifndef OBSERVER_H
52 #define OBSERVER_H
53
54 struct observer;
55 struct bpstats;
56 struct so_list;
57 EOF
58 ;;
59 esac
60
61
62 # generate a list of events that can be observed
63
64 IFS=:
65 sed -n '
66 /@deftypefun void/{
67 # Save original line for later processing into the actual parameter
68 h
69 # Convert from: @deftypefun void EVENT (TYPE @var{PARAM},...)
70 # to event and formals: EVENT:TYPE PARAM, ...:
71 s/^.* void \([a-z_][a-z_]*\) (\(.*\))$/\1:\2/
72 s/@var{//g
73 s/}//g
74 # Switch to held
75 x
76 # Convert from: @deftypefun void FUNC (TYPE @var{PARAM},...)
77 # to actuals: PARAM, ...
78 s/^[^{]*[{]*//
79 s/[}]*[^}]*$//
80 s/}[^{]*{/, /g
81 # Combine held (EVENT:TYPE PARAM, ...:) and pattern (PARAM, ...) into
82 # FUNC:TYPE PARAM, ...:PARAM, ...
83 H
84 x
85 s/\n/:/g
86 p
87 }
88 ' $texi | while read event formal actual
89 do
90 case $lang in
91 h) cat <<EOF >>${otmp}
92
93 /* ${event} notifications. */
94
95 typedef void (observer_${event}_ftype) (${formal});
96
97 extern struct observer *observer_attach_${event} (observer_${event}_ftype *f);
98 extern void observer_detach_${event} (struct observer *observer);
99 extern void observer_notify_${event} (${formal});
100 EOF
101 ;;
102
103 inc)
104 cat <<EOF >>${otmp}
105
106 /* ${event} notifications. */
107
108 static struct observer_list *${event}_subject = NULL;
109
110 struct ${event}_args { `echo "${formal}" | sed -e 's/,/;/g'`; };
111
112 static void
113 observer_${event}_notification_stub (const void *data, const void *args_data)
114 {
115 observer_${event}_ftype *notify = (observer_${event}_ftype *) data;
116 const struct ${event}_args *args = args_data;
117 notify (`echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args->\1/g'`);
118 }
119
120 struct observer *
121 observer_attach_${event} (observer_${event}_ftype *f)
122 {
123 return generic_observer_attach (&${event}_subject,
124 &observer_${event}_notification_stub,
125 (void *) f);
126 }
127
128 void
129 observer_detach_${event} (struct observer *observer)
130 {
131 generic_observer_detach (&${event}_subject, observer);
132 }
133
134 void
135 observer_notify_${event} (${formal})
136 {
137 struct ${event}_args args;
138 `echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args.\1 = \1/g'`;
139 if (observer_debug)
140 fprintf_unfiltered (gdb_stdlog, "observer_notify_${event}() called\n");
141 generic_observer_notify (${event}_subject, &args);
142 }
143 EOF
144 ;;
145 esac
146 done
147
148
149 case $lang in
150 h) cat <<EOF >>${otmp}
151
152 #endif /* OBSERVER_H */
153 EOF
154 esac
155
156
157 echo Moving ${otmp} to ${o}
158 mv ${otmp} ${o}
This page took 0.052335 seconds and 4 git commands to generate.