make minix lwip make explicit use of 'int'
[minix3.git] / kernel / extract-mfield.sh
bloba84ba8f561fad3226e01bd2dd14e4752a48e8d65
1 #!/bin/sh
3 set -e
5 find_files_and_lines()
7 find ../lib/libc/sys-minix ../lib/libsys -name '*.c' | \
8 xargs egrep -n '((_syscall|_taskcall)\([^,][^,]*,[ ]*|_kernel_call\()[A-Z_][A-Z0-9_]*,[ ]*&m\)' | \
9 cut -d: -f1,2
12 # grep message fields
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`
19 path="`echo $f | cut -d: -f1`"
20 linecall="`echo $f | cut -d: -f2`"
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"
29 # extract call name
30 callname=`head -n "$linecall" "$path" | tail -n 1 | sed 's/.*[ (,]\([A-Z_][A-Z0-9_]*\),[ ]*&m).*/\1/'`
32 # extract message fields
33 linelast="`expr "$linecall" - 1`"
34 linecount="`expr "$linelast" - "$linemsg"`"
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)/'
42 pathprev="$path"
43 linemsgprev="$linemsg"
44 done
45 ) | sort | uniq