+ len = clean_line (line, len);
+
+ /* 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) continue;
+ filename = line + 39;
+
+ /* 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;
+ month = atoi(tok) - 1;
+ if (month < 0) month = 0;
+ tok = strtok(NULL, "-");
+ if (tok == NULL) continue;
+ day = atoi(tok);
+ tok = strtok(NULL, " ");
+ if (tok == NULL) continue;
+ year = atoi(tok);
+ /* Assuming the epoch starting at 1.1.1970 */
+ 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;
+ hour = atoi(tok);
+ tok = strtok(NULL, "M");
+ if (tok == NULL) continue;
+ 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 . */
+ tok+=2;
+ if (hour == 12) hour = 0;
+ if (*tok == 'P') hour += 12;
+
+ DEBUGP (("YYYY/MM/DD HH:MM - %d/%02d/%02d %02d:%02d\n",
+ year+1900, month, day, hour, min));
+
+ /* Build the time-stamp (copy & paste from above) */
+ timestruct.tm_sec = 0;
+ timestruct.tm_min = min;
+ timestruct.tm_hour = hour;
+ timestruct.tm_mday = day;
+ timestruct.tm_mon = month;
+ timestruct.tm_year = year;
+ timestruct.tm_wday = 0;
+ timestruct.tm_yday = 0;
+ timestruct.tm_isdst = -1;
+ cur.tstamp = mktime (×truct); /* store the time-stamp */
+ cur.ptype = TT_HOUR_MIN;
+
+ DEBUGP (("Timestamp: %ld\n", cur.tstamp));
+
+ /* Third column: Either file length, or <DIR>. We also set the
+ permissions (guessed as 0644 for plain files and 0755 for
+ directories as the listing does not give us a clue) and filetype
+ here. */
+ tok = strtok(NULL, " ");
+ if (tok == NULL) continue;
+ while ((tok != NULL) && (*tok == '\0')) tok = strtok(NULL, " ");
+ if (tok == NULL) continue;
+ if (*tok == '<')
+ {
+ cur.type = FT_DIRECTORY;
+ cur.size = 0;
+ cur.perms = 0755;
+ DEBUGP (("Directory\n"));
+ }
+ else
+ {
+ wgint size;
+ cur.type = FT_PLAINFILE;
+ errno = 0;
+ size = str_to_wgint (tok, NULL, 10);
+ if (size == WGINT_MAX && errno == ERANGE)
+ cur.size = 0; /* overflow */
+ else
+ cur.size = size;
+ cur.perms = 0644;
+ DEBUGP (("File, size %s bytes\n", number_to_static_string (cur.size)));
+ }
+
+ cur.linkto = NULL;
+
+ /* And put everything into the linked list */
+ if (!dir)
+ {
+ l = dir = xnew (struct fileinfo);
+ memcpy (l, &cur, sizeof (cur));
+ l->prev = l->next = NULL;
+ }
+ else
+ {
+ cur.prev = l;
+ l->next = xnew (struct fileinfo);
+ l = l->next;
+ memcpy (l, &cur, sizeof (cur));
+ l->next = NULL;
+ }
+ }
+
+ xfree (line);
+ fclose(fp);
+ return dir;
+}
+
+
+
+/* Convert the VMS-style directory listing stored in "file" to a
+ linked list of fileinfo (system-independent) entries. The contents
+ of FILE are considered to be produced by the standard VMS
+ "DIRECTORY [/SIZE [= ALL]] /DATE [/OWNER] [/PROTECTION]" command,
+ more or less. (Different VMS FTP servers may have different headers,
+ and may not supply the same data, but all should be subsets of this.)
+
+ VMS normally provides local (server) time and date information.
+ Define the logical name or environment variable
+ "WGET_TIMEZONE_DIFFERENTIAL" (seconds) to adjust the receiving local
+ times if different from the remote local times.
+
+ 2005-02-23 SMS.
+ Added code to eliminate "^" escape characters from ODS5 extended file
+ names. The TCPIP FTP server (V5.4) seems to prefer requests which do
+ not use the escaped names which it provides.
+*/
+
+#define VMS_DEFAULT_PROT_FILE 0644
+#define VMS_DEFAULT_PROT_DIR 0755
+
+/* 2005-02-23 SMS.
+ eat_carets().
+
+ Delete ODS5 extended file name escape characters ("^") in the
+ original buffer.
+ Note that the current scheme does not handle all EFN cases, but it
+ could be made more complicated.
+*/
+
+static void eat_carets( char *str)
+/* char *str; Source pointer. */
+{
+ char *strd; /* Destination pointer. */
+ char hdgt;
+ unsigned char uchr;
+ unsigned char prop;
+
+ /* Skip ahead to the first "^", if any. */
+ while ((*str != '\0') && (*str != '^'))
+ str++;
+
+ /* If no caret was found, quit early. */
+ if (*str != '\0')
+ {
+ /* Shift characters leftward as carets are found. */
+ strd = str;
+ while (*str != '\0')
+ {
+ uchr = *str;
+ if (uchr == '^')
+ {
+ /* Found a caret. Skip it, and check the next character. */
+ uchr = *(++str);
+ prop = char_prop[ uchr];
+ if (prop& 64)
+ {
+ /* Hex digit. Get char code from this and next hex digit. */
+ if (uchr <= '9')
+ {
+ hdgt = uchr- '0'; /* '0' - '9' -> 0 - 9. */
+ }
+ else
+ {
+ hdgt = ((uchr- 'A')& 7)+ 10; /* [Aa] - [Ff] -> 10 - 15. */
+ }
+ hdgt <<= 4; /* X16. */
+ uchr = *(++str); /* Next char must be hex digit. */
+ if (uchr <= '9')
+ {
+ uchr = hdgt+ uchr- '0';
+ }
+ else
+ {
+ uchr = hdgt+ ((uchr- 'A')& 15)+ 10;
+ }
+ }
+ else if (uchr == '_')
+ {
+ /* Convert escaped "_" to " ". */
+ uchr = ' ';
+ }
+ else if (uchr == '/')
+ {
+ /* Convert escaped "/" (invalid Zip) to "?" (invalid VMS). */
+ /* Note that this is a left-over from Info-ZIP code, and is
+ probably of little value here, except perhaps to avoid
+ directory confusion which an unconverted slash might cause.
+ */
+ uchr = '?';
+ }
+ /* Else, not a hex digit. Must be a simple escaped character
+ (or Unicode, which is not yet handled here).
+ */