]>
Commit | Line | Data |
---|---|---|
4b8c099c PZ |
1 | --- bogl/bogl-bgf.c.rh 2001-12-01 18:04:42.000000000 +0100 |
2 | +++ bogl/bogl-bgf.c 2005-03-04 20:26:28.390051760 +0100 | |
3 | @@ -1,44 +1,129 @@ | |
4 | - | |
5 | -#include <fcntl.h> | |
6 | +#include <errno.h> | |
7 | +#include <stddef.h> | |
8 | +#include <stdio.h> | |
9 | +#include <stdlib.h> | |
10 | #include <string.h> | |
11 | -#include <sys/mman.h> | |
12 | -#include <sys/stat.h> | |
13 | -#include <sys/types.h> | |
14 | -#include <unistd.h> | |
15 | +#include <zlib.h> | |
16 | +#include <stdint.h> | |
17 | ||
18 | +#include "bogl-bgf.h" | |
19 | #include "bogl.h" | |
20 | -#include "bogl-font.h" | |
21 | ||
22 | -struct bogl_font *bogl_mmap_font(char *file) | |
23 | -{ | |
24 | - int fd; | |
25 | - struct stat buf; | |
26 | - void *f; | |
27 | - struct bogl_font *font; | |
28 | - | |
29 | - fd = open(file, O_RDONLY); | |
30 | - if (fd == -1) | |
31 | - return 0; | |
32 | - | |
33 | - if (fstat(fd, &buf)) | |
34 | - return 0; | |
35 | - | |
36 | - f = mmap(0, buf.st_size, PROT_READ, MAP_SHARED, fd, 0); | |
37 | - if (f == (void *)-1) | |
38 | - return 0; | |
39 | - | |
40 | - if (memcmp("BGF1", f, 4)) | |
41 | - return 0; | |
42 | - | |
43 | - font = (struct bogl_font *)malloc(sizeof(struct bogl_font)); | |
44 | - if (!font) | |
45 | - return 0; | |
46 | - | |
47 | - memcpy(font, f + 4, sizeof(*font)); | |
48 | - font->name = ((void *)font->name - (void *)0) + f; | |
49 | - font->offset = ((void *)font->offset - (void *)0) + f; | |
50 | - font->index = ((void *)font->index - (void *)0) + f; | |
51 | - font->content = ((void *)font->content - (void *)0) + f; | |
52 | +#define FONT_SIGNATURE "BGF1" | |
53 | + | |
54 | +static size_t get_gz_file_size(const char *path) { | |
55 | + size_t size = 0; | |
56 | + unsigned char buffer[4] = { 0 }; | |
57 | + FILE *stream = NULL; | |
58 | + | |
59 | + stream = fopen(path, "rb"); | |
60 | + if (stream == NULL) { | |
61 | + perror(path); | |
62 | + return -1; | |
63 | + } | |
64 | + if (fread(buffer, sizeof(char), 2, stream) != 2) { | |
65 | + if (ferror(stream)) { | |
66 | + perror(path); | |
67 | + return -1; | |
68 | + } | |
69 | + } | |
70 | + if (memcmp(buffer, "\037\213", 2) == 0) { | |
71 | + uint32_t isize = 0; | |
72 | + | |
73 | + if (fseek(stream, -4L, SEEK_END) == EOF) { | |
74 | + perror(path); | |
75 | + return -1; | |
76 | + } | |
77 | + if (fread(buffer, sizeof(char), (size_t) 4, stream) != 4) { | |
78 | + if (ferror(stream)) { | |
79 | + perror(path); | |
80 | + return -1; | |
81 | + } | |
82 | + else { | |
83 | + fprintf(stderr, "%s: invalid gzip file\n", path); | |
84 | + return -1; | |
85 | + } | |
86 | + } | |
87 | + isize = buffer[0]; | |
88 | + isize |= buffer[1] << 8; | |
89 | + isize |= buffer[2] << 16; | |
90 | + isize |= buffer[3] << 24; | |
91 | + | |
92 | + /* FIXME: ISIZE is not a reliable indicator of size for files >4GB. | |
93 | + * On the other hand, if you have a font >4GB, you've got issues. | |
94 | + */ | |
95 | + size = (size_t) isize; | |
96 | + } | |
97 | + else { | |
98 | + if (fseek(stream, 0L, SEEK_END) == EOF) { | |
99 | + perror(path); | |
100 | + return -1; | |
101 | + } | |
102 | + if ((int) (size = (size_t) ftell(stream)) == EOF) { | |
103 | + perror(path); | |
104 | + return -1; | |
105 | + } | |
106 | + } | |
107 | + if (fclose(stream) == EOF) { | |
108 | + perror(path); | |
109 | + return -1; | |
110 | + } | |
111 | + return size; | |
112 | +} | |
113 | ||
114 | - return font; | |
115 | +struct bogl_font *bogl_load_font(const char *path) { | |
116 | + size_t size; | |
117 | + int errnum; | |
118 | + gzFile file; | |
119 | + void *bgf; | |
120 | + struct bogl_font *font; | |
121 | + | |
122 | + size = (size_t) get_gz_file_size(path); | |
123 | + if (size == (size_t) -1) | |
124 | + return NULL; | |
125 | + if ((bgf = malloc(size)) == NULL) { | |
126 | + perror(path); | |
127 | + return NULL; | |
128 | + } | |
129 | + file = gzopen(path, "rb"); | |
130 | + if (file == NULL) { | |
131 | + if (errno == 0) { | |
132 | + errno = ENOMEM; // if 0 then zlib error == Z_MEM_ERROR | |
133 | + } | |
134 | + perror(path); | |
135 | + return NULL; | |
136 | + } | |
137 | + if (gzread(file, bgf, size) == -1) { | |
138 | + const char *msg = gzerror(file, &errnum); | |
139 | + | |
140 | + if (errnum == Z_ERRNO) { | |
141 | + msg = strerror(errno); | |
142 | + } | |
143 | + fprintf(stderr, "%s: %s\n", path, msg); | |
144 | + return NULL; | |
145 | + } | |
146 | + if (gzclose(file) < 0) { | |
147 | + const char *msg = gzerror(file, &errnum); | |
148 | + | |
149 | + if (errnum == Z_ERRNO) { | |
150 | + msg = strerror(errno); | |
151 | + } | |
152 | + fprintf(stderr, "%s: %s\n", path, msg); | |
153 | + return NULL; | |
154 | + } | |
155 | + if (memcmp(FONT_SIGNATURE, bgf, strlen(FONT_SIGNATURE)) != 0) { | |
156 | + fprintf(stderr, "%s: not a BGF font\n", path); | |
157 | + return NULL; | |
158 | + } | |
159 | + font = (struct bogl_font *) malloc(sizeof(struct bogl_font)); | |
160 | + if (font == NULL) { | |
161 | + perror(path); | |
162 | + return NULL; | |
163 | + } | |
164 | + memcpy(font, bgf + strlen(FONT_SIGNATURE), sizeof(struct bogl_font)); | |
165 | + font->name = bgf + (ptrdiff_t) font->name; | |
166 | + font->offset = bgf + (ptrdiff_t) font->offset; | |
167 | + font->index = bgf + (ptrdiff_t) font->index; | |
168 | + font->content = bgf + (ptrdiff_t) font->content; | |
169 | + return font; | |
170 | } | |
171 | --- bogl/bterm.c.rh 2004-05-06 04:57:06.000000000 +0200 | |
172 | +++ bogl/bterm.c 2005-03-04 20:26:28.397050696 +0100 | |
173 | @@ -64,6 +64,7 @@ | |
174 | ||
175 | static int child_pid = 0; | |
176 | static struct termios ttysave; | |
177 | +static int spawn = 0; | |
178 | ||
179 | /* This first tries the modern Unix98 way of getting a pty, followed by the | |
180 | * old-fashioned BSD way in case that fails. */ | |
181 | @@ -123,15 +124,61 @@ | |
182 | ||
183 | void sigchld(int sig) | |
184 | { | |
185 | - if (wait(0) == child_pid) { | |
186 | + int status; | |
187 | + if (wait(&status) == child_pid) { | |
188 | child_pid = 0; | |
189 | /* Reset ownership and permissions of ttyfd device? */ | |
190 | +#ifdef DIET | |
191 | + bogl_done(); | |
192 | +#endif | |
193 | tcsetattr(0, TCSAFLUSH, &ttysave); | |
194 | - exit(0); | |
195 | + /* exit with the same status as the child so that if our child | |
196 | + * exits uncleanly, causing bogl to exit and we want to be able | |
197 | + * to know how the child exited */ | |
198 | + if (WIFEXITED(status)) | |
199 | + exit(0); | |
200 | + else | |
201 | + exit(WEXITSTATUS(status)); | |
202 | } | |
203 | signal(SIGCHLD, sigchld); | |
204 | } | |
205 | ||
206 | +/* return 0 if parent, 1 if child */ | |
207 | +int spawn_child(int ptyfd, int ttyfd) | |
208 | +{ | |
209 | + fflush(stdout); | |
210 | + child_pid = fork(); | |
211 | + if (child_pid) { | |
212 | + /* Change ownership and permissions of ttyfd device! */ | |
213 | + signal(SIGCHLD, sigchld); | |
214 | + return 0; | |
215 | + } | |
216 | + setenv("TERM", "bterm", 1); | |
217 | + | |
218 | + sleep(1); | |
219 | + close(ptyfd); | |
220 | + | |
221 | + dup2(ttyfd, 0); | |
222 | + dup2(ttyfd, 1); | |
223 | + dup2(ttyfd, 2); | |
224 | + | |
225 | + bogl_close(); | |
226 | + | |
227 | + if (ttyfd > 2) | |
228 | + close(ttyfd); | |
229 | + | |
230 | + setgid(getgid()); | |
231 | + setuid(getuid()); | |
232 | + | |
233 | + setsid(); | |
234 | + if (ioctl(0, TIOCSCTTY, (char *)0)) { | |
235 | + perror("Unable to set a new controlling tty: "); | |
236 | + } | |
237 | + | |
238 | + return 1; | |
239 | +} | |
240 | + | |
241 | + | |
242 | void spawn_shell(int ptyfd, int ttyfd, const char *command) | |
243 | { | |
244 | fflush(stdout); | |
245 | @@ -151,9 +198,11 @@ | |
246 | dup2(ttyfd, 0); | |
247 | dup2(ttyfd, 1); | |
248 | dup2(ttyfd, 2); | |
249 | + | |
250 | if (ttyfd > 2) | |
251 | close(ttyfd); | |
252 | tcsetattr(0, TCSANOW, &ttysave); | |
253 | + | |
254 | setgid(getgid()); | |
255 | setuid(getuid()); | |
256 | ||
257 | @@ -172,14 +221,14 @@ | |
258 | ioctl(ttyfd, TIOCSWINSZ, &win); | |
259 | } | |
260 | ||
261 | -static char *font_name; | |
262 | +static char *font_name = "/usr/lib/bogl/font.bgf.gz"; | |
263 | static struct bogl_term *term; | |
264 | ||
265 | void reload_font(int sig) | |
266 | { | |
267 | struct bogl_font *font; | |
268 | ||
269 | - font = bogl_mmap_font (font_name); | |
270 | + font = bogl_load_font (font_name); | |
271 | if (font == NULL) | |
272 | { | |
273 | fprintf(stderr, "Bad font\n"); | |
274 | @@ -224,6 +273,10 @@ | |
275 | o = argv[i][1]; | |
276 | break; | |
277 | ||
278 | + case 's': | |
279 | + spawn = 1; | |
280 | + break; | |
281 | + | |
282 | default: | |
283 | printf ("unknown option: %c\n", argv[i][1]); | |
284 | } | |
285 | @@ -253,7 +306,7 @@ | |
286 | return 1; | |
287 | } | |
288 | ||
289 | - if ((font = bogl_mmap_font(font_name)) == NULL) { | |
290 | + if ((font = bogl_load_font(font_name)) == NULL) { | |
291 | fprintf(stderr, "Bad font\n"); | |
292 | return 1; | |
293 | } | |
294 | @@ -267,7 +320,7 @@ | |
295 | ||
296 | term = bogl_term_new(font); | |
297 | if (!term) | |
298 | - exit(1); | |
299 | + return 1; | |
300 | ||
301 | bogl_set_palette(0, 16, palette); | |
302 | ||
303 | @@ -278,7 +331,11 @@ | |
304 | exit(1); | |
305 | } | |
306 | ||
307 | - spawn_shell(ptyfd, ttyfd, command == NULL ? "/bin/sh" : command); | |
308 | + if (spawn) { | |
309 | + if (spawn_child(ptyfd, ttyfd)) | |
310 | + return 0; | |
311 | + } else | |
312 | + spawn_shell(ptyfd, ttyfd, command == NULL ? "/bin/sh" : command); | |
313 | ||
314 | signal(SIGHUP, reload_font); | |
315 | ||
316 | @@ -290,7 +347,7 @@ | |
317 | ntio.c_cc[VTIME] = 0; | |
318 | ntio.c_cflag |= CS8; | |
319 | ntio.c_line = 0; | |
320 | - tcsetattr(0, TCSAFLUSH, &ntio); | |
321 | + tcsetattr(0, TCSANOW, &ntio); | |
322 | ||
323 | set_window_size(ttyfd, term->xsize, term->ysize); | |
324 | ||
325 | --- bogl/Makefile.rh 2003-10-05 19:47:03.000000000 +0200 | |
326 | +++ bogl/Makefile 2005-03-04 20:26:28.388052064 +0100 | |
327 | @@ -4,12 +4,23 @@ | |
328 | SONAME = libbogl.so.0 | |
329 | SHARED_LIB = libbogl.so.0.1 | |
330 | ||
331 | +libdir = /usr/lib | |
332 | + | |
333 | +#architecture := $(shell dpkg-architecture -qDEB_BUILD_GNU_CPU) | |
334 | +architecture := $(patsubst i%86,i386,$(shell uname -m)) | |
335 | + | |
336 | +ifeq ($(architecture), none) | |
337 | +USEDIET := 1 | |
338 | +DIETCC = diet gcc | |
339 | +else | |
340 | +USEDIET := 0 | |
341 | +DIETCC = gcc | |
342 | +endif | |
343 | + | |
344 | CFLAGS = -O2 -g -D_GNU_SOURCE | |
345 | WARNCFLAGS += -Wall -D_GNU_SOURCE | |
346 | ALLCFLAGS = $(CFLAGS) $(WARNCFLAGS) $(FBCFLAGS) | |
347 | ||
348 | -architecture := $(shell dpkg-architecture -qDEB_BUILD_GNU_CPU) | |
349 | - | |
350 | LIBOBJECTS = $(LIBBOGLOBJECTS) $(LIBBOMLOBJECTS) $(LIBBOWLOBJECTS) \ | |
351 | $(LIBRSRCOBJECTS) | |
352 | LIBBOGLOBJECTS = bogl.o bogl-font.o | |
353 | @@ -17,6 +28,19 @@ | |
354 | LIBBOWLOBJECTS = bowl.o symbol.o | |
355 | LIBRSRCOBJECTS = helvB10.o helvB12.o helvR10.o timBI18.o tux75.o | |
356 | ||
357 | +LIBBTERM = libbterm.a | |
358 | +LIBBTERMOBJECTS = bterm-lib.o bogl-term.o bogl-bgf.o | |
359 | + | |
360 | +ifeq ($(USEDIET), 1) | |
361 | +LIBBTERMDIET = libbtermdiet.a | |
362 | +LIBBTERMDOBJS = $(patsubst %.o,%.do,$(LIBBTERMOBJECTS)) | |
363 | + | |
364 | +LIBBOGLDIET = libbogldiet.a | |
365 | +LIBBOGLDOBJS = $(patsubst %.o,%.do,$(LIBOBJECTS)) | |
366 | + | |
367 | +BTERMDIET = bterm-diet | |
368 | +endif | |
369 | + | |
370 | SOURCES_DEP = arrow.c bdftobogl.c bogl-cfb.c bogl-cfb.h bogl-cfb8.c \ | |
371 | bogl-cfb8.h bogl-font.c bogl-font.h bogl-pcfb.c bogl-pcfb.h \ | |
372 | bogl-tcfb.c bogl-tcfb.h bogl-test.c bogl.c bogl.h boglP.h boml.c \ | |
373 | @@ -38,7 +62,7 @@ | |
374 | GENERATED = helvB10.c helvB12.c helvR10.c timBI18.c tux75.c | |
375 | ||
376 | # libutf8/libutf8_plug.so unifont-reduced.bgf | |
377 | -all: depend $(SHARED_LIB) $(LIB) bterm bdftobogl reduce-font | |
378 | +all: depend subdirs $(SHARED_LIB) $(LIB) bterm bdftobogl reduce-font $(LIBBTERM) $(LIBBTERMDIET) $(LIBBOGLDIET) $(BTERMDIET) | |
379 | ||
380 | %.lo: %.c | |
381 | $(CC) $(ALLCFLAGS) -o $@ -fPIC -c $< | |
382 | @@ -46,6 +70,16 @@ | |
383 | %.o: %.c | |
384 | $(CC) $(ALLCFLAGS) -o $@ -c $< | |
385 | ||
386 | +subdirs: | |
387 | + cd wlite;\ | |
388 | + make SMALL=1 CC="$(DIETCC)" | |
389 | +ifeq ($(USEDIET), 1) | |
390 | + cd wlite;\ | |
391 | + mv libwlite.a libwlitediet.a;\ | |
392 | + make distclean;\ | |
393 | + make SMALL=1 CC="gcc" | |
394 | +endif | |
395 | + | |
396 | $(SHARED_LIB): $(OBJECTS:%.o=%.lo) | |
397 | $(CC) -shared -Wl,-soname,$(SONAME) -o $(SHARED_LIB) $(OBJECTS:%.o=%.lo) | |
398 | ||
399 | @@ -68,9 +102,36 @@ | |
400 | ||
401 | reduce-font: reduce-font.c | |
402 | ||
403 | +bterm-lib.o: bterm.c | |
404 | + $(CC) $(ALLCFLAGS) -o $@ -c -Dmain=bterm_main $< | |
405 | + | |
406 | +bterm-lib.do: bterm.c | |
407 | + diet $(CC) $(ALLCFLAGS) -DDIET -o $@ -c -Dmain=bterm_main $< | |
408 | + | |
409 | +ifeq ($(architecture), i386) | |
410 | + DFBCFLAGS := -DBOGL_VGA16_FB=1 -DDIET | |
411 | +else | |
412 | + DFBCFLAGS := $(FBCFLAGS) -DDIET | |
413 | +endif | |
414 | + | |
415 | +%.do: %.c | |
416 | + diet $(CC) $(DFBCFLAGS) -c $(CFLAGS) -o $@ $< | |
417 | + | |
418 | +$(LIBBTERM): $(LIBBTERMOBJECTS) | |
419 | + rm -f $@ | |
420 | + ar rcs $@ $^ | |
421 | + | |
422 | +$(LIBBTERMDIET): $(LIBBTERMDOBJS) | |
423 | + rm -f $@ | |
424 | + ar rcs $@ $^ | |
425 | + | |
426 | $(LIB): $(OBJECTS) | |
427 | - rm -f $(LIB) | |
428 | - ar rcs $(LIB) $(OBJECTS) | |
429 | + rm -f $@ | |
430 | + ar rcs $@ $^ | |
431 | + | |
432 | +$(LIBBOGLDIET): $(LIBBOGLDOBJS) | |
433 | + rm -f $@ | |
434 | + ar rcs $@ $^ | |
435 | ||
436 | bogl-test: $(LIB) bogl-test.c tux75.o | |
437 | $(CC) $(ALLCFLAGS) -o bogl-test bogl-test.c tux75.o $(LIB) | |
438 | @@ -79,9 +140,14 @@ | |
439 | $(CC) -DSTANDALONE_TEST $(ALLCFLAGS) bowl-boxes.c $(LIBOBJECTS) -o bowl-boxes | |
440 | ||
441 | bterm: $(LIB) bterm.o bogl-term.o bogl-bgf.o | |
442 | - $(CC) $+ $(LIB) -o bterm | |
443 | + $(CC) $+ $(LIB) -lz -o bterm wlite/libwlite.a | |
444 | + | |
445 | +bterm-diet: $(LIBBOGLDIET) $(LIBBTERMDIET) bterm-diet.c | |
446 | + diet $(CC) -g bterm-diet.c $(LIBBTERMDIET) $(LIBBOGLDIET) wlite/libwlite.a -lz -o $@ | |
447 | ||
448 | bdftobogl: $(LIBBOGLOBJECTS) | |
449 | + $(CC) $(ALLCFLAGS) -o $@ bdftobogl.c $^ wlite/libwlite.a | |
450 | + | |
451 | %.c: %.bdf bdftobogl | |
452 | ./bdftobogl $< > $@ | |
453 | ||
454 | @@ -98,9 +164,11 @@ | |
455 | rm -rf reduce-font bterm bdftobogl pngtobogl *.o $(GENERATED) *-test lang.h tmp.*.c bowl-boxes $(LIB) unifont-reduced.bgf unifont-reduced.bdf | |
456 | rm -f $(OBJECTS:%.o=%.lo) $(SHARED_LIB) | |
457 | rm -f .depend | |
458 | + cd wlite; make clean | |
459 | ||
460 | distclean: clean | |
461 | rm -f $(LIB) .depend *~ .nfs* | |
462 | + cd wlite; make distclean | |
463 | ||
464 | force: | |
465 | ||
466 | @@ -108,12 +176,14 @@ | |
467 | include .depend | |
468 | endif | |
469 | ||
470 | +INSTLIBS = $(LIB) $(LIBBTERM) $(LIBBTERMDIET) $(LIBBOGLDIET) | |
471 | + | |
472 | install: all | |
473 | - install -d $(DESTDIR)/usr/lib $(DESTDIR)/usr/include/bogl $(DESTDIR)/usr/bin | |
474 | - install -m644 $(SHARED_LIB) $(DESTDIR)/usr/lib/$(SHARED_LIB) | |
475 | - ln -s $(SHARED_LIB) $(DESTDIR)/usr/lib/$(DEVLINK) | |
476 | - ln -s $(SHARED_LIB) $(DESTDIR)/usr/lib/$(SONAME) | |
477 | - install -m644 $(LIB) $(DESTDIR)/usr/lib/$(LIB) | |
478 | + install -d $(DESTDIR)/$(libdir) $(DESTDIR)/usr/include/bogl $(DESTDIR)/usr/bin | |
479 | + install -m644 $(SHARED_LIB) $(DESTDIR)/$(libdir)/$(SHARED_LIB) | |
480 | + ln -sf $(SHARED_LIB) $(DESTDIR)/$(libdir)/$(DEVLINK) | |
481 | + ln -sf $(SHARED_LIB) $(DESTDIR)/$(libdir)/$(SONAME) | |
482 | + install -m644 $(INSTLIBS) $(DESTDIR)/$(libdir) | |
483 | install -m644 *.h $(DESTDIR)/usr/include/bogl | |
484 | install -m755 bdftobogl mergebdf bterm pngtobogl reduce-font $(DESTDIR)/usr/bin | |
485 | install -d $(DESTDIR)/usr/share/terminfo | |
486 | --- bogl/reduce-font.c.rh 2001-12-01 18:04:42.000000000 +0100 | |
487 | +++ bogl/reduce-font.c 2005-03-04 20:26:28.398050544 +0100 | |
488 | @@ -42,12 +42,31 @@ | |
489 | printf (": %d\n", l); | |
490 | } | |
491 | ||
492 | +char * | |
493 | +cat_line(char *sofar, const char *line) { | |
494 | + char *buf; | |
495 | + size_t length; | |
496 | + | |
497 | + length = sofar == NULL ? 0 : strlen(sofar); | |
498 | + length += strlen(line); | |
499 | + length++; | |
500 | + buf = sofar == NULL | |
501 | + ? calloc(length, sizeof(char)) | |
502 | + : realloc(sofar, sizeof(char) * length); | |
503 | + if (buf == NULL) { | |
504 | + perror(NULL); | |
505 | + exit(EXIT_FAILURE); | |
506 | + } | |
507 | + return strcat(buf, line); | |
508 | +} | |
509 | + | |
510 | int | |
511 | main (int argc, char **argv) | |
512 | { | |
513 | FILE *font; | |
514 | char *buffer = NULL; | |
515 | char *locale = setlocale (LC_CTYPE, ""); | |
516 | + char *onebdffmtchar = NULL; | |
517 | int error = 0; | |
518 | ||
519 | if (locale == NULL) { | |
520 | @@ -152,14 +171,29 @@ | |
521 | if (!header) | |
522 | { | |
523 | if (strncmp (buf, "STARTCHAR ", 10) == 0) | |
524 | + { | |
525 | + if (onebdffmtchar != NULL) | |
526 | + { | |
527 | + free(onebdffmtchar); | |
528 | + onebdffmtchar = NULL; | |
529 | + } | |
530 | + | |
531 | + } | |
532 | + onebdffmtchar = cat_line(onebdffmtchar, buf); | |
533 | + | |
534 | + if (strncmp (buf, "ENCODING ", 9) == 0) | |
535 | { | |
536 | - wc = strtol (buf + 12, NULL, 16); | |
537 | + wc = strtol (buf + 9, NULL, 10); | |
538 | ||
539 | docopy = used[wc / 32] & (1 << (wc % 32)); | |
540 | } | |
541 | + else if (strncmp (buf, "ENDCHAR", 7) == 0) | |
542 | + { | |
543 | + if (docopy) | |
544 | + fputs (onebdffmtchar, stdout); | |
545 | + docopy = 0; | |
546 | + } | |
547 | ||
548 | - if (docopy) | |
549 | - fprintf (stdout, buf); | |
550 | } | |
551 | } | |
552 | ||
553 | --- bogl/bogl-term.h.rh 2003-11-05 04:01:47.000000000 +0100 | |
554 | +++ bogl/bogl-term.h 2005-03-04 20:26:28.393051304 +0100 | |
555 | @@ -2,7 +2,7 @@ | |
556 | #ifndef bogl_term_h | |
557 | #define bogl_term_h | |
558 | ||
559 | -#include <wchar.h> | |
560 | +#include "wlite/wlite_wchar.h" | |
561 | ||
562 | struct bogl_term { | |
563 | const struct bogl_font *font; | |
564 | @@ -24,6 +24,7 @@ | |
565 | wchar_t **cchars; /* combining chars in cell, or 0 */ | |
566 | int yorig; /* increment this to scroll */ | |
567 | int acs; | |
568 | + char utf[6]; size_t utfn; | |
569 | }; | |
570 | ||
571 | struct bogl_term *bogl_term_new(struct bogl_font *font); | |
572 | --- bogl/bogl-bgf.h.rh 2001-12-01 18:04:42.000000000 +0100 | |
573 | +++ bogl/bogl-bgf.h 2005-03-04 20:26:28.390051760 +0100 | |
574 | @@ -1,2 +1,2 @@ | |
575 | ||
576 | -struct bogl_font *bogl_mmap_font(char *file); | |
577 | +struct bogl_font *bogl_load_font(const char *file); | |
578 | --- bogl/bogl.c.rh 2004-05-06 04:57:06.000000000 +0200 | |
579 | +++ bogl/bogl.c 2005-03-04 20:26:28.395051000 +0100 | |
580 | @@ -53,6 +53,11 @@ | |
581 | #include "bogl-pcfb.h" | |
582 | #include "bogl-tcfb.h" | |
583 | #endif | |
584 | + | |
585 | +#if DIET | |
586 | +#include "wlite/wlite_wchar.h" | |
587 | +#endif | |
588 | + | |
589 | \f | |
590 | /* BOGL main code. */ | |
591 | ||
592 | @@ -196,9 +201,11 @@ | |
593 | ||
594 | ioctl (fb, FBIOGETCMAP, &cmap); | |
595 | } | |
596 | - | |
597 | + | |
598 | +#ifndef DIET | |
599 | if (!status) | |
600 | atexit (bogl_done); | |
601 | +#endif | |
602 | status = 2; | |
603 | ||
604 | return 1; | |
605 | @@ -284,6 +291,11 @@ | |
606 | close (tty); | |
607 | close (fb); | |
608 | } | |
609 | + | |
610 | +void bogl_close(void) { | |
611 | + close (tty); | |
612 | + close (fb); | |
613 | +} | |
614 | \f | |
615 | /* Keyboard interface. */ | |
616 | ||
617 | @@ -621,9 +633,11 @@ | |
618 | if (error) | |
619 | return 0; | |
620 | ||
621 | +#ifndef DIET | |
622 | va_start (args, format); | |
623 | vasprintf (&error, format, args); | |
624 | va_end (args); | |
625 | - | |
626 | +#endif | |
627 | + | |
628 | return 0; | |
629 | } | |
630 | --- bogl/bogl.h.rh 2004-05-06 04:57:06.000000000 +0200 | |
631 | +++ bogl/bogl.h 2005-03-04 20:26:28.395051000 +0100 | |
632 | @@ -22,12 +22,7 @@ | |
633 | #include <stdlib.h> | |
634 | #include <sys/types.h> | |
635 | ||
636 | -/* As a temporary measure, we do this here rather than in config.h, | |
637 | - which would probably make more sense. */ | |
638 | -#include <limits.h> | |
639 | -#ifndef MB_LEN_MAX | |
640 | -#define MB_LEN_MAX 6 /* for UTF-8 */ | |
641 | -#endif | |
642 | +#include "wlite/wlite_wchar.h" | |
643 | ||
644 | /* Proportional font structure definition. */ | |
645 | struct bogl_font | |
646 | @@ -73,6 +68,7 @@ | |
647 | /* Generic routines. */ | |
648 | int bogl_init (void); | |
649 | void bogl_done (void); | |
650 | +void bogl_close (void); | |
651 | const char *bogl_error (void); | |
652 | ||
653 | void bogl_gray_scale (int make_gray); | |
654 | --- bogl/bdftobogl.c.rh 2004-03-08 05:39:59.000000000 +0100 | |
655 | +++ bogl/bdftobogl.c 2005-03-04 20:26:28.389051912 +0100 | |
656 | @@ -24,9 +24,14 @@ | |
657 | #include <string.h> | |
658 | #include <unistd.h> | |
659 | #include <wctype.h> | |
660 | +#include <limits.h> | |
661 | #include "bogl.h" | |
662 | #include "bogl-font.h" | |
663 | ||
664 | +#ifdef DIET | |
665 | +#include "wlite/wlite_wchar.h" | |
666 | +#endif | |
667 | + | |
668 | static void print_glyph (u_int32_t *content, int height, int w); | |
669 | static int bogl_write_font(int fd, struct bogl_font *font); | |
670 | ||
671 | --- /dev/null 2005-03-04 18:11:22.289784760 +0100 | |
672 | +++ bogl/bterm-diet.c 2005-03-04 20:26:28.396050848 +0100 | |
673 | @@ -0,0 +1,7 @@ | |
674 | +extern int bterm_main(int argc, char **argv); | |
675 | + | |
676 | +int main(int argc, char **argv) | |
677 | +{ | |
678 | + bterm_main(argc, argv); | |
679 | +} | |
680 | + | |
681 | --- bogl/bogl-term.c.rh 2003-11-05 05:38:22.000000000 +0100 | |
682 | +++ bogl/bogl-term.c 2005-03-04 20:26:55.737894256 +0100 | |
683 | @@ -24,6 +24,10 @@ | |
684 | * described by the terminfo source in "bterm.ti". | |
685 | */ | |
686 | ||
687 | +#include <limits.h> | |
688 | +#include <string.h> | |
689 | +#include <unistd.h> | |
690 | + | |
691 | #include "bogl.h" | |
692 | #include "bogl-term.h" | |
693 | ||
694 | @@ -50,8 +54,10 @@ | |
695 | term->xsize = bogl_xres / term->xstep; | |
696 | term->ysize = bogl_yres / term->ystep; | |
697 | term->xpos = 0, term->ypos = 0; | |
698 | - term->fg = term->def_fg = 0; | |
699 | - term->bg = term->def_bg = 7; | |
700 | + | |
701 | + /* make default colors like newt tools and bsod! */ | |
702 | + term->fg = term->def_fg = 7; // foreground = white | |
703 | + term->bg = term->def_bg = 4; // background = blue | |
704 | term->rev = 0; | |
705 | term->state = 0; | |
706 | term->cur_visible = 1; | |
707 | @@ -191,14 +197,16 @@ | |
708 | term->screenbg[p] = term->bg; | |
709 | term->screenul[p] = 0; | |
710 | term->dirty[p] = 1; | |
711 | - free (term->cchars[p]); | |
712 | - term->cchars[p] = 0; | |
713 | + if (term->cchars[p] != NULL) { | |
714 | + free (term->cchars[p]); | |
715 | + term->cchars[p] = 0; | |
716 | + } | |
717 | } | |
718 | } | |
719 | ||
720 | static void | |
721 | put_char (struct bogl_term *term, int x, int y, wchar_t wc, wchar_t *cchars, | |
722 | - int fg, int bg, int ul) | |
723 | + int fg, int bg, int ul) | |
724 | { | |
725 | char buf[MB_LEN_MAX]; | |
726 | int j, k, r, w; | |
727 | @@ -296,8 +304,10 @@ | |
728 | term->screenbg[i] = term->bg; | |
729 | term->screenul[i] = 0; | |
730 | } | |
731 | - free (term->cchars[i]); | |
732 | - term->cchars[i] = 0; | |
733 | + if (term->cchars[i] != NULL) { | |
734 | + free (term->cchars[i]); | |
735 | + term->cchars[i] = 0; | |
736 | + } | |
737 | } | |
738 | ||
739 | void | |
740 | @@ -308,12 +318,14 @@ | |
741 | int i, j, w, txp, f, b, use_acs, x, y; | |
742 | char buf[MB_LEN_MAX]; | |
743 | ||
744 | + /* thunk the multibyte state var to the initial setting for the | |
745 | + * sake of glibc. | |
746 | + */ | |
747 | + memset(&term->ps, 0, sizeof(term->ps)); | |
748 | + | |
749 | k = 0; | |
750 | while (1) | |
751 | { | |
752 | - s += k; | |
753 | - n -= k; | |
754 | - | |
755 | /* The n <= 0 check was originally only necessary because of a bug | |
756 | (?) in glibc 2.2.3, as opposed to libiconv. glibc will | |
757 | successfully convert a zero-length string. It is also the only | |
758 | @@ -323,24 +335,30 @@ | |
759 | if (n <= 0) | |
760 | break; | |
761 | ||
762 | - k = mbrtowc (&wc, s, n, &term->ps); | |
763 | + /* queue up the characters and flush immediately when we're out | |
764 | + * of input or we have a valid character. catches cases where a utf-8 | |
765 | + * sequence has been split between two buffered reads | |
766 | + */ | |
767 | + while (term->utfn < sizeof(term->utf) && n-- > 0) { | |
768 | + term->utf[term->utfn++] = *s++; | |
769 | + k = mbrtowc (&wc, term->utf, term->utfn, &term->ps); | |
770 | + if (k != (size_t) -2) { | |
771 | + term->utfn = 0; | |
772 | + break; | |
773 | + } | |
774 | + } | |
775 | ||
776 | /* If we fail to write a character, skip forward one byte and continue. | |
777 | There's not much we can do to recover, but it's better than discarding | |
778 | the whole line. */ | |
779 | - if (k == (size_t) -1) | |
780 | - { | |
781 | + if (k == (size_t) -1) { | |
782 | + k = mbrtowc (NULL, NULL, 0, &term->ps); | |
783 | k = 1; | |
784 | - /* The mbrtowc documentation suggests that we could use mbrtowc | |
785 | - to reset term->ps, but that doesn't work in practice; ps is in | |
786 | - an undefined state which appears to be the illegal state to make | |
787 | - the reset call in. Use memset. */ | |
788 | - memset (&term->ps, 0, sizeof (term->ps)); | |
789 | continue; | |
790 | } | |
791 | else if (k == (size_t) -2) | |
792 | { | |
793 | - /* Incomplete character, so we exit and wait for more to arrive. */ | |
794 | + k = 0; | |
795 | break; | |
796 | } | |
797 | ||
798 | @@ -353,6 +371,21 @@ | |
799 | if (wc == 0) /* 0 has a special meaning in term->screen[] */ | |
800 | continue; | |
801 | ||
802 | + if (wc == 7) { /* bell=^G: flash screen by XORing it twice */ | |
803 | + for (i = 0; i < term->xsize * term->ysize; i++) { | |
804 | + term->screenfg[i] = term->screenfg[i] ^ 0x7; | |
805 | + term->screenbg[i] = term->screenbg[i] ^ 0x7; | |
806 | + } | |
807 | + bogl_term_redraw(term); | |
808 | + usleep(100000); // pause 1/10th of a second | |
809 | + for (i = 0; i < term->xsize * term->ysize; i++) { | |
810 | + term->screenfg[i] = term->screenfg[i] ^ 0x7; | |
811 | + term->screenbg[i] = term->screenbg[i] ^ 0x7; | |
812 | + } | |
813 | + bogl_term_redraw(term); | |
814 | + continue; | |
815 | + } | |
816 | + | |
817 | if (wc == 8) | |
818 | { /* cub1=^H */ | |
819 | if (term->xpos) | |
820 | @@ -395,17 +428,17 @@ | |
821 | continue; | |
822 | } | |
823 | ||
824 | - if (wc == 14) | |
825 | - { | |
826 | - term->acs = 1; | |
827 | - continue; | |
828 | - } | |
829 | + if (wc == 14) | |
830 | + { | |
831 | + term->acs = 1; | |
832 | + continue; | |
833 | + } | |
834 | ||
835 | - if (wc == 15) | |
836 | - { | |
837 | - term->acs = 0; | |
838 | - continue; | |
839 | - } | |
840 | + if (wc == 15) | |
841 | + { | |
842 | + term->acs = 0; | |
843 | + continue; | |
844 | + } | |
845 | ||
846 | if (wc == 27) | |
847 | { /* ESC = \E */ | |
848 | @@ -519,8 +552,10 @@ | |
849 | term->screenbg[i] = term->bg; | |
850 | term->screenul[i] = 0; | |
851 | } | |
852 | - free (term->cchars[i]); | |
853 | - term->cchars[i] = 0; | |
854 | + if (term->cchars[i] != NULL) { | |
855 | + free (term->cchars[i]); | |
856 | + term->cchars[i] = 0; | |
857 | + } | |
858 | } | |
859 | } | |
860 | else if (term->state == 1 && term->arg[0] == 0) | |
861 | @@ -552,8 +587,10 @@ | |
862 | term->screenbg[i] = term->bg; | |
863 | term->screenul[i] = 0; | |
864 | } | |
865 | - free (term->cchars[i]); | |
866 | - term->cchars[i] = 0; | |
867 | + if (term->cchars[i] != NULL) { | |
868 | + free (term->cchars[i]); | |
869 | + term->cchars[i] = 0; | |
870 | + } | |
871 | } | |
872 | } | |
873 | term->state = 0; | |
874 | @@ -608,9 +645,9 @@ | |
875 | continue; | |
876 | } | |
877 | ||
878 | - use_acs = 0; | |
879 | - if (term->acs) | |
880 | - { | |
881 | + use_acs = 0; | |
882 | + if (term->acs) | |
883 | + { | |
884 | /* FIXME: If we are using a non-UTF-8 locale, the wcwidth | |
885 | call below will almost certainly fail. We should have | |
886 | hardcoded results to fall back on in that case. This | |
887 | @@ -618,50 +655,50 @@ | |
888 | less dependent on mbrtowc and wctomb, which I really | |
889 | haven't figured out how to do yet. They aren't really | |
890 | appropriate for a terminal emulator to be using! */ | |
891 | - switch (wc) | |
892 | - { | |
893 | - case 'q': | |
894 | - wc = 0x2500; | |
895 | - use_acs = 1; | |
896 | - break; | |
897 | - case 'j': | |
898 | - wc = 0x2518; | |
899 | - use_acs = 1; | |
900 | - break; | |
901 | - case 'x': | |
902 | - wc = 0x2502; | |
903 | - use_acs = 1; | |
904 | - break; | |
905 | - case 'a': | |
906 | - wc = 0x2591; | |
907 | - use_acs = 1; | |
908 | - break; | |
909 | - case 'm': | |
910 | - wc = 0x2514; | |
911 | - use_acs = 1; | |
912 | - break; | |
913 | - case 'l': | |
914 | - wc = 0x250c; | |
915 | - use_acs = 1; | |
916 | - break; | |
917 | - case 'k': | |
918 | - wc = 0x2510; | |
919 | - use_acs = 1; | |
920 | - break; | |
921 | - case 'u': | |
922 | - wc = 0x2524; | |
923 | - use_acs = 1; | |
924 | - break; | |
925 | - case 't': | |
926 | - wc = 0x251c; | |
927 | - use_acs = 1; | |
928 | - break; | |
929 | - } | |
930 | - } | |
931 | + switch (wc) | |
932 | + { | |
933 | + case 'q': | |
934 | + wc = 0x2500; | |
935 | + use_acs = 1; | |
936 | + break; | |
937 | + case 'j': | |
938 | + wc = 0x2518; | |
939 | + use_acs = 1; | |
940 | + break; | |
941 | + case 'x': | |
942 | + wc = 0x2502; | |
943 | + use_acs = 1; | |
944 | + break; | |
945 | + case 'a': | |
946 | + wc = 0x2591; | |
947 | + use_acs = 1; | |
948 | + break; | |
949 | + case 'm': | |
950 | + wc = 0x2514; | |
951 | + use_acs = 1; | |
952 | + break; | |
953 | + case 'l': | |
954 | + wc = 0x250c; | |
955 | + use_acs = 1; | |
956 | + break; | |
957 | + case 'k': | |
958 | + wc = 0x2510; | |
959 | + use_acs = 1; | |
960 | + break; | |
961 | + case 'u': | |
962 | + wc = 0x2524; | |
963 | + use_acs = 1; | |
964 | + break; | |
965 | + case 't': | |
966 | + wc = 0x251c; | |
967 | + use_acs = 1; | |
968 | + break; | |
969 | + } | |
970 | + } | |
971 | ||
972 | - /* At this point, if we can not decode a character because of ACS, | |
973 | - replace it with a space to minimize graphical corruption. */ | |
974 | - if ((w = wcwidth (wc)) < 0) | |
975 | + /* At this point, if we can not decode a character because of ACS, | |
976 | + replace it with a space to minimize graphical corruption. */ | |
977 | + if (wc < 0 || wc > 0xFFFF || (w = wcwidth (wc)) < 0) | |
978 | { | |
979 | if (use_acs) | |
980 | { | |
981 | @@ -705,8 +742,10 @@ | |
982 | term->screenbg[i] = term->bg; | |
983 | term->screenul[i] = 0; | |
984 | } | |
985 | - free (term->cchars[i]); | |
986 | - term->cchars[i] = NULL; | |
987 | + if (term->cchars[i] != NULL) { | |
988 | + free (term->cchars[i]); | |
989 | + term->cchars[i] = NULL; | |
990 | + } | |
991 | } | |
992 | ||
993 | term->xpos = 0; | |
994 | @@ -720,8 +759,10 @@ | |
995 | term->screenfg[i] = f; | |
996 | term->screenbg[i] = b; | |
997 | term->screenul[i] = term->ul; | |
998 | - free (term->cchars[i]); | |
999 | - term->cchars[i] = NULL; | |
1000 | + if (term->cchars[i] != NULL) { | |
1001 | + free (term->cchars[i]); | |
1002 | + term->cchars[i] = NULL; | |
1003 | + } | |
1004 | ||
1005 | for (j = 1; j < w; j++) | |
1006 | { |