~ubuntu-branches/ubuntu/vivid/nethack/vivid

« back to all changes in this revision

Viewing changes to debian/patches/0004-Add-LISP-based-windowing-system.patch

  • Committer: Package Import Robot
  • Author(s): Vincent Cheng, Bernhard R. Link, Vincent Cheng
  • Date: 2012-06-11 00:47:38 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120611004738-3fy8b3wi0j45y2oq
Tags: 3.4.3-14
* Team upload.

[ Bernhard R. Link ]
* switch to "3.0 (quilt)"
* bump Standards-Version
* modernize debian/rules:
- use dpkg-buildflags
- support build-arch/-indep
- make parallel safe
- don't avoid make errors
* add patch so it can compile with -Werror=format-security
* drop no longer needed patches (-qt and -gnome are gone)
* don't use /dev/null as install template (Closes: 644647)
* drop nethack-common menu (both -console and -x11 have one)

[ Vincent Cheng ]
* Adopt package. (Closes: #673584)
  - Change Maintainer to Debian Games Team.
  - Add myself to Uploaders.
* Modify 0006-Common-config.h-for-all-binary-packages.patch to enable
  AUTOPICKUP_EXCEPTIONS. (Closes: #329318)
* Modify 0011-Pasi-Kallinen-s-patch-to-add-colors-to-inventory-ite.patch
  and 0017-Debian-and-Linux-specifics-defined-in-unixconf.h.patch; add
  0021-fix-kfreebsd-ftbfs.patch to fix FTBFS on kfreebsd.
* Convert debian/copyright to DEP-5 machine-readable format.
* Use dh_lintian to install overrides instead of manually installing them
  in debian/rules.
* Add watch file.
* Add Homepage field in debian/control.
* Add Vcs-* fields in debian/control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 
 
6
---
 
7
 include/winlisp.h  |   70 ++
 
8
 src/windows.c      |    7 +
 
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
 
16
 
 
17
diff --git a/include/winlisp.h b/include/winlisp.h
 
18
new file mode 100644
 
19
index 0000000..f1815b7
 
20
--- /dev/null
 
21
+++ b/include/winlisp.h
 
22
@@ -0,0 +1,70 @@
 
23
+#ifndef WINLISP_H
 
24
+#define WINLISP_H
 
25
+
 
26
+#ifndef E
 
27
+#define E extern
 
28
+#endif
 
29
+
 
30
+#if defined(BOS) || defined(NHSTDC)
 
31
+#define DIMENSION_P int
 
32
+#else
 
33
+# ifdef WIDENED_PROTOTYPES
 
34
+#define DIMENSION_P unsigned int
 
35
+# else
 
36
+#define DIMENSION_P Dimension
 
37
+# endif
 
38
+#endif
 
39
+
 
40
+extern struct window_procs tty_procs;
 
41
+
 
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);
 
67
+#ifdef CLIPPING
 
68
+E void FDECL(lisp_cliparound, (int, int));
 
69
+#endif
 
70
+#ifdef POSITIONBAR
 
71
+E void FDECL(lisp_update_positionbar, (char *));
 
72
+#endif
 
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);
 
85
+
 
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);
 
89
+
 
90
+E void FDECL(lisp_outrip, (winid,int));
 
91
+
 
92
+#endif /* WINLISP_H */
 
93
diff --git a/src/windows.c b/src/windows.c
 
94
index 3c59080..d65710c 100644
 
95
--- a/src/windows.c
 
96
+++ b/src/windows.c
 
97
@@ -40,6 +40,10 @@ extern struct window_procs Gnome_procs;
 
98
 #ifdef MSWIN_GRAPHICS
 
99
 extern struct window_procs mswin_procs;
 
100
 #endif
 
101
+#ifdef LISP_GRAPHICS
 
102
+#include "winlisp.h"
 
103
+extern struct window_procs lisp_procs;
 
104
+#endif
 
105
 
 
106
 STATIC_DCL void FDECL(def_raw_print, (const char *s));
 
107
 
 
108
@@ -81,6 +85,9 @@ struct win_choices {
 
109
 #ifdef MSWIN_GRAPHICS
 
110
     { &mswin_procs, 0 },
 
111
 #endif
 
112
+#ifdef LISP_GRAPHICS
 
113
+    { &lisp_procs, win_lisp_init },
 
114
+#endif
 
115
     { 0, 0 }           /* must be last */
 
116
 };
 
117
 
 
118
diff --git a/win/lisp/ChangeLog b/win/lisp/ChangeLog
 
119
new file mode 100644
 
120
index 0000000..8686f14
 
121
--- /dev/null
 
122
+++ b/win/lisp/ChangeLog
 
123
@@ -0,0 +1,326 @@
 
124
+2005-02-27    <katia_dilkina@verizon.net>
 
125
+
 
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
 
135
+       CMD_EXT type.
 
136
+       (lisp_display_nhwindow): read a dummy string, not a menu string.
 
137
+
 
138
+2004-02-09  Shawn Betts  <sabetts@vcn.bc.ca>
 
139
+
 
140
+       * winlisp.c (lisp_yn_function): catch the chat prompt too.
 
141
+
 
142
+2003-09-19  Shawn Betts  <sabetts@vcn.bc.ca>
 
143
+
 
144
+       * winlisp.c: add extra element to lisp_procs (structure change in 3.4.2).
 
145
+
 
146
+2003-06-03  Shawn Betts  <sabetts@sfu.ca>
 
147
+
 
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
 
152
+
 
153
+2003-05-14  Shawn Betts  <sabetts@sfu.ca>
 
154
+
 
155
+       * winlisp.c (lisp_string): Also escape the backslash character.
 
156
+
 
157
+2002-09-19  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
158
+
 
159
+       * winlisp.c (lisp_cmd): nethack-api-* renamed to nhapi-*.
 
160
+
 
161
+2002-09-16  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
162
+
 
163
+       * ../tty/termcap.c (has_color): Add condition for LISP_GRAPHICS
 
164
+       which returns TRUE.
 
165
+
 
166
+2002-09-12  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
167
+
 
168
+       * winlisp.c (lisp_display_nhwindow): Add call to
 
169
+       `nethack-api-end'.
 
170
+
 
171
+       * ../../include/config.h: Default to LISP_GRAPHICS.
 
172
+
 
173
+       * ../../sys/unix/Makefile.src (WINSRC,WINOBJ,WINLIB): Set to
 
174
+       WINLISP* values.
 
175
+       (depend): Add winlisp.o dependancies.
 
176
+       
 
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
 
184
+       clear-nhwindow.
 
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
 
189
+       numbers.
 
190
+       (lisp_print_glyph): Don't send winid.  Add error check for bad
 
191
+       winids.
 
192
+       (lisp_outrip): Change reference to Enethack to nethack-el.
 
193
+
 
194
+2002-04-23  Shawn  <sabetts@vcn.bc.ca>
 
195
+
 
196
+       * winlisp.c (lisp_player_selection): Update to use new 3.4.0
 
197
+       functionality.
 
198
+       (lisp_print_glyph): likewise
 
199
+
 
200
+2002-02-16  Shawn Betts  <sabetts@vcn.bc.ca>
 
201
+
 
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
 
210
+
 
211
+2002-02-14  Shawn Betts  <sabetts@vcn.bc.ca>
 
212
+
 
213
+       * winlisp.c (lisp_print_glyph): Handle warning glyphs.
 
214
+
 
215
+2002-01-27  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
216
+
 
217
+       * winlisp.c (generate_status_line): Send flag values
 
218
+       individually.  Always send values for all attributes.
 
219
+
 
220
+2002-01-21  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
221
+
 
222
+       * winlisp.c (lisp_add_menu): Add tile argument.
 
223
+
 
224
+2002-01-22  shawn  <sabetts@vcn.bc.ca>
 
225
+
 
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
 
233
+       "add_menu".
 
234
+       (lisp_get_menu_identifier): first argument is now a char.
 
235
+
 
236
+2002-01-20  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
237
+
 
238
+       * winlisp.c (cmd_index): Add remaining functions.
 
239
+
 
240
+2002-01-16  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
241
+
 
242
+       * winlisp.c (lisp_exit_nhwindows): Don't wait for a dummy return
 
243
+       value.
 
244
+       (lisp_destroy_nhwindow): Don't destroy the status, message or map
 
245
+       windows.
 
246
+
 
247
+2002-01-15  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
248
+
 
249
+       * winlisp.c (lisp_exit_nhwindows): Don't wait for a dummy return
 
250
+       value.
 
251
+       
 
252
+2002-01-10  shawn  <sabetts@vcn.bc.ca>
 
253
+
 
254
+       * winlisp.c (win_lisp_init): new function
 
255
+
 
256
+2002-01-09  Ryan C Yeske  <rcyeske@sfu.ca>
 
257
+
 
258
+       * winlisp.c (cmd_index): Add redraw command.    
 
259
+       (C): New macro.
 
260
+
 
261
+2002-01-01  shawn  <sabetts@vcn.bc.ca>
 
262
+
 
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
 
272
+
 
273
+2001-12-20  shawn  <sabetts@vcn.bc.ca>
 
274
+
 
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
 
283
+       call.
 
284
+
 
285
+2001-12-19  shawn  <sabetts@vcn.bc.ca>
 
286
+
 
287
+       * winlisp.c: add extern declaration for glyph2tile and
 
288
+       total_tiles_used.
 
289
+       (lisp_print_glyph): pass the glyph's graphics tile index as an argument.
 
290
+
 
291
+2001-12-02  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
292
+
 
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.
 
300
+
 
301
+2001-10-23  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
302
+
 
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.
 
309
+
 
310
+2001-10-19  shawn  <sabetts@vcn.bc.ca>
 
311
+
 
312
+       * winlisp.c (lisp_init_nhwindows): turn on showexp and time flags.
 
313
+
 
314
+2001-10-17  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
315
+
 
316
+       * winlisp.c (lisp_display_nhwindow): Wait for a string if we are
 
317
+       blocking.
 
318
+
 
319
+2001-07-19  shawn  <sabetts@diggin.lamenet.tmp>
 
320
+
 
321
+       * winlisp.c (lisp_player_selection): terminate if we read a -1 as
 
322
+       a selection.
 
323
+
 
324
+2001-07-16  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
325
+
 
326
+       * winlisp.c (lisp_delay_output): expect a return value from the
 
327
+       client.
 
328
+
 
329
+2001-07-14  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
330
+
 
331
+       * winlisp.c (lisp_add_menu): Quote the attribute.
 
332
+       (lisp_outrip): Add a newline to output.
 
333
+
 
334
+2001-07-06  shawn  <sabetts@diggin.lamenet.tmp>
 
335
+
 
336
+       * winlisp.c (num_digits): new function
 
337
+       (power_of_ten): likewise
 
338
+       (lisp_nhgetch): handles repeated commands.
 
339
+
 
340
+2001-07-05  shawn  <sabetts@diggin.lamenet.tmp>
 
341
+
 
342
+       * winlisp.c (WINLISP_VOID_RETVAL): flushes stdout
 
343
+
 
344
+2001-07-04  Ryan Yeske  <rcyeske@van.gobasis.com>
 
345
+
 
346
+       * winlisp.c (lisp_add_menu): Convert printf to lisp_* macros,
 
347
+       fixing a string quote bug.
 
348
+
 
349
+2001-06-28  shawn  <sabetts@diggin.lamenet.tmp>
 
350
+
 
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
 
358
+       as a number.
 
359
+
 
360
+2001-06-27  shawn  <sabetts@diggin.lamenet.tmp>
 
361
+
 
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.
 
366
+
 
367
+2001-06-21  Shawn Betts  <sabetts@van.gobasis.com>
 
368
+
 
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
 
372
+       allocation.
 
373
+
 
374
+2001-05-06  shawn  <sabetts@diggin.lamenet.tmp>
 
375
+
 
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
 
385
+       from it.
 
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
 
393
+       actual identifier.
 
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
 
397
+
 
398
+2000-10-01  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
399
+
 
400
+       * winlisp.c (cmd_index): renamed "ddoremarm" to "remarm" and
 
401
+       "ddoinv" to "inv".
 
402
+
 
403
+2000-09-25  Shawn  <sabetts@vcn.bc.ca>
 
404
+
 
405
+       * winlisp.c: Added more key commands.
 
406
+       (lisp_player_selection): honours default player selections as
 
407
+       specified in the nethackrc file.
 
408
+
 
409
+2000-09-22  Shawn  <sabetts@vcn.bc.ca>
 
410
+
 
411
+       * winlisp.c (lisp_nhgetch): changed while loop stop condition.
 
412
+
 
413
+2000-09-19  Ryan yeske  <rcyeske@van.gobasis.com>
 
414
+
 
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.
 
418
+
 
419
+2000-09-12  shawn  <sabetts@gobasis.com>
 
420
+
 
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'.
 
427
+
 
428
+2000-09-11  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
429
+
 
430
+       * winlisp.c (lisp_cmd, lisp_close_cmd, lisp_open, lisp_close,
 
431
+       lisp_quote, lisp_int, lisp_string, lisp_dot): created macros.
 
432
+
 
433
+2000-09-10  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
434
+
 
435
+       * winlisp.c (lisp_outrip): added closing paren.
 
436
+
 
437
+2000-08-21  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
438
+
 
439
+       * winlisp.c (lisp_nhgetch): change ch type to int from char.
 
440
+
 
441
+2000-08-20  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
442
+
 
443
+       * winlisp.c (lisp_player_selection): role/race/gender/alignment
 
444
+       selection now sends (nethack-apix-choose-X ALIST) instead of
 
445
+       simply an alist.
 
446
+       (lisp_update_inventory):
 
447
+       s/nethack-api-updated-inventory/nethack-api-update-inventory/
 
448
+       (WINLISP_VOID_RETVAL): added macro, called for every void
 
449
+       function.
 
450
diff --git a/win/lisp/winlisp.c b/win/lisp/winlisp.c
 
451
new file mode 100644
 
452
index 0000000..290a457
 
453
--- /dev/null
 
454
+++ b/win/lisp/winlisp.c
 
455
@@ -0,0 +1,1937 @@
 
456
+/* Copyright (c) Shawn Betts, Ryan Yeske, 2001                    */
 
457
+/* NetHack may be freely redistributed.  See license for details. */
 
458
+
 
459
+/*
 
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.  
 
463
+ */
 
464
+
 
465
+#ifdef MSDOS                   /* from compiler */
 
466
+#define SHORT_FILENAMES
 
467
+#endif
 
468
+
 
469
+#include "hack.h"
 
470
+#include "winlisp.h"
 
471
+#include "func_tab.h"
 
472
+
 
473
+#include "dlb.h"
 
474
+#ifdef SHORT_FILENAMES
 
475
+#include "patchlev.h"
 
476
+#else
 
477
+#include "patchlevel.h"
 
478
+#endif
 
479
+
 
480
+#define CMD_KEY 0
 
481
+#define CMD_EXT 1
 
482
+#define CMD_LISP 2 /* These are commands specific to the lisp port */
 
483
+
 
484
+/* from tile.c */
 
485
+extern short glyph2tile[];
 
486
+extern int total_tiles_used;
 
487
+
 
488
+typedef struct
 
489
+{
 
490
+  anything identifier;
 
491
+  char accelerator;
 
492
+} lisp_menu_item_t;
 
493
+
 
494
+/* An iterator for assigning accelerator keys. */
 
495
+static char lisp_current_accelerator;
 
496
+
 
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;
 
501
+
 
502
+extern char *enc_stat[];
 
503
+const char *hunger_stat[] = {
 
504
+       "Satiated",
 
505
+       "",
 
506
+       "Hungry",
 
507
+       "Weak",
 
508
+       "Fainting",
 
509
+       "Fainted",
 
510
+       "Starved"
 
511
+};
 
512
+
 
513
+typedef struct 
 
514
+{
 
515
+  char *name;
 
516
+  int type;
 
517
+  int cmd;                     /* The command (a keystroke) */
 
518
+}cmd_index_t;
 
519
+
 
520
+#ifndef C
 
521
+#define C(c)           (0x1f & (c))
 
522
+#endif
 
523
+
 
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')},
 
528
+
 
529
+                           {"gosouth", CMD_KEY, 'j'},
 
530
+                           {"gosouthontop", CMD_KEY, 'J'},
 
531
+                           {"gosouthnear", CMD_KEY,  C('j')},
 
532
+
 
533
+                           {"gonorth", CMD_KEY, 'k'},
 
534
+                           {"gonorthontop", CMD_KEY, 'K'},
 
535
+                           {"gonorthnear", CMD_KEY, C('k')},
 
536
+
 
537
+                           {"goeast", CMD_KEY, 'l'},
 
538
+                           {"goeastontop", CMD_KEY, 'L'},
 
539
+                           {"goeastnear", CMD_KEY, C('l')},
 
540
+
 
541
+                           {"gonorthwest", CMD_KEY, 'y'},
 
542
+                           {"gonorthwestontop", CMD_KEY, 'Y'},
 
543
+                           {"gonorthwestnear", CMD_KEY, C('y')},
 
544
+
 
545
+                           {"gonortheast", CMD_KEY, 'u'},
 
546
+                           {"gonortheastontop", CMD_KEY, 'U'},
 
547
+                           {"gonortheastnear", CMD_KEY, C('u')},
 
548
+
 
549
+                           {"gosouthwest", CMD_KEY, 'b'},
 
550
+                           {"gosouthwestontop", CMD_KEY, 'B'},
 
551
+                           {"gosouthwestnear", CMD_KEY, C('b')},
 
552
+
 
553
+                           {"gosoutheast", CMD_KEY, 'n'},
 
554
+                           {"gosoutheastontop", CMD_KEY, 'N'},
 
555
+                           {"gosoutheastnear", CMD_KEY, C('n')},
 
556
+
 
557
+                           {"travel", CMD_KEY, '_'},
 
558
+
 
559
+                           {"idtrap", CMD_KEY, '^'},
 
560
+                           {"apply", CMD_KEY, 'a'},
 
561
+                           {"remarm", CMD_KEY, 'A'},
 
562
+                           {"close", CMD_KEY, 'c'},
 
563
+                           {"drop", CMD_KEY, 'd'},
 
564
+
 
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'},
 
570
+
 
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'},
 
576
+
 
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'},
 
582
+
 
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'},
 
588
+
 
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'},
 
594
+
 
595
+                           {"cast", CMD_KEY, 'Z'},
 
596
+                           {"up", CMD_KEY, '<'},
 
597
+                           {"down", CMD_KEY, '>'},
 
598
+                           {"whatis", CMD_KEY, '/'},
 
599
+                           {"help", CMD_KEY, '?'},
 
600
+
 
601
+                           {"whatdoes", CMD_KEY, '&'},
 
602
+                           {"sh", CMD_KEY, '!'},
 
603
+                           {"discovered", CMD_KEY, '\\'},
 
604
+                           {"null", CMD_KEY, '.'},
 
605
+                           {"look", CMD_KEY, ':'},
 
606
+
 
607
+                           {"quickwhatis", CMD_KEY, ';'},
 
608
+                           {"pickup", CMD_KEY, ','},
 
609
+                           {"togglepickup", CMD_KEY, '@'},
 
610
+                           {"prinuse", CMD_KEY, '*'},
 
611
+                           {"countgold", CMD_KEY, '$'},
 
612
+
 
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')},
 
629
+#ifdef REDO
 
630
+                           {"again", CMD_KEY, DOAGAIN},
 
631
+#endif /* REDO */
 
632
+
 
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')},
 
641
+
 
642
+                           /* wizard extended commands */
 
643
+#ifdef WIZARD
 
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},
 
649
+#ifdef DEBUG
 
650
+                           {"wizdebug", CMD_EXT, 0},
 
651
+#endif /* DEBUG */
 
652
+                           {"wmode", CMD_EXT, 0},
 
653
+#endif /* WIZARD */
 
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},
 
659
+
 
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},
 
665
+
 
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},
 
671
+
 
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},
 
677
+
 
678
+                           {"version", CMD_EXT, 0},
 
679
+                           {"wipe", CMD_EXT, 0},
 
680
+
 
681
+                           /* Lisp port specific commands  */
 
682
+                           {"options", CMD_LISP, 0},
 
683
+
 
684
+                           {0, CMD_KEY, '\0'} };
 
685
+
 
686
+/* This variable is set when the user has selected an extended command. */
 
687
+static int extended_cmd_id;
 
688
+  
 
689
+/* Interface definition, for windows.c */
 
690
+struct window_procs lisp_procs = {
 
691
+  "lisp",
 
692
+  WC_COLOR|WC_HILITE_PET,
 
693
+  0L,
 
694
+  lisp_init_nhwindows,
 
695
+  lisp_player_selection,
 
696
+  lisp_askname,
 
697
+  lisp_get_nh_event,
 
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,
 
705
+  lisp_curs,
 
706
+  lisp_putstr,
 
707
+  lisp_display_file,
 
708
+  lisp_start_menu,
 
709
+  lisp_add_menu,
 
710
+  lisp_end_menu,
 
711
+  lisp_select_menu,
 
712
+  genl_message_menu,
 
713
+  lisp_update_inventory,
 
714
+  lisp_mark_synch,
 
715
+  lisp_wait_synch,
 
716
+#ifdef CLIPPING
 
717
+  lisp_cliparound,
 
718
+#endif
 
719
+#ifdef POSITIONBAR
 
720
+  lisp_update_positionbar,
 
721
+#endif
 
722
+  lisp_print_glyph,
 
723
+  lisp_raw_print,
 
724
+  lisp_raw_print_bold,
 
725
+  lisp_nhgetch,
 
726
+  lisp_nh_poskey,
 
727
+  lisp_nhbell,
 
728
+  lisp_doprev_message,
 
729
+  lisp_yn_function,
 
730
+  lisp_getlin,
 
731
+  lisp_get_ext_cmd,
 
732
+  lisp_number_pad,
 
733
+  lisp_delay_output,
 
734
+#ifdef CHANGE_COLOR    /* the Mac uses a palette device */
 
735
+  donull,
 
736
+  donull,
 
737
+#endif
 
738
+  /* other defs that really should go away (they're tty specific) */
 
739
+  lisp_start_screen,
 
740
+  lisp_end_screen,
 
741
+  lisp_outrip,
 
742
+  genl_preference_update,
 
743
+};
 
744
+
 
745
+/* macros for printing lisp output */
 
746
+#define lisp_cmd(s,body)                       \
 
747
+  do                                           \
 
748
+    {                                          \
 
749
+      printf("(nhapi-%s ",s);          \
 
750
+      body;                                    \
 
751
+      printf(")\n");                           \
 
752
+    }                                          \
 
753
+  while (0)
 
754
+/* #define lisp_cmd0(s) printf ("(nhapi-%s)\n", s) */
 
755
+#define lisp_list(body)                                \
 
756
+  do                                           \
 
757
+    {                                          \
 
758
+      printf("(");                             \
 
759
+      body;                                    \
 
760
+      printf(") ");                            \
 
761
+    }                                          \
 
762
+  while (0)
 
763
+
 
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)                                \
 
771
+  do                                           \
 
772
+    {                                          \
 
773
+      lisp_quote;                              \
 
774
+      printf ("%s ", x);                       \
 
775
+    }                                          \
 
776
+  while (0)
 
777
+#define lisp_cons(x,y)                         \
 
778
+  do                                           \
 
779
+    {                                          \
 
780
+      lisp_open;                               \
 
781
+      x;                                       \
 
782
+      lisp_dot;                                        \
 
783
+      y;                                       \
 
784
+      lisp_close;                              \
 
785
+    }                                          \
 
786
+  while (0)
 
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)                                 \
 
791
+  do                                                   \
 
792
+     {                                                 \
 
793
+       int nhi;                                                \
 
794
+       printf ("\"");                                  \
 
795
+       if (s)                                          \
 
796
+        for (nhi=0;nhi<strlen(s);nhi++)                \
 
797
+          {                                            \
 
798
+            if (s[nhi] == 34                           \
 
799
+                || s[nhi] == 92) putchar('\\');        \
 
800
+            putchar(s[nhi]);                           \
 
801
+          }                                            \
 
802
+       printf("\" ");                                  \
 
803
+     }                                                 \
 
804
+  while (0)
 
805
+
 
806
+static const char*
 
807
+attr_to_string(attr)
 
808
+     int attr;
 
809
+{
 
810
+  switch (attr)
 
811
+    {
 
812
+    case ATR_NONE:
 
813
+      return "atr-none";
 
814
+    case ATR_ULINE:
 
815
+      return "atr-uline";
 
816
+    case ATR_BOLD:
 
817
+      return "atr-bold";
 
818
+    case ATR_BLINK:
 
819
+      return "atr-blink";
 
820
+    case ATR_INVERSE:
 
821
+      return "atr-inverse";
 
822
+    default:
 
823
+      /* Should never happen. */
 
824
+      impossible ("Invalid attribute code.");
 
825
+      exit (EXIT_FAILURE);
 
826
+      break;
 
827
+    }
 
828
+}
 
829
+
 
830
+static const char*
 
831
+special_glyph_to_string(special)
 
832
+     unsigned special;
 
833
+{
 
834
+  switch (special)
 
835
+    {
 
836
+    case MG_CORPSE:
 
837
+      return "corpse";
 
838
+    case MG_INVIS:
 
839
+      return "invis";
 
840
+    case MG_DETECT:
 
841
+      return "detect";
 
842
+    case MG_PET:
 
843
+      return "pet";
 
844
+    case MG_RIDDEN:
 
845
+      return "ridden";
 
846
+    }
 
847
+  
 
848
+  /* If it's a combination, just return special. */
 
849
+  if (special)
 
850
+    return "special";
 
851
+  else
 
852
+    return "none";
 
853
+}
 
854
+
 
855
+static const char*
 
856
+wintype_to_string(type)
 
857
+     int type;
 
858
+{
 
859
+  switch (type)
 
860
+    {
 
861
+    case NHW_MAP:
 
862
+      return "nhw-map";
 
863
+    case NHW_MESSAGE:
 
864
+      return "nhw-message";
 
865
+    case NHW_STATUS:
 
866
+      return "nhw-status";
 
867
+    case NHW_MENU:
 
868
+      return "nhw-menu";
 
869
+    case NHW_TEXT:
 
870
+      return "nhw-text";
 
871
+    default:
 
872
+      fprintf (stderr, "Invalid window code\n");
 
873
+      exit (EXIT_FAILURE);
 
874
+      break;
 
875
+    }
 
876
+}
 
877
+
 
878
+static const char*
 
879
+how_to_string (how)
 
880
+     int how;
 
881
+{
 
882
+  switch (how)
 
883
+    {
 
884
+    case PICK_NONE:
 
885
+      return "pick-none";
 
886
+    case PICK_ONE:
 
887
+      return "pick-one";
 
888
+    case PICK_ANY:
 
889
+      return "pick-any";
 
890
+    default:
 
891
+      impossible ("Invalid how value %d", how);
 
892
+    }
 
893
+}
 
894
+
 
895
+static int
 
896
+read_int (prompt, i)
 
897
+     const char* prompt;
 
898
+     int *i;
 
899
+{
 
900
+  char line[BUFSZ];
 
901
+  int rv;
 
902
+  printf ("%s> ", prompt);
 
903
+  fflush(stdout);
 
904
+  fgets (line, BUFSZ, stdin);
 
905
+  rv = sscanf (line, "%d", i);
 
906
+  if (rv != 1) *i = -1;
 
907
+  return rv;
 
908
+}
 
909
+
 
910
+static int
 
911
+read_string (prompt, str)
 
912
+     const char* prompt;
 
913
+     char **str;
 
914
+{
 
915
+  char* rv;
 
916
+  int len;
 
917
+  int size;
 
918
+  char tmp[BUFSZ];
 
919
+
 
920
+  len = 0;
 
921
+  size = BUFSZ * 2;
 
922
+  *str = malloc (size);
 
923
+  (*str)[0] = '\0';
 
924
+
 
925
+  printf ("%s> ", prompt);
 
926
+  fflush(stdout);
 
927
+  do
 
928
+    {
 
929
+      /* Read the string */
 
930
+      rv = fgets (tmp, BUFSZ, stdin);
 
931
+      if (rv == NULL)
 
932
+       break;
 
933
+
 
934
+      len += strlen (tmp);
 
935
+      if (len >= size - 1)
 
936
+       {
 
937
+         size *= 2;
 
938
+         *str = realloc (*str, size);
 
939
+         if (*str == NULL)
 
940
+           panic ("Memory allocation failure; cannot get %u bytes", size);
 
941
+       }
 
942
+      strcat (*str, tmp);
 
943
+    } while (tmp[strlen (tmp) - 1] != '\n');
 
944
+
 
945
+  /* Did we read a string or error out? */
 
946
+  if (rv == NULL)
 
947
+    {
 
948
+      free (*str);
 
949
+      return -1;
 
950
+    }
 
951
+  else
 
952
+    {
 
953
+      /* chop the newline */
 
954
+      (*str) [strlen (*str) - 1] = '\0';
 
955
+      return 0;
 
956
+    }
 
957
+}
 
958
+
 
959
+
 
960
+static int
 
961
+read_command (prompt, cmd, count)
 
962
+     const char *prompt;
 
963
+     char *cmd;
 
964
+     char *count;
 
965
+{
 
966
+  char *buf;
 
967
+  int rv;
 
968
+  cmd[0] = '\0';
 
969
+  *count = 0;
 
970
+  if (read_string (prompt, &buf) == -1)
 
971
+    return -1;
 
972
+  rv = sscanf (buf, "%s %s", cmd, count);
 
973
+  free (buf);
 
974
+  if (rv != 2) *count = 0;
 
975
+  return rv;
 
976
+}
 
977
+
 
978
+void
 
979
+bail(mesg)
 
980
+     const char *mesg;
 
981
+{
 
982
+  clearlocks ();
 
983
+  lisp_exit_nhwindows (mesg);
 
984
+  terminate (EXIT_SUCCESS);
 
985
+  /*NOTREACHED*/
 
986
+}
 
987
+
 
988
+void
 
989
+win_lisp_init ()
 
990
+{
 
991
+  /* Code to be executed on startup. */
 
992
+}
 
993
+
 
994
+void
 
995
+lisp_player_selection ()
 
996
+{
 
997
+       int i, k, n;
 
998
+       char pick4u = 'n', thisch, lastch = 0;
 
999
+       char pbuf[QBUFSZ], plbuf[QBUFSZ];
 
1000
+       winid win;
 
1001
+       anything any;
 
1002
+       menu_item *selected = 0;
 
1003
+
 
1004
+       /* prevent an unnecessary prompt */
 
1005
+       rigid_role_checks();
 
1006
+
 
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)) {
 
1011
+
 
1012
+         pick4u = lisp_yn_function ("Shall I pick a character for you? [ynq] ", "ynq", 'y');
 
1013
+
 
1014
+         if (pick4u != 'y' && pick4u != 'n') 
 
1015
+           {
 
1016
+           give_up:    /* Quit */
 
1017
+             if (selected) free((genericptr_t) selected);
 
1018
+             bail((char *)0);
 
1019
+             /*NOTREACHED*/
 
1020
+             return;
 
1021
+           }
 
1022
+
 
1023
+       }
 
1024
+
 
1025
+       (void)  root_plselection_prompt(plbuf, QBUFSZ - 1,
 
1026
+                       flags.initrole, flags.initrace, flags.initgend, flags.initalign);
 
1027
+
 
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();
 
1041
+               }
 
1042
+           } else {
 
1043
+               /* Prompt for a role */
 
1044
+               win = create_nhwindow(NHW_MENU);
 
1045
+               start_menu(win);
 
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);
 
1056
+                               else
 
1057
+                                       Strcpy(rolenamebuf, roles[i].name.m);
 
1058
+                       } else {
 
1059
+                               if (roles[i].name.f) {
 
1060
+                                       Strcpy(rolenamebuf, roles[i].name.m);
 
1061
+                                       Strcat(rolenamebuf, "/");
 
1062
+                                       Strcat(rolenamebuf, roles[i].name.f);
 
1063
+                               } else 
 
1064
+                                       Strcpy(rolenamebuf, roles[i].name.m);
 
1065
+                       }       
 
1066
+                       add_menu(win, NO_GLYPH, &any, thisch,
 
1067
+                           0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED);
 
1068
+                       lastch = thisch;
 
1069
+                   }
 
1070
+               }
 
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);
 
1084
+
 
1085
+               /* Process the choice */
 
1086
+               if (n != 1 || selected[0].item.a_int == any.a_int)
 
1087
+                   goto give_up;               /* Selected quit */
 
1088
+
 
1089
+               flags.initrole = selected[0].item.a_int - 1;
 
1090
+               free((genericptr_t) selected),  selected = 0;
 
1091
+           }
 
1092
+           (void)  root_plselection_prompt(plbuf, QBUFSZ - 1,
 
1093
+                       flags.initrole, flags.initrace, flags.initgend, flags.initalign);
 
1094
+       }
 
1095
+       
 
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);
 
1107
+               }
 
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)) {
 
1115
+                       n++;
 
1116
+                       k = i;
 
1117
+                   }
 
1118
+               }
 
1119
+               if (n == 0) {
 
1120
+                   for (i = 0; races[i].noun; i++) {
 
1121
+                       if (validrace(flags.initrole, i)) {
 
1122
+                           n++;
 
1123
+                           k = i;
 
1124
+                       }
 
1125
+                   }
 
1126
+               }
 
1127
+
 
1128
+               /* Permit the user to pick, if there is more than one */
 
1129
+               if (n > 1) {
 
1130
+                   win = create_nhwindow(NHW_MENU);
 
1131
+                   start_menu(win);
 
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);
 
1139
+                       }
 
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 */
 
1155
+
 
1156
+                   k = selected[0].item.a_int - 1;
 
1157
+                   free((genericptr_t) selected),      selected = 0;
 
1158
+               }
 
1159
+               flags.initrace = k;
 
1160
+           }
 
1161
+           (void)  root_plselection_prompt(plbuf, QBUFSZ - 1,
 
1162
+                       flags.initrole, flags.initrace, flags.initgend, flags.initalign);
 
1163
+       }
 
1164
+
 
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);
 
1177
+               }
 
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)) {
 
1185
+                       n++;
 
1186
+                       k = i;
 
1187
+                   }
 
1188
+               }
 
1189
+               if (n == 0) {
 
1190
+                   for (i = 0; i < ROLE_GENDERS; i++) {
 
1191
+                       if (validgend(flags.initrole, flags.initrace, i)) {
 
1192
+                           n++;
 
1193
+                           k = i;
 
1194
+                       }
 
1195
+                   }
 
1196
+               }
 
1197
+
 
1198
+               /* Permit the user to pick, if there is more than one */
 
1199
+               if (n > 1) {
 
1200
+                   win = create_nhwindow(NHW_MENU);
 
1201
+                   start_menu(win);
 
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)) {
 
1206
+                           any.a_int = i+1;
 
1207
+                           add_menu(win, NO_GLYPH, &any, genders[i].adj[0],
 
1208
+                               0, ATR_NONE, genders[i].adj, MENU_UNSELECTED);
 
1209
+                       }
 
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 */
 
1225
+
 
1226
+                   k = selected[0].item.a_int - 1;
 
1227
+                   free((genericptr_t) selected),      selected = 0;
 
1228
+               }
 
1229
+               flags.initgend = k;
 
1230
+           }
 
1231
+           (void)  root_plselection_prompt(plbuf, QBUFSZ - 1,
 
1232
+                       flags.initrole, flags.initrace, flags.initgend, flags.initalign);
 
1233
+       }
 
1234
+
 
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);
 
1246
+               }
 
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,
 
1253
+                                                       i)) {
 
1254
+                       n++;
 
1255
+                       k = i;
 
1256
+                   }
 
1257
+               }
 
1258
+               if (n == 0) {
 
1259
+                   for (i = 0; i < ROLE_ALIGNS; i++) {
 
1260
+                       if (validalign(flags.initrole, flags.initrace, i)) {
 
1261
+                           n++;
 
1262
+                           k = i;
 
1263
+                       }
 
1264
+                   }
 
1265
+               }
 
1266
+
 
1267
+               /* Permit the user to pick, if there is more than one */
 
1268
+               if (n > 1) {
 
1269
+                   win = create_nhwindow(NHW_MENU);
 
1270
+                   start_menu(win);
 
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)) {
 
1275
+                           any.a_int = i+1;
 
1276
+                           add_menu(win, NO_GLYPH, &any, aligns[i].adj[0],
 
1277
+                                0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED);
 
1278
+                       }
 
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 */
 
1294
+
 
1295
+                   k = selected[0].item.a_int - 1;
 
1296
+                   free((genericptr_t) selected),      selected = 0;
 
1297
+               }
 
1298
+               flags.initalign = k;
 
1299
+           }
 
1300
+       }
 
1301
+       /* Success! */
 
1302
+/*     lisp_display_nhwindow(BASE_WINDOW, FALSE); */
 
1303
+}
 
1304
+
 
1305
+/* Reads from standard in, the player's name. */
 
1306
+void
 
1307
+lisp_askname ()
 
1308
+{
 
1309
+  char *line;
 
1310
+  lisp_cmd ("askname",);
 
1311
+  read_string ("string", &line);
 
1312
+  strncpy (plname, line, PL_NSIZ);
 
1313
+  plname[PL_NSIZ-1] = '\0';
 
1314
+  free (line);
 
1315
+}
 
1316
+
 
1317
+/* This is a noop for tty and X, so should it be a noop for us too? */
 
1318
+void
 
1319
+lisp_get_nh_event ()
 
1320
+{
 
1321
+/*   lisp_cmd ("get-event",); */
 
1322
+}
 
1323
+
 
1324
+/* Global Functions */
 
1325
+void
 
1326
+lisp_raw_print(str)
 
1327
+     const char *str;
 
1328
+{
 
1329
+  lisp_cmd ("raw-print", lisp_string (str));
 
1330
+}
 
1331
+
 
1332
+void
 
1333
+lisp_raw_print_bold(str)
 
1334
+     const char *str;
 
1335
+{
 
1336
+  lisp_cmd ("raw-print-bold", lisp_string (str));
 
1337
+}
 
1338
+
 
1339
+void
 
1340
+lisp_curs(window, x, y)
 
1341
+     winid window;
 
1342
+     int x, y;
 
1343
+{
 
1344
+  if (window == WIN_MAP)
 
1345
+    lisp_cmd ("curs",
 
1346
+             lisp_int (x);
 
1347
+             lisp_int (y));
 
1348
+  else if (window == WIN_STATUS)
 
1349
+    {
 
1350
+      /* do nothing */
 
1351
+    }
 
1352
+  else
 
1353
+    lisp_cmd ("error", lisp_string("lisp_curs bad window"); lisp_int (window));
 
1354
+}
 
1355
+
 
1356
+/* Send the options to the lisp process */
 
1357
+static void
 
1358
+get_options()
 
1359
+{
 
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 */
 
1379
+#ifdef WIZARD
 
1380
+           lisp_boolean(iflags.sanity_check); /* run sanity checks */
 
1381
+           lisp_boolean(iflags.mon_polycontrol); /* debug: control monster polymorphs */
 
1382
+#endif
 
1383
+           );
 
1384
+}
 
1385
+
 
1386
+static void
 
1387
+generate_status_line ()
 
1388
+{
 
1389
+  /* Ripped from botl.c */
 
1390
+  int hp, hpmax;
 
1391
+
 
1392
+  hp = Upolyd ? u.mh : u.uhp;
 
1393
+  hpmax = Upolyd ? u.mhmax : u.uhpmax;
 
1394
+  if(hp < 0) hp = 0;
 
1395
+
 
1396
+  printf ("(nhapi-update-status ");
 
1397
+  lisp_quote;
 
1398
+  printf ("(");
 
1399
+  lisp_list (lisp_string ("name");
 
1400
+            lisp_string (plname););
 
1401
+  if (Upolyd) 
 
1402
+    {
 
1403
+      char mbot[BUFSZ];
 
1404
+      int k = 0;
 
1405
+
 
1406
+      lisp_list (lisp_string ("rank");
 
1407
+                lisp_nil);
 
1408
+      lisp_list (lisp_string ("monster");
 
1409
+                lisp_string (mons[u.umonnum].mname));
 
1410
+    }
 
1411
+  else
 
1412
+    {
 
1413
+      lisp_list (lisp_string ("rank");
 
1414
+                lisp_string (rank_of(u.ulevel, Role_switch, flags.female)););;
 
1415
+      lisp_list (lisp_string ("monster");
 
1416
+                lisp_nil);
 
1417
+    }
 
1418
+
 
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");
 
1436
+            else
 
1437
+            lisp_string ("Lawful"););
 
1438
+
 
1439
+#ifdef SCORE_ON_BOTL
 
1440
+  lisp_list (lisp_string ("Score");
 
1441
+            lisp_int (botl_score()););
 
1442
+#endif
 
1443
+
 
1444
+  if (In_endgame(&u.uz))
 
1445
+    {
 
1446
+      lisp_list (lisp_string ("Dungeon");
 
1447
+                if (Is_astralevel(&u.uz))
 
1448
+                lisp_string ("Astral Plane");
 
1449
+                else
 
1450
+                lisp_string ("End Game"););
 
1451
+    }
 
1452
+  else
 
1453
+    {
 
1454
+      lisp_list (lisp_string ("Dungeon");
 
1455
+                lisp_string (dungeons[u.uz.dnum].dname););
 
1456
+    }
 
1457
+
 
1458
+      lisp_list (lisp_string ("Dlvl");
 
1459
+                lisp_int (depth(&u.uz)););
 
1460
+
 
1461
+  lisp_list (lisp_string ("$");
 
1462
+            lisp_int (u.ugold););
 
1463
+  lisp_list (lisp_string ("HP");
 
1464
+            lisp_int (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););
 
1473
+
 
1474
+  if (Upolyd)
 
1475
+    {
 
1476
+      lisp_list (lisp_string ("HD");
 
1477
+                lisp_int (mons[u.umonnum].mlevel););
 
1478
+    }
 
1479
+  else
 
1480
+    {
 
1481
+      lisp_list (lisp_string ("HD");
 
1482
+                lisp_nil);
 
1483
+    }
 
1484
+
 
1485
+  lisp_list (lisp_string ("Level");
 
1486
+            lisp_int (u.ulevel););
 
1487
+#ifdef EXP_ON_BOTL
 
1488
+  lisp_list (lisp_string ("XP");
 
1489
+            lisp_int (u.uexp););
 
1490
+#endif
 
1491
+  lisp_list (lisp_string ("T");
 
1492
+            lisp_int (moves););
 
1493
+
 
1494
+  if (Confusion)
 
1495
+    lisp_list (lisp_string ("confusion"); lisp_string ("Conf"));
 
1496
+  else
 
1497
+    lisp_list (lisp_string ("confusion"); lisp_nil);
 
1498
+
 
1499
+  if (u.uhs != 1)
 
1500
+    lisp_list (lisp_string ("hunger"); lisp_string (hunger_stat[u.uhs]));
 
1501
+  else
 
1502
+    lisp_list (lisp_string ("hunger"); lisp_nil);
 
1503
+
 
1504
+  if (Sick) 
 
1505
+    {
 
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"));
 
1510
+    }
 
1511
+  else
 
1512
+    lisp_list (lisp_string ("sick"); lisp_nil);
 
1513
+
 
1514
+  if (Blind)
 
1515
+    lisp_list (lisp_string ("blind"); lisp_string ("Blind"));
 
1516
+  else
 
1517
+    lisp_list (lisp_string ("blind"); lisp_nil);
 
1518
+
 
1519
+  if (Stunned)
 
1520
+    lisp_list (lisp_string ("stunned"); lisp_string ("Stun"));
 
1521
+  else
 
1522
+    lisp_list (lisp_string ("stunned"); lisp_nil);
 
1523
+
 
1524
+  if (Hallucination)
 
1525
+    lisp_list (lisp_string ("hallucination"); lisp_string ("Hallu"));
 
1526
+  else
 
1527
+    lisp_list (lisp_string ("hallucination"); lisp_nil);
 
1528
+
 
1529
+  if (Slimed)
 
1530
+    lisp_list (lisp_string ("slimed"); lisp_string ("Slime"));
 
1531
+  else
 
1532
+    lisp_list (lisp_string ("slimed"); lisp_nil);
 
1533
+
 
1534
+  if (near_capacity() > UNENCUMBERED)
 
1535
+    lisp_list (lisp_string ("encumbrance"); 
 
1536
+              lisp_string (enc_stat[near_capacity()]));
 
1537
+  else
 
1538
+    lisp_list (lisp_string ("encumbrance"); lisp_nil);
 
1539
+
 
1540
+  printf (" ))\n");
 
1541
+}
 
1542
+
 
1543
+void
 
1544
+lisp_putstr(window, attr, str)
 
1545
+     winid window;
 
1546
+     int attr;
 
1547
+     const char *str;
 
1548
+{
 
1549
+  static char statline1[BUFSZ] = "";
 
1550
+  if (window == WIN_STATUS)
 
1551
+    {
 
1552
+      if (statline1[0]=='\0')
 
1553
+       Strcpy (statline1, str);
 
1554
+      else
 
1555
+       {
 
1556
+         generate_status_line ();
 
1557
+         statline1[0]='\0';
 
1558
+       }
 
1559
+    }
 
1560
+  else if (window == WIN_MESSAGE)
 
1561
+    lisp_cmd ("message", 
 
1562
+             lisp_literal (attr_to_string (attr));
 
1563
+             lisp_string (str));
 
1564
+  else
 
1565
+    lisp_cmd ("menu-putstr",
 
1566
+             lisp_int (window);
 
1567
+             lisp_literal (attr_to_string (attr));
 
1568
+             lisp_string (str));
 
1569
+}
 
1570
+
 
1571
+void
 
1572
+lisp_start_menu(window)
 
1573
+     winid window;
 
1574
+{
 
1575
+  lisp_menu_list_num = 0;
 
1576
+  lisp_current_accelerator = 'a';
 
1577
+  lisp_cmd ("start-menu", lisp_int (window));
 
1578
+}
 
1579
+
 
1580
+void
 
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 */
 
1590
+{
 
1591
+  if (identifier->a_void)
 
1592
+    {
 
1593
+      lisp_menu_item_list[lisp_menu_list_num].identifier = *identifier;
 
1594
+      if (ch == 0)
 
1595
+       {
 
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';
 
1599
+         else
 
1600
+           lisp_current_accelerator++;
 
1601
+       }      
 
1602
+      else
 
1603
+       lisp_menu_item_list[lisp_menu_list_num].accelerator = ch;
 
1604
+
 
1605
+      lisp_menu_list_num++;
 
1606
+    }
 
1607
+  else
 
1608
+    ch = -1;
 
1609
+
 
1610
+  lisp_cmd ("add-menu",
 
1611
+           lisp_int (window);
 
1612
+           lisp_int (glyph);
 
1613
+           lisp_int (glyph2tile[glyph]);
 
1614
+           lisp_int (ch);
 
1615
+           lisp_int (gch);
 
1616
+           lisp_literal (attr_to_string (attr));
 
1617
+           lisp_string (str);
 
1618
+           preselected ? lisp_t : lisp_nil);
 
1619
+}
 
1620
+
 
1621
+void
 
1622
+lisp_end_menu(window, prompt)
 
1623
+    winid window;      /* menu to use */
 
1624
+    const char *prompt;        /* prompt to for menu */
 
1625
+{
 
1626
+  lisp_cmd ("end-menu",
 
1627
+           lisp_int (window);
 
1628
+           lisp_string (prompt));
 
1629
+}
 
1630
+
 
1631
+static int
 
1632
+lisp_get_menu_identifier(ch, identifier)
 
1633
+     char ch;
 
1634
+     anything *identifier;
 
1635
+{
 
1636
+  int i;
 
1637
+
 
1638
+  for(i=0; i < lisp_menu_list_num; i++)
 
1639
+    {
 
1640
+      if( lisp_menu_item_list[i].accelerator == ch )
 
1641
+       {
 
1642
+         *identifier = lisp_menu_item_list[i].identifier;
 
1643
+         return 1;
 
1644
+       }
 
1645
+    }
 
1646
+
 
1647
+  return 0;
 
1648
+}
 
1649
+
 
1650
+int
 
1651
+lisp_select_menu(window, how, menu_list)
 
1652
+    winid window;
 
1653
+    int how;
 
1654
+    menu_item **menu_list;
 
1655
+{
 
1656
+  const char *delim = "() \n";
 
1657
+  char *list;
 
1658
+  char *token;
 
1659
+  int size = 0;
 
1660
+  int toggle;
 
1661
+
 
1662
+  lisp_cmd ("select-menu",
 
1663
+           lisp_int (window);
 
1664
+           lisp_literal (how_to_string (how)));
 
1665
+
 
1666
+  read_string ("menu", &list);
 
1667
+
 
1668
+/*   lisp_prompt ("menu"); */
 
1669
+/*   fgets (list, LINESIZ, stdin); */
 
1670
+
 
1671
+  /* The client should submit a structure like this:
 
1672
+
 
1673
+   ((ch count) (ch count) (ch count) ...) 
 
1674
+
 
1675
+   where ch is the accelerator for the menu item and count is the
 
1676
+   number of them to select.
 
1677
+   
 
1678
+   We strtok it so we just get id count id count id count. */
 
1679
+
 
1680
+  token = strtok (list, delim);
 
1681
+
 
1682
+  /* Start with some memory so realloc doesn't fail. */
 
1683
+  *menu_list = malloc (sizeof (menu_item));
 
1684
+  if (*menu_list == NULL)
 
1685
+    {
 
1686
+      panic ("Memory allocation failure; cannot get %u bytes", 
 
1687
+            sizeof (menu_item));
 
1688
+    }
 
1689
+  size = 0;
 
1690
+
 
1691
+  while (token != NULL)
 
1692
+    {
 
1693
+      /* Make more room in the array for the new item */
 
1694
+      size++;
 
1695
+      if ((*menu_list = realloc (*menu_list, size * sizeof (menu_item))) == NULL)
 
1696
+       {
 
1697
+         panic ("Memory allocation failure; cannot get %u bytes", 
 
1698
+                size * sizeof (menu_item));
 
1699
+       }
 
1700
+
 
1701
+      /* assign the item ID */
 
1702
+      lisp_get_menu_identifier (atoi (token), &(*menu_list)[size-1].item );
 
1703
+
 
1704
+      /* Read the item count */
 
1705
+      token = strtok (NULL, delim);
 
1706
+      (*menu_list)[size-1].count = atoi (token);
 
1707
+
 
1708
+      /* read the next item ID */
 
1709
+      token = strtok (NULL, delim);
 
1710
+    }
 
1711
+
 
1712
+  free (list);
 
1713
+
 
1714
+  return size;
 
1715
+}
 
1716
+
 
1717
+/* This is a tty-specific hack. Do we need it? */
 
1718
+char
 
1719
+lisp_message_menu(let, how, mesg)
 
1720
+     char let;
 
1721
+     int how;
 
1722
+     const char *mesg;
 
1723
+{
 
1724
+  lisp_cmd ("message-menu",
 
1725
+           lisp_int (let);
 
1726
+           lisp_literal (how_to_string (how));
 
1727
+           lisp_string (mesg));
 
1728
+  return '\0';
 
1729
+}
 
1730
+
 
1731
+static int
 
1732
+lisp_get_cmd(str)
 
1733
+     const char *str;
 
1734
+{
 
1735
+  int i;
 
1736
+
 
1737
+  for (i=0; cmd_index[i].name != (char *)0; i++)
 
1738
+    {
 
1739
+      if (!strcmp (str, cmd_index[i].name)) 
 
1740
+       return i;
 
1741
+    }    
 
1742
+
 
1743
+  return -1;
 
1744
+}
 
1745
+
 
1746
+static int
 
1747
+lisp_get_ext_cmd_id (str)
 
1748
+     const char *str;
 
1749
+{
 
1750
+  int i;
 
1751
+
 
1752
+  for (i=0; extcmdlist[i].ef_txt != (char *)0; i++) {
 
1753
+    if (!strcmp (str, extcmdlist[i].ef_txt)) return i;
 
1754
+  }
 
1755
+  
 
1756
+  return -1;
 
1757
+}
 
1758
+
 
1759
+/* static int */
 
1760
+/* num_digits(n) */
 
1761
+/*      int n; */
 
1762
+/* { */
 
1763
+/*   int i; */
 
1764
+/*   int ret = 1; */
 
1765
+  
 
1766
+/*   for (i=10;n / i; i *= 10) */
 
1767
+/*     { */
 
1768
+/*       ret++; */
 
1769
+/*     } */
 
1770
+
 
1771
+/*   return ret; */
 
1772
+/* } */
 
1773
+
 
1774
+/* static */
 
1775
+/* int */
 
1776
+/* power_of_ten (n) */
 
1777
+/*      int n; */
 
1778
+/* { */
 
1779
+/*   int i; */
 
1780
+/*   int power = 1; */
 
1781
+
 
1782
+/*   for (i=0; i<n; i++) */
 
1783
+/*     { */
 
1784
+/*       power *= 10; */
 
1785
+/*     } */
 
1786
+
 
1787
+/*   return power; */
 
1788
+/* } */
 
1789
+
 
1790
+int
 
1791
+lisp_nhgetch()
 
1792
+{
 
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;
 
1797
+  int cmd;
 
1798
+
 
1799
+  if (*count_pos)
 
1800
+    {
 
1801
+      char *tmp = count_pos;
 
1802
+      count_pos++;
 
1803
+      return *tmp;
 
1804
+    }
 
1805
+
 
1806
+  if (count_cmd >= 0)
 
1807
+    {
 
1808
+      cmd = count_cmd;
 
1809
+      count_cmd = -1;
 
1810
+    }
 
1811
+  else
 
1812
+    {
 
1813
+      char cmdstr[BUFSZ];
 
1814
+      int nh_cmd = 0;
 
1815
+
 
1816
+      while (!nh_cmd)
 
1817
+       {
 
1818
+         read_command ("command", cmdstr, count_buf);
 
1819
+
 
1820
+         count_pos = count_buf;
 
1821
+         cmd = lisp_get_cmd (cmdstr);
 
1822
+         if (cmd == -1)
 
1823
+           {
 
1824
+             printf ("(nhapi-message 'atr-none \"undefined-command %s\")\n", cmdstr);
 
1825
+           }
 
1826
+         else if (cmd_index[cmd].type == CMD_LISP)
 
1827
+           {
 
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"))
 
1832
+               {
 
1833
+                 get_options();
 
1834
+               }
 
1835
+           } else {
 
1836
+             /* We have a nh command. */
 
1837
+             nh_cmd = 1;
 
1838
+           }
 
1839
+       }
 
1840
+
 
1841
+      if (atoi (count_pos) > 1)
 
1842
+       {
 
1843
+         char* tmp = count_pos;
 
1844
+         count_pos++;
 
1845
+         count_cmd = cmd;
 
1846
+         return *tmp;
 
1847
+       }
 
1848
+      else
 
1849
+       {
 
1850
+         /* Since the count is 1, zero out the string. */
 
1851
+         *count_pos = 0;
 
1852
+       }
 
1853
+    }
 
1854
+
 
1855
+  if (cmd_index[cmd].type == CMD_KEY)
 
1856
+    {
 
1857
+      return cmd_index[cmd].cmd;
 
1858
+    }
 
1859
+  else if (cmd_index[cmd].type == CMD_EXT)
 
1860
+    {
 
1861
+      if ((extended_cmd_id = lisp_get_ext_cmd_id (cmd_index[cmd].name)) == -1)
 
1862
+       {
 
1863
+         /* Can never happen. */
 
1864
+         printf ("%s:%d: Bad extended command name\n", __FILE__,  __LINE__);
 
1865
+       }
 
1866
+      return '#';
 
1867
+    }
 
1868
+  else
 
1869
+    {
 
1870
+      impossible ("Impossible command type: %d", cmd_index[cmd].type);
 
1871
+    }
 
1872
+}
 
1873
+
 
1874
+int
 
1875
+lisp_nh_poskey(x, y, mod)
 
1876
+     int *x, *y, *mod;
 
1877
+{
 
1878
+/*    char scratch[256]; */
 
1879
+
 
1880
+/*    printf ("(nethack-api-poskey)\n"); */
 
1881
+
 
1882
+/*    scanf ("( %d %d '%255s )", x, y, scratch); */
 
1883
+/*    if (!strcmp (scratch, "click-1")) *mod = CLICK_1; */
 
1884
+/*    else *mod = CLICK_2; */
 
1885
+
 
1886
+/*    return 0; */
 
1887
+
 
1888
+  return lisp_nhgetch();
 
1889
+}
 
1890
+
 
1891
+static boolean inven_win_created = FALSE;
 
1892
+
 
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;
 
1897
+
 
1898
+/* returns index into winid_list that can be used. */
 
1899
+static int
 
1900
+find_empty_cell ()
 
1901
+{
 
1902
+  int i;
 
1903
+
 
1904
+  /* Check for a vacant spot in the list. */
 
1905
+  for (i=0; i<winid_list_len; i++)
 
1906
+    {
 
1907
+      if (winid_list[i] == -1) return i;
 
1908
+    }
 
1909
+
 
1910
+  /* no vacant ones, so grow the array. */
 
1911
+  if (winid_list_len >= winid_list_max)
 
1912
+    {
 
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");
 
1917
+    }
 
1918
+  winid_list_len++;
 
1919
+
 
1920
+  return winid_list_len-1;
 
1921
+}
 
1922
+
 
1923
+static int
 
1924
+winid_is_taken (winid n)
 
1925
+{
 
1926
+  int i;
 
1927
+
 
1928
+  for (i=0; i<winid_list_len; i++)
 
1929
+    if (winid_list[i] == n) return 1;
 
1930
+  
 
1931
+  return 0;
 
1932
+}
 
1933
+
 
1934
+static int
 
1935
+add_winid (winid n)
 
1936
+{
 
1937
+  if (winid_is_taken (n)) return 0; /* failed. */
 
1938
+  
 
1939
+  winid_list[find_empty_cell()] = n;
 
1940
+  return 1; /* success! */
 
1941
+}
 
1942
+
 
1943
+static winid
 
1944
+get_unique_winid ()
 
1945
+{
 
1946
+  winid i;
 
1947
+  
 
1948
+  /* look for a unique number, and add it to the list of taken
 
1949
+     numbers. */
 
1950
+  i = 0;
 
1951
+  while (!add_winid (i)) i++;
 
1952
+
 
1953
+  return i;      
 
1954
+}
 
1955
+
 
1956
+/* When a window is destroyed, it gives back its window number with
 
1957
+   this function. */
 
1958
+static void
 
1959
+return_winid (winid n)
 
1960
+{
 
1961
+  int i;
 
1962
+
 
1963
+  for (i=0; i<winid_list_len; i++)
 
1964
+    {
 
1965
+      if (winid_list[i] == n) 
 
1966
+       {
 
1967
+         winid_list[i] = -1;
 
1968
+         return;
 
1969
+       }
 
1970
+    }
 
1971
+}
 
1972
+
 
1973
+static void
 
1974
+init_winid_list ()
 
1975
+{
 
1976
+  winid_list_max = 10;
 
1977
+  winid_list_len = 0;
 
1978
+
 
1979
+  winid_list = malloc (winid_list_max * sizeof (int));
 
1980
+}
 
1981
+
 
1982
+/* Prints a create_nhwindow function and expects from stdin the id of
 
1983
+   this new window as a number. */
 
1984
+winid
 
1985
+lisp_create_nhwindow(type)
 
1986
+     int type;
 
1987
+{
 
1988
+  winid id = get_unique_winid();
 
1989
+
 
1990
+  switch (type)
 
1991
+    {
 
1992
+    case NHW_MESSAGE:
 
1993
+      lisp_cmd ("create-message-window",);
 
1994
+      break;
 
1995
+    case NHW_MAP:
 
1996
+      lisp_cmd ("create-map-window",);
 
1997
+      break;
 
1998
+    case NHW_STATUS:
 
1999
+      lisp_cmd ("create-status-window",);
 
2000
+      break;
 
2001
+    case NHW_TEXT:
 
2002
+      lisp_cmd ("create-text-window", lisp_int (id));
 
2003
+      break;
 
2004
+    case NHW_MENU:
 
2005
+      if (!inven_win_created)
 
2006
+       {
 
2007
+         lisp_cmd ("create-inventory-window", lisp_int (id));
 
2008
+         inven_win_created = TRUE;
 
2009
+       }
 
2010
+      else
 
2011
+       lisp_cmd ("create-menu-window", lisp_int (id));
 
2012
+      break;
 
2013
+    default:
 
2014
+      impossible ("Unknown window type: %d", type);
 
2015
+    };
 
2016
+
 
2017
+  return id;
 
2018
+}
 
2019
+
 
2020
+void
 
2021
+lisp_clear_nhwindow(window)
 
2022
+     winid window;
 
2023
+{
 
2024
+  if (window == WIN_MESSAGE)
 
2025
+    lisp_cmd ("clear-message",);
 
2026
+  else if (window == WIN_MAP)
 
2027
+    lisp_cmd ("clear-map",);
 
2028
+  else
 
2029
+    /* are other window types ever cleared? */
 
2030
+    lisp_cmd ("error", lisp_string("clearing unknown winid"));
 
2031
+}
 
2032
+
 
2033
+void
 
2034
+lisp_display_nhwindow(window, blocking)
 
2035
+     winid window;
 
2036
+     boolean blocking;
 
2037
+{
 
2038
+  /* don't send display messages for anything but menus */
 
2039
+  char *dummy;
 
2040
+  if (window != WIN_MESSAGE && window != WIN_STATUS && window != WIN_MAP)
 
2041
+    {
 
2042
+      lisp_cmd ("display-menu", lisp_int (window));
 
2043
+      read_string ("dummy", &dummy);
 
2044
+      free (dummy);
 
2045
+    }
 
2046
+  else if (blocking)
 
2047
+    {
 
2048
+      if (window == WIN_MESSAGE)
 
2049
+       {
 
2050
+         /* blocking on the message window happens only at the end of
 
2051
+            the game */
 
2052
+         lisp_cmd ("end",);
 
2053
+       }
 
2054
+      else
 
2055
+       {
 
2056
+         lisp_cmd ("block",);
 
2057
+         read_string ("dummy", &dummy);
 
2058
+         free (dummy);
 
2059
+       }
 
2060
+    }
 
2061
+  else if (window == WIN_STATUS)
 
2062
+    {
 
2063
+      /* initial window setup hack here :) */
 
2064
+      lisp_cmd ("restore-window-configuration",);
 
2065
+    }
 
2066
+}
 
2067
+
 
2068
+void
 
2069
+lisp_destroy_nhwindow(window)
 
2070
+     winid window;
 
2071
+{
 
2072
+  if ((window != WIN_STATUS)
 
2073
+      && (window != WIN_MESSAGE)
 
2074
+      && (window != WIN_MAP))
 
2075
+    {
 
2076
+      lisp_cmd ("destroy-menu", lisp_int (window));
 
2077
+      return_winid (window);
 
2078
+    }
 
2079
+}
 
2080
+
 
2081
+void
 
2082
+lisp_update_inventory()
 
2083
+{
 
2084
+  lisp_cmd ("update-inventory",);
 
2085
+}
 
2086
+
 
2087
+int
 
2088
+lisp_doprev_message()
 
2089
+{
 
2090
+  lisp_cmd ("doprev-message",);
 
2091
+  return 0;
 
2092
+}
 
2093
+
 
2094
+void
 
2095
+lisp_nhbell()
 
2096
+{
 
2097
+  lisp_cmd ("nhbell",);
 
2098
+}
 
2099
+
 
2100
+/* Can be an empty call says window.doc. */
 
2101
+void
 
2102
+lisp_mark_synch()
 
2103
+{
 
2104
+  /* lisp_cmd ("mark-sync",); */
 
2105
+}
 
2106
+
 
2107
+void
 
2108
+lisp_wait_synch()
 
2109
+{
 
2110
+  lisp_cmd ("wait-synch",);
 
2111
+}
 
2112
+
 
2113
+/* Since nethack will never be suspended, we need not worry about this
 
2114
+   function. */
 
2115
+void
 
2116
+lisp_resume_nhwindows()
 
2117
+{
 
2118
+  return;
 
2119
+}
 
2120
+
 
2121
+/* Since nethack will never be suspended, we need not worry about this
 
2122
+   function. */
 
2123
+void
 
2124
+lisp_suspend_nhwindows(str)
 
2125
+     const char *str;
 
2126
+{
 
2127
+  return;
 
2128
+}
 
2129
+
 
2130
+/* All keys are defined in emacs, so number_pad makes no sense. */
 
2131
+void
 
2132
+lisp_number_pad(state)
 
2133
+     int state;
 
2134
+{
 
2135
+  return;
 
2136
+}
 
2137
+
 
2138
+void
 
2139
+lisp_init_nhwindows(argcp,argv)
 
2140
+     int* argcp;
 
2141
+     char** argv;
 
2142
+{
 
2143
+  int i;
 
2144
+
 
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]));
 
2149
+
 
2150
+  /* FIXME: doesn't remove the arguments parsed, as specified in the
 
2151
+     api doc. */
 
2152
+
 
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;
 
2158
+#endif
 
2159
+  flags.time = TRUE;
 
2160
+
 
2161
+  /* inform nethack that the windows have been initialized. */
 
2162
+  iflags.window_inited = TRUE;
 
2163
+
 
2164
+  init_winid_list();
 
2165
+}
 
2166
+
 
2167
+void
 
2168
+lisp_exit_nhwindows (str)
 
2169
+     const char *str;
 
2170
+{
 
2171
+  lisp_cmd ("exit-nhwindows ", lisp_string (str));
 
2172
+}
 
2173
+
 
2174
+void
 
2175
+lisp_delay_output()
 
2176
+{
 
2177
+  char *dummy;
 
2178
+  lisp_cmd ("delay-output",);
 
2179
+  read_string ("dummy", &dummy);
 
2180
+  free (dummy);
 
2181
+}
 
2182
+
 
2183
+void
 
2184
+lisp_getlin(question, input)
 
2185
+     const char *question;
 
2186
+     char *input;
 
2187
+{
 
2188
+  char *tmp;
 
2189
+  lisp_cmd ("getlin", lisp_string (question));
 
2190
+  read_string ("string", &tmp);
 
2191
+  /* FIXME: potential buffer overflow. */
 
2192
+  strcpy (input, tmp);
 
2193
+}
 
2194
+
 
2195
+int
 
2196
+lisp_get_ext_cmd()
 
2197
+{
 
2198
+/*    int cmd; */
 
2199
+/*    int i; */
 
2200
+
 
2201
+/*    printf ("(nethack-api-get-ext-cmd '("); */
 
2202
+
 
2203
+/*    for (i=0; extcmdlist[i].ef_txt != (char *)0; i++) { */
 
2204
+/*      printf ("(\"%s\" . %d)", extcmdlist[i].ef_txt, i); */
 
2205
+/*    } */
 
2206
+/*    printf ("))\n"); */
 
2207
+
 
2208
+/*    scanf ("%d", &cmd); */
 
2209
+
 
2210
+  /* This is set when the user chooses an extended command. */
 
2211
+  return extended_cmd_id;
 
2212
+}
 
2213
+
 
2214
+void
 
2215
+lisp_display_file(str, complain)
 
2216
+     const char *str;
 
2217
+     boolean complain;
 
2218
+{
 
2219
+  lisp_cmd ("display-file",
 
2220
+           lisp_string (str);
 
2221
+           complain ? lisp_t : lisp_nil);;
 
2222
+}
 
2223
+
 
2224
+char
 
2225
+lisp_yn_function(ques, choices, def)
 
2226
+     const char *ques;
 
2227
+     const char *choices;
 
2228
+     char def;
 
2229
+{
 
2230
+  int answer;
 
2231
+
 
2232
+  /* Some questions have special functions. */
 
2233
+  if (!strncmp (ques, "In what direction", 17)
 
2234
+      || !strncmp (ques, "Talk to whom? (in what direction)", 33))
 
2235
+    {
 
2236
+      char *dir;
 
2237
+      lisp_cmd ("ask-direction",
 
2238
+               lisp_string (ques));
 
2239
+      read_string ("direction", &dir);
 
2240
+      if (!strcmp (dir, "n"))
 
2241
+       answer = 'k';
 
2242
+      else if (!strcmp (dir, "s"))
 
2243
+       answer = 'j';
 
2244
+      else if (!strcmp (dir, "e"))
 
2245
+       answer = 'l';
 
2246
+      else if (!strcmp (dir, "w"))
 
2247
+       answer = 'h';
 
2248
+      else if (!strcmp (dir, "ne"))
 
2249
+       answer = 'u';
 
2250
+      else if (!strcmp (dir, "nw"))
 
2251
+       answer = 'y';
 
2252
+      else if (!strcmp (dir, "se"))
 
2253
+       answer = 'n';
 
2254
+      else if (!strcmp (dir, "sw"))
 
2255
+       answer = 'b';
 
2256
+      else if (!strcmp (dir, "up"))
 
2257
+       answer = '<';
 
2258
+      else if (!strcmp (dir, "down"))
 
2259
+       answer = '>';
 
2260
+      else if (!strcmp (dir, "self"))
 
2261
+       answer = '.';
 
2262
+      else
 
2263
+       {
 
2264
+         if (def == '\0')
 
2265
+           answer = 0x20;              /* space */
 
2266
+         else
 
2267
+           answer = def;
 
2268
+       }
 
2269
+
 
2270
+      free (dir);
 
2271
+    }
 
2272
+  else
 
2273
+    {
 
2274
+      lisp_cmd ("yn-function",
 
2275
+               lisp_string (ques);
 
2276
+               lisp_string (choices);
 
2277
+               lisp_int (def));
 
2278
+      read_int ("number", &answer);
 
2279
+    }
 
2280
+
 
2281
+  return (char)answer;
 
2282
+}
 
2283
+
 
2284
+#ifdef POSITIONBAR
 
2285
+void
 
2286
+lisp_update_positionbar(features)
 
2287
+     char *features;
 
2288
+{
 
2289
+  lisp_cmd ("update-positionbar", lisp_string (features));
 
2290
+}
 
2291
+#endif
 
2292
+
 
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
 
2300
+
 
2301
+void
 
2302
+lisp_print_glyph(window, x, y, glyph)
 
2303
+    winid window;
 
2304
+    xchar x, y;
 
2305
+    int glyph;
 
2306
+{
 
2307
+    int ch;
 
2308
+    boolean reverse_on = FALSE;
 
2309
+    int            color;
 
2310
+    unsigned special;
 
2311
+
 
2312
+    /* map glyph to character and color */
 
2313
+    mapglyph(glyph, &ch, &color, &special, x, y);
 
2314
+
 
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)
 
2321
+      {
 
2322
+       special &= ~MG_PET;
 
2323
+      }
 
2324
+
 
2325
+    if (window == WIN_MAP)
 
2326
+      {
 
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. */
 
2330
+       if (special)
 
2331
+         {
 
2332
+           lisp_cmd ("print-glyph",
 
2333
+                     lisp_int (x);
 
2334
+                     lisp_int (y);
 
2335
+                     lisp_int (color);
 
2336
+                     lisp_int (glyph);
 
2337
+                     lisp_int (glyph2tile[glyph]);
 
2338
+                     lisp_int (ch);
 
2339
+                     lisp_literal (special_glyph_to_string (special)););
 
2340
+         }
 
2341
+       else
 
2342
+         {
 
2343
+           lisp_cmd ("print-glyph",
 
2344
+                     lisp_int (x);
 
2345
+                     lisp_int (y);
 
2346
+                     lisp_int (color);
 
2347
+                     lisp_int (glyph);
 
2348
+                     lisp_int (glyph2tile[glyph]);
 
2349
+                     lisp_int (ch););
 
2350
+         }
 
2351
+      }
 
2352
+    else
 
2353
+      lisp_cmd ("error",
 
2354
+               lisp_string ("lisp_print_glyph bad window");
 
2355
+               lisp_int (window));
 
2356
+}
 
2357
+
 
2358
+#ifdef CLIPPING
 
2359
+void
 
2360
+lisp_cliparound(x, y)
 
2361
+     int x;
 
2362
+     int y;
 
2363
+{
 
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 */
 
2367
+
 
2368
+  /*   lisp_cmd ("cliparound", lisp_int (x); lisp_int (y)); */
 
2369
+}
 
2370
+#endif
 
2371
+
 
2372
+void lisp_start_screen() { return; } /* called from setftty() in unixtty.c */
 
2373
+void lisp_end_screen() {return; }    /* called from settty() in unixtty.c */
 
2374
+
 
2375
+static void
 
2376
+get_death_text (buf)
 
2377
+     char buf[BUFSZ];
 
2378
+{
 
2379
+  
 
2380
+}
 
2381
+
 
2382
+void
 
2383
+lisp_outrip(window, how)
 
2384
+     winid window;
 
2385
+     int how;
 
2386
+{
 
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."));
 
2392
+}
 
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;
 
2400
 #endif
 
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;
 
2405
+#endif
 
2406
 #ifdef QT_GRAPHICS
 
2407
        /* XXX has_color() should be added to windowprocs */
 
2408
        if (windowprocs.name != NULL &&