Reindent and restyle
authornorly <ny-git@enpas.org>
Fri, 15 Feb 2013 00:10:58 +0000 (00:10 +0000)
committernorly <ny-git@enpas.org>
Fri, 15 Feb 2013 00:10:58 +0000 (00:10 +0000)
statuses/battery.c
statuses/cpuusage.c
statuses/datetime.c
statuses/fan.c
statuses/memusage.c
statuses/netif.c
statuses/temp.c
statuses/tools.c
statuses/uptime.c
statuses/volume_alsa.c
sysstatus.c

index 4c3599922cc7019aff65b2d842da44f3df6f6e88..5375ea1efa4d396cdedfb91f2ba5a1b077edfaff 100644 (file)
 #include "battery.h"
 
 #ifndef POWER_BASEDIR
-       #define POWER_BASEDIR "/sys/class/power_supply/"
+  #define POWER_BASEDIR "/sys/class/power_supply/"
 #endif
 
 
 void status_battery(char *batname)
 {
-       char batpath[256];
-       int batpathlen;
-
-       char stline[16];
-       ssize_t stlen;
-
-       int chargeNow = 0;
-       int chargeFull = -1;
-       int chargePercent = -1;
-       int battW = 1;
-       int battV = 0;
-       float battTime = -1;
-
-
-       // Prepare path
-       batpathlen = sizeof(POWER_BASEDIR) - 1 + strlen(batname);
-       if (batpathlen + 1 + sizeof("/energy_full") >= sizeof(batpath))
-       {
-               statusError("status_battery",
-                       "batpath buffer too small",
-                       batname);
-               return;
-       }
-       strcpy(batpath, POWER_BASEDIR);
-       strcat(batpath, batname);
-
-
-       // Is the battery present?
-       if (access(batpath, F_OK))
-       {
-               //printf(" ^fg(grey)[%s] ", batname);
-               return;
-       }
-
-
-       // Get info
-       strcpy(&batpath[batpathlen], "/energy_now");
-       stlen = fileRead(stline, sizeof(stline), batpath);
-       if (stlen > 0)
-               chargeNow = atoi(stline);
-
-       strcpy(&batpath[batpathlen], "/energy_full");
-       stlen = fileRead(stline, sizeof(stline), batpath);
-       if (stlen > 0)
-               chargeFull = atoi(stline);
-
-       strcpy(&batpath[batpathlen], "/power_now");
-       stlen = fileRead(stline, sizeof(stline), batpath);
-       if (stlen > 0)
-               battW = atoi(stline);
-
-       strcpy(&batpath[batpathlen], "/voltage_now");
-       stlen = fileRead(stline, sizeof(stline), batpath);
-       if (stlen > 0)
-               battV = atoi(stline);
-
-
-       // Prettyprint
-       if (chargeFull > 0)
-               chargePercent = chargeNow / (chargeFull / 100);
-
-       if (chargePercent <= 40) // 40
-       {
-               if (chargePercent <= 25) // 25
-               {
-                       if (chargePercent <= 10) // 10
-                               fputs("^fg(red)", stdout);
-                       else // 11-25%
-                               fputs("^fg(orange)", stdout);
-               }
-               else // 26-40%
-                       fputs("^fg(yellow)", stdout);
-       }
-       else
-       {
-               if (chargePercent > 70) // 70
-                       fputs("^fg(white)", stdout);
-               else // 41-70%
-                       fputs("^fg(green)", stdout);
-       }
-
-       battTime = (float)chargeNow / (float)battW;
-
-       if (battW == 0) // fully charged and not in use
-               printf(" %s: %d%% _ _ ",
-                       batname, chargePercent);
-       else
-               printf(" %s: %d%% %.1fh %.1fW ",
-                       batname, chargePercent, battTime, (float)battW / 1000000.0);
+  char batpath[256];
+  int batpathlen;
+
+  char stline[16];
+  ssize_t stlen;
+
+  int chargeNow = 0;
+  int chargeFull = -1;
+  int chargePercent = -1;
+  int battW = 1;
+  int battV = 0;
+  float battTime = -1;
+
+
+  /* Prepare path */
+  batpathlen = sizeof(POWER_BASEDIR) - 1 + strlen(batname);
+  if (batpathlen + 1 + sizeof("/energy_full") >= sizeof(batpath)) {
+    statusError("status_battery",
+                "batpath buffer too small",
+                batname);
+    return;
+  }
+  strcpy(batpath, POWER_BASEDIR);
+  strcat(batpath, batname);
+
+
+  /* Is the battery present? */
+  if (access(batpath, F_OK)) {
+    //printf(" ^fg(grey)[%s] ", batname);
+    return;
+  }
+
+
+  /* Get info */
+  strcpy(&batpath[batpathlen], "/energy_now");
+  stlen = fileRead(stline, sizeof(stline), batpath);
+  if (stlen > 0) {
+    chargeNow = atoi(stline);
+  }
+
+  strcpy(&batpath[batpathlen], "/energy_full");
+  stlen = fileRead(stline, sizeof(stline), batpath);
+  if (stlen > 0) {
+    chargeFull = atoi(stline);
+  }
+
+  strcpy(&batpath[batpathlen], "/power_now");
+  stlen = fileRead(stline, sizeof(stline), batpath);
+  if (stlen > 0) {
+    battW = atoi(stline);
+  }
+
+  strcpy(&batpath[batpathlen], "/voltage_now");
+  stlen = fileRead(stline, sizeof(stline), batpath);
+  if (stlen > 0) {
+    battV = atoi(stline);
+  }
+
+
+  /* Prettyprint */
+  if (chargeFull > 0) {
+    chargePercent = chargeNow / (chargeFull / 100);
+  }
+
+  if (chargePercent <= 40) {
+    if (chargePercent <= 25) {
+      if (chargePercent <= 10) {
+        fputs("^fg(red)", stdout);
+      } else {
+        // 11-25%
+        fputs("^fg(orange)", stdout);
+      }
+    } else {
+      // 26-40%
+      fputs("^fg(yellow)", stdout);
+    }
+  } else {
+    if (chargePercent > 70) {
+      fputs("^fg(white)", stdout);
+    } else {
+      // 41-70%
+      fputs("^fg(green)", stdout);
+    }
+  }
+
+  battTime = (float)chargeNow / (float)battW;
+
+  if (battW == 0) {
+    // fully charged and not in use
+    printf(" %s: %d%% _ _ ",
+            batname, chargePercent);
+  } else {
+    printf(" %s: %d%% %.1fh %.1fW ",
+            batname, chargePercent, battTime, (float)battW / 1000000.0);
+  }
 }
index dd9f1c516eb3e86ef67d4c51821cccb2d3b5defb..355f6bbc96a160617ad04d62f4765d333f161fa1 100644 (file)
@@ -6,13 +6,13 @@
 #include "../config.h"
 
 #ifndef NUM_CPUS
-       #define NUM_CPUS 1
+  #define NUM_CPUS 1
 #endif
 #ifndef CPU_HISTORY_SIZE
-       #define CPU_HISTORY_SIZE 1
+  #define CPU_HISTORY_SIZE 1
 #endif
 #if CPU_HISTORY_SIZE < 1
-       #define CPU_HISTORY_SIZE 1
+  #define CPU_HISTORY_SIZE 1
 #endif
 
 
@@ -22,64 +22,69 @@ float cpu_history[CPU_HISTORY_SIZE]; // don't care about init values
 
 void status_cpuusage()
 {
-       double loadavg[3] = { -13.37, -13.37, -13.37 } ;
+  double loadavg[3] = { -13.37, -13.37, -13.37 } ;
 
-       char *stline = NULL;
-       size_t stlen;
-       FILE *stfile;
+  char *stline = NULL;
+  size_t stlen;
+  FILE *stfile;
 
-       unsigned long cpu_user;
-       unsigned long cpu_nice;
-       unsigned long cpu_sys;
-       unsigned long cpu_used;
-       unsigned long cpu_idle;
-       unsigned long cpu_total;
-       int i;
+  unsigned long cpu_user;
+  unsigned long cpu_nice;
+  unsigned long cpu_sys;
+  unsigned long cpu_used;
+  unsigned long cpu_idle;
+  unsigned long cpu_total;
+  int i;
 
 
-       fputs("^fg(yellow)", stdout);   // Error signaling color
+  // Error signaling color
+  fputs("^fg(yellow)", stdout);
 
-       stfile = fopen("/proc/stat", "r");
-       if (stfile != NULL)
-       {
-               for(i = CPU_HISTORY_SIZE - 1; i > 0; i--)
-                       cpu_history[i] = cpu_history[i - 1];
+  stfile = fopen("/proc/stat", "r");
+  if (stfile != NULL) {
+    for(i = CPU_HISTORY_SIZE - 1; i > 0; i--) {
+      cpu_history[i] = cpu_history[i - 1];
+    }
 
-               stlen = getline(&stline, &stlen, stfile);
-               fclose(stfile);
+    stlen = getline(&stline, &stlen, stfile);
+    fclose(stfile);
 
-               if ( 4 == sscanf(stline, "%*s %ld %ld %ld %ld", &cpu_user, &cpu_nice, &cpu_sys, &cpu_idle) )
-               {
-                       cpu_used = cpu_user + cpu_nice + cpu_sys;
-                       cpu_total = cpu_used + cpu_idle;
+    if ( 4 == sscanf(stline, "%*s %ld %ld %ld %ld",
+                    &cpu_user, &cpu_nice, &cpu_sys, &cpu_idle) ) {
+      cpu_used = cpu_user + cpu_nice + cpu_sys;
+      cpu_total = cpu_used + cpu_idle;
 
-                       // Now do the percentage
-                       cpu_history[0] = (float)(cpu_used - last_cpu_used) /
-                                               (float)(cpu_total - last_cpu_total);
+      // Now do the percentage
+      cpu_history[0] = (float)(cpu_used - last_cpu_used) /
+                        (float)(cpu_total - last_cpu_total);
 
-                       last_cpu_used = cpu_used;
-                       last_cpu_total = cpu_total;
+      last_cpu_used = cpu_used;
+      last_cpu_total = cpu_total;
 
 
-                       if (cpu_history[0] < 0.4)
-                               fputs("^fg(#0077FF)", stdout);  // CPU idling OK
-                       else
-                               fputs("^fg(#FF00FF)", stdout);  // CPU busy
+      if (cpu_history[0] < 0.4) {
+        // CPU idling OK
+        fputs("^fg(#0077FF)", stdout);
+      } else {
+        // CPU busy
+        fputs("^fg(#FF00FF)", stdout);
+      }
 
-                       //printf(" CPU: %.0f%% ", cpu_history[0] * 100);
-               }
+      //printf(" CPU: %.0f%% ", cpu_history[0] * 100);
+    }
 
-               free(stline);
-       }
+    free(stline);
+  }
 
 
-       if (getloadavg(loadavg, 3) > 0)
-               printf(" %s%.0f,%.0f,%.0f,%.0f ",
-                       cpu_history[0] < 0.1000 ? " " : "",
-                       cpu_history[0] * 100,
-                       loadavg[0] * (100 / 1),
-                       loadavg[1] * (100 / 1), // (100 / NUM_CPUS)
-                       loadavg[2] * (100 / 1));
+  if (getloadavg(loadavg, 3) > 0) {
+    printf(" %s%.0f,%.0f,%.0f,%.0f ",
+            cpu_history[0] < 0.1000 ? " " : "",
+            cpu_history[0] * 100,
+            loadavg[0] * (100 / 1),
+            loadavg[1] * (100 / 1),  // (100 / NUM_CPUS)
+            loadavg[2] * (100 / 1));
+  }
 
-       //fputs(" CPU usage ", stdout);
+  //fputs(" CPU usage ", stdout);
 }
index 42b37aafb389006661ba4b5d4986db3b594f3f9e..abcc07b59d773344f138eeea3fbe53d2445903cb 100644 (file)
@@ -5,33 +5,30 @@
 
 void status_datetime()
 {
-       time_t nows = 0;
-       struct tm *nowtm;
+  time_t nows = 0;
+  struct tm *nowtm;
 
-       nows = time(NULL);
-       if (nows == ((time_t) -1))
-       {
-               printf(" ^fg(red)ERROR: DATETIME");
-               return;
-       }
+  nows = time(NULL);
+  if (nows == ((time_t) -1)) {
+    printf(" ^fg(red)ERROR: DATETIME");
+    return;
+  }
 
-       nowtm = localtime(&nows);
+  nowtm = localtime(&nows);
 
-       printf(" ^fg(#666666)%d.%d.%d  ^fg(grey)%d:%.2d"
+  printf(" ^fg(#666666)%d.%d.%d  ^fg(grey)%d:%.2d"
+        #ifdef SHOW_SECONDS
+        ":%.2d"
+        #endif
+        " "
+        ,nowtm -> tm_mday,
+        (nowtm -> tm_mon) + 1,
+        (nowtm -> tm_year) + 1900,
+        nowtm -> tm_hour,
+        nowtm -> tm_min
 
-               #ifdef SHOW_SECONDS
-               ":%.2d"
-               #endif
-               " "
-               ,nowtm -> tm_mday,
-               (nowtm -> tm_mon) + 1,
-               (nowtm -> tm_year) + 1900,
-               nowtm -> tm_hour,
-               nowtm -> tm_min
-
-               #ifdef SHOW_SECONDS
-               ,nowtm -> tm_sec
-               #endif
-
-               );
+        #ifdef SHOW_SECONDS
+        ,nowtm -> tm_sec
+        #endif
+    );
 }
index 2be5b284f78ad8232d7cfa195a5b4ec4c322a4e3..84cfa9035f9d6cfc502c1a6c4047b5f8f4349f92 100644 (file)
@@ -5,23 +5,23 @@
 
 void status_fan(char *title, char *sysfile)
 {
-       char stline[16];
-       int stfile;
-       ssize_t stlen;
+  char stline[16];
+  int stfile;
+  ssize_t stlen;
 
-       stlen = fileRead(stline, sizeof(stline), sysfile);
-       if (stlen <= 0)
-               return;
+  stlen = fileRead(stline, sizeof(stline), sysfile);
+  if (stlen <= 0) {
+    return;
+  }
 
-       // Read a valid value? Sometimes we get garbage from sysfs...
-       if (stlen > 5)
-       {
-               printf(" ^fg(red)%sERROR ", title);
-               return;
-       }
+  // Read a valid value? Sometimes we get garbage from sysfs...
+  if (stlen > 5) {
+    printf(" ^fg(red)%sERROR ", title);
+    return;
+  }
 
-       fputs(" ^fg(#CCCCCC)", stdout);
-       fputs(title, stdout);
-       fwrite(stline, 1, stlen - 1, stdout);
-       fputs(" rpm ", stdout);
+  fputs(" ^fg(#CCCCCC)", stdout);
+  fputs(title, stdout);
+  fwrite(stline, 1, stlen - 1, stdout);
+  fputs(" rpm ", stdout);
 }
index 37ba563ca59a45c5cf8e22e9aa2e157fe85dabf0..ea411348e3714521f8eb10a374e699dc35821027 100644 (file)
@@ -5,44 +5,45 @@
 
 void status_memusage()
 {
-       char *stline = NULL;
-       size_t stlen;
-       FILE *stfile;
+  char *stline = NULL;
+  size_t stlen;
+  FILE *stfile;
 
-       int memtotal = 0;
-       int memfree = 0;
-       int memused;
-       int membuffers = 0;
-       int memcached = 0;
+  int memtotal = 0;
+  int memfree = 0;
+  int memused;
+  int membuffers = 0;
+  int memcached = 0;
 
 
-       stfile = fopen("/proc/meminfo", "r");
-       if (stfile != NULL)
-       {
-               stlen = getline(&stline, &stlen, stfile);
-               memtotal = atoi(&stline[17]);
+  stfile = fopen("/proc/meminfo", "r");
+  if (stfile != NULL) {
+    stlen = getline(&stline, &stlen, stfile);
+    memtotal = atoi(&stline[17]);
 
-               stlen = getline(&stline, &stlen, stfile);
-               memfree = atoi(&stline[17]);
+    stlen = getline(&stline, &stlen, stfile);
+    memfree = atoi(&stline[17]);
 
-               stlen = getline(&stline, &stlen, stfile);
-               membuffers = atoi(&stline[17]);
+    stlen = getline(&stline, &stlen, stfile);
+    membuffers = atoi(&stline[17]);
 
-               stlen = getline(&stline, &stlen, stfile);
-               memcached = atoi(&stline[17]);
-               free(stline);
+    stlen = getline(&stline, &stlen, stfile);
+    memcached = atoi(&stline[17]);
+    free(stline);
 
-               fclose(stfile);
+    fclose(stfile);
 
-               memused = memtotal - memfree - memcached - membuffers;
+    memused = memtotal - memfree - memcached - membuffers;
 
-               memused /= 1024;        // Just show MBs used
+    memused /= 1024;   // Just show MBs used
 
-               if ((float)memused / (float)memtotal < 0.85)
-                       fputs("^fg(green)", stdout);    // < 85% mem used
-               else
-                       fputs("^fg(red)", stdout);      // >= 85% mem used
+    /* Change color based on % of RAM used */
+    if ((float)memused / (float)memtotal < 0.85) {
+      fputs("^fg(green)", stdout);
+    } else {
+      fputs("^fg(red)", stdout);
+    }
 
-               printf(" Mem: %d M ", memused);
-       }
+    printf(" Mem: %d M ", memused);
+  }
 }
index d5cc8037610a7b408eb6fda55c26fce3c3489399..581d2796fdd9ef3408200a7d4e5bfb2687176d4f 100644 (file)
@@ -7,76 +7,73 @@
 #include "../config.h"
 
 #ifndef NETIF_BASEDIR
-       #define NETIF_BASEDIR "/sys/class/net/"
+  #define NETIF_BASEDIR "/sys/class/net/"
 #endif
 
 
 void status_netif(char *ifname)
 {
-       char ifpath[256];
-       int ifpathlen;
-
-       char stline[16];
-       ssize_t stlen;
-
-       double ifsum = 0.0;
-       int ifsumpower;
-
-
-       // Prepare path
-       ifpathlen = sizeof(NETIF_BASEDIR) - 1 + strlen(ifname);
-       if (ifpathlen + 1 + sizeof("/statistics/rx_bytes") >= sizeof(ifpath))
-       {
-               statusError("status_netif",
-                       "ifpath buffer too small",
-                       ifname);
-               return;
-       }
-       strcpy(ifpath, NETIF_BASEDIR);
-       strcat(ifpath, ifname);
-
-
-       // Is the interface up?
-       if (access(ifpath, F_OK))
-       {
-               //printf(" ^fg(grey)[%s] ", ifname);
-               return;
-       }
-
-
-       strcpy(&ifpath[ifpathlen], "/carrier");
-       stlen = fileRead(stline, sizeof(stline), ifpath);
-       if (stlen > 0)
-       {
-               if (stline[0] == '1')
-               {
-                       fputs("^fg(yellow)", stdout);
-               }
-               else
-               {
-                       //fputs("^fg(red)", stdout);
-                       return;
-               }
-       } else {
-               return;
-       }
-
-       strcpy(&ifpath[ifpathlen], "/statistics/rx_bytes");
-       stlen = fileRead(stline, sizeof(stline), ifpath);
-       if (stlen > 0)
-               ifsum = atof(stline);
-
-       strcpy(&ifpath[ifpathlen], "/statistics/tx_bytes");
-       stlen = fileRead(stline, sizeof(stline), ifpath);
-       if (stlen > 0)
-               ifsum += atof(stline);
-
-
-       for(ifsumpower = 0; ifsum >= 1024.0; ifsumpower++)
-               ifsum = ifsum / 1024;
-
-       printf(" %s: %.*f %c ", ifname,
-                               ifsumpower ? ifsumpower - 1 : ifsumpower,
-                               ifsum,
-                               powerToChar(ifsumpower));
+  char ifpath[256];
+  int ifpathlen;
+
+  char stline[16];
+  ssize_t stlen;
+
+  double ifsum = 0.0;
+  int ifsumpower;
+
+
+  /* Prepare path */
+  ifpathlen = sizeof(NETIF_BASEDIR) - 1 + strlen(ifname);
+  if (ifpathlen + 1 + sizeof("/statistics/rx_bytes") >= sizeof(ifpath)) {
+    statusError("status_netif",
+                "ifpath buffer too small",
+                ifname);
+    return;
+  }
+  strcpy(ifpath, NETIF_BASEDIR);
+  strcat(ifpath, ifname);
+
+
+  /* Is the interface up? */
+  if (access(ifpath, F_OK)) {
+    //printf(" ^fg(grey)[%s] ", ifname);
+    return;
+  }
+
+
+  strcpy(&ifpath[ifpathlen], "/carrier");
+  stlen = fileRead(stline, sizeof(stline), ifpath);
+  if (stlen > 0) {
+    if (stline[0] == '1') {
+      fputs("^fg(yellow)", stdout);
+    } else {
+      //fputs("^fg(red)", stdout);
+      return;
+    }
+  } else {
+    return;
+  }
+
+  strcpy(&ifpath[ifpathlen], "/statistics/rx_bytes");
+  stlen = fileRead(stline, sizeof(stline), ifpath);
+  if (stlen > 0) {
+    ifsum = atof(stline);
+  }
+
+  strcpy(&ifpath[ifpathlen], "/statistics/tx_bytes");
+  stlen = fileRead(stline, sizeof(stline), ifpath);
+  if (stlen > 0) {
+    ifsum += atof(stline);
+  }
+
+
+  for(ifsumpower = 0; ifsum >= 1024.0; ifsumpower++) {
+    ifsum = ifsum / 1024;
+  }
+
+  printf(" %s: %.*f %c ", ifname,
+                          ifsumpower ? ifsumpower - 1 : ifsumpower,
+                          ifsum,
+                          powerToChar(ifsumpower));
 }
index 5737e29c8a1e8a110a18f89cdcefc54d49a8c425..f2cece80197589a228df2af6d4d845c2f1120f13 100644 (file)
@@ -5,27 +5,30 @@
 
 void status_temp(char *title, char *sysfile)
 {
-       char stline[16];
-       int stfile;
-       ssize_t stlen;
+  char stline[16];
+  int stfile;
+  ssize_t stlen;
 
-       stlen = fileRead(stline, sizeof(stline), sysfile);
-       if (stlen <= 0)
-               return;
+  stlen = fileRead(stline, sizeof(stline), sysfile);
+  if (stlen <= 0) {
+    return;
+  }
 
-       // Read a valid value? Sometimes we get garbage from sysfs...
-       if (stlen < 6 || stlen > 7)
-       {
-               printf(" ^fg(red)%sERROR ", title);
-               return;
-       }
+  /*
+   * Read a valid value?
+   * Sometimes we get garbage from sysfs...
+   */
+  if (stlen < 6 || stlen > 7) {
+    printf(" ^fg(red)%sERROR ", title);
+    return;
+  }
 
-       fputs(" ^fg(#FF33FF)", stdout);
-       fputs(title, stdout);
-       fwrite(stline, 1, stlen - 4, stdout);
-       /*
-       fputs(".", stdout);
-       fwrite(&stline[stlen - 3], 1, 1, stdout);
-       */
-       fputs("°C ", stdout);
+  fputs(" ^fg(#FF33FF)", stdout);
+  fputs(title, stdout);
+  fwrite(stline, 1, stlen - 4, stdout);
+  /*
+  fputs(".", stdout);
+  fwrite(&stline[stlen - 3], 1, 1, stdout);
+  */
+  fputs("°C ", stdout);
 }
index 83fe2b1ab86aa8ebae45cef7a996360fb3ceeae8..abb8a0db943f1693bf01492ff5bc5d1a3f0b2b71 100644 (file)
@@ -5,53 +5,56 @@
 
 char powerToChar(int power)
 {
-       switch(power)
-       {
-               case 0:
-                       return 'b';
-               case 1:
-                       return 'k';
-               case 2:
-                       return 'M';
-               case 3:
-                       return 'G';
-               case 4:
-                       return 'T';
-               case 5:
-                       return 'P';
-               case 6:
-                       return 'E';
-       }
-
-       return '?';
+  switch(power)
+  {
+    case 0:
+      return 'b';
+    case 1:
+      return 'k';
+    case 2:
+      return 'M';
+    case 3:
+      return 'G';
+    case 4:
+      return 'T';
+    case 5:
+      return 'P';
+    case 6:
+      return 'E';
+  }
+
+  return '?';
 }
 
 
 void statusError(char *where, char *what, char *extra)
 {
-       fprintf(stderr, "%s: %s", where, what);
-       if (extra)
-               fprintf(stderr, " -- %s", extra);
-       fputs("\n", stderr);
+  fprintf(stderr, "%s: %s", where, what);
+  if (extra) {
+    fprintf(stderr, " -- %s", extra);
+  }
+  fputs("\n", stderr);
 }
 
 
 ssize_t fileRead(char *buf, size_t bufsize, char *file)
 {
-       int fd;
-       int readbytes;
+  int fd;
+  int readbytes;
 
-       fd = open(file, 0);
-       if (fd < 0)
-               return -1;
+  fd = open(file, 0);
+  if (fd < 0) {
+    return -1;
+  }
 
-       readbytes = read(fd, buf, bufsize - 1);
-       close(fd);
+  readbytes = read(fd, buf, bufsize - 1);
+  close(fd);
 
-       if (readbytes > 0)
-               buf[readbytes] = '\0';
-       else
-               buf[0] = '\0';
+  if (readbytes > 0) {
+    buf[readbytes] = '\0';
+  } else {
+    buf[0] = '\0';
+  }
 
-       return readbytes;
+  return readbytes;
 }
index d512cdb84512f143a5fc2a3e0a4d91385e5e54c4..fba6a6f0b90523ae8f971c1e46b56a5498b036eb 100644 (file)
@@ -7,55 +7,52 @@
 
 void status_uptime()
 {
-       char stline[16];
-       int stfile;
-       ssize_t stlen;
-       int i;
-       int upts, uptm, upth, uptd;
-
-       fputs(" ^fg(#AAAAAA)up: ", stdout);
-
-       stlen = fileRead(stline, sizeof(stline), "/proc/uptime");
-       if (stlen < 0)
-       {
-               fputs(" ^fg(red)ERROR ", stdout);
-               return;
-       }
-
-       // Cut first element
-       for(i = 0; i < stlen; i++)
-       {
-               if (stline[i] == ' ')
-               {
-                       stline[i] = '\0';
-                       break;
-               }
-       }
-
-       // Split time into days, hours, mins, secs
-       upts = atoi(stline);
-       uptd = upts / (24 * 60 * 60);
-       upts -= uptd * (24 * 60 * 60);
-       upth = upts / (60 * 60);
-       upts -= upth * (60 * 60);
-       uptm = upts / (60);
-       upts -= uptm * (60);
-
-       if (uptd > 0)
-               printf("%dd ", uptd);
-
-       printf("%d:%.2d"
-
-               #ifdef SHOW_SECONDS
-               ":%.2d"
-               #endif
-
-               " "
-               ,upth
-               ,uptm
-
-               #ifdef SHOW_SECONDS
-               ,upts
-               #endif
-               );
+  char stline[16];
+  int stfile;
+  ssize_t stlen;
+  int i;
+  int upts, uptm, upth, uptd;
+
+  fputs(" ^fg(#AAAAAA)up: ", stdout);
+
+  stlen = fileRead(stline, sizeof(stline), "/proc/uptime");
+  if (stlen < 0) {
+    fputs(" ^fg(red)ERROR ", stdout);
+    return;
+  }
+
+  /* Cut first element */
+  for(i = 0; i < stlen; i++) {
+    if (stline[i] == ' ') {
+      stline[i] = '\0';
+      break;
+    }
+  }
+
+  // Split time into days, hours, mins, secs
+  upts = atoi(stline);
+  uptd = upts / (24 * 60 * 60);
+  upts -= uptd * (24 * 60 * 60);
+  upth = upts / (60 * 60);
+  upts -= upth * (60 * 60);
+  uptm = upts / (60);
+  upts -= uptm * (60);
+
+  if (uptd > 0) {
+    printf("%dd ", uptd);
+  }
+
+  printf("%d:%.2d"
+          #ifdef SHOW_SECONDS
+          ":%.2d"
+          #endif
+
+          " "
+          ,upth
+          ,uptm
+
+          #ifdef SHOW_SECONDS
+          ,upts
+          #endif
+        );
 }
index 527cafe7bce2cdf860c00df735e8a65540eae44a..5d648c507fd3552ca18d03a78f5484df506c1841 100644 (file)
@@ -3,61 +3,67 @@
 
 int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_id_t channel)
 {
-       snd_mixer_t *handle = NULL;
-       snd_mixer_elem_t *elem;
-       snd_mixer_selem_id_t *sid;
+  snd_mixer_t *handle = NULL;
+  snd_mixer_elem_t *elem;
+  snd_mixer_selem_id_t *sid;
 
-       long min = 0, max = 0;
-       long volume;
-       int on_off;
+  long min = 0, max = 0;
+  long volume;
+  int on_off;
 
 
-       snd_mixer_selem_id_alloca(&sid);
+  snd_mixer_selem_id_alloca(&sid);
 
-       if (snd_mixer_open(&handle, 0) < 0)
-               return -1;
+  if (snd_mixer_open(&handle, 0) < 0) {
+    return -1;
+  }
 
-       if (snd_mixer_attach(handle, cardname) < 0)
-               goto ERROR;
+  if (snd_mixer_attach(handle, cardname) < 0) {
+    goto ERROR;
+  }
 
-       snd_mixer_selem_id_set_name(sid, mixername);
+  snd_mixer_selem_id_set_name(sid, mixername);
 
-       if (snd_mixer_selem_register(handle, NULL, NULL) < 0)
-               goto ERROR;
+  if (snd_mixer_selem_register(handle, NULL, NULL) < 0) {
+    goto ERROR;
+  }
 
-       if (snd_mixer_load(handle) < 0)
-               goto ERROR;
+  if (snd_mixer_load(handle) < 0) {
+    goto ERROR;
+  }
 
-       elem = snd_mixer_find_selem(handle, sid);
-       if (!elem)
-               goto ERROR;
+  elem = snd_mixer_find_selem(handle, sid);
+  if (!elem) {
+    goto ERROR;
+  }
 
-       if (snd_mixer_selem_has_playback_volume(elem) && snd_mixer_selem_has_playback_channel(elem, channel))
-       {
-               snd_mixer_selem_get_playback_switch(elem, channel, &on_off);
-               if (on_off)
-                       fputs("^fg(#22FF22)", stdout);
-               else
-                       fputs("^fg(red)", stdout);
+  if (snd_mixer_selem_has_playback_volume(elem)
+      && snd_mixer_selem_has_playback_channel(elem, channel)) {
+    snd_mixer_selem_get_playback_switch(elem, channel, &on_off);
+    if (on_off) {
+      fputs("^fg(#22FF22)", stdout);
+    } else {
+      fputs("^fg(red)", stdout);
+    }
 
-               snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
+    snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
 
-               snd_mixer_selem_get_playback_volume(elem, channel, &volume);
-               fputs("^ca(1, amixer sset Master toggle)", stdout);
-               fputs("^ca(4, amixer sset Master 2+ unmute)", stdout);
-               fputs("^ca(5, amixer sset Master 2- unmute)", stdout);
-               printf(" Vol: %d ", (int)volume);
-               fputs("^ca()", stdout);
-               fputs("^ca()", stdout);
-               fputs("^ca()", stdout);
-       }
+    snd_mixer_selem_get_playback_volume(elem, channel, &volume);
+    fputs("^ca(1, amixer sset Master toggle)", stdout);
+    fputs("^ca(4, amixer sset Master 2+ unmute)", stdout);
+    fputs("^ca(5, amixer sset Master 2- unmute)", stdout);
+    printf(" Vol: %d ", (int)volume);
+    fputs("^ca()", stdout);
+    fputs("^ca()", stdout);
+    fputs("^ca()", stdout);
+  }
 
-       snd_mixer_close(handle);
+  snd_mixer_close(handle);
 
-       return 0;
+  return 0;
 
-       ERROR:
+  ERROR:
 
-       snd_mixer_close(handle);
-       return -1;
+  snd_mixer_close(handle);
+  return -1;
 }
index aed988c2fba5c6c91f7a4a33e828b6d66eea0f99..9628b17e72877fedba8158c0fa0fb6d042229698 100644 (file)
 
 void updatestatus()
 {
-       //status_uptime();
+  //status_uptime();
 
-       status_cpuusage();
+  status_cpuusage();
 
-       status_battery("BAT0");
-       status_battery("BAT1");
+  status_battery("BAT0");
+  status_battery("BAT1");
 
-       status_memusage();
+  status_memusage();
 
-       status_netif("eth0");
-       //status_netif("eth1");
-       //status_netif("eth2");
-       status_netif("wlan0");
-       //status_netif("wlan1");
-        status_netif("wlan2");
-       //status_netif("usb0");
-       status_netif("ppp0");
+  status_netif("eth0");
+  //status_netif("eth1");
+  //status_netif("eth2");
+  status_netif("wlan0");
+  //status_netif("wlan1");
+  status_netif("wlan2");
+  //status_netif("usb0");
+  status_netif("ppp0");
 
-       //status_temp("GPU: ", "/sys/class/hwmon/hwmon0/device/temp4_input");
-       //status_temp("CPU: ", "/sys/class/hwmon/hwmon0/device/temp2_input");
-       status_temp("CPU: ", "/sys/devices/platform/coretemp.0/temp1_input");
+  //status_temp("GPU: ", "/sys/class/hwmon/hwmon0/device/temp4_input");
+  //status_temp("CPU: ", "/sys/class/hwmon/hwmon0/device/temp2_input");
+  status_temp("CPU: ", "/sys/devices/platform/coretemp.0/temp1_input");
 
-       status_fan("Fan: ", "/sys/devices/platform/thinkpad_hwmon/fan1_input");
+  status_fan("Fan: ", "/sys/devices/platform/thinkpad_hwmon/fan1_input");
 
-       status_volume_alsa("default", "Master", 0);
+  status_volume_alsa("default", "Master", 0);
 
-       status_datetime();
+  status_datetime();
 
-       fputs("\n", stdout);
-       fflush(stdout);
+  fputs("\n", stdout);
+  fflush(stdout);
 }
 
 int main()
 {
-       struct timeval tv;
+  struct timeval tv;
 
-       for(;;)
-       {
-               updatestatus();
+  for(;;)
+  {
+    updatestatus();
 
-               tv.tv_sec = UPDATE_SECS;
-               tv.tv_usec = 0;
+    tv.tv_sec = UPDATE_SECS;
+    tv.tv_usec = 0;
 
-               select(0, NULL, NULL, NULL, &tv);
-       }
+    select(0, NULL, NULL, NULL, &tv);
+  }
 
-       return 0;
+  return 0;
 }