[comp.mail.elm] upelmrc perl script to convert 2.1 elmrc to 2.2

david@wubios.wustl.edu (David J. Camp) (09/08/89)

Enclosed is a perl script I hacked out to convert an elm 2.1 PL1 elmrc
script to an elm 2.2 PL10 elmrc script.  Theoretically, it could be used
to convert from any version of elm to an upgrade.  Note that this does
not replace your elmrc file.  You must do that by hand or in an external
script.  Call it with no arguments for brief help.  It takes the old
elmrc filename and the new elmrc filename.  e.g.  

     mv ~/.elm/elmrc ~/.elm/elmrc.old
     upelmrc ~/.elm/elmrc.old ~/.elm/elmrc

It requires a template file in /usr/local/lib/defelmrc that contains the
defaults for the new options.  It should contain all of the options, i.e.
it should be a valid elmrc file for the new version.  The options
specified in the old elmrc file will replace the equivalent ones in the
default.  If you do not have perl, you have no excuse, because it is
free.  -David-

Bitnet:   david@wubios.wustl                ^      Mr. David J. Camp
Internet: david%wubios@wucs1.wustl.edu    < * >    Box 8067, Biostatistics
uucp:     uunet!wucs1!wubios!david          v      660 South Euclid
Washington University (314) 36-23635               Saint Louis, MO 63110

#! /usr/bin/perl
if ($#ARGV != 1)
    {
    printf stderr "usage: upelmrc oldelmrc newelmrc\n";
    exit 2;
    }
unless (open (oldelmrc, $ARGV [0]))
    {
    printf stderr "Cannot open input file\n".$ARGV [0];
    exit 3;
    }
unless (open (newelmrc, ">".$ARGV [1]))
    {
    printf stderr, "Cannot open output file\n". $ARGV [1];
    exit 4;
    }
unless (open (defelmrc, "/usr/local/lib/defelmrc"))
    {
    print stderr "Cannot find default elmrc file.\n";
    exit 5;
    }
while ($inline = <oldelmrc>)
    {
    if (index ($inline, "#") != 0 && index ($inline, "\n") != 0)
        {
        @assign = split (/ = /, $inline );
        $indice = shift (@assign);
        $entries{$indice} = join (' = ', @assign);
        }
    }
close (oldelmrc);
while ($inline = <defelmrc>)
    {
    if (index ($inline, "#") == 0 || index ($inline, "\n") == 0)
        {
        print newelmrc $inline;
        }
    else
        {
        @assign = split (/ = /, $inline);
        $indice = shift (@assign);
        $outline = join (' = ', @assign);
        if ($entries{$indice} ne "")
            {
            $outline = $entries{$indice};
            }
        print newelmrc $indice." = ".$outline;
        }
    }
close defelmrc;
close newelmrc;
-- 
Bitnet:   david@wubios.wustl                ^      Mr. David J. Camp
Internet: david%wubios@wucs1.wustl.edu    < * >    Box 8067, Biostatistics
uucp:     uunet!wucs1!wubios!david          v      660 South Euclid
Washington University (314) 36-23635               Saint Louis, MO 63110