Compare commits

...

14 Commits

Author SHA1 Message Date
Juhani Krekelä dea1e15e75 Gracefully handle errors in initialization 2021-11-28 02:00:46 +02:00
Juhani Krekelä 25a52b7327 Handle -mode 2021-11-28 02:00:34 +02:00
Juhani Krekelä 01fbcedf24 Make libjpeg a required dependency 2021-11-28 00:51:53 +02:00
Juhani Krekelä fc79ec7d70 Handle events 2021-11-28 00:51:53 +02:00
Juhani Krekelä 74c389f50b Minimize amount of data copied to display server 2021-11-28 00:51:53 +02:00
Juhani Krekelä 10cc1026fe Further bringup and drawing routines 2021-11-28 00:51:53 +02:00
Juhani Krekelä bc82e4023a sprintf → snprintf for graphics-only cases too 2021-11-28 00:51:53 +02:00
Juhani Krekelä 7a701b1ae5 Basic bringup 2021-11-28 00:51:52 +02:00
Juhani Krekelä b7955fa3c3 Add driver to the manual page 2021-11-28 00:51:17 +02:00
Juhani Krekelä d867eb205c Start work on Sortix graphics driver 2021-11-28 00:51:16 +02:00
Juhani Krekelä df0b7c07d0 Add sortix.c to the build system 2021-11-28 00:41:53 +02:00
Juhani Krekelä 6106cbd49a Add .gitignore 2021-11-27 23:37:06 +02:00
Juhani Krekelä 30d01f4321 Sortix patches 2021-10-03 23:32:32 +03:00
Juhani Krekelä 11fa5e22e3 sprintf → snprintf 2021-10-03 23:30:55 +03:00
28 changed files with 624 additions and 96 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
*.o
links
Makefile
config.cache
config.h
config.log
config.status
stamp-h

View File

@ -24,7 +24,7 @@ if JAVASCRIPT
links_LDADD=builtin.o context.o ipret.o javascr.o javascript.o md5.o md5hl.o ns.o pomocny.o regexp.o
endif
links_SOURCES=af_unix.c auth.c beos.c bfu.c block.c bookmark.c cache.c charsets.c compress.c connect.c cookies.c data.c default.c dip.c directfb.c dither.c dns.c dos.c drivers.c error.c file.c finger.c fn_impl.c fontconf.c font_inc.c framebuf.c freetype.c ftp.c gif.c grx.c hpux.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c string.c suffix.c svg.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c vms.c x.c xbm.c beos.h bits.h cfg.h codepage.h com-defs.h config-vms.h dfb_cur.h hpux.h language.h links.h os_dep.h os_depx.h setup.h arrow.inc certs.inc codepage.inc entity.inc fbcommon.inc language.inc links_ic.inc locase.inc suffix.inc suffix_x.inc uni_7b.inc upcase.inc vpipe.inc
links_SOURCES=af_unix.c auth.c beos.c bfu.c block.c bookmark.c cache.c charsets.c compress.c connect.c cookies.c data.c default.c dip.c directfb.c dither.c dns.c dos.c drivers.c error.c file.c finger.c fn_impl.c fontconf.c font_inc.c framebuf.c freetype.c ftp.c gif.c grx.c hpux.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c string.c suffix.c svg.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c vms.c x.c xbm.c beos.h bits.h cfg.h codepage.h com-defs.h config-vms.h dfb_cur.h hpux.h language.h links.h os_dep.h os_depx.h setup.h arrow.inc certs.inc codepage.inc entity.inc fbcommon.inc language.inc links_ic.inc locase.inc suffix.inc suffix_x.inc uni_7b.inc upcase.inc vpipe.inc sortix.c
# builtin.c context.c ipret.c javascr.c javascript.c md5.c md5hl.c ns.c pomocny.c regexp.c md5.h ns.h struct.h tree.h typy.h ipret.h javascript.h builtin.h builtin_keys.h
dist-hook:

View File

@ -35,8 +35,6 @@ mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
@ -78,7 +76,7 @@ bin_PROGRAMS = links
@HAIKU_GR_TRUE@links_LDADD = haiku.o
@JAVASCRIPT_TRUE@links_LDADD = builtin.o context.o ipret.o javascr.o javascript.o md5.o md5hl.o ns.o pomocny.o regexp.o
links_SOURCES = af_unix.c auth.c beos.c bfu.c block.c bookmark.c cache.c charsets.c compress.c connect.c cookies.c data.c default.c dip.c directfb.c dither.c dns.c dos.c drivers.c error.c file.c finger.c fn_impl.c fontconf.c font_inc.c framebuf.c freetype.c ftp.c gif.c grx.c hpux.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c string.c suffix.c svg.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c vms.c x.c xbm.c beos.h bits.h cfg.h codepage.h com-defs.h config-vms.h dfb_cur.h hpux.h language.h links.h os_dep.h os_depx.h setup.h arrow.inc certs.inc codepage.inc entity.inc fbcommon.inc language.inc links_ic.inc locase.inc suffix.inc suffix_x.inc uni_7b.inc upcase.inc vpipe.inc
links_SOURCES = af_unix.c auth.c beos.c bfu.c block.c bookmark.c cache.c charsets.c compress.c connect.c cookies.c data.c default.c dip.c directfb.c dither.c dns.c dos.c drivers.c error.c file.c finger.c fn_impl.c fontconf.c font_inc.c framebuf.c freetype.c ftp.c gif.c grx.c hpux.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c listedit.c lru.c mailto.c main.c memory.c menu.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c string.c suffix.c svg.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c vms.c x.c xbm.c beos.h bits.h cfg.h codepage.h com-defs.h config-vms.h dfb_cur.h hpux.h language.h links.h os_dep.h os_depx.h setup.h arrow.inc certs.inc codepage.inc entity.inc fbcommon.inc language.inc links_ic.inc locase.inc suffix.inc suffix_x.inc uni_7b.inc upcase.inc vpipe.inc sortix.c
CXXFLAGS = @CXXFLAGS@
@ -102,7 +100,7 @@ hpux.o html.o html_gr.o html_r.o html_tbl.o http.o https.o img.o \
imgcache.o jpeg.o jsint.o kbd.o language.o listedit.o lru.o mailto.o \
main.o memory.o menu.o objreq.o os_dep.o pmshell.o png.o sched.o \
select.o session.o smb.o string.o suffix.o svg.o svgalib.o terminal.o \
tiff.o types.o url.o view.o view_gr.o vms.o x.o xbm.o
tiff.o types.o url.o view.o view_gr.o vms.o x.o xbm.o sortix.o
@ATHEOS_GR_TRUE@links_DEPENDENCIES = atheos.o
@JAVASCRIPT_TRUE@links_DEPENDENCIES = builtin.o context.o ipret.o \
@JAVASCRIPT_TRUE@javascr.o javascript.o md5.o md5hl.o ns.o pomocny.o \
@ -459,6 +457,8 @@ session.o: session.c links.h cfg.h config.h com-defs.h os_dep.h \
os_depx.h setup.h language.h codepage.h
smb.o: smb.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \
setup.h language.h codepage.h
sortix.o: sortix.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \
setup.h language.h codepage.h
string.o: string.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \
setup.h language.h codepage.h
suffix.o: suffix.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \

View File

@ -229,6 +229,9 @@
/* */
#undef GRDRV_GRX
/* */
#undef GRDRV_SORTIX
/* Have freetype */
#undef HAVE_FREETYPE

View File

@ -205,6 +205,7 @@ int bind_to_af_unix(unsigned char *name)
#endif
EINTRLOOP(rs, bind(s_unix_fd, &s_unix.s, s_unix_l));
if (rs) {
attempt_connect:
/*debug("bind: %d, %s", errno, strerror(errno));*/
if (af == PF_INET && errno == EADDRNOTAVAIL) {
/* do not try to connect if the user has not configured loopback interface */
@ -217,7 +218,7 @@ int bind_to_af_unix(unsigned char *name)
#if defined(SOL_SOCKET) && defined(SO_REUSEADDR)
EINTRLOOP(rs, setsockopt(s_unix_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&a1, sizeof a1));
#endif
EINTRLOOP(rs, connect(s_unix_fd, &s_unix.s, s_unix_l));
rs = blocking_connect(s_unix_fd, &s_unix.s, s_unix_l);
if (rs) {
retry:
/*debug("connect: %d, %s", errno, strerror(errno));*/
@ -255,6 +256,7 @@ retry_unlink:
}
EINTRLOOP(rs, listen(s_unix_fd, 100));
if (rs) {
if (errno == EADDRINUSE) goto attempt_connect;
error("ERROR: listen failed: %d", errno);
close_and_fail:
EINTRLOOP(rs, close(s_unix_fd));

View File

@ -215,6 +215,9 @@
/* Define if you have the dirfd function. */
#undef HAVE_DIRFD
/* Define if you have the <display.h> header file. */
#undef HAVE_DISPLAY_H
/* Define if you have the event_base_free function. */
#undef HAVE_EVENT_BASE_FREE
@ -596,6 +599,9 @@
/* Define if you have the <fontconfig/fontconfig.h> header file. */
#undef HAVE_FONTCONFIG_FONTCONFIG_H
/* Define if you have the <framebuffer.h> header file. */
#undef HAVE_FRAMEBUFFER_H
/* Define if you have the <ft2build.h> header file. */
#undef HAVE_FT2BUILD_H
@ -764,6 +770,9 @@
/* Define if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define if you have the <sys/keycodes.h> header file. */
#undef HAVE_SYS_KEYCODES_H
/* Define if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H
@ -848,6 +857,9 @@
/* Define if you have the bz2 library (-lbz2). */
#undef HAVE_LIBBZ2
/* Define if you have the display library (-ldisplay). */
#undef HAVE_LIBDISPLAY
/* Define if you have the dl library (-ldl). */
#undef HAVE_LIBDL
@ -1173,6 +1185,9 @@
/* */
#undef GRDRV_GRX
/* */
#undef GRDRV_SORTIX
/* Have freetype */
#undef HAVE_FREETYPE

111
configure vendored
View File

@ -69,6 +69,8 @@ ac_help="$ac_help
--without-haiku compile without Haiku graphics driver"
ac_help="$ac_help
--without-grx compile without DOS GRX graphics driver"
ac_help="$ac_help
--without-sortix compile without Sortix display(1) graphics driver"
ac_help="$ac_help
--with-x use the X Window System"
ac_help="$ac_help
@ -118,7 +120,7 @@ libdir='${exec_prefix}/lib'
includedir='${prefix}/include'
oldincludedir='/usr/include'
infodir='${prefix}/info'
mandir='${prefix}/man'
mandir='${prefix}/share/man'
# Initialize some other variables.
subdirs=
@ -235,7 +237,7 @@ Directory and file names:
--includedir=DIR C header files in DIR [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc in DIR [/usr/include]
--infodir=DIR info documentation in DIR [PREFIX/info]
--mandir=DIR man documentation in DIR [PREFIX/man]
--mandir=DIR man documentation in DIR [PREFIX/share/man]
--srcdir=DIR find the sources in DIR [configure dir or ..]
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
@ -8392,6 +8394,12 @@ if test "${with_grx+set}" = set; then
if test "$withval" = no; then disable_grx=yes; else disable_grx=no; fi
fi
# Check whether --with-sortix or --without-sortix was given.
if test "${with_sortix+set}" = set; then
withval="$with_sortix"
if test "$withval" = no; then disable_sortix=yes; else disable_sortix=no; fi
fi
drivers=""
@ -10416,6 +10424,105 @@ EOF
fi
fi
if test "$disable_sortix" != yes; then
for ac_hdr in display.h framebuffer.h sys/keycodes.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
echo "configure:10432: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 10437 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:10442: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
eval "ac_cv_header_$ac_safe=yes"
else
echo "$ac_err" >&5
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
eval "ac_cv_header_$ac_safe=no"
fi
rm -f conftest*
fi
if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
echo "$ac_t""yes" 1>&6
ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
cat >> confdefs.h <<EOF
#define $ac_tr_hdr 1
EOF
else
echo "$ac_t""no" 1>&6
fi
done
echo $ac_n "checking for display_connect_default in -ldisplay""... $ac_c" 1>&6
echo "configure:10469: checking for display_connect_default in -ldisplay" >&5
ac_lib_var=`echo display'_'display_connect_default | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_save_LIBS="$LIBS"
LIBS="-ldisplay $LIBS"
cat > conftest.$ac_ext <<EOF
#line 10477 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char display_connect_default();
int main() {
display_connect_default()
; return 0; }
EOF
if { (eval echo configure:10488: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f conftest*
LIBS="$ac_save_LIBS"
fi
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
echo "$ac_t""yes" 1>&6
ac_tr_lib=HAVE_LIB`echo display | sed -e 's/[^a-zA-Z0-9_]/_/g' \
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
cat >> confdefs.h <<EOF
#define $ac_tr_lib 1
EOF
LIBS="-ldisplay $LIBS"
else
echo "$ac_t""no" 1>&6
fi
if test "$ac_cv_header_display_h" = yes &&
test "$ac_cv_header_framebuffer_h" = yes &&
test "$ac_cv_header_sys_keycodes_h" = yes &&
test "$ac_cv_lib_display_display_connect_default" = yes; then
cat >> confdefs.h <<\EOF
#define GRDRV_SORTIX 1
EOF
drivers="$drivers sortix"
fi
fi
# Check whether --with-freetype or --without-freetype was given.
if test "${with_freetype+set}" = set; then

View File

@ -1049,6 +1049,7 @@ AC_ARG_WITH(windows, [ --without-windows compile without Windows graphics
AC_ARG_WITH(atheos, [ --without-atheos compile without Atheos graphics driver],[if test "$withval" = no; then disable_atheos=yes; else disable_atheos=no; fi])
AC_ARG_WITH(haiku, [ --without-haiku compile without Haiku graphics driver],[if test "$withval" = no; then disable_haiku=yes; else disable_haiku=no; fi])
AC_ARG_WITH(grx, [ --without-grx compile without DOS GRX graphics driver],[if test "$withval" = no; then disable_grx=yes; else disable_grx=no; fi])
AC_ARG_WITH(sortix, [ --without-sortix compile without Sortix display(1) graphics driver],[if test "$withval" = no; then disable_sortix=yes; else disable_sortix=no; fi])
drivers=""
@ -1311,6 +1312,18 @@ if test "$disable_grx" != yes -a "$ac_cv_have_djgpp" = yes; then
fi
fi
if test "$disable_sortix" != yes; then
AC_CHECK_HEADERS(display.h framebuffer.h sys/keycodes.h)
AC_CHECK_LIB(display, display_connect_default)
if test "$ac_cv_header_display_h" = yes &&
test "$ac_cv_header_framebuffer_h" = yes &&
test "$ac_cv_header_sys_keycodes_h" = yes &&
test "$ac_cv_lib_display_display_connect_default" = yes; then
AC_DEFINE(GRDRV_SORTIX)
drivers="$drivers sortix"
fi
fi
AC_ARG_WITH(freetype, [ --without-freetype compile without freetype support],[if test "$withval" = no; then disable_freetype=yes; else disable_freetype=no; fi])
font_rendering=INTERNAL

View File

@ -307,7 +307,7 @@ int get_pasv_socket(struct connection *c, int cc, int *sock, unsigned char *port
}
#ifdef SUPPORT_IPV6
int get_pasv_socket_ipv6(struct connection *c, int cc, int *sock, unsigned char *result)
int get_pasv_socket_ipv6(struct connection *c, int cc, int *sock, unsigned char *result, size_t result_size)
{
int s;
int rs;
@ -335,7 +335,7 @@ int get_pasv_socket_ipv6(struct connection *c, int cc, int *sock, unsigned char
if (rs) goto e;
EINTRLOOP(rs, listen(s, 1));
if (rs) goto e;
sprintf(cast_char result, "|2|%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x|%d|",
snprintf(cast_char result, result_size, "|2|%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x|%d|",
sa.sin6_addr.s6_addr[0],
sa.sin6_addr.s6_addr[1],
sa.sin6_addr.s6_addr[2],
@ -672,7 +672,7 @@ static void try_connect(struct connection *c)
#if defined(__aarch64__) && defined(__ILP32__)
errno = EINPROGRESS; /* arm64 ilp32 bug */
#endif
EINTRLOOP(rs, connect(s, (struct sockaddr *)(void *)&sa, sizeof sa));
rs = connect(s, (struct sockaddr *)(void *)&sa, sizeof sa);
#ifdef SUPPORT_IPV6
} else if (addr->af == AF_INET6) {
struct sockaddr_in6 sa;
@ -686,14 +686,14 @@ static void try_connect(struct connection *c)
#if defined(__aarch64__) && defined(__ILP32__)
errno = EINPROGRESS; /* arm64 ilp32 bug */
#endif
EINTRLOOP(rs, connect(s, (struct sockaddr *)(void *)&sa, sizeof sa));
rs = connect(s, (struct sockaddr *)(void *)&sa, sizeof sa);
#endif
} else {
rs = -1;
errno = EINVAL;
}
if (rs) {
if (errno != EALREADY && errno != EINPROGRESS) {
if (errno != EALREADY && errno != EINPROGRESS && errno != EINTR) {
#ifdef BEOS
if (errno == EWOULDBLOCK) errno = ETIMEDOUT;
#endif

106
default.c
View File

@ -88,13 +88,13 @@ static void get_compiler_name(void)
if (v1 == 4 && v2 < 5) v1 = 3;
if (v1 == 4 && v2 == 5) v2 = 0;
if (!v3) sprintf(cast_char compiler_name, "Borland C %d.%d", v1, v2);
else sprintf(cast_char compiler_name, "Borland C %d.%d.%d", v1, v2, v3);
if (!v3) snprintf(cast_char compiler_name, sizeof(compiler_name), "Borland C %d.%d", v1, v2);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "Borland C %d.%d.%d", v1, v2, v3);
#elif defined(__clang__)
#if !defined(__clang_major__) || !defined(__clang_minor__)
sprintf(cast_char compiler_name, "LLVM/Clang");
snprintf(cast_char compiler_name, sizeof(compiler_name), "LLVM/Clang");
#else
int v1 = __clang_major__+0;
int v2 = __clang_minor__+0;
@ -103,8 +103,8 @@ static void get_compiler_name(void)
#else
int v3 = 0;
#endif
if (v3 > 0) sprintf(cast_char compiler_name, "LLVM/Clang %d.%d.%d", v1, v2, v3);
else sprintf(cast_char compiler_name, "LLVM/Clang %d.%d", v1, v2);
if (v3 > 0) snprintf(cast_char compiler_name, sizeof(compiler_name), "LLVM/Clang %d.%d.%d", v1, v2, v3);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "LLVM/Clang %d.%d", v1, v2);
#endif
#elif defined(__COMO_VERSION__)
@ -112,33 +112,33 @@ static void get_compiler_name(void)
int w = __COMO_VERSION__+0;
int v1 = w / 100;
int v2 = w % 100;
if (!(v2 % 10)) sprintf(cast_char compiler_name, "Comeau C %d.%d", v1, v2 / 10);
else sprintf(cast_char compiler_name, "Comeau C %d.%02d", v1, v2);
if (!(v2 % 10)) snprintf(cast_char compiler_name, sizeof(compiler_name), "Comeau C %d.%d", v1, v2 / 10);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "Comeau C %d.%02d", v1, v2);
#elif defined(__convexc__)
sprintf(cast_char compiler_name, "Convex C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Convex C");
#elif defined(_CRAYC)
#if !defined(_RELEASE) || !defined(_RELEASE_MINOR)
sprintf(cast_char compiler_name, "Cray C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Cray C");
#else
int v1 = _RELEASE+0;
int v2 = _RELEASE_MINOR+0;
sprintf(cast_char compiler_name, "Cray C %d.%d", v1, v2);
snprintf(cast_char compiler_name, sizeof(compiler_name), "Cray C %d.%d", v1, v2);
#endif
#elif defined(__DCC__)
#ifndef __VERSION_NUMBER__
sprintf(cast_char compiler_name, "Diab C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Diab C");
#else
int w = __VERSION_NUMBER__+0;
int v1 = w / 1000;
int v2 = w / 100 % 10;
int v3 = w % 100;
sprintf(cast_char compiler_name, "Diab C %d.%d.%02d", v1, v2, v3);
snprintf(cast_char compiler_name, sizeof(compiler_name), "Diab C %d.%d.%02d", v1, v2, v3);
#endif
#elif defined(__DMC__)
@ -147,8 +147,8 @@ static void get_compiler_name(void)
int v1 = w / 0x100;
int v2 = w / 0x10 % 0x10;
int v3 = w % 0x10;
if (!v3) sprintf(cast_char compiler_name, "Digital Mars C %d.%d", v1, v2);
else sprintf(cast_char compiler_name, "Digital Mars C %d.%d.%d", v1, v2, v3);
if (!v3) snprintf(cast_char compiler_name, sizeof(compiler_name), "Digital Mars C %d.%d", v1, v2);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "Digital Mars C %d.%d.%d", v1, v2, v3);
#elif defined(__DECC_VER)
@ -156,23 +156,23 @@ static void get_compiler_name(void)
int v1 = w / 10000000;
int v2 = w / 100000 % 100;
int v3 = w % 10000;
sprintf(cast_char compiler_name, "DEC C %d.%d-%03d", v1, v2, v3);
snprintf(cast_char compiler_name, sizeof(compiler_name), "DEC C %d.%d-%03d", v1, v2, v3);
#elif defined(__ghs__)
#ifndef __GHS_VERSION_NUMBER__
sprintf(cast_char compiler_name, "Green Hill C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Green Hill C");
#else
int w = __GHS_VERSION_NUMBER__+0;
int v1 = w / 100;
int v2 = w / 10 % 10;
int v3 = w % 10;
sprintf(cast_char compiler_name, "Green Hill C %d.%d.%d", v1, v2, v3);
snprintf(cast_char compiler_name, sizeof(compiler_name), "Green Hill C %d.%d.%d", v1, v2, v3);
#endif
#elif defined(__HIGHC__)
sprintf(cast_char compiler_name, "MetaWare High C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "MetaWare High C");
#elif defined(__HP_cc)
@ -180,15 +180,15 @@ static void get_compiler_name(void)
int v1 = w / 10000;
int v2 = w / 100 % 100;
int v3 = w % 100;
if (w <= 1) sprintf(cast_char compiler_name, "HP CC");
else sprintf(cast_char compiler_name, "HP CC %d.%02d.%02d", v1, v2, v3);
if (w <= 1) snprintf(cast_char compiler_name, sizeof(compiler_name), "HP CC");
else snprintf(cast_char compiler_name, sizeof(compiler_name), "HP CC %d.%02d.%02d", v1, v2, v3);
#elif defined(__xlc__)
int w = __xlc__+0;
int v1 = w / 0x100;
int v2 = w % 0x100;
sprintf(cast_char compiler_name, "IBM XL C %X.%X", v1, v2);
snprintf(cast_char compiler_name, sizeof(compiler_name), "IBM XL C %X.%X", v1, v2);
#elif defined(__IBMC__) && defined(__COMPILER_VER__)
@ -198,23 +198,23 @@ static void get_compiler_name(void)
int v2 = w / 0x10000 % 0x100;
int v3 = w % 0x10000;
unsigned char *os = !v0 ? "S/370" : v0 == 1 ? "OS/390" : v0 == 4 ? "z/OS" : "";
sprintf(cast_char compiler_name, "IBM%s%s XL C %X.%0X.%X", *os ? " " : "", os, v1, v2, v3);
snprintf(cast_char compiler_name, sizeof(compiler_name), "IBM%s%s XL C %X.%0X.%X", *os ? " " : "", os, v1, v2, v3);
#elif defined(__ICC)
int w = __ICC+0;
int v1 = w / 100;
int v2 = w % 100;
if (!(v2 % 10)) sprintf(cast_char compiler_name, "Intel C %d.%d", v1, v2 / 10);
else sprintf(cast_char compiler_name, "Intel C %d.%02d", v1, v2);
if (!(v2 % 10)) snprintf(cast_char compiler_name, sizeof(compiler_name), "Intel C %d.%d", v1, v2 / 10);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "Intel C %d.%02d", v1, v2);
#elif defined(__LCC__)
sprintf(cast_char compiler_name, "LCC");
snprintf(cast_char compiler_name, sizeof(compiler_name), "LCC");
#elif defined(__NDPC__)
sprintf(cast_char compiler_name, "Microway NDP C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Microway NDP C");
#elif defined(_MSC_VER)
@ -227,8 +227,8 @@ static void get_compiler_name(void)
if (v1 == 2) v1 = 1;
visual = cast_uchar "Visual ";
}
if (!(v2 % 10)) sprintf(cast_char compiler_name, "Microsoft %sC %d.%d", visual, v1, v2 / 10);
else sprintf(cast_char compiler_name, "Microsoft %sC %d.%02d", visual, v1, v2);
if (!(v2 % 10)) snprintf(cast_char compiler_name, sizeof(compiler_name), "Microsoft %sC %d.%d", visual, v1, v2 / 10);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "Microsoft %sC %d.%02d", visual, v1, v2);
#elif defined(__MWERKS__)
@ -236,12 +236,12 @@ static void get_compiler_name(void)
int v1 = w / 0x1000;
int v2 = w / 0x100 % 0x10;
int v3 = w % 0x100;
if (w <= 1) sprintf(cast_char compiler_name, "Metrowerks CodeWarrior");
sprintf(cast_char compiler_name, "Metrowerks CodeWarrior %x.%x.%x", v1, v2, v3);
if (w <= 1) snprintf(cast_char compiler_name, sizeof(compiler_name), "Metrowerks CodeWarrior");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Metrowerks CodeWarrior %x.%x.%x", v1, v2, v3);
#elif defined(__NWCC__)
sprintf(cast_char compiler_name, "NWCC");
snprintf(cast_char compiler_name, sizeof(compiler_name), "NWCC");
#elif defined(__OPEN64__)
@ -268,12 +268,12 @@ static void get_compiler_name(void)
#else
int v3 = 0;
#endif
sprintf(cast_char compiler_name, "PCC %d.%d.%d", v1, v2, v3);
snprintf(cast_char compiler_name, sizeof(compiler_name), "PCC %d.%d.%d", v1, v2, v3);
#elif defined(__PGI) || defined(__PGIC__)
#if !defined(__PGIC__) || !defined(__PGIC_MINOR__)
sprintf(cast_char compiler_name, "The Portland Group C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "The Portland Group C");
#else
int v1 = __PGIC__+0;
int v2 = __PGIC_MINOR__+0;
@ -282,8 +282,8 @@ static void get_compiler_name(void)
#else
int v3 = 0;
#endif
if (v3 > 0) sprintf(cast_char compiler_name, "The Portland Group C %d.%d.%d", v1, v2, v3);
else sprintf(cast_char compiler_name, "The Portland Group C %d.%d", v1, v2);
if (v3 > 0) snprintf(cast_char compiler_name, sizeof(compiler_name), "The Portland Group C %d.%d.%d", v1, v2, v3);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "The Portland Group C %d.%d", v1, v2);
#endif
#elif defined(__SASC__)
@ -291,7 +291,7 @@ static void get_compiler_name(void)
int w = __SASC__+0;
int v1 = w / 100;
int v2 = w % 100;
sprintf(cast_char compiler_name, "SAS C %d.%02d", v1, v2);
snprintf(cast_char compiler_name, sizeof(compiler_name), "SAS C %d.%02d", v1, v2);
#elif (defined(__sgi) && defined(_COMPILER_VERSION)) || defined(_SGI_COMPILER_VERSION)
@ -303,7 +303,7 @@ static void get_compiler_name(void)
int v1 = w / 100;
int v2 = w / 10 % 10;
int v3 = w % 10;
sprintf(cast_char compiler_name, "MIPSpro %d.%d.%d", v1, v2, v3);
snprintf(cast_char compiler_name, sizeof(compiler_name), "MIPSpro %d.%d.%d", v1, v2, v3);
#elif defined(__SUNPRO_C)
@ -313,8 +313,8 @@ static void get_compiler_name(void)
int v1 = w / div;
int v2 = w % div / 0x10;
int v3 = w % 0x10;
if (!v3) sprintf(cast_char compiler_name, "Sun C %X.%0*X", v1, v2_digits, v2);
else sprintf(cast_char compiler_name, "Sun C %X.%0*X.%X", v1, v2_digits, v2, v3);
if (!v3) snprintf(cast_char compiler_name, sizeof(compiler_name), "Sun C %X.%0*X", v1, v2_digits, v2);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "Sun C %X.%0*X.%X", v1, v2_digits, v2, v3);
#elif defined(__SYSC__) && defined(__SYSC_VER__)
@ -322,37 +322,37 @@ static void get_compiler_name(void)
int v1 = w / 10000;
int v2 = w / 100 % 100;
int v3 = w % 100;
sprintf(cast_char compiler_name, "Dignus Systems C %d.%02d.%02d", v1, v2, v3);
snprintf(cast_char compiler_name, sizeof(compiler_name), "Dignus Systems C %d.%02d.%02d", v1, v2, v3);
#elif defined(__TenDRA__)
sprintf(cast_char compiler_name, "TenDRA C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "TenDRA C");
#elif defined(__TINYC__)
sprintf(cast_char compiler_name, "Tiny C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Tiny C");
#elif defined(_UCC)
#if !defined(_MAJOR_REV) || !defined(_MINOR_REV)
sprintf(cast_char compiler_name, "Ultimate C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Ultimate C");
#else
int v1 = _MAJOR_REV+0;
int v2 = _MAJOR_REV+0;
sprintf(cast_char compiler_name, "Ultimate C %d.%d", v1, v2);
snprintf(cast_char compiler_name, sizeof(compiler_name), "Ultimate C %d.%d", v1, v2);
#endif
#elif defined(__USLC__)
sprintf(cast_char compiler_name, "USL C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "USL C");
#elif defined(__VAXC)
sprintf(cast_char compiler_name, "VAX C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "VAX C");
#elif defined(__VOSC__)
sprintf(cast_char compiler_name, "Stratus VOS C");
snprintf(cast_char compiler_name, sizeof(compiler_name), "Stratus VOS C");
#elif defined(__WATCOMC__)
@ -364,8 +364,8 @@ static void get_compiler_name(void)
v1 -= 11;
op = cast_uchar "Open";
}
if (!(v2 % 10)) sprintf(cast_char compiler_name, "%sWatcom C %d.%d", op, v1, v2 / 10);
else sprintf(cast_char compiler_name, "%sWatcom C %d.%02d", op, v1, v2);
if (!(v2 % 10)) snprintf(cast_char compiler_name, sizeof(compiler_name), "%sWatcom C %d.%d", op, v1, v2 / 10);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "%sWatcom C %d.%02d", op, v1, v2);
#elif defined(__GNUC__)
@ -385,10 +385,10 @@ static void get_compiler_name(void)
#else
unsigned char *prefix = cast_uchar "";
#endif
if (v1 == 2 && (v2 >= 90 && v2 <= 91)) sprintf(cast_char compiler_name, "%sEGCS 1.%d", prefix, v2 - 90);
else if (v3 > 0 && v2 >= 0) sprintf(cast_char compiler_name, "%sGNU C %d.%d.%d", prefix, v1, v2, v3);
else if (v2 >= 0) sprintf(cast_char compiler_name, "%sGNU C %d.%d", prefix, v1, v2);
else sprintf(cast_char compiler_name, "%sGNU C %d", prefix, v1);
if (v1 == 2 && (v2 >= 90 && v2 <= 91)) snprintf(cast_char compiler_name, sizeof(compiler_name), "%sEGCS 1.%d", prefix, v2 - 90);
else if (v3 > 0 && v2 >= 0) snprintf(cast_char compiler_name, sizeof(compiler_name), "%sGNU C %d.%d.%d", prefix, v1, v2, v3);
else if (v2 >= 0) snprintf(cast_char compiler_name, sizeof(compiler_name), "%sGNU C %d.%d", prefix, v1, v2);
else snprintf(cast_char compiler_name, sizeof(compiler_name), "%sGNU C %d", prefix, v1);
#else

2
dns.c
View File

@ -773,7 +773,7 @@ int ipv6_full_access(void)
sin6.sin6_family = AF_INET6;
sin6.sin6_port = htons(1024);
memcpy(&sin6.sin6_addr.s6_addr, "\052\001\004\060\000\015\000\000\002\314\236\377\376\044\176\032", 16);
EINTRLOOP(c, connect(h, (struct sockaddr *)(void *)&sin6, sizeof sin6));
c = blocking_connect(h, (struct sockaddr *)(void *)&sin6, sizeof sin6);
EINTRLOOP(rs, close(h));
if (!c) return 1;
#endif

View File

@ -40,6 +40,10 @@ extern struct graphics_driver grx_driver;
#ifdef GRDRV_SDL
extern struct graphics_driver sdl_driver;
#endif
#ifdef GRDRV_SORTIX
extern struct graphics_driver sortix_driver;
#endif
/*
* On SPAD you must test first svgalib and then X (because X test is slow).
@ -82,6 +86,9 @@ static struct graphics_driver *graphics_drivers[] = {
#endif
#ifdef GRDRV_SDL
&sdl_driver,
#endif
#ifdef GRDRV_SORTIX
&sortix_driver,
#endif
NULL
};

View File

@ -412,14 +412,14 @@ void int_error(const char *m, ...)
#else
va_list l;
sprintf(cast_char errbuf, "Internal error at %s:%d\r\n%s", errfile, errline, m);
snprintf(cast_char errbuf, sizeof(errbuf), "Internal error at %s:%d\r\n%s", errfile, errline, m);
va_start(l, m);
os_report_error_va("Internal error", cast_const_char errbuf, l);
va_end(l);
fatal_tty_exit();
sprintf(cast_char errbuf, "\n"ANSI_SET_BOLD"INTERNAL ERROR"ANSI_CLEAR_BOLD" at %s:%d: %s", errfile, errline, m);
snprintf(cast_char errbuf, sizeof(errbuf), "\n"ANSI_SET_BOLD"INTERNAL ERROR"ANSI_CLEAR_BOLD" at %s:%d: %s", errfile, errline, m);
va_start(l, m);
er(1, cast_char errbuf, l);
va_end(l);
@ -433,7 +433,7 @@ void debug_msg(const char *m, ...)
{
va_list l;
va_start(l, m);
sprintf(cast_char errbuf, "\nDEBUG MESSAGE at %s:%d: %s", errfile, errline, m);
snprintf(cast_char errbuf, sizeof(errbuf), "\nDEBUG MESSAGE at %s:%d: %s", errfile, errline, m);
er(0, cast_char errbuf, l);
va_end(l);
}

10
file.c
View File

@ -104,7 +104,7 @@ static void stat_links(unsigned char **p, int *l, struct stat *stp)
unsigned char lnk[64];
if (!stp) add_to_str(p, l, cast_uchar " ");
else {
sprintf(cast_char lnk, "%3ld ", (unsigned long)stp->st_nlink);
snprintf(cast_char lnk, sizeof(lnk), "%3ld ", (unsigned long)stp->st_nlink);
add_to_str(p, l, lnk);
}
#endif
@ -136,13 +136,13 @@ static void stat_user(unsigned char **p, int *l, struct stat *stp, int g)
if (g && id == last_gid && last_gid != -1) goto a;
if (!g) {
ENULLLOOP(pwd, getpwuid(id));
if (!pwd || !pwd->pw_name) sprintf(cast_char pp, "%d", id);
else sprintf(cast_char pp, "%.8s", pwd->pw_name);
if (!pwd || !pwd->pw_name) snprintf(cast_char pp, sizeof(last_user), "%d", id);
else snprintf(cast_char pp, sizeof(last_user), "%.8s", pwd->pw_name);
last_uid = id;
} else {
ENULLLOOP(grp, getgrgid(id));
if (!grp || !grp->gr_name) sprintf(cast_char pp, "%d", id);
else sprintf(cast_char pp, "%.8s", grp->gr_name);
if (!grp || !grp->gr_name) snprintf(cast_char pp, sizeof(last_group), "%d", id);
else snprintf(cast_char pp, sizeof(last_group), "%.8s", grp->gr_name);
last_gid = id;
}
a:

6
ftp.c
View File

@ -250,7 +250,7 @@ static struct ftp_connection_info *add_file_cmd_to_str(struct connection *c, int
int ps;
#ifdef SUPPORT_IPV6
if (is_ipv6(c->sock1)) {
ps = get_pasv_socket_ipv6(c, c->sock1, &c->sock2, port_string);
ps = get_pasv_socket_ipv6(c, c->sock1, &c->sock2, port_string, sizeof(port_string));
if (ps) {
mem_free(d);
mem_free(s);
@ -267,9 +267,9 @@ static struct ftp_connection_info *add_file_cmd_to_str(struct connection *c, int
return NULL;
}
if (inf->eprt_epsv)
sprintf(cast_char port_string, "|1|%d.%d.%d.%d|%d|", pc[0], pc[1], pc[2], pc[3], (pc[4] << 8) | pc[5]);
snprintf(cast_char port_string, sizeof(port_string), "|1|%d.%d.%d.%d|%d|", pc[0], pc[1], pc[2], pc[3], (pc[4] << 8) | pc[5]);
else
sprintf(cast_char port_string, "%d,%d,%d,%d,%d,%d", pc[0], pc[1], pc[2], pc[3], pc[4], pc[5]);
snprintf(cast_char port_string, sizeof(port_string), "%d,%d,%d,%d,%d,%d", pc[0], pc[1], pc[2], pc[3], pc[4], pc[5]);
}
if (strlen(cast_const_char port_string) >= sizeof(port_string))
internal_error("buffer overflow in get_pasv_socket_ipv6: %d > %d", (int)strlen(cast_const_char port_string), (int)sizeof(port_string));

2
html.c
View File

@ -1633,7 +1633,7 @@ static void html_li(unsigned char *a)
unsigned char *x;
for (x = n; *x; x++) *x = upcase(*x);
}
} else sprintf(cast_char n, "%d", par_format.list_number);
} else snprintf(cast_char n, sizeof(n), "%d", par_format.list_number);
put_chrs(n, (int)strlen(cast_const_char n));
put_chrs(cast_uchar ".&nbsp;", 7);
if (!F) par_format.leftmargin += (int)strlen(cast_const_char n) + c + 2;

View File

@ -620,7 +620,7 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
mem_free(a);
}
#ifdef G
sprintf(cast_char cell->bgcolor_str, "#%02x%02x%02x", cell->bgcolor.r & 0xff, cell->bgcolor.g & 0xff, cell->bgcolor.b & 0xff);
snprintf(cast_char cell->bgcolor_str, sizeof(cell->bgcolor_str), "#%02x%02x%02x", cell->bgcolor.r & 0xff, cell->bgcolor.g & 0xff, cell->bgcolor.b & 0xff);
#endif
if ((csp = get_num(t_attr, cast_uchar "colspan")) == -1) csp = 1;
if (!csp) csp = -1;
@ -1805,8 +1805,8 @@ void table_bg(struct text_attrib *ta, unsigned char bgstr[8])
if (ta->fg.g > max) max = ta->fg.g;
if (ta->fg.b > max) max = ta->fg.b;
max &= 0xff;
sprintf(cast_char bgstr, "#%02x%02x%02x", max, max, max);
} else sprintf(cast_char bgstr, "#%02x%02x%02x", G_HTML_TABLE_FRAME_COLOR, G_HTML_TABLE_FRAME_COLOR, G_HTML_TABLE_FRAME_COLOR);
snprintf(cast_char bgstr, 8, "#%02x%02x%02x", max, max, max);
} else snprintf(cast_char bgstr, 8, "#%02x%02x%02x", G_HTML_TABLE_FRAME_COLOR, G_HTML_TABLE_FRAME_COLOR, G_HTML_TABLE_FRAME_COLOR);
}
static void g_new_tag(struct table *t, unsigned char *name, int x, int y)

2
http.c
View File

@ -353,7 +353,7 @@ static void add_url_to_str(unsigned char **str, int *l, unsigned char *url)
for (sp = url; *sp && *sp != POST_CHAR; sp++) {
if (*sp <= ' ' || *sp >= 127) {
unsigned char esc[4];
sprintf(cast_char esc, "%%%02X", (int)*sp);
snprintf(cast_char esc, 4, "%%%02X", (int)*sp);
add_to_str(str, l, esc);
} else {
add_chr_to_str(str, l, *sp);

View File

@ -52,7 +52,7 @@ Run in text mode (overrides previous \-g).
.TP
\f3-driver \f2<driver name>\f1
Graphics driver to use. Drivers are: x, svgalib, fb, directfb, pmshell,
atheos.
atheos, sortix.
List of drivers will be shown if you give it an unknown driver.
Available drivers depend on your operating system and available libraries.

View File

@ -1140,6 +1140,7 @@ extern int terminate_loop;
int can_write(int fd);
int can_read(int fd);
int can_read_timeout(int fd, int sec);
int blocking_connect(int fd, struct sockaddr *addr, socklen_t addrlen);
int close_std_handle(int);
void restore_std_handle(int, int);
unsigned long select_info(int);
@ -1581,7 +1582,7 @@ void continue_connection(struct connection *, int *, void (*)(struct connection
int is_ipv6(int);
int get_pasv_socket(struct connection *, int, int *, unsigned char *);
#ifdef SUPPORT_IPV6
int get_pasv_socket_ipv6(struct connection *, int, int *, unsigned char *);
int get_pasv_socket_ipv6(struct connection *, int, int *, unsigned char *, size_t);
#endif
void write_to_socket(struct connection *, int, unsigned char *, int, void (*)(struct connection *));
struct read_buffer *alloc_read_buffer(struct connection *c);

4
menu.c
View File

@ -3872,8 +3872,8 @@ static void dlg_resize_terminal(struct terminal *term, void *xxx, void *ses_)
struct dialog *d;
unsigned x = (unsigned)term->x > 999 ? 999 : term->x;
unsigned y = (unsigned)term->y > 999 ? 999 : term->y;
sprintf(cast_char x_str, "%u", x);
sprintf(cast_char y_str, "%u", y);
snprintf(cast_char x_str, sizeof(x_str), "%u", x);
snprintf(cast_char y_str, sizeof(y_str), "%u", y);
d = mem_calloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item));
d->title = TEXT_(T_RESIZE_TERMINAL);
d->fn = group_fn;

View File

@ -3434,6 +3434,14 @@ int os_default_charset(void)
return 0;
}
// PATCH: Always use UTF-8 instead of language-specific terminal charsets
#elif defined(__sortix__)
int os_default_charset(void)
{
return utf8_table;
}
#elif !defined(DOS)
int os_default_charset(void)

View File

@ -125,6 +125,22 @@ int can_read(int fd)
}
// PATCH: Handle connect not being restartable
int blocking_connect(int fd, struct sockaddr *addr, socklen_t addrlen)
{
int connect_error;
socklen_t len = sizeof(int);
if (!connect(fd, addr, addrlen)) return 0;
if (errno != EINTR) return -1;
can_do_io(fd, 1, -1); // Wait until connected/failed
getsockopt(fd, SOL_SOCKET, SO_ERROR, &connect_error, &len);
errno = connect_error;
return !connect_error ? 0 : -1;
}
int close_std_handle(int std)
{
#ifndef DOS

View File

@ -192,10 +192,10 @@ static void add_xnum_to_str(unsigned char **s, int *l, off_t n)
static void add_time_to_str(unsigned char **s, int *l, uttime t)
{
unsigned char q[64];
if (t >= 86400) sprintf(cast_char q, "%lud ", (unsigned long)(t / 86400)), add_to_str(s, l, q);
if (t >= 3600) t %= 86400, sprintf(cast_char q, "%d:%02d", (int)(t / 3600), (int)(t / 60 % 60)), add_to_str(s, l, q);
else sprintf(cast_char q, "%d", (int)(t / 60)), add_to_str(s, l, q);
sprintf(cast_char q, ":%02d", (int)(t % 60)), add_to_str(s, l, q);
if (t >= 86400) snprintf(cast_char q, sizeof(q), "%lud ", (unsigned long)(t / 86400)), add_to_str(s, l, q);
if (t >= 3600) t %= 86400, snprintf(cast_char q, sizeof(q), "%d:%02d", (int)(t / 3600), (int)(t / 60 % 60)), add_to_str(s, l, q);
else snprintf(cast_char q, sizeof(q), "%d", (int)(t / 60)), add_to_str(s, l, q);
snprintf(cast_char q, sizeof(q), ":%02d", (int)(t % 60)), add_to_str(s, l, q);
}
static unsigned char *get_stat_msg(struct status *stat, struct terminal *term)

341
sortix.c Normal file
View File

@ -0,0 +1,341 @@
/* sortix.c
* Sortix display(1) support
* (c) 2021 Juhani 'nortti' Krekelä
* This file is a part of the Links program, released under GPL.
*/
#include "cfg.h"
#ifdef GRDRV_SORTIX
#include <sys/keycodes.h>
#include <errno.h>
#include <stdint.h>
#include <display.h>
#include <framebuffer.h>
#include "links.h"
struct window_data
{
uint32_t window_id;
int modifiers;
};
static int default_window_width = 600;
static int default_window_height = 500;
static struct display_connection* connection;
static struct display_event_handlers event_handlers;
struct graphics_driver sortix_driver;
static struct graphics_device *current_dev;
static void on_disconnect(void *ctx)
{
if (current_dev->keyboard_handler)
current_dev->keyboard_handler(current_dev, KBD_CTRL_C, 0);
}
static void on_quit(void *ctx, uint32_t window_id)
{
struct window_data *window_data = current_dev->driver_data;
if (window_id != window_data->window_id) return;
if (current_dev->keyboard_handler)
current_dev->keyboard_handler(current_dev, KBD_CLOSE, 0);
}
static void on_keyboard(void *ctx, uint32_t window_id, uint32_t codepoint)
{
(void) ctx;
struct window_data *window_data = current_dev->driver_data;
if (window_id != window_data->window_id) return;
int kbkey = KBKEY_DECODE(codepoint);
if (kbkey) {
switch (kbkey) {
case KBKEY_LALT: window_data->modifiers |= KBD_ALT; break;
case -KBKEY_LALT: window_data->modifiers &= ~KBD_ALT; break;
case KBKEY_LSHIFT: case KBKEY_RSHIFT: window_data->modifiers |= KBD_SHIFT; break;
case -KBKEY_LSHIFT: case -KBKEY_RSHIFT: window_data->modifiers &= ~KBD_SHIFT; break;
case KBKEY_LCTRL: case KBKEY_RCTRL: window_data->modifiers |= KBD_CTRL; break;
case -KBKEY_LCTRL: case -KBKEY_RCTRL: window_data->modifiers &= ~KBD_CTRL; break;
}
}
if (current_dev->keyboard_handler) {
if (kbkey) codepoint = 0;
switch (codepoint) {
case '\n': codepoint = KBD_ENTER; break;
case 127: codepoint = KBD_BS; break;
case '\t': codepoint = KBD_TAB; break;
}
switch (kbkey) {
case KBKEY_ESC: codepoint = KBD_ESC; break;
case KBKEY_LEFT: codepoint = KBD_LEFT; break;
case KBKEY_RIGHT: codepoint = KBD_RIGHT; break;
case KBKEY_UP: codepoint = KBD_UP; break;
case KBKEY_DOWN: codepoint = KBD_DOWN; break;
case KBKEY_INSERT: codepoint = KBD_INS; break;
case KBKEY_DELETE: codepoint = KBD_DEL; break;
case KBKEY_HOME: codepoint = KBD_HOME; break;
case KBKEY_END: codepoint = KBD_END; break;
case KBKEY_PGUP: codepoint = KBD_PAGE_UP; break;
case KBKEY_PGDOWN: codepoint = KBD_PAGE_DOWN; break;
case KBKEY_F1: codepoint = KBD_F1; break;
case KBKEY_F2: codepoint = KBD_F2; break;
case KBKEY_F3: codepoint = KBD_F3; break;
case KBKEY_F4: codepoint = KBD_F4; break;
case KBKEY_F5: codepoint = KBD_F5; break;
case KBKEY_F6: codepoint = KBD_F6; break;
case KBKEY_F7: codepoint = KBD_F7; break;
case KBKEY_F8: codepoint = KBD_F8; break;
case KBKEY_F9: codepoint = KBD_F9; break;
case KBKEY_F10: codepoint = KBD_F10; break;
case KBKEY_F11: codepoint = KBD_F11; break;
case KBKEY_F12: codepoint = KBD_F12; break;
}
if (codepoint)
current_dev->keyboard_handler(current_dev, codepoint, window_data->modifiers);
}
}
static void on_resize(void *ctx, uint32_t window_id, uint32_t width, uint32_t height)
{
(void) ctx;
struct window_data *window_data = current_dev->driver_data;
if (window_id != window_data->window_id) return;
if (!width || !height) return;
current_dev->size.x2 = width;
current_dev->size.y2 = height;
if (current_dev->resize_handler)
current_dev->resize_handler(current_dev);
}
static void sortix_process_events(void *data)
{
(void) data;
if (!current_dev) return;
while (display_poll_event(connection, &event_handlers) == 0);
}
static unsigned char *sortix_init_driver(unsigned char *param, unsigned char *display)
{
if (param) {
if (sscanf(param, "%ix%i", &default_window_width, &default_window_height) != 2)
return stracpy("-mode syntax is WIDTHxHEIGHT\n");
}
(void) display; // Only used by the X11 driver
connection = display_connect_default();
if (!connection && errno == ECONNREFUSED)
display_spawn(g_argc, g_argv);
if (!connection) {
char err[256];
snprintf(err, sizeof(err), "Error connecting to display: %s\n", strerror(errno));
return stracpy(err);
}
sortix_driver.get_color = get_color_fn(sortix_driver.depth);
event_handlers.disconnect_handler = on_disconnect;
event_handlers.keyboard_handler = on_keyboard;
event_handlers.quit_handler = on_quit;
event_handlers.resize_handler = on_resize;
set_handlers(display_connection_fd(connection), sortix_process_events, NULL, NULL);
return NULL;
}
static struct graphics_device *sortix_init_device(void)
{
struct graphics_device *dev = mem_calloc(sizeof(struct graphics_device));
dev->size.x1 = 0;
dev->size.y1 = 0;
dev->size.x2 = default_window_width;
dev->size.y2 = default_window_height;
dev->clip = dev->size;
struct window_data *window_data = mem_calloc(sizeof(struct window_data));
dev->driver_data = window_data;
window_data->window_id = 0;
display_create_window(connection, window_data->window_id);
display_resize_window(connection, window_data->window_id, dev->size.x2, dev->size.y2);
display_show_window(connection, window_data->window_id);
current_dev = dev;
return dev;
}
static void sortix_shutdown_device(struct graphics_device *dev)
{
struct window_data *window_data = dev->driver_data;
display_destroy_window(connection, window_data->window_id);
free(window_data);
}
static void sortix_shutdown_driver(void)
{
display_disconnect(connection);
}
static void sortix_after_fork(void)
{
if (connection)
display_disconnect(connection);
}
static unsigned char *sortix_get_driver_param(void)
{
return NULL; //TODO: driver parameters?
}
static int sortix_get_empty_bitmap(struct bitmap *dest)
{
// TODO: Overflow when multiplying
dest->data = mem_alloc_mayfail((size_t)dest->x * (size_t)dest->y * sizeof(uint32_t));
if (!dest->data)
return -1;
// TODO: Overflow when multiplying
dest->skip = (ssize_t)dest->x * sizeof(uint32_t);
dest->flags = 0;
return 0;
}
static void sortix_register_bitmap(struct bitmap *bmp)
{
}
static void *sortix_prepare_strip(struct bitmap *bmp, int top, int lines)
{
if (!bmp->data)
return NULL;
// TODO: Overflow when multiplying
return ((unsigned char *)bmp->data) + bmp->skip * top;
}
static void sortix_commit_strip(struct bitmap *bmp, int top, int lines)
{
}
static void sortix_unregister_bitmap(struct bitmap *bmp)
{
if (bmp->data)
mem_free(bmp->data);
}
static void sortix_draw_bitmap(struct graphics_device *dev, struct bitmap *bmp, int x1, int y1)
{
struct window_data *window_data = dev->driver_data;
size_t width = bmp->x;
size_t height = bmp->y;
if (!width || !height)
return;
// TODO: Overflow when multiplying
uint32_t *buffer = mem_alloc(width * height * sizeof(uint32_t));
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
void *pixel_data = ((unsigned char*)bmp->data) + y * bmp->skip + x * sizeof(uint32_t);
uint32_t pixel;
memcpy(&pixel, pixel_data, sizeof(uint32_t));
// Set alpha (see sortix_fill_area() for more details)
pixel |= 0xff000000;
buffer[y * width + x] = pixel;
}
}
display_render_window(connection, window_data->window_id, x1, y1, width, height, buffer);
free(buffer);
}
static void sortix_fill_area(struct graphics_device *dev, int x1, int y1, int x2, int y2, long color)
{
struct window_data *window_data = dev->driver_data;
size_t width = x2 - x1;
size_t height = y2 - y1;
if (!width || !height)
return;
// TODO: Overflow when multiplying
uint32_t *buffer = mem_alloc(width * height * sizeof(uint32_t));
// Links uses a pixel format where the top byte is clear
// Sortix stores alpha there, so set it to 255
uint32_t pixel = color | 0xff000000;
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++)
buffer[y * width + x] = pixel;
}
display_render_window(connection, window_data->window_id, x1, y1, width, height, buffer);
free(buffer);
}
static void sortix_draw_hline(struct graphics_device *dev, int x1, int y, int x2, long color)
{
sortix_fill_area(dev, x1, y, x2, y + 1, color);
}
static void sortix_draw_vline(struct graphics_device *dev, int x, int y1, int y2, long color)
{
sortix_fill_area(dev, x, y1, x + 1, y2, color);
}
static void sortix_set_title(struct graphics_device *dev, unsigned char *title)
{
struct window_data *window_data = dev->driver_data;
display_title_window(connection, window_data->window_id, title);
}
struct graphics_driver sortix_driver =
{
(unsigned char *)"sortix",
sortix_init_driver,
sortix_init_device,
sortix_shutdown_device,
sortix_shutdown_driver,
NULL, // emergency_shutdown
sortix_after_fork,
sortix_get_driver_param,
NULL, // get_af_unix_name
NULL, // get_margin
NULL, // set_margin
sortix_get_empty_bitmap,
sortix_register_bitmap,
sortix_prepare_strip,
sortix_commit_strip,
sortix_unregister_bitmap,
sortix_draw_bitmap,
NULL, // get_color, set in sortix_init_driver()
sortix_fill_area,
sortix_draw_hline,
sortix_draw_vline,
NULL, // scroll
NULL, // set_clip_area
NULL, // flush
NULL, // block
NULL, // unblock
NULL, // set_palette
NULL, // get_real_colors
sortix_set_title,
NULL, // exec
NULL, // set_clipboard_text
NULL, // get_clipboard_text
(24 << 3) | 4, // depth: 24bpp, 4 bytes per pixel
0, 0, // size (x, y), unused
GD_DONT_USE_SCROLL | GD_UNICODE_KEYS, //flags
NULL, // param
};
#endif /* GRDRV_SORTIX */

7
tixbuildinfo Normal file
View File

@ -0,0 +1,7 @@
tix.version=1
tix.class=srctix
pkg.name=links
pkg.build-libraries=libjpeg libpng libssl libz libevent? librsvg? libtiff? xz?
pkg.build-system=configure
pkg.configure.args=--enable-graphics
pkg.location-independent=true

6
url.c
View File

@ -336,7 +336,7 @@ static unsigned char *translate_hashbang(unsigned char *up)
unsigned char c = *dp;
if (c <= 0x20 || c == 0x23 || c == 0x25 || c == 0x26 || c == 0x2b || c >= 0x7f) {
unsigned char h[4];
sprintf(cast_char h, "%%%02X", c);
snprintf(cast_char h, 4, "%%%02X", c);
add_to_str(&r, &rl, h);
} else {
add_chr_to_str(&r, &rl, c);
@ -501,7 +501,7 @@ static void insert_wd(unsigned char **up, unsigned char *cwd)
unsigned char c = *cw;
if (c < ' ' || c == '%' || c >= 127) {
unsigned char h[4];
sprintf(cast_char h, "%%%02X", (unsigned)c & 0xff);
snprintf(cast_char h, 4, "%%%02X", (unsigned)c & 0xff);
add_to_str(&url, &url_l, h);
} else {
add_chr_to_str(&url, &url_l, c);
@ -749,7 +749,7 @@ void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encod
if (!chr) continue;
if (special_char(chr) && encode_special == 1) {
unsigned char h[4];
sprintf(cast_char h, "%%%02X", (unsigned)chr & 0xff);
snprintf(cast_char h, 4, "%%%02X", (unsigned)chr & 0xff);
add_to_str(s, l, h);
continue;
}

4
view.c
View File

@ -2035,7 +2035,7 @@ static void encode_string(unsigned char *name, unsigned char **data, int *len)
else if (safe_char(*name)) add_chr_to_str(data, len, *name);
else {
unsigned char n[4];
sprintf(cast_char n, "%%%02X", *name);
snprintf(cast_char n, 4, "%%%02X", *name);
add_to_str(data, len, n);
}
}
@ -2270,7 +2270,7 @@ unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form
}
for (i = 0; i < len; i++) {
unsigned char p[3];
sprintf(cast_char p, "%02x", (int)data[i]);
snprintf(cast_char p, 3, "%02x", (int)data[i]);
add_to_str(&go, &l, p);
}
}