1#!/bin/sh - 2# $NetBSD: makelintstub,v 1.20 2007/11/13 09:07:33 he 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/timex.h> 72 #include <sys/socket.h> 73 #include <sys/event.h> 74 #include <sys/uuid.h> 75 #ifdef __STDC__ 76 #include <stdarg.h> 77 #else 78 #include <varargs.h> 79 #endif 80 81 __EOF__ 82} 83 84syscall_stub() 85{ 86 87 syscalldump="$1" 88 syscallname="$2" 89 funcname="$3" 90 91 arglist="$( 92 sed -e 'ta 93 :a 94 s,^/\* syscall: \"'"$syscallname"'\" ,, 95 tb 96 d 97 :b 98 s, \*/$,,' $syscalldump 99 )" 100 101 eval set -f -- "$arglist" 102 103 if [ $# -lt 3 ]; then 104 echo syscall $syscallname not found! 1>&2 105 exit 1 106 fi 107 108 shift # kill "ret:" 109 returntype=$1; shift 110 shift # kill "args:" 111 112 cat <<- __EOF__ 113 /*ARGSUSED*/ 114 $returntype 115 __EOF__ 116 117 # do ANSI C function header 118 echo "#ifdef __STDC__" 119 120 echo "$funcname(" 121 first=true; i=1 122 for arg; do 123 if $first; then 124 first=false 125 else 126 echo ", " 127 fi 128 case "$arg" in 129 "...") echo "...";; 130 *) echo "$arg arg$i"; i=$(($i + 1));; 131 esac 132 done 133 if $first; then 134 echo "void" 135 fi 136 echo ")" 137 138 # do K&R C function header 139 echo "#else" 140 141 echo "$funcname(" 142 first=true; i=1 143 for arg; do 144 if $first; then 145 first=false 146 else 147 echo ", " 148 fi 149 case "$arg" in 150 "...") echo "va_alist";; 151 *) echo "arg$i"; i=$(($i + 1));; 152 esac 153 done 154 echo ")" 155 i=1 156 for arg; do 157 case "$arg" in 158 "...") echo " va_dcl";; 159 *) echo " $arg arg$i;"; i=$(($i + 1));; 160 esac 161 done 162 163 # do function body 164 echo "#endif" 165 166 echo "{" 167 if [ "$returntype" != "void" ]; then 168 echo " return (($returntype)0);" 169 fi 170 echo "}" 171} 172 173trailer() 174{ 175 176 cat <<- __EOF__ 177 /* END */ 178 __EOF__ 179} 180 181 182pflag=false 183nflag=false 184oarg="" 185syscallhdr=/usr/include/sys/syscall.h 186syscalldump=/tmp/makelintstub.$$ 187PROG="$(basename "$0")" 188 189if [ -z "${CPP}" ]; then 190 usage 191fi 192 193while getopts no:ps: i 194do 195 case "$i" in 196 n) nflag=true;; 197 o) oarg=$OPTARG;; 198 p) pflag=true;; 199 s) syscallhdr=$OPTARG;; 200 *) usage;; 201 esac 202done 203 204shift $(expr $OPTIND - 1) 205 206if $pflag && $nflag 207then 208 echo "$PROG: -n flag and -p flag may not be used together" 1>&2 209 usage 210fi 211 212if [ -n "$oarg" ]; then 213 exec > $oarg 214fi 215 216trap "rm -f $syscalldump" 0 1 2 3 15 217 218header 219 220echo "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump 221 222for syscall; do 223 fnname=${syscall%.S} 224 if $pflag; then 225 scname=${fnname#_} 226 else 227 scname=$fnname 228 fi 229 syscall_stub $syscalldump $scname $fnname 230 echo "" 231done 232 233trailer 234 235exit 0 236