
/* table of contents */

#include "tar.h"
#include "perms.h"
#include "args.h"
#include "tapeio.h"
#include "table.h"


void VerboseContents(CatInfo *InfoBlk) {
  int uid,gid,unixmode;
  char DateBuffer[80];

  if (Block.Header.linkflag == LF_DIR)
    fputc('d',stdout);
  else
    fputc('-',stdout);

  sscanf(Block.Header.mode,"%o",&unixmode);
  pmode(unixmode);
  if (isArchie) {
  } else {
    sscanf(Block.Header.uid,"%o",&uid);
    sscanf(Block.Header.gid,"%o",&gid);
    printf(" %3d/%1d",uid,gid);
  }
  printf(" %7lu ", InfoBlk->Length);
  if (isArchie) {
    if (Block.Header.compressed == CF_COMPRESSED) {
      printf("%2d%% ", compression);
    } else {
      printf("    ");
    }
  }
  os_swi3(OS_ConvertStandardDateAndTime,(int)&InfoBlk->DateAndName,(int)&DateBuffer,80);
  printf("%s ",DateBuffer);
} /* VerboseContents */


void ListContents(void) {
  int ExtentNo;
  CatInfo InfoBuf;

  while (!UserInterrupt) {
    getdir(&InfoBuf);
    if (endtape())
      break;
    switch (Block.Header.linkflag) {
      case LF_OLDNORMAL:
        if (Block.Header.name[0] == 0)
          break;
      case LF_LASTEXTENT:
      case LF_EXTENT:
      case LF_NORMAL:
      case LF_DIR:
      case LF_GNUEXTENT:
        if (MatchesNextArg(NULL)) {
          if (Verbose)
            VerboseContents(&InfoBuf);
          printf("%s", Block.Header.name);
          if (Verbose && MultipleVolumes) {
            switch (Block.Header.linkflag) {
              case LF_EXTENT:
              case LF_LASTEXTENT:
                sscanf(Block.Header.ExtentNo,"%o",&ExtentNo);
                printf(" (extent #%d)",ExtentNo);
                break;
              case LF_GNUEXTENT:
                printf(" (gnu tar extent)");
                break;
            }
          }
          putchar('\n');
        }
        passtape(InfoBuf.Length);
        break;
      default:
        break;
    }
  }
} /* ListContents */
