Initial check-in. Mostly sort of works. Ish. default tip
authorali@juiblex.co.uk
Mon Jan 29 20:22:01 2007 +0000 (2007-01-29)
changeset 0acc07f1f4b1e
Initial check-in. Mostly sort of works. Ish.
ChangeLog
Makefile.am
bootstrap.sh
configure.ac
license.txt
src/Makefile.am
src/extprocs.c
src/menu.c
src/message.c
src/minhack.c
src/minhack.h
src/window.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ChangeLog	Mon Jan 29 20:22:01 2007 +0000
     1.3 @@ -0,0 +1,3 @@
     1.4 +2007-01-29  J. Ali Harlow  <ali@juiblex.co.uk>
     1.5 +
     1.6 +	Initial check-in
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile.am	Mon Jan 29 20:22:01 2007 +0000
     2.3 @@ -0,0 +1,7 @@
     2.4 +## $Id: Makefile.am,v 1.1 2004/12/30 09:07:43 ali Exp $
     2.5 +## Copyright (C) 2007 J. Ali Harlow
     2.6 +## Minimal Hack may be freely redistributed.  See license for details.
     2.7 +
     2.8 +SUBDIRS = src
     2.9 +
    2.10 +EXTRA_DIST = license.txt
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/bootstrap.sh	Mon Jan 29 20:22:01 2007 +0000
     3.3 @@ -0,0 +1,8 @@
     3.4 +#!/bin/sh
     3.5 +#
     3.6 +# $Id: bootstrap.sh,v 1.1 2004/12/30 09:07:43 ali Exp $
     3.7 +#
     3.8 +autoheader && \
     3.9 +  aclocal && \
    3.10 +  automake --foreign --add-missing && \
    3.11 +  autoconf
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/configure.ac	Mon Jan 29 20:22:01 2007 +0000
     4.3 @@ -0,0 +1,45 @@
     4.4 +#                                               -*- Autoconf -*-
     4.5 +# Process this file with autoconf to produce a configure script.
     4.6 +# Copyright (C) 2007 J. Ali Harlow
     4.7 +# Minimal Hack may be freely redistributed.  See license for details.
     4.8 +
     4.9 +AC_INIT([minhack], [0.1], [ali@juiblex.co.uk])
    4.10 +AC_PREREQ(2.59)
    4.11 +AC_REVISION($Id: configure.ac,v 1.2 2005/01/22 18:39:17 j_ali Exp $)
    4.12 +AC_CONFIG_AUX_DIR([config])
    4.13 +AC_CONFIG_SRCDIR([src/minhack.c])
    4.14 +AC_CONFIG_HEADER([config.h])
    4.15 +AC_CONFIG_FILES([Makefile
    4.16 +src/Makefile
    4.17 +])
    4.18 +AM_INIT_AUTOMAKE(no-define)
    4.19 +
    4.20 +##################################################
    4.21 +# Checks for programs.
    4.22 +##################################################
    4.23 +AC_PROG_CC
    4.24 +
    4.25 +##################################################
    4.26 +# Checks for header files.
    4.27 +##################################################
    4.28 +AC_HEADER_STDC
    4.29 +
    4.30 +##################################################
    4.31 +# Checks for typedefs, structures, and compiler characteristics.
    4.32 +##################################################
    4.33 +
    4.34 +##################################################
    4.35 +# Checks for libraries.
    4.36 +##################################################
    4.37 +PKG_CHECK_MODULES(MINHACK, nhproxy >= 0.9.0)
    4.38 +
    4.39 +##################################################
    4.40 +# Checks for optional features.
    4.41 +##################################################
    4.42 +
    4.43 +##################################################
    4.44 +# Generate the various configured files
    4.45 +##################################################
    4.46 +AC_SUBST(MINHACK_CFLAGS)
    4.47 +AC_SUBST(MINHACK_LIBS)
    4.48 +AC_OUTPUT
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/license.txt	Mon Jan 29 20:22:01 2007 +0000
     5.3 @@ -0,0 +1,95 @@
     5.4 +                    NETHACK GENERAL PUBLIC LICENSE
     5.5 +                    (Copyright 1989 M. Stephenson)
     5.6 +
     5.7 +               (Based on the BISON general public license,
     5.8 +                   copyright 1988 Richard M. Stallman)
     5.9 +
    5.10 + Everyone is permitted to copy and distribute verbatim copies of this
    5.11 + license, but changing it is not allowed.  You can also use this wording to
    5.12 + make the terms for other programs.
    5.13 +
    5.14 +  The license agreements of most software companies keep you at the mercy of
    5.15 +those companies.  By contrast, our general public license is intended to give
    5.16 +everyone the right to share NetHack.  To make sure that you get the rights we
    5.17 +want you to have, we need to make restrictions that forbid anyone to deny you
    5.18 +these rights or to ask you to surrender the rights.  Hence this license
    5.19 +agreement.
    5.20 +
    5.21 +  Specifically, we want to make sure that you have the right to give away
    5.22 +copies of NetHack, that you receive source code or else can get it if you
    5.23 +want it, that you can change NetHack or use pieces of it in new free
    5.24 +programs, and that you know you can do these things.
    5.25 +
    5.26 +  To make sure that everyone has such rights, we have to forbid you to
    5.27 +deprive anyone else of these rights.  For example, if you distribute copies
    5.28 +of NetHack, you must give the recipients all the rights that you have.  You
    5.29 +must make sure that they, too, receive or can get the source code.  And you
    5.30 +must tell them their rights.
    5.31 +
    5.32 +  Also, for our own protection, we must make certain that everyone finds out
    5.33 +that there is no warranty for NetHack.  If NetHack is modified by someone
    5.34 +else and passed on, we want its recipients to know that what they have is
    5.35 +not what we distributed.
    5.36 +
    5.37 +  Therefore we (Mike Stephenson and other holders of NetHack copyrights) make
    5.38 +the following terms which say what you must do to be allowed to distribute or
    5.39 +change NetHack.
    5.40 +
    5.41 +
    5.42 +                        COPYING POLICIES
    5.43 +
    5.44 +  1. You may copy and distribute verbatim copies of NetHack source code as
    5.45 +you receive it, in any medium, provided that you keep intact the notices on
    5.46 +all files that refer to copyrights, to this License Agreement, and to the
    5.47 +absence of any warranty; and give any other recipients of the NetHack
    5.48 +program a copy of this License Agreement along with the program.
    5.49 +
    5.50 +  2. You may modify your copy or copies of NetHack or any portion of it, and
    5.51 +copy and distribute such modifications under the terms of Paragraph 1 above
    5.52 +(including distributing this License Agreement), provided that you also do the
    5.53 +following:
    5.54 +
    5.55 +    a) cause the modified files to carry prominent notices stating that you
    5.56 +    changed the files and the date of any change; and
    5.57 +
    5.58 +    b) cause the whole of any work that you distribute or publish, that in
    5.59 +    whole or in part contains or is a derivative of NetHack or any part
    5.60 +    thereof, to be licensed at no charge to all third parties on terms
    5.61 +    identical to those contained in this License Agreement (except that you
    5.62 +    may choose to grant more extensive warranty protection to some or all
    5.63 +    third parties, at your option)
    5.64 +
    5.65 +    c) You may charge a distribution fee for the physical act of
    5.66 +    transferring a copy, and you may at your option offer warranty protection
    5.67 +    in exchange for a fee.
    5.68 +
    5.69 +  3. You may copy and distribute NetHack (or a portion or derivative of it,
    5.70 +under Paragraph 2) in object code or executable form under the terms of
    5.71 +Paragraphs 1 and 2 above provided that you also do one of the following:
    5.72 +
    5.73 +    a) accompany it with the complete machine-readable source code, which
    5.74 +    must be distributed under the terms of Paragraphs 1 and 2 above; or,
    5.75 +
    5.76 +    b) accompany it with full information as to how to obtain the complete
    5.77 +    machine-readable source code from an appropriate archive site.  (This
    5.78 +    alternative is allowed only for noncommercial distribution.)
    5.79 +
    5.80 +For these purposes, complete source code means either the full source
    5.81 +distribution as originally released over Usenet or updated copies of the
    5.82 +files in this distribution used to create the object code or executable.
    5.83 +
    5.84 +  4. You may not copy, sublicense, distribute or transfer NetHack except as
    5.85 +expressly provided under this License Agreement.  Any attempt otherwise to
    5.86 +copy, sublicense, distribute or transfer NetHack is void and your rights to
    5.87 +use the program under this License agreement shall be automatically
    5.88 +terminated.  However, parties who have received computer software programs
    5.89 +from you with this License Agreement will not have their licenses terminated
    5.90 +so long as such parties remain in full compliance.
    5.91 +
    5.92 +
    5.93 +Stated plainly:  You are permitted to modify NetHack, or otherwise use parts
    5.94 +of NetHack, provided that you comply with the conditions specified above;
    5.95 +in particular, your modified NetHack or program containing parts of NetHack
    5.96 +must remain freely available as provided in this License Agreement.  In
    5.97 +other words, go ahead and share NetHack, but don't try to stop anyone else
    5.98 +from sharing it farther.
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/Makefile.am	Mon Jan 29 20:22:01 2007 +0000
     6.3 @@ -0,0 +1,10 @@
     6.4 +## $Id: Makefile.am,v 1.1 2004/12/30 09:07:46 ali Exp $
     6.5 +## Copyright (C) 2007 J. Ali Harlow
     6.6 +## Minimal Hack may be freely redistributed.  See license for details.
     6.7 +
     6.8 +INCLUDES = -I$(top_srcdir)
     6.9 +AM_CFLAGS = $(MINHACK_CFLAGS) -g
    6.10 +LDADD = $(MINHACK_LIBS) -lmenu -lncurses
    6.11 +
    6.12 +bin_PROGRAMS = minhack
    6.13 +minhack_SOURCES = minhack.c minhack.h extprocs.c menu.c message.c window.c
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/extprocs.c	Mon Jan 29 20:22:01 2007 +0000
     7.3 @@ -0,0 +1,162 @@
     7.4 +/*
     7.5 + * $Id: extprocs.c,v 1.5 2004/12/30 09:07:47 ali Exp $
     7.6 + * Copyright (C) 2007 J. Ali Harlow
     7.7 + * Min Hack may be freely redistributed.  See license for details. 
     7.8 + */
     7.9 +
    7.10 +#include <stdlib.h>
    7.11 +#include <stdio.h>
    7.12 +#include <string.h>
    7.13 +#include "minhack.h"
    7.14 +
    7.15 +struct nhproxy_cb_get_glyph_mapping_res *glyph_map;
    7.16 +struct minhack_window *windows=NULL;
    7.17 +int no_windows=0;
    7.18 +
    7.19 +static int v_hook(void)
    7.20 +{
    7.21 +    fprintf(stderr,"v_hook called\n");
    7.22 +}
    7.23 +
    7.24 +struct nhproxy_clnt_ext_procs minhack_ext_procs = {
    7.25 +    "minhack",
    7.26 +    minhack_init_nhwindows,
    7.27 +    minhack_player_selection,
    7.28 +    minhack_askname,
    7.29 +    NULL,			/* get_nh_event */
    7.30 +    minhack_exit_nhwindows,
    7.31 +    NULL,			/* suspend_nhwindows */
    7.32 +    NULL,			/* resume_nhwindows */
    7.33 +    minhack_create_nhwindow,
    7.34 +    minhack_clear_nhwindow,
    7.35 +    minhack_display_nhwindow,
    7.36 +    minhack_destroy_nhwindow,
    7.37 +    minhack_curs,
    7.38 +    minhack_putstr,
    7.39 +    minhack_display_file,
    7.40 +    minhack_start_menu,
    7.41 +    minhack_add_menu,
    7.42 +    minhack_end_menu,
    7.43 +    minhack_select_menu,
    7.44 +    minhack_message_menu,
    7.45 +    NULL,			/* update_inventory */
    7.46 +    NULL,			/* mark_sync */
    7.47 +    NULL,			/* wait_sync */
    7.48 +    NULL,			/* cliparound */
    7.49 +    NULL,			/* update_positionbar */
    7.50 +    minhack_print_glyph,
    7.51 +    minhack_raw_print,
    7.52 +    minhack_raw_print_bold,
    7.53 +    minhack_nhgetch,
    7.54 +    minhack_nh_poskey,
    7.55 +    NULL,			/* nhbell */
    7.56 +    NULL,			/* doprev_message */
    7.57 +    minhack_yn_function,
    7.58 +    minhack_getlin,
    7.59 +    minhack_get_ext_cmd,
    7.60 +    NULL,			/* number_pad */
    7.61 +    NULL,			/* delay_output */
    7.62 +    NULL,			/* change_color */
    7.63 +    NULL,			/* change_background */
    7.64 +    NULL,			/* set_font_name */
    7.65 +    NULL,			/* get_color_string */
    7.66 +    NULL,			/* start_screen,*/
    7.67 +    NULL,			/* end_screen,*/
    7.68 +    minhack_outrip,
    7.69 +    minhack_preference_update,
    7.70 +    NULL,			/* status */
    7.71 +    v_hook,			/* print_glyph_layered */
    7.72 +    minhack_send_config_file,
    7.73 +};
    7.74 +
    7.75 +int minhack_init_nhwindows(int *argc, char **argv, char ***capv)
    7.76 +{
    7.77 +    initscr();
    7.78 +    nonl();
    7.79 +    cbreak();
    7.80 +    noecho();
    7.81 +    refresh();
    7.82 +    glyph_map=nhproxy_cb_get_glyph_mapping();
    7.83 +    return nhproxy_true;
    7.84 +}
    7.85 +
    7.86 +int minhack_player_selection(int *role, int *race, int *gend, int *align)
    7.87 +{
    7.88 +    return nhproxy_false;
    7.89 +}
    7.90 +
    7.91 +char *minhack_askname(void)
    7.92 +{
    7.93 +    return "ali";
    7.94 +}
    7.95 +
    7.96 +void minhack_exit_nhwindows(const char *str)
    7.97 +{
    7.98 +    endwin();
    7.99 +    minhack_raw_print(str);
   7.100 +}
   7.101 +
   7.102 +void minhack_curs(int window, int x, int y)
   7.103 +{
   7.104 +    wmove(windows[window].win,y,x);
   7.105 +}
   7.106 +
   7.107 +void minhack_putstr(int window, int attr, const char *str)
   7.108 +{
   7.109 +    waddstr(windows[window].win,str);
   7.110 +}
   7.111 +
   7.112 +void minhack_display_file(int fh)
   7.113 +{
   7.114 +    /* FIXME: Implement */
   7.115 +}
   7.116 +
   7.117 +void minhack_print_glyph(int id, int x, int y, int glyph)
   7.118 +{
   7.119 +    struct nhproxy_glyph_map_info info;
   7.120 +    struct nhproxy_glyph_mapping *map;
   7.121 +    map=nhproxy_glyph_map_first(&info,glyph_map);
   7.122 +    while(glyph--)
   7.123 +	map=nhproxy_glyph_map_next(&info);
   7.124 +    mvwaddch(windows[id].win,y,x,map->rgbsym&0xFF);
   7.125 +    nhproxy_glyph_map_close(&info);
   7.126 +}
   7.127 +
   7.128 +void minhack_raw_print(const char *str)
   7.129 +{
   7.130 +    if (*str)
   7.131 +	puts(str);
   7.132 +}
   7.133 +
   7.134 +void minhack_raw_print_bold(const char *str)
   7.135 +{
   7.136 +    minhack_raw_print(str);
   7.137 +}
   7.138 +
   7.139 +int minhack_nhgetch(void)
   7.140 +{
   7.141 +    int i;
   7.142 +    for(i=0;i<no_windows;i++)
   7.143 +	if (windows[i].win && windows[i].type!=NHPROXY_EXT_NHW_MENU &&
   7.144 +	  windows[i].type!=NHPROXY_EXT_NHW_TEXT)
   7.145 +	    wrefresh(windows[i].win);
   7.146 +    return getch();
   7.147 +}
   7.148 +
   7.149 +int minhack_nh_poskey(int *x, int *y, int *mod)
   7.150 +{
   7.151 +    return minhack_nhgetch();
   7.152 +}
   7.153 +
   7.154 +int minhack_outrip(int window, char *killed_by)
   7.155 +{
   7.156 +    return nhproxy_false;
   7.157 +}
   7.158 +
   7.159 +void minhack_preference_update(const char *optnam, const char *value)
   7.160 +{
   7.161 +}
   7.162 +
   7.163 +void minhack_send_config_file(int fh)
   7.164 +{
   7.165 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/menu.c	Mon Jan 29 20:22:01 2007 +0000
     8.3 @@ -0,0 +1,176 @@
     8.4 +/*
     8.5 + * $Id: menu.c,v 1.5 2004/12/30 09:07:47 ali Exp $
     8.6 + * Copyright (C) 2007 J. Ali Harlow
     8.7 + * Min Hack may be freely redistributed.  See license for details. 
     8.8 + */
     8.9 +
    8.10 +#include <stdlib.h>
    8.11 +#include <stdio.h>
    8.12 +#include <string.h>
    8.13 +#include "minhack.h"
    8.14 +
    8.15 +void minhack_free_menu(int window)
    8.16 +{
    8.17 +    struct minhack_menu *menu=windows[window].menu;
    8.18 +    struct minhack_mitem *item,*next;
    8.19 +    if (menu)
    8.20 +    {
    8.21 +	if (menu->menu)
    8.22 +	{
    8.23 +#if 0
    8.24 +	    delwin(menu_win(menu->menu));
    8.25 +	    delwin(menu_sub(menu->menu));
    8.26 +#endif
    8.27 +	    free_menu(menu->menu);
    8.28 +	}
    8.29 +	for(item=menu->mitems;item;item=next)
    8.30 +	{
    8.31 +	    next=item->next;
    8.32 +	    free_item(item->item);
    8.33 +	    free(item->str);
    8.34 +	    free(item);
    8.35 +	}
    8.36 +	free(menu->items);
    8.37 +    }
    8.38 +    windows[window].menu=NULL;
    8.39 +}
    8.40 +
    8.41 +void minhack_start_menu(int window)
    8.42 +{
    8.43 +    minhack_free_menu(window);
    8.44 +    windows[window].menu=
    8.45 +      (struct minhack_menu *)calloc(1,sizeof(struct minhack_menu));
    8.46 +}
    8.47 +
    8.48 +void minhack_add_menu(int window, int glyph, int identifier, char accelerator,
    8.49 +  char groupacc, int attr, const char *str, nhproxy_bool_t preselected)
    8.50 +{
    8.51 +    struct minhack_mitem *item;
    8.52 +    item=(struct minhack_mitem *)malloc(sizeof(*item));
    8.53 +    item->next=windows[window].menu->mitems;
    8.54 +    item->identifier=identifier;
    8.55 +    if (accelerator)
    8.56 +	item->accelerator=accelerator;
    8.57 +    else if (!item->next)
    8.58 +	item->accelerator='a';
    8.59 +    else if (!identifier)
    8.60 +	item->accelerator=item->next->accelerator;
    8.61 +    else if (item->next->accelerator=='z')
    8.62 +	item->accelerator='A';
    8.63 +    else
    8.64 +	item->accelerator=item->next->accelerator+1;
    8.65 +    item->groupacc=groupacc;
    8.66 +    if (identifier)
    8.67 +    {
    8.68 +	item->str=malloc(strlen(str)+5);
    8.69 +	sprintf(item->str,"%c - %s",item->accelerator,str);
    8.70 +    }
    8.71 +    else if (*str)
    8.72 +	item->str=strdup(str);
    8.73 +    else
    8.74 +	item->str=strdup(" ");
    8.75 +    item->selected=preselected;
    8.76 +    item->item=new_item(item->str,item->str);
    8.77 +    if (!identifier)
    8.78 +	item_opts_off(item->item,O_SELECTABLE);
    8.79 +    windows[window].menu->mitems=item;
    8.80 +}
    8.81 +
    8.82 +static struct minhack_mitem *reverse(struct minhack_mitem *curr)
    8.83 +{
    8.84 +    struct minhack_mitem *next,*head=0;
    8.85 +    while (curr)
    8.86 +    {
    8.87 +	next=curr->next;
    8.88 +	curr->next=head;
    8.89 +	head=curr;
    8.90 +	curr=next;
    8.91 +    }
    8.92 +    return head;
    8.93 +}
    8.94 +
    8.95 +void minhack_end_menu(int window, const char *prompt)
    8.96 +{
    8.97 +    int i,rows,cols;
    8.98 +    struct minhack_mitem *item;
    8.99 +    WINDOW *win;
   8.100 +    windows[window].menu->mitems=reverse(windows[window].menu->mitems);
   8.101 +    if (*prompt)
   8.102 +    {
   8.103 +	minhack_add_menu(window,-1,0,0,0,0,"",FALSE);
   8.104 +	minhack_add_menu(window,-1,0,0,0,0,prompt,FALSE);
   8.105 +    }
   8.106 +    for(i=0,item=windows[window].menu->mitems;item;i++,item=item->next)
   8.107 +	;
   8.108 +    windows[window].menu->items=malloc((i+1)*sizeof(ITEM *));
   8.109 +    for(i=0,item=windows[window].menu->mitems;item;i++,item=item->next)
   8.110 +	windows[window].menu->items[i]=item->item;
   8.111 +    windows[window].menu->items[i]=NULL;
   8.112 +    windows[window].menu->menu=new_menu(windows[window].menu->items);
   8.113 +    scale_menu(windows[window].menu->menu,&rows,&cols);
   8.114 +    {
   8.115 +	char buf[100];
   8.116 +	sprintf(buf,"(%dx%d)",rows,cols);
   8.117 +	minhack_putstr(message_win,0,buf);
   8.118 +    }
   8.119 +#if 0
   8.120 +    win=newwin(rows,cols,0,0);
   8.121 +    set_menu_win(windows[window].menu->menu,win);
   8.122 +#endif
   8.123 +    win=newwin(rows,cols,0,0);
   8.124 +    set_menu_sub(windows[window].menu->menu,win);
   8.125 +    set_menu_win(windows[window].menu->menu,windows[map_win].win);
   8.126 +}
   8.127 +
   8.128 +int minhack_select_menu(int window, int how, struct nhproxy_mi **selected)
   8.129 +{
   8.130 +    int i,j,ch;
   8.131 +    struct minhack_mitem *item;
   8.132 +    if (how==MINHACK_PICK_ANY)
   8.133 +	menu_opts_off(windows[window].menu->menu,O_ONEVALUE);
   8.134 +    menu_opts_off(windows[window].menu->menu,O_IGNORECASE);
   8.135 +    menu_opts_off(windows[window].menu->menu,O_SHOWDESC);
   8.136 +    i=post_menu(windows[window].menu->menu);
   8.137 +    for(;;)
   8.138 +    {
   8.139 +	wrefresh(menu_win(windows[window].menu->menu));
   8.140 +#if 1
   8.141 +	wrefresh(menu_sub(windows[window].menu->menu));
   8.142 +#endif
   8.143 +	ch=getch();
   8.144 +	if (ch=='\033')
   8.145 +	{
   8.146 +	    i=how==MINHACK_PICK_NONE?0:-1;
   8.147 +	    break;
   8.148 +	}
   8.149 +	else if (ch>=' ' && ch<='~')
   8.150 +	    if (menu_driver(windows[window].menu->menu,ch)==E_OK)
   8.151 +	    {
   8.152 +		for(i=0,item=windows[window].menu->mitems;item;item=item->next)
   8.153 +		    if (item_value(item->item))
   8.154 +			i++;
   8.155 +		*selected=(struct nhproxy_mi *)calloc(i,
   8.156 +		  sizeof(struct nhproxy_mi));
   8.157 +		for(i=0,item=windows[window].menu->mitems;item;item=item->next)
   8.158 +		    if (item_value(item->item))
   8.159 +		    {
   8.160 +			(*selected)[i].item=item->identifier;
   8.161 +			(*selected)[i].count=-1;	/* FIXME */
   8.162 +		    }
   8.163 +		break;
   8.164 +	    }
   8.165 +    }
   8.166 +    unpost_menu(windows[window].menu->menu);
   8.167 +    redrawwin(menu_win(windows[window].menu->menu));
   8.168 +#if 0
   8.169 +    for(j=0;j<no_windows;j++)
   8.170 +	if (windows[j].win)
   8.171 +	    redrawwin(windows[j].win);
   8.172 +#endif
   8.173 +    return i;
   8.174 +}
   8.175 +
   8.176 +int minhack_message_menu(int let, int how, const char *mesg)
   8.177 +{
   8.178 +    return -1;
   8.179 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/message.c	Mon Jan 29 20:22:01 2007 +0000
     9.3 @@ -0,0 +1,129 @@
     9.4 +/*
     9.5 + * $Id: message.c,v 1.5 2004/12/30 09:07:47 ali Exp $
     9.6 + * Copyright (C) 2007 J. Ali Harlow
     9.7 + * Min Hack may be freely redistributed.  See license for details. 
     9.8 + */
     9.9 +
    9.10 +#include <stdlib.h>
    9.11 +#include <stdio.h>
    9.12 +#include <string.h>
    9.13 +#include "minhack.h"
    9.14 +
    9.15 +char minhack_yn_function(const char *ques, const char *choices, char def,
    9.16 +  int *count)
    9.17 +{
    9.18 +    int i,x,ch,n=0,cnt=0;
    9.19 +    waddstr(windows[message_win].win,ques);
    9.20 +    if (*choices)
    9.21 +    {
    9.22 +	waddstr(windows[message_win].win," [");
    9.23 +	for(i=0;choices[i] && choices[i]!='\033';i++)
    9.24 +	    waddch(windows[message_win].win,choices[i]);
    9.25 +	waddstr(windows[message_win].win,"] ");
    9.26 +	if (def)
    9.27 +	{
    9.28 +	    char buf[5];
    9.29 +	    sprintf(buf,"(%c) ",def);
    9.30 +	    waddstr(windows[message_win].win,buf);
    9.31 +	}
    9.32 +	wclrtoeol(windows[message_win].win);
    9.33 +	getyx(windows[message_win].win,i,x);
    9.34 +	for(;;)
    9.35 +	{
    9.36 +	    ch=wgetch(windows[message_win].win);
    9.37 +	    switch(ch)
    9.38 +	    {
    9.39 +		case '\033':
    9.40 +		    if (strchr(choices,'q'))
    9.41 +			return 'q';
    9.42 +		    else if (strchr(choices,'n'))
    9.43 +			return 'n';
    9.44 +		    else
    9.45 +			return def;
    9.46 +		    break;
    9.47 +		case ' ':
    9.48 +		case '\r':
    9.49 +		case '\n':
    9.50 +		    return def;
    9.51 +		    break;
    9.52 +		default:
    9.53 +		    if (strchr(choices,'#') && strchr("0123456789",ch))
    9.54 +		    {
    9.55 +			waddch(windows[message_win].win,ch);
    9.56 +			n++;
    9.57 +			cnt*=10;
    9.58 +			cnt+=ch-'0';
    9.59 +		    }
    9.60 +		    else if (strchr(choices,ch))
    9.61 +		    {
    9.62 +			if (n)
    9.63 +			    *count=cnt;
    9.64 +			return ch;
    9.65 +		    }
    9.66 +		    else if (cnt && (ch=='\b' || ch==127))
    9.67 +		    {
    9.68 +			n--;
    9.69 +			wmove(windows[message_win].win,0,n+x);
    9.70 +			wclrtoeol(windows[message_win].win);
    9.71 +			cnt/=10;
    9.72 +		    }
    9.73 +		    break;
    9.74 +	    }
    9.75 +	}
    9.76 +    }
    9.77 +    else
    9.78 +	return wgetch(windows[message_win].win);
    9.79 +}
    9.80 +
    9.81 +char *minhack_getlin(const char *query)
    9.82 +{
    9.83 +    int ch,n=0,x,i,j;
    9.84 +    static char line[80];
    9.85 +    nhproxy_cb_flush_screen();
    9.86 +    minhack_putstr(message_win,0,query);
    9.87 +    wclrtoeol(windows[message_win].win);
    9.88 +    getyx(windows[message_win].win,i,x);
    9.89 +    for(;;)
    9.90 +    {
    9.91 +	ch=wgetch(windows[message_win].win);
    9.92 +	if (ch>=' ' && ch<='~' && n<sizeof(line)-1)
    9.93 +	{
    9.94 +	    waddch(windows[message_win].win,ch);
    9.95 +	    line[n++]=ch;
    9.96 +	}
    9.97 +	else if (n && (ch=='\b' || ch==127))
    9.98 +	{
    9.99 +	    n--;
   9.100 +	    wmove(windows[message_win].win,0,n+x);
   9.101 +	    wclrtoeol(windows[message_win].win);
   9.102 +	}
   9.103 +	else if (ch=='\n' || ch=='\r')
   9.104 +	{
   9.105 +	    line[n]='\0';
   9.106 +	    return line;
   9.107 +	}
   9.108 +	else if (ch=='\033')
   9.109 +	{
   9.110 +	    line[0]='\033';
   9.111 +	    line[1]='\0';
   9.112 +	    return line;
   9.113 +	}
   9.114 +    }
   9.115 +}
   9.116 +
   9.117 +int minhack_get_ext_cmd(void)
   9.118 +{
   9.119 +    int i,cmd=-1;
   9.120 +    char *line;
   9.121 +    struct nhproxy_cb_get_extended_commands_res *commands;
   9.122 +    commands=nhproxy_cb_get_extended_commands();
   9.123 +    line=minhack_getlin("# ");
   9.124 +    for(i=0;i<commands->n_commands;i++)
   9.125 +	if (!strcmp(commands->commands[i],line))
   9.126 +	{
   9.127 +	    cmd=i;
   9.128 +	    break;
   9.129 +	}
   9.130 +    nhproxy_cb_free_extended_commands(commands);
   9.131 +    return cmd;
   9.132 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/minhack.c	Mon Jan 29 20:22:01 2007 +0000
    10.3 @@ -0,0 +1,19 @@
    10.4 +#include <nhproxy/nhproxy.h>
    10.5 +#include "minhack.h"
    10.6 +
    10.7 +void
    10.8 +init(void)
    10.9 +{
   10.10 +}
   10.11 +
   10.12 +int
   10.13 +main(int argc, char **argv)
   10.14 +{
   10.15 +    nhproxy_clnt_set_ext_procs(init, &minhack_ext_procs);
   10.16 +#if 0
   10.17 +    if (nhproxy_clnt_connect("tcp", "games.forkexec.com:23277", &argc, argv))
   10.18 +#else
   10.19 +    if (nhproxy_clnt_connect("file", "/usr/local/bin/slashem", &argc, argv))
   10.20 +#endif
   10.21 +	nhproxy_clnt_main();
   10.22 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/minhack.h	Mon Jan 29 20:22:01 2007 +0000
    11.3 @@ -0,0 +1,80 @@
    11.4 +/*
    11.5 + * $Id: minhack.h,v 1.56 2005/02/02 09:36:01 j_ali Exp $
    11.6 + * Copyright (C) 2007 J. Ali Harlow
    11.7 + * Minimal Hack may be freely redistributed.  See license for details.
    11.8 + */
    11.9 +
   11.10 +#ifndef MINHACK_H
   11.11 +#define MINHACK_H
   11.12 +
   11.13 +#include <nhproxy/nhproxy.h>
   11.14 +
   11.15 +#include "config.h"
   11.16 +#include <curses.h>
   11.17 +#include <menu.h>
   11.18 +
   11.19 +#define MINHACK_PICK_NONE	0
   11.20 +#define MINHACK_PICK_ONE	1
   11.21 +#define MINHACK_PICK_ANY	2
   11.22 +
   11.23 +struct minhack_mitem {
   11.24 +    struct minhack_mitem *next;
   11.25 +    int identifier;
   11.26 +    int accelerator;
   11.27 +    int groupacc;
   11.28 +    char *str;
   11.29 +    nhproxy_bool_t selected;
   11.30 +    ITEM *item;
   11.31 +};
   11.32 +
   11.33 +struct minhack_menu {
   11.34 +    struct minhack_mitem *mitems;
   11.35 +    ITEM **items;
   11.36 +    MENU *menu;
   11.37 +};
   11.38 +
   11.39 +struct minhack_window {
   11.40 +    nhproxy_bool_t in_use;
   11.41 +    int type;
   11.42 +    struct minhack_menu *menu;
   11.43 +    WINDOW *win;
   11.44 +};
   11.45 +
   11.46 +extern struct nhproxy_clnt_ext_procs minhack_ext_procs;
   11.47 +extern struct minhack_window *windows;
   11.48 +extern int no_windows;
   11.49 +extern int message_win,map_win;
   11.50 +
   11.51 +extern int minhack_init_nhwindows(int *, char **, char ***);
   11.52 +extern int minhack_player_selection(int *, int *, int *, int *);
   11.53 +extern char *minhack_askname(void);
   11.54 +extern void minhack_exit_nhwindows(const char *);
   11.55 +extern int minhack_create_nhwindow(int);
   11.56 +extern void minhack_clear_nhwindow(int, int, int, int);
   11.57 +extern void minhack_display_nhwindow(int, NHPROXY_BOOLEAN_P);
   11.58 +extern void minhack_destroy_nhwindow(int);
   11.59 +extern void minhack_curs(int, int, int);
   11.60 +extern void minhack_putstr(int, int, const char *);
   11.61 +extern void minhack_display_file(int fh);
   11.62 +extern void minhack_start_menu(int);
   11.63 +extern void minhack_add_menu(int, int, int, NHPROXY_CHAR_P, NHPROXY_CHAR_P,
   11.64 +  int, const char *, NHPROXY_BOOLEAN_P);
   11.65 +extern void minhack_end_menu(int, const char *);
   11.66 +extern int minhack_select_menu(int, int, struct nhproxy_mi **);
   11.67 +extern int minhack_message_menu(int let, int how, const char *mesg);
   11.68 +extern void minhack_print_glyph(int id, int x, int y, int glyph);
   11.69 +extern void minhack_raw_print(const char *);
   11.70 +extern void minhack_raw_print_bold(const char *);
   11.71 +extern int minhack_nhgetch(void);
   11.72 +extern int minhack_nh_poskey(int *, int *, int *);
   11.73 +extern char minhack_yn_function(const char *, const char *, NHPROXY_CHAR_P,
   11.74 +  int *);
   11.75 +extern char *minhack_getlin(const char *query);
   11.76 +extern int minhack_get_ext_cmd(void);
   11.77 +extern int minhack_outrip(int, char *);
   11.78 +extern void minhack_preference_update(const char *, const char *);
   11.79 +extern void minhack_send_config_file(int);
   11.80 +
   11.81 +extern void minhack_free_menu(int window);
   11.82 +
   11.83 +#endif	/* MINHACK_H */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/window.c	Mon Jan 29 20:22:01 2007 +0000
    12.3 @@ -0,0 +1,78 @@
    12.4 +/*
    12.5 + * $Id: window.c,v 1.5 2004/12/30 09:07:47 ali Exp $
    12.6 + * Copyright (C) 2007 J. Ali Harlow
    12.7 + * Min Hack may be freely redistributed.  See license for details. 
    12.8 + */
    12.9 +
   12.10 +#include <stdlib.h>
   12.11 +#include <stdio.h>
   12.12 +#include <string.h>
   12.13 +#include "minhack.h"
   12.14 +
   12.15 +int message_win=-1;
   12.16 +int map_win=-1;
   12.17 +
   12.18 +int minhack_create_nhwindow(int type)
   12.19 +{
   12.20 +    int window;
   12.21 +    for(window=0;window<no_windows;window++)
   12.22 +	if (!windows[window].in_use)
   12.23 +	    break;
   12.24 +    if (window==no_windows)
   12.25 +	windows=realloc(windows,++no_windows*sizeof(*windows));
   12.26 +    windows[window].in_use=nhproxy_true;
   12.27 +    windows[window].type=type;
   12.28 +    windows[window].menu=NULL;
   12.29 +    switch(type)
   12.30 +    {
   12.31 +	case NHPROXY_EXT_NHW_MESSAGE:
   12.32 +	    windows[window].win=newwin(1,0,0,0);
   12.33 +	    if (message_win<0)
   12.34 +		message_win=window;
   12.35 +	    break;
   12.36 +	case NHPROXY_EXT_NHW_STATUS:
   12.37 +	    windows[window].win=newwin(2,0,LINES-2,0);
   12.38 +	    break;
   12.39 +	case NHPROXY_EXT_NHW_MAP:
   12.40 +	    if (map_win<0)
   12.41 +		map_win=window;
   12.42 +	    /* Fall through */
   12.43 +	case NHPROXY_EXT_NHW_MENU:
   12.44 +	case NHPROXY_EXT_NHW_TEXT:
   12.45 +	    windows[window].win=NULL;
   12.46 +	    break;
   12.47 +    }
   12.48 +    return window;
   12.49 +}
   12.50 +
   12.51 +void minhack_clear_nhwindow(int window, int rows, int cols, int layers)
   12.52 +{
   12.53 +    if (windows[window].type==NHPROXY_EXT_NHW_MAP)
   12.54 +    {
   12.55 +	if (windows[window].win)
   12.56 +	    delwin(windows[window].win);
   12.57 +	windows[window].win=newwin(rows,cols,1,0);
   12.58 +    }
   12.59 +    else
   12.60 +	werase(windows[window].win);
   12.61 +}
   12.62 +
   12.63 +void minhack_display_nhwindow(int window, nhproxy_bool_t blocking)
   12.64 +{
   12.65 +    wrefresh(windows[window].win);
   12.66 +}
   12.67 +
   12.68 +void minhack_destroy_nhwindow(int window)
   12.69 +{
   12.70 +    minhack_free_menu(window);
   12.71 +    if (windows[window].win)
   12.72 +    {
   12.73 +	delwin(windows[window].win);
   12.74 +	windows[window].win=NULL;
   12.75 +    }
   12.76 +    if (window==message_win)
   12.77 +	message_win=-1;
   12.78 +    else if (window==map_win)
   12.79 +	map_win=-1;
   12.80 +    windows[window].in_use=nhproxy_false;
   12.81 +}