phunix/minix/usr.bin/trace/signal.awk
David van Moolenbroek b58e161ccb trace(1): resolve all level-5 LLVM warnings
Change-Id: If5ffe97eb0b15387b1ab674657879e13f58fb27e
2016-01-16 14:04:15 +01:00

33 lines
969 B
Awk

# This one is a bit trickier than error.awk, because sys/signal.h is not as
# easy to parse. We currently assume that all (userland) signals are listed
# before the first reference to "_KERNEL", and anything else that looks like a
# signal definition (but isn't) is after that first reference.
BEGIN {
printf("/* This file is automatically generated by signal.awk */\n\n");
printf("#include \"inc.h\"\n\n");
printf("static const char *const signals[] = {\n");
}
/^#define/ {
name = $2;
if (!match(name, "SIG[^_]"))
next;
number = $3;
if (number < 0 || number == "SIGABRT")
next;
printf("\t[%s] = \"%s\",\n", name, name);
}
/_KERNEL/ {
exit;
}
END {
printf("};\n\n");
printf("const char *\nget_signal_name(int sig)\n{\n\n");
printf("\tif (sig >= 0 && (unsigned int)sig < __arraycount(signals) &&\n");
printf("\t signals[sig] != NULL)\n");
printf("\t\treturn signals[sig];\n");
printf("\telse\n");
printf("\t\treturn NULL;\n");
printf("}\n");
}