#!/usr/ug/bin/perl5 # # sample use: # gsub -akf ~whuang/prog/gale/demorse cmd/demorse:@ugcs.caltech.edu/user/demorse.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 = <>; my %mhash = ( ',' ,'--..--' , '.' ,'.-.-.-' , ':' ,'---...' , '?' ,'..--..' , '`' ,'.----.' , '-' ,'-....-' , '/' ,'-..-.' , , '(' ,'-.--.-' , ')' ,'-.--.-' , '"' ,'.-..-.' , '1' ,'.----' , '2' ,'..---' , '3' ,'...--' , '4' ,'....-' , '5' ,'.....' , '6' ,'-....' , '7' ,'--...' , '8' ,'---..' , '9' ,'----.' , '0' ,'-----' , 'A' ,'.-' , 'B' ,'-...' , 'C' ,'-.-.' , 'D' ,'-..' , 'E' ,'.' , 'F' ,'..-.' , 'G' ,'--.' , 'H' ,'....' , 'I' ,'..' , 'J' ,'.---' , 'K' ,'-.-' , 'L' ,'.-..' , 'M' ,'--' , 'N' ,'-.' , 'O' ,'---' , 'P' ,'.--.' , 'Q' ,'--.-' , 'R' ,'.-.' , 'S' ,'...' , 'T' ,'-' , 'U' ,'..-' , 'V' ,'...-' , 'W' ,'.--' , 'X' ,'-..-' , 'Y' ,'-.--' , 'Z' ,'--..' , ' ' ,'/' ); 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/demorse.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/demorse.whuang/') { $outstring = (@othercats == ()) ? "| gsend $SIGN" : "| gsend $SIGN -c ".join(':',@othercats); } else { $outstring = (@othercats == ()) ? "| gsend -c bot/demorse" : "| gsend -c bot/demorse:".join(':',@othercats); } if (join('',@MESSAGE) =~ /^\s*help\s*$/) { @MESSAGE = (); $MESSAGE[0] = <<'End of Help Message'; demorse version 2.0 by Wei-Hwa Huang (whuang@ugcs.caltech.edu) Decodes the Morse code string you puff to it. Put spaces between each code, and slashes where you want spaces in the resulting text. Privately: Send a private puff to demorse.whuang@ugcs.caltech.edu Publically: Send a puff to cmd/demorse. The bot will respond in bot/demorse, 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); $bigmsg =~ s/\// \/ /g; $bigmsg =~ s/_/-/g; $bigmsg =~ s/ / /g while ($bigmsg =~ / /) ; @MESSAGE = (); my $word; my $char; foreach $char (split(' ',$bigmsg)) { my $key; my $found = 0; foreach $key (keys %mhash) { if ($char eq $mhash{$key}) { $found = 1; push(@MESSAGE,$key); } } push(@MESSAGE,"<$char>") if ($found == 0); } } shift(@MESSAGE) while $MESSAGE[0] eq ' '; pop(@MESSAGE) while $MESSAGE[$#MESSAGE] eq ' '; $ENV{'GALE_FROM'}= 'Fargo North'; open(FHAND, $outstring); print FHAND @MESSAGE; close(FHAND); }