~ubuntu-branches/ubuntu/trusty/silo-llnl/trusty

« back to all changes in this revision

Viewing changes to tools/browser/silodiff

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2011-01-02 00:03:01 UTC
  • Revision ID: james.westby@ubuntu.com-20110102000301-9s2hfsjrkguz6h4r
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
 
4
# LLNL-CODE-425250.
 
5
# All rights reserved.
 
6
 
7
# This file is part of Silo. For details, see silo.llnl.gov.
 
8
 
9
# Redistribution and use in source and binary forms, with or without
 
10
# modification, are permitted provided that the following conditions
 
11
# are met:
 
12
 
13
#    * Redistributions of source code must retain the above copyright
 
14
#      notice, this list of conditions and the disclaimer below.
 
15
#    * Redistributions in binary form must reproduce the above copyright
 
16
#      notice, this list of conditions and the disclaimer (as noted
 
17
#      below) in the documentation and/or other materials provided with
 
18
#      the distribution.
 
19
#    * Neither the name of the LLNS/LLNL nor the names of its
 
20
#      contributors may be used to endorse or promote products derived
 
21
#      from this software without specific prior written permission.
 
22
 
23
# THIS SOFTWARE  IS PROVIDED BY  THE COPYRIGHT HOLDERS  AND CONTRIBUTORS
 
24
# "AS  IS" AND  ANY EXPRESS  OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT
 
25
# LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
26
# A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN  NO  EVENT SHALL  LAWRENCE
 
27
# LIVERMORE  NATIONAL SECURITY, LLC,  THE U.S.  DEPARTMENT OF  ENERGY OR
 
28
# CONTRIBUTORS BE LIABLE FOR  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
29
# EXEMPLARY, OR  CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT  LIMITED TO,
 
30
# PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS  OF USE,  DATA, OR
 
31
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
32
# LIABILITY, WHETHER  IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING
 
33
# NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT  OF THE USE  OF THIS
 
34
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
35
 
36
# This work was produced at Lawrence Livermore National Laboratory under
 
37
# Contract  No.   DE-AC52-07NA27344 with  the  DOE.  Neither the  United
 
38
# States Government  nor Lawrence  Livermore National Security,  LLC nor
 
39
# any of  their employees,  makes any warranty,  express or  implied, or
 
40
# assumes   any   liability   or   responsibility  for   the   accuracy,
 
41
# completeness, or usefulness of any information, apparatus, product, or
 
42
# process  disclosed, or  represents  that its  use  would not  infringe
 
43
# privately-owned   rights.  Any  reference   herein  to   any  specific
 
44
# commercial products,  process, or  services by trade  name, trademark,
 
45
# manufacturer or otherwise does not necessarily constitute or imply its
 
46
# endorsement,  recommendation,   or  favoring  by   the  United  States
 
47
# Government or Lawrence Livermore National Security, LLC. The views and
 
48
# opinions  of authors  expressed  herein do  not  necessarily state  or
 
49
# reflect those  of the United  States Government or  Lawrence Livermore
 
50
# National  Security, LLC,  and shall  not  be used  for advertising  or
 
51
# product endorsement purposes.
 
52
 
 
53
# ----------------------------------------------------------------------------
 
54
# Purpose: Difference two silo files and/or directories containing silo files 
 
55
#
 
56
# Programmer: Mark C. Miller
 
57
# Creation:   January 21, 2009
 
58
#
 
59
# Modifications:
 
60
#   Mark C. Miller, Wed Mar 11 10:03:10 PDT 2009
 
61
#   Added browserOptsDef and set lowlevel to 0. That is important when
 
62
#   diff'ing HDF5 files.
 
63
#
 
64
#   Mark C. Miller, Wed Dec  2 11:47:31 PST 2009
 
65
#   Added logic to use path to browser that is 'next to' silodiff or fall
 
66
#   back what a browser in path, but issue a warning if they are somehow
 
67
#   different.
 
68
#
 
69
#   Mark C. Miller, Fri Dec  4 09:58:17 PST 2009
 
70
#   Made it possible to override browser path warning
 
71
# ----------------------------------------------------------------------------
 
72
#
 
73
 
 
74
#
 
75
# Handle Command Line Arguments
 
76
#
 
77
tmpDir=$TMPDIR
 
78
if test -z "$tmpDir"; then
 
79
    if test -d /usr/tmp; then
 
80
       tmpDir=/usr/tmp
 
81
    elif test -d /tmp; then
 
82
       tmpDir=/tmp
 
83
    else
 
84
       tmpDir=`(cd ~; pwd -P)`
 
85
    fi
 
86
fi
 
87
optError=0
 
88
browserOptsDef="-l 0 -r"
 
89
browserOpts=""
 
90
arg1=
 
91
arg2=
 
92
recurse=0
 
93
verbose=0
 
94
override=0
 
95
for options
 
96
do
 
97
   case $1 in
 
98
      "")
 
99
         # handle empty argument
 
100
         ;;
 
101
      help|-help|--help)
 
102
         optError=1
 
103
         shift
 
104
         ;;
 
105
      -recurse|--recurse)
 
106
         recurse=1
 
107
         shift
 
108
         ;;
 
109
      -verbose|--verbose)
 
110
         verbose=1
 
111
         shift
 
112
         ;;
 
113
      -override-browser-warning|--override-browser-warning)
 
114
         override=1
 
115
         shift
 
116
         ;;
 
117
      *)
 
118
         if test -e $1; then
 
119
             if test -z "$arg1"; then
 
120
                 arg1=$1
 
121
             else
 
122
                 arg2=$1
 
123
             fi
 
124
         else
 
125
             browserOpts="$browserOpts $1"
 
126
         fi
 
127
         shift
 
128
         ;;
 
129
   esac
 
130
done
 
131
 
 
132
#
 
133
# Check path to browser and issue error/warning if necessary
 
134
#
 
135
brexe=browser
 
136
sddir=$(dirname $0)
 
137
if test -x ${sddir}/browser; then
 
138
    brexe=${sddir}/browser
 
139
else
 
140
    brdir=$(dirname $(which browser))
 
141
    if test $brdir != $sddir; then
 
142
        leader="*WARNING*"
 
143
        if test $override -eq 0; then
 
144
            leader="*ERROR*"
 
145
        fi
 
146
        echo "$leader"
 
147
        echo "$leader Using browser at \"$brdir\"."
 
148
        echo "$leader and silodiff at \"$sddir\"."
 
149
        echo "$leader"
 
150
        if test $override -eq 0; then
 
151
            echo "$leader Override with \"--override-browser-warning\" option."
 
152
            exit 1
 
153
        fi
 
154
    fi
 
155
fi
 
156
 
 
157
if test $optError = 1 -o -z "$arg1" -o -z "$arg2"; then
 
158
    echo "Usage:  $0 <file|dir> <file|dir> <options>"
 
159
    echo ""
 
160
    echo "Options:"
 
161
    echo "    -help:            print this help message"
 
162
    echo "    -recurse:         recurse on directories"
 
163
    echo "    -verbose:         report names of file(s) as they are processed."
 
164
    echo ""
 
165
    echo "If both arguments are files, $0 will attempt to diff the files."
 
166
    echo ""
 
167
    echo "If one argument is a file and the other a directory, then $0 will attempt"
 
168
    echo "to diff the given file with a file by the same name in the given directory."
 
169
    echo ""
 
170
    echo "If both arguments are directories, $0 will descend into each directory"
 
171
    echo "(and will do so recursively if '-recurse' is specified)  finding files"
 
172
    echo "whose names differ ONLY in the first component of their paths and attempt"
 
173
    echo "to diff them."
 
174
    echo ""
 
175
    echo "$0 uses Silo's browser tool to do its work. In turn, browser supports a"
 
176
    echo "number of additional options. Thus, any arguments to $0 which are neither"
 
177
    echo "files nor directories are treated as arguments to browser itself. For some"
 
178
    echo "options to browser like the '-f FILE' option, use the '--file=<FILE>'"
 
179
    echo "variant instead. By default, $0 will invoke browser with args"
 
180
    echo "'$browserOptsDef'. The available options to browser are..."
 
181
    echo ""
 
182
    $brexe --help 2>&1 | grep -v SWITCHES
 
183
    exit 1
 
184
fi
 
185
 
 
186
if test -d $arg1 -a -d $arg2; then # both are dirs
 
187
    for f in $arg1/*; do
 
188
        if test -d $f; then
 
189
            df=`echo $f | rev | cut -d'/' -f1 | rev`
 
190
            if test $recurse = 1; then
 
191
                if test -d $arg2/$df; then
 
192
                    if test $verbose = 1; then
 
193
                        echo "Processing directory \"$df\"..."
 
194
                        $0 -recurse -verbose $browserOpts $f $arg2/$df
 
195
                    else
 
196
                        $0 -recurse $browserOpts $f $arg2/$df
 
197
                    fi
 
198
                else
 
199
                    test $verbose = 1 && echo "Directory \"$df\" does not exist in \"$arg2\", skipping it."
 
200
                fi
 
201
            else
 
202
                test $verbose = 1 && echo "\"$df\" is a directory, skipping it. Use -recurse to process directories."
 
203
            fi
 
204
        else
 
205
            bf=`basename $f`
 
206
            if test -e $arg2/$bf; then
 
207
                test $verbose = 1 && echo "Processing file \"$bf\"..."
 
208
                $brexe $browserOptsDef $browserOpts -e diff $f $arg2/$bf
 
209
            else
 
210
                test $verbose = 1 && echo "File \"$bf\" does not exist in \"$arg2\", skipping it."
 
211
            fi
 
212
        fi
 
213
    done
 
214
elif test -d $arg1 -o -d $arg2; then # one is dir
 
215
    if test -d $arg1; then
 
216
        $brexe $browserOptsDef $browserOpts -e diff $arg1/$arg2 $arg2
 
217
    else
 
218
        $brexe $browserOptsDef $browserOpts -e diff $arg1 $arg2/$arg1
 
219
    fi
 
220
else # neither are dirs
 
221
    $brexe $browserOptsDef $browserOpts -e diff $arg1 $arg2
 
222
fi