From 4525ae2d175f76b197a2459613d5ef7ba984dda3 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 17 Mar 2008 19:54:08 +0100 Subject: [PATCH] Change empdump syntax Require -i for import, and fail when no action is requested. Also rename option -t to -n. --- man/empdump.6 | 14 ++++++------ src/util/empdump.c | 53 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/man/empdump.6 b/man/empdump.6 index 6861062e..08213c87 100644 --- a/man/empdump.6 +++ b/man/empdump.6 @@ -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, diff --git a/src/util/empdump.c b/src/util/empdump.c index 344c26e3..cdd8ba38 100644 --- a/src/util/empdump.c +++ b/src/util/empdump.c @@ -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, ...) {