OSDN Git Service

import nethack-3.6.0
[jnethack/source.git] / win / chain / wc_chainout.c
1 /* NetHack 3.6  wc_chainout.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. */
4
5 /* -chainout is an internal processor that changes the flow from chain_procs
6  * back to window_procs. */
7
8 #include "hack.h"
9
10 struct chainout_data {
11     struct window_procs *nprocs;
12 #if 0
13         void *ndata;
14
15 #endif
16     int linknum;
17 };
18
19 void *
20 chainout_procs_chain(cmd, n, me, nextprocs, nextdata)
21 int cmd;
22 int n;
23 void *me;
24 void *nextprocs;
25 void *nextdata UNUSED;
26 {
27     switch (cmd) {
28     case WINCHAIN_ALLOC: {
29         struct chainout_data *tdp = calloc(1, sizeof(struct chainout_data));
30         tdp->linknum = n;
31         return tdp;
32     }
33     case WINCHAIN_INIT: {
34         struct chainout_data *tdp = me;
35         tdp->nprocs = nextprocs;
36         return tdp;
37     }
38     default:
39         raw_printf("chainout_procs_chain: bad cmd\n");
40         exit(EXIT_FAILURE);
41     }
42 }
43
44 /* XXX if we don't need this, take it out of the table */
45 void
46 chainout_procs_init(dir)
47 int dir UNUSED;
48 {
49 }
50
51 /***
52  *** winprocs
53  ***/
54
55 void
56 chainout_init_nhwindows(vp, argcp, argv)
57 void *vp;
58 int *argcp;
59 char **argv;
60 {
61     struct chainout_data *tdp = vp;
62
63     (*tdp->nprocs->win_init_nhwindows)(argcp, argv);
64 }
65
66 void
67 chainout_player_selection(vp)
68 void *vp;
69 {
70     struct chainout_data *tdp = vp;
71
72     (*tdp->nprocs->win_player_selection)();
73 }
74
75 void
76 chainout_askname(vp)
77 void *vp;
78 {
79     struct chainout_data *tdp = vp;
80
81     (*tdp->nprocs->win_askname)();
82 }
83
84 void
85 chainout_get_nh_event(vp)
86 void *vp;
87 {
88     struct chainout_data *tdp = vp;
89
90     (*tdp->nprocs->win_get_nh_event)();
91 }
92
93 void
94 chainout_exit_nhwindows(vp, str)
95 void *vp;
96 const char *str;
97 {
98     struct chainout_data *tdp = vp;
99
100     (*tdp->nprocs->win_exit_nhwindows)(str);
101 }
102
103 void
104 chainout_suspend_nhwindows(vp, str)
105 void *vp;
106 const char *str;
107 {
108     struct chainout_data *tdp = vp;
109
110     (*tdp->nprocs->win_suspend_nhwindows)(str);
111 }
112
113 void
114 chainout_resume_nhwindows(vp)
115 void *vp;
116 {
117     struct chainout_data *tdp = vp;
118
119     (*tdp->nprocs->win_resume_nhwindows)();
120 }
121
122 winid
123 chainout_create_nhwindow(vp, type)
124 void *vp;
125 int type;
126 {
127     struct chainout_data *tdp = vp;
128     winid rv;
129
130     rv = (*tdp->nprocs->win_create_nhwindow)(type);
131
132     return rv;
133 }
134
135 void
136 chainout_clear_nhwindow(vp, window)
137 void *vp;
138 winid window;
139 {
140     struct chainout_data *tdp = vp;
141
142     (*tdp->nprocs->win_clear_nhwindow)(window);
143 }
144
145 void
146 chainout_display_nhwindow(vp, window, blocking)
147 void *vp;
148 winid window;
149 BOOLEAN_P blocking;
150 {
151     struct chainout_data *tdp = vp;
152
153     (*tdp->nprocs->win_display_nhwindow)(window, blocking);
154 }
155
156 void
157 chainout_destroy_nhwindow(vp, window)
158 void *vp;
159 winid window;
160 {
161     struct chainout_data *tdp = vp;
162
163     (*tdp->nprocs->win_destroy_nhwindow)(window);
164 }
165
166 void
167 chainout_curs(vp, window, x, y)
168 void *vp;
169 winid window;
170 int x;
171 int y;
172 {
173     struct chainout_data *tdp = vp;
174
175     (*tdp->nprocs->win_curs)(window, x, y);
176 }
177
178 void
179 chainout_putstr(vp, window, attr, str)
180 void *vp;
181 winid window;
182 int attr;
183 const char *str;
184 {
185     struct chainout_data *tdp = vp;
186
187     (*tdp->nprocs->win_putstr)(window, attr, str);
188 }
189
190 void
191 chainout_putmixed(vp, window, attr, str)
192 void *vp;
193 winid window;
194 int attr;
195 const char *str;
196 {
197     struct chainout_data *tdp = vp;
198
199     (*tdp->nprocs->win_putmixed)(window, attr, str);
200 }
201
202 void
203 chainout_display_file(vp, fname, complain)
204 void *vp;
205 const char *fname;
206 boolean complain;
207 {
208     struct chainout_data *tdp = vp;
209
210     (*tdp->nprocs->win_display_file)(fname, complain);
211 }
212
213 void
214 chainout_start_menu(vp, window)
215 void *vp;
216 winid window;
217 {
218     struct chainout_data *tdp = vp;
219
220     (*tdp->nprocs->win_start_menu)(window);
221 }
222
223 void
224 chainout_add_menu(vp, window, glyph, identifier, ch, gch, attr, str,
225                   preselected)
226 void *vp;
227 winid window;               /* window to use, must be of type NHW_MENU */
228 int glyph;                  /* glyph to display with item (unused) */
229 const anything *identifier; /* what to return if selected */
230 char ch;                    /* keyboard accelerator (0 = pick our own) */
231 char gch;                   /* group accelerator (0 = no group) */
232 int attr;                   /* attribute for string (like tty_putstr()) */
233 const char *str;            /* menu string */
234 boolean preselected;        /* item is marked as selected */
235 {
236     struct chainout_data *tdp = vp;
237
238     (*tdp->nprocs->win_add_menu)(window, glyph, identifier, ch, gch, attr,
239                                  str, preselected);
240 }
241
242 void
243 chainout_end_menu(vp, window, prompt)
244 void *vp;
245 winid window;
246 const char *prompt;
247 {
248     struct chainout_data *tdp = vp;
249
250     (*tdp->nprocs->win_end_menu)(window, prompt);
251 }
252
253 int
254 chainout_select_menu(vp, window, how, menu_list)
255 void *vp;
256 winid window;
257 int how;
258 menu_item **menu_list;
259 {
260     struct chainout_data *tdp = vp;
261     int rv;
262
263     rv = (*tdp->nprocs->win_select_menu)(window, how, (void *) menu_list);
264
265     return rv;
266 }
267
268 char
269 chainout_message_menu(vp, let, how, mesg)
270 void *vp;
271 char let;
272 int how;
273 const char *mesg;
274 {
275     struct chainout_data *tdp = vp;
276     char rv;
277
278     rv = (*tdp->nprocs->win_message_menu)(let, how, mesg);
279
280     return rv;
281 }
282
283 void
284 chainout_update_inventory(vp)
285 void *vp;
286 {
287     struct chainout_data *tdp = vp;
288
289     (*tdp->nprocs->win_update_inventory)();
290 }
291
292 void
293 chainout_mark_synch(vp)
294 void *vp;
295 {
296     struct chainout_data *tdp = vp;
297
298     (*tdp->nprocs->win_mark_synch)();
299 }
300
301 void
302 chainout_wait_synch(vp)
303 void *vp;
304 {
305     struct chainout_data *tdp = vp;
306
307     (*tdp->nprocs->win_wait_synch)();
308 }
309
310 #ifdef CLIPPING
311 void
312 chainout_cliparound(vp, x, y)
313 void *vp;
314 int x;
315 int y;
316 {
317     struct chainout_data *tdp = vp;
318
319     (*tdp->nprocs->win_cliparound)(x, y);
320 }
321 #endif
322
323 #ifdef POSITIONBAR
324 void
325 chainout_update_positionbar(vp, posbar)
326 void *vp;
327 char *posbar;
328 {
329     struct chainout_data *tdp = vp;
330
331     (*tdp->nprocs->win_update_positionbar)(posbar);
332 }
333 #endif
334
335 void
336 chainout_print_glyph(vp, window, x, y, glyph, bkglyph)
337 void *vp;
338 winid window;
339 xchar x, y;
340 int glyph, bkglyph;
341 {
342     struct chainout_data *tdp = vp;
343
344     (*tdp->nprocs->win_print_glyph)(window, x, y, glyph, bkglyph);
345 }
346
347 void
348 chainout_raw_print(vp, str)
349 void *vp;
350 const char *str;
351 {
352     struct chainout_data *tdp = vp;
353
354     (*tdp->nprocs->win_raw_print)(str);
355 }
356
357 void
358 chainout_raw_print_bold(vp, str)
359 void *vp;
360 const char *str;
361 {
362     struct chainout_data *tdp = vp;
363
364     (*tdp->nprocs->win_raw_print_bold)(str);
365 }
366
367 int
368 chainout_nhgetch(vp)
369 void *vp;
370 {
371     struct chainout_data *tdp = vp;
372     int rv;
373
374     rv = (*tdp->nprocs->win_nhgetch)();
375
376     return rv;
377 }
378
379 int
380 chainout_nh_poskey(vp, x, y, mod)
381 void *vp;
382 int *x;
383 int *y;
384 int *mod;
385 {
386     struct chainout_data *tdp = vp;
387     int rv;
388
389     rv = (*tdp->nprocs->win_nh_poskey)(x, y, mod);
390
391     return rv;
392 }
393
394 void
395 chainout_nhbell(vp)
396 void *vp;
397 {
398     struct chainout_data *tdp = vp;
399
400     (*tdp->nprocs->win_nhbell)();
401 }
402
403 int
404 chainout_doprev_message(vp)
405 void *vp;
406 {
407     struct chainout_data *tdp = vp;
408     int rv;
409
410     rv = (*tdp->nprocs->win_doprev_message)();
411
412     return rv;
413 }
414
415 char
416 chainout_yn_function(vp, query, resp, def)
417 void *vp;
418 const char *query, *resp;
419 char def;
420 {
421     struct chainout_data *tdp = vp;
422     int rv;
423
424     rv = (*tdp->nprocs->win_yn_function)(query, resp, def);
425
426     return rv;
427 }
428
429 void
430 chainout_getlin(vp, query, bufp)
431 void *vp;
432 const char *query;
433 char *bufp;
434 {
435     struct chainout_data *tdp = vp;
436
437     (*tdp->nprocs->win_getlin)(query, bufp);
438 }
439
440 int
441 chainout_get_ext_cmd(vp)
442 void *vp;
443 {
444     struct chainout_data *tdp = vp;
445     int rv;
446
447     rv = (*tdp->nprocs->win_get_ext_cmd)();
448
449     return rv;
450 }
451
452 void
453 chainout_number_pad(vp, state)
454 void *vp;
455 int state;
456 {
457     struct chainout_data *tdp = vp;
458
459     (*tdp->nprocs->win_number_pad)(state);
460 }
461
462 void
463 chainout_delay_output(vp)
464 void *vp;
465 {
466     struct chainout_data *tdp = vp;
467
468     (*tdp->nprocs->win_delay_output)();
469 }
470
471 #ifdef CHANGE_COLOR
472 void
473 chainout_change_color(vp, color, value, reverse)
474 void *vp;
475 int color;
476 long value;
477 int reverse;
478 {
479     struct chainout_data *tdp = vp;
480
481     (*tdp->nprocs->win_change_color)(color, value, reverse);
482 }
483
484 #ifdef MAC
485 void
486 chainout_change_background(vp, bw)
487 void *vp;
488 int bw;
489 {
490     struct chainout_data *tdp = vp;
491
492     (*tdp->nprocs->win_change_background)(bw);
493 }
494
495 short
496 chainout_set_font_name(vp, window, font)
497 void *vp;
498 winid window;
499 char *font;
500 {
501     struct chainout_data *tdp = vp;
502     short rv;
503
504     rv = (*tdp->nprocs->win_set_font_name)(window, font);
505
506     return rv;
507 }
508 #endif
509
510 char *
511 trace_get_color_string(vp)
512 void *vp;
513 {
514     struct chainout_data *tdp = vp;
515     char *rv;
516
517     rv = (*tdp->nprocs->win_get_color_string)();
518
519     return rv;
520 }
521
522 #endif
523
524 /* other defs that really should go away (they're tty specific) */
525 void
526 chainout_start_screen(vp)
527 void *vp;
528 {
529     struct chainout_data *tdp = vp;
530
531     (*tdp->nprocs->win_start_screen)();
532 }
533
534 void
535 chainout_end_screen(vp)
536 void *vp;
537 {
538     struct chainout_data *tdp = vp;
539
540     (*tdp->nprocs->win_end_screen)();
541 }
542
543 void
544 chainout_outrip(vp, tmpwin, how, when)
545 void *vp;
546 winid tmpwin;
547 int how;
548 time_t when;
549 {
550     struct chainout_data *tdp = vp;
551
552     (*tdp->nprocs->win_outrip)(tmpwin, how, when);
553 }
554
555 void
556 chainout_preference_update(vp, pref)
557 void *vp;
558 const char *pref;
559 {
560     struct chainout_data *tdp = vp;
561
562     (*tdp->nprocs->win_preference_update)(pref);
563 }
564
565 char *
566 chainout_getmsghistory(vp, init)
567 void *vp;
568 boolean init;
569 {
570     struct chainout_data *tdp = vp;
571     char *rv;
572
573     rv = (*tdp->nprocs->win_getmsghistory)(init);
574
575     return rv;
576 }
577
578 void
579 chainout_putmsghistory(vp, msg, is_restoring)
580 void *vp;
581 const char *msg;
582 boolean is_restoring;
583 {
584     struct chainout_data *tdp = vp;
585
586     (*tdp->nprocs->win_putmsghistory)(msg, is_restoring);
587 }
588
589 #ifdef STATUS_VIA_WINDOWPORT
590 void
591 chainout_status_init(vp)
592 void *vp;
593 {
594     struct chainout_data *tdp = vp;
595
596     (*tdp->nprocs->win_status_init)();
597 }
598
599 void
600 chainout_status_finish(vp)
601 void *vp;
602 {
603     struct chainout_data *tdp = vp;
604
605     (*tdp->nprocs->win_status_finish)();
606 }
607
608 void
609 chainout_status_enablefield(vp, fieldidx, nm, fmt, enable)
610 void *vp;
611 int fieldidx;
612 const char *nm;
613 const char *fmt;
614 boolean enable;
615 {
616     struct chainout_data *tdp = vp;
617
618     (*tdp->nprocs->win_status_enablefield)(fieldidx, nm, fmt, enable);
619 }
620
621 void
622 chainout_status_update(vp, idx, ptr, chg, percent)
623 void *vp;
624 int idx, chg, percent;
625 genericptr_t ptr;
626 {
627     struct chainout_data *tdp = vp;
628
629     (*tdp->nprocs->win_status_update)(idx, ptr, chg, percent);
630 }
631
632 #ifdef STATUS_HILITES
633 void
634 chainout_status_threshold(vp, fldidx, thresholdtype, threshold, behavior,
635                           under, over)
636 void *vp;
637 int fldidx, thresholdtype;
638 int behavior, under, over;
639 anything threshold;
640 {
641     struct chainout_data *tdp = vp;
642
643     (*tdp->nprocs->win_status_threshold)(fldidx, thresholdtype, threshold,
644                                          behavior, under, over);
645 }
646 #endif
647 #endif
648
649 boolean
650 chainout_can_suspend(vp)
651 void *vp;
652 {
653     struct chainout_data *tdp = vp;
654     boolean rv;
655
656     rv = (*tdp->nprocs->win_can_suspend)();
657
658     return rv;
659 }
660
661 struct chain_procs chainout_procs = {
662     "-chainout", 0, /* wincap */
663     0,              /* wincap2 */
664     /*
665     XXX problem - the above need to come from the real window port, possibly
666     modified.  May need to do something to call an additional init fn later
667     or if this is the only place like this the choose_windows fn can do the
668     fixup
669     (but not if the value can be modified by the stack?)  TBD
670     */
671     chainout_init_nhwindows,
672     chainout_player_selection, chainout_askname, chainout_get_nh_event,
673     chainout_exit_nhwindows, chainout_suspend_nhwindows,
674     chainout_resume_nhwindows, chainout_create_nhwindow,
675     chainout_clear_nhwindow, chainout_display_nhwindow,
676     chainout_destroy_nhwindow, chainout_curs, chainout_putstr,
677     chainout_putmixed, chainout_display_file, chainout_start_menu,
678     chainout_add_menu, chainout_end_menu, chainout_select_menu,
679     chainout_message_menu, chainout_update_inventory, chainout_mark_synch,
680     chainout_wait_synch,
681 #ifdef CLIPPING
682     chainout_cliparound,
683 #endif
684 #ifdef POSITIONBAR
685     chainout_update_positionbar,
686 #endif
687     chainout_print_glyph, chainout_raw_print, chainout_raw_print_bold,
688     chainout_nhgetch, chainout_nh_poskey, chainout_nhbell,
689     chainout_doprev_message, chainout_yn_function, chainout_getlin,
690     chainout_get_ext_cmd, chainout_number_pad, chainout_delay_output,
691 #ifdef CHANGE_COLOR
692     chainout_change_color,
693 #ifdef MAC
694     chainout_change_background, chainout_set_font_name,
695 #endif
696     chainout_get_color_string,
697 #endif
698
699     chainout_start_screen, chainout_end_screen,
700
701     chainout_outrip, chainout_preference_update, chainout_getmsghistory,
702     chainout_putmsghistory,
703 #ifdef STATUS_VIA_WINDOWPORT
704     chainout_status_init, chainout_status_finish, chainout_status_enablefield,
705     chainout_status_update,
706 #ifdef STATUS_HILITES
707     chainout_status_threshold,
708 #endif
709 #endif
710     chainout_can_suspend,
711 };