Make --help and --version work consistently across all tools.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 19 Sep 2012 17:08:15 +0000 (17:08 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 19 Sep 2012 17:08:15 +0000 (17:08 +0000)
Well, at least across all command-line tools on both Windows and Unix,
and the GTK apps on Unix too. The Windows GUI apps fundamentally can't
write to standard output and it doesn't seem sensible to use message
boxes for these purposes :-)

git-svn-id: svn://svn.tartarus.org/sgt/putty@9673 cda61777-01e9-0310-a592-d414129be87e

cmdgen.c
pscp.c
psftp.c
unix/gtkwin.c
unix/uxplink.c
windows/winplink.c

index 5b0e54d..86a548e 100644 (file)
--- a/cmdgen.c
+++ b/cmdgen.c
@@ -118,10 +118,7 @@ void sk_cleanup(void)
 
 void showversion(void)
 {
-    char *verstr = dupstr(ver);
-    verstr[0] = tolower((unsigned char)verstr[0]);
-    printf("PuTTYgen %s\n", verstr);
-    sfree(verstr);
+    printf("puttygen: %s\n", ver);
 }
 
 void usage(int standalone)
diff --git a/pscp.c b/pscp.c
index 833e46c..054e437 100644 (file)
--- a/pscp.c
+++ b/pscp.c
@@ -2283,9 +2283,12 @@ int psftp_main(int argc, char *argv[])
            preserve = 1;
        } else if (strcmp(argv[i], "-q") == 0) {
            statistics = 0;
-       } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0) {
+       } else if (strcmp(argv[i], "-h") == 0 ||
+                   strcmp(argv[i], "-?") == 0 ||
+                   strcmp(argv[i], "--help") == 0) {
            usage();
-       } else if (strcmp(argv[i], "-V") == 0) {
+       } else if (strcmp(argv[i], "-V") == 0 ||
+                   strcmp(argv[i], "--version") == 0) {
             version();
         } else if (strcmp(argv[i], "-ls") == 0) {
            list = 1;
diff --git a/psftp.c b/psftp.c
index ef930bd..ab287df 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -2923,12 +2923,14 @@ int psftp_main(int argc, char *argv[])
            if (flags & FLAG_VERBOSE)
                verbose = 1;
        } else if (strcmp(argv[i], "-h") == 0 ||
-                  strcmp(argv[i], "-?") == 0) {
+                  strcmp(argv[i], "-?") == 0 ||
+                   strcmp(argv[i], "--help") == 0) {
            usage();
         } else if (strcmp(argv[i], "-pgpfp") == 0) {
             pgp_fingerprints();
             return 1;
-       } else if (strcmp(argv[i], "-V") == 0) {
+       } else if (strcmp(argv[i], "-V") == 0 ||
+                   strcmp(argv[i], "--version") == 0) {
            version();
        } else if (strcmp(argv[i], "-batch") == 0) {
            console_batch_mode = 1;
index 2c0df9c..bd69fb6 100644 (file)
@@ -2592,6 +2592,13 @@ static void help(FILE *fp) {
     }
 }
 
+static void version(FILE *fp) {
+    if(fprintf(fp, "%s: %s\n", appname, ver) < 0 || fflush(fp) < 0) {
+       perror("output error");
+       exit(1);
+    }
+}
+
 int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
                struct gui_data *inst, Conf *conf)
 {
@@ -2801,6 +2808,10 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
            help(stdout);
            exit(0);
 
+       } else if(!strcmp(p, "-version") || !strcmp(p, "--version")) {
+           version(stdout);
+           exit(0);
+
         } else if (!strcmp(p, "-pgpfp")) {
             pgp_fingerprints();
             exit(1);
index 0d89622..560ec38 100644 (file)
@@ -654,8 +654,11 @@ int main(int argc, char **argv)
            } else if (!strcmp(p, "-s")) {
                 /* Save status to write to conf later. */
                use_subsystem = 1;
-           } else if (!strcmp(p, "-V")) {
+           } else if (!strcmp(p, "-V") || !strcmp(p, "--version")) {
                 version();
+           } else if (!strcmp(p, "--help")) {
+                usage();
+                exit(0);
             } else if (!strcmp(p, "-pgpfp")) {
                 pgp_fingerprints();
                 exit(1);
index 7ec98e7..0abed7c 100644 (file)
@@ -343,8 +343,10 @@ int main(int argc, char **argv)
            } else if (!strcmp(p, "-s")) {
                /* Save status to write to conf later. */
                use_subsystem = 1;
-           } else if (!strcmp(p, "-V")) {
+           } else if (!strcmp(p, "-V") || !strcmp(p, "--version")) {
                 version();
+           } else if (!strcmp(p, "--help")) {
+                usage();
             } else if (!strcmp(p, "-pgpfp")) {
                 pgp_fingerprints();
                 exit(1);