1
From 83199fe0ca33c2442d3ea6cb26f62561ce812a41 Mon Sep 17 00:00:00 2001
2
From: Ben Gertzfield <che@debian.org>
3
Date: Thu, 24 Sep 2009 14:21:19 -0700
4
Subject: Add LISP-based windowing system
7
include/winlisp.h | 70 ++
9
win/lisp/ChangeLog | 326 +++++++++
10
win/lisp/winlisp.c | 1937 ++++++++++++++++++++++++++++++++++++++++++++++++++++
11
win/tty/termcap.c | 5 +
12
5 files changed, 2345 insertions(+)
13
create mode 100644 include/winlisp.h
14
create mode 100644 win/lisp/ChangeLog
15
create mode 100644 win/lisp/winlisp.c
17
diff --git a/include/winlisp.h b/include/winlisp.h
19
index 0000000..f1815b7
21
+++ b/include/winlisp.h
30
+#if defined(BOS) || defined(NHSTDC)
31
+#define DIMENSION_P int
33
+# ifdef WIDENED_PROTOTYPES
34
+#define DIMENSION_P unsigned int
36
+#define DIMENSION_P Dimension
40
+extern struct window_procs tty_procs;
42
+/* ### winlisp.c ### */
43
+E void NDECL(win_lisp_init);
44
+E void FDECL(lisp_init_nhwindows, (int *, char **));
45
+E void NDECL(lisp_player_selection);
46
+E void NDECL(lisp_askname);
47
+E void NDECL(lisp_get_nh_event) ;
48
+E void FDECL(lisp_exit_nhwindows, (const char *));
49
+E void FDECL(lisp_suspend_nhwindows, (const char *));
50
+E void NDECL(lisp_resume_nhwindows);
51
+E winid FDECL(lisp_create_nhwindow, (int));
52
+E void FDECL(lisp_clear_nhwindow, (winid));
53
+E void FDECL(lisp_display_nhwindow, (winid, BOOLEAN_P));
54
+E void FDECL(lisp_destroy_nhwindow, (winid));
55
+E void FDECL(lisp_curs, (winid,int,int));
56
+E void FDECL(lisp_putstr, (winid, int, const char *));
57
+E void FDECL(lisp_display_file, (const char *, BOOLEAN_P));
58
+E void FDECL(lisp_start_menu, (winid));
59
+E void FDECL(lisp_add_menu, (winid,int,const ANY_P *,
60
+ CHAR_P, CHAR_P, int, const char *, BOOLEAN_P));
61
+E void FDECL(lisp_end_menu, (winid, const char *));
62
+E int FDECL(lisp_select_menu, (winid, int, MENU_ITEM_P **));
63
+E char FDECL(lisp_message_menu, (char, int, const char *mesg));
64
+E void NDECL(lisp_update_inventory);
65
+E void NDECL(lisp_mark_synch);
66
+E void NDECL(lisp_wait_synch);
68
+E void FDECL(lisp_cliparound, (int, int));
71
+E void FDECL(lisp_update_positionbar, (char *));
73
+E void FDECL(lisp_print_glyph, (winid,XCHAR_P,XCHAR_P,int));
74
+E void FDECL(lisp_raw_print, (const char *));
75
+E void FDECL(lisp_raw_print_bold, (const char *));
76
+E int NDECL(lisp_nhgetch);
77
+E int FDECL(lisp_nh_poskey, (int *, int *, int *));
78
+E void NDECL(lisp_nhbell);
79
+E int NDECL(lisp_doprev_message);
80
+E char FDECL(lisp_yn_function, (const char *, const char *, CHAR_P));
81
+E void FDECL(lisp_getlin, (const char *,char *));
82
+E int NDECL(lisp_get_ext_cmd);
83
+E void FDECL(lisp_number_pad, (int));
84
+E void NDECL(lisp_delay_output);
86
+/* other defs that really should go away (they're tty specific) */
87
+E void NDECL(lisp_start_screen);
88
+E void NDECL(lisp_end_screen);
90
+E void FDECL(lisp_outrip, (winid,int));
92
+#endif /* WINLISP_H */
93
diff --git a/src/windows.c b/src/windows.c
94
index 3c59080..d65710c 100644
97
@@ -40,6 +40,10 @@ extern struct window_procs Gnome_procs;
99
extern struct window_procs mswin_procs;
101
+#ifdef LISP_GRAPHICS
102
+#include "winlisp.h"
103
+extern struct window_procs lisp_procs;
106
STATIC_DCL void FDECL(def_raw_print, (const char *s));
108
@@ -81,6 +85,9 @@ struct win_choices {
109
#ifdef MSWIN_GRAPHICS
112
+#ifdef LISP_GRAPHICS
113
+ { &lisp_procs, win_lisp_init },
115
{ 0, 0 } /* must be last */
118
diff --git a/win/lisp/ChangeLog b/win/lisp/ChangeLog
120
index 0000000..8686f14
122
+++ b/win/lisp/ChangeLog
124
+2005-02-27 <katia_dilkina@verizon.net>
126
+ * winlisp.c (CMD_LISP): new define
127
+ (cmd_index): new "travel" command, new "options" command.
128
+ (lisp_coord): new macro
129
+ (lisp_boolean): likewise
130
+ (read_int): flush stdout.
131
+ (read_string): likewise
132
+ (get_options): new function
133
+ (lisp_nhgetch): hande CMD_LISP commands
134
+ (lisp_nhgetch): call impossible if the command is not a CMD_KEY or
136
+ (lisp_display_nhwindow): read a dummy string, not a menu string.
138
+2004-02-09 Shawn Betts <sabetts@vcn.bc.ca>
140
+ * winlisp.c (lisp_yn_function): catch the chat prompt too.
142
+2003-09-19 Shawn Betts <sabetts@vcn.bc.ca>
144
+ * winlisp.c: add extra element to lisp_procs (structure change in 3.4.2).
146
+2003-06-03 Shawn Betts <sabetts@sfu.ca>
148
+ * winlisp.c (lisp_print_glyph): Pass special to the print-glyph
149
+ lisp function as a symbol. delete the MG_PET bit in special if
150
+ iflags.hilite_pet is not set.
151
+ (special_glyph_to_string): new function
153
+2003-05-14 Shawn Betts <sabetts@sfu.ca>
155
+ * winlisp.c (lisp_string): Also escape the backslash character.
157
+2002-09-19 Ryan Yeske <rcyeske@vcn.bc.ca>
159
+ * winlisp.c (lisp_cmd): nethack-api-* renamed to nhapi-*.
161
+2002-09-16 Ryan Yeske <rcyeske@vcn.bc.ca>
163
+ * ../tty/termcap.c (has_color): Add condition for LISP_GRAPHICS
164
+ which returns TRUE.
166
+2002-09-12 Ryan Yeske <rcyeske@vcn.bc.ca>
168
+ * winlisp.c (lisp_display_nhwindow): Add call to
171
+ * ../../include/config.h: Default to LISP_GRAPHICS.
173
+ * ../../sys/unix/Makefile.src (WINSRC,WINOBJ,WINLIB): Set to
175
+ (depend): Add winlisp.o dependancies.
177
+ * winlisp.c (lisp_curs): Don't send winid. Add error check.
178
+ (lisp_putstr): Call `nethack-api-message' or
179
+ `nethack-api-menu-putstr' when appropriate.
180
+ (lisp_nhgetch): Update error message call.
181
+ (lisp_create_nhwindow): Don't send winids when creating message,
182
+ map, or status windows.
183
+ (lisp_clear_nhwindow): Call clear-message or clear-map instead of
185
+ (lisp_display_nhwindow): Call display-menu instead of
186
+ display-nhwindow. Call block when handling case of blocking on
187
+ displaying the map window.
188
+ (lisp_destroy_nhwindow): Use WIN_* values instead of hardcoded
190
+ (lisp_print_glyph): Don't send winid. Add error check for bad
192
+ (lisp_outrip): Change reference to Enethack to nethack-el.
194
+2002-04-23 Shawn <sabetts@vcn.bc.ca>
196
+ * winlisp.c (lisp_player_selection): Update to use new 3.4.0
198
+ (lisp_print_glyph): likewise
200
+2002-02-16 Shawn Betts <sabetts@vcn.bc.ca>
202
+ * winlisp.c (read_string): take a pointer to a string as the
203
+ second argument. All callers updated. Rewritten to dynamically
204
+ resize the string in order to read an entire line.
205
+ (read_command): free the string returned from read_string
206
+ (lisp_askname): likewise
207
+ (lisp_display_nhwindow): likewise
208
+ (lisp_delay_output): likewise
209
+ (lisp_yn_function): likewise
211
+2002-02-14 Shawn Betts <sabetts@vcn.bc.ca>
213
+ * winlisp.c (lisp_print_glyph): Handle warning glyphs.
215
+2002-01-27 Ryan C Yeske <rcyeske@vcn.bc.ca>
217
+ * winlisp.c (generate_status_line): Send flag values
218
+ individually. Always send values for all attributes.
220
+2002-01-21 Ryan C Yeske <rcyeske@vcn.bc.ca>
222
+ * winlisp.c (lisp_add_menu): Add tile argument.
224
+2002-01-22 shawn <sabetts@vcn.bc.ca>
226
+ * winlisp.c (lisp_player_selection): use the existing menu system
227
+ to select a player.
228
+ (lisp_menu_item_t): add a new member, accelerator.
229
+ (lisp_current_accelerator): new static global.
230
+ (lisp_add_menu): pick our own selector when ch is 0.
231
+ (lisp_start_menu): reset lisp_current_accelerator to 'a'.
232
+ (lisp_add_menu): remove the identifier argument to the lisp_cmd
234
+ (lisp_get_menu_identifier): first argument is now a char.
236
+2002-01-20 Ryan C Yeske <rcyeske@vcn.bc.ca>
238
+ * winlisp.c (cmd_index): Add remaining functions.
240
+2002-01-16 Ryan C Yeske <rcyeske@vcn.bc.ca>
242
+ * winlisp.c (lisp_exit_nhwindows): Don't wait for a dummy return
244
+ (lisp_destroy_nhwindow): Don't destroy the status, message or map
247
+2002-01-15 Ryan C Yeske <rcyeske@vcn.bc.ca>
249
+ * winlisp.c (lisp_exit_nhwindows): Don't wait for a dummy return
252
+2002-01-10 shawn <sabetts@vcn.bc.ca>
254
+ * winlisp.c (win_lisp_init): new function
256
+2002-01-09 Ryan C Yeske <rcyeske@sfu.ca>
258
+ * winlisp.c (cmd_index): Add redraw command.
261
+2002-01-01 shawn <sabetts@vcn.bc.ca>
263
+ * winlisp.c (winid_list): new static global
264
+ (winid_list_len): likewise
265
+ (winid_list_max): likewise
266
+ (find_empty_cell): new function
267
+ (winid_is_taken): likewise
268
+ (add_winid): likewise
269
+ (get_unique_winid): likewise
270
+ (return_winid): likewise
271
+ (init_winid_list): likewise
273
+2001-12-20 shawn <sabetts@vcn.bc.ca>
275
+ * winlisp.c (read_command): return the command count as a string.
276
+ (num_digits): remove function
277
+ (power_of_ten): likewise
278
+ (lisp_nhgetch): command count works.
279
+ (enc_stat): extern reference
280
+ (hunger_stat): new constant
281
+ (generate_status_line): new function
282
+ (lisp_putstr): use generate_status_line to create the status line
285
+2001-12-19 shawn <sabetts@vcn.bc.ca>
287
+ * winlisp.c: add extern declaration for glyph2tile and
289
+ (lisp_print_glyph): pass the glyph's graphics tile index as an argument.
291
+2001-12-02 Ryan Yeske <rcyeske@vcn.bc.ca>
293
+ * winlisp.c (lisp_cmd, lisp_list, lisp_t, lisp_nil, lisp_literal)
294
+ (lisp_cons, lisp_int, lisp_string): Update macros. Update all api
295
+ functions to use these macros.
296
+ (read_int, read_string, read_command): New functions. Update all
297
+ api functions to use these functions.
298
+ (lisp_create_nhwindow): Send specific window creation commands.
299
+ (lisp_cliparound): Comment out body.
301
+2001-10-23 Ryan Yeske <rcyeske@vcn.bc.ca>
303
+ * winlisp.c (lisp_nhgetch): Don't silently loop on invalid
304
+ commands, send back a warning.
305
+ (lisp_yn_function): Make sure special handling is done for all
306
+ direction questions. Include prompt in call to
307
+ nethack-api-ask-direction. Include up, down and self directions.
308
+ If no default is set for a direction question, return space.
310
+2001-10-19 shawn <sabetts@vcn.bc.ca>
312
+ * winlisp.c (lisp_init_nhwindows): turn on showexp and time flags.
314
+2001-10-17 Ryan Yeske <rcyeske@vcn.bc.ca>
316
+ * winlisp.c (lisp_display_nhwindow): Wait for a string if we are
319
+2001-07-19 shawn <sabetts@diggin.lamenet.tmp>
321
+ * winlisp.c (lisp_player_selection): terminate if we read a -1 as
324
+2001-07-16 Ryan Yeske <rcyeske@vcn.bc.ca>
326
+ * winlisp.c (lisp_delay_output): expect a return value from the
329
+2001-07-14 Ryan Yeske <rcyeske@vcn.bc.ca>
331
+ * winlisp.c (lisp_add_menu): Quote the attribute.
332
+ (lisp_outrip): Add a newline to output.
334
+2001-07-06 shawn <sabetts@diggin.lamenet.tmp>
336
+ * winlisp.c (num_digits): new function
337
+ (power_of_ten): likewise
338
+ (lisp_nhgetch): handles repeated commands.
340
+2001-07-05 shawn <sabetts@diggin.lamenet.tmp>
342
+ * winlisp.c (WINLISP_VOID_RETVAL): flushes stdout
344
+2001-07-04 Ryan Yeske <rcyeske@van.gobasis.com>
346
+ * winlisp.c (lisp_add_menu): Convert printf to lisp_* macros,
347
+ fixing a string quote bug.
349
+2001-06-28 shawn <sabetts@diggin.lamenet.tmp>
351
+ * winlisp.c (zap_color): new define
352
+ (cmap_color): likewise
353
+ (obj_color): likewise
354
+ (mon_color): likewise
355
+ (invis_color): likewise
356
+ (pet_color): likewise
357
+ (lisp_print_glyph): export the color. export the ascii character
360
+2001-06-27 shawn <sabetts@diggin.lamenet.tmp>
362
+ * winlisp.c: fix a typo cmd_index
363
+ (lisp_yn_function): pass characters as numbers instead of ascii
364
+ characters. specially handle the "In what direction?" question.
365
+ (lisp_outrip): prints a properly formed lisp expression.
367
+2001-06-21 Shawn Betts <sabetts@van.gobasis.com>
369
+ * winlisp.c (lisp_add_menu): items that are not selectable are
370
+ sent with an identifier of -1.
371
+ (lisp_select_menu): handle failed memory
374
+2001-05-06 shawn <sabetts@diggin.lamenet.tmp>
376
+ * winlisp.c (LINESIZ): new define
377
+ (lisp_menu_item_t): new struct
378
+ (lisp_menu_item_list): new static global
379
+ (lisp_menu_list_size): likewise
380
+ (lisp_menu_list_num): likewise
381
+ (cmd_index): fixed ddrop entry
382
+ (read_int): new function
383
+ (lisp_player_selection): use read_int
384
+ (lisp_askname): read the entire line to a string and parse data
386
+ (lisp_nhgetch): likewise
387
+ (lisp_create_nhwindow): likewise
388
+ (lisp_getlin): likewise
389
+ (lisp_yn_function): likewise
390
+ (lisp_start_menu): set lisp_menu_list_num to 0
391
+ (lisp_add_menu): add an entry to lisp_menu_item_list
392
+ (lisp_add_menu): pass the item's ID to the client instead of the
394
+ (lisp_get_menu_identifier): new function
395
+ (lisp_select_menu): parse the list of selected menu items
396
+ (lisp_print_glyph): escape backslashes in output
398
+2000-10-01 Ryan Yeske <rcyeske@vcn.bc.ca>
400
+ * winlisp.c (cmd_index): renamed "ddoremarm" to "remarm" and
403
+2000-09-25 Shawn <sabetts@vcn.bc.ca>
405
+ * winlisp.c: Added more key commands.
406
+ (lisp_player_selection): honours default player selections as
407
+ specified in the nethackrc file.
409
+2000-09-22 Shawn <sabetts@vcn.bc.ca>
411
+ * winlisp.c (lisp_nhgetch): changed while loop stop condition.
413
+2000-09-19 Ryan yeske <rcyeske@van.gobasis.com>
415
+ * winlisp.c (lisp_nh_getch): renamed from lisp_nh_getcmd() since
416
+ this is really called by the core when nethack wants a key.
417
+ (cmd_index): added gowest, gosouth, gonorth, goeast.
419
+2000-09-12 shawn <sabetts@gobasis.com>
421
+ * winlisp.c (lisp_nh_poskey): Added code to read in an x,y,mod
422
+ combination instead of calling lisp_nhgetcmd. Currently commented
423
+ out until the lisp side catches up. added cmd_index structure to
424
+ translate incoming command strings to extended commands or
425
+ keystrokes. Changed lisp_nhgetch to lisp_nhgetcmd and changed the
426
+ lisp command it calls to 'nethack-get-command'.
428
+2000-09-11 Ryan Yeske <rcyeske@vcn.bc.ca>
430
+ * winlisp.c (lisp_cmd, lisp_close_cmd, lisp_open, lisp_close,
431
+ lisp_quote, lisp_int, lisp_string, lisp_dot): created macros.
433
+2000-09-10 Ryan Yeske <rcyeske@vcn.bc.ca>
435
+ * winlisp.c (lisp_outrip): added closing paren.
437
+2000-08-21 Ryan Yeske <rcyeske@vcn.bc.ca>
439
+ * winlisp.c (lisp_nhgetch): change ch type to int from char.
441
+2000-08-20 Ryan Yeske <rcyeske@vcn.bc.ca>
443
+ * winlisp.c (lisp_player_selection): role/race/gender/alignment
444
+ selection now sends (nethack-apix-choose-X ALIST) instead of
446
+ (lisp_update_inventory):
447
+ s/nethack-api-updated-inventory/nethack-api-update-inventory/
448
+ (WINLISP_VOID_RETVAL): added macro, called for every void
450
diff --git a/win/lisp/winlisp.c b/win/lisp/winlisp.c
452
index 0000000..290a457
454
+++ b/win/lisp/winlisp.c
456
+/* Copyright (c) Shawn Betts, Ryan Yeske, 2001 */
457
+/* NetHack may be freely redistributed. See license for details. */
460
+ * "Main" file for the lisp/emacs window-port. This contains most of
461
+ * the interface routines. Please see doc/window.doc for an
462
+ * description of the window interface.
465
+#ifdef MSDOS /* from compiler */
466
+#define SHORT_FILENAMES
470
+#include "winlisp.h"
471
+#include "func_tab.h"
474
+#ifdef SHORT_FILENAMES
475
+#include "patchlev.h"
477
+#include "patchlevel.h"
482
+#define CMD_LISP 2 /* These are commands specific to the lisp port */
485
+extern short glyph2tile[];
486
+extern int total_tiles_used;
490
+ anything identifier;
494
+/* An iterator for assigning accelerator keys. */
495
+static char lisp_current_accelerator;
497
+/* Helper structures to map menu id's to nethack anything's */
498
+static lisp_menu_item_t lisp_menu_item_list[1000];
499
+static int lisp_menu_list_size = 1000;
500
+static int lisp_menu_list_num;
502
+extern char *enc_stat[];
503
+const char *hunger_stat[] = {
517
+ int cmd; /* The command (a keystroke) */
521
+#define C(c) (0x1f & (c))
524
+/* Taken from cmd.c */
525
+cmd_index_t cmd_index[] = { {"gowest", CMD_KEY, 'h'},
526
+ {"gowestontop", CMD_KEY, 'H'},
527
+ {"gowestnear", CMD_KEY, C('h')},
529
+ {"gosouth", CMD_KEY, 'j'},
530
+ {"gosouthontop", CMD_KEY, 'J'},
531
+ {"gosouthnear", CMD_KEY, C('j')},
533
+ {"gonorth", CMD_KEY, 'k'},
534
+ {"gonorthontop", CMD_KEY, 'K'},
535
+ {"gonorthnear", CMD_KEY, C('k')},
537
+ {"goeast", CMD_KEY, 'l'},
538
+ {"goeastontop", CMD_KEY, 'L'},
539
+ {"goeastnear", CMD_KEY, C('l')},
541
+ {"gonorthwest", CMD_KEY, 'y'},
542
+ {"gonorthwestontop", CMD_KEY, 'Y'},
543
+ {"gonorthwestnear", CMD_KEY, C('y')},
545
+ {"gonortheast", CMD_KEY, 'u'},
546
+ {"gonortheastontop", CMD_KEY, 'U'},
547
+ {"gonortheastnear", CMD_KEY, C('u')},
549
+ {"gosouthwest", CMD_KEY, 'b'},
550
+ {"gosouthwestontop", CMD_KEY, 'B'},
551
+ {"gosouthwestnear", CMD_KEY, C('b')},
553
+ {"gosoutheast", CMD_KEY, 'n'},
554
+ {"gosoutheastontop", CMD_KEY, 'N'},
555
+ {"gosoutheastnear", CMD_KEY, C('n')},
557
+ {"travel", CMD_KEY, '_'},
559
+ {"idtrap", CMD_KEY, '^'},
560
+ {"apply", CMD_KEY, 'a'},
561
+ {"remarm", CMD_KEY, 'A'},
562
+ {"close", CMD_KEY, 'c'},
563
+ {"drop", CMD_KEY, 'd'},
565
+ {"ddrop", CMD_KEY, 'D'},
566
+ {"eat", CMD_KEY, 'e'},
567
+ {"engrave", CMD_KEY, 'E'},
568
+ {"fire", CMD_KEY, 'f'},
569
+ {"inv", CMD_KEY, 'i'},
571
+ {"typeinv", CMD_KEY, 'I'},
572
+ {"open", CMD_KEY, 'o'},
573
+ {"set", CMD_KEY, 'O'},
574
+ {"pay", CMD_KEY, 'p'},
575
+ {"puton", CMD_KEY, 'P'},
577
+ {"drink", CMD_KEY, 'q'},
578
+ {"wieldquiver", CMD_KEY, 'Q'},
579
+ {"read", CMD_KEY, 'r'},
580
+ {"remring", CMD_KEY, 'R'},
581
+ {"search", CMD_KEY, 's'},
583
+ {"save", CMD_KEY, 'S'},
584
+ {"throw", CMD_KEY, 't'},
585
+ {"takeoff", CMD_KEY, 'T'},
586
+ {"simpleversion", CMD_KEY, 'v'},
587
+ {"history", CMD_KEY, 'V'},
589
+ {"wield", CMD_KEY, 'w'},
590
+ {"wear", CMD_KEY, 'W'},
591
+ {"swapweapon", CMD_KEY, 'x'},
592
+ {"enter_explore_mode", CMD_KEY, 'X'},
593
+ {"zap", CMD_KEY, 'z'},
595
+ {"cast", CMD_KEY, 'Z'},
596
+ {"up", CMD_KEY, '<'},
597
+ {"down", CMD_KEY, '>'},
598
+ {"whatis", CMD_KEY, '/'},
599
+ {"help", CMD_KEY, '?'},
601
+ {"whatdoes", CMD_KEY, '&'},
602
+ {"sh", CMD_KEY, '!'},
603
+ {"discovered", CMD_KEY, '\\'},
604
+ {"null", CMD_KEY, '.'},
605
+ {"look", CMD_KEY, ':'},
607
+ {"quickwhatis", CMD_KEY, ';'},
608
+ {"pickup", CMD_KEY, ','},
609
+ {"togglepickup", CMD_KEY, '@'},
610
+ {"prinuse", CMD_KEY, '*'},
611
+ {"countgold", CMD_KEY, '$'},
613
+ {"kick", CMD_KEY, C('d')},
614
+ {"listspells", CMD_KEY, '+'},
615
+ {"redraw", CMD_KEY, C('r')},
616
+ {"teleport", CMD_KEY, C('t')},
617
+ {"callmon", CMD_KEY, 'C'},
618
+ {"fight", CMD_KEY, 'F'},
619
+ {"movenear", CMD_KEY, 'g'},
620
+ {"move", CMD_KEY, 'G'},
621
+ {"movenopickuporfight", CMD_KEY, 'm'},
622
+ {"movenopickup", CMD_KEY, 'M'},
623
+ {"showweapon", CMD_KEY, ')'},
624
+ {"showarmor", CMD_KEY, '['},
625
+ {"showrings", CMD_KEY, '='},
626
+ {"showamulet", CMD_KEY, '"'},
627
+ {"showtool", CMD_KEY, '('},
628
+ {"attributes", CMD_KEY, C('x')},
630
+ {"again", CMD_KEY, DOAGAIN},
633
+ /* wizard commands */
634
+ {"wiz_detect", CMD_KEY, C('e')},
635
+ {"wiz_map", CMD_KEY, C('f')},
636
+ {"wiz_genesis", CMD_KEY, C('g')},
637
+ {"wiz_identify", CMD_KEY, C('i')},
638
+ {"wiz_where", CMD_KEY, C('o')},
639
+ {"wiz_level_tele", CMD_KEY, C('v')},
640
+ {"wiz_wish", CMD_KEY, C('w')},
642
+ /* wizard extended commands */
644
+ {"light sources", CMD_EXT, 0},
645
+ {"seenv", CMD_EXT, 0},
646
+ {"stats", CMD_EXT, 0},
647
+ {"timeout", CMD_EXT, 0},
648
+ {"vision", CMD_EXT, 0},
650
+ {"wizdebug", CMD_EXT, 0},
652
+ {"wmode", CMD_EXT, 0},
654
+ {"pray", CMD_EXT, 0},
655
+ {"adjust", CMD_EXT, 0},
656
+ {"chat", CMD_EXT, 0},
657
+ {"conduct", CMD_EXT, 0},
658
+ {"dip", CMD_EXT, 0},
660
+ {"enhance", CMD_EXT, 0},
661
+ {"force", CMD_EXT, 0},
662
+ {"invoke", CMD_EXT, 0},
663
+ {"jump", CMD_EXT, 0},
664
+ {"loot", CMD_EXT, 0},
666
+ {"monster", CMD_EXT, 0},
667
+ {"name", CMD_EXT, 0},
668
+ {"offer", CMD_EXT, 0},
669
+ {"quit", CMD_EXT, 0},
670
+ {"ride", CMD_EXT, 0},
672
+ {"rub", CMD_EXT, 0},
673
+ {"sit", CMD_EXT, 0},
674
+ {"turn", CMD_EXT, 0},
675
+ {"twoweapon", CMD_EXT, 0},
676
+ {"untrap", CMD_EXT, 0},
678
+ {"version", CMD_EXT, 0},
679
+ {"wipe", CMD_EXT, 0},
681
+ /* Lisp port specific commands */
682
+ {"options", CMD_LISP, 0},
684
+ {0, CMD_KEY, '\0'} };
686
+/* This variable is set when the user has selected an extended command. */
687
+static int extended_cmd_id;
689
+/* Interface definition, for windows.c */
690
+struct window_procs lisp_procs = {
692
+ WC_COLOR|WC_HILITE_PET,
694
+ lisp_init_nhwindows,
695
+ lisp_player_selection,
698
+ lisp_exit_nhwindows,
699
+ lisp_suspend_nhwindows,
700
+ lisp_resume_nhwindows,
701
+ lisp_create_nhwindow,
702
+ lisp_clear_nhwindow,
703
+ lisp_display_nhwindow,
704
+ lisp_destroy_nhwindow,
713
+ lisp_update_inventory,
720
+ lisp_update_positionbar,
724
+ lisp_raw_print_bold,
728
+ lisp_doprev_message,
734
+#ifdef CHANGE_COLOR /* the Mac uses a palette device */
738
+ /* other defs that really should go away (they're tty specific) */
742
+ genl_preference_update,
745
+/* macros for printing lisp output */
746
+#define lisp_cmd(s,body) \
749
+ printf("(nhapi-%s ",s); \
754
+/* #define lisp_cmd0(s) printf ("(nhapi-%s)\n", s) */
755
+#define lisp_list(body) \
764
+#define lisp_open printf("(")
765
+#define lisp_close printf(") ")
766
+#define lisp_quote printf("'")
767
+#define lisp_dot printf(". ")
768
+#define lisp_t printf("t ")
769
+#define lisp_nil printf("nil ")
770
+#define lisp_literal(x) \
774
+ printf ("%s ", x); \
777
+#define lisp_cons(x,y) \
787
+#define lisp_int(i) printf("%d ",i)
788
+#define lisp_coord(c) printf("'(%d,%d) ",c.x,c.y)
789
+#define lisp_boolean(i) printf("%s ",i?"t":"nil")
790
+#define lisp_string(s) \
796
+ for (nhi=0;nhi<strlen(s);nhi++) \
799
+ || s[nhi] == 92) putchar('\\'); \
807
+attr_to_string(attr)
815
+ return "atr-uline";
819
+ return "atr-blink";
821
+ return "atr-inverse";
823
+ /* Should never happen. */
824
+ impossible ("Invalid attribute code.");
825
+ exit (EXIT_FAILURE);
831
+special_glyph_to_string(special)
848
+ /* If it's a combination, just return special. */
856
+wintype_to_string(type)
864
+ return "nhw-message";
866
+ return "nhw-status";
872
+ fprintf (stderr, "Invalid window code\n");
873
+ exit (EXIT_FAILURE);
885
+ return "pick-none";
891
+ impossible ("Invalid how value %d", how);
896
+read_int (prompt, i)
897
+ const char* prompt;
902
+ printf ("%s> ", prompt);
904
+ fgets (line, BUFSZ, stdin);
905
+ rv = sscanf (line, "%d", i);
906
+ if (rv != 1) *i = -1;
911
+read_string (prompt, str)
912
+ const char* prompt;
922
+ *str = malloc (size);
925
+ printf ("%s> ", prompt);
929
+ /* Read the string */
930
+ rv = fgets (tmp, BUFSZ, stdin);
934
+ len += strlen (tmp);
935
+ if (len >= size - 1)
938
+ *str = realloc (*str, size);
940
+ panic ("Memory allocation failure; cannot get %u bytes", size);
942
+ strcat (*str, tmp);
943
+ } while (tmp[strlen (tmp) - 1] != '\n');
945
+ /* Did we read a string or error out? */
953
+ /* chop the newline */
954
+ (*str) [strlen (*str) - 1] = '\0';
961
+read_command (prompt, cmd, count)
962
+ const char *prompt;
970
+ if (read_string (prompt, &buf) == -1)
972
+ rv = sscanf (buf, "%s %s", cmd, count);
974
+ if (rv != 2) *count = 0;
983
+ lisp_exit_nhwindows (mesg);
984
+ terminate (EXIT_SUCCESS);
991
+ /* Code to be executed on startup. */
995
+lisp_player_selection ()
998
+ char pick4u = 'n', thisch, lastch = 0;
999
+ char pbuf[QBUFSZ], plbuf[QBUFSZ];
1002
+ menu_item *selected = 0;
1004
+ /* prevent an unnecessary prompt */
1005
+ rigid_role_checks();
1007
+ /* Should we randomly pick for the player? */
1008
+ if (!flags.randomall &&
1009
+ (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE ||
1010
+ flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) {
1012
+ pick4u = lisp_yn_function ("Shall I pick a character for you? [ynq] ", "ynq", 'y');
1014
+ if (pick4u != 'y' && pick4u != 'n')
1016
+ give_up: /* Quit */
1017
+ if (selected) free((genericptr_t) selected);
1025
+ (void) root_plselection_prompt(plbuf, QBUFSZ - 1,
1026
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
1028
+ /* Select a role, if necessary */
1029
+ /* we'll try to be compatible with pre-selected race/gender/alignment,
1030
+ * but may not succeed */
1031
+ if (flags.initrole < 0) {
1032
+ char rolenamebuf[QBUFSZ];
1033
+ /* Process the choice */
1034
+ if (pick4u == 'y' || flags.initrole == ROLE_RANDOM || flags.randomall) {
1035
+ /* Pick a random role */
1036
+ flags.initrole = pick_role(flags.initrace, flags.initgend,
1037
+ flags.initalign, PICK_RANDOM);
1038
+ if (flags.initrole < 0) {
1039
+/* lisp_putstr(BASE_WINDOW, 0, "Incompatible role!"); */
1040
+ flags.initrole = randrole();
1043
+ /* Prompt for a role */
1044
+ win = create_nhwindow(NHW_MENU);
1046
+ any.a_void = 0; /* zero out all bits */
1047
+ for (i = 0; roles[i].name.m; i++) {
1048
+ if (ok_role(i, flags.initrace, flags.initgend,
1049
+ flags.initalign)) {
1050
+ any.a_int = i+1; /* must be non-zero */
1051
+ thisch = lowc(roles[i].name.m[0]);
1052
+ if (thisch == lastch) thisch = highc(thisch);
1053
+ if (flags.initgend != ROLE_NONE && flags.initgend != ROLE_RANDOM) {
1054
+ if (flags.initgend == 1 && roles[i].name.f)
1055
+ Strcpy(rolenamebuf, roles[i].name.f);
1057
+ Strcpy(rolenamebuf, roles[i].name.m);
1059
+ if (roles[i].name.f) {
1060
+ Strcpy(rolenamebuf, roles[i].name.m);
1061
+ Strcat(rolenamebuf, "/");
1062
+ Strcat(rolenamebuf, roles[i].name.f);
1064
+ Strcpy(rolenamebuf, roles[i].name.m);
1066
+ add_menu(win, NO_GLYPH, &any, thisch,
1067
+ 0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED);
1071
+ any.a_int = pick_role(flags.initrace, flags.initgend,
1072
+ flags.initalign, PICK_RANDOM)+1;
1073
+ if (any.a_int == 0) /* must be non-zero */
1074
+ any.a_int = randrole()+1;
1075
+ add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
1076
+ "Random", MENU_UNSELECTED);
1077
+ any.a_int = i+1; /* must be non-zero */
1078
+ add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
1079
+ "Quit", MENU_UNSELECTED);
1080
+ Sprintf(pbuf, "Pick a role for your %s", plbuf);
1081
+ end_menu(win, pbuf);
1082
+ n = select_menu(win, PICK_ONE, &selected);
1083
+ destroy_nhwindow(win);
1085
+ /* Process the choice */
1086
+ if (n != 1 || selected[0].item.a_int == any.a_int)
1087
+ goto give_up; /* Selected quit */
1089
+ flags.initrole = selected[0].item.a_int - 1;
1090
+ free((genericptr_t) selected), selected = 0;
1092
+ (void) root_plselection_prompt(plbuf, QBUFSZ - 1,
1093
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
1096
+ /* Select a race, if necessary */
1097
+ /* force compatibility with role, try for compatibility with
1098
+ * pre-selected gender/alignment */
1099
+ if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) {
1100
+ /* pre-selected race not valid */
1101
+ if (pick4u == 'y' || flags.initrace == ROLE_RANDOM || flags.randomall) {
1102
+ flags.initrace = pick_race(flags.initrole, flags.initgend,
1103
+ flags.initalign, PICK_RANDOM);
1104
+ if (flags.initrace < 0) {
1105
+/* lisp_putstr(BASE_WINDOW, 0, "Incompatible race!"); */
1106
+ flags.initrace = randrace(flags.initrole);
1108
+ } else { /* pick4u == 'n' */
1109
+ /* Count the number of valid races */
1110
+ n = 0; /* number valid */
1111
+ k = 0; /* valid race */
1112
+ for (i = 0; races[i].noun; i++) {
1113
+ if (ok_race(flags.initrole, i, flags.initgend,
1114
+ flags.initalign)) {
1120
+ for (i = 0; races[i].noun; i++) {
1121
+ if (validrace(flags.initrole, i)) {
1128
+ /* Permit the user to pick, if there is more than one */
1130
+ win = create_nhwindow(NHW_MENU);
1132
+ any.a_void = 0; /* zero out all bits */
1133
+ for (i = 0; races[i].noun; i++)
1134
+ if (ok_race(flags.initrole, i, flags.initgend,
1135
+ flags.initalign)) {
1136
+ any.a_int = i+1; /* must be non-zero */
1137
+ add_menu(win, NO_GLYPH, &any, races[i].noun[0],
1138
+ 0, ATR_NONE, races[i].noun, MENU_UNSELECTED);
1140
+ any.a_int = pick_race(flags.initrole, flags.initgend,
1141
+ flags.initalign, PICK_RANDOM)+1;
1142
+ if (any.a_int == 0) /* must be non-zero */
1143
+ any.a_int = randrace(flags.initrole)+1;
1144
+ add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
1145
+ "Random", MENU_UNSELECTED);
1146
+ any.a_int = i+1; /* must be non-zero */
1147
+ add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
1148
+ "Quit", MENU_UNSELECTED);
1149
+ Sprintf(pbuf, "Pick the race of your %s", plbuf);
1150
+ end_menu(win, pbuf);
1151
+ n = select_menu(win, PICK_ONE, &selected);
1152
+ destroy_nhwindow(win);
1153
+ if (n != 1 || selected[0].item.a_int == any.a_int)
1154
+ goto give_up; /* Selected quit */
1156
+ k = selected[0].item.a_int - 1;
1157
+ free((genericptr_t) selected), selected = 0;
1159
+ flags.initrace = k;
1161
+ (void) root_plselection_prompt(plbuf, QBUFSZ - 1,
1162
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
1165
+ /* Select a gender, if necessary */
1166
+ /* force compatibility with role/race, try for compatibility with
1167
+ * pre-selected alignment */
1168
+ if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace,
1169
+ flags.initgend)) {
1170
+ /* pre-selected gender not valid */
1171
+ if (pick4u == 'y' || flags.initgend == ROLE_RANDOM || flags.randomall) {
1172
+ flags.initgend = pick_gend(flags.initrole, flags.initrace,
1173
+ flags.initalign, PICK_RANDOM);
1174
+ if (flags.initgend < 0) {
1175
+/* lisp_putstr(BASE_WINDOW, 0, "Incompatible gender!"); */
1176
+ flags.initgend = randgend(flags.initrole, flags.initrace);
1178
+ } else { /* pick4u == 'n' */
1179
+ /* Count the number of valid genders */
1180
+ n = 0; /* number valid */
1181
+ k = 0; /* valid gender */
1182
+ for (i = 0; i < ROLE_GENDERS; i++) {
1183
+ if (ok_gend(flags.initrole, flags.initrace, i,
1184
+ flags.initalign)) {
1190
+ for (i = 0; i < ROLE_GENDERS; i++) {
1191
+ if (validgend(flags.initrole, flags.initrace, i)) {
1198
+ /* Permit the user to pick, if there is more than one */
1200
+ win = create_nhwindow(NHW_MENU);
1202
+ any.a_void = 0; /* zero out all bits */
1203
+ for (i = 0; i < ROLE_GENDERS; i++)
1204
+ if (ok_gend(flags.initrole, flags.initrace, i,
1205
+ flags.initalign)) {
1207
+ add_menu(win, NO_GLYPH, &any, genders[i].adj[0],
1208
+ 0, ATR_NONE, genders[i].adj, MENU_UNSELECTED);
1210
+ any.a_int = pick_gend(flags.initrole, flags.initrace,
1211
+ flags.initalign, PICK_RANDOM)+1;
1212
+ if (any.a_int == 0) /* must be non-zero */
1213
+ any.a_int = randgend(flags.initrole, flags.initrace)+1;
1214
+ add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
1215
+ "Random", MENU_UNSELECTED);
1216
+ any.a_int = i+1; /* must be non-zero */
1217
+ add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
1218
+ "Quit", MENU_UNSELECTED);
1219
+ Sprintf(pbuf, "Pick the gender of your %s", plbuf);
1220
+ end_menu(win, pbuf);
1221
+ n = select_menu(win, PICK_ONE, &selected);
1222
+ destroy_nhwindow(win);
1223
+ if (n != 1 || selected[0].item.a_int == any.a_int)
1224
+ goto give_up; /* Selected quit */
1226
+ k = selected[0].item.a_int - 1;
1227
+ free((genericptr_t) selected), selected = 0;
1229
+ flags.initgend = k;
1231
+ (void) root_plselection_prompt(plbuf, QBUFSZ - 1,
1232
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
1235
+ /* Select an alignment, if necessary */
1236
+ /* force compatibility with role/race/gender */
1237
+ if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace,
1238
+ flags.initalign)) {
1239
+ /* pre-selected alignment not valid */
1240
+ if (pick4u == 'y' || flags.initalign == ROLE_RANDOM || flags.randomall) {
1241
+ flags.initalign = pick_align(flags.initrole, flags.initrace,
1242
+ flags.initgend, PICK_RANDOM);
1243
+ if (flags.initalign < 0) {
1244
+/* lisp_putstr(BASE_WINDOW, 0, "Incompatible alignment!"); */
1245
+ flags.initalign = randalign(flags.initrole, flags.initrace);
1247
+ } else { /* pick4u == 'n' */
1248
+ /* Count the number of valid alignments */
1249
+ n = 0; /* number valid */
1250
+ k = 0; /* valid alignment */
1251
+ for (i = 0; i < ROLE_ALIGNS; i++) {
1252
+ if (ok_align(flags.initrole, flags.initrace, flags.initgend,
1259
+ for (i = 0; i < ROLE_ALIGNS; i++) {
1260
+ if (validalign(flags.initrole, flags.initrace, i)) {
1267
+ /* Permit the user to pick, if there is more than one */
1269
+ win = create_nhwindow(NHW_MENU);
1271
+ any.a_void = 0; /* zero out all bits */
1272
+ for (i = 0; i < ROLE_ALIGNS; i++)
1273
+ if (ok_align(flags.initrole, flags.initrace,
1274
+ flags.initgend, i)) {
1276
+ add_menu(win, NO_GLYPH, &any, aligns[i].adj[0],
1277
+ 0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED);
1279
+ any.a_int = pick_align(flags.initrole, flags.initrace,
1280
+ flags.initgend, PICK_RANDOM)+1;
1281
+ if (any.a_int == 0) /* must be non-zero */
1282
+ any.a_int = randalign(flags.initrole, flags.initrace)+1;
1283
+ add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
1284
+ "Random", MENU_UNSELECTED);
1285
+ any.a_int = i+1; /* must be non-zero */
1286
+ add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
1287
+ "Quit", MENU_UNSELECTED);
1288
+ Sprintf(pbuf, "Pick the alignment of your %s", plbuf);
1289
+ end_menu(win, pbuf);
1290
+ n = select_menu(win, PICK_ONE, &selected);
1291
+ destroy_nhwindow(win);
1292
+ if (n != 1 || selected[0].item.a_int == any.a_int)
1293
+ goto give_up; /* Selected quit */
1295
+ k = selected[0].item.a_int - 1;
1296
+ free((genericptr_t) selected), selected = 0;
1298
+ flags.initalign = k;
1302
+/* lisp_display_nhwindow(BASE_WINDOW, FALSE); */
1305
+/* Reads from standard in, the player's name. */
1310
+ lisp_cmd ("askname",);
1311
+ read_string ("string", &line);
1312
+ strncpy (plname, line, PL_NSIZ);
1313
+ plname[PL_NSIZ-1] = '\0';
1317
+/* This is a noop for tty and X, so should it be a noop for us too? */
1319
+lisp_get_nh_event ()
1321
+/* lisp_cmd ("get-event",); */
1324
+/* Global Functions */
1326
+lisp_raw_print(str)
1329
+ lisp_cmd ("raw-print", lisp_string (str));
1333
+lisp_raw_print_bold(str)
1336
+ lisp_cmd ("raw-print-bold", lisp_string (str));
1340
+lisp_curs(window, x, y)
1344
+ if (window == WIN_MAP)
1348
+ else if (window == WIN_STATUS)
1353
+ lisp_cmd ("error", lisp_string("lisp_curs bad window"); lisp_int (window));
1356
+/* Send the options to the lisp process */
1360
+ lisp_cmd ("options",
1361
+ lisp_boolean(iflags.cbreak); /* in cbreak mode, rogue format */
1362
+ lisp_boolean(iflags.DECgraphics); /* use DEC VT-xxx extended character set */
1363
+ lisp_boolean(iflags.echo); /* 1 to echo characters */
1364
+ lisp_boolean(iflags.IBMgraphics); /* use IBM extended character set */
1365
+ lisp_int(iflags.msg_history); /* hint: # of top lines to save */
1366
+ lisp_boolean(iflags.num_pad); /* use numbers for movement commands */
1367
+ lisp_boolean(iflags.news); /* print news */
1368
+ lisp_boolean(iflags.window_inited); /* true if init_nhwindows() completed */
1369
+ lisp_boolean(iflags.vision_inited); /* true if vision is ready */
1370
+ lisp_boolean(iflags.menu_tab_sep); /* Use tabs to separate option menu fields */
1371
+ lisp_boolean(iflags.menu_requested); /* Flag for overloaded use of 'm' prefix
1372
+ * on some non-move commands */
1373
+ lisp_int(iflags.num_pad_mode);
1374
+ lisp_int(iflags.purge_monsters); /* # of dead monsters still on fmon list */
1375
+/* lisp_int(*iflags.opt_booldup); /\* for duplication of boolean opts in config file *\/ */
1376
+/* lisp_int(*iflags.opt_compdup); /\* for duplication of compound opts in config file *\/ */
1377
+ lisp_int(iflags.bouldersym); /* symbol for boulder display */
1378
+ lisp_coord(iflags.travelcc); /* coordinates for travel_cache */
1380
+ lisp_boolean(iflags.sanity_check); /* run sanity checks */
1381
+ lisp_boolean(iflags.mon_polycontrol); /* debug: control monster polymorphs */
1387
+generate_status_line ()
1389
+ /* Ripped from botl.c */
1392
+ hp = Upolyd ? u.mh : u.uhp;
1393
+ hpmax = Upolyd ? u.mhmax : u.uhpmax;
1394
+ if(hp < 0) hp = 0;
1396
+ printf ("(nhapi-update-status ");
1399
+ lisp_list (lisp_string ("name");
1400
+ lisp_string (plname););
1406
+ lisp_list (lisp_string ("rank");
1408
+ lisp_list (lisp_string ("monster");
1409
+ lisp_string (mons[u.umonnum].mname));
1413
+ lisp_list (lisp_string ("rank");
1414
+ lisp_string (rank_of(u.ulevel, Role_switch, flags.female)););;
1415
+ lisp_list (lisp_string ("monster");
1419
+ lisp_list (lisp_string ("St");
1420
+ lisp_int (ACURR(A_STR)););
1421
+ lisp_list (lisp_string ("Dx");
1422
+ lisp_int (ACURR(A_DEX)););
1423
+ lisp_list (lisp_string ("Co");
1424
+ lisp_int (ACURR(A_CON)););
1425
+ lisp_list (lisp_string ("In");
1426
+ lisp_int (ACURR(A_INT)););
1427
+ lisp_list (lisp_string ("Wi");
1428
+ lisp_int (ACURR(A_WIS)););
1429
+ lisp_list (lisp_string ("Ch");
1430
+ lisp_int (ACURR(A_CHA)););
1431
+ lisp_list (lisp_string ("Align");
1432
+ if (u.ualign.type == A_CHAOTIC)
1433
+ lisp_string ("Chaotic");
1434
+ else if (u.ualign.type == A_NEUTRAL)
1435
+ lisp_string ("Neutral");
1437
+ lisp_string ("Lawful"););
1439
+#ifdef SCORE_ON_BOTL
1440
+ lisp_list (lisp_string ("Score");
1441
+ lisp_int (botl_score()););
1444
+ if (In_endgame(&u.uz))
1446
+ lisp_list (lisp_string ("Dungeon");
1447
+ if (Is_astralevel(&u.uz))
1448
+ lisp_string ("Astral Plane");
1450
+ lisp_string ("End Game"););
1454
+ lisp_list (lisp_string ("Dungeon");
1455
+ lisp_string (dungeons[u.uz.dnum].dname););
1458
+ lisp_list (lisp_string ("Dlvl");
1459
+ lisp_int (depth(&u.uz)););
1461
+ lisp_list (lisp_string ("$");
1462
+ lisp_int (u.ugold););
1463
+ lisp_list (lisp_string ("HP");
1465
+ lisp_list (lisp_string ("HPmax");
1466
+ lisp_int (hpmax););
1467
+ lisp_list (lisp_string ("PW");
1468
+ lisp_int (u.uen););
1469
+ lisp_list (lisp_string ("PWmax");
1470
+ lisp_int (u.uenmax););
1471
+ lisp_list (lisp_string ("AC");
1472
+ lisp_int (u.uac););
1476
+ lisp_list (lisp_string ("HD");
1477
+ lisp_int (mons[u.umonnum].mlevel););
1481
+ lisp_list (lisp_string ("HD");
1485
+ lisp_list (lisp_string ("Level");
1486
+ lisp_int (u.ulevel););
1488
+ lisp_list (lisp_string ("XP");
1489
+ lisp_int (u.uexp););
1491
+ lisp_list (lisp_string ("T");
1492
+ lisp_int (moves););
1495
+ lisp_list (lisp_string ("confusion"); lisp_string ("Conf"));
1497
+ lisp_list (lisp_string ("confusion"); lisp_nil);
1500
+ lisp_list (lisp_string ("hunger"); lisp_string (hunger_stat[u.uhs]));
1502
+ lisp_list (lisp_string ("hunger"); lisp_nil);
1506
+ if (u.usick_type & SICK_VOMITABLE)
1507
+ lisp_list (lisp_string ("sick"); lisp_string ("FoodPois"));
1508
+ if (u.usick_type & SICK_NONVOMITABLE)
1509
+ lisp_list (lisp_string ("sick"); lisp_string ("Ill"));
1512
+ lisp_list (lisp_string ("sick"); lisp_nil);
1515
+ lisp_list (lisp_string ("blind"); lisp_string ("Blind"));
1517
+ lisp_list (lisp_string ("blind"); lisp_nil);
1520
+ lisp_list (lisp_string ("stunned"); lisp_string ("Stun"));
1522
+ lisp_list (lisp_string ("stunned"); lisp_nil);
1524
+ if (Hallucination)
1525
+ lisp_list (lisp_string ("hallucination"); lisp_string ("Hallu"));
1527
+ lisp_list (lisp_string ("hallucination"); lisp_nil);
1530
+ lisp_list (lisp_string ("slimed"); lisp_string ("Slime"));
1532
+ lisp_list (lisp_string ("slimed"); lisp_nil);
1534
+ if (near_capacity() > UNENCUMBERED)
1535
+ lisp_list (lisp_string ("encumbrance");
1536
+ lisp_string (enc_stat[near_capacity()]));
1538
+ lisp_list (lisp_string ("encumbrance"); lisp_nil);
1544
+lisp_putstr(window, attr, str)
1549
+ static char statline1[BUFSZ] = "";
1550
+ if (window == WIN_STATUS)
1552
+ if (statline1[0]=='\0')
1553
+ Strcpy (statline1, str);
1556
+ generate_status_line ();
1557
+ statline1[0]='\0';
1560
+ else if (window == WIN_MESSAGE)
1561
+ lisp_cmd ("message",
1562
+ lisp_literal (attr_to_string (attr));
1563
+ lisp_string (str));
1565
+ lisp_cmd ("menu-putstr",
1566
+ lisp_int (window);
1567
+ lisp_literal (attr_to_string (attr));
1568
+ lisp_string (str));
1572
+lisp_start_menu(window)
1575
+ lisp_menu_list_num = 0;
1576
+ lisp_current_accelerator = 'a';
1577
+ lisp_cmd ("start-menu", lisp_int (window));
1581
+lisp_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected)
1582
+ winid window; /* window to use, must be of type NHW_MENU */
1583
+ int glyph; /* glyph to display with item (unused) */
1584
+ const anything *identifier; /* what to return if selected */
1585
+ char ch; /* keyboard accelerator (0 = pick our own) */
1586
+ char gch; /* group accelerator (0 = no group) */
1587
+ int attr; /* attribute for string (like tty_putstr()) */
1588
+ const char *str; /* menu string */
1589
+ boolean preselected; /* item is marked as selected */
1591
+ if (identifier->a_void)
1593
+ lisp_menu_item_list[lisp_menu_list_num].identifier = *identifier;
1596
+ ch = lisp_menu_item_list[lisp_menu_list_num].accelerator = lisp_current_accelerator;
1597
+ if (lisp_current_accelerator == 'z')
1598
+ lisp_current_accelerator = 'A';
1600
+ lisp_current_accelerator++;
1603
+ lisp_menu_item_list[lisp_menu_list_num].accelerator = ch;
1605
+ lisp_menu_list_num++;
1610
+ lisp_cmd ("add-menu",
1611
+ lisp_int (window);
1613
+ lisp_int (glyph2tile[glyph]);
1616
+ lisp_literal (attr_to_string (attr));
1617
+ lisp_string (str);
1618
+ preselected ? lisp_t : lisp_nil);
1622
+lisp_end_menu(window, prompt)
1623
+ winid window; /* menu to use */
1624
+ const char *prompt; /* prompt to for menu */
1626
+ lisp_cmd ("end-menu",
1627
+ lisp_int (window);
1628
+ lisp_string (prompt));
1632
+lisp_get_menu_identifier(ch, identifier)
1634
+ anything *identifier;
1638
+ for(i=0; i < lisp_menu_list_num; i++)
1640
+ if( lisp_menu_item_list[i].accelerator == ch )
1642
+ *identifier = lisp_menu_item_list[i].identifier;
1651
+lisp_select_menu(window, how, menu_list)
1654
+ menu_item **menu_list;
1656
+ const char *delim = "() \n";
1662
+ lisp_cmd ("select-menu",
1663
+ lisp_int (window);
1664
+ lisp_literal (how_to_string (how)));
1666
+ read_string ("menu", &list);
1668
+/* lisp_prompt ("menu"); */
1669
+/* fgets (list, LINESIZ, stdin); */
1671
+ /* The client should submit a structure like this:
1673
+ ((ch count) (ch count) (ch count) ...)
1675
+ where ch is the accelerator for the menu item and count is the
1676
+ number of them to select.
1678
+ We strtok it so we just get id count id count id count. */
1680
+ token = strtok (list, delim);
1682
+ /* Start with some memory so realloc doesn't fail. */
1683
+ *menu_list = malloc (sizeof (menu_item));
1684
+ if (*menu_list == NULL)
1686
+ panic ("Memory allocation failure; cannot get %u bytes",
1687
+ sizeof (menu_item));
1691
+ while (token != NULL)
1693
+ /* Make more room in the array for the new item */
1695
+ if ((*menu_list = realloc (*menu_list, size * sizeof (menu_item))) == NULL)
1697
+ panic ("Memory allocation failure; cannot get %u bytes",
1698
+ size * sizeof (menu_item));
1701
+ /* assign the item ID */
1702
+ lisp_get_menu_identifier (atoi (token), &(*menu_list)[size-1].item );
1704
+ /* Read the item count */
1705
+ token = strtok (NULL, delim);
1706
+ (*menu_list)[size-1].count = atoi (token);
1708
+ /* read the next item ID */
1709
+ token = strtok (NULL, delim);
1717
+/* This is a tty-specific hack. Do we need it? */
1719
+lisp_message_menu(let, how, mesg)
1724
+ lisp_cmd ("message-menu",
1726
+ lisp_literal (how_to_string (how));
1727
+ lisp_string (mesg));
1737
+ for (i=0; cmd_index[i].name != (char *)0; i++)
1739
+ if (!strcmp (str, cmd_index[i].name))
1747
+lisp_get_ext_cmd_id (str)
1752
+ for (i=0; extcmdlist[i].ef_txt != (char *)0; i++) {
1753
+ if (!strcmp (str, extcmdlist[i].ef_txt)) return i;
1760
+/* num_digits(n) */
1766
+/* for (i=10;n / i; i *= 10) */
1776
+/* power_of_ten (n) */
1780
+/* int power = 1; */
1782
+/* for (i=0; i<n; i++) */
1787
+/* return power; */
1793
+ /* multi is not 0 if this */
1794
+ static char count_buf[BUFSIZ] = "";
1795
+ static char *count_pos = count_buf;
1796
+ static int count_cmd = -1;
1801
+ char *tmp = count_pos;
1806
+ if (count_cmd >= 0)
1813
+ char cmdstr[BUFSZ];
1818
+ read_command ("command", cmdstr, count_buf);
1820
+ count_pos = count_buf;
1821
+ cmd = lisp_get_cmd (cmdstr);
1824
+ printf ("(nhapi-message 'atr-none \"undefined-command %s\")\n", cmdstr);
1826
+ else if (cmd_index[cmd].type == CMD_LISP)
1828
+ /* We have to handle Lisp commands in this inner loop, because
1829
+ they don't interact with the nethack layer. */
1830
+ /* FIXME: Maybe this should go in an array? */
1831
+ if (!strcmp(cmd_index[cmd].name, "options"))
1836
+ /* We have a nh command. */
1841
+ if (atoi (count_pos) > 1)
1843
+ char* tmp = count_pos;
1850
+ /* Since the count is 1, zero out the string. */
1855
+ if (cmd_index[cmd].type == CMD_KEY)
1857
+ return cmd_index[cmd].cmd;
1859
+ else if (cmd_index[cmd].type == CMD_EXT)
1861
+ if ((extended_cmd_id = lisp_get_ext_cmd_id (cmd_index[cmd].name)) == -1)
1863
+ /* Can never happen. */
1864
+ printf ("%s:%d: Bad extended command name\n", __FILE__, __LINE__);
1870
+ impossible ("Impossible command type: %d", cmd_index[cmd].type);
1875
+lisp_nh_poskey(x, y, mod)
1878
+/* char scratch[256]; */
1880
+/* printf ("(nethack-api-poskey)\n"); */
1882
+/* scanf ("( %d %d '%255s )", x, y, scratch); */
1883
+/* if (!strcmp (scratch, "click-1")) *mod = CLICK_1; */
1884
+/* else *mod = CLICK_2; */
1888
+ return lisp_nhgetch();
1891
+static boolean inven_win_created = FALSE;
1893
+/* These globals are used to keep track of window IDs. */
1894
+static winid *winid_list = NULL;
1895
+static int winid_list_len = 0;
1896
+static int winid_list_max = 0;
1898
+/* returns index into winid_list that can be used. */
1904
+ /* Check for a vacant spot in the list. */
1905
+ for (i=0; i<winid_list_len; i++)
1907
+ if (winid_list[i] == -1) return i;
1910
+ /* no vacant ones, so grow the array. */
1911
+ if (winid_list_len >= winid_list_max)
1913
+ winid_list_max *= 2;
1914
+ winid_list = realloc (winid_list, sizeof (int) * winid_list_max);
1915
+ if (winid_list == NULL)
1916
+ bail ("Out of memory\n");
1920
+ return winid_list_len-1;
1924
+winid_is_taken (winid n)
1928
+ for (i=0; i<winid_list_len; i++)
1929
+ if (winid_list[i] == n) return 1;
1935
+add_winid (winid n)
1937
+ if (winid_is_taken (n)) return 0; /* failed. */
1939
+ winid_list[find_empty_cell()] = n;
1940
+ return 1; /* success! */
1944
+get_unique_winid ()
1948
+ /* look for a unique number, and add it to the list of taken
1951
+ while (!add_winid (i)) i++;
1956
+/* When a window is destroyed, it gives back its window number with
1959
+return_winid (winid n)
1963
+ for (i=0; i<winid_list_len; i++)
1965
+ if (winid_list[i] == n)
1967
+ winid_list[i] = -1;
1976
+ winid_list_max = 10;
1977
+ winid_list_len = 0;
1979
+ winid_list = malloc (winid_list_max * sizeof (int));
1982
+/* Prints a create_nhwindow function and expects from stdin the id of
1983
+ this new window as a number. */
1985
+lisp_create_nhwindow(type)
1988
+ winid id = get_unique_winid();
1993
+ lisp_cmd ("create-message-window",);
1996
+ lisp_cmd ("create-map-window",);
1999
+ lisp_cmd ("create-status-window",);
2002
+ lisp_cmd ("create-text-window", lisp_int (id));
2005
+ if (!inven_win_created)
2007
+ lisp_cmd ("create-inventory-window", lisp_int (id));
2008
+ inven_win_created = TRUE;
2011
+ lisp_cmd ("create-menu-window", lisp_int (id));
2014
+ impossible ("Unknown window type: %d", type);
2021
+lisp_clear_nhwindow(window)
2024
+ if (window == WIN_MESSAGE)
2025
+ lisp_cmd ("clear-message",);
2026
+ else if (window == WIN_MAP)
2027
+ lisp_cmd ("clear-map",);
2029
+ /* are other window types ever cleared? */
2030
+ lisp_cmd ("error", lisp_string("clearing unknown winid"));
2034
+lisp_display_nhwindow(window, blocking)
2038
+ /* don't send display messages for anything but menus */
2040
+ if (window != WIN_MESSAGE && window != WIN_STATUS && window != WIN_MAP)
2042
+ lisp_cmd ("display-menu", lisp_int (window));
2043
+ read_string ("dummy", &dummy);
2046
+ else if (blocking)
2048
+ if (window == WIN_MESSAGE)
2050
+ /* blocking on the message window happens only at the end of
2052
+ lisp_cmd ("end",);
2056
+ lisp_cmd ("block",);
2057
+ read_string ("dummy", &dummy);
2061
+ else if (window == WIN_STATUS)
2063
+ /* initial window setup hack here :) */
2064
+ lisp_cmd ("restore-window-configuration",);
2069
+lisp_destroy_nhwindow(window)
2072
+ if ((window != WIN_STATUS)
2073
+ && (window != WIN_MESSAGE)
2074
+ && (window != WIN_MAP))
2076
+ lisp_cmd ("destroy-menu", lisp_int (window));
2077
+ return_winid (window);
2082
+lisp_update_inventory()
2084
+ lisp_cmd ("update-inventory",);
2088
+lisp_doprev_message()
2090
+ lisp_cmd ("doprev-message",);
2097
+ lisp_cmd ("nhbell",);
2100
+/* Can be an empty call says window.doc. */
2104
+ /* lisp_cmd ("mark-sync",); */
2110
+ lisp_cmd ("wait-synch",);
2113
+/* Since nethack will never be suspended, we need not worry about this
2116
+lisp_resume_nhwindows()
2121
+/* Since nethack will never be suspended, we need not worry about this
2124
+lisp_suspend_nhwindows(str)
2130
+/* All keys are defined in emacs, so number_pad makes no sense. */
2132
+lisp_number_pad(state)
2139
+lisp_init_nhwindows(argcp,argv)
2145
+ /* Print each command-line option, constructing a list of strings */
2146
+ lisp_cmd ("init-nhwindows",
2147
+ for (i=0; i<*argcp; i++)
2148
+ lisp_string (argv[i]));
2150
+ /* FIXME: doesn't remove the arguments parsed, as specified in the
2153
+ /* Setup certain flags lisp clients need */
2154
+ iflags.num_pad = FALSE;
2155
+#ifdef EXP_ON_BOTL /* we are going to lose if Nethack is
2156
+ compiled without this option -rcy */
2157
+ flags.showexp = TRUE;
2159
+ flags.time = TRUE;
2161
+ /* inform nethack that the windows have been initialized. */
2162
+ iflags.window_inited = TRUE;
2164
+ init_winid_list();
2168
+lisp_exit_nhwindows (str)
2171
+ lisp_cmd ("exit-nhwindows ", lisp_string (str));
2175
+lisp_delay_output()
2178
+ lisp_cmd ("delay-output",);
2179
+ read_string ("dummy", &dummy);
2184
+lisp_getlin(question, input)
2185
+ const char *question;
2189
+ lisp_cmd ("getlin", lisp_string (question));
2190
+ read_string ("string", &tmp);
2191
+ /* FIXME: potential buffer overflow. */
2192
+ strcpy (input, tmp);
2201
+/* printf ("(nethack-api-get-ext-cmd '("); */
2203
+/* for (i=0; extcmdlist[i].ef_txt != (char *)0; i++) { */
2204
+/* printf ("(\"%s\" . %d)", extcmdlist[i].ef_txt, i); */
2206
+/* printf ("))\n"); */
2208
+/* scanf ("%d", &cmd); */
2210
+ /* This is set when the user chooses an extended command. */
2211
+ return extended_cmd_id;
2215
+lisp_display_file(str, complain)
2219
+ lisp_cmd ("display-file",
2220
+ lisp_string (str);
2221
+ complain ? lisp_t : lisp_nil);;
2225
+lisp_yn_function(ques, choices, def)
2227
+ const char *choices;
2232
+ /* Some questions have special functions. */
2233
+ if (!strncmp (ques, "In what direction", 17)
2234
+ || !strncmp (ques, "Talk to whom? (in what direction)", 33))
2237
+ lisp_cmd ("ask-direction",
2238
+ lisp_string (ques));
2239
+ read_string ("direction", &dir);
2240
+ if (!strcmp (dir, "n"))
2242
+ else if (!strcmp (dir, "s"))
2244
+ else if (!strcmp (dir, "e"))
2246
+ else if (!strcmp (dir, "w"))
2248
+ else if (!strcmp (dir, "ne"))
2250
+ else if (!strcmp (dir, "nw"))
2252
+ else if (!strcmp (dir, "se"))
2254
+ else if (!strcmp (dir, "sw"))
2256
+ else if (!strcmp (dir, "up"))
2258
+ else if (!strcmp (dir, "down"))
2260
+ else if (!strcmp (dir, "self"))
2265
+ answer = 0x20; /* space */
2274
+ lisp_cmd ("yn-function",
2275
+ lisp_string (ques);
2276
+ lisp_string (choices);
2278
+ read_int ("number", &answer);
2281
+ return (char)answer;
2286
+lisp_update_positionbar(features)
2289
+ lisp_cmd ("update-positionbar", lisp_string (features));
2293
+#define zap_color(n) zapcolors[n]
2294
+#define cmap_color(n) defsyms[n].color
2295
+#define obj_color(n) objects[n].oc_color
2296
+#define mon_color(n) mons[n].mcolor
2297
+#define invis_color(n) NO_COLOR
2298
+#define pet_color(n) mons[n].mcolor
2299
+#define warn_color(n) def_warnsyms[n].color
2302
+lisp_print_glyph(window, x, y, glyph)
2308
+ boolean reverse_on = FALSE;
2312
+ /* map glyph to character and color */
2313
+ mapglyph(glyph, &ch, &color, &special, x, y);
2315
+ /* If the user doesn't want to highlight the pet, then we erase
2316
+ the PET bit from special. In the lisp code the special argument
2317
+ will be 'pet if the glyph is a pet and will be printed in the
2318
+ color of the pet highlight face. But we don't want this if the
2319
+ user hasn't turned on hilite_pet. */
2320
+ if (!iflags.hilite_pet)
2322
+ special &= ~MG_PET;
2325
+ if (window == WIN_MAP)
2327
+ /* The last parameter, special, is optional. It is only
2328
+ present when the tile is special in some way. FIXME: This
2329
+ duplicate code is a bit gross. */
2332
+ lisp_cmd ("print-glyph",
2337
+ lisp_int (glyph2tile[glyph]);
2339
+ lisp_literal (special_glyph_to_string (special)););
2343
+ lisp_cmd ("print-glyph",
2348
+ lisp_int (glyph2tile[glyph]);
2353
+ lisp_cmd ("error",
2354
+ lisp_string ("lisp_print_glyph bad window");
2355
+ lisp_int (window));
2360
+lisp_cliparound(x, y)
2364
+ /* as far as I can tell, the x and y values here are exactly the
2365
+ ones given by the next lisp_curs call, so its redundant
2366
+ information -rcy */
2368
+ /* lisp_cmd ("cliparound", lisp_int (x); lisp_int (y)); */
2372
+void lisp_start_screen() { return; } /* called from setftty() in unixtty.c */
2373
+void lisp_end_screen() {return; } /* called from settty() in unixtty.c */
2376
+get_death_text (buf)
2383
+lisp_outrip(window, how)
2387
+ lisp_cmd ("outrip",
2388
+ lisp_int (window);
2389
+ lisp_string (plname);
2390
+ lisp_int (u.ugold);
2391
+ lisp_string ("Died while trying to finish nethack-el."));
2393
diff --git a/win/tty/termcap.c b/win/tty/termcap.c
2394
index 706e203..00014d0 100644
2395
--- a/win/tty/termcap.c
2396
+++ b/win/tty/termcap.c
2397
@@ -1164,6 +1164,11 @@ int color;
2398
if (windowprocs.name != NULL &&
2399
!strcmpi(windowprocs.name, "Gem")) return TRUE;
2401
+#ifdef LISP_GRAPHICS
2402
+ /* XXX has_color() should be added to windowprocs */
2403
+ if (windowprocs.name != NULL &&
2404
+ !strcmpi(windowprocs.name, "lisp")) return TRUE;
2407
/* XXX has_color() should be added to windowprocs */
2408
if (windowprocs.name != NULL &&