/* to install open magic.c and find: int dice_parse(CHAR_DATA *ch, int level, char *exp) { char buf[MAX_INPUT_LENGTH]; strcpy( buf, exp ); return rd_parse(ch, level, buf); } Change to: int dice_parse(CHAR_DATA *ch, int level, char *exp) { char buf[MAX_INPUT_LENGTH]; sprintf( buf, "%s", die_parse( ch, level, exp )); return rd_parse(ch, level, buf); } Then you either add this entire file to your makefile in the appropriate places, or extract the pieces and put them somewhere they'll work. Note the comments below explaining where to put the prototypes and what includes to use. */ // You'll need the following includes in whatever file you put these in: #include #include #include // You'll want the following in mud.h or the file you put these in: char *deepest_parens( char *string ); char *format( char *fmt, ...); char *str_replace( char *string, char *word, char *newword ); void add_letter( char *string, char letter); char *catenate( char *txt, int length, bool color ); char *strip_spaces( char *str ); // You'll need this one at the top of magic.c if you don't put it in in mud.h char *die_parse(CHAR_DATA *ch, CHAR_DATA *victim, int level, char *exp); /* This it the main guts. It will handle all the fun junk. */ char *die_parse(CHAR_DATA *ch, int level, char *exp) { static char outbuf[MAX_STRING_LENGTH]; int x; char *string; char buf[MAX_STRING_LENGTH]; char workingstring[MAX_STRING_LENGTH]; char *pointer; strcpy( buf, exp); string = buf; // non destructive to arg sprintf( workingstring, "%s", strip_spaces(string)); //We ll be performing our replacements on this. while ( (pointer = deepest_parens( workingstring)) != workingstring) // Continue parsing until nothing left to parse { char throwaway[MIL]; strcpy( throwaway, pointer); // rd destroys throwaway so we need to preserve the original string. x = rd_parse( ch, level, throwaway); // Calculate the value of the section we've taken. /* This then replaces in the original string, the entire parenthetical portion we've extracted with just it's calculated value. Because we've stripped out all spaces we can safely assume it began and end with ( ) and no spaces. */ sprintf( workingstring, "%s", str_replace( workingstring, format( "(%s)", pointer), itoa(x) ) ); } sprintf( outbuf, "%s", workingstring); return outbuf; } char *deepest_parens( char *string ) { static char outbuf[MAX_STRING_LENGTH]; int x, end=0, position=0; outbuf[0] = '\0'; if (string[0] == '\0') return string; for ( x = 0; string[x] != '\0'; x++) { if ( string[x] == ')' ) { end = x; // Stop here and recurse to opening break; } } if (end == 0) return string; // No parens for ( x = end; x > 0; x--) { if ( string[x] == '(' ) { position = UMAX( 1, x+1); // We found it. break; } } if (end) { for ( x = position == 0 ? 1 : position; x < end; x++) // Never should be a 0 because we're cutting around the ( and there can't be a ( at negative 1 add_letter( outbuf, string[x]); return outbuf; } return string; } /* Everything below this point is all purpose utilities you may already have, or have your own version of. If you understand them and have your own, feel free to replace thier calls. If you don't understand them, it's best to just include them. */ char *format( char *fmt, ...) { static char newstring[MAX_INPUT_LENGTH]; char buf[MAX_STRING_LENGTH*2]; /* better safe than sorry */ va_list args; newstring[0] = '\0'; if (fmt[0] == '\0') return " "; va_start(args, fmt); vsprintf(buf, fmt, args); va_end(args); if (buf[0] == '\0') return " "; strcpy( newstring, buf); return newstring; } void add_letter( char *string, char letter) { char buf[MIL]; sprintf(buf, "%c", letter); strcat(string, buf); return; } char *str_replace( char *string, char *word, char *newword ) { static char outbuf[MAX_STRING_LENGTH]; char *pos=NULL, *end=NULL, *start=NULL; if ( (pos = strstr( string, word ) ) != NULL) { start = catenate( string, (strlen(string)-strlen(pos)), TRUE); end = pos + strlen( word ); sprintf( outbuf, "%s%s%s", start, newword, end ); return outbuf; } return string; } char *itoa(int foo) { static char bar[256]; sprintf(bar,"%d",foo); return(bar); } char *catenate( char *txt, int length, bool color ) { static char newstring[MAX_INPUT_LENGTH]; int x=0, i; bool skipnext = FALSE; if ( !txt) return ""; newstring[0] = '\0'; for ( i = 0; txt[i] != '\0'; i++ ) { if (x >= length) break; if (skipnext) { skipnext = FALSE; if (color) add_letter(newstring, txt[i]); continue; } else if (txt[i] == '&' || txt[i] == '^') { if (color) add_letter(newstring, txt[i]); skipnext = TRUE; continue; } else add_letter(newstring, txt[i]); x++; } return newstring; } char *strip_spaces( char *str ) { static char newstr[MAX_STRING_LENGTH]; int i, j; for ( i=j=0; str[i] != '\0'; i++ ) if ( str[i] != ' ' ) { newstr[j++] = str[i]; } newstr[j] = '\0'; return newstr; }