/*
 */

extern int errno;
const char *prog;

#include "dsrv.h"

int main (int argc, char *argv[])
{
  assert (argc == 2);
  ErrorCode code;
  prog = argv[0];

  umask (077);

  char *pathname = argv[1];
  if (strchr (pathname, '/') == 0)
    {
      struct passwd *pwd = getpwnam ("discuss");
      pathname = new char[strlen (argv[1]) + strlen (pwd->pw_dir) + 3];
      sprintf (pathname, "%s/%s", pwd->pw_dir, argv[1]);
    }

  DiscussCachedMeeting mtg (pathname);

  code = mtg.open ();
  if (code)
    {
      com_err (prog, code, "can't open meeting %s", pathname);
      return 1;
    }

#ifdef DEBUG
  int i;
  for (i = 0; i < mtg.n_chain_blks; i++)
    {
      DiscussFileChainBlk *blk = mtg.chain_blks + i;
      fprintf (stderr, "i=%d ", i);
      blk->print (stderr);
    }
#endif

  code = mtg.expunge ();
  if (code)
    {
      com_err (prog, code, "can't expunge meeting %s", pathname);
      return 1;
    }

  code = mtg.close ();
  if (code)
    {
      com_err (prog, code, "can't close meeting %s", pathname);
      return 1;
    }

  return 0;
}
