Fixes #9 - determine the size of the status buffer based on the number of blocks
[dwmblocks.git] / dwmblocks.c
index ad8e91c..3af799f 100644 (file)
@@ -6,6 +6,7 @@
 #include<X11/Xlib.h>
 #define LENGTH(X)               (sizeof(X) / sizeof (X[0]))
 #define CMDLENGTH              50
+#define STATUSLENGTH (LENGTH(blocks) * CMDLENGTH + 1)
 
 typedef struct {
        char* icon;
@@ -14,14 +15,15 @@ typedef struct {
        unsigned int signal;
 } Block;
 void sighandler(int num);
-void replace(char *str, char old, char new);
 void getcmds(int time);
+#ifndef __OpenBSD__
 void getsigcmds(int signal);
 void setupsignals();
+void sighandler(int signum);
+#endif
 int getstatus(char *str, char *last);
 void setroot();
 void statusloop();
-void sighandler(int signum);
 void termhandler(int signum);
 
 
@@ -31,18 +33,10 @@ static Display *dpy;
 static int screen;
 static Window root;
 static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
-static char statusstr[2][256];
+static char statusstr[2][STATUSLENGTH];
 static int statusContinue = 1;
 static void (*writestatus) () = setroot;
 
-void replace(char *str, char old, char new)
-{
-       int N = strlen(str);
-       for(int i = 0; i < N; i++)
-               if(str[i] == old)
-                       str[i] = new;
-}
-
 //opens process *cmd and stores output in *output
 void getcmd(const Block *block, char *output)
 {
@@ -72,6 +66,7 @@ void getcmds(int time)
        }
 }
 
+#ifndef __OpenBSD__
 void getsigcmds(int signal)
 {
        const Block *current;
@@ -92,6 +87,7 @@ void setupsignals()
        }
 
 }
+#endif
 
 int getstatus(char *str, char *last)
 {
@@ -128,7 +124,9 @@ void pstdout()
 
 void statusloop()
 {
+#ifndef __OpenBSD__
        setupsignals();
+#endif
        int i = 0;
        getcmds(-1);
        while(statusContinue)
@@ -140,12 +138,13 @@ void statusloop()
        }
 }
 
-
+#ifndef __OpenBSD__
 void sighandler(int signum)
 {
        getsigcmds(signum-SIGRTMIN);
        writestatus();
 }
+#endif
 
 void termhandler(int signum)
 {