Exemplo n.º 1
0
/**
 * Converts a regular expression to a DFA. Public function.
 *
 * @param rxs         The regular expression.
 * @param automaton   Pointer to the DFA object to write to.
 */
void
regex2dfa(char *rxs, DFA *automaton)
{
  int Q, i, j;
  int S, Sh, Classes, C; 
  State SP;

  searchstr = rxs;

  init();

  Q = Parse();
  
  if (ERRORS > 0) 
   Rprintf( "%d error(s)\n", ERRORS);
  if (Q == -1) 
    rcqp_receive_error(1);
  FormState(Q);
  MergeStates(); 

  automaton->Max_States = Ss;
  automaton->Max_Input = Environment[eep].MaxPatIndex + 1;
  automaton->E_State = automaton->Max_States;

  if (show_dfa) /* TODO: Use a module-internal debug variable (for encapsulation). */
    WriteStates();

  /* allocate memory for the transition table and initialize it. */
  automaton->TransTable = (int **)cl_malloc(sizeof(int *) * automaton->Max_States);
  for (i = 0; i < Ss; i++)  {
    automaton->TransTable[i] = (int *)cl_malloc(sizeof(int) * automaton->Max_Input);
    for (j = 0; j < automaton->Max_Input; j++)
      automaton->TransTable[i][j] = automaton->E_State;
  }

  /* allocate memory for the table of final states. */
  automaton->Final = (Boolean *)cl_malloc(sizeof(Boolean) * (Ss + 1));

  /* initialize the table of final states. */
  for (i = 0; i <= automaton->Max_States; i++)
    automaton->Final[i] = False;

  for (S = Classes = 0; S < Ss; S++) {
    SP = &STab[S];
    if (SP->Class != Classes)
      continue;
    Classes++;
    if (SP->Empty)
      automaton->Final[SP->Class] = True;
    for (Sh = 0; Sh < SP->Shifts; Sh++) {
      C = SP->ShList[Sh].RHS;
      automaton->TransTable[SP->Class][atoi(SP->ShList[Sh].LHS->Name)] =
        STab[C].Class;
    }
  }
}
Exemplo n.º 2
0
Variable
NewVariable(char *varname)
{
  Variable v;
  int i;

  if (varname == NULL)
    return NULL;

  v = (Variable)cl_malloc(sizeof(VariableBuffer));
  v->valid = 0;
  v->my_name = cl_strdup(varname);
  v->my_corpus = NULL;
  v->my_attribute = NULL;
  v->nr_items = 0;
  v->items = NULL;

  for (i = 0; i < nr_variables; i++) {
    if (VariableSpace[i] == NULL) {
      VariableSpace[i] = v;
      break;
    }
  }

  if (i >= nr_variables) {

    /* not inserted, malloc */
    
    nr_variables += VARIABLE_REALLOC;

    if (VariableSpace == NULL)
      VariableSpace = (Variable *)cl_malloc(nr_variables * sizeof(Variable));
    else
      VariableSpace = (Variable *)cl_realloc(VariableSpace, 
                                          nr_variables * sizeof(Variable));
    if (VariableSpace == NULL) {
      fprintf(stderr, "Fatal Error: Variable space out of memory.\n");
      assert(0 && "Sorry, big problem here!");
    }
    
    VariableSpace[i++] = v;

    for ( ; i < nr_variables; i++)
      VariableSpace[i] = NULL;
  }

  return v;
}
Exemplo n.º 3
0
static int
uncompress2compress(struct ha_msg* msg, int index)
{
	char*	buf;
	size_t	buflen = MAXMSG;
	int	rc = HA_FAIL;

	buf = cl_malloc(buflen);
	if (!buf) {
		cl_log(LOG_ERR, "%s: failed to allocate buffer",
		       __FUNCTION__);
		goto err;
	}

	if (msg->types[index] != FT_UNCOMPRESS){
		cl_log(LOG_ERR, "%s: the %dth field is not FT_UNCOMPRESS type",
		       __FUNCTION__, index);
		goto err;
	}
	

	if (cl_compress_field(msg, index, buf, &buflen) != HA_OK){
		cl_log(LOG_ERR, "%s: compressing %dth field failed", __FUNCTION__, index);
		goto err;
	}
	
	rc = cl_msg_replace(msg, index, buf, buflen, FT_COMPRESS);

err:
	if (buf) {
		cl_free(buf);
	}

	return rc;
}
Exemplo n.º 4
0
int cloudvpn_schedule_work (struct work*w)
/* inserts work into the queue */
{
	struct work_queue** q;
	struct work_queue* nw;

	nw = cl_malloc (sizeof (struct work_queue) );
	if (!nw) return 1;
	nw->w = w;

	cl_mutex_lock (queue_mutex);

	q = &queue;

	while ( (*q) && ( (*q)->w->priority <= w->priority) )
		q = & ( (*q)->next);

	nw->next = *q;
	*q = nw;

	cl_mutex_unlock (queue_mutex);

	/*
	 * Now wake up some thread that processes the event. Note that waking
	 * multiple threads (by broadcast) is not really neccessary, as one
	 * scheduled work can be done only by one thread, and this function is
	 * called for every scheduled work, waking as many threads as needed.
	 */

	cl_cond_signal (queue_just_filled);

	return 0;
}
Exemplo n.º 5
0
/**
 * Reads a Huffman compressed sequence from file.
 *
 * @param filename  Path to file where compressed sequence is saved.
 * @param hc        Pointer to location where the sequence's descriptor block will be loaded to.
 * @return          Boolean: true for all OK, false for error.
 */
int
ReadHCD(char *filename, HCD *hc)
{
  FILE *fd;

  if ((fd = fopen(filename, "r")) == NULL) {
    perror(filename);
    return 0;
  }
  else {
    NreadInt(&hc->size, fd);
    NreadInt(&hc->length, fd);
    NreadInt(&hc->min_codelen, fd);
    NreadInt(&hc->max_codelen, fd);
    NreadInts(hc->lcount, MAXCODELEN, fd);
    NreadInts(hc->symindex, MAXCODELEN, fd);
    NreadInts(hc->min_code, MAXCODELEN, fd);

    hc->symbols = (int *)cl_malloc(sizeof(int) * hc->size);
    NreadInts(hc->symbols, hc->size, fd);

    fclose(fd);
    return 1;
  }
}
Exemplo n.º 6
0
void
LogToCircularBuffer(CircularBuffer_t *buffer, int level, const char *fmt, ...)
{
	va_list ap;
	char buf[MAXLINE];
	int	nbytes;
	CircularBufferEntry_t *entry = cl_malloc(sizeof(CircularBufferEntry_t));
	
	if (!entry) {
		return;
	}
	va_start(ap, fmt);
	nbytes=vsnprintf(buf, MAXLINE, fmt, ap);
	/*	nbytes=vasprintf(&buf, fmt, ap); */
	va_end(ap);

	entry->buf = buf;
	entry->level = level;

	g_queue_push_tail(buffer->queue, entry);

	while(buffer->queue->length > buffer->size) {
		entry = g_queue_pop_head(buffer->queue);
		cl_free(entry->buf);
		cl_free(entry);
	}
}
Exemplo n.º 7
0
static GList* 
list_copy(const GList* _list)
{
	size_t i;
	GList* newlist = NULL;
	GList* list;

	memcpy(&list, &_list, sizeof(GList*));

	for (i = 0; i < g_list_length(list); i++){
		char* dup_element = NULL;
		char* element = g_list_nth_data(list, i);
		int len;
		if (element == NULL){
			cl_log(LOG_WARNING, "list_cleanup:"
			       "element is NULL");
			continue;
		}

		len = strlen(element);
		dup_element= cl_malloc(len + 1);
		if ( dup_element == NULL){
			cl_log(LOG_ERR, "duplicate element failed");
			continue;
		}
		memcpy(dup_element, element,len);
		dup_element[len] = 0;
		
		newlist = g_list_append(newlist, dup_element);		
	}
	
	return newlist;
}
Exemplo n.º 8
0
static void* 
binary_dup(const void* value, size_t len)
{
	
	char* dupvalue;
	
	/* 0 byte binary field is allowed*/

	if (value == NULL && len > 0){
		cl_log(LOG_ERR, "binary_dup:"
		       "NULL value with non-zero len=%d", 
		       (int)len);
		return NULL;
	}
	
	dupvalue = cl_malloc(len + 1);
	if (dupvalue == NULL){
		cl_log(LOG_ERR, "binary_dup:"
		       "cl_malloc failed");
		return NULL;
	}
	
	if (value != NULL) {
		memcpy(dupvalue, value, len);
	}

	dupvalue[len] =0;
	
	return dupvalue;
}
Exemplo n.º 9
0
/* 
 * ------------------------------------------------------------------------
 * 
 * "rcqpCmd_query(SEXP inMother, SEXP inChild, SEXP inQuery)" --
 * 
 *  
 * 
 * ------------------------------------------------------------------------
 */
SEXP rcqpCmd_query(SEXP inMother, SEXP inChild, SEXP inQuery)
{
	SEXP			result = R_NilValue;
	char			*child, *mother, *query, *c, *sc;
	
	if (!isString(inMother) || length(inMother) != 1) error("invalid corpus name");
	if (!isString(inChild) || length(inChild) != 1) error("invalid subcorpus name");
	if (!isString(inQuery) || length(inQuery) != 1) error("invalid query name");
	
	PROTECT(inMother);
	PROTECT(inChild);
	PROTECT(inQuery);

	mother = (char*)CHAR(STRING_ELT(inMother,0));
	child = (char*)CHAR(STRING_ELT(inChild,0));
	query = (char*)CHAR(STRING_ELT(inQuery,0));
	
	if (!split_subcorpus_spec(mother, &c, &sc)) {
		rcqp_error_code(cqi_errno);
	} else {
		char *cqp_query;
		int len = strlen(child) + strlen(query) + 10;
		
		cqp_query = (char *) cl_malloc(len);
		if (!check_subcorpus_name(child) || !cqi_activate_corpus(mother)) {
			rcqp_error_code(cqi_errno);
		} else {
			query_lock = floor(1e9 * cl_runif()) + 1; /* activate query lock mode with random key */
			
			if (rcqp_query_has_semicolon(query)) {
				sprintf(cqp_query, "%s = %s", child, query);
			} else {
				sprintf(cqp_query, "%s = %s;", child, query);
			}
			
			if (!cqp_parse_string(cqp_query)) {
				rcqp_error_code(CQI_CQP_ERROR_GENERAL); /* should be changed to detailed error messages */
			} else {
				char *			full_child;
				CorpusList *	childcl;
				
				full_child = combine_subcorpus_spec(c, child); /* c is the 'physical' part of the mother corpus */
				childcl = cqi_find_corpus(full_child);
				if ((childcl) == NULL) {
					rcqp_error_code(CQI_CQP_ERROR_GENERAL);
				} 
				free(full_child);
			}			
			query_lock = 0;           /* deactivate query lock mode */
		}
		free(cqp_query);
	}
	free(c);
	free(sc);
	
	UNPROTECT(3);
	
	return result;
}
Exemplo n.º 10
0
/** TODO delete: has been replaced throughout with cl_strdup (was only used once anyway) */
char *
CopyS(char *S)
{
  char *NewS = (char *)cl_malloc(strlen(S) + 1);
  
  strcpy(NewS, S); 
  return NewS;
}
Exemplo n.º 11
0
/* initialise new completion list (size 0) without freeing previous list (which was deallocated by readline library) */
void
cc_compl_list_init(void) {
  cc_compl_list = (char **) cl_malloc(CC_COMPL_LIST_ALLOC_BLOCK * sizeof(char *));
  cc_compl_list_allocated = CC_COMPL_LIST_ALLOC_BLOCK;
  cc_compl_list_size = 1;
  cc_compl_list[0] = NULL; /* dummy entry for longest common prefix (computed by cc_compl_list_sort_uniq()) */
  cc_compl_list[1] = NULL; /* end-of-list marker */
}
Exemplo n.º 12
0
void 
do_cqi_cqp_query(void)
{
  char *child, *mother, *query, *c, *sc;
  
  mother = cqi_read_string();
  child = cqi_read_string();
  query = cqi_read_string();
  if (server_debug) 
   Rprintf( "CQi: CQI_CQP_QUERY('%s', '%s', '%s')\n", mother, child, query);
  if (!split_subcorpus_spec(mother, &c, &sc)) {
    cqi_command(cqi_errno);
  }
  else {
    char *cqp_query;
    int len = strlen(child) + strlen(query) + 10;
    
    cqp_query = (char *) cl_malloc(len);
    if (!check_subcorpus_name(child) || !cqi_activate_corpus(mother)) {
      cqi_command(cqi_errno);
    }
    else {
      query_lock = floor(1e9 * cl_runif()) + 1; /* activate query lock mode with random key */

     Rprintf("CQPSERVER: query_lock = %d\n", query_lock);
      if (query_has_semicolon(query))
        sprintf(cqp_query, "%s = %s", child, query);
      else
        sprintf(cqp_query, "%s = %s;", child, query);
      if (!cqp_parse_string(cqp_query))
        cqi_command(CQI_CQP_ERROR_GENERAL); /* should be changed to detailed error messages */
      else {
        char *full_child;
        CorpusList *childcl;
        
        full_child = combine_subcorpus_spec(c, child); /* c is the 'physical' part of the mother corpus */
        childcl = cqi_find_corpus(full_child);
        if ((childcl) == NULL)
          cqi_command(CQI_CQP_ERROR_GENERAL);
        else {
          if (server_log) {
           Rprintf("'%s' ran the following query on %s\n", user, mother);
           Rprintf("\t%s\n", cqp_query);
           Rprintf("and got %d matches.\n", childcl->size);
          }
          cqi_command(CQI_STATUS_OK);

        }
        free(full_child);
      }

      query_lock = 0;           /* deactivate query lock mode */
    }
    free(cqp_query);
  }
  free(c);
  free(sc);
}
Exemplo n.º 13
0
/**
 * Creates a ContextDescriptor object.
 */
ContextDescriptor *
NewContextDescriptor(void)
{
  ContextDescriptor *cd;

  cd = (ContextDescriptor *)cl_malloc(sizeof(ContextDescriptor));
  initialize_context_descriptor(cd);

  return cd;
}
Exemplo n.º 14
0
Arquivo: auth.c Projeto: rforge/rcwb
void 
add_grant_to_last_user(char *corpus)
{
  Grant *grant;

  assert(authorized_users);        /* need a 'last user' in list */
  grant = (Grant *) cl_malloc(sizeof(Grant));
  grant->corpus = cl_strdup(corpus);
  grant->next = authorized_users->grants;
  authorized_users->grants = grant;
}
Exemplo n.º 15
0
void SelectWnd::addSelect(char *msg)
{
    cl_free(slctMsg[slctCnt]);
    slctMsg[slctCnt] = (BYTE *)cl_malloc(lstrlen(msg)+1);
    strcpy((char *)slctMsg[slctCnt], msg);
    if(strlen((char *)slctMsg[slctCnt])>44) {
        slctMsg[slctCnt][44] = '\0';
    }
    if(width < lstrlen((char *)slctMsg[slctCnt]))width = lstrlen((char *)slctMsg[slctCnt]);
    slctCnt ++;
} // SelectWnd::addSelect
Exemplo n.º 16
0
Arquivo: auth.c Projeto: rforge/rcwb
void 
add_hosts_in_subnet_to_list(char *ipsubnet)
{
  char *ipaddr = cl_malloc(strlen(ipsubnet) + 4);        /* 3 digits, NUL */
  int i;

  for (i = 1; i <= 255; i++) {
    sprintf(ipaddr, "%s%d", ipsubnet, i);
    add_host_to_list(ipaddr);
  }
  cl_free(ipaddr);
}
Exemplo n.º 17
0
void SelectWnd::selectBackup(char **selectMsg)
{
    int			i;

    saveInf.selectNum = 0;
    if(!bSelect)return;
    saveInf.selectNum = slctCnt;
    *selectMsg = (char *)cl_malloc(slctCnt*60);
    for(i=0; i<slctCnt; i++) {
        strcpy(*selectMsg +60*i,(char *)slctMsg[i]);
    }
} // SelectWnd::selectBackup
Exemplo n.º 18
0
int
VariableAddItem(Variable v, char *item)
{
  int i;

  if (!VariableItemMember(v, item)) {
    
    v->valid = 0;
    
    for (i = 0; i < v->nr_items; i++)
      if (v->items[i].free) {
        v->items[i].free = 0;
        v->items[i].sval = cl_strdup(item);
        v->items[i].ival = -1;
        break;
      }

    if (i >= v->nr_items) {

      /* no space in list. malloc. */

      v->nr_items += ITEM_REALLOC;
      
      if (v->items == NULL) 
        v->items = (VariableItem *)cl_malloc(sizeof(VariableItem) *
                                          v->nr_items);
      else 
        v->items = (VariableItem *)cl_realloc(v->items,
                                           sizeof(VariableItem) *
                                           v->nr_items);
      
      if (v->items == NULL) {
        fprintf(stderr, "Fatal Error #6: no memory left.");
        perror("Memory fault");
        assert(0 && "Big Problem here!");
      }

      v->items[i].sval = cl_strdup(item);
      v->items[i].free = 0;
      v->items[i].ival = -1;

      i++;

      for ( ; i < v->nr_items; i++) {
        v->items[i].sval = NULL;
        v->items[i].free = 1;
        v->items[i].ival = -1;
      }
    }
  }
  return 1;
}
Exemplo n.º 19
0
cl_kernel_bin_t *cl_create_kernel_bin(size_t numDevices)
{
    cl_kernel_bin_t *bins;

    bins = (cl_kernel_bin_t *)cl_malloc(sizeof(cl_kernel_bin_t));
    if (bins)
    {
        bins->deviceTypes = CL_DEVICE_TYPE_DEFAULT;
        bins->numDevices = numDevices;
        bins->numBytesSizes = sizeof(size_t) * bins->numDevices;
        bins->numBytesData = sizeof(unsigned char *) * bins->numDevices;
        bins->sizes = (size_t *)cl_malloc(bins->numBytesSizes);
        bins->data  = (unsigned char **)cl_malloc(bins->numBytesData);

        if (bins->sizes == NULL || bins->data == NULL)
        {
            cl_assert(bins->sizes != NULL && bins->data != NULL,);
            cl_delete_kernel_bin(bins);
            bins = NULL;
        }
        else
        {
Exemplo n.º 20
0
void CL_add_native_function(CL_Interpreter *interpreter,
                        char *name, CL_NativeFunctionProc *proc)
{
    FunctionDefinition *fd;

    fd = cl_malloc(sizeof(FunctionDefinition));
    fd->name = name;
    fd->type = NATIVE_FUNCTION_DEFINITION;
    fd->u.native_f.proc = proc;
    fd->next = interpreter->function_list;

    interpreter->function_list = fd;
}
Exemplo n.º 21
0
/**
 * Creates a new AttributeList.
 *
 * @param element_type  What type of attribute is this? ATT_POS, ATT_STRUC, etc.
 * @return              Pointer to the new AttributeList object.
 */
AttributeList *
NewAttributeList(int element_type)
{
  AttributeList *l;

  l = (AttributeList *)cl_malloc(sizeof(AttributeList));

  l->list = NULL;
  l->element_type = element_type;
  l->list_valid = 0;
  
  return l;
}
Exemplo n.º 22
0
Arquivo: output.c Projeto: rforge/rcwb
/** allocate and initialize new tabulation item */
TabulationItem
new_tabulation_item(void) {
  TabulationItem item = (TabulationItem) cl_malloc(sizeof(struct _TabulationItem));
  item->attribute_name = NULL;
  item->attribute = NULL;
  item->attribute_type = ATT_NONE;
  item->flags = 0;
  item->anchor1 = NoField;
  item->offset1 = 0;
  item->anchor2 = NoField;
  item->offset2 = 0;
  item->next = NULL;
  return item;
}
Exemplo n.º 23
0
Arquivo: output.c Projeto: rforge/rcwb
int
open_input_stream(struct InputRedir *rd)
{
  int i;
  char *tmp;

  assert(rd);

  /* TODO: check if stream is already open (options: ignore, warning, silently close old stream) */

  if (rd->name) {
    i = strlen(rd->name) - 1;
    if (i < 0) i = 0;
    while (i > 0 && rd->name[i] == ' ')
      i--;
    
    if ((rd->name[i] == '|') && i >= 1) {

      /* read input from a pipe (unless running in "secure" mode) */
      if (insecure) {
        rd->stream = NULL;
        rd->is_pipe = False;
      }
      else {
        rd->is_pipe = True;
        tmp = (char *) cl_malloc(i + 1);
        strncpy(tmp, rd->name, i);
        tmp[i] = '\0';
        rd->stream = popen(tmp, "r");
        cl_free(tmp);
      }

    }
    else {

      /* normal input from a regular file */
      rd->is_pipe = False;
      rd->stream = open_file(rd->name, "r");

    }
  }
  else {
    rd->stream = stdin;
    rd->is_pipe = True;  /* stdin behaves like a pipe */
  }
  return (rd->stream == NULL ? 0 : 1);
}
Exemplo n.º 24
0
Arquivo: auth.c Projeto: rforge/rcwb
void 
add_user_to_list(char *user, char *passwd)
{
  UserEntry *new_user;

  if (find_user(user) != NULL) {
    fprintf(stderr, "WARNING: user '%s' already in list (ignored)\n", user);
  }
  else {
    new_user = (UserEntry *) cl_malloc(sizeof(UserEntry));
    new_user->name = cl_strdup(user); 
    new_user->passwd = cl_strdup(passwd);
    new_user->grants = NULL;
    new_user->next = authorized_users;
    authorized_users = new_user;
  }
}
Exemplo n.º 25
0
static int
string2binary(void* value, size_t len, int depth, void** nv, size_t* nlen)
{
	char	tmpbuf[MAXLINE];
	char*	buf = NULL;
	int	buf_malloced = 0;
	int	ret = HA_FAIL;
	if (len > MAXLINE){
		buf = cl_malloc(len);
		if (buf == NULL){
			cl_log(LOG_ERR, "%s: malloc failed",
			       __FUNCTION__);
			goto out;
		}
		buf_malloced = 1;
	}else {
		buf = &tmpbuf[0];		
	}
	
	if (value == NULL && len == 0){
		*nv = NULL;
		*nlen = 0;
		ret = HA_OK;
		goto out;
	}

	if ( !value || !nv || depth < 0){
		cl_log(LOG_ERR, "string2binary:invalid input");
		ret = HA_FAIL;
		goto out;
	}
	
	memcpy(buf, value, len);
	*nlen = base64_to_binary(buf, len, value, len);				
	
	*nv = value;
	ret = HA_OK;
 out:
	if (buf_malloced && buf){
		cl_free(buf);
	}
	return ret;
}
Exemplo n.º 26
0
cl_byte *cl_load_bin(char *filename, size_t *pNumBytes)
{
    cl_byte *bin = NULL;
    FILE *fp = fopen(filename, "rb");
    if (fp != NULL)
    {
        size_t numBytes = flen(fp);
        bin = (cl_byte *)cl_malloc(numBytes);
        if (bin)
        {
            size_t b = fread(bin, 1, numBytes, fp);
#ifdef CL_DEBUG
            printf("Read "FMT_SIZE_T" bytes\n", b);
#endif
            fclose(fp);
        }
    }
    return bin;
}
Exemplo n.º 27
0
/**
 * Get lexicon IDs of variable's strings in corpus.attribute lexicon.
 *
 * @param v         The Variable object.
 * @param corpus    The corpus we are working with.
 * @param attribute The attribute against which to verify the Variable's items
 * @param nr_items  This will be set to the number of integers in the returned array.
 * @return          Pointer to block of integers based on valid items from the variable;
 *                  NULL if there were no valid items (i.e. items found in the
 *                  attribute's lexicon).
 */
int *
GetVariableItems(Variable v, 
                 Corpus *corpus,
                 Attribute *attribute,
                 /* returned: */
                 int *nr_items)
{
  int *items;
  int i, ip;

  if (VerifyVariable(v, corpus, attribute)) {
    if (v->nr_valid_items > 0) {
      items = (int *)cl_malloc(v->nr_valid_items * sizeof(int));
      *nr_items = v->nr_valid_items;

      ip = 0;
      for (i = 0; i < v->nr_items; i++)
        if (!v->items[i].free && v->items[i].ival >= 0) {
          if (ip >= v->nr_valid_items)
            fprintf(stderr, "Error #2 in variable logic. Please contact developer.\n");
          else {
            items[ip] = v->items[i].ival;
            ip++;
          }
        }

      if (ip != v->nr_valid_items) 
        fprintf(stderr, "Error #3 in variable logic. Please contact developer.\n");

      /* eval_bool() expects a sorted list of IDs (for binary search) */
      qsort(items, *nr_items, sizeof(int), intcompare);
      return items;
    }
    else {
      *nr_items = 0;
      return NULL;
    }
  }
  else {
    *nr_items = 0;
    return NULL;
  }
}
Exemplo n.º 28
0
CircularBuffer_t *
NewCircularBuffer(const char *name, uint size, gboolean empty_after_dump)
{
	CircularBuffer_t *buffer = cl_malloc(sizeof(CircularBuffer_t));
	if (!buffer) {
		return buffer;
	}
	buffer->name = name;
	buffer->size = size;
	buffer->empty_after_dump = empty_after_dump;
	buffer->queue = g_queue_new();

#if 1
	if(empty_after_dump == FALSE) {
		cl_log(LOG_ERR, "This requires glib 2.4");
		empty_after_dump = TRUE;
	}
#endif

	return buffer;
}
Exemplo n.º 29
0
/** Look up the symbol contained in string S in the global hash table. */
Symbol
LookUp(char *S)
{
  Symbol Sym; 
  byte H;
  
  for (H = Hash(S), Sym = HashTab[H]; Sym != 0; Sym = Sym->Next)
    if (strcmp(Sym->Name, S) == 0) 
      return Sym;
  Sym = (Symbol)cl_malloc(sizeof *Sym);
  Sym->Name = cl_strdup(S);
  Sym->Hash = H;
  Sym->Next = HashTab[H];
  HashTab[H] = Sym;
  Sym->Tail = 0;
  if (FirstB == 0) 
    FirstB = Sym; 
  else 
    LastB->Tail = Sym;
  return LastB = Sym;
}
Exemplo n.º 30
0
void
Store(Symbol S, int Q)
{

  int H = 0x100 + S->Hash; 
  Exp E;

  for (E = ExpHash[H]; E != 0; E = E->Tail)
    if (S == E->Body.Leaf) 
      break;
  if (E == 0) 
    {
      E = (Exp)cl_malloc(sizeof *E);
      E->Tag = SymX;
      E->Body.Leaf = S;
      E->Hash = H;
      E->Tail = ExpHash[H];
      ExpHash[H] = E;
    }
  E->Class = Q;
}