added configuration option for n/a text
@@ -11,6 +11,9 @@
/* bar update interval in seconds (smallest value = 1) */ static unsigned int update_interval = 1; +/* text to show if no value can be retrieved */ +static const char unknowntext[] = "n/a"; + /* statusbar - battery_perc (battery percentage) [argument: battery name] - cpu_perc (cpu usage in percent) [argument: NULL]
@@ -76,7 +76,7 @@
/* open battery now file */ if (!(fp = fopen(batterynowfile, "r"))) { fprintf(stderr, "Error opening battery file: %s.\n", batterynowfile); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read value */@@ -88,7 +88,7 @@
/* open battery full file */ if (!(fp = fopen(batteryfullfile, "r"))) { fprintf(stderr, "Error opening battery file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read value */@@ -115,7 +115,7 @@
/* open stat file */ if (!(fp = fopen("/proc/stat","r"))) { fprintf(stderr, "Error opening stat file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read values */@@ -130,7 +130,7 @@
/* open stat file */ if (!(fp = fopen("/proc/stat","r"))) { fprintf(stderr, "Error opening stat file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read values */@@ -155,7 +155,7 @@ size_t bufsize = 64;
char *buf = malloc(bufsize); if (buf == NULL) { fprintf(stderr, "Failed to get date/time.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* get time in format */@@ -165,7 +165,7 @@ if (!strftime(buf, bufsize, timeformat, localtime(&tm))) {
setlocale(LC_TIME, "C"); free(buf); fprintf(stderr, "Strftime failed.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } setlocale(LC_TIME, "C");@@ -184,7 +184,7 @@
/* try to open mountpoint */ if (statvfs(mountpoint, &fs) < 0) { fprintf(stderr, "Could not get filesystem info.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* return free */@@ -201,7 +201,7 @@
/* try to open mountpoint */ if (statvfs(mountpoint, &fs) < 0) { fprintf(stderr, "Could not get filesystem info.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* calculate percent */@@ -220,7 +220,7 @@
/* try to open mountpoint */ if (statvfs(mountpoint, &fs) < 0) { fprintf(stderr, "Could not get filesystem info.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* return total */@@ -236,7 +236,7 @@
/* try to open mountpoint */ if (statvfs(mountpoint, &fs) < 0) { fprintf(stderr, "Could not get filesystem info.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* return used */@@ -253,7 +253,7 @@
/* open entropy file */ if (!(fp = fopen("/proc/sys/kernel/random/entropy_avail", "r"))) { fprintf(stderr, "Could not open entropy file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* extract entropy */@@ -274,12 +274,12 @@ gid_t gid;
if ((gid = getgid()) < 0) { fprintf(stderr, "Could no get gid.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } else { return smprintf("%d", gid); } - return smprintf("n/a"); + return smprintf(unknowntext); } /* hostname */@@ -292,7 +292,7 @@
/* open hostname file */ if (!(fp = fopen("/proc/sys/kernel/hostname", "r"))) { fprintf(stderr, "Could not open hostname file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* extract hostname */@@ -316,7 +316,7 @@
/* check if getting ip address works */ if (getifaddrs(&ifaddr) == -1) { fprintf(stderr, "Error getting IP address.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* get the ip address */@@ -330,7 +330,7 @@
if ((strcmp(ifa->ifa_name, interface) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) { if (s != 0) { fprintf(stderr, "Error getting IP address.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } return smprintf("%s", host); }@@ -339,8 +339,7 @@
/* free the address */ freeifaddrs(ifaddr); - /* return n/a if nothing works */ - return smprintf("n/a"); + return smprintf(unknowntext); } /* ram free */@@ -353,7 +352,7 @@
/* open meminfo file */ if (!(fp = fopen("/proc/meminfo", "r"))) { fprintf(stderr, "Error opening meminfo file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read the values */@@ -377,7 +376,7 @@
/* open meminfo file */ if (!(fp = fopen("/proc/meminfo", "r"))) { fprintf(stderr, "Error opening meminfo file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read the values */@@ -406,7 +405,7 @@
/* open meminfo file */ if (!(fp = fopen("/proc/meminfo", "r"))) { fprintf(stderr, "Error opening meminfo file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read the values */@@ -429,7 +428,7 @@
/* open meminfo file */ if (!(fp = fopen("/proc/meminfo", "r"))) { fprintf(stderr, "Error opening meminfo file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read the values */@@ -459,7 +458,7 @@
/* try to open the command output */ if (!(fp = popen(command, "r"))) { fprintf(stderr, "Could not get command output for: %s.\n", command); - return smprintf("n/a"); + return smprintf(unknowntext); } /* get command output text, save it to buffer */@@ -493,7 +492,7 @@
/* open temperature file */ if (!(fp = fopen(file, "r"))) { fprintf(stderr, "Could not open temperature file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* extract temperature */@@ -522,10 +521,10 @@ if (pw) {
return smprintf("%s", pw->pw_name); } else { fprintf(stderr, "Could not get username.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } - return smprintf("n/a"); + return smprintf(unknowntext); } /* uid */@@ -542,10 +541,10 @@ if (uid) {
return smprintf("%d", uid); } else { fprintf(stderr, "Could not get uid.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } - return smprintf("n/a"); + return smprintf(unknowntext); }@@ -571,7 +570,7 @@ snd_mixer_selem_id_malloc(&mute_info);
/* check */ if (vol_info == NULL || mute_info == NULL) { fprintf(stderr, "Could not get alsa volume.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } snd_mixer_selem_id_set_name(vol_info, channel); snd_mixer_selem_id_set_name(mute_info, channel);@@ -624,7 +623,7 @@
/* open wifi file */ if(!(fp = fopen(path, "r"))) { fprintf(stderr, "Error opening wifi operstate file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* read the status */@@ -635,13 +634,13 @@ fclose(fp);
/* check if interface down */ if(strcmp(status, "up\n") != 0) { - return smprintf("n/a"); + return smprintf(unknowntext); } /* open wifi file */ if (!(fp = fopen("/proc/net/wireless", "r"))) { fprintf(stderr, "Error opening wireless file.\n"); - return smprintf("n/a"); + return smprintf(unknowntext); } /* extract the signal strength */@@ -680,17 +679,17 @@
/* check */ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { fprintf(stderr, "Cannot open socket for interface: %s\n", wificard); - return smprintf("n/a"); + return smprintf(unknowntext); } wreq.u.essid.pointer = id; if (ioctl(sockfd,SIOCGIWESSID, &wreq) == -1) { fprintf(stderr, "Get ESSID ioctl failed for interface %s\n", wificard); - return smprintf("n/a"); + return smprintf(unknowntext); } /* return the essid */ if (strcmp((char *)wreq.u.essid.pointer, "") == 0) { - return smprintf("n/a"); + return smprintf(unknowntext); } else { return smprintf("%s", (char *)wreq.u.essid.pointer); }@@ -720,7 +719,7 @@ argument = args[i];
char *res = argument.func(argument.args); char *element = smprintf(argument.format, res); if (element == NULL) { - element = smprintf("n/a"); + element = smprintf(unknowntext); fprintf(stderr, "Failed to format output.\n"); } strcat(status_string, element);