##---------------------------------------------------------------------------##
## $Id: ewhutil.pl,v 2.9 2002/09/25 03:51:13 ehood Exp $
## Earl Hood mhonarc@mhonarc.org
## Generic utility routines
##---------------------------------------------------------------------------##
## Copyright (C) 1996-2001 Earl Hood, mhonarc@mhonarc.org
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
##---------------------------------------------------------------------------##
##---------------------------------------------------------------------------
## Remove duplicates in an array.
## Returns list with duplicates removed.
return () unless scalar(@
$a);
##---------------------------------------------------------------------------
## "Entify" special characters
sub htmlize
{ # Older name
return '' unless scalar(@_) && defined($_[0]);
$txt =~ s/(["&<>])/$HTMLSpecials{$1}/g;
sub entify
{ # Newer name
return '' unless scalar(@_) && defined($_[0]);
$txt =~ s/(["&<>])/$HTMLSpecials{$1}/g;
## commentize entifies certain characters to avoid problems when a
## string will be included in a comment declaration
$txt =~ s/([\-&])/'&#'.unpack('C',$1).';'/ge;
$txt =~ s/&#(\d+);/pack("C",$1)/ge;
##---------------------------------------------------------------------------
open(SRC
, $src) || die("ERROR: Unable to open $src\n");
open(DST
, "> $dst") || die("ERROR: Unable to create $dst\n");
##---------------------------------------------------------------------------
## Translate html string back to regular string
##---------------------------------------------------------------------------
## Escape special characters in string for URL use.
$url =~ s/([^\w@\.\-])/sprintf("%%%X",unpack("C",$1))/ge;
##---------------------------------------------------------------------------##
## Perform a "modified" rot13 on a string. This version includes
## the '@' character so addresses can be munged a little better.
$str =~ tr/@A-Z[a-z/N-Z[@A-Mn-za-m/;
##---------------------------------------------------------------------------##