Improved signal and sigval parser - sigdwmblocks

This commit is contained in:
Ashish Kumar Yadav 2020-12-25 00:53:39 +05:30
parent 0199791215
commit 8677376b08

View file

@ -11,36 +11,37 @@
#define LOCKFILE "/tmp/dwmblocks.pid" #define LOCKFILE "/tmp/dwmblocks.pid"
int int
parsesignal(char *c, int *s) parsesignal(char *arg, int *s)
{ {
for (*s = 0; *c != '\0'; c++) int i = 0;
if (*c >= '0' && *c <= '9') {
*s *= 10; for (; *arg != '\0'; arg++)
*s += *c - '0'; if (*arg >= '0' && *arg <= '9')
} else i = 10 * i + *arg - '0';
else
return 0; return 0;
if ((*s += SIGRTMIN) > SIGRTMAX) if ((i += SIGRTMIN) > SIGRTMAX)
return 0; return 0;
*s = i;
return 1; return 1;
} }
int int
parsesigval(char *c, int *v) parsesigval(char *arg, int *v)
{ {
int s = 1; int s = 1, i = 0;
if (*c == '-') { if (*arg == '-') {
s = -1; s = -1;
c++; arg++;
} else if (*c == '+') } else if (*arg == '+')
c++; arg++;
for (*v = 0; *c != '\0'; c++) for (; *arg != '\0'; arg++)
if (*c >= '0' && *c <= '9') { if (*arg >= '0' && *arg <= '9')
*v *= 10; i = 10 * i + *arg - '0';
*v += *c - '0'; else
} else
return 0; return 0;
*v *= s; *v = s * i;
return 1; return 1;
} }