/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire 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
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* rdsched.c: Read update schedule
*
* Known contributors to this file:
- * Markus Armbruster, 2007-2008
+ * Markus Armbruster, 2007-2011
*/
#define _XOPEN_SOURCE 500
read_schedule(char *fname, time_t sched[], int n, time_t t0, time_t anchor)
{
FILE *fp;
- int lno = 0;
+ int ret, lno;
char buf[1024];
char *endp;
fname, strerror(errno));
return -1;
}
- } else {
+ } else
fp = stdin;
- fname = "<stdin>";
- }
+ ret = lno = 0;
sched[0] = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
++lno;
endp = strchr(buf, '#');
if (endp)
*endp = 0;
- if (parse_schedule_line(buf, sched, n, t0, &anchor, fname, lno))
- return -1;
+ if (parse_schedule_line(buf, sched, n, t0, &anchor,
+ fname ? fname : "<stdin>", lno)) {
+ ret = -1;
+ break;
+ }
}
- fclose(fp);
- return 0;
+ if (fname)
+ fclose(fp);
+ return ret;
}
/*
{
int i = find_update(t, sched);
if (t == sched[i])
- memmove(sched + i, sched + i + 1,
- (n - 1 - i) * sizeof(*sched));
+ memmove(sched + i, sched + i + 1, (n - 1 - i) * sizeof(*sched));
return i;
}