Difference between revisions of "Ascii alias"
From Scriptwiki
m (damn returns) |
m (%t -> $2-) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | This alias | + | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
− | Usage: | + | ; |
− | /ascii for a list of all characters. | + | ; Written by Vliedel |
− | /ascii <text> to convert the text to the ascii values of all characters. | + | ; Contact: #help.script @ irc.QuakeNet.org |
− | /ascii -r <ascii values> to convert the ascii values to normal text. | + | ; |
− | /ascii -h <text> to convert the text to the hexadecimal values of the characters. | + | ; This alias is usefull to quickly convert characters to ascii values. |
− | /ascii -rh <hexadecimal values> to convert the values to normal text. | + | ; |
+ | ; Usage: /ascii [[-rh] <input>] | ||
+ | ; | ||
+ | ; /ascii for a list of all characters. | ||
+ | ; /ascii <text> to convert the text to the ascii values of all characters. | ||
+ | ; /ascii -r <ascii values> to convert the ascii values to normal text. | ||
+ | ; /ascii -h <text> to convert the text to the hexadecimal values of the characters. | ||
+ | ; /ascii -rh <hexadecimal values> to convert the values to normal text. | ||
+ | ; | ||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
alias ascii { | alias ascii { | ||
− | if ($1 == $null) { | + | if ([[$1-|$1]] == [[$null]]) { |
− | if ($window(@ascii)) { window -c @ascii } | + | if ([[$window]](@ascii)) { [[window]] -c @ascii } |
window -zk0 @ascii 20 20 150 650 | window -zk0 @ascii 20 20 150 650 | ||
− | var %a = 1 | + | [[var]] %a = 1 |
− | while (%a < 256) { aline @ascii $!chr( $+ %a $+ ) $chr(%a) | inc %a } | + | [[while]] (%a < 256) { [[aline]] @ascii $!chr( $+ %a $+ ) [[$chr]](%a) | [[inc]] %a } |
− | return | + | [[return]] |
} | } | ||
− | var %l = $iif($left($1,1) == -,1) , %h = $iif(h isin $1,1) , %r = $iif(r isin $1,1) | + | var %l = [[$iif]]([[$left]]($1,1) == -,1) , %h = $iif(h isin $1,1) , %r = $iif(r isin $1,1) |
− | if (%l) && (%h) && (%r) { | + | [[if]] (%l) && (%h) && (%r) { |
− | var %i = $calc($0 - 1) , %t | + | if (![[$regex]]($2-,/^((^|\s)([\dA-F]?[\dA-F]))+$/i)) { [[echo]] -ag Usage: /ascii -rh <hexadecimal values> | return } |
− | if (%i > $calc(900 - $len($2-))) { var %i = $v2 , %t = $chr(2) truncated } | + | var %i = [[$calc]]([[$0]] - 1) , %t |
− | while (%i) { var %t = $chr($base($gettok($2-,%i,32),16,10,32)) $+ %t | dec %i } | + | if (%i > $calc(900 - [[$len]]($2-))) { var %i = [[$v2]] , %t = $chr(2) truncated } |
+ | while (%i) { var %t = $chr([[$base]]([[$gettok]]($2-,%i,32),16,10,32)) $+ %t | [[dec]] %i } | ||
echo -ag $2- = %t | echo -ag $2- = %t | ||
} | } | ||
elseif (%l) && (%h) { | elseif (%l) && (%h) { | ||
var %i = $len($2-) , %t | var %i = $len($2-) , %t | ||
− | if ($calc(%i * 4) > 900) { var %i = $int($calc((900 - $len($2-))/3)) , %t = $chr(2) $+ truncated } | + | if ($calc(%i * 4) > 900) { var %i = [[$int]]($calc((900 - $len($2-))/3)) , %t = $chr(2) $+ truncated } |
− | while (%i) { var %t = $base($asc($mid($2-,%i,1)),10,16) %t | dec %i } | + | while (%i) { var %t = $base([[$asc]]([[$mid]]($2-,%i,1)),10,16) %t | dec %i } |
echo -ag $2- $chr(15) $+ = %t | echo -ag $2- $chr(15) $+ = %t | ||
} | } | ||
elseif (%l) && (%r) { | elseif (%l) && (%r) { | ||
− | bset &asc 1 $2- | + | if (!$regex($2-,/^((^|\s)(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]))+$/)) { echo -ag Usage: /ascii -r <ascii values> | return } |
+ | [[bset]] &asc 1 $2- | ||
var %m = $calc(900 - $len($2-)) + $0 -1) | var %m = $calc(900 - $len($2-)) + $0 -1) | ||
− | echo -ag $2- = $left($bvar(&asc,1-).text,%m) $iif(%m < $calc($0 -1),$chr(2) truncated) | + | echo -ag $2- = $left([[$bvar]](&asc,1-).text,%m) $iif(%m < $calc($0 -1),$chr(2) $+ truncated) |
} | } | ||
else { | else { | ||
Line 39: | Line 50: | ||
} | } | ||
} | } | ||
+ | |||
+ | [[Category:Script Archive]] |
Latest revision as of 12:19, 27 March 2007
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Written by Vliedel ; Contact: #help.script @ irc.QuakeNet.org ; ; This alias is usefull to quickly convert characters to ascii values. ; ; Usage: /ascii [[-rh] <input>] ; ; /ascii for a list of all characters. ; /ascii <text> to convert the text to the ascii values of all characters. ; /ascii -r <ascii values> to convert the ascii values to normal text. ; /ascii -h <text> to convert the text to the hexadecimal values of the characters. ; /ascii -rh <hexadecimal values> to convert the values to normal text. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; alias ascii { if ($1 == $null) { if ($window(@ascii)) { window -c @ascii } window -zk0 @ascii 20 20 150 650 var %a = 1 while (%a < 256) { aline @ascii $!chr( $+ %a $+ ) $chr(%a) | inc %a } return } var %l = $iif($left($1,1) == -,1) , %h = $iif(h isin $1,1) , %r = $iif(r isin $1,1) if (%l) && (%h) && (%r) { if (!$regex($2-,/^((^|\s)([\dA-F]?[\dA-F]))+$/i)) { echo -ag Usage: /ascii -rh <hexadecimal values> | return } var %i = $calc($0 - 1) , %t if (%i > $calc(900 - $len($2-))) { var %i = $v2 , %t = $chr(2) truncated } while (%i) { var %t = $chr($base($gettok($2-,%i,32),16,10,32)) $+ %t | dec %i } echo -ag $2- = %t } elseif (%l) && (%h) { var %i = $len($2-) , %t if ($calc(%i * 4) > 900) { var %i = $int($calc((900 - $len($2-))/3)) , %t = $chr(2) $+ truncated } while (%i) { var %t = $base($asc($mid($2-,%i,1)),10,16) %t | dec %i } echo -ag $2- $chr(15) $+ = %t } elseif (%l) && (%r) { if (!$regex($2-,/^((^|\s)(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]))+$/)) { echo -ag Usage: /ascii -r <ascii values> | return } bset &asc 1 $2- var %m = $calc(900 - $len($2-)) + $0 -1) echo -ag $2- = $left($bvar(&asc,1-).text,%m) $iif(%m < $calc($0 -1),$chr(2) $+ truncated) } else { bset -t &asc 1 $1- var %m = $int($calc((900 - $len($1-))/4)) echo -ag $1- $chr(15) $+ = $bvar(&asc,1,%m) $iif(%m < $bvar(&asc,0),$chr(2) $+ truncated) } }