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 # Files to find.
     31 file_find='asm/*.h linux/*.h scsi/*.h'
     32 
     33 # Files to stop.
     34 file_stop='asm/byteorder.h linux/config.h linux/pci.h linux/xd.h'
     35 
     36 # Defs to find.
     37 # Work on the kernel source to convert all to df_iowr.
     38 # Don't know how to find low-numbered ioctls in linux/mc146818rtc.h.
     39 df_name='^[	 ]*#[	 ]*define[	 ]+[A-Z_][A-Z0-9_]*[	 ]+'
     40 df_iowr='_IO|_IOR|_IOW|_IOWR'
     41 df_NNNN='0[Xx](03|06|22|46|4B|4C|53|54|56|89|90)[0-9A-Fa-f][0-9A-Fa-f]'
     42 df_4359='0[Xx]4359[0-9A-Fa-f][0-9A-Fa-f]'	# linux/cyclades.h
     43 df_470N='470[0-9]'				# linux/fs.h        (only in 1.2.13)
     44 df_smix='MIXER_READ|MIXER_WRITE'		# linux/soundcard.h
     45 df_12NN='12[3-4][0-9]'				# linux/umsdos_fs.h (only in 1.2.13)
     46 df_tail='([()	 ]|$)'
     47 def_find="$df_name($df_iowr|$df_NNNN|$df_4359|$df_470N|$df_smix|$df_12NN)$df_tail"
     48 
     49 # Defs to stop.
     50 ds_tail='_MAGIC|_PATCH'
     51 ds_fdmp='FD(DEF|GET|SET)MEDIAPRM'		# linux/fd.h aliases (only in 1.2.13)
     52 ds_mtio='MTIOC(GET|SET)CONFIG'			# linux/mtio.h needs config (only in 1.2.13)
     53 def_stop="$ds_tail|$ds_fdmp|$ds_mtio"
     54 
     55 # Validate arg count.
     56 if [ $# -ne 1 ]
     57 then
     58 	echo "usage: $0 include-directory" >&2
     59 	exit 1
     60 fi
     61 
     62 # Grep through the files.
     63 (
     64 	# Construct list: find files minus stop files.
     65 	cd $1 || exit
     66 	file_list=`(ls $file_find $file_stop $file_stop 2>/dev/null) | sort | uniq -u`
     67 
     68 	# Grep matching #define lines.
     69 	# Transform to C structure form.
     70 	# Filter out stop list.
     71 	egrep "$def_find" $file_list |
     72 		sed -n -e 's/^\(.*\):#[	 ]*define[	 ]*\([A-Z_][A-Z0-9_]*\).*$/	{ "\1",	"\2",	\2	},/p' |
     73 		egrep -v "$def_stop"
     74 ) > ioctlent.tmp
     75 
     76 # Generate the output file.
     77 echo '/* This file is automatically generated by ioctlent.sh */'
     78 echo
     79 echo '#include <sys/types.h>'
     80 echo
     81 echo '/* Needed for <linux/baycom.h> */'
     82 echo '#define BAYCOM_DEBUG'
     83 echo
     84 echo '/* Needed for <linux/cyclades.h> */'
     85 echo '#include <linux/termios.h>'
     86 echo '#include <linux/tqueue.h>'
     87 echo
     88 awk '{ print "#include <" substr($2, 2, length($2) - 3) ">" }' ioctlent.tmp | sort -u
     89 echo
     90 echo 'struct ioctlent ioctlent [] ='
     91 echo '{'
     92 cat ioctlent.tmp
     93 echo '};'
     94 
     95 # Clean up.
     96 rm -f ioctlent.tmp
     97