]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Use wget and lynx as fallbacks for Java.
authorBruno Haible <bruno@clisp.org>
Mon, 26 Nov 2001 13:41:15 +0000 (13:41 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Jun 2009 21:25:03 +0000 (23:25 +0200)
src/ChangeLog
src/urlget.c

index 6c55a3b767c56f9ee0a10068788a0ff48c936ea9..9c5ac6d83bf57050ff9c32ba47b9b5f19b164b7b 100644 (file)
@@ -1,5 +1,8 @@
 2001-11-24  Bruno Haible  <bruno@clisp.org>
 
+       * urlget.c (fetch): Call execute_java_class with quiet=true. If Java
+       program failed, try wget or lynx.
+
        * read-java.c (msgdomain_read_java): Update for changed
        execute_java_class parameter list.
 
index 2c2d7779e2eb68a917734a1135d9bdb370abc093..2db7b8b47daeaf67dca7da88cb61bc92096c06df 100644 (file)
@@ -245,25 +245,110 @@ fetch (url, file)
      const char *url;
      const char *file;
 {
-  const char *class_name = "gnu.gettext.GetURL";
-  const char *gettextjar;
-  const char *args[2];
-
-  /* Make it possible to override the gettext.jar location.  This is
-     necessary for running the testsuite before "make install".  */
-  gettextjar = getenv ("GETTEXTJAR");
-  if (gettextjar == NULL || gettextjar[0] == '\0')
-    gettextjar = GETTEXTJAR;
-
-  /* Prepare arguments.  */
-  args[0] = url;
-  args[1] = NULL;
-
-  /* Fetch the URL's contents.  */
-  if (execute_java_class (class_name, &gettextjar, 1, true,
-                         args,
-                         false,
-                         execute_it, NULL))
-    /* Use the file as fallback.  */
-    cat_file (file);
+  /* First try: using Java.  */
+  {
+    const char *class_name = "gnu.gettext.GetURL";
+    const char *gettextjar;
+    const char *args[2];
+
+    /* Make it possible to override the gettext.jar location.  This is
+       necessary for running the testsuite before "make install".  */
+    gettextjar = getenv ("GETTEXTJAR");
+    if (gettextjar == NULL || gettextjar[0] == '\0')
+      gettextjar = GETTEXTJAR;
+
+    /* Prepare arguments.  */
+    args[0] = url;
+    args[1] = NULL;
+
+    /* Fetch the URL's contents.  */
+    if (execute_java_class (class_name, &gettextjar, 1, true,
+                           args,
+                           false, true,
+                           execute_it, NULL) == 0)
+      return;
+  }
+
+  /* Second try: using "wget -q -O - url".  */
+  {
+    static bool wget_tested;
+    static bool wget_present;
+
+    if (!wget_tested)
+      {
+       /* Test for presence of wget: "wget --version > /dev/null"  */
+       char *argv[3];
+       int exitstatus;
+
+       argv[0] = "wget";
+       argv[1] = "--version";
+       argv[2] = NULL;
+       exitstatus = execute ("wget", "wget", argv, false, true, true, false);
+       wget_present = (exitstatus == 0);
+       wget_tested = true;
+      }
+
+    if (wget_present)
+      {
+       char *argv[8];
+       int exitstatus;
+
+       argv[0] = "wget";
+       argv[1] = "-q";
+       argv[2] = "-O"; argv[3] = "-";
+       argv[4] = "-T"; argv[5] = "30";
+       argv[6] = (char *) url;
+       argv[7] = NULL;
+       exitstatus = execute ("wget", "wget", argv, false, false, false, false);
+       if (exitstatus != 127)
+         {
+           if (exitstatus != 0)
+             /* Use the file as fallback.  */
+             cat_file (file);
+           return;
+         }
+      }
+  }
+
+  /* Third try: using "lynx -source url".  */
+  {
+    static bool lynx_tested;
+    static bool lynx_present;
+
+    if (!lynx_tested)
+      {
+       /* Test for presence of lynx: "lynx --version > /dev/null"  */
+       char *argv[3];
+       int exitstatus;
+
+       argv[0] = "lynx";
+       argv[1] = "--version";
+       argv[2] = NULL;
+       exitstatus = execute ("lynx", "lynx", argv, false, true, true, false);
+       lynx_present = (exitstatus == 0);
+       lynx_tested = true;
+      }
+
+    if (lynx_present)
+      {
+       char *argv[4];
+       int exitstatus;
+
+       argv[0] = "lynx";
+       argv[1] = "-source";
+       argv[2] = (char *) url;
+       argv[3] = NULL;
+       exitstatus = execute ("lynx", "lynx", argv, false, false, false, false);
+       if (exitstatus != 127)
+         {
+           if (exitstatus != 0)
+             /* Use the file as fallback.  */
+             cat_file (file);
+           return;
+         }
+      }
+  }
+
+  /* Use the file as fallback.  */
+  cat_file (file);
 }