Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Patch: Call external program with top ten lines

0 views
Skip to first unread message

David S Glasser

unread,
Aug 7, 2003, 4:42:42 PM8/7/03
to

I play nethack on a multi-player system (nethack.mit.edu); we
all use an instant-messaging system (zephyr), and we thought it
would be fun to have nethack send a zephyr every time somebody dies
(or ascends or quits, etc). The following patch to 3.4.1 does that.
It hasn't been rigorously tested yet, but seems to work.

You'll want to change the pathname in topten_print_pipe
to a program that receives a few lines on stdin and does
something with them. (I guess this could have been a patch
to Makefile and so on to and included #ifdefs but this is just
a post to rgrn, not a submission to the DevTeam.)

--dave, killed by a white unicorn right next to a co-aligned
chaotic altar just a few turns before blessing and rubbing a
magic lamp

--- topten.c.old Thu Aug 7 15:08:32 2003
+++ topten.c Thu Aug 7 15:44:41 2003
@@ -61,6 +61,8 @@

STATIC_DCL void FDECL(topten_print, (const char *));
STATIC_DCL void FDECL(topten_print_bold, (const char *));
+STATIC_DCL void FDECL(topten_print_pipe, (const char *));
+STATIC_DCL void NDECL(topten_print_pipe_close);
STATIC_DCL xchar FDECL(observable_depth, (d_level *));
STATIC_DCL void NDECL(outheader);
STATIC_DCL void FDECL(outentry, (int,struct toptenentry *,BOOLEAN_P));
@@ -104,6 +106,32 @@
putstr(toptenwin, ATR_BOLD, x);
}

+static FILE *topten_pipe = NULL;
+
+STATIC_OVL void
+topten_print_pipe(x)
+const char *x;
+{
+ if (topten_pipe == NULL) {
+ topten_pipe = popen("/mit/glasser/bin.common/nethack-topten", "w");
+ if (topten_pipe == NULL) {
+ raw_print("can't open pipe!");
+ return;
+ }
+ }
+ fwrite(x, sizeof(char), strlen(x), topten_pipe);
+ fwrite("\n", sizeof(char), 1, topten_pipe);
+}
+
+STATIC_OVL void
+topten_print_pipe_close()
+{
+ if ((topten_pipe != NULL) && (pclose(topten_pipe) == -1)) {
+ raw_print("error closing pipe!");
+ }
+ topten_pipe = NULL;
+}
+
STATIC_OVL xchar
observable_depth(lev)
d_level *lev;
@@ -501,6 +529,7 @@
}
if(rank0 >= rank) if(!done_stopprint)
outentry(0, t0, TRUE);
+ outentry(0, t0, -1);
#ifdef UPDATE_RECORD_IN_PLACE
if (flg) {
# ifdef TRUNCATE_FILE
@@ -661,7 +690,9 @@
if (bp > linebuf + 5 && !strncmp(bp - 5, " [max", 5)) bp -= 5;
Strcpy(linebuf3, bp+1);
*bp = 0;
- if (so) {
+ if (so == -1) {
+ topten_print_pipe(linebuf);
+ } else if (so) {
while (bp < linebuf + (COLNO-1)) *bp++ = ' ';
*bp = 0;
topten_print_bold(linebuf);
@@ -682,15 +713,19 @@
(t1->maxhp < 10) ? " " : (t1->maxhp < 100) ? " " : "",
t1->maxhp);
}
-
- if (so) {
+
+ if (so == -1) {
+ topten_print_pipe(linebuf);
+ topten_print_pipe_close();
+ } else if (so) {
bp = eos(linebuf);
if (so >= COLNO) so = COLNO-1;
while (bp < linebuf + so) *bp++ = ' ';
*bp = 0;
topten_print_bold(linebuf);
- } else
+ } else {
topten_print(linebuf);
+ }
}

STATIC_OVL int

0 new messages