; Reversing words?
; It started when my friend and I decided to talk backward.
; I found it annoying to rephrase my words manually so I wrote this.
; It's not new but I never say it will never work! :)
; Perhaps the way I handle it may not be the best, but oh well, I tried.
; Author: xiao-wen-zi
; Email: smallmoskito@yahoo.com
; Date: 1st January 2002
;
; Usage
;
; /rev <text> returns <echo | say> result
;
; Example
; Input: /rev hi?
; Output: ?ih
;
; $rev(text) returns result
;
;/revd brings up the GUI
alias rev {
;declare variables
;%c stores the total number of words found
var %c $calc($iif($count($$1-,$chr(32)),$ifmatch,0) +1) , %v, %f
;words loop - begining from the last word of the sentence to the first
while ( %c > 0) {
%f = $gettok($$1-,%c,32) | var %i $len(%f) , %t
;letters loop - begining from the last letter of the word to the first (obviously)
while (%i) { %t = $+(%t,$right($left(%f,%i),1)) | dec %i }
;adds the reconstructed words to the end of the the rest
dec %c | %v = %v %t
}
;if is ident., it'll return the result
if ($isid) { return %v }
;if connected to a server it'll say the result
$iif($server,say,echo) %v
}
;
; Dialog
;
alias revd return $dialog(rev,rev,-1)
dialog rev {
size -1 -1 200 50
option dbu
title "Reverse words?"
edit "Insert text here",2,5 5 192 12, autohs
edit "",3,5 20 192 12, read autohs
button "&Copy reversed words",4,5 36 60 12, default
button "E&xit",1,166 36 30 12, okay default
}
on *:dialog:rev:*:*: {
var %e $devent , %n $dname , %d $did
if (%e == init) { did -fa %n 2 $chr(32) }
if (%e == edit) && (%d == 2) { did -o %n 3 1 $rev($did(2)) }
if (%e == sclick) && (%d == 4) { clipboard $did(3) }
}