]> git.pond.sub.org Git - empserver/commitdiff
New utility program empsched.
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 13 Jul 2007 16:49:13 +0000 (16:49 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 13 Jul 2007 16:49:13 +0000 (16:49 +0000)
doc/schedule
man/emp_server.6
man/empsched.6 [new file with mode: 0644]
src/util/empsched.c [new file with mode: 0644]

index 96f2627ae024817b3967e99649ac24de23aebdb7..dadb4dd7245d019e74667a4567b7ed7ce87ac108 100644 (file)
@@ -47,4 +47,5 @@ starting June 1st 2007, skipping July 4th:
     skip 2007-07-04 20:00
 
 The server reads the schedule file on startup, after an update, on the
-reload command, and on catching SIGHUP.
+reload command, and on catching SIGHUP.  You can use the utility
+program empsched to test a schedule before you install it.
index 31f5730c4282adce9a3ed3a0e8ad2cc2550a949a..1e9979df43ad6ff91744100f3e22405b0cc02332 100644 (file)
@@ -98,7 +98,8 @@ parameters, you must remove the service and reinstall the service.\}
 .SH BUGS
 Please report all bugs to the Wolfpack <wolfpack@wolfpackempire.com>
 .SH "SEE ALSO"
-\fIempire\fR(6), \fIfairland\fR(6), \fIfiles\fR(6), \fIpconfig\fR(6).
+\fIempire\fR(6), \fIempsched\fR(6), \fIfairland\fR(6), \fIfiles\fR(6),
+\fIpconfig\fR(6).
 .SH AUTHORS
 Dave Pare, Jeff Bailey, Thomas Ruschak, Ken Stevens and Steve McClure
 are principal authors.  The full list of authors is too long to
diff --git a/man/empsched.6 b/man/empsched.6
new file mode 100644 (file)
index 0000000..2792b62
--- /dev/null
@@ -0,0 +1,41 @@
+.TH PRSCHED 1
+.SH NAME
+prsched \- Print Empire update schedule
+.SH SYNOPSIS
+.B prsched
+[
+.B \-hv
+]
+[
+.BI \-e " configfile"
+]
+[
+.BI \-n " number"
+]
+[
+.I file
+]
+.br
+.SH DESCRIPTION
+.B prsched
+prints the Empire update schedule.
+.SH OPTIONS
+.TP
+.BI \-e " configfile"
+Use game configuration in \fIconfigfile\fR.
+.TP
+.B \-h 
+Help.  Print brief usage information and exit.
+.TP
+.BI \-n " number"
+Print \fInumber\fR updates.
+.TP
+.B \-v
+Print version information and exit.
+.SH OPERANDS
+If \fIfile\fR is given, \fBprsched\fR prints the schedule defined
+there instead of the current schedule.
+.SH "SEE ALSO"
+\fIemp_server\fR(6).
+.SH AUTHOR
+Markus Armbruster <armbru@pond.sub.org>
diff --git a/src/util/empsched.c b/src/util/empsched.c
new file mode 100644 (file)
index 0000000..d45e972
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ *  Empire - A multi-player, client/server Internet based war game.
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                           Ken Stevens, Steve McClure
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  ---
+ *
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
+ *
+ *  ---
+ *
+ *  empsched.c: Show the update schedule
+ * 
+ *  Known contributors to this file:
+ *     Markus Armbruster, 2007
+ */
+
+#include <config.h>
+
+#if defined(_WIN32)
+#include "../lib/gen/getopt.h"
+#else
+#include <unistd.h>
+#endif
+#include <stdio.h>
+#include "optlist.h"
+#include "prototypes.h"
+#include "version.h"
+
+#define DFLT_N 16
+#define MAX_N 1000
+
+static void
+print_usage(char *program_name)
+{
+    printf("Usage: %s [OPTION]... [FILE]\n"
+          "Print the Empire update schedule.\n\n"
+          "  -e CONFIG-FILE  configuration file\n"
+          "                  (default %s)\n"
+          "  -n NUMBER       print at most NUMBER updates (default %d)\n"
+          "  -h              display this help and exit\n"
+          "  -v              display version information and exit\n\n"
+          "If FILE is given, print the schedule defined there instead of\n"
+          "the current schedule.\n",
+          program_name, dflt_econfig, DFLT_N);
+}
+
+int
+main(int argc, char *argv[])
+{
+    char *config_file = NULL;
+    char *in_file;
+    unsigned long n = DFLT_N;
+    time_t sched[MAX_N + 1];
+    int opt, i;
+
+    while ((opt = getopt(argc, argv, "e:n:hv")) != EOF) {
+       switch (opt) {
+       case 'e':
+           config_file = optarg;
+           break;
+       case 'n':
+           n = strtoul(optarg, NULL, 10);
+           if (n > MAX_N) {
+               fprintf(stderr, "%s: can't print more than %d updates",
+                       argv[0], MAX_N);
+               exit(1);
+           }
+           break;
+       case 'h':
+           print_usage(argv[0]);
+           exit(0);
+       case 'v':
+           printf("%s\n\n%s", version, legal);
+           exit(0);
+       default:
+           print_usage(argv[0]);
+           exit(1);
+       }
+    }
+
+    if (emp_config(config_file) < 0)
+       exit(1);
+
+    if (!argv[optind])
+       in_file = schedulefil;
+    else if (!strcmp(argv[optind], "-"))
+       in_file = NULL;
+    else
+       in_file = argv[optind];
+
+    read_schedule(in_file, sched, n + 1, 0, 0/* FIXME */);
+
+    for (i = 0; sched[i]; i++)
+       printf("%s", ctime(&sched[i]));
+
+    return 0;
+}