#!/bin/sh # # gencalls.sh - generate calls.c and calls.h # # Usage: gencalls.sh callspecs-file if [ "x$1" = x ]; then echo "Usage: $0 callspecs-file" exit 1 fi awk < $1 ' BEGIN { type["ptr"] = "void *"; type["int"] = "int"; type["off"] = "off_t"; type["size"] = "size_t"; fmt["ptr"] = "%p"; fmt["int"] = "%d"; fmt["off"] = "%lld"; fmt["size"] = "%lu"; cast["ptr"] = ""; cast["int"] = ""; cast["off"] = "(long long)"; cast["size"] = "(unsigned long)"; printf "/* Automatically generated file; do not edit */\n"; printf "#include \n"; printf "#include \n"; printf "#include \n"; printf "#include \n"; printf "#include \n"; printf "#include \n"; printf "#include \n"; printf "#include \n"; printf "\n"; printf "#include \"extern.h\"\n"; printf "\n"; printf "typedef void (*tryfunc)(int dofork);\n"; printf "\n"; n=0; } { printf "static\n"; printf "void\n"; printf "try_%s(int dofork)\n", $2; printf "{\n"; for (i=3; i<=NF; i++) { printf "\t%s a%d = rand%s();\n", type[$i], i-3, $i; } printf "\tint result, pid, status;\n"; printf "\tchar buf[128];\n"; printf "\n"; printf "\tsnprintf(buf, sizeof(buf), \"%s(", $2; for (i=3; i<=NF; i++) { printf "%s", fmt[$i]; if (i0) {\n"; printf "\t\twaitpid(pid, &status, 0);\n"; printf "\t\treturn;\n"; printf "\t}\n"; printf "\n"; printf "\tresult = %s(", $2; for (i=3; i<=NF; i++) { printf "a%d", i-3; if (i=2 && asst<=5);\n"; printf "\tlist = tables[asst-2];\n"; printf "\n"; printf "\tfor (i=0; i