Browse Source

Add a C compilation phase to check Error value

git-svn-id: trunk@21826 -
pierre 13 years ago
parent
commit
2d6093645f
1 changed files with 90 additions and 17 deletions
  1. 90 17
      rtl/unix/scripts/check_errno.sh

+ 90 - 17
rtl/unix/scripts/check_errno.sh

@@ -21,10 +21,24 @@ else
   verbose=0
   verbose=0
 fi
 fi
 
 
+if [ "$1" == "addall" ] ; then
+  addall=1
+  echo "Adding all entries to errno-new.inc"
+  shift
+else
+  addall=0
+fi
+
 # Location of error number in system header
 # Location of error number in system header
 
 
-errno_header="/usr/include/asm-generic/errno-base.h /usr/include/asm-generic/errno.h"
-errno_include=./errno.inc
+errno_headers="/usr/include/asm-generic/errno-base.h /usr/include/asm-generic/errno.h"
+
+if [ "$1" != "" ] ; then
+  errno_include=$1
+  echo "Using $errno_include file"
+else
+  errno_include=./errno.inc
+fi
 
 
 # Sustitution made to pass from fpc syscall number
 # Sustitution made to pass from fpc syscall number
 # to system define 
 # to system define 
@@ -53,18 +67,53 @@ fi
 # Use gcc with --save-temps option to create .i file
 # Use gcc with --save-temps option to create .i file
 $CC --save-temps -c ./test-errno.c
 $CC --save-temps -c ./test-errno.c
 # list of errno.h headers listed
 # list of errno.h headers listed
-errno_headers=` sed -n "s:.*\"\(.*\.h\)\".*:\1:p" test-errno.i |sort | uniq`
-echo "Headers found are \"$errno_headers\""
+errno_headers_CC=` sed -n "s:.*\"\(.*\.h\)\".*:\1:p" test-errno.i |sort | uniq`
+echo "Headers found are \"$errno_headers_CC\""
 
 
-if [ "$errno_headers" != "" ] ; then
-  errno_header="$errno_headers"
+if [ "$errno_headers_CC" != "" ] ; then
+  errno_headers="$errno_headers_CC"
 fi
 fi
 
 
 
 
 # You should only need to change the variables above
 # You should only need to change the variables above
 
 
 sed -n "s:^[[:space:]]*${fpc_errno_prefix}\\([_a-zA-Z0-9]*\\)[[:space:]]*=[[:space:]]*\\([0-9][0-9]*\\).*:check_errno_number ${errno_prefix}\1 \2:p" ${errno_include} > check_errno_list.sh
 sed -n "s:^[[:space:]]*${fpc_errno_prefix}\\([_a-zA-Z0-9]*\\)[[:space:]]*=[[:space:]]*\\([0-9][0-9]*\\).*:check_errno_number ${errno_prefix}\1 \2:p" ${errno_include} > check_errno_list.sh
-sed -n "s:#define[[:space:]]*${errno_prefix}\\([_a-zA-Z0-9]*\\)[[:space:]][[:space:]]*\\(-*[0-9A-Za-z_]*\\)[[:space:]]*\(.*\):check_reverse_errno_number ${fpc_errno_prefix}\1 \2 \"\3\":p" ${errno_header} > check_reverse_errno_list.sh
+sed -n "s:#define[[:space:]]*${errno_prefix}\\([_a-zA-Z0-9]*\\)[[:space:]][[:space:]]*\\(-*[0-9A-Za-z_]*\\)[[:space:]]*\(.*\):check_reverse_errno_number ${fpc_errno_prefix}\1 \2 \"\3\":p" ${errno_headers} > check_reverse_errno_list.sh
+
+function rpad {
+  word="$1"
+  while [ ${#word} -lt $2 ]; do
+    word="$word$3";
+  done;
+  echo "$word";
+}
+
+function compile_errno ()
+{
+  errname=$1
+  errvalue=$2
+# Test C file to grab all loaded headers
+cat > test-errno.c <<EOF
+#include <errno.h>
+#include <stdio.h>
+
+int
+main ()
+{
+  printf ("$errname=%d\n",$errname);
+  return 0;
+}
+EOF
+$CC -o ./test-errno ./test-errno.c
+compiledvalue=`./test-errno`
+if [ "$compiledvalue" == "$errname=$errvalue" ] ; then
+  if [ $verbose -ne 0 ]; then
+    echo "GCC reports $compiledvalue OK"
+  fi
+else
+  echo "GCC reports $compiledvalue, but $errvalue is expected"
+fi
+}
 
 
 function check_errno_number ()
 function check_errno_number ()
 {
 {
@@ -75,10 +124,11 @@ function check_errno_number ()
   fi
   fi
   # Remember value of this constant
   # Remember value of this constant
   eval ${sys}=${value}
   eval ${sys}=${value}
+  compile_errno $sys $value
 
 
-  found=`sed -n "/#define[[:space:]][[:space:]]*${sys}[^A-Za-z0-9_]/p" ${errno_header}`
-  val=`sed -n "s:#define[[:space:]][[:space:]]*${sys}[^A-Za-z0-9_][^A-Za-z0-9_]*\([0-9]*\).*:\1:p" ${errno_header}`
-  extval=`sed -n "s:#define[[:space:]][[:space:]]*${sys}[^A-Za-z0-9_][^A-Za-z0-9_]*\([0-9A-Za-z_]*\).*:\1:p" ${errno_header}`
+  found=`sed -n "/#define[[:space:]][[:space:]]*${sys}[^A-Za-z0-9_]/p" ${errno_headers}`
+  val=`sed -n "s:#define[[:space:]][[:space:]]*${sys}[^A-Za-z0-9_][^A-Za-z0-9_]*\([0-9]*\).*:\1:p" ${errno_headers}`
+  extval=`sed -n "s:#define[[:space:]][[:space:]]*${sys}[^A-Za-z0-9_][^A-Za-z0-9_]*\([0-9A-Za-z_]*\).*:\1:p" ${errno_headers}`
   if [ $verbose -ne 0 ] ; then
   if [ $verbose -ne 0 ] ; then
     echo Test for $sys found \"${found}\" \"${value}\" \"${val}\"
     echo Test for $sys found \"${found}\" \"${value}\" \"${val}\"
   fi
   fi
@@ -87,13 +137,16 @@ function check_errno_number ()
       echo ${sys} value ${val} is correct
       echo ${sys} value ${val} is correct
     fi
     fi
   else
   else
+    if [ $verbose -ne 0 ] ; then
+      echo "${sys} val=\"$val\", extval=\"$extval\""
+    fi
     if [ "${val}" == "" ] ; then
     if [ "${val}" == "" ] ; then
-      foundvalue=`sed -n "/#define.*[^A-Za-z0-9_]${value}$/p" ${errno_header}`
+      foundvalue=`sed -n "/#define.*[^A-Za-z0-9_]${value}$/p" ${errno_headers}`
       if [ "${foundvalue}" == "" ] ; then
       if [ "${foundvalue}" == "" ] ; then
-        foundvalue=`sed -n "s:\/\* ${value} is compa: ${value} is compa:p" ${errno_header}`
+        foundvalue=`sed -n "s:\/\* ${value} is compa: ${value} is compa:p" ${errno_headers}`
       fi
       fi
     fi
     fi
-    if [ "$extval" != "" ] ; then
+    if [ "$extval" != "$val" ] ; then
       eval indirectval=\$$extval
       eval indirectval=\$$extval
       echo "indirectval =\"$indirectval\" for \"$extval\""
       echo "indirectval =\"$indirectval\" for \"$extval\""
       if [ "$indirectval" != "$value" ] ; then
       if [ "$indirectval" != "$value" ] ; then
@@ -107,22 +160,42 @@ function check_errno_number ()
   fi
   fi
 }
 }
 
 
+function write_errno_new_head ()
+{
+  echo "{ File generated by $0" > $errnonew
+  uname_info=`uname -s -r -m`
+  echo " generated on \"$uname_info\" machine" >> $errnonew
+  echo "List of missing system error number found in" >> $errnonew
+  echo "$errno_headers" >> $errnonew
+  echo "}" >> $errnonew
+}
 
 
 function check_reverse_errno_number ()
 function check_reverse_errno_number ()
 {
 {
   errname=$1
   errname=$1
   errvalue=$2
   errvalue=$2
+  rpaderrname=$(rpad $errname 20 " ")
+  printf -v padd "%s = %4d" "$rpaderrname" $errvalue
+
   found=`grep -i -w $1 ${errno_include}`
   found=`grep -i -w $1 ${errno_include}`
   comment="$3"
   comment="$3"
-  comment=${comment##*\/\*}
-  comment=${comment%%*\*\/}
+  comment=${comment##\/\*}
+  comment=${comment%%\*\/}
   if [ "${found}" == "" ] ; then
   if [ "${found}" == "" ] ; then
     echo "Error ${errname}, value ${errvalue}, not in ${errno_include} file"
     echo "Error ${errname}, value ${errvalue}, not in ${errno_include} file"
     if [ $addtoerrno -eq 0 ] ; then
     if [ $addtoerrno -eq 0 ] ; then
       addtoerrno=1
       addtoerrno=1
-      echo "{ List of missing system error number found in $errno_header }" > $errnonew
+      write_errno_new_head
+    fi
+    echo "        $padd; { $comment }" >> $errnonew
+  else
+    if [ $addall -eq 1 ] ; then
+      if [ $addtoerrno -eq 0 ] ; then
+        addtoerrno=1
+        write_errno_new_head
+      fi
+      echo "        $padd; { $comment }" >> $errnonew
     fi
     fi
-    echo "        $errname = $errvalue; { $comment }" >> $errnonew
   fi
   fi
 }
 }