2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * empsched.c: Show the update schedule
29 * Known contributors to this file:
30 * Markus Armbruster, 2007-2010
39 #include "prototypes.h"
46 print_usage(char *program_name)
48 printf("Usage: %s [OPTION]... [FILE]\n"
49 "Print the Empire update schedule.\n\n"
50 " -e CONFIG-FILE configuration file\n"
52 " -n NUMBER print at most NUMBER updates (default %d)\n"
53 " -h display this help and exit\n"
54 " -v display version information and exit\n\n"
55 "If FILE is given, print the schedule defined there instead of\n"
56 "the current schedule.\n",
57 program_name, dflt_econfig, DFLT_N);
61 main(int argc, char *argv[])
63 char *config_file = NULL;
65 unsigned long n = DFLT_N;
66 time_t sched[MAX_N + 1], anchor;
69 while ((opt = getopt(argc, argv, "e:n:hv")) != EOF) {
75 n = strtoul(optarg, NULL, 10);
77 fprintf(stderr, "%s: can't print more than %d updates",
86 printf("%s\n\n%s", version, legal);
89 fprintf(stderr, "Try -h for help.\n");
94 if (argc - optind > 1) {
95 fprintf(stderr, "%s: extra operand %s\n", argv[0], argv[optind+1]);
96 fprintf(stderr, "Try -h for help.\n");
100 if (emp_config(config_file) < 0)
104 in_file = schedulefil;
105 else if (!strcmp(argv[optind], "-"))
108 in_file = argv[optind];
110 anchor = (time(NULL) + 59) / 60 * 60;
111 if (read_schedule(in_file, sched, n + 1, 0, anchor) < 0)
114 for (i = 0; sched[i]; i++)
115 printf("%s", ctime(&sched[i]));