From 9106753b8ab9e12614694b3347d2496b4348a807 Mon Sep 17 00:00:00 2001 From: pierre Date: Thu, 19 Apr 2012 07:18:13 +0000 Subject: [PATCH] Improve check_sys.sh script git-svn-id: trunk@20926 - --- rtl/unix/scripts/check_sys.sh | 79 +++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 7 deletions(-) diff --git a/rtl/unix/scripts/check_sys.sh b/rtl/unix/scripts/check_sys.sh index 45c4f041ff..18b21c91cd 100755 --- a/rtl/unix/scripts/check_sys.sh +++ b/rtl/unix/scripts/check_sys.sh @@ -7,6 +7,14 @@ syscall_header=/usr/include/syscall.h fpc_sysnr=./sysnr.inc +os=`uname -s` + +if [ "$os" == "OpenBSD" ] ; then + c_syscall_header=sys/syscall.h +else + c_syscall_header=syscall.h +fi + if ! [ -f $fpc_sysnr ] ; then cpu=`fpc -iTP` fpc_sysnr=./$cpu/sysnr.inc @@ -18,7 +26,7 @@ os=`uname -s` # Test C file to grab all loaded headers cat > test-syscall.c < +#include <${c_syscall_header}> int main () @@ -37,6 +45,11 @@ fi # Use gcc with --save-temps option to create .i file $CC --save-temps -o test-syscall ./test-syscall.c +res=$? +if [ $res -ne 0 ] ; then + echo "Call to $CC failed" + exit +fi # list of errno.h headers listed syscall_headers=` sed -n "s:.*\"\(.*/.*\.h\)\".*:\1:p" test-syscall.i |sort | uniq` echo "Headers found are \"$syscall_headers\"" @@ -45,9 +58,6 @@ if [ "$syscall_headers" != "" ] ; then syscall_header="$syscall_headers" fi - -# Sustitution made to pass from fpc syscall number -# to system define fpc_syscall_prefix=syscall_nr_ if [ "$os" == "Linux" ] ; then # On Linux system, system call number are defined indirectly @@ -61,11 +71,27 @@ fi # You should only need to change the variables above sed -n "s:^[ \t]*${fpc_syscall_prefix}\\([_a-zA-Z0-9]*\\)[ \t]*=[ \t]*\\([0-9]*\\).*:check_syscall_number ${syscall_prefix}\1 \2:p" ${fpc_sysnr} > check_sys_list.sh +sed -n "s:^.*define[[:space:]]*${syscall_prefix}\\([_a-zA-Z0-9]*\\)[[:space:]]*\\([0-9]*\\).*:check_syscall_number_reverse ${fpc_syscall_prefix}\1 \2:p" ${syscall_header} > check_sys_list_reverse.sh + function check_syscall_number () { sys=$1 value=$2 + obsolete=0 + if [[ "$value" =~ ^[0-9]+$ ]] ; then + eval $sys=\$$value + if [ $verbose -ne 0 ] ; then + echo "$sys is $value" + fi + else + eval $sys=$value + if [ $verbose -ne 0 ] ; then + echo "$sys set to \"${$sys}\" trough \"$value\"" + fi + fi + # Remember this value for later + eval $sys=$value if [ $verbose -ne 0 ] ; then echo Testing $sys value $value fi @@ -82,18 +108,57 @@ function check_syscall_number () if [ "${val}" == "" ] ; then found=`sed -n "/#define.*[^A-Za-z0-9_]${value}$/p" ${syscall_header}` if [ "${found}" == "" ] ; then - found=`sed -n "s:\/\* ${value} is compa: ${value} is compa:p" ${syscall_header}` + found=`sed -n "s:\/\* ${value} is compa:/* ${value} is compa:p" ${syscall_header}` + if [ "$found" != "" ] ; then + obsolete=1 + fi fi fi if [ "$found" == "" ] ; then found=`grep -n -w $value ${syscall_header}` fi - echo problem for ${sys} expected ${value}, line is \"${found}\", val found is \"${val}\" + if [ $obsolete -eq 1 ] ; then + echo Warning: ${sys} expected ${value}, is obsolete line is \"${found}\" + else + echo Problem: ${sys} expected ${value}, line is \"${found}\", val found is \"${val}\" + fi fi } +function check_syscall_number_reverse () +{ + sys=$1 + value=$2 + if [ $verbose -ne 0 ] ; then + echo Testing syscall header entry $sys value $value + fi + found=`sed -n "/.*${sys}/p" ${fpc_sysnr}` + val=`sed -n "s:.*${sys}[ \t]*=[ \t]*\([0-9]*\).*:\1:p" ${fpc_sysnr}` + if [ $verbose -ne 0 ] ; then + echo Test for $sys found \"${found}\" \"${value}\" \"${val}\" + fi + if [ "${val}" == "${value}" ] ; then + if [ $verbose -ne 0 ] ; then + echo ${sys} value ${val} is correct + fi + else + if [ "${val}" == "" ] ; then + found=`sed -n "/#define.*[^A-Za-z0-9_]${value}$/p" ${syscall_header}` + if [ "${found}" == "" ] ; then + found=`sed -n "s:\/\* ${value} is compa: ${value} is compa:p" ${syscall_header}` + fi + fi + echo Problem: ${sys} expected ${value}, line is \"${found}\", val found is \"${val}\" + fi +} + + +# Sustitution made to pass from fpc syscall number +# to system define set -f -echo "Checking in ${syscall_header}" +echo "Checking values from \"${fpc_sysnr}\" in \"${syscall_header}\"" source ./check_sys_list.sh +echo "Checking if values in \"${syscall_header}\" are missing in \"${fpc_sysnr}\"" +source ./check_sys_list_reverse.sh