summaryrefslogtreecommitdiff
path: root/src/helpers/sigtool
blob: 85f3ace44e0077d6f634bbc2781ab8e49f3150c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
:
#	SCCS: @(#)sigtool	1.4 (98/09/08)
#
#	UniSoft Ltd., London, England
#
# Copyright (c) 1998 The Open Group
# All rights reserved.
#
# No part of this source code may be reproduced, stored in a retrieval
# system, or transmitted, in any form or by any means, electronic,
# mechanical, photocopying, recording or otherwise, except as stated in
# the end-user licence agreement, without the prior permission of the
# copyright owners.
# A copy of the end-user licence agreement is contained in the file
# Licence which accompanies this distribution.
# 
# Motif, OSF/1, UNIX and the "X" device are registered trademarks and
# IT DialTone and The Open Group are trademarks of The Open Group in
# the US and other countries.
#
# X/Open is a trademark of X/Open Company Limited in the UK and other
# countries.
#
# ************************************************************************
#
# SCCS:   	@(#)sigtool	1.4 98/09/08 TETware release 3.3
# NAME:		sigtool
# PRODUCT:	TETware
# AUTHOR:	Andrew Dingwall, UniSoft Ltd.
# DATE CREATED:	September 1998
#
# DESCRIPTION:
#	Shell script to generate the signal lists used in a defines.mk
#	file when building the xpg3sh API.
#
#	usage:
#		[CC=cc-name] sh sigtool [cc-options ...]
#
#	This script creates a small C program and compiles it.
#	If the C compiler is not called cc on your system, you should set
#	the CC environment variable to the name of the C compiler.
#
#	On most systems, cc-options are not required.
#	Indeed, since this script looks for the value of NSIG (or _NSIG)
#	in <signal.h>, options that enable ANSI C or feature test macros that
#	restrict the namespace should not be specified.
# 
# MODIFICATIONS:
# 
# ************************************************************************


# don't run this script on a Win32 system
case `uname -s` in
Windows_NT|Windows_95|DOS)
	echo "$0: Win32 systems do not really support signals" 1>&2
	echo "$0: use the signal values defined in src/defines/msc+mks.mk" 1>&2
	exit 1
	;;
esac

# temporary file names
tmp1_c=tmp$$-1.c
tmp2_c=tmp$$-2.c
tmp3_c=tmp$$-3.c
tmp4=tmp$$-4
tmp5=tmp$$-5

# arrange to clean up on exit
trap 's=$?; rm -f $tmp1_c $tmp2_c $tmp3_c $tmp4 $tmp5; exit $s' 0
trap 'exit $?' 1 2 3 13 15

# lists of signal names
std_sigs1="SIGHUP SIGINT SIGQUIT SIGILL SIGABRT SIGFPE SIGPIPE SIGALRM"
std_sigs2="SIGTERM SIGUSR1 SIGUSR2 SIGTSTP SIGCONT SIGTTIN SIGTTOU"
spec_sigs="SIGKILL SIGCHLD SIGSTOP SIGSEGV"


# generate the signal evaluation program
for sig in $std_sigs1 $std_sigs2
do
	cat <<!EOF
#ifdef $sig
	printf(" %d", $sig);
#else
	printf(" $sig");
#endif
!EOF
done > $tmp1_c

for sig in $spec_sigs
do
	cat <<!EOF
#ifdef $sig
	printf(" %d", $sig);
#else
	printf(" $sig");
#endif
!EOF
done > $tmp2_c

cat > $tmp3_c <<!EOF
#include <stdio.h>
#include <signal.h>
int main()
{
	printf("SH_STD_SIGNALS =");
#include "$tmp1_c"
	printf("\nSH_SPEC_SIGNALS =");
#include "$tmp2_c"
	printf("\nSH_NSIG = ");
#ifdef NSIG
	printf("%d", NSIG);
#else
#  ifdef _NSIG
	printf("%d", _NSIG);
#  else
	printf("NSIG");
#  endif
#endif
	printf("\n");
	return(0);
}
!EOF

# compile the signal evaluation program
${CC:-cc} $* -o $tmp4 $tmp3_c
if test $? -ne 0
then
	echo "$0: can't compile signal evaluation program" 1>&2
	(exit 1)
	exit 1
fi

# generate the awk script
cat > $tmp5 <<!EOF
BEGIN {
	printf("# The following signal values have been generated by sigtool.\n");
	printf("# It is assumed that the shell is capable of trapping all\n");
	printf("# the signals except $spec_sigs\n");
	printf("# If this is not true on your system you will need to edit\n");
	printf("# the values that follow.\n\n");
	errors = 0;
	done_std_sigs = 0;
	done_spec_sigs = 0;
	done_nsig = 0;
}

\$2 != "=" {
	next;
}

\$1 == "SH_STD_SIGNALS" {
	printf("# standard signals:\n");
	printf("# $std_sigs1\n");
	printf("# $std_sigs2\n");
	done_std_sigs = 1;
}

\$1 == "SH_SPEC_SIGNALS" {
	printf("# signals that cannot be handled by the shell:\n");
	printf("# $spec_sigs\n");
	done_spec_sigs = 1;
}

\$1 == "SH_NSIG" {
	printf("# highest signal number supported by the shell + 1\n");
	done_nsig = 1;
}

{
	for (n = 3; n <= NF; n++)
		if (\$n ~ /[^0-9]/) {
			printf("*** cannot determine a value for %s\n", \$n);
			errors++;
		}
	printf("%s\n\n", \$0);
}

END {
	if (errors || !done_std_sigs || !done_spec_sigs || !done_nsig) {
		printf("You will need to supply the values that could not\n");
		printf("be determined automatically by sigtool.\n");
		printf("For details, please refer to the TETware Installation\n");
		printf("Guide for UNIX Operating Systems.\n");
	}
}
!EOF

# finally, generate the signal lists
./$tmp4 | awk -f $tmp5