stringpad.txt
snippets · 3.0 KB · 2010-03-30
stringpad by Phate (Belgarath): lets you make fancy who lists with padded strings.
Download « Back to the snippets list
/* This code was written by Phate (Belgarath)
* This code will allow you to make new Whos such as...
* _/\_ _/\_
*(____) Unforgotten Wrath (____)
* | | | |
* | |.,~'**'~,....,~'**'~,..,~'**'~,...................................,~'**'~,..,~'**'~,....,~'**'~,.| |
* | | Immortals | |
* | |-------------------------------------------------------------------------------------------------| |
* | | [IMP Human War M] [.....] Phate LALA | |
* | |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| |
* | | Mortals | |
* | |-------------------------------------------------------------------------------------------------| |
* | |'*~.,,.~*''''*~.,,.~*''*~.,,.~*'''''''''''''''''''''''''''''''''''*~.,,.~*''*~.,,.~*''''*~.,,.~*'| |
* | | | |
* | | | |
* | | | |
* ,--, ,--,
*(____) (____)
* With color and not having to worry about the | moving back with each {C.
* I do however ask for a small piece of Credit, which is included int he function itself.
*
* Phate */
*--[merc.h]--*
Insert this anywhere really....
char * string_pad args( ( char *string, int nWidth, bool Right_Align) );
*--[string.c]--*
I just put this at the bottom of my string.c file.
/* String_pad by Phate of Unforgotten Wrath and Final Fantasy 1 MUD */
char* string_pad(char *string, int nWidth, bool Right_Align)
{
char buf[MSL];
char buf2[MSL];
int x = 0;
int count = 0;
if(string == NULL)
return "";
for( x = 0 ; ; x++ )
{
if( string[x] == '\0')
{
break;
}
else if( string[x] == '{')
{
x++;
if(string[x] == '{')
{
count++;
}
}
else
{
count++;
}
}
strcpy(buf2,"");
for( x = 0; x <= nWidth - count; x++)
strcat(buf2," ");
if(Right_Align)
{
strcpy(buf,buf2);
strcat(buf,string);
}
else
{
strcpy(buf,string);
strcat(buf,buf2);
}
return str_dup(buf);
}
Now if you want it to be like my do_who, this is what you would put for the title to have a 45 character area for itself...
IS_NPC(wch) ? string_pad("",45,FALSE) : string_pad(wch->pcdata->title,45,FALSE)