1#!/bin/sh - 2# $NetBSD: makelintstub,v 1.21 2008/01/15 03:37:14 rmind 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] [-o filename] object ... 41 The CPP environment variable must be set 42 to the path to the C preprocessor. 43_EOF 44 exit 1 45} 46 47header() 48{ 49 50 cat <<- __EOF__ 51 /* 52 * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT. 53 */ 54 55 #include <sys/param.h> 56 #include <sys/aio.h> 57 #include <sys/time.h> 58 #include <sys/mount.h> 59 #include <sys/stat.h> 60 #include <ufs/ufs/dinode.h> 61 #include <ufs/lfs/lfs.h> 62 #include <sys/resource.h> 63 #include <sys/poll.h> 64 #include <sys/uio.h> 65 #include <sys/ipc.h> 66 #include <sys/lwpctl.h> 67 #include <sys/mqueue.h> 68 #include <sys/msg.h> 69 #include <sys/sem.h> 70 #include <sys/shm.h> 71 #include <sys/sched.h> 72 #include <sys/timex.h> 73 #include <sys/socket.h> 74 #include <sys/event.h> 75 #include <sys/uuid.h> 76 #ifdef __STDC__ 77 #include <stdarg.h> 78 #else 79 #include <varargs.h> 80 #endif 81 82 __EOF__ 83} 84 85syscall_stub() 86{ 87 88 syscalldump="$1" 89 syscallname="$2" 90 funcname="$3" 91 92 arglist="$( 93 sed -e 'ta 94 :a 95 s,^/\* syscall: \"'"$syscallname"'\" ,, 96 tb 97 d 98 :b 99 s, \*/$,,' $syscalldump 100 )" 101 102 eval set -f -- "$arglist" 103 104 if [ $# -lt 3 ]; then 105 echo syscall $syscallname not found! 1>&2 106 exit 1 107 fi 108 109 shift # kill "ret:" 110 returntype=$1; shift 111 shift # kill "args:" 112 113 cat <<- __EOF__ 114 /*ARGSUSED*/ 115 $returntype 116 __EOF__ 117 118 # do ANSI C function header 119 echo "#ifdef __STDC__" 120 121 echo "$funcname(" 122 first=true; i=1 123 for arg; do 124 if $first; then 125 first=false 126 else 127 echo ", " 128 fi 129 case "$arg" in 130 "...") echo "...";; 131 *) echo "$arg arg$i"; i=$(($i + 1));; 132 esac 133 done 134 if $first; then 135 echo "void" 136 fi 137 echo ")" 138 139 # do K&R C function header 140 echo "#else" 141 142 echo "$funcname(" 143 first=true; i=1 144 for arg; do 145 if $first; then 146 first=false 147 else 148 echo ", " 149 fi 150 case "$arg" in 151 "...") echo "va_alist";; 152 *) echo "arg$i"; i=$(($i + 1));; 153 esac 154 done 155 echo ")" 156 i=1 157 for arg; do 158 case "$arg" in 159 "...") echo " va_dcl";; 160 *) echo " $arg arg$i;"; i=$(($i + 1));; 161 esac 162 done 163 164 # do function body 165 echo "#endif" 166 167 echo "{" 168 if [ "$returntype" != "void" ]; then 169 echo " return (($returntype)0);" 170 fi 171 echo "}" 172} 173 174trailer() 175{ 176 177 cat <<- __EOF__ 178 /* END */ 179 __EOF__ 180} 181 182 183pflag=false 184nflag=false 185oarg="" 186syscallhdr=/usr/include/sys/syscall.h 187syscalldump=/tmp/makelintstub.$$ 188PROG="$(basename "$0")" 189 190if [ -z "${CPP}" ]; then 191 usage 192fi 193 194while getopts no:ps: i 195do 196 case "$i" in 197 n) nflag=true;; 198 o) oarg=$OPTARG;; 199 p) pflag=true;; 200 s) syscallhdr=$OPTARG;; 201 *) usage;; 202 esac 203done 204 205shift $(expr $OPTIND - 1) 206 207if $pflag && $nflag 208then 209 echo "$PROG: -n flag and -p flag may not be used together" 1>&2 210 usage 211fi 212 213if [ -n "$oarg" ]; then 214 exec > $oarg 215fi 216 217trap "rm -f $syscalldump" 0 1 2 3 15 218 219header 220 221echo "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump 222 223for syscall; do 224 fnname=${syscall%.S} 225 if $pflag; then 226 scname=${fnname#_} 227 else 228 scname=$fnname 229 fi 230 syscall_stub $syscalldump $scname $fnname 231 echo "" 232done 233 234trailer 235 236exit 0 237