Improved consistency in coding style

This commit is contained in:
Ashish Kumar Yadav 2020-07-25 03:03:29 +05:30
parent 03d6a25af7
commit c2ab94a4dc

View file

@ -17,10 +17,10 @@
#define NOTATCMDOUTEND(block, i) (i < CMDLENGTH && block->cmdoutcur[i] != '\n' && block->cmdoutcur[i] != '\0')
typedef struct {
char *pathu;
char *pathc;
const int interval;
const int signal;
char *pathu;
char *pathc;
const int interval;
const int signal;
char cmdoutcur[CMDLENGTH];
char cmdoutprv[CMDLENGTH];
} Block;
@ -37,7 +37,7 @@ static void termhandler(int signum);
static int updatestatus();
static void writepid();
static int statusContinue = 1;
static int statuscontinue = 1;
static char statusstr[STTLENGTH];
static size_t delimlength;
static Display *dpy;
@ -45,8 +45,8 @@ static Display *dpy;
void
buttonhandler(int signal, siginfo_t *si, void *ucontext)
{
signal = si->si_value.sival_int >> 8;
switch (fork()) {
signal = si->si_value.sival_int >> 8;
switch (fork()) {
case -1:
perror("buttonhandler - fork");
exit(1);
@ -114,9 +114,9 @@ getcmd(Block *block, int sigval)
void
setroot()
{
if (updatestatus()) /* only set root if block outputs have changed */
return;
XStoreName(dpy, DefaultRootWindow(dpy), statusstr);
if (updatestatus()) /* only set root if block outputs have changed */
return;
XStoreName(dpy, DefaultRootWindow(dpy), statusstr);
XFlush(dpy);
}
@ -129,65 +129,64 @@ setupsignals()
sa.sa_flags = SA_RESTART;
/* to handle INT, HUP and TERM */
sa.sa_handler = termhandler;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
/* to ignore unused realtime signals */
sa.sa_handler = SIG_IGN;
for (int i = SIGRTMIN; i <= SIGRTMAX; i++)
sigaction(i, &sa, NULL);
/* to handle signals generated by dwm on click events */
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = buttonhandler;
sigaction(SIGRTMIN, &sa, NULL);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = buttonhandler;
sigaction(SIGRTMIN, &sa, NULL);
/* to handle update signals for individual blocks */
sa.sa_sigaction = sighandler;
for (Block *current = blocks; current->pathu; current++)
if (current->signal > 0)
sigaction(SIGRTMIN + current->signal, &sa, NULL);
for (Block *current = blocks; current->pathu; current++)
if (current->signal > 0)
sigaction(SIGRTMIN + current->signal, &sa, NULL);
/* to prevent forked children from becoming zombies */
sa.sa_flags = SA_NOCLDWAIT | SA_RESTART;
sa.sa_handler = SIG_DFL;
sa.sa_flags = SA_NOCLDWAIT | SA_RESTART;
sa.sa_handler = SIG_DFL;
sigaction(SIGCHLD, &sa, NULL);
}
void
sighandler(int signal, siginfo_t *si, void *ucontext)
{
signal -= SIGRTMIN;
for (Block *current = blocks; current->pathu; current++) {
if (current->signal == signal)
getcmd(current, si->si_value.sival_int);
}
setroot();
signal -= SIGRTMIN;
for (Block *current = blocks; current->pathu; current++)
if (current->signal == signal)
getcmd(current, si->si_value.sival_int);
setroot();
}
void
statusloop()
{
int i;
int i;
setupsignals();
setupsignals();
for (Block *current = blocks; current->pathu; current++)
if (current->interval >= 0)
getcmd(current, NILL);
setroot();
sleep(SLEEPINTERVAL);
i = SLEEPINTERVAL;
while (statusContinue) {
while (statuscontinue) {
for (Block *current = blocks; current->pathu; current++)
if (current->interval > 0 && i % current->interval == 0)
getcmd(current, NILL);
setroot();
sleep(SLEEPINTERVAL);
i += SLEEPINTERVAL;
}
setroot();
sleep(SLEEPINTERVAL);
i += SLEEPINTERVAL;
}
}
void
termhandler(int signum)
{
statusContinue = 0;
statuscontinue = 0;
}
/* returns whether block outputs have changed and updates statusstr if they have */
@ -224,7 +223,7 @@ updatestatus()
goto update2;
str += delimlength;
}
return 1;
return 1;
update0:
for (; current->pathu; current++) {
if (EMPTYCMDOUT(current)) {
@ -296,7 +295,7 @@ main(int argc, char *argv[])
fputs("Error: could not open display.\n", stderr);
return 1;
}
statusloop();
statusloop();
unlink(LOCKFILE);
XStoreName(dpy, DefaultRootWindow(dpy), "");
XCloseDisplay(dpy);