The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11358 hornik 1
#! /bin/sh
11515 hornik 2
##
45264 ripley 3
## Rdiff -- diff 'without R version'
11358 hornik 4
 
45264 ripley 5
## Copyright (C) 2000-2008 The R Core Development Team.
6
## This is free software; see the GNU General Public License version 2
7
## or later for copying conditions.  There is NO warranty.
8
 
22506 hornik 9
## Usage:
10
##   R CMD Rdiff from-file to-file exitstatus
11
## where from-file equal to '-' means STDIN
12
 
11358 hornik 13
ffile=${1}
14
tfile=${2}
8746 hornik 15
exitstatus=${3}
16
 
45264 ripley 17
## These are set in Renviron if run from R CMD
18
## 'grep -E' is POSIX, but not AT&T Unix, so not supported
19
## by the default grep on Solarix, for example
20
EGREP=${EGREP-egrep}
21
SED=${SED-sed}
22
 
37820 urbaneks 23
## sed scripts to get rid of the startup message
24
scriptold='/^R : Copyright /,/quit R.$/{d;}'
25
scriptnew='/^R version /,/quit R.$/{d;}'
45264 ripley 26
 
27
## turn UTF-8 directional single quotes into ASCII quote
40768 ripley 28
s1="s/‘/'/g"
29
s2="s/’/'/g"
37742 leisch 30
 
37490 maechler 31
## egrep pattern to get rid of some more
32
## <= 2.2.x was pattern='(^Number of.*:|^Time |^Loading required package.*'
39809 maechler 33
pattern='(^Time |^Loading required package.*|^Package [A-Za-z][A-Za-z0-9]+ loaded'
22506 hornik 34
case "${ffile}" in
35
  *primitive-funs*)
36
    pattern=${pattern}'|^\[1\] [19][0-9][0-9])'
37
    ;;
38
  *)
32355 maechler 39
    pattern=${pattern}'|^<(environment|promise|pointer): )'
22506 hornik 40
    ;;
32349 maechler 41
esac
8746 hornik 42
 
32349 maechler 43
if test ${ffile} = '-' ; then
11476 maechler 44
  ffile=''
32349 maechler 45
  bfile=''
46
else
47
  if test -f ${ffile} ; then
48
      bfile=`basename "${ffile}"`
49
  else
50
      echo "no valid file ${ffile}"
51
      exit 1
52
  fi
11476 maechler 53
fi
54
 
32349 maechler 55
tmpfile=${TMPDIR-/tmp}/${bfile}-d.${$}
56
 
45264 ripley 57
${SED} -e "${scriptold}" -e "${scriptnew}" -e "${s1}" -e "${s2}" ${ffile} | ${EGREP} -v "${pattern}" > ${tmpfile}
40768 ripley 58
## some packages ship .Rout.save with CRLF endings
45264 ripley 59
(tr -d '\r' <  ${tfile} | ${SED} -e "${scriptold}" -e "${scriptnew}" -e "${s1}" -e "${s2}" | \
22506 hornik 60
  ${EGREP} -v "${pattern}" | \
11358 hornik 61
  diff -bw ${tmpfile} - ) && exitstatus=0
62
 
8746 hornik 63
rm -f ${tmpfile}
11358 hornik 64
 
8746 hornik 65
exit ${exitstatus}