1#!/bin/sh - 2# $NetBSD: makelintstub,v 1.6 2000/06/14 06:49:10 cgd 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 syscalldump="$1" 75 syscallname="$2" 76 funcname="$3" 77 78 arglist="` 79 sed -e 'ta 80 :a 81 s,^/\* syscall: "'"$syscallname"'" ,, 82 tb 83 d 84 :b 85 s, \*/$,,' $syscalldump 86 `" 87 88 eval set -f -- "$arglist" 89 90 if [ $# -lt 3 ]; then 91 echo syscall $syscallname not found! 1>&2 92 exit 1 93 fi 94 95 shift # kill "ret:" 96 returntype=$1; shift 97 shift # kill "args:" 98 99 cat <<- __EOF__ 100 /*ARGSUSED*/ 101 $returntype 102 __EOF__ 103 104 # do ANSI C function header 105 echo "#ifdef __STDC__" 106 107 echo -n "$funcname(" 108 first=yes; i=1 109 for arg; do 110 if [ $first = yes ]; then 111 first=no 112 else 113 echo -n ", " 114 fi 115 case "$arg" in 116 "...") echo -n "...";; 117 *) echo -n "$arg arg$i"; i=$(($i + 1));; 118 esac 119 done 120 echo ")" 121 122 # do K&R C function header 123 echo "#else" 124 125 echo -n "$funcname(" 126 first=yes; i=1 127 for arg; do 128 if [ $first = yes ]; then 129 first=no 130 else 131 echo -n ", " 132 fi 133 case "$arg" in 134 "...") echo -n "va_alist";; 135 *) echo -n "arg$i"; i=$(($i + 1));; 136 esac 137 done 138 echo ")" 139 i=1 140 for arg; do 141 case "$arg" in 142 "...") echo " va_dcl";; 143 *) echo " $arg arg$i;"; i=$(($i + 1));; 144 esac 145 done 146 147 # do function body 148 echo "#endif" 149 150 echo "{" 151 if [ "$returntype" != "void" ]; then 152 echo " return (($returntype)0);" 153 fi 154 echo "}" 155} 156 157trailer() 158{ 159 160 cat <<- __EOF__ 161 /* END */ 162 __EOF__ 163} 164 165set -- `getopt no:ps: $*` 166 167pflag=NO 168nflag=NO 169oarg="" 170syscallhdr=/usr/include/sys/syscall.h 171syscalldump=/tmp/makelintstub.$$ 172 173if test $? -ne 0; then 174 usage 175fi 176for i; do 177 case "$i" in 178 -n) nflag=YES; shift;; 179 -o) oarg=$2; shift; shift;; 180 -p) pflag=YES; shift;; 181 -s) syscallhdr=$2; shift; shift;; 182 --) shift; break;; 183 esac 184done 185 186if [ $pflag = YES ] && [ $nflag = YES ]; then 187 echo "$0: -n flag and -p flag may not be used together" 188 echo "" 189 usage 190fi 191 192if [ "X$oarg" != "X" ]; then 193 exec > $oarg 194fi 195 196trap "rm -f $syscalldump" 0 1 2 15 197 198header 199printf '#include "'"$syscallhdr"'"' | cpp -C >$syscalldump 200for syscall; do 201 fnname=${syscall%.o} 202 if [ $pflag = YES ]; then 203 scname=${fnname#_} 204 else 205 scname=$fnname 206 fi 207 syscall_stub $syscalldump $scname $fnname 208 echo "" 209done 210trailer 211 212exit 0 213