]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Move the verbosity from the GetURL program to the urlget program.
authorBruno Haible <bruno@clisp.org>
Sat, 19 Jul 2008 13:56:10 +0000 (13:56 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:45 +0000 (12:15 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/gnu/gettext/GetURL.java
gettext-tools/src/urlget.c

index 53fbd601090c416ce0a07ea91afaa0fa9f1dc5df..9e0d17243fd38157a5b7ec485609b8a3e749fe56 100644 (file)
@@ -1,3 +1,16 @@
+2008-07-19  Bruno Haible  <bruno@clisp.org>
+
+       * gnu/gettext/GetURL.java: Don't output anything to standard error.
+       Instead, set exit code to indicate failure reason.
+       * urlget.c (verbose): New variable.
+       (long_options): Add --quiet, --silent option.
+       (main): Implement --quiet, --silent option.
+       (usage): Document --quiet, --silent option.
+       (java_exitcode): New variable.
+       (execute_it): Set it. Return false also when the exit code is 2.
+       (fetch): Implement verbosity to standard error here.
+       Reported by 宋浩 <baritono.tux@gmail.com>.
+
 2008-06-10  Bruno Haible  <bruno@clisp.org>
 
        * msgexec.c (process_string): Update for changed signature of
index 6ce4046dbbfa73eb5964a52544c5edda8b3f4bed..f42ccc4dc993d609892c5c32c266aa352e8a9787 100644 (file)
@@ -1,5 +1,5 @@
 /* Fetch an URL's contents.
- * Copyright (C) 2001 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2008 Free Software Foundation, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +21,10 @@ import java.io.*;
 import java.net.*;
 
 /**
+ * Fetch an URL's contents and emit it to standard output.
+ * Exit code: 0 = success
+ *            1 = failure
+ *            2 = timeout
  * @author Bruno Haible
  */
 public class GetURL {
@@ -37,10 +41,6 @@ public class GetURL {
       System.exit(1);
       return;
     }
-    // We always print something on stderr because the user should know
-    // why we are trying to establish an internet connection.
-    System.err.print("Retrieving "+s+"...");
-    System.err.flush();
     done = false;
     timeoutThread =
       new Thread() {
@@ -48,8 +48,7 @@ public class GetURL {
           try {
             sleep(timeout);
             if (!done) {
-              System.err.println(" timed out.");
-              System.exit(1);
+              System.exit(2);
             }
           } catch (InterruptedException e) {
           }
@@ -69,11 +68,9 @@ public class GetURL {
       istream.close();
     } catch (IOException e) {
       //e.printStackTrace();
-      System.err.println(" failed.");
       System.exit(1);
     }
     done = true;
-    System.err.println(" done.");
   }
   public static void main (String[] args) {
     if (args.length != 1)
index cf1545ac722b0590266d37d87ffa9ed53624b28e..d79aff9e2f01650542fe486cc17117c4788ca793 100644 (file)
    HTML parsers.]  */
 
 
+/* Whether to output something on standard error.
+   This is true by default, because the user should know why we are trying to
+   establish an internet connection.  Also, users get confused if a program
+   produces no output for more than 10 seconds for no apparent reason.  */
+static bool verbose = true;
+
 /* Long options.  */
 static const struct option long_options[] =
 {
   { "help", no_argument, NULL, 'h' },
+  { "quiet", no_argument, NULL, 'q' },
+  { "silent", no_argument, NULL, 'q' },
   { "version", no_argument, NULL, 'V' },
   { NULL, 0, NULL, 0 }
 };
@@ -108,15 +116,18 @@ main (int argc, char *argv[])
   do_version = false;
 
   /* Parse command line options.  */
-  while ((optchar = getopt_long (argc, argv, "hV", long_options, NULL)) != EOF)
+  while ((optchar = getopt_long (argc, argv, "hqV", long_options, NULL)) != EOF)
     switch (optchar)
     {
     case '\0':         /* Long option.  */
       break;
-    case 'h':
+    case 'h':          /* --help */
       do_help = true;
       break;
-    case 'V':
+    case 'q':          /* --quiet / --silent */
+      verbose = false;
+      break;
+    case 'V':          /* --version */
       do_version = true;
       break;
     default:
@@ -178,6 +189,8 @@ Informative output:\n"));
   -h, --help                  display this help and exit\n"));
       printf (_("\
   -V, --version               output version information and exit\n"));
+      printf (_("\
+  -q, --quiet, --silent       suppress progress indicators\n"));
       printf ("\n");
       /* TRANSLATORS: The placeholder indicates the bug-reporting address
          for this package.  Please add _another line_ saying
@@ -225,6 +238,9 @@ cat_file (const char *src_filename)
     error (EXIT_FAILURE, errno, _("error after reading \"%s\""), src_filename);
 }
 
+/* Exit code of the Java program.  */
+static int java_exitcode;
+
 static bool
 execute_it (const char *progname,
            const char *prog_path, char **prog_argv,
@@ -232,15 +248,23 @@ execute_it (const char *progname,
 {
   (void) private_data;
 
-  return execute (progname, prog_path, prog_argv, true, true, false, false,
-                 true, false, NULL)
-        != 0;
+  java_exitcode =
+    execute (progname, prog_path, prog_argv, true, true, false, false, true,
+            false, NULL);
+  /* Exit code 0 means success, 2 means timed out.  */
+  return !(java_exitcode == 0 || java_exitcode == 2);
 }
 
 /* Fetch the URL.  Upon error, use the FILE as fallback.  */
 static void
 fetch (const char *url, const char *file)
 {
+  if (verbose)
+    {
+      fprintf (stderr, _("Retrieving %s..."), url);
+      fflush (stderr);
+    }
+
   /* First try: using Java.  */
   {
     const char *class_name = "gnu.gettext.GetURL";
@@ -269,11 +293,21 @@ fetch (const char *url, const char *file)
     args[1] = NULL;
 
     /* Fetch the URL's contents.  */
-    if (execute_java_class (class_name, &gettextjar, 1, true, gettextjexedir,
-                           args,
-                           false, true,
-                           execute_it, NULL) == 0)
-      return;
+    java_exitcode = 127;
+    if (!execute_java_class (class_name, &gettextjar, 1, true, gettextjexedir,
+                            args,
+                            false, true,
+                            execute_it, NULL))
+      {
+       if (verbose)
+         {
+           if (java_exitcode == 0)
+             fprintf (stderr, _(" done.\n"));
+           else if (java_exitcode == 2)
+             fprintf (stderr, _(" timed out.\n"));
+         }
+       return;
+      }
   }
 
   /* Second try: using "wget -q -O - url".  */
@@ -312,8 +346,9 @@ fetch (const char *url, const char *file)
        if (exitstatus != 127)
          {
            if (exitstatus != 0)
-             /* Use the file as fallback.  */
-             cat_file (file);
+             goto failed;
+           if (verbose)
+             fprintf (stderr, _(" done.\n"));
            return;
          }
       }
@@ -353,8 +388,9 @@ fetch (const char *url, const char *file)
        if (exitstatus != 127)
          {
            if (exitstatus != 0)
-             /* Use the file as fallback.  */
-             cat_file (file);
+             goto failed;
+           if (verbose)
+             fprintf (stderr, _(" done.\n"));
            return;
          }
       }
@@ -394,13 +430,17 @@ fetch (const char *url, const char *file)
        if (exitstatus != 127)
          {
            if (exitstatus != 0)
-             /* Use the file as fallback.  */
-             cat_file (file);
+             goto failed;
+           if (verbose)
+             fprintf (stderr, _(" done.\n"));
            return;
          }
       }
   }
 
+ failed:
+  if (verbose)
+    fprintf (stderr, _(" failed.\n"));
   /* Use the file as fallback.  */
   cat_file (file);
 }