1#! /bin/sh - 2# 3# $FreeBSD$ 4 5set -e 6 7case $# in 8 0) echo "usage: $0 input-file <config-file>" 1>&2 9 exit 1 10 ;; 11esac 12 13if [ -n "$2" -a -f "$2" ]; then 14 . $2 15fi 16 17sed -e ' 18s/\$//g 19:join 20 /\\$/{a\ 21 22 N 23 s/\\\n// 24 b join 25 } 262,${ 27 /^#/!s/\([{}()*,]\)/ \1 /g 28} 29' < $1 | awk ' 30 BEGIN { 31 printf "#include <sys/param.h>\n" 32 printf "#include <machine/atomic.h>\n" 33 printf "\n" 34 printf "#include <sys/_semaphore.h>\n" 35 printf "#include <sys/aio.h>\n" 36 printf "#include <sys/cpuset.h>\n" 37 printf "#include <sys/jail.h>\n" 38 printf "#include <sys/linker.h>\n" 39 printf "#include <sys/mac.h>\n" 40 printf "#include <sys/module.h>\n" 41 printf "#include <sys/mount.h>\n" 42 printf "#include <sys/mqueue.h>\n" 43 printf "#include <sys/msg.h>\n" 44 printf "#include <sys/poll.h>\n" 45 printf "#include <sys/proc.h>\n" 46 printf "#include <sys/resource.h>\n" 47 printf "#include <sys/sem.h>\n" 48 printf "#include <sys/shm.h>\n" 49 printf "#include <sys/signal.h>\n" 50 printf "#include <sys/signalvar.h>\n" 51 printf "#include <sys/socket.h>\n" 52 printf "#include <sys/stat.h>\n" 53 printf "#include <sys/thr.h>\n" 54 printf "#include <sys/time.h>\n" 55 printf "#include <sys/timex.h>\n" 56 printf "#include <sys/timeffc.h>\n" 57 printf "#include <sys/ucontext.h>\n" 58 printf "#include <sys/utsname.h>\n" 59 printf "#include <sys/uuid.h>\n" 60 printf "#include <sys/wait.h>\n" 61 printf "\n" 62 printf "#ifndef _ACL_PRIVATE\n" 63 printf "#define _ACL_PRIVATE\n" 64 printf "#endif\n" 65 printf "#include <sys/acl.h>\n" 66 printf "\n" 67 printf "#ifndef EBUSY\n" 68 printf "#define errno 0\n" 69 printf "#define EBUSY 0\n" 70 printf "#endif\n" 71 printf "#include <sys/umtx.h>\n" 72 printf "\n" 73 # existing compat shims 74 printf "struct ostat;\n" 75 printf "struct nstat;\n" 76 printf "struct ostatfs;\n" 77 printf "struct osigaction;\n" 78 printf "struct osigcontext;\n" 79 printf "struct oaiocb;\n" 80 printf "union semun_old;\n" 81 printf "typedef unsigned int osigset_t;\n" 82 printf "struct msqid_ds_old;\n" 83 printf "struct shmid_ds_old;\n" 84 # TODO 85 printf "struct ucontext4;\n" 86 printf "struct sctp_sndrcvinfo;\n" 87 printf "\n" 88 } 89 NF < 4 || $1 !~ /^[0-9]+$/ { 90 next 91 } 92 $3 ~ "UNIMPL" || $3 ~ "OBSOL" || $3 ~ "NODEF" || $3 ~ "NOPROTO" || 93 $3 ~ "NOSTD"{ 94 next 95 } 96 $4 == "{" { 97 if ($3 ~ /COMPAT[0-9]*/) { 98 n = split($3, flags, /\|/) 99 for (i = 1; i <= n; i++) { 100 if (flags[i] == "COMPAT") { 101 $6 = "o" $6 102 } else if (flags[i] ~ /COMPAT[0-9]+/) { 103 sub(/COMPAT/, "freebsd", flags[i]) 104 $6 = flags[i] "_" $6 105 } 106 } 107 } 108 $6 = "__sysfake_" $6 109 r = "" 110 if ($5 != "void") 111 r = "0" 112 def = "" 113 impl = "" 114 for ( i = 5; i <= NF; i++) { 115 if ($i == ";") 116 break; 117 if ($i == "," || $i == ")") 118 impl = impl " __unused" 119 impl = impl " " $i 120 def = def " " $i 121 } 122 printf "%s;\n", def 123 printf "%s\n{ return %s; }\n", impl, r 124 next 125 } 126 { 127 printf "invalid line: " 128 print 129 } 130' 131