2
## 12_lisp_windowing.dpatch by Ben Gertzfield <che@debian.org>
4
## All lines beginning with `## DP:' are a description of the patch.
5
## DP: Add LISP-based windowing system
8
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
12
-patch) patch -f --no-backup-if-mismatch -p1 < $0;;
13
-unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
15
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
21
Redistribution and use in source and binary forms, with or without modification, are permitted
22
provided that the following conditions are met:
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.
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
50
+#if defined(BOS) || defined(NHSTDC)
51
+#define DIMENSION_P int
53
+# ifdef WIDENED_PROTOTYPES
54
+#define DIMENSION_P unsigned int
56
+#define DIMENSION_P Dimension
60
+extern struct window_procs tty_procs;
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);
88
+E void FDECL(lisp_cliparound, (int, int));
91
+E void FDECL(lisp_update_positionbar, (char *));
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);
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);
110
+E void FDECL(lisp_outrip, (winid,int));
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
116
#ifdef MSWIN_GRAPHICS
117
extern struct window_procs mswin_procs;
119
+#ifdef LISP_GRAPHICS
120
+#include "winlisp.h"
121
+extern struct window_procs lisp_procs;
124
STATIC_DCL void FDECL(def_raw_print, (const char *s));
127
#ifdef MSWIN_GRAPHICS
130
+#ifdef LISP_GRAPHICS
131
+ { &lisp_procs, win_lisp_init },
133
{ 0, 0 } /* must be last */
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;
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;
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
153
+2003-06-03 Shawn Betts <sabetts@sfu.ca>
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
160
+2003-05-14 Shawn Betts <sabetts@sfu.ca>
162
+ * winlisp.c (lisp_string): Also escape the backslash character.
164
+2002-09-19 Ryan Yeske <rcyeske@vcn.bc.ca>
166
+ * winlisp.c (lisp_cmd): nethack-api-* renamed to nhapi-*.
168
+2002-09-16 Ryan Yeske <rcyeske@vcn.bc.ca>
170
+ * ../tty/termcap.c (has_color): Add condition for LISP_GRAPHICS
171
+ which returns TRUE.
173
+2002-09-12 Ryan Yeske <rcyeske@vcn.bc.ca>
175
+ * winlisp.c (lisp_display_nhwindow): Add call to
178
+ * ../../include/config.h: Default to LISP_GRAPHICS.
180
+ * ../../sys/unix/Makefile.src (WINSRC,WINOBJ,WINLIB): Set to
182
+ (depend): Add winlisp.o dependancies.
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
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
197
+ (lisp_print_glyph): Don't send winid. Add error check for bad
199
+ (lisp_outrip): Change reference to Enethack to nethack-el.
201
+2002-04-23 Shawn <sabetts@vcn.bc.ca>
203
+ * winlisp.c (lisp_player_selection): Update to use new 3.4.0
205
+ (lisp_print_glyph): likewise
207
+2002-02-16 Shawn Betts <sabetts@vcn.bc.ca>
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
218
+2002-02-14 Shawn Betts <sabetts@vcn.bc.ca>
220
+ * winlisp.c (lisp_print_glyph): Handle warning glyphs.
222
+2002-01-27 Ryan C Yeske <rcyeske@vcn.bc.ca>
224
+ * winlisp.c (generate_status_line): Send flag values
225
+ individually. Always send values for all attributes.
227
+2002-01-21 Ryan C Yeske <rcyeske@vcn.bc.ca>
229
+ * winlisp.c (lisp_add_menu): Add tile argument.
231
+2002-01-22 shawn <sabetts@vcn.bc.ca>
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
241
+ (lisp_get_menu_identifier): first argument is now a char.
243
+2002-01-20 Ryan C Yeske <rcyeske@vcn.bc.ca>
245
+ * winlisp.c (cmd_index): Add remaining functions.
247
+2002-01-16 Ryan C Yeske <rcyeske@vcn.bc.ca>
249
+ * winlisp.c (lisp_exit_nhwindows): Don't wait for a dummy return
251
+ (lisp_destroy_nhwindow): Don't destroy the status, message or map
254
+2002-01-15 Ryan C Yeske <rcyeske@vcn.bc.ca>
256
+ * winlisp.c (lisp_exit_nhwindows): Don't wait for a dummy return
259
+2002-01-10 shawn <sabetts@vcn.bc.ca>
261
+ * winlisp.c (win_lisp_init): new function
263
+2002-01-09 Ryan C Yeske <rcyeske@sfu.ca>
265
+ * winlisp.c (cmd_index): Add redraw command.
268
+2002-01-01 shawn <sabetts@vcn.bc.ca>
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
280
+2001-12-20 shawn <sabetts@vcn.bc.ca>
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
292
+2001-12-19 shawn <sabetts@vcn.bc.ca>
294
+ * winlisp.c: add extern declaration for glyph2tile and
296
+ (lisp_print_glyph): pass the glyph's graphics tile index as an argument.
298
+2001-12-02 Ryan Yeske <rcyeske@vcn.bc.ca>
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.
308
+2001-10-23 Ryan Yeske <rcyeske@vcn.bc.ca>
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.
317
+2001-10-19 shawn <sabetts@vcn.bc.ca>
319
+ * winlisp.c (lisp_init_nhwindows): turn on showexp and time flags.
321
+2001-10-17 Ryan Yeske <rcyeske@vcn.bc.ca>
323
+ * winlisp.c (lisp_display_nhwindow): Wait for a string if we are
326
+2001-07-19 shawn <sabetts@diggin.lamenet.tmp>
328
+ * winlisp.c (lisp_player_selection): terminate if we read a -1 as
331
+2001-07-16 Ryan Yeske <rcyeske@vcn.bc.ca>
333
+ * winlisp.c (lisp_delay_output): expect a return value from the
336
+2001-07-14 Ryan Yeske <rcyeske@vcn.bc.ca>
338
+ * winlisp.c (lisp_add_menu): Quote the attribute.
339
+ (lisp_outrip): Add a newline to output.
341
+2001-07-06 shawn <sabetts@diggin.lamenet.tmp>
343
+ * winlisp.c (num_digits): new function
344
+ (power_of_ten): likewise
345
+ (lisp_nhgetch): handles repeated commands.
347
+2001-07-05 shawn <sabetts@diggin.lamenet.tmp>
349
+ * winlisp.c (WINLISP_VOID_RETVAL): flushes stdout
351
+2001-07-04 Ryan Yeske <rcyeske@van.gobasis.com>
353
+ * winlisp.c (lisp_add_menu): Convert printf to lisp_* macros,
354
+ fixing a string quote bug.
356
+2001-06-28 shawn <sabetts@diggin.lamenet.tmp>
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
367
+2001-06-27 shawn <sabetts@diggin.lamenet.tmp>
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.
374
+2001-06-21 Shawn Betts <sabetts@van.gobasis.com>
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
381
+2001-05-06 shawn <sabetts@diggin.lamenet.tmp>
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
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
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
405
+2000-10-01 Ryan Yeske <rcyeske@vcn.bc.ca>
407
+ * winlisp.c (cmd_index): renamed "ddoremarm" to "remarm" and
410
+2000-09-25 Shawn <sabetts@vcn.bc.ca>
412
+ * winlisp.c: Added more key commands.
413
+ (lisp_player_selection): honours default player selections as
414
+ specified in the nethackrc file.
416
+2000-09-22 Shawn <sabetts@vcn.bc.ca>
418
+ * winlisp.c (lisp_nhgetch): changed while loop stop condition.
420
+2000-09-19 Ryan yeske <rcyeske@van.gobasis.com>
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.
426
+2000-09-12 shawn <sabetts@gobasis.com>
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'.
435
+2000-09-11 Ryan Yeske <rcyeske@vcn.bc.ca>
437
+ * winlisp.c (lisp_cmd, lisp_close_cmd, lisp_open, lisp_close,
438
+ lisp_quote, lisp_int, lisp_string, lisp_dot): created macros.
440
+2000-09-10 Ryan Yeske <rcyeske@vcn.bc.ca>
442
+ * winlisp.c (lisp_outrip): added closing paren.
444
+2000-08-21 Ryan Yeske <rcyeske@vcn.bc.ca>
446
+ * winlisp.c (lisp_nhgetch): change ch type to int from char.
448
+2000-08-20 Ryan Yeske <rcyeske@vcn.bc.ca>
450
+ * winlisp.c (lisp_player_selection): role/race/gender/alignment
451
+ selection now sends (nethack-apix-choose-X ALIST) instead of
453
+ (lisp_update_inventory):
454
+ s/nethack-api-updated-inventory/nethack-api-update-inventory/
455
+ (WINLISP_VOID_RETVAL): added macro, called for every void
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
460
+/* Copyright (c) Shawn Betts, Ryan Yeske, 2001 */
461
+/* NetHack may be freely redistributed. See license for details. */
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.
469
+#ifdef MSDOS /* from compiler */
470
+#define SHORT_FILENAMES
474
+#include "winlisp.h"
475
+#include "func_tab.h"
478
+#ifdef SHORT_FILENAMES
479
+#include "patchlev.h"
481
+#include "patchlevel.h"
488
+extern short glyph2tile[];
489
+extern int total_tiles_used;
493
+ anything identifier;
497
+/* An iterator for assigning accelerator keys. */
498
+static char lisp_current_accelerator;
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;
505
+extern char *enc_stat[];
506
+const char *hunger_stat[] = {
520
+ int cmd; /* The command (a keystroke) */
524
+#define C(c) (0x1f & (c))
527
+cmd_index_t cmd_index[] = { {"gowest", CMD_KEY, 'h'},
528
+ {"gowestontop", CMD_KEY, 'H'},
529
+ {"gowestnear", CMD_KEY, C('h')},
531
+ {"gosouth", CMD_KEY, 'j'},
532
+ {"gosouthontop", CMD_KEY, 'J'},
533
+ {"gosouthnear", CMD_KEY, C('j')},
535
+ {"gonorth", CMD_KEY, 'k'},
536
+ {"gonorthontop", CMD_KEY, 'K'},
537
+ {"gonorthnear", CMD_KEY, C('k')},
539
+ {"goeast", CMD_KEY, 'l'},
540
+ {"goeastontop", CMD_KEY, 'L'},
541
+ {"goeastnear", CMD_KEY, C('l')},
543
+ {"gonorthwest", CMD_KEY, 'y'},
544
+ {"gonorthwestontop", CMD_KEY, 'Y'},
545
+ {"gonorthwestnear", CMD_KEY, C('y')},
547
+ {"gonortheast", CMD_KEY, 'u'},
548
+ {"gonortheastontop", CMD_KEY, 'U'},
549
+ {"gonortheastnear", CMD_KEY, C('u')},
551
+ {"gosouthwest", CMD_KEY, 'b'},
552
+ {"gosouthwestontop", CMD_KEY, 'B'},
553
+ {"gosouthwestnear", CMD_KEY, C('b')},
555
+ {"gosoutheast", CMD_KEY, 'n'},
556
+ {"gosoutheastontop", CMD_KEY, 'N'},
557
+ {"gosoutheastnear", CMD_KEY, C('n')},
559
+ {"idtrap", CMD_KEY, '^'},
560
+ {"apply", CMD_KEY, 'a'},
561
+ {"remarm", CMD_KEY, 'A'},
562
+ {"close", CMD_KEY, 'c'},
563
+ {"drop", CMD_KEY, 'd'},
565
+ {"ddrop", CMD_KEY, 'D'},
566
+ {"eat", CMD_KEY, 'e'},
567
+ {"engrave", CMD_KEY, 'E'},
568
+ {"fire", CMD_KEY, 'f'},
569
+ {"inv", CMD_KEY, 'i'},
571
+ {"typeinv", CMD_KEY, 'I'},
572
+ {"open", CMD_KEY, 'o'},
573
+ {"set", CMD_KEY, 'O'},
574
+ {"pay", CMD_KEY, 'p'},
575
+ {"puton", CMD_KEY, 'P'},
577
+ {"drink", CMD_KEY, 'q'},
578
+ {"wieldquiver", CMD_KEY, 'Q'},
579
+ {"read", CMD_KEY, 'r'},
580
+ {"remring", CMD_KEY, 'R'},
581
+ {"search", CMD_KEY, 's'},
583
+ {"save", CMD_KEY, 'S'},
584
+ {"throw", CMD_KEY, 't'},
585
+ {"takeoff", CMD_KEY, 'T'},
586
+ {"simpleversion", CMD_KEY, 'v'},
587
+ {"history", CMD_KEY, 'V'},
589
+ {"wield", CMD_KEY, 'w'},
590
+ {"wear", CMD_KEY, 'W'},
591
+ {"swapweapon", CMD_KEY, 'x'},
592
+ {"enter_explore_mode", CMD_KEY, 'X'},
593
+ {"zap", CMD_KEY, 'z'},
595
+ {"cast", CMD_KEY, 'Z'},
596
+ {"up", CMD_KEY, '<'},
597
+ {"down", CMD_KEY, '>'},
598
+ {"whatis", CMD_KEY, '/'},
599
+ {"help", CMD_KEY, '?'},
601
+ {"whatdoes", CMD_KEY, '&'},
602
+ {"sh", CMD_KEY, '!'},
603
+ {"discovered", CMD_KEY, '\\'},
604
+ {"null", CMD_KEY, '.'},
605
+ {"look", CMD_KEY, ':'},
607
+ {"quickwhatis", CMD_KEY, ';'},
608
+ {"pickup", CMD_KEY, ','},
609
+ {"togglepickup", CMD_KEY, '@'},
610
+ {"prinuse", CMD_KEY, '*'},
611
+ {"countgold", CMD_KEY, '$'},
613
+ {"kick", CMD_KEY, C('d')},
614
+ {"listspells", CMD_KEY, '+'},
615
+ {"redraw", CMD_KEY, C('r')},
616
+ {"teleport", CMD_KEY, C('t')},
617
+ {"callmon", CMD_KEY, 'C'},
618
+ {"fight", CMD_KEY, 'F'},
619
+ {"movenear", CMD_KEY, 'g'},
620
+ {"move", CMD_KEY, 'G'},
621
+ {"movenopickuporfight", CMD_KEY, 'm'},
622
+ {"movenopickup", CMD_KEY, 'M'},
623
+ {"showweapon", CMD_KEY, ')'},
624
+ {"showarmor", CMD_KEY, '['},
625
+ {"showrings", CMD_KEY, '='},
626
+ {"showamulet", CMD_KEY, '"'},
627
+ {"showtool", CMD_KEY, '('},
628
+ {"attributes", CMD_KEY, C('x')},
630
+ {"again", CMD_KEY, DOAGAIN},
633
+ /* wizard commands */
634
+ {"wiz_detect", CMD_KEY, C('e')},
635
+ {"wiz_map", CMD_KEY, C('f')},
636
+ {"wiz_genesis", CMD_KEY, C('g')},
637
+ {"wiz_identify", CMD_KEY, C('i')},
638
+ {"wiz_where", CMD_KEY, C('o')},
639
+ {"wiz_level_tele", CMD_KEY, C('v')},
640
+ {"wiz_wish", CMD_KEY, C('w')},
642
+ /* wizard extended commands */
644
+ {"light sources", CMD_EXT, 0},
645
+ {"seenv", CMD_EXT, 0},
646
+ {"stats", CMD_EXT, 0},
647
+ {"timeout", CMD_EXT, 0},
648
+ {"vision", CMD_EXT, 0},
650
+ {"wizdebug", CMD_EXT, 0},
652
+ {"wmode", CMD_EXT, 0},
654
+ {"pray", CMD_EXT, 0},
655
+ {"adjust", CMD_EXT, 0},
656
+ {"chat", CMD_EXT, 0},
657
+ {"conduct", CMD_EXT, 0},
658
+ {"dip", CMD_EXT, 0},
660
+ {"enhance", CMD_EXT, 0},
661
+ {"force", CMD_EXT, 0},
662
+ {"invoke", CMD_EXT, 0},
663
+ {"jump", CMD_EXT, 0},
664
+ {"loot", CMD_EXT, 0},
666
+ {"monster", CMD_EXT, 0},
667
+ {"name", CMD_EXT, 0},
668
+ {"offer", CMD_EXT, 0},
669
+ {"quit", CMD_EXT, 0},
670
+ {"ride", CMD_EXT, 0},
672
+ {"rub", CMD_EXT, 0},
673
+ {"sit", CMD_EXT, 0},
674
+ {"turn", CMD_EXT, 0},
675
+ {"twoweapon", CMD_EXT, 0},
676
+ {"untrap", CMD_EXT, 0},
678
+ {"version", CMD_EXT, 0},
679
+ {"wipe", CMD_EXT, 0},
681
+ {0, CMD_KEY, '\0'} };
683
+/* This variable is set when the user has selected an extended command. */
684
+static int extended_cmd_id;
686
+/* Interface definition, for windows.c */
687
+struct window_procs lisp_procs = {
689
+ WC_COLOR|WC_HILITE_PET,
691
+ lisp_init_nhwindows,
692
+ lisp_player_selection,
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,
710
+ lisp_update_inventory,
717
+ lisp_update_positionbar,
721
+ lisp_raw_print_bold,
725
+ lisp_doprev_message,
731
+#ifdef CHANGE_COLOR /* the Mac uses a palette device */
735
+ /* other defs that really should go away (they're tty specific) */
739
+ genl_preference_update,
742
+/* macros for printing lisp output */
743
+#define lisp_cmd(s,body) \
746
+ printf("(nhapi-%s ",s); \
751
+/* #define lisp_cmd0(s) printf ("(nhapi-%s)\n", s) */
752
+#define lisp_list(body) \
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) \
771
+ printf ("%s ", x); \
774
+#define lisp_cons(x,y) \
784
+#define lisp_int(i) printf("%d ",i)
785
+#define lisp_string(s) \
791
+ for (nhi=0;nhi<strlen(s);nhi++) \
794
+ || s[nhi] == 92) putchar('\\'); \
802
+attr_to_string(attr)
810
+ return "atr-uline";
814
+ return "atr-blink";
816
+ return "atr-inverse";
818
+ /* Should never happen. */
819
+ impossible ("Invalid attribute code.");
820
+ exit (EXIT_FAILURE);
826
+special_glyph_to_string(special)
843
+ /* If it's a combination, just return special. */
851
+wintype_to_string(type)
859
+ return "nhw-message";
861
+ return "nhw-status";
867
+ fprintf (stderr, "Invalid window code\n");
868
+ exit (EXIT_FAILURE);
880
+ return "pick-none";
886
+ impossible ("Invalid how value %d", how);
891
+read_int (prompt, i)
892
+ const char* prompt;
897
+ printf ("%s> ", prompt);
898
+ fgets (line, BUFSZ, stdin);
899
+ rv = sscanf (line, "%d", i);
900
+ if (rv != 1) *i = -1;
905
+read_string (prompt, str)
906
+ const char* prompt;
916
+ *str = malloc (size);
919
+ printf ("%s> ", prompt);
923
+ /* Read the string */
924
+ rv = fgets (tmp, BUFSZ, stdin);
928
+ len += strlen (tmp);
929
+ if (len >= size - 1)
932
+ *str = realloc (*str, size);
934
+ panic ("Memory allocation failure; cannot get %u bytes", size);
936
+ strcat (*str, tmp);
937
+ } while (tmp[strlen (tmp) - 1] != '\n');
939
+ /* Did we read a string or error out? */
947
+ /* chop the newline */
948
+ (*str) [strlen (*str) - 1] = '\0';
955
+read_command (prompt, cmd, count)
956
+ const char *prompt;
964
+ if (read_string (prompt, &buf) == -1)
966
+ rv = sscanf (buf, "%s %s", cmd, count);
968
+ if (rv != 2) *count = 0;
977
+ lisp_exit_nhwindows (mesg);
978
+ terminate (EXIT_SUCCESS);
985
+ /* Code to be executed on startup. */
989
+lisp_player_selection ()
992
+ char pick4u = 'n', thisch, lastch = 0;
993
+ char pbuf[QBUFSZ], plbuf[QBUFSZ];
996
+ menu_item *selected = 0;
998
+ /* prevent an unnecessary prompt */
999
+ rigid_role_checks();
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)) {
1006
+ pick4u = lisp_yn_function ("Shall I pick a character for you? [ynq] ", "ynq", 'y');
1008
+ if (pick4u != 'y' && pick4u != 'n')
1010
+ give_up: /* Quit */
1011
+ if (selected) free((genericptr_t) selected);
1019
+ (void) root_plselection_prompt(plbuf, QBUFSZ - 1,
1020
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
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();
1037
+ /* Prompt for a role */
1038
+ win = create_nhwindow(NHW_MENU);
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);
1051
+ Strcpy(rolenamebuf, roles[i].name.m);
1053
+ if (roles[i].name.f) {
1054
+ Strcpy(rolenamebuf, roles[i].name.m);
1055
+ Strcat(rolenamebuf, "/");
1056
+ Strcat(rolenamebuf, roles[i].name.f);
1058
+ Strcpy(rolenamebuf, roles[i].name.m);
1060
+ add_menu(win, NO_GLYPH, &any, thisch,
1061
+ 0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED);
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);
1079
+ /* Process the choice */
1080
+ if (n != 1 || selected[0].item.a_int == any.a_int)
1081
+ goto give_up; /* Selected quit */
1083
+ flags.initrole = selected[0].item.a_int - 1;
1084
+ free((genericptr_t) selected), selected = 0;
1086
+ (void) root_plselection_prompt(plbuf, QBUFSZ - 1,
1087
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
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);
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)) {
1114
+ for (i = 0; races[i].noun; i++) {
1115
+ if (validrace(flags.initrole, i)) {
1122
+ /* Permit the user to pick, if there is more than one */
1124
+ win = create_nhwindow(NHW_MENU);
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);
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 */
1150
+ k = selected[0].item.a_int - 1;
1151
+ free((genericptr_t) selected), selected = 0;
1153
+ flags.initrace = k;
1155
+ (void) root_plselection_prompt(plbuf, QBUFSZ - 1,
1156
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
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);
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)) {
1184
+ for (i = 0; i < ROLE_GENDERS; i++) {
1185
+ if (validgend(flags.initrole, flags.initrace, i)) {
1192
+ /* Permit the user to pick, if there is more than one */
1194
+ win = create_nhwindow(NHW_MENU);
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)) {
1201
+ add_menu(win, NO_GLYPH, &any, genders[i].adj[0],
1202
+ 0, ATR_NONE, genders[i].adj, MENU_UNSELECTED);
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 */
1220
+ k = selected[0].item.a_int - 1;
1221
+ free((genericptr_t) selected), selected = 0;
1223
+ flags.initgend = k;
1225
+ (void) root_plselection_prompt(plbuf, QBUFSZ - 1,
1226
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
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);
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,
1253
+ for (i = 0; i < ROLE_ALIGNS; i++) {
1254
+ if (validalign(flags.initrole, flags.initrace, i)) {
1261
+ /* Permit the user to pick, if there is more than one */
1263
+ win = create_nhwindow(NHW_MENU);
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)) {
1270
+ add_menu(win, NO_GLYPH, &any, aligns[i].adj[0],
1271
+ 0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED);
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 */
1289
+ k = selected[0].item.a_int - 1;
1290
+ free((genericptr_t) selected), selected = 0;
1292
+ flags.initalign = k;
1296
+/* lisp_display_nhwindow(BASE_WINDOW, FALSE); */
1299
+/* Reads from standard in, the player's name. */
1304
+ lisp_cmd ("askname",);
1305
+ read_string ("string", &line);
1306
+ strncpy (plname, line, PL_NSIZ);
1307
+ plname[PL_NSIZ-1] = '\0';
1311
+/* This is a noop for tty and X, so should it be a noop for us too? */
1313
+lisp_get_nh_event ()
1315
+/* lisp_cmd ("get-event",); */
1318
+/* Global Functions */
1320
+lisp_raw_print(str)
1323
+ lisp_cmd ("raw-print", lisp_string (str));
1327
+lisp_raw_print_bold(str)
1330
+ lisp_cmd ("raw-print-bold", lisp_string (str));
1334
+lisp_curs(window, x, y)
1338
+ if (window == WIN_MAP)
1342
+ else if (window == WIN_STATUS)
1347
+ lisp_cmd ("error", lisp_string("lisp_curs bad window"); lisp_int (window));
1351
+generate_status_line ()
1353
+ /* Ripped from botl.c */
1356
+ hp = Upolyd ? u.mh : u.uhp;
1357
+ hpmax = Upolyd ? u.mhmax : u.uhpmax;
1358
+ if(hp < 0) hp = 0;
1360
+ printf ("(nhapi-update-status ");
1363
+ lisp_list (lisp_string ("name");
1364
+ lisp_string (plname););
1367
+ lisp_list (lisp_string ("rank");
1369
+ lisp_list (lisp_string ("monster");
1370
+ lisp_string (mons[u.umonnum].mname));
1374
+ lisp_list (lisp_string ("rank");
1375
+ lisp_string (rank_of(u.ulevel, Role_switch, flags.female)););;
1376
+ lisp_list (lisp_string ("monster");
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");
1398
+ lisp_string ("Lawful"););
1400
+#ifdef SCORE_ON_BOTL
1401
+ lisp_list (lisp_string ("Score");
1402
+ lisp_int (botl_score()););
1405
+ if (In_endgame(&u.uz))
1407
+ lisp_list (lisp_string ("Dungeon");
1408
+ if (Is_astralevel(&u.uz))
1409
+ lisp_string ("Astral Plane");
1411
+ lisp_string ("End Game"););
1415
+ lisp_list (lisp_string ("Dungeon");
1416
+ lisp_string (dungeons[u.uz.dnum].dname););
1419
+ lisp_list (lisp_string ("Dlvl");
1420
+ lisp_int (depth(&u.uz)););
1422
+ lisp_list (lisp_string ("$");
1423
+ lisp_int (u.ugold););
1424
+ lisp_list (lisp_string ("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););
1437
+ lisp_list (lisp_string ("HD");
1438
+ lisp_int (mons[u.umonnum].mlevel););
1442
+ lisp_list (lisp_string ("HD");
1446
+ lisp_list (lisp_string ("Level");
1447
+ lisp_int (u.ulevel););
1449
+ lisp_list (lisp_string ("XP");
1450
+ lisp_int (u.uexp););
1452
+ lisp_list (lisp_string ("T");
1453
+ lisp_int (moves););
1456
+ lisp_list (lisp_string ("confusion"); lisp_string ("Conf"));
1458
+ lisp_list (lisp_string ("confusion"); lisp_nil);
1461
+ lisp_list (lisp_string ("hunger"); lisp_string (hunger_stat[u.uhs]));
1463
+ lisp_list (lisp_string ("hunger"); lisp_nil);
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"));
1473
+ lisp_list (lisp_string ("sick"); lisp_nil);
1476
+ lisp_list (lisp_string ("blind"); lisp_string ("Blind"));
1478
+ lisp_list (lisp_string ("blind"); lisp_nil);
1481
+ lisp_list (lisp_string ("stunned"); lisp_string ("Stun"));
1483
+ lisp_list (lisp_string ("stunned"); lisp_nil);
1485
+ if (Hallucination)
1486
+ lisp_list (lisp_string ("hallucination"); lisp_string ("Hallu"));
1488
+ lisp_list (lisp_string ("hallucination"); lisp_nil);
1491
+ lisp_list (lisp_string ("slimed"); lisp_string ("Slime"));
1493
+ lisp_list (lisp_string ("slimed"); lisp_nil);
1495
+ if (near_capacity() > UNENCUMBERED)
1496
+ lisp_list (lisp_string ("encumbrance");
1497
+ lisp_string (enc_stat[near_capacity()]));
1499
+ lisp_list (lisp_string ("encumbrance"); lisp_nil);
1505
+lisp_putstr(window, attr, str)
1510
+ static char statline1[BUFSZ] = "";
1511
+ if (window == WIN_STATUS)
1513
+ if (statline1[0]=='\0')
1514
+ Strcpy (statline1, str);
1517
+ generate_status_line ();
1518
+ statline1[0]='\0';
1521
+ else if (window == WIN_MESSAGE)
1522
+ lisp_cmd ("message",
1523
+ lisp_literal (attr_to_string (attr));
1524
+ lisp_string (str));
1526
+ lisp_cmd ("menu-putstr",
1527
+ lisp_int (window);
1528
+ lisp_literal (attr_to_string (attr));
1529
+ lisp_string (str));
1533
+lisp_start_menu(window)
1536
+ lisp_menu_list_num = 0;
1537
+ lisp_current_accelerator = 'a';
1538
+ lisp_cmd ("start-menu", lisp_int (window));
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 */
1552
+ if (identifier->a_void)
1554
+ lisp_menu_item_list[lisp_menu_list_num].identifier = *identifier;
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';
1561
+ lisp_current_accelerator++;
1564
+ lisp_menu_item_list[lisp_menu_list_num].accelerator = ch;
1566
+ lisp_menu_list_num++;
1571
+ lisp_cmd ("add-menu",
1572
+ lisp_int (window);
1574
+ lisp_int (glyph2tile[glyph]);
1577
+ lisp_literal (attr_to_string (attr));
1578
+ lisp_string (str);
1579
+ preselected ? lisp_t : lisp_nil);
1583
+lisp_end_menu(window, prompt)
1584
+ winid window; /* menu to use */
1585
+ const char *prompt; /* prompt to for menu */
1587
+ lisp_cmd ("end-menu",
1588
+ lisp_int (window);
1589
+ lisp_string (prompt));
1593
+lisp_get_menu_identifier(ch, identifier)
1595
+ anything *identifier;
1599
+ for(i=0; i < lisp_menu_list_num; i++)
1601
+ if( lisp_menu_item_list[i].accelerator == ch )
1603
+ *identifier = lisp_menu_item_list[i].identifier;
1612
+lisp_select_menu(window, how, menu_list)
1615
+ menu_item **menu_list;
1617
+ const char *delim = "() \n";
1622
+ lisp_cmd ("select-menu",
1623
+ lisp_int (window);
1624
+ lisp_literal (how_to_string (how)));
1626
+ read_string ("menu", &list);
1628
+/* lisp_prompt ("menu"); */
1629
+/* fgets (list, LINESIZ, stdin); */
1631
+ /* The client should submit a structure like this:
1633
+ ((ch count) (ch count) (ch count) ...)
1635
+ where ch is the accelerator for the menu item and count is the
1636
+ number of them to select.
1638
+ We strtok it so we just get id count id count id count. */
1640
+ token = strtok (list, delim);
1642
+ /* Start with some memory so realloc doesn't fail. */
1643
+ *menu_list = malloc (sizeof (menu_item));
1644
+ if (*menu_list == NULL)
1646
+ panic ("Memory allocation failure; cannot get %u bytes",
1647
+ sizeof (menu_item));
1651
+ while (token != NULL)
1653
+ /* Make more room in the array for the new item */
1655
+ if ((*menu_list = realloc (*menu_list, size * sizeof (menu_item))) == NULL)
1657
+ panic ("Memory allocation failure; cannot get %u bytes",
1658
+ size * sizeof (menu_item));
1661
+ /* assign the item ID */
1662
+ lisp_get_menu_identifier (atoi (token), &(*menu_list)[size-1].item );
1664
+ /* Read the item count */
1665
+ token = strtok (NULL, delim);
1666
+ (*menu_list)[size-1].count = atoi (token);
1668
+ /* read the next item ID */
1669
+ token = strtok (NULL, delim);
1677
+/* This is a tty-specific hack. Do we need it? */
1679
+lisp_message_menu(let, how, mesg)
1684
+ lisp_cmd ("message-menu",
1686
+ lisp_literal (how_to_string (how));
1687
+ lisp_string (mesg));
1697
+ for (i=0; cmd_index[i].name != (char *)0; i++)
1699
+ if (!strcmp (str, cmd_index[i].name))
1707
+lisp_get_ext_cmd_id (str)
1712
+ for (i=0; extcmdlist[i].ef_txt != (char *)0; i++) {
1713
+ if (!strcmp (str, extcmdlist[i].ef_txt)) return i;
1720
+/* num_digits(n) */
1726
+/* for (i=10;n / i; i *= 10) */
1736
+/* power_of_ten (n) */
1740
+/* int power = 1; */
1742
+/* for (i=0; i<n; i++) */
1747
+/* return power; */
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;
1761
+ char *tmp = count_pos;
1766
+ if (count_cmd >= 0)
1773
+ char cmdstr[BUFSZ];
1775
+ read_command ("command", cmdstr, count_buf);
1777
+ count_pos = count_buf;
1778
+ cmd = lisp_get_cmd (cmdstr);
1781
+ printf ("(nhapi-message 'atr-none \"undefined-command %s\")\n", cmdstr);
1782
+ cmd = lisp_get_cmd ("null");
1785
+ if (atoi (count_pos) > 1)
1787
+ char* tmp = count_pos;
1794
+ /* Since the count is 1, zero out the string. */
1799
+ if (cmd_index[cmd].type == CMD_KEY)
1801
+ return cmd_index[cmd].cmd;
1805
+ if ((extended_cmd_id = lisp_get_ext_cmd_id (cmd_index[cmd].name)) == -1)
1807
+ /* Can never happen. */
1808
+ printf ("%s:%d: Bad extended command name\n", __FILE__, __LINE__);
1815
+lisp_nh_poskey(x, y, mod)
1818
+/* char scratch[256]; */
1820
+/* printf ("(nethack-api-poskey)\n"); */
1822
+/* scanf ("( %d %d '%255s )", x, y, scratch); */
1823
+/* if (!strcmp (scratch, "click-1")) *mod = CLICK_1; */
1824
+/* else *mod = CLICK_2; */
1828
+ return lisp_nhgetch();
1831
+static boolean inven_win_created = FALSE;
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;
1838
+/* returns index into winid_list that can be used. */
1844
+ /* Check for a vacant spot in the list. */
1845
+ for (i=0; i<winid_list_len; i++)
1847
+ if (winid_list[i] == -1) return i;
1850
+ /* no vacant ones, so grow the array. */
1851
+ if (winid_list_len >= winid_list_max)
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");
1860
+ return winid_list_len-1;
1864
+winid_is_taken (winid n)
1868
+ for (i=0; i<winid_list_len; i++)
1869
+ if (winid_list[i] == n) return 1;
1875
+add_winid (winid n)
1877
+ if (winid_is_taken (n)) return 0; /* failed. */
1879
+ winid_list[find_empty_cell()] = n;
1880
+ return 1; /* success! */
1884
+get_unique_winid ()
1888
+ /* look for a unique number, and add it to the list of taken
1891
+ while (!add_winid (i)) i++;
1896
+/* When a window is destroyed, it gives back its window number with
1899
+return_winid (winid n)
1903
+ for (i=0; i<winid_list_len; i++)
1905
+ if (winid_list[i] == n)
1907
+ winid_list[i] = -1;
1916
+ winid_list_max = 10;
1917
+ winid_list_len = 0;
1919
+ winid_list = malloc (winid_list_max * sizeof (int));
1922
+/* Prints a create_nhwindow function and expects from stdin the id of
1923
+ this new window as a number. */
1925
+lisp_create_nhwindow(type)
1928
+ winid id = get_unique_winid();
1933
+ lisp_cmd ("create-message-window",);
1936
+ lisp_cmd ("create-map-window",);
1939
+ lisp_cmd ("create-status-window",);
1942
+ lisp_cmd ("create-text-window", lisp_int (id));
1945
+ if (!inven_win_created)
1947
+ lisp_cmd ("create-inventory-window", lisp_int (id));
1948
+ inven_win_created = TRUE;
1951
+ lisp_cmd ("create-menu-window", lisp_int (id));
1954
+ impossible ("Unknown window type: %d", type);
1961
+lisp_clear_nhwindow(window)
1964
+ if (window == WIN_MESSAGE)
1965
+ lisp_cmd ("clear-message",);
1966
+ else if (window == WIN_MAP)
1967
+ lisp_cmd ("clear-map",);
1969
+ /* are other window types ever cleared? */
1970
+ lisp_cmd ("error", lisp_string("clearing unknown winid"));
1974
+lisp_display_nhwindow(window, blocking)
1978
+ /* don't send display messages for anything but menus */
1980
+ if (window != WIN_MESSAGE && window != WIN_STATUS && window != WIN_MAP)
1982
+ lisp_cmd ("display-menu", lisp_int (window));
1983
+ read_string ("menu", &dummy);
1986
+ else if (blocking)
1988
+ if (window == WIN_MESSAGE)
1990
+ /* blocking on the message window happens only at the end of
1992
+ lisp_cmd ("end",);
1996
+ lisp_cmd ("block",);
1997
+ read_string ("dummy", &dummy);
2001
+ else if (window == WIN_STATUS)
2003
+ /* initial window setup hack here :) */
2004
+ lisp_cmd ("restore-window-configuration",);
2009
+lisp_destroy_nhwindow(window)
2012
+ if ((window != WIN_STATUS)
2013
+ && (window != WIN_MESSAGE)
2014
+ && (window != WIN_MAP))
2016
+ lisp_cmd ("destroy-menu", lisp_int (window));
2017
+ return_winid (window);
2022
+lisp_update_inventory()
2024
+ lisp_cmd ("update-inventory",);
2028
+lisp_doprev_message()
2030
+ lisp_cmd ("doprev-message",);
2037
+ lisp_cmd ("nhbell",);
2040
+/* Can be an empty call says window.doc. */
2044
+ /* lisp_cmd ("mark-sync",); */
2050
+ lisp_cmd ("wait-synch",);
2053
+/* Since nethack will never be suspended, we need not worry about this
2056
+lisp_resume_nhwindows()
2061
+/* Since nethack will never be suspended, we need not worry about this
2064
+lisp_suspend_nhwindows(str)
2070
+/* All keys are defined in emacs, so number_pad makes no sense. */
2072
+lisp_number_pad(state)
2079
+lisp_init_nhwindows(argcp,argv)
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]));
2090
+ /* FIXME: doesn't remove the arguments parsed, as specified in the
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;
2099
+ flags.time = TRUE;
2101
+ /* inform nethack that the windows have been initialized. */
2102
+ iflags.window_inited = TRUE;
2104
+ init_winid_list();
2108
+lisp_exit_nhwindows (str)
2111
+ lisp_cmd ("exit-nhwindows ", lisp_string (str));
2115
+lisp_delay_output()
2118
+ lisp_cmd ("delay-output",);
2119
+ read_string ("dummy", &dummy);
2124
+lisp_getlin(question, input)
2125
+ const char *question;
2129
+ lisp_cmd ("getlin", lisp_string (question));
2130
+ read_string ("string", &tmp);
2131
+ /* FIXME: potential buffer overflow. */
2132
+ strcpy (input, tmp);
2141
+/* printf ("(nethack-api-get-ext-cmd '("); */
2143
+/* for (i=0; extcmdlist[i].ef_txt != (char *)0; i++) { */
2144
+/* printf ("(\"%s\" . %d)", extcmdlist[i].ef_txt, i); */
2146
+/* printf ("))\n"); */
2148
+/* scanf ("%d", &cmd); */
2150
+ /* This is set when the user chooses an extended command. */
2151
+ return extended_cmd_id;
2155
+lisp_display_file(str, complain)
2159
+ lisp_cmd ("display-file",
2160
+ lisp_string (str);
2161
+ complain ? lisp_t : lisp_nil);;
2165
+lisp_yn_function(ques, choices, def)
2167
+ const char *choices;
2172
+ /* Some questions have special functions. */
2173
+ if (!strncmp (ques, "In what direction", 17))
2176
+ lisp_cmd ("ask-direction",
2177
+ lisp_string (ques));
2178
+ read_string ("direction", &dir);
2179
+ if (!strcmp (dir, "n"))
2181
+ else if (!strcmp (dir, "s"))
2183
+ else if (!strcmp (dir, "e"))
2185
+ else if (!strcmp (dir, "w"))
2187
+ else if (!strcmp (dir, "ne"))
2189
+ else if (!strcmp (dir, "nw"))
2191
+ else if (!strcmp (dir, "se"))
2193
+ else if (!strcmp (dir, "sw"))
2195
+ else if (!strcmp (dir, "up"))
2197
+ else if (!strcmp (dir, "down"))
2199
+ else if (!strcmp (dir, "self"))
2204
+ answer = 0x20; /* space */
2213
+ lisp_cmd ("yn-function",
2214
+ lisp_string (ques);
2215
+ lisp_string (choices);
2217
+ read_int ("number", &answer);
2220
+ return (char)answer;
2225
+lisp_update_positionbar(features)
2228
+ lisp_cmd ("update-positionbar", lisp_string (features));
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
2241
+lisp_print_glyph(window, x, y, glyph)
2250
+ /* map glyph to character and color */
2251
+ mapglyph(glyph, &ch, &color, &special, x, y);
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)
2260
+ special &= ~MG_PET;
2263
+ if (window == WIN_MAP)
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. */
2270
+ lisp_cmd ("print-glyph",
2275
+ lisp_int (glyph2tile[glyph]);
2277
+ lisp_literal (special_glyph_to_string (special)););
2281
+ lisp_cmd ("print-glyph",
2286
+ lisp_int (glyph2tile[glyph]);
2291
+ lisp_cmd ("error",
2292
+ lisp_string ("lisp_print_glyph bad window");
2293
+ lisp_int (window));
2298
+lisp_cliparound(x, y)
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 */
2306
+ /* lisp_cmd ("cliparound", lisp_int (x); lisp_int (y)); */
2310
+void lisp_start_screen() { return; } /* called from setftty() in unixtty.c */
2311
+void lisp_end_screen() {return; } /* called from settty() in unixtty.c */
2314
+get_death_text (buf)
2321
+lisp_outrip(window, how)
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."));