};
static const struct unit units[] = {
+ { 'd', 86400, 1 },
+ { 'h', 3600, 1 },
{ 'k', 1000, 1 },
{ 'm', 1000000, 1 },
{ 'g', 1000000000, 1 },
return msg;
}
+byte *cf_parse_u64(byte *value, u64 *varp)
+{
+ char *msg = NULL;
+ const struct unit *u;
+
+ if (!*value)
+ msg = "Missing number";
+ else {
+ errno = 0;
+ char *end;
+ u64 x = strtoull(value, &end, 0);
+ if (errno == ERANGE)
+ msg = cf_rngerr;
+ else if (u = cf_lookup_unit(value, end, &msg)) {
+ if (x > ~(u64)0 / u->num)
+ msg = "Number out of range";
+ else {
+ x *= u->num;
+ if (x % u->den)
+ msg = "Number is not an integer";
+ else
+ *varp = x / u->den;
+ }
+ } else
+ *varp = x;
+ }
+ return msg;
+}
+
byte *cf_parse_double(byte *value, double *varp)
{
char *msg = NULL;
case CT_DOUBLE:
msg = cf_parse_double(value, (double *) item->var);
break;
+ case CT_U64:
+ msg = cf_parse_u64(value, (u64 *) item->var);
+ break;
default:
msg = "Unknown keyword";
}
int *longindex)
{
int res;
+ static int other_options;
do{
res=getopt_long(argc,argv,shortopts,longopts,longindex);
+ if(res == 'S' || res == 'C') {
+ if(other_options)
+ die("The -S and -C options must precede all other arguments");
+ }
if(res=='S'){
byte *sect,*name,*value;
byte *c;
msg=cf_set_item(sect,name,value);
}
if(msg)
- die("Invalid command line argument %s.%s=%s: %s",sect,name,value,msg);
+ die("Invalid command line argument -S%s.%s=%s: %s",sect,name,value,msg);
}else if(res=='C'){
cf_read(optarg);
/* unhandled option or end of options */
if(cfdeffile)
cf_read(cfdeffile);
+ other_options++;
return res;
}
}while(1);