FreeCalypso > hg > freecalypso-ui-dev
comparison lcdemu/main.c @ 0:e7f1035f10d4
lcdemu: initial import from freecalypso-tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 14 Mar 2018 18:16:45 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7f1035f10d4 |
---|---|
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 init_image_conversion(); | |
23 load_resources(); | |
24 create_our_window(); | |
25 set_initial_window_title(); | |
26 set_initial_icon_name(); | |
27 create_mainwin_gc(); | |
28 XMapWindow(mydisplay, mainwindow); | |
29 XFlush(mydisplay); | |
30 | |
31 mainloop(); | |
32 /* NOTREACHED */ | |
33 } | |
34 | |
35 process_cmdline(argc, argv) | |
36 char **argv; | |
37 { | |
38 register char **ap, *opt; | |
39 char *rhost, *ruser; | |
40 int len; | |
41 | |
42 if (argc < 1) { | |
43 fprintf(stderr, "fc-lcdemu: invalid invokation\n"); | |
44 exit(1); | |
45 } | |
46 opt = rindex(argv[0], '/'); | |
47 if (opt) | |
48 progbasename = opt + 1; | |
49 else | |
50 progbasename = argv[0]; | |
51 proginstancename = progbasename; | |
52 for (ap = argv+1; *ap; ) { | |
53 if (**ap == '-') | |
54 opt = *ap++; | |
55 else | |
56 break; | |
57 if (!strcmp(opt, "-display")) { | |
58 if (!*ap) { | |
59 argreq: fprintf(stderr, "%s: %s requires an argument\n", | |
60 progbasename, opt); | |
61 exit(1); | |
62 } | |
63 mydisplayname = *ap++; | |
64 continue; | |
65 } | |
66 if (!strcmp(opt, "-name")) { | |
67 if (!*ap) | |
68 goto argreq; | |
69 proginstancename = *ap++; | |
70 continue; | |
71 } | |
72 if (!strcmp(opt, "-geometry") || !strcmp(opt, "-geom")) { | |
73 if (!*ap) | |
74 goto argreq; | |
75 XrmPutStringResource(&xrmdb_cmdline, "LCDemu.geometry", | |
76 *ap++); | |
77 continue; | |
78 } | |
79 if (!strcmp(opt, "-iconic")) { | |
80 XrmPutStringResource(&xrmdb_cmdline, "LCDemu.iconic", | |
81 "on"); | |
82 continue; | |
83 } | |
84 if (!strcmp(opt, "-title")) { | |
85 if (!*ap) | |
86 goto argreq; | |
87 XrmPutStringResource(&xrmdb_cmdline, "LCDemu.title", | |
88 *ap++); | |
89 continue; | |
90 } | |
91 if (!strcmp(opt, "-borderwidth") || !strcmp(opt, "-bw")) { | |
92 if (!*ap) | |
93 goto argreq; | |
94 XrmPutStringResource(&xrmdb_cmdline, "*borderWidth", | |
95 *ap++); | |
96 continue; | |
97 } | |
98 if (!strcmp(opt, "-bordercolor") || !strcmp(opt, "-bd")) { | |
99 if (!*ap) | |
100 goto argreq; | |
101 XrmPutStringResource(&xrmdb_cmdline, "*borderColor", | |
102 *ap++); | |
103 continue; | |
104 } | |
105 if (!strcmp(opt, "-xrm")) { | |
106 if (!*ap) | |
107 goto argreq; | |
108 XrmPutLineResource(&xrmdb_cmdline, *ap++); | |
109 continue; | |
110 } | |
111 fprintf(stderr, "%s: %s: unrecognized option\n", progbasename, | |
112 opt); | |
113 exit(1); | |
114 } | |
115 } | |
116 | |
117 open_display() | |
118 { | |
119 if (!mydisplayname) | |
120 mydisplayname = getenv("DISPLAY"); | |
121 if (!mydisplayname) { | |
122 fprintf(stderr, "%s: no X display available\n", progbasename); | |
123 exit(1); | |
124 } | |
125 mydisplay = XOpenDisplay(mydisplayname); | |
126 if (!mydisplay) { | |
127 fprintf(stderr, "%s: unable to open display %s\n", progbasename, | |
128 mydisplayname); | |
129 exit(1); | |
130 } | |
131 } | |
132 | |
133 mainloop() | |
134 { | |
135 register int i, cc; | |
136 XEvent event; | |
137 fd_set readfds; | |
138 int maxfd; | |
139 char buf[1024]; | |
140 | |
141 maxfd = ConnectionNumber(mydisplay) + 1; | |
142 for (;;) { | |
143 cc = XPending(mydisplay); | |
144 for (i = 0; i < cc; i++) | |
145 XNextEvent(mydisplay, &event); | |
146 XFlush(mydisplay); | |
147 FD_ZERO(&readfds); | |
148 FD_SET(0, &readfds); | |
149 FD_SET(ConnectionNumber(mydisplay), &readfds); | |
150 i = select(maxfd, &readfds, NULL, NULL, NULL); | |
151 if (i < 0) { | |
152 if (errno == EINTR) | |
153 continue; | |
154 perror("select"); | |
155 exit(1); | |
156 } | |
157 if (FD_ISSET(0, &readfds)) { | |
158 cc = read(0, buf, sizeof buf); | |
159 if (cc > 0) | |
160 input_on_stdin(buf, cc); | |
161 else | |
162 exit(0); | |
163 XFlush(mydisplay); | |
164 } | |
165 } | |
166 } |