X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dwmblocks.c;h=ad8e91cb0f26d865cf87b1c5fd4ccfb22443635b;hb=3906995607d60e2721a03db78d4f3f4b63cd6afb;hp=30712432b175e3246463c0a527f7bb43c4099e33;hpb=1766af7d5e0facb911c664584fc703c5f8f89092;p=dwmblocks.git diff --git a/dwmblocks.c b/dwmblocks.c index 3071243..ad8e91c 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -5,6 +5,7 @@ #include #include #define LENGTH(X) (sizeof(X) / sizeof (X[0])) +#define CMDLENGTH 50 typedef struct { char* icon; @@ -20,7 +21,6 @@ void setupsignals(); int getstatus(char *str, char *last); void setroot(); void statusloop(); -void statusinit(); void sighandler(int signum); void termhandler(int signum); @@ -30,13 +30,10 @@ void termhandler(int signum); static Display *dpy; static int screen; static Window root; -static char statusbar[LENGTH(blocks)][50] = {0}; +static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; static char statusstr[2][256]; static int statusContinue = 1; -<<<<<<< HEAD static void (*writestatus) () = setroot; -======= ->>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 void replace(char *str, char old, char new) { @@ -56,8 +53,8 @@ void getcmd(const Block *block, char *output) return; char c; int i = strlen(block->icon); - while((c = fgetc(cmdf)) != EOF) - output[i++] = c; + fgets(output+i, CMDLENGTH-i, cmdf); + i = strlen(output); if (delim != '\0' && --i) output[i++] = delim; output[i++] = '\0'; @@ -99,21 +96,10 @@ void setupsignals() int getstatus(char *str, char *last) { strcpy(last, str); -<<<<<<< HEAD str[0] = '\0'; for(int i = 0; i < LENGTH(blocks); i++) -======= - int j = 0; - for(int i = 0; i < LENGTH(blocks); j+=strlen(statusbar[i++])) ->>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 - { strcat(str, statusbar[i]); - } -<<<<<<< HEAD str[strlen(str)-1] = '\0'; -======= - str[--j] = '\0'; ->>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 return strcmp(str, last);//0 if they are the same } @@ -154,11 +140,6 @@ void statusloop() } } -void statusinit() -{ - statusloop(); -} - void sighandler(int signum) { @@ -183,5 +164,5 @@ int main(int argc, char** argv) } signal(SIGTERM, termhandler); signal(SIGINT, termhandler); - statusinit(); + statusloop(); }