* vfs.c (vfs_parse_filemode): Fix parsing for filenames that

begin with a number.
From Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
This commit is contained in:
Pavel Roskin 2002-09-25 05:09:08 +00:00
parent a3f9820755
commit d2417f2096
2 changed files with 70 additions and 58 deletions

View File

@ -1,3 +1,9 @@
2002-09-25 Pavel Roskin <proski@gnu.org>
* vfs.c (vfs_parse_filemode): Fix parsing for filenames that
begin with a number.
From Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
2002-09-24 Andrew V. Samoilov <sav@bcs.zp.ua> 2002-09-24 Andrew V. Samoilov <sav@bcs.zp.ua>
* smbfs.c: Undef USE_NCURSES - no needs to include *curces.h. * smbfs.c: Undef USE_NCURSES - no needs to include *curces.h.

110
vfs/vfs.c
View File

@ -1573,92 +1573,99 @@ int vfs_parse_filemode (const char *p)
return res; return res;
} }
int vfs_parse_filedate(int idx, time_t *t) /* This function parses from idx in the columns[] array */
{ /* This thing parses from idx in columns[] array */ int
vfs_parse_filedate (int idx, time_t *t)
{
char *p; char *p;
struct tm tim; struct tm tim;
int d[3]; int d[3];
int got_year = 0; int got_year = 0;
/* Let's setup default time values */ /* Let's setup default time values */
tim.tm_year = current_year; tim.tm_year = current_year;
tim.tm_mon = current_mon; tim.tm_mon = current_mon;
tim.tm_mday = current_mday; tim.tm_mday = current_mday;
tim.tm_hour = 0; tim.tm_hour = 0;
tim.tm_min = 0; tim.tm_min = 0;
tim.tm_sec = 0; tim.tm_sec = 0;
tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */ tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
p = columns [idx++]; p = columns[idx++];
/* We eat weekday name in case of extfs */ /* We eat weekday name in case of extfs */
if(is_week(p, &tim)) if (is_week (p, &tim))
p = columns [idx++]; p = columns[idx++];
/* Month name */ /* Month name */
if(is_month(p, &tim)){ if (is_month (p, &tim)) {
/* And we expect, it followed by day number */ /* And we expect, it followed by day number */
if (is_num (idx)) if (is_num (idx))
tim.tm_mday = (int)atol (columns [idx++]); tim.tm_mday = (int) atol (columns[idx++]);
else else
return 0; /* No day */ return 0; /* No day */
} else { } else {
/* We usually expect: /* We usually expect:
Mon DD hh:mm Mon DD hh:mm
Mon DD YYYY Mon DD YYYY
But in case of extfs we allow these date formats: But in case of extfs we allow these date formats:
Mon DD YYYY hh:mm Mon DD YYYY hh:mm
Mon DD hh:mm YYYY Mon DD hh:mm YYYY
Wek Mon DD hh:mm:ss YYYY Wek Mon DD hh:mm:ss YYYY
MM-DD-YY hh:mm MM-DD-YY hh:mm
where Mon is Jan-Dec, DD, MM, YY two digit day, month, year, where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
YYYY four digit year, hh, mm, ss two digit hour, minute or second. */ YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
/* Here just this special case with MM-DD-YY */ /* Here just this special case with MM-DD-YY */
if (is_dos_date(p)){ if (is_dos_date (p)) {
p[2] = p[5] = '-'; p[2] = p[5] = '-';
if(sscanf(p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3){ if (sscanf (p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3) {
/* We expect to get: /* We expect to get:
1. MM-DD-YY 1. MM-DD-YY
2. DD-MM-YY 2. DD-MM-YY
3. YY-MM-DD 3. YY-MM-DD
4. YY-DD-MM */ 4. YY-DD-MM */
/* Hmm... maybe, next time :)*/ /* Hmm... maybe, next time :) */
/* At last, MM-DD-YY */ /* At last, MM-DD-YY */
d[0]--; /* Months are zerobased */ d[0]--; /* Months are zerobased */
/* Y2K madness */ /* Y2K madness */
if(d[2] < 70) if (d[2] < 70)
d[2] += 100; d[2] += 100;
tim.tm_mon = d[0]; tim.tm_mon = d[0];
tim.tm_mday = d[1]; tim.tm_mday = d[1];
tim.tm_year = d[2]; tim.tm_year = d[2];
got_year = 1; got_year = 1;
} else } else
return 0; /* sscanf failed */ return 0; /* sscanf failed */
} else } else
return 0; /* unsupported format */ return 0; /* unsupported format */
} }
/* Here we expect to find time and/or year */ /* Here we expect to find time and/or year */
if (is_num (idx)) { if (is_num (idx)) {
if(is_time(columns[idx], &tim) || (got_year = is_year(columns[idx], &tim))) { if (is_time (columns[idx], &tim)
|| (got_year = is_year (columns[idx], &tim))) {
idx++; idx++;
/* This is a special case for ctime() or Mon DD YYYY hh:mm */ /* This is a special case for ctime() or Mon DD YYYY hh:mm */
if(is_num (idx) && (columns[idx+1][0]) && if (is_num (idx) && (columns[idx + 1][0])) {
((got_year |= is_year(columns[idx], &tim)) || is_time(columns[idx], &tim))) if (got_year) {
idx++; /* time & year or reverse */ if (is_time (columns[idx], &tim))
} /* only time or date */ idx++; /* time also */
} } else {
else if ((got_year = is_year (columns[idx], &tim)))
return 0; /* Nor time or date */ idx++; /* year also */
}
}
} /* only time or date */
} else
return 0; /* Nor time or date */
/* /*
* If the date is less than 6 months in the past, it is shown without year * If the date is less than 6 months in the past, it is shown without year
@ -1666,14 +1673,13 @@ int vfs_parse_filedate(int idx, time_t *t)
* This does not check for years before 1900 ... I don't know, how * This does not check for years before 1900 ... I don't know, how
* to represent them at all * to represent them at all
*/ */
if (!got_year && if (!got_year && current_mon < 6 && current_mon < tim.tm_mon
current_mon < 6 && current_mon < tim.tm_mon && && tim.tm_mon - current_mon >= 6)
tim.tm_mon - current_mon >= 6)
tim.tm_year--; tim.tm_year--;
if ((*t = mktime(&tim)) < 0) if ((*t = mktime (&tim)) < 0)
*t = 0; *t = 0;
return idx; return idx;
} }