1 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/include/color.h nethack-3.4.3-menucolors/include/color.h
2 --- nethack-3.4.3-orig/include/color.h 2006-08-08 23:07:19.000000000 +0300
3 +++ nethack-3.4.3-menucolors/include/color.h 2005-02-18 18:01:56.000000000 +0200
9 +# ifdef MENU_COLOR_REGEX
15 * The color scheme used is tailored for an IBM PC. It consists of the
16 * standard 8 colors, folowed by their bright counterparts. There are
18 #define DRAGON_SILVER CLR_BRIGHT_CYAN
19 #define HI_ZAP CLR_BRIGHT_BLUE
22 +struct menucoloring {
23 +# ifdef MENU_COLOR_REGEX
24 +# ifdef MENU_COLOR_REGEX_POSIX
27 + struct re_pattern_buffer match;
33 + struct menucoloring *next;
35 +#endif /* MENU_COLOR */
38 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/include/config.h nethack-3.4.3-menucolors/include/config.h
39 --- nethack-3.4.3-orig/include/config.h 2006-08-08 23:07:19.000000000 +0300
40 +++ nethack-3.4.3-menucolors/include/config.h 2006-09-20 23:25:49.000000000 +0300
45 +#if defined(TTY_GRAPHICS) || defined(MSWIN_GRAPHICS)
47 +# define MENU_COLOR_REGEX
48 +/*# define MENU_COLOR_REGEX_POSIX */
49 +/* if MENU_COLOR_REGEX is defined, use regular expressions (regex.h,
50 + * GNU specific functions by default, POSIX functions with
51 + * MENU_COLOR_REGEX_POSIX).
52 + * otherwise use pmatch() to match menu color lines.
53 + * pmatch() provides basic globbing: '*' and '?' wildcards.
57 /*#define GOLDOBJ */ /* Gold is kept on obj chains - Helge Hafting */
58 /*#define AUTOPICKUP_EXCEPTIONS */ /* exceptions to autopickup */
60 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/include/extern.h nethack-3.4.3-menucolors/include/extern.h
61 --- nethack-3.4.3-orig/include/extern.h 2006-08-08 23:07:19.000000000 +0300
62 +++ nethack-3.4.3-menucolors/include/extern.h 2005-02-18 18:01:56.000000000 +0200
64 E int FDECL(add_autopickup_exception, (const char *));
65 E void NDECL(free_autopickup_exceptions);
66 #endif /* AUTOPICKUP_EXCEPTIONS */
68 +E boolean FDECL(add_menu_coloring, (char *));
69 +#endif /* MENU_COLOR */
73 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/include/flag.h nethack-3.4.3-menucolors/include/flag.h
74 --- nethack-3.4.3-orig/include/flag.h 2006-08-08 23:07:19.000000000 +0300
75 +++ nethack-3.4.3-menucolors/include/flag.h 2005-02-18 18:01:56.000000000 +0200
77 char prevmsg_window; /* type of old message window to use */
78 boolean extmenu; /* extended commands use menu interface */
81 + boolean use_menu_color; /* use color in menus; only if wc_color */
84 boolean checkspace; /* check disk space before writing files */
85 /* (in iflags to allow restore after moving
86 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/README.menucolor nethack-3.4.3-menucolors/README.menucolor
87 --- nethack-3.4.3-orig/README.menucolor 1970-01-01 02:00:00.000000000 +0200
88 +++ nethack-3.4.3-menucolors/README.menucolor 2006-09-20 23:27:08.000000000 +0300
91 + This is version 1.5 of the menucolors patch.
93 + This patch allows the user to define in what color menus are shown.
94 + For example, putting
97 + MENUCOLOR=" blessed "=green
98 + MENUCOLOR=" holy "=green
99 + MENUCOLOR=" cursed "=red
100 + MENUCOLOR=" unholy "=red
101 + MENUCOLOR=" cursed .* (being worn)"=orange&underline
103 + in the configuration file makes all known blessed items
104 + show up in green, all cursed items show up in red and
105 + all cursed worn items show up in orange and underlined
106 + when viewing inventory.
108 + If you have regex.h but it is not GNU (e.g. DJGPP, *BSD), uncomment
109 + #define MENU_COLOR_REGEX_POSIX in include/config.h
111 + If you do not have regex.h, comment
112 + #define MENU_COLOR_REGEX out from include/config.h
113 + and replace the MENUCOLOR lines in your config file with these:
115 + MENUCOLOR="* blessed *"=green
116 + MENUCOLOR="* holy *"=green
117 + MENUCOLOR="* cursed *"=red
118 + MENUCOLOR="* unholy *"=red
119 + MENUCOLOR="* cursed * (being worn)"=orange&underline
122 + Colors: black, red, green, brown, blue, magenta, cyan, gray, orange,
123 + lightgreen, yellow, lightblue, lightmagenta, lightcyan, white.
124 + Attributes: none, bold, dim, underline, blink, inverse.
126 + Note that the terminal is free to interpret the attributes however
132 + o Only works with TTY and Windows GUI.
133 + o You can't use '=' or '&' in the match-string.
134 + o Maybe add color-field to tty_menu_item in include/wintty.h
135 + (so there's no need to find the color for the line again)
136 + o Guidebook is not up to date
137 + o Better place to put the functions, colornames[] and attrnames[]?
138 + o Some menus do not need coloring; maybe add new parameter
139 + to process_menu_window()?
145 + o Partial support for Windows GUI windowport; supports colors,
146 + but not attributes.
149 + o Option to use standard instead of GNU regex functions.
152 + o Updated to use 3.4.3 codebase.
153 + o Added a text to #version to show menucolors is compiled in.
156 + o Updated to use 3.4.2 codebase.
159 + o Updated to use 3.4.1 codebase.
160 + o replaced USE_REGEX_MATCH with MENU_COLOR_REGEX
163 + o Oops! 1.03 worked only on *nixes... (GNU regex.h)
164 + o Compile-time option USE_REGEX_MATCH: if it's defined, use regex,
165 + otherwise use globbing. ('?' and '*' wildcards)
169 + o Now using Nethack 3.4.0 codebase
170 + o Compile-time option MENU_COLOR
171 + o Strings match using regular expressions instead of globbing
172 + o You can use attribute with color (attr must come after '&')
173 + o Use ``MENUCOLOR="foo"=color'' instead of ``OPTIONS=menucolor=...''
174 + (Both work, but OPTIONS complains if you define menucolor
179 + o Should now work with OS/2, thanks to Jukka Lahtinen
180 + o Strings match now using simple globbing. ('?' and '*' wildcards)
184 + o Moved 'menucolors' boolean option, so now the options-menu
185 + is in alphabetical order.
186 + o Fixed 'menucolor' description in dat/opthelp.
187 + o menu_colorings is now initialized to null in src/decl.c.
196 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/src/decl.c nethack-3.4.3-menucolors/src/decl.c
197 --- nethack-3.4.3-orig/src/decl.c 2006-08-08 23:07:19.000000000 +0300
198 +++ nethack-3.4.3-menucolors/src/decl.c 2005-02-18 18:01:56.000000000 +0200
200 "white", /* CLR_WHITE */
204 +struct menucoloring *menu_colorings = 0;
207 struct c_common_strings c_common_strings = {
208 "Nothing happens.", "That's enough tries!",
209 "That is a silly thing to %s.", "shudder for a moment.",
210 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/src/files.c nethack-3.4.3-menucolors/src/files.c
211 --- nethack-3.4.3-orig/src/files.c 2006-08-08 23:07:19.000000000 +0300
212 +++ nethack-3.4.3-menucolors/src/files.c 2005-02-18 18:01:56.000000000 +0200
213 @@ -1794,6 +1794,10 @@
214 } else if (match_varname(buf, "BOULDER", 3)) {
215 (void) get_uchars(fp, buf, bufp, &iflags.bouldersym, TRUE,
217 + } else if (match_varname(buf, "MENUCOLOR", 9)) {
219 + (void) add_menu_coloring(bufp);
221 } else if (match_varname(buf, "GRAPHICS", 4)) {
222 len = get_uchars(fp, buf, bufp, translate, FALSE,
223 MAXPCHARS, "GRAPHICS");
224 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/src/options.c nethack-3.4.3-menucolors/src/options.c
225 --- nethack-3.4.3-orig/src/options.c 2006-08-08 23:07:19.000000000 +0300
226 +++ nethack-3.4.3-menucolors/src/options.c 2005-02-18 18:01:56.000000000 +0200
229 {"mail", (boolean *)0, TRUE, SET_IN_FILE},
233 + {"menucolors", &iflags.use_menu_color, TRUE, SET_IN_GAME},
235 + {"menucolors", &iflags.use_menu_color, FALSE, SET_IN_GAME},
238 + {"menucolors", (boolean *)0, FALSE, SET_IN_GAME},
241 /* for menu debugging only*/
242 {"menu_tab_sep", &iflags.menu_tab_sep, FALSE, SET_IN_GAME},
244 { "horsename", "the name of your (first) horse (e.g., horsename:Silver)",
245 PL_PSIZ, DISP_IN_GAME },
246 { "map_mode", "map display mode under Windows", 20, DISP_IN_GAME }, /*WC*/
247 + { "menucolor", "set menu colors", PL_PSIZ, SET_IN_FILE },
248 { "menustyle", "user interface for object selection",
249 MENUTYPELEN, SET_IN_GAME },
250 { "menu_deselect_all", "deselect all items in a menu", 4, SET_IN_FILE },
251 @@ -964,6 +974,133 @@
256 +extern struct menucoloring *menu_colorings;
258 +static const struct {
262 + {"black", CLR_BLACK},
264 + {"green", CLR_GREEN},
265 + {"brown", CLR_BROWN},
266 + {"blue", CLR_BLUE},
267 + {"magenta", CLR_MAGENTA},
268 + {"cyan", CLR_CYAN},
269 + {"gray", CLR_GRAY},
270 + {"orange", CLR_ORANGE},
271 + {"lightgreen", CLR_BRIGHT_GREEN},
272 + {"yellow", CLR_YELLOW},
273 + {"lightblue", CLR_BRIGHT_BLUE},
274 + {"lightmagenta", CLR_BRIGHT_MAGENTA},
275 + {"lightcyan", CLR_BRIGHT_CYAN},
276 + {"white", CLR_WHITE}
279 +static const struct {
283 + {"none", ATR_NONE},
284 + {"bold", ATR_BOLD},
286 + {"underline", ATR_ULINE},
287 + {"blink", ATR_BLINK},
288 + {"inverse", ATR_INVERSE}
292 +/* parse '"regex_string"=color&attr' and add it to menucoloring */
294 +add_menu_coloring(str)
297 + int i, c = NO_COLOR, a = ATR_NONE;
298 + struct menucoloring *tmp;
299 + char *tmps, *cs = strchr(str, '=');
300 +#ifdef MENU_COLOR_REGEX_POSIX
304 + const char *err = (char *)0;
306 + if (!cs || !str) return FALSE;
310 + while (*tmps && isspace(*tmps)) tmps++;
312 + for (i = 0; i < SIZE(colornames); i++)
313 + if (strstri(tmps, colornames[i].name) == tmps) {
314 + c = colornames[i].color;
317 + if ((i == SIZE(colornames)) && (*tmps >= '0' && *tmps <='9'))
320 + if (c > 15) return FALSE;
322 + tmps = strchr(str, '&');
325 + while (*tmps && isspace(*tmps)) tmps++;
326 + for (i = 0; i < SIZE(attrnames); i++)
327 + if (strstri(tmps, attrnames[i].name) == tmps) {
328 + a = attrnames[i].attr;
331 + if ((i == SIZE(attrnames)) && (*tmps >= '0' && *tmps <='9'))
337 + if ((*tmps == '"') || (*tmps == '\'')) {
339 + while (isspace(*cs)) cs--;
340 + if (*cs == *tmps) {
346 + tmp = (struct menucoloring *)alloc(sizeof(struct menucoloring));
347 +#ifdef MENU_COLOR_REGEX
348 +#ifdef MENU_COLOR_REGEX_POSIX
349 + errnum = regcomp(&tmp->match, tmps, REG_EXTENDED | REG_NOSUB);
352 + regerror(errnum, &tmp->match, errbuf, sizeof(errbuf));
356 + tmp->match.translate = 0;
357 + tmp->match.fastmap = 0;
358 + tmp->match.buffer = 0;
359 + tmp->match.allocated = 0;
360 + tmp->match.regs_allocated = REGS_FIXED;
361 + err = re_compile_pattern(tmps, strlen(tmps), &tmp->match);
364 + tmp->match = (char *)alloc(strlen(tmps)+1);
365 + (void) memcpy((genericptr_t)tmp->match, (genericptr_t)tmps, strlen(tmps)+1);
368 + raw_printf("\nMenucolor regex error: %s\n", err);
373 + tmp->next = menu_colorings;
376 + menu_colorings = tmp;
380 +#endif /* MENU_COLOR */
383 parseoptions(opts, tinitial, tfrom_file)
385 @@ -1133,6 +1270,18 @@
389 + /* menucolor:"regex_string"=color */
390 + fullname = "menucolor";
391 + if (match_optname(opts, fullname, 9, TRUE)) {
393 + if (negated) bad_negation(fullname, FALSE);
394 + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0)
395 + if (!add_menu_coloring(op))
401 fullname = "msghistory";
402 if (match_optname(opts, fullname, 3, TRUE)) {
403 op = string_for_env_opt(fullname, opts, negated);
404 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/src/save.c nethack-3.4.3-menucolors/src/save.c
405 --- nethack-3.4.3-orig/src/save.c 2006-08-08 23:07:19.000000000 +0300
406 +++ nethack-3.4.3-menucolors/src/save.c 2005-02-18 18:01:56.000000000 +0200
412 +extern struct menucoloring *menu_colorings;
415 /* need to preserve these during save to avoid accessing freed memory */
416 static unsigned ustuck_id = 0, usteed_id = 0;
418 @@ -953,12 +957,34 @@
424 +free_menu_coloring()
426 + struct menucoloring *tmp = menu_colorings;
429 + struct menucoloring *tmp2 = tmp->next;
430 +# ifdef MENU_COLOR_REGEX
431 + (void) regfree(&tmp->match);
439 +#endif /* MENU_COLOR */
445 free_invbuf(); /* let_to_name (invent.c) */
446 free_youbuf(); /* You_buf,&c (pline.c) */
448 + free_menu_coloring();
450 tmp_at(DISP_FREEMEM, 0); /* temporary display effects */
451 #ifdef FREE_ALL_MEMORY
452 # define freeobjchn(X) (saveobjchn(0, X, FREE_SAVE), X = 0)
453 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/util/makedefs.c nethack-3.4.3-menucolors/util/makedefs.c
454 --- nethack-3.4.3-orig/util/makedefs.c 2006-08-08 23:07:20.000000000 +0300
455 +++ nethack-3.4.3-menucolors/util/makedefs.c 2005-02-18 18:01:56.000000000 +0200
461 +# ifdef MENU_COLOR_REGEX
462 + "menu colors via regular expressions",
464 + "menu colors via pmatch",
468 "MSDOS protected mode",
470 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/win/tty/wintty.c nethack-3.4.3-menucolors/win/tty/wintty.c
471 --- nethack-3.4.3-orig/win/tty/wintty.c 2006-08-08 23:07:20.000000000 +0300
472 +++ nethack-3.4.3-menucolors/win/tty/wintty.c 2005-02-18 18:01:57.000000000 +0200
474 static char winpanicstr[] = "Bad window id %d";
475 char defmorestr[] = "--More--";
478 +extern struct menucoloring *menu_colorings;
482 # if defined(USE_TILES) && defined(MSDOS)
483 boolean clipping = FALSE; /* clipping on? */
484 @@ -1128,6 +1132,32 @@
490 +get_menu_coloring(str, color, attr)
494 + struct menucoloring *tmpmc;
495 + if (iflags.use_menu_color)
496 + for (tmpmc = menu_colorings; tmpmc; tmpmc = tmpmc->next)
497 +# ifdef MENU_COLOR_REGEX
498 +# ifdef MENU_COLOR_REGEX_POSIX
499 + if (regexec(&tmpmc->match, str, 0, NULL, 0) == 0) {
501 + if (re_search(&tmpmc->match, str, strlen(str), 0, 9999, 0) >= 0) {
504 + if (pmatch(tmpmc->match, str)) {
506 + *color = tmpmc->color;
507 + *attr = tmpmc->attr;
512 +#endif /* MENU_COLOR */
515 process_menu_window(window, cw)
517 @@ -1204,6 +1234,10 @@
518 for (page_lines = 0, curr = page_start;
520 page_lines++, curr = curr->next) {
522 + int color = NO_COLOR, attr = ATR_NONE;
523 + boolean menucolr = FALSE;
526 *rp++ = curr->selector;
528 @@ -1219,6 +1253,13 @@
529 * actually output the character. We're faster doing
533 + if (iflags.use_menu_color &&
534 + (menucolr = get_menu_coloring(curr->str, &color,&attr))) {
535 + term_start_attr(attr);
536 + if (color != NO_COLOR) term_start_color(color);
539 term_start_attr(curr->attr);
540 for (n = 0, cp = curr->str;
542 @@ -1236,6 +1277,12 @@
543 (void) putchar('#'); /* count selected */
547 + if (iflags.use_menu_color && menucolr) {
548 + if (color != NO_COLOR) term_end_color();
549 + term_end_attr(attr);
552 term_end_attr(curr->attr);
555 diff -Nurd --exclude-from=diff_ignore_files.txt nethack-3.4.3-orig/win/win32/mhmenu.c nethack-3.4.3-menucolors/win/win32/mhmenu.c
556 --- nethack-3.4.3-orig/win/win32/mhmenu.c 2006-08-08 23:07:20.000000000 +0300
557 +++ nethack-3.4.3-menucolors/win/win32/mhmenu.c 2006-09-20 23:24:21.000000000 +0300
560 extern short glyph2tile[];
563 +extern struct menucoloring *menu_colorings;
566 static WNDPROC wndProcListViewOrig = NULL;
567 static WNDPROC editControlWndProc = NULL;
570 static void reset_menu_count(HWND hwndList, PNHMenuWindow data);
571 static BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch);
574 +/* FIXME: nhcolor_to_RGB copied from mhmap.c */
575 +/* map nethack color to RGB */
576 +COLORREF nhcolor_to_RGB(int c)
579 + case CLR_BLACK: return RGB(0x55, 0x55, 0x55);
580 + case CLR_RED: return RGB(0xFF, 0x00, 0x00);
581 + case CLR_GREEN: return RGB(0x00, 0x80, 0x00);
582 + case CLR_BROWN: return RGB(0xA5, 0x2A, 0x2A);
583 + case CLR_BLUE: return RGB(0x00, 0x00, 0xFF);
584 + case CLR_MAGENTA: return RGB(0xFF, 0x00, 0xFF);
585 + case CLR_CYAN: return RGB(0x00, 0xFF, 0xFF);
586 + case CLR_GRAY: return RGB(0xC0, 0xC0, 0xC0);
587 + case NO_COLOR: return RGB(0xFF, 0xFF, 0xFF);
588 + case CLR_ORANGE: return RGB(0xFF, 0xA5, 0x00);
589 + case CLR_BRIGHT_GREEN: return RGB(0x00, 0xFF, 0x00);
590 + case CLR_YELLOW: return RGB(0xFF, 0xFF, 0x00);
591 + case CLR_BRIGHT_BLUE: return RGB(0x00, 0xC0, 0xFF);
592 + case CLR_BRIGHT_MAGENTA: return RGB(0xFF, 0x80, 0xFF);
593 + case CLR_BRIGHT_CYAN: return RGB(0x80, 0xFF, 0xFF); /* something close to aquamarine */
594 + case CLR_WHITE: return RGB(0xFF, 0xFF, 0xFF);
595 + default: return RGB(0x00, 0x00, 0x00); /* black */
601 +get_menu_coloring(str, color, attr)
605 + struct menucoloring *tmpmc;
606 + if (iflags.use_menu_color)
607 + for (tmpmc = menu_colorings; tmpmc; tmpmc = tmpmc->next)
608 +# ifdef MENU_COLOR_REGEX
609 +# ifdef MENU_COLOR_REGEX_POSIX
610 + if (regexec(&tmpmc->match, str, 0, NULL, 0) == 0) {
612 + if (re_search(&tmpmc->match, str, strlen(str), 0, 9999, 0) >= 0) {
615 + if (pmatch(tmpmc->match, str)) {
617 + *color = tmpmc->color;
618 + *attr = tmpmc->attr;
623 +#endif /* MENU_COLOR */
625 /*-----------------------------------------------------------------------------*/
626 HWND mswin_init_menu_window (int type) {
633 + int color = NO_COLOR, attr;
634 + boolean menucolr = FALSE;
637 lpdis = (LPDRAWITEMSTRUCT) lParam;
639 /* If there are no list box items, skip this message. */
641 buf[0] = item->accelerator;
645 + if (iflags.use_menu_color &&
646 + (menucolr = get_menu_coloring(item->str, &color,&attr))) {
647 + /* TODO: use attr too */
648 + if (color != NO_COLOR)
649 + SetTextColor(lpdis->hDC, nhcolor_to_RGB(color));
653 SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom );
654 DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);