Fix Dead Store (Dead assignement/Dead increment) warning found by Clang
[metze/wireshark/wip.git] / tools / textify.sh
1 #!/bin/bash
2 #
3 # Text file conversion script for packaging on Windows
4 #
5 # This script copies a text file from a source to a destination,
6 # converting line endings and adding a ".txt" filename extension
7 # if needed. If the destination is a directory the source file
8 # name is used. Newer files will not be overwritten.
9 #
10 # The destination file should be double-clickable and usable
11 # when Notepad is the default editor.
12 #
13 # Copyright 2013 Gerald Combs <gerald@wireshark.org>
14 #
15 # Wireshark - Network traffic analyzer
16 # By Gerald Combs <gerald@wireshark.org>
17 # Copyright 1998 Gerald Combs
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License
21 # as published by the Free Software Foundation; either version 2
22 # of the License, or (at your option) any later version.
23 #
24 # This program is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32
33 SRC="$1"
34 DST="$2"
35
36 err_exit () {
37     for str in "$@" ; do
38         echo "ERROR: $str"
39     done
40     echo "Usage:"
41     echo "  $0 <source file> <destination file>"
42     echo ""
43     exit 1
44 }
45
46 if [ -z "$SRC" -o -z "$DST" ] ; then
47     err_exit
48 fi
49
50 if [ ! -r "$SRC" ] ; then
51     err_exit "Can't read $SRC"
52 fi    
53
54 if [ -f "$DST" -a "$DST" -nt "SRC" ]; then
55     exit 0
56 fi
57
58 if [ -d "$DST" ] ; then
59     DSTBASE=`basename "$SRC" txt`
60     DST="$DST/$DSTBASE.txt"
61 else
62     DSTDIR=`dirname "$DST"`
63     DSTBASE=`basename "$DST" txt`
64     DST="$DSTDIR/$DSTBASE.txt"
65 fi
66
67 cp "$SRC" "$DST"
68 u2d "$DST"