Change empdump syntax

Require -i for import, and fail when no action is requested.  Also
rename option -t to -n.
This commit is contained in:
Markus Armbruster 2008-03-17 19:54:08 +01:00
parent af8ff598aa
commit 4525ae2d17
2 changed files with 43 additions and 24 deletions

View file

@ -4,13 +4,13 @@ empdump \- Export/import Empire game state
.SH SYNOPSIS
.B empdump
[
.B \-mtxhv
.B \-mnxhv
]
[
.BI \-e " configfile"
]
[
.I dump-file
.BI \-i " dump-file"
]
.br
.SH DESCRIPTION
@ -24,23 +24,21 @@ Use game configuration in \fIconfigfile\fR.
.B \-h
Help. Print brief usage information and exit.
.TP
.BI \-i " dump-file"
Import from \fIdump-file\fR.
.TP
.B \-m
Use machine-readable format for export. Import always recognizes both
machine-readable and human-readable format.
.TP
.B \-t
Test import, don't update game state.
.B \-n
Dry run, don't actually update game state on import.
.TP
.B \-v
Print version information and exit.
.TP
.B \-x
Export game state to standard output.
.SH OPERANDS
.TP
.I dump-file
The file to import.
.SH "LIMITATIONS"
.B empdump
can't export player bmaps, power report, telegrams, announcements,

View file

@ -44,6 +44,7 @@
#include "version.h"
#include "xdump.h"
static void exit_bad_arg(char *, ...) ATTRIBUTE((noreturn));
static void dump_table(int, int);
static void pln_fixup(void);
static void lnd_fixup(void);
@ -61,42 +62,48 @@ main(int argc, char *argv[])
FILE *impf = NULL;
int dirty[EF_MAX];
while ((opt = getopt(argc, argv, "e:mtxhv")) != EOF) {
while ((opt = getopt(argc, argv, "e:i:mnxhv")) != EOF) {
switch (opt) {
case 'e':
config_file = optarg;
break;
case 'h':
printf("Usage: %s [OPTION]... [DUMP-FILE]\n"
" -e CONFIG-FILE configuration file\n"
" (default %s)\n"
" -m use machine-readable format\n"
" -t test import, don't update game state\n"
" -x export to standard output\n"
" -h display this help and exit\n"
" -v display version information and exit\n",
argv[0], dflt_econfig);
exit(0);
case 'i':
import = optarg;
break;
case 'm':
human = 0;
break;
case 't':
case 'n':
private = EFF_PRIVATE;
break;
case 'x':
export = 1;
break;
case 'h':
printf("Usage: %s [OPTION]...\n"
" -e CONFIG-FILE configuration file\n"
" (default %s)\n"
" -i DUMP-FILE import from DUMP-FILE\n"
" -m use machine-readable format\n"
" -n dry run, don't update game state\n"
" -x export to standard output\n"
" -h display this help and exit\n"
" -v display version information and exit\n",
argv[0], dflt_econfig);
exit(0);
case 'v':
printf("%s\n\n%s", version, legal);
exit(0);
default:
fprintf(stderr, "Try -h for help.\n");
exit(1);
exit_bad_arg(NULL);
}
}
if (argv[optind])
import = argv[optind++];
exit_bad_arg("%s: extra operand %s\n", argv[0], argv[optind]);
if (!import && !export)
exit_bad_arg("%s: nothing to do!\n", argv[0]);
if (import) {
impf = fopen(import, "r");
@ -170,6 +177,20 @@ main(int argc, char *argv[])
return 0;
}
static void
exit_bad_arg(char *complaint, ...)
{
va_list ap;
if (complaint) {
va_start(ap, complaint);
vfprintf(stderr, complaint, ap);
va_end(ap);
}
fprintf(stderr, "Try -h for help.\n");
exit(1);
}
static void
printf_wrapper(char *fmt, ...)
{