ftpparse + foreign month names

<[email protected]> Sun, 9 Feb 2003 12:16:03 -0800 (PST)
Newsgroups gmane.comp.lib.ftp-parse
Message-ID <[email protected]>
It appears so that ftpparse cannot handle LIST
entries which include a month name in a foreign language.

this code is used to match a monthname from a list entry

with the ones listed in static char *months
static int check(char *buf,char *monthname)
{
  if ((buf[0] != monthname[0]) && (buf[0] != monthname[0] - 32))
      return 0;
  if ((buf[1] != monthname[1]) && (buf[1] != monthname[1] - 32))
      return 0;
  if ((buf[2] != monthname[2]) && (buf[2] != monthname[2] - 32))
      return 0;
  return 1;
}

static char *months[12] = {
  "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"
} ;

static int getmonth(char *buf,int len)
{
  int i;
  if (len == 3)
    for (i = 0;i < 12;++i)
      if (check(buf,months[i])) return i;
  return -1;
}

when the month in the LIST entry is from a foreign language,
for example in Icelandic "dec" would be "des" and getmonth
would not find anything.

this is the code that calls getmonth to try to convert monthname
into its corresponding month number.  (for the normal UNIX listing).

case 5: /* searching for month, otherwise getting tentative size */
  month = getmonth(buf + i,j - i);
  if (month >= 0)
    state = 6;
  else
    size = getlong(buf + i,j - i);
  break;

if month is greater or equal to 0, it goes to state 6 and continues,
however, if it less than 0 (which is the case when an "invalid"
month has been encountered) then it tries to find some "tentative" size
and is not continued.

This is causing some problem in a program of mine that has been
using ftpparse because ftpparse() returns 0 when a LIST output
with a "foreign month name" is encounted and that line is, therefore, not
handled.

A solution would be to try to parse month names as is done currently
but when the month name is a foreign one then save it as a string
and leave mtime as -1 to indicate that it was not possible to parse
it to find its modification time.  This would allow the entries to be
shown in the ftp program.


gunnsteinn hall