From: Ian Jackson Date: Thu, 7 Jun 2012 18:09:08 +0000 (+0100) Subject: boolean option X-Git-Tag: debian/4.1.32~7 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=commitdiff_plain;h=44a53b350e1bf482eb1f0991b997a0385def5039 boolean option --- diff --git a/cprogs/xacpi-simple.c b/cprogs/xacpi-simple.c index f2ba491..2a392b5 100644 --- a/cprogs/xacpi-simple.c +++ b/cprogs/xacpi-simple.c @@ -62,7 +62,7 @@ #define TIMEOUT_ONERROR 3333 /* milliseconds */ static const char program_name[]= "xacpi-simple"; -static int debug, alarmlevel; +static int debug=-1, alarmlevel; /*---------- general utility stuff and declarations ----------*/ @@ -526,6 +526,28 @@ static const char *getresource(const char *want) { return val.addr; } +static int getresource_bool(const char *want, int def, int *cache) { + /* *cache should be initialised to -1 and will be set to !!value */ + + if (*cache >= 0) return *cache; + const char *str= getresource(want); + int result = def; + if (str && str[0]) { + char *ep; + long l= strtol(str,&ep,0); + if (!*ep) { + result = l > 0; + } else { + switch (str[0]) { + case 't': case 'T': case 'y': case 'Y': result= 1; break; + case 'f': case 'F': case 'n': case 'N': result= 0; break; + case '-': /* option name from XrmoptionIsArg */ result= 1; break; + } + } + } + return *cache= result; +} + static void more_resources(const char *str, const char *why) { XrmDatabase more; @@ -547,7 +569,7 @@ static void parseargs(int argc, char **argv) { if (argc>1) badusage(); - debug= !!getresource("debug"); + getresource_bool("debug",0,&debug); const char *alarmlevel_string= getresource("alarmLevel"); alarmlevel = alarmlevel_string ? atoi(alarmlevel_string) : 300; diff --git a/debian/changelog b/debian/changelog index 62aea32..7c10cba 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +chiark-utils (4.1.32) unstable; urgency=medium + + xacpi-simple improvements: + * Better parsing of boolean -debug option. + + -- + chiark-utils (4.1.31) unstable; urgency=medium Bugfixes to programs: