int pdata_get_var_s( pdata *pd, const char *name, char *val){
  char str[80];
  if( hashtab_find( pd, name, str) == HT_FAILURE){
    return PDATA_FAILURE;
  };
  strcpy( val, str);
  return PDATA_SUCCESS;
}
int pdata_get_var_i( pdata *pd, const char *name, int *val){
  char str[80];
  if( hashtab_find( pd, name, str) == HT_FAILURE){
    return PDATA_FAILURE;
  };
  *val = atoi( str);
  return PDATA_SUCCESS;
}
void hashtab_delete(struct hashtable *s,const unsigned char* key,const size_t len)
{
	struct element* e = hashtab_find(s,key,len);
	if(e && e->key) {	
		PROFILE_HASH_DELETE(s);
		free(e->key);/*FIXME: any way to shut up warnings here? if I make key char*, I get tons of warnings in entitylist.h */
		e->key = DELETED_KEY;
		s->used--;
	}
}
/*!
 * Get the number of elements stored under the key `name`.
 */
int pdata_array_length( pdata *pd, const char *name){
  int i=0;
  char name_iter[80];
  char str[80];
  do{
    sprintf( name_iter, "%s___%03d", name, i);
    i++;
  }while( hashtab_find( pd, name_iter, str) == HT_SUCCESS );
  return i;
}
/*!
 * Read in multiple data of various types.
 *
 * Use the `stdarg.h` macros to make a function that can take a
 * variable number of arguments. The arguments should always come in
 * pairs `data_type` (INT_T, DOUBLE_T, STRING_T), then a pointer to
 * that data type. This can be used to write simple wrappers to fill
 * up custom defined structs.
 */
int pdata_get_list( pdata *pd, const char *name, int num, ...){
  int i, *j;
  double *d;
  char *s;
  char name_iter[80], str[80];
  va_list vl;
 
  /* make sure the last argument is there */
  sprintf( name_iter, "%s___%03d", name, num-1);
  if( hashtab_find( pd, name_iter, str) == HT_FAILURE){
    return PDATA_FAILURE;
  }

  /* Go through the arguments */
  va_start( vl, num);
  for( i=0; i<num; i++){
    sprintf( name_iter, "%s___%03d", name, i);
    if( hashtab_find( pd, name_iter, str) == HT_FAILURE){
      return i;
    };
    switch( va_arg( vl, pdata_type)){
    case DOUBLE_T:
      d = va_arg( vl, double*);
      *d = atof( str);
      break;
    case INT_T:
      j = va_arg( vl, int*);
      *j = atoi( str);
      break;
    case STRING_T:
      s = va_arg( vl, char*);
      strcpy( s, str);
      break;
    default:
      break;
    }
  }
  va_end( vl);

  return PDATA_SUCCESS;
}
int pdata_get_array_s( pdata *pd, const char *name, char **val){
  int i=0;
  char name_iter[80];
  char str[80];
  sprintf( name_iter, "%s___%03d", name, i);
  while( hashtab_find( pd, name_iter, str) == HT_SUCCESS ){
    strcpy( val[i], str);
    i++;
    sprintf( name_iter, "%s___%03d", name, i);
  }
  return i;
}
Exemple #7
0
static long scope_lookup(struct scope *s, const char *token, const size_t len)
{
	while(s) {
		const struct element *el = hashtab_find(&s->id_map, token, len);
		if(el && el->data != -1) {
			return el->data;
		}
		/* not found in current scope, try in outer scope */
		s = s->parent;
	}
	return -1;
}
int pdata_get_element_s( pdata *pd, const char *name, 
                        unsigned int i, char *val){
  char name_iter[80];
  char str[80];
  sprintf( name_iter, "%s___%03d", name, i);

  if( hashtab_find( pd, name_iter, str) == HT_SUCCESS){
    strcpy( val, str);
    return PDATA_SUCCESS;
  }else{
    return PDATA_FAILURE;
  }
}
Exemple #9
0
static const char* scope_use(struct scope *s, const char *token, const size_t len)
{
	const struct element *el = hashtab_find(&s->id_map, token, len);
	if(el) {
		/* identifier already found in current scope,
		 * return here to avoid overwriting uniq id */
		return el->key;
	}
	/* identifier not yet in current scope's hashtab, add with ID -1.
	 * Later if we find a declaration it will automatically assign a uniq ID
	 * to it. If not, we'll know that we have to push ID == -1 tokens to an
	 * outer scope.*/
	el = hashtab_insert(&s->id_map, token, len, -1);
	return el ? el->key : NULL;
}