1#!/bin/sh - 2# $NetBSD: makelintstub,v 1.22 2008/08/05 01:54:47 lukem Exp $ 3# 4# Copyright (c) 1996, 1997 Christopher G. Demetriou 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 3. All advertising materials mentioning features or use of this software 16# must display the following acknowledgement: 17# This product includes software developed for the 18# NetBSD Project. See http://www.NetBSD.org/ for 19# information about NetBSD. 20# 4. The name of the author may not be used to endorse or promote products 21# derived from this software without specific prior written permission. 22# 23# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33# 34# <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> 35 36usage() 37{ 38 39cat << _EOF 1>&2 40Usage: $PROG [-n|-p] [-e sedcmd] [-o filename] [-s syscall.h] object ... 41 -e sedcmd sed(1) command to translate filename to syscall name. 42 The ".S" suffix is always removed. 43 Multiple sed commands may be supplied. 44 -n Create SYSCALL_NOERROR. 45 -p Create PSEUDO_NOERROR. 46 (also removes leading "_" on syscall name). 47 -o filename Output to filename. 48 -s syscall.h Header to #include instead of <sys/syscall.h>. 49 50 The CPP environment variable must be set 51 to the path to the C preprocessor. 52_EOF 53 exit 1 54} 55 56header() 57{ 58 59 cat <<- __EOF__ 60 /* 61 * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT. 62 */ 63 64 #include <sys/param.h> 65 #include <sys/aio.h> 66 #include <sys/time.h> 67 #include <sys/mount.h> 68 #include <sys/stat.h> 69 #include <ufs/ufs/dinode.h> 70 #include <ufs/lfs/lfs.h> 71 #include <sys/resource.h> 72 #include <sys/poll.h> 73 #include <sys/uio.h> 74 #include <sys/ipc.h> 75 #include <sys/lwpctl.h> 76 #include <sys/mqueue.h> 77 #include <sys/msg.h> 78 #include <sys/sem.h> 79 #include <sys/shm.h> 80 #include <sys/sched.h> 81 #include <sys/timex.h> 82 #include <sys/socket.h> 83 #include <sys/event.h> 84 #include <sys/uuid.h> 85 #ifdef __STDC__ 86 #include <stdarg.h> 87 #else 88 #include <varargs.h> 89 #endif 90 91 __EOF__ 92} 93 94syscall_stub() 95{ 96 97 syscalldump="$1" 98 syscallname="$2" 99 funcname="$3" 100 101 arglist="$( 102 sed -e 'ta 103 :a 104 s,^/\* syscall: \"'"$syscallname"'\" ,, 105 tb 106 d 107 :b 108 s, \*/$,,' $syscalldump 109 )" 110 111 eval set -f -- "$arglist" 112 113 if [ $# -lt 3 ]; then 114 echo syscall $syscallname not found! 1>&2 115 exit 1 116 fi 117 118 shift # kill "ret:" 119 returntype=$1; shift 120 shift # kill "args:" 121 122 cat <<- __EOF__ 123 /*ARGSUSED*/ 124 $returntype 125 __EOF__ 126 127 # do ANSI C function header 128 echo "#ifdef __STDC__" 129 130 echo "$funcname(" 131 first=true; i=1 132 for arg; do 133 if $first; then 134 first=false 135 else 136 echo ", " 137 fi 138 case "$arg" in 139 "...") echo "...";; 140 *) echo "$arg arg$i"; i=$(($i + 1));; 141 esac 142 done 143 if $first; then 144 echo "void" 145 fi 146 echo ")" 147 148 # do K&R C function header 149 echo "#else" 150 151 echo "$funcname(" 152 first=true; i=1 153 for arg; do 154 if $first; then 155 first=false 156 else 157 echo ", " 158 fi 159 case "$arg" in 160 "...") echo "va_alist";; 161 *) echo "arg$i"; i=$(($i + 1));; 162 esac 163 done 164 echo ")" 165 i=1 166 for arg; do 167 case "$arg" in 168 "...") echo " va_dcl";; 169 *) echo " $arg arg$i;"; i=$(($i + 1));; 170 esac 171 done 172 173 # do function body 174 echo "#endif" 175 176 echo "{" 177 if [ "$returntype" != "void" ]; then 178 echo " return (($returntype)0);" 179 fi 180 echo "}" 181} 182 183trailer() 184{ 185 186 cat <<- __EOF__ 187 /* END */ 188 __EOF__ 189} 190 191 192pflag=false 193nflag=false 194oarg="" 195fnsedcmd="" 196syscallhdr=/usr/include/sys/syscall.h 197syscalldump=/tmp/makelintstub.$$ 198PROG="$(basename "$0")" 199 200if [ -z "${CPP}" ]; then 201 usage 202fi 203 204while getopts e:no:ps: i 205do 206 case "$i" in 207 e) fnsedcmd="$fnsedcmd -e $OPTARG";; 208 n) nflag=true;; 209 o) oarg=$OPTARG;; 210 p) pflag=true;; 211 s) syscallhdr=$OPTARG;; 212 *) usage;; 213 esac 214done 215 216shift $(expr $OPTIND - 1) 217 218if $pflag && $nflag 219then 220 echo "$PROG: -n flag and -p flag may not be used together" 1>&2 221 usage 222fi 223 224if [ -n "$oarg" ]; then 225 exec > $oarg 226fi 227 228trap "rm -f $syscalldump" 0 1 2 3 15 229 230header 231 232echo "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump 233 234for syscall; do 235 fnname=${syscall%.S} 236 if [ -n "$fnsedcmd" ]; then 237 fnname=$(echo "$fnname" | sed $fnsedcmd) 238 fi 239 if $pflag; then 240 scname=${fnname#_} 241 else 242 scname=$fnname 243 fi 244 syscall_stub $syscalldump $scname $fnname 245 echo "" 246done 247 248trailer 249 250exit 0 251