]> mj.ucw.cz Git - osdd.git/blob - osdc.c
Let make clean delete all binaries
[osdd.git] / osdc.c
1 /*
2  *      On-screen Display Client
3  *
4  *      (c) 2010 Martin Mares <mj@ucw.cz>
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <xosd.h>
11 #include <X11/Xlib.h>
12 #include <X11/Xatom.h>
13
14 #include "util.h"
15 #include "send.h"
16
17 static struct osd_msg *msg;
18
19 static void NONRET
20 usage(void)
21 {
22   fprintf(stderr, "\
23 Usage: osdc [--<property>=<value> | <message>]*\n\
24 \n\
25 Either <value> or <message> can be `-' for standard input.\n\
26 ");
27   exit(1);
28 }
29
30 static void
31 parse_stdin(char *key)
32 {
33   char line[1024];
34   while (fgets(line, sizeof(line), stdin))
35     {
36       char *nl = strchr(line, '\n');
37       if (nl)
38         *nl = 0;
39       osd_add_line(msg, key, line);
40     }
41 }
42
43 int main(int argc, char **argv)
44 {
45   msg = osd_new_msg();
46
47   int more_opts = 1;
48   for (int i=1; i<argc; i++)
49     {
50       char *arg = argv[i];
51       if (more_opts && arg[0] == '-')
52         {
53           if (arg[1] == '-')
54             {
55               if (!arg[2])
56                 more_opts = 0;
57               else
58                 {
59                   arg += 2;
60                   if (!strcmp(arg, "help"))
61                     usage();
62                   char *sep = strchr(arg, '=');
63                   if (!sep)
64                     usage();
65                   *sep++ = 0;
66                   if (!strcmp(sep, "-"))
67                     parse_stdin(arg);
68                   else
69                     osd_add_line(msg, arg, sep);
70                 }
71             }
72           else if (!arg[1])
73             parse_stdin(NULL);
74           else
75             usage();
76         }
77       else
78         osd_add_line(msg, NULL, arg);
79     }
80
81   osd_send(msg);
82   return 0;
83 }