From: Bruno Haible Date: Sat, 19 Jul 2008 13:56:10 +0000 (+0000) Subject: Move the verbosity from the GetURL program to the urlget program. X-Git-Tag: v0.18~394 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1bf7c2fd53245edf854c60d59c6e2fb28ea4563;p=thirdparty%2Fgettext.git Move the verbosity from the GetURL program to the urlget program. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 53fbd6010..9e0d17243 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,16 @@ +2008-07-19 Bruno Haible + + * 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 宋浩 . + 2008-06-10 Bruno Haible * msgexec.c (process_string): Update for changed signature of diff --git a/gettext-tools/src/gnu/gettext/GetURL.java b/gettext-tools/src/gnu/gettext/GetURL.java index 6ce4046db..f42ccc4dc 100644 --- a/gettext-tools/src/gnu/gettext/GetURL.java +++ b/gettext-tools/src/gnu/gettext/GetURL.java @@ -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) diff --git a/gettext-tools/src/urlget.c b/gettext-tools/src/urlget.c index cf1545ac7..d79aff9e2 100644 --- a/gettext-tools/src/urlget.c +++ b/gettext-tools/src/urlget.c @@ -62,10 +62,18 @@ 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); }