Ejemplo n.º 1
0
Archivo: base.c Proyecto: 0xb1dd1e/swig
DOH *DohCopy(const DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;

  if (!obj)
    return 0;
  if (!DohCheck(b)) {
#if SWIG_DEBUG_DELETE
    fputs("DOH: Fatal error. Attempt to copy a non-doh object.\n", stderr);
    abort();
#else
    assert(0);
#endif
    return 0;
  }
  objinfo = b->type;
  if (objinfo->doh_copy) {
    DohBase *bc = (DohBase *) (objinfo->doh_copy) (b);
    if ((bc) && b->meta) {
      bc->meta = Copy(b->meta);
    }
    return (DOH *) bc;
  }
  return 0;
}
Ejemplo n.º 2
0
DOHString *DohNewStringWithSize(const DOH *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);
}
Ejemplo n.º 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);
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
int
DohSetmeta(DOH *ho, const DOH *name, const DOH *value) {
  DohBase *h = (DohBase *) ho;
  if (!DohCheck(ho)) return 0;
  if (!h->meta) h->meta = NewHash();
  return DohSetattr(h->meta, name, value);
}
Ejemplo n.º 6
0
int
DohDelmeta(DOH *ho, const DOH *name) {
  DohBase *h = (DohBase *) ho;
  if (!DohCheck(ho)) return 0;
  if (!h->meta) return 0;
  return DohDelattr(h->meta, name);
}
Ejemplo n.º 7
0
Archivo: base.c Proyecto: 0xb1dd1e/swig
void DohDelete(DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;

  if (!obj)
    return;
  if (!DohCheck(b)) {
#if SWIG_DEBUG_DELETE
    fputs("DOH: Fatal error. Attempt to delete a non-doh object.\n", stderr);
    abort();
#else
    assert(0);
#endif
    return;
  }
  if (b->flag_intern)
    return;
  assert(b->refcount > 0);
  b->refcount--;
  if (b->refcount <= 0) {
    objinfo = b->type;
    if (objinfo->doh_del) {
      (objinfo->doh_del) (b);
    } else {
      if (b->data)
	DohFree(b->data);
    }
    DohObjFree(b);
  }
}
Ejemplo n.º 8
0
int
DohIsString(const DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (!DohCheck(b)) return 0;
  objinfo = b->type;
  if (objinfo->doh_string) return 1;
  else return 0;
}
Ejemplo n.º 9
0
int
DohIsSequence(const DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (!DohCheck(b)) return 0;
  objinfo = b->type;
  if (objinfo->doh_list) return 1;
  else return 0;
}
Ejemplo n.º 10
0
int
DohCmp(const DOH *obj1, const DOH *obj2) {
  DohBase *b1, *b2;
  DohObjInfo *b1info, *b2info;
  b1 = (DohBase *) obj1;
  b2 = (DohBase *) obj2;
  if ((!DohCheck(b1)) || (!DohCheck(b2))) {
    if ((b1 == 0) && (b2 == 0)) return 0;
    if (b1 && !b2) return 1;
    if (!b1 &&  b2) return -1;
    return strcmp((char *) DohData(b1),(char *) DohData(b2));
  }
  b1info = b1->type;
  b2info = b2->type;
  if ((b1info == b2info) && (b1info->doh_cmp)) 
    return (b1info->doh_cmp)(b1,b2);
  return 1;
}
int DohSeek(DOH *obj, long offset, int whence) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (DohCheck(obj)) {
    objinfo = b->type;
    if ((objinfo->doh_file) && (objinfo->doh_file->doh_seek)) {
      return (objinfo->doh_file->doh_seek) (b, offset, whence);
    }
    return -1;
  }
  return fseek((FILE *) b, offset, whence);
}
long DohTell(DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (DohCheck(obj)) {
    objinfo = b->type;
    if ((objinfo->doh_file) && (objinfo->doh_file->doh_tell)) {
      return (objinfo->doh_file->doh_tell) (b);
    }
    return -1;
  }
  return ftell((FILE *) b);
}
int DohUngetc(int ch, DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (DohCheck(obj)) {
    objinfo = b->type;
    if (objinfo->doh_file->doh_ungetc) {
      return (objinfo->doh_file->doh_ungetc) (b, ch);
    }
    return EOF;
  }
  return ungetc(ch, (FILE *) b);
}
int DohClose(DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (DohCheck(obj)) {
    objinfo = b->type;
    if (objinfo->doh_file->doh_close) {
      return (objinfo->doh_file->doh_close) (b);
    }
    return 0;
  }
  return fclose((FILE *) obj);
}
Ejemplo n.º 15
0
int
DohHashval(const DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (DohCheck(b)) {
    objinfo = b->type;
    if (objinfo->doh_hashval) {
      return (objinfo->doh_hashval)(b);
    }
  }
  return 0;
}
void *DohData(const DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (DohCheck(obj)) {
    objinfo = b->type;
    if (objinfo->doh_data) {
      return (objinfo->doh_data) (b);
    }
    return 0;
  }
  return (void *) obj;
}
Ejemplo n.º 17
0
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;
}
int DohWrite(DOH *obj, void *buffer, int length) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (DohCheck(obj)) {
    objinfo = b->type;
    if ((objinfo->doh_file) && (objinfo->doh_file->doh_write)) {
      return (objinfo->doh_file->doh_write) (b, buffer, length);
    }
    return -1;
  }
  /* Hmmm.  Not a file.  Maybe it's a real FILE */
  return fwrite(buffer, 1, length, (FILE *) b);
}
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;
}
Ejemplo n.º 20
0
static int String_insert(DOH *so, int pos, DOH *str) {
  String *s;
  char *nstr;
  int len;
  char *data;

  if (pos == DOH_END) {
    DohString_append(so, str);
    return 0;
  }


  s = (String *) ObjData(so);
  s->hashkey = -1;
  if (DohCheck(str)) {
    String *ss = (String *) ObjData(str);
    data = (char *) String_data(str);
    len = ss->len;
  } else {
    data = (char *) (str);
    len = (int) strlen(data);
  }
  nstr = s->str;

  if (pos < 0)
    pos = 0;
  else if (pos > s->len)
    pos = s->len;

  /* See if there is room to insert the new data */
  while (s->maxsize <= s->len + len) {
    int newsize = 2 * s->maxsize;
    s->str = (char *) DohRealloc(s->str, newsize);
    assert(s->str);
    s->maxsize = newsize;
  }
  memmove(s->str + pos + len, s->str + pos, (s->len - pos));
  memcpy(s->str + pos, data, len);
  if (s->sp >= pos) {
    int i;

    for (i = 0; i < len; i++) {
      if (data[i] == '\n')
	s->line++;
    }
    s->sp += len;
  }
  s->len += len;
  s->str[s->len] = 0;
  return 0;
}
Ejemplo n.º 21
0
int
DohEqual(const DOH *obj1, const DOH *obj2) {
  DohBase *b1 = (DohBase *) obj1;
  DohBase *b2 = (DohBase *) obj2;
  if (!b1) {
    return !b2;
  } else if (!b2) {
    return 0;
  } else {
    DohObjInfo *b1info = 0;
    DohObjInfo *b2info = 0;
    if (DohCheck(b1)) {
      b1info = b1->type;
      if (DohCheck(b2)) {
	b2info = b2->type;
      } else {
	int len = (b1info->doh_len)(b1);
	char *cobj = (char *) obj2;
	return len == (int)strlen(cobj) ? (memcmp(RawData(b1), cobj, len) == 0) : 0;
      }
    } else if (DohCheck(b2)) {
      int len = (b2->type->doh_len)(b2);
      char *cobj = (char *) obj1;
      return len == (int)strlen(cobj) ? (memcmp(RawData(b2), cobj, len) == 0) : 0;
    } else {
      return strcmp((char*) obj1, (char*) obj2) == 0;
    }
    
    if (!b1info) {
      return obj1 == obj2;
    } else if ((b1info == b2info)) {
      return b1info->doh_equal ? (b1info->doh_equal)(b1,b2) : 
	(b1info->doh_cmp ? (b1info->doh_cmp)(b1,b2) == 0 : (b1 == b2));
    } else {
      return 0;
    }
  }
}
Ejemplo n.º 22
0
int
DohCmp(const DOH *obj1, const DOH *obj2) {
  DohBase *b1, *b2;
  DohObjInfo *b1info, *b2info;
  int c1, c2;
  b1 = (DohBase *) obj1;
  b2 = (DohBase *) obj2;
  c1 = DohCheck(b1);
  c2 = DohCheck(b2);
  /* most of the times, obj2 is a plain c string */  
  if (!c1 || !c2) {
    if ((b1 == 0) && (b2 == 0)) return 0;
    if (b1 && !b2) return 1;
    if (!b1 &&  b2) return -1;
    return strcmp((char *) (c1 ? RawData(b1) : (void*) obj1),
		  (char *) (c2 ? RawData(b2) : (void*) obj2));
  }
  b1info = b1->type;
  b2info = b2->type;
  if ((b1info == b2info) && (b1info->doh_cmp)) 
    return (b1info->doh_cmp)(b1,b2);
  return 1;
}
DOH *DohStr(const DOH *obj) {
  char buffer[512];
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (DohCheck(b)) {
    objinfo = b->type;
    if (objinfo->doh_str) {
      return (objinfo->doh_str) (b);
    }
    sprintf(buffer, "<Object '%s' at %p>", objinfo->objname, (void *) b);
    return NewString(buffer);
  } else {
    return NewString(obj);
  }
}
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;
}
/* -----------------------------------------------------------------------------
 * DohLen() - Defaults to strlen() if not a DOH object
 * ----------------------------------------------------------------------------- */
int DohLen(const DOH *obj) {
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (!b)
    return 0;
  if (DohCheck(b)) {
    objinfo = b->type;
    if (objinfo->doh_len) {
      return (objinfo->doh_len) (b);
    }
    return 0;
  } else {
    return strlen((char *) obj);
  }
}
Ejemplo n.º 26
0
DohIterator
DohFirst(DOH *obj) {
  DohIterator iter;
  DohBase     *b;
  DohObjInfo  *binfo;

  b = (DohBase *) obj;
  if (DohCheck(b)) {
    binfo = b->type;
    if (binfo->doh_first) {
      return (binfo->doh_first)(b);
    }
  }
  iter.object  = 0;
  iter.item    = 0;
  iter.key     = 0;
  return iter;
}
int DohGetc(DOH *obj) {
  static DOH *lastdoh = 0;
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;
  if (obj == lastdoh) {
    objinfo = b->type;
    return (objinfo->doh_file->doh_getc) (b);
  }
  if (DohCheck(obj)) {
    objinfo = b->type;
    if (objinfo->doh_file->doh_getc) {
      lastdoh = obj;
      return (objinfo->doh_file->doh_getc) (b);
    }
    return EOF;
  }
  return fgetc((FILE *) b);
}
int DohPutc(int ch, DOH *obj) {
  static DOH *lastdoh = 0;
  DohBase *b = (DohBase *) obj;
  DohObjInfo *objinfo;

  if (obj == lastdoh) {
    objinfo = b->type;
    return (objinfo->doh_file->doh_putc) (b, ch);
  }
  if (DohCheck(obj)) {
    objinfo = b->type;
    if (objinfo->doh_file->doh_putc) {
      lastdoh = obj;
      return (objinfo->doh_file->doh_putc) (b, ch);
    }
    return EOF;
  }
  return fputc(ch, (FILE *) b);
}
Ejemplo n.º 29
0
static void DohString_append(DOH *so, const DOHString_or_char *str) {
  int oldlen, newlen, newmaxsize, l, sp;
  char *tc;
  String *s = (String *) ObjData(so);
  char *newstr = 0;

  if (DohCheck(str)) {
    String *ss = (String *) ObjData(str);
    newstr = (char *) String_data((DOH *) str);
    l = ss->len;
  } else {
    newstr = (char *) (str);
    l = (int) strlen(newstr);
  }
  if (!newstr)
    return;
  s->hashkey = -1;

  oldlen = s->len;
  newlen = oldlen + l + 1;
  if (newlen >= s->maxsize - 1) {
    newmaxsize = 2 * s->maxsize;
    if (newlen >= newmaxsize - 1)
      newmaxsize = newlen + 1;
    s->str = (char *) DohRealloc(s->str, newmaxsize);
    assert(s->str);
    s->maxsize = newmaxsize;
  }
  tc = s->str;
  memcpy(tc + oldlen, newstr, l + 1);
  sp = s->sp;
  if (sp >= oldlen) {
    int i = oldlen + l - sp;
    tc += sp;
    for (; i; --i) {
      if (*(tc++) == '\n')
	s->line++;
    }
    s->sp = oldlen + l;
  }
  s->len += l;
}
Ejemplo n.º 30
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);
}