#!/bin/sh
self=`basename $0`
path=`dirname $0`
tool="modify"
perl="perl"
###############################################################################
##                                                                           ##
##    Copyright (c) 1995, 1996, 1997, 1998 by Steffen Beyer.                 ##
##    All rights reserved.                                                   ##
##                                                                           ##
##    This program is free software; you can redistribute it                 ##
##    and/or modify it under the same terms as Perl itself.                  ##
##                                                                           ##
###############################################################################
if [ "$1" = "" ]
then
    echo
    echo "Usage: $self <filename> [<filename>]*"
    echo
    echo "This utility tries to upgrade your Perl application(s) \"<filename>\""
    echo "from \"Bit::Vector\" version 4.x to \"Bit::Vector\" version 5.2."
    echo
else
    file="$path/$tool"
    if [ ! -f "$file" ]
    then
        file=`which $tool`
        if [ ! -f "$file" ]
        then
            echo
            echo "$self: unable to find perl script \"$tool\"!"
            echo
            exit 1
        fi
    fi
    tool="$file"
    for file in "$@"
    do
        if [ -f "$file" ]
        then
            echo "$self: upgrading \"$file\" using \"$tool\"..."
            $perl $tool 's/to_ASCII/to_Enum/g;s/from_ASCII/from_Enum/g;s/to_String/to_Hex/g;s/(\$.+?)\s*->\s*from_string\s*\((.+?)\)/( eval { $1->from_Hex($2); !\$\@; } )/g;s/(\$.+?)\s*->\s*lexorder\s*\((.+?)\)/($1->Lexicompare($2) <= 0)/g;s/(\$.+?)\s*=\s*Bit::Vector\s*->\s*new_from_String\s*\((.+?)\)/$1 = Bit::Vector->new_Hex(length($2)<<2,$2)/g' $file
        else
            echo "$self: unable to find file \"$file\"!"
        fi
    done
fi
