chiark / gitweb /
boolean option
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 7 Jun 2012 18:09:08 +0000 (19:09 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 7 Jun 2012 18:10:09 +0000 (19:10 +0100)
cprogs/xacpi-simple.c
debian/changelog

index f2ba491d93adbc41d8773eedf77b4564f90ece13..2a392b5f679ecf40ebe61fd85939ee4f2df4e70b 100644 (file)
@@ -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;
index 62aea32fbf5b3bbcbf705317469b8d397db3528d..7c10cbae16299cc0f40ed36ec6f8b452d536e221 100644 (file)
@@ -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: