makelintstub revision 1.3
1#!/bin/sh - 2# $NetBSD: makelintstub,v 1.3 1998/03/01 10:20:06 fvdl Exp $ 3# 4# Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 3. All advertising materials mentioning features or use of this software 15# must display the following acknowledgement: 16# This product includes software developed for the NetBSD Project 17# by Christopher G. Demetriou. 18# 4. The name of the author may not be used to endorse or promote products 19# derived from this software without specific prior written permission 20# 21# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32usage() 33{ 34 35 echo "usage: $0 [-n|-p] [-o filename] object ..." 36 exit 1 37} 38 39header() 40{ 41 42 cat <<- __EOF__ 43 /* 44 * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT. 45 */ 46 47 #include <sys/param.h> 48 #include <sys/time.h> 49 #include <sys/mount.h> 50 #include <sys/stat.h> 51 #include <ufs/ufs/dinode.h> 52 #include <ufs/lfs/lfs.h> 53 #include <sys/resource.h> 54 #include <sys/poll.h> 55 #include <sys/uio.h> 56 #include <sys/ipc.h> 57 #include <sys/msg.h> 58 #include <sys/sem.h> 59 #include <sys/shm.h> 60 #include <sys/timex.h> 61 #include <sys/socket.h> 62 #ifdef __STDC__ 63 #include <stdarg.h> 64 #else 65 #include <varargs.h> 66 #endif 67 68 __EOF__ 69} 70 71syscall_stub() 72{ 73 74 syscallhdr="$1" 75 syscallname="$2" 76 funcname="$3" 77 78 arglist="`printf '#include "'"$syscallhdr"'"' | cpp -C | \ 79 grep '^/\* syscall: "'"$syscallname"'" ' | \ 80 sed -e 's,^/\* syscall: ,,;s, \*/$,,'`" 81 82 eval set -f -- "$arglist" 83 84 if [ $# -lt 4 ]; then 85 echo syscall $syscallname not found! 1>&2 86 exit 1 87 fi 88 89 syscallname=$1 90 shift 2 # kill name and "ret:" 91 returntype=$1 92 shift 2 # kill return type and "args:" 93 94 cat <<- __EOF__ 95 /*ARGSUSED*/ 96 $returntype 97 __EOF__ 98 99 if [ "`eval echo -n \\$$#`" = "..." ]; then 100 varargs=YES 101 nargs=$(($# - 1)) 102 else 103 varargs=NO 104 nargs=$# 105 fi 106 nargswithva=$# 107 108 # do ANSI C function header 109 if [ $varargs = YES ]; then 110 echo "#ifdef __STDC__" 111 112 echo -n "$funcname(" 113 i=1 114 while [ $i -le $nargs ]; do 115 eval echo -n \""\$$i"\" 116 echo -n " arg$i" 117 if [ $i -lt $nargswithva ]; then 118 echo -n ", " 119 fi 120 i=$(($i + 1)) 121 done 122 if [ $varargs = YES ]; then 123 echo -n "..." 124 fi 125 echo ")" 126 127 # do K&R C function header 128 echo "#else" 129 fi 130 131 echo -n "$funcname(" 132 i=1 133 while [ $i -le $nargs ]; do 134 echo -n "arg$i" 135 if [ $i -lt $nargswithva ]; then 136 echo -n ", " 137 fi 138 i=$(($i + 1)) 139 done 140 if [ $varargs = YES ]; then 141 echo -n "va_alist" 142 fi 143 echo ")" 144 i=1 145 while [ $i -le $nargs ]; do 146 eval echo -n \"" \$$i"\" 147 echo " arg$i;" 148 i=$(($i + 1)) 149 done 150 if [ $varargs = YES ]; then 151 echo " va_dcl" 152 fi 153 154 # do function body 155 if [ $varargs = YES ]; then 156 echo "#endif" 157 fi 158 echo "{" 159 if [ "$returntype" != "void" ]; then 160 echo " return (($returntype)0);" 161 fi 162 echo "}" 163} 164 165trailer() 166{ 167 168 cat <<- __EOF__ 169 /* END */ 170 __EOF__ 171} 172 173set -- `getopt no:ps: $*` 174 175pflag=NO 176nflag=NO 177oarg="" 178syscallhdr=/usr/include/sys/syscall.h 179 180if test $? -ne 0; then 181 usage 182fi 183for i; do 184 case "$i" in 185 -n) nflag=YES; shift;; 186 -o) oarg=$2; shift; shift;; 187 -p) pflag=YES; shift;; 188 -s) syscallhdr=$2; shift; shift;; 189 --) shift; break;; 190 esac 191done 192 193if [ $pflag = YES ] && [ $nflag = YES ]; then 194 echo "$0: -n flag and -p flag may not be used together" 195 echo "" 196 usage 197fi 198 199if [ "X$oarg" != "X" ]; then 200 exec > $oarg 201fi 202 203header 204for syscall; do 205 fnname=`echo $syscall | sed -e 's,\.o$,,'` 206 if [ $pflag = YES ]; then 207 scname=`echo $fnname | sed -e 's,^_,,'` 208 else 209 scname=$fnname 210 fi 211 syscall_stub $syscallhdr $scname $fnname 212 echo "" 213done 214trailer 215 216exit 0 217