]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/rea.c
Move show_first_tel() from player.c to rea.c
[empserver] / src / lib / commands / rea.c
index cf58ed9905e0e497264e2aa08fd2db10f60068aa..94465953cd572fb0da050b3d61908345e3c70797 100644 (file)
@@ -36,6 +36,7 @@
 #include <config.h>
 
 #include <ctype.h>
+#include <errno.h>
 #include <stdio.h>
 #include "commands.h"
 #include "match.h"
@@ -200,6 +201,31 @@ rea(void)
     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)
 {