#include "emil.h"


int
init_data(struct data *d)
{
  if (d == NULL)
    return(NOK);
  d->offset = d->bodystart;
  return(OK);
}
long
get_length(struct data *d)
{
  if (d == NULL || d->offset >= d->end)
    return(0);
  else
    return(d->bodyend - d->offset);
}

int
check_length(struct data *d, long l)
{
  if (d == NULL || d->offset >= d->end)
    return(NOK);
  if (d->bodystart + l > d->end)
    return(NOK);
  return(OK);
}

char *
get_string(struct data *d, unsigned long offset, int length)
{
  char *c;
  c = (char *)Yalloc(length + 1);
  bcopy(d->contents + d->bodystart + offset,
	c, length);
  return(c);
}

void
set_type(struct data *d)
{
  if (d != NULL)
    {
      if ((d->type = confextr("APPLEFILE", d->appletype, NULL)) == NULL)
	if ((d->type = confextr("APPLEFILE", "DEFAULT", NULL)) == NULL)
	  d->type = NEWSTR("APPLICATION");
    }
}
