static int List_insert(DOH *lo, int pos, DOH *item) { List *l = (List *) ObjData(lo); int i; if (!item) return -1; if (!DohCheck(item)) { item = NewString(item); Decref(item); } if (pos == DOH_END) pos = l->nitems; if (pos < 0) pos = 0; if (pos > l->nitems) pos = l->nitems; if (l->nitems == l->maxitems) more(l); for (i = l->nitems; i > pos; i--) { l->items[i] = l->items[i - 1]; } l->items[pos] = item; Incref(item); l->nitems++; return 0; }
/* ----------------------------------------------------------------------------- * 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); }
static void String_setfile(DOH *so, DOH *file) { DOH *fo; String *str = (String *) ObjData(so); if (!DohCheck(file)) { fo = NewString(file); Decref(fo); } else fo = file; Incref(fo); Delete(str->file); str->file = fo; }
static void List_setfile(DOH *lo, DOH *file) { DOH *fo; List *l = (List *) ObjData(lo); if (!DohCheck(file)) { fo = NewString(file); Decref(fo); } else fo = file; Incref(fo); Delete(l->file); l->file = fo; }
static int List_set(DOH *lo, int n, DOH *val) { List *l = (List *) ObjData(lo); if (!val) return -1; assert(!((n < 0) || (n >= l->nitems))); if (!DohCheck(val)) { val = NewString(val); Decref(val); } Delete(l->items[n]); l->items[n] = val; Incref(val); Delete(val); return 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); }
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); }
void DohIncref(DOH *obj) { Incref(obj); }