makelintstub revision 1.20
11.1Scgd#!/bin/sh - 21.20She# $NetBSD: makelintstub,v 1.20 2007/11/13 09:07:33 he Exp $ 31.1Scgd# 41.7Scgd# Copyright (c) 1996, 1997 Christopher G. Demetriou 51.7Scgd# All rights reserved. 61.7Scgd# 71.1Scgd# Redistribution and use in source and binary forms, with or without 81.1Scgd# modification, are permitted provided that the following conditions 91.1Scgd# are met: 101.1Scgd# 1. Redistributions of source code must retain the above copyright 111.1Scgd# notice, this list of conditions and the following disclaimer. 121.1Scgd# 2. Redistributions in binary form must reproduce the above copyright 131.1Scgd# notice, this list of conditions and the following disclaimer in the 141.1Scgd# documentation and/or other materials provided with the distribution. 151.1Scgd# 3. All advertising materials mentioning features or use of this software 161.1Scgd# must display the following acknowledgement: 171.7Scgd# This product includes software developed for the 181.14Ssalo# NetBSD Project. See http://www.NetBSD.org/ for 191.7Scgd# information about NetBSD. 201.1Scgd# 4. The name of the author may not be used to endorse or promote products 211.7Scgd# derived from this software without specific prior written permission. 221.7Scgd# 231.1Scgd# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 241.1Scgd# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 251.1Scgd# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 261.1Scgd# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 271.1Scgd# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 281.1Scgd# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 291.1Scgd# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 301.1Scgd# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 311.1Scgd# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 321.1Scgd# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 331.7Scgd# 341.7Scgd# <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> 351.1Scgd 361.2Sthorpejusage() 371.2Sthorpej{ 381.2Sthorpej 391.17Schristoscat << _EOF 1>&2 401.17SchristosUsage: $PROG [-n|-p] [-o filename] object ... 411.17Schristos The CPP environment variable must be set 421.17Schristos to the path to the C preprocessor. 431.17Schristos_EOF 441.1Scgd exit 1 451.2Sthorpej} 461.1Scgd 471.2Sthorpejheader() 481.2Sthorpej{ 491.1Scgd 501.2Sthorpej cat <<- __EOF__ 511.2Sthorpej /* 521.2Sthorpej * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT. 531.2Sthorpej */ 541.2Sthorpej 551.2Sthorpej #include <sys/param.h> 561.19Srmind #include <sys/aio.h> 571.2Sthorpej #include <sys/time.h> 581.2Sthorpej #include <sys/mount.h> 591.2Sthorpej #include <sys/stat.h> 601.3Sfvdl #include <ufs/ufs/dinode.h> 611.2Sthorpej #include <ufs/lfs/lfs.h> 621.2Sthorpej #include <sys/resource.h> 631.2Sthorpej #include <sys/poll.h> 641.2Sthorpej #include <sys/uio.h> 651.2Sthorpej #include <sys/ipc.h> 661.20She #include <sys/lwpctl.h> 671.19Srmind #include <sys/mqueue.h> 681.2Sthorpej #include <sys/msg.h> 691.2Sthorpej #include <sys/sem.h> 701.2Sthorpej #include <sys/shm.h> 711.2Sthorpej #include <sys/timex.h> 721.2Sthorpej #include <sys/socket.h> 731.10Sjdolecek #include <sys/event.h> 741.16Stsarna #include <sys/uuid.h> 751.2Sthorpej #ifdef __STDC__ 761.2Sthorpej #include <stdarg.h> 771.2Sthorpej #else 781.2Sthorpej #include <varargs.h> 791.2Sthorpej #endif 801.2Sthorpej 811.2Sthorpej __EOF__ 821.2Sthorpej} 831.2Sthorpej 841.2Sthorpejsyscall_stub() 851.2Sthorpej{ 861.2Sthorpej 871.4Smycroft syscalldump="$1" 881.2Sthorpej syscallname="$2" 891.2Sthorpej funcname="$3" 901.2Sthorpej 911.17Schristos arglist="$( 921.4Smycroft sed -e 'ta 931.4Smycroft :a 941.9Sthorpej s,^/\* syscall: \"'"$syscallname"'\" ,, 951.4Smycroft tb 961.4Smycroft d 971.4Smycroft :b 981.4Smycroft s, \*/$,,' $syscalldump 991.17Schristos )" 1001.2Sthorpej 1011.2Sthorpej eval set -f -- "$arglist" 1021.2Sthorpej 1031.4Smycroft if [ $# -lt 3 ]; then 1041.2Sthorpej echo syscall $syscallname not found! 1>&2 1051.2Sthorpej exit 1 1061.2Sthorpej fi 1071.1Scgd 1081.4Smycroft shift # kill "ret:" 1091.4Smycroft returntype=$1; shift 1101.4Smycroft shift # kill "args:" 1111.2Sthorpej 1121.2Sthorpej cat <<- __EOF__ 1131.2Sthorpej /*ARGSUSED*/ 1141.2Sthorpej $returntype 1151.2Sthorpej __EOF__ 1161.2Sthorpej 1171.2Sthorpej # do ANSI C function header 1181.5Smycroft echo "#ifdef __STDC__" 1191.2Sthorpej 1201.9Sthorpej echo "$funcname(" 1211.17Schristos first=true; i=1 1221.5Smycroft for arg; do 1231.17Schristos if $first; then 1241.17Schristos first=false 1251.5Smycroft else 1261.9Sthorpej echo ", " 1271.2Sthorpej fi 1281.5Smycroft case "$arg" in 1291.9Sthorpej "...") echo "...";; 1301.9Sthorpej *) echo "$arg arg$i"; i=$(($i + 1));; 1311.5Smycroft esac 1321.5Smycroft done 1331.17Schristos if $first; then 1341.9Sthorpej echo "void" 1351.9Sthorpej fi 1361.5Smycroft echo ")" 1371.1Scgd 1381.5Smycroft # do K&R C function header 1391.5Smycroft echo "#else" 1401.1Scgd 1411.9Sthorpej echo "$funcname(" 1421.17Schristos first=true; i=1 1431.5Smycroft for arg; do 1441.17Schristos if $first; then 1451.17Schristos first=false 1461.5Smycroft else 1471.9Sthorpej echo ", " 1481.2Sthorpej fi 1491.5Smycroft case "$arg" in 1501.9Sthorpej "...") echo "va_alist";; 1511.9Sthorpej *) echo "arg$i"; i=$(($i + 1));; 1521.5Smycroft esac 1531.2Sthorpej done 1541.2Sthorpej echo ")" 1551.2Sthorpej i=1 1561.5Smycroft for arg; do 1571.5Smycroft case "$arg" in 1581.5Smycroft "...") echo " va_dcl";; 1591.5Smycroft *) echo " $arg arg$i;"; i=$(($i + 1));; 1601.5Smycroft esac 1611.2Sthorpej done 1621.1Scgd 1631.2Sthorpej # do function body 1641.5Smycroft echo "#endif" 1651.5Smycroft 1661.2Sthorpej echo "{" 1671.2Sthorpej if [ "$returntype" != "void" ]; then 1681.2Sthorpej echo " return (($returntype)0);" 1691.2Sthorpej fi 1701.2Sthorpej echo "}" 1711.2Sthorpej} 1721.2Sthorpej 1731.2Sthorpejtrailer() 1741.2Sthorpej{ 1751.2Sthorpej 1761.2Sthorpej cat <<- __EOF__ 1771.2Sthorpej /* END */ 1781.2Sthorpej __EOF__ 1791.2Sthorpej} 1801.2Sthorpej 1811.2Sthorpej 1821.17Schristospflag=false 1831.17Schristosnflag=false 1841.2Sthorpejoarg="" 1851.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h 1861.4Smycroftsyscalldump=/tmp/makelintstub.$$ 1871.17SchristosPROG="$(basename "$0")" 1881.2Sthorpej 1891.17Schristosif [ -z "${CPP}" ]; then 1901.9Sthorpej usage 1911.9Sthorpejfi 1921.9Sthorpej 1931.17Schristoswhile getopts no:ps: i 1941.17Schristosdo 1951.2Sthorpej case "$i" in 1961.17Schristos n) nflag=true;; 1971.17Schristos o) oarg=$OPTARG;; 1981.17Schristos p) pflag=true;; 1991.17Schristos s) syscallhdr=$OPTARG;; 2001.17Schristos *) usage;; 2011.2Sthorpej esac 2021.1Scgddone 2031.1Scgd 2041.17Schristosshift $(expr $OPTIND - 1) 2051.17Schristos 2061.17Schristosif $pflag && $nflag 2071.17Schristosthen 2081.17Schristos echo "$PROG: -n flag and -p flag may not be used together" 1>&2 2091.2Sthorpej usage 2101.2Sthorpejfi 2111.2Sthorpej 2121.17Schristosif [ -n "$oarg" ]; then 2131.2Sthorpej exec > $oarg 2141.2Sthorpejfi 2151.2Sthorpej 2161.17Schristostrap "rm -f $syscalldump" 0 1 2 3 15 2171.4Smycroft 2181.2Sthorpejheader 2191.17Schristos 2201.17Schristosecho "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump 2211.17Schristos 2221.2Sthorpejfor syscall; do 2231.8Stv fnname=${syscall%.S} 2241.17Schristos if $pflag; then 2251.4Smycroft scname=${fnname#_} 2261.2Sthorpej else 2271.2Sthorpej scname=$fnname 2281.1Scgd fi 2291.4Smycroft syscall_stub $syscalldump $scname $fnname 2301.2Sthorpej echo "" 2311.1Scgddone 2321.17Schristos 2331.2Sthorpejtrailer 2341.1Scgd 2351.1Scgdexit 0 236