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

View file

@ -44,6 +44,7 @@
#include "version.h" #include "version.h"
#include "xdump.h" #include "xdump.h"
static void exit_bad_arg(char *, ...) ATTRIBUTE((noreturn));
static void dump_table(int, int); static void dump_table(int, int);
static void pln_fixup(void); static void pln_fixup(void);
static void lnd_fixup(void); static void lnd_fixup(void);
@ -61,42 +62,48 @@ main(int argc, char *argv[])
FILE *impf = NULL; FILE *impf = NULL;
int dirty[EF_MAX]; int dirty[EF_MAX];
while ((opt = getopt(argc, argv, "e:mtxhv")) != EOF) { while ((opt = getopt(argc, argv, "e:i:mnxhv")) != EOF) {
switch (opt) { switch (opt) {
case 'e': case 'e':
config_file = optarg; config_file = optarg;
break; break;
case 'h': case 'i':
printf("Usage: %s [OPTION]... [DUMP-FILE]\n" import = optarg;
" -e CONFIG-FILE configuration file\n" break;
" (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 'm': case 'm':
human = 0; human = 0;
break; break;
case 't': case 'n':
private = EFF_PRIVATE; private = EFF_PRIVATE;
break; break;
case 'x': case 'x':
export = 1; export = 1;
break; 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': case 'v':
printf("%s\n\n%s", version, legal); printf("%s\n\n%s", version, legal);
exit(0); exit(0);
default: default:
fprintf(stderr, "Try -h for help.\n"); exit_bad_arg(NULL);
exit(1);
} }
} }
if (argv[optind]) 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) { if (import) {
impf = fopen(import, "r"); impf = fopen(import, "r");
@ -170,6 +177,20 @@ main(int argc, char *argv[])
return 0; 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 static void
printf_wrapper(char *fmt, ...) printf_wrapper(char *fmt, ...)
{ {