The R Project SVN R

Rev

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

Rev 47522 Rev 47774
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: 47522 $'
5
revision='$Rev: 47774 $'
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 Solarix, for example
39
## by the default grep on Solarix, 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
## <= 2.2.x was pattern='(^Number of.*:|^Time |^Loading required package.*'
-
 
53
pattern='(^Time |^Loading required package.*|^Package [A-Za-z][A-Za-z0-9]+ loaded'
52
pattern='(^Time |^Loading required package.*|^Package [A-Za-z][A-Za-z0-9]+ loaded|^<(environment|promise|pointer): )'
54
case "${ffile}" in
-
 
55
  *primitive-funs*)
-
 
56
    pattern=${pattern}'|^\[1\] [19][0-9][0-9])'
-
 
57
    ;;
-
 
58
  *)
-
 
59
    pattern=${pattern}'|^<(environment|promise|pointer): )'
-
 
60
    ;;
-
 
61
esac
-
 
62
 
53
 
63
if test ${ffile} = '-' ; then
54
if test ${ffile} = '-' ; then
64
  ffile=''
55
  ffile=''
65
  bfile=''
56
  bfile=''
66
else
57
else
67
  if test -f ${ffile} ; then
58
  if test -f ${ffile} ; then
68
      bfile=`basename "${ffile}"`
59
      bfile=`basename "${ffile}"`
69
  else
60
  else
70
      echo "no valid file ${ffile}"
61
      echo "no valid file ${ffile}"
71
      exit 1
62
      exit 1
72
  fi
63
  fi
73
fi
64
fi
74
 
65
 
75
tmpfile=${TMPDIR-/tmp}/${bfile}-d.${$}
66
tmpfile=${TMPDIR-/tmp}/${bfile}-d.${$}
76
 
67
 
77
${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}
78
## some packages ship .Rout.save with CRLF endings
69
## some packages ship .Rout.save with CRLF endings
79
(tr -d '\r' <  ${tfile} | ${SED} -e "${scriptold}" -e "${scriptnew}" -e "${s1}" -e "${s2}" | \
70
(tr -d '\r' <  ${tfile} | ${SED} -e "${scriptold}" -e "${scriptnew}" -e "${s1}" -e "${s2}" | \
80
  ${EGREP} -v "${pattern}" | \
71
  ${EGREP} -v "${pattern}" | \
81
  diff -bw ${tmpfile} - ) && exitstatus=0
72
  diff -bw ${tmpfile} - ) && exitstatus=0
82
 
73
 
83
rm -f ${tmpfile}
74
rm -f ${tmpfile}
84
 
75
 
85
exit ${exitstatus}
76
exit ${exitstatus}