1#!/bin/sh 2# Copyright (c) 1993, 1994, 1995 Rick Sladkey <jrs@world.std.com> 3# All rights reserved. 4# 5# Copyright (c) 1995, 1996 Michael Elizabeth Chastain <mec@duracef.shout.net> 6# All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 3. The name of the author may not be used to endorse or promote products 17# derived from this software without specific prior written permission. 18# 19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29# 30# $Id: ioctlent.sh,v 1.1 1999/11/01 00:46:49 wichert Exp $ 31 32# Files to find. 33file_find='asm/*.h linux/*.h scsi/*.h' 34 35# Files to stop. 36file_stop='asm/byteorder.h linux/config.h linux/pci.h linux/xd.h' 37 38# Defs to find. 39# Work on the kernel source to convert all to df_iowr. 40# Don't know how to find low-numbered ioctls in linux/mc146818rtc.h. 41df_name='^[ ]*#[ ]*define[ ]+[A-Z_][A-Z0-9_]*[ ]+' 42df_iowr='_IO|_IOR|_IOW|_IOWR' 43df_NNNN='0[Xx](03|06|22|46|4B|4C|53|54|56|89|90)[0-9A-Fa-f][0-9A-Fa-f]' 44df_4359='0[Xx]4359[0-9A-Fa-f][0-9A-Fa-f]' # linux/cyclades.h 45df_470N='470[0-9]' # linux/fs.h (only in 1.2.13) 46df_smix='MIXER_READ|MIXER_WRITE' # linux/soundcard.h 47df_12NN='12[3-4][0-9]' # linux/umsdos_fs.h (only in 1.2.13) 48df_tail='([() ]|$)' 49def_find="$df_name($df_iowr|$df_NNNN|$df_4359|$df_470N|$df_smix|$df_12NN)$df_tail" 50 51# Defs to stop. 52ds_tail='_MAGIC|_PATCH' 53ds_fdmp='FD(DEF|GET|SET)MEDIAPRM' # linux/fd.h aliases (only in 1.2.13) 54ds_mtio='MTIOC(GET|SET)CONFIG' # linux/mtio.h needs config (only in 1.2.13) 55def_stop="$ds_tail|$ds_fdmp|$ds_mtio" 56 57# Validate arg count. 58if [ $# -ne 1 ] 59then 60 echo "usage: $0 include-directory" >&2 61 exit 1 62fi 63 64# Grep through the files. 65( 66 # Construct list: find files minus stop files. 67 cd $1 || exit 68 file_list=`(ls $file_find $file_stop $file_stop 2>/dev/null) | sort | uniq -u` 69 70 # Grep matching #define lines. 71 # Transform to C structure form. 72 # Filter out stop list. 73 egrep "$def_find" $file_list | 74 sed -n -e 's/^\(.*\):#[ ]*define[ ]*\([A-Z_][A-Z0-9_]*\).*$/ { "\1", "\2", \2 },/p' | 75 egrep -v "$def_stop" 76) > ioctlent.tmp 77 78# Generate the output file. 79echo '/* This file is automatically generated by ioctlent.sh */' 80echo 81echo '#include <sys/types.h>' 82echo 83echo '/* Needed for <linux/baycom.h> */' 84echo '#define BAYCOM_DEBUG' 85echo 86echo '/* Needed for <linux/cyclades.h> */' 87echo '#include <linux/termios.h>' 88echo '#include <linux/tqueue.h>' 89echo 90awk '{ print "#include <" substr($2, 2, length($2) - 3) ">" }' ioctlent.tmp | sort -u 91echo 92echo 'struct ioctlent ioctlent [] =' 93echo '{' 94cat ioctlent.tmp 95echo '};' 96 97# Clean up. 98rm -f ioctlent.tmp 99