#!/usr/bin/perl -w #can($choice); $f->(); exit(0); #--------------------------------------------------------------------- # Decode URLs. sub Action::urldecode { local $_; while (<>) { s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg; s///g; print; } } #--------------------------------------------------------------------- # Encode strings unless they're already encoded. sub Action::urlencode { local $_; while (<>) { s/([^a-z0-9\/\n\-_.!~*'()+])/"%" . sprintf("%2.2X", ord($1))/gei unless /%([a-fA-F0-9]{2,2})/; print; } } #--------------------------------------------------------------------- # Print a usage message from the comments and exit. sub usage { my ($emsg) = @_; use Pod::Usage qw(pod2usage); warn "$emsg\n" if defined $emsg; pod2usage(-verbose => 99, -sections => "NAME|SYNOPSIS|OPTIONS"); } sub manpage { use Pod::Man(); my $parser = Pod::Man->new(); open(STDOUT, "| groff -T ascii -man | gcat -s | less") || die "groff\n"; $parser->parse_from_file($0); close STDOUT || die "$myname: can't close stdout: $!\n"; $? = 1 if $? == 255; # from die exit($?); } #--------------------------------------------------------------------- # Print the UUID, current version, or source location. sub myuuid { my $UUID = sprintf("%s", q$UUID: eb021dd0-8b94-36b0-9041-87e0ed317e20 $ =~ /UUID: (.*) /); print "$UUID\n"; exit(0); } sub version { my $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); my $DATE = sprintf("%s", q$Date: 2008/04/14 21:08:31 $ =~ /Date: (.*) /); print "$myname $VERSION $DATE\n"; exit(0); } sub where { my $SOURCE = print "$SOURCE\n"; exit(0); } #--------------------------------------------------------------------- __END__ =head1 NAME url - encode or decode URLs =head1 SYNOPSIS url [-dehmuvw] [file ...] =head1 OPTIONS =over 4 =item B<-d> Decode strings resembling URLs. =item B<-e> Encode strings resembling URLs. =item B<-h> Print a brief help message and exit. =item B<-m> Print the manual page and exit. =item B<-u> Print the script UUID and exit. =item B<-v> Print the version and exit. =item B<-w> Print the source location and exit. =back =head1 DESCRIPTION B will read strings that look like URLs and either encode them for use in a browser, or decode them. Can be used to turn webserver log entries into filenames or vice-versa. =head1 EXAMPLES me% echo 'Process%20Improvements' | url -d Process Improvements me% echo 'Process Improvements' | url -e Process%20Improvements =head1 AUTHOR Karl Vogel Sumaria Systems, Inc. =cut