NetBSD/usr.bin/ktruss/makeerrnos.sh
kamil 453514a280 Add support for SIGRTMIN+1..SIGRTMAX-1 signals in ktruss(1)
Generate misc.c and misc.h with entries for signals between SIGRTMIN+1
and SIGRTMAX-1.
2019-05-06 11:58:37 +00:00

92 lines
1.6 KiB
Bash
Executable File

#! /bin/sh
#
# $NetBSD: makeerrnos.sh,v 1.7 2019/05/06 11:58:37 kamil Exp $
if [ $# -ne 3 ]; then
echo "usage: makeerrnos.sh errno.h signal.h output"
exit 1;
fi
ERRNOH=$1
SIGNALH=$2
CFILE=$3.c
HFILE=$3.h
: ${AWK:=awk}
: ${CPP:=cpp}
: ${CPPFLAGS:=}
cat <<__EOF__ > $CFILE
#include "misc.h"
struct systab errnos[] = {
__EOF__
cat ${ERRNOH} | ${CPP} ${CPPFLAGS} -dM |
${AWK} '
/^#[ ]*define[ ]*E[A-Z0-9]*[ ]*[0-9-][0-9]*[ ]*.*/ {
for (i = 1; i <= NF; i++)
if ($i ~ /define/)
break;
i++;
j = i + 1;
#
printf("\t{ \"%s\", %s },\n", $i, $j);
}
END {
print " { \"0\", 0 },\n";
}
' | sort -n -k 3 >> $CFILE
echo " { 0L, 0},
};" >> $CFILE
lines=`wc -l $CFILE | ${AWK} ' { print $1; } ' -`
lines=`expr $lines - 4`
cat <<__EOF__ >> $CFILE
struct systab signals[] = {
__EOF__
cat ${SIGNALH} | ${CPP} ${CPPFLAGS} -dM |
${AWK} '
/^#[ ]*define[ ]*S[A-Z0-9]*[ ]*[0-9-][0-9]*[ ]*.*/ {
for (i = 1; i <= NF; i++)
if ($i ~ /define/)
break;
i++;
j = i + 1;
if ($i == "SIGRTMIN") {
sigrtmin=$j;
}
if ($i == "SIGRTMAX") {
sigrtmax=$j;
}
#
printf("\t{ \"%s\", %s },\n", $i, $j);
}
END {
j = 1;
for (i = sigrtmin + 1; i < sigrtmax; i++) {
printf("\t{ \"SIGRTMIN+%s\", %s },\n", j++, i);
}
print " { \"0\", 0 },\n";
}
' | sort -n -k 3 >> $CFILE
echo " { 0L, 0},
};" >> $CFILE
elines=`grep '{ "SIG' $CFILE | wc -l`
elines=`expr $elines + 1`
cat <<__EOF__ >$HFILE
struct systab {
const char *name;
int value;
};
extern struct systab errnos[$lines + 1];
extern struct systab signals[$elines + 1];
#define MAXERRNOS $lines
#define MAXSIGNALS $elines
__EOF__