/* Parsing FTP `ls' output.
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
+ Inc.
This file is part of GNU Wget.
struct tm timestruct;
char *line, *tok; /* tokenizer */
+ char *filename;
struct fileinfo *dir, *l, cur; /* list creation */
fp = fopen (file, "rb");
{
len = clean_line (line);
- /* Extracting name is a bit of black magic and we have to do it
- before `strtok' inserted extra \0 characters in the line
- string. For the moment let us just suppose that the name starts at
- column 39 of the listing. This way we could also recognize
- filenames that begin with a series of space characters (but who
- really wants to use such filenames anyway?). */
- if (len < 40) continue;
- tok = line + 39;
- cur.name = xstrdup(tok);
- DEBUGP (("Name: '%s'\n", cur.name));
+ /* Name begins at 39 column of the listing if date presented in `mm-dd-yy'
+ format or at 41 column if date presented in `mm-dd-yyyy' format. Thus,
+ we cannot extract name before we parse date. Using this information we
+ also can recognize filenames that begin with a series of space
+ characters (but who really wants to use such filenames anyway?). */
+ if (len < 40) goto continue_loop;
+ filename = line + 39;
- /* First column: mm-dd-yy. Should atoi() on the month fail, january
- will be assumed. */
+ /* First column: mm-dd-yy or mm-dd-yyyy. Should atoi() on the month fail,
+ january will be assumed. */
tok = strtok(line, "-");
- if (tok == NULL) continue;
+ if (tok == NULL) goto continue_loop;
month = atoi(tok) - 1;
if (month < 0) month = 0;
tok = strtok(NULL, "-");
- if (tok == NULL) continue;
+ if (tok == NULL) goto continue_loop;
day = atoi(tok);
tok = strtok(NULL, " ");
- if (tok == NULL) continue;
+ if (tok == NULL) goto continue_loop;
year = atoi(tok);
/* Assuming the epoch starting at 1.1.1970 */
- if (year <= 70) year += 100;
+ if (year <= 70)
+ {
+ year += 100;
+ }
+ else if (year >= 1900)
+ {
+ year -= 1900;
+ filename += 2;
+ }
+ /* Now it is possible to determine the position of the first symbol in
+ filename. */
+ cur.name = xstrdup(filename);
+ DEBUGP (("Name: '%s'\n", cur.name));
+
/* Second column: hh:mm[AP]M, listing does not contain value for
seconds */
tok = strtok(NULL, ":");
- if (tok == NULL) continue;
+ if (tok == NULL) goto continue_loop;
hour = atoi(tok);
tok = strtok(NULL, "M");
- if (tok == NULL) continue;
+ if (tok == NULL) goto continue_loop;
min = atoi(tok);
/* Adjust hour from AM/PM. Just for the record, the sequence goes
11:00AM, 12:00PM, 01:00PM ... 11:00PM, 12:00AM, 01:00AM . */
directories as the listing does not give us a clue) and filetype
here. */
tok = strtok(NULL, " ");
- if (tok == NULL) continue;
+ if (tok == NULL) goto continue_loop;
while ((tok != NULL) && (*tok == '\0')) tok = strtok(NULL, " ");
- if (tok == NULL) continue;
+ if (tok == NULL) goto continue_loop;
if (*tok == '<')
{
cur.type = FT_DIRECTORY;
l->next = NULL;
}
+continue_loop:
xfree (line);
}