Author: Eric Herman Date: 2009-09-27 Initial Package Version: nethack-3.4.3 Upstream Status: Not submitted Description: allows the integration of an external script for posting scores set the 'postcommand' in the .nethackrc file and the script specied will be executed upon game completion with the nethack score data. If the .nethackrc file defines 'postuserdata' the additional data will be added as arguments. I test this with the following defined by the path in 'postcommand' and my twitter_name:password defined as my 'postuserdata' #!/bin/bash # trim leading and trailing whitespace & compress remaining whitespace export TWEET=$(echo ${1}); curl -u ${2} -d status="${TWEET}" http://twitter.com/statuses/update.xml diff -Naur nethack-3.4.3.orig/include/decl.h nethack-3.4.3.post/include/decl.h --- nethack-3.4.3.orig/include/decl.h 2003-12-08 00:39:13.000000000 +0100 +++ nethack-3.4.3.post/include/decl.h 2009-09-27 20:37:32.000000000 +0200 @@ -385,6 +385,10 @@ }; #endif /* AUTOPICKUP_EXCEPTIONS */ +E NEARDATA char postcommand[]; +E NEARDATA char postuserdata[]; +E NEARDATA char postscoredata[]; + #undef E #endif /* DECL_H */ diff -Naur nethack-3.4.3.orig/src/decl.c nethack-3.4.3.post/src/decl.c --- nethack-3.4.3.orig/src/decl.c 2003-12-08 00:39:13.000000000 +0100 +++ nethack-3.4.3.post/src/decl.c 2009-09-27 20:37:32.000000000 +0200 @@ -271,6 +271,10 @@ "lockdir", "configdir", "troubledir" }; #endif +NEARDATA char postcommand[BUFSZ] = DUMMY; +NEARDATA char postuserdata[BUFSZ] = DUMMY; +NEARDATA char postscoredata[BUFSZ] = DUMMY; + /* dummy routine used to force linkage */ void decl_init() diff -Naur nethack-3.4.3.orig/src/end.c nethack-3.4.3.post/src/end.c --- nethack-3.4.3.orig/src/end.c 2003-12-08 00:39:13.000000000 +0100 +++ nethack-3.4.3.post/src/end.c 2009-09-27 20:39:31.000000000 +0200 @@ -10,6 +10,7 @@ #include #endif #include "dlb.h" +#include /* these probably ought to be generated by makedefs, like LAST_GEM */ #define FIRST_GEM DILITHIUM_CRYSTAL @@ -537,7 +538,7 @@ int how; { boolean taken; - char kilbuf[BUFSZ], pbuf[BUFSZ]; + char kilbuf[BUFSZ], pbuf[BUFSZ], postcommandbuf[BUFSZ]; winid endwin = WIN_ERR; boolean bones_ok, have_windows = iflags.window_inited; struct obj *corpse = (struct obj *)0; @@ -911,6 +912,16 @@ } if(done_stopprint) { raw_print(""); raw_print(""); } + + /* send topten entry to external command */ + if (postcommand[0]) { + if (postuserdata[0]) + sprintf(postcommandbuf,"%s '%s' %s",postcommand, postscoredata, postuserdata); + else + sprintf(postcommandbuf,"%s '%s'",postcommand, postscoredata); + system(postcommandbuf); + } + terminate(EXIT_SUCCESS); } diff -Naur nethack-3.4.3.orig/src/files.c nethack-3.4.3.post/src/files.c --- nethack-3.4.3.orig/src/files.c 2003-12-08 00:39:13.000000000 +0100 +++ nethack-3.4.3.post/src/files.c 2009-09-27 20:37:32.000000000 +0200 @@ -1823,6 +1823,10 @@ (void) get_uchars(fp, buf, bufp, translate, FALSE, WARNCOUNT, "WARNINGS"); assign_warnings(translate); + } else if (match_varname(buf, "POSTCOMMAND", 3)) { + (void) strncpy(postcommand, bufp, PL_PSIZ-1); + } else if (match_varname(buf, "POSTUSERDATA", 3)) { + (void) strncpy(postuserdata, bufp, PL_PSIZ-1); #ifdef WIZARD } else if (match_varname(buf, "WIZKIT", 6)) { (void) strncpy(wizkit, bufp, WIZKIT_MAX-1); diff -Naur nethack-3.4.3.orig/src/options.c nethack-3.4.3.post/src/options.c --- nethack-3.4.3.orig/src/options.c 2003-12-08 00:39:13.000000000 +0100 +++ nethack-3.4.3.post/src/options.c 2009-09-27 20:37:32.000000000 +0200 @@ -332,6 +332,10 @@ { "windowcolors", "the foreground/background colors of windows", /*WC*/ 80, DISP_IN_GAME }, { "windowtype", "windowing system to use", WINTYPELEN, DISP_IN_GAME }, + { "postcommand", "the command to call on completeion", + PL_PSIZ, DISP_IN_GAME }, + { "postuserdata", "additional data to pass to post command", + PL_PSIZ, DISP_IN_GAME }, { (char *)0, (char *)0, 0, 0 } }; @@ -1085,6 +1089,22 @@ return; } + fullname = "postcommand"; + if (match_optname(opts, fullname, 3, TRUE)) { + if (negated) bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) + nmcpy(postcommand, op, PL_PSIZ); + return; + } + + fullname = "postuserdata"; + if (match_optname(opts, fullname, 3, TRUE)) { + if (negated) bad_negation(fullname, FALSE); + else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) + nmcpy(postuserdata, op, PL_PSIZ); + return; + } + fullname = "number_pad"; if (match_optname(opts, fullname, 10, TRUE)) { boolean compat = (strlen(opts) <= 10); @@ -2920,6 +2940,10 @@ iflags.bouldersym : oc_syms[(int)objects[BOULDER].oc_class]); else if (!strcmp(optname, "catname")) Sprintf(buf, "%s", catname[0] ? catname : none ); + else if (!strcmp(optname, "postcommand")) + Sprintf(buf, "%s", postcommand[0] ? postcommand : none ); + else if (!strcmp(optname, "postuserdata")) + Sprintf(buf, "%s", postuserdata[0] ? postuserdata : none ); else if (!strcmp(optname, "disclose")) { for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) { char topt[2]; diff -Naur nethack-3.4.3.orig/src/topten.c nethack-3.4.3.post/src/topten.c --- nethack-3.4.3.orig/src/topten.c 2003-12-08 00:39:13.000000000 +0100 +++ nethack-3.4.3.post/src/topten.c 2009-09-27 20:43:08.000000000 +0200 @@ -563,6 +563,7 @@ linebuf[0] = '\0'; + postscoredata[0] = '\0'; if (rank) Sprintf(eos(linebuf), "%3d", rank); else Strcat(linebuf, " "); @@ -665,8 +666,10 @@ while (bp < linebuf + (COLNO-1)) *bp++ = ' '; *bp = 0; topten_print_bold(linebuf); - } else + } else { topten_print(linebuf); + } + Strcat(postscoredata, linebuf); Sprintf(linebuf, "%15s %s", "", linebuf3); lngr = strlen(linebuf); } @@ -689,8 +692,10 @@ while (bp < linebuf + so) *bp++ = ' '; *bp = 0; topten_print_bold(linebuf); - } else + } else { topten_print(linebuf); + } + Strcat(postscoredata, linebuf); } STATIC_OVL int