rpcgen-sh
上传用户:dgyhgb
上传日期:2007-01-07
资源大小:676k
文件大小:3k
源码类别:

SQL Server

开发平台:

Unix_Linux

  1. #! /bin/sh
  2. #
  3. # prcgen-sh :  rpcgen workaround
  4. #           
  5. # This file is a part of GNU SQL Server
  6. #
  7. # Contacts: gss@ispras.ru
  8. #
  9. rpcgen=$1
  10. option=$2
  11. incdir=$3
  12. proto=$4
  13. # =======================================
  14. external_srcdir=no
  15. include_h_brakets=no
  16. # parse option
  17. for opt in $option ; do
  18.   case $opt in
  19.   Ihdr) # include additional comments
  20.     include_h_brakets=yes
  21.      ;;
  22.   *) ;;
  23.   esac
  24. done
  25. # ------------
  26. libdir=`echo $0 | tr '/' '|' | sed "s/|rpcgen-sh//g" | tr '|' '/' `
  27. fname=`echo $proto | tr '/' '|' | sed "s/.x//g;s/.*|//g" | tr '|' '/' `
  28. macro_fname=`echo $fname | tr '[a-z]' '[A-Z]' | tr '.' '_' | tr '-' '_' `
  29. if [ "x$incdir" = "x" ];  then
  30.   echo target directory name is empty
  31.   exit 1
  32. fi
  33. if [ "x$fname"  = "x" ]; then
  34.   echo empty protocol file name 
  35.   exit 1
  36. fi
  37. if [ ! -f $fname.x ]; then
  38.   cp $proto $fname.x
  39.   external_srcdir=yes
  40. fi
  41. echo "  rpcgen $fname.x --> $incdir/$fname.h"
  42. $1 $fname.x
  43. if [ "$external_srcdir" = "yes" ]; then
  44.   rm -f $fname.x
  45. fi
  46. tmpfile=__tmp__
  47. proto_h=$incdir/$fname.h
  48. [ -f $tmpfile ] || rm -f $tmpfile
  49. if [ "$include_h_brakets" = "yes" ]; then
  50.   echo "#ifndef _${macro_fname}_RPCGEN " >  $tmpfile
  51.   echo "#define _${macro_fname}_RPCGEN " >> $tmpfile
  52.   echo "                               " >> $tmpfile
  53.   echo "#ifndef  RPC_H_RPCGEN          " >> $tmpfile
  54.   echo "# define  RPC_H_RPCGEN         " >> $tmpfile
  55.   echo "                               " >> $tmpfile
  56.   echo '# include <rpc/rpc.h>          ' >> $tmpfile
  57.   echo "                               " >> $tmpfile
  58.   echo '# include "setup_os.h"         ' >> $tmpfile
  59.   echo '# if TIME_WITH_SYS_TIME        ' >> $tmpfile
  60.   echo '#  include <sys/time.h>        ' >> $tmpfile
  61.   echo '#  include <time.h>            ' >> $tmpfile
  62.   echo '# else                         ' >> $tmpfile
  63.   echo '#  if HAVE_SYS_TIME_H          ' >> $tmpfile
  64.   echo '#   include <sys/time.h>       ' >> $tmpfile
  65.   echo '#  else                        ' >> $tmpfile
  66.   echo '#   include <time.h>           ' >> $tmpfile
  67.   echo '#  endif                       ' >> $tmpfile
  68.   echo "# endif                        " >> $tmpfile
  69.   echo '#endif                         ' >> $tmpfile
  70.   echo "                               " >> $tmpfile
  71. fi
  72. cat $fname.h >>$tmpfile
  73. rm  $fname.h
  74. if [ "$include_h_brakets" = "yes" ]; then
  75.   echo "#endif /*_${macro_fname}_RPCGEN*/" >>$tmpfile
  76. fi
  77. if [ -f $proto_h ]; then
  78.    rm -f $proto_h
  79. fi
  80. $libdir/move-if-change mv $tmpfile $proto_h
  81. if [ "$include_h_brakets" = "yes" ]; then
  82.  # we have already added '#include <rpc/rpc.h>' and '...time.h'
  83.  # now we need to eliminate such includes from generated stubs
  84.  for stub in ${fname}_svc.c ${fname}_clnt.c ${fname}_xdr.c ; do
  85.    sed "s/^#include.*rpc[.]h>//g;s/^#include.*time[.]h>//g" ${stub} >$tmpfile
  86.    $libdir/move-if-change mv $tmpfile ${stub}
  87.  done
  88. fi