]> sjero.net Git - wget/blobdiff - src/ftp-ls.c
[svn] Merge of fix for bugs 20341 and 20410.
[wget] / src / ftp-ls.c
index 7e448295e64f82d9bb5631185d2b0afe26a0c459..748bd788a9df591e3388ef49d77bfca09aada6bf 100644 (file)
@@ -1,12 +1,11 @@
 /* Parsing FTP `ls' output.
 /* Parsing FTP `ls' output.
-   Copyright (C) 1995, 1996, 1997, 2000, 2001
-   Free Software Foundation, Inc. 
+   Copyright (C) 1996-2004 Free Software Foundation, Inc. 
 
 This file is part of GNU Wget.
 
 GNU Wget is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 
 This file is part of GNU Wget.
 
 GNU Wget is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 GNU Wget is distributed in the hope that it will be useful,
 (at your option) any later version.
 
 GNU Wget is distributed in the hope that it will be useful,
@@ -15,8 +14,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with Wget; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+along with Wget.  If not, see <http://www.gnu.org/licenses/>.
 
 In addition, as a special exception, the Free Software Foundation
 gives permission to link the code of its release of Wget with the
 
 In addition, as a special exception, the Free Software Foundation
 gives permission to link the code of its release of Wget with the
@@ -44,8 +42,7 @@ so, delete this exception statement from your version.  */
 #include "ftp.h"
 #include "url.h"
 #include "convert.h"           /* for html_quote_string prototype */
 #include "ftp.h"
 #include "url.h"
 #include "convert.h"           /* for html_quote_string prototype */
-
-extern FILE *output_stream;
+#include "retr.h"              /* for output_stream */
 
 /* Converts symbolic permissions to number-style ones, e.g. string
    rwxr-xr-x to 755.  For now, it knows nothing of
 
 /* Converts symbolic permissions to number-style ones, e.g. string
    rwxr-xr-x to 755.  For now, it knows nothing of
@@ -106,7 +103,7 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
   struct tm timestruct, *tnow;
   time_t timenow;
 
   struct tm timestruct, *tnow;
   time_t timenow;
 
-  char *line, *tok;            /* tokenizer */
+  char *line, *tok, *ptok;     /* tokenizer */
   struct fileinfo *dir, *l, cur; /* list creation */
 
   fp = fopen (file, "rb");
   struct fileinfo *dir, *l, cur; /* list creation */
 
   fp = fopen (file, "rb");
@@ -197,7 +194,9 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
         This tactic is quite dubious when it comes to
         internationalization issues (non-English month names), but it
         works for now.  */
         This tactic is quite dubious when it comes to
         internationalization issues (non-English month names), but it
         works for now.  */
-      while ((tok = strtok (NULL, " ")) != NULL)
+      tok = line;
+      while (ptok = tok,
+            (tok = strtok (NULL, " ")) != NULL)
        {
          --next;
          if (next < 0)         /* a month name was not encountered */
        {
          --next;
          if (next < 0)         /* a month name was not encountered */
@@ -211,25 +210,22 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
                {
                  wgint size;
 
                {
                  wgint size;
 
-                 /* Back up to the beginning of the previous token
-                    and parse it with str_to_wgint.  */
-                 char *t = tok - 2;
-                 while (t > line && ISDIGIT (*t))
-                   --t;
-                 if (t == line)
+                 /* Parse the previous token with str_to_wgint.  */
+                 if (ptok == line)
                    {
                      /* Something has gone wrong during parsing. */
                      error = 1;
                      break;
                    }
                  errno = 0;
                    {
                      /* Something has gone wrong during parsing. */
                      error = 1;
                      break;
                    }
                  errno = 0;
-                 size = str_to_wgint (t, NULL, 10);
+                 size = str_to_wgint (ptok, NULL, 10);
                  if (size == WGINT_MAX && errno == ERANGE)
                    /* Out of range -- ignore the size.  #### Should
                       we refuse to start the download.  */
                    cur.size = 0;
                  else
                    cur.size = size;
                  if (size == WGINT_MAX && errno == ERANGE)
                    /* Out of range -- ignore the size.  #### Should
                       we refuse to start the download.  */
                    cur.size = 0;
                  else
                    cur.size = size;
+                 DEBUGP (("size: %s; ", number_to_static_string(cur.size)));
 
                  month = i;
                  next = 5;
 
                  month = i;
                  next = 5;
@@ -363,7 +359,7 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
       if (!cur.name || (cur.type == FT_SYMLINK && !cur.linkto))
        error = 1;
 
       if (!cur.name || (cur.type == FT_SYMLINK && !cur.linkto))
        error = 1;
 
-      DEBUGP (("\n"));
+      DEBUGP (("%s\n", cur.name ? cur.name : ""));
 
       if (error || ignore)
        {
 
       if (error || ignore)
        {
@@ -644,7 +640,8 @@ ftp_parse_vms_ls (const char *file)
       tok = strtok(line, " ");
       if (tok == NULL) tok = line;
       DEBUGP(("file name: '%s'\n", tok));
       tok = strtok(line, " ");
       if (tok == NULL) tok = line;
       DEBUGP(("file name: '%s'\n", tok));
-      for (p = tok ; *p && *p != ';' ; p++);
+      for (p = tok ; *p && *p != ';' ; p++)
+       ;
       if (*p == ';') *p = '\0';
       p   = tok + strlen(tok) - 4;
       if (!strcmp(p, ".DIR")) *p = '\0';
       if (*p == ';') *p = '\0';
       p   = tok + strlen(tok) - 4;
       if (!strcmp(p, ".DIR")) *p = '\0';
@@ -726,10 +723,12 @@ ftp_parse_vms_ls (const char *file)
       min = sec = 0;
       p = tok;
       hour = atoi (p);
       min = sec = 0;
       p = tok;
       hour = atoi (p);
-      for (; *p && *p != ':'; ++p);
+      for (; *p && *p != ':'; ++p)
+       ;
       if (*p)
        min = atoi (++p);
       if (*p)
        min = atoi (++p);
-      for (; *p && *p != ':'; ++p);
+      for (; *p && *p != ':'; ++p)
+       ;
       if (*p)
        sec = atoi (++p);
 
       if (*p)
        sec = atoi (++p);