Example #1
0
static int String_cmp(DOH *so1, DOH *so2) {
  String *s1, *s2;
  char *c1, *c2;
  int maxlen, i;
  s1 = (String *) ObjData(so1);
  s2 = (String *) ObjData(so2);
  maxlen = s1->len;
  if (s2->len < maxlen)
    maxlen = s2->len;
  c1 = s1->str;
  c2 = s2->str;
  for (i = maxlen; i; --i, c1++, c2++) {
    if (*c1 != *c2)
      break;
  }
  if (i != 0) {
    if (*c1 < *c2)
      return -1;
    else
      return 1;
  }
  if (s1->len == s2->len)
    return 0;
  if (s1->len > s2->len)
    return 1;
  return -1;
}
Example #2
0
static int String_equal(DOH *so1, DOH *so2) {
  String *s1 = (String *) ObjData(so1);
  String *s2 = (String *) ObjData(so2);
  register int len = s1->len;
  if (len != s2->len) {
    return 0;
  } else {
    register char *c1 = s1->str;
    register char *c2 = s2->str;
#if 0
    register int mlen = len >> 2;
    register int i = mlen;
    for (; i; --i) {
      if (*(c1++) != *(c2++))
	return 0;
      if (*(c1++) != *(c2++))
	return 0;
      if (*(c1++) != *(c2++))
	return 0;
      if (*(c1++) != *(c2++))
	return 0;
    }
    for (i = len - (mlen << 2); i; --i) {
      if (*(c1++) != *(c2++))
	return 0;
    }
    return 1;
#else
    return memcmp(c1, c2, len) == 0;
#endif
  }
}
Example #3
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;
}
Example #4
0
static int
String_putc(DOH *so, int ch)
{
  register int len, maxsize, sp;
  String *s = (String *) ObjData(so);
  s->hashkey = -1;
  len = s->len;
  sp = s->sp;
  if (sp >= len) {
    register char *tc;
    maxsize = s->maxsize;
    if (len > (maxsize-2)) {
      s->str = (char *) DohRealloc(s->str,2*maxsize);
      assert(s->str);
      s->maxsize = 2*maxsize;
    }
    tc = s->str + len;
    *(tc++) = ch;
    if (sp >= len) {
      s->sp = len+1;
      *tc = 0;
      if (ch == '\n') s->line++;
    }
    s->len = len+1;
  } else {
    s->str[s->sp++] = (char) ch;
    if (ch == '\n') s->line++;
  }
  return ch;
}
Example #5
0
static DOH *
String_str(DOH *so)
{
  String *s = (String *) ObjData(so);
  s->str[s->len] = 0;
  return NewString(s->str);
}
Example #6
0
BOOL CRTDBTopic::CreateNewRequestItem(const char* pszItem)
  {
  Strng Tag, Cnv;
  TaggedObject::SplitTagCnv((char*)pszItem, Tag, Cnv);

  CXM_Route  ObjRoute; 
  CXM_ObjectTag ObjTag(Tag(), TABOpt_AllInfo);
  CXM_ObjectData ObjData(0);
 
  DWORD RetCode = pDdeExec->XReadTaggedItem(ObjTag, ObjData, ObjRoute);
  
  //LogNote(Tag(), 0, "DDE: '%s' %s", pszItem, RetCode ? "Found" : "Not Found");
  if (RetCode==0)
    LogError(Tag(), 0, "DDE: Tag request for '%s' not found", pszItem);
  pDdeExec->StatsCnt[RetCode==0 ? 3 : 1]++;

  if (RetCode) //This is a configured point so go and add the item
    {
    m_pServer->Lock();
    CPkDataItem * pPItem = ObjData.FirstItem();
    CRTDBItem* pItem = new CRTDBItem();
    pItem->iCnvIndex = pPItem->CnvIndex();
    pItem->Create(pszItem);
    AddItem(pItem);
    m_pServer->Release();
    pItem->SetDataOnly(pPItem->Value()->GetString("%i", "%g", pItem->iCnvIndex, Cnv()));
    pDdeExec->XBuildMyDataLists();
    return TRUE;
    }
  return FALSE;
  }
Example #7
0
File: list.c Project: s1d/sniffjoke
static DOH *
List_next(DOH *lo) {
   List *l = (List *) ObjData(lo);
   l->iter++;
   if (l->iter >= l->nitems) return 0;
   return l->items[l->iter];
}
Example #8
0
static int String_putc(DOH *so, int ch) {
  String *s = (String *) ObjData(so);
  register int len = s->len;
  register int sp = s->sp;
  s->hashkey = -1;
  if (sp >= len) {
    register int maxsize = s->maxsize;
    register char *tc = s->str;
    if (len > (maxsize - 2)) {
      maxsize *= 2;
      tc = (char *) DohRealloc(tc, maxsize);
      assert(tc);
      s->maxsize = (int) maxsize;
      s->str = tc;
    }
    tc += sp;
    *tc = (char) ch;
    *(++tc) = 0;
    s->len = s->sp = sp + 1;
  } else {
    s->str[s->sp++] = (char) ch;
  }
  if (ch == '\n')
    s->line++;
  return ch;
}
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;
}
Example #10
0
static int
String_delslice(DOH *so, int sindex, int eindex) {
  String *s = (String *) ObjData(so);
  int     size;
  s->hashkey = -1;
  if (eindex == DOH_END) eindex = s->len;
  if (sindex == DOH_BEGIN) sindex = 0;
  if (s->len == 0) return 0;
  
  size = eindex - sindex;
  if (s->sp > eindex) {
    /* Adjust the file pointer and line count */
    char *c = s->str + sindex;
    int i;
    for (i = 0; i < size; i++) {
      if (*c == '\n') s->line--;
    }
    s->sp -= size;
    assert(s->sp >= 0);
  }
  memmove(s->str+sindex,s->str+eindex, ((s->len-size) - sindex));
  s->len -= size;
  s->str[s->len] = 0;
  return 0;
}
Example #11
0
static int String_delslice(DOH *so, int sindex, int eindex) {
  String *s = (String *) ObjData(so);
  int size;
  if (s->len == 0)
    return 0;
  s->hashkey = -1;
  if (eindex == DOH_END)
    eindex = s->len;
  if (sindex == DOH_BEGIN)
    sindex = 0;

  size = eindex - sindex;
  if (s->sp > sindex) {
    /* Adjust the file pointer and line count */
    int i, end;
    if (s->sp > eindex) {
      end = eindex;
      s->sp -= size;
    } else {
      end = s->sp;
      s->sp = sindex;
    }
    for (i = sindex; i < end; i++) {
      if (s->str[i] == '\n')
	s->line--;
    }
    assert(s->sp >= 0);
  }
  memmove(s->str + sindex, s->str + eindex, s->len - eindex);
  s->len -= size;
  s->str[s->len] = 0;
  return 0;
}
Example #12
0
static void
DelString(DOH *so) {
  String *s = (String *) ObjData(so);
  s->hashkey = -1;
  DohFree(s->str);
  s->str = 0;
  DohFree(s);
}
Example #13
0
static void String_clear(DOH *so) {
  String *s = (String *) ObjData(so);
  s->hashkey = -1;
  s->len = 0;
  *(s->str) = 0;
  s->sp = 0;
  s->line = 1;
}
static void List_clear(DOH *lo) {
  List *l = (List *) ObjData(lo);
  int i;
  for (i = 0; i < l->nitems; i++) {
    Delete(l->items[i]);
  }
  l->nitems = 0;
}
Example #15
0
File: list.c Project: kanbang/Colt
static DOH *
List_get(DOH *lo, int n) {
    List *l = (List *) ObjData(lo);
    if (n == DOH_END) n = l->nitems-1;
    if (n == DOH_BEGIN) n = 0;
    assert(!((n < 0) || (n >= l->nitems)));
    return l->items[n];
}
static void DelList(DOH *lo) {
  List *l = (List *) ObjData(lo);
  int i;
  for (i = 0; i < l->nitems; i++)
    Delete(l->items[i]);
  DohFree(l->items);
  DohFree(l);
}
/* Sort a list */
void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *)) {
  List *l = (List *) ObjData(lo);
  if (cmp) {
    List_sort_compare_func = cmp;
  } else {
    List_sort_compare_func = DohCmp;
  }
  qsort(l->items, l->nitems, sizeof(DOH *), List_qsort_compare);
}
Example #18
0
static int 
String_ungetc(DOH *so, int ch)
{
  String *s = (String *) ObjData(so);
  if (ch == EOF) return ch;
  if (s->sp <= 0) return EOF;
  s->sp--;
  if (ch == '\n') s->line--;
  return ch;
}
Example #19
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;
}
static DohIterator List_next(DohIterator iter) {
  List *l = (List *) ObjData(iter.object);
  iter._index = iter._index + 1;
  if (iter._index >= l->nitems) {
    iter.item = 0;
    iter.key = 0;
  } else {
    iter.item = l->items[iter._index];
  }
  return iter;
}
Example #21
0
File: file.c Project: 0xb1dd1e/swig
static int File_seek(DOH *fo, long offset, int whence) {
  DohFile *f = (DohFile *) ObjData(fo);
  if (f->filep) {
    return fseek(f->filep, offset, whence);
  } else if (f->fd) {
#ifdef DOH_INTFILE
    return lseek(f->fd, offset, whence);
#endif
  }
  return -1;
}
Example #22
0
File: file.c Project: 0xb1dd1e/swig
static long File_tell(DOH *fo) {
  DohFile *f = (DohFile *) ObjData(fo);
  if (f->filep) {
    return ftell(f->filep);
  } else if (f->fd) {
#ifdef DOH_INTFILE
    return lseek(f->fd, 0, SEEK_CUR);
#endif
  }
  return -1;
}
Example #23
0
File: file.c Project: 0xb1dd1e/swig
static int File_ungetc(DOH *fo, int ch) {
  DohFile *f = (DohFile *) ObjData(fo);
  if (f->filep) {
    return ungetc(ch, f->filep);
  } else if (f->fd) {
#ifdef DOH_INTFILE
    /* Not implemented yet */
#endif
  }
  return -1;
}
Example #24
0
static int String_getc(DOH *so) {
  int c;
  String *s = (String *) ObjData(so);
  if (s->sp >= s->len)
    c = EOF;
  else
    c = (int)(unsigned char) s->str[s->sp++];
  if (c == '\n')
    s->line++;
  return c;
}
static int List_dump(DOH *lo, DOH *out) {
  int nsent = 0;
  int i, ret;
  List *l = (List *) ObjData(lo);
  for (i = 0; i < l->nitems; i++) {
    ret = Dump(l->items[i], out);
    if (ret < 0)
      return -1;
    nsent += ret;
  }
  return nsent;
}
Example #26
0
File: file.c Project: 0xb1dd1e/swig
static int File_read(DOH *fo, void *buffer, int len) {
  DohFile *f = (DohFile *) ObjData(fo);

  if (f->filep) {
    return fread(buffer, 1, len, f->filep);
  } else if (f->fd) {
#ifdef DOH_INTFILE
    return read(f->fd, buffer, len);
#endif
  }
  return -1;
}
Example #27
0
static int String_seek(DOH *so, long offset, int whence) {
  int pos, nsp, inc;
  String *s = (String *) ObjData(so);
  if (whence == SEEK_SET)
    pos = 0;
  else if (whence == SEEK_CUR)
    pos = s->sp;
  else if (whence == SEEK_END) {
    pos = s->len;
    offset = -offset;
  } else
    pos = s->sp;

  nsp = pos + offset;
  if (nsp < 0)
    nsp = 0;
  if (s->len > 0 && nsp > s->len)
    nsp = s->len;

  inc = (nsp > s->sp) ? 1 : -1;

  {
#if 0
    register int sp = s->sp;
    register char *tc = s->str;
    register int len = s->len;
    while (sp != nsp) {
      int prev = sp + inc;
      if (prev >= 0 && prev <= len && tc[prev] == '\n')
	s->line += inc;
      sp += inc;
    }
#else
    register int sp = s->sp;
    register char *tc = s->str;
    if (inc > 0) {
      while (sp != nsp) {
	if (tc[++sp] == '\n')
	  ++s->line;
      }
    } else {
      while (sp != nsp) {
	if (tc[--sp] == '\n')
	  --s->line;
      }
    }
#endif
    s->sp = sp;
  }
  assert(s->sp >= 0);
  return 0;
}
Example #28
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;
}
Example #29
0
static int String_dump(DOH *so, DOH *out) {
  int nsent;
  int ret;
  String *s = (String *) ObjData(so);
  nsent = 0;
  while (nsent < s->len) {
    ret = Write(out, s->str + nsent, (s->len - nsent));
    if (ret < 0)
      return ret;
    nsent += ret;
  }
  return nsent;
}
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;
}