summaryrefslogtreecommitdiff
path: root/mcon/U/Signal.U
diff options
context:
space:
mode:
Diffstat (limited to 'mcon/U/Signal.U')
-rw-r--r--mcon/U/Signal.U163
1 files changed, 121 insertions, 42 deletions
diff --git a/mcon/U/Signal.U b/mcon/U/Signal.U
index 2eb4ea9..6ac5eb8 100644
--- a/mcon/U/Signal.U
+++ b/mcon/U/Signal.U
@@ -1,12 +1,12 @@
-?RCS: $Id: Signal.U,v 3.0.1.1 1997/02/28 15:20:01 ram Exp $
+?RCS: $Id$
?RCS:
-?RCS: Copyright (c) 1991-1993, Raphael Manfredi
+?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic Licence,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic Licence; a copy of which may be found at the root
-?RCS: of the source tree for dist 3.0.
+?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: $Log: Signal.U,v $
?RCS: Revision 3.0.1.1 1997/02/28 15:20:01 ram
@@ -14,7 +14,8 @@
?RCS:
?X:
?X: This unit produces three files:
-?X: 1- A signal.c file, which, when compiled and ran, produces an output like:
+?X:
+?X: 1- A signal.c file, which, when compiled and run, produces an output like:
?X:
?X: HUP 1
?X: INT 2
@@ -23,54 +24,75 @@
?X:
?X: 2- A signal.awk script to parse the output of signal.c, fill
?X: in gaps (up to NSIG) and move duplicates to the end.
+?X:
?X: 3- A signal_cmd script to compile signal.c and run it
-?X: through sort -n +1 | uniq | awk -f signal.awk.
+?X: through sort -n -k 2 | uniq | awk -f signal.awk.
+?X: (we try also sort -n +1 since some old hosts don't grok sort -k)
?X: (This is called signal_cmd to avoid OS/2 confusion with
?X: signal.cmd vs. signal.
+?X: The signal_cmd script also falls back on checking signals one at a
+?X: time in case the signal.c program fails. On at least one version of
+?X: Linux 2.1.x, the header file #define'd SIGRTMAX to a symbol that
+?X: is not defined by the compiler/linker. :-(. Further, on that same
+?X: version of Linux, the user had a defective C-shell that gave an
+?X: incorrect list for kill -l, so the fall-back didn't work.
?X:
?X: This unit is then used by sig_name.U.
?X:
?MAKE:Signal: test tr rm awk cat grep startsh eunicefix sed sort uniq \
- Findhdr cppstdin +cppflags cppminus +cc +ccflags +ldflags _o
+ Findhdr cppstdin +cppflags cppminus Compile trnl run
?MAKE: -pick add $@ %<
?X:all files declared as "public" since they're used from other units
?F:signal.c signal_cmd signal.lst signal signal.awk
?T: xx xxx xxxfiles
+?LINT:use rm run
: Trace out the files included by signal.h, then look for SIGxxx names.
-: Remove SIGARRAYSIZE used by HPUX.
-: Remove SIGTYP void lines used by OS2.
-xxx=`echo '#include <signal.h>' |
+?X: Remove SIGARRAYSIZE used by HPUX.
+?X: Remove SIGSTKSIZE used by Linux.
+?X: Remove SIGSTKSZ used by Posix.
+?X: Remove SIGTYP void lines used by OS2.
+?X: Some cpps, like os390, dont give the file name anywhere
+if [ "X$fieldn" = X ]; then
+ : Just make some guesses. We check them later.
+ xxx='/usr/include/signal.h /usr/include/sys/signal.h'
+else
+ xxx=`echo '#include <signal.h>' |
$cppstdin $cppminus $cppflags 2>/dev/null |
$grep '^[ ]*#.*include' |
- $awk "{print \\$$fieldn}" | $sed 's!"!!g' | $sort | $uniq`
-: Check this list of files to be sure we have parsed the cpp output ok.
-: This will also avoid potentially non-existent files, such
-: as ../foo/bar.h
+ $awk "{print \\$$fieldn}" | $sed 's!"!!g' | \
+ $sed 's!\\\\\\\\!/!g' | $sort | $uniq`
+fi
+?X: Check this list of files to be sure we have parsed the cpp output ok.
+?X: This will also avoid potentially non-existent files, such
+?X: as ../foo/bar.h
xxxfiles=''
?X: Add /dev/null in case the $xxx list is empty.
for xx in $xxx /dev/null ; do
$test -f "$xx" && xxxfiles="$xxxfiles $xx"
done
-: If we have found no files, at least try signal.h
+?X: If we have found no files, at least try signal.h
case "$xxxfiles" in
'') xxxfiles=`./findhdr signal.h` ;;
esac
xxx=`awk '
-$1 ~ /^#define$/ && $2 ~ /^SIG[A-Z0-9]*$/ && $2 !~ /SIGARRAYSIZE/ && $3 !~ /void/ {
+$1 ~ /^#define$/ && $2 ~ /^SIG[A-Z0-9]*$/ && $2 !~ /SIGARRAYSIZE/ && $2 !~ /SIGSTKSIZE/ && $2 !~ /SIGSTKSZ/ && $3 !~ /void/ {
print substr($2, 4, 20)
}
$1 == "#" && $2 ~ /^define$/ && $3 ~ /^SIG[A-Z0-9]*$/ && $3 !~ /SIGARRAYSIZE/ && $4 !~ /void/ {
print substr($3, 4, 20)
}' $xxxfiles`
: Append some common names just in case the awk scan failed.
-xxx="$xxx ABRT ALRM BUS CHLD CLD CONT DIL EMT FPE HUP ILL INT IO IOT KILL"
-xxx="$xxx LOST PHONE PIPE POLL PROF PWR QUIT SEGV STKFLT STOP SYS TERM TRAP"
-xxx="$xxx TSTP TTIN TTOU URG USR1 USR2 USR3 USR4 VTALRM"
-xxx="$xxx WINCH WIND WINDOW XCPU XFSZ"
+xxx="$xxx ABRT ALRM BUS CANCEL CHLD CLD CONT DIL EMT FPE"
+xxx="$xxx FREEZE HUP ILL INT IO IOT KILL LOST LWP PHONE"
+xxx="$xxx PIPE POLL PROF PWR QUIT RTMAX RTMIN SEGV STKFLT STOP"
+xxx="$xxx SYS TERM THAW TRAP TSTP TTIN TTOU URG USR1 USR2"
+xxx="$xxx USR3 USR4 VTALRM WAITING WINCH WIND WINDOW XCPU XFSZ"
+
: generate a few handy files for later
-$cat > signal.c <<'EOP'
+$cat > signal.c <<'EOCP'
#include <sys/types.h>
#include <signal.h>
+#include <stdio.h>
int main() {
/* Strange style to avoid deeply-nested #if/#else/#endif */
@@ -125,8 +147,11 @@ int main() {
printf("NSIG %d\n", NSIG);
-EOP
-echo $xxx | $tr ' ' '\012' | $sort | $uniq | $awk '
+#ifndef JUST_NSIG
+
+EOCP
+
+echo $xxx | $tr ' ' $trnl | $sort | $uniq | $awk '
{
printf "#ifdef SIG"; printf $1; printf "\n"
printf "printf(\""; printf $1; printf " %%d\\n\",SIG";
@@ -134,7 +159,8 @@ echo $xxx | $tr ' ' '\012' | $sort | $uniq | $awk '
printf "#endif\n"
}
END {
- printf "}\n";
+ printf "#endif /* JUST_NSIG */\n";
+ printf "exit(0);\n}\n";
}
' >>signal.c
$cat >signal.awk <<'EOP'
@@ -151,41 +177,94 @@ $1 ~ /^NSIG$/ { nsig = $2 }
sig_name[$2] = $1
sig_num[$2] = $2
}
-
}
END {
- if (nsig == 0) { nsig = maxsig + 1 }
- for (n = 1; n < nsig; n++) {
- if (sig_name[n]) {
- printf("%s %d\n", sig_name[n], sig_num[n])
- }
- else {
- printf("NUM%d %d\n", n, n)
- }
+ if (nsig == 0) {
+ nsig = maxsig + 1
+ }
+ printf("NSIG %d\n", nsig);
+ for (n = 1; n < nsig; n++) {
+ if (sig_name[n]) {
+ printf("%s %d\n", sig_name[n], sig_num[n])
}
+ else {
+ printf("NUM%d %d\n", n, n)
+ }
+ }
for (n = 0; n < ndups; n++) {
- printf("%s %d\n", dup_name[n], dup_num[n])
+ printf("%s %d\n", dup_name[n], dup_num[n])
}
}
EOP
$cat >signal_cmd <<EOS
$startsh
-$test -s signal.lst && exit 0
-if $cc $ccflags signal.c -o signal $ldflags >/dev/null 2>&1; then
- ./signal | $sort -n +1 | $uniq | $awk -f signal.awk >signal.lst
+if $test -s signal.lst; then
+ echo "Using your existing signal.lst file"
+ exit 0
+fi
+xxx="$xxx"
+EOS
+?X: Avoid variable interpolation problems, especially with
+?X: xxx, which contains newlines.
+$cat >>signal_cmd <<'EOS'
+
+set signal
+if eval $compile_ok; then
+ $run ./signal$_exe | ($sort -n -k 2 2>/dev/null || $sort -n +1) | \
+ $uniq | $awk -f signal.awk >signal.lst
+else
+ echo "(I can't seem be able to compile the whole test program)" >&4
+ echo "(I'll try it in little pieces.)" >&4
+ set signal -DJUST_NSIG
+ if eval $compile_ok; then
+ $run ./signal$_exe > signal.nsg
+ $cat signal.nsg
+ else
+ echo "I can't seem to figure out how many signals you have." >&4
+ echo "Guessing 50." >&4
+ echo 'NSIG 50' > signal.nsg
+ fi
+ : Now look at all the signal names, one at a time.
+ for xx in `echo $xxx | $tr ' ' $trnl | $sort | $uniq`; do
+ $cat > signal.c <<EOCP
+#include <sys/types.h>
+#include <signal.h>
+#include <stdio.h>
+int main() {
+printf("$xx %d\n", SIG${xx});
+return 0;
+}
+EOCP
+ set signal
+ if eval $compile; then
+ echo "SIG${xx} found."
+ $run ./signal$_exe >> signal.ls1
+ else
+ echo "SIG${xx} NOT found."
+ fi
+ done
+ if $test -s signal.ls1; then
+ $cat signal.nsg signal.ls1 |
+ $sort -n | $uniq | $awk -f signal.awk >signal.lst
+ fi
+
+fi
+if $test -s signal.lst; then
+ :
else
- echo "(I can't seem be able to compile the test program -- Guessing)"
+ echo "(AAK! I can't compile the test programs -- Guessing)" >&4
echo 'kill -l' >signal
- set X \`csh -f <signal\`
+ set X `csh -f <signal`
$rm -f signal
shift
- case \$# in
+ case $# in
0) set HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM;;
esac
- echo \$@ | $tr ' ' '\012' | \
- $awk '{ printf $1; printf " %d\n", ++s; }' >signal.lst
+ echo $@ | $tr ' ' $trnl | \
+ $awk '{ printf "%s %d\n", $1, ++s; }
+ END { printf "NSIG %d\n", ++s }' >signal.lst
fi
-$rm -f signal.c signal signal$_o
+$rm -f signal.c signal$_exe signal$_o signal.nsg signal.ls1
EOS
chmod a+x signal_cmd
$eunicefix signal_cmd