# HG changeset patch # User ali@juiblex.co.uk # Date 1170102121 0 # Node ID acc07f1f4b1e7c37b9bdda44266767bb7764fe8f Initial check-in. Mostly sort of works. Ish. diff -r 000000000000 -r acc07f1f4b1e ChangeLog --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ChangeLog Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,3 @@ +2007-01-29 J. Ali Harlow + + Initial check-in diff -r 000000000000 -r acc07f1f4b1e Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile.am Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,7 @@ +## $Id: Makefile.am,v 1.1 2004/12/30 09:07:43 ali Exp $ +## Copyright (C) 2007 J. Ali Harlow +## Minimal Hack may be freely redistributed. See license for details. + +SUBDIRS = src + +EXTRA_DIST = license.txt diff -r 000000000000 -r acc07f1f4b1e bootstrap.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bootstrap.sh Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,8 @@ +#!/bin/sh +# +# $Id: bootstrap.sh,v 1.1 2004/12/30 09:07:43 ali Exp $ +# +autoheader && \ + aclocal && \ + automake --foreign --add-missing && \ + autoconf diff -r 000000000000 -r acc07f1f4b1e configure.ac --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/configure.ac Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,45 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. +# Copyright (C) 2007 J. Ali Harlow +# Minimal Hack may be freely redistributed. See license for details. + +AC_INIT([minhack], [0.1], [ali@juiblex.co.uk]) +AC_PREREQ(2.59) +AC_REVISION($Id: configure.ac,v 1.2 2005/01/22 18:39:17 j_ali Exp $) +AC_CONFIG_AUX_DIR([config]) +AC_CONFIG_SRCDIR([src/minhack.c]) +AC_CONFIG_HEADER([config.h]) +AC_CONFIG_FILES([Makefile +src/Makefile +]) +AM_INIT_AUTOMAKE(no-define) + +################################################## +# Checks for programs. +################################################## +AC_PROG_CC + +################################################## +# Checks for header files. +################################################## +AC_HEADER_STDC + +################################################## +# Checks for typedefs, structures, and compiler characteristics. +################################################## + +################################################## +# Checks for libraries. +################################################## +PKG_CHECK_MODULES(MINHACK, nhproxy >= 0.9.0) + +################################################## +# Checks for optional features. +################################################## + +################################################## +# Generate the various configured files +################################################## +AC_SUBST(MINHACK_CFLAGS) +AC_SUBST(MINHACK_LIBS) +AC_OUTPUT diff -r 000000000000 -r acc07f1f4b1e license.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/license.txt Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,95 @@ + NETHACK GENERAL PUBLIC LICENSE + (Copyright 1989 M. Stephenson) + + (Based on the BISON general public license, + copyright 1988 Richard M. Stallman) + + Everyone is permitted to copy and distribute verbatim copies of this + license, but changing it is not allowed. You can also use this wording to + make the terms for other programs. + + The license agreements of most software companies keep you at the mercy of +those companies. By contrast, our general public license is intended to give +everyone the right to share NetHack. To make sure that you get the rights we +want you to have, we need to make restrictions that forbid anyone to deny you +these rights or to ask you to surrender the rights. Hence this license +agreement. + + Specifically, we want to make sure that you have the right to give away +copies of NetHack, that you receive source code or else can get it if you +want it, that you can change NetHack or use pieces of it in new free +programs, and that you know you can do these things. + + To make sure that everyone has such rights, we have to forbid you to +deprive anyone else of these rights. For example, if you distribute copies +of NetHack, you must give the recipients all the rights that you have. You +must make sure that they, too, receive or can get the source code. And you +must tell them their rights. + + Also, for our own protection, we must make certain that everyone finds out +that there is no warranty for NetHack. If NetHack is modified by someone +else and passed on, we want its recipients to know that what they have is +not what we distributed. + + Therefore we (Mike Stephenson and other holders of NetHack copyrights) make +the following terms which say what you must do to be allowed to distribute or +change NetHack. + + + COPYING POLICIES + + 1. You may copy and distribute verbatim copies of NetHack source code as +you receive it, in any medium, provided that you keep intact the notices on +all files that refer to copyrights, to this License Agreement, and to the +absence of any warranty; and give any other recipients of the NetHack +program a copy of this License Agreement along with the program. + + 2. You may modify your copy or copies of NetHack or any portion of it, and +copy and distribute such modifications under the terms of Paragraph 1 above +(including distributing this License Agreement), provided that you also do the +following: + + a) cause the modified files to carry prominent notices stating that you + changed the files and the date of any change; and + + b) cause the whole of any work that you distribute or publish, that in + whole or in part contains or is a derivative of NetHack or any part + thereof, to be licensed at no charge to all third parties on terms + identical to those contained in this License Agreement (except that you + may choose to grant more extensive warranty protection to some or all + third parties, at your option) + + c) You may charge a distribution fee for the physical act of + transferring a copy, and you may at your option offer warranty protection + in exchange for a fee. + + 3. You may copy and distribute NetHack (or a portion or derivative of it, +under Paragraph 2) in object code or executable form under the terms of +Paragraphs 1 and 2 above provided that you also do one of the following: + + a) accompany it with the complete machine-readable source code, which + must be distributed under the terms of Paragraphs 1 and 2 above; or, + + b) accompany it with full information as to how to obtain the complete + machine-readable source code from an appropriate archive site. (This + alternative is allowed only for noncommercial distribution.) + +For these purposes, complete source code means either the full source +distribution as originally released over Usenet or updated copies of the +files in this distribution used to create the object code or executable. + + 4. You may not copy, sublicense, distribute or transfer NetHack except as +expressly provided under this License Agreement. Any attempt otherwise to +copy, sublicense, distribute or transfer NetHack is void and your rights to +use the program under this License agreement shall be automatically +terminated. However, parties who have received computer software programs +from you with this License Agreement will not have their licenses terminated +so long as such parties remain in full compliance. + + +Stated plainly: You are permitted to modify NetHack, or otherwise use parts +of NetHack, provided that you comply with the conditions specified above; +in particular, your modified NetHack or program containing parts of NetHack +must remain freely available as provided in this License Agreement. In +other words, go ahead and share NetHack, but don't try to stop anyone else +from sharing it farther. diff -r 000000000000 -r acc07f1f4b1e src/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Makefile.am Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,10 @@ +## $Id: Makefile.am,v 1.1 2004/12/30 09:07:46 ali Exp $ +## Copyright (C) 2007 J. Ali Harlow +## Minimal Hack may be freely redistributed. See license for details. + +INCLUDES = -I$(top_srcdir) +AM_CFLAGS = $(MINHACK_CFLAGS) -g +LDADD = $(MINHACK_LIBS) -lmenu -lncurses + +bin_PROGRAMS = minhack +minhack_SOURCES = minhack.c minhack.h extprocs.c menu.c message.c window.c diff -r 000000000000 -r acc07f1f4b1e src/extprocs.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/extprocs.c Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,162 @@ +/* + * $Id: extprocs.c,v 1.5 2004/12/30 09:07:47 ali Exp $ + * Copyright (C) 2007 J. Ali Harlow + * Min Hack may be freely redistributed. See license for details. + */ + +#include +#include +#include +#include "minhack.h" + +struct nhproxy_cb_get_glyph_mapping_res *glyph_map; +struct minhack_window *windows=NULL; +int no_windows=0; + +static int v_hook(void) +{ + fprintf(stderr,"v_hook called\n"); +} + +struct nhproxy_clnt_ext_procs minhack_ext_procs = { + "minhack", + minhack_init_nhwindows, + minhack_player_selection, + minhack_askname, + NULL, /* get_nh_event */ + minhack_exit_nhwindows, + NULL, /* suspend_nhwindows */ + NULL, /* resume_nhwindows */ + minhack_create_nhwindow, + minhack_clear_nhwindow, + minhack_display_nhwindow, + minhack_destroy_nhwindow, + minhack_curs, + minhack_putstr, + minhack_display_file, + minhack_start_menu, + minhack_add_menu, + minhack_end_menu, + minhack_select_menu, + minhack_message_menu, + NULL, /* update_inventory */ + NULL, /* mark_sync */ + NULL, /* wait_sync */ + NULL, /* cliparound */ + NULL, /* update_positionbar */ + minhack_print_glyph, + minhack_raw_print, + minhack_raw_print_bold, + minhack_nhgetch, + minhack_nh_poskey, + NULL, /* nhbell */ + NULL, /* doprev_message */ + minhack_yn_function, + minhack_getlin, + minhack_get_ext_cmd, + NULL, /* number_pad */ + NULL, /* delay_output */ + NULL, /* change_color */ + NULL, /* change_background */ + NULL, /* set_font_name */ + NULL, /* get_color_string */ + NULL, /* start_screen,*/ + NULL, /* end_screen,*/ + minhack_outrip, + minhack_preference_update, + NULL, /* status */ + v_hook, /* print_glyph_layered */ + minhack_send_config_file, +}; + +int minhack_init_nhwindows(int *argc, char **argv, char ***capv) +{ + initscr(); + nonl(); + cbreak(); + noecho(); + refresh(); + glyph_map=nhproxy_cb_get_glyph_mapping(); + return nhproxy_true; +} + +int minhack_player_selection(int *role, int *race, int *gend, int *align) +{ + return nhproxy_false; +} + +char *minhack_askname(void) +{ + return "ali"; +} + +void minhack_exit_nhwindows(const char *str) +{ + endwin(); + minhack_raw_print(str); +} + +void minhack_curs(int window, int x, int y) +{ + wmove(windows[window].win,y,x); +} + +void minhack_putstr(int window, int attr, const char *str) +{ + waddstr(windows[window].win,str); +} + +void minhack_display_file(int fh) +{ + /* FIXME: Implement */ +} + +void minhack_print_glyph(int id, int x, int y, int glyph) +{ + struct nhproxy_glyph_map_info info; + struct nhproxy_glyph_mapping *map; + map=nhproxy_glyph_map_first(&info,glyph_map); + while(glyph--) + map=nhproxy_glyph_map_next(&info); + mvwaddch(windows[id].win,y,x,map->rgbsym&0xFF); + nhproxy_glyph_map_close(&info); +} + +void minhack_raw_print(const char *str) +{ + if (*str) + puts(str); +} + +void minhack_raw_print_bold(const char *str) +{ + minhack_raw_print(str); +} + +int minhack_nhgetch(void) +{ + int i; + for(i=0;i +#include +#include +#include "minhack.h" + +void minhack_free_menu(int window) +{ + struct minhack_menu *menu=windows[window].menu; + struct minhack_mitem *item,*next; + if (menu) + { + if (menu->menu) + { +#if 0 + delwin(menu_win(menu->menu)); + delwin(menu_sub(menu->menu)); +#endif + free_menu(menu->menu); + } + for(item=menu->mitems;item;item=next) + { + next=item->next; + free_item(item->item); + free(item->str); + free(item); + } + free(menu->items); + } + windows[window].menu=NULL; +} + +void minhack_start_menu(int window) +{ + minhack_free_menu(window); + windows[window].menu= + (struct minhack_menu *)calloc(1,sizeof(struct minhack_menu)); +} + +void minhack_add_menu(int window, int glyph, int identifier, char accelerator, + char groupacc, int attr, const char *str, nhproxy_bool_t preselected) +{ + struct minhack_mitem *item; + item=(struct minhack_mitem *)malloc(sizeof(*item)); + item->next=windows[window].menu->mitems; + item->identifier=identifier; + if (accelerator) + item->accelerator=accelerator; + else if (!item->next) + item->accelerator='a'; + else if (!identifier) + item->accelerator=item->next->accelerator; + else if (item->next->accelerator=='z') + item->accelerator='A'; + else + item->accelerator=item->next->accelerator+1; + item->groupacc=groupacc; + if (identifier) + { + item->str=malloc(strlen(str)+5); + sprintf(item->str,"%c - %s",item->accelerator,str); + } + else if (*str) + item->str=strdup(str); + else + item->str=strdup(" "); + item->selected=preselected; + item->item=new_item(item->str,item->str); + if (!identifier) + item_opts_off(item->item,O_SELECTABLE); + windows[window].menu->mitems=item; +} + +static struct minhack_mitem *reverse(struct minhack_mitem *curr) +{ + struct minhack_mitem *next,*head=0; + while (curr) + { + next=curr->next; + curr->next=head; + head=curr; + curr=next; + } + return head; +} + +void minhack_end_menu(int window, const char *prompt) +{ + int i,rows,cols; + struct minhack_mitem *item; + WINDOW *win; + windows[window].menu->mitems=reverse(windows[window].menu->mitems); + if (*prompt) + { + minhack_add_menu(window,-1,0,0,0,0,"",FALSE); + minhack_add_menu(window,-1,0,0,0,0,prompt,FALSE); + } + for(i=0,item=windows[window].menu->mitems;item;i++,item=item->next) + ; + windows[window].menu->items=malloc((i+1)*sizeof(ITEM *)); + for(i=0,item=windows[window].menu->mitems;item;i++,item=item->next) + windows[window].menu->items[i]=item->item; + windows[window].menu->items[i]=NULL; + windows[window].menu->menu=new_menu(windows[window].menu->items); + scale_menu(windows[window].menu->menu,&rows,&cols); + { + char buf[100]; + sprintf(buf,"(%dx%d)",rows,cols); + minhack_putstr(message_win,0,buf); + } +#if 0 + win=newwin(rows,cols,0,0); + set_menu_win(windows[window].menu->menu,win); +#endif + win=newwin(rows,cols,0,0); + set_menu_sub(windows[window].menu->menu,win); + set_menu_win(windows[window].menu->menu,windows[map_win].win); +} + +int minhack_select_menu(int window, int how, struct nhproxy_mi **selected) +{ + int i,j,ch; + struct minhack_mitem *item; + if (how==MINHACK_PICK_ANY) + menu_opts_off(windows[window].menu->menu,O_ONEVALUE); + menu_opts_off(windows[window].menu->menu,O_IGNORECASE); + menu_opts_off(windows[window].menu->menu,O_SHOWDESC); + i=post_menu(windows[window].menu->menu); + for(;;) + { + wrefresh(menu_win(windows[window].menu->menu)); +#if 1 + wrefresh(menu_sub(windows[window].menu->menu)); +#endif + ch=getch(); + if (ch=='\033') + { + i=how==MINHACK_PICK_NONE?0:-1; + break; + } + else if (ch>=' ' && ch<='~') + if (menu_driver(windows[window].menu->menu,ch)==E_OK) + { + for(i=0,item=windows[window].menu->mitems;item;item=item->next) + if (item_value(item->item)) + i++; + *selected=(struct nhproxy_mi *)calloc(i, + sizeof(struct nhproxy_mi)); + for(i=0,item=windows[window].menu->mitems;item;item=item->next) + if (item_value(item->item)) + { + (*selected)[i].item=item->identifier; + (*selected)[i].count=-1; /* FIXME */ + } + break; + } + } + unpost_menu(windows[window].menu->menu); + redrawwin(menu_win(windows[window].menu->menu)); +#if 0 + for(j=0;j +#include +#include +#include "minhack.h" + +char minhack_yn_function(const char *ques, const char *choices, char def, + int *count) +{ + int i,x,ch,n=0,cnt=0; + waddstr(windows[message_win].win,ques); + if (*choices) + { + waddstr(windows[message_win].win," ["); + for(i=0;choices[i] && choices[i]!='\033';i++) + waddch(windows[message_win].win,choices[i]); + waddstr(windows[message_win].win,"] "); + if (def) + { + char buf[5]; + sprintf(buf,"(%c) ",def); + waddstr(windows[message_win].win,buf); + } + wclrtoeol(windows[message_win].win); + getyx(windows[message_win].win,i,x); + for(;;) + { + ch=wgetch(windows[message_win].win); + switch(ch) + { + case '\033': + if (strchr(choices,'q')) + return 'q'; + else if (strchr(choices,'n')) + return 'n'; + else + return def; + break; + case ' ': + case '\r': + case '\n': + return def; + break; + default: + if (strchr(choices,'#') && strchr("0123456789",ch)) + { + waddch(windows[message_win].win,ch); + n++; + cnt*=10; + cnt+=ch-'0'; + } + else if (strchr(choices,ch)) + { + if (n) + *count=cnt; + return ch; + } + else if (cnt && (ch=='\b' || ch==127)) + { + n--; + wmove(windows[message_win].win,0,n+x); + wclrtoeol(windows[message_win].win); + cnt/=10; + } + break; + } + } + } + else + return wgetch(windows[message_win].win); +} + +char *minhack_getlin(const char *query) +{ + int ch,n=0,x,i,j; + static char line[80]; + nhproxy_cb_flush_screen(); + minhack_putstr(message_win,0,query); + wclrtoeol(windows[message_win].win); + getyx(windows[message_win].win,i,x); + for(;;) + { + ch=wgetch(windows[message_win].win); + if (ch>=' ' && ch<='~' && nn_commands;i++) + if (!strcmp(commands->commands[i],line)) + { + cmd=i; + break; + } + nhproxy_cb_free_extended_commands(commands); + return cmd; +} diff -r 000000000000 -r acc07f1f4b1e src/minhack.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/minhack.c Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,19 @@ +#include +#include "minhack.h" + +void +init(void) +{ +} + +int +main(int argc, char **argv) +{ + nhproxy_clnt_set_ext_procs(init, &minhack_ext_procs); +#if 0 + if (nhproxy_clnt_connect("tcp", "games.forkexec.com:23277", &argc, argv)) +#else + if (nhproxy_clnt_connect("file", "/usr/local/bin/slashem", &argc, argv)) +#endif + nhproxy_clnt_main(); +} diff -r 000000000000 -r acc07f1f4b1e src/minhack.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/minhack.h Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,80 @@ +/* + * $Id: minhack.h,v 1.56 2005/02/02 09:36:01 j_ali Exp $ + * Copyright (C) 2007 J. Ali Harlow + * Minimal Hack may be freely redistributed. See license for details. + */ + +#ifndef MINHACK_H +#define MINHACK_H + +#include + +#include "config.h" +#include +#include + +#define MINHACK_PICK_NONE 0 +#define MINHACK_PICK_ONE 1 +#define MINHACK_PICK_ANY 2 + +struct minhack_mitem { + struct minhack_mitem *next; + int identifier; + int accelerator; + int groupacc; + char *str; + nhproxy_bool_t selected; + ITEM *item; +}; + +struct minhack_menu { + struct minhack_mitem *mitems; + ITEM **items; + MENU *menu; +}; + +struct minhack_window { + nhproxy_bool_t in_use; + int type; + struct minhack_menu *menu; + WINDOW *win; +}; + +extern struct nhproxy_clnt_ext_procs minhack_ext_procs; +extern struct minhack_window *windows; +extern int no_windows; +extern int message_win,map_win; + +extern int minhack_init_nhwindows(int *, char **, char ***); +extern int minhack_player_selection(int *, int *, int *, int *); +extern char *minhack_askname(void); +extern void minhack_exit_nhwindows(const char *); +extern int minhack_create_nhwindow(int); +extern void minhack_clear_nhwindow(int, int, int, int); +extern void minhack_display_nhwindow(int, NHPROXY_BOOLEAN_P); +extern void minhack_destroy_nhwindow(int); +extern void minhack_curs(int, int, int); +extern void minhack_putstr(int, int, const char *); +extern void minhack_display_file(int fh); +extern void minhack_start_menu(int); +extern void minhack_add_menu(int, int, int, NHPROXY_CHAR_P, NHPROXY_CHAR_P, + int, const char *, NHPROXY_BOOLEAN_P); +extern void minhack_end_menu(int, const char *); +extern int minhack_select_menu(int, int, struct nhproxy_mi **); +extern int minhack_message_menu(int let, int how, const char *mesg); +extern void minhack_print_glyph(int id, int x, int y, int glyph); +extern void minhack_raw_print(const char *); +extern void minhack_raw_print_bold(const char *); +extern int minhack_nhgetch(void); +extern int minhack_nh_poskey(int *, int *, int *); +extern char minhack_yn_function(const char *, const char *, NHPROXY_CHAR_P, + int *); +extern char *minhack_getlin(const char *query); +extern int minhack_get_ext_cmd(void); +extern int minhack_outrip(int, char *); +extern void minhack_preference_update(const char *, const char *); +extern void minhack_send_config_file(int); + +extern void minhack_free_menu(int window); + +#endif /* MINHACK_H */ diff -r 000000000000 -r acc07f1f4b1e src/window.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/window.c Mon Jan 29 20:22:01 2007 +0000 @@ -0,0 +1,78 @@ +/* + * $Id: window.c,v 1.5 2004/12/30 09:07:47 ali Exp $ + * Copyright (C) 2007 J. Ali Harlow + * Min Hack may be freely redistributed. See license for details. + */ + +#include +#include +#include +#include "minhack.h" + +int message_win=-1; +int map_win=-1; + +int minhack_create_nhwindow(int type) +{ + int window; + for(window=0;window