Switch the license of all .h files to GPLv3.
[deliverable/binutils-gdb.git] / gdb / observer.sh
CommitLineData
7a464420
AC
1#!/bin/sh -e
2
6e2c7fa1
DJ
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
7a464420
AC
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
15c3c5c6 16o=$1
99efcb59
AS
17case $lang in
18 h) tmp=htmp ;;
19 inc) tmp=itmp ;;
20esac
21otmp="`echo $1 | sed -e 's,\.[^.]*$,,'`.$tmp"; shift
15c3c5c6
EZ
22echo "Creating ${otmp}" 1>&2
23rm -f ${otmp}
7a464420
AC
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
15c3c5c6 29cat <<EOF >>${otmp}
7a464420
AC
30/* GDB Notifications to Observers.
31
6aba47ca 32 Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
7a464420
AC
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 2 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, write to the Free Software
197e01b6
EZ
48 Foundation, Inc., 51 Franklin Street, Fifth Floor,
49 Boston, MA 02110-1301, USA.
7a464420
AC
50
51 --
52
53 This file was generated using observer.sh and observer.texi. */
54
55EOF
56
57
58case $lang in
15c3c5c6 59 h) cat <<EOF >>${otmp}
7a464420
AC
60#ifndef OBSERVER_H
61#define OBSERVER_H
62
63struct observer;
64struct bpstats;
84acb35a 65struct so_list;
06d3b283 66struct objfile;
7a464420
AC
67EOF
68 ;;
69esac
70
5711a8b0
EZ
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
f3e25dcb 74if test -n "$DJGPP"
5711a8b0
EZ
75then
76 texi=`echo $texi | sed -e 's,^\([a-zA-Z]\):/,/dev/\1/,'`
77fi
7a464420
AC
78
79# generate a list of events that can be observed
80
81IFS=:
82sed -n '
83/@deftypefun void/{
350c2e5b 84# Save original line for later processing into the actual parameter
7a464420 85 h
350c2e5b
JB
86# Convert from: @deftypefun void EVENT (TYPE @var{PARAM},...)
87# to event and formals: EVENT:TYPE PARAM, ...:
7a464420
AC
88 s/^.* void \([a-z_][a-z_]*\) (\(.*\))$/\1:\2/
89 s/@var{//g
90 s/}//g
350c2e5b 91# Switch to held
7a464420 92 x
350c2e5b
JB
93# Convert from: @deftypefun void FUNC (TYPE @var{PARAM},...)
94# to actuals: PARAM, ...
7a464420
AC
95 s/^[^{]*[{]*//
96 s/[}]*[^}]*$//
97 s/}[^{]*{/, /g
350c2e5b
JB
98# Combine held (EVENT:TYPE PARAM, ...:) and pattern (PARAM, ...) into
99# FUNC:TYPE PARAM, ...:PARAM, ...
7a464420
AC
100 H
101 x
102 s/\n/:/g
103 p
104}
105' $texi | while read event formal actual
106do
107 case $lang in
15c3c5c6 108 h) cat <<EOF >>${otmp}
7a464420
AC
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)
15c3c5c6 121 cat <<EOF >>${otmp}
7a464420
AC
122
123/* ${event} notifications. */
124
125static struct observer_list *${event}_subject = NULL;
126
127struct ${event}_args { `echo "${formal}" | sed -e 's/,/;/g'`; };
128
129static void
130observer_${event}_notification_stub (const void *data, const void *args_data)
131{
132 observer_${event}_ftype *notify = (observer_${event}_ftype *) data;
133 const struct ${event}_args *args = args_data;
134 notify (`echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args->\1/g'`);
135}
136
137struct observer *
138observer_attach_${event} (observer_${event}_ftype *f)
139{
140 return generic_observer_attach (&${event}_subject,
141 &observer_${event}_notification_stub,
142 (void *) f);
143}
144
145void
146observer_detach_${event} (struct observer *observer)
147{
148 generic_observer_detach (&${event}_subject, observer);
149}
150
151void
152observer_notify_${event} (${formal})
153{
154 struct ${event}_args args;
155 `echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args.\1 = \1/g'`;
2b4855ab
AC
156 if (observer_debug)
157 fprintf_unfiltered (gdb_stdlog, "observer_notify_${event}() called\n");
7a464420
AC
158 generic_observer_notify (${event}_subject, &args);
159}
160EOF
161 ;;
162 esac
163done
164
165
166case $lang in
15c3c5c6 167 h) cat <<EOF >>${otmp}
7a464420
AC
168
169#endif /* OBSERVER_H */
170EOF
171esac
172
173
15c3c5c6
EZ
174echo Moving ${otmp} to ${o}
175mv ${otmp} ${o}
This page took 0.281053 seconds and 4 git commands to generate.