Document explicitly what m-prefix does to each command
[aNetHack.git] / win / chain / wc_trace.c
blob9073e062a993aa41b9cb1e75bf99d5c83670845b
1 /* NetHack 3.6 wc_trace.c $NHDT-Date: 1433806611 2015/06/08 23:36:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
2 /* Copyright (c) Kenneth Lorber, 2012 */
3 /* NetHack may be freely redistributed. See license for details. */
5 #include "hack.h"
6 #include "wintty.h"
7 #include "func_tab.h"
9 #include <ctype.h>
10 #include <errno.h>
12 FILE *wc_tracelogf; /* Should be static, but it's just too useful to have
13 * access to this logfile from arbitrary other files. */
14 static unsigned int indent_level; /* Some winfuncs call other winfuncs, so
15 * we need to support nesting. */
17 static char indentdata[10] = " ";
18 #define ISCALE 1
19 #if 1
20 #define INDENT \
21 &indentdata[((indent_level * ISCALE) < (sizeof(indentdata))) \
22 ? ((sizeof(indentdata) - 1) - (indent_level * ISCALE)) \
23 : 0]
24 #else
25 /* for debugging this file */
26 #define INDENT \
27 ({ \
28 static char buf[50]; \
29 sprintf(buf, "[%s:%d %d]\t", __func__, __LINE__, indent_level); \
30 buf; \
32 #endif
33 #define PRE indent_level++
34 #define POST indent_level--
36 struct trace_data {
37 struct chain_procs *nprocs;
38 void *ndata;
40 int linknum;
43 void *
44 trace_procs_chain(cmd, n, me, nextprocs, nextdata)
45 int cmd;
46 int n;
47 void *me;
48 void *nextprocs;
49 void *nextdata;
51 switch (cmd) {
52 case WINCHAIN_ALLOC: {
53 struct trace_data *tdp = calloc(1, sizeof(struct trace_data));
54 tdp->linknum = n;
55 return tdp;
57 case WINCHAIN_INIT: {
58 struct trace_data *tdp = me;
59 tdp->nprocs = nextprocs;
60 tdp->ndata = nextdata;
61 return tdp;
63 default:
64 raw_printf("trace_procs_chain: bad cmd\n");
65 exit(EXIT_FAILURE);
69 void
70 trace_procs_init(dir)
71 int dir;
73 char fname[200];
75 /* processors shouldn't need this test, but just in case */
76 if (dir != WININIT)
77 return;
79 sprintf(fname, "%s/tlog.%d", HACKDIR, getpid());
80 wc_tracelogf = fopen(fname, "w");
81 if (wc_tracelogf == NULL) {
82 fprintf(stderr, "Can't open trace log file %s: %s\n", fname,
83 strerror(errno));
84 exit(EXIT_FAILURE);
86 setvbuf(wc_tracelogf, (char *) NULL, _IONBF, 0);
87 fprintf(wc_tracelogf, "Trace log started for pid %d\n", getpid());
89 indent_level = 0;
92 /***
93 *** winprocs
94 ***/
96 void
97 trace_init_nhwindows(vp, argcp, argv)
98 void *vp;
99 int *argcp;
100 char **argv;
102 struct trace_data *tdp = vp;
104 fprintf(wc_tracelogf, "%sinit_nhwindows(%d,*)\n", INDENT, *argcp);
106 PRE;
107 (*tdp->nprocs->win_init_nhwindows)(tdp->ndata, argcp, argv);
108 POST;
111 void
112 trace_player_selection(vp)
113 void *vp;
115 struct trace_data *tdp = vp;
116 fprintf(wc_tracelogf, "%splayer_selection()\n", INDENT);
118 PRE;
119 (*tdp->nprocs->win_player_selection)(tdp->ndata);
120 POST;
123 void
124 trace_askname(vp)
125 void *vp;
127 struct trace_data *tdp = vp;
128 fprintf(wc_tracelogf, "%saskname()\n", INDENT);
130 PRE;
131 (*tdp->nprocs->win_askname)(tdp->ndata);
132 POST;
135 void
136 trace_get_nh_event(vp)
137 void *vp;
139 struct trace_data *tdp = vp;
140 fprintf(wc_tracelogf, "%sget_nh_event()\n", INDENT);
142 PRE;
143 (*tdp->nprocs->win_get_nh_event)(tdp->ndata);
144 POST;
147 void
148 trace_exit_nhwindows(vp, str)
149 void *vp;
150 const char *str;
152 struct trace_data *tdp = vp;
153 fprintf(wc_tracelogf, "%sexit_nhwindows(%s)\n", INDENT, str);
155 PRE;
156 (*tdp->nprocs->win_exit_nhwindows)(tdp->ndata, str);
157 POST;
160 void
161 trace_suspend_nhwindows(vp, str)
162 void *vp;
163 const char *str;
165 struct trace_data *tdp = vp;
166 fprintf(wc_tracelogf, "%ssuspend_nhwindows(%s)\n", INDENT, str);
168 PRE;
169 (*tdp->nprocs->win_suspend_nhwindows)(tdp->ndata, str);
170 POST;
173 void
174 trace_resume_nhwindows(vp)
175 void *vp;
177 struct trace_data *tdp = vp;
178 fprintf(wc_tracelogf, "%sresume_nhwindows()\n", INDENT);
180 PRE;
181 (*tdp->nprocs->win_resume_nhwindows)(tdp->ndata);
182 POST;
185 static const char *
186 NHWname(type)
187 int type;
189 switch (type) {
190 case NHW_MESSAGE:
191 return "MESSAGE";
192 case NHW_STATUS:
193 return "STATUS";
194 case NHW_MAP:
195 return "MAP";
196 case NHW_MENU:
197 return "MENU";
198 case NHW_TEXT:
199 return "TEXT";
200 case NHW_BASE:
201 return "BASE";
202 default: {
203 static char b[20];
204 sprintf(b, "(%d)", type);
205 return b;
210 winid
211 trace_create_nhwindow(vp, type)
212 void *vp;
213 int type;
215 struct trace_data *tdp = vp;
216 const char *typestring = NHWname(type);
217 winid rv;
219 fprintf(wc_tracelogf, "%screate_nhwindow(%s)\n", INDENT, typestring);
221 PRE;
222 rv = (*tdp->nprocs->win_create_nhwindow)(tdp->ndata, type);
223 POST;
225 fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv);
226 return rv;
229 void
230 trace_clear_nhwindow(vp, window)
231 void *vp;
232 winid window;
234 struct trace_data *tdp = vp;
236 fprintf(wc_tracelogf, "%sclear_nhwindow(%d)\n", INDENT, window);
238 PRE;
239 (*tdp->nprocs->win_clear_nhwindow)(tdp->ndata, window);
240 POST;
243 void
244 trace_display_nhwindow(vp, window, blocking)
245 void *vp;
246 winid window;
247 BOOLEAN_P blocking;
249 struct trace_data *tdp = vp;
251 fprintf(wc_tracelogf, "%sdisplay_nhwindow(%d, %d)\n", INDENT, window,
252 blocking);
254 PRE;
255 (*tdp->nprocs->win_display_nhwindow)(tdp->ndata, window, blocking);
256 POST;
259 void
260 trace_destroy_nhwindow(vp, window)
261 void *vp;
262 winid window;
264 struct trace_data *tdp = vp;
266 fprintf(wc_tracelogf, "%sdestroy_nhwindow(%d)\n", INDENT, window);
268 PRE;
269 (*tdp->nprocs->win_destroy_nhwindow)(tdp->ndata, window);
270 POST;
273 void
274 trace_curs(vp, window, x, y)
275 void *vp;
276 winid window;
277 int x;
278 int y;
280 struct trace_data *tdp = vp;
282 fprintf(wc_tracelogf, "%scurs(%d, %d, %d)\n", INDENT, window, x, y);
284 PRE;
285 (*tdp->nprocs->win_curs)(tdp->ndata, window, x, y);
286 POST;
289 void
290 trace_putstr(vp, window, attr, str)
291 void *vp;
292 winid window;
293 int attr;
294 const char *str;
296 struct trace_data *tdp = vp;
298 if (str) {
299 fprintf(wc_tracelogf, "%sputstr(%d, %d, '%s'(%d))\n", INDENT, window,
300 attr, str, (int) strlen(str));
301 } else {
302 fprintf(wc_tracelogf, "%sputstr(%d, %d, NULL)\n", INDENT, window,
303 attr);
306 PRE;
307 (*tdp->nprocs->win_putstr)(tdp->ndata, window, attr, str);
308 POST;
311 void
312 trace_putmixed(vp, window, attr, str)
313 void *vp;
314 winid window;
315 int attr;
316 const char *str;
318 struct trace_data *tdp = vp;
320 if (str) {
321 fprintf(wc_tracelogf, "%sputmixed(%d, %d, '%s'(%d))\n", INDENT,
322 window, attr, str, (int) strlen(str));
323 } else {
324 fprintf(wc_tracelogf, "%sputmixed(%d, %d, NULL)\n", INDENT, window,
325 attr);
328 PRE;
329 (*tdp->nprocs->win_putmixed)(tdp->ndata, window, attr, str);
330 POST;
333 void
334 trace_display_file(vp, fname, complain)
335 void *vp;
336 const char *fname;
337 boolean complain;
339 struct trace_data *tdp = vp;
341 if (fname) {
342 fprintf(wc_tracelogf, "%sdisplay_file('%s'(%d), %d)\n", INDENT, fname,
343 (int) strlen(fname), complain);
344 } else {
345 fprintf(wc_tracelogf, "%sdisplay_file(NULL, %d)\n", INDENT, complain);
348 PRE;
349 (*tdp->nprocs->win_display_file)(tdp->ndata, fname, complain);
350 POST;
353 void
354 trace_start_menu(vp, window)
355 void *vp;
356 winid window;
358 struct trace_data *tdp = vp;
360 fprintf(wc_tracelogf, "%sstart_menu(%d)\n", INDENT, window);
362 PRE;
363 (*tdp->nprocs->win_start_menu)(tdp->ndata, window);
364 POST;
367 void
368 trace_add_menu(vp, window, glyph, identifier, ch, gch, attr, str, preselected)
369 void *vp;
370 winid window; /* window to use, must be of type NHW_MENU */
371 int glyph; /* glyph to display with item (unused) */
372 const anything *identifier; /* what to return if selected */
373 char ch; /* keyboard accelerator (0 = pick our own) */
374 char gch; /* group accelerator (0 = no group) */
375 int attr; /* attribute for string (like tty_putstr()) */
376 const char *str; /* menu string */
377 boolean preselected; /* item is marked as selected */
379 struct trace_data *tdp = vp;
381 char buf_ch[10];
382 char buf_gch[10];
384 if (isprint(ch)) {
385 sprintf(buf_ch, "'%c'(%d)", ch, ch);
386 } else {
387 sprintf(buf_ch, "(%d)", ch);
390 if (isprint(gch)) {
391 sprintf(buf_gch, "'%c'(%d)", gch, gch);
392 } else {
393 sprintf(buf_gch, "(%d)", gch);
396 if (str) {
397 fprintf(wc_tracelogf,
398 "%sadd_menu(%d, %d, %p, %s, %s, %d, '%s'(%d), %d)\n", INDENT,
399 window, glyph, (void *) identifier, buf_ch, buf_gch, attr,
400 str, (int) strlen(str), preselected);
401 } else {
402 fprintf(wc_tracelogf,
403 "%sadd_menu(%d, %d, %p, %s, %s, %d, NULL, %d)\n", INDENT,
404 window, glyph, (void *) identifier, buf_ch, buf_gch, attr,
405 preselected);
408 PRE;
409 (*tdp->nprocs->win_add_menu)(tdp->ndata, window, glyph, identifier, ch,
410 gch, attr, str, preselected);
411 POST;
414 void
415 trace_end_menu(vp, window, prompt)
416 void *vp;
417 winid window;
418 const char *prompt;
420 struct trace_data *tdp = vp;
422 if (prompt) {
423 fprintf(wc_tracelogf, "%send_menu(%d, '%s'(%d))\n", INDENT, window,
424 prompt, (int) strlen(prompt));
425 } else {
426 fprintf(wc_tracelogf, "%send_menu(%d, NULL)\n", INDENT, window);
429 PRE;
430 (*tdp->nprocs->win_end_menu)(tdp->ndata, window, prompt);
431 POST;
435 trace_select_menu(vp, window, how, menu_list)
436 void *vp;
437 winid window;
438 int how;
439 menu_item **menu_list;
441 struct trace_data *tdp = vp;
442 int rv;
444 fprintf(wc_tracelogf, "%sselect_menu(%d, %d, %p)\n", INDENT, window, how,
445 (void *) menu_list);
447 PRE;
448 rv = (*tdp->nprocs->win_select_menu)(tdp->ndata, window, how,
449 (void *) menu_list);
450 POST;
452 fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv);
453 return rv;
456 char
457 trace_message_menu(vp, let, how, mesg)
458 void *vp;
459 char let;
460 int how;
461 const char *mesg;
463 struct trace_data *tdp = vp;
464 char buf_let[10];
465 char rv;
467 if (isprint(let)) {
468 sprintf(buf_let, "'%c'(%d)", let, let);
469 } else {
470 sprintf(buf_let, "(%d)", let);
473 if (mesg) {
474 fprintf(wc_tracelogf, "%smessage_menu(%s, %d, '%s'(%d))\n", INDENT,
475 buf_let, how, mesg, (int) strlen(mesg));
476 } else {
477 fprintf(wc_tracelogf, "%smessage_menu(%s, %d, NULL)\n", INDENT,
478 buf_let, how);
481 PRE;
482 rv = (*tdp->nprocs->win_message_menu)(tdp->ndata, let, how, mesg);
483 POST;
485 if (isprint(rv)) {
486 sprintf(buf_let, "'%c'(%d)", rv, rv);
487 } else {
488 sprintf(buf_let, "(%d)", rv);
490 fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf_let);
492 return rv;
495 void
496 trace_update_inventory(vp)
497 void *vp;
499 struct trace_data *tdp = vp;
501 fprintf(wc_tracelogf, "%supdate_inventory()\n", INDENT);
503 PRE;
504 (*tdp->nprocs->win_update_inventory)(tdp->ndata);
505 POST;
508 void
509 trace_mark_synch(vp)
510 void *vp;
512 struct trace_data *tdp = vp;
514 fprintf(wc_tracelogf, "%smark_synch()\n", INDENT);
516 PRE;
517 (*tdp->nprocs->win_mark_synch)(tdp->ndata);
518 POST;
521 void
522 trace_wait_synch(vp)
523 void *vp;
525 struct trace_data *tdp = vp;
527 fprintf(wc_tracelogf, "%swait_synch()\n", INDENT);
529 PRE;
530 (*tdp->nprocs->win_wait_synch)(tdp->ndata);
531 POST;
534 #ifdef CLIPPING
535 void
536 trace_cliparound(vp, x, y)
537 void *vp;
538 int x;
539 int y;
541 struct trace_data *tdp = vp;
543 fprintf(wc_tracelogf, "%scliparound(%d, %d)\n", INDENT, x, y);
545 PRE;
546 (*tdp->nprocs->win_cliparound)(tdp->ndata, x, y);
547 POST;
549 #endif
551 #ifdef POSITIONBAR
552 void
553 trace_update_positionbar(vp, posbar)
554 void *vp;
555 char *posbar;
557 struct trace_data *tdp = vp;
559 if (posbar) {
560 fprintf(wc_tracelogf, "%supdate_positionbar('%s'(%d))\n", INDENT,
561 posbar, (int) strlen(posbar));
562 } else {
563 fprintf(wc_tracelogf, "%supdate_positionbar(NULL)\n");
565 PRE;
566 (*tdp->nprocs->win_update_positionbar)(tdp->ndata, posbar);
567 POST;
569 #endif
571 /* XXX can we decode the glyph in a meaningful way? see mapglyph()?
572 genl_putmixed? */
573 void
574 trace_print_glyph(vp, window, x, y, glyph, bkglyph)
575 void *vp;
576 winid window;
577 xchar x, y;
578 int glyph, bkglyph;
580 struct trace_data *tdp = vp;
582 fprintf(wc_tracelogf, "%sprint_glyph(%d, %d, %d, %d, %d)\n", INDENT, window,
583 x, y, glyph, bkglyph);
585 PRE;
586 (*tdp->nprocs->win_print_glyph)(tdp->ndata, window, x, y, glyph, bkglyph);
587 POST;
590 void
591 trace_raw_print(vp, str)
592 void *vp;
593 const char *str;
595 struct trace_data *tdp = vp;
597 if (str) {
598 fprintf(wc_tracelogf, "%sraw_print('%s'(%d))\n", INDENT, str,
599 (int) strlen(str));
600 } else {
601 fprintf(wc_tracelogf, "%sraw_print(NULL)\n", INDENT);
604 PRE;
605 (*tdp->nprocs->win_raw_print)(tdp->ndata, str);
606 POST;
609 void
610 trace_raw_print_bold(vp, str)
611 void *vp;
612 const char *str;
614 struct trace_data *tdp = vp;
616 if (str) {
617 fprintf(wc_tracelogf, "%sraw_print_bold('%s'(%d))\n", INDENT, str,
618 (int) strlen(str));
619 } else {
620 fprintf(wc_tracelogf, "%sraw_print_bold(NULL)\n", INDENT);
623 PRE;
624 (*tdp->nprocs->win_raw_print_bold)(tdp->ndata, str);
625 POST;
629 trace_nhgetch(vp)
630 void *vp;
632 struct trace_data *tdp = vp;
633 int rv;
634 char buf[10];
636 fprintf(wc_tracelogf, "%snhgetch()\n", INDENT);
638 PRE;
639 rv = (*tdp->nprocs->win_nhgetch)(tdp->ndata);
640 POST;
642 if (rv > 0 && rv < 256 && isprint(rv)) {
643 sprintf(buf, "'%c'(%d)", rv, rv);
644 } else {
645 sprintf(buf, "(%d)", rv);
647 fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf);
649 return rv;
653 trace_nh_poskey(vp, x, y, mod)
654 void *vp;
655 int *x;
656 int *y;
657 int *mod;
659 struct trace_data *tdp = vp;
660 int rv;
661 char buf[10];
663 fprintf(wc_tracelogf, "%snh_poskey(%d, %d, %d)\n", INDENT, *x, *y, *mod);
665 PRE;
666 rv = (*tdp->nprocs->win_nh_poskey)(tdp->ndata, x, y, mod);
667 POST;
668 if (rv > 0 && rv < 256 && isprint(rv)) {
669 sprintf(buf, "'%c'(%d)", rv, rv);
670 } else {
671 sprintf(buf, "(%d)", rv);
673 fprintf(wc_tracelogf, "%s=> %s (%d, %d, %d)\n", INDENT, buf, *x, *y,
674 *mod);
676 return rv;
679 void
680 trace_nhbell(vp)
681 void *vp;
683 struct trace_data *tdp = vp;
685 fprintf(wc_tracelogf, "%snhbell()\n", INDENT);
687 PRE;
688 (*tdp->nprocs->win_nhbell)(tdp->ndata);
689 POST;
693 trace_doprev_message(vp)
694 void *vp;
696 struct trace_data *tdp = vp;
697 int rv;
699 fprintf(wc_tracelogf, "%sdoprev_message()\n", INDENT);
701 PRE;
702 rv = (*tdp->nprocs->win_doprev_message)(tdp->ndata);
703 POST;
705 fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv);
707 return rv;
710 char
711 trace_yn_function(vp, query, resp, def)
712 void *vp;
713 const char *query, *resp;
714 char def;
716 struct trace_data *tdp = vp;
717 char rv;
718 char buf[10];
720 if (query) {
721 fprintf(wc_tracelogf, "%syn_function('%s'(%d), ", INDENT, query,
722 (int) strlen(query));
723 } else {
724 fprintf(wc_tracelogf, "%syn_function(NULL, ", INDENT);
727 if (resp) {
728 fprintf(wc_tracelogf, "'%s'(%d), ", resp, (int) strlen(resp));
729 } else {
730 fprintf(wc_tracelogf, "NULL, ");
733 if (isprint(def)) {
734 sprintf(buf, "'%c'(%d)", def, def);
735 } else {
736 sprintf(buf, "(%d)", def);
739 fprintf(wc_tracelogf, "%s)\n", buf);
741 PRE;
742 rv = (*tdp->nprocs->win_yn_function)(tdp->ndata, query, resp, def);
743 POST;
745 if (isprint(rv)) {
746 sprintf(buf, "'%c'(%d)", rv, rv);
747 } else {
748 sprintf(buf, "(%d)", rv);
751 fprintf(wc_tracelogf, "%s=> %s\n", INDENT, buf);
753 return rv;
756 void
757 trace_getlin(vp, query, bufp)
758 void *vp;
759 const char *query;
760 char *bufp;
762 struct trace_data *tdp = vp;
764 if (query) {
765 fprintf(wc_tracelogf, "%sgetlin('%s'(%d), ", INDENT, query,
766 (int) strlen(query));
767 } else {
768 fprintf(wc_tracelogf, "%sgetlin(NULL, ", INDENT);
771 if (bufp) {
772 fprintf(wc_tracelogf, "%p)\n", bufp);
773 } else {
774 fprintf(wc_tracelogf, "NULL)\n");
777 PRE;
778 (*tdp->nprocs->win_getlin)(tdp->ndata, query, bufp);
779 POST;
783 trace_get_ext_cmd(vp)
784 void *vp;
786 struct trace_data *tdp = vp;
787 int rv;
788 int ecl_size;
790 /* this is ugly, but the size isn't exposed */
791 const struct ext_func_tab *efp;
792 for (efp = extcmdlist; efp->ef_txt; efp++)
793 ecl_size++;
795 fprintf(wc_tracelogf, "%sget_ext_cmd()\n", INDENT);
797 PRE;
798 rv = (*tdp->nprocs->win_get_ext_cmd)(tdp->ndata);
799 POST;
801 if (rv < 0 || rv >= ecl_size) {
802 fprintf(wc_tracelogf, "%s=> (%d)\n", INDENT, rv);
803 } else {
804 fprintf(wc_tracelogf, "%s=> %d/%s\n", INDENT, rv,
805 extcmdlist[rv].ef_txt);
808 return rv;
811 void
812 trace_number_pad(vp, state)
813 void *vp;
814 int state;
816 struct trace_data *tdp = vp;
818 fprintf(wc_tracelogf, "%snumber_pad(%d)\n", INDENT, state);
820 PRE;
821 (*tdp->nprocs->win_number_pad)(tdp->ndata, state);
822 POST;
825 void
826 trace_delay_output(vp)
827 void *vp;
829 struct trace_data *tdp = vp;
831 fprintf(wc_tracelogf, "%sdelay_output()\n", INDENT);
833 PRE;
834 (*tdp->nprocs->win_delay_output)(tdp->ndata);
835 POST;
838 #ifdef CHANGE_COLOR
839 void
840 trace_change_color(vp, color, value, reverse)
841 void *vp;
842 int color;
843 long value;
844 int reverse;
846 struct trace_data *tdp = vp;
848 fprintf(wc_tracelogf, "%schange_color(%d, $%lx, %d)\n", INDENT, color,
849 value, reverse);
851 PRE;
852 (*tdp->nprocs->win_change_color)(tdp->ndata, color, value, reverse);
853 POST;
856 #ifdef MAC
857 void
858 trace_change_background(vp, bw)
859 void *vp;
860 int bw;
862 struct trace_data *tdp = vp;
864 fprintf(wc_tracelogf, "%schange_background(%d)\n", INDENT, bw);
866 PRE;
867 (*tdp->nprocs->win_change_background)(tdp->ndata, bw);
868 POST;
871 short
872 trace_set_font_name(vp, window, font)
873 void *vp;
874 winid window;
875 char *font;
877 struct trace_data *tdp = vp;
878 short rv;
880 if (font) {
881 fprintf(wc_tracelogf, "%sset_font_name(%d, '%s'(%d))\n", INDENT,
882 window, font, (int) (strlen(font)));
883 } else {
884 fprintf(wc_tracelogf, "%sset_font_name(%d, NULL)\n", INDENT, window);
887 PRE;
888 rv = (*tdp->nprocs->win_set_font_name)(tdp->ndata, window, font);
889 POST;
891 fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv);
893 return rv;
895 #endif
897 char *
898 trace_get_color_string(vp)
899 void *vp;
901 struct trace_data *tdp = vp;
902 char *rv;
904 fprintf(wc_tracelogf, "%sget_color_string()\n");
906 PRE;
907 rv = (*tdp->nprocs->win_get_color_string)(tdp->ndata);
908 POST;
910 if (rv) {
911 fprintf(wc_tracelogf, "%s=> '%s'(%d)\n", INDENT, rv,
912 (int) strlen(rv));
913 } else {
914 fprintf(wc_tracelogf, "%s=> NULL\n");
917 return rv;
920 #endif
922 /* other defs that really should go away (they're tty specific) */
923 void
924 trace_start_screen(vp)
925 void *vp;
927 struct trace_data *tdp = vp;
929 fprintf(wc_tracelogf, "%sstart_screen()\n", INDENT);
931 PRE;
932 (*tdp->nprocs->win_start_screen)(tdp->ndata);
933 POST;
936 void
937 trace_end_screen(vp)
938 void *vp;
940 struct trace_data *tdp = vp;
942 fprintf(wc_tracelogf, "%send_screen()\n", INDENT);
944 PRE;
945 (*tdp->nprocs->win_end_screen)(tdp->ndata);
946 POST;
949 void
950 trace_outrip(vp, tmpwin, how, when)
951 void *vp;
952 winid tmpwin;
953 int how;
954 time_t when;
956 struct trace_data *tdp = vp;
958 fprintf(wc_tracelogf, "%soutrip(%d, %d, %ld)\n", INDENT, (int) tmpwin,
959 how, (long) when);
961 PRE;
962 (*tdp->nprocs->win_outrip)(tdp->ndata, tmpwin, how, when);
963 POST;
966 void
967 trace_preference_update(vp, pref)
968 void *vp;
969 const char *pref;
971 struct trace_data *tdp = vp;
973 if (pref) {
974 fprintf(wc_tracelogf, "%spreference_update('%s'(%d))\n", INDENT, pref,
975 (int) strlen(pref));
976 } else {
977 fprintf(wc_tracelogf, "%spreference_update(NULL)\n", INDENT);
980 PRE;
981 (*tdp->nprocs->win_preference_update)(tdp->ndata, pref);
982 POST;
985 char *
986 trace_getmsghistory(vp, init)
987 void *vp;
988 boolean init;
990 struct trace_data *tdp = vp;
991 char *rv;
993 fprintf(wc_tracelogf, "%sgetmsghistory(%d)\n", INDENT, init);
995 PRE;
996 rv = (*tdp->nprocs->win_getmsghistory)(tdp->ndata, init);
997 POST;
999 if (rv) {
1000 fprintf(wc_tracelogf, "%s=> '%s'(%d)\n", INDENT, rv,
1001 (int) strlen(rv));
1002 } else {
1003 fprintf(wc_tracelogf, "%s=> NULL\n", INDENT);
1006 return rv;
1009 void
1010 trace_putmsghistory(vp, msg, is_restoring)
1011 void *vp;
1012 const char *msg;
1013 boolean is_restoring;
1015 struct trace_data *tdp = vp;
1017 if (msg) {
1018 fprintf(wc_tracelogf, "%sputmsghistory('%s'(%d), %d)\n", INDENT, msg,
1019 (int) strlen(msg), is_restoring);
1020 } else {
1021 fprintf(wc_tracelogf, "%sputmghistory(NULL, %d)\n", INDENT,
1022 is_restoring);
1025 PRE;
1026 (*tdp->nprocs->win_putmsghistory)(tdp->ndata, msg, is_restoring);
1027 POST;
1030 #ifdef STATUS_VIA_WINDOWPORT
1031 void
1032 trace_status_init(vp)
1033 void *vp;
1035 struct trace_data *tdp = vp;
1037 fprintf(wc_tracelogf, "%sstatus_init()\n", INDENT);
1039 PRE;
1040 (*tdp->nprocs->win_status_init)(tdp->ndata);
1041 POST;
1044 void
1045 trace_status_finish(vp)
1046 void *vp;
1048 struct trace_data *tdp = vp;
1050 fprintf(wc_tracelogf, "%sstatus_finish()\n", INDENT);
1052 PRE;
1053 (*tdp->nprocs->win_status_finish)(tdp->ndata);
1054 POST;
1057 void
1058 trace_status_enablefield(vp, fieldidx, nm, fmt, enable)
1059 void *vp;
1060 int fieldidx;
1061 const char *nm;
1062 const char *fmt;
1063 boolean enable;
1065 struct trace_data *tdp = vp;
1067 fprintf(wc_tracelogf, "%sstatus_enablefield(%d, ", INDENT, fieldidx);
1068 if (nm) {
1069 fprintf(wc_tracelogf, "'%s'(%d), ", nm, (int) strlen(nm));
1070 } else {
1071 fprintf(wc_tracelogf, "NULL, ");
1073 if (fmt) {
1074 fprintf(wc_tracelogf, "'%s'(%d), ", fmt, (int) strlen(fmt));
1075 } else {
1076 fprintf(wc_tracelogf, "NULL, ");
1078 fprintf(wc_tracelogf, "%d)\n", enable);
1080 PRE;
1081 (*tdp->nprocs->win_status_enablefield)(tdp->ndata, fieldidx, nm, fmt,
1082 enable);
1083 POST;
1086 void
1087 trace_status_update(vp, idx, ptr, chg, percent)
1088 void *vp;
1089 int idx, chg, percent;
1090 genericptr_t ptr;
1092 struct trace_data *tdp = vp;
1094 fprintf(wc_tracelogf, "%sstatus_update(%d, %p, %d, %d)\n", INDENT, idx,
1095 ptr, chg, percent);
1097 PRE;
1098 (*tdp->nprocs->win_status_update)(tdp->ndata, idx, ptr, chg, percent);
1099 POST;
1102 #ifdef STATUS_HILITES
1103 void
1104 trace_status_threshold(vp, fldidx, thresholdtype, threshold, behavior, under,
1105 over)
1106 void *vp;
1107 int fldidx, thresholdtype;
1108 int behavior, under, over;
1109 anything threshold;
1111 struct trace_data *tdp = vp;
1113 /* XXX how do we print an anything? We don't. */
1114 fprintf(wc_tracelogf, "%sstatus_threshold(%d, %d, -, %d, %d, %d)\n",
1115 INDENT, fldidx, thresholdtype, behavior, under, over);
1117 PRE;
1118 (*tdp->nprocs->win_status_threshold)(tdp->ndata, fldidx, thresholdtype,
1119 threshold, behavior, under, over);
1120 POST;
1122 #endif
1123 #endif
1125 boolean
1126 trace_can_suspend(vp)
1127 void *vp;
1129 struct trace_data *tdp = vp;
1130 boolean rv;
1132 fprintf(wc_tracelogf, "%scan_suspend()\n", INDENT);
1134 PRE;
1135 rv = (*tdp->nprocs->win_can_suspend)(tdp->ndata);
1136 POST;
1138 fprintf(wc_tracelogf, "%s=> %d\n", INDENT, rv);
1140 return rv;
1143 struct chain_procs trace_procs = {
1144 "+trace", 0, /* wincap */
1145 0, /* wincap2 */
1147 XXX problem - the above need to come from the real window port, possibly
1148 modified. May need to do something to call an additional init fn later
1149 or if this is the only place like this the choose_windows fn can do the
1150 fixup
1151 (but not if the value can be modified by the stack?) TBD
1153 trace_init_nhwindows,
1154 trace_player_selection, trace_askname, trace_get_nh_event,
1155 trace_exit_nhwindows, trace_suspend_nhwindows, trace_resume_nhwindows,
1156 trace_create_nhwindow, trace_clear_nhwindow, trace_display_nhwindow,
1157 trace_destroy_nhwindow, trace_curs, trace_putstr, trace_putmixed,
1158 trace_display_file, trace_start_menu, trace_add_menu, trace_end_menu,
1159 trace_select_menu, trace_message_menu, trace_update_inventory,
1160 trace_mark_synch, trace_wait_synch,
1161 #ifdef CLIPPING
1162 trace_cliparound,
1163 #endif
1164 #ifdef POSITIONBAR
1165 trace_update_positionbar,
1166 #endif
1167 trace_print_glyph, trace_raw_print, trace_raw_print_bold, trace_nhgetch,
1168 trace_nh_poskey, trace_nhbell, trace_doprev_message, trace_yn_function,
1169 trace_getlin, trace_get_ext_cmd, trace_number_pad, trace_delay_output,
1170 #ifdef CHANGE_COLOR
1171 trace_change_color,
1172 #ifdef MAC
1173 trace_change_background, trace_set_font_name,
1174 #endif
1175 trace_get_color_string,
1176 #endif
1178 trace_start_screen, trace_end_screen,
1180 trace_outrip, trace_preference_update, trace_getmsghistory,
1181 trace_putmsghistory,
1182 #ifdef STATUS_VIA_WINDOWPORT
1183 trace_status_init, trace_status_finish, trace_status_enablefield,
1184 trace_status_update,
1185 #ifdef STATUS_HILITES
1186 trace_status_threshold,
1187 #endif
1188 #endif
1189 trace_can_suspend,