links2

links 2.15+ fork
git clone git://git.codemadness.org/links2
Log | Files | Refs | README

commit 5aaecf54e7d2152fe843b8831e1d48bc2ec71cb8
parent 9adcf07f37fa6d7c93bd8edbd9519de1bc8c6cb5
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat, 28 Apr 2018 21:10:23 +0200

remove unused code, remove xbm support

Diffstat:
Links_logo.png | 0
Makefile.am | 35-----------------------------------
Makefile.in | 576-------------------------------------------------------------------------------
beos.c | 265-------------------------------------------------------------------------------
bfu.c | 10----------
bookmark.c | 4----
cache.c | 6------
compress.c | 511-------------------------------------------------------------------------------
connect.c | 42------------------------------------------
default.c | 187-------------------------------------------------------------------------------
dip.c | 101+------------------------------------------------------------------------------
directfb.c | 818-------------------------------------------------------------------------------
dither.c | 2--
dns.c | 171+------------------------------------------------------------------------------
dos.c | 846-------------------------------------------------------------------------------
drivers.c | 179-------------------------------------------------------------------------------
error.c | 441-------------------------------------------------------------------------------
file.c | 15---------------
fn_impl.c | 363-------------------------------------------------------------------------------
framebuf.c | 1951-------------------------------------------------------------------------------
ftp.c | 2--
gif.c | 2--
grx.c | 572-------------------------------------------------------------------------------
html.c | 56--------------------------------------------------------
html_gr.c | 12------------
html_r.c | 44--------------------------------------------
http.c | 40----------------------------------------
https.c | 343-------------------------------------------------------------------------------
img.c | 101-------------------------------------------------------------------------------
install-sh | 251-------------------------------------------------------------------------------
jsint.c | 3860-------------------------------------------------------------------------------
kbd.c | 120+------------------------------------------------------------------------------
language.c | 4----
links.h | 3---
main.c | 14--------------
memory.c | 3---
menu.c | 411-------------------------------------------------------------------------------
missing | 198-------------------------------------------------------------------------------
os_dep.c | 2481++++---------------------------------------------------------------------------
pmshell.c | 2556-------------------------------------------------------------------------------
png.c | 14--------------
sched.c | 14--------------
select.c | 114++-----------------------------------------------------------------------------
session.c | 175-------------------------------------------------------------------------------
smb.c | 674-------------------------------------------------------------------------------
stamp-h.in | 1-
string.c | 68--------------------------------------------------------------------
suffix.c | 2--
svg.c | 308-------------------------------------------------------------------------------
svgalib.c | 2565-------------------------------------------------------------------------------
terminal.c | 70----------------------------------------------------------------------
tiff.c | 289------------------------------------------------------------------------------
types.c | 3---
unifdef.h | 674-------------------------------------------------------------------------------
url.c | 55-------------------------------------------------------
view.c | 378-------------------------------------------------------------------------------
view_gr.c | 28----------------------------
vms.c | 1146-------------------------------------------------------------------------------
x.c | 40----------------------------------------
xbm.c | 300-------------------------------------------------------------------------------
60 files changed, 103 insertions(+), 24411 deletions(-)

diff --git a/Links_logo.png b/Links_logo.png Binary files differ. diff --git a/Makefile.am b/Makefile.am @@ -1,35 +0,0 @@ -# Makefile.am -# (c) 2002 Mikulas Patocka, Karel 'Clock' Kulhavy, Petr 'Brain' Kulhavy, -# Martin 'PerM' Pergel - -man_MANS=links.1 - -EXTRA_DIST=$(man_MANS) atheos.cpp BRAILLE_HOWTO KEYS SITES descrip.mms *.opt PATCH-gpm-1.20.0-smooth-cursor PATCH-libpng-1.2.18 mailcap.pl rebuild Links_logo.png Unicode/*.cp Unicode/[!C]* certs/[!C]* intl/[!C]* suffix/[!C]* graphics/*.c graphics/arrow.png graphics/gen graphics/system_font/*.png graphics/font/century_extensions-medium-roman-serif-vari/*.png graphics/font/century_school-bold-roman-serif-vari/*.png graphics/font/century_school-medium-roman-serif-vari/*.png graphics/font/courier-medium-roman-serif-mono/*.png graphics/font/japanese-medium-roman-sans-mono/*.png graphics/font/symbol-medium-roman-sans-vari/*.png graphics/font/century_school-bold-roman-serif-vari/aliases graphics/font/century_school-medium-roman-serif-vari/aliases graphics/font/japanese-medium-roman-sans-mono/aliases graphics/font/symbol-medium-roman-sans-vari/aliases doc/links_cal/*.png doc/links_cal/*.html graphics/Makefile graphics/Fontmap graphics/clip.c graphics/links.xpm graphics/makefont graphics/pdf2html graphics/spacer.png pkg-config.m4 *.xpm *.ico *.rc mk-release-os2 mk-release-win mk-dos mk-dos83.cmd links.wis *.nsi -# parser/gen parser/javascr.l parser/javascript.y - -bin_PROGRAMS=links - -if ATHEOS_GR -links_LDADD=atheos.o -else -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 font_inc.c framebuf.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 -# 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: -#remove the symlinka: - rm $(distdir)/INSTALL - echo Links $(VERSION) -- How To Install > $(distdir)/INSTALL - echo Links $(VERSION) -- How To Install | tr -c '\n' '-' >> $(distdir)/INSTALL - echo >> $(distdir)/INSTALL - cat $(srcdir)/INSTALL >> $(distdir)/INSTALL - -CXXFLAGS=@CXXFLAGS@ - -atheos.o: $(srcdir)/atheos.cpp - $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c $(srcdir)/atheos.cpp - -datadir = $(prefix)/@DATADIRNAME@ -LIBS = @LIBS@ - diff --git a/Makefile.in b/Makefile.in @@ -1,576 +0,0 @@ -# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -# Makefile.am -# (c) 2002 Mikulas Patocka, Karel 'Clock' Kulhavy, Petr 'Brain' Kulhavy, -# Martin 'PerM' Pergel - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = . - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -CC = @CC@ -CXX = @CXX@ -DIRECTFB_CONFIG = @DIRECTFB_CONFIG@ -MAKEINFO = @MAKEINFO@ -PACKAGE = @PACKAGE@ -PKG_CONFIG = @PKG_CONFIG@ -VERSION = @VERSION@ - -man_MANS = links.1 - -EXTRA_DIST = $(man_MANS) atheos.cpp BRAILLE_HOWTO KEYS SITES descrip.mms *.opt PATCH-gpm-1.20.0-smooth-cursor PATCH-libpng-1.2.18 mailcap.pl rebuild Links_logo.png Unicode/*.cp Unicode/[!C]* certs/[!C]* intl/[!C]* suffix/[!C]* graphics/*.c graphics/arrow.png graphics/gen graphics/system_font/*.png graphics/font/century_extensions-medium-roman-serif-vari/*.png graphics/font/century_school-bold-roman-serif-vari/*.png graphics/font/century_school-medium-roman-serif-vari/*.png graphics/font/courier-medium-roman-serif-mono/*.png graphics/font/japanese-medium-roman-sans-mono/*.png graphics/font/symbol-medium-roman-sans-vari/*.png graphics/font/century_school-bold-roman-serif-vari/aliases graphics/font/century_school-medium-roman-serif-vari/aliases graphics/font/japanese-medium-roman-sans-mono/aliases graphics/font/symbol-medium-roman-sans-vari/aliases doc/links_cal/*.png doc/links_cal/*.html graphics/Makefile graphics/Fontmap graphics/clip.c graphics/links.xpm graphics/makefont graphics/pdf2html graphics/spacer.png pkg-config.m4 *.xpm *.ico *.rc mk-release-os2 mk-release-win mk-dos mk-dos83.cmd links.wis *.nsi -# parser/gen parser/javascr.l parser/javascript.y - -bin_PROGRAMS = links - -@ATHEOS_GR_TRUE@links_LDADD = atheos.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 font_inc.c framebuf.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 - -CXXFLAGS = @CXXFLAGS@ - -datadir = $(prefix)/@DATADIRNAME@ -LIBS = @LIBS@ -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = -PROGRAMS = $(bin_PROGRAMS) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I. -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -links_OBJECTS = af_unix.o auth.o beos.o bfu.o block.o bookmark.o \ -cache.o charsets.o compress.o connect.o cookies.o data.o default.o \ -dip.o directfb.o dither.o dns.o dos.o drivers.o error.o file.o finger.o \ -fn_impl.o font_inc.o framebuf.o ftp.o gif.o grx.o 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 -@ATHEOS_GR_TRUE@links_DEPENDENCIES = atheos.o -links_LDFLAGS = -CFLAGS = @CFLAGS@ -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -man1dir = $(mandir)/man1 -MANS = $(man_MANS) - -NROFF = nroff -DIST_COMMON = README ./stamp-h.in AUTHORS COPYING ChangeLog INSTALL \ -Makefile.am Makefile.in NEWS acconfig.h aclocal.m4 config.guess \ -config.h.in config.sub configure configure.in install-sh missing \ -mkinstalldirs - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = tar -GZIP_ENV = --best -SOURCES = $(links_SOURCES) -OBJECTS = $(links_OBJECTS) - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .o .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status - -$(ACLOCAL_M4): configure.in - cd $(srcdir) && $(ACLOCAL) - -config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - $(SHELL) ./config.status --recheck -$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) - cd $(srcdir) && $(AUTOCONF) - -config.h: stamp-h - @if test ! -f $@; then \ - rm -f stamp-h; \ - $(MAKE) stamp-h; \ - else :; fi -stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status - cd $(top_builddir) \ - && CONFIG_FILES= CONFIG_HEADERS=config.h \ - $(SHELL) ./config.status - @echo timestamp > stamp-h 2> /dev/null -$(srcdir)/config.h.in: $(srcdir)/stamp-h.in - @if test ! -f $@; then \ - rm -f $(srcdir)/stamp-h.in; \ - $(MAKE) $(srcdir)/stamp-h.in; \ - else :; fi -$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h - cd $(top_srcdir) && $(AUTOHEADER) - @echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null - -mostlyclean-hdr: - -clean-hdr: - -distclean-hdr: - -rm -f config.h - -maintainer-clean-hdr: - -mostlyclean-binPROGRAMS: - -clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) - -distclean-binPROGRAMS: - -maintainer-clean-binPROGRAMS: - -install-binPROGRAMS: $(bin_PROGRAMS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(bindir) - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - if test -f $$p; then \ - echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ - $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - else :; fi; \ - done - -uninstall-binPROGRAMS: - @$(NORMAL_UNINSTALL) - list='$(bin_PROGRAMS)'; for p in $$list; do \ - rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ - done - -.c.o: - $(COMPILE) -c $< - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -links: $(links_OBJECTS) $(links_DEPENDENCIES) - @rm -f links - $(LINK) $(links_LDFLAGS) $(links_OBJECTS) $(links_LDADD) $(LIBS) - -install-man1: - $(mkinstalldirs) $(DESTDIR)$(man1dir) - @list='$(man1_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.1*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \ - else file=$$i; fi; \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst"; \ - $(INSTALL_DATA) $$file $(DESTDIR)$(man1dir)/$$inst; \ - done - -uninstall-man1: - @list='$(man1_MANS)'; \ - l2='$(man_MANS)'; for i in $$l2; do \ - case "$$i" in \ - *.1*) list="$$list $$i" ;; \ - esac; \ - done; \ - for i in $$list; do \ - ext=`echo $$i | sed -e 's/^.*\\.//'`; \ - inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ - inst=`echo $$inst | sed '$(transform)'`.$$ext; \ - echo " rm -f $(DESTDIR)$(man1dir)/$$inst"; \ - rm -f $(DESTDIR)$(man1dir)/$$inst; \ - done -install-man: $(MANS) - @$(NORMAL_INSTALL) - $(MAKE) $(AM_MAKEFLAGS) install-man1 -uninstall-man: - @$(NORMAL_UNINSTALL) - $(MAKE) $(AM_MAKEFLAGS) uninstall-man1 - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags -o $$here/TAGS $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP)) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(PACKAGE)-$(VERSION) -top_distdir = $(distdir) - -# This target untars the dist file and tries a VPATH configuration. Then -# it guarantees that the distribution is self-contained by making another -# tarfile. -distcheck: dist - -rm -rf $(distdir) - GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz - mkdir $(distdir)/=build - mkdir $(distdir)/=inst - dc_install_base=`cd $(distdir)/=inst && pwd`; \ - cd $(distdir)/=build \ - && ../configure --srcdir=.. --prefix=$$dc_install_base \ - && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ - && $(MAKE) $(AM_MAKEFLAGS) check \ - && $(MAKE) $(AM_MAKEFLAGS) install \ - && $(MAKE) $(AM_MAKEFLAGS) installcheck \ - && $(MAKE) $(AM_MAKEFLAGS) dist - -rm -rf $(distdir) - @banner="$(distdir).tar.gz is ready for distribution"; \ - dashes=`echo "$$banner" | sed s/./=/g`; \ - echo "$$dashes"; \ - echo "$$banner"; \ - echo "$$dashes" -dist: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -dist-all: distdir - -chmod -R a+r $(distdir) - GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) - -rm -rf $(distdir) -distdir: $(DISTFILES) - -rm -rf $(distdir) - mkdir $(distdir) - -chmod 755 $(distdir) - $(mkinstalldirs) $(distdir)/Unicode $(distdir)/certs \ - $(distdir)/doc/links_cal $(distdir)/graphics \ - $(distdir)/graphics/font/century_extensions-medium-roman-serif-vari \ - $(distdir)/graphics/font/century_school-bold-roman-serif-vari \ - $(distdir)/graphics/font/century_school-medium-roman-serif-vari \ - $(distdir)/graphics/font/courier-medium-roman-serif-mono \ - $(distdir)/graphics/font/japanese-medium-roman-sans-mono \ - $(distdir)/graphics/font/symbol-medium-roman-sans-vari \ - $(distdir)/graphics/system_font $(distdir)/intl \ - $(distdir)/suffix - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done - $(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-hook -af_unix.o: af_unix.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -auth.o: auth.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -beos.o: beos.c -bfu.o: bfu.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -block.o: block.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -bookmark.o: bookmark.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -cache.o: cache.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -charsets.o: charsets.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h codepage.inc uni_7b.inc \ - entity.inc upcase.inc locase.inc -compress.o: compress.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -connect.o: connect.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -cookies.o: cookies.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -data.o: data.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -default.o: default.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -dip.o: dip.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h links_ic.inc -directfb.o: directfb.c cfg.h config.h links.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h dfb_cur.h -dither.o: dither.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h bits.h -dns.o: dns.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -dos.o: dos.c -drivers.o: drivers.c cfg.h config.h links.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -error.o: error.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -file.o: file.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -finger.o: finger.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -fn_impl.o: fn_impl.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -font_inc.o: font_inc.c cfg.h config.h links.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -framebuf.o: framebuf.c cfg.h config.h links.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h bits.h arrow.inc \ - fbcommon.inc -ftp.o: ftp.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -gif.o: gif.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -grx.o: grx.c cfg.h config.h -hpux.o: hpux.c -html.o: html.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -html_gr.o: html_gr.c cfg.h config.h links.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -html_r.o: html_r.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -html_tbl.o: html_tbl.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -http.o: http.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -https.o: https.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h certs.inc -img.o: img.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -imgcache.o: imgcache.c cfg.h config.h links.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -jpeg.o: jpeg.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -jsint.o: jsint.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -kbd.o: kbd.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -language.o: language.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h language.inc -listedit.o: listedit.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -lru.o: lru.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -mailto.o: mailto.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -main.o: main.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -memory.o: memory.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -menu.o: menu.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -objreq.o: objreq.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -os_dep.o: os_dep.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -pmshell.o: pmshell.c cfg.h config.h -png.o: png.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -sched.o: sched.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -select.o: select.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -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 -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 \ - setup.h language.h codepage.h suffix.inc suffix_x.inc -svg.o: svg.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h bits.h -svgalib.o: svgalib.c cfg.h config.h links.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h bits.h arrow.inc \ - fbcommon.inc -terminal.o: terminal.c links.h cfg.h config.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -tiff.o: tiff.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h bits.h -types.o: types.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -url.o: url.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -view.o: view.c links.h cfg.h config.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h -view_gr.o: view_gr.c cfg.h config.h links.h com-defs.h os_dep.h \ - os_depx.h setup.h language.h codepage.h -vms.o: vms.c -x.o: x.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h setup.h \ - language.h codepage.h -xbm.o: xbm.c cfg.h config.h links.h com-defs.h os_dep.h os_depx.h \ - setup.h language.h codepage.h - -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -all-recursive-am: config.h - $(MAKE) $(AM_MAKEFLAGS) all-recursive - -install-exec-am: install-binPROGRAMS -install-exec: install-exec-am - -install-data-am: install-man -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: uninstall-binPROGRAMS uninstall-man -uninstall: uninstall-am -all-am: Makefile $(PROGRAMS) $(MANS) config.h -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1 - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-hdr mostlyclean-binPROGRAMS \ - mostlyclean-compile mostlyclean-tags \ - mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-hdr clean-binPROGRAMS clean-compile clean-tags \ - clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-hdr distclean-binPROGRAMS distclean-compile \ - distclean-tags distclean-generic clean-am - -distclean: distclean-am - -rm -f config.status - -maintainer-clean-am: maintainer-clean-hdr maintainer-clean-binPROGRAMS \ - maintainer-clean-compile maintainer-clean-tags \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -rm -f config.status - -.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ -mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \ -maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile install-man1 uninstall-man1 install-man \ -uninstall-man tags mostlyclean-tags distclean-tags clean-tags \ -maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \ -installcheck-am installcheck all-recursive-am install-exec-am \ -install-exec install-data-am install-data install-am install \ -uninstall-am uninstall all-redirect all-am all installdirs \ -mostlyclean-generic distclean-generic clean-generic \ -maintainer-clean-generic clean mostlyclean distclean maintainer-clean - -# 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: -#remove the symlinka: - rm $(distdir)/INSTALL - echo Links $(VERSION) -- How To Install > $(distdir)/INSTALL - echo Links $(VERSION) -- How To Install | tr -c '\n' '-' >> $(distdir)/INSTALL - echo >> $(distdir)/INSTALL - cat $(srcdir)/INSTALL >> $(distdir)/INSTALL - -atheos.o: $(srcdir)/atheos.cpp - $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c $(srcdir)/atheos.cpp - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/beos.c b/beos.c @@ -1,265 +0,0 @@ -/* beos.c - * (c) 2002 Mikulas Patocka - * This file is a part of the Links program, released under GPL - */ - -#if defined(__BEOS__) || defined(__HAIKU__) - -#include "com-defs.h" - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <be/kernel/OS.h> - -#define SHS 128 - -#ifndef MAXINT -#define MAXINT 0x7fffffff -#endif - -#ifdef __HAIKU__ -int closesocket(int); -#endif - -#include "beos.h" - -int be_read(int s, void *ptr, int len) -{ - if (s >= SHS) return recv(s - SHS, ptr, len, 0); - return read(s, ptr, len); -} - -int be_write(int s, void *ptr, int len) -{ - if (s >= SHS) return send(s - SHS, ptr, len, 0); - return write(s, ptr, len); -} - -int be_close(int s) -{ - if (s >= SHS) return closesocket(s - SHS); - return close(s); -} - -int be_socket(int af, int sock, int prot) -{ - int h = socket(af, sock, prot); - if (h < 0) return h; - return h + SHS; -} - -int be_connect(int s, struct sockaddr *sa, int sal) -{ - return connect(s - SHS, sa, sal); -} - -int be_getpeername(int s, struct sockaddr *sa, int *sal) -{ - return getpeername(s - SHS, sa, sal); -} - -int be_getsockname(int s, struct sockaddr *sa, int *sal) -{ - return getsockname(s - SHS, sa, sal); -} - -int be_listen(int s, int c) -{ - return listen(s - SHS, c); -} - -int be_accept(int s, struct sockaddr *sa, int *sal) -{ - int a = accept(s - SHS, sa, sal); - if (a < 0) return -1; - return a + SHS; -} - -int be_bind(int s, struct sockaddr *sa, int sal) -{ - /*struct sockaddr_in *sin = (struct sockaddr_in *)sa; - if (!ntohs(sin->sin_port)) { - int i; - for (i = 16384; i < 49152; i++) { - sin->sin_port = htons(i); - if (!be_bind(s, sa, sal)) return 0; - } - return -1; - }*/ - if (bind(s - SHS, sa, sal)) return -1; - getsockname(s - SHS, sa, &sal); - return 0; -} - -#define PIPE_RETRIES 10 - -int be_pipe(int *fd) -{ - int s1, s2, s3, l; - struct sockaddr_in sa1, sa2; - int retry_count = 0; - again: - if ((s1 = be_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { - /*perror("socket1");*/ - goto fatal_retry; - } - if ((s2 = be_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { - /*perror("socket2");*/ - be_close(s1); - goto fatal_retry; - } - memset(&sa1, 0, sizeof(sa1)); - sa1.sin_family = AF_INET; - sa1.sin_port = htons(0); - sa1.sin_addr.s_addr = INADDR_ANY; - if (be_bind(s1, (struct sockaddr *)&sa1, sizeof(sa1))) { - /*perror("bind");*/ - clo: - be_close(s1); - be_close(s2); - goto fatal_retry; - } - if (be_listen(s1, 1)) { - /*perror("listen");*/ - goto clo; - } - if (be_connect(s2, (struct sockaddr *)&sa1, sizeof(sa1))) { - /*perror("connect");*/ - goto clo; - } - l = sizeof(sa2); - if ((s3 = be_accept(s1, (struct sockaddr *)&sa2, &l)) < 0) { - /*perror("accept");*/ - goto clo; - } - be_getsockname(s3, (struct sockaddr *)&sa1, &l); - if (sa1.sin_addr.s_addr != sa2.sin_addr.s_addr) { - be_close(s3); - goto clo; - } - be_close(s1); - fd[0] = s2; - fd[1] = s3; - return 0; - - fatal_retry: - if (++retry_count > PIPE_RETRIES) return -1; - sleep(1); - goto again; -} - -int be_select(int n, struct fd_set *rd, struct fd_set *wr, struct fd_set *exc, struct timeval *tm) -{ - int i, s; - struct fd_set d, rrd; -retry: - FD_ZERO(&d); - if (!rd) rd = &d; - if (!wr) wr = &d; - if (!exc) exc = &d; - if (n >= FD_SETSIZE) n = FD_SETSIZE; - FD_ZERO(exc); - for (i = 0; i < n; i++) if ((i < SHS && FD_ISSET(i, rd)) || FD_ISSET(i, wr)) { - for (i = SHS; i < n; i++) FD_CLR(i, rd); - return MAXINT; - } - FD_ZERO(&rrd); - for (i = SHS; i < n; i++) if (FD_ISSET(i, rd)) FD_SET(i - SHS, &rrd); - if ((s = select(FD_SETSIZE, &rrd, &d, &d, tm)) < 0) { - if (errno == EINTR) goto retry; - FD_ZERO(rd); - return 0; - } - FD_ZERO(rd); - for (i = SHS; i < n; i++) if (FD_ISSET(i - SHS, &rrd)) FD_SET(i, rd); - return s; -} - -#ifndef SO_ERROR -#define SO_ERROR 10001 -#endif - -int be_getsockopt(int s, int level, int optname, void *optval, int *optlen) -{ - if (optname == SO_ERROR && *optlen >= sizeof(int)) { - *(int *)optval = 0; - *optlen = sizeof(int); - return 0; - } - return -1; -} - -static int ihpipe[2]; - -static int inth; - -static void input_handle_th(void *p) -{ - char c; - int b = 0; - setsockopt(ihpipe[1], SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); - while (1) if (read(0, &c, 1) == 1) be_write(ihpipe[1], &c, 1); -} - -int get_input_handle(void) -{ - static int h = -1; - if (h >= 0) return h; - if (be_pipe(ihpipe) < 0) return -1; - if ((inth = start_thr(input_handle_th, NULL, "input_thread")) < 0) { - closesocket(ihpipe[0]); - closesocket(ihpipe[1]); - fatal_exit("Can't spawn input thread"); - } - return h = ihpipe[0]; -} - -void block_stdin(void) -{ - suspend_thread(inth); -} - -void unblock_stdin(void) -{ - resume_thread(inth); -} - -/*int ohpipe[2]; - -#define O_BUF 16384 - -static void output_handle_th(void *p) -{ - char *c = malloc(O_BUF); - int r, b = 0; - if (!c) return; - setsockopt(ohpipe[1], SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); - while ((r = be_read(ohpipe[0], c, O_BUF)) > 0) write(1, c, r); - free(c); -} - -int get_output_handle(void) -{ - static int h = -1; - if (h >= 0) return h; - if (be_pipe(ohpipe) < 0) return -1; - if (start_thr(output_handle_th, NULL, "output_thread") < 0) { - closesocket(ohpipe[0]); - closesocket(ohpipe[1]); - fatal_exit("Can't spawn output thread"); - } - return h = ohpipe[1]; -}*/ - -#else - -typedef int beos_c_no_empty_unit; - -#endif diff --git a/bfu.c b/bfu.c @@ -68,18 +68,14 @@ static inline int is_utf_8(struct terminal *term) #ifdef G if (F) return 1; #endif -#ifdef ENABLE_UTF8 if (term_charset(term) == utf8_table) return 1; -#endif return 0; } static inline int ttxtlen(struct terminal *term, unsigned char *s) { -#ifdef ENABLE_UTF8 if (term_charset(term) == utf8_table) return strlen_utf8(s); -#endif return (int)strlen(cast_const_char s); } @@ -1580,10 +1576,8 @@ static int check_local_ip_address_internal(struct dialog_data *dlg, struct dialo if (!*p) { return 0; } -#ifdef SUPPORT_IPV6 if (pf == PF_INET6) rs = numeric_ipv6_address(p, NULL, NULL); else -#endif rs = numeric_ip_address(p, NULL); if (rs) { msg_box(dlg->win->term, NULL, TEXT_(T_BAD_IP_ADDRESS), AL_CENTER, TEXT_(T_INVALID_IP_ADDRESS_SYNTAX), NULL, 1, TEXT_(T_CANCEL), NULL, B_ENTER | B_ESC); @@ -1623,11 +1617,7 @@ int check_local_ip_address(struct dialog_data *dlg, struct dialog_item_data *di) int check_local_ipv6_address(struct dialog_data *dlg, struct dialog_item_data *di) { -#ifdef SUPPORT_IPV6 return check_local_ip_address_internal(dlg, di, PF_INET6); -#else - return 0; -#endif } int cancel_dialog(struct dialog_data *dlg, struct dialog_item_data *di) diff --git a/bookmark.c b/bookmark.c @@ -631,11 +631,7 @@ void init_bookmarks(void) unsigned char *e; safe_strncpy(bookmarks_file, links_home ? links_home : (unsigned char*)"", MAX_STR_LEN); e = cast_uchar strchr(cast_const_char bookmarks_file, 0); -#ifdef DOS_FS_8_3 - safe_strncpy(e, cast_uchar "bookmark.htm", MAX_STR_LEN - (e - bookmarks_file)); -#else safe_strncpy(e, cast_uchar "bookmarks.html", MAX_STR_LEN - (e - bookmarks_file)); -#endif } bookmark_ld.codepage = utf8_table; diff --git a/cache.c b/cache.c @@ -5,9 +5,7 @@ #include "links.h" -#if defined(HAVE_SEARCH_H) && defined(HAVE_TDELETE) && defined(HAVE_TFIND) && defined(HAVE_TSEARCH) #define USE_TREE -#endif static struct list_head cache = {&cache, &cache}; @@ -473,9 +471,7 @@ void delete_cache_entry(struct cache_entry *e) if (e->head) mem_free(e->head); if (e->redirect) mem_free(e->redirect); if (e->ip_address) mem_free(e->ip_address); -#ifdef HAVE_SSL if (e->ssl_info) mem_free(e->ssl_info); -#endif mem_free(e); } @@ -547,10 +543,8 @@ ret: void init_cache(void) { -#ifdef HAVE_GETPAGESIZE int getpg; EINTRLOOP(getpg, getpagesize()); if (getpg > 0 && getpg < 0x10000 && !(getpg & (getpg - 1))) page_size = getpg; -#endif register_cache_upcall(shrink_file_cache, 0, cast_uchar "file"); } diff --git a/compress.c b/compress.c @@ -58,7 +58,6 @@ static void decompress_error(struct terminal *term, struct cache_entry *ce, unsi #endif -#ifdef HAVE_ZLIB #include <zlib.h> static int decode_gzip(struct terminal *term, struct cache_entry *ce, int defl, int *errp) { @@ -261,445 +260,10 @@ static int decode_gzip(struct terminal *term, struct cache_entry *ce, int defl, ce->decompressed = mem_realloc(ce->decompressed, ce->decompressed_len); return 0; } -#endif - -#ifdef HAVE_BROTLI -#if defined(__TINYC__) && defined(__STDC_VERSION__) -#undef __STDC_VERSION__ -#endif -#include <brotli/decode.h> -static void *brotli_alloc(void *opaque, size_t size) -{ - return mem_alloc_mayfail(size); -} -static void brotli_free(void *opaque, void *ptr) -{ - if (ptr) mem_free(ptr); -} -static int decode_brotli(struct terminal *term, struct cache_entry *ce, int *errp) -{ - unsigned char err; - BrotliDecoderState *br; - const unsigned char *next_in; - size_t avail_in; - unsigned char *next_out; - size_t avail_out; - off_t offset; - BrotliDecoderResult res; - unsigned char *p; - struct fragment *f; - struct list_head *lf; - size_t size; - - err = 0; - decoder_memory_init(&p, &size, ce->length); - next_out = p; - avail_out = size; - br = BrotliDecoderCreateInstance(brotli_alloc, brotli_free, NULL); - if (!br) { - decompress_error(term, ce, cast_uchar "brotli", TEXT_(T_OUT_OF_MEMORY), errp); - err = 1; - goto after_inflateend; - } - - offset = 0; - foreach(struct fragment, f, lf, ce->frag) { - if (f->offset != offset) break; - next_in = f->data; - avail_in = (size_t)f->length; - if ((off_t)avail_in != f->length) overalloc(); - repeat_frag: - res = BrotliDecoderDecompressStream(br, &avail_in, &next_in, &avail_out, &next_out, NULL); - if (res == BROTLI_DECODER_RESULT_ERROR) { - decompress_error(term, ce, cast_uchar "brotli", cast_uchar BrotliDecoderErrorString(BrotliDecoderGetErrorCode(br)), errp); - err = 1; - goto finish; - } - if (!avail_out) { - size_t addsize; - if (decoder_memory_expand(&p, size, &addsize) < 0) { - decompress_error(term, ce, cast_uchar "brotli", TEXT_(T_OUT_OF_MEMORY), errp); - err = 1; - goto finish; - } - next_out = p + size; - avail_out = addsize; - size += addsize; - goto repeat_frag; - } - if (avail_in) goto repeat_frag; - /* - BrotliDecoderHasMoreOutput(br) returns BROTLI_BOOL which is defined differently for different compilers, so we must not use it - if (BrotliDecoderHasMoreOutput(br)) goto repeat_frag; - */ - offset += f->length; - } - - finish: - BrotliDecoderDestroyInstance(br); - after_inflateend: - if (err && next_out == p) { - mem_free(p); - return 1; - } - ce->decompressed = p; - ce->decompressed_len = next_out - p; - decompressed_cache_size += ce->decompressed_len; - ce->decompressed = mem_realloc(ce->decompressed, ce->decompressed_len); - return 0; -} -#endif - -#ifdef HAVE_BZIP2 -#include <bzlib.h> -static int decode_bzip2(struct terminal *term, struct cache_entry *ce, int *errp) -{ - unsigned char err; - unsigned char memory_error; - bz_stream z; - off_t offset; - int r; - unsigned char *p; - struct fragment *f; - struct list_head *lf; - size_t size; - - retry_after_memory_error: - err = 0; - memory_error = 0; - decoder_memory_init(&p, &size, ce->length); - memset(&z, 0, sizeof z); - z.next_in = NULL; - z.avail_in = 0; - z.next_out = cast_char p; - z.avail_out = (unsigned)size; - z.bzalloc = NULL; - z.bzfree = NULL; - z.opaque = NULL; - r = BZ2_bzDecompressInit(&z, 0, 0); - init_failed: - switch (r) { - case BZ_OK: break; - case BZ_MEM_ERROR: memory_error = 1; - err = 1; - goto after_inflateend; - case BZ_PARAM_ERROR: - decompress_error(term, ce, cast_uchar "bzip2", cast_uchar "Invalid parameter", errp); - err = 1; - goto after_inflateend; - case BZ_CONFIG_ERROR: decompress_error(term, ce, cast_uchar "bzip2", cast_uchar "Bzlib is miscompiled", errp); - err = 1; - goto after_inflateend; - default: decompress_error(term, ce, cast_uchar "bzip2", cast_uchar "Unknown return value on BZ2_bzDecompressInit", errp); - err = 1; - goto after_inflateend; - } - offset = 0; - foreach(struct fragment, f, lf, ce->frag) { - if (f->offset != offset) break; - z.next_in = cast_char f->data; - z.avail_in = (unsigned)f->length; - if ((off_t)z.avail_in != f->length) overalloc(); - repeat_frag: - r = BZ2_bzDecompress(&z); - switch (r) { - case BZ_OK: break; - case BZ_STREAM_END: - r = BZ2_bzDecompressEnd(&z); - if (r != BZ_OK) goto end_failed; - r = BZ2_bzDecompressInit(&z, 0, 0); - if (r != BZ_OK) goto init_failed; - break; - case BZ_DATA_ERROR_MAGIC: - case BZ_DATA_ERROR: decompress_error(term, ce, cast_uchar "bzip2", TEXT_(T_COMPRESSED_ERROR), errp); - err = 1; - goto finish; - case BZ_PARAM_ERROR: decompress_error(term, ce, cast_uchar "bzip2", cast_uchar "Internal error on BZ2_bzDecompress", errp); - err = 1; - goto finish; - case BZ_MEM_ERROR: - mem_error: memory_error = 1; - err = 1; - goto finish; - default: decompress_error(term, ce, cast_uchar "bzip2", cast_uchar "Unknown return value on BZ2_bzDecompress", errp); - err = 1; - break; - } - if (!z.avail_out) { - size_t addsize; - if (decoder_memory_expand(&p, size, &addsize) < 0) - goto mem_error; - z.next_out = cast_char(p + size); - z.avail_out = (unsigned)addsize; - size += addsize; - goto repeat_frag; - } - if (z.avail_in) goto repeat_frag; - offset += f->length; - } - finish: - r = BZ2_bzDecompressEnd(&z); - end_failed: - switch (r) { - case BZ_OK: break; - case BZ_PARAM_ERROR: decompress_error(term, ce, cast_uchar "bzip2", cast_uchar "Internal error on BZ2_bzDecompressEnd", errp); - err = 1; - break; - case BZ_MEM_ERROR: memory_error = 1; - err = 1; - break; - default: decompress_error(term, ce, cast_uchar "bzip2", cast_uchar "Unknown return value on BZ2_bzDecompressEnd", errp); - err = 1; - break; - } - after_inflateend: - if (memory_error) { - mem_free(p); - if (out_of_memory(0, NULL, 0)) - goto retry_after_memory_error; - decompress_error(term, ce, cast_uchar "bzip2", TEXT_(T_OUT_OF_MEMORY), errp); - return 1; - } - if (err && (unsigned char *)z.next_out == p) { - mem_free(p); - return 1; - } - ce->decompressed = p; - ce->decompressed_len = (unsigned char *)z.next_out - (unsigned char *)p; - decompressed_cache_size += ce->decompressed_len; - ce->decompressed = mem_realloc(ce->decompressed, ce->decompressed_len); - return 0; -} -#endif - -#ifdef HAVE_LZMA -#undef internal -#include <lzma.h> -#define internal internal_ -static int decode_lzma(struct terminal *term, struct cache_entry *ce, int *errp) -{ - unsigned char err; - unsigned char memory_error; - lzma_stream z = LZMA_STREAM_INIT; - off_t offset; - int r; - unsigned char *p; - struct fragment *f; - struct list_head *lf; - size_t size; - - retry_after_memory_error: - err = 0; - memory_error = 0; - decoder_memory_init(&p, &size, ce->length); - z.next_in = NULL; - z.avail_in = 0; - z.next_out = p; - z.avail_out = size; - r = lzma_auto_decoder(&z, UINT64_MAX, 0); - init_failed: - switch (r) { - case LZMA_OK: break; - case LZMA_MEM_ERROR: memory_error = 1; - err = 1; - goto after_inflateend; - case LZMA_OPTIONS_ERROR: - decompress_error(term, ce, cast_uchar "lzma", cast_uchar "Invalid parameter", errp); - err = 1; - goto after_inflateend; - case LZMA_PROG_ERROR: decompress_error(term, ce, cast_uchar "lzma", cast_uchar "Lzma is miscompiled", errp); - err = 1; - goto after_inflateend; - default: decompress_error(term, ce, cast_uchar "lzma", cast_uchar "Unknown return value on lzma_auto_decoder", errp); - err = 1; - goto after_inflateend; - } - offset = 0; - foreach(struct fragment, f, lf, ce->frag) { - if (f->offset != offset) break; - z.next_in = f->data; - z.avail_in = (size_t)f->length; - if ((off_t)z.avail_in != f->length) overalloc(); - repeat_frag: - r = lzma_code(&z, LZMA_RUN); - switch (r) { - case LZMA_OK: - case LZMA_NO_CHECK: - case LZMA_UNSUPPORTED_CHECK: - case LZMA_GET_CHECK: - break; - case LZMA_STREAM_END: - lzma_end(&z); - r = lzma_auto_decoder(&z, UINT64_MAX, 0); - if (r != LZMA_OK) goto init_failed; - break; - case LZMA_MEM_ERROR: - mem_error: memory_error = 1; - err = 1; - goto finish; - case LZMA_MEMLIMIT_ERROR: - decompress_error(term, ce, cast_uchar "lzma", cast_uchar "Memory limit was exceeded", errp); - err = 1; - goto finish; - case LZMA_FORMAT_ERROR: - case LZMA_DATA_ERROR: - case LZMA_BUF_ERROR: - decompress_error(term, ce, cast_uchar "lzma", TEXT_(T_COMPRESSED_ERROR), errp); - err = 1; - goto finish; - case LZMA_OPTIONS_ERROR:decompress_error(term, ce, cast_uchar "lzma", cast_uchar "File contains unsupported options", errp); - err = 1; - goto finish; - case LZMA_PROG_ERROR: decompress_error(term, ce, cast_uchar "lzma", cast_uchar "Lzma is miscompiled", errp); - err = 1; - goto finish; - default: decompress_error(term, ce, cast_uchar "lzma", cast_uchar "Unknown return value on lzma_code", errp); - err = 1; - break; - } - if (!z.avail_out) { - size_t addsize; - if (decoder_memory_expand(&p, size, &addsize) < 0) - goto mem_error; - z.next_out = p + size; - z.avail_out = addsize; - size += addsize; - goto repeat_frag; - } - if (z.avail_in) goto repeat_frag; - offset += f->length; - } - finish: - lzma_end(&z); - after_inflateend: - if (memory_error) { - mem_free(p); - if (out_of_memory(0, NULL, 0)) - goto retry_after_memory_error; - decompress_error(term, ce, cast_uchar "lzma", TEXT_(T_OUT_OF_MEMORY), errp); - return 1; - } - if (err && (unsigned char *)z.next_out == p) { - mem_free(p); - return 1; - } - ce->decompressed = p; - ce->decompressed_len = (unsigned char *)z.next_out - (unsigned char *)p; - decompressed_cache_size += ce->decompressed_len; - ce->decompressed = mem_realloc(ce->decompressed, ce->decompressed_len); - return 0; -} -#endif -#ifdef HAVE_LZIP -#include <lzlib.h> -static int decode_lzip(struct terminal *term, struct cache_entry *ce, int *errp) -{ - unsigned char err; - unsigned char memory_error; - void *lz; - off_t offset; - int r; - enum LZ_Errno le; - unsigned char *p; - struct fragment *f; - struct list_head *lf; - size_t size; - size_t used_size; - retry_after_memory_error: - err = 0; - memory_error = 0; - decoder_memory_init(&p, &size, ce->length); - used_size = 0; - lz = LZ_decompress_open(); - if (!lz) { - err = 1; - memory_error = 1; - goto after_inflateend; - } - if (LZ_decompress_errno(lz) != LZ_ok) { -lz_error: - le = LZ_decompress_errno(lz); - if (0) -mem_error: le = LZ_mem_error; - err = 1; - if (le == LZ_mem_error) { - memory_error = 1; - } else if (!ce->incomplete) { - decompress_error(term, ce, cast_uchar "lzip", cast_uchar LZ_strerror(le), errp); - } - goto finish; - } - offset = 0; - foreach(struct fragment, f, lf, ce->frag) { - unsigned char *current_ptr; - int current_len; - if (f->offset != offset) break; - current_ptr = f->data; - current_len = (int)f->length; - while (current_len) { - r = LZ_decompress_write(lz, current_ptr, current_len); - if (r == -1) - goto lz_error; - current_ptr += r; - current_len -= r; - do { - if (used_size == size) { - size_t addsize; - if (decoder_memory_expand(&p, size, &addsize) < 0) - goto mem_error; - size += addsize; - } - r = LZ_decompress_read(lz, p + used_size, (int)(size - used_size)); - if (r == -1) - goto lz_error; - used_size += r; - } while (r); - } - offset += f->length; - } - r = LZ_decompress_finish(lz); - if (r == -1) - goto lz_error; - while ((r = LZ_decompress_finished(lz)) == 0) { - if (used_size == size) { - size_t addsize; - if (decoder_memory_expand(&p, size, &addsize) < 0) - goto mem_error; - size += addsize; - } - r = LZ_decompress_read(lz, p + used_size, (int)(size - used_size)); - if (r == -1) - goto lz_error; - used_size += r; - } - if (r == -1) - goto lz_error; - -finish: - LZ_decompress_close(lz); -after_inflateend: - if (memory_error) { - mem_free(p); - if (out_of_memory(0, NULL, 0)) - goto retry_after_memory_error; - decompress_error(term, ce, cast_uchar "lzip", TEXT_(T_OUT_OF_MEMORY), errp); - return 1; - } - if (err && !used_size) { - mem_free(p); - return 1; - } - ce->decompressed = p; - ce->decompressed_len = used_size; - decompressed_cache_size += ce->decompressed_len; - ce->decompressed = mem_realloc(ce->decompressed, ce->decompressed_len); - return 0; -} -#endif int get_file_by_term(struct terminal *term, struct cache_entry *ce, unsigned char **start, unsigned char **end, int *errp) { @@ -719,42 +283,12 @@ int get_file_by_term(struct terminal *term, struct cache_entry *ce, unsigned cha } enc = get_content_encoding(ce->head, ce->url, 0); if (enc) { -#ifdef HAVE_ZLIB if (!casestrcmp(enc, cast_uchar "gzip") || !casestrcmp(enc, cast_uchar "x-gzip") || !casestrcmp(enc, cast_uchar "deflate")) { int defl = !casestrcmp(enc, cast_uchar "deflate"); mem_free(enc); if (decode_gzip(term, ce, defl, errp)) goto uncompressed; goto return_decompressed; } -#endif -#ifdef HAVE_BROTLI - if (!casestrcmp(enc, cast_uchar "br")) { - mem_free(enc); - if (decode_brotli(term, ce, errp)) goto uncompressed; - goto return_decompressed; - } -#endif -#ifdef HAVE_BZIP2 - if (!casestrcmp(enc, cast_uchar "bzip2")) { - mem_free(enc); - if (decode_bzip2(term, ce, errp)) goto uncompressed; - goto return_decompressed; - } -#endif -#ifdef HAVE_LZMA - if (!casestrcmp(enc, cast_uchar "lzma") || !casestrcmp(enc, cast_uchar "lzma2")) { - mem_free(enc); - if (decode_lzma(term, ce, errp)) goto uncompressed; - goto return_decompressed; - } -#endif -#ifdef HAVE_LZIP - if (!casestrcmp(enc, cast_uchar "lzip")) { - mem_free(enc); - if (decode_lzip(term, ce, errp)) goto uncompressed; - goto return_decompressed; - } -#endif mem_free(enc); goto uncompressed; } @@ -799,7 +333,6 @@ void free_decompressed_data(struct cache_entry *e) void add_compress_methods(unsigned char **s, int *l) { int cl = 0; -#ifdef HAVE_ZLIB { if (!cl) cl = 1; else add_to_str(s, l, cast_uchar ", "); add_to_str(s, l, cast_uchar "ZLIB"); @@ -809,50 +342,6 @@ void add_compress_methods(unsigned char **s, int *l) add_to_str(s, l, cast_uchar ")"); #endif } -#endif -#ifdef HAVE_BROTLI - { - unsigned bv = BrotliDecoderVersion(); - if (!cl) cl = 1; else add_to_str(s, l, cast_uchar ", "); - add_to_str(s, l, cast_uchar "BROTLI"); - add_to_str(s, l, cast_uchar " ("); - add_num_to_str(s, l, bv >> 24); - add_to_str(s, l, cast_uchar "."); - add_num_to_str(s, l, (bv >> 12) & 0xfff); - add_to_str(s, l, cast_uchar "."); - add_num_to_str(s, l, bv & 0xfff); - add_to_str(s, l, cast_uchar ")"); - } -#endif -#ifdef HAVE_BZIP2 - { - unsigned char *b = (unsigned char *)BZ2_bzlibVersion(); - int bl = (int)strcspn(cast_const_char b, ","); - if (!cl) cl = 1; else add_to_str(s, l, cast_uchar ", "); - add_to_str(s, l, cast_uchar "BZIP2"); - add_to_str(s, l, cast_uchar " ("); - add_bytes_to_str(s, l, b, bl); - add_to_str(s, l, cast_uchar ")"); - } -#endif -#ifdef HAVE_LZMA - { - if (!cl) cl = 1; else add_to_str(s, l, cast_uchar ", "); - add_to_str(s, l, cast_uchar "LZMA"); - add_to_str(s, l, cast_uchar " ("); - add_to_str(s, l, cast_uchar lzma_version_string()); - add_to_str(s, l, cast_uchar ")"); - } -#endif -#ifdef HAVE_LZIP - { - if (!cl) cl = 1; else add_to_str(s, l, cast_uchar ", "); - add_to_str(s, l, cast_uchar "LZIP"); - add_to_str(s, l, cast_uchar " ("); - add_to_str(s, l, cast_uchar LZ_version()); - add_to_str(s, l, cast_uchar ")"); - } -#endif } #endif diff --git a/connect.c b/connect.c @@ -53,7 +53,6 @@ static void log_number(int number) #define log_number(x) do { } while (0) #endif -#ifdef HAVE_SSL static void log_ssl_error(unsigned char *url, int line, int ret1, int ret2) { #ifndef LOG_SSL @@ -63,9 +62,7 @@ static void log_ssl_error(unsigned char *url, int line, int ret1, int ret2) unsigned char *u, *uu; u = stracpy(url); if ((uu = cast_uchar strchr(cast_const_char u, POST_CHAR))) *uu = 0; -#if defined(HAVE_SSL_LOAD_ERROR_STRINGS) || defined(SSL_load_error_strings) SSL_load_error_strings(); -#endif #if defined(HAVE_OPENSSL) && !defined(OPENSSL_NO_STDIO) ERR_print_errors_fp(stderr); #else @@ -88,7 +85,6 @@ void clear_ssl_errors(int line) if (ERR_peek_error()) log_ssl_error(cast_uchar "", line, 0, 0); } -#endif static void connected(void *); static void update_dns_priority(struct connection *); @@ -127,7 +123,6 @@ int socket_and_bind(int pf, unsigned char *address) } break; } -#ifdef SUPPORT_IPV6 case PF_INET6: { struct sockaddr_in6 sa; unsigned char addr[16]; @@ -141,9 +136,7 @@ int socket_and_bind(int pf, unsigned char *address) sa.sin6_family = AF_INET6; memcpy(&sa.sin6_addr, addr, 16); sa.sin6_port = htons(0); -#ifdef SUPPORT_IPV6_SCOPE sa.sin6_scope_id = scope; -#endif EINTRLOOP(rs, bind(s, (struct sockaddr *)(void *)&sa, sizeof sa)); if (rs) { int sv_errno = errno; @@ -153,7 +146,6 @@ int socket_and_bind(int pf, unsigned char *address) } break; } -#endif default: { EINTRLOOP(rs, close(s)); errno = EINVAL; @@ -245,7 +237,6 @@ void make_connection(struct connection *c, int port, int *sock, void (*func)(str int is_ipv6(int h) { -#ifdef SUPPORT_IPV6 union { struct sockaddr sa; struct sockaddr_in sin; @@ -257,9 +248,6 @@ int is_ipv6(int h) EINTRLOOP(rs, getsockname(h, &u.sa, &len)); if (rs) return 0; return u.sa.sa_family == AF_INET6; -#else - return 0; -#endif } int get_pasv_socket(struct connection *c, int cc, int *sock, unsigned char *port) @@ -300,7 +288,6 @@ int get_pasv_socket(struct connection *c, int cc, int *sock, unsigned char *port return -1; } -#ifdef SUPPORT_IPV6 int get_pasv_socket_ipv6(struct connection *c, int cc, int *sock, unsigned char *result) { int s; @@ -354,9 +341,7 @@ int get_pasv_socket_ipv6(struct connection *c, int cc, int *sock, unsigned char retry_connection(c); return -1; } -#endif -#ifdef HAVE_SSL static void ssl_setup_downgrade(struct connection *c) { #if !defined(HAVE_NSS) @@ -460,7 +445,6 @@ static void ssl_want_io(void *c_) break; } } -#endif static void handle_socks(void *c_) { @@ -575,13 +559,11 @@ void retry_connect(struct connection *c, int err, int ssl_downgrade) { struct conn_info *b = c->newconn; if (!b->l.addr_index) b->first_error = err; -#ifdef HAVE_SSL if (c->ssl) { freeSSL(c->ssl); if (is_proxy_url(c->url)) c->ssl = NULL; else c->ssl = DUMMY; } -#endif if (ssl_downgrade) { log_string(cast_uchar "\nSSL DOWNGRADE\n"); close_socket(b->sock); @@ -616,10 +598,8 @@ static void try_connect(struct connection *c) /*debug("%p: %p %d %d\n", b, addr, b->l.addr_index, addr->af);*/ if (addr->af == AF_INET) { s = socket_and_bind(PF_INET, bind_ip_address); -#ifdef SUPPORT_IPV6 } else if (addr->af == AF_INET6) { s = socket_and_bind(PF_INET6, bind_ipv6_address); -#endif } else { setcstate(c, S_INTERNAL); abort_connection(c); @@ -649,27 +629,20 @@ static void try_connect(struct connection *c) memcpy(&sa.sin_addr.s_addr, addr->addr, 4); sa.sin_port = htons(p); EINTRLOOP(rs, connect(s, (struct sockaddr *)(void *)&sa, sizeof sa)); -#ifdef SUPPORT_IPV6 } else if (addr->af == AF_INET6) { struct sockaddr_in6 sa; memset(&sa, 0, sizeof sa); sa.sin6_family = AF_INET6; memcpy(&sa.sin6_addr, addr->addr, 16); -#ifdef SUPPORT_IPV6_SCOPE sa.sin6_scope_id = addr->scope_id; -#endif sa.sin6_port = htons(p); EINTRLOOP(rs, connect(s, (struct sockaddr *)(void *)&sa, sizeof sa)); -#endif } else { rs = -1; errno = EINVAL; } if (rs) { if (errno != EALREADY && errno != EINPROGRESS) { -#ifdef BEOS - if (errno == EWOULDBLOCK) errno = ETIMEDOUT; -#endif retry_connect(c, get_error_from_errno(errno), 0); return; } @@ -685,7 +658,6 @@ static void try_connect(struct connection *c) } } -#ifdef HAVE_SSL void continue_connection(struct connection *c, int *sock, void (*func)(struct connection *)) { struct conn_info *b; @@ -700,7 +672,6 @@ void continue_connection(struct connection *c, int *sock, void (*func)(struct co log_string(cast_uchar "\nCONTINUE CONNECTION\n"); connected(c); } -#endif static void connected(void *c_) { @@ -728,9 +699,6 @@ static void connected(void *c_) && err != EISCONN #endif ) { -#ifdef DOS - if (err == EALREADY) err = ETIMEDOUT; -#endif retry_connect(c, get_error_from_errno(err), 0); return; } @@ -743,7 +711,6 @@ static void connected(void *c_) return; } log_string(cast_uchar "\nCONNECTED\n"); -#ifdef HAVE_SSL if (c->ssl) { int ret1, ret2; unsigned char *orig_url = remove_proxy_prefix(c->url); @@ -784,9 +751,7 @@ static void connected(void *c_) ssl_setup_downgrade(c); #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME if (h[0] == '[' || !numeric_ip_address(h, NULL) -#ifdef SUPPORT_IPV6 || !numeric_ipv6_address(h, NULL, NULL) -#endif ) goto skip_numeric_address; SSL_set_tlsext_host_name(c->ssl->ssl, h); skip_numeric_address: @@ -810,7 +775,6 @@ skip_numeric_address: return; } } -#endif connected_callback(c); } @@ -914,7 +878,6 @@ static void write_select(void *c_) for (wr = wb->pos; wr < wb->len; wr++) printf("%c", wb->data[wr]); printf("-\n");*/ -#ifdef HAVE_SSL if (c->ssl) { set_handlers(wb->sock, NULL, write_select, c); if ((wr = SSL_write(c->ssl->ssl, (void *)(wb->data + wb->pos), wb->len - wb->pos)) <= 0) { @@ -935,7 +898,6 @@ static void write_select(void *c_) } c->ssl->bytes_written += wr; } else -#endif { EINTRLOOP(wr, (int)write(wb->sock, wb->data + wb->pos, wb->len - wb->pos)); if (wr <= 0) { @@ -998,7 +960,6 @@ read_more: rb = mem_realloc(rb, sizeof(struct read_buffer) + rb->len + READ_SIZE); c->buffer = rb; -#ifdef HAVE_SSL if (c->ssl) { if ((rd = SSL_read(c->ssl->ssl, (void *)(rb->data + rb->len), READ_SIZE)) <= 0) { int err; @@ -1025,7 +986,6 @@ read_more: } c->ssl->bytes_read += rd; } else -#endif { EINTRLOOP(rd, (int)read(rb->sock, rb->data + rb->len, READ_SIZE)); if (rd <= 0) { @@ -1045,9 +1005,7 @@ read_more: total_read += rd; if ((rd == READ_SIZE -#ifdef HAVE_SSL || c->ssl -#endif ) && total_read <= TOTAL_READ) { if (can_read(rb->sock)) goto read_more; diff --git a/default.c b/default.c @@ -11,36 +11,18 @@ unsigned char system_name[MAX_STR_LEN]; static void get_system_name(void) { -#ifdef OS2 - if (!os_get_system_name(system_name)) - return; -#endif -#if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME) { struct utsname name; int rs; memset(&name, 0, sizeof name); EINTRLOOP(rs, uname(&name)); if (!rs) { -#ifdef OPENVMS - unsigned char * volatile p; -#endif unsigned char *str = init_str(); int l = 0; add_to_str(&str, &l, cast_uchar name.sysname); add_to_str(&str, &l, cast_uchar " "); -#ifdef OPENVMS - add_to_str(&str, &l, cast_uchar name.version); -#else add_to_str(&str, &l, cast_uchar name.release); -#endif add_to_str(&str, &l, cast_uchar " "); -#ifdef OPENVMS - p = cast_uchar name.nodename + sizeof(name.nodename); - if ((unsigned char *)(&name + 1) - p >= 16 && memchr(cast_const_char p, 0, 16)) - add_to_str(&str, &l, cast_uchar p); - else -#endif add_to_str(&str, &l, cast_uchar name.machine); if (l >= MAX_STR_LEN) str[MAX_STR_LEN - 1] = 0; strcpy(cast_char system_name, cast_const_char str); @@ -48,8 +30,6 @@ static void get_system_name(void) return; } } -#endif -#ifdef HAVE_POPEN /*if (0) { FILE *f; unsigned char *p; @@ -68,7 +48,6 @@ static void get_system_name(void) if (system_name[0]) return; } fail:*/ -#endif strcpy(cast_char system_name, SYSTEM_NAME); } @@ -197,14 +176,6 @@ static void get_compiler_name(void) 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); -#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); - #elif defined(__LCC__) sprintf(cast_char compiler_name, "LCC"); @@ -437,10 +408,6 @@ static unsigned char *p_arse_options(int argc, unsigned char *argv[], struct opt goto found; } uu: -#ifdef GRDRV_DIRECTFB - if (!strncmp(cast_const_char argv[-1], "--dfb:", 6)) - goto found; -#endif fprintf(stderr, "Unknown option %s\n", argv[-1]); return NULL; } else if (!u) u = argv[-1]; @@ -634,22 +601,12 @@ try_new_count: err = errno; goto unlink_err; } -#if defined(OPENVMS) - /* delete all versions of the file */ - count = 0; - do { - EINTRLOOP(rs, unlink(cast_const_char name)); - } while (!rs && ++count < 65536); -#elif !defined(RENAME_OVER_EXISTING_FILES) - EINTRLOOP(rs, unlink(cast_const_char name)); -#endif EINTRLOOP(rs, rename(cast_const_char tmp_name, cast_const_char name)); if (rs) { err = errno; goto unlink_err; } mem_free(tmp_name); -#if !defined(OS2) && !defined(OPENVMS) if (do_sync) { unsigned char *e, *le; tmp_name = stracpy(name); @@ -657,14 +614,6 @@ try_new_count: for (e = tmp_name; *e; e++) if (dir_sep(*e)) le = e; while (le > tmp_name && dir_sep(le[-1])) le--; if (le == tmp_name && dir_sep(*le)) le++; -#ifdef DOS_FS - if (le - tmp_name <= 2 && upcase(tmp_name[0]) >= 'A' && upcase(tmp_name[0]) <= 'Z' && tmp_name[1] == ':') { - if (dir_sep(tmp_name[2])) - le = tmp_name + 3; - else - le = tmp_name + 2; - } -#endif *le = 0; h = c_open(*tmp_name ? tmp_name : cast_uchar ".", O_RDONLY | O_NOCTTY); @@ -674,7 +623,6 @@ try_new_count: } mem_free(tmp_name); } -#endif return 0; @@ -687,17 +635,6 @@ try_new_count: return get_error_from_errno(err); } -#ifdef OPENVMS -static void translate_vms_to_unix(unsigned char **str) -{ - unsigned char *n; - if (!*str || strchr(cast_const_char *str, '/')) return; - n = cast_uchar decc$translate_vms(cast_const_char *str); - if (!n || (my_intptr_t)n == -1) return; - mem_free(*str); - *str = stracpy(n); -} -#endif static unsigned char *get_home(int *n) { @@ -715,53 +652,7 @@ static unsigned char *get_home(int *n) config_dir = stracpy(cast_uchar getenv("CONFIG_DIR")); if (n) *n = 1; -#ifdef WIN - if (!home) { - home = stracpy(cast_uchar getenv("APPDATA")); -#ifdef HAVE_CYGWIN_CONV_PATH - /* - * Newer Cygwin complains about windows-style path, so - * we have to convert it. - */ - if (home) { - unsigned char *new_path; - ssize_t sz = cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE, home, NULL, 0); - if (sz < 0) - goto skip_path_conv; - new_path = mem_alloc(sz); - sz = cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE, home, new_path, sz); - if (sz < 0) { - mem_free(new_path); - goto skip_path_conv; - } - mem_free(home); - home = new_path; -skip_path_conv:; - } -#endif - if (home) { - EINTRLOOP(rs, stat(cast_const_char home, &st)); - if (rs || !S_ISDIR(st.st_mode)) { - mem_free(home); - home = NULL; - } - } - } -#endif if (!home) home = stracpy(cast_uchar getenv("HOME")); -#ifdef WIN -/* When we run in Cygwin without Cygwin environment, it reports home "/". - Unfortunatelly, it can't write anything to that directory */ - if (home && !strcmp(cast_const_char home, "/")) { - mem_free(home); - home = NULL; - } -#endif -#ifdef OPENVMS - if (!home) home = stracpy(cast_uchar "/SYS$LOGIN"); - translate_vms_to_unix(&home); - translate_vms_to_unix(&config_dir); -#endif if (!home) { int i; home = stracpy(path_to_exe); @@ -795,22 +686,12 @@ skip_path_conv:; mem_free(config_dir); } else { add_dot_links: -#ifdef OPENVMS - add_to_strn(&home_links, cast_uchar "links"); -#else add_to_strn(&home_links, cast_uchar ".links"); -#endif } EINTRLOOP(rs, stat(cast_const_char home_links, &st)); if (rs) { EINTRLOOP(rs, mkdir(cast_const_char home_links, 0700)); if (!rs) goto home_creat; -#ifdef OPENVMS - if (errno == EEXIST) { - memset(&st, 0, sizeof st); - goto home_ok; - } -#endif if (config_dir) goto failed; goto first_failed; } @@ -823,21 +704,11 @@ skip_path_conv:; first_failed: mem_free(home_links); home_links = stracpy(home); -#ifdef DOS - add_to_strn(&home_links, cast_uchar "links.cfg"); -#else add_to_strn(&home_links, cast_uchar "links"); -#endif EINTRLOOP(rs, stat(cast_const_char home_links, &st)); if (rs) { EINTRLOOP(rs, mkdir(cast_const_char home_links, 0700)); if (!rs) goto home_creat; -#ifdef OPENVMS - if (errno == EEXIST) { - memset(&st, 0, sizeof st); - goto home_ok; - } -#endif goto failed; } if (S_ISDIR(st.st_mode)) goto home_ok; @@ -852,9 +723,7 @@ skip_path_conv:; if (n) *n = 0; if ((st.st_mode & 07777) != 0700) { home_creat: -#ifdef HAVE_CHMOD EINTRLOOP(rs, chmod(cast_const_char home_links, 0700)); -#endif } add_to_strn(&home_links, cast_uchar "/"); mem_free(home); @@ -1008,9 +877,6 @@ static unsigned char *cp_rd(struct option *o, unsigned char *c) int i; if (!tok) return cast_uchar "Missing argument"; if ((i = get_cp_index(tok)) == -1) e = cast_uchar "Unknown codepage"; -#ifndef ENABLE_UTF8 - else if (o->min == 1 && i == utf8_table) e = cast_uchar "UTF-8 can't be here"; -#endif else *(int *)o->ptr = i; mem_free(tok); return e; @@ -1222,11 +1088,6 @@ static unsigned char *term_rd(struct option *o, unsigned char *c) } else { if ((i = get_cp_index(w)) == -1) goto err_f; } -#ifndef ENABLE_UTF8 - if (i == utf8_table) { - i = 0; - } -#endif ts->character_set = i; mem_free(w); l = get_token_num(&c); @@ -1283,11 +1144,6 @@ static unsigned char *term2_rd(struct option *o, unsigned char *c) } else { if ((i = get_cp_index(w)) == -1) goto err_f; } -#ifndef ENABLE_UTF8 - if (i == utf8_table) { - i = 0; - } -#endif ts->character_set = i; mem_free(w); return NULL; @@ -1419,9 +1275,7 @@ static unsigned char *ipv6_rd(struct option *o, unsigned char *c) unsigned char *e; e = str_rd(o, c); if (e) return e; -#ifdef SUPPORT_IPV6 if (*(unsigned char *)o->ptr && numeric_ipv6_address(o->ptr, NULL, NULL) == -1) return cast_uchar "Invalid IPv6 address"; -#endif return NULL; } @@ -1729,11 +1583,7 @@ fprintf(stdout, "%s%s%s%s%s%s\n", " 2 - reject invalid certificate\n" "\n" " -ssl.builtin-certificates <0>/<1>\n" -#if defined(DOS) || defined(OPENVMS) -" (default 1)\n" -#else " (default 0)\n" -#endif " Use built-in certificates instead of system certificates.\n" "\n" " -ssl.client-cert-key <filename>\n" @@ -1897,33 +1747,6 @@ fprintf(stdout, "%s%s%s%s%s%s\n", " (valid for svgalib and framebuffer).\n" " Overwriting may or may not be faster, depending on hardware.\n" "\n" -#ifdef JS -" -enable-javascript <0>/<1>\n" -" Enable javascript.\n" -"\n" -" -js.verbose-errors <0>/<1>\n" -" Display javascript errors.\n" -"\n" -" -js.verbose-warnings <0>/<1>\n" -" Display javascript warnings.\n" -"\n" -" -js.enable-all-conversions <0>/<1>\n" -" Enable conversions between all types in javascript.\n" -"\n" -" -js.enable-global-resolution <0>/<1>\n" -" Resolve global names.\n" -"\n" -" -js.manual-confirmation <0>/<1>\n" -" Ask user to confirm potentially dangerous operations.\n" -" (opening windows, going to url etc.) Default 1.\n" -"\n" -" -js.recursion-depth <integer>\n" -" Depth of javascript call stack.\n" -"\n" -" -js.memory-limit <memory amount>\n" -" Amount of kilobytes the javascript may allocate.\n" -"\n" -#endif " -html-assume-codepage <codepage>\n" " If server didn't specify document character set, assume this.\n" "\n" @@ -2082,14 +1905,8 @@ int screen_width = 80; int dump_codepage = -1; int force_html = 0; -#ifdef DOS -/* DOS networking is slow with too many connections */ -int max_connections = 3; -int max_connections_to_host = 2; -#else int max_connections = 10; int max_connections_to_host = 8; -#endif int max_tries = 3; int receive_timeout = 120; int unrestartable_receive_timeout = 600; @@ -2108,11 +1925,7 @@ int aggressive_cache = 1; struct ipv6_options ipv6_options = { ADDR_PREFERENCE_DEFAULT }; struct proxies proxies = { "", "", "", "", "", "", 0 }; struct ssl_options ssl_options = { SSL_WARN_ON_INVALID_CERTIFICATE, -#if defined(DOS) || defined(OPENVMS) - 1, -#else 0, -#endif "", "", "" }; struct http_options http_options = { 0, 1, 1, 0, 0, 0, 0, { 0, 0, REFERER_REAL_SAME_SERVER, "", "", "" } }; struct ftp_options ftp_options = { "somebody@host.domain", 0, 0, 0, 1 }; diff --git a/dip.c b/dip.c @@ -12,9 +12,7 @@ #include "links.h" -#ifdef HAVE_MATH_H #include <math.h> -#endif /* HAVE_MATH_H */ /* #define this if you want to report missing letters to stderr. * Leave it commented up for normal operation and releases! */ @@ -119,15 +117,8 @@ static struct lru font_cache; */ typedef double scale_t; #define USE_FP_SCALE -#elif defined(HAVE_LONG_LONG) -typedef unsigned long long scale_t; #else -/* - * This may overflow, but systems without long long are very old - * and we will rather accept overflow on big images (65536 pixels) - * than slowing down the process unacceptably with possibly emulated FPU. - */ -typedef unsigned long scale_t; +typedef unsigned long long scale_t; #endif /* Each input byte represents 1 byte (gray). The question whether 0 is @@ -157,12 +148,6 @@ static void add_row_gray(unsigned *my_restrict row_buf, unsigned char *my_restri /* line_skip is in pixels. The column contains the whole pixels (R G B) * We assume unsigned short holds at least 16 bits. */ -#ifdef __ICC -#if __ICC >= 1000 && defined(__i386__) && defined(USE_FP_SCALE) -/* ICC for i386 misoptimizes this function when inlining it */ -ATTR_NOINLINE -#endif -#endif static void add_col_color(scale_t *my_restrict col_buf, unsigned short *my_restrict ptr, int line_skip, int n, ulonglong weight) { @@ -379,20 +364,7 @@ static void enlarge_gray_horizontal(unsigned char *in, int ix, int y, static inline longlong multiply_int(int a, int b) { -#ifndef HAVE_LONG_LONG - volatile -#endif longlong result = (ulonglong)a * (ulonglong)b; -#if !defined(__TINYC__) && !defined(HAVE_LONG_LONG) - if (result / a != (longlong)b) { - /*fprintf(stderr, "%lld, %lld, %d, %d\n", result / a, result, a, b);*/ - overflow(); - } -#endif -#ifndef HAVE_LONG_LONG - if (result == result + 1 || result == result - 1) - overflow(); -#endif return result; } @@ -403,9 +375,6 @@ static inline longlong multiply_int(int a, int b) static void enlarge_color_horizontal(unsigned short *in, int ix, int y, unsigned short **outa, int ox) { -#ifdef HAVE_OPENMP - int use_omp; -#endif int n_threads; int alloc_size; scale_t *col_buf; @@ -444,28 +413,17 @@ static void enlarge_color_horizontal(unsigned short *in, int ix, int y, multiply_int(ix-1,ox-1); n_threads = omp_start(); -#ifdef HAVE_OPENMP - use_omp = !OPENMP_NONATOMIC & (n_threads > 1) & (ox >= 24); - if (!use_omp) - n_threads = 1; -#endif if ((unsigned)y > (MAXINT - SMP_ALIGN + 1) / 3 / sizeof(*col_buf)) overalloc(); alloc_size = (int)(y*3*sizeof(*col_buf)); alloc_size = (alloc_size + SMP_ALIGN - 1) & ~(SMP_ALIGN - 1); if (alloc_size > MAXINT / n_threads) overalloc(); col_buf = mem_alloc_mayfail(alloc_size * n_threads); if (!col_buf) goto skip_omp; -#ifdef HAVE_OPENMP -#pragma omp parallel default(none) firstprivate(col_buf,alloc_size,in,out,ix,ox,y,skip,oskip) if (use_omp) -#endif { scale_t *thread_col_buf; int out_idx; thread_col_buf = (scale_t *)((char *)col_buf + alloc_size * omp_get_thread_num()); bias_buf_color(thread_col_buf, y, (scale_t)(ox - 1) / 2); -#ifdef HAVE_OPENMP -#pragma omp for nowait -#endif for (out_idx = 0; out_idx <= ox - 1; out_idx++) { ulonglong out_pos, in_pos, in_end; int in_idx; @@ -556,9 +514,6 @@ static void scale_gray_horizontal(unsigned char *in, int ix, int y, static void scale_color_horizontal(unsigned short *in, int ix, int y, unsigned short **outa, int ox) { -#ifdef HAVE_OPENMP - int use_omp; -#endif int n_threads; int alloc_size; scale_t *col_buf; @@ -590,28 +545,17 @@ static void scale_color_horizontal(unsigned short *in, int ix, int y, } n_threads = omp_start(); -#ifdef HAVE_OPENMP - use_omp = !OPENMP_NONATOMIC & (n_threads > 1) & (ox >= 24); - if (!use_omp) - n_threads = 1; -#endif if ((unsigned)y > (MAXINT - SMP_ALIGN + 1) / 3 / sizeof(*col_buf)) overalloc(); alloc_size = (int)(y*3*sizeof(*col_buf)); alloc_size = (alloc_size + SMP_ALIGN - 1) & ~(SMP_ALIGN - 1); if (alloc_size > MAXINT / n_threads) overalloc(); col_buf = mem_alloc_mayfail(alloc_size * n_threads); if (!col_buf) goto skip_omp; -#ifdef HAVE_OPENMP -#pragma omp parallel default(none) firstprivate(col_buf,alloc_size,in,out,ix,ox,y,skip,oskip) if (use_omp) -#endif { scale_t *thread_col_buf; int out_idx; thread_col_buf = (scale_t *)((char *)col_buf + alloc_size * omp_get_thread_num()); bias_buf_color(thread_col_buf, y, (scale_t)ix / 2); -#ifdef HAVE_OPENMP -#pragma omp for nowait -#endif for (out_idx = 0; out_idx < ox; out_idx++) { ulonglong out_pos, out_end, in_pos; int in_idx; @@ -704,9 +648,6 @@ static void enlarge_gray_vertical(unsigned char *in, int x, int iy, static void enlarge_color_vertical(unsigned short *in, int x, int iy, unsigned short **outa ,int oy) { -#ifdef HAVE_OPENMP - int use_omp; -#endif int n_threads; int alloc_size; scale_t *row_buf; @@ -741,28 +682,17 @@ static void enlarge_color_vertical(unsigned short *in, int x, int iy, multiply_int(iy-1,oy-1); n_threads = omp_start(); -#ifdef HAVE_OPENMP - use_omp = (!OPENMP_NONATOMIC | !(x & 1)) & (n_threads > 1) & (oy >= 24); - if (!use_omp) - n_threads = 1; -#endif if ((unsigned)x > (MAXINT - SMP_ALIGN + 1) / 3 / sizeof(*row_buf)) overalloc(); alloc_size = (int)(x*3*sizeof(*row_buf)); alloc_size = (alloc_size + SMP_ALIGN - 1) & ~(SMP_ALIGN - 1); if (alloc_size > MAXINT / n_threads) overalloc(); row_buf = mem_alloc_mayfail(alloc_size * n_threads); if (!row_buf) goto skip_omp; -#ifdef HAVE_OPENMP -#pragma omp parallel default(none) firstprivate(row_buf,alloc_size,in,out,x,iy,oy) if (use_omp) -#endif { scale_t *thread_row_buf; int out_idx; thread_row_buf = (scale_t *)((char *)row_buf + alloc_size * omp_get_thread_num()); bias_buf_color(thread_row_buf,x,(scale_t)(oy-1) / 2); -#ifdef HAVE_OPENMP -#pragma omp for nowait -#endif for (out_idx = 0; out_idx <= oy - 1; out_idx++) { ulonglong out_pos, in_pos, in_end; int in_idx; @@ -855,9 +785,6 @@ static void scale_gray_vertical(unsigned char *in, int x, int iy, static void scale_color_vertical(unsigned short *in, int x, int iy, unsigned short **outa, int oy) { -#ifdef HAVE_OPENMP - int use_omp; -#endif int n_threads; int alloc_size; scale_t *row_buf; @@ -886,28 +813,17 @@ static void scale_color_vertical(unsigned short *in, int x, int iy, return; } n_threads = omp_start(); -#ifdef HAVE_OPENMP - use_omp = (!OPENMP_NONATOMIC | !(x & 1)) & (n_threads > 1) & (oy >= 24); - if (!use_omp) - n_threads = 1; -#endif if ((unsigned)x > (MAXINT - SMP_ALIGN + 1) / 3 / sizeof(*row_buf)) overalloc(); alloc_size = (int)(x*3*sizeof(*row_buf)); alloc_size = (alloc_size + SMP_ALIGN - 1) & ~(SMP_ALIGN - 1); if (alloc_size > MAXINT / n_threads) overalloc(); row_buf = mem_alloc_mayfail(alloc_size * n_threads); if (!row_buf) goto skip_omp; -#ifdef HAVE_OPENMP -#pragma omp parallel default(none) firstprivate(row_buf,alloc_size,in,out,x,iy,oy) if (use_omp) -#endif { scale_t *thread_row_buf; int out_idx; thread_row_buf = (scale_t *)((char *)row_buf + alloc_size * omp_get_thread_num()); bias_buf_color(thread_row_buf,x,(scale_t)iy / 2); -#ifdef HAVE_OPENMP -#pragma omp for nowait -#endif for (out_idx = 0; out_idx < oy; out_idx++) { ulonglong out_pos, out_end, in_pos; int in_idx; @@ -1694,22 +1610,14 @@ const unsigned char *png_data, int png_length) } if (color_type==PNG_COLOR_TYPE_PALETTE){ png_set_expand(png_ptr); -#ifdef HAVE_PNG_SET_RGB_TO_GRAY png_set_rgb_to_gray(png_ptr, 1, -1, -1); -#else - goto end; -#endif } if (color_type & PNG_COLOR_MASK_ALPHA){ png_set_strip_alpha(png_ptr); } if (color_type==PNG_COLOR_TYPE_RGB || color_type==PNG_COLOR_TYPE_RGB_ALPHA){ -#ifdef HAVE_PNG_SET_RGB_TO_GRAY png_set_rgb_to_gray(png_ptr, 1, -1, -1); -#else - goto end; -#endif } } /* If the depth is different from 8 bits/gray, make the libpng expand @@ -1730,13 +1638,6 @@ const unsigned char *png_data, int png_length) png_destroy_read_struct(&png_ptr, &info_ptr, NULL); mem_free(ptrs); return; -#ifndef HAVE_PNG_SET_RGB_TO_GRAY - end: - if (*x && (unsigned)*x * (unsigned)*y / (unsigned)*x != (unsigned)*y) overalloc(); - if ((unsigned)*x * (unsigned)*y > MAXINT) overalloc(); - *dest=mem_calloc(*x*(*y)); - return; -#endif } /* Like load_char, but we dictate the y. diff --git a/directfb.c b/directfb.c @@ -18,821 +18,3 @@ #include "cfg.h" -#ifdef GRDRV_DIRECTFB - -#include <netinet/in.h> /* for htons */ - -#include <directfb.h> - -#include "links.h" -#include "dfb_cur.h" - - -#define FOCUSED_OPACITY 0xFF -#define UNFOCUSED_OPACITY 0xC0 - -#define DIRECTFB_HASH_TABLE_SIZE 23 -static struct graphics_device **directfb_hash_table[DIRECTFB_HASH_TABLE_SIZE]; - -typedef struct _DFBDeviceData DFBDeviceData; -struct _DFBDeviceData -{ - DFBWindowID id; - IDirectFBWindow *window; - IDirectFBSurface *surface; - DFBRegion flip_region; - int flip_pending; -}; - - -extern struct graphics_driver directfb_driver; - -static IDirectFB *dfb = NULL; -static IDirectFBDisplayLayer *layer = NULL; -static IDirectFBSurface *arrow = NULL; -static IDirectFBEventBuffer *events = NULL; -static DFBSurfacePixelFormat pixelformat = DSPF_UNKNOWN; -static struct timer *event_timer = NULL; - - -static void directfb_register_flip (DFBDeviceData *data, - int x, int y, int w, int h); -static void directfb_flip_surface (void *pointer); -static void directfb_check_events (void *pointer); -static void directfb_translate_key (DFBWindowEvent *event, - int *key, int *flag); -static void directfb_add_to_table (struct graphics_device *gd); -static void directfb_remove_from_table (struct graphics_device *gd); -static struct graphics_device * directfb_lookup_in_table (DFBWindowID id); - - -static unsigned char * -directfb_init_driver (unsigned char *param, unsigned char *display) -{ - DFBDisplayLayerConfig config; - DFBResult ret; - unsigned char *error; - unsigned char *result; - - DirectFBInit (&g_argc, (char ***)(void *)&g_argv); - if ((ret = DirectFBCreate (&dfb)) != DFB_OK) { - error = (unsigned char *)DirectFBErrorString(ret); - goto ret; - } - - if ((ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer)) != DFB_OK) { - error = (unsigned char *)DirectFBErrorString(ret); - goto ret_dfb; - } - - if ((ret = layer->GetConfiguration (layer, &config)) != DFB_OK) { - error = (unsigned char *)DirectFBErrorString(ret); - goto ret_layer; - } - - pixelformat = config.pixelformat; - - directfb_driver.depth = (((DFB_BYTES_PER_PIXEL (pixelformat) & 0x7)) | - ((DFB_COLOR_BITS_PER_PIXEL (pixelformat) & 0x1F) << 3)); - - if (directfb_driver.depth == 4) - directfb_driver.depth = 196; - - /* endian test */ - if (htons (0x1234) == 0x1234) { - if ((directfb_driver.depth & 0x7) == 2) - directfb_driver.depth |= 0x100; - if ((directfb_driver.depth & 0x7) == 4) - directfb_driver.depth |= 0x200; - } - - if (!get_color_fn(directfb_driver.depth)) { - error = cast_uchar "Unsupported color depth"; - goto ret_layer; - } - - directfb_driver.x = config.width; - directfb_driver.y = config.height; - - memset (directfb_hash_table, 0, sizeof (directfb_hash_table)); - - if ((ret = dfb->CreateEventBuffer (dfb, &events)) != DFB_OK) { - error = (unsigned char *)DirectFBErrorString(ret); - goto ret_layer; - } - - event_timer = install_timer (20, directfb_check_events, events); - - if (dfb->CreateSurface (dfb, directfb_get_arrow_desc(), &arrow) != DFB_OK) - arrow = NULL; - - return NULL; - -ret_layer: - layer->Release(layer); -ret_dfb: - dfb->Release(dfb); -ret: - result = init_str(); - add_to_strn(&result, error); - add_to_strn(&result, cast_uchar "\n"); - return result; -} - -static struct graphics_device * -directfb_init_device (void) -{ - struct graphics_device *gd; - DFBDeviceData *data; - IDirectFBWindow *window; - DFBWindowDescription desc; - - desc.flags = (DFBWindowDescriptionFlags)(DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_POSX | DWDESC_POSY); - desc.width = directfb_driver.x; - desc.height = directfb_driver.y; - desc.posx = 0; - desc.posy = 0; - - retry: - if (layer->CreateWindow (layer, &desc, &window) != DFB_OK) { - if (out_of_memory(MF_GPI, NULL, 0)) - goto retry; - return NULL; - } - - gd = mem_alloc (sizeof (struct graphics_device)); - - gd->size.x1 = 0; - gd->size.y1 = 0; - window->GetSize (window, &gd->size.x2, &gd->size.y2); - - gd->clip = gd->size; - - data = mem_alloc (sizeof (DFBDeviceData)); - - data->window = window; - data->flip_pending = 0; - - if (arrow) - window->SetCursorShape (window, arrow, arrow_hot_x, arrow_hot_y); - - window->GetSurface (window, &data->surface); - window->GetID (window, &data->id); - - gd->driver_data = data; - gd->user_data = NULL; - - directfb_add_to_table (gd); - - window->AttachEventBuffer (window, events); - - window->SetOpacity (window, FOCUSED_OPACITY); - - return gd; -} - -static void -directfb_shutdown_device (struct graphics_device *gd) -{ - DFBDeviceData *data; - - if (!gd) - return; - - data = gd->driver_data; - - unregister_bottom_half (directfb_flip_surface, data); - directfb_remove_from_table (gd); - - data->surface->Release (data->surface); - data->window->Destroy (data->window); - data->window->Release (data->window); - - mem_free (data); - mem_free (gd); -} - -static void -directfb_shutdown_driver (void) -{ - int i; - - kill_timer (event_timer); - events->Release (events); - events = NULL; - - if (arrow) - arrow->Release (arrow); - - layer->Release (layer); - dfb->Release (dfb); - - for (i = 0; i < DIRECTFB_HASH_TABLE_SIZE; i++) - if (directfb_hash_table[i]) - mem_free (directfb_hash_table[i]); - - dfb = NULL; -} - -static unsigned char * -directfb_get_driver_param (void) -{ - return NULL; -} - -static int -directfb_get_empty_bitmap (struct bitmap *bmp) -{ - IDirectFBSurface *surface; - DFBSurfaceDescription desc; - - bmp->data = bmp->flags = NULL; - - desc.flags = (DFBSurfaceDescriptionFlags)(DSDESC_WIDTH | DSDESC_HEIGHT); - desc.width = bmp->x; - desc.height = bmp->y; - - retry: - if (dfb->CreateSurface (dfb, &desc, &surface) != DFB_OK) { - if (out_of_memory(MF_GPI, NULL, 0)) - goto retry; - return -1; - } - - surface->Lock (surface, (DFBSurfaceLockFlags)(DSLF_READ | DSLF_WRITE), &bmp->data, &bmp->skip); - - bmp->flags = surface; - - return 0; -} - -static void -directfb_register_bitmap (struct bitmap *bmp) -{ - IDirectFBSurface *surface = bmp->flags; - if (!surface) return; - - surface->Unlock (surface); - bmp->data = NULL; -} - -static void * -directfb_prepare_strip (struct bitmap *bmp, int top, int lines) -{ - IDirectFBSurface *surface = bmp->flags; - if (!surface) return NULL; - - surface->Lock (surface, (DFBSurfaceLockFlags)(DSLF_READ | DSLF_WRITE), &bmp->data, &bmp->skip); - - return ((unsigned char *) bmp->data + top * bmp->skip); -} - -static void -directfb_commit_strip (struct bitmap *bmp, int top, int lines) -{ - IDirectFBSurface *surface = bmp->flags; - if (!surface) return; - - surface->Unlock (surface); - bmp->data = NULL; -} - -static void -directfb_unregister_bitmap (struct bitmap *bmp) -{ - IDirectFBSurface *surface = bmp->flags; - if (!surface) return; - - surface->Release (surface); -} - -static void -directfb_draw_bitmap (struct graphics_device *gd, struct bitmap *bmp, - int x, int y) -{ - DFBDeviceData *data = gd->driver_data; - IDirectFBSurface *src = bmp->flags; - if (!src) return; - - if (gd->clip.x1 >= gd->clip.x2 || - gd->clip.y1 >= gd->clip.y2) return; - - data->surface->Blit (data->surface, src, NULL, x, y); - - directfb_register_flip (data, x, y, bmp->x, bmp->y); -} - -static long -directfb_get_color (int rgb) -{ - return rgb; -} - - -static inline void directfb_set_color (IDirectFBSurface *surface, long color) -{ - surface->SetColor (surface, - (color & 0xFF0000) >> 16, - (color & 0xFF00) >> 8, - (color & 0xFF), - 0xFF); -} - -static void -directfb_fill_area (struct graphics_device *gd, - int x1, int y1, int x2, int y2, long color) -{ - DFBDeviceData *data = gd->driver_data; - int w = x2 - x1; - int h = y2 - y1; - - directfb_set_color (data->surface, color); - data->surface->FillRectangle (data->surface, x1, y1, w, h); - - directfb_register_flip (data, x1, y1, w, h); -} - -static void -directfb_draw_hline (struct graphics_device *gd, - int left, int y, int right, long color) -{ - DFBDeviceData *data = gd->driver_data; - - if (right <= left) return; - - right--; - - directfb_set_color (data->surface, color); - data->surface->DrawLine (data->surface, left, y, right, y); - - directfb_register_flip (data, left, y, right - left, 1); -} - -static void -directfb_draw_vline (struct graphics_device *gd, - int x, int top, int bottom, long color) -{ - DFBDeviceData *data = gd->driver_data; - - if (bottom <= top) return; - - bottom--; - - directfb_set_color (data->surface, color); - data->surface->DrawLine (data->surface, x, top, x, bottom); - - directfb_register_flip (data, x, top, 1, bottom - top); -} - -static void -directfb_set_clip_area (struct graphics_device *gd, struct rect *r) -{ - DFBDeviceData *data = gd->driver_data; - DFBRegion region; - generic_set_clip_area(gd, r); - region.x1 = gd->clip.x1; - region.y1 = gd->clip.y1; - region.x2 = gd->clip.x2 - 1; - region.y2 = gd->clip.y2 - 1; - - data->surface->SetClip (data->surface, &region); -} - -static int -directfb_hscroll (struct graphics_device *gd, struct rect_set **set, int sc) -{ - DFBDeviceData *data = gd->driver_data; - DFBRectangle rect; - - *set = NULL; - if (!sc) - return 0; - - rect.x = gd->clip.x1; - rect.y = gd->clip.y1; - rect.w = gd->clip.x2 - rect.x; - rect.h = gd->clip.y2 - rect.y; - - data->surface->Blit (data->surface, - data->surface, &rect, rect.x + sc, rect.y); - - directfb_register_flip (data, rect.x, rect.y, rect.w, rect.h); - - return 1; -} - -static int -directfb_vscroll (struct graphics_device *gd, struct rect_set **set, int sc) -{ - DFBDeviceData *data = gd->driver_data; - DFBRectangle rect; - - *set = NULL; - if (!sc) - return 0; - - rect.x = gd->clip.x1; - rect.y = gd->clip.y1; - rect.w = gd->clip.x2 - rect.x; - rect.h = gd->clip.y2 - rect.y; - - data->surface->Blit (data->surface, - data->surface, &rect, rect.x, rect.y + sc); - - directfb_register_flip (data, rect.x, rect.y, rect.w, rect.h); - - return 1; -} - -static void directfb_register_flip (DFBDeviceData *data, - int x, int y, int w, int h) -{ - if (x < 0 || y < 0 || w < 1 || h < 1) - return; - - w = x + w - 1; - h = y + h - 1; - - if (data->flip_pending) - { - if (data->flip_region.x1 > x) data->flip_region.x1 = x; - if (data->flip_region.y1 > y) data->flip_region.y1 = y; - if (data->flip_region.x2 < w) data->flip_region.x2 = w; - if (data->flip_region.y2 < h) data->flip_region.y2 = h; - } - else - { - data->flip_region.x1 = x; - data->flip_region.y1 = y; - data->flip_region.x2 = w; - data->flip_region.y2 = h; - - data->flip_pending = 1; - - register_bottom_half (directfb_flip_surface, data); - } -} - -static void -directfb_flip_surface (void *pointer) -{ - DFBDeviceData *data = pointer; - - if (!data->flip_pending) - return; - - data->surface->Flip (data->surface, &data->flip_region, (DFBSurfaceFlipFlags)0); - - data->flip_pending = 0; -} - -static void -directfb_flush(struct graphics_device *gd) -{ - DFBDeviceData *data = gd->driver_data; - unregister_bottom_half (directfb_flip_surface, data); - directfb_flip_surface(data); -} - -static void -directfb_check_events (void *pointer) -{ - struct graphics_device *gd = NULL; - DFBDeviceData *data = NULL; - DFBWindowEvent event; - DFBWindowEvent next; - - while (events->GetEvent (events, DFB_EVENT (&event)) == DFB_OK) - { - switch (event.type) - { - case DWET_GOTFOCUS: - case DWET_LOSTFOCUS: - case DWET_POSITION_SIZE: - case DWET_SIZE: - case DWET_KEYDOWN: - case DWET_BUTTONDOWN: - case DWET_BUTTONUP: - case DWET_WHEEL: - case DWET_MOTION: - break; - default: - continue; - } - - if (!data || data->id != event.window_id) - { - gd = directfb_lookup_in_table (event.window_id); - if (!gd) - continue; - } - - data = gd->driver_data; - - switch (event.type) - { -#if 0 - case DWET_GOTFOCUS: - data->window->SetOpacity (data->window, FOCUSED_OPACITY); - break; - - case DWET_LOSTFOCUS: - data->window->SetOpacity (data->window, UNFOCUSED_OPACITY); - break; -#endif - - case DWET_POSITION_SIZE: - case DWET_SIZE: - while ((events->PeekEvent (events, DFB_EVENT (&next)) == DFB_OK) && - (next.type == DWET_SIZE || next.type == DWET_POSITION_SIZE) && - (next.window_id == data->id)) - events->GetEvent (events, DFB_EVENT (&event)); - - gd->size.x2 = event.w; - gd->size.y2 = event.h; - gd->resize_handler (gd); - break; - - case DWET_KEYDOWN: - { - int key, flag; - - directfb_translate_key (&event, &key, &flag); - if (key) - gd->keyboard_handler (gd, key, flag); - } - break; - - case DWET_BUTTONDOWN: - case DWET_BUTTONUP: - { - int flags; - - /* - * For unknown reason, we get the event twice - */ - while ((events->PeekEvent (events, DFB_EVENT (&next)) == DFB_OK) && - (next.type == event.type && next.button == event.button && - next.x == event.x && next.y == event.y && next.window_id == data->id)) - events->GetEvent (events, DFB_EVENT (&event)); - - if (event.type == DWET_BUTTONUP) - { - flags = B_UP; - data->window->UngrabPointer (data->window); - } - else - { - flags = B_DOWN; - data->window->GrabPointer (data->window); - } - - switch (event.button) - { - case DIBI_LEFT: - flags |= B_LEFT; - break; - case DIBI_RIGHT: - flags |= B_RIGHT; - break; - case DIBI_MIDDLE: - flags |= B_MIDDLE; - break; - default: - continue; - } - - gd->mouse_handler (gd, event.x, event.y, flags); - } - break; - - case DWET_WHEEL: - gd->mouse_handler (gd, event.x, event.y, - B_MOVE | - (event.step > 0 ? B_WHEELUP : B_WHEELDOWN)); - break; - - case DWET_MOTION: - { - int flags; - - while ((events->PeekEvent (events, DFB_EVENT (&next)) == DFB_OK) && - (next.type == DWET_MOTION) && - (next.window_id == data->id)) - events->GetEvent (events, DFB_EVENT (&event)); - - switch (event.buttons) - { - case DIBM_LEFT: - flags = B_DRAG | B_LEFT; - break; - case DIBM_RIGHT: - flags = B_DRAG | B_RIGHT; - break; - case DIBM_MIDDLE: - flags = B_DRAG | B_MIDDLE; - break; - default: - flags = B_MOVE; - break; - } - - gd->mouse_handler (gd, event.x, event.y, flags); - } - break; - - case DWET_CLOSE: - gd->keyboard_handler (gd, KBD_CLOSE, 0); - break; - - default: - break; - } - } - - event_timer = install_timer (20, directfb_check_events, events); -} - -static void -directfb_translate_key (DFBWindowEvent *event, int *key, int *flag) -{ - *key = 0; - *flag = 0; - - if (event->modifiers & DIMM_CONTROL && event->key_id == DIKI_C) - { - *key = KBD_CTRL_C; - return; - } - - /* setting Shift seems to break things - * - * if (event->modifiers & DIMM_SHIFT) - * *flag |= KBD_SHIFT; - */ - if (event->modifiers & DIMM_CONTROL) - *flag |= KBD_CTRL; - if (event->modifiers & DIMM_ALT) - *flag |= KBD_ALT; - - switch (event->key_symbol) - { - case DIKS_ENTER: *key = KBD_ENTER; break; - case DIKS_BACKSPACE: *key = KBD_BS; break; - case DIKS_TAB: *key = KBD_TAB; break; - case DIKS_ESCAPE: *key = KBD_ESC; break; - case DIKS_CURSOR_UP: *key = KBD_UP; break; - case DIKS_CURSOR_DOWN: *key = KBD_DOWN; break; - case DIKS_CURSOR_LEFT: *key = KBD_LEFT; break; - case DIKS_CURSOR_RIGHT: *key = KBD_RIGHT; break; - case DIKS_INSERT: *key = KBD_INS; break; - case DIKS_DELETE: *key = KBD_DEL; break; - case DIKS_HOME: *key = KBD_HOME; break; - case DIKS_END: *key = KBD_END; break; - case DIKS_PAGE_UP: *key = KBD_PAGE_UP; break; - case DIKS_PAGE_DOWN: *key = KBD_PAGE_DOWN; break; - case DIKS_F1: *key = KBD_F1; break; - case DIKS_F2: *key = KBD_F2; break; - case DIKS_F3: *key = KBD_F3; break; - case DIKS_F4: *key = KBD_F4; break; - case DIKS_F5: *key = KBD_F5; break; - case DIKS_F6: *key = KBD_F6; break; - case DIKS_F7: *key = KBD_F7; break; - case DIKS_F8: *key = KBD_F8; break; - case DIKS_F9: *key = KBD_F9; break; - case DIKS_F10: *key = KBD_F10; break; - case DIKS_F11: *key = KBD_F11; break; - case DIKS_F12: *key = KBD_F12; break; - - default: - if (DFB_KEY_TYPE (event->key_symbol) == DIKT_UNICODE) - *key = event->key_symbol; - break; - } -} - -static void -directfb_add_to_table (struct graphics_device *gd) -{ - DFBDeviceData *data = gd->driver_data; - struct graphics_device **devices; - int i; - - i = data->id % DIRECTFB_HASH_TABLE_SIZE; - - devices = directfb_hash_table[i]; - - if (devices) - { - int c = 0; - - while (devices[c++]) - if (c == MAXINT) overalloc(); - - if ((unsigned)c > MAXINT / sizeof(void *) - 1) overalloc(); - devices = mem_realloc (devices, (c + 1) * sizeof (void *)); - devices[c-1] = gd; - devices[c] = NULL; - } - else - { - devices = mem_alloc (2 * sizeof (void *)); - devices[0] = gd; - devices[1] = NULL; - } - - directfb_hash_table[i] = devices; -} - -static void -directfb_remove_from_table (struct graphics_device *gd) -{ - DFBDeviceData *data = gd->driver_data; - struct graphics_device **devices; - int i, j, c; - - i = data->id % DIRECTFB_HASH_TABLE_SIZE; - - devices = directfb_hash_table[i]; - if (!devices) - return; - - for (j = 0, c = -1; devices[j]; j++) - if (devices[j] == gd) - c = j; - - if (c < 0) - return; - - memmove (devices + c, devices + c + 1, (j - c) * sizeof (void *)); - devices = mem_realloc (devices, j * sizeof (void *)); - - directfb_hash_table[i] = devices; -} - -static struct graphics_device * -directfb_lookup_in_table (DFBWindowID id) -{ - struct graphics_device **devices; - int i; - - i = id % DIRECTFB_HASH_TABLE_SIZE; - - devices = directfb_hash_table[i]; - if (!devices) - return NULL; - - while (*devices) - { - DFBDeviceData *data = (*devices)->driver_data; - - if (data->id == id) - return *devices; - - devices++; - } - - return NULL; -} - -struct graphics_driver directfb_driver = -{ - cast_uchar "directfb", - directfb_init_driver, - directfb_init_device, - directfb_shutdown_device, - directfb_shutdown_driver, - NULL, - NULL, - directfb_get_driver_param, - NULL, - NULL, - NULL, - directfb_get_empty_bitmap, - directfb_register_bitmap, - directfb_prepare_strip, - directfb_commit_strip, - directfb_unregister_bitmap, - directfb_draw_bitmap, - directfb_get_color, - directfb_fill_area, - directfb_draw_hline, - directfb_draw_vline, - directfb_hscroll, - directfb_vscroll, - directfb_set_clip_area, - directfb_flush, - dummy_block, - dummy_unblock, - NULL, /* set_title */ - NULL, /* exec */ - NULL, /* set_clipboard_text */ - NULL, /* get_clipboard_text */ - 0, /* depth */ - 0, 0, /* size */ - GD_UNICODE_KEYS | GD_NO_OS_SHELL | GD_NOAUTO, /* flags */ - 0, /* codepage */ - NULL, /* shell */ -}; - -#endif /* GRDRV_DIRECTFB */ diff --git a/dither.c b/dither.c @@ -12,9 +12,7 @@ #include "bits.h" -#ifdef HAVE_MATH_H #include <math.h> -#endif /* The input of dithering function is 3 times 16-bit value. The value is * proportional to light that will go out of the monitor. Only in this space it diff --git a/dns.c b/dns.c @@ -5,21 +5,10 @@ #include "links.h" -#ifdef SUPPORT_IPV6 int support_ipv6; -#endif -#if !defined(USE_GETADDRINFO) && (defined(HAVE_GETHOSTBYNAME_BUG) || !defined(HAVE_GETHOSTBYNAME)) -#define EXTERNAL_LOOKUP -#endif -#if defined(WIN) || defined(INTERIX) -#define EXTRA_IPV6_LOOKUP -#endif -#ifdef OPENVMS_64BIT -#define addrinfo __addrinfo64 -#endif struct dnsentry { list_entry_1st @@ -78,7 +67,6 @@ int numeric_ip_address(unsigned char *name, unsigned char address[4]) return 0; } -#ifdef SUPPORT_IPV6 static int extract_ipv6_address(struct addrinfo *p, unsigned char address[16], unsigned *scope_id) { @@ -89,11 +77,7 @@ static int extract_ipv6_address(struct addrinfo *p, unsigned char address[16], u }*/ if (p->ai_family == AF_INET6 && (socklen_t)p->ai_addrlen >= (socklen_t)sizeof(struct sockaddr_in6) && p->ai_addr->sa_family == AF_INET6) { memcpy(address, &((struct sockaddr_in6 *)p->ai_addr)->sin6_addr, 16); -#ifdef SUPPORT_IPV6_SCOPE *scope_id = ((struct sockaddr_in6 *)p->ai_addr)->sin6_scope_id; -#else - *scope_id = 0; -#endif return 0; } return -1; @@ -104,14 +88,11 @@ int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigne unsigned char dummy_a[16]; unsigned dummy_s; int r; -#ifdef HAVE_INET_PTON struct in6_addr i6a; -#endif struct addrinfo hints, *res; if (!address) address = dummy_a; if (!scope_id) scope_id = &dummy_s; -#ifdef HAVE_INET_PTON if (inet_pton(AF_INET6, cast_const_char name, &i6a) == 1) { memcpy(address, &i6a, 16); *scope_id = 0; @@ -119,7 +100,6 @@ int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigne } if (!strchr(cast_const_char name, '%')) return -1; -#endif memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET6; @@ -131,72 +111,7 @@ int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigne return r; } -#endif -#ifdef EXTERNAL_LOOKUP - -static int do_external_lookup(unsigned char *name, unsigned char *host) -{ - unsigned char buffer[1024]; - unsigned char sink[16]; - int rd; - int pi[2]; - pid_t f; - unsigned char *n; - int rs; - if (c_pipe(pi) == -1) - return -1; - EINTRLOOP(f, fork()); - if (f == -1) { - EINTRLOOP(rs, close(pi[0])); - EINTRLOOP(rs, close(pi[1])); - return -1; - } - if (!f) { -#ifdef HAVE_SETSID - /* without setsid it gets stuck when on background */ - EINTRLOOP(rs, setsid()); -#endif - EINTRLOOP(rs, close(pi[0])); - EINTRLOOP(rs, dup2(pi[1], 1)); - if (rs == -1) _exit(1); - EINTRLOOP(rs, dup2(pi[1], 2)); - if (rs == -1) _exit(1); - EINTRLOOP(rs, close(pi[1])); - EINTRLOOP(rs, execlp("host", "host", name, NULL)); - EINTRLOOP(rs, execl("/usr/sbin/host", "host", name, NULL)); - _exit(1); - } - EINTRLOOP(rs, close(pi[1])); - rd = hard_read(pi[0], buffer, sizeof buffer - 1); - if (rd >= 0) buffer[rd] = 0; - if (rd > 0) { - while (hard_read(pi[0], sink, sizeof sink) > 0); - } - EINTRLOOP(rs, close(pi[0])); - /* Don't wait for the process, we already have sigchld handler that - * does cleanup. - * waitpid(f, NULL, 0); */ - if (rd < 0) return -1; - /*fprintf(stderr, "query: '%s', result: %s\n", name, buffer);*/ - while ((n = strstr(buffer, name))) { - memset(n, '-', strlen(cast_const_char name)); - } - for (n = buffer; n < buffer + rd; n++) { - if (*n >= '0' && *n <= '9') { - if (get_addr_byte(&n, host + 0, '.')) goto skip_addr; - if (get_addr_byte(&n, host + 1, '.')) goto skip_addr; - if (get_addr_byte(&n, host + 2, '.')) goto skip_addr; - if (get_addr_byte(&n, host + 3, 255)) goto skip_addr; - return 0; -skip_addr: - if (n >= buffer + rd) break; - } - } - return -1; -} - -#endif #if MAX_ADDRESSES > 1 static int memcmp_host_address(struct host_address *a, struct host_address *b) @@ -216,10 +131,8 @@ static void add_address(struct lookup_result *host, int af, unsigned char *addre #endif if (af != AF_INET && preference == ADDR_PREFERENCE_IPV4_ONLY) return; -#ifdef SUPPORT_IPV6 if (af != AF_INET6 && preference == ADDR_PREFERENCE_IPV6_ONLY) return; -#endif if (host->n >= MAX_ADDRESSES) return; memset(&neww, 0, sizeof(struct host_address)); @@ -236,12 +149,10 @@ static void add_address(struct lookup_result *host, int af, unsigned char *addre t = n; break; } -#ifdef SUPPORT_IPV6 if (preference == ADDR_PREFERENCE_IPV6 && af == AF_INET6 && n->af != AF_INET6) { t = n; break; } -#endif } memmove(t + 1, t, (e - t) * sizeof(struct host_address)); #endif @@ -263,7 +174,6 @@ static int use_getaddrinfo(unsigned char *name, struct addrinfo *hints, int pref add_address(host, AF_INET, (unsigned char *)&((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr, 0, preference); continue; } -#ifdef SUPPORT_IPV6 { unsigned char address[16]; unsigned scope_id; @@ -272,7 +182,6 @@ static int use_getaddrinfo(unsigned char *name, struct addrinfo *hints, int pref continue; } } -#endif } freeaddrinfo(res); return 0; @@ -311,9 +220,7 @@ do_swap: void do_real_lookup(unsigned char *name, int preference, struct lookup_result *host) { unsigned char address[16]; -#ifdef SUPPORT_IPV6 size_t nl; -#endif memset(host, 0, sizeof(struct lookup_result)); @@ -326,7 +233,6 @@ void do_real_lookup(unsigned char *name, int preference, struct lookup_result *h add_address(host, AF_INET, address, 0, preference); goto ret; } -#ifdef SUPPORT_IPV6 nl = strlen(cast_const_char name); if (name[0] == '[' && name[nl - 1] == ']') { unsigned char *n2 = cast_uchar strdup(cast_const_char(name + 1)); @@ -347,7 +253,6 @@ void do_real_lookup(unsigned char *name, int preference, struct lookup_result *h goto ret; } } -#endif #if defined(USE_GETADDRINFO) use_getaddrinfo(name, NULL, preference, host); @@ -367,7 +272,7 @@ void do_real_lookup(unsigned char *name, int preference, struct lookup_result *h } already_have_inet6:; #endif -#elif defined(HAVE_GETHOSTBYNAME) +#else { int i; struct hostent *hst; @@ -386,12 +291,6 @@ void do_real_lookup(unsigned char *name, int preference, struct lookup_result *h } #endif -#ifdef EXTERNAL_LOOKUP - if (!do_external_lookup(name, address)) { - add_address(host, AF_INET, address, 0, preference); - goto ret; - } -#endif ret: return; @@ -665,40 +564,15 @@ delete_last: unsigned char *print_address(struct host_address *a) { #define SCOPE_ID_LEN 11 -#ifdef SUPPORT_IPV6 static unsigned char buffer[INET6_ADDRSTRLEN + SCOPE_ID_LEN]; -#else - static unsigned char buffer[INET_ADDRSTRLEN + SCOPE_ID_LEN]; -#endif -#ifdef HAVE_INET_NTOP union { struct in_addr in; -#ifdef SUPPORT_IPV6 struct in6_addr in6; -#endif char pad[16]; } u; memcpy(&u, a->addr, 16); if (!inet_ntop(a->af, &u, cast_char buffer, sizeof buffer - SCOPE_ID_LEN)) return NULL; -#else - if (a->af == AF_INET) - snprintf(cast_char buffer, sizeof buffer, "%d.%d.%d.%d", a->addr[0], a->addr[1], a->addr[2], a->addr[3]); -#ifdef SUPPORT_IPV6 - else if (a->af == AF_INET6) - snprintf(cast_char buffer, sizeof buffer, "%x:%x:%x:%x:%x:%x:%x:%x", - (a->addr[0] << 8) | a->addr[1], - (a->addr[2] << 8) | a->addr[3], - (a->addr[4] << 8) | a->addr[5], - (a->addr[6] << 8) | a->addr[7], - (a->addr[8] << 8) | a->addr[9], - (a->addr[10] << 8) | a->addr[11], - (a->addr[12] << 8) | a->addr[13], - (a->addr[14] << 8) | a->addr[15]); -#endif - else - return NULL; -#endif if (a->scope_id) { unsigned char *end = cast_uchar strchr(cast_const_char buffer, 0); snprintf(cast_char end, buffer + sizeof(buffer) - end, "%%%u", a->scope_id); @@ -708,7 +582,6 @@ unsigned char *print_address(struct host_address *a) int ipv6_full_access(void) { -#ifdef SUPPORT_IPV6 /* * Test if we can access global IPv6 address space. * This doesn't send anything anywhere, it just creates an UDP socket, @@ -726,54 +599,13 @@ int ipv6_full_access(void) EINTRLOOP(c, connect(h, (struct sockaddr *)(void *)&sin6, sizeof sin6)); EINTRLOOP(rs, close(h)); if (!c) return 1; -#endif return 0; } -#ifdef FLOOD_MEMORY - -void flood_memory(void) -{ - struct list_head list; - size_t s = 32768 * 32; - struct dnsentry *de; - dns_cache_addr_preference = ipv6_options.addr_preference; -#if defined(HAVE__HEAPMIN) - _heapmin(); -#endif - init_list(list); - while (!list_empty(dns_cache)) { - de = list_struct(dns_cache.prev, struct dnsentry); - del_from_list(de); - add_to_list(list, de); - } - while (1) { - while ((de = mem_alloc_mayfail(s))) { - de->absolute_time = get_absolute_time(); - memset(&de->addr, 0, sizeof de->addr); - de->name[0] = 0; - add_to_list(list, de); - } - if (s == sizeof(struct dnsentry)) break; - s = s / 2; - if (s < sizeof(struct dnsentry)) s = sizeof(struct dnsentry); - } - while (!list_empty(list)) { - de = list_struct(list.prev, struct dnsentry); - del_from_list(de); - add_to_list(dns_cache, de); - } -} - -#endif void init_dns(void) { register_cache_upcall(shrink_dns_cache, 0, cast_uchar "dns"); -#ifdef FLOOD_MEMORY - flood_memory(); -#endif -#ifdef SUPPORT_IPV6 { int h, rs; h = c_socket(AF_INET6, SOCK_STREAM, 0); @@ -784,5 +616,4 @@ void init_dns(void) support_ipv6 = 1; } } -#endif } diff --git a/dos.c b/dos.c @@ -1,846 +0,0 @@ -#ifdef __DJGPP - -#include "links.h" - -#include <pc.h> -#include <dpmi.h> -#include <bios.h> -#include <go32.h> -#include <libc/dosio.h> -#include <sys/exceptn.h> -#include <sys/movedata.h> - -#define VIRTUAL_PIPE_SIZE 512 - -#define DOS_MOUSE_FLUSH_TIME 300 - -#undef read -#undef write -#undef close -#undef select - -/* - * Asynchronous exits from signal handler cause a crash if they interrupt - * networking in a wrong place. So, we use synchronous exit. - */ -static volatile unsigned char break_pressed = 0; -static volatile unsigned char break_exiting = 0; - -void dos_poll_break(void) -{ - if (break_pressed && !break_exiting) { - break_exiting = 1; - fatal_exit("Exiting on Ctrl+Break"); - } -} - -static void sigbreak(int sig) -{ - break_pressed = 1; -} - -static unsigned screen_x = 80; -static unsigned screen_y = 25; - -int get_terminal_size(int fd, int *x, int *y) -{ - *x = screen_x = ScreenCols(); - *y = screen_y = ScreenRows(); - return 0; -} - -void handle_terminal_resize(int fd, void (*fn)(void)) -{ -} - -void unhandle_terminal_resize(int fd) -{ -} - -static size_t init_seq_len; - -static unsigned char screen_initialized = 0; -static unsigned char *screen_backbuffer = NULL; -static int screen_backbuffer_x; -static int screen_backbuffer_y; -static int saved_cursor_x; -static int saved_cursor_y; -static unsigned char screen_default_attr; - -static unsigned cursor_x; -static unsigned cursor_y; -static unsigned current_attr; - -static unsigned char dos_mouse_initialized = 0; -static unsigned char dos_mouse_buttons; - -static int dos_mouse_last_x; -static int dos_mouse_last_y; -static int dos_mouse_last_button; -static uttime dos_mouse_time; - -static struct links_event *dos_mouse_queue = DUMMY; -static int dos_mouse_queue_n; - -static void (*txt_mouse_handler)(void *, unsigned char *, int) = NULL; -static void *txt_mouse_data; - -static int dos_mouse_coord(int v) -{ - if (!F) v /= 8; - return v; -} - -static void dos_mouse_show(void) -{ - if (dos_mouse_initialized && !F) { - __dpmi_regs r; - memset(&r, 0, sizeof r); - r.x.ax = 1; - __dpmi_int(0x33, &r); - } -} - -static void dos_mouse_hide(void) -{ - if (dos_mouse_initialized && !F) { - __dpmi_regs r; - memset(&r, 0, sizeof r); - r.x.ax = 2; - __dpmi_int(0x33, &r); - } -} - -static void dos_mouse_init(unsigned x, unsigned y) -{ - __dpmi_regs r; - memset(&r, 0, sizeof r); - __dpmi_int(0x33, &r); - if (r.x.ax != 0xffff) return; - dos_mouse_buttons = r.x.bx == 3 ? 3 : 2; - dos_mouse_initialized = 1; - memset(&r, 0, sizeof r); - r.x.ax = 7; - r.x.cx = 0; - r.x.dx = x - 1; - __dpmi_int(0x33, &r); - memset(&r, 0, sizeof r); - r.x.ax = 8; - r.x.cx = 0; - r.x.dx = y - 1; - __dpmi_int(0x33, &r); - memset(&r, 0, sizeof r); - r.x.ax = 3; - __dpmi_int(0x33, &r); - dos_mouse_last_x = dos_mouse_coord(r.x.cx); - dos_mouse_last_y = dos_mouse_coord(r.x.dx); - dos_mouse_last_button = r.x.bx; - dos_mouse_time = get_time(); -} - -void dos_mouse_terminate(void) -{ - mem_free(dos_mouse_queue); - dos_mouse_queue = DUMMY; - dos_mouse_queue_n = 0; - dos_mouse_hide(); -} - -static void dos_mouse_enqueue(int x, int y, int b) -{ - if (dos_mouse_queue_n && ((b & BM_ACT) == B_DRAG || (b & BM_ACT) == B_MOVE) && (b & BM_ACT) == (dos_mouse_queue[dos_mouse_queue_n - 1].b & BM_ACT)) { - dos_mouse_queue_n--; - goto set_last; - } - dos_mouse_queue = mem_realloc(dos_mouse_queue, (dos_mouse_queue_n + 1) * sizeof(struct links_event)); -set_last: - dos_mouse_queue[dos_mouse_queue_n].ev = EV_MOUSE; - dos_mouse_queue[dos_mouse_queue_n].x = x; - dos_mouse_queue[dos_mouse_queue_n].y = y; - dos_mouse_queue[dos_mouse_queue_n].b = b; - dos_mouse_queue_n++; -} - -static int dos_mouse_button(int b) -{ - switch (b) { - default: - case 0: return B_LEFT; - case 1: return B_RIGHT; - case 2: return B_MIDDLE; - } -} - -static void dos_mouse_poll(void) -{ - int i; - int cx, cy; - __dpmi_regs r; - dos_poll_break(); - if (dos_mouse_initialized) { - if (dos_mouse_initialized == 1 && get_time() - dos_mouse_time > DOS_MOUSE_FLUSH_TIME) - dos_mouse_initialized = 2; - for (i = 0; i < dos_mouse_buttons; i++) { - if (dos_mouse_initialized == 1 && i > 0) { - memset(&r, 0, sizeof r); - r.x.ax = 5; - r.x.bx = i; - __dpmi_int(0x33, &r); - memset(&r, 0, sizeof r); - r.x.ax = 6; - r.x.bx = i; - __dpmi_int(0x33, &r); - continue; - } - memset(&r, 0, sizeof r); - r.x.ax = !(dos_mouse_last_button & (1 << i)) ? 5 : 6; - r.x.bx = i; - __dpmi_int(0x33, &r); -px: - if (r.x.bx) { - dos_mouse_last_x = dos_mouse_coord(r.x.cx); - dos_mouse_last_y = dos_mouse_coord(r.x.dx); - dos_mouse_last_button ^= 1 << i; - dos_mouse_enqueue(dos_mouse_last_x, dos_mouse_last_y, dos_mouse_button(i) | (dos_mouse_last_button & (1 << i) ? B_DOWN : B_UP)); - /*printf("%s %d %d\n", dos_mouse_last_button & (1 << i) ? "press" : "release", r.x.cx, r.x.dx);*/ - if (!((dos_mouse_last_button ^ r.x.ax) & (1 << i))) { - memset(&r, 0, sizeof r); - r.x.ax = !(dos_mouse_last_button & (1 << i)) ? 5 : 6; - r.x.bx = i; - __dpmi_int(0x33, &r); - if ((dos_mouse_last_button ^ r.x.ax) & (1 << i)) - goto px; - } - } - } - memset(&r, 0, sizeof r); - r.x.ax = 3; - __dpmi_int(0x33, &r); - cx = dos_mouse_coord(r.x.cx); - cy = dos_mouse_coord(r.x.dx); - if (cx != dos_mouse_last_x || cy != dos_mouse_last_y) { - for (i = 0; i < dos_mouse_buttons; i++) - if (dos_mouse_last_button & (1 << i)) { - dos_mouse_enqueue(cx, cy, B_DRAG | dos_mouse_button(i)); - goto x; - } - if (F) dos_mouse_enqueue(cx, cy, B_MOVE); -x: - dos_mouse_last_x = cx; - dos_mouse_last_y = cy; - } - } -#if defined(G) && defined(GRDRV_GRX) - if (grx_mouse_initialized) { - grx_mouse_poll(); - } -#endif -} - -void *handle_mouse(int cons, void (*fn)(void *, unsigned char *, int), void *data) -{ - dos_mouse_init(screen_backbuffer_x * 8, screen_backbuffer_y * 8); - if (!dos_mouse_initialized) return NULL; - dos_mouse_show(); - txt_mouse_handler = fn; - txt_mouse_data = data; - - return (void *)1; -} - -void unhandle_mouse(void *data) -{ - dos_mouse_terminate(); - txt_mouse_handler = NULL; -} - -void want_draw(void) -{ - dos_mouse_hide(); -} - -void done_draw(void) -{ - dos_mouse_show(); -} - -static int dos_mouse_event(void) -{ - if (dos_mouse_queue_n) { - if (!F && txt_mouse_handler) { - struct links_event *q = dos_mouse_queue; - int ql = dos_mouse_queue_n; - dos_mouse_queue = DUMMY; - dos_mouse_queue_n = 0; - txt_mouse_handler(txt_mouse_data, (unsigned char *)(void *)q, ql * sizeof(struct links_event)); - mem_free(q); - return 1; - } - } -#if defined(G) && defined(GRDRV_GRX) - if (grx_mouse_initialized) { - return grx_mouse_event(); - } -#endif - return 0; -} - -void dos_save_screen(void) -{ - unsigned char *sc; - screen_backbuffer_x = ScreenCols(); - screen_backbuffer_y = ScreenRows(); - screen_default_attr = ScreenAttrib; - if (screen_backbuffer) { - sc = screen_backbuffer; - screen_backbuffer = NULL; - mem_free(sc); - } - sc = mem_alloc(2 * screen_backbuffer_x * screen_backbuffer_y); - ScreenRetrieve(sc); - ScreenGetCursor(&saved_cursor_y, &saved_cursor_x); - screen_backbuffer = sc; -} - -void dos_restore_screen(void) -{ - if (screen_backbuffer) { - unsigned char *sc; - if (ScreenCols() == screen_backbuffer_x && ScreenRows() == screen_backbuffer_y) { - ScreenUpdate(screen_backbuffer); - ScreenSetCursor(saved_cursor_y, saved_cursor_x); - } - sc = screen_backbuffer; - screen_backbuffer = NULL; - mem_free(sc); - } -} - -static void ansi_initialize(void) -{ - if (screen_initialized) - return; - - dos_save_screen(); - - ScreenClear(); - cursor_x = 0; - cursor_y = 0; - current_attr = screen_default_attr; - screen_initialized = 1; -} - -static void ansi_terminate(void) -{ - if (!screen_initialized) - return; - - ScreenSetCursor(0, 0); - dos_restore_screen(); - screen_initialized = 0; -} - -static unsigned ansi2pc(unsigned c) -{ - return ((c & 4) >> 2) | (c & 2) | ((c & 1) << 2); -} - -static void ansi_write(const unsigned char *str, size_t size) -{ - if (!screen_initialized) { - if (size >= init_seq_len && !memcmp(str, init_seq, init_seq_len)) { - ansi_initialize(); - goto process_ansi; - } - write(1, str, size); - return; - } -process_ansi: - while (size--) { - unsigned char c = *str++; - unsigned char buffer[128]; - unsigned buf_size; - unsigned clen; - unsigned x, y; - switch (c) { - case 7: - continue; - case 10: - cursor_y++; - /*-fallthrough*/ - case 13: - cursor_x = 0; - break; - case 27: - if (!size--) goto ret; - switch (*str++) { - case ')': - if (!size--) goto ret; - str++; - continue; - case '7': - default: - continue; - case '8': - ansi_terminate(); - goto ret2; - case '[': - clen = 0; - while (1) { - unsigned char u; - if (clen >= size) goto ret; - u = upcase(str[clen]); - if (u >= 'A' && u <= 'Z') - break; - clen++; - } - } - if (clen >= sizeof(buffer)) goto ret; - memcpy(buffer, str, clen); - buffer[clen] = 0; - switch (str[clen]) { - case 'J': - if (!strcmp(cast_const_char buffer, "2")) - ScreenClear(); - break; - case 'H': - if (sscanf(cast_const_char buffer, "%u;%u", &y, &x) == 2) { - cursor_x = x - 1; - cursor_y = y - 1; - } - break; - case 'm': - while (buffer[0] >= '0' && buffer[0] < '9') { - unsigned long a; - unsigned char *e; - a = strtoul(cast_const_char buffer, (char **)(void *)&e, 10); - if (*e == ';') e++; - memmove(buffer, e, strlen(cast_const_char e) + 1); - switch (a) { - case 0: - current_attr = screen_default_attr; - break; - case 1: - current_attr |= 0x08; - break; - case 7: - current_attr = ((screen_default_attr & 0x70) >> 4) | ((screen_default_attr & 0x07) << 4); - break; - case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: - current_attr = (current_attr & 0x78) | ansi2pc(a - 30); - break; - case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: - current_attr = (current_attr & 0x0f) | (ansi2pc(a - 40) << 4); - break; - } - } - break; - } - str += clen + 1; - size -= clen + 1; - continue; - default: - buffer[0] = c; - buf_size = 1; - while (size && *str >= ' ' && buf_size < sizeof(buffer) - 1) { - buffer[buf_size++] = *str++; - size--; - } - buffer[buf_size] = 0; - ScreenPutString(cast_const_char buffer, current_attr, cursor_x, cursor_y); - cursor_x += buf_size; - break; - } - } -ret: - ScreenSetCursor(cursor_y, cursor_x); -ret2:; -} - -#ifdef DOS_EXTRA_KEYBOARD - -static short dos_buffered_char = -1; - -static int dos_select_keyboard(void) -{ - int bk; - if (dos_buffered_char >= 0) return 1; - bk = bioskey(0x11); - return !!bk; -} - -static int dos_read_keyboard(void *buf, size_t size) -{ - int k; - if (!size) return 0; - if (dos_buffered_char >= 0) { - *(unsigned char *)buf = dos_buffered_char; - dos_buffered_char = -1; - return 1; - } - k = getkey(); - if (!k) return 0; - /*printf("returned key %04x\n", k);*/ - if (k < 0x100) { - *(unsigned char *)buf = k; - return 1; - } else { - *(unsigned char *)buf = 0; - if (size >= 2) { - *((unsigned char *)buf + 1) = k; - return 2; - } else { - dos_buffered_char = k & 0xff; - return 1; - } - } -} - -#endif - -static inline void pipe_lock(void) -{ -} - -static inline void pipe_unlock(void) -{ -} - -static inline void pipe_unlock_wait(void) -{ -} - -static inline void pipe_wake(void) -{ -} - -#include "vpipe.inc" - -int c_pipe(int *fd) -{ - int r = vpipe_create(fd); - /*printf("c_pipe: (%d) : %d,%d\n", r, fd[0], fd[1]);*/ - return r; -} - -void set_nonblock(int fd) -{ - int rs; - EINTRLOOP(rs, fcntl(fd, F_SETFL, O_NONBLOCK)); -} - -int dos_read(int fd, void *buf, size_t size) -{ - int r; - dos_mouse_poll(); - r = vpipe_read(fd, buf, size); - /*printf("dos_read(%d,%d) : %d,%d\n", r, errno, fd, size);*/ - if (r != -2) return r; -#ifdef DOS_EXTRA_KEYBOARD - if (fd == 0) return dos_read_keyboard(buf, size); -#endif - return read(fd, buf, size); -} - -int dos_write(int fd, const void *buf, size_t size) -{ - int r; - dos_mouse_poll(); - r = vpipe_write(fd, buf, size); - /*printf("dos_write(%d,%d) : %d,%d\n", r, errno, fd, size);*/ - if (r != -2) return r; - if (fd == 1) { - ansi_write(buf, size); - return size; - } - return write(fd, buf, size); -} - -int dos_close(int fd) -{ - int r; - r = vpipe_close(fd); - if (r != -2) return r; - return close(fd); -} - -int dos_select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t, int from_main_loop) -{ - int i; - int last_pass = 0; - int ret_cnt = 0; - - int r; - fd_set rsb, wsb, esb; - struct timeval xtime; - - dos_mouse_poll(); - - pipe_lock(); - for (i = 0; i < n; i++) { - int ts = 0; - if (rs && FD_ISSET(i, rs)) { - int signaled = 0; - if (pipe_desc[i]) { - if (vpipe_may_read(i)) - signaled = 1; - else - FD_CLR(i, rs); - /*printf("dos_select_read(%d) : %d\n", i, vpipe_may_read(i));*/ - } else { - } - if (!last_pass) { - if (signaled) { - clear_inactive(rs, i); - clear_inactive(ws, i); - clear_inactive(es, i); - last_pass = 1; - } - } else { - if (!signaled) FD_CLR(i, rs); - } - ts |= signaled; - } - if (ws && FD_ISSET(i, ws)) { - int signaled = 0; - if (pipe_desc[i]) { - if (vpipe_may_write(i)) - signaled = 1; - else - FD_CLR(i, ws); - /*printf("dos_select_write(%d) : %d\n", i, vpipe_may_write(i));*/ - } else { - } - if (!last_pass) { - if (signaled) { - clear_inactive(rs, i + 1); - clear_inactive(ws, i); - clear_inactive(es, i); - last_pass = 1; - } - } else { - if (!signaled) FD_CLR(i, ws); - } - ts |= signaled; - } - if (es && FD_ISSET(i, es)) { - int signaled = 0; - if (pipe_desc[i]) { - FD_CLR(i, es); - } else { - } - if (!last_pass) { - if (signaled) { - clear_inactive(rs, i + 1); - clear_inactive(ws, i + 1); - clear_inactive(es, i); - last_pass = 1; - } - } else { - if (!signaled) FD_CLR(i, es); - } - ts |= signaled; - } - if (last_pass) ret_cnt += ts; - } - pipe_unlock(); - if (last_pass) { - /*printf("ret_cnt: %d\n", ret_cnt);*/ - return ret_cnt; - } - /*printf("real select\n");*/ - /*return select(n, rs, ws, es, t);*/ - if (rs) rsb = *rs; - else FD_ZERO(&rsb); - if (ws) wsb = *ws; - else FD_ZERO(&wsb); - if (es) esb = *es; - else FD_ZERO(&esb); - if (t) { - EINTRLOOP(r, gettimeofday(&xtime, NULL)); - if (r) fatal_exit("gettimeofday failed: %d", errno); - xtime.tv_usec += t->tv_usec; - if (xtime.tv_usec >= 1000000) { - xtime.tv_usec -= 1000000; - xtime.tv_sec++; - } - xtime.tv_sec += t->tv_sec; - } - while (1) { - struct timeval zero = { 0, 0 }; - struct timeval now; -#ifdef DOS_EXTRA_KEYBOARD - if (rs && FD_ISSET(0, rs)) { - if (dos_select_keyboard()) { - FD_ZERO(rs); - FD_SET(0, rs); - if (ws) FD_ZERO(ws); - if (es) FD_ZERO(es); - if (from_main_loop && dos_mouse_event()) - check_bottom_halves(); - return 1; - } - FD_CLR(0, rs); - } -#endif - if (from_main_loop && dos_mouse_event()) { - check_bottom_halves(); - return 0; - } - r = select(n, rs, ws, es, &zero); - if (r == -1 && errno == EBADF) { - /* DJGPP occasionally returns EBADF */ - int re = 0; - if (rs) FD_ZERO(rs); - if (ws) FD_ZERO(ws); - if (es) FD_ZERO(es); - i = 0; -#ifdef DOS_EXTRA_KEYBOARD - i++; -#endif - for (; i < n; i++) { - fd_set rsx; - fd_set wsx; - fd_set esx; - int x, s; - if (!FD_ISSET(i, &rsb) && - !FD_ISSET(i, &wsb) && - !FD_ISSET(i, &esb)) - continue; - FD_ZERO(&rsx); - FD_ZERO(&wsx); - FD_ZERO(&esx); - if (FD_ISSET(i, &rsb)) FD_SET(i, &rsx); - if (FD_ISSET(i, &wsb)) FD_SET(i, &wsx); - if (FD_ISSET(i, &esb)) FD_SET(i, &esx); - zero.tv_sec = 0; - zero.tv_usec = 0; - x = select(i + 1, &rsx, &wsx, &esx, &zero); - s = 0; - if (FD_ISSET(i, &rsb) && (x < 0 || (x > 0 && FD_ISSET(i, &rsx)))) FD_SET(i, rs), s = 1; - if (FD_ISSET(i, &wsb) && (x < 0 || (x > 0 && FD_ISSET(i, &wsx)))) FD_SET(i, ws), s = 1; - if (FD_ISSET(i, &esb) && (x < 0 || (x > 0 && FD_ISSET(i, &esx)))) FD_SET(i, es), s = 1; - if (s) re++; - } - if (re) return re; - r = 0; - } - if (r) return r; - EINTRLOOP(r, gettimeofday(&now, NULL)); - if (r) fatal_exit("gettimeofday failed: %d", errno); - if (t) { - if (now.tv_sec > xtime.tv_sec || - (now.tv_sec == xtime.tv_sec && now.tv_usec >= xtime.tv_usec)) - return 0; - } - if (rs) *rs = rsb; - if (ws) *ws = wsb; - if (es) *es = esb; - dos_mouse_poll(); - __dpmi_yield(); - dos_mouse_poll(); - } -} - -#ifdef DOS_EXTRA_KEYBOARD - -int setraw(int ctl, int save) -{ - __djgpp_set_ctrl_c(0); - return 0; -} - -void setcooked(int ctl) -{ -} - -#endif - -#define RANDOM_POOL_SIZE 65536 - -void os_seed_random(unsigned char **pool, int *pool_size) -{ - unsigned *random_pool, *tmp_pool; - int a, i; - random_pool = mem_alloc(RANDOM_POOL_SIZE); - tmp_pool = mem_alloc(RANDOM_POOL_SIZE); - for (a = 0; a <= 640 * 1024 - RANDOM_POOL_SIZE; a += RANDOM_POOL_SIZE) { - dosmemget(a, RANDOM_POOL_SIZE, tmp_pool); - for (i = 0; i < RANDOM_POOL_SIZE / 4; i++) - random_pool[i] += tmp_pool[i]; - } - mem_free(tmp_pool); - *pool = (unsigned char *)(void *)random_pool; - *pool_size = RANDOM_POOL_SIZE; -} - -void init_os(void) -{ - int s, rs; - struct sigaction sa; - - init_seq_len = strlen(cast_const_char init_seq); - - /* preload the packet driver */ - s = c_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - if (s >= 0) { - EINTRLOOP(rs, close(s)); - } - - tcp_cbreak(1); - - memset(&sa, 0, sizeof sa); - sa.sa_handler = sigbreak; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; - EINTRLOOP(rs, sigaction(SIGINT, &sa, NULL)); -} - -void terminate_osdep(void) -{ - if (screen_backbuffer) - mem_free(screen_backbuffer); -} - -int os_default_language(void) -{ - __dpmi_regs r; - memset(&r, 0, sizeof r); - r.x.ax = 0x3800; - r.x.dx = __tb_offset; - r.x.ds = __tb_segment; - __dpmi_int(0x21, &r); - if (!(r.x.flags & 1)) { - return get_country_language(r.x.bx); - } - return -1; -} - -int os_default_charset(void) -{ - __dpmi_regs r; - memset(&r, 0, sizeof r); - r.x.ax = 0x6601; - __dpmi_int(0x21, &r); - if (!(r.x.flags & 1)) { - unsigned char a[8]; - int cp; - snprintf(cast_char a, sizeof a, "%d", r.x.bx); - if ((cp = get_cp_index(a)) >= 0 && cp != utf8_table) - return cp; - } - return 0; -} - -int dos_is_bw(void) -{ - unsigned char cfg; - dosmemget(0x410, sizeof cfg, &cfg); - return (cfg & 0x30) == 0x30; -} - -#else - -typedef int dos_c_no_empty_unit; - -#endif diff --git a/drivers.c b/drivers.c @@ -16,27 +16,6 @@ struct graphics_driver *drv = NULL; #ifdef GRDRV_X extern struct graphics_driver x_driver; #endif -#ifdef GRDRV_SVGALIB -extern struct graphics_driver svga_driver; -#endif -#ifdef GRDRV_FB -extern struct graphics_driver fb_driver; -#endif -#ifdef GRDRV_DIRECTFB -extern struct graphics_driver directfb_driver; -#endif -#ifdef GRDRV_PMSHELL -extern struct graphics_driver pmshell_driver; -#endif -#ifdef GRDRV_ATHEOS -extern struct graphics_driver atheos_driver; -#endif -#ifdef GRDRV_GRX -extern struct graphics_driver grx_driver; -#endif -#ifdef GRDRV_SDL -extern struct graphics_driver sdl_driver; -#endif /* * On SPAD you must test first svgalib and then X (because X test is slow). @@ -45,38 +24,9 @@ extern struct graphics_driver sdl_driver; */ static struct graphics_driver *graphics_drivers[] = { -#ifdef GRDRV_PMSHELL - &pmshell_driver, -#endif -#ifdef GRDRV_ATHEOS - &atheos_driver, -#endif -#ifndef SPAD -#ifdef GRDRV_X - &x_driver, -#endif -#endif -#ifdef GRDRV_FB - /* use FB before DirectFB because DirectFB has bugs */ - &fb_driver, -#endif -#ifdef GRDRV_DIRECTFB - &directfb_driver, -#endif -#ifdef GRDRV_SVGALIB - &svga_driver, -#endif -#ifdef SPAD #ifdef GRDRV_X &x_driver, #endif -#endif -#ifdef GRDRV_GRX - &grx_driver, -#endif -#ifdef GRDRV_SDL - &sdl_driver, -#endif NULL }; @@ -140,18 +90,6 @@ unsigned char *init_graphics(unsigned char *driver, unsigned char *param, unsign unsigned char *s = init_str(); int l = 0; struct graphics_driver **gd; -#if defined(GRDRV_PMSHELL) && defined(GRDRV_X) - if (is_xterm()) { - static unsigned char swapped = 0; - if (!swapped) { - for (gd = graphics_drivers; *gd; gd++) { - if (*gd == &pmshell_driver) *gd = &x_driver; - else if (*gd == &x_driver) *gd = &pmshell_driver; - } - swapped = 1; - } - } -#endif for (gd = graphics_drivers; *gd; gd++) { if (!driver || !*driver || !casestrcmp((*gd)->name, driver)) { unsigned char *r; @@ -224,122 +162,5 @@ void generic_set_clip_area(struct graphics_device *dev, struct rect *r) } } -#ifdef GRDRV_VIRTUAL_DEVICES - -struct graphics_device **virtual_devices; -int n_virtual_devices = 0; -struct graphics_device *current_virtual_device; - -static struct timer *virtual_device_timer; - -int init_virtual_devices(struct graphics_driver *drv, int n) -{ - if (n_virtual_devices) { - internal("init_virtual_devices: already initialized"); - return -1; - } - if ((unsigned)n > MAXINT / sizeof(struct graphics_device *)) overalloc(); - virtual_devices = mem_calloc(n * sizeof(struct graphics_device *)); - n_virtual_devices = n; - virtual_device_timer = NULL; - current_virtual_device = NULL; - return 0; -} - -struct graphics_device *init_virtual_device(void) -{ - int i; - for (i = 0; i < n_virtual_devices; i++) if (!virtual_devices[i]) { - struct graphics_device *dev; - dev = mem_calloc(sizeof(struct graphics_device)); - dev->size.x2 = drv->x; - dev->size.y2 = drv->y; - current_virtual_device = virtual_devices[i] = dev; - drv->set_clip_area(dev, &dev->size); - return dev; - } - return NULL; -} - -static void virtual_device_timer_fn(void *p) -{ - virtual_device_timer = NULL; - if (current_virtual_device && current_virtual_device->redraw_handler) { - drv->set_clip_area(current_virtual_device, &current_virtual_device->size); - current_virtual_device->redraw_handler(current_virtual_device, &current_virtual_device->size); - } -} - -void switch_virtual_device(int i) -{ - if (i == VD_NEXT) { - int j; - int t = 0; - for (j = 0; j < n_virtual_devices * 2; j++) - if (virtual_devices[j % n_virtual_devices] == current_virtual_device) t = 1; - else if (virtual_devices[j % n_virtual_devices] && t) { - current_virtual_device = virtual_devices[j % n_virtual_devices]; - goto ok_switch; - } - return; - } - if (i < 0 || i >= n_virtual_devices || !virtual_devices[i]) return; - current_virtual_device = virtual_devices[i]; - ok_switch: - if (virtual_device_timer == NULL) - virtual_device_timer = install_timer(0, virtual_device_timer_fn, NULL); -} - -void shutdown_virtual_device(struct graphics_device *dev) -{ - int i; - for (i = 0; i < n_virtual_devices; i++) if (virtual_devices[i] == dev) { - virtual_devices[i] = NULL; - mem_free(dev); - if (current_virtual_device != dev) return; - for (; i < n_virtual_devices; i++) if (virtual_devices[i]) { - switch_virtual_device(i); - return; - } - for (i = 0; i < n_virtual_devices; i++) if (virtual_devices[i]) { - switch_virtual_device(i); - return; - } - current_virtual_device = NULL; - return; - } - mem_free(dev); - /*internal("shutdown_virtual_device: device not initialized");*/ -} - -void resize_virtual_devices(int x, int y) -{ - int i; - drv->x = x; - drv->y = y; - for (i = 0; i < n_virtual_devices; i++) { - struct graphics_device *dev = virtual_devices[i]; - if (dev) { - dev->size.x2 = x; - dev->size.y2 = y; - dev->resize_handler(dev); - } - } -} - -void shutdown_virtual_devices(void) -{ - int i; - if (!n_virtual_devices) { - internal("shutdown_virtual_devices: already shut down"); - return; - } - for (i = 0; i < n_virtual_devices; i++) if (virtual_devices[i]) internal("shutdown_virtual_devices: virtual device %d is still active", i); - mem_free(virtual_devices); - n_virtual_devices = 0; - if (virtual_device_timer != NULL) kill_timer(virtual_device_timer), virtual_device_timer = NULL; -} - -#endif #endif diff --git a/error.c b/error.c @@ -5,18 +5,7 @@ #include "links.h" -#if DEBUGLEVEL >= 2 -#define RED_ZONE 'R' -#endif -#if DEBUGLEVEL >= 3 -#define FREE_FILL 0xfe -#define REALLOC_FILL 0xfd -#define ALLOC_FILL 0xfc -#endif -#if DEBUGLEVEL < 0 -#define FREE_FILL 0xfe -#endif #ifdef RED_ZONE #define RED_ZONE_INC 1 @@ -37,151 +26,36 @@ void *do_not_optimize_here(void *p) } -#if defined(USE_WIN32_HEAP) - -#include <windows.h> - -/*#define NEW_HEAP*/ - -static HANDLE heap; - -#define heap_malloc(s) HeapAlloc(heap, 0, (s)) -#define heap_calloc(s) HeapAlloc(heap, HEAP_ZERO_MEMORY, (s)) -#define heap_free(p) HeapFree(heap, 0, (p)) -#define heap_realloc(p, s) HeapReAlloc(heap, 0, (p), (s)) - -void init_heap(void) -{ -#ifndef NEW_HEAP - heap = GetProcessHeap(); -#else - if (!(heap = HeapCreate(0, 0, 0))) - fatal_exit("HeapCreate failed: %x", (unsigned)GetLastError()); -#endif - { - ULONG heap_frag = 2; - if (!HeapSetInformation(heap, HeapCompatibilityInformation, &heap_frag, sizeof(heap_frag))) { - /*fatal_exit("HeapSetInformation failed: %x", (unsigned)GetLastError());*/ - } - } -} - -static void exit_heap(void) -{ -#if DEBUGLEVEL >= 1 - if (!HeapValidate(heap, 0, NULL)) - internal("HeapValidate failed: %x", (unsigned)GetLastError()); -#endif -#ifdef NEW_HEAP - if (!HeapDestroy(heap)) - internal("HeapDestroy failed: %x", (unsigned)GetLastError()); -#endif -} - -#else #define heap_malloc malloc #define heap_realloc realloc #define heap_free free -#ifdef HAVE_CALLOC #define heap_calloc(x) calloc(1, (x)) -#else -static inline void *heap_calloc(size_t x) -{ - void *p; - if ((p = heap_malloc(x))) memset(p, 0, x); - return p; -} -#endif void init_heap(void) { } #define exit_heap() do { } while (0) -#endif - - -#ifdef LEAK_DEBUG - -my_uintptr_t mem_amount = 0; -my_uintptr_t mem_blocks = 0; - -#define ALLOC_MAGIC 0xa110c -#define ALLOC_FREE_MAGIC 0xf4ee -#define ALLOC_REALLOC_MAGIC 0x4ea110c - -#ifndef LEAK_DEBUG_LIST -struct alloc_header { - int magic; - size_t size; -}; -#else -struct alloc_header { - list_entry_1st - size_t size; - unsigned char *file; - unsigned char *comment; - list_entry_last - int line; - int magic; -}; -static struct list_head memory_list = { &memory_list, &memory_list }; -#endif - -#define L_D_S ((sizeof(struct alloc_header) + 15) & ~15) -unsigned alloc_overhead = L_D_S + RED_ZONE_INC; -#endif static inline void force_dump(void) { -#if defined(DOS) - fprintf(stderr, "\n"ANSI_SET_BOLD"Exiting"ANSI_CLEAR_BOLD"\n"); - fflush(stdout); - fflush(stderr); - exit(RET_INTERNAL); -#else int rs; fprintf(stderr, "\n"ANSI_SET_BOLD"Forcing core dump"ANSI_CLEAR_BOLD"\n"); fflush(stdout); fflush(stderr); EINTRLOOP(rs, raise(SIGSEGV)); -#endif } void check_memory_leaks(void) { -#if defined(LEAK_DEBUG) && !defined(NO_IE) - if (mem_amount || mem_blocks) { - fatal_tty_exit(); - fprintf(stderr, "\n"ANSI_SET_BOLD"Memory leak by %lu bytes (%lu blocks)"ANSI_CLEAR_BOLD"\n", (unsigned long)mem_amount, (unsigned long)mem_blocks); -#ifdef LEAK_DEBUG_LIST - fprintf(stderr, "\nList of blocks: "); - { - int r = 0; - struct alloc_header *ah; - struct list_head *lah; - foreach(struct alloc_header, ah, lah, memory_list) { - fprintf(stderr, "%s%p:%lu @ %s:%d", r ? ", ": "", (unsigned char *)ah + L_D_S, (unsigned long)ah->size, ah->file, ah->line), r = 1; - if (ah->comment) fprintf(stderr, ":\"%s\"", ah->comment); - } - fprintf(stderr, "\n"); - } -#endif - force_dump(); - } -#endif exit_heap(); } static void er(int b, char *m, va_list l) { -#ifdef HAVE_VPRINTF vfprintf(stderr, cast_const_char m, l); -#else - fprintf(stderr, "%s", m); -#endif if (b) fprintf(stderr, ANSI_BELL); fprintf(stderr, "\n"); fflush(stderr); @@ -240,236 +114,6 @@ void debug_msg(char *m, ...) va_end(l); } -#ifdef LEAK_DEBUG - -void *debug_mem_alloc(unsigned char *file, int line, size_t size, int mayfail) -{ - void *p; -#ifdef LEAK_DEBUG - struct alloc_header *ah; -#endif - dos_poll_break(); - debug_test_free(file, line); - if (!size) return DUMMY; - if (size > MAXINT) { - if (mayfail) return NULL; - overalloc_at(file, line); - } - size += L_D_S; - retry: -#ifdef LEAK_DEBUG - mem_amount += size - L_D_S; - mem_blocks++; -#endif - if (!(p = heap_malloc(size + RED_ZONE_INC))) { -#ifdef LEAK_DEBUG - mem_amount -= size - L_D_S; - mem_blocks--; -#endif - if (out_of_memory_fl(0, !mayfail ? cast_uchar "malloc" : NULL, size + RED_ZONE_INC, file, line)) goto retry; - return NULL; - } -#ifdef RED_ZONE - *((unsigned char *)p + size + RED_ZONE_INC - 1) = RED_ZONE; -#endif -#ifdef LEAK_DEBUG - ah = p; - p = (unsigned char *)p + L_D_S; - ah->size = size - L_D_S; - ah->magic = ALLOC_MAGIC; -#ifdef LEAK_DEBUG_LIST - ah->file = file; - ah->line = line; - ah->comment = NULL; - add_to_list(memory_list, ah); -#endif -#endif -#ifdef ALLOC_FILL - memset(p, ALLOC_FILL, size - L_D_S); -#endif - return p; -} - -void *debug_mem_calloc(unsigned char *file, int line, size_t size, int mayfail) -{ - void *p; -#ifdef LEAK_DEBUG - struct alloc_header *ah; -#endif - dos_poll_break(); - debug_test_free(file, line); - if (!size) return DUMMY; - if (size > MAXINT) { - if (mayfail) return NULL; - overalloc_at(file, line); - } - size += L_D_S; - retry: -#ifdef LEAK_DEBUG - mem_amount += size - L_D_S; - mem_blocks++; -#endif - if (!(p = heap_calloc(size + RED_ZONE_INC))) { -#ifdef LEAK_DEBUG - mem_amount -= size - L_D_S; - mem_blocks--; -#endif - if (out_of_memory_fl(0, !mayfail ? cast_uchar "calloc" : NULL, size + RED_ZONE_INC, file, line)) goto retry; - return NULL; - } -#ifdef RED_ZONE - *((unsigned char *)p + size + RED_ZONE_INC - 1) = RED_ZONE; -#endif -#ifdef LEAK_DEBUG - ah = p; - p = (unsigned char *)p + L_D_S; - ah->size = size - L_D_S; - ah->magic = ALLOC_MAGIC; -#ifdef LEAK_DEBUG_LIST - ah->file = file; - ah->line = line; - ah->comment = NULL; - add_to_list(memory_list, ah); -#endif -#endif - return p; -} - -void debug_mem_free(unsigned char *file, int line, void *p) -{ -#ifdef LEAK_DEBUG - struct alloc_header *ah; -#endif - dos_poll_break(); - if (p == DUMMY) return; - if (!p) { - errfile = file, errline = line, int_error("mem_free(NULL)"); - return; - } -#ifdef LEAK_DEBUG - p = (unsigned char *)p - L_D_S; - ah = p; - if (ah->magic != ALLOC_MAGIC) { - errfile = file, errline = line, int_error("mem_free: magic doesn't match: %08x", ah->magic); - return; - } -#ifdef FREE_FILL - memset((unsigned char *)p + L_D_S, FREE_FILL, ah->size); -#endif - ah->magic = ALLOC_FREE_MAGIC; -#ifdef LEAK_DEBUG_LIST - del_from_list(ah); - if (ah->comment) heap_free(ah->comment); -#endif - mem_amount -= ah->size; - mem_blocks--; -#endif -#ifdef RED_ZONE - if (*((unsigned char *)p + L_D_S + ah->size + RED_ZONE_INC - 1) != RED_ZONE) { - errfile = file, errline = line, int_error("mem_free: red zone damaged: %02x (block allocated at %s:%d%s%s)", *((unsigned char *)p + L_D_S + ah->size + RED_ZONE_INC - 1), -#ifdef LEAK_DEBUG_LIST - ah->file, ah->line, ah->comment ? ":" : "", ah->comment ? ah->comment : (unsigned char *)""); -#else - "-", 0, "-"); -#endif - return; - } -#endif - heap_free(p); -} - -void *debug_mem_realloc(unsigned char *file, int line, void *p, size_t size, int mayfail) -{ -#ifdef LEAK_DEBUG - struct alloc_header *ah; -#endif - void *np; - if (p == DUMMY) return debug_mem_alloc(file, line, size, mayfail); - dos_poll_break(); - debug_test_free(file, line); - if (!p) { - errfile = file, errline = line, int_error("mem_realloc(NULL, %lu)", (unsigned long)size); - return NULL; - } - if (!size) { - debug_mem_free(file, line, p); - return DUMMY; - } - if (size > MAXINT) { - if (mayfail) return NULL; - overalloc_at(file, line); - } -#ifdef LEAK_DEBUG - p = (unsigned char *)p - L_D_S; - ah = p; - if (ah->magic != ALLOC_MAGIC) { - errfile = file, errline = line, int_error("mem_realloc: magic doesn't match: %08x", ah->magic); - return NULL; - } - ah->magic = ALLOC_REALLOC_MAGIC; -#ifdef REALLOC_FILL - if (!mayfail && size < (size_t)ah->size) memset((unsigned char *)p + L_D_S + size, REALLOC_FILL, ah->size - size); -#endif -#endif -#ifdef RED_ZONE - if (*((unsigned char *)p + L_D_S + ah->size + RED_ZONE_INC - 1) != RED_ZONE) { - errfile = file, errline = line, int_error("mem_realloc: red zone damaged: %02x (block allocated at %s:%d%s%s)", *((unsigned char *)p + L_D_S + ah->size + RED_ZONE_INC - 1), -#ifdef LEAK_DEBUG_LIST - ah->file, ah->line, ah->comment ? ":" : "", ah->comment ? ah->comment : (unsigned char *)""); -#else - "-", 0, "-"); -#endif - return (unsigned char *)p + L_D_S; - } -#endif - retry: - if (!(np = heap_realloc(p, size + L_D_S + RED_ZONE_INC))) { - if (out_of_memory_fl(0, !mayfail ? cast_uchar "realloc" : NULL, size + L_D_S + RED_ZONE_INC, file, line)) goto retry; - ah->magic = ALLOC_MAGIC; - return NULL; - } - p = np; -#ifdef RED_ZONE - *((unsigned char *)p + size + L_D_S + RED_ZONE_INC - 1) = RED_ZONE; -#endif -#ifdef LEAK_DEBUG - ah = p; - /* OpenVMS Alpha C miscompiles this: mem_amount += size - ah->size; */ - mem_amount += size; - mem_amount -= ah->size; - ah->size = size; - ah->magic = ALLOC_MAGIC; -#ifdef LEAK_DEBUG_LIST - fix_list_after_realloc(ah); -#endif -#endif - return (unsigned char *)p + L_D_S; -} - -void set_mem_comment(void *p, unsigned char *c, int l) -{ -#ifdef LEAK_DEBUG_LIST - struct alloc_header *ah = (struct alloc_header *)((unsigned char *)p - L_D_S); - if (ah->comment) heap_free(ah->comment); - if ((ah->comment = heap_malloc(l + 1))) memcpy(ah->comment, c, l), ah->comment[l] = 0; -#endif -} - -#ifdef JS -unsigned char *get_mem_comment(void *p) -{ -#ifdef LEAK_DEBUG_LIST - /* perm je prase: return ((struct alloc_header*)((unsigned char*)((void*)((unsigned char*)p-sizeof(int))) - L_D_S))->comment;*/ - struct alloc_header *ah = (struct alloc_header *)((unsigned char *)p - L_D_S); - if (!ah->comment) return cast_uchar ""; - else return ah->comment; -#else - return cast_uchar ""; -#endif -} -#endif - -#else void *mem_alloc_(size_t size, int mayfail) { @@ -544,9 +188,7 @@ void *mem_realloc_(void *p, size_t size, int mayfail) return np; } -#endif -#if !(defined(LEAK_DEBUG) && defined(LEAK_DEBUG_LIST)) unsigned char *memacpy(const unsigned char *src, size_t len) { @@ -564,89 +206,6 @@ unsigned char *stracpy(const unsigned char *src) return src ? memacpy(src, src != DUMMY ? strlen(cast_const_char src) : 0) : NULL; } -#else - -unsigned char *debug_memacpy(unsigned char *f, int l, const unsigned char *src, size_t len) -{ - unsigned char *m; - m = (unsigned char *)debug_mem_alloc(f, l, len + 1, 0); - if (len) - memcpy(m, src, len); - m[len] = 0; - return m; -} - -unsigned char *debug_stracpy(unsigned char *f, int l, const unsigned char *src) -{ - return src ? (unsigned char *)debug_memacpy(f, l, src, src != DUMMY ? strlen(cast_const_char src) : 0L) : NULL; -} - -#endif - -#ifdef OOPS -struct prot { - list_entry_1st - sigjmp_buf buf; - list_entry_last -}; - -static struct list_head prot = { &prot, &prot }; - -static void fault(void *dummy) -{ - struct prot *p; - /*fprintf(stderr, "FAULT: %d !\n", (int)(unsigned long)dummy);*/ - if (list_empty(prot)) { - fatal_tty_exit(); - exit(0); - } - p = list_struct(prot.next, struct prot); - del_from_list(p); - longjmp(p->buf, 1); -} - -sigjmp_buf *new_stack_frame(void) -{ - static int handled = 0; - struct prot *new; - if (!handled) { -#ifdef SIGILL - install_signal_handler(SIGILL, fault, (void *)SIGILL, 1); -#endif -#ifdef SIGABRT - install_signal_handler(SIGABRT, fault, (void *)SIGABRT, 1); -#endif -#ifdef SIGFPE - install_signal_handler(SIGFPE, fault, (void *)SIGFPE, 1); -#endif -#ifdef SIGSEGV - install_signal_handler(SIGSEGV, fault, (void *)SIGSEGV, 1); -#endif -#ifdef SIGBUS - install_signal_handler(SIGBUS, fault, (void *)SIGBUS, 1); -#endif - handled = 1; - } - if (!(new = mem_alloc(sizeof(struct prot)))) return NULL; - add_to_list(prot, new); - return &new->buf; -} - -void xpr(void) -{ - if (!list_empty(prot)) { - struct prot *next = list_struct(prot.next, struct prot); - del_from_list(next); - mem_free(next); - } -} - -void nopr(void) -{ - free_list(struct prot, prot); -} - -#endif diff --git a/file.c b/file.c @@ -170,16 +170,12 @@ static void stat_date(unsigned char **p, int *l, struct stat *stp) if ((ulonglong)current_time > (ulonglong)when + 6L * 30L * 24L * 60L * 60L || (ulonglong)current_time < (ulonglong)when - 60L * 60L) fmt = fmt1; else fmt = fmt2; -#ifdef HAVE_STRFTIME again: wr = (int)strftime(cast_char str, 13, cast_const_char fmt, when_local); if (wr && strstr(cast_const_char str, " e ") && ((e = cast_uchar strchr(cast_const_char fmt, 'e')))) { *e = 'd'; goto again; } -#else - wr = 0; -#endif set_empty: while (wr < 12) str[wr++] = ' '; str[12] = 0; @@ -191,9 +187,6 @@ static unsigned char *get_filename(unsigned char *url) { unsigned char *p, *m; int ml; -#ifdef DOS_FS - if (url[7] == '/' && strchr(cast_const_char(url + 8), ':')) url++; -#endif for (p = url + 7; *p && *p != POST_CHAR; p++) ; m = init_str(), ml = 0; @@ -311,10 +304,6 @@ void file_func(struct connection *c) if (!strcmp(cast_const_char de->d_name, ".")) continue; if (!strcmp(cast_const_char de->d_name, "..")) { unsigned char *n = name; -#if defined(DOS_FS) || defined(SPAD) - unsigned char *nn = cast_uchar strchr(cast_const_char n, ':'); - if (nn) n = nn + 1; -#endif if (strspn(cast_const_char n, dir_sep('\\') ? "/\\" : "/") == strlen(cast_const_char n)) continue; } @@ -420,11 +409,7 @@ void file_func(struct connection *c) abort_connection(c); return; } if ((r = hard_read(h, file, (int)stt.st_size)) -#ifdef OPENVMS - < 0 -#else != stt.st_size -#endif ) { mem_free(file); EINTRLOOP(rs, close(h)); diff --git a/fn_impl.c b/fn_impl.c @@ -1,366 +1,3 @@ #include "links.h" -#ifndef HAVE_SNPRINTF -#define B_SZ 65536 - -static char snprtintf_buffer[B_SZ]; - -int my_snprintf(char *str, int n, char *f, ...) -{ - int i; - va_list l; - if (!n) return -1; - va_start(l, f); -#ifdef HAVE_VPRINTF - vsprintf(snprtintf_buffer, f, l); -#elif defined(HAVE_DOPRNT) - { - struct _iobuf strbuf; - strbuf._flag = _IOWRT+_IOSTRG; - strbuf._ptr = snprtintf_buffer; - strbuf._cnt = 32767; - _doprnt(f, l, &strbuf); - putc('\0', &strbuf); - } -#else - fatal_exit("No vsprintf!"); -#endif - va_end(l); - i = strlen(snprtintf_buffer); - if (i >= B_SZ) { - fatal_exit("String size too large!"); - } - if (i >= n) { - memcpy(str, snprtintf_buffer, n); - str[n - 1] = 0; - return -1; - } - strcpy(str, snprtintf_buffer); - return i; -} - -#endif - -#ifndef HAVE_RAISE -int raise(int s) -{ -#ifdef HAVE_GETPID - pid_t p; - EINTRLOOP(p, getpid()); - if (p == -1) return -1; - return kill(p, s); -#else - return 0; -#endif -}; -#endif -#ifndef HAVE_GETTIMEOFDAY -int gettimeofday(struct timeval *tv, struct timezone *tz) -{ - time_t t; - errno = 0; - EINTRLOOPX(t, time(NULL), (time_t)-1); - if (tv) tv->tv_sec = t, tv->tv_usec = 0; - if (tz) tz->tz_minuteswest = tz->tz_dsttime = 0; - return 0; -} -#endif -#ifndef HAVE_GETCWD -char *getcwd(char *buf, size_t size) -{ -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif - static char cwd[MAXPATHLEN]; - if (!getwd(cwd)) - return NULL; - if (strlen(cwd) >= size) { - errno = ERANGE; - return NULL; - } - strcpy(buf, cwd); - return 0; -} -#endif -#ifndef HAVE_TEMPNAM -char *tempnam(const char *dir, const char *pfx) -{ - static int counter = 0; - unsigned char *d, *s, *a; - int l; - if (!(d = cast_uchar getenv("TMPDIR"))) { - if (dir) d = cast_uchar dir; - else if (!(d = cast_uchar getenv("TMP")) && !(d = cast_uchar getenv("TEMP"))) { -#ifdef P_tmpdir - d = cast_uchar(P_tmpdir); -#else - d = cast_uchar "/tmp"; -#endif - } - } - l = 0; - s = init_str(); - add_to_str(&s, &l, d); - if (s[0] && s[strlen(cast_const_char s) - 1] != '/') add_chr_to_str(&s, &l, '/'); - add_to_str(&s, &l, cast_uchar pfx); - add_num_to_str(&s, &l, counter++); - a = cast_uchar strdup(cast_const_char s); - mem_free(s); - return cast_char a; -} -#endif -#ifndef HAVE_STRDUP -char *strdup(const char *s) -{ - char *a = malloc(strlen(s) + 1); - if (!a) return NULL; - return strcpy(a, s); -} -#endif -#ifndef HAVE_STRTOL -long strtol(const char *nptr, char **endptr, int base) -{ - unsigned long result; - char negative = 0; - if (*nptr == '-') { - negative = 1; - nptr++; - } - result = 0; - while (1) { - char c = *nptr; - char val; - unsigned long nr; - if (c >= '0' && c <= '9') val = c - '0'; - else if (c >= 'A' && c <= 'Z') val = c - 'A' + 10; - else if (c >= 'a' && c <= 'z') val = c - 'a' + 10; - else break; - if (val >= base) break; - nr = result * base + val; - if ((long)nr < val || (nr - val) / base != result) break; - result = nr; - nptr++; - } - if (endptr) *endptr = (char *)nptr; - if (negative) return -result; - return result; -} -#endif -#ifndef HAVE_STRTOUL -unsigned long strtoul(const char *nptr, char **endptr, int base) -{ - if (*nptr == '-') { - if (endptr) *endptr = nptr; - return 0; - } - return (unsigned long)strtol(nptr,endptr,base); -}; -#endif -#ifndef HAVE_STRTOD -double strtod(const char *nptr, char **endptr) -{ - double d = 0; - char dummy; - if (endptr) *endptr = (char *)nptr; - if (sscanf(nptr, "%lf%c", &d, &dummy) == 1) { - if (endptr) *endptr = strchr(nptr, 0); - } - return d; -} -#endif -#ifndef HAVE_STRLEN -size_t strlen(const char *s) -{ - size_t len = 0; - while (s[len]) len++; - return len; -} -#endif -#ifndef HAVE_STRCPY -char *strcpy(char *dst, const char *src) -{ - return memcpy(dst, src, strlen(src) + 1); -} -#endif -#ifndef HAVE_STRCHR -char *strchr(const char *s, int c) -{ - do { - if (*s == (char)c) - return (char *)s; - } while (*s++); - return NULL; -} -#endif -#ifndef HAVE_STRRCHR -char *strrchr(const char *s, int c) -{ - char *ret = NULL; - do { - if (*s == (char)c) - ret = (char *)s; - } while (*s++); - return ret; -} -#endif -#ifndef HAVE_STRCMP -int strcmp(const char *s1, const char *s2) -{ - while (1) { - unsigned char c1 = (unsigned char)*s1; - unsigned char c2 = (unsigned char)*s2; - if (c1 != c2) { - return (int)c1 - (int)c2; - } - if (!c1) break; - s1++, s2++; - } - return 0; -} -#endif -#ifndef HAVE_STRNCMP -int strncmp(const char *s1, const char *s2, size_t n) -{ - while (n--) { - unsigned char c1 = (unsigned char)*s1; - unsigned char c2 = (unsigned char)*s2; - if (c1 != c2) { - return (int)c1 - (int)c2; - } - if (!c1) break; - s1++, s2++; - } - return 0; -} -#endif -#ifndef HAVE_STRCSPN -size_t strcspn(const char *s, const char *reject) -{ - size_t r; - for (r = 0; *s; r++, s++) { - const char *rj; - for (rj = reject; *rj; rj++) if (*s == *rj) goto brk; - } - brk: - return r; -} -#endif -#ifndef HAVE_STRSPN -size_t strspn(const char *s, const char *accept) -{ - size_t r; - for (r = 0; *s; r++, s++) { - const char *rj; - for (rj = accept; *rj; rj++) if (*s == *rj) goto ac; - break; - ac:; - } - return r; -} -#endif -#ifndef HAVE_STRSTR -char *strstr(const char *haystack, const char *needle) -{ - size_t hs = strlen(haystack); - size_t ns = strlen(needle); - if (!ns) return (char *)haystack; - while (hs >= ns) { - if (*haystack == *needle && !memcmp(haystack, needle, ns)) return (char *)haystack; - haystack++, hs--; - } - return NULL; -} -#endif -#ifndef HAVE_MEMCHR -void *memchr(const void *s, int c, size_t length) -{ - const char *sp = s; - while (length--) { - if (*sp == (char)c) - return (char *)s; - sp++; - } - return NULL; -} -#endif -#ifndef HAVE_MEMCMP -int memcmp(const void *src0, const void *src1, size_t length) -{ - const unsigned char *s0, *s1; -#ifdef HAVE_BCMP - if (!bcmp(src0, src1, length)) - return 0; -#endif - s0 = src0; - s1 = src1; - while (length--) { - int c = *s0 - *s1; - if (c) return c; - s0++, s1++; - } - return 0; -} -#endif -#ifndef HAVE_MEMCPY -void *memcpy(void *dst0, const void *src0, size_t length) -{ - return memmove(dst0, src0, length); -} -#endif -#ifndef HAVE_MEMMOVE -void *memmove(void *dst0, const void *src0, size_t length) -{ -#ifdef HAVE_BCOPY - bcopy(src0, dst0, length); - return dst0; -#else - unsigned char *dst = dst0; - const unsigned char *src = src0; - - if ((const unsigned char *)dst == src || !length) - return dst0; - - if ((const unsigned char *)dst <= src) { - while (length--) *dst++ = *src++; - } else { - dst += length - 1; - src += length - 1; - while (length--) *dst-- = *src--; - } - return dst0; -#endif -} -#endif -#ifndef HAVE_MEMSET -void *memset(void *s, int c, size_t n) -{ - char *sc = s; -#ifdef HAVE_BZERO - if (!c) bzero(s, n); - else -#endif - while (n--) *sc++ = c; - return s; -} -#endif -#ifndef HAVE_MEMMEM -void *memmem(const void *haystack, size_t hs, const void *needle, size_t ns) -{ - if (!ns) return (void *)haystack; - while (hs >= ns) { - if (*(const char *)haystack == *(const char *)needle && !memcmp(haystack, needle, ns)) return (void *)haystack; - haystack = (const void *)((const char *)haystack + 1), hs--; - } - return NULL; -} -#endif -#ifndef HAVE_STRERROR -extern char *sys_errlist[]; -extern int sys_nerr; -char *strerror(int errnum) -{ - if (errnum < 0 || errnum >= sys_nerr) return "Unknown error"; - return sys_errlist[errnum]; -}; -#endif diff --git a/framebuf.c b/framebuf.c @@ -6,1954 +6,3 @@ #include "cfg.h" -#ifdef GRDRV_FB - -/*#define USE_FB_ACCEL*/ -/*#define USE_FB_ACCEL_FILLRECT*/ - -/* #define FB_DEBUG */ -/* #define SC_DEBUG */ - -/* note: SIGUSR1 is used by libpthread and is disabled even if no thread - functions are called --- do not use */ - -#define SIG_REL SIGUSR2 -#define SIG_ACQ SIGVTALRM - -#if defined(FB_DEBUG) || defined(SC_DEBUG) -#define MESSAGE(a) fprintf(stderr,"%s",a); -#endif - -#include "links.h" - -#include "bits.h" - -#include <gpm.h> - -#include <sys/mman.h> -#include <sys/ioctl.h> - -#include <linux/fb.h> -#include <linux/kd.h> -#include <linux/vt.h> - -#include "arrow.inc" - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1L) -#endif - -#ifdef GPM_HAVE_SMOOTH -#define gpm_smooth GPM_SMOOTH -#else -#define gpm_smooth 0 -#endif - -#if defined(USE_FB_ACCEL) -#if !defined(FBIO_ACCEL_SUPPORT) -#define FBIO_ACCEL_SUPPORT 0x4630 -#define FBIO_ACCEL_SYNC 0x4631 -#define FBIO_ACCEL_FILLRECT 0x4632 -#define FBIO_ACCEL_FILLRECT_SYNC 0x4633 -#define FBIO_ACCEL_COPYAREA 0x4634 -#define FBIO_ACCEL_COPYAREA_SYNC 0x4635 -#define FB_ACCEL_FILLRECT_SUPPORTED 0x00000001 -#define FB_ACCEL_FILLRECT_ACCELERATED 0x00000002 -#define FB_ACCEL_COPYAREA_SUPPORTED 0x00000004 -#define FB_ACCEL_COPYAREA_ACCELERATED 0x00000008 -#define FB_ACCEL_SYNC_NEEDED 0x40000000 -/* we don't know if fb_copyarea and fb_fillrect are or aren't defined */ -#define fb_copyarea fb_redefined_copyarea -#define fb_fillrect fb_redefined_fillrect -struct fb_copyarea { - __u32 dx; - __u32 dy; - __u32 width; - __u32 height; - __u32 sx; - __u32 sy; -}; -struct fb_fillrect { - __u32 dx; - __u32 dy; - __u32 width; - __u32 height; - __u32 color; - __u32 rop; -}; -#endif -#ifndef ROP_COPY -#define ROP_COPY 0 -#endif -#ifndef ROP_XOR -#define ROP_XOR 1 -#endif -#endif - -static int TTY = 0; - -static int fb_hgpm; - -static int fb_console; - -static struct itrm *fb_kbd; - -static struct graphics_device *fb_old_vd; -static struct graphics_device *fb_block_dev; - -static int fb_handle; -static unsigned char *fb_mem, *fb_vmem; -static unsigned fb_mem_size; -static unsigned fb_mapped_size; -static int fb_linesize,fb_bits_pp,fb_pixelsize; -static int fb_xsize,fb_ysize; -static int border_left, border_right, border_top, border_bottom; -static int fb_colors, fb_palette_colors; -static struct fb_var_screeninfo vi; -static struct fb_fix_screeninfo fi; - -static void fb_draw_bitmap(struct graphics_device *dev,struct bitmap* hndl, int x, int y); - -static unsigned char *fb_driver_param; -extern struct graphics_driver fb_driver; -static int have_cmap; -static volatile int fb_active; - -struct palette -{ - unsigned short *red; - unsigned short *green; - unsigned short *blue; -}; - -static struct palette old_palette; -static struct palette global_pal; -static struct vt_mode vt_mode,vt_omode; - -/*static struct fb_var_screeninfo oldmode;*/ - -static volatile int in_gr_operation; - -#ifdef USE_FB_ACCEL -static int accel_flags; -static int need_accel_sync; -static inline void accel_sync(void) -{ - int rs; - if (need_accel_sync) { - EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_SYNC)); - need_accel_sync = 0; - } -} -#else -#define accel_sync() do { } while (0) -#endif - -/* mouse */ -static int mouse_x, mouse_y; /* mouse pointer coordinates */ -static long mouse_black, mouse_white; -static int background_x, background_y; /* Where was the mouse background taken from */ -static unsigned char *mouse_buffer, *background_buffer, *new_background_buffer; -static struct graphics_device *mouse_graphics_device; -static int global_mouse_hidden; -static int last_mouse_buttons; - - -#define TEST_MOUSE(xl,xh,yl,yh) if (RECTANGLES_INTERSECT(\ - (xl),(xh),\ - background_x,background_x+arrow_width,\ - (yl),(yh),\ - background_y,background_y+arrow_height)\ - && !global_mouse_hidden){\ - mouse_hidden=1;\ - hide_mouse();\ - }else mouse_hidden=0; - -#define END_MOUSE if (mouse_hidden) show_mouse(); - -#define END_GR \ - do_not_optimize_here(&fb_vmem); \ - in_gr_operation--;\ - if (!fb_active && !in_gr_operation) {\ - accel_sync();\ - EINTRLOOP(rs, ioctl(TTY,VT_RELDISP,1));\ - } -#define INC_IN_GR \ - in_gr_operation++; \ - do_not_optimize_here(&fb_vmem); -#define START_GR \ - INC_IN_GR \ - if (!fb_active) { END_GR return; } -#define START_GR_0 \ - INC_IN_GR \ - if (!fb_active) { END_GR return 0; } - - -#define NUMBER_OF_DEVICES 10 - -#define TEST_INACTIVITY if (!fb_active||dev!=current_virtual_device) return; - -#define TEST_INACTIVITY_0 if (!fb_active||dev!=current_virtual_device) return 0; - -#define RECTANGLES_INTERSECT(xl0, xh0, xl1, xh1, yl0, yh0, yl1, yh1) (\ - (xl0)<(xh1)\ - && (xl1)<(xh0)\ - && (yl0)<(yh1)\ - && (yl1)<(yh0)) - -/* This assures that x, y, xs, ys, data will be sane according to clipping - * rectangle. If nothing lies within this rectangle, the current function - * returns. The data pointer is automatically advanced by this macro to reflect - * the right position to start with inside the bitmap. */ -#define CLIP_PREFACE \ - int mouse_hidden;\ - int xs=hndl->x,ys=hndl->y;\ - unsigned char *data=hndl->data;\ -\ - TEST_INACTIVITY\ - if (x>=dev->clip.x2||x+xs<=dev->clip.x1) return;\ - if (y>=dev->clip.y2||y+ys<=dev->clip.y1) return;\ - if (x+xs>dev->clip.x2) xs=dev->clip.x2-x;\ - if (y+ys>dev->clip.y2) ys=dev->clip.y2-y;\ - if (dev->clip.x1-x>0){\ - xs-=(dev->clip.x1-x);\ - data+=fb_pixelsize*(dev->clip.x1-x);\ - x=dev->clip.x1;\ - }\ - if (dev->clip.y1-y>0){\ - ys-=(dev->clip.y1-y);\ - data+=hndl->skip*(dev->clip.y1-y);\ - y=dev->clip.y1;\ - }\ - /* xs, ys: how much pixels to paint\ - * data: where to start painting from\ - */\ - START_GR\ - TEST_MOUSE (x,x+xs,y,y+ys) - - -/* fill_area: 5,5,10,10 fills in 25 pixels! */ - -/* This assures that left, right, top, bottom will be sane according to the - * clipping rectangle set up by fb_driver->set_clip_area. If empty region - * results, return from current function occurs. */ -#define FILL_CLIP_PREFACE \ - int mouse_hidden;\ - TEST_INACTIVITY\ - if (left>=right||top>=bottom) return;\ - if (left>=dev->clip.x2||right<=dev->clip.x1||top>=dev->clip.y2||bottom<=dev->clip.y1) return;\ - if (left<dev->clip.x1) left=dev->clip.x1;\ - if (right>dev->clip.x2) right=dev->clip.x2;\ - if (top<dev->clip.y1) top=dev->clip.y1;\ - if (bottom>dev->clip.y2) bottom=dev->clip.y2;\ - START_GR\ - TEST_MOUSE(left,right,top,bottom) - - -#define HLINE_CLIP_PREFACE \ - int mouse_hidden;\ - TEST_INACTIVITY\ - if (y<dev->clip.y1||y>=dev->clip.y2||right<=dev->clip.x1||left>=dev->clip.x2) return;\ - if (left<dev->clip.x1) left=dev->clip.x1;\ - if (right>dev->clip.x2) right=dev->clip.x2;\ - if (left>=right) return;\ - START_GR\ - TEST_MOUSE (left,right,y,y+1) - -#define VLINE_CLIP_PREFACE \ - int mouse_hidden;\ - TEST_INACTIVITY\ - if (x<dev->clip.x1||x>=dev->clip.x2||top>=dev->clip.y2||bottom<=dev->clip.y1) return;\ - if (top<dev->clip.y1) top=dev->clip.y1;\ - if (bottom>dev->clip.y2) bottom=dev->clip.y2;\ - if (top>=bottom) return;\ - START_GR\ - TEST_MOUSE(x,x+1,top,bottom) - -#define HSCROLL_CLIP_PREFACE \ - int mouse_hidden;\ - TEST_INACTIVITY_0\ - if (!sc) return 0;\ - if (sc>(dev->clip.x2-dev->clip.x1)||-sc>(dev->clip.x2-dev->clip.x1))\ - return 1;\ - START_GR_0\ - TEST_MOUSE (dev->clip.x1,dev->clip.x2,dev->clip.y1,dev->clip.y2) - -#define VSCROLL_CLIP_PREFACE \ - int mouse_hidden;\ - TEST_INACTIVITY_0\ - if (!sc) return 0;\ - if (sc>dev->clip.y2-dev->clip.y1||-sc>dev->clip.y2-dev->clip.y1) return 1;\ - START_GR_0\ - TEST_MOUSE (dev->clip.x1, dev->clip.x2, dev->clip.y1, dev->clip.y2)\ - -#include "fbcommon.inc" - -static void redraw_mouse(void); - -static void fb_mouse_move(int dx, int dy) -{ - struct links_event ev; - mouse_x += dx; - mouse_y += dy; - ev.ev = EV_MOUSE; - if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1; - if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1; - if (mouse_x < 0) mouse_x = 0; - if (mouse_y < 0) mouse_y = 0; - ev.x = mouse_x; - ev.y = mouse_y; - ev.b = B_MOVE; - if (((last_mouse_buttons & BM_ACT) == B_DOWN || (last_mouse_buttons & BM_ACT) == B_DRAG) && - !BM_IS_WHEEL(last_mouse_buttons)) { - ev.b = (last_mouse_buttons & BM_BUTT) | B_DRAG; - } - if (!current_virtual_device) return; - if (current_virtual_device->mouse_handler) current_virtual_device->mouse_handler(current_virtual_device, ev.x, ev.y, (int)ev.b); - redraw_mouse(); -} - -static void fb_key_in(struct itrm *p, unsigned char *ev_, int size) -{ - struct links_event *ev = (struct links_event *)(void *)ev_; - if (size != sizeof(struct links_event)) return; - if (ev->ev == EV_ABORT) terminate_loop = 1; - if (ev->ev != EV_KBD) return; - if ((ev->y & KBD_ALT) && ev->x >= '0' && ev->x <= '9') { - switch_virtual_device((ev->x - '1' + 10) % 10); - return; - } - if (!current_virtual_device) return; - if (!ev->y && ev->x == KBD_F5) fb_mouse_move(-3, 0); - else if (!ev->y && ev->x == KBD_F6) fb_mouse_move(0, 3); - else if (!ev->y && ev->x == KBD_F7) fb_mouse_move(0, -3); - else if (!ev->y && ev->x == KBD_F8) fb_mouse_move(3, 0); - else { - if (g_kbd_codepage(&fb_driver) != utf8_table && ev->x >= 128 && ev->x <= 255) - if ((ev->x = cp2u(ev->x, g_kbd_codepage(&fb_driver))) == -1) return; - if (current_virtual_device->keyboard_handler) current_virtual_device->keyboard_handler(current_virtual_device, ev->x, ev->y); - } -} - - - - -#define mouse_getscansegment(buf,x,y,w) memcpy(buf,fb_vmem+y*fb_linesize+x*fb_pixelsize,w) -#define mouse_drawscansegment(ptr,x,y,w) memcpy(fb_vmem+y*fb_linesize+x*fb_pixelsize,ptr,w); - -#define do_with_mouse_device(cmd) \ -do { \ - struct graphics_device *current_virtual_device_backup; \ - \ - current_virtual_device_backup = current_virtual_device; \ - current_virtual_device = mouse_graphics_device; \ - cmd; \ - current_virtual_device = current_virtual_device_backup; \ -} while (0) - -/* Flushes the background_buffer onscreen where it was originally taken from. */ -static void place_mouse_background(void) -{ - struct bitmap bmp; - - bmp.x=arrow_width; - bmp.y=arrow_height; - bmp.skip=arrow_width*fb_pixelsize; - bmp.data=background_buffer; - - do_with_mouse_device(fb_draw_bitmap(mouse_graphics_device, &bmp, background_x, background_y)); - -} - -/* Only when the old and new mouse don't interfere. Using it on interfering mouses would - * cause a flicker. - */ -static void hide_mouse(void) -{ - global_mouse_hidden=1; - place_mouse_background(); -} - -/* Gets background from the screen (clipping provided only right and bottom) to the - * passed buffer. - */ -static void get_mouse_background(unsigned char *buffer_ptr) -{ - int width,height,skip,x,y; - - skip=arrow_width*fb_pixelsize; - - x=mouse_x; - y=mouse_y; - - width=fb_pixelsize*(arrow_width+x>fb_xsize?fb_xsize-x:arrow_width); - height=arrow_height+y>fb_ysize?fb_ysize-y:arrow_height; - - accel_sync(); - - for (;height;height--){ - mouse_getscansegment(buffer_ptr,x,y,width); - buffer_ptr+=skip; - y++; - } -} - -/* Overlays the arrow's image over the mouse_buffer - * Doesn't draw anything into the screen - */ -static void render_mouse_arrow(void) -{ - int x,y; - unsigned reg0, reg1; - unsigned char *mouse_ptr=mouse_buffer; - const unsigned *arrow_ptr=arrow; - - for (y=arrow_height;y;y--){ - reg0=*arrow_ptr; - reg1=arrow_ptr[1]; - arrow_ptr+=2; - for (x=arrow_width;x;) - { - unsigned mask=1U<<(--x); - - if (reg0&mask) - memcpy (mouse_ptr, &mouse_black, fb_pixelsize); - else if (reg1&mask) - memcpy (mouse_ptr, &mouse_white, fb_pixelsize); - mouse_ptr+=fb_pixelsize; - } - } -} - -static void place_mouse(void) -{ - struct bitmap bmp; - - bmp.x=arrow_width; - bmp.y=arrow_height; - bmp.skip=arrow_width*fb_pixelsize; - bmp.data=mouse_buffer; - do_with_mouse_device(fb_draw_bitmap(mouse_graphics_device, &bmp, mouse_x, mouse_y)); - global_mouse_hidden=0; -} - -/* Only when the old and the new mouse positions do not interfere. Using this routine - * on interfering positions would cause a flicker. - */ -static void show_mouse(void) -{ - get_mouse_background(background_buffer); - background_x=mouse_x; - background_y=mouse_y; - memcpy(mouse_buffer,background_buffer,fb_pixelsize*arrow_area); - render_mouse_arrow(); - place_mouse(); -} - -/* Doesn't draw anything into the screen - */ -static void put_and_clip_background_buffer_over_mouse_buffer(void) -{ - unsigned char *bbufptr=background_buffer, *mbufptr=mouse_buffer; - int left=background_x-mouse_x; - int top=background_y-mouse_y; - int right,bottom; - int bmpixelsizeL=fb_pixelsize; - int number_of_bytes; - int byte_skip; - - right=left+arrow_width; - bottom=top+arrow_height; - - if (left<0){ - bbufptr-=left*bmpixelsizeL; - left=0; - } - if (right>arrow_width) right=arrow_width; - if (top<0){ - bbufptr-=top*bmpixelsizeL*arrow_width; - top=0; - } - if (bottom>arrow_height) bottom=arrow_height; - mbufptr+=bmpixelsizeL*(left+arrow_width*top); - byte_skip=arrow_width*bmpixelsizeL; - number_of_bytes=bmpixelsizeL*(right-left); - for (;top<bottom;top++){ - memcpy(mbufptr,bbufptr,number_of_bytes); - mbufptr+=byte_skip; - bbufptr+=byte_skip; - } -} - -/* This draws both the contents of background_buffer and mouse_buffer in a scan - * way (left-right, top-bottom), so the flicker is reduced. - */ -static inline void place_mouse_composite(void) -{ - int mouse_left=mouse_x; - int mouse_top=mouse_y; - int background_left=background_x; - int background_top=background_y; - int mouse_right=mouse_left+arrow_width; - int mouse_bottom=mouse_top+arrow_height; - int background_right=background_left+arrow_width; - int background_bottom=background_top+arrow_height; - int skip=arrow_width*fb_pixelsize; - int background_length,mouse_length; - unsigned char *mouse_ptr=mouse_buffer,*background_ptr=background_buffer; - int yend; - - if (mouse_bottom>fb_ysize) mouse_bottom=fb_ysize; - if (background_bottom>fb_ysize) background_bottom=fb_ysize; - - accel_sync(); - - /* Let's do the top part */ - if (background_top<mouse_top){ - /* Draw the background */ - background_length=background_right>fb_xsize?fb_xsize-background_left - :arrow_width; - for (;background_top<mouse_top;background_top++){ - mouse_drawscansegment(background_ptr,background_left - ,background_top,background_length*fb_pixelsize); - background_ptr+=skip; - } - - }else if (background_top>mouse_top){ - /* Draw the mouse */ - mouse_length=mouse_right>fb_xsize - ?fb_xsize-mouse_left:arrow_width; - for (;mouse_top<background_top;mouse_top++){ - mouse_drawscansegment(mouse_ptr,mouse_left,mouse_top,mouse_length*fb_pixelsize); - mouse_ptr+=skip; - } - } - - /* Let's do the middle part */ - yend=mouse_bottom<background_bottom?mouse_bottom:background_bottom; - if (background_left<mouse_left){ - /* Draw background, mouse */ - mouse_length=mouse_right>fb_xsize?fb_xsize-mouse_left:arrow_width; - for (;mouse_top<yend;mouse_top++){ - mouse_drawscansegment(background_ptr,background_left,mouse_top - ,(mouse_left-background_left)*fb_pixelsize); - mouse_drawscansegment(mouse_ptr,mouse_left,mouse_top,mouse_length*fb_pixelsize); - mouse_ptr+=skip; - background_ptr+=skip; - } - - }else{ - int l1, l2, l3; - - /* Draw mouse, background */ - mouse_length=mouse_right>fb_xsize?fb_xsize-mouse_left:arrow_width; - background_length=background_right-mouse_right; - if (background_length+mouse_right>fb_xsize) - background_length=fb_xsize-mouse_right; - l1=mouse_length*fb_pixelsize; - l2=(mouse_right-background_left)*fb_pixelsize; - l3=background_length*fb_pixelsize; - for (;mouse_top<yend;mouse_top++){ - mouse_drawscansegment(mouse_ptr,mouse_left,mouse_top,l1); - if (background_length>0) - mouse_drawscansegment( - background_ptr +l2, - mouse_right,mouse_top ,l3); - mouse_ptr+=skip; - background_ptr+=skip; - } - } - - if (background_bottom<mouse_bottom){ - /* Count over bottoms! tops will be invalid! */ - /* Draw mouse */ - mouse_length=mouse_right>fb_xsize?fb_xsize-mouse_left - :arrow_width; - for (;background_bottom<mouse_bottom;background_bottom++){ - mouse_drawscansegment(mouse_ptr,mouse_left,background_bottom - ,mouse_length*fb_pixelsize); - mouse_ptr+=skip; - } - }else{ - /* Draw background */ - background_length=background_right>fb_xsize?fb_xsize-background_left - :arrow_width; - for (;mouse_bottom<background_bottom;mouse_bottom++){ - mouse_drawscansegment(background_ptr,background_left,mouse_bottom - ,background_length*fb_pixelsize); - background_ptr+=skip; - } - } -} - -/* This moves the mouse a sophisticated way when the old and new position of the - * cursor overlap. - */ -static inline void redraw_mouse_sophisticated(void) -{ - int new_background_x, new_background_y; - - get_mouse_background(mouse_buffer); - put_and_clip_background_buffer_over_mouse_buffer(); - memcpy(new_background_buffer,mouse_buffer,fb_pixelsize*arrow_area); - new_background_x=mouse_x; - new_background_y=mouse_y; - render_mouse_arrow(); - place_mouse_composite(); - memcpy(background_buffer,new_background_buffer,fb_pixelsize*arrow_area); - background_x=new_background_x; - background_y=new_background_y; -} - -static void redraw_mouse(void) -{ - if (!fb_active) return; /* We are not drawing */ - if (mouse_x!=background_x||mouse_y!=background_y){ - if (RECTANGLES_INTERSECT( - background_x, background_x+arrow_width, - mouse_x, mouse_x+arrow_width, - background_y, background_y+arrow_height, - mouse_y, mouse_y+arrow_height)){ - redraw_mouse_sophisticated(); - }else{ - /* Do a normal hide/show */ - get_mouse_background(mouse_buffer); - memcpy(new_background_buffer, - mouse_buffer,arrow_area*fb_pixelsize); - render_mouse_arrow(); - hide_mouse(); - place_mouse(); - memcpy(background_buffer,new_background_buffer - ,arrow_area*fb_pixelsize); - background_x=mouse_x; - background_y=mouse_y; - } - } -} - -/* This is an empiric magic that ensures - * Good white purity - * Correct rounding and dithering prediction - * And this is the cabbala: - * 063 021 063 - * 009 009 021 - * 255 085 255 - * 036 036 084 - */ -static void generate_palette(struct palette *palette) -{ - int a; - - switch (fb_colors) - { - case 16: - case 256: - for (a=0;a<fb_palette_colors;a++) - { - unsigned rgb[3]; - q_palette(fb_colors, a, 65535, rgb); - palette->red[a] = rgb[0]; - palette->green[a] = rgb[1]; - palette->blue[a] = rgb[2]; - } - break; - case 32768: - for (a=0;a<fb_palette_colors;a++){ - /* - palette->red[a]=((a>>10)&31)*(65535/31); - palette->green[a]=((a>>5)&31)*(65535/31); - palette->blue[a]=(a&31)*(65535/31); - */ - palette->red[a]= - palette->green[a]= - palette->blue[a]=(((a&31)*255)/31)*257; - } - break; - case 65536: - for (a=0;a<fb_palette_colors;a++){ - /* - palette->red[a]=((a>>11)&31)*(65535/31); - palette->green[a]=((a>>5)&63)*(65535/63); - palette->blue[a]=(a&31)*(65535/31); - */ - palette->green[a]=(((a&63)*255)/64)*257; - palette->red[a]= - palette->blue[a]=(((a&31)*255)/32)*257; - } - break; - default: - for (a=0;a<fb_palette_colors;a++){ - palette->red[a]= - palette->green[a]= - palette->blue[a]=a*257; - /* stuff it in both high and low byte */ - } - } -} - -static void alloc_palette(struct palette *pal) -{ - pal->red=mem_calloc(sizeof(unsigned short)*fb_palette_colors); - pal->green=mem_calloc(sizeof(unsigned short)*fb_palette_colors); - pal->blue=mem_calloc(sizeof(unsigned short)*fb_palette_colors); - - if (!pal->red||!pal->green||!pal->blue) { - /*internal("Cannot create palette.\n")*/; - } -} - - -static void free_palette(struct palette *pal) -{ - mem_free(pal->red); - mem_free(pal->green); - mem_free(pal->blue); -} - - -static void set_palette(struct palette *pal) -{ - struct fb_cmap cmap; - int i; - unsigned short *red=pal->red; - unsigned short *green=pal->green; - unsigned short *blue=pal->blue; - __u16 *r, *g, *b, *t; - int rs; - - r=mem_alloc(fb_palette_colors*sizeof(__u16)); - g=mem_alloc(fb_palette_colors*sizeof(__u16)); - b=mem_alloc(fb_palette_colors*sizeof(__u16)); - t=mem_calloc(fb_palette_colors*sizeof(__u16)); - - if (!r||!g||!b||!t) { - /*internal("Cannot allocate memory.\n")*/; - } - - for (i = 0; i < fb_palette_colors; i++) - { - r[i] = red[i]; - g[i] = green[i]; - b[i] = blue[i]; - /*fprintf(stderr, "%d %d %d\n", r[i], g[i], b[i]);*/ - /*fprintf(stderr, "%5x: %5x\t%5x\t%5x\t%5x\n",i,r[i],g[i],b[i],t[i]);*/ - - } - - cmap.start = 0; - cmap.len = fb_palette_colors; - cmap.red = r; - cmap.green = g; - cmap.blue = b; - cmap.transp = t; - - EINTRLOOP(rs, ioctl(fb_handle, FBIOPUTCMAP, &cmap)); - if (rs==-1) { - /*internal("Cannot set palette\n")*/; - } - - mem_free(r);mem_free(g);mem_free(b);mem_free(t); -} - - -static void get_palette(struct palette *pal) -{ - struct fb_cmap cmap; - int i; - __u16 *r, *g, *b, *t; - int rs; - - r=mem_alloc(fb_palette_colors*sizeof(__u16)); - g=mem_alloc(fb_palette_colors*sizeof(__u16)); - b=mem_alloc(fb_palette_colors*sizeof(__u16)); - t=mem_alloc(fb_palette_colors*sizeof(__u16)); - - if (!r||!g||!b||!t) { - /*internal("Cannot allocate memory.\n")*/; - } - - cmap.start = 0; - cmap.len = fb_palette_colors; - cmap.red = r; - cmap.green = g; - cmap.blue = b; - cmap.transp = t; - - EINTRLOOP(rs, ioctl(fb_handle, FBIOGETCMAP, &cmap)); - if (rs==-1) { - /*internal("Cannot get palette\n")*/; - } - - for (i = 0; i < fb_palette_colors; i++) - { - /*printf("%d %d %d\n",r[i],g[i],b[i]);*/ - pal->red[i] = r[i]; - pal->green[i] = g[i]; - pal->blue[i] = b[i]; - } - - mem_free(r);mem_free(g);mem_free(b);mem_free(t); -} - -static void fb_clear_videoram(void) -{ - int rs; - START_GR -#ifdef USE_FB_ACCEL_FILLRECT - if (accel_flags & FB_ACCEL_FILLRECT_ACCELERATED) { - struct fb_fillrect f; - f.dx = 0; - f.dy = 0; - f.width = fb_xsize + border_left + border_right; - f.height = fb_ysize + border_top + border_bottom; - f.color = 0; - f.rop = ROP_COPY; - EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_FILLRECT_SYNC, &f)); - if (rs < 0) { - error("fb_clear_videoram accel failed\n"); - goto no_accel; - } - } else - no_accel: -#endif - { - accel_sync(); - memset(fb_mem, 0, (border_top + fb_ysize + border_bottom) * fb_linesize); - /*{ - int size = (border_top + fb_ysize + border_bottom) * fb_linesize; - int pos; - for (pos = 0; pos < size; pos++) { - fb_mem[pos] = (unsigned char)pos; - } - }*/ - } - END_GR -} - -static void fb_switch_signal_rel(void *data) -{ - int rs; - fb_active=0; - if (!in_gr_operation) { - accel_sync(); - EINTRLOOP(rs, ioctl(TTY,VT_RELDISP,1)); - } -} - -static void fb_switch_signal_acq(void *data) -{ - struct vt_stat st; - struct rect r; - int rs; - - EINTRLOOP(rs, ioctl(TTY,VT_GETSTATE,&st)); - if (rs) return; - if (st.v_active != fb_console) return; - INC_IN_GR - fb_active=1; - EINTRLOOP(rs, ioctl(TTY,VT_RELDISP,VT_ACKACQ)); - /* - * There is a race condition in Linux NVidia framebuffer driver - * It still draws into a framebuffer here, so we have to sleep - */ - portable_sleep(10); - if (have_cmap && current_virtual_device) - set_palette(&global_pal); - END_GR - r.x1=0; - r.y1=0; - r.x2=fb_xsize; - r.y2=fb_ysize; - if (border_left | border_top | border_right | border_bottom) fb_clear_videoram(); - if (current_virtual_device) current_virtual_device->redraw_handler(current_virtual_device,&r); -} - - -static unsigned char *fb_switch_init(void) -{ - int rs; - - INC_IN_GR - - /* If we use threads, the signal handler may execute on a different - thread. framebuf.c doesn't handle different-thread signals, so - we must switch to synchronous signal handling when using threads */ - install_signal_handler(SIG_REL, fb_switch_signal_rel, NULL, -#ifndef EXEC_IN_THREADS - 1 -#else - 0 -#endif - ); - install_signal_handler(SIG_ACQ, fb_switch_signal_acq, NULL, 0); - EINTRLOOP(rs, ioctl(TTY,VT_GETMODE, &vt_omode)); - if (rs == -1) { - in_gr_operation--; - return stracpy(cast_uchar "Could not get VT mode.\n"); - } - memcpy(&vt_mode, &vt_omode, sizeof(vt_mode)); - - vt_mode.mode = VT_PROCESS; - vt_mode.waitv = 0; - vt_mode.relsig = SIG_REL; - vt_mode.acqsig = SIG_ACQ; - - EINTRLOOP(rs, ioctl(TTY,VT_SETMODE, &vt_mode)); - if (rs == -1) { - in_gr_operation--; - return stracpy(cast_uchar "Could not set VT mode.\n"); - } - - EINTRLOOP(rs, ioctl(TTY, VT_WAITACTIVE, fb_console)); - fb_active = 1; - - return NULL; -} - -static void fb_switch_shutdown(void) -{ - int rs; - if (in_gr_operation <= 0) internal("fb_switch_shutdown: in_gr_operation %d", in_gr_operation); - if (!fb_active && in_gr_operation == 1) { - EINTRLOOP(rs, ioctl(TTY,VT_RELDISP,1)); - } - EINTRLOOP(rs, ioctl(TTY,VT_SETMODE, &vt_omode)); - install_signal_handler(SIG_REL, (void (*)(void *))NULL, (void*)SIG_REL, 1); - install_signal_handler(SIG_ACQ, (void (*)(void *))NULL, (void*)SIG_ACQ, 0); - in_gr_operation--; -} - -static void fb_shutdown_palette(void) -{ - if (have_cmap) - { - if (fb_active) - set_palette(&old_palette); - free_palette(&old_palette); - free_palette(&global_pal); - } -} - -static void fb_ctrl_c(void *i_) -{ - kbd_ctrl_c(); -} - -static void unhandle_fb_mouse(void); - -static void fb_gpm_in(void *nic) -{ - struct links_event ev; - Gpm_Event gev; - again: - set_handlers(fb_hgpm, (void (*)(void *))NULL, (void (*)(void *))NULL, NULL); - if (Gpm_GetEvent(&gev) <= 0) { - fb_hgpm = -1; - unhandle_fb_mouse(); - return; - } - set_handlers(fb_hgpm, fb_gpm_in, (void (*)(void *))NULL, NULL); - /*fprintf(stderr, "%x %x %d %d %d %d\n", gev.type, gev.buttons, gev.dx, gev.dy, gev.wdx, gev.wdy);*/ - if (gev.dx || gev.dy) { - if (!((int)gev.type & gpm_smooth)) { - mouse_x += gev.dx * 8; - mouse_y += gev.dy * 8; - } -#ifdef GPM_HAVE_SMOOTH - else { - mouse_x += gev.dx; - mouse_y += gev.dy; - } -#endif - } - ev.ev = EV_MOUSE; - if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1; - if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1; - if (mouse_x < 0) mouse_x = 0; - if (mouse_y < 0) mouse_y = 0; - - if (!((int)gev.type & gpm_smooth) && (gev.dx || gev.dy)) { - mouse_x = (mouse_x + 8) / 8 * 8 - 4; - mouse_y = (mouse_y + 8) / 8 * 8 - 4; - if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1; - if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1; - if (mouse_x < 0) mouse_x = 0; - if (mouse_y < 0) mouse_y = 0; - } - - ev.x = mouse_x; - ev.y = mouse_y; - if (gev.buttons & GPM_B_LEFT) ev.b = B_LEFT; - else if (gev.buttons & GPM_B_MIDDLE) ev.b = B_MIDDLE; - else if (gev.buttons & GPM_B_RIGHT) ev.b = B_RIGHT; -#ifdef GPM_B_FOURTH - else if (gev.buttons & GPM_B_FOURTH) ev.b = B_FOURTH; -#endif -#ifdef GPM_B_UP - else if (gev.buttons & GPM_B_UP) ev.b = B_FIFTH; -#endif -#ifdef GPM_B_DOWN - else if (gev.buttons & GPM_B_DOWN) ev.b = B_SIXTH; -#endif - else ev.b = 0; - if ((int)gev.type & GPM_DOWN) ev.b |= B_DOWN; - else if ((int)gev.type & GPM_UP) ev.b |= B_UP; - else if ((int)gev.type & GPM_DRAG) ev.b |= B_DRAG; - else ev.b |= B_MOVE; - -#ifdef HAVE_WDX_WDY - if ((ev.b & BM_ACT) == B_DRAG || (ev.b & BM_ACT) == B_MOVE) { - if (gev.wdy < 0) { - ev.b &= ~BM_BUTT; - ev.b |= B_WHEELDOWN; - } else if (gev.wdy > 0) { - ev.b &= ~BM_BUTT; - ev.b |= B_WHEELUP; - } -#if 0 - /* it doesn't work anyway - the exps2 protocol doesn't support it and evdev support in gpm is buggy */ - else if (gev.wdx < 0) { - ev.b &= ~BM_BUTT; - ev.b |= B_WHEELRIGHT; - } else if (gev.wdx > 0) { - ev.b &= ~BM_BUTT; - ev.b |= B_WHEELLEFT; -#endif - } -#endif - - if (((ev.b & BM_ACT) == B_MOVE && !(ev.b & BM_BUTT)) || (ev.b & BM_ACT) == B_DRAG) { - if (can_read(fb_hgpm)) goto again; - } - - last_mouse_buttons = (int)ev.b; - if (!current_virtual_device) return; - if (current_virtual_device->mouse_handler) current_virtual_device->mouse_handler(current_virtual_device, ev.x, ev.y, (int)ev.b); - redraw_mouse(); -} - -static int handle_fb_mouse(void) -{ - Gpm_Connect conn; - fb_hgpm = -1; - conn.eventMask = (unsigned short)~0U; - conn.defaultMask = gpm_smooth; - conn.minMod = 0; - conn.maxMod = (unsigned short)~0U; - if ((fb_hgpm = Gpm_Open(&conn, 0)) < 0) { - unhandle_fb_mouse(); - return -1; - } - set_handlers(fb_hgpm, fb_gpm_in, (void (*)(void *))NULL, NULL); -#ifdef SIGTSTP - install_signal_handler(SIGTSTP, sig_tstp, NULL, 0); -#endif -#ifdef SIGCONT - install_signal_handler(SIGCONT, sig_cont, NULL, 0); -#endif -#ifdef SIGTTIN - install_signal_handler(SIGTTIN, sig_tstp, NULL, 0); -#endif - - return 0; -} - -static void unhandle_fb_mouse(void) -{ - if (fb_hgpm >= 0) set_handlers(fb_hgpm, (void (*)(void *))NULL, (void (*)(void *))NULL, NULL); - Gpm_Close(); -#ifdef SIGTSTP - install_signal_handler(SIGTSTP, sig_tstp, NULL, 0); -#endif -#ifdef SIGCONT - install_signal_handler(SIGCONT, sig_cont, NULL, 0); -#endif -#ifdef SIGTTIN - install_signal_handler(SIGTTIN, sig_tstp, NULL, 0); -#endif -} - -static const unsigned char seq_hide_cursor[] = "\033[10000B\033[10000C\033[?25l"; -static const unsigned char seq_show_cursor[] = "\033[10000D\033[?25h"; - -static void fb_print(const unsigned char *str) -{ - int wr; - EINTRLOOP(wr, (int)write(TTY, str, strlen(cast_const_char str))); - if (wr <= 0) - EINTRLOOP(wr, (int)write(1, str, strlen(cast_const_char str))); -} - -static void fb_hide_cursor(void) -{ - fb_print(seq_hide_cursor); -} - -static void fb_show_cursor(void) -{ - fb_print(seq_show_cursor); -} - -static void fb_pan_display(void) -{ - int rs; - vi.xoffset=0; - vi.yoffset=0; - EINTRLOOP(rs, ioctl(fb_handle, FBIOPAN_DISPLAY, &vi)); - /* don't check error */ -} - -static unsigned char *fb_init_driver(unsigned char *param, unsigned char *ignore) -{ - unsigned char *e; - struct stat st; - int rs; - unsigned long ul; - - TTY = 0; - EINTRLOOP(rs, ioctl(TTY,VT_GETMODE, &vt_omode)); - if (rs == -1) { - TTY = 1; - EINTRLOOP(rs, ioctl(TTY,VT_GETMODE, &vt_omode)); - if (rs == -1) { - TTY = 0; - } - } - - kbd_set_raw = 1; - fb_old_vd = NULL; - fb_driver_param=NULL; - if(param != NULL) - fb_driver_param=stracpy(param); - - border_left = border_right = border_top = border_bottom = 0; - if (!param) param=cast_uchar ""; - if (*param) { - if (*param < '0' || *param > '9') { - bad_p: - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - return stracpy(cast_uchar "-mode syntax is left_border[,top_border[,right_border[,bottom_border]]]\n"); - } - ul = strtoul(cast_const_char param, (char **)(void *)&param, 10); - if (ul > MAXINT / 10) goto bad_p; - border_left = (int)ul; - if (*param == ',') param++; - } else { - border_left = 0; - } - if (*param) { - if (*param < '0' || *param > '9') goto bad_p; - ul = strtoul(cast_const_char param, (char **)(void *)&param, 10); - if (ul > MAXINT / 10) goto bad_p; - border_top = (int)ul; - if (*param == ',') param++; - } else { - border_top = border_left; - } - if (*param) { - if (*param < '0' || *param > '9') goto bad_p; - ul = strtoul(cast_const_char param, (char **)(void *)&param, 10); - if (ul > MAXINT / 10) goto bad_p; - border_right = (int)ul; - if (*param == ',') param++; - } else { - border_right = border_left; - } - if (*param) { - if (*param < '0' || *param > '9') goto bad_p; - ul = strtoul(cast_const_char param, (char **)(void *)&param, 10); - if (ul > MAXINT / 10) goto bad_p; - border_bottom = (int)ul; - if (*param == ',') param++; - } else { - border_bottom = border_top; - } - if (*param) goto bad_p; - - EINTRLOOP(rs, fstat(TTY, &st)); - if (rs) { - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - return stracpy(cast_uchar "Cannon stat stdin.\n"); - } - - fb_console = (int)(st.st_rdev & 0xff); - - fb_hide_cursor(); - - if ((e = fb_switch_init())) { - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return e; - } - - fb_handle = c_open(cast_uchar "/dev/fb0", O_RDWR | O_NOCTTY); - if (fb_handle==-1) { - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Cannot open /dev/fb0.\n"); - } - - EINTRLOOP(rs, ioctl(fb_handle, FBIOGET_VSCREENINFO, &vi)); - if (rs==-1) - { - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Cannot get FB VSCREENINFO.\n"); - } - - /*oldmode=vi;*/ - - EINTRLOOP(rs, ioctl(fb_handle, FBIOGET_FSCREENINFO, &fi)); - if (rs==-1) - { - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Cannot get FB FSCREENINFO.\n"); - } - -#if 0 - { - unsigned i, j, l; - fprintf(stderr, "\n"); - for (i = 0; i < sizeof(fi); i += 16) { - l = sizeof(fi)- i; - if (l > 16) l = 16; - fprintf(stderr, "fi(%02x):", i); - for (j = 0; j < l; j++) fprintf(stderr, " %02x", ((unsigned char *)&fi)[i + j]); - fprintf(stderr, "\n"); - } - fprintf(stderr, "\n"); - for (i = 0; i < sizeof(vi); i += 16) { - l = sizeof(vi)- i; - if (l > 16) l = 16; - fprintf(stderr, "vi(%02x):",i); - for (j = 0; j < l; j++) fprintf(stderr, " %02x", ((unsigned char *)&vi)[i + j]); - fprintf(stderr, "\n"); - } - } -#endif - - fb_xsize=vi.xres; - fb_ysize=vi.yres; - fb_bits_pp=vi.bits_per_pixel; - if (fb_bits_pp == 16 && vi.green.length == 5) fb_bits_pp = 15; - - if (fb_xsize <= border_left + border_right) border_left = border_right = 0; - fb_xsize -= border_left + border_right; - if (fb_ysize <= border_top + border_bottom) border_top = border_bottom = 0; - fb_ysize -= border_top + border_bottom; - - fb_driver.x=fb_xsize; - fb_driver.y=fb_ysize; - - switch(fb_bits_pp) - { - case 4: - fb_pixelsize=1; - fb_palette_colors=16; - break; - - case 8: - fb_pixelsize=1; - fb_palette_colors=256; - break; - - case 15: - case 16: - fb_pixelsize=2; - fb_palette_colors=64; - break; - - case 24: - fb_palette_colors=256; - fb_pixelsize=3; - break; - - case 32: - fb_palette_colors=256; - fb_pixelsize=4; - fb_bits_pp=24; - break; - - default: - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Unknown bit depth"); - } - fb_colors=1<<fb_bits_pp; - - /* we must pan before setting palette */ - fb_pan_display(); - - have_cmap = 0; - if (fi.visual==FB_VISUAL_PSEUDOCOLOR && fb_colors <= 0x1000000) /* set palette */ - { - have_cmap=1; - fb_palette_colors=fb_colors; - alloc_palette(&old_palette); - get_palette(&old_palette); - - alloc_palette(&global_pal); - generate_palette(&global_pal); - set_palette(&global_pal); - } - if (fi.visual==FB_VISUAL_DIRECTCOLOR) /* set pseudo palette */ - { - have_cmap=2; - alloc_palette(&old_palette); - get_palette(&old_palette); - - alloc_palette(&global_pal); - generate_palette(&global_pal); - set_palette(&global_pal); - } - - fb_linesize=fi.line_length; - fb_mem_size=fi.smem_len; - - if (init_virtual_devices(&fb_driver, NUMBER_OF_DEVICES)){ - fb_shutdown_palette(); - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Allocation of virtual devices failed.\n"); - } - fb_kbd = handle_svgalib_keyboard(fb_key_in); - - /* Mikulas: nechodi to na sparcu */ - if (fb_mem_size < (unsigned)((border_top + fb_ysize + border_bottom) * fb_linesize)) - { - fb_shutdown_palette(); - svgalib_free_trm(fb_kbd); - shutdown_virtual_devices(); - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Nonlinear mapping of graphics memory not supported.\n"); - } - - if (vi.nonstd) { - fb_shutdown_palette(); - svgalib_free_trm(fb_kbd); - shutdown_virtual_devices(); - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Non-standard pixel format.\n"); - } - - fb_driver.flags |= GD_DONT_USE_SCROLL; -#ifdef USE_FB_ACCEL - need_accel_sync = 0; - EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_SUPPORT)); - if (rs < 0) { - accel_flags = 0; - /*debug("accel not supported");*/ - } else { - accel_flags = rs; - /*debug("accel supported, flags %x", accel_flags);*/ - } - if (fb_bits_pp != 8) - accel_flags &= ~(FB_ACCEL_FILLRECT_SUPPORTED | FB_ACCEL_FILLRECT_ACCELERATED); - if (accel_flags & FB_ACCEL_COPYAREA_ACCELERATED) - fb_driver.flags &= ~GD_DONT_USE_SCROLL; -#endif - - /* - * Some framebuffer implementations (for example Mach64) on Sparc64 hate - * partial framebuffer mappings. - * - * For others, we can save virtual memory space by doing a partial mmap. - */ - fb_mapped_size = (border_top + fb_ysize + border_bottom) * fb_linesize; -retry1: - if ((fb_mem=mmap(0,fb_mapped_size,PROT_READ|PROT_WRITE,MAP_SHARED,fb_handle,0))==MAP_FAILED) { - if (errno == EINTR) goto retry1; - fb_mapped_size = fb_mem_size; -retry2: - if ((fb_mem=mmap(0,fb_mapped_size,PROT_READ|PROT_WRITE,MAP_SHARED,fb_handle,0))==MAP_FAILED) { - if (errno == EINTR) goto retry2; - fb_shutdown_palette(); - svgalib_free_trm(fb_kbd); - shutdown_virtual_devices(); - - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Cannot mmap graphics memory.\n"); - } - } - fb_vmem = fb_mem + border_left * fb_pixelsize + border_top * fb_linesize; - fb_driver.depth=fb_pixelsize&7; - fb_driver.depth|=(fb_bits_pp&31)<<3; -#if 0 - fprintf(stderr, "\nfb: bytes %u, bits %u\n", fb_pixelsize, fb_bits_pp); - fprintf(stderr, "r: %x %x %x\n", vi.red.offset, vi.red.length, vi.red.msb_right); - fprintf(stderr, "g: %x %x %x\n", vi.green.offset, vi.green.length, vi.green.msb_right); - fprintf(stderr, "b: %x %x %x\n", vi.blue.offset, vi.blue.length, vi.blue.msb_right); - fprintf(stderr, "t: %x %x %x\n", vi.transp.offset, vi.transp.length, vi.transp.msb_right); -#endif - if (htonl(0x12345678) == 0x12345678) { - /* Big endian */ - if (fb_driver.depth == 130 || fb_driver.depth == 122) fb_driver.depth |= 1 << 8; - else if (fb_driver.depth == 196) fb_driver.depth |= 1 << 9; - } - - fb_driver.get_color=get_color_fn(fb_driver.depth); - if (!fb_driver.get_color) { - fb_shutdown_palette(); - svgalib_free_trm(fb_kbd); - shutdown_virtual_devices(); - - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Unknown bit format.\n"); - } - install_signal_handler(SIGINT, fb_ctrl_c, fb_kbd, 0); - - /* mouse */ - mouse_buffer=mem_alloc(fb_pixelsize*arrow_area); - background_buffer=mem_alloc(fb_pixelsize*arrow_area); - new_background_buffer=mem_alloc(fb_pixelsize*arrow_area); - background_x=mouse_x=fb_xsize>>1; - background_y=mouse_y=fb_ysize>>1; - mouse_black=fb_driver.get_color(0); - mouse_white=fb_driver.get_color(0xffffff); - mouse_graphics_device=fb_driver.init_device(); - virtual_devices[0] = NULL; - global_mouse_hidden=1; - last_mouse_buttons = B_MOVE; - if (handle_fb_mouse()) { - fb_driver.shutdown_device(mouse_graphics_device); - mem_free(mouse_buffer); - mem_free(background_buffer); - mem_free(new_background_buffer); - fb_shutdown_palette(); - svgalib_free_trm(fb_kbd); - shutdown_virtual_devices(); - - EINTRLOOP(rs, close(fb_handle)); - fb_switch_shutdown(); - if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } - fb_show_cursor(); - return stracpy(cast_uchar "Cannot open GPM mouse.\n"); - } - /* hide cursor */ - if (border_left | border_top | border_right | border_bottom) fb_clear_videoram(); - - show_mouse(); - - END_GR - - return NULL; -} - -static void fb_shutdown_driver(void) -{ - int rs; - mem_free(mouse_buffer); - mem_free(background_buffer); - mem_free(new_background_buffer); - fb_driver.shutdown_device(mouse_graphics_device); - unhandle_fb_mouse(); - INC_IN_GR - if (fb_active) { - fb_clear_videoram(); - /*EINTRLOOP(rs, ioctl(fb_handle, FBIOPUT_VSCREENINFO, &oldmode));*/ - } - fb_shutdown_palette(); - EINTRLOOP(rs, close(fb_handle)); - EINTRLOOP(rs, munmap(fb_mem,fb_mapped_size)); - shutdown_virtual_devices(); - fb_switch_shutdown(); - svgalib_free_trm(fb_kbd); - if(fb_driver_param) mem_free(fb_driver_param); - /* show cursor */ - fb_show_cursor(); - install_signal_handler(SIGINT, (void (*)(void *))NULL, NULL, 0); - - if (in_gr_operation) internal("fb_shutdown_driver: in_gr_operation %d", in_gr_operation); -} - -static void fb_after_fork(void) -{ - int rs; - EINTRLOOP(rs, close(fb_handle)); -} - -static unsigned char *fb_get_driver_param(void) -{ - return fb_driver_param; -} - -static void fb_get_margin(int *left, int *right, int *top, int *bottom) -{ - *left = border_left; - *right = border_right; - *top = border_top; - *bottom = border_bottom; -} - -static int fb_set_margin(int left, int right, int top, int bottom) -{ - struct rect_set *rs; - int i, l; - struct rect r; - - if (left + right >= fb_xsize + border_left + border_right) - return -1; - if (top + bottom >= fb_ysize + border_top + border_bottom) - return -1; - - hide_mouse(); - - rs = init_rect_set(); - add_to_rect_set(&rs, &mouse_graphics_device->size); - r.x1 = left - border_left; - r.y1 = top - border_top; - r.x2 = fb_xsize - (right - border_right); - r.y2 = fb_ysize - (bottom - border_bottom); - exclude_rect_from_set(&rs, &r); - do_with_mouse_device( - for (i = 0; i < rs->m; i++) if (is_rect_valid(&rs->r[i])) - drv->fill_area(current_virtual_device, rs->r[i].x1, rs->r[i].y1, rs->r[i].x2, rs->r[i].y2, 0); - ); - mem_free(rs); - - mouse_x += border_left - left; - mouse_y += border_top - top; - fb_xsize = fb_xsize + border_left + border_right - (left + right); - fb_ysize = fb_ysize + border_top + border_bottom - (top + bottom); - border_left = left; - border_right = right; - border_top = top; - border_bottom = bottom; - - if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1; - if (mouse_x < 0) mouse_x = 0; - if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1; - if (mouse_y < 0) mouse_y = 0; - - fb_vmem = fb_mem + border_left * fb_pixelsize + border_top * fb_linesize; - - mouse_graphics_device->size.x2 = mouse_graphics_device->clip.x2 = fb_xsize; - mouse_graphics_device->size.y2 = mouse_graphics_device->clip.y2 = fb_ysize; - - show_mouse(); - - if (fb_driver_param) mem_free(fb_driver_param); - fb_driver_param = init_str(); - l = 0; - add_num_to_str(&fb_driver_param, &l, left); - add_chr_to_str(&fb_driver_param, &l, ','); - add_num_to_str(&fb_driver_param, &l, top); - add_chr_to_str(&fb_driver_param, &l, ','); - add_num_to_str(&fb_driver_param, &l, right); - add_chr_to_str(&fb_driver_param, &l, ','); - add_num_to_str(&fb_driver_param, &l, bottom); - - resize_virtual_devices(fb_xsize, fb_ysize); - - return 0; -} - -/* Return value: 0 alloced on heap - * 1 alloced in vidram - * 2 alloced in X server shm - */ -static int fb_get_empty_bitmap(struct bitmap *dest) -{ - if (dest->x && (unsigned)dest->x * (unsigned)dest->y / (unsigned)dest->x != (unsigned)dest->y) overalloc(); - if ((unsigned)dest->x * (unsigned)dest->y > (unsigned)MAXINT / fb_pixelsize) overalloc(); - dest->data=mem_alloc(dest->x*dest->y*fb_pixelsize); - dest->skip=dest->x*fb_pixelsize; - dest->flags=0; - return 0; -} - -static void fb_register_bitmap(struct bitmap *bmp) -{ -} - -static void fb_unregister_bitmap(struct bitmap *bmp) -{ - mem_free(bmp->data); -} - -static void *fb_prepare_strip(struct bitmap *bmp, int top, int lines) -{ - return ((unsigned char *)bmp->data) + bmp->skip * top; -} - - -static void fb_commit_strip(struct bitmap *bmp, int top, int lines) -{ -} - - -static void fb_draw_bitmap(struct graphics_device *dev,struct bitmap* hndl, int x, int y) -{ - unsigned char *scr_start; - int rs; - - CLIP_PREFACE - - accel_sync(); - - scr_start=fb_vmem+y*fb_linesize+x*fb_pixelsize; - for(;ys;ys--){ - memcpy(scr_start,data,xs*fb_pixelsize); - data+=hndl->skip; - scr_start+=fb_linesize; - } - END_MOUSE - END_GR -} - - -#ifdef USE_FB_ACCEL_FILLRECT -static inline unsigned fb_accel_color(void *ptr) -{ - return *(unsigned char *)ptr; -} -#endif - - -static void fb_fill_area(struct graphics_device *dev, int left, int top, int right, int bottom, long color) -{ - unsigned char *dest; - int y; - int rs; - - FILL_CLIP_PREFACE - -#ifdef USE_FB_ACCEL_FILLRECT - if (accel_flags & FB_ACCEL_FILLRECT_ACCELERATED) { - struct fb_fillrect f; - f.dx = left + border_left; - f.dy = top + border_top; - f.width = right - left; - f.height = bottom - top; - f.color = fb_accel_color(&color); - f.rop = ROP_COPY; - EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_FILLRECT, &f)); - if (rs < 0) { - error("fill_area accel failed\n"); - goto no_accel; - } - if (accel_flags & FB_ACCEL_SYNC_NEEDED) - need_accel_sync = 1; - } else - no_accel: -#endif - { - accel_sync(); - dest=fb_vmem+top*fb_linesize+left*fb_pixelsize; - for (y=bottom-top;y;y--){ - pixel_set(dest,(right-left)*fb_pixelsize,&color); - dest+=fb_linesize; - } - } - END_MOUSE - END_GR -} - - -static void fb_draw_hline(struct graphics_device *dev, int left, int y, int right, long color) -{ - unsigned char *dest; - int rs; - - HLINE_CLIP_PREFACE - -#ifdef USE_FB_ACCEL_FILLRECT - if (accel_flags & FB_ACCEL_FILLRECT_ACCELERATED) { - struct fb_fillrect f; - f.dx = left + border_left; - f.dy = y + border_top; - f.width = right - left; - f.height = 1; - f.color = fb_accel_color(&color); - f.rop = ROP_COPY; - EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_FILLRECT, &f)); - if (rs < 0) { - error("draw_hline accel failed\n"); - goto no_accel; - } - if (accel_flags & FB_ACCEL_SYNC_NEEDED) - need_accel_sync = 1; - } else - no_accel: -#endif - { - accel_sync(); - dest=fb_vmem+y*fb_linesize+left*fb_pixelsize; - pixel_set(dest,(right-left)*fb_pixelsize,&color); - } - END_MOUSE - END_GR -} - - -static void fb_draw_vline(struct graphics_device *dev, int x, int top, int bottom, long color) -{ - unsigned char *dest; - int y; - int rs; - - VLINE_CLIP_PREFACE - -#ifdef USE_FB_ACCEL_FILLRECT - if (accel_flags & FB_ACCEL_FILLRECT_ACCELERATED) { - struct fb_fillrect f; - f.dx = x + border_left; - f.dy = top + border_top; - f.width = 1; - f.height = bottom - top; - f.color = fb_accel_color(&color); - f.rop = ROP_COPY; - EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_FILLRECT, &f)); - if (rs < 0) { - error("draw_vline accel failed\n"); - goto no_accel; - } - if (accel_flags & FB_ACCEL_SYNC_NEEDED) - need_accel_sync = 1; - } else - no_accel: -#endif - { - accel_sync(); - dest=fb_vmem+top*fb_linesize+x*fb_pixelsize; - for (y=(bottom-top);y;y--){ - memcpy(dest,&color,fb_pixelsize); - dest+=fb_linesize; - } - } - END_MOUSE - END_GR -} - - -static int fb_hscroll(struct graphics_device *dev, struct rect_set **ignore, int sc) -{ - unsigned char *dest, *src; - int y; - int len; - int rs; - - HSCROLL_CLIP_PREFACE - -#ifdef USE_FB_ACCEL - if (accel_flags & FB_ACCEL_COPYAREA_ACCELERATED) { - struct fb_copyarea f; - f.sy = dev->clip.y1 + border_top; - f.height = dev->clip.y2 - dev->clip.y1; - f.dy = dev->clip.y1 + border_top; - if (sc > 0) { - f.sx = dev->clip.x1 + border_left; - f.width = dev->clip.x2 - dev->clip.x1 - sc; - f.dx = dev->clip.x1 + sc + border_left; - } else { - f.sx = dev->clip.x1 - sc + border_left; - f.width = dev->clip.x2 - dev->clip.x1 + sc; - f.dx = dev->clip.x1 + border_left; - } - EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_COPYAREA, &f)); - if (rs < 0) { - error("hscroll accel failed\n"); - goto no_accel; - } - if (accel_flags & FB_ACCEL_SYNC_NEEDED) - need_accel_sync = 1; - } else - no_accel: -#endif - { - accel_sync(); - if (sc>0){ - len=(dev->clip.x2-dev->clip.x1-sc)*fb_pixelsize; - src=fb_vmem+fb_linesize*dev->clip.y1+dev->clip.x1*fb_pixelsize; - dest=src+sc*fb_pixelsize; - for (y=dev->clip.y2-dev->clip.y1;y;y--){ - memmove(dest,src,len); - dest+=fb_linesize; - src+=fb_linesize; - } - }else{ - len=(dev->clip.x2-dev->clip.x1+sc)*fb_pixelsize; - dest=fb_vmem+fb_linesize*dev->clip.y1+dev->clip.x1*fb_pixelsize; - src=dest-sc*fb_pixelsize; - for (y=dev->clip.y2-dev->clip.y1;y;y--){ - memmove(dest,src,len); - dest+=fb_linesize; - src+=fb_linesize; - } - } - } - END_MOUSE - END_GR - return 1; -} - - -static int fb_vscroll(struct graphics_device *dev, struct rect_set **ignore, int sc) -{ - unsigned char *dest, *src; - int y; - int len; - int rs; - - VSCROLL_CLIP_PREFACE - -#ifdef USE_FB_ACCEL - if (accel_flags & FB_ACCEL_COPYAREA_ACCELERATED) { - struct fb_copyarea f; - f.sx = dev->clip.x1 + border_left; - f.width = dev->clip.x2 - dev->clip.x1; - f.dx = dev->clip.x1 + border_left; - if (sc > 0) { - f.sy = dev->clip.y1 + border_top; - f.height = dev->clip.y2 - dev->clip.y1 - sc; - f.dy = dev->clip.y1 + sc + border_top; - } else { - f.sy = dev->clip.y1 - sc + border_top; - f.height = dev->clip.y2 - dev->clip.y1 + sc; - f.dy = dev->clip.y1 + border_top; - } - EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_COPYAREA, &f)); - if (rs < 0) { - error("vscroll accel failed\n"); - goto no_accel; - } - if (accel_flags & FB_ACCEL_SYNC_NEEDED) - need_accel_sync = 1; - } else - no_accel: -#endif - { - accel_sync(); - len=(dev->clip.x2-dev->clip.x1)*fb_pixelsize; - if (sc>0){ - /* Down */ - dest=fb_vmem+(dev->clip.y2-1)*fb_linesize+dev->clip.x1*fb_pixelsize; - src=dest-fb_linesize*sc; - for (y=dev->clip.y2-dev->clip.y1-sc;y;y--){ - memcpy(dest,src,len); - dest-=fb_linesize; - src-=fb_linesize; - } - }else{ - /* Up */ - dest=fb_vmem+dev->clip.y1*fb_linesize+dev->clip.x1*fb_pixelsize; - src=dest-fb_linesize*sc; - for (y=dev->clip.y2-dev->clip.y1+sc;y;y--){ - memcpy(dest,src,len); - dest+=fb_linesize; - src+=fb_linesize; - } - } - } - END_MOUSE - END_GR - return 1; -} - - -static int fb_block(struct graphics_device *dev) -{ - if (fb_old_vd) return 1; - INC_IN_GR - if (fb_active) accel_sync(); - fb_block_dev = dev; - unhandle_fb_mouse(); - fb_old_vd = current_virtual_device; - current_virtual_device=NULL; - svgalib_block_itrm(fb_kbd); - if (have_cmap && fb_active) set_palette(&old_palette); - fb_switch_shutdown(); - fb_show_cursor(); - fb_print(cast_uchar "\n"); - return 0; -} - -static int fb_unblock(struct graphics_device *dev) -{ - int rs; - unsigned char *e; - if (current_virtual_device) return 0; - if (dev != fb_block_dev) return -2; - if (svgalib_unblock_itrm(fb_kbd)) return -1; - e = fb_switch_init(); - if (e) { - fatal_exit("fb_switch_init failed: %s", e); - } - fb_hide_cursor(); - fb_pan_display(); - current_virtual_device = fb_old_vd; - fb_old_vd = NULL; - if (have_cmap) set_palette(&global_pal); - if (handle_fb_mouse()) { - fatal_exit("Cannot open GPM mouse."); - } - END_GR - if (border_left | border_top | border_right | border_bottom) fb_clear_videoram(); - if (current_virtual_device) current_virtual_device->redraw_handler(current_virtual_device - ,&current_virtual_device->size); - return 0; -} - - -struct graphics_driver fb_driver={ - cast_uchar "fb", - fb_init_driver, - init_virtual_device, - shutdown_virtual_device, - fb_shutdown_driver, - (void (*)(void))NULL, - fb_after_fork, - fb_get_driver_param, - (unsigned char *(*)(void))NULL, - fb_get_margin, - fb_set_margin, - fb_get_empty_bitmap, - fb_register_bitmap, - fb_prepare_strip, - fb_commit_strip, - fb_unregister_bitmap, - fb_draw_bitmap, - (long (*)(int))NULL, /* fb_get_color */ - fb_fill_area, - fb_draw_hline, - fb_draw_vline, - fb_hscroll, - fb_vscroll, - generic_set_clip_area, - NULL, - fb_block, - fb_unblock, - (void (*)(struct graphics_device *, unsigned char *))NULL, /* set_title */ - (int (*)(unsigned char *, int))NULL, /* exec */ - (void (*)(struct graphics_device *, unsigned char *))NULL, /* set_clipboard_text */ - (unsigned char *(*)(void))NULL, /* get_clipboard_text */ - 0, /* depth (filled in fb_init_driver function) */ - 0, 0, /* size (in X is empty) */ - GD_NEED_CODEPAGE, /* flags */ - 0, /* codepage */ - NULL, /* shell */ -}; - -#endif /* GRDRV_FB */ diff --git a/ftp.c b/ftp.c @@ -288,7 +288,6 @@ static struct ftp_connection_info *add_file_cmd_to_str(struct connection *c, int if (!inf->pasv) { int ps; -#ifdef SUPPORT_IPV6 if (is_ipv6(c->sock1)) { ps = get_pasv_socket_ipv6(c, c->sock1, &c->sock2, port_string); if (ps) { @@ -297,7 +296,6 @@ static struct ftp_connection_info *add_file_cmd_to_str(struct connection *c, int return NULL; } } else -#endif { unsigned char pc[6]; ps = get_pasv_socket(c, c->sock1, &c->sock2, pc); diff --git a/gif.c b/gif.c @@ -12,9 +12,7 @@ #include "links.h" -#ifdef HAVE_MATH_H #include <math.h> -#endif struct gif_decoder{ unsigned char *color_map; /* NULL if no color map, otherwise a block of 768 bytes, red, green, blue, diff --git a/grx.c b/grx.c @@ -1,572 +0,0 @@ -#include "cfg.h" - -#ifdef GRDRV_GRX - -#include "links.h" - -#include <grx20.h> - -#include "arrow.inc" - -#define NUMBER_OF_DEVICES 12 - -void _GrCloseVideoDriver(void); - -extern struct graphics_driver grx_driver; - -static struct itrm *svgalib_kbd; - -static unsigned char *grx_driver_param = NULL; -static struct graphics_device *grx_old_vd; -static unsigned char in_graphics_mode = 0; - -#define TEST_INACTIVITY if (dev != current_virtual_device || !dev->clip.x2) return; -#define TEST_INACTIVITY_0 if (dev != current_virtual_device || !dev->clip.x2) return 0; - -static void grx_set_palette(void) -{ - int i; - if (grx_driver.depth == 33) { - for (i = 0; i < 16; i++) { - GrSetColor(i, - i & 8 ? 255 : 0, - ((i >> 1) & 3) * 85, - i & 1 ? 255 : 0); - } - } - if (grx_driver.depth == 65) { - for (i = 0; i < 256; i++) { - GrSetColor(i, - ((i >> 5) & 7) * (255./7.), - ((i >> 2) & 7) * (255./7.), - (i & 3) * 85); - } - } -} - -static void grx_set_text(void) -{ - if (in_graphics_mode) { - GrSetMode(GR_default_text); - in_graphics_mode = 0; - _GrCloseVideoDriver(); -#ifdef DOS - dos_restore_screen(); -#endif - } -} - -static void grx_restore(void) -{ - if (grx_driver_param) mem_free(grx_driver_param), grx_driver_param = NULL; - grx_set_text(); -} - -static void grx_set_clip(void) -{ - GrSetClipBox( - current_virtual_device->clip.x1, - current_virtual_device->clip.y1, - current_virtual_device->clip.x2 - 1, - current_virtual_device->clip.y2 - 1 - ); -} - -static void grx_key_in(struct itrm *p, unsigned char *ev_, int size) -{ - int vd; - struct links_event *ev = (struct links_event *)(void *)ev_; - if (size != sizeof(struct links_event)) return; - if (ev->ev == EV_ABORT) terminate_loop = 1; - if (ev->ev != EV_KBD) return; - if ((ev->y & KBD_ALT) && ev->x >= '0' && ev->x <= '9') { - vd = (ev->x - '1' + 10) % 10; - goto switch_vd; - } - if ((ev->y & KBD_ALT) && ev->x == '-') { - vd = 10; - goto switch_vd; - } - if ((ev->y & KBD_ALT) && ev->x == '=') { - vd = 11; - goto switch_vd; - } - if ((ev->y & KBD_ALT) && ev->x <= KBD_F1 && ev->x >= KBD_F12) { - vd = KBD_F1 - ev->x; - goto switch_vd; - } - if (g_kbd_codepage(&grx_driver) != utf8_table && ev->x >= 128 && ev->x <= 255) - if ((ev->x = cp2u(ev->x, g_kbd_codepage(&grx_driver))) == -1) return; - if (current_virtual_device && current_virtual_device->keyboard_handler) current_virtual_device->keyboard_handler(current_virtual_device, ev->x, ev->y); - return; - -switch_vd: - switch_virtual_device(vd); - grx_set_clip(); -} - -int grx_mouse_initialized = 0; -static GrCursor *grx_mouse_cursor; - -static void grx_mouse_init(void) -{ - int x, y; - static unsigned char cursor[arrow_area]; - static GrColor table[3]; - - if (!GrMouseDetect()) return; - grx_mouse_initialized = 1; - GrMouseInit(); - GrMouseEventEnable(0, 1); - - memset(&table, 0, sizeof table); - table[0] = 2; - table[1] = grx_driver.get_color(0); - table[2] = grx_driver.get_color(0xffffff); - for (y = 0; y < arrow_height; y++) - for (x = 0; x < arrow_width; x++) - cursor[y * arrow_width + x] = - (arrow[2 * y] >> (arrow_width - x - 1)) & 1 ? 1 : - (arrow[2 * y + 1] >> (arrow_width - x - 1)) & 1 ? 2 : - 0; - - grx_mouse_cursor = GrBuildCursor(cast_char cursor, arrow_width, arrow_width, arrow_height, 0, 0, table); - - if (!grx_mouse_cursor) GrMouseSetColors(GrWhite(), GrBlack()); - else GrMouseSetCursor(grx_mouse_cursor); - - GrMouseDisplayCursor(); -} - -static void grx_mouse_terminate(void) -{ - if (!grx_mouse_initialized) return; - GrMouseUnInit(); - if (grx_mouse_cursor) GrDestroyCursor(grx_mouse_cursor); - grx_mouse_initialized = 0; -} - -void grx_mouse_poll(void) -{ - int x = GrMousePendingEvent(); - x = x; -} - -static void grx_do_event(GrMouseEvent *ev, int b) -{ - if (!current_virtual_device) return; - if (current_virtual_device->mouse_handler) current_virtual_device->mouse_handler(current_virtual_device, ev->x, ev->y, b); -} - -int grx_mouse_event(void) -{ - int e; - GrMouseEvent ev; - e = 0; -get_another: - GrMouseGetEvent(GR_M_MOTION | GR_M_BUTTON_CHANGE | GR_M_POLL, &ev); - if (ev.flags & GR_M_LEFT_DOWN) grx_do_event(&ev, B_LEFT | B_DOWN), e = 1; - if (ev.flags & GR_M_LEFT_UP) grx_do_event(&ev, B_LEFT | B_UP), e = 1; - if (ev.flags & GR_M_RIGHT_DOWN) grx_do_event(&ev, B_RIGHT | B_DOWN), e = 1; - if (ev.flags & GR_M_RIGHT_UP) grx_do_event(&ev, B_RIGHT | B_UP), e = 1; - if (ev.flags & GR_M_MIDDLE_DOWN) grx_do_event(&ev, B_MIDDLE | B_DOWN), e = 1; - if (ev.flags & GR_M_MIDDLE_UP) grx_do_event(&ev, B_MIDDLE | B_UP), e = 1; - if (ev.flags & GR_M_P4_DOWN) grx_do_event(&ev, B_WHEELUP | B_MOVE), e = 1; - if (ev.flags & GR_M_P5_DOWN) grx_do_event(&ev, B_WHEELDOWN | B_MOVE), e = 1; - if (!e && ev.flags & GR_M_MOTION) { - if (GrMousePendingEvent()) - goto get_another; - grx_do_event(&ev, - ev.buttons & GR_M_LEFT ? B_LEFT | B_DRAG : - ev.buttons & GR_M_RIGHT ? B_RIGHT | B_DRAG : - ev.buttons & GR_M_MIDDLE ? B_DRAG | B_MIDDLE : B_MOVE), e = 1; - } - return e; -} - -static unsigned char *set_mode_according_to_param(unsigned char *param) -{ - unsigned char e[MAX_STR_LEN]; -#ifdef DOS - dos_save_screen(); -#endif - if (!param || !*param) { - return stracpy(cast_uchar "There is no default videomode.\nUse the switch \"-mode WIDTHxHEIGHTxCOLORS\" to select video mode.\nThe COLORS argument may be 16, 256, 32k, 64k, 16M.\n"); - if (!GrSetMode(GR_default_graphics)) - return stracpy(cast_uchar "GrSetMode failed.\n"); - in_graphics_mode = 1; - } else { - unsigned long x, y; - int pl; - unsigned char *ptr = param, *end; - x = strtoul(cast_const_char ptr, (char **)(void *)&end, 10); - if (end == ptr || *end != 'x' || x >= MAXINT) - goto bad_param; - ptr = end + 1; - y = strtoul(cast_const_char ptr, (char **)(void *)&end, 10); - if (end == ptr || *end != 'x' || y >= MAXINT) - goto bad_param; - ptr = end + 1; - if (!strcmp(cast_const_char ptr, "16")) pl = 4; - else if (!strcmp(cast_const_char ptr, "256")) pl = 8; - else if (!casestrcmp(ptr, cast_uchar "32k") || !strcmp(cast_const_char ptr, "32768")) pl = 15; - else if (!casestrcmp(ptr, cast_uchar "64k") || !strcmp(cast_const_char ptr, "65536")) pl = 16; - else if (!casestrcmp(ptr, cast_uchar "16M") || !casestrcmp(ptr, cast_uchar "16M32") || !strcmp(cast_const_char ptr, "16777216")) pl = 24; - else goto bad_param; - if (x == 800 && y == 600 && pl == 4) y = 599; /* a bug in GRX */ - if (!GrSetMode(GR_width_height_bpp_graphics, (int)x, (int)y, pl)) { - snprintf(cast_char e, MAX_STR_LEN, "GrSetMode(%lu,%lu,%d) failed.\n", x, y, pl); - return stracpy(e); - } - in_graphics_mode = 1; - } - return NULL; - -bad_param: - return stracpy(cast_uchar "Bad -mode parameter.\n"); -} - -static void grx_set_graphics(void) -{ - if (!in_graphics_mode) { - unsigned char *er; - er = set_mode_according_to_param(grx_driver_param); - if (er) - fatal_exit("grx: Unable to restore video mode '%s': %s", grx_driver_param, er); - } -} - -static unsigned char *grx_init_driver(unsigned char *param, unsigned char *ignore) -{ - unsigned char e[MAX_STR_LEN]; - unsigned char *er; - const GrVideoMode *mode; - const GrFrameDriver *fd; - - kbd_set_raw = 1; - - grx_old_vd = NULL; - - er = set_mode_according_to_param(param); - if (er) - return er; - - mode = GrCurrentVideoMode(); - fd = GrScreenFrameDriver(); - if (GrNumPlanes() != (mode->bpp == 4 ? 4 : 1)) { -unsupported_videomode: - snprintf(cast_char e, MAX_STR_LEN, "Unsupported videomode: x %d, y %d, bpp (%d, %d), planes %d.\n", mode->width, mode->height, mode->bpp, fd->bits_per_pixel, (int)GrNumPlanes()); - grx_restore(); - return stracpy(e); - } - switch (mode->bpp) { - case 4: - grx_driver.depth = 33; - break; - case 8: - grx_driver.depth = 65; - break; - case 15: - grx_driver.depth = 122; - break; - case 16: - grx_driver.depth = 130; - break; - case 24: - case 32: - if (fd->bits_per_pixel == 24) - grx_driver.depth = 195; - else if (fd->bits_per_pixel == 32) - grx_driver.depth = 196; - else - goto unsupported_videomode; - break; - default: - goto unsupported_videomode; - } - grx_driver.get_color = get_color_fn(grx_driver.depth); - grx_driver.x = mode->width; - grx_driver.y = mode->height; - if (mode->bpp >= 8) grx_driver.flags |= GD_DONT_USE_SCROLL; - else grx_driver.flags &= ~GD_DONT_USE_SCROLL; - /*fatal_exit("current mode: %d,%d,%d planes %d bits %d %d", mode->width, mode->height, mode->bpp, GrNumPlanes(), GrScreenFrameDriver()->bits_per_pixel, mode->bpp);*/ - - grx_set_palette(); - - grx_driver_param = stracpy(param ? param : cast_uchar ""); - - if (init_virtual_devices(&grx_driver, NUMBER_OF_DEVICES)) { - grx_restore(); - return stracpy(cast_uchar "Allocation of virtual devices failed.\n"); - } - - svgalib_kbd = handle_svgalib_keyboard(grx_key_in); - grx_mouse_init(); - return NULL; -} - -static void grx_shutdown_driver(void) -{ - shutdown_virtual_devices(); - grx_mouse_terminate(); - svgalib_free_trm(svgalib_kbd); - grx_restore(); -} - -static void grx_emergency_shutdown(void) -{ - grx_restore(); -} - -static unsigned char *grx_get_driver_param(void) -{ - return grx_driver_param; -} - -struct grx_bmp { - GrContext c; -}; - -static int grx_get_empty_bitmap(struct bitmap *bmp) -{ - struct grx_bmp *b; - - if (!in_graphics_mode) - internal("grx_get_empty_bitmap: not in graphics mode"); - - b = mem_alloc_mayfail(sizeof(struct grx_bmp)); - if (!b) goto fail0; -again1: - if (!GrCreateContext(bmp->x, bmp->y, NULL, &b->c)) { - if (out_of_memory(0, NULL, 0)) - goto again1; - goto fail1; - } - bmp->flags = b; - if (GrNumPlanes() == 1) { - bmp->data = b->c.gc_baseaddr[0]; - bmp->skip = b->c.gc_lineoffset; - } else { - if (bmp->x && (unsigned)bmp->x * (unsigned)bmp->y / (unsigned)bmp->x != (unsigned)bmp->y) goto fail2; - if ((unsigned)bmp->x * (unsigned)bmp->y > (unsigned)MAXINT) goto fail2; - bmp->skip = bmp->x; - bmp->data = mem_alloc_mayfail(bmp->skip * bmp->y); - if (!bmp->data) goto fail2; - } - return 0; - -fail2: - GrDestroyContext(&b->c); -fail1: - mem_free(b); -fail0: - bmp->data = NULL; - bmp->flags = NULL; - return -1; -} - -static void grx_copy_planes(struct bitmap *bmp, int y, int n) -{ - struct grx_bmp *b = bmp->flags; - int j; - if (!b) return; - for (j = 0; j < n; y++, j++) { - int i; - for (i = 0; i < GrNumPlanes(); i++) { - int x; - unsigned char *src = (unsigned char *)bmp->data + bmp->skip * j; - unsigned char *dst = (unsigned char *)b->c.gc_baseaddr[i] + y * b->c.gc_lineoffset; - unsigned char byt = 0; - for (x = 0; x < bmp->x; ) { - unsigned char bit = (*src++ >> i) & 1; - byt |= bit << ((x & 7) ^ 7); - x++; - if (!(x & 7)) *dst++ = byt, byt = 0; - } - if (x & 7) *dst = byt; - } - } -} - -static void grx_register_bitmap(struct bitmap *bmp) -{ - if (GrNumPlanes() != 1) { - grx_copy_planes(bmp, 0, bmp->y); - mem_free(bmp->data); - } -} - -static void *grx_prepare_strip(struct bitmap *bmp, int top, int lines) -{ - struct grx_bmp *b = bmp->flags; - if (!b) return NULL; - if (GrNumPlanes() != 1) { - bmp->data = mem_alloc_mayfail(bmp->skip * lines); - return bmp->data; - } - return ((unsigned char *)bmp->data) + bmp->skip * top; -} - - -static void grx_commit_strip(struct bitmap *bmp, int top, int lines) -{ - if (GrNumPlanes() != 1) { - if (!bmp->data) return; - grx_copy_planes(bmp, top, lines); - mem_free(bmp->data); - } -} - -static void grx_unregister_bitmap(struct bitmap *bmp) -{ - struct grx_bmp *b = bmp->flags; - if (!b) return; - GrDestroyContext(&b->c); - mem_free(b); -} - -static void grx_draw_bitmap(struct graphics_device *dev, struct bitmap *bmp, int x, int y) -{ - struct grx_bmp *b = bmp->flags; - if (!b) return; - TEST_INACTIVITY - /* note: GrImageDisplay has buggy clipping. - It doesn't draw if the target x or y coordinate is one pixel - before the end of clip area */ - GrBitBlt(NULL, x, y, &b->c, 0, 0, bmp->x - 1, bmp->y - 1, GrWRITE); -} - -static void grx_fill_area(struct graphics_device *dev, int x1, int y1, int x2, int y2, long color) -{ - TEST_INACTIVITY - if (x1 >= x2 || y1 >= y2) return; - GrFilledBox(x1, y1, x2 - 1, y2 - 1, color); -} - -static void grx_draw_hline(struct graphics_device *dev, int x1, int y, int x2, long color) -{ - TEST_INACTIVITY - if (x1 >= x2) return; - GrHLine(x1, x2 - 1, y, color); -} - -static void grx_draw_vline(struct graphics_device *dev, int x, int y1, int y2, long color) -{ - TEST_INACTIVITY - if (y1 >= y2) return; - GrVLine(x, y1, y2 - 1, color); -} - -static int grx_hscroll(struct graphics_device *dev, struct rect_set **ignore, int sc) -{ - TEST_INACTIVITY_0 - if (!sc) return 0; - if (sc < 0) { - if (-sc >= dev->clip.x2 - dev->clip.x1) return 1; - GrBitBlt(NULL, dev->clip.x1, dev->clip.y1, - NULL, dev->clip.x1 - sc, dev->clip.y1, - dev->clip.x2 - 1, dev->clip.y2 - 1, GrWRITE); - } else { - if (sc >= dev->clip.x2 - dev->clip.x1) return 1; - GrBitBlt(NULL, dev->clip.x1 + sc, dev->clip.y1, - NULL, dev->clip.x1, dev->clip.y1, - dev->clip.x2 - sc - 1, dev->clip.y2 - 1, GrWRITE); - } - return 1; -} - -static int grx_vscroll(struct graphics_device *dev, struct rect_set **ignore, int sc) -{ - TEST_INACTIVITY_0 - if (!sc) return 0; - if (sc < 0) { - if (-sc >= dev->clip.y2 - dev->clip.y1) return 1; - GrBitBlt(NULL, dev->clip.x1, dev->clip.y1, - NULL, dev->clip.x1, dev->clip.y1 - sc, - dev->clip.x2 - 1, dev->clip.y2 - 1, GrWRITE); - } else { - if (sc >= dev->clip.y2 - dev->clip.y1) return 1; - GrBitBlt(NULL, dev->clip.x1, dev->clip.y1 + sc, - NULL, dev->clip.x1, dev->clip.y1, - dev->clip.x2 - 1, dev->clip.y2 - sc - 1, GrWRITE); - } - return 1; -} - -static void grx_set_clip_area(struct graphics_device *dev, struct rect *r) -{ - generic_set_clip_area(dev, r); - if (dev != current_virtual_device) return; - grx_set_clip(); -} - -static int grx_block(struct graphics_device *dev) -{ - if (grx_old_vd) return 1; - grx_old_vd = current_virtual_device; - current_virtual_device = NULL; - grx_mouse_terminate(); - svgalib_block_itrm(svgalib_kbd); - grx_set_text(); - return 0; -} - -static int grx_unblock(struct graphics_device *dev) -{ - if (current_virtual_device) { - internal("grx_unblock called without grx_block"); - return 0; - } - grx_set_graphics(); - svgalib_unblock_itrm(svgalib_kbd); - current_virtual_device = grx_old_vd; - grx_old_vd = NULL; - grx_set_palette(); - grx_set_clip(); - grx_mouse_init(); - if (current_virtual_device) current_virtual_device->redraw_handler(current_virtual_device, &current_virtual_device->size); - return 0; -} - -struct graphics_driver grx_driver = { - cast_uchar "grx", - grx_init_driver, - init_virtual_device, - shutdown_virtual_device, - grx_shutdown_driver, - grx_emergency_shutdown, - NULL, - grx_get_driver_param, - NULL, - NULL, - NULL, - grx_get_empty_bitmap, - /*grx_get_filled_bitmap,*/ - grx_register_bitmap, - grx_prepare_strip, - grx_commit_strip, - grx_unregister_bitmap, - grx_draw_bitmap, - /*grx_draw_bitmaps,*/ - NULL, - grx_fill_area, - grx_draw_hline, - grx_draw_vline, - grx_hscroll, - grx_vscroll, - grx_set_clip_area, - NULL, - grx_block, - grx_unblock, - NULL, /* set_title */ - NULL, /* exec */ - NULL, /* set_clipboard_text */ - NULL, /* get_clipboard_text */ - 0, /* depth */ - 0, 0, /* size */ - GD_NEED_CODEPAGE, /* flags */ - 0, /* codepage */ - NULL, /* shell */ -}; - -#endif diff --git a/html.c b/html.c @@ -551,23 +551,6 @@ void kill_html_stack_item(struct html_element *e) mem_free(e); } -#if defined(DEBUG) && 0 -void debug_stack(void) -{ - struct html_element *e; - struct list_head *le; - printf("HTML stack debug: \n"); - foreachback(struct html_element, e, le, html_stack) { - int i; - printf("\""); - for (i = 0; i < e->namelen; i++) printf("%c", e->name[i]); - printf("\"\n"); - } - printf("%c", 7); - fflush(stdout); - portable_sleep(1000); -} -#endif void html_stack_dup(void) { @@ -600,41 +583,6 @@ void html_stack_dup(void) } -#ifdef JS -static void get_js_event(unsigned char *a, unsigned char *name, unsigned char **where) -{ - unsigned char *v; - if ((v = get_attr_val(a, name))) { - if (*where) mem_free(*where); - *where = v; - } -} - -static int get_js_events_x(struct js_event_spec **spec, unsigned char *a) -{ - if (!has_attr(a, cast_uchar "onkeyup") && !has_attr(a, cast_uchar "onkeydown") && !has_attr(a,cast_uchar "onkeypress") && !has_attr(a,cast_uchar "onchange") && !has_attr(a, cast_uchar "onfocus") && !has_attr(a,cast_uchar "onblur") && !has_attr(a, cast_uchar "onclick") && !has_attr(a, cast_uchar "ondblclick") && !has_attr(a, cast_uchar "onmousedown") && !has_attr(a, cast_uchar "onmousemove") && !has_attr(a, cast_uchar "onmouseout") && !has_attr(a, cast_uchar "onmouseover") && !has_attr(a, cast_uchar "onmouseup")) return 0; - create_js_event_spec(spec); - get_js_event(a, cast_uchar "onclick", &(*spec)->click_code); - get_js_event(a, cast_uchar "ondblclick", &(*spec)->dbl_code); - get_js_event(a, cast_uchar "onmousedown", &(*spec)->down_code); - get_js_event(a, cast_uchar "onmouseup", &(*spec)->up_code); - get_js_event(a, cast_uchar "onmouseover", &(*spec)->over_code); - get_js_event(a, cast_uchar "onmouseout", &(*spec)->out_code); - get_js_event(a, cast_uchar "onmousemove", &(*spec)->move_code); - get_js_event(a, cast_uchar "onfocus", &(*spec)->focus_code); - get_js_event(a, cast_uchar "onblur", &(*spec)->blur_code); - get_js_event(a, cast_uchar "onchange", &(*spec)->change_code); - get_js_event(a, cast_uchar "onkeypress", &(*spec)->keypress_code); - get_js_event(a, cast_uchar "onkeyup", &(*spec)->keyup_code); - get_js_event(a, cast_uchar "onkeydown", &(*spec)->keydown_code); - return 1; -} - -static int get_js_events(unsigned char *a) -{ - return get_js_events_x(&format_.js_event, a); -} -#else static int get_js_events_x(struct js_event_spec **spec, unsigned char *a) { return 0; @@ -643,7 +591,6 @@ static int get_js_events(unsigned char *a) { return 0; } -#endif void *ff; void (*put_chars_f)(void *, unsigned char *, int); @@ -2574,9 +2521,6 @@ static void html_frameset(unsigned char *a) fp.parent = html_top.frameset; if (fp.x && fp.y) { html_top.frameset = special_f(ff, SP_FRAMESET, &fp); -#ifdef JS - if (html_top.frameset)html_top.frameset->onload_code=get_attr_val(a,cast_uchar "onload"); -#endif } mem_free(fp.xw); mem_free(fp.yw); diff --git a/html_gr.c b/html_gr.c @@ -549,18 +549,6 @@ static void do_image(struct g_part *p, struct image_description *im) link->target = stracpy(ld->target); link->img_alt = stracpy(ld->label); link->where_img = stracpy(im->url); -#ifdef JS - if (ld->onclick || ld->ondblclick || ld->onmousedown || ld->onmouseup || ld->onmouseover || ld->onmouseout || ld->onmousemove) { - create_js_event_spec(&link->js_event); - link->js_event->click_code = stracpy(ld->onclick); - link->js_event->dbl_code = stracpy(ld->ondblclick); - link->js_event->down_code = stracpy(ld->onmousedown); - link->js_event->up_code = stracpy(ld->onmouseup); - link->js_event->over_code = stracpy(ld->onmouseover); - link->js_event->out_code = stracpy(ld->onmouseout); - link->js_event->move_code = stracpy(ld->onmousemove); - } -#endif a->link_num = (int)(link - p->data->links); } if (last_link) mem_free(last_link), last_link = NULL; diff --git a/html_r.c b/html_r.c @@ -13,10 +13,6 @@ struct f_data *init_formatted(struct document_options *opt) scr->data = DUMMY; scr->nlinks = 0; scr->links = DUMMY; -#ifdef JS - scr->nlink_events = 0; - scr->link_events = DUMMY; -#endif init_list(scr->forms); init_list(scr->tags); init_list(scr->nodes); @@ -60,9 +56,6 @@ void free_frameset_desc(struct frameset_desc *fd) if (fd->f[i].name) mem_free(fd->f[i].name); if (fd->f[i].url) mem_free(fd->f[i].url); } -#ifdef JS - if (fd->onload_code)mem_free(fd->onload_code); -#endif mem_free(fd); } @@ -73,9 +66,6 @@ struct frameset_desc *copy_frameset_desc(struct frameset_desc *fd) if ((unsigned)fd->n > MAXINT / sizeof(struct frame_desc)) overalloc(); neww = mem_alloc(sizeof(struct frameset_desc) + fd->n * sizeof(struct frame_desc)); memcpy(neww, fd, sizeof(struct frameset_desc) + fd->n * sizeof(struct frame_desc)); -#ifdef JS - if (neww->onload_code) neww->onload_code = stracpy(neww->onload_code); -#endif for (i = 0; i < neww->n; i++) { if (neww->f[i].subframe) neww->f[i].subframe = copy_frameset_desc(neww->f[i].subframe); if (neww->f[i].name) neww->f[i].name = stracpy(neww->f[i].name); @@ -137,12 +127,6 @@ static void clear_formatted(struct f_data *scr) free_js_event_spec(l->js_event); } mem_free(scr->links); -#ifdef JS - for (n = 0; n < scr->nlink_events; n++) { - free_js_event_spec(scr->link_events[n]); - } - mem_free(scr->link_events); -#endif if (!F) for (y = 0; y < scr->y; y++) mem_free(scr->data[y].d); mem_free(scr->data); if (scr->lines1) mem_free(scr->lines1); @@ -162,10 +146,6 @@ static void clear_formatted(struct f_data *scr) if (scr->search_lengths) mem_free(scr->search_lengths); #endif if (scr->refresh) mem_free(scr->refresh); -#ifdef JS - if (scr->script_href_base) mem_free(scr->script_href_base); - free_js_event_spec(scr->js_event); -#endif } void destroy_formatted(struct f_data *scr) @@ -620,7 +600,6 @@ static void put_chars(void *p_, unsigned char *c, int l) if (c[0] != ' ' || (c[1] && c[1] != ' ')) { last_tag_for_newline = &p->data->tags; } -#ifdef ENABLE_UTF8 if (d_opt->cp == utf8_table && !(format_.attr & AT_GRAPHICS)) { int pl; unsigned char *cc; @@ -676,7 +655,6 @@ static void put_chars(void *p_, unsigned char *c, int l) return; } } else -#endif { ll = l; } @@ -693,11 +671,9 @@ static void put_chars(void *p_, unsigned char *c, int l) mem_free(uni_c); return; } -#ifdef ENABLE_UTF8 if (d_opt->cp == utf8_table && !(format_.attr & AT_GRAPHICS)) { set_hline_uni(p, p->cx, p->cy, ll, uni_c, ((fg&0x08)<<3)|(bg<<3)|(fg&0x07)); } else -#endif { set_hline(p, p->cx, p->cy, l, c, ((fg&0x08)<<3)|(bg<<3)|(fg&0x07)); } @@ -922,26 +898,10 @@ void create_frame(struct frame_param *fp) void process_script(struct f_data *f, unsigned char *t) { -#ifdef JS - if (t && !f->script_href_base) f->script_href_base = stracpy(format_.href_base); - if (!d_opt->js_enable) return; - if (t) { - unsigned char *u; - u = join_urls(f->script_href_base, t); - if (u) { - request_additional_file(f, u); - mem_free(u); - } - } - f->are_there_scripts = 1; -#endif } void set_base(struct f_data *f, unsigned char *t) { -#ifdef JS - if (!f->script_href_base) f->script_href_base = stracpy(format_.href_base); -#endif } void html_process_refresh(struct f_data *f, unsigned char *url, int time) @@ -1227,11 +1187,7 @@ void really_format_html(struct cache_entry *ce, unsigned char *start, unsigned c head = init_str(), hdl = 0; if (ce->head) add_to_str(&head, &hdl, ce->head); scan_http_equiv(start, end, &head, &hdl, &t, d_opt->plain ? NULL : &bg, d_opt->plain || d_opt->col < 2 ? NULL : &bgcolor, &implicit_pre_wrap, -#ifdef JS - &screen->js_event -#else NULL -#endif ); if (d_opt->break_long_lines) implicit_pre_wrap = 1; if (d_opt->plain) *t = 0; diff --git a/http.c b/http.c @@ -224,10 +224,8 @@ static void http_send_header(struct connection *c) set_connection_timeout(c); info = mem_calloc(sizeof(struct http_connection_info)); c->info = info; -#ifdef HAVE_SSL info->https_forward = !c->ssl && proxy && host && !casecmp(host, cast_uchar "https://", 8); if (c->ssl) proxy = 0; -#endif info->send_close = info->https_forward || http10 || (post && http_options.bug_post_no_keepalive); hdr = init_str(); if (!host) { @@ -246,7 +244,6 @@ static void http_send_header(struct connection *c) post = cast_uchar strchr(cast_const_char host, POST_CHAR); if (post) post++; } -#ifdef HAVE_SSL if (info->https_forward) { add_to_str(&hdr, &l, cast_uchar "CONNECT "); h = get_host_name(host); @@ -260,7 +257,6 @@ static void http_send_header(struct connection *c) mem_free(h); goto added_connect; } else -#endif if (!post) { add_to_str(&hdr, &l, cast_uchar "GET "); } else { @@ -289,9 +285,7 @@ static void http_send_header(struct connection *c) } add_url_to_str(&hdr, &l, u2); if (u2 != u) mem_free(u2); -#ifdef HAVE_SSL added_connect: -#endif if (!http10) add_to_str(&hdr, &l, cast_uchar " HTTP/1.1\r\n"); else add_to_str(&hdr, &l, cast_uchar " HTTP/1.0\r\n"); if (!info->https_forward && (h = get_host_name(host))) { @@ -521,39 +515,9 @@ static void add_accept_encoding(unsigned char **hdr, int *l, unsigned char *url, int l1; add_to_str(hdr, l, cast_uchar "Accept-Encoding: "); l1 = *l; -#if defined(HAVE_ZLIB) if (*l != l1) add_to_str(hdr, l, cast_uchar ", "); add_to_str(hdr, l, cast_uchar "gzip, deflate"); -#endif -#if defined(HAVE_BROTLI) - if ((!SCRUB_HEADERS -#ifdef HAVE_SSL - || c->ssl -#endif - ) && !(info->bl_flags & BL_NO_BZIP2)) { - if (*l != l1) add_to_str(hdr, l, cast_uchar ", "); - add_to_str(hdr, l, cast_uchar "br"); - } -#endif -#if defined(HAVE_BZIP2) - if (!SCRUB_HEADERS && !(info->bl_flags & BL_NO_BZIP2)) { - if (*l != l1) add_to_str(hdr, l, cast_uchar ", "); - add_to_str(hdr, l, cast_uchar "bzip2"); - } -#endif /* LZMA on DOS often fails with out of memory, don't announce it */ -#if defined(HAVE_LZMA) && !defined(DOS) - if (!SCRUB_HEADERS && !(info->bl_flags & BL_NO_BZIP2)) { - if (*l != l1) add_to_str(hdr, l, cast_uchar ", "); - add_to_str(hdr, l, cast_uchar "lzma, lzma2"); - } -#endif -#if defined(HAVE_LZIP) - if (!SCRUB_HEADERS && !(info->bl_flags & BL_NO_BZIP2)) { - if (*l != l1) add_to_str(hdr, l, cast_uchar ", "); - add_to_str(hdr, l, cast_uchar "lzip"); - } -#endif if (*l != l1) add_to_str(hdr, l, cast_uchar "\r\n"); else *l = orig_l; } @@ -945,7 +909,6 @@ static void http_got_header(struct connection *c, struct read_buffer *rb) abort_connection(c); return; } -#ifdef HAVE_SSL if (info->https_forward && h >= 200 && h < 300) { mem_free(head); mem_free(c->info); @@ -960,7 +923,6 @@ static void http_got_header(struct connection *c, struct read_buffer *rb) abort_connection(c); return; } -#endif if (h != 401 && h != 407) { unsigned char *cookie; unsigned char *ch = head; @@ -1053,12 +1015,10 @@ static void http_got_header(struct connection *c, struct read_buffer *rb) } mem_free(d); } -#ifdef HAVE_SSL if (c->ssl) { if (e->ssl_info) mem_free(e->ssl_info); e->ssl_info = get_cipher_string(c->ssl); } -#endif if (e->redirect) mem_free(e->redirect), e->redirect = NULL; if ((h == 302 || h == 303 || h == 307 || h == 511) && !e->expire_time) e->expire_time = 1; if (h == 301 || h == 302 || h == 303 || h == 307) { diff --git a/https.c b/https.c @@ -23,29 +23,18 @@ #define PATH_MAX 255 #endif -#ifdef HAVE_SSL #ifndef LINKS_CRT_FILE #define LINKS_CRT_FILE links.crt #endif -#ifdef HAVE_BUILTIN_SSL_CERTIFICATES -#include "certs.inc" -#define N_SSL_CONTEXTS 2 -#else #define N_SSL_CONTEXTS 1 -#endif static int ssl_initialized = 0; static SSL_CTX *contexts[N_SSL_CONTEXTS]; -#ifdef HAVE_CRYPTO_SET_MEM_FUNCTIONS_1 #define file_line_arg #define pass_file_line -#else -#define file_line_arg , const char *file, int line -#define pass_file_line , file, line -#endif #ifdef HAVE_CRYPTO_SET_MEM_FUNCTIONS @@ -55,14 +44,8 @@ static void *malloc_hook(size_t size file_line_arg) { void *p; in_ssl_malloc_hook++; -#if !defined(HAVE_OPENSSL_CLEANUP) || defined(HAVE_CRYPTO_SET_MEM_FUNCTIONS_1) if (!size) size = 1; do p = malloc(size); while (!p && out_of_memory(0, NULL, 0)); -#elif defined(LEAK_DEBUG) - p = debug_mem_alloc(cast_uchar file, line, size, 1); -#else - p = mem_alloc_mayfail(size); -#endif in_ssl_malloc_hook--; return p; } @@ -72,14 +55,8 @@ static void *realloc_hook(void *ptr, size_t size file_line_arg) void *p; if (!ptr) return malloc_hook(size pass_file_line); in_ssl_malloc_hook++; -#if !defined(HAVE_OPENSSL_CLEANUP) || defined(HAVE_CRYPTO_SET_MEM_FUNCTIONS_1) if (!size) size = 1; do p = realloc(ptr, size); while (!p && out_of_memory(0, NULL, 0)); -#elif defined(LEAK_DEBUG) - p = debug_mem_realloc(cast_uchar file, line, ptr, size, 1); -#else - p = mem_realloc_mayfail(ptr, size); -#endif in_ssl_malloc_hook--; return p; } @@ -87,148 +64,13 @@ static void *realloc_hook(void *ptr, size_t size file_line_arg) static void free_hook(void *ptr file_line_arg) { if (!ptr) return; -#if !defined(HAVE_OPENSSL_CLEANUP) || defined(HAVE_CRYPTO_SET_MEM_FUNCTIONS_1) free(ptr); -#elif defined(LEAK_DEBUG) - debug_mem_free(cast_uchar file, line, ptr); -#else - mem_free(ptr); -#endif } #endif -#if defined(HAVE_SSL_CERTIFICATES) && (defined(DOS) || defined(OS2) || defined(WIN) || defined(OPENVMS)) -static int ssl_set_private_paths(SSL_CTX *ctx) -{ - unsigned char *path, *c; - int r; -#ifdef OPENVMS - path = stracpy(g_argv[0]); -#else - path = stracpy(path_to_exe); -#endif - for (c = path + strlen(cast_const_char path); c > path; c--) { - if (dir_sep(c[-1]) -#ifdef OPENVMS - || c[-1] == ']' || c[-1] == ':' -#endif - ) - break; - } - c[0] = 0; - add_to_strn(&path, cast_uchar stringify(LINKS_CRT_FILE)); - r = SSL_CTX_load_verify_locations(ctx, cast_const_char path, NULL); - mem_free(path); - clear_ssl_errors(__LINE__); - if (r != 1) - return -1; - return 0; -} -#else #define ssl_set_private_paths(c) (-1) -#endif -#ifdef HAVE_BUILTIN_SSL_CERTIFICATES -static void ssl_load_private_certificates(SSL_CTX *ctx) -{ - int i; - int errs = 0; - int succeeded = 0; - int total_certificates = (int)array_elements(certificates); - X509_STORE *store = SSL_CTX_get_cert_store(ctx); - if (!store) - errs |= 1; - else for (i = 0; i < total_certificates; i++) { - BIO *bio; - X509 *cert; - unsigned char *data = cast_uchar certificates[i].data; - int len = certificates[i].len; - unsigned char *b64; - if (data[len]) - internal("invalid builtin certificate %u", i); -#if 1 - b64 = base64_encode(data, len, cast_uchar "-----BEGIN CERTIFICATE-----\n", cast_uchar "-----END CERTIFICATE-----", 6); - bio = BIO_new_mem_buf(b64, (int)strlen(cast_const_char b64)); -#else - { - static_const unsigned char base64_chars[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - int l, x; - int col = 0; - b64 = init_str(); - l = 0; - add_to_str(&b64, &l, cast_uchar "-----BEGIN CERTIFICATE-----\n"); - for (x = 0; x < len; x += 3) { - unsigned char out[4]; - out[0] = base64_chars[data[x] >> 2]; - out[1] = base64_chars[((data[x] << 4) & 63) | (data[x + 1] >> 4)]; - if (x + 1 < len) - out[2] = base64_chars[((data[x + 1] << 2) & 63) | (data[x + 2] >> 6)]; - else - out[2] = '='; - if (x + 2 < len) - out[3] = base64_chars[data[x + 2] & 63]; - else - out[3] = '='; - add_bytes_to_str(&b64, &l, out, 4); - if (!((col += 4) & 63)) - add_chr_to_str(&b64, &l, '\n'); - } - if (b64[l - 1] != '\n') - add_chr_to_str(&b64, &l, '\n'); - add_to_str(&b64, &l, cast_uchar "-----END CERTIFICATE-----"); - bio = BIO_new_mem_buf(b64, l); - } -#endif - /*fprintf(stderr, "%s\n", b64);*/ - if (!bio) { - errs |= 2; - mem_free(b64); - continue; - } - cert = PEM_read_bio_X509(bio, NULL, 0, NULL); - if (cert) { - if (!X509_STORE_add_cert(store, cert)) { - errs |= 8; - } else { - succeeded++; - } - X509_free(cert); - } else { - errs |= 4; - } - mem_free(b64); - BIO_free(bio); - clear_ssl_errors(__LINE__); - } - if (errs) { - static_const char * const err_strings[4] = { "SSL_CTX_get_cert_store", "BIO_new_mem_buf", "PEM_read_bio_X509", "X509_STORE_add_cert" }; - struct session *ses; - unsigned char *err_str = init_str(); - int err_strl = 0; - unsigned char *numfail_str = init_str(); - int numfail_strl = 0; - int e; - ses = get_download_ses(NULL); - for (e = 0; e < 4; e++) { - if (errs & (1 << e)) { - if (err_strl) add_to_str(&err_str, &err_strl, cast_uchar ", "); - add_to_str(&err_str, &err_strl, cast_uchar err_strings[e]); - } - } - add_num_to_str(&numfail_str, &numfail_strl, total_certificates - succeeded); - add_chr_to_str(&numfail_str, &numfail_strl, '/'); - add_num_to_str(&numfail_str, &numfail_strl, total_certificates); - if (!ses) { - error("error initializing built-in certificates: %s, failed %s", err_str, numfail_str); - mem_free(err_str); - mem_free(numfail_str); - } else { - msg_box(ses->term, getml(err_str, numfail_str, NULL), TEXT_(T_SSL_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT_(T_ERROR_INITIALIZING_BUILT_IN_CERTIFICATES), ": ", err_str, ", ", TEXT_(T_FAILED), " ", numfail_str, NULL, NULL, 1, TEXT_(T_CANCEL), NULL, B_ENTER | B_ESC); - } - } -} -#endif int ssl_asked_for_password; @@ -263,7 +105,6 @@ links_ssl *getSSL(void) } #endif -#if defined(HAVE_RAND_ADD) { unsigned char *os_pool; int os_pool_size; @@ -271,23 +112,12 @@ links_ssl *getSSL(void) if (os_pool_size) RAND_add(os_pool, os_pool_size, os_pool_size); mem_free(os_pool); } -#endif -#if defined(HAVE_OPENSSL_INIT_SSL) OPENSSL_init_ssl(0, NULL); -#elif defined(OpenSSL_add_ssl_algorithms) - OpenSSL_add_ssl_algorithms(); -#else - SSLeay_add_ssl_algorithms(); -#endif ssl_initialized = 1; } idx = 0; -#ifdef HAVE_BUILTIN_SSL_CERTIFICATES - if (ssl_options.built_in_certificates || proxies.only_proxies) - idx = 1; -#endif if (!contexts[idx]) { SSL_CTX *ctx; const SSL_METHOD *m; @@ -318,9 +148,6 @@ links_ssl *getSSL(void) if (ssl_set_private_paths(ctx)) SSL_CTX_set_default_verify_paths(ctx); } else { -#ifdef HAVE_BUILTIN_SSL_CERTIFICATES - ssl_load_private_certificates(ctx); -#endif } SSL_CTX_set_default_passwd_cb(ctx, ssl_password_callback); } @@ -383,174 +210,19 @@ void https_func(struct connection *c) #ifdef HAVE_SSL_CERTIFICATES -#if !(defined(HAVE_X509_CHECK_HOST) && defined(HAVE_X509_CHECK_IP)) - -static int check_host_name(const unsigned char *templ, const unsigned char *host) -{ - int templ_len = (int)strlen(cast_const_char templ); - int host_len = (int)strlen(cast_const_char host); - unsigned char *wildcard; - - if (templ_len > 0 && templ[templ_len - 1] == '.') templ_len--; - if (host_len > 0 && host[host_len - 1] == '.') host_len--; - - wildcard = memchr(templ, '*', templ_len); - if (!wildcard) { - if (templ_len == host_len && !casecmp(templ, host, templ_len)) - return 0; - return -1; - } else { - int prefix_len, suffix_len; - if (templ_len > host_len) - return -1; - prefix_len = (int)(wildcard - templ); - suffix_len = (int)(templ + templ_len - (wildcard + 1)); - if (memchr(templ, '.', prefix_len)) - return -1; - if (memchr(wildcard + 1, '*', suffix_len)) - return -1; - if (casecmp(host, templ, prefix_len)) - return -1; - if (memchr(host + prefix_len, '.', host_len - prefix_len - suffix_len)) - return -1; - if (casecmp(host + host_len - suffix_len, wildcard + 1, suffix_len)) - return -1; - return 0; - } -} - -#ifdef HAVE_ASN1_STRING_GET0_DATA -#define asn_string_data ASN1_STRING_get0_data -#else -#define asn_string_data ASN1_STRING_data -#endif - -/* - * This function is based on verifyhost in libcurl - I hope that it is correct. - */ -static int verify_ssl_host_name(X509 *server_cert, unsigned char *host) -{ - unsigned char ipv4_address[4]; -#ifdef SUPPORT_IPV6 - unsigned char ipv6_address[16]; -#endif - unsigned char *address = NULL; - int address_len = 0; - int type = GEN_DNS; - - STACK_OF(GENERAL_NAME) *altnames; - - if (!numeric_ip_address(host, ipv4_address)) { - address = ipv4_address; - address_len = 4; - type = GEN_IPADD; - } -#ifdef SUPPORT_IPV6 - if (!numeric_ipv6_address(host, ipv6_address, NULL)) { - address = ipv6_address; - address_len = 16; - type = GEN_IPADD; - } -#endif - -#if 1 - altnames = X509_get_ext_d2i(server_cert, NID_subject_alt_name, NULL, NULL); - if (altnames) { - int retval = 1; - int i; - int n_altnames = sk_GENERAL_NAME_num(altnames); - for (i = 0; i < n_altnames; i++) { - const GENERAL_NAME *altname = sk_GENERAL_NAME_value(altnames, i); - const unsigned char *altname_ptr; - int altname_len; - if (altname->type != type) { - if (altname->type == GEN_IPADD || altname->type == GEN_DNS || altname->type == GEN_URI) - retval = S_INVALID_CERTIFICATE; - continue; - } - altname_ptr = asn_string_data(altname->d.ia5); - altname_len = ASN1_STRING_length(altname->d.ia5); - if (type == GEN_IPADD) { - if (altname_len == address_len && !memcmp(altname_ptr, address, address_len)) { - retval = 0; - break; - } - } else { - if (altname_len == (int)strlen(cast_const_char altname_ptr) && !check_host_name(altname_ptr, host)) { - retval = 0; - break; - } - } - retval = S_INVALID_CERTIFICATE; - } - GENERAL_NAMES_free(altnames); - if (retval != 1) - return retval; - } -#endif - - { - unsigned char *nulstr = cast_uchar ""; - unsigned char *peer_CN = nulstr; - X509_NAME *name; - int j, i = -1; - - retval = 1; - - name = X509_get_subject_name(server_cert); - if (name) - while ((j = X509_NAME_get_index_by_NID(name, NID_commonName, i)) >= 0) - i = j; - if (i >= 0) { - ASN1_STRING *tmp = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i)); - if (tmp) { - if (ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) { - j = ASN1_STRING_length(tmp); - if (j >= 0) { - peer_CN = OPENSSL_malloc(j + 1); - if (peer_CN) { - memcpy(peer_CN, asn_string_data(tmp), j); - peer_CN[j] = '\0'; - } - } - } else { - j = ASN1_STRING_to_UTF8(&peer_CN, tmp); - } - if (peer_CN && (int)strlen(cast_const_char peer_CN) != j) { - retval = S_INVALID_CERTIFICATE; - } - } - } - if (peer_CN && peer_CN != nulstr) { - if (retval == 1 && !check_host_name(peer_CN, host)) - retval = 0; - OPENSSL_free(peer_CN); - } - if (retval != 1) - return retval; - } - - return S_INVALID_CERTIFICATE; -} - -#else static int verify_ssl_host_name(X509 *server_cert, unsigned char *host) { int v; unsigned char ipv4_address[4]; -#ifdef SUPPORT_IPV6 unsigned char ipv6_address[16]; -#endif if (!numeric_ip_address(host, ipv4_address)) { v = X509_check_ip(server_cert, ipv4_address, 4, 0); } -#ifdef SUPPORT_IPV6 else if (!numeric_ipv6_address(host, ipv6_address, NULL)) { v = X509_check_ip(server_cert, ipv6_address, 16, 0); } -#endif else { v = X509_check_host(server_cert, cast_const_char host, strlen(cast_const_char host), 0, NULL); } @@ -558,7 +230,6 @@ static int verify_ssl_host_name(X509 *server_cert, unsigned char *host) return v == 1 ? 0 : S_INVALID_CERTIFICATE; } -#endif int verify_ssl_certificate(links_ssl *ssl, unsigned char *host) { @@ -640,11 +311,6 @@ unsigned char *get_cipher_string(links_ssl *ssl) add_chr_to_str(&s, &l, ' '); add_to_str(&s, &l, cipher); } -#if defined(SSL_SESSION_RESUME) && 0 - if (SSL_session_reused(ssl->ssl)) { - add_to_str(&s, &l, cast_uchar " (reused session)"); - } -#endif return s; } @@ -783,12 +449,3 @@ void init_session_cache(void) #endif -#else - -void https_func(struct connection *c) -{ - setcstate(c, S_NO_SSL); - abort_connection(c); -} - -#endif diff --git a/img.c b/img.c @@ -47,19 +47,6 @@ static void destroy_decoder (struct cached_image *cimg) case IM_GIF: gif_destroy_decoder(cimg); break; - case IM_XBM: - /* do nothing */ - break; -#ifdef HAVE_TIFF - case IM_TIFF: - tiff_destroy_decoder(cimg); - break; -#endif -#ifdef HAVE_SVG - case IM_SVG: - svg_destroy_decoder(cimg); - break; -#endif } mem_free(cimg->decoder); } @@ -289,13 +276,6 @@ int header_dimensions_known(struct cached_image *cimg) cimg->yww = cimg->height; } -#ifdef HAVE_SVG - if (cimg->image_type == IM_SVG) { - /* SVG images are scaled using the cairo library, not the Links scaler */ - cimg->width = cimg->xww; - cimg->height = cimg->yww; - } -#endif if (cimg->width!=cimg->xww||cimg->height!=cimg->yww) cimg->strip_optimized=0; cimg->gamma_stamp=gamma_stamp; @@ -803,16 +783,6 @@ static void type(struct cached_image *cimg, unsigned char *content_type, unsigne if (data[0] == 0xff && data[1] == 0xd8) goto have_jpeg; #endif -#ifdef HAVE_TIFF - if (data[0] == 'I' && data[1] == 'I') - goto have_tiff; - if (data[0] == 'M' && data[1] == 'M') - goto have_tiff; -#endif -#ifdef HAVE_SVG - if (data[0] == '<' && data[1] == '?') - goto have_svg; -#endif if (data[0] == 0x89 && data[1] == 'P' && data[2] == 'N' && data[3] == 'G') goto have_png; if (data[0] == 'G' && data[1] == 'I' && data[2] == 'F') @@ -838,26 +808,7 @@ static void type(struct cached_image *cimg, unsigned char *content_type, unsigne have_gif: cimg->image_type=IM_GIF; gif_start(cimg); - } else if (dtest(cast_uchar "image/x-xbitmap",content_type)){ - cimg->image_type=IM_XBM; - xbm_start(cimg); - } else -#ifdef HAVE_TIFF - if (dtest(cast_uchar "image/tiff",content_type) || - dtest(cast_uchar "image/tif",content_type)) { - have_tiff: - cimg->image_type=IM_TIFF; - tiff_start(cimg); - } else -#endif /* #ifdef HAVE_TIFF */ -#ifdef HAVE_SVG - if (dtest(cast_uchar "image/svg+xml",content_type) || - dtest(cast_uchar "image/svg",content_type)) { - have_svg: - cimg->image_type=IM_SVG; - svg_start(cimg); } else -#endif /* #ifdef HAVE_SVG */ { /* Error */ img_end(cimg); @@ -938,22 +889,9 @@ static int img_process_download(struct g_object_image *goi, struct f_data_c *fda jpeg_restart(cimg,data,length); break; #endif /* #ifdef HAVE_JPEG */ - case IM_XBM: - xbm_restart(cimg,data,length); - break; case IM_GIF: gif_restart(data,length); break; -#ifdef HAVE_TIFF - case IM_TIFF: - tiff_restart(cimg,data,length); - break; -#endif /* #ifdef HAVE_TIFF */ -#ifdef HAVE_SVG - case IM_SVG: - svg_restart(cimg,data,length); - break; -#endif /* #ifdef HAVE_SVG */ #ifdef DEBUG default: fprintf(stderr,"cimg->image_type=%d\n",cimg->state); @@ -973,14 +911,6 @@ img_process_download.\n"); */ if (!chopped){ if (!((cimg->state^8)&9)) { -#ifdef HAVE_TIFF - if (cimg->image_type==IM_TIFF) - tiff_finish(cimg); -#endif -#ifdef HAVE_SVG - if (cimg->image_type==IM_SVG) - svg_finish(cimg); -#endif } cimg->eof_hit=1; if (goi->af->rq->ce) @@ -1319,29 +1249,6 @@ next_chunk: return image; } -#ifdef JS - -void change_image (struct g_object_image *goi, unsigned char *url, unsigned char *src, struct f_data *fdata) -{ - /*struct cached_image *cimg;*/ - - global_goi = goi; - mem_free(goi->src); - goi->src = stracpy(url); - if (goi->orig_src) mem_free(goi->orig_src); - goi->orig_src = stracpy(src); - if (!(goi->goti.go.xw && goi->goti.go.yw)) return; - goi->cimg->refcount--; - goi->af = request_additional_file(fdata,url); - goi->af->need_reparse = -1; - - find_or_make_cached_image(goi, url, fdata->opt.image_scale); - /* Automatically sets up global_cimg */ - - refresh_image(fdata->fd, &goi->goti.go, 0); -} - -#endif #endif @@ -1360,14 +1267,6 @@ int known_image_type(unsigned char *type) if (!casestrcmp(type, cast_uchar "image/pjpeg")) return 1; if (!casestrcmp(type, cast_uchar "image/pjpg")) return 1; #endif -#ifdef HAVE_TIFF - if (!casestrcmp(type, cast_uchar "image/tiff")) return 1; - if (!casestrcmp(type, cast_uchar "image/tif")) return 1; -#endif -#ifdef HAVE_SVG - if (!casestrcmp(type, cast_uchar "image/svg+xml")) return 1; - if (!casestrcmp(type, cast_uchar "image/svg")) return 1; -#endif #endif return 0; } diff --git a/install-sh b/install-sh @@ -1,251 +0,0 @@ -#!/bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5 (mit/util/scripts/install.sh). -# -# Copyright 1991 by the Massachusetts Institute of Technology -# -# Permission to use, copy, modify, distribute, and sell this software and its -# documentation for any purpose is hereby granted without fee, provided that -# the above copyright notice appear in all copies and that both that -# copyright notice and this permission notice appear in supporting -# documentation, and that the name of M.I.T. not be used in advertising or -# publicity pertaining to distribution of the software without specific, -# written prior permission. M.I.T. makes no representations about the -# suitability of this software for any purpose. It is provided "as is" -# without express or implied warranty. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. It can only install one file at a time, a restriction -# shared with many OS's install programs. - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - chmodcmd="" - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 diff --git a/jsint.c b/jsint.c @@ -32,3865 +32,6 @@ #include "links.h" -#ifdef JS - -tcount jsint_execute_seq = 0; - -#include "struct.h" -#include "ipret.h" -#include "builtin_keys.h" - -/* -vypisuje to: jaky kod byl zarazen do fronty. jaky kod byl predan interpretu do js_execute_code. jaky kod byl vykonan a ukoncen intepretem jsint_done_execution -#define TRACE_EXECUTE -*/ - -struct js_request { - list_entry_1st - int onclick_submit; /* >=0 (znamena cislo formulare) pokud tohle je request onclick handleru u submit tlacitka nebo onsubmit handleru */ - int onsubmit; /* dtto pro submit handler */ - struct links_event ev; /* event, ktery se ma poslat pri uspechu */ - int write_pos; /* document.write position from END of document. -1 if document.write cannot be used */ - int wrote; /* this request called document.write */ - int len; - tcount seq; - list_entry_last - unsigned char code[1]; -}; - - -/* set_cookies bude parsovat takhle: - * +....=............;...............................+ <- tohle je strinzik - * ^ ^ - * najdu 1. rovnase a za nim 1. strednik, najdu nasledujici rovnase a - * nasledujici strednik, pokud to bude platne (&'='<&';') a 2. jmeno bude - * "expires", tak to je furt jedna cookie -> poslu Mikulasovi. - * - * kdyz ne, tak je to jina susenka a poslu to 1. Mikulasovi - * - * pokud najdu ';' a za nim whitespace, za kterym neni rovnase, tak od toho - * stredniku je to garbaz, kterou vratim do strinziku (fd->js->ctx->cookies) - */ - -/* sets all cookies in fd>js->ctx->cookies */ -/* final_flush means, that set_cookies was called from jsint_done_execution */ - - - - - - -/* JESTLI V TYHLE FUNKCI BUDE NEJAKA BUGA, tak za to muze PerM, Clock a pan GNU, - * ktery tady kolem rusili, ze jsem se nemohl soustredit. Takze se s - * pripadnejma reklamacema obratte na ne! - * - * Brain - */ - -/* prototypes */ -static void jsint_send_event(struct f_data_c *fd, struct links_event *ev); -static int jsint_create(struct f_data_c *); -static void jsint_done_execution(void *); -static int jsint_can_access(struct f_data_c *, struct f_data_c *); -static struct f_data_c *jsint_find_recursive(struct f_data_c *, long); /* line 89 */ -static void *jsint_find_object(struct f_data_c *, long); -static long *add_id(long *, int *, long ); -static long *add_fd_id(long *, int *, long, long, unsigned char *); -static void send_vodevri_v_novym_vokne(struct terminal *, int (*)(struct terminal *, unsigned char *, unsigned char *), struct session *); -static void add_all_recursive_in_fd(long **, int *, struct f_data_c *, struct f_data_c *); - - -void jsint_set_cookies(struct f_data_c *fd, int final_flush) -{ - unsigned char *str; - unsigned char *next; - unsigned char *eq1, *semic1, *eq2, *semic2; - - if(!(fd->js)||!(fd->js->ctx))internal("jsint_set_cookies called with NULL context.\n"); - if (!(fd->js->ctx->cookies)||!(fd->rq))return; /* cookies string is empty, nothing to set */ - str=fd->js->ctx->cookies; - -a_znova: - eq1=strchr(str,'='); - semic1=strchr(str,';'); - - if (!*str||(!final_flush&&!semic1)) /* na konci neni strednik a skript jeste bezi, takze to musime vratit do stringu a vypadnout */ - { - unsigned char *bla=NULL; - if (*str)bla=stracpy1(str); - js_mem_free(fd->js->ctx->cookies); - fd->js->ctx->cookies=bla; - return; - } - - /* ted se v str bud vyskytuje strednik, nebo skript uz skoncil */ - - if (semic1&&eq1>semic1) /* '=' je za ';' takze to pred strednikem a strednik skipnem */ - { - str=semic1+1; - goto a_znova; - } - - next=semic1?semic1+1:str+strlen(cast_const_char str); - if (!eq1) /* neni tam '=', takze to preskocime */ - { - str=next; - goto a_znova; - } - - /* ted by to mela bejt regulerni susenka */ - - next_par: - eq2=NULL,semic2=NULL; - if (semic1!=NULL) - { - eq2=strchr(semic1+1,'='); - semic2=strchr(semic1+1,';'); - } - - if (eq2&&semic1&&(final_flush||semic2)) - { - unsigned char *p=strstr(semic1+1,"expires"); - if (!p)p=strstr(semic1+1,"Expires"); - if (!p)p=strstr(semic1+1,"EXPIRES"); - if (!p)p=strstr(semic1+1,"domain"); - if (!p)p=strstr(semic1+1,"Domain"); - if (!p)p=strstr(semic1+1,"DOMAIN"); - if (!p)p=strstr(semic1+1,"path"); - if (!p)p=strstr(semic1+1,"Path"); - if (!p)p=strstr(semic1+1,"PATH"); - if (!p)p=strstr(semic1+1,"comment"); - if (!p)p=strstr(semic1+1,"Comment"); - if (!p)p=strstr(semic1+1,"COMMENT"); - if (!p)p=strstr(semic1+1,"max-age"); - if (!p)p=strstr(semic1+1,"Max-age"); - if (!p)p=strstr(semic1+1,"Max-Age"); - if (!p)p=strstr(semic1+1,"MAX-AGE"); - if (!p)p=strstr(semic1+1,"version"); - if (!p)p=strstr(semic1+1,"Version"); - if (!p)p=strstr(semic1+1,"VERSION"); - if (p&&p>semic1&&p<eq2) /* za 1. prirazenim nasleduje "expires=", takze to je porad jedna susenka */ - { - next=semic2?semic2+1:str+strlen(cast_const_char str); - semic1=semic2; - goto next_par; - } - } - - if (*next)next[-1]=0; - - for (;*str&&WHITECHAR(*str);str++); /* skip whitechars */ - - /*debug("set_cookie: \"%s\"", str);*/ - set_cookie(fd->ses->term, fd->rq->url, str); - - str=next; - goto a_znova; -} - - -int jsint_object_type(long to_je_on_Padre) -{ - return to_je_on_Padre&JS_OBJ_MASK; -} - - -static int jsint_create(struct f_data_c *fd) -{ - struct js_state *js; - - if (fd->js) internal("javascript state present"); - js = mem_calloc(sizeof(struct js_state)); - if (!(js->ctx = js_create_context(fd, ((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT))) { - mem_free(js); - return 1; - } - init_list(js->queue); - fd->js = js; - return 0; -} - -void jsint_destroy(struct f_data_c *fd) -{ - struct js_state *js = fd->js; - fd->script_t = 0; - if (!js) return; - fd->js = NULL; - pr(js_destroy_context(js->ctx)) return; - if (js->src) mem_free(js->src); - if (js->active) mem_free(js->active); - js_zaflaknuto_pameti -= js->newdata; - free_list(struct js_request, js->queue); - mem_free(js); -} - -/* for <a href="javascript:..."> */ -void javascript_func(struct session *ses, unsigned char *hlavne_ze_je_vecirek) -{ - unsigned char *code=get_url_data(hlavne_ze_je_vecirek); - - jsint_execute_code(current_frame(ses),code,strlen(cast_const_char code),-1,-1,-1, NULL); -} - -static void jsint_send_event(struct f_data_c *fd, struct links_event *ev) -{ - if (!ev || !ev->b) return; - send_event(fd->ses, ev); -} - -/* executes or queues javascript code in frame: - write_pos is number of bytes from the position where document.write should write to the end of document - write_pos == -1 if it is not from <SCRIPT> statement and cannot use document.write -*/ -/* data je cislo formulare pro onclick submit handler, jinak se nepouziva */ -/* ev je udalost, ktera se ma znovu poslat, pokud bylo vraceno true */ -void jsint_execute_code(struct f_data_c *fd, unsigned char *code, int len, int write_pos, int onclick_submit, int onsubmit, struct links_event *ev) -{ - struct js_request *r, *q; - struct list_head *lq; - - for (;code&&len&&*code&&((*code)==' '||(*code)==9||(*code)==13||(*code)==10);code++,len--); - - /* - FUJ !!!! - if (!casecmp(code, cast_uchar "javascript:",strlen(cast_const_char "javascript:")))code+=strlen(cast_const_char "javascript:"); - */ - - if (len >= 11 && !casecmp(code, "javascript:", 11)) code += 11, len -= 11; - - if (!js_enable) { - jsint_send_event(fd, ev); - return; - } - -#ifdef TRACE_EXECUTE - fprintf(stderr, "Submitted: ^^%.*s^^\n", len, code); -#endif - - if (!fd->js && jsint_create(fd)) { - jsint_send_event(fd, ev); - return; - } - if ((unsigned)len > MAXINT - sizeof(struct js_request)) overalloc(); - r = mem_calloc(sizeof(struct js_request) + len); - r->seq = jsint_execute_seq++; - r->write_pos = write_pos; - r->len = len; - r->onclick_submit = onclick_submit; - r->onsubmit = onsubmit; - memcpy(r->code, code, len); - if (ev) memcpy(&r->ev, ev, sizeof(struct links_event)); - if (write_pos == -1) { - add_to_list_end(fd->js->queue, r); - } else { - /* add it beyond all <SCRIPT> requests but before non-<SCRIPT> ones */ - foreach(struct js_request, q, lq, fd->js->queue) if (q->write_pos == -1) break; - add_before_list_entry(lq, &r->list_entry); - } - jsint_run_queue(fd); -} - -static void jsint_done_execution(void *fd_) -{ - struct f_data_c *fd = (struct f_data_c *)fd_; - struct js_request *r, *to_exec; - struct list_head *lr; - struct js_state *js = fd->js; - struct links_event ev = { 0, 0, 0, 0 }; - if (!js) { - internal("no js in frame"); - return; - } - if (!js->active) { - internal("jsint_done_execution: completion function called on inactive js"); - return; - } - -#ifdef TRACE_EXECUTE - fprintf(stderr, "Done: ^^%.*s^^\n", js->active->len, js->active->code); -#endif - - /* accept all cookies set by the script */ - jsint_set_cookies(fd,1); - - /* js->active obsahuje request prave dobehnuteho skriptu */ - - /* dobehl onclick_handler a nezaplatil (vratil false), budou se dit veci */ - if (js->active->ev.b && js->ctx->zaplatim) - memcpy(&ev, &js->active->ev, sizeof(struct links_event)); - if (js->active->onclick_submit >=0 && !js->ctx->zaplatim) - { - /* pokud je handler od stejneho formulare, jako je defered, tak odlozeny skok znicime a zlikvidujem prislusny onsubmit handler z fronty */ - if (js->active->onclick_submit == fd->ses->defered_data) - { - foreach(struct js_request, r, lr,js->queue) - /* to je onsubmit od naseho formulare, tak ho smazem */ - if (r->onsubmit == js->active->onclick_submit) - { - del_from_list(r); - mem_free(r); - break; /* zadny dalsi onsubmit tohoto formulare uz nebude */ - } - ses_destroy_defered_jump(fd->ses); - } - } - - if (js->active->write_pos == -1) mem_free(js->active), js->active = NULL; - else { - r = js->active; js->active = NULL; - if (r->wrote) js->wrote = 1; - jsint_scan_script_tags(fd); - if (!f_is_finished(fd->f_data)) { - fd->done = 0; - fd->parsed_done = 0; - } - if (js->wrote && fd->script_t == -1) { - fd->done = 0; - fd->parsed_done = 0; - fd_loaded(NULL, fd); - js->wrote = 0; - } - mem_free(r); - } - - to_exec = js->active; - if (!to_exec && !list_empty(fd->js->queue)) to_exec = list_struct(fd->js->queue.next, struct js_request); - if (fd->ses->defered_url && (!to_exec || (to_exec->seq > fd->ses->defered_seq && to_exec->write_pos == -1))) - { - unsigned char *url, *target; - - url=stracpy(fd->ses->defered_url); - target=stracpy(fd->ses->defered_url); - - goto_url_f(fd->ses,NULL,url,target,fd->ses->defered_target_base,fd->ses->defered_data,0,0,0); - mem_free(url); - mem_free(target); - } - else - jsint_run_queue(fd); - jsint_send_event(fd, &ev); -} - -void jsint_run_queue(struct f_data_c *fd) -{ - struct js_request *r; - struct js_state *js = fd->js; - - if ((!fd->done && fd->f_data) || !js || js->active || list_empty(js->queue)) return; - - r = list_struct(js->queue.next, struct js_request); - del_from_list(r); - js->active = r; -#ifdef TRACE_EXECUTE - fprintf(stderr, "Executing: ^^%.*s^^\n", r->len, r->code); - -#endif - pr(js_execute_code(js->ctx, r->code, r->len, jsint_done_execution)) {}; -} - -/* returns: 1 - source is modified by document.write - 0 - original source -*/ - -int jsint_get_source(struct f_data_c *fd, unsigned char **start, unsigned char **end) -{ - struct js_state *js = fd->js; - - if (!js || !js->src) return 0; - if (start) *start = js->src; - if (end) *end = js->src + js->srclen; - return 1; -} - -/* - * tests if script running in frame "running" can access document in frame "accessed" - * 0=no permission, 1=permission OK - */ -static int jsint_can_access(struct f_data_c *running, struct f_data_c *accessed) -{ - int a; - unsigned char *h1, *h2; - if (!running || !accessed || !running->rq || !accessed->rq) return 0; - - h1 = get_host_name(running->rq->url); - h2 = get_host_name(accessed->rq->url); - a = !casestrcmp(h1, h2); - mem_free(h1); - mem_free(h2); - return a; -} - - -/* doc_id is real document id, whithout any type */ -/* fd must be a valid pointer */ -static struct f_data_c *jsint_find_recursive(struct f_data_c *fd, long doc_id) -{ - struct f_data_c *sub, *fdd; - struct list_head *lsub; - if (fd->id == doc_id) return fd; - foreach(struct f_data_c, sub, lsub, fd->subframes) { - if ((fdd = jsint_find_recursive(sub, doc_id))) return fdd; - } - return NULL; -} - -/* - * This function finds document that has given ID - */ -struct f_data_c *jsint_find_document(long doc_id) -{ - struct f_data_c *fd; - struct session *ses; - struct list_head *lses; - int type=jsint_object_type(doc_id); - - if (type!=JS_OBJ_T_DOCUMENT&&type!=JS_OBJ_T_FRAME) - {unsigned char txt[256]; snprintf(txt,256,"jsint_find_document called with type=%d\n",type);internal(txt);} - doc_id>>=JS_OBJ_MASK_SIZE; - foreach(struct session, ses, lses, sessions) if ((fd = jsint_find_recursive(ses->screen, doc_id))) return fd; - return NULL; -} - -/* Document has just loaded. Scan for <SCRIPT> tags and execute each of them */ - -void jsint_scan_script_tags(struct f_data_c *fd) -{ - unsigned char *name, *attr; - int namelen; - unsigned char *val, *e, *ee; - unsigned char *s, *ss, *eof; - unsigned char *start, *end; - unsigned char *onload_code=NULL; - int uv; - int bs; - - if (!js_enable)return; - if (!fd->rq || !fd->rq->ce || !fd->f_data) return; - if (!jsint_get_source(fd, &ss, &eof)) { - if (get_file(fd->rq, &ss, &eof)) return; - } - - d_opt = &fd->f_data->opt; - - s = ss; - se: - while (s < eof && *s != '<') sp:s++; - if (s >= eof || fd->script_t < 0) - { - if (onload_code && fd->script_t != -1) - { - jsint_execute_code(fd,onload_code,strlen(cast_const_char onload_code),-1,-1,-1, NULL); - } - fd->script_t = -1; - goto ret; - } - if (s + 2 <= eof && (s[1] == '!' || s[1] == '?')) { - s = skip_comment(s, eof); - goto se; - } - if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp; - if (!onload_code&&namelen==4&&!casecmp(name,"BODY",4)) - { - onload_code=get_attr_val(attr,"onload"); /* if the element doesn't have onload attribute get_attr_val returns NULL */ - goto se; - } - - if (!onload_code&&namelen==3&&!casecmp(name,"IMG",3)) - { - onload_code=get_attr_val(attr,"onload"); /* if the element doesn't have onload attribute get_attr_val returns NULL */ - goto se; - } - - if (namelen != 6 || casecmp(name, "SCRIPT", 6) || s - ss < fd->script_t) goto se; - start = end = NULL; - if ((val = get_attr_val(attr, "src"))) { - unsigned char *url; - if (fd->f_data->script_href_base && ((url = join_urls(fd->f_data->script_href_base, val)))) { - int code, version; - struct additional_file *af = request_additional_file(fd->f_data, url); - mem_free(url); - mem_free(val); - if (!af || !af->rq) goto se; - if (af->rq->state >= 0) goto ret; - if (!af->rq->ce) goto se; - if (!get_http_code(af->rq->ce->head, &code, &version)) { - if (code < 200 || code >= 300) goto se; - } - if (get_file(af->rq, &start, &end)) goto se; - if (start == end) goto se; - } else { - mem_free(val); - goto se; - } - } - e = s; - uv = 0; - bs = 0; - while (e < eof && *e != '<') { - es: - if (!uv && (*e == '"' || *e == '\'')) uv = *e, bs = 0; - else if (*e == '\\' && uv) bs = 1; - else if (*e == uv && !bs) uv = 0; - else bs = 0; - e++; - } - if (e + 8 <= eof) { - if (/*uv ||*/ casecmp(e, "</SCRIPT", 8)) goto es; - } else e = eof; - ee = e; - while (ee < eof && *ee != '>') ee++; - if (ee < eof) ee++; - fd->script_t = ee - ss; - if (!start || !end) jsint_execute_code(fd, s, e - s, eof - ee,-1,-1, NULL); - else jsint_execute_code(fd, start, end - start, eof - ee,-1,-1, NULL); - ret: - if (onload_code)mem_free(onload_code); - - d_opt = &dd_opt; -} - - -struct hopla_mladej -{ - struct form_control *fc; - struct form_state *fs; -}; - - -/* Returns pointer to the object with given ID in the document, or NULL when - * there's no such object. Document must be a valid pointer. - * - * Pointer type depends on type of object, caller must know the type and - * interpret the pointer in the right way. - */ - -static void *jsint_find_object(struct f_data_c *document, long obj_id) -{ - int type=obj_id&JS_OBJ_MASK; - int orig_obj_id=obj_id; - obj_id>>=JS_OBJ_MASK_SIZE; - - switch (type) - { - /* form element - * obj_id can be from 0 up to number of form fields - * (document->vs->form_info_len may be actually lower if the fields were never - * touched) - * returns allocated struct hopla_mladej, you must free it after use - */ - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - case JS_OBJ_T_CHECKBOX: - case JS_OBJ_T_RADIO: - case JS_OBJ_T_SELECT: - case JS_OBJ_T_SUBMIT: - case JS_OBJ_T_RESET: - case JS_OBJ_T_HIDDEN: - case JS_OBJ_T_BUTTON: - { - struct hopla_mladej *hopla; - - struct form_control *fc; - struct list_head *lfc; - int a=0; - - if (obj_id<0/*||obj_id>=n*/)return NULL; - hopla=mem_alloc(sizeof(struct hopla_mladej)); - - if (!(document->f_data)){mem_free(hopla);return NULL;}; - - foreachback(struct form_control, fc, lfc, document->f_data->forms) - if (fc->g_ctrl_num==obj_id){a=1;break;} - if (!a){mem_free(hopla);return NULL;} - - hopla->fs=find_form_state(document, fc); - hopla->fc=fc; - return hopla; - } - - /* link - * obj_id can be from 0 to (nlinks-1) - */ - case JS_OBJ_T_LINK: - { - struct link*l; - int n; - - if (!(document->f_data))return NULL; - - l=document->f_data->links; - n=document->f_data->nlinks; - - if (obj_id<0||obj_id>=n)return NULL; - return l+obj_id; - } - - /* form - * obj_id is form_num in struct form_control (f_data->forms) - */ - case JS_OBJ_T_FORM: - { - struct form_control *f; - struct list_head *lf; - - if (!(document->f_data))return NULL; - foreachback(struct form_control, f, lf, document->f_data->forms) if ((f->form_num)==obj_id)return f; - return NULL; - } - - /* anchors - * obj_id is position in list of all tags - */ - case JS_OBJ_T_ANCHOR: - { - struct tag *t; - struct list_head *lt; - int a=0; - - if (!(document->f_data))return NULL; - foreach(struct tag, t, lt, document->f_data->tags) - { - if (obj_id==a)return t; - a++; - } - return NULL; - } - break; - - /* this is document - * call jsint_find_document - * returned value is struct f_data_c - */ - case JS_OBJ_T_FRAME: - case JS_OBJ_T_DOCUMENT: - return jsint_find_document(orig_obj_id); - - /* image - * returned value is struct g_object_image * - */ - case JS_OBJ_T_IMAGE: -#ifdef G - if (F) { - struct g_object_image *gi; - struct list_head *lgi; - - if (!document->f_data) return NULL; - foreach(struct g_object_image, gi, lgi, document->f_data->images) { - if (gi->id == obj_id) return gi; - } - return NULL; - }else -#endif - return NULL; - - default: - internal("jsint_find_object: unknown type %d.",type); - return NULL; /* never called, but GCC likes it ;-) */ - } -} - - -static long *add_id(long *field,int *len,long id) -{ - long *p; - int a; - for (a=0;a<(*len);a++) /* this object is already on the list */ - if (field[a]==id)return field; - - (*len)++; - if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); - p=mem_realloc(field,(*len)*sizeof(long)); - - p[(*len)-1]=id; - return p; -} - -long *add_fd_id(long *field,int *len,long fd,long id, unsigned char *name) -{ - long *p; - int a; - for (a=0;a<(*len);a+=3) /* this object is already on the list */ - if (field[a]==fd&&field[a+1]==id)return field; - - - (*len)+=3; - if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); - p=mem_realloc(field,(*len)*sizeof(long)); - - p[(*len)-3]=fd; - p[(*len)-2]=id; - p[(*len)-1]=(name&&(*name))?(long)stracpy(name):(long)NULL; - return p; -} - -static long js_upcall_get_frame_id(void *data); - -/* finds all objects with name takhle_tomu_u_nas_nadavame - * in fd and all it's subframes with rq==NULL - * js_ctx is f_data_c of the accessing script - */ -static long *find_in_subframes(struct f_data_c *js_ctx, struct f_data_c *fd, long *pole_vole, int *n_items, unsigned char *takhle_tomu_u_nas_nadavame) -{ - struct f_data_c *ff; - struct list_head *lff; - struct form_control *f; - struct list_head *lf; - - /* search frame */ - foreach(struct f_data_c, ff, lff, fd->subframes) - if (ff->loc&&ff->loc->name&&!strcmp(cast_const_char ff->loc->name,cast_const_char takhle_tomu_u_nas_nadavame)&&jsint_can_access(js_ctx,ff)) /* to je on! */ - if (!(pole_vole=add_id(pole_vole,n_items,js_upcall_get_frame_id(ff))))return NULL; - - if (!(fd->f_data))goto a_je_po_ptakach; - -#ifdef G - if (F) { - struct g_object_image *gi; - struct list_head *lgi; - /* search images */ - foreach(struct g_object_image, gi, lgi, fd->f_data->images) { - if (gi->name&&!strcmp(cast_const_char gi->name, cast_const_char takhle_tomu_u_nas_nadavame)) - if (!(pole_vole=add_id(pole_vole,n_items,JS_OBJ_T_IMAGE+((gi->id)<<JS_OBJ_MASK_SIZE))))return NULL; - } - } -#endif - /* search forms */ - foreachback(struct form_control, f, lf, fd->f_data->forms) - if (f->form_name&&!strcmp(cast_const_char f->form_name,cast_const_char takhle_tomu_u_nas_nadavame)) /* tak tohle JE Jim Beam */ - if (!(pole_vole=add_id(pole_vole,n_items,((f->form_num)<<JS_OBJ_MASK_SIZE)+JS_OBJ_T_FORM)))return NULL; - - /* search form elements */ - foreachback(struct form_control, f, lf, fd->f_data->forms) - if (f->name&&!strcmp(cast_const_char f->name,cast_const_char takhle_tomu_u_nas_nadavame)) /* tak tohle JE Jim Beam */ - { - long tak_mu_to_ukaz=0; - tak_mu_to_ukaz=(f->g_ctrl_num)<<JS_OBJ_MASK_SIZE; - switch (f->type) - { - case FC_TEXT: tak_mu_to_ukaz|=JS_OBJ_T_TEXT; break; - case FC_PASSWORD: tak_mu_to_ukaz|=JS_OBJ_T_PASSWORD; break; - case FC_TEXTAREA: tak_mu_to_ukaz|=JS_OBJ_T_TEXTAREA; break; - case FC_CHECKBOX: tak_mu_to_ukaz|=JS_OBJ_T_CHECKBOX; break; - case FC_RADIO: tak_mu_to_ukaz|=JS_OBJ_T_RADIO; break; - case FC_IMAGE: - case FC_SELECT: tak_mu_to_ukaz|=JS_OBJ_T_SELECT; break; - case FC_SUBMIT: tak_mu_to_ukaz|=JS_OBJ_T_SUBMIT ; break; - case FC_RESET: tak_mu_to_ukaz|=JS_OBJ_T_RESET ; break; - case FC_HIDDEN: tak_mu_to_ukaz|=JS_OBJ_T_HIDDEN ; break; - case FC_BUTTON: tak_mu_to_ukaz|=JS_OBJ_T_BUTTON ; break; - default: /* internal("Invalid form element type.\n"); */ - tak_mu_to_ukaz=0;break; - } - if (tak_mu_to_ukaz&&!(pole_vole=add_id(pole_vole,n_items,tak_mu_to_ukaz)))return NULL; - } - -a_je_po_ptakach: - /* find in all rq==NULL */ - foreach(struct f_data_c, ff, lff, fd->subframes) - if (!(ff->rq)) pole_vole=find_in_subframes(js_ctx,ff,pole_vole,n_items,takhle_tomu_u_nas_nadavame); - - - return pole_vole; -} - -/* resolves name of an object, returns field of all ID's with the name - * obj_id is object in which we're searching - * takhle_tomu_u_nas_nadavame is the searched name - * context is identifier of the javascript context - * n_items is number of returned items - * - * on error returns NULL - */ -long *jsint_resolve(void *context, long obj_id, char *takhle_tomu_u_nas_nadavame,int *n_items) -{ - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)context; - long *pole_vole; - *n_items=0; - - if (!takhle_tomu_u_nas_nadavame||!(*takhle_tomu_u_nas_nadavame))return NULL; - pole_vole=mem_alloc(sizeof(long)); - switch(jsint_object_type(obj_id)) - { - /* searched object can be a frame, image, form or a form element */ - case JS_OBJ_T_DOCUMENT: - case JS_OBJ_T_FRAME: - fd=jsint_find_document(obj_id); - if (!fd||!(jsint_can_access(js_ctx,fd)))break; - - pole_vole=find_in_subframes(js_ctx, fd, pole_vole, n_items, takhle_tomu_u_nas_nadavame); - break; - - /* searched name can be a form element */ - case JS_OBJ_T_FORM: - { - struct form_control *fc=jsint_find_object(js_ctx,obj_id); - struct form_control *f; - struct list_head *lf; - if (!fc){mem_free(pole_vole);return NULL;} - - if (!(js_ctx->f_data)){mem_free(pole_vole);return NULL;} - foreachback(struct form_control, f, lf, js_ctx->f_data->forms) - { - if (f->form_num==fc->form_num) /* this form */ - if (f->name&&!strcmp(cast_const_char f->name,cast_const_char takhle_tomu_u_nas_nadavame)) /* this IS Jim Beam */ - { - long tak_mu_to_ukaz=0; - tak_mu_to_ukaz=(f->g_ctrl_num)<<JS_OBJ_MASK_SIZE; - switch (f->type) - { - case FC_TEXT: tak_mu_to_ukaz|=JS_OBJ_T_TEXT; break; - case FC_PASSWORD: tak_mu_to_ukaz|=JS_OBJ_T_PASSWORD; break; - case FC_TEXTAREA: tak_mu_to_ukaz|=JS_OBJ_T_TEXTAREA; break; - case FC_CHECKBOX: tak_mu_to_ukaz|=JS_OBJ_T_CHECKBOX; break; - case FC_RADIO: tak_mu_to_ukaz|=JS_OBJ_T_RADIO; break; - case FC_IMAGE: - case FC_SELECT: tak_mu_to_ukaz|=JS_OBJ_T_SELECT; break; - case FC_SUBMIT: tak_mu_to_ukaz|=JS_OBJ_T_SUBMIT ; break; - case FC_RESET: tak_mu_to_ukaz|=JS_OBJ_T_RESET ; break; - case FC_HIDDEN: tak_mu_to_ukaz|=JS_OBJ_T_HIDDEN ; break; - case FC_BUTTON: tak_mu_to_ukaz|=JS_OBJ_T_BUTTON ; break; - default: tak_mu_to_ukaz=0;break; - /* internal("Invalid form element type.\n"); */ - } - if ((tak_mu_to_ukaz&JS_OBJ_MASK)&&!(pole_vole=add_id(pole_vole,n_items,tak_mu_to_ukaz)))return NULL; - } - } - } - break; - } - if (!pole_vole)return NULL; - if (!(*n_items)){mem_free(pole_vole);pole_vole=NULL;} - return pole_vole; -} - -/*------------------------>>>>>>>> UPCALLS <<<<<<<<-------------------------*/ - - -/* tyhle upcally se volaji ze select smycky: - - void js_upcall_confirm(void *data) - void js_upcall_alert(void * data) - void js_upcall_close_window(void *data) - void js_upcall_get_string(void *data) - void js_upcall_goto_url(void * data) - void js_upcall_goto_history(void * data) - void js_upcall_set_image_src(void* data) - -V nich se musi volat js_spec_vykill_timer, aby se znicil timer, ktery upcall -zavolal. - -Tyto upcally MUZOU dostavat f_data_c pointer primo, protoze kdyz ten f_data_c -umre a s nim i ten JS, tak se timery znicej --- tudiz se nic nestane. -*/ - - -static void redraw_document(struct f_data_c *f) -{ - /* - if (F) { - f->xl = -1; - f->yl = -1; - draw_to_window(f->ses->win, draw_doc, f); - } - */ - draw_fd(f); -} - - -/* returns ID of a document with the javascript */ -long js_upcall_get_document_id(void *data) -{ - struct f_data_c *fd; - if (!data)internal("js_upcall_get_document_id called with NULL pointer!"); - - fd=(struct f_data_c*)data; - return (((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT); -} - - -/* same as get_document_id, but returned type is FRAME */ -static long js_upcall_get_frame_id(void *data) -{ - struct f_data_c *fd; - if (!data)internal("js_upcall_get_document_id called with NULL pointer!"); - - fd=(struct f_data_c*)data; - return (((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_FRAME); -} - - -/* writes "len" bytes starting at "str" to document */ -void js_upcall_document_write(void *p, unsigned char *str, int len) -{ - int pos; - unsigned char *s; - struct f_data_c *fd = p; - struct js_state *js = fd->js; - if (!js)return; - if (!js->active) internal("js_upcall_document_write: no request active"); - if (js->active->write_pos == -1) return; - if (js->active->write_pos < 0) internal("js_upcall_document_write: js->active trashed"); - if (!js->src) { - unsigned char *s, *eof; - if (get_file(fd->rq, &s, &eof)) return; - js->src = memacpy(s, eof - s); - js->srclen = eof - s; - } - if ((unsigned)js->srclen + (unsigned)len > MAXINT) overalloc(); - if ((unsigned)js->srclen + (unsigned)len < (unsigned)len) overalloc(); - s = mem_realloc(js->src, js->srclen + len); - js->src = s; - if ((pos = js->srclen - js->active->write_pos) < 0) pos = 0; - memmove(s + pos + len, s + pos, js->srclen - pos); - memcpy(s + pos, str, len); - js->srclen += len; - js->newdata += len; - js_zaflaknuto_pameti += len; - js->active->wrote = 1; -} - - -/* returns title of actual document (=document in the script context) */ -/* when an error occurs, returns NULL */ -/* returned string should be deallocated after use */ -unsigned char *js_upcall_get_title(void *data) -{ - struct f_data_c *fd; - unsigned char *title, *t; - - if (!data)internal("js_upcall_get_title called with NULL pointer!"); - fd=(struct f_data_c *)data; - - title=mem_alloc(MAX_STR_LEN); - - if (!(get_current_title(fd,title,MAX_STR_LEN))){mem_free(title);return NULL;} - if (fd->f_data) - { - t = convert(fd->f_data->opt.cp, fd->f_data->cp, title, NULL); - mem_free(title); - title=t; - } - return title; -} - - -/* sets title of actual document (=document in the script context) */ -/* string title will be deallocated after use */ -void js_upcall_set_title(void *data, unsigned char *title) -{ - unsigned char *t; - struct f_data_c *fd; - int l=0; - - if (!data)internal("js_upcall_get_title called with NULL pointer!"); - fd=(struct f_data_c *)data; - - if (!title)return; - - if (!(fd->f_data)){mem_free(title);return;} - if (fd->f_data->title)mem_free(fd->f_data->title); - fd->f_data->title=init_str(); - fd->f_data->uncacheable=1; - t = convert(fd->f_data->cp, fd->f_data->opt.cp, title, NULL); - add_to_str(&(fd->f_data->title),&l,t); - mem_free(t); - - mem_free(title); - redraw_document(fd); -} - - -/* returns URL of actual document (=document in the script context) */ -/* when an error occurs, returns NULL */ -/* returned string should be deallocated after use */ -unsigned char *js_upcall_get_location(void *data) -{ - struct f_data_c *fd; - unsigned char *loc; - - if (!data)internal("js_upcall_get_location called with NULL pointer!"); - fd=(struct f_data_c *)data; - - loc=mem_alloc(MAX_STR_LEN); - - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} - return loc; -} - - -/* returns string containing last modification date */ -/* or NULL when the date is not known or when an error occurs */ -unsigned char *js_upcall_document_last_modified(void *data, long document_id) -{ - struct f_data_c *fd; - struct f_data_c *document; - unsigned char *retval; - - document=jsint_find_document(document_id); - if (!data)internal("js_upcall_document_last_modified called with NULL pointer!"); - fd=(struct f_data_c *)data; - - if (!document)return NULL; /* document not found */ - if (!jsint_can_access(fd, document))return NULL; /* you have no permissions to look at the document */ - - if (!fd->rq||!fd->rq->ce)return NULL; - retval=stracpy(fd->rq->ce->last_modified); - - return retval; -} - - -/* returns allocated string with user-agent */ -unsigned char *js_upcall_get_useragent(void *data) -{ - /*struct f_data_c *fd;*/ - unsigned char *retval=init_str(); - int l=0; - - if (!data)internal("js_upcall_get_useragent called with NULL pointer!"); - /*fd=(struct f_data_c *)data;*/ - - if (!http_options.header.fake_useragent||!(*http_options.header.fake_useragent)) { - add_to_str(&retval, &l, "Links (" VERSION_STRING "; "); - add_to_str(&retval, &l, system_name); - add_to_str(&retval, &l, ")"); - } - else { - add_to_str(&retval, &l, http_options.header.fake_useragent); - } - - return retval; -} - - -/* returns allocated string with browser name */ -unsigned char *js_upcall_get_appname(void) -{ - if (!http_options.header.fake_useragent||!(*http_options.header.fake_useragent)) - return stracpy("Links"); - else - return stracpy(http_options.header.fake_useragent); -} - - -/* returns allocated string with browser name */ -unsigned char *js_upcall_get_appcodename(void) -{ - if (!http_options.header.fake_useragent||!(*http_options.header.fake_useragent)) - return stracpy("Links"); - else - return stracpy(http_options.header.fake_useragent); -} - - -/* returns allocated string with browser version: "version_number (system_name)" */ -unsigned char *js_upcall_get_appversion(void) -{ - unsigned char *str; - int l=0; - - if (http_options.header.fake_useragent&&(*http_options.header.fake_useragent))return stracpy(http_options.header.fake_useragent); - str=init_str(); - add_to_str(&str,&l,VERSION_STRING); - add_to_str(&str,&l," ("); - add_to_str(&str,&l,system_name); - add_to_str(&str,&l,")"); - return str; -} - - -/* returns allocated string with referrer */ -unsigned char *js_upcall_get_referrer(void *data) -{ - struct f_data_c *fd; - unsigned char *retval=init_str(); - unsigned char *loc; - int l=0; - - if (!data)internal("js_upcall_get_referrer called with NULL pointer!"); - fd=(struct f_data_c *)data; - - switch (http_options.header.referer) - { - case REFERER_FAKE: - add_to_str(&retval, &l, http_options.header.fake_referer); - break; - - case REFERER_SAME_URL: - loc=mem_alloc(MAX_STR_LEN); - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);break;} - add_to_str(&retval, &l, loc); - mem_free(loc); - break; - - case REFERER_REAL: - { - unsigned char *post; - - if (!fd->rq||!(fd->rq->prev_url))break; /* no referrer */ - post=strchr(fd->rq->prev_url, POST_CHAR); - if (!post)add_to_str(&retval, &l, fd->rq->prev_url); - else add_bytes_to_str(&retval, &l, fd->rq->prev_url, post - fd->rq->prev_url); - } - break; - } - - return retval; -} - -struct gimme_js_id -{ - long id; /* id of f_data_c */ - long js_id; /* unique id of javascript */ -}; - -/* tady se netestuje js_id, protoze BFU to chce killnout, tak to proste killne */ -/* aux function for all dialog upcalls */ -static void js_kill_script_pressed(void *data) -{ - struct f_data_c *fd; - struct gimme_js_id *jsid=(struct gimme_js_id*)data; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - if (!(fd->js))return; - js_downcall_game_over(fd->js->ctx); /* call downcall */ -} - - - -/* aux function for js_upcall_confirm */ -static void js_upcall_confirm_ok_pressed(void *data) -{ - struct f_data_c *fd; - struct gimme_js_id *jsid=(struct gimme_js_id*)data; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - if (!(fd->js)||jsid->js_id!=fd->js->ctx->js_id)return; - js_downcall_vezmi_true(fd->js->ctx); /* call downcall */ -} - - -/* aux function for js_upcall_confirm */ -static void js_upcall_confirm_cancel_pressed(void *data) -{ - struct f_data_c *fd; - struct gimme_js_id *jsid=(struct gimme_js_id*)data; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - if (!(fd->js)||jsid->js_id!=fd->js->ctx->js_id)return; - js_downcall_vezmi_false(fd->js->ctx); /* call downcall */ -} - - -/* creates dialog with text s->string and buttons OK/Cancel */ -/* s->string will be dealocated */ -/* s will be dealocated too */ -/* must be called from select loop */ -void js_upcall_confirm(void *data) -{ - struct fax_me_tender_string *s=(struct fax_me_tender_string*)data; - struct gimme_js_id* jsid; - struct f_data_c *fd; - struct terminal *term; - unsigned char *txt; - - if (!s)internal("js_upcall_confirm called with NULL pointer\n"); /* to jenom kdyby na mne PerM zkousel naky oplzlosti... */ - - /* context must be a valid pointer ! */ - fd=(struct f_data_c*)(s->ident); - term=fd->ses->term; - - if (!fd->js)return; - jsid=mem_alloc(sizeof(struct gimme_js_id)); - - /* kill timer, that called me */ - js_spec_vykill_timer(fd->js->ctx,0); - - /* fill in jsid */ - jsid->id=((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT; - jsid->js_id=fd->js->ctx->js_id; - - skip_nonprintable(s->string); - if (fd->f_data) - { - txt=convert(fd->f_data->cp, fd->f_data->opt.cp, s->string, NULL); - } - else - txt=stracpy(s->string); - js_mem_free(s->string); - msg_box( - term, /* terminal */ - getml(txt,jsid,NULL), /* memory blocks to free */ - TEXT_(T_QUESTION), /* title */ - AL_CENTER, /* alignment */ - txt, /* message */ - jsid, /* data for button functions */ - 3, /* # of buttons */ - TEXT_(T_OK),js_upcall_confirm_ok_pressed,B_ENTER, /* first button */ - TEXT_(T_CANCEL),js_upcall_confirm_cancel_pressed,B_ESC, /* second button */ - TEXT_(T_KILL_SCRIPT), js_kill_script_pressed,NULL - ); - - js_mem_free(s); -} - - -/* aux function for js_upcall_alert */ -static void js_upcall_alert_ok_pressed(void *data) -{ - struct f_data_c *fd; - struct gimme_js_id *jsid=(struct gimme_js_id*)data; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - if (!(fd->js)||jsid->js_id!=fd->js->ctx->js_id)return; - js_downcall_vezmi_null(fd->js->ctx); /* call downcall */ -} - - -/* gets struct fax_me_tender_string* */ -/* creates dialog with title "Alert" and message got from struct fax_me_tender_string */ -/* structure and the text are both deallocated */ -/* must be called from select loop */ -void js_upcall_alert(void * data) -{ - struct fax_me_tender_string *s=(struct fax_me_tender_string*)data; - struct gimme_js_id* jsid; - struct f_data_c *fd; - struct terminal *term; - unsigned char *txt; - - if (!s)internal("Alert called with NULL pointer.\n"); /* to jenom kdyby na mne PerM zkousel naky oplzlosti... */ - - /* context must be a valid pointer ! */ - fd=(struct f_data_c*)(s->ident); - term=fd->ses->term; - - if (!fd->js) return; - jsid=mem_alloc(sizeof(struct gimme_js_id)); - - /* kill timer, that called me */ - js_spec_vykill_timer(fd->js->ctx,0); - - /* fill in jsid */ - jsid->id=((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT; - jsid->js_id=fd->js->ctx->js_id; - - skip_nonprintable(s->string); - if (fd->f_data) - { - txt=convert(fd->f_data->cp, fd->f_data->opt.cp, s->string, NULL); - } - else - txt=stracpy(s->string); - js_mem_free(s->string); - msg_box( - term, /* terminal */ - getml(txt,jsid,NULL), /* memory blocks to free */ - TEXT_(T_ALERT), /* title */ - AL_CENTER, /* alignment */ - txt, /* message */ - jsid, /* data for button functions */ - 2, /* # of buttons */ - TEXT_(T_OK),js_upcall_alert_ok_pressed,B_ENTER|B_ESC, - TEXT_(T_KILL_SCRIPT), js_kill_script_pressed,NULL - ); - - js_mem_free(s); -} - - -/* aux function for js_upcall_close_window */ -/* tady se netestuje js_id, protoze BFU zmacklo, ze chce zavrit okno a v - * nekterych pripadech by ho to nezavrelo (kdyby se testovalo) a to by vypadalo - * blbe */ -static void js_upcall_close_window_yes_pressed(void *data) -{ - struct f_data_c *fd; - struct gimme_js_id *jsid=(struct gimme_js_id*)data; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - really_exit_prog(fd->ses); -} - - -/* asks user if he really wants to close the window and calls really_exit_prog */ -/* argument is struct fax_me_tender_nothing* */ -/* must be called from select loop */ -void js_upcall_close_window(void *data) -{ - struct fax_me_tender_nothing *s=(struct fax_me_tender_nothing*)data; - struct f_data_c *fd; - struct terminal *term; - - if (!s)internal("js_upcall_close_window called with NULL pointer\n"); /* to jenom kdyby na mne PerM zkousel naky oplzlosti... */ - - /* context must be a valid pointer ! */ - fd=(struct f_data_c*)(s->ident); - if (!fd->js) return; - term=fd->ses->term; - - /* kill timer, that called me */ - js_spec_vykill_timer(fd->js->ctx,0); - - if (js_manual_confirmation) - { - struct gimme_js_id* jsid; - - jsid=mem_alloc(sizeof(struct gimme_js_id)); - - /* fill in jsid */ - jsid->id=((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT; - jsid->js_id=fd->js->ctx->js_id; - - msg_box( - term, /* terminal */ - getml(jsid,NULL), /* memory blocks to free */ - TEXT_(T_EXIT_LINKS), /* title */ - AL_CENTER, /* alignment */ - TEXT_(T_SCRIPT_TRYING_TO_CLOSE_WINDOW), /* message */ - jsid, /* data for button functions */ - 2, /* # of buttons */ - TEXT_(T_YES),js_upcall_close_window_yes_pressed,NULL, - TEXT_(T_KILL_SCRIPT), js_kill_script_pressed,NULL - ); - js_mem_free(s); - } - else - { - js_mem_free(s); - if (term->list_entry.next == term->list_entry.prev && are_there_downloads()) - query_exit(fd->ses); - else - really_exit_prog(fd->ses); - } -} - - -/* returns parent window ID of the script */ -long js_upcall_get_window_id(void *data) -{ - struct f_data_c *fd; - if (!data)internal("js_upcall_get_window_id called with NULL pointer!"); - - fd=(struct f_data_c*)data; - return ((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_FRAME; -} - - - -/* aux function for js_upcall_get_string */ -static void js_upcall_get_string_ok_pressed(void *data, unsigned char *str) -{ - struct f_data_c *fd; - struct gimme_js_id *jsid=(struct gimme_js_id*)data; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - if (!(fd->js)||jsid->js_id!=fd->js->ctx->js_id)return; - js_downcall_vezmi_string(fd->js->ctx, stracpy(str)); /* call downcall */ -} - -static void js_upcall_get_string_kill_script_pressed(void *data, unsigned char *str) -{ - js_kill_script_pressed(data); -} - -struct history js_get_string_history={0, {&js_get_string_history.items, &js_get_string_history.items}}; - - -/* creates input field for string, with text s->string1, default response - * s->string2 and buttons OK/Kill Script - * s->string1 and s->string2 will be dealocated - * s will be dealocated too - * must be called from select loop */ - -void js_upcall_get_string(void *data) -{ - struct fax_me_tender_2_stringy *s=(struct fax_me_tender_2_stringy*)data; - struct gimme_js_id* jsid; - struct f_data_c *fd; - struct terminal *term; - unsigned char *str1,*str2; - - if (!s)internal("js_upcall_get_string called with NULL pointer\n"); /* to jenom kdyby na mne PerM zkousel naky oplzlosti... */ - - /* context must be a valid pointer ! */ - fd=(struct f_data_c*)(s->ident); - term=fd->ses->term; - - if (!fd->js) return; - jsid=mem_alloc(sizeof(struct gimme_js_id)); - - /* kill timer, that called me */ - js_spec_vykill_timer(fd->js->ctx,0); - - /* fill in jsid */ - jsid->id=((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT; - jsid->js_id=fd->js->ctx->js_id; - - str1=stracpy(s->string1); - str2=stracpy(s->string2); - js_mem_free(s->string1); - js_mem_free(s->string2); - - input_field( - term, /* terminal */ - getml(str1, str2,jsid,NULL), /* mem to free */ - TEXT_(T_ENTER_STRING), /* title */ - str1, /* question */ - jsid, /* data for functions */ - &js_get_string_history, /* history */ - MAX_INPUT_URL_LEN, /* string len */ - str2, /* string to fill the dialog with */ - 0, /* min value */ - 0, /* max value */ - NULL, /* check fn */ - TEXT_(T_OK), /* ok button */ - js_upcall_get_string_ok_pressed, - TEXT_(T_KILL_SCRIPT), /* cancel button */ - js_upcall_get_string_kill_script_pressed, - NULL - ); - js_mem_free(s); -} - - -/* clears window with javascript */ -/* must be called from select loop */ -/* javascript must halt before calling this upcall */ -void js_upcall_clear_window(void *data) -{ - /* context must be a valid pointer ! */ - /*struct f_data_c *fd=(struct f_data_c*)data;*/ - /* no jsint_destroy context or so here, it's called automatically from reinit_f_data_c */ - /* - zatim jsem to zrusil ... tahle funkce musi byt volana pres timer, takhle je to uplne blbe a spadne to pri kazdem volani -- Mikulas - - to je <|>vina, v komentari je jasne napsano, ze tahle fce musi byt volana ze select loop, takze to nema co padat -- Brain - - no prave!! ze select smycky == z timeru. Z javascriptu to volat nemuzes, protoze to pod sebou ten kontext javascriptu smaze, a ten interpret spadne, protoze jeho kontext uz nebude existovat. -- Mikulas - - reinit_f_data_c(fd); - */ -} - - -/* returns allocated string with window name */ -unsigned char *js_upcall_get_window_name(void *data) -{ - /* context must be a valid pointer ! */ - struct f_data_c *fd=(struct f_data_c*)data; - - return fd->loc?stracpy(fd->loc->name):NULL; -} - - -/* returns allocated field of ID's of links in JS document - * number of links is stored in len - * if number of links is 0, returns NULL - * on error returns NULL too - */ -long *js_upcall_get_links(void *data, long document_id, int *len) -{ - struct f_data_c *js_ctx=(struct f_data_c*)data; - struct f_data_c *fd; - /*struct link *l;*/ - int a; - long *to_je_Ono; - - fd=jsint_find_document(document_id); - if (!js_ctx)internal("js_upcall_get_links called with NULL context pointer\n"); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - if (!(fd->f_data))return NULL; - *len=fd->f_data->nlinks; - if (!(*len))return NULL; - /*l=fd->f_data->links;*/ - if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); - to_je_Ono=mem_alloc((*len)*sizeof(long)); - - for (a=0;a<(*len);a++) - /*to_je_Ono[a]=JS_OBJ_T_LINK+(((l+a)->num)<<JS_OBJ_MASK_SIZE);*/ - to_je_Ono[a]=JS_OBJ_T_LINK+(a<<JS_OBJ_MASK_SIZE); - - return to_je_Ono; -} - - -/* returns allocated string with TARGET of the link - * if the link doesn't exist in the document, returns NULL - */ -unsigned char *js_upcall_get_link_target(void *data, long document_id, long link_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)data; - struct f_data_c *fd; - struct link *l; - - if (!js_ctx)internal("js_upcall_get_link_target called with NULL context pointer\n"); - if ((link_id&JS_OBJ_MASK)!=JS_OBJ_T_LINK)return NULL; /* this isn't link */ - - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - l=jsint_find_object(fd,link_id); - if (!l)return NULL; - - return stracpy((l->target)?(l->target):(unsigned char *)("")); -} - - -/* returns allocated field of ID's of forms in JS document - * number of forms is stored in len - * if number of forms is 0, returns NULL - * on error returns NULL too - */ -long *js_upcall_get_forms(void *data, long document_id, int *len) -{ - struct f_data_c *js_ctx=(struct f_data_c *)data; - struct f_data_c *fd; - struct form_control *fc; - struct list_head *lfc; - long *to_je_Ono; - long last=0; - - if (!js_ctx)internal("js_upcall_get_forms called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - if (!(fd->f_data))return NULL; - - to_je_Ono=mem_alloc(sizeof(long)); - - *len=0; - - foreachback(struct form_control, fc, lfc, fd->f_data->forms) { - long *p; - int a; - - if ((*len)&&(fc->form_num)==last)continue; - for (a=0;a<(*len);a++) - if ((to_je_Ono[a]>>JS_OBJ_MASK_SIZE)==(fc->form_num))goto already_have; /* we already have this number */ - - (*len)++; - if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); - p=mem_realloc(to_je_Ono,(*len)*sizeof(long)); - to_je_Ono=p; - to_je_Ono[(*len)-1]=JS_OBJ_T_FORM|((fc->form_num)<<JS_OBJ_MASK_SIZE); - last=fc->form_num; -already_have:; - } - - if (!(*len)){mem_free(to_je_Ono);to_je_Ono=NULL;} - - return to_je_Ono; -} - - -/* returns allocated string with the form action - * when an error occurs, returns NULL - */ -unsigned char *js_upcall_get_form_action(void *data, long document_id, long form_id) -{ - struct f_data_c *js_ctx=(struct f_data_c *)data; - struct f_data_c *fd; - struct form_control *fc; - - if (!js_ctx)internal("js_upcall_get_form_action called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ - - fc=jsint_find_object(fd,form_id); - if (!fc)return NULL; - - return stracpy(fc->action); -} - - - -/* sets form action - */ -void js_upcall_set_form_action(void *context, long document_id, long form_id, unsigned char *action) -{ - struct f_data_c *js_ctx=(struct f_data_c *)context; - struct f_data_c *fd; - struct form_control *fc; - - if (!js_ctx) { - internal("js_upcall_set_form_action called with NULL context pointer\n"); - } - - fd=jsint_find_document(document_id); - if (!fd || !jsint_can_access(js_ctx,fd)) { - if (action) mem_free(action); - return; - } - - if ( (form_id&JS_OBJ_MASK) != JS_OBJ_T_FORM ) { - if (action) mem_free(action); - return; - } - - fc=jsint_find_object(fd,form_id); - if (!fc) { - if (action) mem_free(action); - return; - } - - if (fc->action) { - mem_free (fc->action); - if ( fd->loc && fd->loc->url ) - fc->action=join_urls(fd->loc->url,action); - else - fc->action=stracpy(action); - fd->f_data->uncacheable=1; - } - - if (action) { - mem_free(action); - } -} - - -/* returns allocated string with the form target - * when an error occurs, returns NULL - */ -unsigned char *js_upcall_get_form_target(void *data, long document_id, long form_id) -{ - struct f_data_c *js_ctx=(struct f_data_c *)data; - struct f_data_c *fd; - struct form_control *fc; - - if (!js_ctx)internal("js_upcall_get_form_target called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ - - fc=jsint_find_object(fd,form_id); - if (!fc)return NULL; - - return stracpy(fc->target); -} - - - -/* returns allocated string with the form method - * when an error occurs, returns NULL - */ -unsigned char *js_upcall_get_form_method(void *data, long document_id, long form_id) -{ - struct f_data_c *js_ctx=(struct f_data_c *)data; - struct f_data_c *fd; - struct form_control *fc; - - if (!js_ctx)internal("js_upcall_get_form_method called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ - - fc=jsint_find_object(fd,form_id); - if (!fc)return NULL; - - switch (fc->method) - { - case FM_GET: - return stracpy("GET"); - - case FM_POST: - case FM_POST_MP: - return stracpy("POST"); - - default: - internal("Invalid form method!\n"); - return NULL; /* never called, but GCC likes it */ - } -} - - - -/* returns allocated string with the form encoding (value of attribute enctype) - * when an error occurs, returns NULL - */ -unsigned char *js_upcall_get_form_encoding(void *data, long document_id, long form_id) -{ - struct f_data_c *js_ctx=(struct f_data_c *)data; - struct f_data_c *fd; - struct form_control *fc; - - if (!js_ctx)internal("js_upcall_get_form_encoding called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ - - fc=jsint_find_object(fd,form_id); - if (!fc)return NULL; - - switch (fc->method) - { - case FM_GET: - case FM_POST: - return stracpy("application/x-www-form-urlencoded"); - - case FM_POST_MP: - return stracpy("multipart/form-data"); - - default: - internal("Invalid form method!\n"); - return NULL; /* never called, but GCC likes it */ - } -} - - -/* returns allocated string containing protocol from current URL in the script context - * on error (or there's no protocol) NULL is returned - */ -unsigned char *js_upcall_get_location_protocol(void *data) -{ - struct f_data_c *fd; - unsigned char *loc; - unsigned char *p; - int l; - - if (!data)internal("js_upcall_get_location called with NULL pointer!"); - fd=(struct f_data_c *)data; - - loc=mem_alloc(MAX_STR_LEN); - - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} - - if (parse_url(loc, &l, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)){mem_free(loc);return NULL;} - p=memacpy(loc,l+1); /* l is pointing to the colon, but we want protocol with colon */ - mem_free(loc); - return p; -} - - -/* returns allocated string containing port of current URL in the script context - * on error (or there's no protocol) NULL is returned - */ -unsigned char *js_upcall_get_location_port(void *data) -{ - struct f_data_c *fd; - unsigned char *loc; - unsigned char *p; - - if (!data)internal("js_upcall_get_location called with NULL pointer!"); - fd=(struct f_data_c *)data; - - loc=mem_alloc(MAX_STR_LEN); - - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} - - p=get_port_str(loc); - mem_free(loc); - return p; -} - - -/* returns allocated string containing hostname of current URL in the script context - * on error (or there's no protocol) NULL is returned - */ -unsigned char *js_upcall_get_location_hostname(void *data) -{ - struct f_data_c *fd; - unsigned char *loc; - unsigned char *p; - - if (!data)internal("js_upcall_get_location called with NULL pointer!"); - fd=(struct f_data_c *)data; - - loc=mem_alloc(MAX_STR_LEN); - - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} - - p=get_host_name(loc); - mem_free(loc); - return p; -} - - -/* returns allocated string containing hostname and port of current URL in the script context - * on error (or there's no protocol) NULL is returned - */ -unsigned char *js_upcall_get_location_host(void *data) -{ - struct f_data_c *fd; - unsigned char *loc; - unsigned char *p, *h; - int l1,l2; - - if (!data)internal("js_upcall_get_location called with NULL pointer!"); - fd=(struct f_data_c *)data; - - loc=mem_alloc(MAX_STR_LEN); - - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} - - if (parse_url(loc, NULL, NULL, NULL, NULL, NULL, &h, &l1, NULL, &l2, NULL, NULL, NULL)){mem_free(loc);return NULL;} - p=memacpy(h,l1+l2); - mem_free(loc); - return p; -} - - -/* returns allocated string containing pathname of current URL in the script context - * on error (or there's no protocol) NULL is returned - */ -unsigned char *js_upcall_get_location_pathname(void *data) -{ - struct f_data_c *fd; - unsigned char *loc; - unsigned char *d, *p; - - if (!data)internal("js_upcall_get_location called with NULL pointer!"); - fd=(struct f_data_c *)data; - - loc=mem_alloc(MAX_STR_LEN); - - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} - - if (parse_url(loc, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &d, NULL, NULL)){mem_free(loc);return NULL;} - if (!d){mem_free(loc);return NULL;} - p=memacpy(d,strcspn(d,"?")); - mem_free(loc); - return p; -} - - -/* returns allocated string containing everything after ? in current URL in the script context - * on error (or there's no protocol) NULL is returned - */ -unsigned char *js_upcall_get_location_search(void *data) -{ - struct f_data_c *fd; - unsigned char *loc; - unsigned char *d, *p; - - if (!data)internal("js_upcall_get_location called with NULL pointer!"); - fd=(struct f_data_c *)data; - - loc=mem_alloc(MAX_STR_LEN); - - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} - - if (parse_url(loc, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &d, NULL, NULL)){mem_free(loc);return NULL;} - if (!d){mem_free(loc);return NULL;} - p=stracpy(strchr(d,'?')); - mem_free(loc); - return p; -} - - -/* returns allocated string containing everything between # and ? in current URL in the script context - * on error (or there's no protocol) NULL is returned - */ -unsigned char *js_upcall_get_location_hash(void *data) -{ - struct f_data_c *fd; - unsigned char *loc; - unsigned char *d, *p; - - if (!data)internal("js_upcall_get_location called with NULL pointer!"); - fd=(struct f_data_c *)data; - - loc=mem_alloc(MAX_STR_LEN); - - if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} - - if (parse_url(loc, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &d, NULL, NULL)){mem_free(loc);return NULL;} - if (!d){mem_free(loc);return NULL;} - d=strchr(d,'#'); - if (!d){mem_free(loc);return NULL;} - d++; - p=memacpy(d,strcspn(d,"?")); - mem_free(loc); - return p; -} - - -/* returns allocated field of all form elements - * size of the field will be stored in len - * when an error occurs, returns NULL - */ -long *js_upcall_get_form_elements(void *data, long document_id, long form_id, int *len) -{ - struct f_data_c *js_ctx=(struct f_data_c *)data; - struct f_data_c *fd; - struct form_control *fc, *fc2; - struct list_head *lfc2; - long *pole_Premysla_Zavorace; - int b; - - if (!js_ctx)internal("js_upcall_get_form_elements called with NULL context pointer\n"); - if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return NULL; - - fc=jsint_find_object(fd,form_id); - if (!fc)return NULL; - - *len=0; - - foreach(struct form_control, fc2, lfc2, fd->f_data->forms) - if (fc2->form_num==fc->form_num)(*len)++; - - if (!(*len))return NULL; - - if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); - pole_Premysla_Zavorace=mem_alloc((*len)*sizeof(long)); - - b=0; - foreachback(struct form_control, fc2, lfc2, fd->f_data->forms) - if (fc2->form_num==fc->form_num) - { - switch (fc2->type) - { - case FC_TEXT: pole_Premysla_Zavorace[b]=JS_OBJ_T_TEXT; break; - case FC_PASSWORD: pole_Premysla_Zavorace[b]=JS_OBJ_T_PASSWORD; break; - case FC_TEXTAREA: pole_Premysla_Zavorace[b]=JS_OBJ_T_TEXTAREA; break; - case FC_CHECKBOX: pole_Premysla_Zavorace[b]=JS_OBJ_T_CHECKBOX; break; - case FC_RADIO: pole_Premysla_Zavorace[b]=JS_OBJ_T_RADIO; break; - case FC_IMAGE: - case FC_SELECT: pole_Premysla_Zavorace[b]=JS_OBJ_T_SELECT; break; - case FC_SUBMIT: pole_Premysla_Zavorace[b]=JS_OBJ_T_SUBMIT ; break; - case FC_RESET: pole_Premysla_Zavorace[b]=JS_OBJ_T_RESET ; break; - case FC_HIDDEN: pole_Premysla_Zavorace[b]=JS_OBJ_T_HIDDEN ; break; - case FC_BUTTON: pole_Premysla_Zavorace[b]=JS_OBJ_T_BUTTON ; break; - default: /* internal("Invalid form element type.\n"); */ - (*len)--; - continue; - } - pole_Premysla_Zavorace[b]|=((fc2->g_ctrl_num)<<JS_OBJ_MASK_SIZE); - b++; - } - return pole_Premysla_Zavorace; -} - - -/* returns allocated field with anchors - * size of the field is stored in len - * when there're no anchors, *len is 0 and NULL is returned - * on error NULL is returned - */ -long *js_upcall_get_anchors(void *hej_Hombre, long document_id, int *len) -{ - struct f_data_c *js_ctx=(struct f_data_c*)hej_Hombre; - struct f_data_c *fd; - int a; - long *to_je_Ono; - *len=0; - - if (!js_ctx)internal("js_upcall_get_anchors called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - if (!(fd->f_data))return NULL; - *len = (int)list_size(&fd->f_data->tags); - if (!*len) return NULL; - if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); - to_je_Ono = mem_alloc((*len)*sizeof(long)); - - for (a = 0; a < *len; a++) - to_je_Ono[a] = JS_OBJ_T_ANCHOR + (a << JS_OBJ_MASK_SIZE); - return to_je_Ono; - -} - - -/* returns whether radio or checkbox is checked - * return value: 0=not checked - * 1=checked - * -1=error - */ -int js_upcall_get_checkbox_radio_checked(void *smirak, long document_id, long radio_tv_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)smirak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - int state; - - if (!js_ctx)internal("js_upcall_get_checkbox_radio_checked called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - if ((radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO&&(radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_CHECKBOX)return -1; /* this isn't radio nor TV */ - - hopla=jsint_find_object(fd,radio_tv_id); - if (!hopla)return -1; - - state=hopla->fs->state; - mem_free(hopla); - return state; -} - - -/* checks/unchecks radio or checkbox - */ -void js_upcall_set_checkbox_radio_checked(void *smirak, long document_id, long radio_tv_id, int value) -{ - struct f_data_c *js_ctx=(struct f_data_c*)smirak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - - if (!js_ctx)internal("js_upcall_set_checkbox_radio_checked called with NULL context pointer\n"); - if ((radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO&&(radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_CHECKBOX)return; /* this isn't radio nor TV */ - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return; - - hopla=jsint_find_object(fd,radio_tv_id); - if (!hopla)return; - - hopla->fs->state=!!value; - mem_free(hopla); - redraw_document(fd); -} - - -/* returns whether radio or checkbox is checked - * return value: 0=default not checked - * 1=default checked - * -1=error - */ -int js_upcall_get_checkbox_radio_default_checked(void *bidak_smirak, long document_id, long radio_tv_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak_smirak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - int default_checked; - - if (!js_ctx)internal("js_upcall_get_checkbox_radio_default_checked called with NULL context pointer\n"); - if ((radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO&&(radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_CHECKBOX)return -1; /* this isn't radio nor TV */ - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - hopla=jsint_find_object(fd,radio_tv_id); - if (!hopla)return -1; - - default_checked=hopla->fc->default_state; - mem_free(hopla); - return default_checked; -} - - -/* sets radio/checkbox default_checked in the form - */ -void js_upcall_set_checkbox_radio_default_checked(void *bidak_smirak, long document_id, long radio_tv_id, int value) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak_smirak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - int something_changed; - value=!!value; - - if (!js_ctx)internal("js_upcall_set_checkbox_radio_default_checked called with NULL context pointer\n"); - if ((radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO&&(radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_CHECKBOX)return; /* this isn't radio nor TV */ - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return; - - hopla=jsint_find_object(fd,radio_tv_id); - if (!hopla)return; - - something_changed=(hopla->fc->default_state)^value; - hopla->fc->default_state=value; - fd->f_data->uncacheable|=something_changed; - mem_free(hopla); -} - - -/* returns allocated string with name of the form element - * don't forget to free the string after use - * on error returns NULL - */ -unsigned char *js_upcall_get_form_element_name(void *bidak, long document_id, long ksunt_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - unsigned char *hele_ho_bidaka; - - if (!js_ctx)internal("js_upcall_get_form_element_name called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - switch (ksunt_id&JS_OBJ_MASK) - { - case JS_OBJ_T_RADIO: - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - case JS_OBJ_T_CHECKBOX: - case JS_OBJ_T_SELECT: - case JS_OBJ_T_SUBMIT: - case JS_OBJ_T_RESET: - case JS_OBJ_T_HIDDEN: - case JS_OBJ_T_BUTTON: - break; - - default: - return NULL; /* To neni Jim Beam! */ - } - - hopla=jsint_find_object(fd,ksunt_id); - if (!hopla)return NULL; - - hele_ho_bidaka=stracpy(hopla->fc->name); - mem_free(hopla); - return hele_ho_bidaka; -} - - -/* sets name of the form element - * name is allocated string, this function deallocates it - */ -void js_upcall_set_form_element_name(void *bidak, long document_id, long ksunt_id, unsigned char *name) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - - if (!js_ctx)internal("js_upcall_set_form_element_name called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd)){if (name)mem_free(name);return;} - - switch (ksunt_id&JS_OBJ_MASK) - { - case JS_OBJ_T_RADIO: - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - case JS_OBJ_T_CHECKBOX: - case JS_OBJ_T_SELECT: - case JS_OBJ_T_SUBMIT: - case JS_OBJ_T_RESET: - case JS_OBJ_T_HIDDEN: - case JS_OBJ_T_BUTTON: - break; - - default: - if(name) mem_free(name); - return; /* To neni Jim Beam! */ - } - - hopla=jsint_find_object(fd,ksunt_id); - if (!hopla){if (name)mem_free(name);return;} - - if ((name||(hopla->fc->name))&&strcmp(cast_const_char name,cast_const_char hopla->fc->name)) - { - mem_free(hopla->fc->name); - hopla->fc->name=stracpy(name); - fd->f_data->uncacheable=1; - } - mem_free(hopla); - if(name) mem_free(name); -} - - -/* returns allocated string with value of VALUE attribute of the form element - * on error returns NULL - * don't forget to free the string after use - */ -unsigned char *js_upcall_get_form_element_default_value(void *bidak, long document_id, long ksunt_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - unsigned char *hele_ho_bidaka; - - if (!js_ctx)internal("js_upcall_get_form_element_default_value called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return NULL; - - switch (ksunt_id&JS_OBJ_MASK) - { - case JS_OBJ_T_RADIO: - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - case JS_OBJ_T_CHECKBOX: - case JS_OBJ_T_SELECT: - case JS_OBJ_T_SUBMIT: - case JS_OBJ_T_RESET: - case JS_OBJ_T_HIDDEN: - break; - - default: - return NULL; /* To neni Jim Beam! */ - } - - hopla=jsint_find_object(fd,ksunt_id); - if (!hopla)return NULL; - - hele_ho_bidaka=convert(fd->f_data->opt.cp, fd->f_data->cp, hopla->fc->default_value, NULL); - - mem_free(hopla); - return hele_ho_bidaka; -} - - -/* sets attribute VALUE of the form element - * name is allocated string that, this function frees it - * when name is NULL default value will be empty - */ -void js_upcall_set_form_element_default_value(void *bidak, long document_id, long ksunt_id, unsigned char *name) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - - if (!js_ctx)internal("js_upcall_set_form_element_default_value called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd)){if (name)mem_free(name);return;} - - switch (ksunt_id&JS_OBJ_MASK) - { - case JS_OBJ_T_RADIO: - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - case JS_OBJ_T_CHECKBOX: - case JS_OBJ_T_SELECT: - case JS_OBJ_T_SUBMIT: - case JS_OBJ_T_RESET: - case JS_OBJ_T_HIDDEN: - break; - - default: - if (name)mem_free(name); - return; /* To neni Jim Beam! */ - } - - hopla=jsint_find_object(fd,ksunt_id); - if (!hopla){if (name)mem_free(name);return;} - - if ((name||(hopla->fc->default_value))&&strcmp(cast_const_char name,cast_const_char hopla->fc->default_value)) - { - mem_free(hopla->fc->default_value); - hopla->fc->default_value=convert(fd->f_data->cp, fd->f_data->opt.cp, name, NULL); - fd->f_data->uncacheable=1; - } - mem_free(hopla); - if (name)mem_free(name); -} - -static unsigned char **get_js_event_ptr(struct js_event_spec **j, long type) -{ - create_js_event_spec(j); - if (type == Conkeydown) return &(*j)->keydown_code; - else if (type == Conkeypress) return &(*j)->keypress_code; - else if (type == Conkeyup) return &(*j)->keyup_code; - else return NULL; -} - -void js_upcall_set_form_element_event_handler(void *bidak, long document_id, long ksunt_id, long type, unsigned char *name) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - int i; - - if (!js_ctx)internal("js_upcall_set_form_element_event_handler called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd)){if (name)mem_free(name);return;} - if ((ksunt_id&JS_OBJ_MASK) == JS_OBJ_T_FRAME || (ksunt_id&JS_OBJ_MASK) == JS_OBJ_T_DOCUMENT) { - unsigned char **p = get_js_event_ptr(&fd->f_data->js_event, type); - if (!p) { - mem_free(name); - return; - } - if (*p) mem_free(*p); - *p = name; - fd->f_data->uncacheable=1; - return; - } - hopla=jsint_find_object(fd,ksunt_id); - if (!hopla){if (name)mem_free(name);return;} - for (i = 0; i < fd->f_data->nlinks; i++) { - struct link *l = &fd->f_data->links[i]; - if (l->form == hopla->fc) { - unsigned char **p = get_js_event_ptr(&l->js_event, type); - mem_free(hopla); - if (!p) { - mem_free(name); - return; - } - if (*p) mem_free(*p); - *p = name; - fd->f_data->uncacheable=1; - return; - } - } - mem_free(hopla); - mem_free(name); -} - - -/* returns allocated string with actual value of password, text or textarea element - * on error returns NULL - * don't forget to free the string after use - */ -unsigned char *js_upcall_get_form_element_value(void *bidak, long document_id, long ksunt_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - unsigned char *hele_ho_bidaka; - - if (!js_ctx)internal("js_upcall_get_form_element_value called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return NULL; - - switch (ksunt_id&JS_OBJ_MASK) - { - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - break; - - default: - return NULL; /* To neni Jim Beam! */ - } - - hopla=jsint_find_object(fd,ksunt_id); - if (!hopla)return NULL; - - hele_ho_bidaka=convert(fd->f_data->opt.cp, fd->f_data->cp, hopla->fs->value, NULL); - - mem_free(hopla); - return hele_ho_bidaka; -} - - -/* sets actual value of password, text or textarea element - * name is allocated string that, this function frees it - * when name is NULL default value will be empty - */ -void js_upcall_set_form_element_value(void *bidak, long document_id, long ksunt_id, unsigned char *name) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - struct hopla_mladej *hopla; - - if (!js_ctx)internal("js_upcall_set_form_element_value called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd)){if (name)mem_free(name);return;} - - fd=jsint_find_document(document_id); - - switch (ksunt_id&JS_OBJ_MASK) - { - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - break; - - default: - if (name)mem_free(name); - return; /* To neni Jim Beam! */ - } - - hopla=jsint_find_object(fd,ksunt_id); - if (!hopla){if (name)mem_free(name);return;} - - mem_free(hopla->fs->value); - hopla->fs->value=convert(fd->f_data->cp, fd->f_data->opt.cp, name, NULL); - - if ((size_t)hopla->fs->state > strlen(cast_const_char hopla->fs->value)) - hopla->fs->state = strlen(cast_const_char hopla->fs->value); - if ((ksunt_id&JS_OBJ_MASK) != JS_OBJ_T_TEXTAREA) { - if ((size_t)hopla->fs->vpos > strlen(cast_const_char hopla->fs->value)) - hopla->fs->vpos = strlen(cast_const_char hopla->fs->value); - } - mem_free(hopla); - if (name)mem_free(name); - redraw_document(fd); -} - - -/* emulates click on everything */ -void js_upcall_click(void *bidak, long document_id, long elem_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - - if (!js_ctx)internal("js_upcall_click called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return; - - switch (elem_id&JS_OBJ_MASK) - { - case JS_OBJ_T_CHECKBOX: - case JS_OBJ_T_RADIO: - case JS_OBJ_T_SUBMIT: - case JS_OBJ_T_RESET: - case JS_OBJ_T_BUTTON: - { - struct hopla_mladej *hopla; - int a; - struct link *l; - - if (!fd->f_data)return; - hopla=jsint_find_object(fd,elem_id); - if (!hopla)return; - - for (a=0;a<fd->f_data->nlinks;a++) - { - l=&(fd->f_data->links[a]); - if (l->form&&l->form==hopla->fc) /* to je on! */ - { - int old_link=fd->vs->current_link; - int old_orig_link=fd->vs->orig_link; - fd->vs->current_link=a; - fd->vs->orig_link=a; - enter(fd->ses,fd,0); - draw_fd(fd); - fd->vs->current_link=old_link; - fd->vs->orig_link=old_orig_link; - change_screen_status(fd->ses); - print_screen_status(fd->ses); - break; - } - } - mem_free(hopla); - } - break; - } -} - -#ifdef G -static int find_go_link_num; -static struct g_object *to_je_on_bidak; -static void find_go(struct g_object *p, struct g_object *c) -{ - if (c->draw == g_text_draw) { - struct g_object_text *t = get_struct(c, struct g_object_text, goti.go); - if (t->goti.link_num==find_go_link_num){to_je_on_bidak=c;return;} - } - if (c->get_list) c->get_list(c, find_go); -} -#endif - -/* emulates focus on password, text and textarea */ -void js_upcall_focus(void *bidak, long document_id, long elem_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - - if (!js_ctx)internal("js_upcall_focus called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return; - - switch (elem_id&JS_OBJ_MASK) - { - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - { - struct hopla_mladej *hopla; - int a; - struct link *l; - - if (!fd->f_data)return; - hopla=jsint_find_object(fd,elem_id); - if (!hopla)return; - - for (a=0;a<fd->f_data->nlinks;a++) - { - l=&(fd->f_data->links[a]); - if (l->form&&l->form==hopla->fc) /* to je on! */ - { - struct session *ses = fd->ses; - /*int x = 0;*/ - while (fd != current_frame(ses)) next_frame(ses, 1)/*, x = 1*/; - fd->vs->current_link=a; - fd->vs->orig_link=a; - if (fd->ses->term->spec->braille) { - if (fd->f_data->links[a].n) { - fd->vs->brl_x = fd->vs->orig_brl_x = fd->f_data->links[a].pos[0].x; - fd->vs->brl_y = fd->vs->orig_brl_y = fd->f_data->links[a].pos[0].y; - } - } -#ifdef G - if (F) - { - fd->ses->locked_link=1; - to_je_on_bidak=NULL; - find_go_link_num=a; - - /* tak tedka tu budu carovat g_object_text, kterej patri k tomuhle linku */ - if (fd->f_data->root->get_list)fd->f_data->root->get_list(fd->f_data->root,find_go); - fd->f_data->locked_on=to_je_on_bidak; - } -#endif - if (l->js_event&&l->js_event->focus_code) - jsint_execute_code(fd,l->js_event->focus_code,strlen(cast_const_char l->js_event->focus_code),-1,-1,-1, NULL); - - /*draw_fd(fd);*/ - draw_formatted(ses); - change_screen_status(fd->ses); - print_screen_status(fd->ses); - break; - } - } - mem_free(hopla); - } - break; - } -} - -/* emulates focus on password, text and textarea */ -void js_upcall_blur(void *bidak, long document_id, long elem_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - - if (!js_ctx)internal("js_upcall_blur called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return; - - /* in text mode do nothing, because we don't know where to go with cursor */ -#ifdef G - if (F) - switch (elem_id&JS_OBJ_MASK) - { - case JS_OBJ_T_TEXT: - case JS_OBJ_T_PASSWORD: - case JS_OBJ_T_TEXTAREA: - { - struct hopla_mladej *hopla; - int a; - struct link *l; - - if (!fd->f_data)return; - hopla=jsint_find_object(fd,elem_id); - if (!hopla)return; - - for (a=0;a<fd->f_data->nlinks;a++) - { - l=&(fd->f_data->links[a]); - if (l->form&&l->form==hopla->fc) /* to je on! */ - { - fd->ses->locked_link=0; - if (l->js_event&&l->js_event->blur_code) - jsint_execute_code(fd,l->js_event->blur_code,strlen(cast_const_char l->js_event->blur_code),-1,-1,-1, NULL); - - /* pro jistotu */ - draw_fd(fd); - change_screen_status(fd->ses); - print_screen_status(fd->ses); - break; - } - } - mem_free(hopla); - } - break; - } -#endif -} - -/* emulates submit of a form */ -void js_upcall_submit(void *bidak, long document_id, long form_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - struct form_control *form; - int has_onsubmit; - unsigned char *u; - - if (!js_ctx)internal("js_upcall_submit called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return; - - if (fd->ses->rq && fd->ses->defered_url) return; - - if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return; - form=jsint_find_object(fd,form_id); - if (!form)return; - - u=get_form_url(fd->ses,fd,form,&has_onsubmit); - if (u) { - goto_url_f(fd->ses,NULL,u,NULL,fd,form->form_num, has_onsubmit,0,0); - mem_free(u); - } - draw_fd(fd); - change_screen_status(fd->ses); - print_screen_status(fd->ses); -} - - -/* emulates reset of a form */ -void js_upcall_reset(void *bidak, long document_id, long form_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)bidak; - struct f_data_c *fd; - - if (!js_ctx)internal("js_upcall_reset called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return; - if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return; - if (!fd->f_data)return; - - reset_form(fd,form_id>>JS_OBJ_MASK_SIZE); - draw_fd(fd); - change_screen_status(fd->ses); - print_screen_status(fd->ses); -} - -/* returns length (number of radio buttons) of a radio - * on error returns -1 - */ -int js_upcall_get_radio_length(void *p, long document_id, long radio_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)p; - struct f_data_c *fd; - struct form_control *f; - struct list_head *lf; - struct hopla_mladej *hopla; - struct form_control *radio; - int count=0; - - if (!js_ctx)internal("js_upcall_get_radio_length called with NULL context pointer\n"); - if ((radio_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO) return -1; - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return -1; - - hopla=jsint_find_object(fd,radio_id); - if (!hopla)return -1; - radio=hopla->fc; - - /* find form elements with the same type, form_num (belonging to the same form) and name */ - foreachback(struct form_control, f, lf, fd->f_data->forms) - if (f->type==radio->type&&f->form_num==radio->form_num&&!strcmp(cast_const_char radio->name,cast_const_char f->name))count++; - mem_free(hopla); - return count; -} - -/* returns number of items in a select form element - * on error returns -1 - */ -int js_upcall_get_select_length(void *p, long document_id, long select_id) -{ - int l; - struct f_data_c *js_ctx=(struct f_data_c*)p; - struct f_data_c *fd; - struct hopla_mladej *hopla; - - if (!js_ctx)internal("js_upcall_get_select_length called with NULL context pointer\n"); - if ((select_id&JS_OBJ_MASK)!=JS_OBJ_T_SELECT) return -1; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - hopla=jsint_find_object(fd,select_id); - if (!hopla)return -1; - - l = hopla->fc->nvalues; - mem_free(hopla); - return l; -} - - -/* returns allocated field of select items - * don't forget to free: text and value of each item and the field - * on error returns NULL - * n is number of items in the field - */ -struct js_select_item* js_upcall_get_select_options(void *p, long document_id, long select_id, int *n) -{ - struct f_data_c *js_ctx=(struct f_data_c*)p; - struct f_data_c *fd; - struct hopla_mladej *hopla; - struct js_select_item* elektricke_pole; - int ukazme_si_na_nej; - - *n=0; - if (!js_ctx)internal("js_upcall_get_select_length called with NULL context pointer\n"); - if ((select_id&JS_OBJ_MASK)!=JS_OBJ_T_SELECT) return NULL; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - hopla=jsint_find_object(fd,select_id); - if (!hopla)return NULL; - - *n=hopla->fc->nvalues; - if ((unsigned)*n > MAXINT / sizeof(struct js_select_item)) overalloc(); - elektricke_pole=mem_alloc((*n)*sizeof(struct js_select_item)); - - for (ukazme_si_na_nej=0;ukazme_si_na_nej<(*n);ukazme_si_na_nej++) - { - elektricke_pole[ukazme_si_na_nej].text=stracpy((hopla->fc->labels)[ukazme_si_na_nej]); - elektricke_pole[ukazme_si_na_nej].value=stracpy((hopla->fc->values)[ukazme_si_na_nej]); - elektricke_pole[ukazme_si_na_nej].selected=(ukazme_si_na_nej==(hopla->fs->state)); - elektricke_pole[ukazme_si_na_nej].default_selected=(ukazme_si_na_nej==(hopla->fc->default_state)); - } - mem_free(hopla); - return elektricke_pole; -} - -/* returns index of just selected item in a select form element - * on error returns -1 - */ -int js_upcall_get_select_index(void *p, long document_id, long select_id) -{ - struct f_data_c *js_ctx=(struct f_data_c*)p; - struct f_data_c *fd; - struct hopla_mladej *hopla; - int l; - - if (!js_ctx)internal("js_upcall_get_select_length called with NULL context pointer\n"); - if ((select_id&JS_OBJ_MASK)!=JS_OBJ_T_SELECT) return -1; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - hopla=jsint_find_object(fd,select_id); - if (!hopla)return -1; - - l = hopla->fs->state; - mem_free(hopla); - return l; -} - - -struct gimme_js_id_string -{ - long id; - long js_id; - unsigned char *string; - int n; -}; - -/* open a link in a new xterm */ -static void send_vodevri_v_novym_vokne(struct terminal *term, int (*open_window)(struct terminal *term, unsigned char *, unsigned char *), struct session *ses) -{ - if (ses->dn_url) { - unsigned char *enc_url = encode_url(ses->dn_url); - open_window(term, path_to_exe, enc_url); - mem_free(enc_url); - } -} - -/* aux function for js_upcall_goto_url */ -static void js_upcall_goto_url_ok_pressed(void *data) -{ - struct f_data_c *fd; - struct gimme_js_id_string *jsid=(struct gimme_js_id_string*)data; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - /* it doesn't matter, that fd->js is NULL */ - if (jsid->n&&can_open_in_new(fd->ses->term)) /* open in new window */ - { - if (fd->ses->dn_url) mem_free(fd->ses->dn_url); - fd->ses->dn_url=stracpy(jsid->string); - open_in_new_window(fd->ses->term, send_vodevri_v_novym_vokne, fd->ses); - } - else - goto_url(fd->ses,jsid->string); - - if (!(fd->js)||jsid->js_id!=fd->js->ctx->js_id)return; - js_downcall_vezmi_null(fd->js->ctx); /* call downcall */ -} - - -/* aux function for js_upcall_goto_url */ -static void js_upcall_goto_url_cancel_pressed(void *data) -{ - struct f_data_c *fd; - struct gimme_js_id *jsid=(struct gimme_js_id*)data; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - if (!(fd->js)||jsid->js_id!=fd->js->ctx->js_id)return; - js_downcall_vezmi_null(fd->js->ctx); /* call downcall */ -} - - -/* gets struct fax_me_tender_int_string */ -/* asks user whether to go to the url or not */ -/* structure and the text are both deallocated */ -/* must be called from select loop */ -/* if num in fax_me_tender_int_string is not null, open in a new window */ -void js_upcall_goto_url(void * data) -{ - struct fax_me_tender_int_string *s=(struct fax_me_tender_int_string*)data; - struct f_data_c *fd; - struct terminal *term; - unsigned char *dest_url; - int in_new_win; - - fd=(struct f_data_c*)(s->ident); - term=fd->ses->term; - - if (!fd->js) return; - - /* kill timer, that called me */ - js_spec_vykill_timer(fd->js->ctx,0); - - if (!s)internal("js_upcall_goto_url called with NULL pointer\n"); - - if (!s->string){js_mem_free(data);goto goto_url_failed;} - if (fd->loc&&fd->loc->url) dest_url=join_urls(fd->loc->url,s->string); - else dest_url=stracpy(s->string); - if (!(dest_url)){js_mem_free(s->string);js_mem_free(data);goto goto_url_failed;} - js_mem_free(s->string); - in_new_win=s->num; - - if (js_manual_confirmation) - { - struct gimme_js_id_string* jsid; - - /* goto the same url */ - { - unsigned char txt[MAX_STR_LEN]; - void *p; - - p=get_current_url(fd->ses,txt,MAX_STR_LEN); - if (p&&fd->loc&&fd->loc->url&&!strcmp(cast_const_char txt,cast_const_char dest_url)) - { - mem_free(dest_url); - js_mem_free(data); - goto goto_url_failed; - } - } - - jsid=mem_alloc(sizeof(struct gimme_js_id_string)); - - /* context must be a valid pointer ! */ - /* fill in jsid */ - jsid->id=((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT; - jsid->js_id=fd->js->ctx->js_id; - jsid->string=dest_url; - jsid->n=s->num; - - msg_box( - term, /* terminal */ - getml(jsid->string,jsid,NULL), /* memory blocks to free */ - TEXT_(T_GOTO_URL), /* title */ - AL_CENTER|AL_EXTD_TEXT, /* alignment */ - jsid->n?TEXT_(T_JS_IS_ATTEMPTING_TO_OPEN_NEW_WINDOW_WITH_URL):TEXT_(T_JS_IS_ATTEMPTING_TO_GO_TO_URL), " \"",jsid->string,"\".",NULL, /* message */ - jsid, /* data for button functions */ - 3, /* # of buttons */ - TEXT_(T_ALLOW),js_upcall_goto_url_ok_pressed,B_ENTER, - TEXT_(T_REJECT),js_upcall_goto_url_cancel_pressed,B_ESC, - TEXT_(T_KILL_SCRIPT), js_kill_script_pressed,NULL /* dirty trick: gimme_js_id_string and gimme_js_id begins with the same long */ - ); - js_mem_free(s); - } - else - { - js_mem_free(s); - if (in_new_win&&can_open_in_new(fd->ses->term)) /* open in new window */ - { - if (fd->ses->dn_url) mem_free(fd->ses->dn_url); - fd->ses->dn_url=stracpy(dest_url); - open_in_new_window(fd->ses->term, send_vodevri_v_novym_vokne, fd->ses); - } - else - goto_url(fd->ses,dest_url); - js_downcall_vezmi_null(fd->js->ctx); /* call downcall */ - mem_free(dest_url); - } - return; - -goto_url_failed: - js_downcall_vezmi_null(fd->js->ctx); /* call downcall */ - return; -} - - -/* returns number of items in history */ -int js_upcall_get_history_length(void *context) -{ - struct f_data_c *fd=(struct f_data_c*)context; - - if (!fd)internal("PerMe, PerMe, ja si te podam!\n"); - - return (int)list_size(&fd->ses->history); -} - - -/* aux function for js_upcall_goto_history */ -static void js_upcall_goto_history_ok_pressed(void *data) -{ - struct f_data_c *fd; - struct gimme_js_id_string *jsid=(struct gimme_js_id_string*)data; - int a; - - fd=jsint_find_document(jsid->id); - if (!fd)return; /* context no longer exists */ - - a = (int)list_size(&fd->ses->history); - - if (a<jsid->n&&(fd->js)&&jsid->js_id==fd->js->ctx->js_id){js_downcall_vezmi_null(fd->js->ctx);return;} /* call downcall */ - - go_backwards(fd->ses->term,(void*)(my_intptr_t)(jsid->n),fd->ses); -} - - -/* gets struct fax_me_tender_int_string - * either num or string is set, but not both, the other must be NULL - * asks user whether to go to the url or not - * structure and the text are both deallocated - * must be called from select loop - * number can be: - * >0 go forward in history (not supported) - * 0 do nothing (means use string) - * <0 go backward in history (supported :) ) - * if string is defined - find appropriate history item and go to the url, when - * the URL doesn't exist do nothing - * - * JAK TO FUNGUJE: - * string se prekonvertuje na cislo (projde se historie) - * po zmacknuti OK se spocita delka historie a pokud je dostatecna, n-krat - * zavola go_back. Pokud neni, tak se chovame jako pri cancelu. - */ - -void js_upcall_goto_history(void * data) -{ - struct fax_me_tender_int_string *s=(struct fax_me_tender_int_string*)data; - struct f_data_c *fd; - struct terminal *term; - unsigned char *url=NULL; - unsigned char txt[16]; - long history_num=0; - - /* context must be a valid pointer ! */ - fd=(struct f_data_c*)(s->ident); - - if (!fd->js) return; - - /* kill timer, that called me */ - js_spec_vykill_timer(fd->js->ctx,0); - - if (!s)internal("Hele, tyhle prasarny si zkousej na nekoho jinyho, jo?!\n"); - if (!(s->num)&&!(s->string))internal("Tak tohle na mne nezkousej, bidaku!\n"); - if ((s->num)&&(s->string))internal("Ta sedla!\n"); - - /* find the history item */ - if (s->num) /* goto n-th item */ - { - struct location *loc; - struct list_head *lloc; - int a=0; - - if ((s->num)>0){if (s->string)js_mem_free(s->string);js_mem_free(data);goto goto_history_failed;} /* forward not supported */ - s->num=-s->num; - history_num=s->num; - - foreach(struct location, loc, lloc, fd->ses->history) { - if (a==s->num){url=stracpy(loc->url);break;} - a++; - } - } - else /* goto given url */ - { - struct location *loc; - struct list_head *lloc; - int a=0; - - foreach(struct location, loc, lloc, fd->ses->history) { - if (!strcmp(cast_const_char s->string,cast_const_char loc->url)){url=stracpy(s->string);history_num=a;break;} - a++; - } - } - - if (s->string)js_mem_free(s->string); - if (!url){js_mem_free(data);goto goto_history_failed;} - - term=fd->ses->term; - - if (js_manual_confirmation) - { - struct gimme_js_id_string* jsid; - - jsid=mem_alloc(sizeof(struct gimme_js_id_string)); - - /* fill in jsid */ - jsid->id=((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT; - jsid->js_id=fd->js->ctx->js_id; - jsid->string=url; - jsid->n=history_num; - - snprintf(txt,16," (-%d) ",jsid->n); - msg_box( - term, /* terminal */ - getml(url,jsid,NULL), /* memory blocks to free */ - TEXT_(T_GOTO_HISTORY), /* title */ - AL_CENTER|AL_EXTD_TEXT, /* alignment */ - TEXT_(T_JS_IS_ATTEMPTING_TO_GO_INTO_HISTORY), txt, TEXT_(T_TO_URL), " \"",url,"\".",NULL, /* message */ - jsid, /* data for button functions */ - 3, /* # of buttons */ - TEXT_(T_ALLOW),js_upcall_goto_history_ok_pressed,B_ENTER, - TEXT_(T_REJECT),js_upcall_goto_url_cancel_pressed,B_ESC, - TEXT_(T_KILL_SCRIPT), js_kill_script_pressed,NULL /* dirty trick: gimme_js_id_string and gimme_js_id begins with the same long */ - ); - js_mem_free(s); - } - else - { - js_mem_free(s); - mem_free(url); - go_backwards(term,(void*)(history_num),fd->ses); - } - return; -goto_history_failed: - js_downcall_vezmi_null(fd->js->ctx); - return; -} - - -/* set default status-line text - * tak_se_ukaz_Kolbene is allocated string or NULL - */ -void js_upcall_set_default_status(void *context, unsigned char *tak_se_ukaz_Kolbene) -{ - struct f_data_c *fd=(struct f_data_c*)context; - unsigned char *trouba; - - if (!fd)internal("Tak tohle teda ne, bobanku!\n"); - - if (!(*tak_se_ukaz_Kolbene)){mem_free(tak_se_ukaz_Kolbene);tak_se_ukaz_Kolbene=NULL;} /* Ale to hlavni jsme se nedozvedeli - s tim chrapanim jste mi neporadil... */ - - if (fd->ses->default_status)mem_free(fd->ses->default_status); - skip_nonprintable(tak_se_ukaz_Kolbene); - if (fd->f_data&&tak_se_ukaz_Kolbene) - { - /* ... a ted ty pochybne reci o majetku ... */ - trouba=convert(fd->f_data->cp, fd->f_data->opt.cp, tak_se_ukaz_Kolbene, NULL); /* Taky to mate levnejsi - jinak by to stalo deset! */ - mem_free(tak_se_ukaz_Kolbene); - /* a je to v troube... */ - } - else - { - trouba=tak_se_ukaz_Kolbene; - } - - fd->ses->default_status=trouba; - change_screen_status(fd->ses); - print_screen_status(fd->ses); -} - - -/* returns allocated string with default status-line value or NULL when default value is empty - */ -unsigned char* js_upcall_get_default_status(void *context) -{ - struct f_data_c *fd=(struct f_data_c *)context; - unsigned char *tak_se_ukaz_Danku=NULL; - unsigned char *trouba; - - if (!fd)internal("Ale hovno!\n"); - - if (fd->ses->default_status&&(*fd->ses->default_status))tak_se_ukaz_Danku=stracpy(fd->ses->default_status); - skip_nonprintable(tak_se_ukaz_Danku); - if (fd->f_data&&tak_se_ukaz_Danku) - { - trouba=convert(fd->f_data->opt.cp, fd->f_data->cp, tak_se_ukaz_Danku, NULL); - mem_free(tak_se_ukaz_Danku); - } - else - { - trouba=tak_se_ukaz_Danku; - } - - /* Tak to mame Kolben a Danek po peti korunach... */ - - return trouba; /* No jo, je to v troube! */ -} - - -/* set status-line text - * tak_se_ukaz_Kolbene is allocated string or NULL - */ -void js_upcall_set_status(void *context, unsigned char *tak_se_ukaz_Kolbene) -{ - struct f_data_c *fd=(struct f_data_c*)context; - unsigned char *trouba; - - if (!fd)internal("To leda tak -PRd!\n"); - - if (!(*tak_se_ukaz_Kolbene)){mem_free(tak_se_ukaz_Kolbene);tak_se_ukaz_Kolbene=NULL;} - - if (fd->ses->st)mem_free(fd->ses->st); - skip_nonprintable(tak_se_ukaz_Kolbene); - if (fd->f_data&&tak_se_ukaz_Kolbene) - { - trouba=convert(fd->f_data->cp, fd->f_data->opt.cp, tak_se_ukaz_Kolbene, NULL); - mem_free(tak_se_ukaz_Kolbene); - /* a je to v troube... */ - } - else - { - trouba=tak_se_ukaz_Kolbene; - } - - fd->ses->st=trouba; - print_screen_status(fd->ses); -} - - -/* returns allocated string with default status-line value or NULL when default value is empty - */ -unsigned char* js_upcall_get_status(void *context) -{ - struct f_data_c *fd=(struct f_data_c *)context; - unsigned char *tak_se_ukaz_Danku=NULL; - unsigned char *trouba; - - if (!fd)internal("To leda tak hovno!\n"); - - if (fd->ses->st&&(*fd->ses->st))tak_se_ukaz_Danku=stracpy(fd->ses->st); - skip_nonprintable(tak_se_ukaz_Danku); - if (fd->f_data&&tak_se_ukaz_Danku) - { - trouba=convert(fd->f_data->opt.cp, fd->f_data->cp, tak_se_ukaz_Danku, NULL); - mem_free(tak_se_ukaz_Danku); - } - else - { - trouba=tak_se_ukaz_Danku; - } - - /* Kolben a Danek, to mame po peti korunach... */ - - return trouba; -} - -/* returns allocated string with cookies, or NULL on error */ -unsigned char * js_upcall_get_cookies(void *context) -{ - struct f_data_c *fd=(struct f_data_c *)context; - unsigned char *s=init_str(); - int l=0; - int nc=0; - struct cookie *c; - struct list_head *lc; - unsigned char *server, *data; - struct c_domain *cd; - struct list_head *lcd; - - if (!fd)internal("Tak tomu rikam selhani komunikace...\n"); - - /* zavolame set_cookies, ten zparsuje fd->js->ctx->cookies a necha tam nezparsovatelnej zbytek */ - - if (!fd->js||!fd->js->ctx) {mem_free(s);return NULL;} - if (!fd->rq) goto ty_uz_se_nevratis; - - jsint_set_cookies(fd,0); - - server = get_host_name(fd->rq->url); - data = get_url_data(fd->rq->url); - - if (data > fd->rq->url) data--; - foreach(struct c_domain, cd, lcd, c_domains) if (is_in_domain(cd->domain, server)) goto ok; - mem_free(server); -ty_uz_se_nevratis: - if (fd->js->ctx->cookies)add_to_str(&s,&l,fd->js->ctx->cookies); - else {mem_free(s);s=NULL;} - return s; - ok: - foreach(struct cookie, c, lc, all_cookies) if (is_in_domain(c->domain, server)) if (is_path_prefix(c->path, data)) { - if (cookie_expired(c)) { - lc = lc->prev; - del_from_list(c); - free_cookie(c); - continue; - } - if (c->secure) continue; - if (!nc) nc = 1; - else add_to_str(&s, &l, "; "); - add_to_str(&s, &l, c->name); - if (c->value) { - add_to_str(&s, &l, "="); - add_to_str(&s, &l, c->value); - } - } - - if (!nc) {mem_free(s);s=NULL;} - mem_free(server); - - /* za strinzik sestaveny z vnitrni reprezentace susenek jeste prilepime nezparsovatelnej zbytek */ - if (fd->js->ctx->cookies) - { - if (!s)s=stracpy(fd->js->ctx->cookies); - else {add_to_str(&s,&l,"; ");add_to_str(&s,&l,fd->js->ctx->cookies);} - } - /*debug("get_cookies: \"%s\"", s);*/ - return s; -} - -/* FIXME: document.all nechodi, musi se prepsat, aby vracel dvojice frame:idcko */ - - -/* adds all in given f_data_c, the f_data_c must be accessible by the javascript */ -static void add_all_recursive_in_fd(long **field, int *len, struct f_data_c *fd, struct f_data_c *js_ctx) -{ - struct f_data_c *ff; - struct list_head *lff; - struct form_control *fc; - struct list_head *lfc; - - /* add all accessible frames */ - foreach(struct f_data_c, ff, lff, fd->subframes) - if (jsint_can_access(js_ctx,ff)) - if (!((*field)=add_fd_id(*field,len,js_upcall_get_frame_id(fd),js_upcall_get_frame_id(ff),ff->f_data?ff->f_data->opt.framename:NULL)))return; - - if (!(fd->f_data))goto tady_uz_nic_peknyho_nebude; - -#ifdef G - /* add all images */ - if (F) { - struct g_object_image *gi; - struct list_head *lgi; - - foreach(struct g_object_image, gi, lgi, fd->f_data->images) { - if (!((*field)=add_fd_id(*field,len,js_upcall_get_frame_id(fd),JS_OBJ_T_IMAGE+((gi->id)<<JS_OBJ_MASK_SIZE),gi->name)))return; - } - } -#endif - /* add all forms */ - foreachback(struct form_control, fc, lfc, fd->f_data->forms) - if (!((*field)=add_fd_id(*field,len,js_upcall_get_frame_id(fd),((fc->form_num)<<JS_OBJ_MASK_SIZE)+JS_OBJ_T_FORM,fc->form_name)))return; - - /* add all form elements */ - foreachback(struct form_control, fc, lfc, fd->f_data->forms) - { - long tak_mu_to_ukaz=0; - tak_mu_to_ukaz=(fc->g_ctrl_num)<<JS_OBJ_MASK_SIZE; - switch (fc->type) - { - case FC_TEXT: tak_mu_to_ukaz|=JS_OBJ_T_TEXT; break; - case FC_PASSWORD: tak_mu_to_ukaz|=JS_OBJ_T_PASSWORD; break; - case FC_TEXTAREA: tak_mu_to_ukaz|=JS_OBJ_T_TEXTAREA; break; - case FC_CHECKBOX: tak_mu_to_ukaz|=JS_OBJ_T_CHECKBOX; break; - case FC_RADIO: tak_mu_to_ukaz|=JS_OBJ_T_RADIO; break; - case FC_IMAGE: - case FC_SELECT: tak_mu_to_ukaz|=JS_OBJ_T_SELECT; break; - case FC_SUBMIT: tak_mu_to_ukaz|=JS_OBJ_T_SUBMIT ; break; - case FC_RESET: tak_mu_to_ukaz|=JS_OBJ_T_RESET ; break; - case FC_HIDDEN: tak_mu_to_ukaz|=JS_OBJ_T_HIDDEN ; break; - case FC_BUTTON: tak_mu_to_ukaz|=JS_OBJ_T_BUTTON ; break; - default:/* internal("Invalid form element type.\n"); */ - tak_mu_to_ukaz=0;break; - } - if (tak_mu_to_ukaz&&!((*field)=add_fd_id(*field,len,js_upcall_get_frame_id(fd),tak_mu_to_ukaz,fc->name)))return; - } - -tady_uz_nic_peknyho_nebude: - - foreach(struct f_data_c, ff, lff, fd->subframes) - if (jsint_can_access(js_ctx,ff)) add_all_recursive_in_fd(field,len,ff,js_ctx); -} - -/* returns allocated field of all objects in the document (document.all) - * size of the field will be stored in len - * the field has 3x more items than the number of objects - * field[x+0]==id of frame - * field[x+1]==id of the object - * field[x+2]==allocated unsigned char* with name of the object or NULL (when there's no name) - * - * when an error occurs, returns NULL - */ -long * js_upcall_get_all(void *chuligane, long document_id, int *len) -{ - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - long *pole_neorane; /* Premysle Zavoraci, kde se flakas? Zase forbesis, co? */ - struct f_data_c *fd; - - if (!js_ctx)internal("js_upcall_get_all called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - *len=0; - - pole_neorane=mem_alloc(sizeof(long)); - - add_all_recursive_in_fd(&pole_neorane,len,fd,js_ctx); - - /* nothing was found */ - if (!pole_neorane)return NULL; - if (!(*len))mem_free(pole_neorane),pole_neorane=NULL; - - return pole_neorane; -} - - -/* returns allocated field of all images - * size of the field will be stored in len - * when an error occurs, returns NULL - */ - -long *js_upcall_get_images(void *chuligane, long document_id, int *len) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - long *pole_Premysla_Zavorace; - int a; - - if (F) { - struct g_object_image *gi; - struct list_head *lgi; - - if (!js_ctx)internal("js_upcall_get_images called with NULL context pointer\n"); - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return NULL; - - *len = list_size(&fd->f_data->images); - - if (!(*len))return NULL; - - if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); - pole_Premysla_Zavorace=mem_alloc((*len)*sizeof(long)); - - a=0; - foreach(struct g_object_image, gi, lgi, fd->f_data->images) { - unsigned id = gi->id;; - pole_Premysla_Zavorace[a]=JS_OBJ_T_IMAGE+(id<<JS_OBJ_MASK_SIZE); - a++; - } - return pole_Premysla_Zavorace; - } else -#endif - { - document_id=document_id; - *len=0; - return NULL; - } -} - -/* returns width of given image or -1 on error */ -int js_upcall_get_image_width(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct f_data_c *fd; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_get_image_width called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return -1; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return -1; - - return gi->goti.go.xw; - }else -#endif - { - document_id=document_id; - image_id=image_id; - return -1; - } -} - - -/* returns height of given image or -1 on error */ -int js_upcall_get_image_height(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct f_data_c *fd; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_get_image_height called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return -1; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return -1; - - return gi->goti.go.yw; - }else -#endif - { - document_id=document_id; - image_id=image_id; - return -1; - } -} - - -/* returns border of given image or -1 on error */ -int js_upcall_get_image_border(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_get_image_border called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return -1; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return -1; - - return gi->border; - }else -#endif - { - document_id=document_id; - image_id=image_id; - return -1; - } -} - - -/* returns vspace of given image or -1 on error */ -int js_upcall_get_image_vspace(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_get_image_vspace called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return -1; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return -1; - - return gi->vspace; - }else -#endif - { - document_id=document_id; - image_id=image_id; - return -1; - } -} - - -/* returns hspace of given image or -1 on error */ -int js_upcall_get_image_hspace(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_get_image_hspace called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return -1; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return -1; - - return gi->hspace; - }else -#endif - { - document_id=document_id; - image_id=image_id; - return -1; - } -} - - -/* returns allocated string with name of given image or NULL on error */ -unsigned char * js_upcall_get_image_name(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_get_image_name called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return NULL; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return NULL; - - return stracpy(gi->name); - }else -#endif - { - document_id=document_id; - image_id=image_id; - return NULL; - } -} - - -/* returns allocated string with name of given image or NULL on error */ -unsigned char * js_upcall_get_image_alt(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_get_image_alt called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return NULL; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return NULL; - - return stracpy(gi->alt); - }else -#endif - { - chuligane=chuligane; - document_id=document_id; - image_id=image_id; - return NULL; - } -} - - -/* sets image name to given value */ -/* name is deallocated after use with mem_free */ -void js_upcall_set_image_name(void *chuligane, long document_id, long image_id, unsigned char *name) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_set_image_name called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return; - - if (gi->name)mem_free(gi->name); - gi->name=stracpy(name); /* radeji takhle, protoze to je bezpecnejsi: az PerM zase do neceho slapne, tak se to pozna hned tady a ne buhvikde */ - if (name)mem_free(name); - return; - }else -#endif - { - chuligane=chuligane; - document_id=document_id; - image_id=image_id; - if (name)mem_free(name); - return; - } -} - - -/* sets image alt to given value */ -/* alt is deallocated after use with mem_free */ -void js_upcall_set_image_alt(void *chuligane, long document_id, long image_id, unsigned char *alt) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_set_image_alt called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return; - fd=jsint_find_document(document_id); - if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return; - - if (gi->alt)mem_free(gi->alt); - gi->alt=stracpy(alt); /* radeji takhle, protoze to je bezpecnejsi: az PerM zase do neceho slapne, tak se to pozna hned tady a ne buhvikde */ - if (fd->f_data&&gi->goti.link_num>=0&&gi->goti.link_num<fd->f_data->nlinks) - { - struct link *l=&fd->f_data->links[gi->goti.link_num]; - - if (l->img_alt)mem_free(l->img_alt); - l->img_alt=stracpy(alt); - } - if (alt)mem_free(alt); - change_screen_status(fd->ses); - print_screen_status(fd->ses); - return; - }else -#endif - { - chuligane=chuligane; - document_id=document_id; - image_id=image_id; - if (alt)mem_free(alt); - return; - } -} - - -/* returns allocated string with source URL of given image or NULL on error */ -unsigned char * js_upcall_get_image_src(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_get_image_src called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return NULL; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return NULL; - - return stracpy(gi->orig_src); - }else -#endif - { - document_id=document_id; - image_id=image_id; - return NULL; - } -} - - -/* changes image URL - * gets struct fax_me_tender_string_2_longy - * num1 = document_id, num2 = image_id, string = url - * - * frees the string and the fax_me_tender struct with js_mem_free function - */ -void js_upcall_set_image_src(void *chuligane) -{ - unsigned char *zvrat; - struct fax_me_tender_string_2_longy *fax=(struct fax_me_tender_string_2_longy*)chuligane; - struct f_data_c *js_ctx; -#ifdef G - struct f_data_c *fd; - struct g_object_image *gi; - long image_id,document_id; - unsigned char *vecirek; - if (F) - { - js_ctx=(struct f_data_c*)fax->ident; - js_spec_vykill_timer(js_ctx->js->ctx,0); - if (!chuligane)internal("js_upcall_set_image_src called with NULL argument\n"); - if (!js_ctx)internal("js_upcall_set_image_src called with NULL context pointer\n"); - image_id=fax->obj_id; - document_id=fax->doc_id; - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)goto abych_tu_nepovecerel; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))goto abych_tu_nepovecerel; - - gi=jsint_find_object(fd,image_id); - - if (!gi||!fd->f_data)goto abych_tu_nepovecerel; - - /* string joinnem s url */ - if (fd->f_data&&fd->f_data->script_href_base) vecirek=join_urls(fd->f_data->script_href_base,fax->string); - else if (fd->loc&&fd->loc->url) vecirek=join_urls(fd->loc->url,fax->string); - else vecirek=stracpy(fax->string); - /* a mame to kompatidebilni s verzi pred jointem */ - - change_image(gi,vecirek,fax->string,fd->f_data); - if (vecirek) mem_free(vecirek); - fd->f_data->uncacheable = 1; - abych_tu_nepovecerel:; - }else -#endif - { - js_ctx=(struct f_data_c*)fax->ident; - if (!js_ctx)internal("js_upcall_set_image_src called with NULL context pointer\n"); - js_spec_vykill_timer(js_ctx->js->ctx,0); - if (!chuligane)internal("js_upcall_set_image_src called with NULL argument\n"); - } - zvrat=stracpy(fax->string); - js_mem_free(fax->string); - js_mem_free(fax); - js_downcall_vezmi_string(js_ctx->js->ctx,zvrat); -} - - -/* returns 1 if image has completed loading, 0 when not, -1 on error */ -int js_upcall_image_complete(void *chuligane, long document_id, long image_id) -{ -#ifdef G - struct f_data_c *fd; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct g_object_image *gi; - - if (F) - { - if (!js_ctx)internal("js_upcall_image_complete called with NULL context pointer\n"); - if ((image_id&JS_OBJ_MASK)!=JS_OBJ_T_IMAGE)return -1; - fd=jsint_find_document(document_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - gi=jsint_find_object(fd,image_id); - - if (!gi)return -1; - - if (!gi->af||!gi->af->rq||!gi->af->rq->state)return -1; - return gi->af->rq->state==O_OK; - }else -#endif - { - document_id=document_id; - image_id=image_id; - return -1; - } -} - - -/* returns parent of given frame (or document), or -1 on error or no permissions */ -/* if frame_id is already top frame returns the same frame */ -long js_upcall_get_parent(void *chuligane, long frame_id) -{ - struct f_data_c *fd, *ff; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - - if (!js_ctx)internal("js_upcall_get_parent called with NULL context pointer\n"); - if ((frame_id&JS_OBJ_MASK)!=JS_OBJ_T_FRAME&&(frame_id&JS_OBJ_MASK)!=JS_OBJ_T_DOCUMENT)return -1; - fd=jsint_find_document(frame_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - - for (ff=fd->parent;ff&&!ff->rq;ff=ff->parent); - - if (!ff)ff=fd->ses->screen; - return jsint_can_access(fd,ff)?js_upcall_get_frame_id(ff):-1; -} - - -/* returns top of given frame (or document), or -1 on error */ -/* returns highest grandparent accessible from given frame */ -long js_upcall_get_frame_top(void *chuligane, long frame_id) -{ - struct f_data_c *fd, *ff; - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - - if (!js_ctx)internal("js_upcall_get_frame_top called with NULL context pointer\n"); - if ((frame_id&JS_OBJ_MASK)!=JS_OBJ_T_FRAME&&(frame_id&JS_OBJ_MASK)!=JS_OBJ_T_DOCUMENT)return -1; - fd=jsint_find_document(frame_id); - if (!fd||!jsint_can_access(js_ctx,fd))return -1; - for (ff=fd->parent;ff;ff=ff->parent) - { - if (ff->rq) - { - if (!jsint_can_access(fd,ff))break; - fd=ff; - } - } - return js_upcall_get_frame_id(fd); -} - - -/* returns allocated field of subframes or NULL on error */ -/* count cointains length of the field */ -/* don't forget to free the field after use */ -long * js_upcall_get_subframes(void *chuligane, long frame_id, int *count) -{ - struct f_data_c *js_ctx=(struct f_data_c*)chuligane; - struct f_data_c *fd; - struct f_data_c *f; - struct list_head *lf; - int a; - long *pole; - *count=0; - - if (!js_ctx)internal("js_upcall_get_subframes called with NULL context pointer\n"); - if ((frame_id&JS_OBJ_MASK)!=JS_OBJ_T_FRAME&&(frame_id&JS_OBJ_MASK)!=JS_OBJ_T_DOCUMENT)return NULL; - fd=jsint_find_document(frame_id); - if (!fd||!jsint_can_access(js_ctx,fd))return NULL; - - foreach(struct f_data_c, f, lf, fd->subframes) - if (jsint_can_access(fd,f)) (*count)++; - - if (!*count)return NULL; - if ((unsigned)*count > MAXINT / sizeof(long)) overalloc(); - pole=mem_alloc((*count)*sizeof(long)); - - a=0; - foreach(struct f_data_c, f, lf, fd->subframes) - if (jsint_can_access(fd,f)) - {pole[a]=js_upcall_get_frame_id(f);a++;} - return pole; -} - - -/*--------------------- DOWNCALLS ---------------------------*/ - -void js_downcall_game_over(void *context) -{ - struct f_data_c *fd=(struct f_data_c*)(((js_context*)(context))->ptr); - - /* js_error(get_text_translation(TEXT_(T_SCRIPT_KILLED_BY_USER),fd->ses->term),context); - * Tato hlaska me srala. Na to bych neprisel, ze jsem prave zabil - * rucne javascript. */ - if (fd->ses->default_status)mem_free(fd->ses->default_status),fd->ses->default_status=NULL; /* pekne uklidime bordylek, ktery nam BFU nacintalo do status lajny */ - jsint_destroy(fd); -#if 0 - js_durchfall=0; - if(((js_context*)context)->running) - js_volej_kolbena(context); - /* Kolben - ale nespi mi - co s tim budeme delat? */ - ((js_context*)context)->running=0; -#endif -} - - -void js_downcall_vezmi_int(void *context, int i) -{ -} - - -void js_downcall_vezmi_float(void *context, float f) -{ -} - -#else void jsint_execute_code(struct f_data_c *fd, unsigned char *code, int len, int write_pos, int onclick_submit, int onsubmit, struct links_event *ev) { @@ -3909,4 +50,3 @@ int jsint_get_source(struct f_data_c *fd, unsigned char **start, unsigned char * return 0; } -#endif diff --git a/kbd.c b/kbd.c @@ -135,13 +135,11 @@ static void send_init_sequence(int h, int flags) { want_draw(); hard_write(h, init_seq, (int)strlen(cast_const_char init_seq)); -#ifndef DOS if (flags & USE_TWIN_MOUSE) { hard_write(h, init_seq_tw_mouse, (int)strlen(cast_const_char init_seq_tw_mouse)); } else { hard_write(h, init_seq_x_mouse, (int)strlen(cast_const_char init_seq_x_mouse)); } -#endif done_draw(); } @@ -149,13 +147,11 @@ static void send_term_sequence(int h, int flags) { want_draw(); hard_write(h, term_seq, (int)strlen(cast_const_char term_seq)); -#ifndef DOS if (flags & USE_TWIN_MOUSE) { hard_write(h, term_seq_tw_mouse, (int)strlen(cast_const_char term_seq_tw_mouse)); } else { hard_write(h, term_seq_x_mouse, (int)strlen(cast_const_char term_seq_x_mouse)); } -#endif done_draw(); } @@ -171,24 +167,14 @@ static void resize_terminal(void) #if defined(OS_SETRAW) -#elif defined(HAVE_TERMIOS_H) +#else static void os_cfmakeraw(struct termios *t) { -#ifdef HAVE_CFMAKERAW cfmakeraw(t); #ifdef VMIN t->c_cc[VMIN] = 1; #endif -#else - t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); - t->c_oflag &= ~OPOST; - t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); - t->c_cflag &= ~(CSIZE|PARENB); - t->c_cflag |= CS8; - t->c_cc[VMIN] = 1; - t->c_cc[VTIME] = 0; -#endif #if defined(NO_CTRL_Z) && defined(VSUSP) t->c_cc[VSUSP] = 0; #endif @@ -295,9 +281,6 @@ static int setraw(int ctl, int save) t.c_lflag |= TOSTOP; #endif t.c_oflag |= OPOST; -#ifdef DOS - t.c_lflag &= ~(ISIG | ECHO); -#endif if (ttcsetattr(ctl, TCSANOW, &t)) { /*fprintf(stderr, "setattr result %s\n", strerror(errno));*/ return -1; @@ -311,43 +294,6 @@ static void setcooked(int ctl) ttcsetattr(ctl, TCSANOW, &saved_termios); } -#elif defined(HAVE_SGTTY_H) - -static struct sgttyb saved_sgtty; - -static int setraw(int ctl, int save) -{ - struct sgttyb sgtty; - if (ctl < 0) return 0; - if (gtty(ctl, &sgtty)) { - return -1; - } - if (save) memcpy(&saved_sgtty, &sgtty, sizeof(struct sgttyb)); - sgtty.sg_flags |= CBREAK; - sgtty.sg_flags &= ~ECHO; - if (stty(ctl, &sgtty)) { - return -1; - } - return 0; -} - -static void setcooked(int ctl) -{ - if (ctl < 0) return; - stty(ctl, &saved_sgtty); -} - -#else - -static int setraw(int ctl, int save) -{ - return 0; -} - -static void setcooked(int ctl) -{ -} - #endif void handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in, void *init_string, int init_len) @@ -478,16 +424,10 @@ static void free_trm(struct itrm *itrm) void fatal_tty_exit(void) { -#ifdef DOS - dos_mouse_terminate(); -#endif if (ditrm) setcooked(ditrm->ctl_in); #ifdef G if (drv && drv->emergency_shutdown) drv->emergency_shutdown(); #endif -#ifdef DOS - dos_restore_screen(); -#endif } static void resize_terminal_x(unsigned char *text) @@ -953,12 +893,8 @@ static int xterm_button = -1; static int is_interix(void) { -#ifdef INTERIX - return 1; -#else unsigned char *term = cast_uchar getenv("TERM"); return term && !strncmp(cast_const_char term, "interix", 7); -#endif } static int is_uwin(void) @@ -1311,58 +1247,4 @@ static void in_kbd(void *itrm_) ; } -#ifdef GRDRV_VIRTUAL_DEVICES - -int kbd_set_raw; - -void svgalib_free_trm(struct itrm *itrm) -{ - /*debug("svgalib_free: %p", itrm);*/ - if (!itrm) return; - if (kbd_set_raw) setcooked(itrm->ctl_in); - set_handlers(itrm->std_in, NULL, NULL, NULL); - unregister_bottom_half(itrm_error, itrm); - if (itrm->tm != NULL) kill_timer(itrm->tm); - mem_free(itrm); - if (itrm == ditrm) ditrm = NULL; -} - -struct itrm *handle_svgalib_keyboard(void (*queue_event)(struct itrm *, unsigned char *, int)) -{ - struct itrm *itrm; - itrm = mem_calloc(sizeof(struct itrm)); - ditrm = itrm; - itrm->queue_event = queue_event; - itrm->free_trm = svgalib_free_trm; - itrm->std_in = 0; - itrm->ctl_in = 0; - itrm->tm = NULL; - if (kbd_set_raw) setraw(itrm->ctl_in, 1); - set_handlers(itrm->std_in, in_kbd, NULL, itrm); - /*debug("svgalib_handle: %p", itrm);*/ - return itrm; -} - -int svgalib_unblock_itrm(struct itrm *itrm) -{ - /*debug("svgalib_unblock: %p", itrm);*/ - if (!itrm) return -1; - if (kbd_set_raw) if (setraw(itrm->ctl_in, 0)) return -1; - itrm->blocked = 0; - set_handlers(itrm->std_in, in_kbd, NULL, itrm); - unblock_stdin(); - return 0; -} - -void svgalib_block_itrm(struct itrm *itrm) -{ - /*debug("svgalib_block: %p", itrm);*/ - if (!itrm) return; - itrm->blocked = 1; - block_stdin(); - if (kbd_set_raw) setcooked(itrm->ctl_in); - set_handlers(itrm->std_in, NULL, NULL, itrm); -} - -#endif diff --git a/language.c b/language.c @@ -153,10 +153,6 @@ int get_default_charset(void) i = 0; ret_i: -#ifndef ENABLE_UTF8 - if (!F && i == utf8_table) - i = 0; -#endif default_charset = i; return i; } diff --git a/links.h b/links.h @@ -4033,9 +4033,6 @@ void gif_destroy_decoder(struct cached_image *); void gif_start(struct cached_image *goi); void gif_restart(unsigned char *data, int length); -void xbm_start(struct cached_image *goi); -void xbm_restart(struct cached_image *goi, unsigned char *data, int length); - #endif /* png.c */ diff --git a/main.c b/main.c @@ -11,15 +11,6 @@ int retval = RET_OK; static void unhandle_basic_signals(struct terminal *); static void poll_fg(void *); -#ifdef WIN -static void sig_terminate(void *t_) -{ - struct terminal *t = (struct terminal *)t_; - unhandle_basic_signals(t); - terminate_loop = 1; - retval = RET_SIGNAL; -} -#endif static void sig_intr(void *t_) { @@ -126,9 +117,6 @@ static void handle_basic_signals(struct terminal *term) install_signal_handler(SIGHUP, sig_intr, term, 0); if (!F) install_signal_handler(SIGINT, sig_ctrl_c, term, 0); /*install_signal_handler(SIGTERM, sig_terminate, term, 0);*/ -#ifdef WIN - install_signal_handler(SIGQUIT, sig_terminate, term, 0); -#endif #ifdef SIGTSTP if (!F) install_signal_handler(SIGTSTP, sig_tstp, term, 0); #endif @@ -549,9 +537,7 @@ static void terminate_all_subsystems(void) free_all_caches(); free_format_text_cache(); -#ifdef HAVE_SSL ssl_finish(); -#endif if (init_b) save_url_history(); free_history_lists(); free_term_specs(); diff --git a/memory.c b/memory.c @@ -117,9 +117,6 @@ retry: fatal_tty_exit(); fprintf(stderr, "\n"); -#ifdef LEAK_DEBUG - fprintf(stderr, "Allocated: %lu bytes, %lu blocks\n", (unsigned long)mem_amount, (unsigned long)mem_blocks); -#endif fprintf(stderr, "File cache: %lu bytes, %lu files, %lu locked, %lu loading\n", (unsigned long)cache_info(CI_BYTES), (unsigned long)cache_info(CI_FILES), (unsigned long)cache_info(CI_LOCKED), (unsigned long)cache_info(CI_LOADING)); #ifdef HAVE_ANY_COMPRESSION fprintf(stderr, "Decompressed cache: %lu bytes, %lu files, %lu locked\n", (unsigned long)decompress_info(CI_BYTES), (unsigned long)decompress_info(CI_FILES), (unsigned long)decompress_info(CI_LOCKED)); diff --git a/menu.c b/menu.c @@ -21,9 +21,6 @@ static unsigned char * const version_texts[] = { #if defined(__linux__) || defined(__LINUX__) || defined(__SPAD__) || defined(USE_GPM) TEXT_(T_GPM_MOUSE_DRIVER), #endif -#ifdef OS2 - TEXT_(T_XTERM_FOR_OS2), -#endif TEXT_(T_GRAPHICS_MODE), #ifdef G TEXT_(T_IMAGE_LIBRARIES), @@ -97,13 +94,9 @@ static void menu_version(void *term_) add_to_str(&s, &l, cast_uchar "\n"); add_and_pad(&s, &l, term, *text_ptr++, maxlen); -#ifdef SUPPORT_IPV6 if (!support_ipv6) add_to_str(&s, &l, get_text_translation(TEXT_(T_NOT_ENABLED_IN_SYSTEM), term)); else if (!ipv6_full_access()) add_to_str(&s, &l, get_text_translation(TEXT_(T_LOCAL_NETWORK_ONLY), term)); else add_to_str(&s, &l, get_text_translation(TEXT_(T_YES), term)); -#else - add_to_str(&s, &l, get_text_translation(TEXT_(T_NO), term)); -#endif add_to_str(&s, &l, cast_uchar "\n"); add_and_pad(&s, &l, term, *text_ptr++, maxlen); @@ -115,7 +108,6 @@ static void menu_version(void *term_) add_to_str(&s, &l, cast_uchar "\n"); add_and_pad(&s, &l, term, *text_ptr++, maxlen); -#ifdef HAVE_SSL #ifdef OPENSSL_VERSION add_to_str(&s, &l, (unsigned char *)OpenSSL_version(OPENSSL_VERSION)); #else @@ -126,38 +118,18 @@ static void menu_version(void *term_) add_to_str(&s, &l, get_text_translation(TEXT_(T_NO_CERTIFICATE_VERIFICATION), term)); add_to_str(&s, &l, cast_uchar ")"); #endif -#else - add_to_str(&s, &l, get_text_translation(TEXT_(T_NO), term)); -#endif add_to_str(&s, &l, cast_uchar "\n"); add_and_pad(&s, &l, term, *text_ptr++, maxlen); -#ifdef ENABLE_UTF8 add_to_str(&s, &l, get_text_translation(TEXT_(T_YES), term)); -#else - add_to_str(&s, &l, get_text_translation(TEXT_(T_NO), term)); -#endif add_to_str(&s, &l, cast_uchar "\n"); #if defined(__linux__) || defined(__LINUX__) || defined(__SPAD__) || defined(USE_GPM) add_and_pad(&s, &l, term, *text_ptr++, maxlen); -#ifdef USE_GPM - add_gpm_version(&s, &l); -#else add_to_str(&s, &l, get_text_translation(TEXT_(T_NO), term)); -#endif add_to_str(&s, &l, cast_uchar "\n"); #endif -#ifdef OS2 - add_and_pad(&s, &l, term, *text_ptr++, maxlen); -#ifdef X2 - add_to_str(&s, &l, get_text_translation(TEXT_(T_YES), term)); -#else - add_to_str(&s, &l, get_text_translation(TEXT_(T_NO), term)); -#endif - add_to_str(&s, &l, cast_uchar "\n"); -#endif add_and_pad(&s, &l, term, *text_ptr++, maxlen); #ifdef G @@ -176,36 +148,12 @@ static void menu_version(void *term_) add_to_str(&s, &l, cast_uchar ", "); add_jpeg_version(&s, &l); #endif -#ifdef HAVE_TIFF - add_to_str(&s, &l, cast_uchar ", "); - add_tiff_version(&s, &l); -#endif -#ifdef HAVE_SVG - add_to_str(&s, &l, cast_uchar ", "); - add_svg_version(&s, &l); -#endif add_to_str(&s, &l, cast_uchar "\n"); #endif #ifdef G add_and_pad(&s, &l, term, *text_ptr++, maxlen); -#ifndef HAVE_OPENMP add_to_str(&s, &l, get_text_translation(TEXT_(T_NO), term)); -#else - if (!F) { - add_to_str(&s, &l, get_text_translation(TEXT_(T_NOT_USED_IN_TEXT_MODE), term)); - } else if (disable_openmp) { - add_to_str(&s, &l, get_text_translation(TEXT_(T_DISABLED), term)); - } else { - int thr = omp_start(); - omp_end(); - add_num_to_str(&s, &l, thr); - add_to_str(&s, &l, cast_uchar " "); - if (thr == 1) add_to_str(&s, &l, get_text_translation(TEXT_(T_THREAD), term)); - else if (thr >= 2 && thr <= 4) add_to_str(&s, &l, get_text_translation(TEXT_(T_THREADS), term)); - else add_to_str(&s, &l, get_text_translation(TEXT_(T_THREADS5), term)); - } -#endif add_to_str(&s, &l, cast_uchar "\n"); #endif @@ -518,72 +466,6 @@ static void resource_info_menu(struct terminal *term, void *d, struct session *s resource_info(term, NULL); } -#ifdef LEAK_DEBUG - -static int memory_info(struct terminal *term, struct refresh *r2) -{ - unsigned char *a; - int l; - struct refresh *r; - - r = mem_alloc(sizeof(struct refresh)); - r->term = term; - r->win = NULL; - r->fn = memory_info; - r->timer = NULL; - l = 0; - a = init_str(); - - add_unsigned_long_num_to_str(&a, &l, mem_amount); - add_to_str(&a, &l, cast_uchar " "); - add_to_str(&a, &l, get_text_translation(TEXT_(T_MEMORY_ALLOCATED), term)); - add_to_str(&a, &l, cast_uchar ", "); - add_unsigned_long_num_to_str(&a, &l, mem_blocks); - add_to_str(&a, &l, cast_uchar " "); - add_to_str(&a, &l, get_text_translation(TEXT_(T_BLOCKS_ALLOCATED), term)); - add_to_str(&a, &l, cast_uchar "."); - -#ifdef MEMORY_REQUESTED - if (mem_requested && blocks_requested) { - add_to_str(&a, &l, cast_uchar "\n"); - add_unsigned_long_num_to_str(&a, &l, mem_requested); - add_to_str(&a, &l, cast_uchar " "); - add_to_str(&a, &l, get_text_translation(TEXT_(T_MEMORY_REQUESTED), term)); - add_to_str(&a, &l, cast_uchar ", "); - add_unsigned_long_num_to_str(&a, &l, blocks_requested); - add_to_str(&a, &l, cast_uchar " "); - add_to_str(&a, &l, get_text_translation(TEXT_(T_BLOCKS_REQUESTED), term)); - add_to_str(&a, &l, cast_uchar "."); - } -#endif -#ifdef JS - add_to_str(&a, &l, cast_uchar "\n"); - add_unsigned_long_num_to_str(&a, &l, js_zaflaknuto_pameti); - add_to_str(&a, &l, cast_uchar " "); - add_to_str(&a, &l, get_text_translation(TEXT_(T_JS_MEMORY_ALLOCATED), term)); - add_to_str(&a, &l, cast_uchar "."); -#endif - - if (r2 && !strcmp(cast_const_char a, cast_const_char *(unsigned char **)((struct dialog_data *)r2->win->data)->dlg->udata)) { - mem_free(a); - mem_free(r); - r2->timer = install_timer(RESOURCE_INFO_REFRESH, refresh, r2); - return 1; - } - - msg_box(term, getml(a, NULL), TEXT_(T_MEMORY_INFO), AL_CENTER, a, r, 1, TEXT_(T_OK), NULL, B_ENTER | B_ESC); - r->win = list_struct(term->windows.next, struct window); - ((struct dialog_data *)r->win->data)->dlg->abort = refresh_abort; - r->timer = install_timer(RESOURCE_INFO_REFRESH, refresh, r); - return 0; -} - -static void memory_info_menu(struct terminal *term, void *d, struct session *ses) -{ - memory_info(term, NULL); -} - -#endif static void flush_caches(struct terminal *term, void *d, void *e) { @@ -667,9 +549,6 @@ static void downloads_menu(struct terminal *term, void *ddd, struct session *ses f = !d->prog ? d->orig_file : d->url; for (ff = f; *ff; ff++) if ((dir_sep(ff[0]) -#if defined(DOS_FS) || defined(SPAD) - || (!d->prog && ff[0] == ':') -#endif ) && ff[1]) f = ff + 1; if (!d->prog) @@ -683,76 +562,9 @@ static void downloads_menu(struct terminal *term, void *ddd, struct session *ses else do_menu(term, mi, ses); } -#ifndef GRDRV_VIRTUAL_DEVICES #define have_windows_menu 0 -#else - -#define have_windows_menu (F && drv->init_device == init_virtual_device) - -static void window_switch(struct terminal *term, void *nump, void *ses) -{ - int n = (int)(my_intptr_t)nump; - switch_virtual_device(n); -} - -static void windows_menu(struct terminal *term, void *xxx, struct session *ses) -{ - struct menu_item *mi = new_menu(15); - int i; - int selected = 0; - int pos = 0; - int have_free_slot = 0; - int o; - for (i = 0; i < n_virtual_devices; i++) { - if (virtual_devices[i]) { - struct session *xs; - struct list_head *ls; - unsigned char *l = init_str(), *r = init_str(), *h = init_str(); - int ll = 0, rr = 0, hh = 0; - add_num_to_str(&l, &ll, i + 1); - add_to_str(&l, &ll, cast_uchar "."); - foreach(struct session, xs, ls, sessions) if ((void *)xs->term == virtual_devices[i]->user_data) { - if (xs->screen && xs->screen->f_data && xs->screen->f_data->title) { - add_chr_to_str(&l, &ll, ' '); - if (xs->screen->f_data->title[0]) { - add_to_str(&l, &ll, xs->screen->f_data->title); - } else if (xs->screen->rq && xs->screen->rq->url) { - unsigned char *url = display_url(term, xs->screen->rq->url, 1); - add_to_str(&l, &ll, url); - mem_free(url); - } - } - break; - } - if (n_virtual_devices > 10) { - add_to_str(&r, &rr, cast_uchar "Alt-F"); - add_num_to_str(&r, &rr, i + 1); - } else { - add_to_str(&r, &rr, cast_uchar "Alt-"); - add_chr_to_str(&r, &rr, (i + 1) % 10 + '0'); - } - if (i < 10) { - add_chr_to_str(&h, &hh, (i + 1) % 10 + '0'); - } - if (current_virtual_device == virtual_devices[i]) - selected = pos; - add_to_menu(&mi, l, r, h, window_switch, (void *)(my_intptr_t)i, 0, pos++); - } else { - have_free_slot = 1; - } - } - if ((o = can_open_in_new(term)) && have_free_slot) { - add_to_menu(&mi, cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, pos++); - mi[pos - 1].free_i = 1; - add_to_menu(&mi, TEXT_(T_NEW_WINDOW), cast_uchar "", TEXT_(T_HK_NEW_WINDOW), MENU_FUNC open_in_new_window, (void *)send_open_new_xterm, o - 1, pos++); - mi[pos - 1].free_i = 1; - } - do_menu_selected(term, mi, ses, selected, NULL, NULL); -} - -#endif static void menu_doc_info(struct terminal *term, void *ddd, struct session *ses) { @@ -814,11 +626,7 @@ static void charset_sel_list(struct terminal *term, int ini, void (*set)(struct static void charset_list(struct terminal *term, void *xxx, struct session *ses) { charset_sel_list(term, term->spec->character_set, set_display_codepage, NULL, -#ifdef ENABLE_UTF8 1 -#else - 0 -#endif , 1); } @@ -1010,121 +818,6 @@ static void screen_margins(struct terminal *term, void *xxx, struct session *ses do_dialog(term, d, getml(d, NULL)); } -#ifdef JS - -static unsigned char * const jsopt_labels[] = { TEXT_(T_KILL_ALL_SCRIPTS), TEXT_(T_ENABLE_JAVASCRIPT), TEXT_(T_VERBOSE_JS_ERRORS), TEXT_(T_VERBOSE_JS_WARNINGS), TEXT_(T_ENABLE_ALL_CONVERSIONS), TEXT_(T_ENABLE_GLOBAL_NAME_RESOLUTION), TEXT_(T_MANUAL_JS_CONTROL), TEXT_(T_JS_RECURSION_DEPTH), TEXT_(T_JS_MEMORY_LIMIT_KB), NULL }; - -static int kill_script_opt; -static unsigned char js_fun_depth_str[7]; -static unsigned char js_memory_limit_str[7]; - - -static inline void kill_js_recursively(struct f_data_c *fd) -{ - struct f_data_c *f; - struct list_head *lf; - - if (fd->js) js_downcall_game_over(fd->js->ctx); - foreach(struct f_data_c, f, lf, fd->subframes) kill_js_recursively(f); -} - - -static inline void quiet_kill_js_recursively(struct f_data_c *fd) -{ - struct f_data_c *f; - struct list_head *lf; - - if (fd->js) js_downcall_game_over(fd->js->ctx); - foreach(struct f_data_c, f, lf, fd->subframes) quiet_kill_js_recursively(f); -} - - -static void refresh_javascript(void *ses_) -{ - struct session *ses = (struct session *)ses_; - if (ses->screen->f_data)jsint_scan_script_tags(ses->screen); - if (kill_script_opt) - kill_js_recursively(ses->screen); - if (!js_enable) /* vypnuli jsme skribt */ - { - if (ses->default_status)mem_free(ses->default_status),ses->default_status=NULL; - quiet_kill_js_recursively(ses->screen); - } - - js_fun_depth=strtol(cast_const_char js_fun_depth_str,0,10); - js_memory_limit=strtol(cast_const_char js_memory_limit_str,0,10); - - /* reparse document (muze se zmenit hodne veci) */ - html_interpret_recursive(ses->screen); - draw_formatted(ses); -} - - -static void javascript_options(struct terminal *term, void *xxx, struct session *ses) -{ - struct dialog *d; - kill_script_opt=0; - snprintf(cast_char js_fun_depth_str,7,"%d",js_fun_depth); - snprintf(cast_char js_memory_limit_str,7,"%d",js_memory_limit); - d = mem_calloc(sizeof(struct dialog) + 11 * sizeof(struct dialog_item)); - d->title = TEXT_(T_JAVASCRIPT_OPTIONS); - d->fn = group_fn; - d->refresh = refresh_javascript; - d->refresh_data=ses; - d->udata = (void *)jsopt_labels; - d->items[0].type = D_CHECKBOX; - d->items[0].gid = 0; - d->items[0].dlen = sizeof(int); - d->items[0].data = (void *)&kill_script_opt; - d->items[1].type = D_CHECKBOX; - d->items[1].gid = 0; - d->items[1].dlen = sizeof(int); - d->items[1].data = (void *)&js_enable; - d->items[2].type = D_CHECKBOX; - d->items[2].gid = 0; - d->items[2].dlen = sizeof(int); - d->items[2].data = (void *)&js_verbose_errors; - d->items[3].type = D_CHECKBOX; - d->items[3].gid = 0; - d->items[3].dlen = sizeof(int); - d->items[3].data = (void *)&js_verbose_warnings; - d->items[4].type = D_CHECKBOX; - d->items[4].gid = 0; - d->items[4].dlen = sizeof(int); - d->items[4].data = (void *)&js_all_conversions; - d->items[5].type = D_CHECKBOX; - d->items[5].gid = 0; - d->items[5].dlen = sizeof(int); - d->items[5].data = (void *)&js_global_resolve; - d->items[6].type = D_CHECKBOX; - d->items[6].gid = 0; - d->items[6].dlen = sizeof(int); - d->items[6].data = (void *)&js_manual_confirmation; - d->items[7].type = D_FIELD; - d->items[7].dlen = 7; - d->items[7].data = js_fun_depth_str; - d->items[7].fn = check_number; - d->items[7].gid = 1; - d->items[7].gnum = 999999; - d->items[8].type = D_FIELD; - d->items[8].dlen = 7; - d->items[8].data = js_memory_limit_str; - d->items[8].fn = check_number; - d->items[8].gid = 1024; - d->items[8].gnum = 30*1024; - d->items[9].type = D_BUTTON; - d->items[9].gid = B_ENTER; - d->items[9].fn = ok_dialog; - d->items[9].text = TEXT_(T_OK); - d->items[10].type = D_BUTTON; - d->items[10].gid = B_ESC; - d->items[10].fn = cancel_dialog; - d->items[10].text = TEXT_(T_CANCEL); - d->items[11].type = D_END; - do_dialog(term, d, getml(d, NULL)); -} - -#endif #ifndef G @@ -1454,7 +1147,6 @@ static void dlg_net_options(struct terminal *term, void *xxx, void *yyy) d->items[a].data = bind_ip_address; d->items[a].dlen = sizeof(bind_ip_address); d->items[a++].fn = check_local_ip_address; -#ifdef SUPPORT_IPV6 if (support_ipv6) { net_msg[a] = TEXT_(T_BIND_TO_LOCAL_IPV6_ADDRESS); d->items[a].type = D_FIELD; @@ -1462,7 +1154,6 @@ static void dlg_net_options(struct terminal *term, void *xxx, void *yyy) d->items[a].dlen = sizeof(bind_ipv6_address); d->items[a++].fn = check_local_ipv6_address; } -#endif net_msg[a] = TEXT_(T_ASYNC_DNS_LOOKUP); d->items[a].type = D_CHECKBOX; d->items[a].data = (unsigned char *)&async_lookup; @@ -1483,7 +1174,6 @@ static void dlg_net_options(struct terminal *term, void *xxx, void *yyy) do_dialog(term, d, getml(d, NULL)); } -#ifdef SUPPORT_IPV6 static unsigned char * const ipv6_labels[] = { TEXT_(T_IPV6_DEFAULT), TEXT_(T_IPV6_PREFER_IPV4), TEXT_(T_IPV6_PREFER_IPV6), TEXT_(T_IPV6_USE_ONLY_IPV4), TEXT_(T_IPV6_USE_ONLY_IPV6), NULL }; @@ -1532,20 +1222,13 @@ static void dlg_ipv6_options(struct terminal *term, void *xxx, void *yyy) do_dialog(term, d, getml(d, NULL)); } -#endif -#ifdef HAVE_SSL #define N_N 6 -#else -#define N_N 5 -#endif static unsigned char * const proxy_msg[] = { TEXT_(T_HTTP_PROXY__HOST_PORT), TEXT_(T_FTP_PROXY__HOST_PORT), -#ifdef HAVE_SSL TEXT_(T_HTTPS_PROXY__HOST_PORT), -#endif TEXT_(T_SOCKS_4A_PROXY__USER_HOST_PORT), TEXT_(T_APPEND_TEXT_TO_SOCKS_LOOKUPS), TEXT_(T_NOPROXY_LIST), @@ -1599,13 +1282,8 @@ static void proxy_fn(struct dialog_data *dlg) void reset_settings_for_tor(void) { -#ifdef DOS - max_connections = 3; - max_connections_to_host = 2; -#else max_connections = 10; max_connections_to_host = 8; -#endif max_tries = 3; receive_timeout = 120; unrestartable_receive_timeout = 600; @@ -1834,13 +1512,11 @@ static void dlg_proxy_options(struct terminal *term, void *xxx, void *yyy) d->items[a].data = ftp_proxy; d->items[a].fn = check_proxy; a++; -#ifdef HAVE_SSL d->items[a].type = D_FIELD; d->items[a].dlen = MAX_STR_LEN; d->items[a].data = https_proxy; d->items[a].fn = check_proxy; a++; -#endif d->items[a].type = D_FIELD; d->items[a].dlen = MAX_STR_LEN; d->items[a].data = socks_proxy; @@ -1925,9 +1601,6 @@ static unsigned char * const ssl_labels[] = { TEXT_(T_ACCEPT_INVALID_CERTIFICATES), TEXT_(T_WARN_ON_INVALID_CERTIFICATES), TEXT_(T_REJECT_INVALID_CERTIFICATES), -#ifdef HAVE_BUILTIN_SSL_CERTIFICATES - TEXT_(T_USE_BUILT_IN_CERTIFICATES), -#endif TEXT_(T_