/**********************************************************************
 * luc_fill_mtg.c -- fill in contents of struct lmeeting
 *
 * $Author: brlewis $
 * $Source: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_fill_mtg.c,v $
 * $Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_fill_mtg.c,v 1.2 91/08/01 14:30:07 brlewis Exp Locker: brlewis $
 *
 * Copyright 1991 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 **********************************************************************/
#include <mit-copyright.h>

#ifndef lint
static char rcsid_luc_fill_mtg_c[] = "$Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_fill_mtg.c,v 1.2 91/08/01 14:30:07 brlewis Exp Locker: brlewis $";
#endif /* lint */

#include <stdio.h>
#include <strings.h>
#include <sys/errno.h>
#include "lucy/lucy.h"
#include "lucy/memory.h"

/**********************************************************************
 * luc_fill_mtg(LMEETING *mtg)
 *	caller should allocate and zero mtg
 *	mtg->nb should already be filled in
 *	XXX how to deallocate?
 *
 * - creates directory for transaction caching
 * - fills in mtg->dir
 * - returns error code
 **********************************************************************/

long
luc_fill_mtg(mtg)
     LMEETING *mtg;
{
  static char *usd = "/usr/spool/discuss/";
  long code;
  register char *s;

  /* Abbreviate "/usr/spool/discuss/" to "" */
  s = mtg->nb.pathname;
  if (strncmp(s, usd, strlen(usd)) == 0)
    s += strlen(usd);

  /* get directory name */
  mtg->dir = malloc(strlen(luv_topdir)
		    + strlen(mtg->nb.hostname)
		    + strlen(s) + 3);
  if (!mtg->dir) {
    luv_context[0] = '\0';	/* error context = "" */
    return((long) errno);
  }
  sprintf(mtg->dir, "%s/%s:%s", luv_topdir, mtg->nb.hostname,
	  s);

  /* Change slashes to @ signs in discuss pathname (ala gnuemacs) */
  for (s=index(mtg->dir, ':'); *s; s++)
    if (*s == '/') *s = '@';

  /* Make the directory */
  if (mkdir(mtg->dir, 0700) && errno != EEXIST) {
    sprintf(luv_context, "making directory \"%s\"", mtg->dir);
    return((long) errno);
  }

  /* Get meeting info */
  dsc_get_mtg_info(&(mtg->nb), &(mtg->info), &code);
  if (code) sprintf(luv_context, "getting info on %s:%s",
		    mtg->nb.hostname, mtg->nb.pathname);
  return(code);
}
