The R Project SVN R

Rev

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

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