#include "util.h"
#include "send.h"
+static struct osd_msg *msg;
+
static void NONRET
usage(void)
{
- fprintf(stderr, "Usage: osdc [--<property>=<value> | <message>]*\n");
+ fprintf(stderr, "\
+Usage: osdc [--<property>=<value> | <message>]*\n\
+\n\
+Either <value> or <message> can be `-' for standard input.\n\
+");
exit(1);
}
+static void
+parse_stdin(char *key)
+{
+ char line[1024];
+ while (fgets(line, sizeof(line), stdin))
+ {
+ char *nl = strchr(line, '\n');
+ if (nl)
+ *nl = 0;
+ osd_add_line(msg, key, line);
+ }
+}
+
int main(int argc, char **argv)
{
- struct osd_msg *m = osd_new_msg();
+ msg = osd_new_msg();
int more_opts = 1;
for (int i=1; i<argc; i++)
{
char *arg = argv[i];
- if (more_opts && arg[0] == '-' && arg[1] == '-')
+ if (more_opts && arg[0] == '-')
{
- if (!arg[2])
- more_opts = 0;
- else
+ if (arg[1] == '-')
{
- arg += 2;
- if (!strcmp(arg, "help"))
- usage();
- char *sep = strchr(arg, '=');
- if (!sep)
- usage();
- *sep++ = 0;
- osd_add_line(m, arg, sep);
+ if (!arg[2])
+ more_opts = 0;
+ else
+ {
+ arg += 2;
+ if (!strcmp(arg, "help"))
+ usage();
+ char *sep = strchr(arg, '=');
+ if (!sep)
+ usage();
+ *sep++ = 0;
+ if (!strcmp(sep, "-"))
+ parse_stdin(arg);
+ else
+ osd_add_line(msg, arg, sep);
+ }
}
+ else if (!arg[1])
+ parse_stdin(NULL);
+ else
+ usage();
}
else
- osd_add_line(m, NULL, arg);
+ osd_add_line(msg, NULL, arg);
}
- osd_send(m);
+ osd_send(msg);
return 0;
}