home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
FAQ
/
discus_admin_1357211388
/
source
/
webtags2.pl
< prev
Wrap
Text File
|
2009-11-06
|
4KB
|
97 lines
# FILE: webtags2.pl
# DESCRIPTION: Special definitions for Discus formatting tags
#-------------------------------------------------------------------------------
# DISCUS COPYRIGHT NOTICE
#
# Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
# The use of Discus is governed by the Discus License Agreement which is
# available from the Discus WWW site at:
# http://www.discusware.com/discus/license
#
# Pursuant to the Discus License Agreement, this copyright notice may not be
# removed or altered in any way.
#-------------------------------------------------------------------------------
use strict;
use vars qw($GLOBAL_OPTIONS $PARAMS $DCONF);
### ////////////////////////////////////////////////////////////////////////////
### DEMONSTRATION OF HOW TO WRITE FUNCTIONS
### ////////////////////////////////////////////////////////////////////////////
###
### pig_latin
###
### Takes incoming text and roughly translates it to Pig Latin.
###
sub pig_latin {
my ($text_in) = @_; # This subroutine takes one argument
my $text_out = ""; # Initialize output string
while ($text_in =~ /(^|[\s>,\.:;])([a-zA-Z]+)([\s\.,<!\?:;!]|$)/) { # Iterate over all words while avoiding HTML codes
my ($before, $space, $word, $space2, $after) = ($`, $1, $2, $3, $'); # Save matches
$text_out .= join("", $before, $space); # Avoid converting these to pig latin
if ($word =~ /^([a-z])$/i) { # Single-letter word
$text_out .= join("", $word, "ay"); # Just add -ay
} elsif ($word =~ /^[AEIOUY]/i) { # Word starting with vowel
$text_out .= join("", $word, "ay"); # Just add -ay to word
} elsif ($word =~ /^([a-z])/) { # Non-capitalized word
$text_out .= join("", $', join("", $1, "ay")); # Pig latin for consonant
} elsif ($word =~ /^([A-Z])/) { # Capitalized word
$text_out .= join("", "\u$'", join("", "\l$1", "ay")); # Pig latin for capitalized consonant
} else { # Other catch-all
$text_out .= $word;
}
$text_out .= $space2;
$text_in = $after; # Loops ahead
}
$text_out .= $text_in; # Add remaining text at end
return $text_out; # Return converted pig latin string
}
###
### word_find
###
### An example of how to interface to a Perl module. You need the Games::WordFind
### module in order to use this tag (you can find this module, and others, at your
### CPAN mirror; for this module: http://www.cpan.org/modules/by-module/Games/)
###
sub word_find {
my @list = split(/,/, $_[0]); # Word list from input
@list = map { s/[^a-z]//gi; tr/a-z/A-Z/; trim($_) } @list; # Clean up the list
@list = grep { /\S/ } @list; # Remove empty words
# From the documentation of Games::WordFind, in "eval" in case you don't have
# the module installed
my $puz_html = eval "
use Games::WordFind;
my \$puz = Games::WordFind->new({cols=>10, intersect=>1});
\$puz->create_puzzle(\@list);
\$puz->get_html({solution => 0, wrapper => 0});
";
# Some conversions to make posts more suitable for being within messages
# rather than on a page by themselves
$puz_html =~ s%<font size=\+5>%%gi;
$puz_html =~ s&<hr width="50%">&<hr width="50%" align=center>&gi;
$puz_html =~ s%<H1 align=center>(.*?)</H1>%<h3 align=center>$1</h3>%gi;
# And, add the missing </center> tag
$puz_html .= "</center>";
# Return wordsearch
return $puz_html;
}
### ////////////////////////////////////////////////////////////////////////////
### PUT YOUR OWN SUBROUTINES HERE
### ////////////////////////////////////////////////////////////////////////////
1;