]> git.pond.sub.org Git - empserver/commitdiff
Change empdump syntax
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 17 Mar 2008 18:54:08 +0000 (19:54 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 17 Mar 2008 18:54:08 +0000 (19:54 +0100)
Require -i for import, and fail when no action is requested.  Also
rename option -t to -n.

man/empdump.6
src/util/empdump.c

index 6861062e4aa07e12555ffa4f7bdd659e69985448..08213c870e3fc28fd370964342bc88d4d8bc075a 100644 (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,
index 344c26e3b1e3d5821e7a3dcd3feafc0e9e2ebab3..cdd8ba386a3db92fc8dfa7e16295e882fca10293 100644 (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 'i':
+           import = optarg;
+           break;
+       case 'm':
+           human = 0;
+           break;
+       case 'n':
+           private = EFF_PRIVATE;
+           break;
+       case 'x':
+           export = 1;
+           break;
        case 'h':
-           printf("Usage: %s [OPTION]... [DUMP-FILE]\n"
+           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"
-                  "  -t              test import, don't update game state\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 'm':
-           human = 0;
-           break;
-       case 't':
-           private = EFF_PRIVATE;
-           break;
-       case 'x':
-           export = 1;
-           break;
        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, ...)
 {