Skip to content
Snippets Groups Projects
Commit f3b7c40f authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Added --to=stdout option.

parent 2f655e73
Branches
No related tags found
No related merge requests found
......@@ -51,6 +51,8 @@ You can also add attributes to the message (written as command-line options):
--slider=p Draw a line with a slider (p=0..100)
--to=stdout Write message to stdout instead of display.
The default values of most of these attributes can be given by command-line
options of the daemon, use `osdd --help' to get the full list.
......
......@@ -178,7 +178,6 @@ display_msg(struct msg *msg)
outline_color = val;
else if (!strcmp(key, "outline-width"))
outline_width = atoi(val);
if (l)
{
l->fg_color = fg_color;
......@@ -195,6 +194,44 @@ display_msg(struct msg *msg)
osd_show(osd);
}
static void
msg_to_stdout(struct msg *msg)
{
DBG("## Printing message to stdout\n");
char *line = msg->text;
int out_parametr_index=0;
while (*line)
{
// The parser it destructive, but it does not do any harm, since we display each message only once.
char *nl = strchr(line, '\n');
*nl++ = 0;
char *key;
char *val = strchr(line, ':');
if (val)
{
key = line;
*val++ = 0;
}
else
{
key = "";
val = line;
}
DBG("\t%s:%s\n", key, val);
if (!key[0])
{
printf(out_parametr_index++?" %s":"%s",val);
}
line = nl;
}
printf("\n");
fflush(stdout);
}
static void
hide_msg(struct msg *msg)
{
......@@ -218,6 +255,45 @@ enqueue_msg(unsigned char *buf, int len)
memcpy(msg->text, buf, len);
msg->text[len] = 0;
char to[123];
*to=0;
char *line = msg->text;
while (*line)
{
char *nl = strchr(line, '\n');
*nl++=0;
char *key;
char *val = strchr(line, ':');
if (val)
{
key = line;
*val++ = 0;
}
else
{
key = "";
val = line;
}
DBG("\t%s:%s\n", key, val);
if (!strcmp(key, "to"))
{
if(strlen(val)<120)
strcpy(to,val);
}
val[-1]=':';
nl[-1]=10;
line = nl;
}
if(!strcmp(to,"stdout"))
{
msg_to_stdout(msg);
}
else
{
if (first_msg)
last_msg->next = msg;
else
......@@ -225,6 +301,7 @@ enqueue_msg(unsigned char *buf, int len)
last_msg = msg;
msg->next = NULL;
}
}
static void
parse_input(unsigned char *buf, int len)
......
......@@ -16,7 +16,7 @@ typedef uint64_t timestamp_t;
void NONRET FORMAT_CHECK(printf,1,2) die(char *fmt, ...);
#ifdef DEBUG
#define DBG(f...) printf(f)
#define DBG(f...) fprintf(stderr,f)
#else
#define DBG(f...) do { } while(0)
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment