/*
 * mtd.c:
 *
 * Copyright (c) 2000 James McKenzie <james@fishsoup.dhs.org>,
 * All rights reserved.
 *
 */

static char rcsid[] = "$Id: mtd.c,v 1.11 2001/10/12 13:51:11 root Exp $";

/*
 * $Log: mtd.c,v $
 * Revision 1.11  2001/10/12 13:51:11  root
 * #
 *
 * Revision 1.10  2001/10/04 18:21:16  root
 * #
 *
 * Revision 1.9  2001/01/30 06:16:18  root
 * #
 *
 * Revision 1.8  2000/12/01 04:42:10  root
 * #
 *
 * Revision 1.7  2000/11/23 23:45:19  root
 * #
 *
 * Revision 1.6  2000/10/07 18:30:03  root
 * #
 *
 * Revision 1.5  2000/09/24 01:58:21  root
 * #
 *
 * Revision 1.4  2000/09/24 01:48:12  root
 * #
 *
 * Revision 1.3  2000/09/24 01:44:47  root
 * #
 *
 * Revision 1.2  2000/09/24 01:12:43  root
 * #
 *
 * Revision 1.1  2000/09/19 03:53:27  root
 * #
 *
 */

#include "project.h"

extern FILE *yyin;
char *mtd_filename;
extern int yyparse(void);
extern int line;

INTERNAL void mtd_add_work(Eweid e)
{
  work_add(e);
}

INTERNAL void mtd_remove_work(Eweid e)
{
  work_remove(e);
}

INTERNAL void mtd_remove_text(Eweid e)
{
  text_remove(e);
}

INTERNAL void mtd_add_text(Eweid e, char *text)
{
  text_add(e, text);
}

INTERNAL void mtd_add_uri(Eweid e, char *uri)
{
  uri_add(e, uri);
}

INTERNAL void mtd_add_group(Eweid e, char *file)
{
  text_add(e, file);
}

static FILE *p_file = NULL;
static int (*p_readfn) (char *, int) = NULL;

static int mtd_readfn(char *buf, int len)
{
  return fread(buf, 1, len, p_file);
}

INTERNAL int mtd_read(char *buf, int len)
{
  return p_readfn(buf, len);
}


INTERNAL int do_parse_mtd(int (*readfn) (char *, int))
{
  if (!readfn)
    return 1;

  p_readfn = readfn;

  mtd_filename = NULL;

  line = 0;

  yyparse();

  p_readfn = NULL;

  return 0;
}


INTERNAL int parse_mtd(const char *file)
{
  mtd_filename = (char *) file;

  p_file = fopen(file, "r");

  if (!p_file)
    return 1;

  p_readfn = mtd_readfn;

  line = 0;

  yyparse();

  p_readfn = NULL;

  fclose(p_file);
  p_file = NULL;

  return 0;
}
