/******************************************************************************* * _ | File Name: format_string.c * / \ _-' | Description: This snippet allows you to incoorperate * _/| \-''- _ / | the format string command on your mud. * __-' | \ | format_str_len will format any string * / \ | to a length excluding color codes. * / "o. |o | | It can also center/left/right or ignore * | \ ; | alignment. * ', | * \_ __\ | (c) 2000-2001 TAKA * ''-_ \.// | (c) 2000-2001 The GhostMud Project Team * / '-____' | * / | You may use this code under GNU license restriction * _' The Wolf | 1) This header block remains in the code. * _-' strikes! | 2) You email me at a_ghost_dancer@excite.com *_________________________| letting me know you are using this code * please incluse your name, your mud name * All rights reserved your mud address, your email and this file * GhostMud is copyrighted name. * by TAKA 3) In your help files mention me where appropriate * IE: help snippets. * 4) Your use of this snippet must not violate any * ROM, MERC or DIKU license. *********************************************************************************/ /* * If there are any problems with implimentation, please mail me and I will * try to help. If there is a general problem in the code, please note the * list so those that are using it can fix it. As far as I know, when * released, all code is bug free, but I make no claims or promises that * this will not fry your system, etc, etc. And as with most, i take no * responsability if this breaks anything. Use at your own risk. My main * concern is that the snipets work and that they don't conflict with anything. * If anyone has any general tips for me, again, feel free to mail me. * * Permission is granted to post this to other list, put it on a web site, * etc, etc, as long as I am given full credit for it. * * -Taka * * * GhostMUD has a user list at GhostMUD-subscribe@yahoogroups.com * I monitor this list and answer questions there so many can benifit from * the answers. * * A web page with my snippets and code releases is being set up at * http://ghostmud.betterbox.net/code/ * http://ghostmud.betterbox.net/snippets/ * Both dos and linux versions of GhostMUD will appear on the code page * very soon. * * Anyone using my snippets or wishing to keep up with my latest work can * find this information there. * * char *FmtString char buf[MSL]; FmtString = format_str_len(whotitle, 14, ALIGN_CENTER); strcpy (buf, FmtString); printf_to_char(ch, "this is your string now: %s", buf); * NOTE if you do not have printf_to_char then get it from Erwin it is * very handy. * */ add this to MERC.H char * format_str_len(char * string, int length, int align); /* * format string alignment functions */ #define ALIGN_NONE 0 #define ALIGN_LEFT 1 #define ALIGN_RIGHT 2 #define ALIGN_CENTER 3 #define MSL MAX_STRING_LENGTH /* You may already have MSL defined but id not here it is */ add this to ACT_NEWC.C or ACT_INFO.C /* * format a string to a length * by TAKA of GhostMUD project */ char * format_str_len(char * string, int length, int align) { char buf[MSL]; char buf2[MSL]; char *new_string; char *count_string; char temp; int count = 0, nCount = 0; int pos = 0; new_string = buf; count_string = buf2; strcpy(buf2, string); /* get count for alignment */ while( *count_string && nCount != length ) { temp = *count_string++; if (temp == '{' ) { temp = *count_string++; if (temp == '{') nCount++; continue; } nCount++; } /* force alignment of text to the right */ if(align == ALIGN_RIGHT) { count = (length - ++nCount); while(nCount++ <= length) { buf[pos++] = ' '; } } /* force alignment of text to the center */ if(align == ALIGN_CENTER) { nCount = (length - nCount) / 2; count = nCount; while(nCount-- > 0) { buf[pos++] = ' '; } } /* add to buffer */ while( *string && count != length ) { temp = *string++; buf[pos++] = temp; if (temp == '{' ) { buf[pos] = *string++; if (buf[pos] == '{') count++; pos++; continue; } count++; } /* pad remaining space with blanks */ while (count++ < length) buf[pos++] = ' '; buf[pos] = '\0'; return (new_string); }