LPMuds.net Forums > Code Vault

Improved ASCII command

(1/1)

z993126:
This bit of code is intended as an improved replacement for the existing DS 'ascii' command, and is public domain and free to modify and use.


--- Code: ---/* /cmds/creators/ascii.c
 * 2012-May-05 T. Cook improved output
 */
#include <daemons.h>
#include <lib.h>

inherit LIB_COMMAND;

int cmd( string str ){
int code, count2, scrX = this_player()->GetScreen()[0];
string err1 = "", err2 = "";
string tmp = "";
string ret = "";

if( str ){ code = hextoi( str ); }
if( str && ( code < 32 || code > 255 ) ){
write( "Argument to this command must be between 20 and FE." );
return 1;
}
if( !scrX ){ scrX = 79; }

if( code ){
ret = convert_ascii( code );
write( "The ASCII code " + code + " is:  " + ret );
return 1;
}

for( code = 0; code < 16; code++ ){
tmp += " " + sprintf( "%1X", code );
}
ret += "A table of the printable ASCII characters.  Be aware that only 20 (space) through 7E (tilde) " +
"are 'safe' for use and certain to display the same for every client.\n";
ret += center( sprintf( "    %%^B_BLUE%%^%%^YELLOW%%^%s%%^RESET%%^\n\n", tmp ), scrX );
tmp = "";
for( count2 = 32; count2 < 256; count2 += 16 ){
for( code = 0; code < 16; code++ ){
tmp += " " + convert_ascii( count2 + code );
}
if( sizeof( tmp ) ){
ret += center( sprintf(
"%%^B_BLUE%%^%%^YELLOW%%^ %X %%^RESET%%^%s%s%s%s",
count2, count2 > 127 ? "%^BOLD%^%^BLACK%^" : "%^BOLD%^", tmp, "%^RESET%^", count2 < 240 ? "\n\n" : "  "
), scrX );
tmp = "";
}
}

write( ret );
return 1;
}

string GetHelp( string str ){
return "syntax:  ascii <CODE>\n\n
"Provided a hexadecimal code that corresponds to an ASCII code known to " +
"the mud, that character will be displayed.  Note that the characters whose values " +
"are greater than 127 vary with font and active code page.\nWithout an argument, the command " +
"displays a table of all ASCII codes known to the mud and their characters."
}
/* EOF */
--- End code ---

Navigation

[0] Message Index

Go to full version