Changed delimeter to accept multiple characters.

This commit is contained in:
Aidan 2019-11-04 15:34:34 -07:00
parent 690475e1e5
commit 3da92ebccb
2 changed files with 16 additions and 8 deletions

View file

@ -16,5 +16,5 @@ static const Block blocks[] = {
{"", "~/bin/statusbar/clock", 5, 0}, {"", "~/bin/statusbar/clock", 5, 0},
}; };
//sets delimeter between status commands. NULL character ('\0') means no delimeter. //sets delimeter between status commands. Empty string ("") means no delimeter.
static char delim = '|'; static char* delim = "|";

View file

@ -56,13 +56,20 @@ void getcmd(const Block *block, char *output)
return; return;
//int N = strlen(output); //int N = strlen(output);
char c; char c;
int i = strlen(block->icon); int sl;
int i = sl = strlen(block->icon);
while((c = fgetc(cmdf)) != EOF) while((c = fgetc(cmdf)) != EOF)
output[i++] = c; output[i++] = c;
if (delim != '\0' && --i)
output[i++] = delim;
output[i++] = '\0';
pclose(cmdf); pclose(cmdf);
if (i == sl) { //return empty string if command has no output
output[0] = '\0';
return;
}
if (delim[0] != '\0' && --i)
for (int j = 0; delim[j]; j++)
output[i++] = delim[j];
else
output[--i] = '\0';
} }
void getcmds(int time) void getcmds(int time)
@ -104,6 +111,7 @@ void getstatus(char *str)
{ {
strcpy(str + j, statusbar[i]); strcpy(str + j, statusbar[i]);
} }
for (int i = 0; delim[i]; i++)
str[--j] = '\0'; str[--j] = '\0';
} }
@ -159,7 +167,7 @@ int main(int argc, char** argv)
for(int i = 0; i < argc; i++) for(int i = 0; i < argc; i++)
{ {
if (!strcmp("-d",argv[i])) if (!strcmp("-d",argv[i]))
delim = argv[++i][0]; delim = argv[++i];
} }
signal(SIGTERM, termhandler); signal(SIGTERM, termhandler);
signal(SIGINT, termhandler); signal(SIGINT, termhandler);