The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

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