xref: /minix/minix/kernel/extract-mfield.sh (revision 433d6423)
1#!/bin/sh
2
3set -e
4
5find_files_and_lines()
6(
7	find  ../lib/libc/sys ../lib/libsys -name '*.c' | \
8	xargs egrep -n '((_syscall|_taskcall)\([^,][^,]*,[ 	]*|_kernel_call\()[A-Z_][A-Z0-9_]*,[ 	]*&m\)' | \
9	cut -d: -f1,2
10)
11
12# grep message fields
13(
14	# find references to _syscall, _taskcall and _kernel_call in the libraries
15	pathprev=
16	linecallprev=0
17	for f in `find_files_and_lines`
18	do
19		path="`echo $f | cut -d: -f1`"
20		linecall="`echo $f | cut -d: -f2`"
21
22		# find the matching message declaration; we can identify fields between message decl and call
23		linemsg=`head -n "$linecall" "$path" | egrep -n 'message[ 	][ 	]*m;' | tail -n 1 | cut -d: -f1`
24		if [ "x$linemsg" != "x" ]
25		then
26			# watch out: message may be re-used; start from last call in this case
27			[ \( "x$path" != "x$pathprev" \) -o \( "$linemsg" -gt "$linecallprev" \) ] || linemsg="$linecallprev"
28
29			# extract call name
30			callname=`head -n "$linecall" "$path" | tail -n 1 | sed 's/.*[ 	(,]\([A-Z_][A-Z0-9_]*\),[ 	]*&m).*/\1/'`
31
32			# extract message fields
33			linelast="`expr "$linecall" - 1`"
34			linecount="`expr "$linelast" - "$linemsg"`"
35
36			head -n "$linelast" "$path" | \
37			tail -n "$linecount" | \
38			tr ' \t' ' ' | \
39			egrep '^ *m\.[A-Za-z_][A-Za-z0-9_]* *=' | \
40			sed 's/^ *m\.\([A-Za-z_][A-Za-z0-9_]*\) *=.*/IDENT('$callname', \1)/'
41		fi
42		pathprev="$path"
43		linemsgprev="$linemsg"
44	done
45) | sort | uniq
46