| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | #!/usr/bin/env bash# Script to check for errno strings in errnostr.inc # compared to constant values in errno.inctemps="check_errnostr_list.sh testerrnostr* errnostrlst.inc"if [ "$1" == "clean" ] ; then  echo Removing $temps  rm -f $temps  exitfi# Use gsed if presentSED=`which gsed`if [ "$SED" == "" ] ; then  SED=sedfi$SED -n "s:ESysE\(.*\)[[:space:]]*=[[:space:]]*\([[:space:]0-9]*\);: test_errnostr E\1 \2 :p" errno.inc | \  $SED "s:':'':g" > check_errnostr_list.sh if [ "$1" == "verbose" ] ; then  verbose=1  fpcopt=-glelse  verbose=0  fpcopt=fi# Reverse 'error string', { ENUMBER }# to ENUMBER string $SED -n -e "s|[^']*\('.*'\)[[:space:]]*,*[[:space:]]*{[[:space:]]*\(E[A-Za-z_0-9]*\).*|(Number : ESys\2; NumberStr : '\2'; Str : \1),|p" errnostr.inc > errnostrlst.inc# Use temp directory to avoid# re-compilation of system unitmkdir .testtmpcd .testtmp# Free Pascal source including# errnostr.inc file# to test if strings are correctcat > testerrnostr.pp <<EOFuses  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.EOFfpc $fpcopt  -Fi.. -o../testerrnostr ./testerrnostr.ppres=$?cd ..if [ $res -ne 0 ] ; then  echo "Compilation of testerrnostr.pp failed"  exitelse  rm -Rf .testtmpfiexport verbosefunction 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
 |