comparison lcdemu/main.c @ 903:312778104f54

lcdemu started, compiles and runs w/o actual functionality
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 07 Sep 2015 08:34:37 +0000
parents
children 69623c4cbf6c
comparison
equal deleted inserted replaced
902:4423039aeb4b 903:312778104f54
1 /*
2 * LCDemu main module
3 */
4
5 #include <sys/types.h>
6 #include <sys/errno.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <X11/Xlib.h>
12 #include <X11/Xresource.h>
13 #include <X11/Xutil.h>
14 #include "globals.h"
15
16 main(argc, argv)
17 char **argv;
18 {
19 XrmInitialize();
20 process_cmdline(argc, argv);
21 open_display();
22 load_resources();
23 create_our_window();
24 set_initial_window_title();
25 set_initial_icon_name();
26 create_mainwin_gc();
27 XMapWindow(mydisplay, mainwindow);
28 XFlush(mydisplay);
29
30 mainloop();
31 /* NOTREACHED */
32 }
33
34 process_cmdline(argc, argv)
35 char **argv;
36 {
37 register char **ap, *opt;
38 char *rhost, *ruser;
39 int len;
40
41 if (argc < 1) {
42 fprintf(stderr, "fc-lcdemu: invalid invokation\n");
43 exit(1);
44 }
45 opt = rindex(argv[0], '/');
46 if (opt)
47 progbasename = opt + 1;
48 else
49 progbasename = argv[0];
50 proginstancename = progbasename;
51 for (ap = argv+1; *ap; ) {
52 if (**ap == '-')
53 opt = *ap++;
54 else
55 break;
56 if (!strcmp(opt, "-display")) {
57 if (!*ap) {
58 argreq: fprintf(stderr, "%s: %s requires an argument\n",
59 progbasename, opt);
60 exit(1);
61 }
62 mydisplayname = *ap++;
63 continue;
64 }
65 if (!strcmp(opt, "-name")) {
66 if (!*ap)
67 goto argreq;
68 proginstancename = *ap++;
69 continue;
70 }
71 if (!strcmp(opt, "-geometry") || !strcmp(opt, "-geom")) {
72 if (!*ap)
73 goto argreq;
74 XrmPutStringResource(&xrmdb_cmdline, "LCDemu.geometry",
75 *ap++);
76 continue;
77 }
78 if (!strcmp(opt, "-iconic")) {
79 XrmPutStringResource(&xrmdb_cmdline, "LCDemu.iconic",
80 "on");
81 continue;
82 }
83 if (!strcmp(opt, "-title")) {
84 if (!*ap)
85 goto argreq;
86 XrmPutStringResource(&xrmdb_cmdline, "LCDemu.title",
87 *ap++);
88 continue;
89 }
90 if (!strcmp(opt, "-borderwidth") || !strcmp(opt, "-bw")) {
91 if (!*ap)
92 goto argreq;
93 XrmPutStringResource(&xrmdb_cmdline, "*borderWidth",
94 *ap++);
95 continue;
96 }
97 if (!strcmp(opt, "-bordercolor") || !strcmp(opt, "-bd")) {
98 if (!*ap)
99 goto argreq;
100 XrmPutStringResource(&xrmdb_cmdline, "*borderColor",
101 *ap++);
102 continue;
103 }
104 if (!strcmp(opt, "-xrm")) {
105 if (!*ap)
106 goto argreq;
107 XrmPutLineResource(&xrmdb_cmdline, *ap++);
108 continue;
109 }
110 fprintf(stderr, "%s: %s: unrecognized option\n", progbasename,
111 opt);
112 exit(1);
113 }
114 }
115
116 open_display()
117 {
118 if (!mydisplayname)
119 mydisplayname = getenv("DISPLAY");
120 if (!mydisplayname) {
121 fprintf(stderr, "%s: no X display available\n", progbasename);
122 exit(1);
123 }
124 mydisplay = XOpenDisplay(mydisplayname);
125 if (!mydisplay) {
126 fprintf(stderr, "%s: unable to open display %s\n", progbasename,
127 mydisplayname);
128 exit(1);
129 }
130 }
131
132 mainloop()
133 {
134 register int i, cc;
135 XEvent event;
136 fd_set readfds;
137 int maxfd;
138 char buf[1024];
139
140 maxfd = ConnectionNumber(mydisplay) + 1;
141 for (;;) {
142 cc = XPending(mydisplay);
143 for (i = 0; i < cc; i++)
144 XNextEvent(mydisplay, &event);
145 XFlush(mydisplay);
146 FD_ZERO(&readfds);
147 FD_SET(0, &readfds);
148 FD_SET(ConnectionNumber(mydisplay), &readfds);
149 i = select(maxfd, &readfds, NULL, NULL, NULL);
150 if (i < 0) {
151 if (errno == EINTR)
152 continue;
153 perror("select");
154 exit(1);
155 }
156 if (FD_ISSET(0, &readfds)) {
157 cc = read(0, buf, sizeof buf);
158 if (cc > 0)
159 input_on_stdin(buf, cc);
160 else
161 exit(0);
162 XFlush(mydisplay);
163 }
164 }
165 }