Exemple #1
0
DOH *DohNewVoid(void *obj, void (*del) (void *)) {
  VoidObj *v;
  v = (VoidObj *) DohMalloc(sizeof(VoidObj));
  v->ptr = obj;
  v->del = del;
  return DohObjMalloc(&DohVoidType, v);
}
Exemple #2
0
DOHString *DohNewStringWithSize(const DOHString_or_char *so, int len) {
  int l = 0, max;
  String *str;
  char *s;
  if (DohCheck(so)) {
    s = (char *) String_data((String *) so);
  } else {
    s = (char *) so;
  }

  str = (String *) DohMalloc(sizeof(String));
  str->hashkey = -1;
  str->sp = 0;
  str->line = 1;
  str->file = 0;
  max = INIT_MAXSIZE;
  if (s) {
    l = (int) len;
    if ((l + 1) > max)
      max = l + 1;
  }
  str->str = (char *) DohMalloc(max);
  str->maxsize = max;
  if (s) {
    strncpy(str->str, s, len);
    str->len = l;
    str->sp = l;
  } else {
    str->str[0] = 0;
    str->len = 0;
  }
  return DohObjMalloc(&DohStringType, str);
}
Exemple #3
0
DOHString *
DohNewString(const DOH *so)
{
    int l = 0, max;
    String *str;
    char *s;
    if (DohCheck(so)) s = Char(so);
    else s = (char *) so;
    str = (String *) DohMalloc(sizeof(String));
    str->hashkey = -1;
    str->sp = 0;
    str->line = 1;
    str->file = 0;
    max = INIT_MAXSIZE;
    if (s) {
      l = (int) strlen(s);
      if ((l+1) > max) max = l+1;
    }
    str->str = (char *) DohMalloc(max);
    str->maxsize = max;
    if (s) {
	strcpy(str->str,s);
	str->len = l;
	str->sp = l;
    } else {
	str->str[0] = 0;
	str->len = 0;
    }
    return DohObjMalloc(&DohStringType,str);
}
Exemple #4
0
DOH *DohNewFileFromFd(int fd) {
  DohFile *f;
  f = (DohFile *) DohMalloc(sizeof(DohFile));
  if (!f)
    return 0;
  f->filep = 0;
  f->fd = fd;
  f->closeondel = 0;
  return DohObjMalloc(&DohFileType, f);
}
Exemple #5
0
DOH *DohNewFileFromFile(FILE *file) {
  DohFile *f;
  f = (DohFile *) DohMalloc(sizeof(DohFile));
  if (!f)
    return 0;
  f->filep = file;
  f->fd = 0;
  f->closeondel = 0;
  return DohObjMalloc(&DohFileType, f);
}
Exemple #6
0
DOHString *DohNewStringEmpty(void) {
  int max = INIT_MAXSIZE;
  String *str = (String *) DohMalloc(sizeof(String));
  str->hashkey = 0;
  str->sp = 0;
  str->line = 1;
  str->file = 0;
  str->str = (char *) DohMalloc(max);
  str->maxsize = max;
  str->str[0] = 0;
  str->len = 0;
  return DohObjMalloc(&DohStringType, str);
}
DOH *DohNewList() {
  List *l;
  int i;
  l = (List *) DohMalloc(sizeof(List));
  l->nitems = 0;
  l->maxitems = MAXLISTITEMS;
  l->items = (void **) DohMalloc(l->maxitems * sizeof(void *));
  for (i = 0; i < MAXLISTITEMS; i++) {
    l->items[i] = 0;
  }
  l->file = 0;
  l->line = 0;
  return DohObjMalloc(&DohListType, l);
}
Exemple #8
0
static DOH *CopyString(DOH *so) {
  String *str;
  String *s = (String *) ObjData(so);
  str = (String *) DohMalloc(sizeof(String));
  str->hashkey = s->hashkey;
  str->sp = s->sp;
  str->line = s->line;
  str->file = s->file;
  if (str->file)
    Incref(str->file);
  str->str = (char *) DohMalloc(s->len + 1);
  memcpy(str->str, s->str, s->len);
  str->maxsize = s->len;
  str->len = s->len;
  str->str[str->len] = 0;

  return DohObjMalloc(&DohStringType, str);
}
/* -----------------------------------------------------------------------------
 * CopyList()
 *
 * Make a shallow copy of a list.
 * ----------------------------------------------------------------------------- */
static DOH *CopyList(DOH *lo) {
  List *l, *nl;
  int i;
  l = (List *) ObjData(lo);
  nl = (List *) DohMalloc(sizeof(List));
  nl->nitems = l->nitems;
  nl->maxitems = l->maxitems;
  nl->items = (void **) DohMalloc(l->maxitems * sizeof(void *));
  for (i = 0; i < l->nitems; i++) {
    nl->items[i] = l->items[i];
    Incref(nl->items[i]);
  }
  nl->file = l->file;
  if (nl->file)
    Incref(nl->file);
  nl->line = l->line;
  return DohObjMalloc(&DohListType, nl);
}
Exemple #10
0
static DOH *
CopyString(DOH *so) {
  int max;
  String *str;
  String *s = (String *) ObjData(so);
  str = (String *) DohMalloc(sizeof(String));
  str->hashkey = -1;
  str->sp = s->sp;
  str->line = s->line;
  str->file = s->file;
  if (str->file) Incref(str->file);
  max = s->maxsize;
  str->str = (char *) DohMalloc(max+1);
  memmove(str->str, s->str, max);
  str->maxsize= max;
  str->len = s->len;
  str->str[str->len] = 0;
  
  return DohObjMalloc(&DohStringType,str);
}
Exemple #11
0
DOH *DohNewFile(DOH *filename, const char *mode, DOHList *newfiles) {
  DohFile *f;
  FILE *file;
  char *filen;

  filen = Char(filename);
  file = fopen(filen, mode);
  if (!file)
    return 0;

  f = (DohFile *) DohMalloc(sizeof(DohFile));
  if (!f) {
    fclose(file);
    return 0;
  }
  if (newfiles)
    Append(newfiles, filename);
  f->filep = file;
  f->fd = 0;
  f->closeondel = 1;
  return DohObjMalloc(&DohFileType, f);
}
Exemple #12
0
DOHString *DohNewString(const DOHString_or_char *so) {
  int l = 0, max;
  String *str;
  char *s;
  int hashkey = -1;
  if (DohCheck(so)) {
    str = (String *) ObjData(so);
    s = (char *) String_data((String *) so);
    l = s ? str->len : 0;
    hashkey = str->hashkey;
  } else {
    s = (char *) so;
    l = s ? (int) strlen(s) : 0;
  }

  str = (String *) DohMalloc(sizeof(String));
  str->hashkey = hashkey;
  str->sp = 0;
  str->line = 1;
  str->file = 0;
  max = INIT_MAXSIZE;
  if (s) {
    if ((l + 1) > max)
      max = l + 1;
  }
  str->str = (char *) DohMalloc(max);
  str->maxsize = max;
  if (s) {
    strcpy(str->str, s);
    str->len = l;
    str->sp = l;
  } else {
    str->str[0] = 0;
    str->len = 0;
  }
  return DohObjMalloc(&DohStringType, str);
}