Commits

William Giokas committed b39d02c

Version 0.2.1

clang works now!
Reordered functions to be slightly more intuitive
Created a `status' function that can be used to edit the status bar
without having to mess with main. I'll move it up by the #defines soon
enough.

Signed-off-by: William Giokas <1007380@gmail.com>

Comments (0)

Files changed (3)

 NAME = dwmstatus
-VERSION = 0.2
+VERSION = 0.2.1
 
 # Customize below to fit your system
 
 dwmstatus \- simple status bar for dwm
 .SH SYNOPSIS
 .B dwmstatus
+.RB [ \-v ]
 .SH DESCRIPTION
 dwmstatus is a simple, small status bar for dwm. Unlike large, complex shell
 scripts, this status bar tries to stay clean and concise, has no configuration
 system information is located and recompile.
 .SH OPTIONS
 .TP
-.B None.
+.B \-v
+Prints version information to stdout then exits with status 0
 .SH USAGE
 .TP
 Run dwbstatus in a shell and it will put its output into the dwm status bar
 
 	return smprintf("%s", line);
 }
+
+int runevery(time_t *ltime, int sec)
+{
+    time_t now = time(NULL);
+
+    if (difftime(now, *ltime) >= sec) {
+        *ltime = now;
+        return(1);
+    }
+    else
+        return(0);
+}
+
 /* BATTERY USAGE
  * Linux seems to change the filenames after suspend/hibernate
  * according to a random scheme. So just check for both possibilities.
 	remcap = -1;
     using  = -1;
     remaining = -1;
-    stat = "Not Present";
+    stat = "Not Charging";
 
 	co = readfile(base, "present");
 	if (co == NULL || co[0] != '1') {
 	free(co);
 
     co = readfile(base, "status");
+    if (co == NULL) {
+        co = "Not Charging";
+    }
     sscanf(co, "%s", &status);
-    free(co);
 
 	co = readfile(base, "charge_full_design");
 	if (co == NULL) {
 		return smprintf("invalid");
 
     /* Getting time remaining */
-    if (status == *("Discharging")) {
+    if (status == 'D') {
         remaining = (float)remcap / using;
         stat = "Batt";
-    } else if (status == *("Charging")) {
+    } else if (status == 'C') {
         remaining = ((float)descap - (float)remcap) /using;
         stat = "Char";
     } else {
     return smprintf("%02.0f°C", atof(co) / 1000);
 }
 /* END TEMP STUFF
+ *
+ * =========================
+ * setup the status bar here
  */
-
-int runevery(time_t *ltime, int sec) 
-{
-    time_t now = time(NULL);
-
-    if (difftime(now, *ltime) >= sec) {
-        *ltime = now;
-        return(1);
-    }
-    else
-        return(0);
-}
-
-
 int
-main(void)
+status()
 {
 	char *status = NULL;
 	char *avgs = NULL;
         free(net);
 		setstatus(status);
 	}
+    return 0;
+}
 
+int
+main(int argc, char *argv[])
+{
+    if(argc == 2 && !strcmp("-v", argv[1])) {
+        printf("dwmstatus %s © 2012-2013 William Giokas. See LICENSE for more info.\n",
+                VERSION);
+        return 0;
+    }
+    else if(argc != 1) {
+        printf("usage: dwmstatus [-v]\n");
+        return 1;
+    }
+    else
+        status();
 	XCloseDisplay(dpy);
-
-	return 0;
+    return 0;
 }
-