----------------------------------------------------------------- SMAUG strlen_color 1.0 By Xerves (Released August 2, 1999) Xerves is the admin/owner of Rafermand (mud.rafermand.net port 3002) Website: http://www.rafermand.net Contact: xerves@rafermand.net ----------------------------------------------------------------- This is simply a function you can throw in handler and it will work like strlen but it will remove all space references to color (and will also work to fix the && and ^^ space problems you might have). Also, included is an example how this can be used (if you use colors with rank, this shows you a good way to fix up the rank so when they type rank, it will align properly if they use colors or not). (Thanks Rusty for the orginal code and posting it) ----------------------------------------------------------------- Files Needed: act_wiz.c handler.c mud.h ----------------------------------------------------------------- 1. Handler.c This is the strlen_color function. You can dump it anywhere you want, but I thought handler was the right place for it.. /* Strlen_color by Rusty, useful for skipping over colors */ /* Fixed and edited by Xerves -- 8/29/99 */ int strlen_color (char *argument) { char *str; int i, length; str = argument; if (argument == NULL) return 0; for (length=i=0; i < strlen (argument); ++i) { if ((str [i] != '&') && (str [i] != '^')) ++length; if ((str [i] == '&') || (str [i] == '^')) { if ((str[i] == '&') && (str[i+1] == '&')) length=2+length; else if ((str[i] == '^') && (str[i+1] == '^')) length=2+length; else --length; } } return length; } 2. Act_wiz.c An example is the rank command. I will post the who function and put little notes to the side. You don't have to add this to make strlen_color work, but just an example of why this might be useful... void do_rank( CHAR_DATA *ch, char *argument ) { char add_len[MAX_INPUT_LENGTH]; /* Following defines are for putting spaces into the rank */ int sp1, sx; /* To fix the color problem. */ char finrank[MAX_INPUT_LENGTH]; set_char_color( AT_IMMORT, ch ); sp1 = strlen_color(argument); /* Finds the strlen_color of the argument */ sprintf( add_len, " "); /* Init. the add_len strength */ for (sx=14; sx > sp1; sx--) /* 15 - 1 for add_len init.*/ strcat( add_len, " "); /* For every time it will add a blank space after the rank */ strcpy( finrank, argument); /* Adding spaces to finish out rank --Xerves*/ strcat( finrank, add_len); /* Adding the length to the end of the argument -- Xerves*/ if ( IS_NPC(ch) ) return; if ( !argument || argument[0] == '\0' ) { send_to_char( "Usage: rank .\n\r", ch ); send_to_char( " or: rank none.\n\r", ch ); return; } smash_tilde( argument ); DISPOSE( ch->pcdata->rank ); if ( !str_cmp( argument, "none" ) ) ch->pcdata->rank = str_dup( "" ); else ch->pcdata->rank = str_dup( finrank ); /* If there is a rank, it will use finrank instead of */ send_to_char( "Ok.\n\r", ch ); /* the argument. finrank is the argument with the spaces */ return; } 3. Mud.h Find these lines /* handler.c */ int get_exp args( ( CHAR_DATA *ch ) ); int get_exp_worth args( ( CHAR_DATA *ch ) ); Right after the /* handler.c */ line, add this line int strlen_color args( (char *argument) ); ------------------------------------------------------------------------------ Well that is it. strlen_color might come in handy for you, it might not. If you ever need it though, there it is.