Jelajahi Sumber

+ New script to check errnostr.inc entries

git-svn-id: trunk@20933 -
pierre 13 tahun lalu
induk
melakukan
3f24548e58
2 mengubah file dengan 137 tambahan dan 0 penghapusan
  1. 1 0
      .gitattributes
  2. 136 0
      rtl/unix/scripts/check_errnostr.sh

+ 1 - 0
.gitattributes

@@ -8376,6 +8376,7 @@ rtl/unix/ports.pp svneol=native#text/plain
 rtl/unix/printer.pp svneol=native#text/plain
 rtl/unix/scripts/README svneol=native#text/plain
 rtl/unix/scripts/check_errno.sh svneol=native#text/plain
+rtl/unix/scripts/check_errnostr.sh svneol=native#text/plain
 rtl/unix/scripts/check_sys.sh svneol=native#text/plain
 rtl/unix/serial.pp svneol=native#text/plain
 rtl/unix/settimeo.inc svneol=native#text/plain

+ 136 - 0
rtl/unix/scripts/check_errnostr.sh

@@ -0,0 +1,136 @@
+#!/usr/bin/env bash
+
+# Script to check for errno strings in errnostr.inc 
+# compared to constant values in errno.inc
+
+temps="check_errnostr_list.sh testerrnostr* errnostrlst.inc"
+
+if [ "$1" == "clean" ] ; then
+  echo Removing $temps
+  rm -f $temps
+  exit
+fi
+
+gsed -n "s:ESysE\(.*\)[[:space:]]*=[[:space:]]*\([[:space:]0-9]*\);: test_errnostr E\1 \2 :p" errno.inc | \
+  gsed "s:':'':g" > check_errnostr_list.sh 
+
+if [ "$1" == "verbose" ] ; then
+  verbose=1
+  fpcopt=-gl
+else
+  verbose=0
+  fpcopt=
+fi
+
+# Reverse 'error string', { ENUMBER }
+# to ENUMBER string 
+gsed -n -e "s|[^']*\('.*'\)[[:space:]]*,*[[:space:]]*{[[:space:]]*\(E[A-Za-z_0-9]*\).*|(Number : ESys\2; NumberStr : '\2'; Str : \1),|p" errnostr.inc > errnostrlst.inc
+
+# Free Pascal source including
+# errnostr.inc file
+# to test if strings are correct
+cat > testerrnostr.pp <<EOF
+
+uses
+  Dos;
+
+{\$i errnostr.inc}
+{\$i errno.inc}
+
+type
+  TNumberString = record
+    Number : longint;
+    NumberStr : String;
+    Str : String;
+  end;
+
+const
+  ErrStringArray :
+   Array [0..sys_errn] of TNumberString= ( 
+   (Number :0; NumberStr : '0' ; str : ''),
+{\$i errnostrlst.inc}
+   (Number :-1; NumberStr : ''; str : ''));
+
+var
+  ErrorName : string;
+  value,i,j : longint;
+  verbose : boolean;
+  str : string;
+function Quote (s : string) : string;
+var
+  i : longint;
+begin
+  Quote:='';
+  for i:=1 to length(s) do
+    if (s[i]='''') then
+      Quote:=quote+''''''
+    else
+      Quote:=quote+s[i];
+end;
+
+begin
+  if (paramcount=1) and (paramstr(1)='--write') then
+    begin
+      for i:=0 to sys_errn-1 do
+        for j:=0 to sys_errn do
+          if (ErrStringArray[j].Number=i) then
+            with ErrStringArray[j] do 
+        writeln('  ''',Quote(Str), ''' { ',NumberStr, ' ',Number,' }');
+
+      exit;
+    end;
+  if paramcount < 3 then
+    begin
+      writeln('Usage: testerrnostr ENAME value "Comment"');
+      exit;
+    end;
+  val(paramstr(2),value);
+  if (value>=0) and (value<sys_errn) then
+    str:=sys_errlist[value] 
+  else
+    str:='';
+  verbose:=(GetEnv('verbose')<>'0');
+  while (pos('''',str)>0) do
+    delete(str,pos('''',str),1);
+  
+  if pos(str,paramstr(3))>0 then
+    begin
+      if verbose then
+        writeln('String for ',paramstr(1),' is "',str,'" contained in ',paramstr(3));
+    end
+  else if (value>=sys_errn) then
+    writeln('String for ',paramstr(1),' index ',value,'not in errnostr.inc, comment is ',paramstr(3))
+  else
+    begin
+      write('String for ',paramstr(1),' index ',value, ' is "',sys_errlist[value],'"');
+      writeln(', comment in errno.inc is ',paramstr(3));
+    end;
+end.
+EOF
+
+fpc $fpcopt ./testerrnostr.pp
+res=$?
+if [ $res -ne 0 ] ; then
+  echo "Compilation of testerrnostr.pp failed"
+  exit
+fi
+
+export verbose
+
+function test_errnostr ()
+{
+  if [ $verbose -eq 1 ] ; then
+    echo "Testing errno \"$1\""
+  fi
+  errno=$1
+  shift
+  value=$1
+  shift
+  comment="$@"
+  comment2=`grep $errno errnostrlst.inc`
+  ./testerrnostr $errno $value "$comment"
+}
+
+. ./check_errnostr_list.sh
+
+# ./testerrnostr --write