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
11 -#include <sys/mman.h>
12 -#include <sys/stat.h>
13 -#include <sys/types.h>
18 +#include "bogl-bgf.h"
20 -#include "bogl-font.h"
22 -struct bogl_font *bogl_mmap_font(char *file)
27 - struct bogl_font *font;
29 - fd = open(file, O_RDONLY);
33 - if (fstat(fd, &buf))
36 - f = mmap(0, buf.st_size, PROT_READ, MAP_SHARED, fd, 0);
37 - if (f == (void *)-1)
40 - if (memcmp("BGF1", f, 4))
43 - font = (struct bogl_font *)malloc(sizeof(struct bogl_font));
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"
54 +static size_t get_gz_file_size(const char *path) {
56 + unsigned char buffer[4] = { 0 };
57 + FILE *stream = NULL;
59 + stream = fopen(path, "rb");
60 + if (stream == NULL) {
64 + if (fread(buffer, sizeof(char), 2, stream) != 2) {
65 + if (ferror(stream)) {
70 + if (memcmp(buffer, "\037\213", 2) == 0) {
73 + if (fseek(stream, -4L, SEEK_END) == EOF) {
77 + if (fread(buffer, sizeof(char), (size_t) 4, stream) != 4) {
78 + if (ferror(stream)) {
83 + fprintf(stderr, "%s: invalid gzip file\n", path);
88 + isize |= buffer[1] << 8;
89 + isize |= buffer[2] << 16;
90 + isize |= buffer[3] << 24;
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.
95 + size = (size_t) isize;
98 + if (fseek(stream, 0L, SEEK_END) == EOF) {
102 + if ((int) (size = (size_t) ftell(stream)) == EOF) {
107 + if (fclose(stream) == EOF) {
115 +struct bogl_font *bogl_load_font(const char *path) {
120 + struct bogl_font *font;
122 + size = (size_t) get_gz_file_size(path);
123 + if (size == (size_t) -1)
125 + if ((bgf = malloc(size)) == NULL) {
129 + file = gzopen(path, "rb");
130 + if (file == NULL) {
132 + errno = ENOMEM; // if 0 then zlib error == Z_MEM_ERROR
137 + if (gzread(file, bgf, size) == -1) {
138 + const char *msg = gzerror(file, &errnum);
140 + if (errnum == Z_ERRNO) {
141 + msg = strerror(errno);
143 + fprintf(stderr, "%s: %s\n", path, msg);
146 + if (gzclose(file) < 0) {
147 + const char *msg = gzerror(file, &errnum);
149 + if (errnum == Z_ERRNO) {
150 + msg = strerror(errno);
152 + fprintf(stderr, "%s: %s\n", path, msg);
155 + if (memcmp(FONT_SIGNATURE, bgf, strlen(FONT_SIGNATURE)) != 0) {
156 + fprintf(stderr, "%s: not a BGF font\n", path);
159 + font = (struct bogl_font *) malloc(sizeof(struct bogl_font));
160 + if (font == NULL) {
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;
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
175 static int child_pid = 0;
176 static struct termios ttysave;
177 +static int spawn = 0;
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 @@
183 void sigchld(int sig)
185 - if (wait(0) == child_pid) {
187 + if (wait(&status) == child_pid) {
189 /* Reset ownership and permissions of ttyfd device? */
193 tcsetattr(0, TCSAFLUSH, &ttysave);
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))
201 + exit(WEXITSTATUS(status));
203 signal(SIGCHLD, sigchld);
206 +/* return 0 if parent, 1 if child */
207 +int spawn_child(int ptyfd, int ttyfd)
210 + child_pid = fork();
212 + /* Change ownership and permissions of ttyfd device! */
213 + signal(SIGCHLD, sigchld);
216 + setenv("TERM", "bterm", 1);
234 + if (ioctl(0, TIOCSCTTY, (char *)0)) {
235 + perror("Unable to set a new controlling tty: ");
242 void spawn_shell(int ptyfd, int ttyfd, const char *command)
252 tcsetattr(0, TCSANOW, &ttysave);
257 @@ -172,14 +221,14 @@
258 ioctl(ttyfd, TIOCSWINSZ, &win);
261 -static char *font_name;
262 +static char *font_name = "/usr/lib/bogl/font.bgf.gz";
263 static struct bogl_term *term;
265 void reload_font(int sig)
267 struct bogl_font *font;
269 - font = bogl_mmap_font (font_name);
270 + font = bogl_load_font (font_name);
273 fprintf(stderr, "Bad font\n");
283 printf ("unknown option: %c\n", argv[i][1]);
289 - if ((font = bogl_mmap_font(font_name)) == NULL) {
290 + if ((font = bogl_load_font(font_name)) == NULL) {
291 fprintf(stderr, "Bad font\n");
296 term = bogl_term_new(font);
301 bogl_set_palette(0, 16, palette);
307 - spawn_shell(ptyfd, ttyfd, command == NULL ? "/bin/sh" : command);
309 + if (spawn_child(ptyfd, ttyfd))
312 + spawn_shell(ptyfd, ttyfd, command == NULL ? "/bin/sh" : command);
314 signal(SIGHUP, reload_font);
317 ntio.c_cc[VTIME] = 0;
320 - tcsetattr(0, TCSAFLUSH, &ntio);
321 + tcsetattr(0, TCSANOW, &ntio);
323 set_window_size(ttyfd, term->xsize, term->ysize);
325 --- bogl/Makefile.rh 2003-10-05 19:47:03.000000000 +0200
326 +++ bogl/Makefile 2005-03-04 20:26:28.388052064 +0100
328 SONAME = libbogl.so.0
329 SHARED_LIB = libbogl.so.0.1
333 +#architecture := $(shell dpkg-architecture -qDEB_BUILD_GNU_CPU)
334 +architecture := $(patsubst i%86,i386,$(shell uname -m))
336 +ifeq ($(architecture), none)
344 CFLAGS = -O2 -g -D_GNU_SOURCE
345 WARNCFLAGS += -Wall -D_GNU_SOURCE
346 ALLCFLAGS = $(CFLAGS) $(WARNCFLAGS) $(FBCFLAGS)
348 -architecture := $(shell dpkg-architecture -qDEB_BUILD_GNU_CPU)
350 LIBOBJECTS = $(LIBBOGLOBJECTS) $(LIBBOMLOBJECTS) $(LIBBOWLOBJECTS) \
352 LIBBOGLOBJECTS = bogl.o bogl-font.o
354 LIBBOWLOBJECTS = bowl.o symbol.o
355 LIBRSRCOBJECTS = helvB10.o helvB12.o helvR10.o timBI18.o tux75.o
357 +LIBBTERM = libbterm.a
358 +LIBBTERMOBJECTS = bterm-lib.o bogl-term.o bogl-bgf.o
360 +ifeq ($(USEDIET), 1)
361 +LIBBTERMDIET = libbtermdiet.a
362 +LIBBTERMDOBJS = $(patsubst %.o,%.do,$(LIBBTERMOBJECTS))
364 +LIBBOGLDIET = libbogldiet.a
365 +LIBBOGLDOBJS = $(patsubst %.o,%.do,$(LIBOBJECTS))
367 +BTERMDIET = bterm-diet
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 \
374 GENERATED = helvB10.c helvB12.c helvR10.c timBI18.c tux75.c
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)
381 $(CC) $(ALLCFLAGS) -o $@ -fPIC -c $<
384 $(CC) $(ALLCFLAGS) -o $@ -c $<
388 + make SMALL=1 CC="$(DIETCC)"
389 +ifeq ($(USEDIET), 1)
391 + mv libwlite.a libwlitediet.a;\
393 + make SMALL=1 CC="gcc"
396 $(SHARED_LIB): $(OBJECTS:%.o=%.lo)
397 $(CC) -shared -Wl,-soname,$(SONAME) -o $(SHARED_LIB) $(OBJECTS:%.o=%.lo)
401 reduce-font: reduce-font.c
403 +bterm-lib.o: bterm.c
404 + $(CC) $(ALLCFLAGS) -o $@ -c -Dmain=bterm_main $<
406 +bterm-lib.do: bterm.c
407 + diet $(CC) $(ALLCFLAGS) -DDIET -o $@ -c -Dmain=bterm_main $<
409 +ifeq ($(architecture), i386)
410 + DFBCFLAGS := -DBOGL_VGA16_FB=1 -DDIET
412 + DFBCFLAGS := $(FBCFLAGS) -DDIET
416 + diet $(CC) $(DFBCFLAGS) -c $(CFLAGS) -o $@ $<
418 +$(LIBBTERM): $(LIBBTERMOBJECTS)
422 +$(LIBBTERMDIET): $(LIBBTERMDOBJS)
428 - ar rcs $(LIB) $(OBJECTS)
432 +$(LIBBOGLDIET): $(LIBBOGLDOBJS)
436 bogl-test: $(LIB) bogl-test.c tux75.o
437 $(CC) $(ALLCFLAGS) -o bogl-test bogl-test.c tux75.o $(LIB)
439 $(CC) -DSTANDALONE_TEST $(ALLCFLAGS) bowl-boxes.c $(LIBOBJECTS) -o bowl-boxes
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
445 +bterm-diet: $(LIBBOGLDIET) $(LIBBTERMDIET) bterm-diet.c
446 + diet $(CC) -g bterm-diet.c $(LIBBTERMDIET) $(LIBBOGLDIET) wlite/libwlite.a -lz -o $@
448 bdftobogl: $(LIBBOGLOBJECTS)
449 + $(CC) $(ALLCFLAGS) -o $@ bdftobogl.c $^ wlite/libwlite.a
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)
458 + cd wlite; make clean
461 rm -f $(LIB) .depend *~ .nfs*
462 + cd wlite; make distclean
466 @@ -108,12 +176,14 @@
470 +INSTLIBS = $(LIB) $(LIBBTERM) $(LIBBTERMDIET) $(LIBBOGLDIET)
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
489 printf (": %d\n", l);
493 +cat_line(char *sofar, const char *line) {
497 + length = sofar == NULL ? 0 : strlen(sofar);
498 + length += strlen(line);
500 + buf = sofar == NULL
501 + ? calloc(length, sizeof(char))
502 + : realloc(sofar, sizeof(char) * length);
505 + exit(EXIT_FAILURE);
507 + return strcat(buf, line);
511 main (int argc, char **argv)
515 char *locale = setlocale (LC_CTYPE, "");
516 + char *onebdffmtchar = NULL;
519 if (locale == NULL) {
520 @@ -152,14 +171,29 @@
523 if (strncmp (buf, "STARTCHAR ", 10) == 0)
525 + if (onebdffmtchar != NULL)
527 + free(onebdffmtchar);
528 + onebdffmtchar = NULL;
532 + onebdffmtchar = cat_line(onebdffmtchar, buf);
534 + if (strncmp (buf, "ENCODING ", 9) == 0)
536 - wc = strtol (buf + 12, NULL, 16);
537 + wc = strtol (buf + 9, NULL, 10);
539 docopy = used[wc / 32] & (1 << (wc % 32));
541 + else if (strncmp (buf, "ENDCHAR", 7) == 0)
544 + fputs (onebdffmtchar, stdout);
549 - fprintf (stdout, buf);
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
560 +#include "wlite/wlite_wchar.h"
563 const struct bogl_font *font;
565 wchar_t **cchars; /* combining chars in cell, or 0 */
566 int yorig; /* increment this to scroll */
568 + char utf[6]; size_t utfn;
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
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
581 #include "bogl-pcfb.h"
582 #include "bogl-tcfb.h"
586 +#include "wlite/wlite_wchar.h"
590 /* BOGL main code. */
594 ioctl (fb, FBIOGETCMAP, &cmap);
610 +void bogl_close(void) {
615 /* Keyboard interface. */
622 va_start (args, format);
623 vasprintf (&error, format, args);
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
634 #include <sys/types.h>
636 -/* As a temporary measure, we do this here rather than in config.h,
637 - which would probably make more sense. */
640 -#define MB_LEN_MAX 6 /* for UTF-8 */
642 +#include "wlite/wlite_wchar.h"
644 /* Proportional font structure definition. */
647 /* Generic routines. */
648 int bogl_init (void);
649 void bogl_done (void);
650 +void bogl_close (void);
651 const char *bogl_error (void);
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
662 #include "bogl-font.h"
665 +#include "wlite/wlite_wchar.h"
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);
671 --- /dev/null 2005-03-04 18:11:22.289784760 +0100
672 +++ bogl/bterm-diet.c 2005-03-04 20:26:28.396050848 +0100
674 +extern int bterm_main(int argc, char **argv);
676 +int main(int argc, char **argv)
678 + bterm_main(argc, argv);
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
684 * described by the terminfo source in "bterm.ti".
692 #include "bogl-term.h"
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;
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
706 term->cur_visible = 1;
707 @@ -191,14 +197,16 @@
708 term->screenbg[p] = term->bg;
709 term->screenul[p] = 0;
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;
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)
725 char buf[MB_LEN_MAX];
728 term->screenbg[i] = term->bg;
729 term->screenul[i] = 0;
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;
740 @@ -308,12 +318,14 @@
741 int i, j, w, txp, f, b, use_acs, x, y;
742 char buf[MB_LEN_MAX];
744 + /* thunk the multibyte state var to the initial setting for the
747 + memset(&term->ps, 0, sizeof(term->ps));
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 @@
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
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) {
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
779 - if (k == (size_t) -1)
781 + if (k == (size_t) -1) {
782 + k = mbrtowc (NULL, NULL, 0, &term->ps);
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));
791 else if (k == (size_t) -2)
793 - /* Incomplete character, so we exit and wait for more to arrive. */
799 if (wc == 0) /* 0 has a special meaning in term->screen[] */
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;
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;
813 + bogl_term_redraw(term);
820 @@ -395,17 +428,17 @@
849 term->screenbg[i] = term->bg;
850 term->screenul[i] = 0;
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;
860 else if (term->state == 1 && term->arg[0] == 0)
862 term->screenbg[i] = term->bg;
863 term->screenul[i] = 0;
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;
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! */
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)
982 term->screenbg[i] = term->bg;
983 term->screenul[i] = 0;
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;
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;
1005 for (j = 1; j < w; j++)