Exemple #1
0
const char *ccRegEx::GetMatch(int match)
{
	if (match < 0 || match >= nmatch)
		throw ccException("Invalid regular expression match offset");
	if (this->match[match].rm_so == -1) return NULL;
	return matches[match];
}
Exemple #2
0
const char *ccFile::Read(const char *filename)
{
    Reset();

    fd = open(filename, O_RDONLY);
    if (fd == -1)
        throw ccException("Error opening file");

    long pages = 1;
    long page_size = sysconf(_SC_PAGESIZE);
    if (page_size == -1) page_size = 4096;
    buffer = (char *)realloc(NULL, pages * page_size);

    void *ptr = (void *)buffer;
    ssize_t total = 0, bytes;
    for ( ;; ) {
        bytes = read(fd, ptr, page_size);
        if (bytes > 0) total += bytes;
        if (bytes != page_size) break;
        pages++;
        buffer = (char *)realloc((void *)buffer, pages * page_size);
        ptr = buffer + (pages * page_size);
    }
    buffer = (char *)realloc((void *)buffer, total + 1);
    ptr = buffer + total;
    (*(char *)ptr) = '\0';
    file_stat.st_size = -1;
    this->filename = filename;
    return (const char *)buffer;
}
Exemple #3
0
CC_List_Iterator_base::CC_List_Iterator_base (CC_Listbase *list)
: f_list (list)
{
  if ( !list ) {
    throw(CASTCCEXCEPT ccException());
  }

  reset();
}
Exemple #4
0
const char *ccFile::Map(const char *filename)
{
    Reset();

    fd = open(filename, O_RDONLY);
    if (fd == -1)
        throw ccException("Error opening file");
    if (fstat(fd, &file_stat) == -1) {
        close(fd);
        throw ccException("Unable to stat file");
    }
    buffer = (char *)mmap(0, file_stat.st_size,
        PROT_READ, MAP_SHARED, fd, 0);
    if (buffer == MAP_FAILED) {
        close(fd);
        throw ccException("Error mapping file");
    }
    this->filename = filename;
    return (const char *)buffer;
}
Exemple #5
0
ccRegEx::ccRegEx(const char *expr, int nmatch, int flags)
	: match(NULL), nmatch(nmatch), matches(NULL)
{
	if (!nmatch) flags |= REG_NOSUB;
	if (regcomp(&regex, expr, flags) != 0)
		throw ccException("Regular expression compilation error");
	if (nmatch) {
		match = new regmatch_t[nmatch];
		matches = new char *[nmatch];
		for (int i = 0; i < nmatch; i++) matches[i] = NULL;
	}
}
Exemple #6
0
// /////////////////////////////////////////////////////////////////
// CC_Listbase::remove - remove element pointed to by iterator
// /////////////////////////////////////////////////////////////////
CC_Link_base *
CC_Listbase::remove (CC_List_Iterator_base &iterator)
{
  // Make sure the iterator points to this this.
  if (iterator.f_list != this)
    throw (CASTCCEXCEPT ccException());

  // Make sure the iterator is pointing to an element. 
  if (iterator.f_current == NULL)
    return(NULL);

  // NOTE: If two iterators are active in the list at the same time
  // it is possible to blow away an element that another iterator
  // is pointing at (either previous or current).  We could make this
  // safer by only marking elements as deleted for now, then actually
  // delete the items when there are no more iterators pointing at it.
  //    19:41 22-Jul-93 DJB 

  // Link around the link we're removing.
  if (iterator.f_previous != NULL) {
    iterator.f_previous->f_next = iterator.f_current->f_next;
    if ( f_tail != iterator.f_current ) { 
      iterator.f_current->f_next->f_prev  = iterator.f_previous;
    }
  }
  else {   // must be at the head 
    f_head = iterator.f_current->f_next;
    if ( f_head ) {
      f_head->f_prev = NULL;
    }
  }
  
  if (iterator.f_current == f_tail) {
    f_tail = iterator.f_previous;
    if ( f_tail ) { 
      f_tail->f_next = NULL;
    }
    
  }

  // Increment the iterator. 
  CC_Link_base *entry = iterator.f_current;
  iterator.f_current = iterator.f_current->f_next;

  f_length--;

  return (entry);
}
Exemple #7
0
void
CC_Listbase::insert (CC_Link_base *element)
{
  if (!element) {
    throw(CASTCCEXCEPT ccException());
  }

  if (!f_tail) {
    f_tail = f_head = element;
  }
  else {
    f_tail->f_next = element;
    element->f_prev = f_tail;
    f_tail = element;
  }

  f_length++;
}
Exemple #8
0
int ccRegEx::Execute(const char *subject)
{
	if (!subject)
		throw ccException("Invalid regular expression subject");
	int rc = regexec(&regex, subject, nmatch, match, 0);
	for (int i = 0; i < nmatch; i++) {
		if (matches[i]) delete [] matches[i];
		matches[i] = NULL;
	}
	if (rc == 0) {
		for (int i = 0; i < nmatch; i++) {
			int len = match[i].rm_eo - match[i].rm_so;
			char *buffer = new char[len + 1];
			memset(buffer, 0, len + 1);
			memcpy(buffer, subject + match[i].rm_so, len);
			matches[i] = buffer;
		}
	}
	return rc;
}
Exemple #9
0
void
CC_Listbase::prepend (CC_Link_base *element)
{

  if ( !element ) {
    throw(CASTCCEXCEPT ccException());
  }

  if ( !f_head ) {
    f_head = element;
  }
  else {
    element->f_next = f_head;
    f_head->f_prev = element;
    f_head = element;
  }

  if (f_tail == NULL)
    f_tail = element;
  f_length++;
}