/* This program is free software; you can redistribute it and/or modify it
under the terms of the license (GNU LGPL) which comes with this package. */
-#include "gras_private.h" /* prototypes of this module */
+#include "xbt/misc.h"
+#include "xbt/sysdep.h"
+#include "xbt/log.h"
+#include "xbt/error.h"
+#include "xbt/dynar.h"
+#include "xbt/dict.h"
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(config,gros,"configuration support");
+#include "xbt/config.h" /* prototypes of this module */
+
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(config,xbt,"configuration support");
/* gras_cfgelm_t: the typedef corresponding to a config cell.
*/
-gras_error_t gras_cfg_new(gras_cfg_t **whereto) {
- return gras_dict_new((gras_dict_t**)whereto);
+gras_cfg_t *gras_cfg_new(void) {
+ return (gras_cfg_t *)gras_dict_new();
}
/**
*
*/
-gras_error_t
+void
gras_cfg_cpy(gras_cfg_t **whereto, gras_cfg_t *tocopy) {
gras_dict_cursor_t *cursor=NULL;
gras_cfgelm_t *cell=NULL;
char *name=NULL;
- int errcode=no_error;
*whereto=NULL;
gras_assert0(tocopy,"cannot copy NULL config");
gras_dict_foreach((gras_dict_t*)tocopy,cursor,name,cell) {
- if ((errcode=gras_cfg_register(*whereto, name, cell->type,
- cell->min, cell->max)) != no_error) {
- if (cursor) gras_dict_cursor_free(cursor);
- if (*whereto) gras_cfg_free(whereto);
- return errcode;
- }
+ gras_cfg_register(*whereto, name, cell->type, cell->min, cell->max);
}
-
- return errcode;
}
void gras_cfg_free(gras_cfg_t **cfg) {
* register an element within a config set
*/
-gras_error_t
+void
gras_cfg_register(gras_cfg_t *cfg,
const char *name, gras_cfgelm_type_t type,
int min, int max){
gras_error_t errcode;
DEBUG4("Register cfg elm %s (%d to %d %s)",name,min,max,gras_cfgelm_type_name[type]);
- TRYCATCH(mismatch_error,gras_dict_get((gras_dict_t*)cfg,name,(void**)&res));
+ errcode = gras_dict_get((gras_dict_t*)cfg,name,(void**)&res);
- if (errcode != mismatch_error) {
+ if (errcode == no_error) {
WARN1("Config elem %s registered twice.",name);
/* Will be removed by the insertion of the new one */
}
+ gras_assert_error(mismatch_error);
res=gras_new(gras_cfgelm_t,1);
- if (!res)
- RAISE_MALLOC;
res->type=type;
res->min=min;
switch (type) {
case gras_cfgelm_int:
- TRY(gras_dynar_new(&(res->content), sizeof(int), NULL));
+ res->content = gras_dynar_new(sizeof(int), NULL);
break;
case gras_cfgelm_double:
- TRY(gras_dynar_new(&(res->content), sizeof(double), NULL));
+ res->content = gras_dynar_new(sizeof(double), NULL);
break;
case gras_cfgelm_string:
- TRY(gras_dynar_new(&(res->content),sizeof(char*),&gras_cfg_str_free));
+ res->content = gras_dynar_new(sizeof(char*),&gras_cfg_str_free);
break;
case gras_cfgelm_host:
- TRY(gras_dynar_new(&(res->content),sizeof(gras_host_t*),&gras_cfg_host_free));
+ res->content = gras_dynar_new(sizeof(gras_host_t*),&gras_cfg_host_free);
break;
default:
ERROR1("%d is an invalide type code",type);
}
- return gras_dict_set((gras_dict_t*)cfg,name,res,&gras_cfgelm_free);
+ gras_dict_set((gras_dict_t*)cfg,name,res,&gras_cfgelm_free);
}
/**
gras_error_t
gras_cfg_register_str(gras_cfg_t *cfg,const char *entry) {
- char *entrycpy=strdup(entry);
+ char *entrycpy=gras_strdup(entry);
char *tok;
int min,max;
gras_cfgelm_type_t type;
- gras_error_t errcode;
-
tok=strchr(entrycpy, ':');
if (!tok) {
ERROR3("%s%s%s",
gras_abort();
}
- TRYCLEAN(gras_cfg_register(cfg,entrycpy,type,min,max),
- gras_free(entrycpy));
+ gras_cfg_register(cfg,entrycpy,type,min,max);
gras_free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */
return no_error;
if (!options || !strlen(options)) { /* nothing to do */
return no_error;
}
- optionlist_cpy=strdup(options);
+ optionlist_cpy=gras_strdup(options);
DEBUG1("List to parse and set:'%s'",options);
option=optionlist_cpy;
/* Pass the value */
while (option-name<=(len-1) && *option != ' ' && *option != '\n' && *option != '\t') {
- //fprintf(stderr,"Take %c.\n",*option);
+ /*fprintf(stderr,"Take %c.\n",*option);*/
option++;
}
if (option-name == len) {
- //fprintf(stderr,"Boundary=EOL\n");
+ /*fprintf(stderr,"Boundary=EOL\n");*/
option=NULL; /* don't do next iteration */
} else {
- //fprintf(stderr,"Boundary on '%c'. len=%d;option-name=%d\n",*option,len,option-name);
+ /*fprintf(stderr,"Boundary on '%c'. len=%d;option-name=%d\n",*option,len,option-name);*/
/* Pass the following blank chars */
*(option++)='\0';
while (option-name<(len-1) && (*option == ' ' || *option == '\n' || *option == '\t')) {
- // fprintf(stderr,"Ignore a blank char.\n");
+ /* fprintf(stderr,"Ignore a blank char.\n");*/
option++;
}
if (option-name == len-1)
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_int,&cell));
if (cell->max > 1) {
- return gras_dynar_push(cell->content,&val);
+ gras_dynar_push(cell->content,&val);
} else {
- return gras_dynar_set(cell->content,0,&val);
+ gras_dynar_set(cell->content,0,&val);
}
+ return no_error;
}
/**
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_double,&cell));
if (cell->max > 1) {
- return gras_dynar_push(cell->content,&val);
+ gras_dynar_push(cell->content,&val);
} else {
- return gras_dynar_set(cell->content,0,&val);
+ gras_dynar_set(cell->content,0,&val);
}
+ return no_error;
}
/**
gras_cfg_set_string(gras_cfg_t *cfg,const char*name, const char*val) {
gras_cfgelm_t *cell;
gras_error_t errcode;
- char *newval = strdup(val);
+ char *newval = gras_strdup(val);
VERB2("Configuration setting: %s=%s",name,val);
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_string,&cell));
if (cell->max > 1) {
- return gras_dynar_push(cell->content,&newval);
+ gras_dynar_push(cell->content,&newval);
} else {
- return gras_dynar_set(cell->content,0,&newval);
+ gras_dynar_set(cell->content,0,&newval);
}
+ return no_error;
}
/**
gras_host_t *val=gras_new(gras_host_t,1);
VERB3("Configuration setting: %s=%s:%d",name,host,port);
- if (!val)
- RAISE_MALLOC;
- val->name = strdup(name);
+
+ val->name = gras_strdup(name);
val->port = port;
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_host,&cell));
if (cell->max > 1) {
- return gras_dynar_push(cell->content,&val);
+ gras_dynar_push(cell->content,&val);
} else {
- return gras_dynar_set(cell->content,0,&val);
+ gras_dynar_set(cell->content,0,&val);
}
+ return no_error;
}
/* ---- [ Removing ] ---- */