1 /* SCCS Id: @(#)gnbind.c 3.4 2000/07/16 */
2 /* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
3 /* NetHack may be freely redistributed. See license for details. */
4
5 #include "hack.h"
6 #include "dlb.h"
7 #include "func_tab.h"
8
9 #include <termios.h>
10 #include <unistd.h>
11
12 #include "dummy_graphics.h"
13
14 /*
15 * This file implements the interface between the window port specific
16 * code in the Gnome port and the rest of the nethack game engine.
17 */
18
19 /* Interface definition, for windows.c */
20 struct window_procs dummy_procs = {
21 "dummy",
22 0L,
23 0L,
24 dummy_init_nhwindows,
25 dummy_player_selection,
26 dummy_askname,
27 dummy_get_nh_event,
28 dummy_exit_nhwindows,
29 dummy_suspend_nhwindows,
30 dummy_resume_nhwindows,
31 dummy_create_nhwindow,
32 dummy_clear_nhwindow,
33 dummy_display_nhwindow,
34 dummy_destroy_nhwindow,
35 dummy_curs,
36 dummy_putstr,
37 dummy_display_file,
38 dummy_start_menu,
39 dummy_add_menu,
40 dummy_end_menu,
41 dummy_select_menu,
42 genl_message_menu, /* no need for X-specific handling */
43 dummy_update_inventory,
44 dummy_mark_synch,
45 dummy_wait_synch,
46 #ifdef CLIPPING
47 dummy_cliparound,
48 #endif
49 #ifdef POSITIONBAR
50 donull,
51 #endif
52 dummy_print_glyph,
53 dummy_raw_print,
54 dummy_raw_print_bold,
55 dummy_nhgetch,
56 dummy_nh_poskey,
57 dummy_nhbell,
58 dummy_doprev_message,
59 dummy_yn_function,
60 dummy_getlin,
61 dummy_get_ext_cmd,
62 dummy_number_pad,
63 dummy_delay_output,
64 #ifdef CHANGE_COLOR /* only a Mac option currently */
65 donull,
66 donull,
67 #endif
68 /* other defs that really should go away (they're tty specific) */
69 dummy_start_screen,
70 dummy_end_screen,
71 dummy_outrip,
72 genl_preference_update,
73 };
74
75 /*
76 init_nhwindows(int* argcp, char** argv)
77 -- Initialize the windows used by NetHack. This can also
78 create the standard windows listed at the top, but does
79 not display them.
80 -- Any commandline arguments relevant to the windowport
81 should be interpreted, and *argcp and *argv should
82 be changed to remove those arguments.
83 -- When the message window is created, the variable
84 iflags.window_inited needs to be set to TRUE. Otherwise
85 all plines() will be done via raw_print().
86 ** Why not have init_nhwindows() create all of the "standard"
87 ** windows? Or at least all but WIN_INFO? -dean
88 */
dummy_init_nhwindows(int * argc,char ** argv)89 void dummy_init_nhwindows(int* argc, char** argv)
90 {
91 printf("dummy_init_nhwindows\n");
92 }
93
94
95 /* Do a window-port specific player type selection. If player_selection()
96 offers a Quit option, it is its responsibility to clean up and terminate
97 the process. You need to fill in pl_character[0].
98 */
99 void
dummy_player_selection()100 dummy_player_selection()
101 {
102 #if 0
103 int n, i, sel;
104 const char** choices;
105 int* pickmap;
106
107 /* prevent an unnecessary prompt */
108 rigid_role_checks();
109
110 if (!flags.randomall && flags.initrole < 0) {
111
112 /* select a role */
113 for (n = 0; roles[n].name.m; n++) continue;
114 choices = (const char **)alloc(sizeof(char *) * (n+1));
115 pickmap = (int*)alloc(sizeof(int) * (n+1));
116 for (;;) {
117 for (n = 0, i = 0; roles[i].name.m; i++) {
118 if (ok_role(i, flags.initrace,
119 flags.initgend, flags.initalign)) {
120 if (flags.initgend >= 0 && flags.female && roles[i].name.f)
121 choices[n] = roles[i].name.f;
122 else
123 choices[n] = roles[i].name.m;
124 pickmap[n++] = i;
125 }
126 }
127 if (n > 0) break;
128 else if (flags.initalign >= 0) flags.initalign = -1; /* reset */
129 else if (flags.initgend >= 0) flags.initgend = -1;
130 else if (flags.initrace >= 0) flags.initrace = -1;
131 else panic("no available ROLE+race+gender+alignment combinations");
132 }
133 choices[n] = (const char *) 0;
134 if (n > 1)
135 sel = ghack_player_sel_dialog(choices,
136 _("Player selection"), _("Choose one of the following roles:"));
137 else sel = 0;
138 if (sel >= 0) sel = pickmap[sel];
139 else if (sel == ROLE_NONE) { /* Quit */
140 clearlocks();
141 dummy_exit_nhwindows(0);
142 }
143 free(choices);
144 free(pickmap);
145 } else if (flags.initrole < 0) sel = ROLE_RANDOM;
146 else sel = flags.initrole;
147
148 if (sel == ROLE_RANDOM) { /* Random role */
149 sel = pick_role(flags.initrace, flags.initgend,
150 flags.initalign, PICK_RANDOM);
151 if (sel < 0) sel = randrole();
152 }
153
154 flags.initrole = sel;
155
156 /* Select a race, if necessary */
157 /* force compatibility with role, try for compatibility with
158 * pre-selected gender/alignment */
159 if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) {
160 if (flags.initrace == ROLE_RANDOM || flags.randomall) {
161 flags.initrace = pick_race(flags.initrole, flags.initgend,
162 flags.initalign, PICK_RANDOM);
163 if (flags.initrace < 0) flags.initrace = randrace(flags.initrole);
164 } else {
165 /* Count the number of valid races */
166 n = 0; /* number valid */
167 for (i = 0; races[i].noun; i++) {
168 if (ok_race(flags.initrole, i, flags.initgend, flags.initalign))
169 n++;
170 }
171 if (n == 0) {
172 for (i = 0; races[i].noun; i++) {
173 if (validrace(flags.initrole, i)) n++;
174 }
175 }
176
177 choices = (const char **)alloc(sizeof(char *) * (n+1));
178 pickmap = (int*)alloc(sizeof(int) * (n + 1));
179 for (n = 0, i = 0; races[i].noun; i++) {
180 if (ok_race(flags.initrole, i, flags.initgend,
181 flags.initalign)) {
182 choices[n] = races[i].noun;
183 pickmap[n++] = i;
184 }
185 }
186 choices[n] = (const char *) 0;
187 /* Permit the user to pick, if there is more than one */
188 if (n > 1)
189 sel = ghack_player_sel_dialog(choices, _("Race selection"),
190 _("Choose one of the following races:"));
191 else sel = 0;
192 if (sel >= 0) sel = pickmap[sel];
193 else if (sel == ROLE_NONE) { /* Quit */
194 clearlocks();
195 dummy_exit_nhwindows(0);
196 }
197 flags.initrace = sel;
198 free(choices);
199 free(pickmap);
200 }
201 if (flags.initrace == ROLE_RANDOM) { /* Random role */
202 sel = pick_race(flags.initrole, flags.initgend,
203 flags.initalign, PICK_RANDOM);
204 if (sel < 0) sel = randrace(flags.initrole);
205 flags.initrace = sel;
206 }
207 }
208
209 /* Select a gender, if necessary */
210 /* force compatibility with role/race, try for compatibility with
211 * pre-selected alignment */
212 if (flags.initgend < 0 ||
213 !validgend(flags.initrole, flags.initrace, flags.initgend)) {
214 if (flags.initgend == ROLE_RANDOM || flags.randomall) {
215 flags.initgend = pick_gend(flags.initrole, flags.initrace,
216 flags.initalign, PICK_RANDOM);
217 if (flags.initgend < 0)
218 flags.initgend = randgend(flags.initrole, flags.initrace);
219 } else {
220 /* Count the number of valid genders */
221 n = 0; /* number valid */
222 for (i = 0; i < ROLE_GENDERS; i++) {
223 if (ok_gend(flags.initrole, flags.initrace, i, flags.initalign))
224 n++;
225 }
226 if (n == 0) {
227 for (i = 0; i < ROLE_GENDERS; i++) {
228 if (validgend(flags.initrole, flags.initrace, i)) n++;
229 }
230 }
231
232 choices = (const char **)alloc(sizeof(char *) * (n+1));
233 pickmap = (int*)alloc(sizeof(int) * (n + 1));
234 for (n = 0, i = 0; i < ROLE_GENDERS; i++) {
235 if (ok_gend(flags.initrole, flags.initrace, i,
236 flags.initalign)) {
237 choices[n] = genders[i].adj;
238 pickmap[n++] = i;
239 }
240 }
241 choices[n] = (const char *) 0;
242 /* Permit the user to pick, if there is more than one */
243 if (n > 1)
244 sel = ghack_player_sel_dialog(choices, _("Gender selection"),
245 _("Choose one of the following genders:"));
246 else sel = 0;
247 if (sel >= 0) sel = pickmap[sel];
248 else if (sel == ROLE_NONE) { /* Quit */
249 clearlocks();
250 dummy_exit_nhwindows(0);
251 }
252 flags.initgend = sel;
253 free(choices);
254 free(pickmap);
255 }
256 if (flags.initgend == ROLE_RANDOM) { /* Random gender */
257 sel = pick_gend(flags.initrole, flags.initrace,
258 flags.initalign, PICK_RANDOM);
259 if (sel < 0) sel = randgend(flags.initrole, flags.initrace);
260 flags.initgend = sel;
261 }
262 }
263
264 /* Select an alignment, if necessary */
265 /* force compatibility with role/race/gender */
266 if (flags.initalign < 0 ||
267 !validalign(flags.initrole, flags.initrace, flags.initalign)) {
268 if (flags.initalign == ROLE_RANDOM || flags.randomall) {
269 flags.initalign = pick_align(flags.initrole, flags.initrace,
270 flags.initgend, PICK_RANDOM);
271 if (flags.initalign < 0)
272 flags.initalign = randalign(flags.initrole, flags.initrace);
273 } else {
274 /* Count the number of valid alignments */
275 n = 0; /* number valid */
276 for (i = 0; i < ROLE_ALIGNS; i++) {
277 if (ok_align(flags.initrole, flags.initrace, flags.initgend, i))
278 n++;
279 }
280 if (n == 0) {
281 for (i = 0; i < ROLE_ALIGNS; i++)
282 if (validalign(flags.initrole, flags.initrace, i)) n++;
283 }
284
285 choices = (const char **)alloc(sizeof(char *) * (n+1));
286 pickmap = (int*)alloc(sizeof(int) * (n + 1));
287 for (n = 0, i = 0; i < ROLE_ALIGNS; i++) {
288 if (ok_align(flags.initrole,
289 flags.initrace, flags.initgend, i)) {
290 choices[n] = aligns[i].adj;
291 pickmap[n++] = i;
292 }
293 }
294 choices[n] = (const char *) 0;
295 /* Permit the user to pick, if there is more than one */
296 if (n > 1)
297 sel = ghack_player_sel_dialog(choices, _("Alignment selection"),
298 _("Choose one of the following alignments:"));
299 else sel = 0;
300 if (sel >= 0) sel = pickmap[sel];
301 else if (sel == ROLE_NONE) { /* Quit */
302 clearlocks();
303 dummy_exit_nhwindows(0);
304 }
305 flags.initalign = sel;
306 free(choices);
307 free(pickmap);
308 }
309 if (flags.initalign == ROLE_RANDOM) {
310 sel = pick_align(flags.initrole, flags.initrace,
311 flags.initgend, PICK_RANDOM);
312 if (sel < 0) sel = randalign(flags.initrole, flags.initrace);
313 flags.initalign = sel;
314 }
315 }
316 #endif
317 }
318
319
320 /* Ask the user for a player name. */
dummy_askname()321 void dummy_askname()
322 {
323 fprintf(stdout, "What is your name? ");
324 char *ret = fgets(plname, sizeof(plname), stdin);
325 /* Quit if they want to quit... */
326 if (ret==NULL) {
327 dummy_exit_nhwindows(0);
328 }
329 }
330
331
332 /* Does window event processing (e.g. exposure events).
333 A noop for the tty and X window-ports.
334 */
dummy_get_nh_event()335 void dummy_get_nh_event()
336 {
337 printf("dummy_get_nh_event\n");
338 }
339
340 /* Exits the window system. This should dismiss all windows,
341 except the "window" used for raw_print(). str is printed if possible.
342 */
dummy_exit_nhwindows(const char * str)343 void dummy_exit_nhwindows(const char *str)
344 {
345 printf("dummy_exit_nhwindows(%s)\n", str);
346 }
347
348 /* Prepare the window to be suspended. */
dummy_suspend_nhwindows(const char * str)349 void dummy_suspend_nhwindows(const char *str)
350 {
351 printf("dummy_suspend_nhwindows(%s)\n", str);
352 /* I don't think we need to do anything here... */
353 return;
354 }
355
356
357 /* Restore the windows after being suspended. */
dummy_resume_nhwindows()358 void dummy_resume_nhwindows()
359 {
360 /* Do Nothing. */
361 printf("dummy_resume_nhwindows\n");
362 }
363
364 static const char*
winid2str(int type)365 winid2str(int type)
366 {
367 switch(type) {
368 case NHW_MESSAGE: return "NHW_MESSAGE";
369 case NHW_STATUS: return "NHW_STATUS";
370 case NHW_MAP: return "NHW_MAP";
371 case NHW_MENU: return "NHW_MENU";
372 case NHW_TEXT: return "NHW_TEXT";
373 default: return "unknown win type";
374 }
375 }
376
377
378 /* Create a window of type "type" which can be
379 NHW_MESSAGE (top line)
380 NHW_STATUS (bottom lines)
381 NHW_MAP (main dungeon)
382 NHW_MENU (inventory or other "corner" windows)
383 NHW_TEXT (help/text, full screen paged window)
384 */
385 winid
dummy_create_nhwindow(int type)386 dummy_create_nhwindow(int type)
387 {
388 printf("dummy_create_nhwindow(%s)\n", winid2str(type));
389 return type;
390 }
391
392 /* Clear the given window, when asked to. */
dummy_clear_nhwindow(winid wid)393 void dummy_clear_nhwindow(winid wid)
394 {
395 printf("dummy_clear_nhwindow(%s)\n", winid2str(wid));
396 }
397
398 /* -- Display the window on the screen. If there is data
399 pending for output in that window, it should be sent.
400 If blocking is TRUE, display_nhwindow() will not
401 return until the data has been displayed on the screen,
402 and acknowledged by the user where appropriate.
403 -- All calls are blocking in the tty window-port.
404 -- Calling display_nhwindow(WIN_MESSAGE,???) will do a
405 --more--, if necessary, in the tty window-port.
406 */
dummy_display_nhwindow(winid wid,BOOLEAN_P block)407 void dummy_display_nhwindow(winid wid, BOOLEAN_P block)
408 {
409 printf("dummy_display_nhwindow(%s, %d)\n", winid2str(wid), block);
410 }
411
412
413 /* Destroy will dismiss the window if the window has not
414 * already been dismissed.
415 */
dummy_destroy_nhwindow(winid wid)416 void dummy_destroy_nhwindow(winid wid)
417 {
418 printf("dummy_destroy_nhwindow(%s)\n", winid2str(wid));
419 }
420
421 /* Next output to window will start at (x,y), also moves
422 displayable cursor to (x,y). For backward compatibility,
423 1 <= x < cols, 0 <= y < rows, where cols and rows are
424 the size of window.
425 */
dummy_curs(winid wid,int x,int y)426 void dummy_curs(winid wid, int x, int y)
427 {
428 printf("winid %s, x %d, y %d\n", winid2str(wid), x, y);
429 }
430
431 /*
432 putstr(window, attr, str)
433 -- Print str on the window with the given attribute. Only
434 printable ASCII characters (040-0126) must be supported.
435 Multiple putstr()s are output on separate lines.
436 Attributes
437 can be one of
438 ATR_NONE (or 0)
439 ATR_ULINE
440 ATR_BOLD
441 ATR_BLINK
442 ATR_INVERSE
443 If a window-port does not support all of these, it may map
444 unsupported attributes to a supported one (e.g. map them
445 all to ATR_INVERSE). putstr() may compress spaces out of
446 str, break str, or truncate str, if necessary for the
447 display. Where putstr() breaks a line, it has to clear
448 to end-of-line.
449 -- putstr should be implemented such that if two putstr()s
450 are done consecutively the user will see the first and
451 then the second. In the tty port, pline() achieves this
452 by calling more() or displaying both on the same line.
453 */
dummy_putstr(winid wid,int attr,const char * text)454 void dummy_putstr(winid wid, int attr, const char *text)
455 {
456 printf("winid %s, %s, attr %d\n", winid2str(wid), text, attr);
457 }
458
459 /* Display the file named str. Complain about missing files
460 iff complain is TRUE.
461 */
dummy_display_file(const char * filename,BOOLEAN_P must_exist)462 void dummy_display_file(const char *filename,BOOLEAN_P must_exist)
463 {
464 printf("dummy_display_file(%s, %d)\n", filename, must_exist);
465 dlb *f;
466
467 f = dlb_fopen(filename, "r");
468 if (!f) {
469 if (must_exist) {
470 printf("Warning! Could not find file: %s\n",filename);
471 }
472 } else {
473 #define LLEN 128
474 char line[LLEN];
475 int num_lines, charcount;
476
477 num_lines = 0;
478 charcount = 1;
479 while (dlb_fgets(line, LLEN, f)) {
480 printf("%s", line);
481 }
482 (void) dlb_fclose(f);
483 }
484 }
485
486 /* Start using window as a menu. You must call start_menu()
487 before add_menu(). After calling start_menu() you may not
488 putstr() to the window. Only windows of type NHW_MENU may
489 be used for menus.
490 */
dummy_start_menu(winid wid)491 void dummy_start_menu(winid wid)
492 {
493 /* Do Nothing */
494 printf("dummy_start_menu(%s)\n", winid2str(wid));
495 }
496
497 /*
498 add_menu(windid window, int glyph, const anything identifier,
499 char accelerator, char groupacc,
500 int attr, char *str, boolean preselected)
501 -- Add a text line str to the given menu window. If identifier
502 is 0, then the line cannot be selected (e.g. a title).
503 Otherwise, identifier is the value returned if the line is
504 selected. Accelerator is a keyboard key that can be used
505 to select the line. If the accelerator of a selectable
506 item is 0, the window system is free to select its own
507 accelerator. It is up to the window-port to make the
508 accelerator visible to the user (e.g. put "a - " in front
509 of str). The value attr is the same as in putstr().
510 Glyph is an optional glyph to accompany the line. If
511 window port cannot or does not want to display it, this
512 is OK. If there is no glyph applicable, then this
513 value will be NO_GLYPH.
514 -- All accelerators should be in the range [A-Za-z].
515 -- It is expected that callers do not mix accelerator
516 choices. Either all selectable items have an accelerator
517 or let the window system pick them. Don't do both.
518 -- Groupacc is a group accelerator. It may be any character
519 outside of the standard accelerator (see above) or a
520 number. If 0, the item is unaffected by any group
521 accelerator. If this accelerator conflicts with
522 the menu command (or their user defined alises), it loses.
523 The menu commands and aliases take care not to interfere
524 with the default object class symbols.
525 -- If you want this choice to be preselected when the
526 menu is displayed, set preselected to TRUE.
527 */
dummy_add_menu(winid wid,int glyph,int cnt,const ANY_P * identifier,CHAR_P accelerator,CHAR_P group_accel,int attr,const char * str,BOOLEAN_P presel)528 void dummy_add_menu(winid wid, int glyph, int cnt, const ANY_P * identifier,
529 CHAR_P accelerator, CHAR_P group_accel, int attr,
530 const char *str, BOOLEAN_P presel)
531 {
532 /* Do Nothing */
533 printf("dummy_add_menu(%s, %d, %d, %d, %c, %c, %d, %s, %d\n", winid2str(wid),
534 glyph, cnt, (int)identifier, accelerator, group_accel, attr, str, presel);
535 }
536
537 /*
538 end_menu(window, prompt)
539 -- Stop adding entries to the menu and flushes the window
540 to the screen (brings to front?). Prompt is a prompt
541 to give the user. If prompt is NULL, no prompt will
542 be printed.
543 ** This probably shouldn't flush the window any more (if
544 ** it ever did). That should be select_menu's job. -dean
545 */
dummy_end_menu(winid wid,const char * prompt)546 void dummy_end_menu(winid wid, const char *prompt)
547 {
548 /* Do Nothing */
549 printf("dummy_end_menu(%s, %s)\n", winid2str(wid), prompt);
550 }
551
552 /*
553 int select_menu(windid window, int how, menu_item **selected)
554 -- Return the number of items selected; 0 if none were chosen,
555 -1 when explicitly cancelled. If items were selected, then
556 selected is filled in with an allocated array of menu_item
557 structures, one for each selected line. The caller must
558 free this array when done with it. The "count" field
559 of selected is a user supplied count. If the user did
560 not supply a count, then the count field is filled with
561 -1 (meaning all). A count of zero is equivalent to not
562 being selected and should not be in the list. If no items
563 were selected, then selected is NULL'ed out. How is the
564 mode of the menu. Three valid values are PICK_NONE,
565 PICK_ONE, and PICK_N, meaning: nothing is selectable,
566 only one thing is selectable, and any number valid items
567 may selected. If how is PICK_NONE, this function should
568 never return anything but 0 or -1.
569 -- You may call select_menu() on a window multiple times --
570 the menu is saved until start_menu() or destroy_nhwindow()
571 is called on the window.
572 -- Note that NHW_MENU windows need not have select_menu()
573 called for them. There is no way of knowing whether
574 select_menu() will be called for the window at
575 create_nhwindow() time.
576 */
dummy_select_menu(winid wid,int how,MENU_ITEM_P ** selected)577 int dummy_select_menu(winid wid, int how, MENU_ITEM_P **selected)
578 {
579 int nReturned = -1;
580 printf("dummy_select_menu(%s, %d, ...)\n", winid2str(wid), how);
581
582 /*if (wid != -1 && dummy_windowlist[wid].win != NULL &&
583 dummy_windowlist[wid].type == NHW_MENU)
584 {
585 nReturned=ghack_menu_window_select_menu (dummy_windowlist[wid].win,
586 selected, how);
587 }*/
588
589 return nReturned;
590 }
591
592 /*
593 -- Indicate to the window port that the inventory has been changed.
594 -- Merely calls display_inventory() for window-ports that leave the
595 window up, otherwise empty.
596 */
dummy_update_inventory()597 void dummy_update_inventory()
598 {
599 /* Do Nothing */
600 printf("dummy_update_inventory\n");
601 }
602
603 /*
604 mark_synch() -- Don't go beyond this point in I/O on any channel until
605 all channels are caught up to here. Can be an empty call
606 for the moment
607 */
dummy_mark_synch()608 void dummy_mark_synch()
609 {
610 /* Do nothing */
611 printf("dummy_mark_synch\n");
612 }
613
614 /*
615 wait_synch() -- Wait until all pending output is complete (*flush*() for
616 streams goes here).
617 -- May also deal with exposure events etc. so that the
618 display is OK when return from wait_synch().
619 */
dummy_wait_synch()620 void dummy_wait_synch()
621 {
622 /* Do nothing */
623 printf("dummy_wait_synch\n");
624 }
625
626 /*
627 cliparound(x, y)-- Make sure that the user is more-or-less centered on the
628 screen if the playing area is larger than the screen.
629 -- This function is only defined if CLIPPING is defined.
630 */
dummy_cliparound(int x,int y)631 void dummy_cliparound(int x, int y)
632 {
633 /* Do Nothing */
634 printf("dummy_cliparound\n");
635 }
636
637 /*
638 print_glyph(window, x, y, glyph)
639 -- Print the glyph at (x,y) on the given window. Glyphs are
640 integers at the interface, mapped to whatever the window-
641 port wants (symbol, font, color, attributes, ...there's
642 a 1-1 map between glyphs and distinct things on the map).
643 */
dummy_print_glyph(winid wid,XCHAR_P x,XCHAR_P y,int glyph)644 void dummy_print_glyph(winid wid,XCHAR_P x,XCHAR_P y,int glyph)
645 {
646 if (wid != -1) {
647 printf("winid %d; x %d, y %d, glyph: %d\n",
648 wid, x, y, glyph);
649 }
650 }
651
652 /*
653 raw_print(str) -- Print directly to a screen, or otherwise guarantee that
654 the user sees str. raw_print() appends a newline to str.
655 It need not recognize ASCII control characters. This is
656 used during startup (before windowing system initialization
657 -- maybe this means only error startup messages are raw),
658 for error messages, and maybe other "msg" uses. E.g.
659 updating status for micros (i.e, "saving").
660 */
dummy_raw_print(const char * str)661 void dummy_raw_print(const char *str)
662 {
663 printf("dummy_raw_print\n%s\n", str);
664 }
665
666 /*
667 raw_print_bold(str)
668 -- Like raw_print(), but prints in bold/standout (if
669 possible).
670 */
dummy_raw_print_bold(const char * str)671 void dummy_raw_print_bold(const char *str)
672 {
673 printf("dummy_raw_print_bold\n*%s*\n", str);
674 }
675
dummy_getchar()676 static int dummy_getchar()
677 {
678 char input[256];
679 char *rets = NULL;
680 do {
681 rets = fgets(input, sizeof(input), stdin);
682 } while (rets == NULL);
683
684 return input[0];
685 }
686
687 /*
688 int nhgetch() -- Returns a single character input from the user.
689 -- In the tty window-port, nhgetch() assumes that tgetch()
690 will be the routine the OS provides to read a character.
691 Returned character _must_ be non-zero.
692 */
dummy_nhgetch()693 int dummy_nhgetch()
694 {
695 printf("dummy_nhgetch\n");
696 int ret = dummy_getchar();
697 printf("dummy_nhgetch %d %c\n",ret,ret);
698 return ret;
699 }
700
701 /*
702 int nh_poskey(int *x, int *y, int *mod)
703 -- Returns a single character input from the user or a
704 a positioning event (perhaps from a mouse). If the
705 return value is non-zero, a character was typed, else,
706 a position in the MAP window is returned in x, y and mod.
707 mod may be one of
708
709 CLICK_1 -- mouse click type 1
710 CLICK_2 -- mouse click type 2
711
712 The different click types can map to whatever the
713 hardware supports. If no mouse is supported, this
714 routine always returns a non-zero character.
715 */
dummy_nh_poskey(int * x,int * y,int * mod)716 int dummy_nh_poskey(int *x, int *y, int *mod)
717 {
718 #if 0
719 gtk_signal_emit (GTK_OBJECT (dummy_windowlist[WIN_STATUS].win),
720 ghack_signals[GHSIG_FADE_HIGHLIGHT]);
721
722 g_askingQuestion = 0;
723 /* Process events until a key or map-click arrives. */
724 while ( g_numKeys == 0 && g_numClicks == 0 )
725 gtk_main_iteration();
726
727 if (g_numKeys > 0) {
728 int key;
729 GList *theFirst;
730
731 theFirst = g_list_first( g_keyBuffer);
732 g_keyBuffer = g_list_remove_link(g_keyBuffer, theFirst);
733 key = GPOINTER_TO_INT( theFirst->data);
734 g_list_free_1( theFirst);
735 g_numKeys--;
736 return ( key);
737 }
738 else {
739 GHClick *click;
740 GList *theFirst;
741
742 theFirst = g_list_first( g_clickBuffer);
743 g_clickBuffer = g_list_remove_link(g_clickBuffer, theFirst);
744 click = (GHClick*) theFirst->data;
745 *x=click->x;
746 *y=click->y;
747 *mod=click->mod;
748 g_free( click);
749 g_list_free_1( theFirst);
750 g_numClicks--;
751 return ( 0);
752 }
753 #endif
754 printf("dummy_nh_poskey\n");
755 return dummy_getchar();
756 }
757
758 /*
759 nhbell() -- Beep at user. [This will exist at least until sounds are
760 redone, since sounds aren't attributable to windows anyway.]
761 */
dummy_nhbell()762 void dummy_nhbell()
763 {
764 printf("BEEP!\n");
765 }
766
767 /*
768 doprev_message()
769 -- Display previous messages. Used by the ^P command.
770 -- On the tty-port this scrolls WIN_MESSAGE back one line.
771 */
dummy_doprev_message()772 int dummy_doprev_message()
773 {
774 /* Do Nothing. They can read old messages using the scrollbar. */
775 return 0;
776 }
777
778 /*
779 char yn_function(const char *ques, const char *choices, char default)
780 -- Print a prompt made up of ques, choices and default.
781 Read a single character response that is contained in
782 choices or default. If choices is NULL, all possible
783 inputs are accepted and returned. This overrides
784 everything else. The choices are expected to be in
785 lower case. Entering ESC always maps to 'q', or 'n',
786 in that order, if present in choices, otherwise it maps
787 to default. Entering any other quit character (SPACE,
788 RETURN, NEWLINE) maps to default.
789 -- If the choices string contains ESC, then anything after
790 it is an acceptable response, but the ESC and whatever
791 follows is not included in the prompt.
792 -- If the choices string contains a '#' then accept a count.
793 Place this value in the global "yn_number" and return '#'.
794 -- This uses the top line in the tty window-port, other
795 ports might use a popup.
796 */
dummy_yn_function(const char * question,const char * choices,CHAR_P def)797 char dummy_yn_function(const char *question, const char *choices,
798 CHAR_P def)
799 {
800 // TODO
801 printf("dummy_yn_function %s\n", question);
802 int ret = dummy_getchar();
803 printf("dummy_yn_function %d %c\n", ret, ret);
804 return ret;
805 }
806
807 /** Strips newline from end of string. */
strip_newline(char * str)808 void strip_newline(char *str) {
809 /* Strip newline from end */
810 if (str[strlen(str)-1] == '\n') {
811 str[strlen(str)-1] = '\0';
812 }
813 }
814
815 /*
816 getlin(const char *ques, char *input)
817 -- Prints ques as a prompt and reads a single line of text,
818 up to a newline. The string entered is returned without the
819 newline. ESC is used to cancel, in which case the string
820 "\033\000" is returned.
821 -- getlin() must call flush_screen(1) before doing anything.
822 -- This uses the top line in the tty window-port, other
823 ports might use a popup.
824 */
dummy_getlin(const char * question,char * input)825 void dummy_getlin(const char *question, char *input)
826 {
827 printf("dummy_getlin\n");
828 fprintf(stdout, "%s:\n", question);
829 fflush(stdout);
830 char *ret = fgets(input, 256, stdin);
831
832 if (ret == NULL) {
833 input[0] = '\033';
834 input[1] = '\0';
835 } else {
836 strip_newline(input);
837 }
838
839 }
840
841 /*
842 int get_ext_cmd(void)
843 -- Get an extended command in a window-port specific way.
844 An index into extcmdlist[] is returned on a successful
845 selection, -1 otherwise.
846 */
dummy_get_ext_cmd()847 int dummy_get_ext_cmd()
848 {
849 char cmd[255];
850 int i;
851 char *ret;
852
853 printf("dummy_get_ext_cmd\n");
854 ret = fgets(cmd, sizeof(cmd), stdin);
855
856 for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++) {
857 strip_newline(ret);
858 if (!strcmpi(ret, extcmdlist[i].ef_txt)) {
859 return i;
860 }
861 }
862 return -1;
863 }
864
865
866 /*
867 number_pad(state)
868 -- Initialize the number pad to the given state.
869 */
dummy_number_pad(int state)870 void dummy_number_pad(int state)
871 {
872 /* Do Nothing */
873 printf("dummy_number_pad\n");
874 }
875
876 /*
877 delay_output() -- Causes a visible delay of 50ms in the output.
878 Conceptually, this is similar to wait_synch() followed
879 by a nap(50ms), but allows asynchronous operation.
880 */
dummy_delay_output()881 void dummy_delay_output()
882 {
883 // TODO
884 /* Do Nothing */
885 printf("dummy_delay_output\n");
886 }
887
888 /*
889 start_screen() -- Only used on Unix tty ports, but must be declared for
890 completeness. Sets up the tty to work in full-screen
891 graphics mode. Look at win/tty/termcap.c for an
892 example. If your window-port does not need this function
893 just declare an empty function.
894 */
dummy_start_screen()895 void dummy_start_screen()
896 {
897 /* Do Nothing */
898 printf("dummy_start_screen\n");
899 }
900
901 /*
902 end_screen() -- Only used on Unix tty ports, but must be declared for
903 completeness. The complement of start_screen().
904 */
dummy_end_screen()905 void dummy_end_screen()
906 {
907 /* Do Nothing */
908 printf("dummy_end_screen\n");
909 }
910
911 /*
912 outrip(winid, int)
913 -- The tombstone code. If you want the traditional code use
914 genl_outrip for the value and check the #if in rip.c.
915 */
dummy_outrip(winid wid,int how)916 void dummy_outrip(winid wid, int how)
917 {
918 printf("dummy_outrip\n");
919 }
920