preserve
上传用户:dgyhgb
上传日期:2007-01-07
资源大小:676k
文件大小:2k
- #! /bin/sh
- # preserve: tool to resolve abscence of external tools
- #
- # This file is part of GNU SQL Server
- #
- # processing of preserved files
- # usage: preserve save/restore case file
- # where case is :
- # --bison
- # --flex
- # --rpcgen [incdir]
- # --custom="extension list_of_derivative_extensions"
- #
- # Contacts: gss@ispras.ru
- #
- #set -xv
- if [ $1 = save ] ; then
- preserve=yes
- else
- preserve=no
- fi
- fn=$3
- case "$2" in
- --bison)
- extension="y"
- subst_list=".c .h"
- ;;
- --flex)
- extension="l"
- subst_list=".c"
- ;;
- --rpcgen)
- extension="x"
- subst_list=".h _svc.c _clnt.c _xdr.c"
- if [ $preserve = 'no' ]; then ## simulate rpcgen
- incdir=$fn
- fn=$4
- fi
- ;;
- --custom=*)
- set `echo $2 | sed 's/--custom=//g'`
- extension=$1; shift; subst_list=$*
- ;;
- *)
- echo preserve: incorrect parameters
- exit 1
- ;;
- esac
- fn_root=`echo $fn | sed "s/[.]${extension}//g"`
- for tail in $subst_list ; do
- cfn=${fn_root}${tail}
- if [ $preserve = 'no' ] ; then
- ## file.preserve has to be in distribution
- if [ ! -f ${cfn}.preserve ] ; then
- echo "cant find file $cfn"
- exit 1
- fi
- cp -p ${cfn}.preserve ${cfn}
- if [ $extension = "x" -a $tail = ".h" ] ; then ## rpcgen header
- `echo $0 | sed 's/preserve$/move-if-change/1'` mv ${cfn} ${incdir}/${cfn}
- fi
- else # let's preserve file
- if [ -f ${cfn}.preserve -a `ls -t ${cfn}.preserve ${fn} | head -1` = ${cfn}.preserve ]; then
- echo "$cfn has already preserved"
- elif [ -f ${cfn} ] ; then
- cat ${cfn} | sed 's/#line.*$//g' > ${cfn}.preserve
- if [ $extension = "l" ] ; then
- echo "int yywrap() { return 1; }" >>${cfn}.preserve
- fi
- elif [ $extension = "x" -a $tail = ".h" ] ; then
- ## it's possible in the case of rpcgen generated header file
- fn_only=`echo $fn_root | sed "s/[^/]*[/]//g"`
- cat `find . -name ${fn_only}${tail} -print | head -1` | sed "s/#line.*$//g" >${cfn}.preserve
- else
- echo "can't preserve file $cfn"
- fi
- fi
- done