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