The R Project SVN R

Rev

Rev 46821 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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