]> mj.ucw.cz Git - osdd.git/blob - osdc.c
Merge branch 'master' of ssh://git.ucw.cz/home/mj/GIT/osdd
[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 "osd.h"
15
16 static struct osd_msg *msg;
17
18 static void NONRET
19 usage(void)
20 {
21   fprintf(stderr, "\
22 Usage: osdc [--<property>=<value> | <message>]*\n\
23 \n\
24 Either <value> or <message> can be `-' for standard input.\n\
25 ");
26   exit(1);
27 }
28
29 static void
30 parse_stdin(char *key)
31 {
32   char line[1024];
33   while (fgets(line, sizeof(line), stdin))
34     {
35       char *nl = strchr(line, '\n');
36       if (nl)
37         *nl = 0;
38       osd_add_line(msg, key, line);
39     }
40 }
41
42 int main(int argc, char **argv)
43 {
44   msg = osd_new_msg();
45
46   int more_opts = 1;
47   for (int i=1; i<argc; i++)
48     {
49       char *arg = argv[i];
50       if (more_opts && arg[0] == '-')
51         {
52           if (arg[1] == '-')
53             {
54               if (!arg[2])
55                 more_opts = 0;
56               else
57                 {
58                   arg += 2;
59                   if (!strcmp(arg, "help"))
60                     usage();
61                   char *sep = strchr(arg, '=');
62                   if (!sep)
63                     usage();
64                   *sep++ = 0;
65                   if (!strcmp(sep, "-"))
66                     parse_stdin(arg);
67                   else
68                     osd_add_line(msg, arg, sep);
69                 }
70             }
71           else if (!arg[1])
72             parse_stdin(NULL);
73           else
74             usage();
75         }
76       else
77         osd_add_line(msg, NULL, arg);
78     }
79
80   osd_send(msg);
81   return 0;
82 }