#---------------------------------------------------------------------#
# This source code is (c)1998 Dave Belfer-Shevett - shevett@pobox.com #
# see http://www.stonekeep.com/license.html for licensing information #
#---------------------------------------------------------------------#

package Utilities;

#-----------------------------------------------------------------------
# Utilities.pm
# $Id:
#-----------------------------------------------------------------------

=head1 NAME

Utilities - A collection of utilities that are not specific to Keystone.

=head1 SYNOPSIS 

        require Utilities;

	$larger = max( $one, $two );

	$smaller = min( $one, $two );

	$string = enquote( $string );

=head1 DESCRIPTION


=head1 FUNCTIONS

=cut



# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

=head2 max() -- Find the larger number.

Find the larger of two numbers.

=over 4

=item Use:

  $larger = max( $one, $two );

=item Parameters:

=over 4

=item one

A number to compare.

=item two

Another number to compare.

=back

=item Returns:

The larger number.

=back

=cut # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

sub max {
  my ($one, $two) = @_;

  $main::debug && print STDERR "Entering max( " . $one . ", " . $two . " ).\n";

  if ($one > $two) {
    return $one;
  }
  else {
    return $two;
  }
}



# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

=head2 min() -- Find the smaller number.

Find the smaller of two numbers.

=over 4

=item Use:

  $smaller = min( $one, $two );

=item Parameters:

=over 4

=item one

A number to compare.

=item two

Another number to compare.

=back

=item Returns:

The smaller number.

=back

=cut # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

sub min {
  my ($one, $two) = @_;

  if ($one > $two) {
    return $two;
  }
  else {
    return $one;
  }
}



# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

=head2 enquote() -- Put quotes around a string.

Any double quotes or slash characters in the provided string get a
slash inserted ahead of them.  Double quotes are added around the
string.

=over 4

=item Use:

  $string = enquote( $string );

=item Parameters:

=over 4

=item string

String to modify.

=back

=item Returns:

The modified string.

=back

=cut # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

sub enquote {
  my ($string) = @_;


  $main::debug && print STDERR "Entering enquote( " . $string . " ).\n";

  $string =~ s/(\\|")/\\$1/g;
  $string = '"' . $string . '"';


  $main::debug && print STDERR "Returning qw( " . $string .
      " ) from enquote().\n";

  return $string;
}

1;

__END__

=head1 CAVEATS

=head1 BUGS

None that I know of.

=head1 AUTHOR

David H. Silber
of Silber Software Engineering
F<E<lt>david@SilberSoft.comE<gt>>
wrote this for StoneKeep Consulting
as part of the B<keycli> development effort.

=head1 SEE ALSO

=cut

