~ubuntu-branches/ubuntu/intrepid/nethack/intrepid

« back to all changes in this revision

Viewing changes to debian/patches/12_lisp_windowing.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2004-04-28 22:20:28 UTC
  • Revision ID: james.westby@ubuntu.com-20040428222028-ir8ahbbxi1jcot2d
Tags: 3.4.3-5
* Add Catalan translation (Closes: #248734)
* Patch work:
  - 91_enh_menucolors: Fix Pasi Kallinen's email address. pk -> pkalli
  - 19_gnome_ext_events (new): Fix a problem in Gnomehack where mouse click
    events in the extended menu would not be handled (thus a certain
    choice might be chosen, but a different one 'picked' by the code).
    (Closes: #246265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh -e
 
2
## 12_lisp_windowing.dpatch by Ben Gertzfield <che@debian.org>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: Add LISP-based windowing system
 
6
 
 
7
if [ $# -ne 1 ]; then
 
8
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
 
9
    exit 1
 
10
fi
 
11
case "$1" in
 
12
    -patch) patch -f --no-backup-if-mismatch -p1 < $0;;
 
13
    -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
 
14
    *)
 
15
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
 
16
        exit 1;;
 
17
esac
 
18
 
 
19
exit 0
 
20
 
 
21
Redistribution and use in source and binary forms, with or without modification, are permitted
 
22
provided that the following conditions are met:
 
23
 
 
24
 1. Redistributions of source code must retain the above copyright notice, this list of conditions
 
25
    and the following disclaimer.
 
26
 2. Redistributions in binary form must reproduce the above copyright notice, this list of
 
27
    conditions and the following disclaimer in the documentation and/or other materials provided
 
28
    with the distribution.
 
29
 3. The name of the author may not be used to endorse or promote products derived from this
 
30
    software without specific prior written permission.
 
31
 
 
32
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
33
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 
34
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 
35
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
36
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
37
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
38
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
39
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
40
--- /dev/null   2003-05-01 12:00:27.000000000 -0700
 
41
+++ nethack/include/winlisp.h   2002-01-10 19:54:20.000000000 -0800
 
42
@@ -0,0 +1,70 @@
 
43
+#ifndef WINLISP_H
 
44
+#define WINLISP_H
 
45
+
 
46
+#ifndef E
 
47
+#define E extern
 
48
+#endif
 
49
+
 
50
+#if defined(BOS) || defined(NHSTDC)
 
51
+#define DIMENSION_P int
 
52
+#else
 
53
+# ifdef WIDENED_PROTOTYPES
 
54
+#define DIMENSION_P unsigned int
 
55
+# else
 
56
+#define DIMENSION_P Dimension
 
57
+# endif
 
58
+#endif
 
59
+
 
60
+extern struct window_procs tty_procs;
 
61
+
 
62
+/* ### winlisp.c ### */
 
63
+E void NDECL(win_lisp_init);
 
64
+E void FDECL(lisp_init_nhwindows, (int *, char **));
 
65
+E void NDECL(lisp_player_selection);
 
66
+E void NDECL(lisp_askname);
 
67
+E void NDECL(lisp_get_nh_event) ;
 
68
+E void FDECL(lisp_exit_nhwindows, (const char *));
 
69
+E void FDECL(lisp_suspend_nhwindows, (const char *));
 
70
+E void NDECL(lisp_resume_nhwindows);
 
71
+E winid FDECL(lisp_create_nhwindow, (int));
 
72
+E void FDECL(lisp_clear_nhwindow, (winid));
 
73
+E void FDECL(lisp_display_nhwindow, (winid, BOOLEAN_P));
 
74
+E void FDECL(lisp_destroy_nhwindow, (winid));
 
75
+E void FDECL(lisp_curs, (winid,int,int));
 
76
+E void FDECL(lisp_putstr, (winid, int, const char *));
 
77
+E void FDECL(lisp_display_file, (const char *, BOOLEAN_P));
 
78
+E void FDECL(lisp_start_menu, (winid));
 
79
+E void FDECL(lisp_add_menu, (winid,int,const ANY_P *,
 
80
+                       CHAR_P, CHAR_P, int, const char *, BOOLEAN_P));
 
81
+E void FDECL(lisp_end_menu, (winid, const char *));
 
82
+E int FDECL(lisp_select_menu, (winid, int, MENU_ITEM_P **));
 
83
+E char FDECL(lisp_message_menu, (char, int, const char *mesg));
 
84
+E void NDECL(lisp_update_inventory);
 
85
+E void NDECL(lisp_mark_synch);
 
86
+E void NDECL(lisp_wait_synch);
 
87
+#ifdef CLIPPING
 
88
+E void FDECL(lisp_cliparound, (int, int));
 
89
+#endif
 
90
+#ifdef POSITIONBAR
 
91
+E void FDECL(lisp_update_positionbar, (char *));
 
92
+#endif
 
93
+E void FDECL(lisp_print_glyph, (winid,XCHAR_P,XCHAR_P,int));
 
94
+E void FDECL(lisp_raw_print, (const char *));
 
95
+E void FDECL(lisp_raw_print_bold, (const char *));
 
96
+E int NDECL(lisp_nhgetch);
 
97
+E int FDECL(lisp_nh_poskey, (int *, int *, int *));
 
98
+E void NDECL(lisp_nhbell);
 
99
+E int NDECL(lisp_doprev_message);
 
100
+E char FDECL(lisp_yn_function, (const char *, const char *, CHAR_P));
 
101
+E void FDECL(lisp_getlin, (const char *,char *));
 
102
+E int NDECL(lisp_get_ext_cmd);
 
103
+E void FDECL(lisp_number_pad, (int));
 
104
+E void NDECL(lisp_delay_output);
 
105
+
 
106
+/* other defs that really should go away (they're tty specific) */
 
107
+E void NDECL(lisp_start_screen);
 
108
+E void NDECL(lisp_end_screen);
 
109
+
 
110
+E void FDECL(lisp_outrip, (winid,int));
 
111
+
 
112
+#endif /* WINLISP_H */
 
113
--- nethack-3.4.2/src/windows.c 2003-08-29 17:07:43.000000000 -0700
 
114
+++ nethack/src/windows.c       2002-04-23 17:44:58.000000000 -0700
 
115
@@ -40,6 +40,10 @@
 
116
 #ifdef MSWIN_GRAPHICS
 
117
 extern struct window_procs mswin_procs;
 
118
 #endif
 
119
+#ifdef LISP_GRAPHICS
 
120
+#include "winlisp.h"
 
121
+extern struct window_procs lisp_procs;
 
122
+#endif
 
123
 
 
124
 STATIC_DCL void FDECL(def_raw_print, (const char *s));
 
125
 
 
126
@@ -81,6 +85,9 @@
 
127
 #ifdef MSWIN_GRAPHICS
 
128
     { &mswin_procs, 0 },
 
129
 #endif
 
130
+#ifdef LISP_GRAPHICS
 
131
+    { &lisp_procs, win_lisp_init },
 
132
+#endif
 
133
     { 0, 0 }           /* must be last */
 
134
 };
 
135
 
 
136
--- nethack-3.4.2/win/tty/termcap.c     2003-08-29 17:08:25.000000000 -0700
 
137
+++ nethack/win/tty/termcap.c   2003-03-09 13:50:46.000000000 -0800
 
138
@@ -1161,6 +1161,11 @@
 
139
        if (windowprocs.name != NULL &&
 
140
            !strcmpi(windowprocs.name, "Gem")) return TRUE;
 
141
 #endif
 
142
+#ifdef LISP_GRAPHICS
 
143
+       /* XXX has_color() should be added to windowprocs */
 
144
+       if (windowprocs.name != NULL &&
 
145
+           !strcmpi(windowprocs.name, "lisp")) return TRUE;
 
146
+#endif
 
147
 #ifdef QT_GRAPHICS
 
148
        /* XXX has_color() should be added to windowprocs */
 
149
        if (windowprocs.name != NULL &&
 
150
--- /dev/null   2003-05-01 12:00:27.000000000 -0700
 
151
+++ nethack/win/lisp/ChangeLog  2003-06-03 02:04:26.000000000 -0700
 
152
@@ -0,0 +1,304 @@
 
153
+2003-06-03  Shawn Betts  <sabetts@sfu.ca>
 
154
+
 
155
+       * winlisp.c (lisp_print_glyph): Pass special to the print-glyph
 
156
+       lisp function as a symbol. delete the MG_PET bit in special if
 
157
+       iflags.hilite_pet is not set.
 
158
+       (special_glyph_to_string): new function
 
159
+
 
160
+2003-05-14  Shawn Betts  <sabetts@sfu.ca>
 
161
+
 
162
+       * winlisp.c (lisp_string): Also escape the backslash character.
 
163
+
 
164
+2002-09-19  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
165
+
 
166
+       * winlisp.c (lisp_cmd): nethack-api-* renamed to nhapi-*.
 
167
+
 
168
+2002-09-16  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
169
+
 
170
+       * ../tty/termcap.c (has_color): Add condition for LISP_GRAPHICS
 
171
+       which returns TRUE.
 
172
+
 
173
+2002-09-12  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
174
+
 
175
+       * winlisp.c (lisp_display_nhwindow): Add call to
 
176
+       `nethack-api-end'.
 
177
+
 
178
+       * ../../include/config.h: Default to LISP_GRAPHICS.
 
179
+
 
180
+       * ../../sys/unix/Makefile.src (WINSRC,WINOBJ,WINLIB): Set to
 
181
+       WINLISP* values.
 
182
+       (depend): Add winlisp.o dependancies.
 
183
+       
 
184
+       * winlisp.c (lisp_curs): Don't send winid.  Add error check.
 
185
+       (lisp_putstr): Call `nethack-api-message' or
 
186
+       `nethack-api-menu-putstr' when appropriate.
 
187
+       (lisp_nhgetch): Update error message call.
 
188
+       (lisp_create_nhwindow): Don't send winids when creating message,
 
189
+       map, or status windows.
 
190
+       (lisp_clear_nhwindow): Call clear-message or clear-map instead of
 
191
+       clear-nhwindow.
 
192
+       (lisp_display_nhwindow): Call display-menu instead of
 
193
+       display-nhwindow.  Call block when handling case of blocking on
 
194
+       displaying the map window.
 
195
+       (lisp_destroy_nhwindow): Use WIN_* values instead of hardcoded
 
196
+       numbers.
 
197
+       (lisp_print_glyph): Don't send winid.  Add error check for bad
 
198
+       winids.
 
199
+       (lisp_outrip): Change reference to Enethack to nethack-el.
 
200
+
 
201
+2002-04-23  Shawn  <sabetts@vcn.bc.ca>
 
202
+
 
203
+       * winlisp.c (lisp_player_selection): Update to use new 3.4.0
 
204
+       functionality.
 
205
+       (lisp_print_glyph): likewise
 
206
+
 
207
+2002-02-16  Shawn Betts  <sabetts@vcn.bc.ca>
 
208
+
 
209
+       * winlisp.c (read_string): take a pointer to a string as the
 
210
+       second argument. All callers updated. Rewritten to dynamically
 
211
+       resize the string in order to read an entire line.
 
212
+       (read_command): free the string returned from read_string
 
213
+       (lisp_askname): likewise
 
214
+       (lisp_display_nhwindow): likewise
 
215
+       (lisp_delay_output): likewise
 
216
+       (lisp_yn_function): likewise
 
217
+
 
218
+2002-02-14  Shawn Betts  <sabetts@vcn.bc.ca>
 
219
+
 
220
+       * winlisp.c (lisp_print_glyph): Handle warning glyphs.
 
221
+
 
222
+2002-01-27  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
223
+
 
224
+       * winlisp.c (generate_status_line): Send flag values
 
225
+       individually.  Always send values for all attributes.
 
226
+
 
227
+2002-01-21  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
228
+
 
229
+       * winlisp.c (lisp_add_menu): Add tile argument.
 
230
+
 
231
+2002-01-22  shawn  <sabetts@vcn.bc.ca>
 
232
+
 
233
+       * winlisp.c (lisp_player_selection): use the existing menu system
 
234
+       to select a player.
 
235
+       (lisp_menu_item_t): add a new member, accelerator.
 
236
+       (lisp_current_accelerator): new static global.
 
237
+       (lisp_add_menu): pick our own selector when ch is 0.
 
238
+       (lisp_start_menu): reset lisp_current_accelerator to 'a'.
 
239
+       (lisp_add_menu): remove the identifier argument to the lisp_cmd
 
240
+       "add_menu".
 
241
+       (lisp_get_menu_identifier): first argument is now a char.
 
242
+
 
243
+2002-01-20  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
244
+
 
245
+       * winlisp.c (cmd_index): Add remaining functions.
 
246
+
 
247
+2002-01-16  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
248
+
 
249
+       * winlisp.c (lisp_exit_nhwindows): Don't wait for a dummy return
 
250
+       value.
 
251
+       (lisp_destroy_nhwindow): Don't destroy the status, message or map
 
252
+       windows.
 
253
+
 
254
+2002-01-15  Ryan C Yeske  <rcyeske@vcn.bc.ca>
 
255
+
 
256
+       * winlisp.c (lisp_exit_nhwindows): Don't wait for a dummy return
 
257
+       value.
 
258
+       
 
259
+2002-01-10  shawn  <sabetts@vcn.bc.ca>
 
260
+
 
261
+       * winlisp.c (win_lisp_init): new function
 
262
+
 
263
+2002-01-09  Ryan C Yeske  <rcyeske@sfu.ca>
 
264
+
 
265
+       * winlisp.c (cmd_index): Add redraw command.    
 
266
+       (C): New macro.
 
267
+
 
268
+2002-01-01  shawn  <sabetts@vcn.bc.ca>
 
269
+
 
270
+       * winlisp.c (winid_list): new static global
 
271
+       (winid_list_len): likewise
 
272
+       (winid_list_max): likewise
 
273
+       (find_empty_cell): new function
 
274
+       (winid_is_taken): likewise
 
275
+       (add_winid): likewise
 
276
+       (get_unique_winid): likewise
 
277
+       (return_winid): likewise
 
278
+       (init_winid_list): likewise
 
279
+
 
280
+2001-12-20  shawn  <sabetts@vcn.bc.ca>
 
281
+
 
282
+       * winlisp.c (read_command): return the command count as a string.
 
283
+       (num_digits): remove function
 
284
+       (power_of_ten): likewise
 
285
+       (lisp_nhgetch): command count works.
 
286
+       (enc_stat): extern reference
 
287
+       (hunger_stat): new constant
 
288
+       (generate_status_line): new function
 
289
+       (lisp_putstr): use generate_status_line to create the status line
 
290
+       call.
 
291
+
 
292
+2001-12-19  shawn  <sabetts@vcn.bc.ca>
 
293
+
 
294
+       * winlisp.c: add extern declaration for glyph2tile and
 
295
+       total_tiles_used.
 
296
+       (lisp_print_glyph): pass the glyph's graphics tile index as an argument.
 
297
+
 
298
+2001-12-02  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
299
+
 
300
+       * winlisp.c (lisp_cmd, lisp_list, lisp_t, lisp_nil, lisp_literal)
 
301
+       (lisp_cons, lisp_int, lisp_string): Update macros.  Update all api
 
302
+       functions to use these macros.
 
303
+       (read_int, read_string, read_command): New functions.  Update all
 
304
+       api functions to use these functions.
 
305
+       (lisp_create_nhwindow): Send specific window creation commands.
 
306
+       (lisp_cliparound): Comment out body.
 
307
+
 
308
+2001-10-23  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
309
+
 
310
+       * winlisp.c (lisp_nhgetch): Don't silently loop on invalid
 
311
+       commands, send back a warning.
 
312
+       (lisp_yn_function): Make sure special handling is done for all
 
313
+       direction questions.  Include prompt in call to
 
314
+       nethack-api-ask-direction.  Include up, down and self directions.
 
315
+       If no default is set for a direction question, return space.
 
316
+
 
317
+2001-10-19  shawn  <sabetts@vcn.bc.ca>
 
318
+
 
319
+       * winlisp.c (lisp_init_nhwindows): turn on showexp and time flags.
 
320
+
 
321
+2001-10-17  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
322
+
 
323
+       * winlisp.c (lisp_display_nhwindow): Wait for a string if we are
 
324
+       blocking.
 
325
+
 
326
+2001-07-19  shawn  <sabetts@diggin.lamenet.tmp>
 
327
+
 
328
+       * winlisp.c (lisp_player_selection): terminate if we read a -1 as
 
329
+       a selection.
 
330
+
 
331
+2001-07-16  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
332
+
 
333
+       * winlisp.c (lisp_delay_output): expect a return value from the
 
334
+       client.
 
335
+
 
336
+2001-07-14  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
337
+
 
338
+       * winlisp.c (lisp_add_menu): Quote the attribute.
 
339
+       (lisp_outrip): Add a newline to output.
 
340
+
 
341
+2001-07-06  shawn  <sabetts@diggin.lamenet.tmp>
 
342
+
 
343
+       * winlisp.c (num_digits): new function
 
344
+       (power_of_ten): likewise
 
345
+       (lisp_nhgetch): handles repeated commands.
 
346
+
 
347
+2001-07-05  shawn  <sabetts@diggin.lamenet.tmp>
 
348
+
 
349
+       * winlisp.c (WINLISP_VOID_RETVAL): flushes stdout
 
350
+
 
351
+2001-07-04  Ryan Yeske  <rcyeske@van.gobasis.com>
 
352
+
 
353
+       * winlisp.c (lisp_add_menu): Convert printf to lisp_* macros,
 
354
+       fixing a string quote bug.
 
355
+
 
356
+2001-06-28  shawn  <sabetts@diggin.lamenet.tmp>
 
357
+
 
358
+       * winlisp.c (zap_color): new define
 
359
+       (cmap_color): likewise
 
360
+       (obj_color): likewise
 
361
+       (mon_color): likewise
 
362
+       (invis_color): likewise
 
363
+       (pet_color): likewise
 
364
+       (lisp_print_glyph): export the color. export the ascii character
 
365
+       as a number.
 
366
+
 
367
+2001-06-27  shawn  <sabetts@diggin.lamenet.tmp>
 
368
+
 
369
+       * winlisp.c: fix a typo cmd_index
 
370
+       (lisp_yn_function): pass characters as numbers instead of ascii
 
371
+       characters. specially handle the "In what direction?" question.
 
372
+       (lisp_outrip): prints a properly formed lisp expression.
 
373
+
 
374
+2001-06-21  Shawn Betts  <sabetts@van.gobasis.com>
 
375
+
 
376
+       * winlisp.c (lisp_add_menu): items that are not selectable are
 
377
+       sent with an identifier of -1.
 
378
+       (lisp_select_menu): handle failed memory
 
379
+       allocation.
 
380
+
 
381
+2001-05-06  shawn  <sabetts@diggin.lamenet.tmp>
 
382
+
 
383
+       * winlisp.c (LINESIZ): new define
 
384
+       (lisp_menu_item_t): new struct
 
385
+       (lisp_menu_item_list): new static global
 
386
+       (lisp_menu_list_size): likewise
 
387
+       (lisp_menu_list_num): likewise
 
388
+       (cmd_index): fixed ddrop entry
 
389
+       (read_int): new function
 
390
+       (lisp_player_selection): use read_int
 
391
+       (lisp_askname): read the entire line to a string and parse data
 
392
+       from it.
 
393
+       (lisp_nhgetch): likewise
 
394
+       (lisp_create_nhwindow): likewise
 
395
+       (lisp_getlin): likewise
 
396
+       (lisp_yn_function): likewise
 
397
+       (lisp_start_menu): set lisp_menu_list_num to 0
 
398
+       (lisp_add_menu): add an entry to lisp_menu_item_list
 
399
+       (lisp_add_menu): pass the item's ID to the client instead of the
 
400
+       actual identifier.
 
401
+       (lisp_get_menu_identifier): new function
 
402
+       (lisp_select_menu): parse the list of selected menu items
 
403
+       (lisp_print_glyph): escape backslashes in output
 
404
+
 
405
+2000-10-01  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
406
+
 
407
+       * winlisp.c (cmd_index): renamed "ddoremarm" to "remarm" and
 
408
+       "ddoinv" to "inv".
 
409
+
 
410
+2000-09-25  Shawn  <sabetts@vcn.bc.ca>
 
411
+
 
412
+       * winlisp.c: Added more key commands.
 
413
+       (lisp_player_selection): honours default player selections as
 
414
+       specified in the nethackrc file.
 
415
+
 
416
+2000-09-22  Shawn  <sabetts@vcn.bc.ca>
 
417
+
 
418
+       * winlisp.c (lisp_nhgetch): changed while loop stop condition.
 
419
+
 
420
+2000-09-19  Ryan yeske  <rcyeske@van.gobasis.com>
 
421
+
 
422
+       * winlisp.c (lisp_nh_getch): renamed from lisp_nh_getcmd() since
 
423
+       this is really called by the core when nethack wants a key.
 
424
+       (cmd_index): added gowest, gosouth, gonorth, goeast.
 
425
+
 
426
+2000-09-12  shawn  <sabetts@gobasis.com>
 
427
+
 
428
+       * winlisp.c (lisp_nh_poskey): Added code to read in an x,y,mod
 
429
+       combination instead of calling lisp_nhgetcmd. Currently commented
 
430
+       out until the lisp side catches up.  added cmd_index structure to
 
431
+       translate incoming command strings to extended commands or
 
432
+       keystrokes. Changed lisp_nhgetch to lisp_nhgetcmd and changed the
 
433
+       lisp command it calls to 'nethack-get-command'.
 
434
+
 
435
+2000-09-11  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
436
+
 
437
+       * winlisp.c (lisp_cmd, lisp_close_cmd, lisp_open, lisp_close,
 
438
+       lisp_quote, lisp_int, lisp_string, lisp_dot): created macros.
 
439
+
 
440
+2000-09-10  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
441
+
 
442
+       * winlisp.c (lisp_outrip): added closing paren.
 
443
+
 
444
+2000-08-21  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
445
+
 
446
+       * winlisp.c (lisp_nhgetch): change ch type to int from char.
 
447
+
 
448
+2000-08-20  Ryan Yeske  <rcyeske@vcn.bc.ca>
 
449
+
 
450
+       * winlisp.c (lisp_player_selection): role/race/gender/alignment
 
451
+       selection now sends (nethack-apix-choose-X ALIST) instead of
 
452
+       simply an alist.
 
453
+       (lisp_update_inventory):
 
454
+       s/nethack-api-updated-inventory/nethack-api-update-inventory/
 
455
+       (WINLISP_VOID_RETVAL): added macro, called for every void
 
456
+       function.
 
457
--- /dev/null   2003-05-01 12:00:27.000000000 -0700
 
458
+++ nethack/win/lisp/winlisp.c  2003-09-13 12:38:18.000000000 -0700
 
459
@@ -0,0 +1,1871 @@
 
460
+/* Copyright (c) Shawn Betts, Ryan Yeske, 2001                    */
 
461
+/* NetHack may be freely redistributed.  See license for details. */
 
462
+
 
463
+/*
 
464
+ * "Main" file for the lisp/emacs window-port.  This contains most of
 
465
+ * the interface routines.  Please see doc/window.doc for an
 
466
+ * description of the window interface.  
 
467
+ */
 
468
+
 
469
+#ifdef MSDOS                   /* from compiler */
 
470
+#define SHORT_FILENAMES
 
471
+#endif
 
472
+
 
473
+#include "hack.h"
 
474
+#include "winlisp.h"
 
475
+#include "func_tab.h"
 
476
+
 
477
+#include "dlb.h"
 
478
+#ifdef SHORT_FILENAMES
 
479
+#include "patchlev.h"
 
480
+#else
 
481
+#include "patchlevel.h"
 
482
+#endif
 
483
+
 
484
+#define CMD_KEY 0
 
485
+#define CMD_EXT 1
 
486
+
 
487
+/* from tile.c */
 
488
+extern short glyph2tile[];
 
489
+extern int total_tiles_used;
 
490
+
 
491
+typedef struct
 
492
+{
 
493
+  anything identifier;
 
494
+  char accelerator;
 
495
+} lisp_menu_item_t;
 
496
+
 
497
+/* An iterator for assigning accelerator keys. */
 
498
+static char lisp_current_accelerator;
 
499
+
 
500
+/* Helper structures to map menu id's to nethack anything's */
 
501
+static lisp_menu_item_t lisp_menu_item_list[1000];
 
502
+static int lisp_menu_list_size = 1000;
 
503
+static int lisp_menu_list_num;
 
504
+
 
505
+extern char *enc_stat[];
 
506
+const char *hunger_stat[] = {
 
507
+       "Satiated",
 
508
+       "",
 
509
+       "Hungry",
 
510
+       "Weak",
 
511
+       "Fainting",
 
512
+       "Fainted",
 
513
+       "Starved"
 
514
+};
 
515
+
 
516
+typedef struct 
 
517
+{
 
518
+  char *name;
 
519
+  int type;
 
520
+  int cmd;                     /* The command (a keystroke) */
 
521
+}cmd_index_t;
 
522
+
 
523
+#ifndef C
 
524
+#define C(c)           (0x1f & (c))
 
525
+#endif
 
526
+
 
527
+cmd_index_t cmd_index[] = { {"gowest", CMD_KEY, 'h'},
 
528
+                           {"gowestontop", CMD_KEY, 'H'},
 
529
+                           {"gowestnear", CMD_KEY, C('h')},
 
530
+
 
531
+                           {"gosouth", CMD_KEY, 'j'},
 
532
+                           {"gosouthontop", CMD_KEY, 'J'},
 
533
+                           {"gosouthnear", CMD_KEY,  C('j')},
 
534
+
 
535
+                           {"gonorth", CMD_KEY, 'k'},
 
536
+                           {"gonorthontop", CMD_KEY, 'K'},
 
537
+                           {"gonorthnear", CMD_KEY, C('k')},
 
538
+
 
539
+                           {"goeast", CMD_KEY, 'l'},
 
540
+                           {"goeastontop", CMD_KEY, 'L'},
 
541
+                           {"goeastnear", CMD_KEY, C('l')},
 
542
+
 
543
+                           {"gonorthwest", CMD_KEY, 'y'},
 
544
+                           {"gonorthwestontop", CMD_KEY, 'Y'},
 
545
+                           {"gonorthwestnear", CMD_KEY, C('y')},
 
546
+
 
547
+                           {"gonortheast", CMD_KEY, 'u'},
 
548
+                           {"gonortheastontop", CMD_KEY, 'U'},
 
549
+                           {"gonortheastnear", CMD_KEY, C('u')},
 
550
+
 
551
+                           {"gosouthwest", CMD_KEY, 'b'},
 
552
+                           {"gosouthwestontop", CMD_KEY, 'B'},
 
553
+                           {"gosouthwestnear", CMD_KEY, C('b')},
 
554
+
 
555
+                           {"gosoutheast", CMD_KEY, 'n'},
 
556
+                           {"gosoutheastontop", CMD_KEY, 'N'},
 
557
+                           {"gosoutheastnear", CMD_KEY, C('n')},
 
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
+                           {0, CMD_KEY, '\0'} };
 
682
+
 
683
+/* This variable is set when the user has selected an extended command. */
 
684
+static int extended_cmd_id;
 
685
+  
 
686
+/* Interface definition, for windows.c */
 
687
+struct window_procs lisp_procs = {
 
688
+  "lisp",
 
689
+  WC_COLOR|WC_HILITE_PET,
 
690
+  0L,
 
691
+  lisp_init_nhwindows,
 
692
+  lisp_player_selection,
 
693
+  lisp_askname,
 
694
+  lisp_get_nh_event,
 
695
+  lisp_exit_nhwindows,
 
696
+  lisp_suspend_nhwindows,
 
697
+  lisp_resume_nhwindows,
 
698
+  lisp_create_nhwindow,
 
699
+  lisp_clear_nhwindow,
 
700
+  lisp_display_nhwindow,
 
701
+  lisp_destroy_nhwindow,
 
702
+  lisp_curs,
 
703
+  lisp_putstr,
 
704
+  lisp_display_file,
 
705
+  lisp_start_menu,
 
706
+  lisp_add_menu,
 
707
+  lisp_end_menu,
 
708
+  lisp_select_menu,
 
709
+  genl_message_menu,
 
710
+  lisp_update_inventory,
 
711
+  lisp_mark_synch,
 
712
+  lisp_wait_synch,
 
713
+#ifdef CLIPPING
 
714
+  lisp_cliparound,
 
715
+#endif
 
716
+#ifdef POSITIONBAR
 
717
+  lisp_update_positionbar,
 
718
+#endif
 
719
+  lisp_print_glyph,
 
720
+  lisp_raw_print,
 
721
+  lisp_raw_print_bold,
 
722
+  lisp_nhgetch,
 
723
+  lisp_nh_poskey,
 
724
+  lisp_nhbell,
 
725
+  lisp_doprev_message,
 
726
+  lisp_yn_function,
 
727
+  lisp_getlin,
 
728
+  lisp_get_ext_cmd,
 
729
+  lisp_number_pad,
 
730
+  lisp_delay_output,
 
731
+#ifdef CHANGE_COLOR    /* the Mac uses a palette device */
 
732
+  donull,
 
733
+  donull,
 
734
+#endif
 
735
+  /* other defs that really should go away (they're tty specific) */
 
736
+  lisp_start_screen,
 
737
+  lisp_end_screen,
 
738
+  lisp_outrip,
 
739
+  genl_preference_update,
 
740
+};
 
741
+
 
742
+/* macros for printing lisp output */
 
743
+#define lisp_cmd(s,body)                       \
 
744
+  do                                           \
 
745
+    {                                          \
 
746
+      printf("(nhapi-%s ",s);          \
 
747
+      body;                                    \
 
748
+      printf(")\n");                           \
 
749
+    }                                          \
 
750
+  while (0)
 
751
+/* #define lisp_cmd0(s) printf ("(nhapi-%s)\n", s) */
 
752
+#define lisp_list(body)                                \
 
753
+  do                                           \
 
754
+    {                                          \
 
755
+      printf("(");                             \
 
756
+      body;                                    \
 
757
+      printf(") ");                            \
 
758
+    }                                          \
 
759
+  while (0)
 
760
+
 
761
+#define lisp_open printf("(")
 
762
+#define lisp_close printf(") ")
 
763
+#define lisp_quote printf("'")
 
764
+#define lisp_dot printf(". ")
 
765
+#define lisp_t printf("t ")
 
766
+#define lisp_nil printf("nil ")
 
767
+#define lisp_literal(x)                                \
 
768
+  do                                           \
 
769
+    {                                          \
 
770
+      lisp_quote;                              \
 
771
+      printf ("%s ", x);                       \
 
772
+    }                                          \
 
773
+  while (0)
 
774
+#define lisp_cons(x,y)                         \
 
775
+  do                                           \
 
776
+    {                                          \
 
777
+      lisp_open;                               \
 
778
+      x;                                       \
 
779
+      lisp_dot;                                        \
 
780
+      y;                                       \
 
781
+      lisp_close;                              \
 
782
+    }                                          \
 
783
+  while (0)
 
784
+#define lisp_int(i) printf("%d ",i)
 
785
+#define lisp_string(s)                                 \
 
786
+  do                                                   \
 
787
+     {                                                 \
 
788
+       int nhi;                                                \
 
789
+       printf ("\"");                                  \
 
790
+       if (s)                                          \
 
791
+        for (nhi=0;nhi<strlen(s);nhi++)                \
 
792
+          {                                            \
 
793
+            if (s[nhi] == 34                           \
 
794
+                || s[nhi] == 92) putchar('\\');        \
 
795
+            putchar(s[nhi]);                           \
 
796
+          }                                            \
 
797
+       printf("\" ");                                  \
 
798
+     }                                                 \
 
799
+  while (0)
 
800
+
 
801
+static const char*
 
802
+attr_to_string(attr)
 
803
+     int attr;
 
804
+{
 
805
+  switch (attr)
 
806
+    {
 
807
+    case ATR_NONE:
 
808
+      return "atr-none";
 
809
+    case ATR_ULINE:
 
810
+      return "atr-uline";
 
811
+    case ATR_BOLD:
 
812
+      return "atr-bold";
 
813
+    case ATR_BLINK:
 
814
+      return "atr-blink";
 
815
+    case ATR_INVERSE:
 
816
+      return "atr-inverse";
 
817
+    default:
 
818
+      /* Should never happen. */
 
819
+      impossible ("Invalid attribute code.");
 
820
+      exit (EXIT_FAILURE);
 
821
+      break;
 
822
+    }
 
823
+}
 
824
+
 
825
+static const char*
 
826
+special_glyph_to_string(special)
 
827
+     unsigned special;
 
828
+{
 
829
+  switch (special)
 
830
+    {
 
831
+    case MG_CORPSE:
 
832
+      return "corpse";
 
833
+    case MG_INVIS:
 
834
+      return "invis";
 
835
+    case MG_DETECT:
 
836
+      return "detect";
 
837
+    case MG_PET:
 
838
+      return "pet";
 
839
+    case MG_RIDDEN:
 
840
+      return "ridden";
 
841
+    }
 
842
+  
 
843
+  /* If it's a combination, just return special. */
 
844
+  if (special)
 
845
+    return "special";
 
846
+  else
 
847
+    return "none";
 
848
+}
 
849
+
 
850
+static const char*
 
851
+wintype_to_string(type)
 
852
+     int type;
 
853
+{
 
854
+  switch (type)
 
855
+    {
 
856
+    case NHW_MAP:
 
857
+      return "nhw-map";
 
858
+    case NHW_MESSAGE:
 
859
+      return "nhw-message";
 
860
+    case NHW_STATUS:
 
861
+      return "nhw-status";
 
862
+    case NHW_MENU:
 
863
+      return "nhw-menu";
 
864
+    case NHW_TEXT:
 
865
+      return "nhw-text";
 
866
+    default:
 
867
+      fprintf (stderr, "Invalid window code\n");
 
868
+      exit (EXIT_FAILURE);
 
869
+      break;
 
870
+    }
 
871
+}
 
872
+
 
873
+static const char*
 
874
+how_to_string (how)
 
875
+     int how;
 
876
+{
 
877
+  switch (how)
 
878
+    {
 
879
+    case PICK_NONE:
 
880
+      return "pick-none";
 
881
+    case PICK_ONE:
 
882
+      return "pick-one";
 
883
+    case PICK_ANY:
 
884
+      return "pick-any";
 
885
+    default:
 
886
+      impossible ("Invalid how value %d", how);
 
887
+    }
 
888
+}
 
889
+
 
890
+static int
 
891
+read_int (prompt, i)
 
892
+     const char* prompt;
 
893
+     int *i;
 
894
+{
 
895
+  char line[BUFSZ];
 
896
+  int rv;
 
897
+  printf ("%s> ", prompt);
 
898
+  fgets (line, BUFSZ, stdin);
 
899
+  rv = sscanf (line, "%d", i);
 
900
+  if (rv != 1) *i = -1;
 
901
+  return rv;
 
902
+}
 
903
+
 
904
+static int
 
905
+read_string (prompt, str)
 
906
+     const char* prompt;
 
907
+     char **str;
 
908
+{
 
909
+  char* rv;
 
910
+  int len;
 
911
+  int size;
 
912
+  char tmp[BUFSZ];
 
913
+
 
914
+  len = 0;
 
915
+  size = BUFSZ * 2;
 
916
+  *str = malloc (size);
 
917
+  (*str)[0] = '\0';
 
918
+
 
919
+  printf ("%s> ", prompt);
 
920
+
 
921
+  do
 
922
+    {
 
923
+      /* Read the string */
 
924
+      rv = fgets (tmp, BUFSZ, stdin);
 
925
+      if (rv == NULL)
 
926
+       break;
 
927
+
 
928
+      len += strlen (tmp);
 
929
+      if (len >= size - 1)
 
930
+       {
 
931
+         size *= 2;
 
932
+         *str = realloc (*str, size);
 
933
+         if (*str == NULL)
 
934
+           panic ("Memory allocation failure; cannot get %u bytes", size);
 
935
+       }
 
936
+      strcat (*str, tmp);
 
937
+    } while (tmp[strlen (tmp) - 1] != '\n');
 
938
+
 
939
+  /* Did we read a string or error out? */
 
940
+  if (rv == NULL)
 
941
+    {
 
942
+      free (*str);
 
943
+      return -1;
 
944
+    }
 
945
+  else
 
946
+    {
 
947
+      /* chop the newline */
 
948
+      (*str) [strlen (*str) - 1] = '\0';
 
949
+      return 0;
 
950
+    }
 
951
+}
 
952
+
 
953
+
 
954
+static int
 
955
+read_command (prompt, cmd, count)
 
956
+     const char *prompt;
 
957
+     char *cmd;
 
958
+     char *count;
 
959
+{
 
960
+  char *buf;
 
961
+  int rv;
 
962
+  cmd[0] = '\0';
 
963
+  *count = 0;
 
964
+  if (read_string (prompt, &buf) == -1)
 
965
+    return -1;
 
966
+  rv = sscanf (buf, "%s %s", cmd, count);
 
967
+  free (buf);
 
968
+  if (rv != 2) *count = 0;
 
969
+  return rv;
 
970
+}
 
971
+
 
972
+void
 
973
+bail(mesg)
 
974
+     const char *mesg;
 
975
+{
 
976
+  clearlocks ();
 
977
+  lisp_exit_nhwindows (mesg);
 
978
+  terminate (EXIT_SUCCESS);
 
979
+  /*NOTREACHED*/
 
980
+}
 
981
+
 
982
+void
 
983
+win_lisp_init ()
 
984
+{
 
985
+  /* Code to be executed on startup. */
 
986
+}
 
987
+
 
988
+void
 
989
+lisp_player_selection ()
 
990
+{
 
991
+       int i, k, n;
 
992
+       char pick4u = 'n', thisch, lastch = 0;
 
993
+       char pbuf[QBUFSZ], plbuf[QBUFSZ];
 
994
+       winid win;
 
995
+       anything any;
 
996
+       menu_item *selected = 0;
 
997
+
 
998
+       /* prevent an unnecessary prompt */
 
999
+       rigid_role_checks();
 
1000
+
 
1001
+       /* Should we randomly pick for the player? */
 
1002
+       if (!flags.randomall &&
 
1003
+           (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE ||
 
1004
+            flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) {
 
1005
+
 
1006
+         pick4u = lisp_yn_function ("Shall I pick a character for you? [ynq] ", "ynq", 'y');
 
1007
+
 
1008
+         if (pick4u != 'y' && pick4u != 'n') 
 
1009
+           {
 
1010
+           give_up:    /* Quit */
 
1011
+             if (selected) free((genericptr_t) selected);
 
1012
+             bail((char *)0);
 
1013
+             /*NOTREACHED*/
 
1014
+             return;
 
1015
+           }
 
1016
+
 
1017
+       }
 
1018
+
 
1019
+       (void)  root_plselection_prompt(plbuf, QBUFSZ - 1,
 
1020
+                       flags.initrole, flags.initrace, flags.initgend, flags.initalign);
 
1021
+
 
1022
+       /* Select a role, if necessary */
 
1023
+       /* we'll try to be compatible with pre-selected race/gender/alignment,
 
1024
+        * but may not succeed */
 
1025
+       if (flags.initrole < 0) {
 
1026
+           char rolenamebuf[QBUFSZ];
 
1027
+           /* Process the choice */
 
1028
+           if (pick4u == 'y' || flags.initrole == ROLE_RANDOM || flags.randomall) {
 
1029
+               /* Pick a random role */
 
1030
+               flags.initrole = pick_role(flags.initrace, flags.initgend,
 
1031
+                                               flags.initalign, PICK_RANDOM);
 
1032
+               if (flags.initrole < 0) {
 
1033
+/*                 lisp_putstr(BASE_WINDOW, 0, "Incompatible role!"); */
 
1034
+                   flags.initrole = randrole();
 
1035
+               }
 
1036
+           } else {
 
1037
+               /* Prompt for a role */
 
1038
+               win = create_nhwindow(NHW_MENU);
 
1039
+               start_menu(win);
 
1040
+               any.a_void = 0;         /* zero out all bits */
 
1041
+               for (i = 0; roles[i].name.m; i++) {
 
1042
+                   if (ok_role(i, flags.initrace, flags.initgend,
 
1043
+                                                       flags.initalign)) {
 
1044
+                       any.a_int = i+1;        /* must be non-zero */
 
1045
+                       thisch = lowc(roles[i].name.m[0]);
 
1046
+                       if (thisch == lastch) thisch = highc(thisch);
 
1047
+                       if (flags.initgend != ROLE_NONE && flags.initgend != ROLE_RANDOM) {
 
1048
+                               if (flags.initgend == 1  && roles[i].name.f)
 
1049
+                                       Strcpy(rolenamebuf, roles[i].name.f);
 
1050
+                               else
 
1051
+                                       Strcpy(rolenamebuf, roles[i].name.m);
 
1052
+                       } else {
 
1053
+                               if (roles[i].name.f) {
 
1054
+                                       Strcpy(rolenamebuf, roles[i].name.m);
 
1055
+                                       Strcat(rolenamebuf, "/");
 
1056
+                                       Strcat(rolenamebuf, roles[i].name.f);
 
1057
+                               } else 
 
1058
+                                       Strcpy(rolenamebuf, roles[i].name.m);
 
1059
+                       }       
 
1060
+                       add_menu(win, NO_GLYPH, &any, thisch,
 
1061
+                           0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED);
 
1062
+                       lastch = thisch;
 
1063
+                   }
 
1064
+               }
 
1065
+               any.a_int = pick_role(flags.initrace, flags.initgend,
 
1066
+                                   flags.initalign, PICK_RANDOM)+1;
 
1067
+               if (any.a_int == 0)     /* must be non-zero */
 
1068
+                   any.a_int = randrole()+1;
 
1069
+               add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
 
1070
+                               "Random", MENU_UNSELECTED);
 
1071
+               any.a_int = i+1;        /* must be non-zero */
 
1072
+               add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
 
1073
+                               "Quit", MENU_UNSELECTED);
 
1074
+               Sprintf(pbuf, "Pick a role for your %s", plbuf);
 
1075
+               end_menu(win, pbuf);
 
1076
+               n = select_menu(win, PICK_ONE, &selected);
 
1077
+               destroy_nhwindow(win);
 
1078
+
 
1079
+               /* Process the choice */
 
1080
+               if (n != 1 || selected[0].item.a_int == any.a_int)
 
1081
+                   goto give_up;               /* Selected quit */
 
1082
+
 
1083
+               flags.initrole = selected[0].item.a_int - 1;
 
1084
+               free((genericptr_t) selected),  selected = 0;
 
1085
+           }
 
1086
+           (void)  root_plselection_prompt(plbuf, QBUFSZ - 1,
 
1087
+                       flags.initrole, flags.initrace, flags.initgend, flags.initalign);
 
1088
+       }
 
1089
+       
 
1090
+       /* Select a race, if necessary */
 
1091
+       /* force compatibility with role, try for compatibility with
 
1092
+        * pre-selected gender/alignment */
 
1093
+       if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) {
 
1094
+           /* pre-selected race not valid */
 
1095
+           if (pick4u == 'y' || flags.initrace == ROLE_RANDOM || flags.randomall) {
 
1096
+               flags.initrace = pick_race(flags.initrole, flags.initgend,
 
1097
+                                                       flags.initalign, PICK_RANDOM);
 
1098
+               if (flags.initrace < 0) {
 
1099
+/*                 lisp_putstr(BASE_WINDOW, 0, "Incompatible race!"); */
 
1100
+                   flags.initrace = randrace(flags.initrole);
 
1101
+               }
 
1102
+           } else {    /* pick4u == 'n' */
 
1103
+               /* Count the number of valid races */
 
1104
+               n = 0;  /* number valid */
 
1105
+               k = 0;  /* valid race */
 
1106
+               for (i = 0; races[i].noun; i++) {
 
1107
+                   if (ok_race(flags.initrole, i, flags.initgend,
 
1108
+                                                       flags.initalign)) {
 
1109
+                       n++;
 
1110
+                       k = i;
 
1111
+                   }
 
1112
+               }
 
1113
+               if (n == 0) {
 
1114
+                   for (i = 0; races[i].noun; i++) {
 
1115
+                       if (validrace(flags.initrole, i)) {
 
1116
+                           n++;
 
1117
+                           k = i;
 
1118
+                       }
 
1119
+                   }
 
1120
+               }
 
1121
+
 
1122
+               /* Permit the user to pick, if there is more than one */
 
1123
+               if (n > 1) {
 
1124
+                   win = create_nhwindow(NHW_MENU);
 
1125
+                   start_menu(win);
 
1126
+                   any.a_void = 0;         /* zero out all bits */
 
1127
+                   for (i = 0; races[i].noun; i++)
 
1128
+                       if (ok_race(flags.initrole, i, flags.initgend,
 
1129
+                                                       flags.initalign)) {
 
1130
+                           any.a_int = i+1;    /* must be non-zero */
 
1131
+                           add_menu(win, NO_GLYPH, &any, races[i].noun[0],
 
1132
+                               0, ATR_NONE, races[i].noun, MENU_UNSELECTED);
 
1133
+                       }
 
1134
+                   any.a_int = pick_race(flags.initrole, flags.initgend,
 
1135
+                                       flags.initalign, PICK_RANDOM)+1;
 
1136
+                   if (any.a_int == 0) /* must be non-zero */
 
1137
+                       any.a_int = randrace(flags.initrole)+1;
 
1138
+                   add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
 
1139
+                                   "Random", MENU_UNSELECTED);
 
1140
+                   any.a_int = i+1;    /* must be non-zero */
 
1141
+                   add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
 
1142
+                                   "Quit", MENU_UNSELECTED);
 
1143
+                   Sprintf(pbuf, "Pick the race of your %s", plbuf);
 
1144
+                   end_menu(win, pbuf);
 
1145
+                   n = select_menu(win, PICK_ONE, &selected);
 
1146
+                   destroy_nhwindow(win);
 
1147
+                   if (n != 1 || selected[0].item.a_int == any.a_int)
 
1148
+                       goto give_up;           /* Selected quit */
 
1149
+
 
1150
+                   k = selected[0].item.a_int - 1;
 
1151
+                   free((genericptr_t) selected),      selected = 0;
 
1152
+               }
 
1153
+               flags.initrace = k;
 
1154
+           }
 
1155
+           (void)  root_plselection_prompt(plbuf, QBUFSZ - 1,
 
1156
+                       flags.initrole, flags.initrace, flags.initgend, flags.initalign);
 
1157
+       }
 
1158
+
 
1159
+       /* Select a gender, if necessary */
 
1160
+       /* force compatibility with role/race, try for compatibility with
 
1161
+        * pre-selected alignment */
 
1162
+       if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace,
 
1163
+                                               flags.initgend)) {
 
1164
+           /* pre-selected gender not valid */
 
1165
+           if (pick4u == 'y' || flags.initgend == ROLE_RANDOM || flags.randomall) {
 
1166
+               flags.initgend = pick_gend(flags.initrole, flags.initrace,
 
1167
+                                               flags.initalign, PICK_RANDOM);
 
1168
+               if (flags.initgend < 0) {
 
1169
+/*                 lisp_putstr(BASE_WINDOW, 0, "Incompatible gender!"); */
 
1170
+                   flags.initgend = randgend(flags.initrole, flags.initrace);
 
1171
+               }
 
1172
+           } else {    /* pick4u == 'n' */
 
1173
+               /* Count the number of valid genders */
 
1174
+               n = 0;  /* number valid */
 
1175
+               k = 0;  /* valid gender */
 
1176
+               for (i = 0; i < ROLE_GENDERS; i++) {
 
1177
+                   if (ok_gend(flags.initrole, flags.initrace, i,
 
1178
+                                                       flags.initalign)) {
 
1179
+                       n++;
 
1180
+                       k = i;
 
1181
+                   }
 
1182
+               }
 
1183
+               if (n == 0) {
 
1184
+                   for (i = 0; i < ROLE_GENDERS; i++) {
 
1185
+                       if (validgend(flags.initrole, flags.initrace, i)) {
 
1186
+                           n++;
 
1187
+                           k = i;
 
1188
+                       }
 
1189
+                   }
 
1190
+               }
 
1191
+
 
1192
+               /* Permit the user to pick, if there is more than one */
 
1193
+               if (n > 1) {
 
1194
+                   win = create_nhwindow(NHW_MENU);
 
1195
+                   start_menu(win);
 
1196
+                   any.a_void = 0;         /* zero out all bits */
 
1197
+                   for (i = 0; i < ROLE_GENDERS; i++)
 
1198
+                       if (ok_gend(flags.initrole, flags.initrace, i,
 
1199
+                                                           flags.initalign)) {
 
1200
+                           any.a_int = i+1;
 
1201
+                           add_menu(win, NO_GLYPH, &any, genders[i].adj[0],
 
1202
+                               0, ATR_NONE, genders[i].adj, MENU_UNSELECTED);
 
1203
+                       }
 
1204
+                   any.a_int = pick_gend(flags.initrole, flags.initrace,
 
1205
+                                           flags.initalign, PICK_RANDOM)+1;
 
1206
+                   if (any.a_int == 0) /* must be non-zero */
 
1207
+                       any.a_int = randgend(flags.initrole, flags.initrace)+1;
 
1208
+                   add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
 
1209
+                                   "Random", MENU_UNSELECTED);
 
1210
+                   any.a_int = i+1;    /* must be non-zero */
 
1211
+                   add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
 
1212
+                                   "Quit", MENU_UNSELECTED);
 
1213
+                   Sprintf(pbuf, "Pick the gender of your %s", plbuf);
 
1214
+                   end_menu(win, pbuf);
 
1215
+                   n = select_menu(win, PICK_ONE, &selected);
 
1216
+                   destroy_nhwindow(win);
 
1217
+                   if (n != 1 || selected[0].item.a_int == any.a_int)
 
1218
+                       goto give_up;           /* Selected quit */
 
1219
+
 
1220
+                   k = selected[0].item.a_int - 1;
 
1221
+                   free((genericptr_t) selected),      selected = 0;
 
1222
+               }
 
1223
+               flags.initgend = k;
 
1224
+           }
 
1225
+           (void)  root_plselection_prompt(plbuf, QBUFSZ - 1,
 
1226
+                       flags.initrole, flags.initrace, flags.initgend, flags.initalign);
 
1227
+       }
 
1228
+
 
1229
+       /* Select an alignment, if necessary */
 
1230
+       /* force compatibility with role/race/gender */
 
1231
+       if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace,
 
1232
+                                                       flags.initalign)) {
 
1233
+           /* pre-selected alignment not valid */
 
1234
+           if (pick4u == 'y' || flags.initalign == ROLE_RANDOM || flags.randomall) {
 
1235
+               flags.initalign = pick_align(flags.initrole, flags.initrace,
 
1236
+                                                       flags.initgend, PICK_RANDOM);
 
1237
+               if (flags.initalign < 0) {
 
1238
+/*                 lisp_putstr(BASE_WINDOW, 0, "Incompatible alignment!"); */
 
1239
+                   flags.initalign = randalign(flags.initrole, flags.initrace);
 
1240
+               }
 
1241
+           } else {    /* pick4u == 'n' */
 
1242
+               /* Count the number of valid alignments */
 
1243
+               n = 0;  /* number valid */
 
1244
+               k = 0;  /* valid alignment */
 
1245
+               for (i = 0; i < ROLE_ALIGNS; i++) {
 
1246
+                   if (ok_align(flags.initrole, flags.initrace, flags.initgend,
 
1247
+                                                       i)) {
 
1248
+                       n++;
 
1249
+                       k = i;
 
1250
+                   }
 
1251
+               }
 
1252
+               if (n == 0) {
 
1253
+                   for (i = 0; i < ROLE_ALIGNS; i++) {
 
1254
+                       if (validalign(flags.initrole, flags.initrace, i)) {
 
1255
+                           n++;
 
1256
+                           k = i;
 
1257
+                       }
 
1258
+                   }
 
1259
+               }
 
1260
+
 
1261
+               /* Permit the user to pick, if there is more than one */
 
1262
+               if (n > 1) {
 
1263
+                   win = create_nhwindow(NHW_MENU);
 
1264
+                   start_menu(win);
 
1265
+                   any.a_void = 0;         /* zero out all bits */
 
1266
+                   for (i = 0; i < ROLE_ALIGNS; i++)
 
1267
+                       if (ok_align(flags.initrole, flags.initrace,
 
1268
+                                                       flags.initgend, i)) {
 
1269
+                           any.a_int = i+1;
 
1270
+                           add_menu(win, NO_GLYPH, &any, aligns[i].adj[0],
 
1271
+                                0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED);
 
1272
+                       }
 
1273
+                   any.a_int = pick_align(flags.initrole, flags.initrace,
 
1274
+                                           flags.initgend, PICK_RANDOM)+1;
 
1275
+                   if (any.a_int == 0) /* must be non-zero */
 
1276
+                       any.a_int = randalign(flags.initrole, flags.initrace)+1;
 
1277
+                   add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
 
1278
+                                   "Random", MENU_UNSELECTED);
 
1279
+                   any.a_int = i+1;    /* must be non-zero */
 
1280
+                   add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
 
1281
+                                   "Quit", MENU_UNSELECTED);
 
1282
+                   Sprintf(pbuf, "Pick the alignment of your %s", plbuf);
 
1283
+                   end_menu(win, pbuf);
 
1284
+                   n = select_menu(win, PICK_ONE, &selected);
 
1285
+                   destroy_nhwindow(win);
 
1286
+                   if (n != 1 || selected[0].item.a_int == any.a_int)
 
1287
+                       goto give_up;           /* Selected quit */
 
1288
+
 
1289
+                   k = selected[0].item.a_int - 1;
 
1290
+                   free((genericptr_t) selected),      selected = 0;
 
1291
+               }
 
1292
+               flags.initalign = k;
 
1293
+           }
 
1294
+       }
 
1295
+       /* Success! */
 
1296
+/*     lisp_display_nhwindow(BASE_WINDOW, FALSE); */
 
1297
+}
 
1298
+
 
1299
+/* Reads from standard in, the player's name. */
 
1300
+void
 
1301
+lisp_askname ()
 
1302
+{
 
1303
+  char *line;
 
1304
+  lisp_cmd ("askname",);
 
1305
+  read_string ("string", &line);
 
1306
+  strncpy (plname, line, PL_NSIZ);
 
1307
+  plname[PL_NSIZ-1] = '\0';
 
1308
+  free (line);
 
1309
+}
 
1310
+
 
1311
+/* This is a noop for tty and X, so should it be a noop for us too? */
 
1312
+void
 
1313
+lisp_get_nh_event ()
 
1314
+{
 
1315
+/*   lisp_cmd ("get-event",); */
 
1316
+}
 
1317
+
 
1318
+/* Global Functions */
 
1319
+void
 
1320
+lisp_raw_print(str)
 
1321
+     const char *str;
 
1322
+{
 
1323
+  lisp_cmd ("raw-print", lisp_string (str));
 
1324
+}
 
1325
+
 
1326
+void
 
1327
+lisp_raw_print_bold(str)
 
1328
+     const char *str;
 
1329
+{
 
1330
+  lisp_cmd ("raw-print-bold", lisp_string (str));
 
1331
+}
 
1332
+
 
1333
+void
 
1334
+lisp_curs(window, x, y)
 
1335
+     winid window;
 
1336
+     int x, y;
 
1337
+{
 
1338
+  if (window == WIN_MAP)
 
1339
+    lisp_cmd ("curs",
 
1340
+             lisp_int (x);
 
1341
+             lisp_int (y));
 
1342
+  else if (window == WIN_STATUS)
 
1343
+    {
 
1344
+      /* do nothing */
 
1345
+    }
 
1346
+  else
 
1347
+    lisp_cmd ("error", lisp_string("lisp_curs bad window"); lisp_int (window));
 
1348
+}
 
1349
+
 
1350
+static void
 
1351
+generate_status_line ()
 
1352
+{
 
1353
+  /* Ripped from botl.c */
 
1354
+  int hp, hpmax;
 
1355
+
 
1356
+  hp = Upolyd ? u.mh : u.uhp;
 
1357
+  hpmax = Upolyd ? u.mhmax : u.uhpmax;
 
1358
+  if(hp < 0) hp = 0;
 
1359
+
 
1360
+  printf ("(nhapi-update-status ");
 
1361
+  lisp_quote;
 
1362
+  printf ("(");
 
1363
+  lisp_list (lisp_string ("name");
 
1364
+            lisp_string (plname););
 
1365
+  if (Upolyd) 
 
1366
+    {
 
1367
+      lisp_list (lisp_string ("rank");
 
1368
+                lisp_nil);
 
1369
+      lisp_list (lisp_string ("monster");
 
1370
+                lisp_string (mons[u.umonnum].mname));
 
1371
+    }
 
1372
+  else
 
1373
+    {
 
1374
+      lisp_list (lisp_string ("rank");
 
1375
+                lisp_string (rank_of(u.ulevel, Role_switch, flags.female)););;
 
1376
+      lisp_list (lisp_string ("monster");
 
1377
+                lisp_nil);
 
1378
+    }
 
1379
+
 
1380
+  lisp_list (lisp_string ("St");
 
1381
+            lisp_int (ACURR(A_STR)););
 
1382
+  lisp_list (lisp_string ("Dx");
 
1383
+            lisp_int (ACURR(A_DEX)););
 
1384
+  lisp_list (lisp_string ("Co");
 
1385
+            lisp_int (ACURR(A_CON)););
 
1386
+  lisp_list (lisp_string ("In");
 
1387
+            lisp_int (ACURR(A_INT)););
 
1388
+  lisp_list (lisp_string ("Wi");
 
1389
+            lisp_int (ACURR(A_WIS)););
 
1390
+  lisp_list (lisp_string ("Ch");
 
1391
+            lisp_int (ACURR(A_CHA)););
 
1392
+  lisp_list (lisp_string ("Align");
 
1393
+            if (u.ualign.type == A_CHAOTIC)
 
1394
+            lisp_string ("Chaotic");
 
1395
+            else if (u.ualign.type == A_NEUTRAL)
 
1396
+            lisp_string ("Neutral");
 
1397
+            else
 
1398
+            lisp_string ("Lawful"););
 
1399
+
 
1400
+#ifdef SCORE_ON_BOTL
 
1401
+  lisp_list (lisp_string ("Score");
 
1402
+            lisp_int (botl_score()););
 
1403
+#endif
 
1404
+
 
1405
+  if (In_endgame(&u.uz))
 
1406
+    {
 
1407
+      lisp_list (lisp_string ("Dungeon");
 
1408
+                if (Is_astralevel(&u.uz))
 
1409
+                lisp_string ("Astral Plane");
 
1410
+                else
 
1411
+                lisp_string ("End Game"););
 
1412
+    }
 
1413
+  else
 
1414
+    {
 
1415
+      lisp_list (lisp_string ("Dungeon");
 
1416
+                lisp_string (dungeons[u.uz.dnum].dname););
 
1417
+    }
 
1418
+
 
1419
+      lisp_list (lisp_string ("Dlvl");
 
1420
+                lisp_int (depth(&u.uz)););
 
1421
+
 
1422
+  lisp_list (lisp_string ("$");
 
1423
+            lisp_int (u.ugold););
 
1424
+  lisp_list (lisp_string ("HP");
 
1425
+            lisp_int (hp););
 
1426
+  lisp_list (lisp_string ("HPmax");
 
1427
+            lisp_int (hpmax););
 
1428
+  lisp_list (lisp_string ("PW");
 
1429
+            lisp_int (u.uen););
 
1430
+  lisp_list (lisp_string ("PWmax");
 
1431
+            lisp_int (u.uenmax););
 
1432
+  lisp_list (lisp_string ("AC");
 
1433
+            lisp_int (u.uac););
 
1434
+
 
1435
+  if (Upolyd)
 
1436
+    {
 
1437
+      lisp_list (lisp_string ("HD");
 
1438
+                lisp_int (mons[u.umonnum].mlevel););
 
1439
+    }
 
1440
+  else
 
1441
+    {
 
1442
+      lisp_list (lisp_string ("HD");
 
1443
+                lisp_nil);
 
1444
+    }
 
1445
+
 
1446
+  lisp_list (lisp_string ("Level");
 
1447
+            lisp_int (u.ulevel););
 
1448
+#ifdef EXP_ON_BOTL
 
1449
+  lisp_list (lisp_string ("XP");
 
1450
+            lisp_int (u.uexp););
 
1451
+#endif
 
1452
+  lisp_list (lisp_string ("T");
 
1453
+            lisp_int (moves););
 
1454
+
 
1455
+  if (Confusion)
 
1456
+    lisp_list (lisp_string ("confusion"); lisp_string ("Conf"));
 
1457
+  else
 
1458
+    lisp_list (lisp_string ("confusion"); lisp_nil);
 
1459
+
 
1460
+  if (u.uhs != 1)
 
1461
+    lisp_list (lisp_string ("hunger"); lisp_string (hunger_stat[u.uhs]));
 
1462
+  else
 
1463
+    lisp_list (lisp_string ("hunger"); lisp_nil);
 
1464
+
 
1465
+  if (Sick) 
 
1466
+    {
 
1467
+      if (u.usick_type & SICK_VOMITABLE)
 
1468
+       lisp_list (lisp_string ("sick"); lisp_string ("FoodPois"));
 
1469
+      if (u.usick_type & SICK_NONVOMITABLE)
 
1470
+       lisp_list (lisp_string ("sick"); lisp_string ("Ill"));
 
1471
+    }
 
1472
+  else
 
1473
+    lisp_list (lisp_string ("sick"); lisp_nil);
 
1474
+
 
1475
+  if (Blind)
 
1476
+    lisp_list (lisp_string ("blind"); lisp_string ("Blind"));
 
1477
+  else
 
1478
+    lisp_list (lisp_string ("blind"); lisp_nil);
 
1479
+
 
1480
+  if (Stunned)
 
1481
+    lisp_list (lisp_string ("stunned"); lisp_string ("Stun"));
 
1482
+  else
 
1483
+    lisp_list (lisp_string ("stunned"); lisp_nil);
 
1484
+
 
1485
+  if (Hallucination)
 
1486
+    lisp_list (lisp_string ("hallucination"); lisp_string ("Hallu"));
 
1487
+  else
 
1488
+    lisp_list (lisp_string ("hallucination"); lisp_nil);
 
1489
+
 
1490
+  if (Slimed)
 
1491
+    lisp_list (lisp_string ("slimed"); lisp_string ("Slime"));
 
1492
+  else
 
1493
+    lisp_list (lisp_string ("slimed"); lisp_nil);
 
1494
+
 
1495
+  if (near_capacity() > UNENCUMBERED)
 
1496
+    lisp_list (lisp_string ("encumbrance"); 
 
1497
+              lisp_string (enc_stat[near_capacity()]));
 
1498
+  else
 
1499
+    lisp_list (lisp_string ("encumbrance"); lisp_nil);
 
1500
+
 
1501
+  printf (" ))\n");
 
1502
+}
 
1503
+
 
1504
+void
 
1505
+lisp_putstr(window, attr, str)
 
1506
+     winid window;
 
1507
+     int attr;
 
1508
+     const char *str;
 
1509
+{
 
1510
+  static char statline1[BUFSZ] = "";
 
1511
+  if (window == WIN_STATUS)
 
1512
+    {
 
1513
+      if (statline1[0]=='\0')
 
1514
+       Strcpy (statline1, str);
 
1515
+      else
 
1516
+       {
 
1517
+         generate_status_line ();
 
1518
+         statline1[0]='\0';
 
1519
+       }
 
1520
+    }
 
1521
+  else if (window == WIN_MESSAGE)
 
1522
+    lisp_cmd ("message", 
 
1523
+             lisp_literal (attr_to_string (attr));
 
1524
+             lisp_string (str));
 
1525
+  else
 
1526
+    lisp_cmd ("menu-putstr",
 
1527
+             lisp_int (window);
 
1528
+             lisp_literal (attr_to_string (attr));
 
1529
+             lisp_string (str));
 
1530
+}
 
1531
+
 
1532
+void
 
1533
+lisp_start_menu(window)
 
1534
+     winid window;
 
1535
+{
 
1536
+  lisp_menu_list_num = 0;
 
1537
+  lisp_current_accelerator = 'a';
 
1538
+  lisp_cmd ("start-menu", lisp_int (window));
 
1539
+}
 
1540
+
 
1541
+void
 
1542
+lisp_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected)
 
1543
+    winid window;              /* window to use, must be of type NHW_MENU */
 
1544
+    int glyph;                 /* glyph to display with item (unused) */
 
1545
+    const anything *identifier;        /* what to return if selected */
 
1546
+    char ch;                   /* keyboard accelerator (0 = pick our own) */
 
1547
+    char gch;                  /* group accelerator (0 = no group) */
 
1548
+    int attr;                  /* attribute for string (like tty_putstr()) */
 
1549
+    const char *str;           /* menu string */
 
1550
+    boolean preselected;       /* item is marked as selected */
 
1551
+{
 
1552
+  if (identifier->a_void)
 
1553
+    {
 
1554
+      lisp_menu_item_list[lisp_menu_list_num].identifier = *identifier;
 
1555
+      if (ch == 0)
 
1556
+       {
 
1557
+         ch = lisp_menu_item_list[lisp_menu_list_num].accelerator = lisp_current_accelerator;
 
1558
+         if (lisp_current_accelerator == 'z')
 
1559
+           lisp_current_accelerator = 'A';
 
1560
+         else
 
1561
+           lisp_current_accelerator++;
 
1562
+       }      
 
1563
+      else
 
1564
+       lisp_menu_item_list[lisp_menu_list_num].accelerator = ch;
 
1565
+
 
1566
+      lisp_menu_list_num++;
 
1567
+    }
 
1568
+  else
 
1569
+    ch = -1;
 
1570
+
 
1571
+  lisp_cmd ("add-menu",
 
1572
+           lisp_int (window);
 
1573
+           lisp_int (glyph);
 
1574
+           lisp_int (glyph2tile[glyph]);
 
1575
+           lisp_int (ch);
 
1576
+           lisp_int (gch);
 
1577
+           lisp_literal (attr_to_string (attr));
 
1578
+           lisp_string (str);
 
1579
+           preselected ? lisp_t : lisp_nil);
 
1580
+}
 
1581
+
 
1582
+void
 
1583
+lisp_end_menu(window, prompt)
 
1584
+    winid window;      /* menu to use */
 
1585
+    const char *prompt;        /* prompt to for menu */
 
1586
+{
 
1587
+  lisp_cmd ("end-menu",
 
1588
+           lisp_int (window);
 
1589
+           lisp_string (prompt));
 
1590
+}
 
1591
+
 
1592
+static int
 
1593
+lisp_get_menu_identifier(ch, identifier)
 
1594
+     char ch;
 
1595
+     anything *identifier;
 
1596
+{
 
1597
+  int i;
 
1598
+
 
1599
+  for(i=0; i < lisp_menu_list_num; i++)
 
1600
+    {
 
1601
+      if( lisp_menu_item_list[i].accelerator == ch )
 
1602
+       {
 
1603
+         *identifier = lisp_menu_item_list[i].identifier;
 
1604
+         return 1;
 
1605
+       }
 
1606
+    }
 
1607
+
 
1608
+  return 0;
 
1609
+}
 
1610
+
 
1611
+int
 
1612
+lisp_select_menu(window, how, menu_list)
 
1613
+    winid window;
 
1614
+    int how;
 
1615
+    menu_item **menu_list;
 
1616
+{
 
1617
+  const char *delim = "() \n";
 
1618
+  char *list;
 
1619
+  char *token;
 
1620
+  int size = 0;
 
1621
+
 
1622
+  lisp_cmd ("select-menu",
 
1623
+           lisp_int (window);
 
1624
+           lisp_literal (how_to_string (how)));
 
1625
+
 
1626
+  read_string ("menu", &list);
 
1627
+
 
1628
+/*   lisp_prompt ("menu"); */
 
1629
+/*   fgets (list, LINESIZ, stdin); */
 
1630
+
 
1631
+  /* The client should submit a structure like this:
 
1632
+
 
1633
+   ((ch count) (ch count) (ch count) ...) 
 
1634
+
 
1635
+   where ch is the accelerator for the menu item and count is the
 
1636
+   number of them to select.
 
1637
+   
 
1638
+   We strtok it so we just get id count id count id count. */
 
1639
+
 
1640
+  token = strtok (list, delim);
 
1641
+
 
1642
+  /* Start with some memory so realloc doesn't fail. */
 
1643
+  *menu_list = malloc (sizeof (menu_item));
 
1644
+  if (*menu_list == NULL)
 
1645
+    {
 
1646
+      panic ("Memory allocation failure; cannot get %u bytes", 
 
1647
+            sizeof (menu_item));
 
1648
+    }
 
1649
+  size = 0;
 
1650
+
 
1651
+  while (token != NULL)
 
1652
+    {
 
1653
+      /* Make more room in the array for the new item */
 
1654
+      size++;
 
1655
+      if ((*menu_list = realloc (*menu_list, size * sizeof (menu_item))) == NULL)
 
1656
+       {
 
1657
+         panic ("Memory allocation failure; cannot get %u bytes", 
 
1658
+                size * sizeof (menu_item));
 
1659
+       }
 
1660
+
 
1661
+      /* assign the item ID */
 
1662
+      lisp_get_menu_identifier (atoi (token), &(*menu_list)[size-1].item );
 
1663
+
 
1664
+      /* Read the item count */
 
1665
+      token = strtok (NULL, delim);
 
1666
+      (*menu_list)[size-1].count = atoi (token);
 
1667
+
 
1668
+      /* read the next item ID */
 
1669
+      token = strtok (NULL, delim);
 
1670
+    }
 
1671
+
 
1672
+  free (list);
 
1673
+
 
1674
+  return size;
 
1675
+}
 
1676
+
 
1677
+/* This is a tty-specific hack. Do we need it? */
 
1678
+char
 
1679
+lisp_message_menu(let, how, mesg)
 
1680
+     char let;
 
1681
+     int how;
 
1682
+     const char *mesg;
 
1683
+{
 
1684
+  lisp_cmd ("message-menu",
 
1685
+           lisp_int (let);
 
1686
+           lisp_literal (how_to_string (how));
 
1687
+           lisp_string (mesg));
 
1688
+  return '\0';
 
1689
+}
 
1690
+
 
1691
+static int
 
1692
+lisp_get_cmd(str)
 
1693
+     const char *str;
 
1694
+{
 
1695
+  int i;
 
1696
+
 
1697
+  for (i=0; cmd_index[i].name != (char *)0; i++)
 
1698
+    {
 
1699
+      if (!strcmp (str, cmd_index[i].name)) 
 
1700
+       return i;
 
1701
+    }    
 
1702
+
 
1703
+  return -1;
 
1704
+}
 
1705
+
 
1706
+static int
 
1707
+lisp_get_ext_cmd_id (str)
 
1708
+     const char *str;
 
1709
+{
 
1710
+  int i;
 
1711
+
 
1712
+  for (i=0; extcmdlist[i].ef_txt != (char *)0; i++) {
 
1713
+    if (!strcmp (str, extcmdlist[i].ef_txt)) return i;
 
1714
+  }
 
1715
+  
 
1716
+  return -1;
 
1717
+}
 
1718
+
 
1719
+/* static int */
 
1720
+/* num_digits(n) */
 
1721
+/*      int n; */
 
1722
+/* { */
 
1723
+/*   int i; */
 
1724
+/*   int ret = 1; */
 
1725
+  
 
1726
+/*   for (i=10;n / i; i *= 10) */
 
1727
+/*     { */
 
1728
+/*       ret++; */
 
1729
+/*     } */
 
1730
+
 
1731
+/*   return ret; */
 
1732
+/* } */
 
1733
+
 
1734
+/* static */
 
1735
+/* int */
 
1736
+/* power_of_ten (n) */
 
1737
+/*      int n; */
 
1738
+/* { */
 
1739
+/*   int i; */
 
1740
+/*   int power = 1; */
 
1741
+
 
1742
+/*   for (i=0; i<n; i++) */
 
1743
+/*     { */
 
1744
+/*       power *= 10; */
 
1745
+/*     } */
 
1746
+
 
1747
+/*   return power; */
 
1748
+/* } */
 
1749
+
 
1750
+int
 
1751
+lisp_nhgetch()
 
1752
+{
 
1753
+  /* multi is not 0 if this  */
 
1754
+  static char count_buf[BUFSIZ] = "";
 
1755
+  static char *count_pos = count_buf;
 
1756
+  static int count_cmd = -1;
 
1757
+  int cmd;
 
1758
+
 
1759
+  if (*count_pos)
 
1760
+    {
 
1761
+      char *tmp = count_pos;
 
1762
+      count_pos++;
 
1763
+      return *tmp;
 
1764
+    }
 
1765
+
 
1766
+  if (count_cmd >= 0)
 
1767
+    {
 
1768
+      cmd = count_cmd;
 
1769
+      count_cmd = -1;
 
1770
+    }
 
1771
+  else
 
1772
+    {
 
1773
+      char cmdstr[BUFSZ];
 
1774
+
 
1775
+      read_command ("command", cmdstr, count_buf);
 
1776
+
 
1777
+      count_pos = count_buf;
 
1778
+      cmd = lisp_get_cmd (cmdstr);
 
1779
+      if (cmd == -1)
 
1780
+       {
 
1781
+         printf ("(nhapi-message 'atr-none \"undefined-command %s\")\n", cmdstr);
 
1782
+         cmd = lisp_get_cmd ("null");
 
1783
+       }
 
1784
+
 
1785
+      if (atoi (count_pos) > 1)
 
1786
+       {
 
1787
+         char* tmp = count_pos;
 
1788
+         count_pos++;
 
1789
+         count_cmd = cmd;
 
1790
+         return *tmp;
 
1791
+       }
 
1792
+      else
 
1793
+       {
 
1794
+         /* Since the count is 1, zero out the string. */
 
1795
+         *count_pos = 0;
 
1796
+       }
 
1797
+    }
 
1798
+
 
1799
+  if (cmd_index[cmd].type == CMD_KEY)
 
1800
+    {
 
1801
+      return cmd_index[cmd].cmd;
 
1802
+    }
 
1803
+  else
 
1804
+    {
 
1805
+      if ((extended_cmd_id = lisp_get_ext_cmd_id (cmd_index[cmd].name)) == -1)
 
1806
+       {
 
1807
+         /* Can never happen. */
 
1808
+         printf ("%s:%d: Bad extended command name\n", __FILE__,  __LINE__);
 
1809
+       }
 
1810
+      return '#';
 
1811
+    }
 
1812
+}
 
1813
+
 
1814
+int
 
1815
+lisp_nh_poskey(x, y, mod)
 
1816
+     int *x, *y, *mod;
 
1817
+{
 
1818
+/*    char scratch[256]; */
 
1819
+
 
1820
+/*    printf ("(nethack-api-poskey)\n"); */
 
1821
+
 
1822
+/*    scanf ("( %d %d '%255s )", x, y, scratch); */
 
1823
+/*    if (!strcmp (scratch, "click-1")) *mod = CLICK_1; */
 
1824
+/*    else *mod = CLICK_2; */
 
1825
+
 
1826
+/*    return 0; */
 
1827
+
 
1828
+  return lisp_nhgetch();
 
1829
+}
 
1830
+
 
1831
+static boolean inven_win_created = FALSE;
 
1832
+
 
1833
+/* These globals are used to keep track of window IDs. */
 
1834
+static winid *winid_list = NULL;
 
1835
+static int winid_list_len = 0;
 
1836
+static int winid_list_max = 0;
 
1837
+
 
1838
+/* returns index into winid_list that can be used. */
 
1839
+static int
 
1840
+find_empty_cell ()
 
1841
+{
 
1842
+  int i;
 
1843
+
 
1844
+  /* Check for a vacant spot in the list. */
 
1845
+  for (i=0; i<winid_list_len; i++)
 
1846
+    {
 
1847
+      if (winid_list[i] == -1) return i;
 
1848
+    }
 
1849
+
 
1850
+  /* no vacant ones, so grow the array. */
 
1851
+  if (winid_list_len >= winid_list_max)
 
1852
+    {
 
1853
+      winid_list_max *= 2;
 
1854
+      winid_list = realloc (winid_list, sizeof (int) * winid_list_max);
 
1855
+      if (winid_list == NULL)
 
1856
+       bail ("Out of memory\n");
 
1857
+    }
 
1858
+  winid_list_len++;
 
1859
+
 
1860
+  return winid_list_len-1;
 
1861
+}
 
1862
+
 
1863
+static int
 
1864
+winid_is_taken (winid n)
 
1865
+{
 
1866
+  int i;
 
1867
+
 
1868
+  for (i=0; i<winid_list_len; i++)
 
1869
+    if (winid_list[i] == n) return 1;
 
1870
+  
 
1871
+  return 0;
 
1872
+}
 
1873
+
 
1874
+static int
 
1875
+add_winid (winid n)
 
1876
+{
 
1877
+  if (winid_is_taken (n)) return 0; /* failed. */
 
1878
+  
 
1879
+  winid_list[find_empty_cell()] = n;
 
1880
+  return 1; /* success! */
 
1881
+}
 
1882
+
 
1883
+static winid
 
1884
+get_unique_winid ()
 
1885
+{
 
1886
+  winid i;
 
1887
+  
 
1888
+  /* look for a unique number, and add it to the list of taken
 
1889
+     numbers. */
 
1890
+  i = 0;
 
1891
+  while (!add_winid (i)) i++;
 
1892
+
 
1893
+  return i;      
 
1894
+}
 
1895
+
 
1896
+/* When a window is destroyed, it gives back its window number with
 
1897
+   this function. */
 
1898
+static void
 
1899
+return_winid (winid n)
 
1900
+{
 
1901
+  int i;
 
1902
+
 
1903
+  for (i=0; i<winid_list_len; i++)
 
1904
+    {
 
1905
+      if (winid_list[i] == n) 
 
1906
+       {
 
1907
+         winid_list[i] = -1;
 
1908
+         return;
 
1909
+       }
 
1910
+    }
 
1911
+}
 
1912
+
 
1913
+static void
 
1914
+init_winid_list ()
 
1915
+{
 
1916
+  winid_list_max = 10;
 
1917
+  winid_list_len = 0;
 
1918
+
 
1919
+  winid_list = malloc (winid_list_max * sizeof (int));
 
1920
+}
 
1921
+
 
1922
+/* Prints a create_nhwindow function and expects from stdin the id of
 
1923
+   this new window as a number. */
 
1924
+winid
 
1925
+lisp_create_nhwindow(type)
 
1926
+     int type;
 
1927
+{
 
1928
+  winid id = get_unique_winid();
 
1929
+
 
1930
+  switch (type)
 
1931
+    {
 
1932
+    case NHW_MESSAGE:
 
1933
+      lisp_cmd ("create-message-window",);
 
1934
+      break;
 
1935
+    case NHW_MAP:
 
1936
+      lisp_cmd ("create-map-window",);
 
1937
+      break;
 
1938
+    case NHW_STATUS:
 
1939
+      lisp_cmd ("create-status-window",);
 
1940
+      break;
 
1941
+    case NHW_TEXT:
 
1942
+      lisp_cmd ("create-text-window", lisp_int (id));
 
1943
+      break;
 
1944
+    case NHW_MENU:
 
1945
+      if (!inven_win_created)
 
1946
+       {
 
1947
+         lisp_cmd ("create-inventory-window", lisp_int (id));
 
1948
+         inven_win_created = TRUE;
 
1949
+       }
 
1950
+      else
 
1951
+       lisp_cmd ("create-menu-window", lisp_int (id));
 
1952
+      break;
 
1953
+    default:
 
1954
+      impossible ("Unknown window type: %d", type);
 
1955
+    };
 
1956
+
 
1957
+  return id;
 
1958
+}
 
1959
+
 
1960
+void
 
1961
+lisp_clear_nhwindow(window)
 
1962
+     winid window;
 
1963
+{
 
1964
+  if (window == WIN_MESSAGE)
 
1965
+    lisp_cmd ("clear-message",);
 
1966
+  else if (window == WIN_MAP)
 
1967
+    lisp_cmd ("clear-map",);
 
1968
+  else
 
1969
+    /* are other window types ever cleared? */
 
1970
+    lisp_cmd ("error", lisp_string("clearing unknown winid"));
 
1971
+}
 
1972
+
 
1973
+void
 
1974
+lisp_display_nhwindow(window, blocking)
 
1975
+     winid window;
 
1976
+     boolean blocking;
 
1977
+{
 
1978
+  /* don't send display messages for anything but menus */
 
1979
+  char *dummy;
 
1980
+  if (window != WIN_MESSAGE && window != WIN_STATUS && window != WIN_MAP)
 
1981
+    {
 
1982
+      lisp_cmd ("display-menu", lisp_int (window));
 
1983
+      read_string ("menu", &dummy);
 
1984
+      free (dummy);
 
1985
+    }
 
1986
+  else if (blocking)
 
1987
+    {
 
1988
+      if (window == WIN_MESSAGE)
 
1989
+       {
 
1990
+         /* blocking on the message window happens only at the end of
 
1991
+            the game */
 
1992
+         lisp_cmd ("end",);
 
1993
+       }
 
1994
+      else
 
1995
+       {
 
1996
+         lisp_cmd ("block",);
 
1997
+         read_string ("dummy", &dummy);
 
1998
+         free (dummy);
 
1999
+       }
 
2000
+    }
 
2001
+  else if (window == WIN_STATUS)
 
2002
+    {
 
2003
+      /* initial window setup hack here :) */
 
2004
+      lisp_cmd ("restore-window-configuration",);
 
2005
+    }
 
2006
+}
 
2007
+
 
2008
+void
 
2009
+lisp_destroy_nhwindow(window)
 
2010
+     winid window;
 
2011
+{
 
2012
+  if ((window != WIN_STATUS)
 
2013
+      && (window != WIN_MESSAGE)
 
2014
+      && (window != WIN_MAP))
 
2015
+    {
 
2016
+      lisp_cmd ("destroy-menu", lisp_int (window));
 
2017
+      return_winid (window);
 
2018
+    }
 
2019
+}
 
2020
+
 
2021
+void
 
2022
+lisp_update_inventory()
 
2023
+{
 
2024
+  lisp_cmd ("update-inventory",);
 
2025
+}
 
2026
+
 
2027
+int
 
2028
+lisp_doprev_message()
 
2029
+{
 
2030
+  lisp_cmd ("doprev-message",);
 
2031
+  return 0;
 
2032
+}
 
2033
+
 
2034
+void
 
2035
+lisp_nhbell()
 
2036
+{
 
2037
+  lisp_cmd ("nhbell",);
 
2038
+}
 
2039
+
 
2040
+/* Can be an empty call says window.doc. */
 
2041
+void
 
2042
+lisp_mark_synch()
 
2043
+{
 
2044
+  /* lisp_cmd ("mark-sync",); */
 
2045
+}
 
2046
+
 
2047
+void
 
2048
+lisp_wait_synch()
 
2049
+{
 
2050
+  lisp_cmd ("wait-synch",);
 
2051
+}
 
2052
+
 
2053
+/* Since nethack will never be suspended, we need not worry about this
 
2054
+   function. */
 
2055
+void
 
2056
+lisp_resume_nhwindows()
 
2057
+{
 
2058
+  return;
 
2059
+}
 
2060
+
 
2061
+/* Since nethack will never be suspended, we need not worry about this
 
2062
+   function. */
 
2063
+void
 
2064
+lisp_suspend_nhwindows(str)
 
2065
+     const char *str;
 
2066
+{
 
2067
+  return;
 
2068
+}
 
2069
+
 
2070
+/* All keys are defined in emacs, so number_pad makes no sense. */
 
2071
+void
 
2072
+lisp_number_pad(state)
 
2073
+     int state;
 
2074
+{
 
2075
+  return;
 
2076
+}
 
2077
+
 
2078
+void
 
2079
+lisp_init_nhwindows(argcp,argv)
 
2080
+     int* argcp;
 
2081
+     char** argv;
 
2082
+{
 
2083
+  int i;
 
2084
+
 
2085
+  /* Print each command-line option, constructing a list of strings */
 
2086
+  lisp_cmd ("init-nhwindows",
 
2087
+           for (i=0; i<*argcp; i++) 
 
2088
+             lisp_string (argv[i]));
 
2089
+
 
2090
+  /* FIXME: doesn't remove the arguments parsed, as specified in the
 
2091
+     api doc. */
 
2092
+
 
2093
+  /* Setup certain flags lisp clients need */
 
2094
+  iflags.num_pad = FALSE;
 
2095
+#ifdef EXP_ON_BOTL             /* we are going to lose if Nethack is
 
2096
+                                  compiled without this option -rcy */
 
2097
+  flags.showexp = TRUE;
 
2098
+#endif
 
2099
+  flags.time = TRUE;
 
2100
+
 
2101
+  /* inform nethack that the windows have been initialized. */
 
2102
+  iflags.window_inited = TRUE;
 
2103
+
 
2104
+  init_winid_list();
 
2105
+}
 
2106
+
 
2107
+void
 
2108
+lisp_exit_nhwindows (str)
 
2109
+     const char *str;
 
2110
+{
 
2111
+  lisp_cmd ("exit-nhwindows ", lisp_string (str));
 
2112
+}
 
2113
+
 
2114
+void
 
2115
+lisp_delay_output()
 
2116
+{
 
2117
+  char *dummy;
 
2118
+  lisp_cmd ("delay-output",);
 
2119
+  read_string ("dummy", &dummy);
 
2120
+  free (dummy);
 
2121
+}
 
2122
+
 
2123
+void
 
2124
+lisp_getlin(question, input)
 
2125
+     const char *question;
 
2126
+     char *input;
 
2127
+{
 
2128
+  char *tmp;
 
2129
+  lisp_cmd ("getlin", lisp_string (question));
 
2130
+  read_string ("string", &tmp);
 
2131
+  /* FIXME: potential buffer overflow. */
 
2132
+  strcpy (input, tmp);
 
2133
+}
 
2134
+
 
2135
+int
 
2136
+lisp_get_ext_cmd()
 
2137
+{
 
2138
+/*    int cmd; */
 
2139
+/*    int i; */
 
2140
+
 
2141
+/*    printf ("(nethack-api-get-ext-cmd '("); */
 
2142
+
 
2143
+/*    for (i=0; extcmdlist[i].ef_txt != (char *)0; i++) { */
 
2144
+/*      printf ("(\"%s\" . %d)", extcmdlist[i].ef_txt, i); */
 
2145
+/*    } */
 
2146
+/*    printf ("))\n"); */
 
2147
+
 
2148
+/*    scanf ("%d", &cmd); */
 
2149
+
 
2150
+  /* This is set when the user chooses an extended command. */
 
2151
+  return extended_cmd_id;
 
2152
+}
 
2153
+
 
2154
+void
 
2155
+lisp_display_file(str, complain)
 
2156
+     const char *str;
 
2157
+     boolean complain;
 
2158
+{
 
2159
+  lisp_cmd ("display-file",
 
2160
+           lisp_string (str);
 
2161
+           complain ? lisp_t : lisp_nil);;
 
2162
+}
 
2163
+
 
2164
+char
 
2165
+lisp_yn_function(ques, choices, def)
 
2166
+     const char *ques;
 
2167
+     const char *choices;
 
2168
+     char def;
 
2169
+{
 
2170
+  int answer;
 
2171
+
 
2172
+  /* Some questions have special functions. */
 
2173
+  if (!strncmp (ques, "In what direction", 17))
 
2174
+    {
 
2175
+      char *dir;
 
2176
+      lisp_cmd ("ask-direction",
 
2177
+               lisp_string (ques));
 
2178
+      read_string ("direction", &dir);
 
2179
+      if (!strcmp (dir, "n"))
 
2180
+       answer = 'k';
 
2181
+      else if (!strcmp (dir, "s"))
 
2182
+       answer = 'j';
 
2183
+      else if (!strcmp (dir, "e"))
 
2184
+       answer = 'l';
 
2185
+      else if (!strcmp (dir, "w"))
 
2186
+       answer = 'h';
 
2187
+      else if (!strcmp (dir, "ne"))
 
2188
+       answer = 'u';
 
2189
+      else if (!strcmp (dir, "nw"))
 
2190
+       answer = 'y';
 
2191
+      else if (!strcmp (dir, "se"))
 
2192
+       answer = 'n';
 
2193
+      else if (!strcmp (dir, "sw"))
 
2194
+       answer = 'b';
 
2195
+      else if (!strcmp (dir, "up"))
 
2196
+       answer = '<';
 
2197
+      else if (!strcmp (dir, "down"))
 
2198
+       answer = '>';
 
2199
+      else if (!strcmp (dir, "self"))
 
2200
+       answer = '.';
 
2201
+      else
 
2202
+       {
 
2203
+         if (def == '\0')
 
2204
+           answer = 0x20;              /* space */
 
2205
+         else
 
2206
+           answer = def;
 
2207
+       }
 
2208
+
 
2209
+      free (dir);
 
2210
+    }
 
2211
+  else
 
2212
+    {
 
2213
+      lisp_cmd ("yn-function",
 
2214
+               lisp_string (ques);
 
2215
+               lisp_string (choices);
 
2216
+               lisp_int (def));
 
2217
+      read_int ("number", &answer);
 
2218
+    }
 
2219
+
 
2220
+  return (char)answer;
 
2221
+}
 
2222
+
 
2223
+#ifdef POSITIONBAR
 
2224
+void
 
2225
+lisp_update_positionbar(features)
 
2226
+     char *features;
 
2227
+{
 
2228
+  lisp_cmd ("update-positionbar", lisp_string (features));
 
2229
+}
 
2230
+#endif
 
2231
+
 
2232
+#define zap_color(n)  zapcolors[n]
 
2233
+#define cmap_color(n) defsyms[n].color
 
2234
+#define obj_color(n)  objects[n].oc_color
 
2235
+#define mon_color(n)  mons[n].mcolor
 
2236
+#define invis_color(n) NO_COLOR
 
2237
+#define pet_color(n)  mons[n].mcolor
 
2238
+#define warn_color(n) def_warnsyms[n].color
 
2239
+
 
2240
+void
 
2241
+lisp_print_glyph(window, x, y, glyph)
 
2242
+    winid window;
 
2243
+    xchar x, y;
 
2244
+    int glyph;
 
2245
+{
 
2246
+    int ch;
 
2247
+    int            color;
 
2248
+    unsigned special;
 
2249
+
 
2250
+    /* map glyph to character and color */
 
2251
+    mapglyph(glyph, &ch, &color, &special, x, y);
 
2252
+
 
2253
+    /* If the user doesn't want to highlight the pet, then we erase
 
2254
+       the PET bit from special. In the lisp code the special argument
 
2255
+       will be 'pet if the glyph is a pet and will be printed in the
 
2256
+       color of the pet highlight face. But we don't want this if the
 
2257
+       user hasn't turned on hilite_pet. */
 
2258
+    if (!iflags.hilite_pet)
 
2259
+      {
 
2260
+       special &= ~MG_PET;
 
2261
+      }
 
2262
+
 
2263
+    if (window == WIN_MAP)
 
2264
+      {
 
2265
+       /* The last parameter, special, is optional. It is only
 
2266
+          present when the tile is special in some way. FIXME: This
 
2267
+          duplicate code is a bit gross. */
 
2268
+       if (special)
 
2269
+         {
 
2270
+           lisp_cmd ("print-glyph",
 
2271
+                     lisp_int (x);
 
2272
+                     lisp_int (y);
 
2273
+                     lisp_int (color);
 
2274
+                     lisp_int (glyph);
 
2275
+                     lisp_int (glyph2tile[glyph]);
 
2276
+                     lisp_int (ch);
 
2277
+                     lisp_literal (special_glyph_to_string (special)););
 
2278
+         }
 
2279
+       else
 
2280
+         {
 
2281
+           lisp_cmd ("print-glyph",
 
2282
+                     lisp_int (x);
 
2283
+                     lisp_int (y);
 
2284
+                     lisp_int (color);
 
2285
+                     lisp_int (glyph);
 
2286
+                     lisp_int (glyph2tile[glyph]);
 
2287
+                     lisp_int (ch););
 
2288
+         }
 
2289
+      }
 
2290
+    else
 
2291
+      lisp_cmd ("error",
 
2292
+               lisp_string ("lisp_print_glyph bad window");
 
2293
+               lisp_int (window));
 
2294
+}
 
2295
+
 
2296
+#ifdef CLIPPING
 
2297
+void
 
2298
+lisp_cliparound(x, y)
 
2299
+     int x;
 
2300
+     int y;
 
2301
+{
 
2302
+  /* as far as I can tell, the x and y values here are exactly the
 
2303
+     ones given by the next lisp_curs call, so its redundant
 
2304
+     information -rcy */
 
2305
+
 
2306
+  /*   lisp_cmd ("cliparound", lisp_int (x); lisp_int (y)); */
 
2307
+}
 
2308
+#endif
 
2309
+
 
2310
+void lisp_start_screen() { return; } /* called from setftty() in unixtty.c */
 
2311
+void lisp_end_screen() {return; }    /* called from settty() in unixtty.c */
 
2312
+
 
2313
+static void
 
2314
+get_death_text (buf)
 
2315
+     char buf[BUFSZ];
 
2316
+{
 
2317
+  
 
2318
+}
 
2319
+
 
2320
+void
 
2321
+lisp_outrip(window, how)
 
2322
+     winid window;
 
2323
+     int how;
 
2324
+{
 
2325
+  lisp_cmd ("outrip",
 
2326
+           lisp_int (window);      
 
2327
+           lisp_string (plname);
 
2328
+           lisp_int (u.ugold);
 
2329
+           lisp_string ("Died while trying to finish nethack-el."));
 
2330
+}