Package: svgalib Version: 1:1.4.3-29 Severity: important Tags: patch User: debian-...@lists.debian.org Usertags: kfreebsd X-Debbugs-CC: debian-...@lists.debian.org
Hi, I made svgalib build on GNU/kFreeBSD, here is a patch.
diff -ur svgalib-1.4.3.orig/debian/control svgalib-1.4.3/debian/control --- svgalib-1.4.3.orig/debian/control 2009-11-14 00:50:00.000000000 -0500 +++ svgalib-1.4.3/debian/control 2010-08-04 19:56:00.117398564 -0400 @@ -7,7 +7,7 @@ Vcs-Browser: http://git.hadrons.org/?p=debian/pkgs/svgalib.git Vcs-Git: git://git.hadrons.org/git/debian/pkgs/svgalib.git Standards-Version: 3.8.3 -Build-Depends: debhelper (>= 7), libx86-dev [amd64 i386] +Build-Depends: debhelper (>= 7), libx86-dev [amd64 i386 kfreebsd-amd64 kfreebsd-i386] Package: svgalib-bin Architecture: any diff -ur svgalib-1.4.3.orig/src/keyboard/keyboard.c svgalib-1.4.3/src/keyboard/keyboard.c --- svgalib-1.4.3.orig/src/keyboard/keyboard.c 2010-08-04 13:43:15.000000000 -0400 +++ svgalib-1.4.3/src/keyboard/keyboard.c 2010-08-04 19:54:40.714634914 -0400 @@ -33,7 +33,11 @@ /* should also be useful for svgalib programs using the keyboard. It misses */ /* a few KERNEL ifdefs around kernel data structures though. */ #include "keyboard_lnx.h" +#if defined(__linux__) #include <sys/vt.h> +#elif defined(__FreeBSD_kernel__) +#include <sys/consio.h> +#endif /* Needed to check uid of keymap files */ #include <sys/stat.h> #include <unistd.h> @@ -385,6 +389,22 @@ __svgalib_kbd_fd = -1; } +static inline int vt_getactive(int fd) +{ + int v; +#ifdef VT_GETSTATE + struct vt_stat vts; + if (ioctl(fd, VT_GETSTATE, &vts) == 0) + v = vts.v_active; + else + v = -1; +#else + if (ioctl(fd, VT_GETACTIVE, &v) != 0) + v = -1; +#endif + return v; +} + /* For now, we assume there's no console switching. */ /* (Actually, there won't be any unless we catch the console switching */ /* keys). */ @@ -578,7 +598,6 @@ /* VT switch. */ /* *** what about F11 & F12? */ int j, vt = 0; - struct vt_stat vts; for (j = 0; j < 12; j++) if (functionkey_state & (1 << j)) { vt = j + 1; @@ -587,9 +606,7 @@ } /* Do not switch vt's if need not to */ - ioctl(__svgalib_tty_fd, VT_GETSTATE, &vts); - - if(vt != vts.v_active) { + if(vt != vt_getactive(__svgalib_tty_fd)) { /* if switching vt's, need to clear keystates */ keyboard_clearstate(); /* diff -ur svgalib-1.4.3.orig/src/mouse/ms.c svgalib-1.4.3/src/mouse/ms.c --- svgalib-1.4.3.orig/src/mouse/ms.c 2010-08-04 13:43:15.000000000 -0400 +++ svgalib-1.4.3/src/mouse/ms.c 2010-08-04 19:49:23.495541626 -0400 @@ -117,7 +117,9 @@ tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; tty.c_lflag = 0; +#ifdef __linux__ tty.c_line = 0; +#endif tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; @@ -527,7 +529,9 @@ tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; tty.c_lflag = 0; +#ifdef __linux__ tty.c_line = 0; +#endif tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; tty.c_cflag = cflag[m_type] | B1200; diff -ur svgalib-1.4.3.orig/src/vga.c svgalib-1.4.3/src/vga.c --- svgalib-1.4.3.orig/src/vga.c 2010-08-04 13:43:15.000000000 -0400 +++ svgalib-1.4.3/src/vga.c 2010-08-04 19:53:16.757293455 -0400 @@ -25,7 +25,11 @@ #include <sys/kd.h> #include <sys/ioctl.h> #include <sys/stat.h> +#if defined(__linux__) #include <sys/vt.h> +#elif defined(__FreeBSD_kernel__) +#include <sys/consio.h> +#endif #include <sys/wait.h> #include <errno.h> #include <ctype.h> @@ -781,7 +785,7 @@ /* Leave keyboard alone when rawkeyboard is enabled! */ if (__svgalib_kbd_fd < 0) { /* set graphics mode termio parameters */ - ioctl(0, TCSETSW, &graph_termio); + tcsetattr(0, TCSADRAIN, &graph_termio); } } @@ -791,7 +795,7 @@ /* Leave keyboard alone when rawkeyboard is enabled! */ if (__svgalib_kbd_fd < 0) { /* restore text mode termio parameters */ - ioctl(0, TCSETSW, &text_termio); + tcsetattr(0, TCSADRAIN, &text_termio); } } @@ -802,9 +806,9 @@ /* Well, one could argue that sigint is not enabled at all when in __svgalib_nosigint but sometimes they *still* are enabled b4 graph_termio is set.. */ - ioctl(0, TCGETS, &cur_termio); + tcgetattr(0, &cur_termio); cur_termio.c_lflag &= ~ISIG; - ioctl(0, TCSETSW, &cur_termio); + tcsetattr(0, TCSADRAIN, &cur_termio); } @@ -814,9 +818,9 @@ if (__svgalib_nosigint) /* do not reenable, they are often reenabled by text_termio */ return; - ioctl(0, TCGETS, &cur_termio); + tcgetattr(0, &cur_termio); cur_termio.c_lflag |= ISIG; - ioctl(0, TCSETSW, &cur_termio); + tcsetattr(0, TCSADRAIN, &cur_termio); } /* The following is rather messy and inelegant. The only solution I can */ @@ -938,10 +942,26 @@ return 0; } +static inline int vt_getactive(int fd) +{ + int v; +#ifdef VT_GETSTATE + struct vt_stat vts; + if (ioctl(fd, VT_GETSTATE, &vts) == 0) + v = vts.v_active; + else + v = -1; +#else + if (ioctl(fd, VT_GETACTIVE, &v) != 0) + v = -1; +#endif + return v; +} + void __svgalib_open_devconsole(void) { struct vt_mode vtm; - struct vt_stat vts; + int v_active; struct stat sbuf; char fname[30]; @@ -998,8 +1018,8 @@ setsid(); /* We must use RDWR to allow for output... */ if (((__svgalib_tty_fd = open(fname, O_RDWR)) >= 0) && - (ioctl(__svgalib_tty_fd, VT_GETSTATE, &vts) >= 0)) { - if (!check_owner(vts.v_active)) + (v_active = vt_getactive(__svgalib_tty_fd)) >= 0) { + if (!check_owner(v_active)) goto error; /* success, redirect all stdios */ if (DREP) @@ -1016,8 +1036,8 @@ /* clear screen and switch to it */ fwrite("\e[H\e[J", 6, 1, stderr); fflush(stderr); - if (svgalib_vc != vts.v_active) { - startup_vc = vts.v_active; + if (svgalib_vc != v_active) { + startup_vc = v_active; ioctl(__svgalib_tty_fd, VT_ACTIVATE, svgalib_vc); __svgalib_waitvtactive(); } @@ -1329,7 +1349,11 @@ SIGTRAP, SIGIOT, SIGBUS, SIGFPE, SIGSEGV, SIGPIPE, SIGALRM, SIGTERM, SIGXCPU, SIGXFSZ, SIGVTALRM, -/* SIGPROF ,*/ SIGPWR}; +/* SIGPROF ,*/ +#ifdef SIGPWR +SIGPWR +#endif +}; static struct sigaction old_signal_handler[sizeof(sig2catch)]; struct vt_mode __svgalib_oldvtmode; @@ -1939,12 +1963,16 @@ #endif /* save text mode termio parameters */ - ioctl(0, TCGETS, &text_termio); + tcgetattr(0, &text_termio); graph_termio = text_termio; /* change termio parameters to allow our own I/O processing */ - graph_termio.c_iflag &= ~(BRKINT | PARMRK | INPCK | IUCLC | IXON | IXOFF); + graph_termio.c_iflag &= ~(BRKINT | PARMRK | INPCK +#ifdef IUCLC +| IUCLC +#endif +| IXON | IXOFF); graph_termio.c_iflag |= (IGNBRK | IGNPAR); graph_termio.c_oflag &= ~(ONOCR); diff -ur svgalib-1.4.3.orig/src/vgamisc.c svgalib-1.4.3/src/vgamisc.c --- svgalib-1.4.3.orig/src/vgamisc.c 2010-08-04 13:43:15.000000000 -0400 +++ svgalib-1.4.3/src/vgamisc.c 2010-08-04 19:47:52.858115087 -0400 @@ -73,18 +73,40 @@ return __svgalib_graph_mem; } +#if defined(__linux__) + #include <sys/sysinfo.h> +static inline int get_totalram(void) +{ + struct sysinfo si; + si.totalram = 0; + sysinfo(&si); + return si.totalram; +} + +#elif defined(__FreeBSD_kernel__) + +#include <sys/sysctl.h> + +static inline int get_totalram(void) +{ + int totalram; + size_t totalram_size = sizeof(totalram); + if (sysctlbyname("vm.stats.vm.v_page_count", &totalram, &totalram_size, NULL, 0) == -1) + return -1; + return totalram * getpagesize() / 1024; +} + +#endif + int __svgalib_physmem(void) { #ifdef __alpha__ printf("__svgalib_physmem: are you sure you wanna do this??\n"); return -1; #else - struct sysinfo si; - si.totalram = 0; - sysinfo(&si); - return si.totalram; + return get_totalram(); #endif } @@ -303,18 +325,18 @@ int vga_getkey(void) { - struct termio zap, original; + struct termios zap, original; int e; char c; - ioctl(fileno(stdin), TCGETA, &original); /* Get termio */ + tcgetattr(fileno(stdin), &original); /* Get termio */ zap = original; zap.c_cc[VMIN] = 0; /* Modify termio */ zap.c_cc[VTIME] = 0; zap.c_lflag = 0; - ioctl(fileno(stdin), TCSETA, &zap); /* Set new termio */ + tcsetattr(fileno(stdin), TCSANOW, &zap); /* Set new termio */ e = read(fileno(stdin), &c, 1); /* Read one char */ - ioctl(fileno(stdin), TCSETA, &original); /* Restore termio */ + tcsetattr(fileno(stdin), TCSANOW, &original); /* Restore termio */ if (e != 1) return 0; /* No key pressed. */ return c; /* Return key. */ diff -ur svgalib-1.4.3.orig/utils/gtf/scitech.h svgalib-1.4.3/utils/gtf/scitech.h --- svgalib-1.4.3.orig/utils/gtf/scitech.h 2010-08-04 13:43:15.000000000 -0400 +++ svgalib-1.4.3/utils/gtf/scitech.h 2010-08-04 20:01:14.814950032 -0400 @@ -216,7 +216,7 @@ #endif /* 32-bit Linux compile environment */ -#elif defined(__LINUX__) || defined(linux) +#elif defined(__LINUX__) || defined(linux) || defined(__GLIBC__) #ifndef __LINUX__ #define __LINUX__ #endif