/* lists a CPIO file's contents */
BOOL
ListCpio(ULONG type,UBYTE *infile)
{
  int ct, done, i;
  ULONG uncomp, comp, time;
  ULONG tfiles = 0, tcomp = 0, tuncomp = 0;
  UBYTE b[200],time_str[25];
  struct tm *tm;
  FILE *fp;

  fp = OpenFile(type,infile);
  ct = fread(b, 76, 1, fp);

  /* check CPIO signature */
  if ((strnicmp(CPIO_SIG,b,6) != 0) || ct != 1)
   {
    fclose(fp);
    return(WRONG_ARCHIVE);
   }

  /* start listing */
  InitList(CPIO,infile);

  /* parse each header block until CPIO signature check fails or EOF */
  done= FALSE;
  while ( ! done) {
    comp = uncomp = Convert8(b+70);

    /* get Un*x stored time */
    sscanf (b+48,"%11o",&time);
    tm = localtime (&time);
    sprintf (time_str,"%02d-%s-19%d %02d:%02d:%02d",
      tm->tm_mday,months[tm->tm_mon],tm->tm_year,tm->tm_hour,
      tm->tm_min,tm->tm_sec);

    /* get filename */
    i = Convert8(b+59);
    fread(b, (ULONG) i, 1, fp);
    PrintList(b, uncomp, comp,&tfiles,&tcomp,&tuncomp,time_str);

    fseek(fp,uncomp,SEEK_CUR);

    /* get next block and check */
    ct = fread(b, 76, 1, fp);
    i = Convert8(b+70);
    if ((strnicmp(CPIO_SIG,b,6) != 0) || ct != 1 || i == 0)
      done = TRUE;
    }

  fclose(fp);
  EndStats(tfiles,tcomp,tuncomp);
  return(TRUE);
}

