From 6f11c9053a972ae05ae7fd4c7d1624075c8ec88b Mon Sep 17 00:00:00 2001 From: Joshua Kwan Date: Fri, 30 Jan 2004 02:49:29 +0000 Subject: [PATCH] Regenerate dependencies, function prototypes, remove useless includes, globals, and make code more readable. Move externs into a header file, just tidying up. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@186 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- Makefile | 12 +++++++++--- dgamelaunch.c | 10 +++------- dgamelaunch.h | 53 ++++++++++++++++++++++++++++----------------------- ttyplay.c | 25 +++--------------------- ttyplay.h | 16 ++++++++++++++++ ttyrec.c | 29 +++++++++++----------------- ttyrec.h | 15 +++++++++++++++ 7 files changed, 86 insertions(+), 74 deletions(-) create mode 100644 ttyplay.h diff --git a/Makefile b/Makefile index 171c0bb..b0ec0dc 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ indent: lex.yy.c: config.l $(LEX) $< -y.tab.c: config.y +y.tab.c y.tab.h: config.y $(YACC) -d $< lex.yy.o: lex.yy.c @@ -76,9 +76,15 @@ dist: clean @echo "Created source release $(NAME)-$(VERSION).tar.gz" # Dependencies - we may auto-generate later -dgamelaunch.o: dgamelaunch.c dgamelaunch.h y.tab.o +ee.o: ee.c io.o: io.c ttyrec.h +last_char_is.o: last_char_is.c +mygetnstr.o: mygetnstr.c +nethackstub.o: nethackstub.c stripgfx.o: stripgfx.c stripgfx.h -ttyplay.o: ttyplay.c ttyrec.h io.h stripgfx.h +strlcat.o: strlcat.c +strlcpy.o: strlcpy.c +ttyplay.o: ttyplay.c dgamelaunch.h ttyplay.h ttyrec.h io.h stripgfx.h ttyrec.o: ttyrec.c dgamelaunch.h ttyrec.h io.h virus.o: virus.c last_char_is.c +y.tab.o: y.tab.c dgamelaunch.h diff --git a/dgamelaunch.c b/dgamelaunch.c index 860bf7e..073a784 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -29,7 +29,10 @@ */ #define _GNU_SOURCE + #include "dgamelaunch.h" +#include "ttyplay.h" +#include "ttyrec.h" /* a request from the author: please leave some remnance of * 'based on dgamelaunch version xxx' in any derivative works, or @@ -82,14 +85,7 @@ extern FILE* yyin; extern int yyparse (); -extern pid_t child; /* nethack process */ - extern int editor_main (int argc, char **argv); -extern int ttyplay_main (char *ttyfile, int mode, int rstripgfx); -extern int ttyrec_main (char *username, char* ttyrec_filename); -extern int master, slave; -extern struct termios tt; -extern struct winsize win; /* global variables */ diff --git a/dgamelaunch.h b/dgamelaunch.h index 0c696d1..f712c8b 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -54,33 +54,38 @@ struct dg_config unsigned long max; }; +/* Global variables */ extern char* config; /* file path */ extern struct dg_config *myconfig; +extern char *chosen_name; +extern int loggedin; -/* dgamelaunch.c function prototypes */ -extern void create_config (void); -extern void ttyrec_getmaster (void); -extern char* gen_ttyrec_filename (void); -extern char* gen_inprogress_lock (pid_t pid, char* ttyrec_filename); -extern void catch_sighup (int signum); -extern void loadbanner (struct dg_banner *ban); -extern void drawbanner (unsigned int start_line, unsigned int howmany); -extern struct dg_game **populate_games (int *l); -extern void inprogressmenu (void); -extern int changepw (void); -extern void domailuser (char *username); -extern void drawmenu (void); -extern void freefile (void); -extern void initcurses (void); -extern void loginprompt (void); -extern void newuser (void); -extern int passwordgood (char *cpw); -extern int readfile (int nolock); -extern int userexist (char *cname); -extern void write_canned_rcfile (char *target); -extern void editoptions (void); -extern void writefile (int requirenew); -extern void graceful_exit (int status); +/* dgamelaunch.c */ +extern void create_config(void); +extern void ttyrec_getmaster(void); +extern char *gen_ttyrec_filename(void); +extern char *gen_inprogress_lock(pid_t pid, char *ttyrec_filename); +extern void catch_sighup(int signum); +extern void loadbanner(struct dg_banner *ban); +extern void drawbanner(unsigned int start_line, unsigned int howmany); +extern struct dg_game **populate_games(int *l); +extern void inprogressmenu(void); +extern int changepw(void); +extern void domailuser(char *username); +extern void drawmenu(void); +extern void freefile(void); +extern void initcurses(void); +extern void loginprompt(void); +extern void newuser(void); +extern int passwordgood(char *cpw); +extern int readfile(int nolock); +extern int userexist(char *cname); +extern void write_canned_rcfile(char *target); +extern void editoptions(void); +extern void writefile(int requirenew); +extern void graceful_exit(int status); +extern int purge_stale_locks(void); +extern void menuloop(void); /* strlcpy.c */ extern size_t strlcpy (char *dst, const char *src, size_t siz); diff --git a/ttyplay.c b/ttyplay.c index b01f9f3..da61a0e 100644 --- a/ttyplay.c +++ b/ttyplay.c @@ -42,27 +42,15 @@ #include #include #include + +#include "dgamelaunch.h" +#include "ttyplay.h" #include "ttyrec.h" #include "io.h" #include "stripgfx.h" -extern void domailuser (char *); -extern void initcurses (void); -extern char *chosen_name; -extern int loggedin; - -int ttyplay_main (char *ttyfile, int mode, int rstripgfx); - off_t seek_offset_clrscr; int bstripgfx; -char *ttyfile_local; - -typedef double (*WaitFunc) (struct timeval prev, - struct timeval cur, double speed); -typedef int (*ReadFunc) (FILE * fp, Header * h, char **buf, int pread); -typedef void (*WriteFunc) (char *buf, int len); -typedef void (*ProcessFunc) (FILE * fp, double speed, - ReadFunc read_func, WaitFunc wait_func); struct timeval timeval_diff (struct timeval tv1, struct timeval tv2) @@ -210,11 +198,6 @@ ttypread (FILE * fp, Header * h, char **buf, int pread) { initcurses (); domailuser (chosen_name); - /* XXX jilles: just quit out after mail for now */ -#if 0 - endwin (); - ttyplay_main (ttyfile_local, 1, 0); /* ICK! Recursive */ -#endif return 0; } break; @@ -392,8 +375,6 @@ ttyplay_main (char *ttyfile, int mode, int rstripgfx) FILE *input = stdin; struct termios old, new; - ttyfile_local = ttyfile; - /* strip graphics mode flag */ bstripgfx = rstripgfx; if (bstripgfx) diff --git a/ttyplay.h b/ttyplay.h new file mode 100644 index 0000000..9581a6a --- /dev/null +++ b/ttyplay.h @@ -0,0 +1,16 @@ +#ifndef INCLUDED_ttyplay_h +#define INCLUDED_ttyplay_h + +#include +#include "ttyrec.h" + +int ttyplay_main (char *ttyfile, int mode, int rstripgfx); + +typedef double (*WaitFunc) (struct timeval prev, + struct timeval cur, double speed); +typedef int (*ReadFunc) (FILE * fp, Header * h, char **buf, int pread); +typedef void (*WriteFunc) (char *buf, int len); +typedef void (*ProcessFunc) (FILE * fp, double speed, + ReadFunc read_func, WaitFunc wait_func); + +#endif /* !INCLUDED_ttyrec_h */ diff --git a/ttyrec.c b/ttyrec.c index f2d9f3a..c376522 100644 --- a/ttyrec.c +++ b/ttyrec.c @@ -42,11 +42,10 @@ /* * script */ -#include "dgamelaunch.h" + #include #include #include -#include #include #include @@ -62,6 +61,7 @@ #include #include +#include "dgamelaunch.h" #include "ttyrec.h" #include "io.h" @@ -69,31 +69,20 @@ # define XCASE 0 #endif -void done (void); -void fail (void); -void fixtty (void); -void getslave (void); -void doinput (void); -void dooutput (void); -void doshell (char *); - -FILE *fscript; -int master; int slave; pid_t child, subchild; char* ipfile = NULL; +FILE *fscript; +int master; + struct termios tt; struct winsize win; -int lb; -int l; -int aflg; int uflg; int ttyrec_main (char *username, char* ttyrec_filename) { - void finish (); char dirname[100]; snprintf (dirname, 100, "%sttyrec/%s", myconfig->dglroot, username); @@ -157,15 +146,19 @@ doinput () } void -finish () +finish (int sig) { int status; register int pid; register int die = 0; - while ((pid = wait3 ((int *) &status, WNOHANG, 0)) > 0) + (void)sig; /* unused */ + + while ((pid = wait3 (&status, WNOHANG, 0)) > 0) + { if (pid == child) die = 1; + } if (die) done (); diff --git a/ttyrec.h b/ttyrec.h index c8c623a..9270624 100644 --- a/ttyrec.h +++ b/ttyrec.h @@ -11,5 +11,20 @@ typedef struct header } Header; +extern void done (void); +extern void fail (void); +extern void fixtty (void); +extern void getslave (void); +extern void doinput (void); +extern void dooutput (void); +extern void doshell (char *); +extern void finish (int); + +extern int ttyrec_main(char *username, char *ttyrec_filename); + +extern pid_t child; /* nethack process */ +extern int master, slave; +extern struct termios tt; +extern struct winsize win; #endif -- 2.47.3