/* * 1,yes,true * 0,no,false */ int rc_getbool(struct rcfile *rcp, const char *section, int sect_id, const char *key, int *value) { struct rcsection *rsp; struct rckey *rkp; char *p; rsp = rc_findsect(rcp, section, sect_id); if (!rsp) return (ENOENT); rkp = rc_sect_findkey(rsp,key); if (!rkp) return (ENOENT); p = rkp->rk_value; while (*p && isspace(*p)) p++; if (*p == '0' || strcasecmp(p,"no") == 0 || strcasecmp(p, "false") == 0 || strcasecmp(p, "off") == 0) { *value = 0; return (0); } if (*p == '1' || strcasecmp(p,"yes") == 0 || strcasecmp(p, "true") == 0 || strcasecmp(p, "on") == 0) { *value = 1; return (0); } fprintf(stderr, "invalid boolean value '%s' for key '%s' in section " "'%s' \n",p, key, section); return (EINVAL); }
int rc_getstringptr(struct rcfile *rcp,char *section, char *key,char **dest) { struct rcsection *rsp; struct rckey *rkp; *dest = NULL; rsp = rc_findsect(rcp, section); if (!rsp) return ENOENT; rkp = rc_sect_findkey(rsp,key); if (!rkp) return ENOENT; *dest = rkp->rk_value; return 0; }
static struct rckey * rc_sect_addkey(struct rcsection *rsp, char *name, char *value) { struct rckey *p; p = rc_sect_findkey(rsp, name); if (p) { free(p->rk_value); } else { p = malloc(sizeof(*p)); if (!p) return NULL; SLIST_INSERT_HEAD(&rsp->rs_keys, p, rk_next); p->rk_name = strdup(name); } p->rk_value = value ? strdup(value) : strdup(""); return p; }
int rc_getstringptr(struct rcfile *rcp, const char *section, int sect_id, const char *key, char **dest) { struct rcsection *rsp; struct rckey *rkp; *dest = NULL; rsp = rc_findsect(rcp, section, sect_id); if (!rsp) return (ENOENT); rkp = rc_sect_findkey(rsp,key); if (!rkp) return (ENOENT); *dest = rkp->rk_value; return (0); }
int rc_getint(struct rcfile *rcp,char *section, char *key,int *value) { struct rcsection *rsp; struct rckey *rkp; rsp = rc_findsect(rcp, section); if (!rsp) return ENOENT; rkp = rc_sect_findkey(rsp,key); if (!rkp) return ENOENT; errno = 0; *value = strtol(rkp->rk_value,NULL,0); if (errno) { fprintf(stderr, "invalid int value '%s' for key '%s' in section '%s'\n",rkp->rk_value,key,section); return errno; } return 0; }