#!/usr/ug/bin/perl5 # # sample use: # gsub -akf ~whuang/prog/gale/morse cmd/morse:@ugcs.caltech.edu/user/morse.whuang # # by Wei-Hwa Huang (whuang@ugcs.caltech.edu) # sections of code stolen from jtr@ugcs.caltech.edu use strict; use POSIX qw(strftime); # gale info use vars qw($FROM $ENC $CAT $SIGN $TIME @MESSAGE $NEWCAT $FTIME); # misc use vars qw($GALE $HOME $LOGDIR $USER %LOGGEDTO); $FROM= $ENV{'HEADER_FROM'}; $TIME= $ENV{'HEADER_TIME'}; $CAT= $ENV{'GALE_CATEGORY'}; $CAT =~ s-zephyr/message-zephyr/MESSAGE-gi; print STDERR "incoming message from category: $CAT\n"; $ENC= $ENV{'GALE_ENCRYPTED'}; $SIGN= $ENV{'GALE_SIGNED'}; $HOME= $ENV{'HOME'}; $GALE= $HOME . "/.gale/"; $LOGDIR= $HOME . "/gale/"; $USER= $ENV{'USER'}; $FTIME= $ENV{'GALE_TIME_ID_TIME'}; @MESSAGE = <>; print STDERR "$CAT\n"; my @cats = split(":",$CAT); my (@cmdcats, @botcats, @othercats) = ((),(),()); my $singlecat; foreach $singlecat (@cats) { if ($singlecat =~ /^bot\./) { push(@botcats,$singlecat); } elsif ($singlecat eq '@ugcs.caltech.edu/user/morse.whuang/') { push(@cmdcats,$singlecat); } elsif ($singlecat =~ /^cmd\./) { push(@cmdcats,$singlecat); } else { push(@othercats,$singlecat); } } foreach $singlecat (@cmdcats) { my $outstring; if ($singlecat eq '@ugcs.caltech.edu/user/morse.whuang/') { $outstring = (@othercats == ()) ? "| gsend $SIGN" : "| gsend $SIGN -c ".join(':',@othercats); } else { $outstring = (@othercats == ()) ? "| gsend -c bot.morse" : "| gsend -c bot.morse:".join(':',@othercats); } if (join('',@MESSAGE) =~ /^\s*help\s*$/) { @MESSAGE = (); $MESSAGE[0] = <<'End of Help Message'; morse version 3.0 by Wei-Hwa Huang (whuang@ugcs.caltech.edu) Converts the English string you puff to it into morse code. Privately: Send a private puff to morse.whuang@ugcs.caltech.edu Publically: Send a puff to cmd.morse. The bot will respond in bot.morse, along with any crosspuffed categories. Known bugs: Unrecognized characters will be outputted as '*'. Non-ASCII alphabetic (international) characters are unrecognized. End of Help Message } else { chomp @MESSAGE; my $bigmsg = join(' ',@MESSAGE); @MESSAGE = (); my $word; my $char; my @newword; foreach $word (split(' ',$bigmsg)) { @newword = (); $word =~ tr/a-z/A-Z/; foreach $char (split(//,$word)) { if ($char eq '.') { push(@newword,'.-.-.-' );} elsif ($char eq ',') { push(@newword,'--..--' );} elsif ($char eq ':') { push(@newword,'---...' );} elsif ($char eq '?') { push(@newword,'..--..' );} elsif ($char eq '\'') { push(@newword,'.----.' );} elsif ($char eq '`') { push(@newword,'.----.' );} elsif ($char eq '-') { push(@newword,'-....-' );} elsif ($char eq '_') { push(@newword,'-....-' );} elsif ($char eq '/') { push(@newword,'-..-.' );} elsif ($char eq '\\') { push(@newword,'-..-.' );} elsif ($char eq ']') { push(@newword,'-.--.-' );} elsif ($char eq '[') { push(@newword,'-.--.-' );} elsif ($char eq '(') { push(@newword,'-.--.-' );} elsif ($char eq ')') { push(@newword,'-.--.-' );} elsif ($char eq '{') { push(@newword,'-.--.-' );} elsif ($char eq '}') { push(@newword,'-.--.-' );} elsif ($char eq '"') { push(@newword,'.-..-.' );} elsif ($char eq '1') { push(@newword,'.----' );} elsif ($char eq '2') { push(@newword,'..---' );} elsif ($char eq '3') { push(@newword,'...--' );} elsif ($char eq '4') { push(@newword,'....-' );} elsif ($char eq '5') { push(@newword,'.....' );} elsif ($char eq '6') { push(@newword,'-....' );} elsif ($char eq '7') { push(@newword,'--...' );} elsif ($char eq '8') { push(@newword,'---..' );} elsif ($char eq '9') { push(@newword,'----.' );} elsif ($char eq '0') { push(@newword,'-----' );} elsif ($char eq 'A') { push(@newword,'.-' );} elsif ($char eq 'B') { push(@newword,'-...' );} elsif ($char eq 'C') { push(@newword,'-.-.' );} elsif ($char eq 'D') { push(@newword,'-..' );} elsif ($char eq 'E') { push(@newword,'.' );} elsif ($char eq 'F') { push(@newword,'..-.' );} elsif ($char eq 'G') { push(@newword,'--.' );} elsif ($char eq 'H') { push(@newword,'....' );} elsif ($char eq 'I') { push(@newword,'..' );} elsif ($char eq 'J') { push(@newword,'.---' );} elsif ($char eq 'K') { push(@newword,'-.-' );} elsif ($char eq 'L') { push(@newword,'.-..' );} elsif ($char eq 'M') { push(@newword,'--' );} elsif ($char eq 'N') { push(@newword,'-.' );} elsif ($char eq 'O') { push(@newword,'---' );} elsif ($char eq 'P') { push(@newword,'.--.' );} elsif ($char eq 'Q') { push(@newword,'--.-' );} elsif ($char eq 'R') { push(@newword,'.-.' );} elsif ($char eq 'S') { push(@newword,'...' );} elsif ($char eq 'T') { push(@newword,'-' );} elsif ($char eq 'U') { push(@newword,'..-' );} elsif ($char eq 'V') { push(@newword,'...-' );} elsif ($char eq 'W') { push(@newword,'.--' );} elsif ($char eq 'X') { push(@newword,'-..-' );} elsif ($char eq 'Y') { push(@newword,'-.--' );} elsif ($char eq 'Z') { push(@newword,'--..' );} elsif ($char eq '') { push(@newword,'' );} else { push(@newword,'*'); } } push(@MESSAGE,' / '.(join(' ',@newword))); } push(@MESSAGE,' / '); } $ENV{'GALE_FROM'}= '... .- -- -- -.--'; open(FHAND, $outstring); print FHAND @MESSAGE; close(FHAND); }