summaryrefslogtreecommitdiffstats
path: root/src/sig2code.awk
diff options
context:
space:
mode:
Diffstat (limited to 'src/sig2code.awk')
-rw-r--r--src/sig2code.awk61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/sig2code.awk b/src/sig2code.awk
new file mode 100644
index 0000000..d6bdb0d
--- /dev/null
+++ b/src/sig2code.awk
@@ -0,0 +1,61 @@
+BEGIN {
+ FS = "[ \t]*->[ \t]*";
+
+ #read in codes
+ while (getline < "sig2code.txt")
+ {
+ sub(/^[ \t]*/, "");
+ if (NF < 2)
+ continue;
+
+ #print $1, $2
+ sigmap[$2] = $1
+ }
+
+ close("sig2code.txt");
+
+ FS = "[ \t]*,[ \t]*";
+
+ print "/* Include in your C module */";
+ print "static PY_SIGNAL_SPEC_REC py_sigmap[] = {";
+}
+
+function match_type(t)
+{
+ for (type in sigmap)
+ {
+ if (index(t, type) != 0)
+ return sigmap[type];
+ }
+
+ return "?";
+}
+
+$1 ~ /^[ \t]*"/ && $1 !~ /"script error"/ {
+ sub(/^[ \t]*/, "");
+
+ signal = $1
+ if (signal ~ /.*<cmd>$/)
+ {
+ varsig = 1;
+ sub(/<cmd>/, "", signal);
+ }
+ else
+ varsig = 0;
+
+ args = "";
+ for (i = 2; i <= NF; i++)
+ {
+ args = args""match_type($i);
+ }
+
+ printf(" {%s, \"%s\", 0, 0, %d},\n", signal, args, varsig);
+}
+
+END {
+ print " {NULL}" ;
+ print "};";
+ print "";
+ print "#define py_sigmap_len() (sizeof(py_sigmap) / sizeof(py_sigmap[0]) - 1)";
+}
+