#!/usr/bin/perl -T --
# -*- Mode: perl; indent-tabs-mode: nil -*-
#


# show_env - a pretty print replacement for the env command. The
# output is broken up using common separators so that it is easier to
# read.  The output is /bin/sh compatible and can be sourced to
# recreate the environment.


# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Tinderbox build tool.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#

# complete rewrite by Ken Estes for contact info see the
#     mozilla/webtools/tinderbox2/Contact file.
# Contributor(s): 

# $Revision: 1.3 $
# $Date: 2003/08/17 00:48:55 $
# $Author: kestes%walrus.com $
# $Name:  $


sub pretty_print {
# nicely format %env output
	
    my ($str)=@_;
    
    # protect quotes and dollars with a backslash
    $str =~ s!\"!\\\"!;  
    $str =~ s!\$!\\\$!;  

    # break lines at the different separators in the string
    $separator = "\";\n\tx=\"\$x";

    $str =~ s!;!$separator;!g;
    $str =~ s!:!$separator:!g;
    $str =~ s!,!$separator,!g;
    $str =~ s! !$separator !g;

    $str = "\tx=\"$str\";\n";
    
    return $str;
}


# ------- main ---------

{

  foreach $env (sort keys %ENV) {	
    print &pretty_print($ENV{$env});
    print "\n$env=\$x; export $env;\n\n";
  }

  exit 0;   
}
