Move show_first_tel() from player.c to rea.c

This commit is contained in:
Markus Armbruster 2009-02-08 11:33:10 +01:00
parent 87b7330805
commit e8926559d1
3 changed files with 27 additions and 36 deletions

View file

@ -77,6 +77,7 @@ extern void trdswitchown(int, void *, int);
extern int do_look(short); extern int do_look(short);
extern int radar(short); extern int radar(short);
extern void update_power(void); extern void update_power(void);
extern int show_first_tel(char *);
/* Commands */ /* Commands */
int acce(void); int acce(void);
int add(void); int add(void);
@ -382,7 +383,6 @@ extern int natbyname(char *, natid *);
extern int natpass(int, char *); extern int natpass(int, char *);
/* player.c */ /* player.c */
extern struct player *player; /* current player's context */ extern struct player *player; /* current player's context */
extern int show_first_tel(char *);
extern char *praddr(struct player *); extern char *praddr(struct player *);
extern void player_main(struct player *); extern void player_main(struct player *);
/* more under Commands */ /* more under Commands */

View file

@ -36,6 +36,7 @@
#include <config.h> #include <config.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include "commands.h" #include "commands.h"
#include "match.h" #include "match.h"
@ -200,6 +201,31 @@ rea(void)
return RET_OK; return RET_OK;
} }
/*
* Print first telegram in file FNAME.
*/
int
show_first_tel(char *fname)
{
FILE *fp;
struct telstr tgm;
if ((fp = fopen(fname, "rb")) == NULL) {
if (errno == ENOENT)
return 0;
else {
logerror("Could not open %s.\n", fname);
return -1;
}
}
if (tel_read_header(fp, fname, &tgm) < 0)
return -1;
if (tel_read_body(fp, fname, &tgm, print_sink, NULL) < 0)
return -1;
fclose(fp);
return 0;
}
static int static int
print_sink(char *chunk, size_t sz, void *arg) print_sink(char *chunk, size_t sz, void *arg)
{ {

View file

@ -35,8 +35,6 @@
#include <config.h> #include <config.h>
#include <errno.h>
#include <stdio.h>
#include "com.h" #include "com.h"
#include "empio.h" #include "empio.h"
#include "empthread.h" #include "empthread.h"
@ -53,7 +51,6 @@
static int command(void); static int command(void);
static int status(void); static int status(void);
static int print_sink(char *, size_t, void *);
struct player *player; struct player *player;
@ -262,38 +259,6 @@ show_motd(void)
return RET_OK; return RET_OK;
} }
/*
* Print first telegram in file FNAME.
*/
int
show_first_tel(char *fname)
{
FILE *fp;
struct telstr tgm;
if ((fp = fopen(fname, "rb")) == NULL) {
if (errno == ENOENT)
return 0;
else {
logerror("Could not open %s.\n", fname);
return -1;
}
}
if (tel_read_header(fp, fname, &tgm) < 0)
return -1;
if (tel_read_body(fp, fname, &tgm, print_sink, NULL) < 0)
return -1;
fclose(fp);
return 0;
}
static int
print_sink(char *chunk, size_t sz, void *arg)
{
uprnf(chunk);
return 0;
}
int int
quit(void) quit(void)
{ {