Return to watching after sending a simplemail message. This behaves like

choosing the letter again in the watch menu, as the screen contents are lost
when typing in the message and must be restored.

Tested on my FreeBSD 4.8 machine and the Solaris 9 machine. On the latter,
some problems because dgamelaunch doesn't recognize nethackstub's clear
screen sequence. Continuing watching works on both.


git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@193 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Jilles Tjoelker 2004-01-30 21:28:38 +00:00
parent 7222c4a282
commit e8f6f8de8e
2 changed files with 38 additions and 27 deletions

View File

@ -129,13 +129,14 @@ ttyread (FILE * fp, Header * h, char **buf, int pread)
if (read_header (fp, h) == 0) if (read_header (fp, h) == 0)
{ {
return 0; return READ_EOF;
} }
/* length should never be longer than one BUFSIZ */ /* length should never be longer than one BUFSIZ */
if (h->len > BUFSIZ) if (h->len > BUFSIZ)
{ {
fprintf (stderr, "h->len too big (%d) limit %d\n", h->len, BUFSIZ); fprintf (stderr, "h->len too big (%ld) limit %ld\n",
(long)h->len, (long)BUFSIZ);
exit (-21); exit (-21);
} }
@ -149,9 +150,9 @@ ttyread (FILE * fp, Header * h, char **buf, int pread)
if (fread (*buf, 1, h->len, fp) != h->len) if (fread (*buf, 1, h->len, fp) != h->len)
{ {
fseek (fp, offset, SEEK_SET); fseek (fp, offset, SEEK_SET);
return 0; return READ_EOF;
} }
return 1; return READ_DATA;
} }
int int
@ -167,7 +168,7 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
/* /*
* Read persistently just like tail -f. * Read persistently just like tail -f.
*/ */
while (ttyread (fp, h, buf, 1) == 0) while (ttyread (fp, h, buf, 1) == READ_EOF)
{ {
struct timeval w = { 0, 100000 }; struct timeval w = { 0, 100000 };
select (0, NULL, NULL, NULL, &w); select (0, NULL, NULL, NULL, &w);
@ -177,7 +178,6 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
endwin (); endwin ();
printf ("Exiting due to 20 minutes of inactivity.\n"); printf ("Exiting due to 20 minutes of inactivity.\n");
exit (-23); exit (-23);
return 0;
} }
@ -191,20 +191,20 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
switch (c) switch (c)
{ {
case 'q': case 'q':
return 0; return READ_EOF;
break; break;
case 'm': case 'm':
if (loggedin) if (loggedin)
{ {
initcurses (); initcurses ();
domailuser (chosen_name); domailuser (chosen_name);
return 0; return READ_RESTART;
} }
break; break;
} }
} }
} }
return 1; return READ_DATA;
} }
void void
@ -229,11 +229,12 @@ ttynowrite (char *buf, int len)
/* do nothing */ /* do nothing */
} }
void int
ttyplay (FILE * fp, double speed, ReadFunc read_func, ttyplay (FILE * fp, double speed, ReadFunc read_func,
WriteFunc write_func, WaitFunc wait_func, off_t offset) WriteFunc write_func, WaitFunc wait_func, off_t offset)
{ {
int first_time = 1; int first_time = 1;
int r = READ_EOF;
struct timeval prev; struct timeval prev;
setbuf (stdout, NULL); setbuf (stdout, NULL);
@ -250,7 +251,8 @@ ttyplay (FILE * fp, double speed, ReadFunc read_func,
char *buf; char *buf;
Header h; Header h;
if (read_func (fp, &h, &buf, 0) == 0) r = read_func (fp, &h, &buf, 0);
if (r != READ_DATA)
{ {
break; break;
} }
@ -265,6 +267,7 @@ ttyplay (FILE * fp, double speed, ReadFunc read_func,
prev = h.tv; prev = h.tv;
free (buf); free (buf);
} }
return r;
} }
void void
@ -322,7 +325,7 @@ set_seek_offset_clrscr (FILE * fp)
char *buf; char *buf;
Header h; Header h;
if (ttyread (fp, &h, &buf, 0) == 0) if (ttyread (fp, &h, &buf, 0) != READ_DATA)
{ {
break; break;
} }
@ -353,7 +356,11 @@ ttyplayback (FILE * fp, double speed, ReadFunc read_func, WaitFunc wait_func)
} }
void void
ttypeek (FILE * fp, double speed, ReadFunc read_func, WaitFunc wait_func) ttypeek (FILE * fp, double speed)
{
int r;
do
{ {
ttyskipall (fp); ttyskipall (fp);
set_seek_offset_clrscr (fp); set_seek_offset_clrscr (fp);
@ -361,7 +368,8 @@ ttypeek (FILE * fp, double speed, ReadFunc read_func, WaitFunc wait_func)
{ {
ttyplay (fp, 0, ttyread, ttywrite, ttynowait, seek_offset_clrscr); ttyplay (fp, 0, ttyread, ttywrite, ttynowait, seek_offset_clrscr);
} }
ttyplay (fp, speed, ttypread, ttywrite, ttynowait, 0); r = ttyplay (fp, speed, ttypread, ttywrite, ttynowait, 0);
} while (r == READ_RESTART);
} }
@ -371,7 +379,6 @@ ttyplay_main (char *ttyfile, int mode, int rstripgfx)
double speed = 1.0; double speed = 1.0;
ReadFunc read_func = ttyread; ReadFunc read_func = ttyread;
WaitFunc wait_func = ttywait; WaitFunc wait_func = ttywait;
ProcessFunc process = ttyplayback;
FILE *input = stdin; FILE *input = stdin;
struct termios old, new; struct termios old, new;
@ -382,9 +389,6 @@ ttyplay_main (char *ttyfile, int mode, int rstripgfx)
seek_offset_clrscr = 0; seek_offset_clrscr = 0;
if (mode == 1)
process = ttypeek;
input = efopen (ttyfile, "r"); input = efopen (ttyfile, "r");
tcgetattr (0, &old); /* Get current terminal state */ tcgetattr (0, &old); /* Get current terminal state */
@ -394,7 +398,11 @@ ttyplay_main (char *ttyfile, int mode, int rstripgfx)
new.c_cc[VTIME] = 0; new.c_cc[VTIME] = 0;
tcsetattr (0, TCSANOW, &new); /* Make it current */ tcsetattr (0, TCSANOW, &new); /* Make it current */
process (input, speed, read_func, wait_func); if (mode == 1)
ttypeek (input, speed);
else
ttyplayback (input, speed, read_func, wait_func);
tcsetattr (0, TCSANOW, &old); /* Return terminal state */ tcsetattr (0, TCSANOW, &old); /* Return terminal state */
return 0; return 0;

View File

@ -10,7 +10,10 @@ typedef double (*WaitFunc) (struct timeval prev,
struct timeval cur, double speed); struct timeval cur, double speed);
typedef int (*ReadFunc) (FILE * fp, Header * h, char **buf, int pread); typedef int (*ReadFunc) (FILE * fp, Header * h, char **buf, int pread);
typedef void (*WriteFunc) (char *buf, int len); typedef void (*WriteFunc) (char *buf, int len);
typedef void (*ProcessFunc) (FILE * fp, double speed,
ReadFunc read_func, WaitFunc wait_func); /* Return values for ReadFunc (and ProcessFunc) */
#define READ_DATA 0 /* Data */
#define READ_EOF 1 /* Normal EOF or user aborted */
#define READ_RESTART 2 /* Screen must be redrawn (after simplemail) */
#endif /* !INCLUDED_ttyplay_h */ #endif /* !INCLUDED_ttyplay_h */