* 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>
* smbfs.c: Undef USE_NCURSES - no needs to include *curces.h.

View File

@ -1573,9 +1573,10 @@ int vfs_parse_filemode (const char *p)
return res;
}
int vfs_parse_filedate(int idx, time_t *t)
{ /* This thing parses from idx in columns[] array */
/* This function parses from idx in the columns[] array */
int
vfs_parse_filedate (int idx, time_t *t)
{
char *p;
struct tm tim;
int d[3];
@ -1590,17 +1591,17 @@ int vfs_parse_filedate(int idx, time_t *t)
tim.tm_sec = 0;
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 */
if(is_week(p, &tim))
p = columns [idx++];
if (is_week (p, &tim))
p = columns[idx++];
/* Month name */
if(is_month(p, &tim)){
if (is_month (p, &tim)) {
/* And we expect, it followed by day number */
if (is_num (idx))
tim.tm_mday = (int)atol (columns [idx++]);
tim.tm_mday = (int) atol (columns[idx++]);
else
return 0; /* No day */
@ -1617,22 +1618,22 @@ int vfs_parse_filedate(int idx, time_t *t)
YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
/* Here just this special case with MM-DD-YY */
if (is_dos_date(p)){
if (is_dos_date (p)) {
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:
1. MM-DD-YY
2. DD-MM-YY
3. YY-MM-DD
4. YY-DD-MM */
/* Hmm... maybe, next time :)*/
/* Hmm... maybe, next time :) */
/* At last, MM-DD-YY */
d[0]--; /* Months are zerobased */
/* Y2K madness */
if(d[2] < 70)
if (d[2] < 70)
d[2] += 100;
tim.tm_mon = d[0];
@ -1648,16 +1649,22 @@ int vfs_parse_filedate(int idx, time_t *t)
/* Here we expect to find time and/or year */
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++;
/* This is a special case for ctime() or Mon DD YYYY hh:mm */
if(is_num (idx) && (columns[idx+1][0]) &&
((got_year |= is_year(columns[idx], &tim)) || is_time(columns[idx], &tim)))
idx++; /* time & year or reverse */
} /* only time or date */
if (is_num (idx) && (columns[idx + 1][0])) {
if (got_year) {
if (is_time (columns[idx], &tim))
idx++; /* time also */
} else {
if ((got_year = is_year (columns[idx], &tim)))
idx++; /* year also */
}
else
}
} /* only time or date */
} else
return 0; /* Nor time or date */
/*
@ -1666,13 +1673,12 @@ int vfs_parse_filedate(int idx, time_t *t)
* This does not check for years before 1900 ... I don't know, how
* to represent them at all
*/
if (!got_year &&
current_mon < 6 && current_mon < tim.tm_mon &&
tim.tm_mon - current_mon >= 6)
if (!got_year && current_mon < 6 && current_mon < tim.tm_mon
&& tim.tm_mon - current_mon >= 6)
tim.tm_year--;
if ((*t = mktime(&tim)) < 0)
if ((*t = mktime (&tim)) < 0)
*t = 0;
return idx;
}