Home | History | Annotate | Download | only in mips
      1 #!/bin/sh
      2 # Copyright (c) 1993, 1994, 1995 Rick Sladkey <jrs (at] world.std.com>
      3 # All rights reserved.
      4 #
      5 # Copyright (c) 1995, 1996 Michael Elizabeth Chastain <mec (at] 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$
     31 
     32 # Files to find.
     33 file_find='asm/*.h linux/*.h scsi/*.h'
     34 
     35 # Files to stop.
     36 file_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.
     41 df_name='^[	 ]*#[	 ]*define[	 ]+[A-Z_][A-Z0-9_]*[	 ]+'
     42 df_iowr='_IO|_IOR|_IOW|_IOWR'
     43 df_NNNN='0[Xx](03|06|22|46|4B|4C|53|54|56|89|90)[0-9A-Fa-f][0-9A-Fa-f]'
     44 df_4359='0[Xx]4359[0-9A-Fa-f][0-9A-Fa-f]'	# linux/cyclades.h
     45 df_470N='470[0-9]'				# linux/fs.h        (only in 1.2.13)
     46 df_smix='MIXER_READ|MIXER_WRITE'		# linux/soundcard.h
     47 df_12NN='12[3-4][0-9]'				# linux/umsdos_fs.h (only in 1.2.13)
     48 df_tail='([()	 ]|$)'
     49 def_find="$df_name($df_iowr|$df_NNNN|$df_4359|$df_470N|$df_smix|$df_12NN)$df_tail"
     50 
     51 # Defs to stop.
     52 ds_tail='_MAGIC|_PATCH'
     53 ds_fdmp='FD(DEF|GET|SET)MEDIAPRM'		# linux/fd.h aliases (only in 1.2.13)
     54 ds_mtio='MTIOC(GET|SET)CONFIG'			# linux/mtio.h needs config (only in 1.2.13)
     55 def_stop="$ds_tail|$ds_fdmp|$ds_mtio"
     56 
     57 # Validate arg count.
     58 if [ $# -ne 1 ]
     59 then
     60 	echo "usage: $0 include-directory" >&2
     61 	exit 1
     62 fi
     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.
     79 echo '/* This file is automatically generated by ioctlent.sh */'
     80 echo
     81 echo '#include <sys/types.h>'
     82 echo
     83 echo '/* Needed for <linux/baycom.h> */'
     84 echo '#define BAYCOM_DEBUG'
     85 echo
     86 echo '/* Needed for <linux/cyclades.h> */'
     87 echo '#include <linux/termios.h>'
     88 echo '#include <linux/tqueue.h>'
     89 echo
     90 awk '{ print "#include <" substr($2, 2, length($2) - 3) ">" }' ioctlent.tmp | sort -u
     91 echo
     92 echo 'struct ioctlent ioctlent [] ='
     93 echo '{'
     94 cat ioctlent.tmp
     95 echo '};'
     96 
     97 # Clean up.
     98 rm -f ioctlent.tmp
     99