Improved and fixed a bug in updatestatus

This commit is contained in:
Ashish Kumar Yadav 2020-08-06 02:15:49 +05:30
parent 9c5af35c14
commit d4cceab950

View file

@ -10,10 +10,8 @@
#define CMDLENGTH 25
#define STTLENGTH 256
#define LOCKFILE "/tmp/dwmblocks.pid"
#define NILL INT_MIN
#define EMPTYCMDOUT(block) (*block->cmdoutcur == '\n' || *block->cmdoutcur == '\0')
#define LOCKFILE "/tmp/dwmblocks.pid"
typedef struct {
char *pathu;
@ -215,7 +213,12 @@ updatestatus()
/* checking half of the function */
/* skip empty blocks */
while (current->pathu && EMPTYCMDOUT(current)) {
for (;;) {
if (!current->pathu)
return 0;
/* skip delimiter for the first non-empty block */
if (*current->cmdoutcur != '\n' && *current->cmdoutcur != '\0')
goto skipdelimc;
if (*current->cmdoutcur != *current->cmdoutprv) {
*current->cmdoutprv = *current->cmdoutcur;
current++;
@ -223,23 +226,31 @@ updatestatus()
}
current++;
}
/* skip delimiter in front of the first non-empty block */
if (current->pathu)
goto skipdelimc;
else
return 0;
/* main loop */
for (; current->pathu; current++) {
s += delimlength;
skipdelimc:
c = current->cmdoutcur; p = current->cmdoutprv;
do {
if (*c != *p) {
s += c - current->cmdoutcur;
/* handles delimiter */
if (*current->cmdoutcur != '\n' && *current->cmdoutcur != '\0')
s += delimlength;
else {
if (*current->cmdoutcur != *current->cmdoutprv) {
*current->cmdoutprv = *current->cmdoutcur;
current++;
goto update1;
}
continue;
}
skipdelimc:
c = current->cmdoutcur; p = current->cmdoutprv;
if (*c != *p)
goto update2;
else {
c++; p++;
} while (*c != '\n' && *c != '\0');
}
for (; *c != '\n' && *c != '\0'; c++, p++)
if (*c != *p) {
s += c - current->cmdoutcur;
goto update2;
}
s += c - current->cmdoutcur;
if (current->pathc && current->signal)
s++;
@ -248,24 +259,31 @@ skipdelimc:
update0:
/* updating half of the function */
/* skip empty blocks */
while (current->pathu && EMPTYCMDOUT(current)) {
for (;;) {
if (!current->pathu)
return 1;
/* skip delimiter for the first non-empty block */
if (*current->cmdoutcur != '\n' && *current->cmdoutcur != '\0')
goto skipdelimu;
*current->cmdoutprv = *current->cmdoutcur;
current++;
}
/* skip delimiter in front of the first non-empty block */
if (current->pathu)
goto skipdelimu;
else
return 1;
update1:
/* main loop */
for (; current->pathu; current++) {
d = delim;
while (*d)
*(s++) = *(d++);
*(s++) = '\n'; /* to mark the end of delimiter */
/* handles delimiter */
if (*current->cmdoutcur != '\n' && *current->cmdoutcur != '\0') {
d = delim;
while (*d)
*(s++) = *(d++);
*(s++) = '\n'; /* to mark the end of delimiter */
} else {
*current->cmdoutprv = *current->cmdoutcur;
continue;
}
skipdelimu:
c = current->cmdoutcur; p = current->cmdoutprv;
update1:
update2:
do {
*(s++) = *c;
*p = *c;