From a2a7a7ec5ee97eff37e968e0577d70af9eb5a20e Mon Sep 17 00:00:00 2001
From: Mattias Andrée <maandree@operamail.com>
Date: Sun, 26 Jan 2014 12:04:06 +0100
Subject: some small fixes + add -h and --help
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Mattias Andrée <maandree@operamail.com>
---
 src/adjbacklight.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

(limited to 'src')

diff --git a/src/adjbacklight.c b/src/adjbacklight.c
index 98e5bdf..53f3013 100644
--- a/src/adjbacklight.c
+++ b/src/adjbacklight.c
@@ -177,7 +177,7 @@ int main(int argc, char** argv)
   int i, j;
   pid_t pid = 0;
   char* set = NULL;
-  int get = 0, all = 0, cols = 80, ndevices = 0;
+  int get = 0, help = 0, all = 0, cols = 80, ndevices = 0;
   char** devices = alloca(argc * sizeof(char*));
   
   
@@ -188,7 +188,9 @@ int main(int argc, char** argv)
 	{
 	  #define T(S)  (!strcmp(arg, S))
 	  arg = *(argv + i);
-	  if (T("-a") || T("--all"))
+	  if (T("-h") || T("--help"))
+	    help = 1;
+	  else if (T("-a") || T("--all"))
 	    all = 1;
 	  else if (T("-c") || T("--copyright") || T("--copying"))
 	    {
@@ -255,7 +257,8 @@ int main(int argc, char** argv)
 	    }
 	  #undef T
 	}
-      if ((all + ndevices + get == 0) && !set)
+      fflush(stderr);
+      if (help || ((all + ndevices + get == 0) && !set))
 	{
 	  P("\n");
 	  P("adjbacklight - Convient method for adjusting the backlight on your portable computer");
@@ -494,12 +497,18 @@ int main(int argc, char** argv)
 	  free(space);
 	}
       else if (get)
-	{
-	  brightness *= 100.f;
-	  brightness /= nbrightness;
-	  printf("%.2f%%\n", brightness);
-	  fflush(stdout);
-	}
+	if (nbrightness)
+	  {
+	    brightness *= 100.f;
+	    brightness /= nbrightness;
+	    printf("%.2f%%\n", brightness);
+	    fflush(stdout);
+	  }
+	else
+	  {
+	    printf("%s\n", "100.00%");
+	    fflush(stdout);
+	  }
     }
   
   
@@ -548,6 +557,9 @@ static int isnumerical(const char* str)
 	case '%':
 	  p++;
 	  break;
+	  
+	default:
+	  return 0;
 	}
     }
   return p <= 2;
-- 
cgit v1.2.3-70-g09d2