1# Icky intimate knowledge of MiG output.
2
3BEGIN { print "/* This file is generated by shortcut.awk.  */";
4	print "#include <mach-shortcuts-hidden.h>";
5	echo=1;
6	inproto=0; proto=""; arglist="";
7      }
8
9$1 == "LINTLIBRARY" { print "#include <mach.h>"; next }
10
11$1 == "weak_alias" { next }
12
13# Copy the first line of the definition, but
14# replace the function name (RPC) with CALL.
15$NF == rpc \
16  {
17    for (i = 1; i < NF; ++i) printf "%s ", $i;
18    print call;
19    next;
20  }
21
22# Collect the lines of the prototype in PROTO, and extract the parameter
23# names into ARGLIST.
24NF == 1 && $1 == ")" { inproto=0 }
25inproto { proto = proto $0;
26	  arg = $NF;
27	  gsub(/[^a-zA-Z0-9_,]/, "", arg);
28	  arglist = arglist arg;
29	}
30NF == 1 && $1 == "(" { inproto=1 }
31
32/^{$/ { echo=0; }
33
34echo == 1 { print $0; }
35
36/^}$/ && proto != "" \
37  {
38    print "{";
39    print "  kern_return_t err;";
40    print "  extern kern_return_t " syscall " (" proto ");";
41    print "  extern kern_return_t " rpc " (" proto ");";
42    print "  err = " syscall " (" arglist ");";
43    print "  if (err == MACH_SEND_INTERRUPTED)";
44    print "    err = " rpc " (" arglist ");";
45    print "  return err;"
46    print "}";
47    print "weak_alias (" call ", " alias ")";
48    print "libc_hidden_def (" call ")";
49    # Declare RPC so the weak_alias that follows will work.
50    print "extern __typeof (" call ") " rpc ";";
51    echo = 1;
52  }
53