]> sjero.net Git - wget/blobdiff - src/ftp-ls.c
[svn] Fix breakage in ls output parsing. By Larry Jones.
[wget] / src / ftp-ls.c
index 93bdf79f53421a0bc68c0be094985c30b37b6ac4..6406c8fbe9894a8b3d1f0e27656c18e968d2b290 100644 (file)
@@ -104,7 +104,7 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
   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");
@@ -195,7 +195,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.  */
-      while ((tok = strtok (NULL, " ")) != NULL)
+      tok = line;
+      while (ptok = tok,
+            (tok = strtok (NULL, " ")) != NULL)
        {
          --next;
          if (next < 0)         /* a month name was not encountered */
@@ -209,25 +211,22 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
                {
                  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;
-                 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;
+                 DEBUGP (("size: %s; ", number_to_static_string(cur.size)));
 
                  month = i;
                  next = 5;
@@ -361,7 +360,7 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
       if (!cur.name || (cur.type == FT_SYMLINK && !cur.linkto))
        error = 1;
 
-      DEBUGP (("\n"));
+      DEBUGP (("%s\n", cur.name ? cur.name : ""));
 
       if (error || ignore)
        {
@@ -642,7 +641,8 @@ ftp_parse_vms_ls (const char *file)
       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';
@@ -724,10 +724,12 @@ ftp_parse_vms_ls (const char *file)
       min = sec = 0;
       p = tok;
       hour = atoi (p);
-      for (; *p && *p != ':'; ++p);
+      for (; *p && *p != ':'; ++p)
+       ;
       if (*p)
        min = atoi (++p);
-      for (; *p && *p != ':'; ++p);
+      for (; *p && *p != ':'; ++p)
+       ;
       if (*p)
        sec = atoi (++p);