diff -u ../angband-291.orig/src/defines.h src/defines.h --- ../angband-291.orig/src/defines.h Tue Jul 25 14:57:49 2000 +++ src/defines.h Sun Sep 3 16:00:03 2000 @@ -205,6 +205,20 @@ */ #define MESSAGE_BUF 32768 +#ifdef MSG_COLOR_BY_MATCH +/* + * OPTION: Maximum number of message match strings to hold (see "util.c") + * Default: assume at most 256 strings are specified + */ +# define MSGMATCH_MAX 256 + +/* + * OPTION: Maximum space for the message match string buffer (see "util.c") + * Default: allow 64 chars per string + */ +# define MSGMATCH_BUF 16384 +#endif /* MSG_COLOR_BY_MATCH */ + /* * Maximum value storable in a "byte" (hard-coded) @@ -3004,6 +3018,12 @@ # define MESSAGE_MAX 128 # undef MESSAGE_BUF # define MESSAGE_BUF 4096 +#ifdef MSG_COLOR_BY_MATCH +# undef MSGMATCH_MAX +# define MSGMATCH_MAX 64 +# undef MSGMATCH_BUF +# define MSGMATCH_BUF 4096 +#endif /* MSG_COLOR_BY_MATCH */ #endif diff -u ../angband-291.orig/src/externs.h src/externs.h --- ../angband-291.orig/src/externs.h Tue Jul 25 14:57:49 2000 +++ src/externs.h Sun Sep 3 16:06:40 2000 @@ -143,6 +143,13 @@ extern char *message__buf; extern u16b *message__type; extern byte message__color[MSG_MAX]; +#ifdef MSG_COLOR_BY_MATCH +extern s16b msgmatch__num; +extern u16b *msgmatch__ptr; +extern char *msgmatch__buf; +extern byte *msgmatch__color; +extern u16b msgmatch__tail; +#endif /* MSG_COLOR_BY_MATCH */ extern term *angband_term[8]; extern char angband_term_name[8][16]; extern byte angband_color_table[256][4]; @@ -684,6 +691,9 @@ extern u16b message_type(s16b age); extern byte message_color(s16b age); extern void message_add(cptr str, u16b type); +#ifdef MSG_COLOR_BY_MATCH +extern errr msgmatch_add(cptr str, byte color); +#endif extern errr message_init(void); extern void move_cursor(int row, int col); extern void msg_print(cptr msg); diff -u ../angband-291.orig/src/files.c src/files.c --- ../angband-291.orig/src/files.c Tue Jul 25 14:57:48 2000 +++ src/files.c Sun Sep 3 15:31:39 2000 @@ -532,6 +532,17 @@ u16b type = (u16b)strtol(zz[0], NULL, 0); byte color = color_char_to_attr(zz[1][0]); +#ifdef MSG_COLOR_BY_MATCH + /* + * Mega-Hack -- If the message type is not a + * number, assume it's a match string. + */ + if (!isdigit(zz[0][0])) + { + return msgmatch_add(zz[0], color); + } +#endif /* MSG_COLOR_BY_MATCH */ + /* Ignore illegal types */ if (type >= MSG_MAX) return (1); diff -u ../angband-291.orig/src/util.c src/util.c --- ../angband-291.orig/src/util.c Tue Jul 25 14:57:49 2000 +++ src/util.c Sun Sep 10 16:36:40 2000 @@ -1950,8 +1950,8 @@ { s16b x; - /* Forgotten messages have no special color */ - if ((age < 0) || (age >= message_num())) return (TERM_WHITE); + /* Forgotten messages have no special type */ + if ((age < 0) || (age >= message_num())) return (MSG_GENERIC); /* Get the "logical" index */ x = (message__next + MESSAGE_MAX - (age + 1)) % MESSAGE_MAX; @@ -1966,7 +1966,11 @@ */ byte message_color(s16b age) { - return message__color[message_type(age)]; + u16b type = message_type(age); + + if (type >= MSG_MAX) + return type - MSG_MAX; + return message__color[type]; } @@ -2185,6 +2189,17 @@ /* Hack -- No messages yet */ message__tail = MESSAGE_BUF; +#ifdef MSG_COLOR_BY_MATCH + /* Message match string variables */ + C_MAKE(msgmatch__ptr, MSGMATCH_MAX, u16b); + C_MAKE(msgmatch__buf, MSGMATCH_BUF, char); + C_MAKE(msgmatch__color, MSGMATCH_MAX, byte); + + /* Hack -- No message match strings yet */ + msgmatch__num = 0; + msgmatch__tail = 0; +#endif /* MSG_COLOR_BY_MATCH */ + /* Success */ return (0); } @@ -2335,6 +2350,30 @@ if (n > 1000) return; +#ifdef MSG_COLOR_BY_MATCH + /* + * Mega-Hack -- If any of the user-supplied substrings match, set + * the message type to a pseudo-type code containing the user's + * chosen color. + */ + if (msgmatch__num > 0) + { + int i; + u16b o; + + for (i = 0; i < msgmatch__num; i++) + { + o = msgmatch__ptr[i]; + if (strstr(msg, msgmatch__buf + o)) + { + /* Found a match, set the pseudo-type */ + type = MSG_MAX + msgmatch__color[i]; + break; + } + } + } +#endif /* MSG_COLOR_BY_MATCH */ + /* Memorize the message (if legal) */ if (character_generated && !(p_ptr->is_dead)) message_add(msg, type); @@ -2362,7 +2401,16 @@ /* Get the color of the message (if legal) */ if (message__color) +#ifdef MSG_COLOR_BY_MATCH + { + if (type >= MSG_MAX) + color = type - MSG_MAX; + else +#endif color = message__color[type]; +#ifdef MSG_COLOR_BY_MATCH + } +#endif /* HACK -- no "black" messages */ if (color == TERM_DARK) color = TERM_WHITE; @@ -2463,6 +2511,44 @@ msg_print_aux(message_type, message); } + + +#ifdef MSG_COLOR_BY_MATCH +errr msgmatch_add(cptr str, byte color) +{ + int n; + cptr u; + char *v; + + /* Hack -- Ignore "non-messages" */ + if (!str || !*str) return 1; + + /* Message length */ + n = strlen(str); + + /* Punt if we're out of space */ + if (msgmatch__num >= MSGMATCH_MAX) return (1); + if (n > MSGMATCH_BUF - msgmatch__tail) return (1); + + /* Inline 'strcpy(msgmatch__buf + msgmatch__tail, str)' */ + v = msgmatch__buf + msgmatch__tail; + for (u = str; *u; ) *v++ = *u++; + *v = '\0'; + + /* Assign the starting address and color */ + msgmatch__ptr[msgmatch__num] = msgmatch__tail; + msgmatch__color[msgmatch__num] = color; + + /* Advance message count */ + msgmatch__num++; + + /* Advance the "tail" pointer */ + msgmatch__tail += (n + 1); + + /* Success */ + return (0); +} +#endif /* MSG_COLOR_BY_MATCH */ diff -u ../angband-291.orig/src/variable.c src/variable.c --- ../angband-291.orig/src/variable.c Tue Jul 25 14:57:49 2000 +++ src/variable.c Sun Sep 3 16:05:13 2000 @@ -211,6 +211,36 @@ u16b *message__type; +#ifdef MSG_COLOR_BY_MATCH + +/* + * Number of active message match strings. + */ +s16b msgmatch__num; + +/* + * The array[MSGMATCH_MAX] of offsets, by index + */ +u16b *msgmatch__ptr; + +/* + * The array[MSGMATCH_BUF] of chars, by offset + */ +char *msgmatch__buf; + +/* + * The array[MSGMATCH_MAX] of colors associated with message match strings + */ +byte *msgmatch__color; + +/* + * The offset of the remaining free space in the buffer + */ +u16b msgmatch__tail; + +#endif /* MSG_COLOR_BY_MATCH */ + + /* * Table of colors associated to message-types */