Commit: 383a48adfcbc9cd7a735dda612ae07b8b9255d3d
Parent: beb35db16b287e286cf3f8731f75db6e412516de
Author: opask
Date: Sun, 8 Jul 2018 21:18:54 -0600
remove unused code and xbm support
Diffstat:
M | Makefile | | | 4 | +--- |
M | bfu.c | | | 4 | ---- |
M | bookmark.c | | | 4 | ---- |
M | cfg.h | | | 49 | ------------------------------------------------- |
M | config.h | | | 31 | ------------------------------- |
M | connect.c | | | 9 | --------- |
M | default.c | | | 127 | ------------------------------------------------------------------------------- |
M | dip.c | | | 2 | -- |
D | directfb.c | | | 838 | ------------------------------------------------------------------------------- |
M | dither.c | | | 2 | -- |
M | dns.c | | | 8 | -------- |
D | dos.c | | | 847 | ------------------------------------------------------------------------------- |
M | drivers.c | | | 180 | ------------------------------------------------------------------------------- |
M | error.c | | | 455 | ------------------------------------------------------------------------------- |
M | file.c | | | 15 | --------------- |
D | framebuf.c | | | 1973 | ------------------------------------------------------------------------------- |
D | grx.c | | | 572 | ------------------------------------------------------------------------------- |
M | html.c | | | 39 | --------------------------------------- |
M | html_gr.c | | | 12 | ------------ |
M | html_r.c | | | 48 | +----------------------------------------------- |
M | https.c | | | 29 | ----------------------------- |
M | img.c | | | 103 | ------------------------------------------------------------------------------- |
M | jsint.c | | | 3865 | ------------------------------------------------------------------------------- |
M | kbd.c | | | 17 | ----------------- |
M | language.c | | | 4 | ---- |
M | links.h | | | 398 | +------------------------------------------------------------------------------ |
M | menu.c | | | 211 | +------------------------------------------------------------------------------ |
M | os_dep.c | | | 2462 | ++----------------------------------------------------------------------------- |
M | os_dep.h | | | 219 | ------------------------------------------------------------------------------- |
M | os_depx.h | | | 77 | ----------------------------------------------------------------------------- |
D | pmshell.c | | | 2556 | ------------------------------------------------------------------------------- |
M | sched.c | | | 3 | --- |
M | select.c | | | 6 | ------ |
M | session.c | | | 154 | ------------------------------------------------------------------------------- |
M | setup.h | | | 4 | ---- |
D | smb.c | | | 676 | ------------------------------------------------------------------------------- |
M | string.c | | | 55 | ------------------------------------------------------- |
D | svg.c | | | 308 | ------------------------------------------------------------------------------- |
D | svgalib.c | | | 2522 | ------------------------------------------------------------------------------- |
M | terminal.c | | | 67 | ------------------------------------------------------------------- |
D | tiff.c | | | 289 | ------------------------------------------------------------------------------ |
M | types.c | | | 3 | --- |
M | url.c | | | 18 | ------------------ |
M | view.c | | | 386 | ------------------------------------------------------------------------------- |
M | view_gr.c | | | 30 | ------------------------------ |
M | vpipe.inc | | | 4 | ---- |
M | x.c | | | 19 | ++----------------- |
D | xbm.c | | | 300 | ------------------------------------------------------------------------------- |
48 files changed, 47 insertions(+), 19957 deletions(-)
diff --git a/Makefile b/Makefile
@@ -17,7 +17,6 @@ SRC = \
drivers.c\
error.c\
file.c\
- finger.c\
fn_impl.c\
ftp.c\
html.c\
@@ -58,8 +57,7 @@ XSRC = \
jpeg.c\
png.c\
view_gr.c\
- x.c\
- xbm.c
+ x.c
XOBJ = $(XSRC:.c=.o)
all: linksg
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);
}
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/cfg.h b/cfg.h
@@ -11,60 +11,11 @@
#ifdef HAVE_CONFIG2_H
#include "config2.h"
#endif
-#ifdef HAVE_CONFIG_VMS_H
-#include "config-vms.h"
-#define HAVE_RAND_ADD 1
-#define HAVE_RAND_FILE_NAME 1
-#define HAVE_RAND_LOAD_FILE 1
-#define HAVE_RAND_WRITE_FILE 1
-#define HAVE_SSL_GET1_SESSION 1
-#define HAVE_ASN1_STRING_TO_UTF8 1
-#ifdef VMS_DEBUGLEVEL
-#undef DEBUGLEVEL
-#define DEBUGLEVEL VMS_DEBUGLEVEL
-#endif
-#ifdef __VAX
-#undef HAVE_LONG_LONG
-#undef SIZEOF_UNSIGNED_LONG_LONG
-#undef HAVE_SNPRINTF
-#undef HAVE_STRTOLL
-#undef HAVE_STRTOQ
-#undef HAVE_SOCKETPAIR
-#undef HAVE_GETADDRINFO
-#undef HAVE_FREEADDRINFO
-#undef SUPPORT_IPV6
-#undef SUPPORT_IPV6_SCOPE
-#endif
-#endif
#if !defined(G) && DEBUGLEVEL >= 0 && defined(HAVE_SETJMP_H)
#undef HAVE_SETJMP_H
#endif
-/* no one will probably ever port svgalib on atheos or beos or port atheos
- interface to beos, but anyway: make sure they don't clash */
-
-#if defined(__BEOS__) || defined(__HAIKU__) || defined(__VMS) || defined(__DJGPP)
-#ifdef GRDRV_SVGALIB
-#undef GRDRV_SVGALIB
-#endif
-#ifdef GRDRV_ATHEOS
-#undef GRDRV_ATHEOS
-#endif
-#endif
-
-#ifdef GRDRV_ATHEOS
-#ifdef GRDRV_SVGALIB
-#undef GRDRV_SVGALIB
-#endif
-#endif
-
-#if !(defined(__EMX__) || defined(_WIN32) || defined(__CYGWIN__))
-#ifdef GRDRV_PMSHELL
-#undef GRDRV_PMSHELL
-#endif
-#endif
-
#ifndef HAVE_VOLATILE
#define volatile
#endif
diff --git a/config.h b/config.h
@@ -1,6 +1,3 @@
-/* Define if you have the strftime function. */
-#define HAVE_STRFTIME 1
-
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
#define HAVE_SYS_WAIT_H 1
@@ -10,9 +7,6 @@
/* Define as the return type of signal handlers (int or void). */
#define RETSIGTYPE void
-/* Define if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
@@ -411,9 +405,6 @@
/* Define if you have the <locale.h> header file. */
#define HAVE_LOCALE_H 1
-/* Define if you have the <math.h> header file. */
-#define HAVE_MATH_H 1
-
/* Define if you have the <netinet/in_systm.h> header file. */
#define HAVE_NETINET_IN_SYSTM_H 1
@@ -610,12 +601,6 @@
#define HAVE_POWF 1
/* */
-#undef JS
-
-/* */
-#define ENABLE_UTF8 1
-
-/* */
#define HAVE_XSETLOCALE 1
/* */
@@ -630,13 +615,6 @@
/* */
#define HAVE_ZLIB 1
-/* Tiff by Brain */
-#undef HAVE_TIFF
-
-/* SVG */
-/* #undef HAVE_SVG */
-#undef HAVE_SVG
-
/* Gpm_Event has wdx and wdy */
/* #undef HAVE_WDX_WDY */
@@ -652,23 +630,16 @@
#undef __CYGWIN__
#undef HAVE_ATHEOS_THREADS_H
-#undef INTERIX
#undef OS2
#undef OS2_ADVANCED_HEAP
#undef OPENVMS
#undef BEOS
-#undef JS
#undef SPAD
#undef DOS
#undef DOS_FS
#undef DOS_FS_8_3
-#undef GRDRV_FB
-#undef GRDRV_SDL
-#undef GRDRV_DIRECTFB
#undef GRDRV_SVGALIB
#undef GRDRV_ATHEOS
-#undef GRDRV_SVGALIB
-#undef GRDRV_PMSHELL
#undef __DJGPP
#undef VMS_DEBUGLEVEL
#undef __VAX
@@ -686,7 +657,5 @@
#undef GRDRV_VIRTUAL_DEVICES
#undef USE_GPM
#undef HAVE_BUILTIN_SSL_CERTIFICATES
-#undef USE_WIN32_HEAP
#undef LEAK_DEBUG
#undef OOPS
-#undef RISCOS
diff --git a/connect.c b/connect.c
@@ -731,9 +731,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;
}
@@ -942,12 +939,6 @@ static void write_select(void *c_)
{
EINTRLOOP(wr, (int)write(wb->sock, wb->data + wb->pos, wb->len - wb->pos));
if (wr <= 0) {
-#if defined(ATHEOS) || defined(DOS)
- /* Workaround for a bug in Syllable */
- if (wr && (errno == EAGAIN || errno == EWOULDBLOCK)) {
- return;
- }
-#endif
setcstate(c, wr ? get_error_from_errno(errno) : S_CANT_WRITE);
retry_connection(c);
return;
diff --git a/default.c b/default.c
@@ -22,25 +22,12 @@ static void get_system_name(void)
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);
safe_strncpy(system_name, str, MAX_STR_LEN);
mem_free(str);
@@ -436,10 +423,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];
@@ -633,22 +616,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);
@@ -656,14 +629,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);
@@ -673,7 +638,6 @@ try_new_count:
}
mem_free(tmp_name);
}
-#endif
return 0;
@@ -686,18 +650,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)
{
struct stat st;
@@ -756,11 +708,6 @@ skip_path_conv:;
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);
@@ -793,22 +740,12 @@ skip_path_conv:;
}
} 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;
}
@@ -821,21 +758,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;
@@ -1011,9 +938,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;
@@ -1204,11 +1128,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);
@@ -1265,11 +1184,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;
@@ -1714,11 +1628,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"
@@ -1882,33 +1792,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"
@@ -2067,14 +1950,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;
@@ -2093,11 +1970,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! */
diff --git a/directfb.c b/directfb.c
@@ -1,838 +0,0 @@
-/* directfb.c
- * DirectFB graphics driver
- * (c) 2002 Sven Neumann <sven@directfb.org>
- *
- * This file is a part of the Links program, released under GPL.
- */
-
-/* TODO:
- * - Store window size as driver params (?)
- * - Fix wrong colors on big-endian systems (fixed?)
- * - Make everything work correctly ;-)
- *
- * KNOWN PROBLEMS:
- * - If mouse drags don't work for you, update DirectFB
- * (the upcoming 0.9.14 release fixes this).
- */
-
-
-#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, ®ion);
-}
-
-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 (!gd || 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
@@ -13,14 +13,6 @@ int support_ipv6;
#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
uttime absolute_time;
diff --git a/dos.c b/dos.c
@@ -1,847 +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;
- }
- if ((unsigned)dos_mouse_queue_n > (unsigned)MAXINT / sizeof(struct links_event) - 1) overalloc();
- 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,4 @@ 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, ¤t_virtual_device->size);
- current_virtual_device->redraw_handler(current_virtual_device, ¤t_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,19 +5,6 @@
#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
#else
@@ -36,152 +23,32 @@ void *do_not_optimize_here(void *p)
return 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,237 +107,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 > MAX_SIZE_T - L_D_S - RED_ZONE_INC) {
- 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 > MAX_SIZE_T - L_D_S - RED_ZONE_INC) {
- 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 > MAX_SIZE_T - L_D_S - RED_ZONE_INC) {
- 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)
{
void *p;
@@ -532,10 +168,6 @@ 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)
{
unsigned char *m;
@@ -551,90 +183,3 @@ 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
@@ -188,16 +188,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;
@@ -209,9 +205,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;
@@ -329,10 +322,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;
}
@@ -438,11 +427,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/framebuf.c b/framebuf.c
@@ -1,1973 +0,0 @@
-/* framebuf.c
- * Linux framebuffer code
- * (c) 2002 Petr 'Brain' Kulhavy
- * This file is a part of the Links program, released under GPL.
- */
-
-#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 = -2;
-
-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_PASTE) goto skip;
- if ((ev->y & (KBD_CTRL | KBD_ALT)) == KBD_ALT && ev->x >= '0' && ev->x <= '9') {
- switch_virtual_device((ev->x - '1' + 10) % 10);
- 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 {
-skip:
- 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 && 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;
- int g;
- Gpm_Event gev;
- again:
- set_handlers(fb_hgpm, (void (*)(void *))NULL, (void (*)(void *))NULL, NULL);
- save_gpm_signals();
- g = Gpm_GetEvent(&gev);
- restore_gpm_signals();
- if (g <= 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 = -2;
- conn.eventMask = (unsigned short)~0U;
- conn.defaultMask = gpm_smooth;
- conn.minMod = 0;
- conn.maxMod = (unsigned short)~0U;
- save_gpm_signals();
- fb_hgpm = Gpm_Open(&conn, 0);
- restore_gpm_signals();
- if (fb_hgpm < 0) {
- fb_hgpm = -2;
- 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);
- if (fb_hgpm >= -1) {
- save_gpm_signals();
- Gpm_Close();
- restore_gpm_signals();
- }
- fb_hgpm = -2;
-#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 *)¶m, 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 *)¶m, 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 *)¶m, 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 *)¶m, 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
- ,¤t_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/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_PASTE) goto skip;
- if (((ev->y & (KBD_CTRL | KBD_ALT)) == KBD_ALT) && ev->x >= '0' && ev->x <= '9') {
- vd = (ev->x - '1' + 10) % 10;
- goto switch_vd;
- }
- if (((ev->y & (KBD_CTRL | KBD_ALT)) == KBD_ALT) && ev->x == '-') {
- vd = 10;
- goto switch_vd;
- }
- if (((ev->y & (KBD_CTRL | KBD_ALT)) == KBD_ALT) && ev->x == '=') {
- vd = 11;
- goto switch_vd;
- }
- if (((ev->y & (KBD_CTRL | KBD_ALT)) == KBD_ALT) && ev->x <= KBD_F1 && ev->x >= KBD_F12) {
- vd = KBD_F1 - ev->x;
- goto switch_vd;
- }
-skip:
- 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, ¤t_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_register_bitmap,
- grx_prepare_strip,
- grx_commit_strip,
- grx_unregister_bitmap,
- grx_draw_bitmap,
- 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
@@ -600,41 +600,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 +608,6 @@ static int get_js_events(unsigned char *a)
{
return 0;
}
-#endif
void *ff;
void (*put_chars_f)(void *, unsigned char *, int);
@@ -2585,9 +2549,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
@@ -556,18 +556,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)
@@ -623,7 +603,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;
@@ -680,7 +659,6 @@ static void put_chars(void *p_, unsigned char *c, int l)
return;
}
} else
-#endif
{
ll = l;
}
@@ -697,11 +675,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));
}
@@ -926,26 +902,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)
@@ -1232,13 +1192,7 @@ void really_format_html(struct cache_entry *ce, unsigned char *start, unsigned c
eofff = end;
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
- );
+ 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, NULL );
if (d_opt->break_long_lines) implicit_pre_wrap = 1;
if (d_opt->plain) *t = 0;
if (screen->opt.plain == 2) {
diff --git a/https.c b/https.c
@@ -98,36 +98,7 @@ static void free_hook(void *ptr file_line_arg)
#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)
diff --git a/img.c b/img.c
@@ -45,19 +45,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);
}
@@ -287,14 +274,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;
if (cimg->strip_optimized){
@@ -799,16 +778,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')
@@ -834,26 +803,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);
@@ -934,22 +884,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);
@@ -969,14 +906,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)
@@ -1315,30 +1244,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
int known_image_type(unsigned char *type)
@@ -1356,14 +1261,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/jsint.c b/jsint.c
@@ -32,3869 +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 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,MSG_BOX_END, /* message */
- (void *)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,MSG_BOX_END, /* message */
- (void *)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),MSG_BOX_END, /* message */
- (void *)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 */
- 2, /* the number of buttons */
- TEXT_(T_OK), /* ok button */
- js_upcall_get_string_ok_pressed,
- TEXT_(T_KILL_SCRIPT), /* cancel button */
- js_upcall_get_string_kill_script_pressed
- );
- 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, void *open_window_, void *ses_)
-{
- int (*open_window)(struct terminal *, unsigned char *, unsigned char *) = *(int (* const *)(struct terminal *, unsigned char *, unsigned char *))open_window_;
- struct session *ses = (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);
- }
-}
-
-static void (* const send_vodevri_v_novym_vokne_ptr)(struct terminal *term, void *open_window_, void *ses_) = send_vodevri_v_novym_vokne;
-
-/* 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, (void *)&send_vodevri_v_novym_vokne_ptr, 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, /* 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,"\".",MSG_BOX_END, /* message */
- (void *)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, (void *)&send_vodevri_v_novym_vokne_ptr, 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, /* alignment */
- TEXT_(T_JS_IS_ATTEMPTING_TO_GO_INTO_HISTORY), txt, TEXT_(T_TO_URL), " \"",url,"\".",MSG_BOX_END, /* message */
- (void *)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)
{
}
@@ -3911,5 +48,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
@@ -137,13 +137,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();
}
@@ -151,13 +149,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();
}
@@ -297,9 +293,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;
@@ -480,16 +473,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)
@@ -955,12 +942,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)
diff --git a/language.c b/language.c
@@ -112,10 +112,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
@@ -143,9 +143,6 @@
#ifdef HAVE_UWIN_H
#include <uwin.h>
#endif
-#ifdef HAVE_INTERIX_INTERIX_H
-#include <interix/interix.h>
-#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
@@ -215,9 +212,6 @@
#if !defined(NO_SSL_CERTIFICATES) && defined(HAVE_OPENSSL_X509V3_H) && defined(HAVE_ASN1_STRING_TO_UTF8)
#define HAVE_SSL_CERTIFICATES
#endif
-#if defined(OPENVMS) && defined(__VAX)
-#define OPENSSL_NO_SHA512
-#endif
#include <openssl/ssl.h>
#include <openssl/rand.h>
@@ -264,7 +258,7 @@
#include <sgtty.h>
#endif
-#if defined(HAVE_POLL_H) && defined(HAVE_POLL) && !defined(INTERIX) && !defined(__HOS_AIX__)
+#if defined(HAVE_POLL_H) && defined(HAVE_POLL) && !defined(__HOS_AIX__)
#define USE_POLL
#include <poll.h>
#endif
@@ -300,14 +294,6 @@
#define ulonglong double
#endif
-#if defined(__INTERIX) && defined(HAVE_STRTOQ)
-extern quad_t
-#if defined(__cdecl) || defined(_MSC_VER)
-__cdecl
-#endif
-strtoq(const char *, char **, int);
-#endif
-
#define stringify_internal(arg) #arg
#define stringify(arg) stringify_internal(arg)
@@ -329,21 +315,12 @@ strtoq(const char *, char **, int);
#define cast_char (char *)
#define cast_uchar (unsigned char *)
-#ifdef OPENVMS
-#define RET_OK 1 /* SS$_NORMAL */
-#define RET_ERROR 3586 /* SS$_LINEABRT */
-#define RET_SIGNAL 2096 /* SS$_CANCEL */
-#define RET_SYNTAX 20 /* SS$_BADPARAM */
-#define RET_FATAL 44 /* SS$_ABORT */
-#define RET_INTERNAL 44 /* SS$_ABORT */
-#else
#define RET_OK 0
#define RET_ERROR 1
#define RET_SIGNAL 2
#define RET_SYNTAX 3
#define RET_FATAL 4
#define RET_INTERNAL 127
-#endif
#ifndef HAVE_SNPRINTF
int my_snprintf(char *, int n, char *format, ...) PRINTF_FORMAT(3, 4);
@@ -557,21 +534,11 @@ extern int F;
/* error.c */
-#if defined(DOS)
-#define ANSI_BELL "\007"
-#define ANSI_SET_BOLD ""
-#define ANSI_CLEAR_BOLD ""
-#else
#define ANSI_BELL "\007"
#define ANSI_SET_BOLD "\033[1m"
#define ANSI_CLEAR_BOLD "\033[0m"
-#endif
-#ifdef LEAK_DEBUG
-extern unsigned alloc_overhead;
-#else
#define alloc_overhead 0
-#endif
void *do_not_optimize_here(void *p);
void init_heap(void);
@@ -849,9 +816,6 @@ long strtolx(unsigned char *c, unsigned char **end);
my_strtoll_t my_strtoll(unsigned char *string, unsigned char **end);
void safe_strncpy(unsigned char *dst, const unsigned char *src, size_t dst_size);
-#ifdef JS
-void skip_nonprintable(unsigned char *txt);
-#endif
/* case insensitive compare of 2 strings */
/* comparison ends after len (or less) characters */
/* return value: 1=strings differ, 0=strings are same */
@@ -956,9 +920,6 @@ void restore_gpm_signals(void);
void *handle_mouse(int, void (*)(void *, unsigned char *, int), void *);
void unhandle_mouse(void *);
void add_gpm_version(unsigned char **s, int *l);
-#ifdef OPENVMS
-extern int vms_thread_high_priority;
-#endif
int start_thread(void (*)(void *, int), void *, int, int);
unsigned char *get_clipboard_text(struct terminal *);
void set_clipboard_text(struct terminal *, unsigned char *);
@@ -996,9 +957,6 @@ int can_open_os_shell(int);
unsigned char *links_xterm(void);
struct open_in_new *get_open_in_new(int);
void set_highpri(void);
-#if defined(OPENVMS) && defined(GRDRV_X)
-int vms_x11_fd(int ef);
-#endif
void os_free_clipboard(void);
@@ -1595,10 +1553,6 @@ void data_func(struct connection *);
void file_func(struct connection *);
-/* finger.c */
-
-void finger_func(struct connection *);
-
/* ftp.c */
#if defined(IP_TOS) && defined(IPTOS_THROUGHPUT)
@@ -1607,10 +1561,6 @@ void finger_func(struct connection *);
void ftp_func(struct connection *);
-/* smb.c */
-
-void smb_func(struct connection *);
-
/* mailto.c */
void magnet_func(struct session *, unsigned char *);
@@ -1701,19 +1651,6 @@ extern unsigned char term_seq[];
extern unsigned char term_seq_x_mouse[];
extern unsigned char term_seq_tw_mouse[];
-#if defined(GRDRV_SVGALIB) || defined(GRDRV_FB) || defined(GRDRV_GRX)
-#define GRDRV_VIRTUAL_DEVICES
-#endif
-
-#ifdef GRDRV_VIRTUAL_DEVICES
-extern int kbd_set_raw;
-struct itrm *handle_svgalib_keyboard(void (*)(struct itrm *, unsigned char *, int));
-void svgalib_free_trm(struct itrm *);
-void svgalib_block_itrm(struct itrm *);
-int svgalib_unblock_itrm(struct itrm *);
-#endif
-
-
struct rgb {
unsigned char r, g, b; /* This is 3*8 bits with sRGB gamma (in sRGB space)
* This is not rounded. */
@@ -1931,16 +1868,6 @@ extern struct graphics_device *current_virtual_device;
void generic_set_clip_area(struct graphics_device *dev, struct rect *r);
-#ifdef GRDRV_VIRTUAL_DEVICES
-int init_virtual_devices(struct graphics_driver *, int);
-struct graphics_device *init_virtual_device(void);
-#define VD_NEXT -1
-void switch_virtual_device(int);
-void shutdown_virtual_device(struct graphics_device *dev);
-void resize_virtual_devices(int x, int y);
-void shutdown_virtual_devices(void);
-#endif
-
/* dip.c */
/* Digital Image Processing utilities
@@ -2134,26 +2061,14 @@ void free_dither(void);
extern unsigned char frame_dumb[];
-#ifndef ENABLE_UTF8
-typedef unsigned char char_t;
-#else
typedef unsigned char_t;
-#endif
typedef struct {
- char_t ch
-#ifdef ENABLE_UTF8
- :24
-#endif
- ;
+ char_t ch :24;
unsigned char at;
} chr;
-#ifdef ENABLE_UTF8
#define chr_has_padding (sizeof(chr) != 4)
-#else
-#define chr_has_padding (sizeof(chr) != 2)
-#endif
struct links_event {
int ev;
@@ -2245,10 +2160,8 @@ struct terminal {
int last_mouse_y;
int last_mouse_b;
#endif
-#if defined(G) || defined(ENABLE_UTF8)
unsigned char utf8_buffer[7];
int utf8_paste_mode;
-#endif
list_entry_last
};
@@ -2376,9 +2289,6 @@ extern int current_language;
void init_trans(void);
void shutdown_trans(void);
-#if defined(OS2) || defined(DOS)
-int get_country_language(int c);
-#endif
int get_language_from_lang(unsigned char *);
int get_default_charset(void);
int get_commandline_charset(void);
@@ -2389,24 +2299,8 @@ void set_language(void);
#define TEXT_(x) (dummyarray + x) /* TEXT causes name clash on windows */
/* dos.c */
-
-#ifdef DOS
-void dos_poll_break(void);
-void dos_mouse_terminate(void);
-void dos_save_screen(void);
-void dos_restore_screen(void);
-int dos_is_bw(void);
-#else
-#define dos_poll_break() do { } while (0)
-#endif
-
-/* grx.c */
-
-#ifdef GRDRV_GRX
-extern int grx_mouse_initialized;
-void grx_mouse_poll(void);
-int grx_mouse_event(void);
-#endif
+/* Used in error.c */
+#define dos_poll_break() do { } while (0)
/* af_unix.c */
@@ -2586,9 +2480,6 @@ struct form_state {
int state; /* index of selected item of a select item */
int vpos;
int vypos;
-#ifdef JS
- int changed; /* flag if form element has changed --- for onchange handler */
-#endif
};
struct js_event_spec;
@@ -2770,9 +2661,6 @@ struct frameset_desc {
int n; /* = x * y */
int x, y; /* velikost */
int xp, yp; /* pozice pri pridavani */
-#ifdef JS
- unsigned char *onload_code;
-#endif
struct frame_desc f[1];
};
@@ -2893,14 +2781,6 @@ struct g_object_tag {
#define IM_JPG 3
#endif /* #ifdef HAVE_JPEG */
-#ifdef HAVE_TIFF
-#define IM_TIFF 4
-#endif /* #ifdef HAVE_TIFF */
-
-#ifdef HAVE_SVG
-#define IM_SVG 5
-#endif /* #ifdef HAVE_SVG */
-
#define MEANING_DIMS 0
#define MEANING_AUTOSCALE 1
struct cached_image {
@@ -3032,23 +2912,7 @@ void refresh_image(struct f_data_c *fd, struct g_object *img, uttime tm);
struct additional_file *request_additional_file(struct f_data *f, unsigned char *url);
struct js_event_spec {
-#ifdef JS
- unsigned char *move_code;
- unsigned char *over_code;
- unsigned char *out_code;
- unsigned char *down_code;
- unsigned char *up_code;
- unsigned char *click_code;
- unsigned char *dbl_code;
- unsigned char *blur_code;
- unsigned char *focus_code;
- unsigned char *change_code;
- unsigned char *keypress_code;
- unsigned char *keyup_code;
- unsigned char *keydown_code;
-#else
char dummy;
-#endif
};
/*
@@ -3103,10 +2967,6 @@ struct f_data {
struct line *data;
struct link *links;
int nlinks;
-#ifdef JS
- struct js_event_spec **link_events;
- int nlink_events;
-#endif
struct link **lines1;
struct link **lines2;
struct list_head nodes; /* struct node */
@@ -3120,20 +2980,12 @@ struct f_data {
struct list_head forms; /* struct form_control */
struct list_head tags; /* struct tag */
-#ifdef JS
- int are_there_scripts;
- unsigned char *script_href_base;
-#endif
unsigned char *refresh;
int refresh_seconds;
int uncacheable; /* cannot be cached - either created from source modified by document.write or modified by javascript */
-#ifdef JS
- struct js_event_spec *js_event;
-#endif
-
/* graphics only */
#ifdef G
struct g_object *root;
@@ -3220,17 +3072,10 @@ struct f_data_c {
int marginwidth, marginheight;
-#ifdef JS
- struct js_state *js;
-#endif
-
struct timer *image_timer;
struct timer *refresh_timer;
-#ifdef JS
- unsigned char *onload_frameset_code;
-#endif
unsigned char scrolling;
unsigned char last_captured;
@@ -3324,14 +3169,6 @@ struct session {
unsigned char *imgmap_href_base;
unsigned char *imgmap_target_base;
-#ifdef JS
- unsigned char *defered_url;
- unsigned char *defered_target;
- struct f_data_c *defered_target_base;
- int defered_data; /* for submit: form number, jinak -1 */
- tcount defered_seq;
-#endif
-
int brl_cursor_mode;
#ifdef G
@@ -3410,195 +3247,8 @@ unsigned char *get_current_title(struct f_data_c *, unsigned char *, size_t);
/*unsigned char *get_current_link_url(struct session *, unsigned char *, size_t);*/
unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form_control *form, int *onsubmit);
-/* js.c */
-
-#ifdef JS
-struct javascript_context *js_create_context(void *, long);
-void js_destroy_context(struct javascript_context *);
-void js_execute_code(struct javascript_context *, unsigned char *, int, void (*)(void *));
-#endif
-
/* jsint.c */
-#ifdef JS
-
-#define JS_OBJ_MASK 255
-#define JS_OBJ_MASK_SIZE 8
-
-#define JS_OBJ_T_UNKNOWN 0
-#define JS_OBJ_T_DOCUMENT 1
-#define JS_OBJ_T_FRAME 2 /* document a frame se tvari pro mne stejne --Brain */
-#define JS_OBJ_T_LINK 3
-#define JS_OBJ_T_FORM 4
-#define JS_OBJ_T_ANCHOR 5
-#define JS_OBJ_T_IMAGE 6
-/* form elements */
-#define JS_OBJ_T_TEXT 7
-#define JS_OBJ_T_PASSWORD 8
-#define JS_OBJ_T_TEXTAREA 9
-#define JS_OBJ_T_CHECKBOX 10
-#define JS_OBJ_T_RADIO 11
-#define JS_OBJ_T_SELECT 12
-#define JS_OBJ_T_SUBMIT 13
-#define JS_OBJ_T_RESET 14
-#define JS_OBJ_T_HIDDEN 15
-#define JS_OBJ_T_BUTTON 16
-
-extern long js_zaflaknuto_pameti;
-
-extern struct history js_get_string_history;
-extern int js_manual_confirmation;
-
-struct js_state {
- struct javascript_context *ctx; /* kontext beziciho javascriptu??? */
- struct list_head queue; /* struct js_request - list of javascripts to run */
- struct js_request *active; /* request is running */
- unsigned char *src; /* zdrojak beziciho javascriptu??? */ /* mikulas: ne. to je zdrojak stranky */
- int srclen;
- int wrote;
- int newdata;
-};
-
-
-/* funkce js_get_select_options vraci pole s temito polozkami */
-struct js_select_item{
- /* index je poradi v poli, ktere vratim, takze se tu nemusi skladovat */
- int default_selected;
- int selected;
- unsigned char *text; /* text, ktery se zobrazuje */
- unsigned char *value; /* value, ktera se posila */
-};
-
-struct fax_me_tender_string{
- void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
- unsigned char *string;
-};
-
-struct fax_me_tender_int_string{
- void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
- int num;
- unsigned char *string;
-};
-
-struct fax_me_tender_string_2_longy{
- void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
- unsigned char *string;
- long doc_id,obj_id;
-};
-
-struct fax_me_tender_2_stringy{
- void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
- unsigned char *string1;
- unsigned char *string2;
-};
-
-struct fax_me_tender_nothing{
- void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
-};
-
-extern tcount jsint_execute_seq;
-
-void javascript_func(struct session *ses, unsigned char *code);
-void jsint_run_queue(struct f_data_c *);
-long *jsint_resolve(void *context, long obj_id, char *takhle_tomu_u_nas_nadavame,int *n_items);
-int jsint_object_type(long);
-void jsint_set_cookies(struct f_data_c *fd, int final_flush);
-struct f_data_c *jsint_find_document(long doc_id);
-
-void js_upcall_document_write(void *p, unsigned char *str, int len);
-void js_upcall_alert(void *struct_fax_me_tender_string);
-unsigned char *js_upcall_get_title(void *data);
-void js_upcall_set_title(void *data, unsigned char *title);
-unsigned char *js_upcall_get_location(void *data);
-unsigned char *js_upcall_get_useragent(void *data);
-void js_upcall_confirm(void *struct_fax_me_tender_string);
-void js_upcall_get_string(void *data);
-unsigned char *js_upcall_get_referrer(void *data);
-unsigned char *js_upcall_get_appname(void);
-unsigned char *js_upcall_get_appcodename(void);
-unsigned char *js_upcall_get_appversion(void);
-long js_upcall_get_document_id(void *data);
-long js_upcall_get_window_id(void *data);
-void js_upcall_close_window(void *struct_fax_me_tender_nothing);
-unsigned char *js_upcall_document_last_modified(void *data, long document_id);
-unsigned char *js_upcall_get_window_name(void *data);
-void js_upcall_clear_window(void *);
-long *js_upcall_get_links(void *data, long document_id, int *len);
-unsigned char *js_upcall_get_link_target(void *data, long document_id, long link_id);
-long *js_upcall_get_forms(void *data, long document_id, int *len);
-unsigned char *js_upcall_get_form_action(void *data, long document_id, long form_id);
-unsigned char *js_upcall_get_form_target(void *data, long document_id, long form_id);
-unsigned char *js_upcall_get_form_method(void *data, long document_id, long form_id);
-unsigned char *js_upcall_get_form_encoding(void *data, long document_id, long form_id);
-unsigned char *js_upcall_get_location_protocol(void *data);
-unsigned char *js_upcall_get_location_port(void *data);
-unsigned char *js_upcall_get_location_hostname(void *data);
-unsigned char *js_upcall_get_location_host(void *data);
-unsigned char *js_upcall_get_location_pathname(void *data);
-unsigned char *js_upcall_get_location_search(void *data);
-unsigned char *js_upcall_get_location_hash(void *data);
-long *js_upcall_get_form_elements(void *data, long document_id, long form_id, int *len);
-long *js_upcall_get_anchors(void *hej_Hombre, long document_id, int *len);
-int js_upcall_get_checkbox_radio_checked(void *smirak, long document_id, long radio_tv_id);
-void js_upcall_set_checkbox_radio_checked(void *smirak, long document_id, long radio_tv_id, int value);
-int js_upcall_get_checkbox_radio_default_checked(void *smirak, long document_id, long radio_tv_id);
-void js_upcall_set_checkbox_radio_default_checked(void *smirak, long document_id, long radio_tv_id, int value);
-unsigned char *js_upcall_get_form_element_name(void *smirak, long document_id, long ksunt_id);
-void js_upcall_set_form_element_name(void *smirak, long document_id, long ksunt_id, unsigned char *name);
-unsigned char *js_upcall_get_form_element_default_value(void *smirak, long document_id, long ksunt_id);
-void js_upcall_set_form_element_default_value(void *smirak, long document_id, long ksunt_id, unsigned char *name);
-void js_upcall_set_form_element_event_handler(void *bidak, long document_id, long ksunt_id, long typ, unsigned char *name);
-unsigned char *js_upcall_get_form_element_value(void *smirak, long document_id, long ksunt_id);
-void js_upcall_set_form_element_value(void *smirak, long document_id, long ksunt_id, unsigned char *name);
-void js_upcall_click(void *smirak, long document_id, long elem_id);
-void js_upcall_focus(void *smirak, long document_id, long elem_id);
-void js_upcall_blur(void *smirak, long document_id, long elem_id);
-void js_upcall_submit(void *bidak, long document_id, long form_id);
-void js_upcall_reset(void *bidak, long document_id, long form_id);
-int js_upcall_get_radio_length(void *smirak, long document_id, long radio_id); /* radio.length */
-int js_upcall_get_select_length(void *smirak, long document_id, long select_id); /* select.length */
-int js_upcall_get_select_index(void *smirak, long document_id, long select_id); /* select.selectedIndex */
-struct js_select_item* js_upcall_get_select_options(void *smirak, long document_id, long select_id, int *n);
-void js_upcall_goto_url(void* struct_fax_me_tender_string);
-int js_upcall_get_history_length(void *context);
-void js_upcall_goto_history(void* data);
-void js_upcall_set_default_status(void *context, unsigned char *tak_se_ukaz_Kolbene);
-unsigned char *js_upcall_get_default_status(void *context);
-void js_upcall_set_status(void *context, unsigned char *tak_se_ukaz_Kolbene);
-unsigned char *js_upcall_get_status(void *context);
-unsigned char *js_upcall_get_cookies(void *context);
-long *js_upcall_get_images(void *smirak, long document_id, int *len);
-long * js_upcall_get_all(void *context, long document_id, int *len);
-int js_upcall_get_image_width(void *smirak, long document_id, long image_id);
-int js_upcall_get_image_height(void *smirak, long document_id, long image_id);
-int js_upcall_get_image_border(void *smirak, long document_id, long image_id);
-int js_upcall_get_image_vspace(void *smirak, long document_id, long image_id);
-int js_upcall_get_image_hspace(void *smirak, long document_id, long image_id);
-unsigned char *js_upcall_get_image_name(void *smirak, long document_id, long image_id);
-unsigned char *js_upcall_get_image_alt(void *smirak, long document_id, long image_id);
-void js_upcall_set_image_name(void *smirak, long document_id, long image_id, unsigned char *name);
-void js_upcall_set_image_alt(void *smirak, long document_id, long image_id, unsigned char *alt);
-unsigned char *js_upcall_get_image_src(void *smirak, long document_id, long image_id);
-void js_upcall_set_image_src(void *chuligane);
-int js_upcall_image_complete(void *smirak, long document_id, long image_id);
-long js_upcall_get_parent(void *smirak, long frame_id);
-long js_upcall_get_frame_top(void *smirak, long frame_id);
-long * js_upcall_get_subframes(void *smirak, long frame_id, int *count);
-void js_upcall_set_form_action(void *context, long document_id, long form_id, unsigned char *action);
-
-
-void js_downcall_vezmi_true(void *context);
-void js_downcall_vezmi_false(void *context);
-void js_downcall_vezmi_null(void *context);
-void js_downcall_game_over(void *context);
-void js_downcall_quiet_game_over(void *context);
-void js_downcall_vezmi_int(void *context, int i);
-void js_downcall_vezmi_float(void*context,double f);
-/*void js_downcall_vezmi_float(void *context, float f);*/
-void js_downcall_vezmi_string(void *context, unsigned char *string);
-
-#endif
-
void jsint_execute_code(struct f_data_c *, unsigned char *, int, int, int, int, struct links_event *);
void jsint_destroy(struct f_data_c *);
void jsint_scan_script_tags(struct f_data_c *);
@@ -3948,11 +3598,9 @@ static inline int utf8chrlen(unsigned char c)
static inline unsigned GET_TERM_CHAR(struct terminal *term, unsigned char **str)
{
unsigned ch;
-#if defined(G) || defined(ENABLE_UTF8)
if (term_charset(term) == utf8_table)
GET_UTF_8(*str, ch);
else
-#endif
ch = *(*str)++;
return ch;
}
@@ -4060,38 +3708,10 @@ void add_png_version(unsigned char **s, int *l);
#endif /* #ifdef G */
-/* tiff.c */
-
-#if defined(G) && defined(HAVE_TIFF)
-
-void tiff_start(struct cached_image *cimg);
-void tiff_restart(struct cached_image *cimg, unsigned char *data, int length);
-void tiff_finish(struct cached_image *cimg);
-void tiff_destroy_decoder(struct cached_image *cimg);
-
-void add_tiff_version(unsigned char **s, int *l);
-
-#endif /* #if defined(G) && defined(HAVE_TIFF) */
-
/* svg.c */
-#if defined(G) && defined(HAVE_SVG)
-
-void spawn_font_thread(void);
-
-void svg_start(struct cached_image *cimg);
-void svg_restart(struct cached_image *cimg, unsigned char *data, int length);
-void svg_finish(struct cached_image *cimg);
-void svg_destroy_decoder(struct cached_image *cimg);
-
-void add_svg_version(unsigned char **s, int *l);
-
-#else
-
#define spawn_font_thread() do { } while (0)
-#endif
-
/* img.c */
#ifdef G
@@ -4467,10 +4087,8 @@ struct part {
int spl;
int link_num;
struct list_head uf;
-#ifdef ENABLE_UTF8
unsigned char utf8_part[7];
unsigned char utf8_part_len;
-#endif
};
#ifdef G
@@ -4723,14 +4341,6 @@ extern unsigned char download_dir[];
#define SCRUB_HEADERS (proxies.only_proxies || http_options.header.fake_firefox)
-#ifdef JS
-extern int js_enable;
-extern int js_verbose_errors;
-extern int js_verbose_warnings;
-extern int js_all_conversions;
-extern int js_global_resolve;
-#endif
-
extern double display_red_gamma,display_green_gamma,display_blue_gamma;
extern double user_gamma;
extern double bfu_aspect;
diff --git a/menu.c b/menu.c
@@ -24,9 +24,6 @@ static unsigned char * const version_texts[] = {
#ifdef OS2
TEXT_(T_XTERM_FOR_OS2),
#endif
-#ifdef JS
- TEXT_(T_JAVASCRIPT),
-#endif
TEXT_(T_GRAPHICS_MODE),
#ifdef G
TEXT_(T_IMAGE_LIBRARIES),
@@ -135,11 +132,7 @@ static void menu_version(void *term_)
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)
@@ -162,12 +155,6 @@ static void menu_version(void *term_)
add_to_str(&s, &l, cast_uchar "\n");
#endif
-#ifdef JS
- add_and_pad(&s, &l, term, *text_ptr++, maxlen);
- add_to_str(&s, &l, get_text_translation(TEXT_(T_YES), term));
- add_to_str(&s, &l, cast_uchar "\n");
-#endif
-
add_and_pad(&s, &l, term, *text_ptr++, maxlen);
#ifdef G
i = l;
@@ -185,14 +172,6 @@ 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
@@ -564,13 +543,6 @@ static int memory_info(struct terminal *term, struct refresh *r2)
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);
@@ -678,9 +650,6 @@ static void downloads_menu(struct terminal *term, void *ddd, void *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)
@@ -828,13 +797,7 @@ static void charset_sel_list(struct terminal *term, int ini, void (*set)(struct
static void charset_list(struct terminal *term, void *xxx, void *ses_)
{
- charset_sel_list(term, term->spec->character_set, set_display_codepage, NULL,
-#ifdef ENABLE_UTF8
- 1
-#else
- 0
-#endif
- , 1);
+ charset_sel_list(term, term->spec->character_set, set_display_codepage, NULL, 1, 1);
}
static void terminal_options_ok(void *p)
@@ -1025,123 +988,6 @@ static void screen_margins(struct terminal *term, void *xxx, void *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, void *ses_)
-{
- struct session *ses = (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
static inline void reinit_video(void) { }
@@ -1615,13 +1461,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;
@@ -2341,39 +2182,6 @@ static void dlg_ftp_options(struct terminal *term, void *xxx, void *yyy)
do_dialog(term, d, getml(d, NULL));
}
-#ifndef DISABLE_SMB
-
-static unsigned char * const smb_labels[] = { TEXT_(T_ALLOW_HYPERLINKS_TO_SMB), NULL };
-
-static void dlg_smb_options(struct terminal *term, void *xxx, void *yyy)
-{
- int a;
- struct dialog *d;
- d = mem_calloc(sizeof(struct dialog) + 3 * sizeof(struct dialog_item));
- d->title = TEXT_(T_SMB_OPTIONS);
- d->fn = checkbox_list_fn;
- d->udata = (void *)smb_labels;
- a=0;
- d->items[a].type = D_CHECKBOX;
- d->items[a].gid = 0;
- d->items[a].dlen = sizeof(int);
- d->items[a].data = (void*)&smb_options.allow_hyperlinks_to_smb;
- a++;
- d->items[a].type = D_BUTTON;
- d->items[a].gid = B_ENTER;
- d->items[a].fn = ok_dialog;
- d->items[a].text = TEXT_(T_OK);
- a++;
- d->items[a].type = D_BUTTON;
- d->items[a].gid = B_ESC;
- d->items[a].fn = cancel_dialog;
- d->items[a].text = TEXT_(T_CANCEL);
- a++;
- d->items[a].type = D_END;
- do_dialog(term, d, getml(d, NULL));
-}
-
-#endif
static unsigned char * const prg_msg[] = {
TEXT_(T_MAILTO_PROG),
@@ -2723,11 +2531,7 @@ static int dlg_assume_cp(struct dialog_data *dlg, struct dialog_item_data *di)
static int dlg_kb_cp(struct dialog_data *dlg, struct dialog_item_data *di)
{
charset_sel_list(dlg->win->term, *(int *)di->cdata, set_val, (void *)di->cdata,
-#ifdef DOS
- 0
-#else
1
-#endif
, 1);
return 0;
}
@@ -3580,9 +3384,6 @@ static_const struct menu_item net_options_menu[] = {
#endif
{ TEXT_(T_HTTP_OPTIONS), cast_uchar "", TEXT_(T_HK_HTTP_OPTIONS), dlg_http_options, NULL, 0, 0 },
{ TEXT_(T_FTP_OPTIONS), cast_uchar "", TEXT_(T_HK_FTP_OPTIONS), dlg_ftp_options, NULL, 0, 0 },
-#ifndef DISABLE_SMB
- { TEXT_(T_SMB_OPTIONS), cast_uchar "", TEXT_(T_HK_SMB_OPTIONS), dlg_smb_options, NULL, 0, 0 },
-#endif
{ NULL, NULL, 0, NULL, NULL, 0, 0 }
};
@@ -3596,9 +3397,6 @@ static_const struct menu_item net_options_ipv6_menu[] = {
#endif
{ TEXT_(T_HTTP_OPTIONS), cast_uchar "", TEXT_(T_HK_HTTP_OPTIONS), dlg_http_options, NULL, 0, 0 },
{ TEXT_(T_FTP_OPTIONS), cast_uchar "", TEXT_(T_HK_FTP_OPTIONS), dlg_ftp_options, NULL, 0, 0 },
-#ifndef DISABLE_SMB
- { TEXT_(T_SMB_OPTIONS), cast_uchar "", TEXT_(T_HK_SMB_OPTIONS), dlg_smb_options, NULL, 0, 0 },
-#endif
{ NULL, NULL, 0, NULL, NULL, 0, 0 }
};
#endif
@@ -3642,9 +3440,6 @@ static_const struct menu_item setup_menu_6[] = {
};
static_const struct menu_item setup_menu_7[] = {
-#ifdef JS
- { TEXT_(T_JAVASCRIPT_OPTIONS), cast_uchar "", TEXT_(T_HK_JAVASCRIPT_OPTIONS), javascript_options, NULL, 0, 1 },
-#endif
{ TEXT_(T_CACHE), cast_uchar "", TEXT_(T_HK_CACHE), cache_opt, NULL, 0, 1 },
{ TEXT_(T_MAIL_AND_TELNEL), cast_uchar "", TEXT_(T_HK_MAIL_AND_TELNEL), net_programs, NULL, 0, 1 },
{ TEXT_(T_ASSOCIATIONS), cast_uchar "", TEXT_(T_HK_ASSOCIATIONS), menu_assoc_manager, NULL, 0, 1 },
@@ -3987,8 +3782,4 @@ void free_history_lists(void)
free_history(goto_url_history);
free_history(file_history);
free_history(search_history);
-#ifdef JS
- free_history(js_get_string_history); /* is in jsint.c */
-#endif
}
-
diff --git a/os_dep.c b/os_dep.c
@@ -9,220 +9,11 @@
#include <sys/ioctl.h>
#endif
-#ifdef USE_GPM
-#include <gpm.h>
-#endif
-
-#ifdef WIN
-#include <windows.h>
-#endif
-
-#if defined(__CYGWIN__) && defined(HAVE_LOCALE_H)
-#include <locale.h>
-#ifdef HAVE_LANGINFO_H
-#include <langinfo.h>
-#endif
-
-#endif
-
#ifdef HAVE_PTHREADS
#include <pthread.h>
#endif
-#ifdef OS2
-
-#define INCL_MOU
-#define INCL_VIO
-#define INCL_DOSPROCESS
-#define INCL_DOSERRORS
-#define INCL_DOSMODULEMGR
-#define INCL_DOSMISC
-#define INCL_DOSNLS
-#define INCL_WIN
-#define INCL_WINCLIPBOARD
-#define INCL_WINSWITCHLIST
-#include <os2.h>
-#include <io.h>
-#include <process.h>
-#include <sys/video.h>
-#ifdef HAVE_SYS_FMUTEX_H
-#include <sys/builtin.h>
-#include <sys/fmutex.h>
-#endif
-
-#ifdef X2
-/* from xf86sup - XFree86 OS/2 support driver */
-#include <pty.h>
-#endif
-
-#endif
-
-#ifdef OS2
-
-/* The process crashes if we write to console from high address - so we must
- * never do it.
- * TCP/IP 4.0 returns EFAULT if we do I/O to/from high address - we test for
- * EFAULT and retry with a bounce buffer. */
-
-#define BOUNCE_BUFFER_SIZE 256
-
-int bounced_read(int fd, void *buf, size_t size)
-{
- unsigned char *bounce_buffer;
- size_t xsiz;
- int r;
- if (fd < 3 && (unsigned long)buf + size > 0x20000000) goto bounce;
- r = _read(fd, buf, size);
- if (r == -1 && errno == EFAULT) goto bounce;
- return r;
- bounce:
- xsiz = size > BOUNCE_BUFFER_SIZE ? BOUNCE_BUFFER_SIZE : size;
- bounce_buffer = alloca(xsiz);
- r = _read(fd, bounce_buffer, xsiz);
- if (r > 0) memcpy(buf, bounce_buffer, r);
- return r;
-}
-
-int bounced_write(int fd, const void *buf, size_t size)
-{
- unsigned char *bounce_buffer;
- size_t xsiz;
- int r;
- if (fd < 3 && (unsigned long)buf + size > 0x20000000) goto bounce;
- r = _write(fd, buf, size);
- if (r == -1 && errno == EFAULT) goto bounce;
- return r;
- bounce:
- xsiz = size > BOUNCE_BUFFER_SIZE ? BOUNCE_BUFFER_SIZE : size;
- bounce_buffer = alloca(xsiz);
- memcpy(bounce_buffer, buf, xsiz);
- return _write(fd, bounce_buffer, xsiz);
-}
-
-#endif
-
-#ifdef OS2_ADVANCED_HEAP
-
-#include <umalloc.h>
-
-#ifndef OBJ_ANY
-#define OBJ_ANY 0x0400
-#endif
-
-unsigned long mem_requested = 0;
-unsigned long blocks_requested = 0;
-
-static int dosallocmem_attrib = PAG_READ | PAG_WRITE | PAG_COMMIT;
-
-#define HEAP_ALIGN 0x10000
-#define HEAP_PAD 2
-#define HEAP_MAXPAD 0x1000000
-#define HEAP_IMMEDIATE_RELEASE 0x100000
-
-static void heap_release(Heap_t h, void *ptr, size_t len)
-{
- int rc;
- mem_requested -= ((len | 4095) + 1);
- blocks_requested--;
- rc = DosFreeMem(ptr);
- /*fprintf(stderr, "heap free %p -> %d\n", ptr, rc);*/
- if (rc) {
- fatal_exit("DosFreeMem failed: %d", rc);
- }
-}
-
-static void *heap_alloc(Heap_t h, size_t *size, int *pclean)
-{
- void *result;
- int rc;
- /* If we rounded up to page size, EMX would join all allocations
- * to one segment and refuse to free memory. So round up to
- * page size - 1 */
- size_t real_size = *size;
- if (real_size < HEAP_MAXPAD / HEAP_PAD) {
- real_size *= HEAP_PAD;
- real_size = real_size | (HEAP_ALIGN - 1);
- } else {
- real_size |= 1;
- }
- rc = DosAllocMem(&result, real_size, dosallocmem_attrib);
- /*fprintf(stderr, "heap alloc %d -> %p, %d\n", *size, result, rc);*/
- if (!rc) {
- /*
- * Hitting the shared arena has a negative impact on the whole
- * system. Therefore, we fake failure (so that Links frees
- * some caches) and try allocating near the shared arena only
- * as a last resort.
- */
- if ((unsigned long)result >= 0x12000000 &&
- (unsigned long)result < 0x20000000) {
- if (!malloc_try_hard) {
- heap_release(NULL, result, real_size);
- return NULL;
- }
- }
- *size = real_size;
- *pclean = _BLOCK_CLEAN;
- mem_requested += ((real_size | 4095) + 1);
- blocks_requested++;
- return result;
- } else {
- return NULL;
- }
-}
-
-static void init_os2_heap(void)
-{
- Heap_t new_heap;
- size_t init_size = _HEAP_MIN_SIZE;
- void *init_mem;
- int init_clean;
- dosallocmem_attrib |= OBJ_ANY;
- init_mem = heap_alloc(NULL, &init_size, &init_clean);
- if (!init_mem) {
- dosallocmem_attrib &= ~OBJ_ANY;
- init_mem = heap_alloc(NULL, &init_size, &init_clean);
- if (!init_mem) {
- return;
- }
- }
- new_heap = _ucreate(init_mem, init_size, init_clean, _HEAP_REGULAR, heap_alloc, heap_release);
- if (!new_heap) {
- heap_release(NULL, init_mem, init_size);
- return;
- }
- if (_uopen(new_heap) == -1) {
-#if defined(HAVE__UDESTROY) && defined(_FORCE)
- _udestroy(new_heap, _FORCE);
-#else
- heap_release(NULL, init_mem, init_size);
-#endif
- return;
- }
- _udefault(new_heap);
-}
-
-void mem_freed_large(size_t size)
-{
-#if defined(HAVE__HEAPMIN)
- if (size >= HEAP_IMMEDIATE_RELEASE)
- _heapmin();
-#endif
-}
-
-#endif
-
-
-#ifdef OS2
-static int os2_full_screen = 0;
-static int os2_detached = 0;
-static PTIB os2_tib = NULL;
-PPIB os2_pib = NULL;
-static HSWITCH os2_switchhandle = NULLHANDLE;
-#ifdef HAVE_SYS_FMUTEX_H
-static _fmutex fd_mutex;
-#endif
-#elif defined(HAVE_PTHREADS)
+#if defined(HAVE_PTHREADS)
static pthread_mutex_t pth_mutex;
static void fd_lock(void);
static void fd_unlock(void);
@@ -235,7 +26,6 @@ static void fd_init(void)
}
#endif
-#if !defined(OPENVMS) && !defined(DOS)
void init_os(void)
{
/* Disable per-thread heap */
@@ -246,19 +36,7 @@ void init_os(void)
mallopt(M_ARENA_MAX, 1);
#endif
-#ifdef OS2
- DosGetInfoBlocks(&os2_tib, &os2_pib);
- if (os2_pib) {
- os2_switchhandle = WinQuerySwitchHandle(0, os2_pib->pib_ulpid);
- os2_full_screen = os2_pib->pib_ultype == 0;
- os2_detached = os2_pib->pib_ultype == 4;
- if (os2_pib->pib_ultype == 3) force_g = 1;
- }
-#ifdef HAVE_SYS_FMUTEX_H
- if (_fmutex_create(&fd_mutex, 0))
- fatal_exit("failed to create fd mutex");
-#endif
-#elif defined(HAVE_PTHREADS)
+#if defined(HAVE_PTHREADS)
{
int r;
fd_init();
@@ -267,55 +45,7 @@ void init_os(void)
fatal_exit("pthread_atfork failed: %s", strerror(r));
}
#endif
-
-#ifdef OS2_ADVANCED_HEAP
- init_os2_heap();
-#endif
-
-#ifdef WIN
- if (!GetConsoleCP())
- force_g = 1;
-#if defined(__CYGWIN__) && defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
- {
- unsigned char *l = cast_uchar setlocale(LC_CTYPE, "");
- if (!l || !casestrcmp(l, cast_uchar "C")) {
- setlocale(LC_CTYPE, "en_US.utf-8");
- }
- }
-#endif
-#if defined(__CYGWIN__)
- /*
- * When started from cmd.exe and the argument contains some characters
- * not valid in the current locale, cygwin doesn't remove the quotation
- * marks around the argument. So, we must remove the quotation marks
- * here.
- */
- if (getppid() == 1) {
- int i;
- for (i = 1; i < g_argc; i++) {
- unsigned char *a = g_argv[i];
- int l = (int)strlen(cast_const_char a);
- if (l >= 3 && a[0] == '"' && a[l - 1] == '"') {
- unsigned char *a2 = cast_uchar strdup(cast_const_char (a + 1));
- if (a2) {
- unsigned char *p, *q;
- a2[l - 2] = 0;
- for (p = q = a2; *p; p++) {
- if (p[0] == '\\' && p[1] == '"')
- continue;
- *q++ = *p;
- }
- *q = 0;
- g_argv[i] = a2;
- }
- }
- }
- }
-#endif
-#endif
}
-#endif
-
int is_safe_in_shell(unsigned char c)
{
@@ -392,12 +122,6 @@ void ignore_signals(void)
#ifdef SIGXFSZ
do_signal(SIGXFSZ, SIG_IGN);
#endif
-#ifdef OPENVMS
-#ifdef SIGCHLD
- do_signal(SIGCHLD, SIG_IGN);
-#endif
- do_signal(SIGINT, SIG_IGN);
-#endif
}
uttime get_absolute_time(void)
@@ -411,23 +135,6 @@ uttime get_absolute_time(void)
uttime get_time(void)
{
-#if defined(OS2) || defined(WIN)
- static unsigned last_tim = 0;
- static uttime add = 0;
- unsigned tim;
-#if defined(OS2)
- int rc;
- rc = DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &tim, sizeof tim);
- if (rc) fatal_exit("DosQuerySysInfo failed: %d", rc);
-#elif defined(WIN)
- tim = GetTickCount();
-#endif
- if (tim < last_tim) {
- add += (uttime)1 << 31 << 1;
- }
- last_tim = tim;
- return tim | add;
-#else
#if defined(HAVE_CLOCK_GETTIME) && defined(TIME_WITH_SYS_TIME) && (defined(CLOCK_MONOTONIC_RAW) || defined(CLOCK_MONOTONIC))
struct timespec ts;
int rs;
@@ -441,10 +148,8 @@ uttime get_time(void)
#endif
#endif
return get_absolute_time();
-#endif
}
-
static unsigned char *clipboard = NULL;
void os_free_clipboard(void)
@@ -454,40 +159,6 @@ void os_free_clipboard(void)
/* Terminal size */
-#if defined(WIN) || defined(OPENVMS)
-
-/* Cygwin has a bug and loses SIGWINCH sometimes, so poll it */
-
-static void winch_thread(void *p, int l)
-{
- static int old_xsize, old_ysize;
- static int cur_xsize, cur_ysize;
- if (get_terminal_size(1, &old_xsize, &old_ysize)) return;
- while (1) {
- if (get_terminal_size(1, &cur_xsize, &cur_ysize)) return;
- if ((old_xsize != cur_xsize) || (old_ysize != cur_ysize)) {
- int rr;
- old_xsize = cur_xsize;
- old_ysize = cur_ysize;
- EINTRLOOP(rr, raise(SIGWINCH));
- }
- sleep(1);
- }
-}
-
-static void terminal_resize_poll(void)
-{
- static int winch_thread_running = 0;
- if (!winch_thread_running) {
- if (start_thread(winch_thread, NULL, 0, 0) >= 0)
- winch_thread_running = 1;
- }
-}
-
-#endif
-
-#if defined(UNIX) || defined(WIN) || defined(INTERIX) || defined(BEOS) || defined(RISCOS) || defined(ATHEOS) || defined(SPAD) || defined(OPENVMS)
-
#ifdef SIGWINCH
static void sigwinch(void *s)
{
@@ -500,13 +171,6 @@ void handle_terminal_resize(int fd, void (*fn)(void))
#ifdef SIGWINCH
install_signal_handler(SIGWINCH, sigwinch, (void *)fn, 0);
#endif
-#ifdef WIN
- terminal_resize_poll();
-#endif
-#ifdef OPENVMS
- if (is_xterm())
- terminal_resize_poll();
-#endif
}
void unhandle_terminal_resize(int fd)
@@ -516,8 +180,6 @@ void unhandle_terminal_resize(int fd)
#endif
}
-#if !defined(OPENVMS)
-
int get_terminal_size(int fd, int *x, int *y)
{
int rs = -1;
@@ -546,136 +208,7 @@ int get_terminal_size(int fd, int *x, int *y)
return 0;
}
-#endif
-
-#elif defined(OS2)
-
-#define A_DECL(type, var) type var##1, var##2, *var = _THUNK_PTR_STRUCT_OK(&var##1) ? &var##1 : &var##2
-
-int is_xterm(void)
-{
- static int xt = -1;
- if (xt == -1) xt = !!getenv("WINDOWID");
- return xt;
-}
-
-static int winch_pipe[2];
-static unsigned char winch_thread_running = 0;
-
-#define WINCH_SLEEPTIME 500 /* time in ms for winch thread to sleep */
-
-static void winch_thread(void *arg)
-{
- /* A thread which regularly checks whether the size of
- window has changed. Then raise SIGWINCH or notifiy
- the thread responsible to handle this. */
- static int old_xsize, old_ysize;
- static int cur_xsize, cur_ysize;
-
- ignore_signals();
- if (get_terminal_size(1, &old_xsize, &old_ysize)) return;
- while (1) {
- if (get_terminal_size(1, &cur_xsize, &cur_ysize)) return;
- if ((old_xsize != cur_xsize) || (old_ysize != cur_ysize)) {
- int wr;
- old_xsize = cur_xsize;
- old_ysize = cur_ysize;
- EINTRLOOP(wr, (int)write(winch_pipe[1], "x", 1));
- /* Resizing may take some time. So don't send a flood
- of requests?! */
- _sleep2(2*WINCH_SLEEPTIME);
- }
- else
- _sleep2(WINCH_SLEEPTIME);
- }
-}
-
-static void winch(void *s)
-{
- unsigned char c;
- while (can_read(winch_pipe[0])) {
- int rd;
- EINTRLOOP(rd, (int)read(winch_pipe[0], &c, 1));
- if (rd != 1) break;
- }
- ((void (*)(void))s)();
-}
-
-void handle_terminal_resize(int fd, void (*fn)(void))
-{
- if (!is_xterm()) return;
- if (!winch_thread_running) {
- if (c_pipe(winch_pipe) < 0) return;
- winch_thread_running = 1;
- if (_beginthread(winch_thread, NULL, 0x32000, NULL) == -1) {
- }
- }
- set_handlers(winch_pipe[0], winch, NULL, fn);
-}
-
-void unhandle_terminal_resize(int fd)
-{
- if (!winch_thread_running) return;
- set_handlers(winch_pipe[0], NULL, NULL, NULL);
-}
-
-int get_terminal_size(int fd, int *x, int *y)
-{
- if (is_xterm()) {
-#ifdef X2
- int arc;
- struct winsize win;
-
- /* fd = STDIN_FILENO; */
- arc = ptioctl(1, TIOCGWINSZ, &win);
- if (arc) {
- *x = 80;
- *y = 24;
- return 0;
- }
- *y = win.ws_row;
- *x = win.ws_col;
- goto set_default;
-#else
- *x = 80; *y = 24;
- return 0;
-#endif
- } else {
- int a[2] = { 0, 0 };
- _scrsize(a);
- *x = a[0];
- *y = a[1];
-#ifdef X2
- set_default:
-#endif
- if (*x == 0) {
- *x = get_e("COLUMNS");
- if (*x == 0) *x = 80;
- }
- if (*y == 0) {
- *y = get_e("LINES");
- if (*y == 0) *y = 24;
- }
- }
- return 0;
-}
-
-#endif
-
-
-#if defined(OS2) && defined(HAVE_SYS_FMUTEX_H)
-
-static void fd_lock(void)
-{
- _fmutex_request(&fd_mutex, _FMR_IGNINT);
-}
-
-static void fd_unlock(void)
-{
- _fmutex_release(&fd_mutex);
-}
-
-#elif defined(HAVE_PTHREADS)
+#if defined(HAVE_PTHREADS)
static void fd_lock(void)
{
@@ -709,15 +242,10 @@ static void new_fd_cloexec(int fd)
static void new_fd_bin(int fd)
{
new_fd_cloexec(fd);
-#if defined(OS2) || (defined(WIN) && !defined(_UWIN)) || defined(DOS)
- setmode(fd, O_BINARY);
-#endif
}
/* Pipe */
-#if !defined(OPENVMS) && !defined(DOS)
-
void set_nonblock(int fd)
{
#ifdef O_NONBLOCK
@@ -740,8 +268,6 @@ int c_pipe(int *fd)
return r;
}
-#endif
-
int c_dup(int oh)
{
int h;
@@ -797,13 +323,11 @@ DIR *c_opendir(unsigned char *path)
DIR *d;
fd_lock();
ENULLLOOP(d, opendir(cast_const_char path));
-#ifdef HAVE_DIRFD
if (d) {
int h;
EINTRLOOP(h, dirfd(d));
if (h != -1) new_fd_cloexec(h);
}
-#endif
fd_unlock();
return d;
}
@@ -858,8 +382,6 @@ int open_prealloc(unsigned char *name, int flags, int mode, off_t siz)
/* Exec */
-#if defined(UNIX) || defined(ATHEOS) || defined(INTERIX)
-
int is_twterm(void)
{
static int xt = -1;
@@ -867,17 +389,6 @@ int is_twterm(void)
return xt;
}
-#else
-
-int is_twterm(void)
-{
- return 0;
-}
-
-#endif
-
-#if defined(UNIX) || defined(ATHEOS) || defined(INTERIX)
-
int is_screen(void)
{
static int xt = -1;
@@ -885,17 +396,6 @@ int is_screen(void)
return xt;
}
-#else
-
-int is_screen(void)
-{
- return 0;
-}
-
-#endif
-
-#if defined(UNIX) || defined(SPAD)
-
int is_xterm(void)
{
static int xt = -1;
@@ -903,31 +403,6 @@ int is_xterm(void)
return xt;
}
-#elif defined(BEOS) || defined(ATHEOS) || defined(DOS)
-
-int is_xterm(void)
-{
- return 0;
-}
-
-#elif defined(WIN) || defined(INTERIX)
-
-int is_xterm(void)
-{
- static int xt = -1;
- if (xt == -1) xt = !!getenv("WINDOWID");
- return xt;
-}
-
-#elif defined(RISCOS)
-
-int is_xterm(void)
-{
- return 1;
-}
-
-#endif
-
void close_fork_tty(void)
{
struct terminal *t;
@@ -964,348 +439,31 @@ void close_fork_tty(void)
EINTRLOOP(rs, close(k->conn));
}
-
-#if defined(WIN)
-
-void get_path_to_exe(void)
-{
- /* Standard method (argv[0]) doesn't work, if links is executed from
- symlink --- it returns symlink name and cmd.exe is unable to start
- it */
- unsigned r;
- static unsigned char path[4096];
- r = GetModuleFileNameA(NULL, cast_char path, sizeof path);
- if (r <= 0 || r >= sizeof path) {
- path_to_exe = g_argv[0];
- return;
- }
- path_to_exe = path;
-}
-
-#elif defined(OS2)
-
void get_path_to_exe(void)
{
- /* If you spawn links with quotation marks from cmd.exe,
- the quotation marks will be present in g_argv[0] ... and will
- prevent executing it */
- static unsigned char path[270];
path_to_exe = g_argv[0];
- if (!os2_pib) return;
- if (DosQueryModuleName(os2_pib->pib_hmte, sizeof path, path)) return;
- path_to_exe = path;
-}
-
-static ULONG os2_old_type;
-static HAB os2_hab;
-static HMQ os2_hmq;
-
-static int os2_init_pm(void)
-{
- if (!os2_pib) goto err0;
- os2_old_type = os2_pib->pib_ultype;
- os2_pib->pib_ultype = 3;
- os2_hab = WinInitialize(0);
- if (os2_hab == NULLHANDLE) goto err1;
- os2_hmq = WinCreateMsgQueue(os2_hab, 0);
- if (os2_hmq == NULLHANDLE) goto err2;
- return 0;
-err2:
- WinTerminate(os2_hab);
-err1:
- os2_pib->pib_ultype = os2_old_type;
-err0:
- return -1;
}
-static void os2_exit_pm(void)
+void init_os_terminal(void)
{
- WinDestroyMsgQueue(os2_hmq);
- WinTerminate(os2_hab);
- os2_pib->pib_ultype = os2_old_type;
}
-int os_get_system_name(unsigned char *buffer)
+unsigned char *os_conv_to_external_path(unsigned char *file, unsigned char *prog)
{
- ULONG version[3];
- if (DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_REVISION, version, sizeof version))
- return -1;
- if (version[0] == 20) {
- version[0] = 2;
- if (version[1] == 10) {
- version[1] = 1;
- } else if (version[1] >= 30) {
- version[0] = version[1] / 10;
- version[1] %= 10;
- }
- }
- sprintf(cast_char buffer, "OS/2 %d.%d i386", (int)version[0], (int)version[1]);
- return 0;
+ return stracpy(file);
}
-#elif !defined(OPENVMS)
-
-void get_path_to_exe(void)
+unsigned char *os_fixup_external_program(unsigned char *prog)
{
- path_to_exe = g_argv[0];
+ return stracpy(prog);
}
-#endif
-
-void init_os_terminal(void)
+/* UNIX */
+int exe(unsigned char *path, int fg)
{
-#ifdef INTERIX
- {
- /* Some sort of terminal bug in Interix, if we run xterm -e links,
- terminal doesn't switch to raw mode, executing "stty sane" fixes it.
- Don't do this workaround on console. */
- unsigned char *term = cast_uchar getenv("TERM");
- if (!term || casecmp(term, cast_uchar "interix", 7)) {
- system("stty sane 2>/dev/null");
- }
- }
-#endif
-#ifdef OS2
- if (os2_detached) {
- fatal_exit("Links doesn't work in detached session");
- }
-#endif
-}
-
-#ifdef INTERIX
-
-static inline void cut_program_path(unsigned char *prog, unsigned char **prog_start, unsigned char **prog_end)
-{
- while (WHITECHAR(*prog)) prog++;
- if (prog[0] == '"' || prog[0] == '\'') {
- *prog_start = prog + 1;
- *prog_end = cast_uchar strchr(cast_const_char(prog + 1), prog[0]);
- if (!*prog_end)
- *prog_end = cast_uchar strchr(cast_const_char prog, 0);
- } else {
- *prog_start = prog;
- *prog_end = prog + strcspn(cast_const_char prog, " ");
- }
-}
-
-static inline int is_windows_drive(unsigned char *prog_start, unsigned char *prog_end)
-{
- if (prog_end - prog_start >= 3 && upcase(prog_start[0]) >= 'A' && upcase(prog_start[0]) <= 'Z' && prog_start[1] == ':')
- return 1;
- return 0;
-}
-
-static inline int is_windows_program(unsigned char *prog_start, unsigned char *prog_end)
-{
- if (prog_end - prog_start > 4 && (
- !casecmp(prog_end - 4, cast_uchar ".exe", 4) ||
- !casecmp(prog_end - 4, cast_uchar ".bat", 4)))
- return 1;
- return 0;
-}
-
-#endif
-
-#if defined(WIN) && defined(HAVE_CYGWIN_CONV_PATH)
-
-unsigned char *os_conv_to_external_path(unsigned char *file, unsigned char *prog)
-{
- unsigned char *new_path;
- ssize_t sz;
- sz = cygwin_conv_path(CCP_POSIX_TO_WIN_A | CCP_ABSOLUTE, file, NULL, 0);
- if (sz < 0 || sz >= MAXINT) return stracpy(file);
- new_path = mem_alloc(sz);
- sz = cygwin_conv_path(CCP_POSIX_TO_WIN_A | CCP_ABSOLUTE, file, new_path, sz);
- if (sz < 0) {
- mem_free(new_path);
- return stracpy(file);
- }
- return new_path;
-}
-
-#elif defined(WIN) && defined(HAVE_CYGWIN_CONV_TO_FULL_WIN32_PATH)
-
-unsigned char *os_conv_to_external_path(unsigned char *file, unsigned char *prog)
-{
-#ifdef MAX_PATH
- unsigned char new_path[MAX_PATH];
-#else
- unsigned char new_path[1024];
-#endif
- *new_path = 0;
- cygwin_conv_to_full_win32_path(cast_const_char file, cast_char new_path);
- if (!*new_path) return stracpy(file);
- return stracpy(new_path);
-}
-
-#elif defined(WIN) && defined(HAVE_UWIN_PATH)
-
-unsigned char *os_conv_to_external_path(unsigned char *file, unsigned char *prog)
-{
- unsigned char *new_path;
- ssize_t sz, sz2;
- sz = uwin_path(file, NULL, 0);
- if (sz < 0 || sz >= MAXINT) return stracpy(file);
- new_path = mem_alloc(sz + 1);
- sz2 = uwin_path(file, new_path, sz + 1);
- if (sz2 < 0 || sz2 > sz) {
- mem_free(new_path);
- return stracpy(file);
- }
- return new_path;
-}
-
-#elif defined(INTERIX) && defined(HAVE_UNIXPATH2WIN)
-
-unsigned char *os_conv_to_external_path(unsigned char *file, unsigned char *prog)
-{
- unsigned char *prog_start, *prog_end;
- if (!prog) prog = ".exe";
- cut_program_path(prog, &prog_start, &prog_end);
- /* Convert path only if the program has ".exe" or ".bat" extension */
- if (is_windows_program(prog_start, prog_end)) {
-#ifdef MAX_PATH
- unsigned char new_path[MAX_PATH];
-#else
- unsigned char new_path[512];
-#endif
- unsigned char *newstr;
- int newstrl;
- unsigned char *p;
- if (unixpath2win(file, 0, new_path, sizeof(new_path)))
- goto copy_path;
- /*return stracpy(new_path);*/
- newstr = init_str();
- newstrl = 0;
- for (p = new_path; *p; p++) {
- /*
- * Unix shell hates backslash and Windows applications
- * accept '/'
- */
- if (*p == '\\') add_to_str(&newstr, &newstrl, cast_uchar "/");
- else add_chr_to_str(&newstr, &newstrl, *p);
- }
- return newstr;
- }
- copy_path:
- return stracpy(file);
-}
-
-#elif defined(OS2) || defined(DOS)
-
-unsigned char *os_conv_to_external_path(unsigned char *file, unsigned char *prog)
-{
- unsigned char *f, *x;
- f = stracpy(file);
-#ifdef OS2
- if (prog)
- return f;
-#endif
- x = f;
- while ((x = cast_uchar strchr(cast_const_char x, '/'))) *x = '\\';
- return f;
-}
-
-
-#else
-
-unsigned char *os_conv_to_external_path(unsigned char *file, unsigned char *prog)
-{
- return stracpy(file);
-}
-
-#endif
-
-#if defined(INTERIX) && defined(HAVE_WINPATH2UNIX)
-
-unsigned char *os_fixup_external_program(unsigned char *prog)
-{
- unsigned char *prog_start, *prog_end;
- cut_program_path(prog, &prog_start, &prog_end);
- if (is_windows_drive(prog_start, prog_end)) {
-#ifdef MAX_PATH
- unsigned char new_path[MAX_PATH];
-#else
- unsigned char new_path[1024];
-#endif
- unsigned char *newstr;
- int newstrl;
- unsigned char *xpath;
- if (is_windows_program(prog_start, prog_end)) {
- /*
- * There is some bug in Interix. Executing Win32
- * binaries works from the console but doesn't work
- * from xterm. So we prepend "cmd /c" to the program
- * as a workaround.
- */
- newstr = init_str();
- newstrl = 0;
- add_to_str(&newstr, &newstrl, cast_uchar "cmd /c ");
- add_to_str(&newstr, &newstrl, prog);
- return newstr;
- }
- xpath = memacpy(prog_start, prog_end - prog_start);
- if (winpath2unix(xpath, 0, new_path, sizeof(new_path))) {
- mem_free(xpath);
- goto copy_prog;
- }
- mem_free(xpath);
- newstr = init_str();
- newstrl = 0;
- add_bytes_to_str(&newstr, &newstrl, prog, prog_start - prog);
- add_to_str(&newstr, &newstrl, new_path);
- add_to_str(&newstr, &newstrl, prog_end);
- return newstr;
- }
- copy_prog:
- return stracpy(prog);
-}
-
-#else
-
-unsigned char *os_fixup_external_program(unsigned char *prog)
-{
- return stracpy(prog);
-}
-
-#endif
-
-
-#if defined(UNIX) || defined(INTERIX) || defined(BEOS) || defined(RISCOS) || defined(ATHEOS) || defined(SPAD) || defined(OPENVMS) || defined(DOS)
-
-#if defined(BEOS) && defined(HAVE_SETPGID)
-
-int exe(unsigned char *path, int fg)
-{
- pid_t p, rp;
- int s, rs;
- EINTRLOOP(p, fork());
- if (!p) {
- EINTRLOOP(rs, setpgid(0, 0));
- system(path);
- _exit(0);
- }
- if (p > 0) {
- EINTRLOOP(rp, waitpid(p, &s, 0));
- } else {
- system(path);
- return rs;
- }
- return 0;
-}
-
-#else
-
-/* UNIX */
-int exe(unsigned char *path, int fg)
-{
-#ifdef OPENVMS
- if (!strcmp(cast_const_char path, DEFAULT_SHELL))
- path = cast_uchar "";
-#endif
-#ifndef EXEC_IN_THREADS
-#ifdef SIGCHLD
- do_signal(SIGCHLD, SIG_DFL);
+#ifndef EXEC_IN_THREADS
+#ifdef SIGCHLD
+ do_signal(SIGCHLD, SIG_DFL);
#endif
do_signal(SIGPIPE, SIG_DFL);
#ifdef SIGXFSZ
@@ -1327,8 +485,6 @@ int exe(unsigned char *path, int fg)
return system(cast_const_char path);
}
-#endif
-
/* clipboard -> links */
unsigned char *get_clipboard_text(struct terminal *term)
{
@@ -1381,1035 +537,38 @@ int resize_window(int x, int y)
return -1;
}
-#elif defined(WIN)
-
-int is_winnt(void)
-{
- OSVERSIONINFO v;
- v.dwOSVersionInfoSize = sizeof v;
- if (!GetVersionEx(&v)) return 0;
- return v.dwPlatformId >= VER_PLATFORM_WIN32_NT;
-}
-
-static void close_handles(int keep_output)
-{
- int i, rs;
- for (i = 0; i < FD_SETSIZE; i++) {
- if (keep_output && (i == 1 || i == 2)) continue;
- EINTRLOOP(rs, close(i));
- }
- EINTRLOOP(rs, open("nul", O_RDONLY));
- if (!keep_output) {
- EINTRLOOP(rs, open("nul", O_WRONLY));
- EINTRLOOP(rs, open("nul", O_WRONLY));
- }
-}
-
-#define WIN32_START_STRING "start /wait "
-
-int exe(unsigned char *path, int fg)
-{
- /* This is very tricky. We must have exactly 3 arguments, the first
- one shell and the second one "/c", otherwise Cygwin would quote
- the arguments and trash them */
- int ct = 0;
- unsigned char buffer[1024];
- unsigned char buffer2[1024];
- size_t want_alloc;
- pid_t pid, rp;
-#ifndef _UWIN
- int rs;
-#endif
- unsigned char *x1;
- unsigned char *arg;
- x1 = cast_uchar GETSHELL;
- if (!x1) x1 = cast_uchar DEFAULT_SHELL;
-
- want_alloc = strlen(cast_const_char WIN32_START_STRING) + 3 + strlen(cast_const_char path) + 1;
-#ifdef _UWIN
- want_alloc += strlen(cast_const_char x1) + 4;
- want_alloc *= 2;
-#endif
-
- arg = malloc(want_alloc);
- if (!arg) return -1;
- *arg = 0;
-#ifdef _UWIN
- strcat(cast_char arg, cast_const_char x1);
- strcat(cast_char arg, " /c ");
-#endif
- strcat(cast_char arg, cast_const_char WIN32_START_STRING);
- if (*path == '"' && is_winnt()) strcat(cast_char arg, "\"\" ");
- strcat(cast_char arg, cast_const_char path);
- if (!is_winnt()) ct = GetConsoleTitleA(cast_char buffer, sizeof buffer);
-#if defined(_UWIN) && !defined(__DMC__)
- {
- unsigned char *q1 = arg, *q2 = arg;
- while (*q1) {
- if (*q1 == '\\') q2++;
- q2++;
- q1++;
- }
- while (1) {
- *q2 = *q1;
- if (*q1 == '\\') {
- q2--;
- *q2 = '\\';
- }
- if (q1 == arg) break;
- q1--;
- q2--;
- }
- }
- /* UWin corrupts heap if we use threads and fork */
- fd_lock();
- pid = spawnl("/bin/sh", "/bin/sh", "-c", arg, (char *)NULL);
- fd_unlock();
-#else
-#if 1 /* spawn breaks mouse, do this only in graphics mode */
- if (F && is_winnt()) {
- /* spawn crashes on Win98 */
- fd_lock();
- spawnlp(_P_WAIT, cast_const_char x1, cast_const_char x1, "/c", cast_const_char arg, (char *)NULL);
- fd_unlock();
- /*FreeConsole();*/
- goto free_ret;
- } else
-#endif
- {
- EINTRLOOP(pid, fork());
- if (!pid) {
- /* Win98 crashes if we spawn command.com and have some sockets open */
- close_handles(0);
- EINTRLOOP(rs, execlp(cast_const_char x1, cast_const_char x1, "/c", cast_const_char arg, (char *)NULL));
- _exit(1);
- }
- }
-#endif
- if (!is_winnt()) {
- portable_sleep(1000);
- if (ct && GetConsoleTitleA(cast_char buffer2, sizeof buffer2) && !casecmp(buffer2, cast_uchar "start", 5)) {
- SetConsoleTitleA(cast_const_char buffer);
- }
- }
- if (pid != -1) EINTRLOOP(rp, waitpid(pid, NULL, 0));
- goto free_ret;
-
- free_ret:
- free(arg);
- return 0;
-}
-
-int exe_on_background(unsigned char *path, unsigned char *del)
-{
-#ifdef __CYGWIN__
- unsigned char *x1;
- unsigned char *arg;
- unsigned char *delx;
- int use_create_process = 0;
-#if CYGWIN_VERSION_API_MAJOR > 1 || CYGWIN_VERSION_API_MINOR >= 154
- if (is_winnt()) {
- use_create_process = 1;
- if (cygwin_internal(CW_SYNC_WINENV))
- use_create_process = 0;
- }
-#endif
-
- if (!is_winnt()) {
- if (del && *del)
- return -1;
- }
-
- x1 = cast_uchar GETSHELL;
- if (!x1) x1 = cast_uchar DEFAULT_SHELL;
-
- arg = stracpy(cast_uchar "");
- if (use_create_process) {
- add_to_strn(&arg, x1);
- add_to_strn(&arg, cast_uchar " /c ");
- }
- add_to_strn(&arg, cast_uchar WIN32_START_STRING);
- if (is_winnt()) if (*path == '"') add_to_strn(&arg, cast_uchar "\"\" ");
- add_to_strn(&arg, path);
- if (del && *del) {
- add_to_strn(&arg, cast_uchar " & ");
- add_to_strn(&arg, cast_uchar "del \"");
- delx = os_conv_to_external_path(del, path);
- add_to_strn(&arg, delx);
- mem_free(delx);
- add_to_strn(&arg, cast_uchar "\"");
- }
-
- /*debug("'%s'", arg);*/
-
- if (use_create_process) {
- PROCESS_INFORMATION pi;
- STARTUPINFO si;
- memset(&pi, 0, sizeof pi);
- memset(&si, 0, sizeof si);
- si.cb = sizeof si;
- fd_lock();
- if (CreateProcessA(cast_char x1, cast_char arg, NULL, NULL, FALSE, CREATE_NO_WINDOW | (is_winnt() ? DETACHED_PROCESS : 0), NULL, NULL, &si, &pi)) {
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- }
- fd_unlock();
- } else {
- /* We need to fork here so that we can close handles */
- pid_t pid;
- /*int rs;*/
- EINTRLOOP(pid, fork());
- if (!pid) {
- close_handles(0);
- /*EINTRLOOP(rs, execlp(cast_const_char x1, cast_const_char x1, "/c", cast_const_char arg, (char *)NULL));*/
- spawnlp(_P_DETACH, cast_const_char x1, cast_const_char x1, "/c", cast_const_char arg, (char *)NULL);
- _exit(1);
- }
- }
-
- mem_free(arg);
- return 0;
-#else
- return -1;
-#endif
-}
-
-int windows_charset(void)
-{
-#if defined(HAVE_NL_LANGINFO) && defined(HAVE_LANGINFO_H) && defined(CODESET)
- int idx;
- unsigned char *cp;
- cp = cast_uchar nl_langinfo(CODESET);
- idx = get_cp_index(cp);
- if (idx >= 0)
- return idx;
-#endif
- return utf8_table;
-}
-
-unsigned char *get_clipboard_text(struct terminal *term)
-{
- unsigned char buffer[256];
- unsigned char *str, *s, *d, *result;
- int l;
- int r;
- int rs;
- int h;
- if (!clipboard_support(term)) {
- str = stracpy(clipboard);
- goto cvt_ret;
- }
- /* O_TEXT doesn't work on clipboard handle */
- h = c_open(cast_uchar "/dev/clipboard", O_RDONLY);
- if (h == -1) return stracpy(clipboard);
- str = init_str();
- l = 0;
- /* Don't use hard_read because UWin has buggy end-of-file signalling.
- It resets the position to the beginning after signalling eof. */
- while (1) {
- EINTRLOOP(r, (int)read(h, buffer, sizeof buffer));
- if (r <= 0) break;
- add_bytes_to_str(&str, &l, buffer, r);
- }
- EINTRLOOP(rs, close(h));
- for (s = str, d = str; *s; s++)
- if (!(s[0] == '\r' && s[1] == '\n')) *d++ = *s;
- *d = 0;
-
- cvt_ret:
- result = convert(windows_charset(), term_charset(term), str, NULL);
- mem_free(str);
- return result;
-}
-
-void set_clipboard_text(struct terminal *term, unsigned char *data)
-{
- unsigned char *p;
- unsigned char *conv_data;
- int l;
- int h;
- int rs;
- if (clipboard) mem_free(clipboard);
- clipboard = convert(term_charset(term), windows_charset(), data, NULL);
- if (!clipboard_support(term)) return;
- /* O_TEXT doesn't work on clipboard handle */
- h = c_open(cast_uchar "/dev/clipboard", O_WRONLY);
- if (h == -1) return;
- conv_data = init_str();
- l = 0;
- for (p = clipboard; *p; p++) {
- if (*p == '\n') add_to_str(&conv_data, &l, cast_uchar "\r\n");
- else add_chr_to_str(&conv_data, &l, *p);
- }
- hard_write(h, conv_data, l);
- mem_free(conv_data);
- EINTRLOOP(rs, close(h));
-}
-
-int clipboard_support(struct terminal *term)
-{
- struct stat st;
- int rs;
- EINTRLOOP(rs, stat("/dev/clipboard", &st));
- return !rs && S_ISCHR(st.st_mode);
-}
-
-int get_windows_cp(int cons)
-{
- unsigned char str[8];
- int cp, idx;
- if (cons && is_winnt())
- cp = GetConsoleOutputCP();
- else
- cp = GetACP();
- if (cp <= 0 || cp >= 100000) return 0;
- if (cp == 874) cp = 28605;
- if (cp >= 28591 && cp <= 28605) {
- sprintf(cast_char str, "8859-%d", cp - 28590);
- } else {
- sprintf(cast_char str, "%d", cp);
- }
- if ((idx = get_cp_index(str)) < 0) return 0;
- return idx;
-}
-
-void set_window_title(unsigned char *title)
-{
- unsigned char *t, *p;
- if (!title) return;
- if (is_xterm()) return;
- t = convert(utf8_table, get_windows_cp(1), title, NULL);
- for (p = cast_uchar strchr(cast_const_char t, 1); p; p = cast_uchar strchr(cast_const_char(p + 1), 1))
- *p = ' ';
- SetConsoleTitleA(cast_const_char t);
- mem_free(t);
-}
-
-unsigned char *get_window_title(void)
-{
- int r;
- unsigned char buffer[1024];
- if (is_xterm()) return NULL;
- if (!(r = GetConsoleTitleA(cast_char buffer, sizeof buffer))) return NULL;
- if (r >= 1024) r = 1023;
- buffer[r] = 0;
- return convert(get_windows_cp(1), utf8_table, buffer, NULL);
-}
-
-static void call_resize(unsigned char *x1, int x, int y)
-{
- pid_t pid, rp;
-#ifndef _UWIN
- int rs;
-#endif
- unsigned char arg[64];
-#ifdef _UWIN
- x++;
-#endif
- snprintf(cast_char arg, (int)sizeof(arg), "mode %d,%d", x, y);
-#if defined(_UWIN) && !defined(__DMC__)
- pid = spawnlp(x1, x1, "/c", arg, (char *)NULL);
-#else
-#if 0 /* spawn breaks mouse, don't use this */
- if (is_winnt()) {
- /* spawn crashes on Win98 */
- fd_lock();
- spawnlp(_P_WAIT, x1, x1, "/c", arg, (char *)NULL);
- fd_unlock();
- return;
- } else
-#endif
- {
- EINTRLOOP(pid, fork());
- if (!pid) {
- /* Win98 crashes if we spawn command.com and have some sockets open */
- close_handles(1);
- EINTRLOOP(rs, execlp(cast_const_char x1, cast_const_char x1, "/c", cast_const_char arg, (char *)NULL));
- _exit(1);
- }
- }
-#endif
- if (pid != -1) EINTRLOOP(rp, waitpid(pid, NULL, 0));
-}
-
-int resize_window(int x, int y)
-{
- int old_x, old_y;
- int ct = 0, fullscreen = 0;
- unsigned char buffer[1024];
- unsigned char *x1;
- if (is_xterm()) return -1;
- if (get_terminal_size(1, &old_x, &old_y)) return -1;
- x1 = cast_uchar GETSHELL;
- if (!x1) x1 = cast_uchar DEFAULT_SHELL;
- if (!is_winnt()) {
- ct = GetConsoleTitleA(cast_char buffer, sizeof buffer);
- }
-
- call_resize(x1, x, y);
- if (!is_winnt()) {
- int new_x, new_y;
- /* If we resize console on Win98 in fullscreen mode, it won't be
- notified by Cygwin (it is valid for all Cygwin apps). So we must
- switch to windowed mode, resize it again (twice, because resizing
- to the same size won't have an effect) and switch back to full-screen
- mode. */
- /* I'm not sure what's the behavior on WinNT 4. Anybody wants to test?
- */
- if (!fullscreen && !get_terminal_size(1, &new_x, &new_y) && (new_x != x || new_y != y)) {
- fullscreen = 1;
-#ifdef __CYGWIN__
- keybd_event(VK_MENU, 0x38, 0, 0);
- keybd_event(VK_RETURN, 0x1c, 0, 0);
- keybd_event(VK_RETURN, 0x1c, KEYEVENTF_KEYUP, 0);
- keybd_event(VK_MENU, 0x38, KEYEVENTF_KEYUP, 0);
-#endif
- if (y != 25) call_resize(x1, 80, 25);
- else call_resize(x1, 80, 50);
- call_resize(x1, x, y);
- if (get_terminal_size(1, &new_x, &new_y) || new_x != x || new_y != y) call_resize(x1, old_x, old_y);
-#ifdef __CYGWIN__
- keybd_event(VK_MENU, 0x38, 0, 0);
- keybd_event(VK_RETURN, 0x1c, 0, 0);
- keybd_event(VK_RETURN, 0x1c, KEYEVENTF_KEYUP, 0);
- keybd_event(VK_MENU, 0x38, KEYEVENTF_KEYUP, 0);
-#endif
- }
- if (ct) SetConsoleTitleA(cast_const_char buffer);
- }
- return 0;
-}
-
-#elif defined(OS2)
-
-int exe(unsigned char *path, int fg)
-{
- int flags = P_SESSION;
- pid_t pid, rs;
- int ret;
-#ifdef G
- int old0 = 0, old1 = 1, old2 = 2;
-#endif
- unsigned char *shell;
- if (!(shell = GETSHELL)) shell = DEFAULT_SHELL;
- if (is_xterm()) flags |= P_BACKGROUND;
-#ifdef G
- if (F) {
- old0 = c_dup(0);
- old1 = c_dup(1);
- old2 = c_dup(2);
- fd_lock();
- if (old0 >= 0) EINTRLOOP(rs, close(0));
- if (old1 >= 0) EINTRLOOP(rs, close(1));
- if (old2 >= 0) EINTRLOOP(rs, close(2));
- if (old0 >= 0) EINTRLOOP(rs, open("con", O_RDONLY));
- if (old1 >= 0) EINTRLOOP(rs, open("con", O_WRONLY));
- if (old2 >= 0) EINTRLOOP(rs, open("con", O_WRONLY));
- } else
-#endif
- {
- fd_lock();
- }
- pid = spawnlp(flags, shell, shell, "/c", path, (char *)NULL);
-#ifdef G
- if (F) {
- if (old0 >= 0) EINTRLOOP(rs, dup2(old0, 0));
- if (old1 >= 0) EINTRLOOP(rs, dup2(old1, 1));
- if (old2 >= 0) EINTRLOOP(rs, dup2(old2, 2));
- if (old0 >= 0) EINTRLOOP(rs, close(old0));
- if (old1 >= 0) EINTRLOOP(rs, close(old1));
- if (old2 >= 0) EINTRLOOP(rs, close(old2));
- }
-#endif
- fd_unlock();
- if (pid != -1) EINTRLOOP(rs, waitpid(pid, &ret, 0));
- else ret = -1;
- return ret;
-}
-
-unsigned char *get_clipboard_text(struct terminal *term)
-{
- unsigned char *ret = NULL;
-
- if (os2_init_pm()) return NULL;
-
- if (WinOpenClipbrd(os2_hab)) {
- ULONG fmtInfo = 0;
-
- if (WinQueryClipbrdFmtInfo(os2_hab, CF_TEXT, &fmtInfo)!=FALSE)
- {
- ULONG selClipText = WinQueryClipbrdData(os2_hab, CF_TEXT);
-
- if (selClipText) {
- unsigned char *u;
- PCHAR pchClipText = (PCHAR)selClipText;
- ret = stracpy(pchClipText);
- while ((u = cast_uchar strchr(cast_const_char ret, 13))) memmove(u, u + 1, strlen(cast_const_char(u + 1)) + 1);
- }
- }
-
- WinCloseClipbrd(os2_hab);
- }
-
-#ifdef G
- if (F && ret) {
- static int cp = -1;
- unsigned char *d;
- if (cp == -1) {
- int c = WinQueryCp(os2_hmq);
- unsigned char a[8];
- snprintf(cast_char a, sizeof a, "%d", c);
- if ((cp = get_cp_index(a)) < 0 || cp == utf8_table) cp = 0;
- }
- d = convert(cp, utf8_table, ret, NULL);
- mem_free(ret);
- ret = d;
- }
-#endif
-
- os2_exit_pm();
-
- return ret;
-}
-
-void set_clipboard_text(struct terminal *term, unsigned char *data)
-{
- unsigned char *d = NULL;
-
- if (os2_init_pm()) return;
-
-#ifdef G
- if (F) {
- static int cp = -1;
- unsigned char *p;
- if (cp == -1) {
- int c = WinQueryCp(os2_hmq);
- unsigned char a[8];
- snprintf(cast_char a, sizeof a, "%d", c);
- if ((cp = get_cp_index(a)) < 0 || cp == utf8_table) cp = 0;
- }
- d = convert(utf8_table, cp, data, NULL);
- for (p = cast_uchar strchr(cast_const_char d, 1); p; p = cast_uchar strchr(cast_const_char(p + 1), 1))
- *p = ' ';
- data = d;
- }
-#endif
- if (WinOpenClipbrd(os2_hab)) {
- PVOID pvShrObject = NULL;
- if (DosAllocSharedMem(&pvShrObject, NULL, strlen(cast_const_char data)+1, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GIVEABLE) == NO_ERROR) {
- strcpy(cast_char pvShrObject, cast_const_char data);
- WinEmptyClipbrd(os2_hab);
- WinSetClipbrdData(os2_hab, (ULONG)pvShrObject, CF_TEXT, CFI_POINTER);
- }
- WinCloseClipbrd(os2_hab);
- }
-
- os2_exit_pm();
-
- if (d) mem_free(d);
-}
-
-int clipboard_support(struct terminal *term)
-{
- return 1;
-}
-
-unsigned char *get_window_title(void)
-{
-#ifndef OS2_DEBUG
- unsigned char *win_title = NULL;
- SWCNTRL swData;
-
- memset(&swData, 0, sizeof swData);
- if (os2_switchhandle != NULLHANDLE && !WinQuerySwitchEntry(os2_switchhandle, &swData)) {
- swData.szSwtitle[MAXNAMEL - 1] = 0;
- win_title = stracpy(swData.szSwtitle);
- if (swData.hwnd != NULLHANDLE && !os2_init_pm()) {
- LONG len = WinQueryWindowTextLength(swData.hwnd);
- if (len > 0 && len < MAXINT) {
- mem_free(win_title);
- win_title = mem_alloc(len + 1);
- win_title[0] = 0;
- WinQueryWindowText(swData.hwnd, len + 1, win_title);
- win_title[len] = 0;
- }
- os2_exit_pm();
- }
- }
-
- return win_title;
-#else
- return NULL;
-#endif
-}
-
-void set_window_title(unsigned char *title)
-{
-#ifndef OS2_DEBUG
- SWCNTRL swData;
-
- if (!title) return;
-
- memset(&swData, 0, sizeof swData);
- if (os2_switchhandle != NULLHANDLE && !WinQuerySwitchEntry(os2_switchhandle, &swData)) {
- safe_strncpy(swData.szSwtitle, title, MAXNAMEL);
- WinChangeSwitchEntry(os2_switchhandle, &swData);
- if (swData.hwnd != NULLHANDLE && !os2_init_pm()) {
- WinSetWindowText(swData.hwnd, title);
- os2_exit_pm();
- }
- }
-#endif
-}
-
-static tcount resize_count = 0;
-
-int resize_window(int x, int y)
-{
- int xfont, yfont;
- A_DECL(VIOMODEINFO, vmi);
- SWCNTRL swData;
-
- resize_count++;
- if (is_xterm()) return -1;
- vmi->cb = sizeof(*vmi);
- if (VioGetMode(vmi, 0)) return -1;
- vmi->col = x;
- vmi->row = y;
- /*debug("%d %d %d", vmi->buf_length, vmi->full_length, vmi->partial_length);*/
- for (xfont = 9; xfont >= 8; xfont--)
- for (yfont = 16; yfont >= 8; yfont--) {
- vmi->hres = x * xfont;
- vmi->vres = y * yfont;
- if (vmi->vres <= 400) vmi->vres = 400;
- else if (vmi->vres <= 480) vmi->vres = 480;
- vmi->buf_length = vmi->full_length = vmi->partial_length = x * ((vmi->vres + yfont - 1) / yfont) * 2;
- vmi->full_length = (vmi->full_length + 4095) & ~4095;
- vmi->partial_length = (vmi->partial_length + 4095) & ~4095;
- if (!VioSetMode(vmi, 0)) goto resized;
- }
- return -1;
-
- resized:
- memset(&swData, 0, sizeof swData);
- if (os2_switchhandle != NULLHANDLE && !WinQuerySwitchEntry(os2_switchhandle, &swData) && swData.hwnd != NULLHANDLE && !os2_init_pm()) {
- SWP swp;
- if (WinQueryWindowPos(swData.hwnd, &swp) && !(swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE | SWP_HIDE))) {
- const int expand = 16383;
- WinSetWindowPos(swData.hwnd, NULLHANDLE, swp.x, swp.y - expand, swp.cx + expand, swp.cy + expand, SWP_MOVE | SWP_SIZE);
- }
- os2_exit_pm();
- }
- return 0;
-}
-
-#endif
-
/* Threads */
-#if (defined(HAVE_BEGINTHREAD) && defined(OS2)) || defined(BEOS) || defined(HAVE_PTHREADS) || defined(HAVE_ATHEOS_THREADS_H)
-
-struct tdata {
- void (*fn)(void *, int);
- int h;
- int counted;
- unsigned char data[1];
-};
-
-static void bgt(void *t_)
-{
- struct tdata *t = t_;
- int rs;
- ignore_signals();
- t->fn(t->data, t->h);
- EINTRLOOP(rs, (int)write(t->h, "x", 1));
- EINTRLOOP(rs, close(t->h));
- free(t);
-}
-
-#ifdef HAVE_ATHEOS_THREADS_H
-#include <atheos/threads.h>
-static uint32 bgat(void *t)
-{
- bgt(t);
- return 0;
-}
-#endif
-
-#endif
-
-#if defined(UNIX) || defined(OS2) || defined(WIN) || defined(INTERIX) || defined(RISCOS) || defined(ATHEOS) || defined(SPAD)
-
-void terminate_osdep(void)
-{
-}
-
-#endif
-
-#ifndef BEOS
-
-void block_stdin(void) {}
-void unblock_stdin(void) {}
-
-#endif
-
-#if defined(BEOS)
-
-#include <be/kernel/OS.h>
-
-static int thr_sem_init = 0;
-static sem_id thr_sem;
-
-static struct list_head active_threads = { &active_threads, &active_threads };
-
-struct active_thread {
- list_entry_1st
- thread_id tid;
- void (*fn)(void *);
- void *data;
- list_entry_last
-};
-
-static int32 started_thr(void *data)
-{
- struct active_thread *thrd = data;
- thrd->fn(thrd->data);
- if (acquire_sem(thr_sem) < B_NO_ERROR) return 0;
- del_from_list(thrd);
- free(thrd);
- release_sem(thr_sem);
- return 0;
-}
-
-int start_thr(void (*fn)(void *), void *data, unsigned char *name)
-{
- struct active_thread *thrd;
- int tid;
- if (!thr_sem_init) {
- if ((thr_sem = create_sem(0, "thread_sem")) < B_NO_ERROR) return -1;
- thr_sem_init = 1;
- } else if (acquire_sem(thr_sem) < B_NO_ERROR) return -1;
- retry:
- if (!(thrd = malloc(sizeof(struct active_thread)))) {
- if (out_of_memory(0, NULL, 0))
- goto retry;
- goto err1;
- }
- thrd->fn = fn;
- thrd->data = data;
- if ((tid = thrd->tid = spawn_thread(started_thr, name, B_NORMAL_PRIORITY, thrd)) < B_NO_ERROR)
- goto err2;
- resume_thread(thrd->tid);
- add_to_list(active_threads, thrd);
- release_sem(thr_sem);
- return tid;
-
- err2:
- free(thrd);
- err1:
- release_sem(thr_sem);
- return -1;
-}
-
-void terminate_osdep(void)
-{
- struct list_head *p;
- struct active_thread *thrd;
- struct list_head *lthrd;
- if (acquire_sem(thr_sem) < B_NO_ERROR) return;
- foreach(struct active_thread, thrd, lthrd, active_threads) kill_thread(thrd->tid);
- while (!list_empty(active_threads)) {
- thrd = list_struct(active_threads.next, struct active_thread);
- del_from_list(thrd);
- free(thrd);
- }
- release_sem(thr_sem);
-}
-
-int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
-{
- int p[2];
- struct tdata *t;
- int rs;
- if (c_pipe(p) < 0) return -1;
- retry:
- if (!(t = malloc(sizeof(struct tdata) + l))) {
- if (out_of_memory(0, NULL, 0))
- goto retry;
- goto err1;
- }
- t->fn = fn;
- t->h = p[1];
- t->counted = counted;
- memcpy(t->data, ptr, l);
- if (start_thr(bgt, t, cast_uchar "links_thread") < 0)
- goto err2;
- return p[0];
-
- err2:
- free(t);
- err1:
- EINTRLOOP(rs, close(p[0]));
- EINTRLOOP(rs, close(p[1]));
- return -1;
-}
-
-
-#elif defined(HAVE_BEGINTHREAD) && defined(OS2)
-
-int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
-{
- int p[2];
- struct tdata *t;
- int rs;
- if (c_pipe(p) < 0) return -1;
- retry:
- if (!(t = malloc(sizeof(struct tdata) + l))) {
- if (out_of_memory(0, NULL, 0))
- goto retry;
- goto err1;
- }
- t->fn = fn;
- t->h = p[1];
- t->counted = counted;
- memcpy(t->data, ptr, l);
- if (_beginthread(bgt, NULL, 65536, t) == -1)
- goto err2;
- return p[0];
-
- err2:
- free(t);
- err1:
- EINTRLOOP(rs, close(p[0]));
- EINTRLOOP(rs, close(p[1]));
- return -1;
-}
-
-#ifdef HAVE__READ_KBD
-
-static int tp = -1;
-static int ti = -1;
-
-static void input_thread(void *p)
-{
- unsigned char c[2];
- int h = (int)p;
- int rs;
- ignore_signals();
- while (1) {
- /* for the records:
- _read_kbd(0, 1, 1) will
- read a char, don't echo it, wait for one available and
- accept CTRL-C.
- Knowing that, I suggest we replace this call completly!
- */
- *c = _read_kbd(0, 1, 1);
- EINTRLOOP(rs, (int)write(h, c, 1));
- }
- EINTRLOOP(rs, close(h));
-}
-#endif /* #ifdef HAVE__READ_KBD */
-
-#if defined(HAVE_MOUOPEN) && defined(HAVE_BEGINTHREAD) && !defined(USE_GPM)
-
-#define USING_OS2_MOUSE
-
-static int mouse_h = -1;
-
-struct os2_mouse_spec {
- int p[2];
- void (*fn)(void *, unsigned char *, int);
- void *data;
- unsigned char buffer[sizeof(struct links_event)];
- int bufptr;
- int terminate;
-};
-
-#define MOU_EMULATE_CURSOR
-
-#ifdef MOU_EMULATE_CURSOR
-static int mouse_x = -1, mouse_y = -1;
-static unsigned char mouse_attr;
-#endif
-
-static void mouse_remove_pointer(void)
-{
-#ifndef MOU_EMULATE_CURSOR
- A_DECL(NOPTRRECT, pa);
- static int x = -1, y = -1;
- static tcount c = -1;
- if (x == -1 || y == -1 || (c != resize_count)) get_terminal_size(1, &x, &y), c = resize_count;
- pa->row = 0;
- pa->col = 0;
- pa->cRow = y - 1;
- pa->cCol = x - 1;
- MouRemovePtr(pa, mouse_h);
-#else
- if (mouse_x >= 0 && mouse_y >= 0) {
- VioWrtNAttr(&mouse_attr, 1, mouse_y, mouse_x, 0);
- }
- mouse_x = -1, mouse_y = -1;
-#endif
-}
-
-static void mouse_draw_pointer(int x, int y)
-{
-#ifndef MOU_EMULATE_CURSOR
- MouDrawPtr(mouse_h);
-#else
- unsigned char str[4];
- USHORT str_len;
- unsigned char attr;
- unsigned char fg, bg;
- int r;
- if (!os2_full_screen)
- return;
- DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
- if (mouse_x == x && mouse_y == y)
- return;
- mouse_remove_pointer();
- str_len = sizeof(str);
- r = VioReadCellStr(str, &str_len, y, x, 0);
- if (r || str_len < 2) return;
- mouse_attr = str[1];
- fg = mouse_attr & 0x07;
- bg = (mouse_attr & 0x70) >> 4;
- if (fg == bg) fg ^= 0x07, bg ^= 0x07;
- attr = (mouse_attr & 0x88) | (fg << 4) | bg;
- r = VioWrtNAttr(&attr, 1, y, x, 0);
- if (r) return;
- mouse_x = x, mouse_y = y, mouse_attr = str[1];
-#endif
-}
-
-static void mouse_thread(void *p)
-{
- int status;
- int rs;
- struct os2_mouse_spec *oms = p;
- A_DECL(HMOU, mh);
- A_DECL(MOUEVENTINFO, ms);
- A_DECL(USHORT, rd);
- A_DECL(USHORT, mask);
- struct links_event ev;
- ignore_signals();
- ev.ev = EV_MOUSE;
- if (MouOpen(NULL, mh)) goto ret;
- mouse_h = *mh;
- *mask = MOUSE_MOTION_WITH_BN1_DOWN | MOUSE_BN1_DOWN |
- MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_BN2_DOWN |
- MOUSE_MOTION_WITH_BN3_DOWN | MOUSE_BN3_DOWN |
- MOUSE_MOTION;
- MouSetEventMask(mask, *mh);
- *rd = MOU_WAIT;
- status = -1;
- while (1) {
- /*int w, ww;*/
- if (MouReadEventQue(ms, rd, *mh)) break;
- fd_lock();
- if (!oms->terminate) mouse_draw_pointer(ms->col, ms->row);
- fd_unlock();
- ev.x = ms->col;
- ev.y = ms->row;
- /*debug("status: %d %d %d", ms->col, ms->row, ms->fs);*/
- if (ms->fs & (MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN)) ev.b = status = B_DOWN | (ms->fs & MOUSE_BN1_DOWN ? B_LEFT : ms->fs & MOUSE_BN2_DOWN ? B_RIGHT : B_MIDDLE);
- else if (ms->fs & (MOUSE_MOTION_WITH_BN1_DOWN | MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_MOTION_WITH_BN3_DOWN)) {
- int b = ms->fs & MOUSE_MOTION_WITH_BN1_DOWN ? B_LEFT : ms->fs & MOUSE_MOTION_WITH_BN2_DOWN ? B_RIGHT : B_MIDDLE;
- if (status == -1) b |= B_DOWN;
- else b |= B_DRAG;
- ev.b = status = b;
- }
- else {
- if (status == -1) continue;
- ev.b = (status & BM_BUTT) | B_UP;
- status = -1;
- }
- if (hard_write(oms->p[1], (unsigned char *)&ev, sizeof(struct links_event)) != sizeof(struct links_event)) break;
- }
- fd_lock();
- mouse_h = -1;
- MouClose(*mh);
- fd_unlock();
- ret:
- EINTRLOOP(rs, close(oms->p[1]));
- /*free(oms);*/
-}
-
-static void mouse_handle(void *oms_)
-{
- struct os2_mouse_spec *oms = (struct os2_mouse_spec *)oms_;
- int r;
- EINTRLOOP(r, (int)read(oms->p[0], oms->buffer + oms->bufptr, sizeof(struct links_event) - oms->bufptr));
- if (r <= 0) {
- unhandle_mouse(oms);
- return;
- }
- if ((oms->bufptr += r) == sizeof(struct links_event)) {
- oms->bufptr = 0;
- oms->fn(oms->data, oms->buffer, sizeof(struct links_event));
- }
-}
-
-void *handle_mouse(int cons, void (*fn)(void *, unsigned char *, int), void *data)
-{
- struct os2_mouse_spec *oms;
- if (is_xterm()) return NULL;
- /* This is never freed but it's allocated only once */
- retry:
- if (!(oms = malloc(sizeof(struct os2_mouse_spec)))) {
- if (out_of_memory(0, NULL, 0))
- goto retry;
- return NULL;
- }
- oms->fn = fn;
- oms->data = data;
- oms->bufptr = 0;
- oms->terminate = 0;
- if (c_pipe(oms->p)) {
- free(oms);
- return NULL;
- }
- if (_beginthread(mouse_thread, NULL, 0x10000, (void *)oms) == -1) {
- }
- set_handlers(oms->p[0], mouse_handle, NULL, oms);
- return oms;
-}
-
-void unhandle_mouse(void *om)
-{
- struct os2_mouse_spec *oms = om;
- want_draw();
- oms->terminate = 1;
- close_socket(&oms->p[0]);
- done_draw();
-}
+#if (defined(HAVE_BEGINTHREAD) && defined(OS2)) || defined(BEOS) || defined(HAVE_PTHREADS) || defined(HAVE_ATHEOS_THREADS_H)
+
+struct tdata {
+ void (*fn)(void *, int);
+ int h;
+ int counted;
+ unsigned char data[1];
+};
-void want_draw(void)
+static void bgt(void *t_)
{
- static int ansi = 0;
- fd_lock();
- if (!ansi) {
- VioSetAnsi(1, 0);
- ansi = 1;
- }
- if (mouse_h != -1) {
- mouse_remove_pointer();
- }
+ struct tdata *t = t_;
+ int rs;
+ ignore_signals();
+ t->fn(t->data, t->h);
+ EINTRLOOP(rs, (int)write(t->h, "x", 1));
+ EINTRLOOP(rs, close(t->h));
+ free(t);
}
-void done_draw(void)
+#endif
+
+void terminate_osdep(void)
{
- fd_unlock();
}
-#endif /* if HAVE_MOUOPEN */
-
-#elif defined(HAVE_PTHREADS)
+void block_stdin(void) {}
+void unblock_stdin(void) {}
-#ifdef OPENVMS
-#define THREAD_NEED_STACK_SIZE 65536
-int vms_thread_high_priority = 0;
-#endif
+#if defined(HAVE_PTHREADS)
static unsigned thread_count = 0;
@@ -2491,27 +650,6 @@ int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
goto err3;
}
#endif
-#ifdef OPENVMS
- if (vms_thread_high_priority) {
- struct sched_param param;
- memset(¶m, 0, sizeof param);
- if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED))
- goto err3;
- if (vms_thread_high_priority > 0) {
- if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO))
- goto err3;
- param.sched_priority = PRI_FIFO_MIN;
- if (pthread_attr_setschedparam(&attr, ¶m))
- goto err3;
- } else {
- if (pthread_attr_setschedpolicy(&attr, SCHED_LFI_NP))
- goto err3;
- param.sched_priority = PRI_BG_MIN_NP;
- if (pthread_attr_setschedparam(&attr, ¶m))
- goto err3;
- }
- }
-#endif
if (counted) inc_thread_count();
if (pthread_create(&thread, &attr, bgpt, t)) {
if (counted) dec_thread_count();
@@ -2530,52 +668,6 @@ int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
return -1;
}
-#elif defined(HAVE_ATHEOS_THREADS_H) && defined(HAVE_SPAWN_THREAD) && defined(HAVE_RESUME_THREAD)
-
-#include <atheos/threads.h>
-
-int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
-{
- int p[2];
- int rs;
- thread_id f;
- struct tdata *t;
- if (c_pipe(p) < 0) return -1;
- retry:
- if (!(t = malloc(sizeof(struct tdata) + l))) {
- if (out_of_memory(0, NULL, 0))
- goto retry;
- goto err1;
- }
- t->fn = fn;
- t->h = p[1];
- t->counted = counted;
- memcpy(t->data, ptr, l);
- if ((f = spawn_thread("links_lookup", bgat, 0, 0, t)) == -1)
- goto err2;
- resume_thread(f);
- return p[0];
-
- err2:
- free(t);
- err1:
- EINTRLOOP(rs, close(p[0]));
- EINTRLOOP(rs, close(p[1]));
- return -1;
-}
-
-#elif defined(DOS)
-
-int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
-{
- int p[2];
- int rs;
- if (c_pipe(p) < 0) return -1;
- fn(ptr, p[1]);
- EINTRLOOP(rs, close(p[1]));
- return p[0];
-}
-
#else /* HAVE_BEGINTHREAD */
int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
@@ -2611,19 +703,9 @@ void done_draw(void) {}
int get_output_handle(void) { return 1; }
-#if defined(OS2)
-
-int get_ctl_handle(void) { return get_input_handle(); }
-
-#else
-
int get_ctl_handle(void) { return 0; }
-#endif
-
-#if defined(BEOS)
-
-#elif defined(HAVE_BEGINTHREAD) && defined(HAVE__READ_KBD)
+#if defined(HAVE_BEGINTHREAD) && defined(HAVE__READ_KBD)
int get_input_handle(void)
{
@@ -2647,7 +729,7 @@ int get_input_handle(void)
return fd[0];
}
-#elif !defined(OPENVMS)
+#else
int get_input_handle(void)
{
@@ -2657,215 +739,18 @@ int get_input_handle(void)
#endif /* defined(HAVE_BEGINTHREAD) && defined(HAVE__READ_KBD) */
-#if defined(USE_GPM) || defined(GRDRV_FB)
-
-/* GPM installs its own signal handlers and we don't want them */
-
-static sigset_t gpm_sigset;
-static unsigned char gpm_sigset_valid;
-#ifdef SIGWINCH
-static struct sigaction gpm_winch;
-static unsigned char gpm_winch_valid;
-#endif
-#ifdef SIGTSTP
-static struct sigaction gpm_tstp;
-static unsigned char gpm_tstp_valid;
-#endif
-
-void save_gpm_signals(void)
-{
- sigset_t sig;
- int rs;
- sigemptyset(&sig);
-#ifdef SIGWINCH
- sigaddset(&sig, SIGWINCH);
-#endif
-#ifdef SIGTSTP
- sigaddset(&sig, SIGTSTP);
-#endif
- EINTRLOOP(rs, do_sigprocmask(SIG_BLOCK, &sig, &gpm_sigset));
- gpm_sigset_valid = !rs;
-#ifdef SIGWINCH
- EINTRLOOP(rs, sigaction(SIGWINCH, NULL, &gpm_winch));
- gpm_winch_valid = !rs;
-#endif
-#ifdef SIGTSTP
- EINTRLOOP(rs, sigaction(SIGTSTP, NULL, &gpm_tstp));
- gpm_tstp_valid = !rs;
-#endif
-}
-
-void restore_gpm_signals(void)
-{
- int rs;
-#ifdef SIGWINCH
- if (gpm_winch_valid)
- EINTRLOOP(rs, sigaction(SIGWINCH, &gpm_winch, NULL));
-#endif
-#ifdef SIGTSTP
- if (gpm_tstp_valid)
- EINTRLOOP(rs, sigaction(SIGTSTP, &gpm_tstp, NULL));
-#endif
- if (gpm_sigset_valid)
- EINTRLOOP(rs, do_sigprocmask(SIG_SETMASK, &gpm_sigset, NULL));
-}
-
-#endif
-
-#ifdef USE_GPM
-
-struct gpm_mouse_spec {
- int h;
- void (*fn)(void *, unsigned char *, int);
- void *data;
-};
-
-static void gpm_mouse_in(void *gms_)
-{
- struct gpm_mouse_spec *gms = (struct gpm_mouse_spec *)gms_;
- int g;
- Gpm_Event gev;
- struct links_event ev;
- set_handlers(gms->h, NULL, NULL, NULL);
- save_gpm_signals();
- g = Gpm_GetEvent(&gev);
- restore_gpm_signals();
- if (g <= 0) {
- gms->h = -1;
- return;
- }
- set_handlers(gms->h, gpm_mouse_in, NULL, gms);
- ev.ev = EV_MOUSE;
- ev.x = gev.x - 1;
- ev.y = gev.y - 1;
- if (ev.x < 0) ev.x = 0;
- if (ev.y < 0) ev.y = 0;
- 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 return;
- 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 return;
- gms->fn(gms->data, (unsigned char *)&ev, sizeof(struct links_event));
-}
-
-void *handle_mouse(int cons, void (*fn)(void *, unsigned char *, int), void *data)
-{
- int h;
- Gpm_Connect conn;
- struct gpm_mouse_spec *gms;
- conn.eventMask = (unsigned short)~(unsigned)GPM_MOVE;
- conn.defaultMask = GPM_MOVE;
- conn.minMod = 0;
- conn.maxMod = 0;
- save_gpm_signals();
- h = Gpm_Open(&conn, cons);
- restore_gpm_signals();
- if (h < 0) return NULL;
- gms = mem_alloc(sizeof(struct gpm_mouse_spec));
- gms->h = h;
- gms->fn = fn;
- gms->data = data;
- set_handlers(h, gpm_mouse_in, NULL, gms);
- return gms;
-}
-
-void unhandle_mouse(void *h)
-{
- struct gpm_mouse_spec *gms = h;
- if (gms->h != -1) set_handlers(gms->h, NULL, NULL, NULL);
- save_gpm_signals();
- Gpm_Close();
- restore_gpm_signals();
- mem_free(gms);
-}
-
-void add_gpm_version(unsigned char **s, int *l)
-{
- add_to_str(s, l, cast_uchar "GPM");
-#ifdef HAVE_GPM_GETLIBVERSION
- add_to_str(s, l, cast_uchar " (");
- add_to_str(s, l, cast_uchar Gpm_GetLibVersion(NULL));
- add_to_str(s, l, cast_uchar ")");
-#endif
-}
-
-#elif !defined(USING_OS2_MOUSE) && !defined(DOS)
+#if !defined(USING_OS2_MOUSE) && !defined(DOS)
void *handle_mouse(int cons, void (*fn)(void *, unsigned char *, int), void *data) { return NULL; }
void unhandle_mouse(void *data) { }
-#endif /* #ifdef USE_GPM */
-
-
-#if defined(WIN) || defined(INTERIX)
-
-static int is_remote_connection(void)
-{
- return !!getenv("SSH_CONNECTION");
-}
-
#endif
-
-#if defined(OS2)
-
-int get_system_env(void)
-{
- if (is_xterm()) return 0;
- return ENV_OS2VIO; /* !!! FIXME: telnet */
-}
-
-#elif defined(BEOS)
-
-int get_system_env(void)
-{
- unsigned char *term = cast_uchar getenv("TERM");
- if (!term || (upcase(term[0]) == 'B' && upcase(term[1]) == 'E')) return ENV_BE;
- return 0;
-}
-
-#elif defined(WIN)
-
int get_system_env(void)
{
- if (is_xterm()) return 0;
- if (is_remote_connection()) return 0;
- return ENV_WIN32;
-}
-
-#elif defined(INTERIX)
-
-#define INTERIX_START_COMMAND "/usr/contrib/win32/bin/start"
-
-int get_system_env(void)
-{
- if (is_xterm()) return 0;
- if (is_remote_connection()) return 0;
- if (!access(INTERIX_START_COMMAND, X_OK)) return ENV_INTERIX;
return 0;
}
-#else
-
-int get_system_env(void)
-{
- return 0;
-}
-
-#endif
-
static void exec_new_links(struct terminal *term, unsigned char *xterm, unsigned char *exe, unsigned char *param)
{
unsigned char *str;
@@ -2893,11 +778,7 @@ unsigned char *links_xterm(void)
{
unsigned char *xterm;
if (!(xterm = cast_uchar getenv("LINKS_XTERM"))) {
-#ifdef OPENVMS
- xterm = cast_uchar "CREATE /TERMINAL /WAIT";
-#else
xterm = cast_uchar "xterm -e";
-#endif
}
return xterm;
}
@@ -2914,55 +795,6 @@ static int open_in_new_screen(struct terminal *term, unsigned char *exe, unsigne
return 0;
}
-#ifdef OS2
-static int open_in_new_vio(struct terminal *term, unsigned char *exe, unsigned char *param)
-{
- unsigned char *x = stracpy(cast_uchar "\"");
- add_to_strn(&x, exe);
- add_to_strn(&x, cast_uchar "\"");
- exec_new_links(term, cast_uchar "start \"Links\" /c /f /win", x, param);
- mem_free(x);
- return 0;
-}
-
-static int open_in_new_fullscreen(struct terminal *term, unsigned char *exe, unsigned char *param)
-{
- unsigned char *x = stracpy(cast_uchar "\"");
- add_to_strn(&x, exe);
- add_to_strn(&x, cast_uchar "\"");
- exec_new_links(term, cast_uchar "start \"Links\" /c /f /fs", x, param);
- mem_free(x);
- return 0;
-}
-#endif
-
-#ifdef WIN
-static int open_in_new_win32(struct terminal *term, unsigned char *exe, unsigned char *param)
-{
- exec_new_links(term, cast_uchar "", exe, param);
- return 0;
-}
-#endif
-
-#ifdef INTERIX
-static int open_in_new_interix(struct terminal *term, unsigned char *exe, unsigned char *param)
-{
- unsigned char *param_x = stracpy(param);
- add_to_strn(¶m_x, cast_uchar "'");
- exec_new_links(term, cast_uchar(INTERIX_START_COMMAND " '\"Links\"' posix /u /c /bin/sh -c '"), exe, param_x);
- mem_free(param_x);
- return 0;
-}
-#endif
-
-#ifdef BEOS
-static int open_in_new_be(struct terminal *term, unsigned char *exe, unsigned char *param)
-{
- exec_new_links(term, cast_uchar "Terminal", exe, param);
- return 0;
-}
-#endif
-
#ifdef G
static int open_in_new_g(struct terminal *term, unsigned char *exe, unsigned char *param)
{
@@ -2998,19 +830,6 @@ static const struct {
{ENV_XWIN, open_in_new_xterm, TEXT_(T_XTERM), TEXT_(T_HK_XTERM)},
{ENV_TWIN, open_in_new_twterm, TEXT_(T_TWTERM), TEXT_(T_HK_TWTERM)},
{ENV_SCREEN, open_in_new_screen, TEXT_(T_SCREEN), TEXT_(T_HK_SCREEN)},
-#ifdef OS2
- {ENV_OS2VIO, open_in_new_vio, TEXT_(T_WINDOW), TEXT_(T_HK_WINDOW)},
- {ENV_OS2VIO, open_in_new_fullscreen, TEXT_(T_FULL_SCREEN), TEXT_(T_HK_FULL_SCREEN)},
-#endif
-#ifdef WIN
- {ENV_WIN32, open_in_new_win32, TEXT_(T_WINDOW), TEXT_(T_HK_WINDOW)},
-#endif
-#ifdef INTERIX
- {ENV_INTERIX, open_in_new_interix, TEXT_(T_WINDOW), TEXT_(T_HK_WINDOW)},
-#endif
-#ifdef BEOS
- {ENV_BE, open_in_new_be, TEXT_(T_BEOS_TERMINAL), TEXT_(T_HK_BEOS_TERMINAL)},
-#endif
#ifdef G
{ENV_G, open_in_new_g, TEXT_(T_WINDOW), TEXT_(T_HK_WINDOW)},
#endif
@@ -3040,24 +859,11 @@ struct open_in_new *get_open_in_new(int environment)
int can_resize_window(struct terminal *term)
{
-#if defined(OS2) || defined(WIN)
- if (!strncmp(cast_const_char term->term, "xterm", 5)) return 0;
- if (term->environment & (ENV_OS2VIO | ENV_WIN32)) return 1;
-#endif
return 0;
}
int can_open_os_shell(int environment)
{
-#ifdef OS2
- if (environment & ENV_XWIN) return 0;
-#endif
-#ifdef WIN
- if (!F && !(environment & ENV_WIN32)) return 0;
-#endif
-#ifdef BEOS
- if (!(environment & ENV_BE)) return 0;
-#endif
#ifdef G
if (F && drv->flags & GD_NO_OS_SHELL) return 0;
#endif
@@ -3066,40 +872,14 @@ int can_open_os_shell(int environment)
void set_highpri(void)
{
-#ifdef OS2
- DosSetPriority(PRTYS_PROCESS, PRTYC_FOREGROUNDSERVER, 0, 0);
-#endif
}
-#if !defined(DOS) && !defined(OPENVMS)
void os_seed_random(unsigned char **pool, int *pool_size)
{
*pool = DUMMY;
*pool_size = 0;
}
-#endif
-#if defined(WIN)
-int os_send_fg_cookie(int h)
-{
- DWORD pid;
- pid = GetCurrentProcessId();
- if (hard_write(h, (unsigned char *)&pid, sizeof pid) != sizeof pid)
- return -1;
- return 0;
-}
-int os_receive_fg_cookie(int h)
-{
- DWORD pid;
- BOOL (WINAPI *fn_AllowSetForegroundWindow)(DWORD);
- if (hard_read(h, (unsigned char *)&pid, sizeof pid) != sizeof pid)
- return -1;
- fn_AllowSetForegroundWindow = (BOOL (WINAPI *)(DWORD))GetProcAddress(GetModuleHandleA("user32.dll"), "AllowSetForegroundWindow");
- if (fn_AllowSetForegroundWindow)
- fn_AllowSetForegroundWindow(pid);
- return 0;
-}
-#else
int os_send_fg_cookie(int h)
{
return 0;
@@ -3108,14 +888,9 @@ int os_receive_fg_cookie(int h)
{
return 0;
}
-#endif
void os_detach_console(void)
{
-#if defined(WIN)
- if (is_winnt())
- FreeConsole();
-#endif
#if !defined(NO_FORK_ON_EXIT)
{
pid_t rp;
@@ -3142,173 +917,12 @@ void os_detach_console(void)
#endif
}
-#if defined(OS2) || defined(DOS)
-
-int get_country_language(int c)
-{
- static_const struct {
- int code;
- unsigned char *language;
- } countries[] = {
- { 1, cast_uchar "English" },
- { 2, cast_uchar "French" },
- { 3, cast_uchar "Spanish" },
- { 4, cast_uchar "English" },
- { 7, cast_uchar "Russian" },
- { 27, cast_uchar "English" },
- { 30, cast_uchar "Greek" },
- { 31, cast_uchar "Dutch" },
- { 32, cast_uchar "Dutch" },
- { 33, cast_uchar "French" },
- { 34, cast_uchar "Spanish" },
- { 36, cast_uchar "Hungarian" },
- { 38, cast_uchar "Serbian" },
- { 39, cast_uchar "Italian" },
- { 40, cast_uchar "Romanian" },
- { 41, cast_uchar "Swiss German" },
- { 42, cast_uchar "Czech" },
- { 43, cast_uchar "German" },
- { 44, cast_uchar "English" },
- { 45, cast_uchar "Danish" },
- { 46, cast_uchar "Swedish" },
- { 47, cast_uchar "Norwegian" },
- { 48, cast_uchar "Polish" },
- { 49, cast_uchar "German" },
- { 52, cast_uchar "Spanish" },
- { 54, cast_uchar "Spanish" },
- { 55, cast_uchar "Brazilian Portuguese" },
- { 56, cast_uchar "Spanish" },
- { 57, cast_uchar "Spanish" },
- { 58, cast_uchar "Spanish" },
- { 61, cast_uchar "English" },
- { 64, cast_uchar "English" },
- { 65, cast_uchar "English" },
- { 90, cast_uchar "Turkish" },
- { 99, cast_uchar "English" },
- { 351, cast_uchar "Portuguese" },
- { 353, cast_uchar "English" },
- { 354, cast_uchar "Icelandic" },
- { 358, cast_uchar "Finnish" },
- { 359, cast_uchar "Bulgarian" },
- { 371, cast_uchar "Lithuanian" },
- { 372, cast_uchar "Estonian" },
- { 381, cast_uchar "Serbian" },
- { 384, cast_uchar "Croatian" },
- { 385, cast_uchar "Croatian" },
-#ifdef DOS
- { 421, cast_uchar "Slovak" },
-#else
- { 421, cast_uchar "Czech" },
-#endif
- { 422, cast_uchar "Slovak" },
- { 593, cast_uchar "Spanish" },
- };
- int idx;
-#define C_EQUAL(a, b) countries[a].code == (b)
-#define C_ABOVE(a, b) countries[a].code > (b)
- BIN_SEARCH(array_elements(countries), C_EQUAL, C_ABOVE, c, idx);
- if (idx == -1)
- return -1;
- if (!casestrcmp(language_name(0), countries[idx].language))
- return 0;
- return -1;
-}
-
-#endif
-
-#if defined(OS2)
-
-int os_default_language(void)
-{
- COUNTRYCODE cc;
- COUNTRYINFO ci;
- ULONG ul;
- int rc;
- memset(&cc, 0, sizeof cc);
- rc = DosQueryCtryInfo(sizeof ci, &cc, &ci, &ul);
- if (!rc)
- return get_country_language(ci.country);
- return -1;
-}
-
-#elif defined(WIN)
-
-int os_default_language(void)
-{
- LCID id;
- unsigned char iso639[9];
- unsigned char iso3166[9];
- unsigned char loc[8 + 1 + 8 + 1];
- unsigned char *lang;
- lang = cast_uchar getenv("LANG");
- if (lang) {
- int l = get_language_from_lang(lang);
- if (l >= 0)
- return l;
- }
- id = GetUserDefaultUILanguage();
- if (!GetLocaleInfo(id, LOCALE_SISO639LANGNAME, cast_char iso639, 9))
- return -1;
- iso3166[0] = 0;
- GetLocaleInfo(id, LOCALE_SISO3166CTRYNAME, cast_char iso3166, 9);
- strcpy(cast_char loc, cast_const_char iso639);
- if (id >= 0x400 && iso3166[0]) {
- strcat(cast_char loc, "_");
- strcat(cast_char loc, cast_const_char iso3166);
- }
- return get_language_from_lang(loc);
-}
-
-#elif !defined(DOS)
-
int os_default_language(void)
{
return -1;
}
-#endif
-
-#if defined(WIN) && defined(__CYGWIN__) && defined(HAVE_CYGWIN_CONV_PATH)
-
-int os_default_charset(void)
-{
- unsigned char *term = cast_uchar getenv("TERM");
- if (term) {
- if (!casestrcmp(term, cast_uchar "cygwin")) {
-#if defined(HAVE_NL_LANGINFO) && defined(HAVE_LANGINFO_H) && defined(CODESET)
- return windows_charset();
-#endif
- }
- if (!casestrcmp(term, cast_uchar "xterm")) {
- return utf8_table;
- }
- }
- return -1;
-}
-
-#elif defined(OS2)
-
-int os_default_charset(void)
-{
- ULONG os2_cp[1];
- ULONG size = 0;
- int rc;
- rc = DosQueryCp(sizeof(os2_cp), os2_cp, &size);
- if ((!rc || rc == ERROR_CPLIST_TOO_SMALL) && size >= sizeof(ULONG)) {
- unsigned char a[8];
- int cp;
- snprintf(cast_char a, sizeof a, "%lu", os2_cp[0]);
- if ((cp = get_cp_index(a)) >= 0 && cp != utf8_table)
- return cp;
- }
- return 0;
-}
-
-#elif !defined(DOS)
-
int os_default_charset(void)
{
return -1;
}
-
-#endif
diff --git a/os_dep.h b/os_dep.h
@@ -22,28 +22,7 @@
#ifdef UNIX
#undef UNIX
#endif
-
-#if defined(__EMX__)
-#define OS2
-#elif defined(_WIN32) || defined(__CYGWIN__)
-#define WIN
-#elif defined(__INTERIX)
-#define INTERIX
-#elif defined(__BEOS__) || defined(__HAIKU__)
-#define BEOS
-#elif defined(__riscos__)
-#define RISCOS
-#elif defined(__ATHEOS__) || defined(__SYLLABLE__)
-#define ATHEOS
-#elif defined(__SPAD__)
-#define SPAD
-#elif defined(__VMS)
-#define OPENVMS
-#elif defined(__DJGPP)
-#define DOS
-#else
#define UNIX
-#endif
#if defined(UNIX)
@@ -66,204 +45,6 @@ static inline int dir_sep(unsigned char x) { return x == '/'; }
#define ASSOC_BLOCK
#define ASSOC_CONS_XWIN
-#elif defined(OS2)
-
-static inline int dir_sep(unsigned char x) { return x == '/' || x == '\\'; }
-#define NEWLINE "\r\n"
-/*#define NO_ASYNC_LOOKUP*/
-#define SYSTEM_ID SYS_OS2
-#define SYSTEM_NAME "OS/2"
-#define DEFAULT_SHELL "cmd.exe"
-#define GETSHELL getenv("COMSPEC")
-#define NO_FG_EXEC
-#define NO_CTRL_Z
-#define DOS_FS
-#define DOS_FS_8_3
-#define NO_FILE_SECURITY
-#define NO_FORK_ON_EXIT
-#define ASSOC_CONS_XWIN
-#define DISABLE_SMB
-
-#elif defined(WIN)
-
-static inline int dir_sep(unsigned char x) { return x == '/' || x == '\\'; }
-#define NEWLINE "\r\n"
-/*#define NO_ASYNC_LOOKUP*/
-#define SYSTEM_ID SYS_WIN_32
-#define SYSTEM_NAME "Win32"
-#define DEFAULT_SHELL "cmd.exe"
-#define GETSHELL getenv("COMSPEC")
-#define NO_FG_EXEC
-#define NO_CTRL_Z
-#define DOS_FS
-#define SET_WINDOW_TITLE_UTF_8
-#define ASSOC_CONS_XWIN
-#define DISABLE_SMB
-#ifdef __CYGWIN__
-#define OS_BAD_SIGNALS
-#endif
-#ifndef HAVE_PTHREADS
-#define HAVE_PTHREADS
-#endif
-#if defined(HAVE_SYS_UN_H) && !defined(_UWIN)
-#define USE_AF_UNIX
-#else
-#define DONT_USE_AF_UNIX
-#endif
-#if defined(_UWIN)
-#define USE_WIN32_HEAP
-#endif
-#ifdef USE_WIN32_HEAP
-#define NO_FORK_ON_EXIT
-#endif
-#ifndef __CYGWIN__
-#define OS_NO_SYSTEM_CHARSET
-#endif
-
-#elif defined(INTERIX)
-
-static inline int dir_sep(unsigned char x) { return x == '/'; }
-#define NEWLINE "\n"
-#define FS_UNIX_RIGHTS
-#define FS_UNIX_HARDLINKS
-#define FS_UNIX_SOFTLINKS
-#define FS_UNIX_USERS
-#define SYSTEM_ID SYS_INTERIX
-#define SYSTEM_NAME "Interix"
-#define DEFAULT_SHELL "/bin/sh"
-#define GETSHELL getenv("SHELL")
-#define SHARED_CONFIG_DIR "/etc/"
-#ifdef HAVE_SYS_UN_H
-#define USE_AF_UNIX
-#else
-#define DONT_USE_AF_UNIX
-#endif
-#define ASSOC_BLOCK
-#define ASSOC_CONS_XWIN
-#define OS_NO_SYSTEM_CHARSET
-
-#elif defined(BEOS)
-
-static inline int dir_sep(unsigned char x) { return x == '/'; }
-#define NEWLINE "\n"
-#define NO_ASYNC_LOOKUP /* async lookup works on BeOS but crashes the Haiku kernel */
-#define FS_UNIX_RIGHTS
-#define FS_UNIX_SOFTLINKS
-#define FS_UNIX_USERS
-#define SYSTEM_ID SYS_BEOS
-#define SYSTEM_NAME "BeOS"
-#define DEFAULT_SHELL "/bin/sh"
-#define GETSHELL getenv("SHELL")
-#define NO_CTRL_Z
-#define SHARED_CONFIG_DIR "/etc/"
-#define NO_FORK_ON_EXIT
-#define ASSOC_BLOCK
-#define OS_NO_SYSTEM_CHARSET
-#define OS_NO_SYSTEM_LANGUAGE
-
-#include <sys/time.h>
-#include <sys/types.h>
-#ifdef HAVE_NET_SOCKET_H
-#include <net/socket.h>
-#endif
-#include <sys/socket.h>
-
-#include "beos.h"
-
-#elif defined(RISCOS)
-
-static inline int dir_sep(unsigned char x) { return x == '/' || x == '\\'; }
-#define NEWLINE "\n"
-#define SYSTEM_ID SYS_RISCOS
-#define SYSTEM_NAME "RISC OS"
-#define DEFAULT_SHELL "gos"
-#define GETSHELL getenv("SHELL")
-#define NO_FG_EXEC
-#define NO_CTRL_Z
-#define NO_FILE_SECURITY
-#define NO_FORK_ON_EXIT
-#define DISABLE_SMB
-#define OS_NO_SYSTEM_CHARSET
-#define OS_NO_SYSTEM_LANGUAGE
-
-#elif defined(ATHEOS)
-
-static inline int dir_sep(unsigned char x) { return x == '/'; }
-#define NEWLINE "\n"
-#define FS_UNIX_RIGHTS
-#define FS_UNIX_HARDLINKS
-#define FS_UNIX_SOFTLINKS
-#define FS_UNIX_USERS
-#define SYSTEM_ID SYS_ATHEOS
-#define SYSTEM_NAME "Atheos"
-#define DEFAULT_SHELL "/bin/sh"
-#define GETSHELL getenv("SHELL")
-#define SHARED_CONFIG_DIR "/etc/"
-#define DONT_USE_AF_UNIX
-#define NO_FORK_ON_EXIT
-#define ASSOC_BLOCK
-
-#elif defined(SPAD)
-
-static inline int dir_sep(unsigned char x) { return x == '/'; }
-#define NEWLINE "\n"
-#define SYSTEM_ID SYS_SPAD
-#define SYSTEM_NAME "Spad"
-#define DEFAULT_SHELL "LIB.:/SHELL.EXE"
-#define GETSHELL "LIB.:/SHELL.EXE"
-#define NO_CTRL_Z
-#define SHARED_CONFIG_DIR "ETC.:/"
-#ifdef HAVE_SYS_UN_H
-#define USE_AF_UNIX
-#else
-#define DONT_USE_AF_UNIX
-#endif
-#define NO_FORK_ON_EXIT
-#define ASSOC_BLOCK
-#define ASSOC_CONS_XWIN
-#define OS_NO_SYSTEM_CHARSET
-#define OS_NO_SYSTEM_LANGUAGE
-
-#elif defined(OPENVMS)
-
-static inline int dir_sep(unsigned char x) { return x == '/'; }
-#define NEWLINE "\n"
-#define FS_UNIX_RIGHTS
-#define SYSTEM_ID SYS_OPENVMS
-#define SYSTEM_NAME "VMS"
-#define DEFAULT_SHELL "/DCL"
-#define GETSHELL NULL
-#define SHARED_CONFIG_DIR "/etc/"
-#ifndef HAVE_PTHREADS
-#define HAVE_PTHREADS
-#endif
-#define DONT_USE_AF_UNIX
-#define NO_CTRL_Z
-#define NO_FORK_ON_EXIT
-#define ASSOC_BLOCK
-#define ASSOC_CONS_XWIN
-#define DISABLE_SMB
-#define OS_NO_SYSTEM_CHARSET
-#define OS_NO_SYSTEM_LANGUAGE
-
-#elif defined(DOS)
-
-static inline int dir_sep(unsigned char x) { return x == '/' || x == '\\'; }
-#define NEWLINE "\r\n"
-#define NO_ASYNC_LOOKUP
-#define SYSTEM_ID SYS_DOS
-#define SYSTEM_NAME "DOS"
-#define DEFAULT_SHELL "command.com"
-#define GETSHELL getenv("COMSPEC")
-#define SHARED_CONFIG_DIR "/dev/env/DJDIR/etc"
-#define NO_CTRL_Z
-#define DOS_FS
-#define DOS_FS_8_3
-#define NO_FILE_SECURITY
-#define DONT_USE_AF_UNIX
-#define NO_FORK_ON_EXIT
-#define DISABLE_SMB
-
#endif
#ifdef FS_UNIX_USERS
diff --git a/os_depx.h b/os_depx.h
@@ -123,10 +123,6 @@ extern int errno;
#define SIG_ERR ((int (*)())-1)
#endif
-#if defined(OPENVMS) || defined(DOS)
-#define NO_SIGNAL_HANDLERS
-#endif
-
#if !defined(HAVE_STRTOIMAX) && defined(strtoimax) && defined(HAVE___STRTOLL)
#define HAVE_STRTOIMAX 1
#endif
@@ -169,43 +165,6 @@ int bounced_write(int fd, const void *buf, size_t size);
#endif
#endif
-#ifdef OPENVMS
-#if defined(__INITIAL_POINTER_SIZE)
-#if __INITIAL_POINTER_SIZE == 64
-#define OPENVMS_64BIT
-#endif
-#endif
-#ifndef HAVE_GETCWD
-#define HAVE_GETCWD 1
-#endif
-#define getcwd(x, y) getcwd(x, y, 0)
-#define sleep(x) portable_sleep((x) * 1000) /* sleep is buggy */
-#define OS_SETRAW
-int vms_read(int fd, void *buf, size_t size);
-int vms_write(int fd, const void *buf, size_t size);
-#define read vms_read
-#define write vms_write
-int vms_close(int fd);
-int vms_select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t);
-#define close vms_close
-#define select vms_select
-#endif
-
-#ifdef DOS
-#define DOS_EXTRA_KEYBOARD
-#ifdef DOS_EXTRA_KEYBOARD
-#define OS_SETRAW
-#endif
-int dos_read(int fd, void *buf, size_t size);
-int dos_write(int fd, const void *buf, size_t size);
-int dos_close(int fd);
-int dos_select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t, int from_main_loop);
-#define read dos_read
-#define write dos_write
-#define close dos_close
-#define select(a, b, c, d, e) dos_select(a, b, c, d, e, 0)
-#endif
-
#if defined(O_SIZE) && defined(__EMX__)
#define HAVE_OPEN_PREALLOC
#elif (defined(HAVE_FALLOCATE) || defined(HAVE_POSIX_FALLOCATE)) && !defined(OPENVMS)
@@ -224,21 +183,9 @@ int dos_select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t, int
#define SIGNAL_HANDLER
#endif
-#if defined(HAVE_UTIME) && defined(HAVE_UTIMES) && defined(INTERIX)
-#undef HAVE_UTIMES
-#endif
-
-#if defined(HAVE_HERROR) && defined(__GNUC__) && defined(__hpux)
-#undef HAVE_HERROR
-#endif
-
#ifndef HAVE_SOCKLEN_T
-#ifdef OPENVMS
-#define socklen_t unsigned
-#else
#define socklen_t int
#endif
-#endif
#ifndef PF_INET
#define PF_INET AF_INET
@@ -247,21 +194,8 @@ int dos_select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t, int
#define PF_UNIX AF_UNIX
#endif
-#if defined(__hpux)
-#include "hpux.h"
-#define accept hp_accept
-#define getpeername hp_getpeername
-#define getsockname hp_getsockname
-#define getsockopt hp_getsockopt
-#endif
-
-#if defined(OPENVMS_64BIT)
-#define my_intptr_t long long
-#define my_uintptr_t unsigned long long
-#else
#define my_intptr_t long
#define my_uintptr_t unsigned long
-#endif
#if defined(__GNUC__)
#if __GNUC__ >= 2
@@ -355,15 +289,4 @@ typedef const char *const_char_ptr;
#define THREAD_SAFE_LOOKUP
#endif
-#if defined(DOS)
-#define loop_select(a, b, c, d, e) dos_select(a, b, c, d, e, 1)
-#elif defined(GRDRV_SVGALIB)
-#define loop_select vga_select
-int vga_select(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t);
-#elif defined(GRDRV_ATHEOS)
-#define loop_select ath_select
-int ath_select(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t);
-#else
#define loop_select select
-#endif
-
diff --git a/pmshell.c b/pmshell.c
@@ -1,2556 +0,0 @@
-/* pmshell.c
- * PMShell graphics driver
- * (c) 2002 Mikulas Patocka
- * This file is a part of the Links program, released under GPL.
- */
-
-#include "cfg.h"
-
-/*#define PM_DEBUG*/
-
-#ifdef PM_DEBUG
-#define debug_call(x) do { printf("%016llx, %d: ", (unsigned long long)get_time(), _gettid()); printf x; putchar('\n'); fflush(stdout); } while (0)
-#else
-#define debug_call(x)
-#endif
-
-#ifdef GRDRV_PMSHELL
-
-#include "links.h"
-
-extern struct graphics_driver pmshell_driver;
-
-#ifdef OS2
-
-#define INCL_DOS
-#define INCL_DOSERRORS
-#define INCL_GPI
-#define INCL_WIN
-#include <os2.h>
-
-#include <sys/builtin.h>
-#include <sys/fmutex.h>
-
-#define PM_SPAWN_SUBPROC
-
-/* Links on OS/2 crashes with 24-bit bpp and bitmaps wider than 10921 pixels,
- apparently there is something that expects 15-bit line stride in bitmap
- handling code in pmshell.
- We set this limit lower, to 128, so that we don't exhaust shared memory with
- big images */
-#define OS2_MAX_BITMAP_SIZE 128
-
-/* GpiDrawBits can't draw images with more than 32767 pixes in X direction.
- We'd better draw them line-by-line */
-#define OS2_MAX_LINE_SIZE 8191
-
-extern PPIB os2_pib;
-
-static ULONG pm_hidden_frame = 0;
-static ULONG pm_frame = (FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX | FCF_SHELLPOSITION | FCF_TASKLIST | FCF_NOBYTEALIGN);
-
-static HAB hab_disp;
-static HAB hab;
-static HMQ hmq;
-static HDC hdc_mem;
-static HPS hps_mem;
-static HWND hwnd_hidden;
-static HPS hps_hidden;
-static HPOINTER icon;
-
-static _fmutex pm_mutex;
-
-static int pm_lock_init(void)
-{
- return _fmutex_create(&pm_mutex, 0);
-}
-
-static void pm_lock_close(void)
-{
- _fmutex_checked_close(&pm_mutex);
-}
-
-static inline void pm_lock(void)
-{
- _fmutex_request(&pm_mutex, _FMR_IGNINT);
-}
-
-static inline void pm_unlock(void)
-{
- _fmutex_release(&pm_mutex);
-}
-
-static HEV pm_sem;
-static ULONG pm_event_dummy;
-
-static int pm_event_init(void)
-{
- return DosCreateEventSem(NULL, &pm_sem, 0, 0);
-}
-
-static void pm_event_close(void)
-{
- APIRET r;
- r = DosCloseEventSem(pm_sem);
- if (r && r != ERROR_SEM_BUSY)
- fatal_exit("DoscloseEventSem failed: %ld", (long)r);
-}
-
-static inline void pm_event_wait(void)
-{
- APIRET r;
- wait_again:
- r = DosWaitEventSem(pm_sem, SEM_INDEFINITE_WAIT);
- if (r == ERROR_INTERRUPT)
- goto wait_again;
- if (r)
- fatal_exit("DosWaitEventSem failed: %ld", (long)r);
- if ((r = DosResetEventSem(pm_sem, &pm_event_dummy)))
- fatal_exit("DosResetEventSem failed: %ld", (long)r);
-}
-
-static inline void pm_event_signal(void)
-{
- APIRET r;
- if ((r = DosPostEventSem(pm_sem)))
- fatal_exit("DosPostEventSem failed: %ld", (long)r);
-}
-
-static inline void SetCapture(HWND hwnd)
-{
- WinSetCapture(HWND_DESKTOP, hwnd);
-}
-
-static inline void ReleaseCapture(void)
-{
- WinSetCapture(HWND_DESKTOP, NULLHANDLE);
-}
-
-#endif
-
-#ifdef WIN
-
-/*#define UNICODE*/
-/*#define NO_STRICT*/
-
-#include <windows.h>
-#ifdef HAVE_WINDOWSX_H
-#include <windowsx.h>
-#endif
-#include <pthread.h>
-
-static HMODULE module_handle;
-static pthread_t pthread_handle;
-static int unicode_title_supported;
-static int unicode_supported;
-static ATOM window_class_atom;
-static HDC screen_dc;
-static HWND hwnd_hidden;
-static HICON icon_big;
-static HICON icon_small;
-
-#define RECTL RECT
-#define xLeft left
-#define xRight right
-#define yTop top
-#define yBottom bottom
-
-#define WM_BUTTON1DOWN WM_LBUTTONDOWN
-#define WM_BUTTON1DBLCLK WM_LBUTTONDBLCLK
-#define WM_BUTTON2DOWN WM_RBUTTONDOWN
-#define WM_BUTTON2DBLCLK WM_RBUTTONDBLCLK
-#define WM_BUTTON3DOWN WM_MBUTTONDOWN
-#define WM_BUTTON3DBLCLK WM_MBUTTONDBLCLK
-
-#define WM_BUTTON1UP WM_LBUTTONUP
-#define WM_BUTTON2UP WM_RBUTTONUP
-#define WM_BUTTON3UP WM_MBUTTONUP
-
-#ifndef WM_XBUTTONDOWN
-#define WM_XBUTTONDOWN 0x20b
-#endif
-#ifndef WM_XBUTTONDBLCLK
-#define WM_XBUTTONDBLCLK 0x20d
-#endif
-#ifndef WM_XBUTTONUP
-#define WM_XBUTTONUP 0x20c
-#endif
-#ifndef XBUTTON1
-#define XBUTTON1 0x0001
-#endif
-#ifndef XBUTTON2
-#define XBUTTON2 0x0002
-#endif
-#ifndef GET_X_LPARAM
-#define GET_X_LPARAM(lp) ((short)LOWORD(lp))
-#endif
-#ifndef GET_Y_LPARAM
-#define GET_Y_LPARAM(lp) ((short)HIWORD(lp))
-#endif
-
-static HANDLE winapi_semaphore;
-
-static int pm_lock_init(void)
-{
- winapi_semaphore = CreateSemaphoreA(NULL, 1, 1, NULL);
- return !winapi_semaphore;
-}
-
-static void pm_lock_close(void)
-{
- if (!CloseHandle(winapi_semaphore))
- fatal_exit("CloseHandle failed");
-}
-
-static inline void pm_lock(void)
-{
- if (WaitForSingleObject(winapi_semaphore, INFINITE) == WAIT_FAILED)
- fatal_exit("WaitForSingleObject failed");
-}
-
-static inline void pm_unlock(void)
-{
- if (!ReleaseSemaphore(winapi_semaphore, 1, NULL))
- fatal_exit("ReleaseSemaphore failed");
-}
-
-static HANDLE winapi_event;
-
-static int pm_event_init(void)
-{
- winapi_event = CreateEventA(NULL, FALSE, FALSE, NULL);
- return !winapi_event;
-}
-
-static void pm_event_close(void)
-{
- if (!CloseHandle(winapi_event))
- fatal_exit("CloseHandle failed");
-}
-
-static inline void pm_event_wait(void)
-{
- if (WaitForSingleObject(winapi_event, INFINITE) == WAIT_FAILED)
- fatal_exit("WaitForSingleObject failed");
-}
-
-static inline void pm_event_signal(void)
-{
- if (!SetEvent(winapi_event))
- fatal_exit("SetEvent failed");
-}
-
-#endif
-
-
-#define PM_ALLOC_ZERO 1
-#define PM_ALLOC_MAYFAIL 2
-
-#if defined(WIN) && !defined(USE_WIN32_HEAP)
-
-/* space allocated with malloc may span multiple mapped areas
- and SetDIBitsToDevice doesn't like it. So use HeapAlloc/HeapFree */
-
-static void *pm_alloc(size_t size, int flags)
-{
- void *data;
-again:
- data = HeapAlloc(GetProcessHeap(), flags & PM_ALLOC_ZERO ? HEAP_ZERO_MEMORY : 0, size);
- if (!data) {
- if (out_of_memory(0, flags & PM_ALLOC_MAYFAIL ? NULL : cast_uchar "pm_alloc", size))
- goto again;
- }
- return data;
-}
-
-static void pm_free(void *ptr)
-{
- HeapFree(GetProcessHeap(), 0, ptr);
-}
-
-#else
-
-static void *pm_alloc(size_t size, int flags)
-{
- if (!(flags & PM_ALLOC_MAYFAIL))
- if (!(flags & PM_ALLOC_ZERO))
- return mem_alloc(size);
- else
- return mem_calloc(size);
- else
- if (!(flags & PM_ALLOC_ZERO))
- return mem_alloc_mayfail(size);
- else
- return mem_calloc_mayfail(size);
-}
-
-#define pm_free mem_free
-
-#endif
-
-
-static BITMAPINFO *pm_bitmapinfo;
-static int icon_set;
-
-#define pm_class_name "links"
-#define pm_class_name_l L"links"
-
-#define E_KEY 1
-#define E_MOUSE 2
-#define E_REDRAW 3
-#define E_RESIZE 4
-
-struct pm_event {
- list_entry_1st
- int type;
- int x1, y1, x2, y2;
- list_entry_last
-};
-
-struct pm_window {
- list_entry_1st
- int x, y;
- unsigned char in;
- unsigned char minimized;
- struct pm_window *nxt;
- struct pm_window **prv;
-#ifdef OS2
- HPS ps;
- HWND h;
-#endif
-#ifdef WIN
- HDC dc;
- HPEN pen_orig;
- HPEN pen_cache;
- HBRUSH brush_cache;
- int pen_cache_color;
- int brush_cache_color;
-#endif
- HWND hc;
- struct graphics_device *dev;
- int button;
- unsigned long lastpos;
- struct list_head queue;
- list_entry_last
-};
-
-#define WIN_HASH 64
-
-static int HASH_VALUE(HWND hw)
-{
- return (unsigned long)hw & (WIN_HASH - 1);
-}
-
-static struct pm_window *pm_windows[WIN_HASH];
-
-static void pm_hash_window(struct pm_window *win)
-{
- int pos = HASH_VALUE(win->hc);
- win->prv = &pm_windows[pos];
- if ((win->nxt = pm_windows[pos])) pm_windows[pos]->prv = &win->nxt;
- pm_windows[pos] = win;
-}
-
-static void pm_unhash_window(struct pm_window *win)
-{
- if (win->nxt) win->nxt->prv = win->prv;
- *win->prv = win->nxt;
-}
-
-static inline struct pm_window *pm_lookup_window(HWND h)
-{
- struct pm_window *win;
- for (win = pm_windows[HASH_VALUE(h)]; win && win->hc != h; win = win->nxt) ;
- return win;
-}
-
-#define pm_win(dev) ((struct pm_window *)dev->driver_data)
-
-static int pm_pipe[2];
-
-static unsigned char *pm_status;
-
-static int pm_cp;
-
-static struct list_head pm_event_windows = { &pm_event_windows, &pm_event_windows };
-
-static void pm_send_event(struct pm_window *win, int t, int x1, int y1, int x2, int y2)
-{
- /* must be called with pm_lock */
- struct pm_event *ev;
- if ((ev = malloc(sizeof(struct pm_event)))) {
- ev->type = t;
- ev->x1 = x1, ev->y1 = y1;
- ev->x2 = x2, ev->y2 = y2;
- if (!win->in) {
- if (list_empty(pm_event_windows)) {
- int wr;
- EINTRLOOP(wr, write(pm_pipe[1], "x", 1));
- }
- add_to_list(pm_event_windows, win);
- win->in = 1;
- }
- add_to_list(win->queue, ev);
- }
-}
-
-static void pm_send_mouse_event(struct pm_window *win, int x1, int y1, int b)
-{
- if (!list_empty(win->queue)) {
- struct pm_event *last = list_struct(win->queue.next, struct pm_event);
- if (last->type == E_MOUSE && last->x2 == b) {
- last->x1 = x1;
- last->y1 = y1;
- return;
- }
- }
- pm_send_event(win, E_MOUSE, x1, y1, b, 0);
-}
-
-static void pm_cancel_event(struct pm_window *win, int t, struct pm_event **pev)
-{
- struct pm_event *ev;
- struct list_head *lev;
- if (pev) *pev = NULL;
- foreachback(struct pm_event, ev, lev, win->queue) if (ev->type == t) {
- if (pev) *pev = ev;
- else {
- del_from_list(ev);
- free(ev);
- }
- return;
- }
-}
-
-static void pm_resize(struct pm_window *win, RECTL *r)
-{
- struct pm_event *ev;
- win->x = r->xRight;
- win->y = r->yTop;
- pm_cancel_event(win, E_REDRAW, NULL);
- pm_cancel_event(win, E_RESIZE, &ev);
- if (ev) {
- ev->x2 = r->xRight;
- ev->y2 = r->yTop;
- } else pm_send_event(win, E_RESIZE, 0, 0, r->xRight, r->yTop);
-}
-
-static void pm_redraw(struct pm_window *win, RECTL *r)
-{
- struct pm_event *ev;
- pm_cancel_event(win, E_RESIZE, &ev);
- if (ev) return;
- pm_cancel_event(win, E_REDRAW, &ev);
- if (ev) {
- if (r->xLeft < ev->x1) ev->x1 = r->xLeft;
- if (r->xRight > ev->x2) ev->x2 = r->xRight;
- if (win->y - r->yTop < ev->y1) ev->y1 = win->y - r->yTop;
- if (win->y - r->yBottom > ev->y2) ev->y2 = win->y - r->yBottom;
- return;
- }
- pm_send_event(win, E_REDRAW, r->xLeft, win->y - r->yTop, r->xRight, win->y - r->yBottom);
-}
-
-#ifdef OS2
-
-#define N_VK 0x42
-
-static struct os2_key pm_vk_table[N_VK] = {
- {0, 0}, {0, 0}, {0, 0}, {0, 0}, {KBD_CTRL_C, 0}, {KBD_BS, 0}, {KBD_TAB, 0}, {KBD_TAB, KBD_SHIFT},
- {KBD_ENTER, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {KBD_ESC, 0},
- {' ', 0}, {KBD_PAGE_UP, 0}, {KBD_PAGE_DOWN, 0}, {KBD_END, 0}, {KBD_HOME, 0}, {KBD_LEFT, 0}, {KBD_UP, 0}, {KBD_RIGHT, 0},
- {KBD_DOWN, 0}, {0, 0}, {KBD_INS, 0}, {KBD_DEL, 0}, {0, 0}, {0, 0}, {KBD_ENTER, 0}, {0, 0},
- {KBD_F1, 0}, {KBD_F2, 0}, {KBD_F3, 0}, {KBD_F4, 0}, {KBD_F5, 0}, {KBD_F6, 0}, {KBD_F7, 0}, {KBD_F8, 0},
- {KBD_F9, 0}, {KBD_F10, 0}, {KBD_F11, 0}, {KBD_F12, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
- {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
- {0, 0}, {KBD_DEL, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
- {0, 0}, {0, 0}
-};
-
-#endif
-
-static int win_x(struct pm_window *win)
-{
-#ifdef OS2
- int x = (short)(win->lastpos & 0xffff);
-#endif
-#ifdef WIN
- int x = GET_X_LPARAM(win->lastpos);
-#endif
- if (x < 0) x = -1;
- if (x > win->x) x = win->x;
- return x;
-}
-
-static int win_y(struct pm_window *win)
-{
-#ifdef OS2
- int y = (short)(win->y - (win->lastpos >> 16));
-#endif
-#ifdef WIN
- int y = GET_Y_LPARAM(win->lastpos);
-#endif
- if (y < 0) y = -1;
- if (y > win->y) y = win->y;
- return y;
-}
-
-static void pm_user_msg(unsigned long msg, void *mp1, void *mp2);
-
-#ifdef OS2
-static MRESULT EXPENTRY pm_window_proc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
-#define mouse_pos ((unsigned)mp1)
-#endif
-#ifdef WIN
-static LRESULT CALLBACK pm_window_proc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2)
-#define mouse_pos ((unsigned long)mp2)
-#endif
-{
-#ifdef OS2
- MRESULT ret;
- int k_usch;
- int scancode;
-#endif
- int flags;
- long k_usvk;
- long k_fsflags;
- long key;
- struct pm_window *win;
- RECTL wr, ur;
- debug_call(("T: pm_window_proc: %lx %lx %p %p", hwnd, msg, mp1, mp2));
- if (hwnd == hwnd_hidden) {
- debug_call(("T: pm_user_msg"));
- pm_user_msg(msg, (void *)mp1, (void *)mp2);
- } else switch (msg) {
- case WM_PAINT:
- debug_call(("T: WM_PAINT: pm_lock"));
- pm_lock();
-#ifdef OS2
- debug_call(("T: WM_PAINT: WinQueryUpdateRect"));
- WinQueryUpdateRect(hwnd, &ur);
- debug_call(("T: WM_PAINT: WinQueryWindowRect"));
- if (!WinQueryWindowRect(hwnd, &wr)) {
- debug_call(("T: WM_PAINT: WinQueryWindowRect failed"));
- memset(&wr, 0, sizeof wr);
- }
- debug_call(("T: WM_PAINT: WinValidateRect"));
- WinValidateRect(hwnd, &ur, FALSE);
-#endif
-#ifdef WIN
- GetUpdateRect(hwnd, &ur, FALSE);
- if (!GetClientRect(hwnd, &wr)) {
- memset(&wr, 0, sizeof wr);
- }
- wr.yTop = wr.yBottom;
- wr.yBottom = 0;
- if (!ValidateRect(hwnd, &ur))
- fatal_exit("ValidateRect failed");
-#endif
- debug_call(("T: WM_PAINT: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: WM_PAINT: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: WM_PAINT: return 0"));
- return 0;
- }
- if (win->minimized) {
- debug_call(("T: WM_PAINT: win->minimized"));
- pm_unlock();
- debug_call(("T: WM_PAINT: break"));
- break;
- }
-#ifdef WIN
- ur.yTop = win->y - ur.yTop;
- ur.yBottom = win->y - ur.yBottom;
-#endif
- if (wr.xRight != win->x || wr.yTop != win->y) {
-#if 0
- if (WinQueryWindowRect(win->h, &wr)) {
- pm_default_window_width = wr.xRight;
- pm_default_window_height = wr.yTop;
- }
-#endif
- debug_call(("T: WM_PAINT: pm_resize"));
- pm_resize(win, &wr);
- } else {
- debug_call(("T: WM_PAINT: pm_redraw"));
- pm_redraw(win, &ur);
- }
- debug_call(("T: WM_PAINT: pm_unlock"));
- pm_unlock();
- debug_call(("T: WM_PAINT: return 0"));
- return 0;
-#ifdef OS2
- case WM_MINMAXFRAME:
- debug_call(("T: WM_MINMAXFRAME: pm_lock"));
- pm_lock();
- debug_call(("T: WM_MINMAXFRAME: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: WM_MINMAXFRAME: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: WM_MINMAXFRAME: return 0"));
- return 0;
- }
- if (((SWP *)mp1)->fl & (SWP_HIDE | SWP_MINIMIZE))
- win->minimized = 1;
- else
- win->minimized = 0;
- debug_call(("T: WM_MINMAXFRAME: minimized: %d, win->minimized", win->minimized));
- pm_unlock();
- debug_call(("T: WM_MINMAXFRAME: break"));
- break;
-#endif
- case WM_CLOSE:
- debug_call(("T: WM_CLOSE"));
- case WM_QUIT:
- debug_call(("T: WM_QUIT: pm_lock"));
- pm_lock();
- debug_call(("T: WM_QUIT: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: WM_QUIT: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: WM_QUIT: return 0"));
- return 0;
- }
- debug_call(("T: WM_QUIT: pm_send_event"));
- pm_send_event(win, E_KEY, KBD_CTRL_C, 0, 0, 0);
- debug_call(("T: WM_QUIT: pm_unlock"));
- pm_unlock();
- debug_call(("T: WM_QUIT: return 0"));
- return 0;
- case WM_CHAR:
- debug_call(("T: WM_CHAR"));
-#ifdef WIN
- case WM_SYSCHAR:
- case WM_KEYDOWN:
- case WM_SYSKEYDOWN:
-#endif
-#ifdef OS2
- k_fsflags = (int)mp1;
- scancode = ((unsigned long)mp1 >> 24) & 0xff;
- k_usch = (int)mp2 & 0xffff;
- k_usvk = ((int)mp2 >> 16) & 0xffff;
-
- /*
- * F1 keydown is lost for unknown reason --- so catch
- * keyup instead.
- */
- if ((k_fsflags & (KC_VIRTUALKEY | KC_CHAR)) == KC_VIRTUALKEY && k_usvk == 0x20)
- k_fsflags ^= KC_KEYUP;
-
- if (k_fsflags & (KC_KEYUP | KC_DEADKEY | KC_INVALIDCOMP)) {
- debug_call(("T: WM_CHAR: return 0 @ 1"));
- return 0;
- }
-
- flags = (k_fsflags & KC_SHIFT ? KBD_SHIFT : 0) | (k_fsflags & KC_CTRL ? KBD_CTRL : 0) | (k_fsflags & KC_ALT ? KBD_ALT : 0);
- if (k_fsflags & KC_ALT && ((scancode >= 0x47 && scancode <= 0x49) || (scancode >= 0x4b && scancode <= 0x4d) || (scancode >= 0x4f && scancode <= 0x52))) {
- debug_call(("T: WM_CHAR: return 0 @ 2"));
- return 0;
- }
- if ((k_fsflags & (KC_VIRTUALKEY | KC_CHAR)) == KC_VIRTUALKEY) {
- if (k_usvk < N_VK && (key = pm_vk_table[k_usvk].x)) {
- flags |= pm_vk_table[k_usvk].y;
- if (key == KBD_CTRL_C) flags &= ~KBD_CTRL;
- goto s;
- }
- }
- if (k_usch & 0xff) {
- key = k_usch & 0xff;
- if (!(flags & KBD_CTRL)) {
- if (key == 0x0d) key = KBD_ENTER;
- if (key == 0x08) key = KBD_BS;
- if (key == 0x09) key = KBD_TAB;
- if (key == 0x1b) key = KBD_ESC;
- }
- if (key >= 0 && key < ' ') key += '@', flags |= KBD_CTRL;
- } else key = os2xtd[k_usch >> 8].x, flags |= os2xtd[k_usch >> 8].y;
- if ((key & 0xdf) == 'C' && (flags & KBD_CTRL)) key = KBD_CTRL_C, flags &= ~KBD_CTRL;
- s:
- if (!key) {
- debug_call(("T: WM_CHAR: return 0 @ 3"));
- return 0;
- }
- /*if (key >= 0) flags &= ~KBD_SHIFT;*/
- if (key >= 0x80 && pm_cp) {
- if ((key = cp2u(key, pm_cp)) < 0) {
- debug_call(("T: WM_CHAR: return 0 @ 4"));
- return 0;
- }
- }
-#endif
-#ifdef WIN
- k_fsflags = (long)mp2;
- flags = 0;
- if (k_fsflags & (1 << 29))
- flags |= KBD_ALT;
- if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
- /*fprintf(stderr, "vk: %lx %lx\n", (long)mp1, (long)mp2);*/
- k_usvk = (long)mp1;
- switch (k_usvk) {
- case VK_CANCEL: key = KBD_CTRL_C; break;
- case VK_PRIOR: key = KBD_PAGE_UP; break;
- case VK_NEXT: key = KBD_PAGE_DOWN; break;
- case VK_END: key = KBD_END; break;
- case VK_HOME: key = KBD_HOME; break;
- case VK_LEFT: key = KBD_LEFT; break;
- case VK_RIGHT: key = KBD_RIGHT; break;
- case VK_DOWN: key = KBD_DOWN; break;
- case VK_UP: key = KBD_UP; break;
- case VK_INSERT: key = KBD_INS; break;
- case VK_DELETE: key = KBD_DEL; break;
- case VK_HELP: key = KBD_F1; break;
- case VK_F1: key = KBD_F1; break;
- case VK_F2: key = KBD_F2; break;
- case VK_F3: key = KBD_F3; break;
- case VK_F4: key = KBD_F4; break;
- case VK_F5: key = KBD_F5; break;
- case VK_F6: key = KBD_F6; break;
- case VK_F7: key = KBD_F7; break;
- case VK_F8: key = KBD_F8; break;
- case VK_F9: key = KBD_F9; break;
- case VK_F10: key = KBD_F10; break;
- case VK_F11: key = KBD_F11; break;
- case VK_F12: key = KBD_F12; break;
- default: return 0;
- }
- } else {
- /*fprintf(stderr, "ch: %lx %lx\n", (long)mp1, (long)mp2);*/
- key = (long)mp1;
- if (key <= 0) return 0;
- if (key > 0 && key < 0x20) {
- if (key == 3) key = KBD_CTRL_C;
- else if (key == 8) key = KBD_BS;
- else if (key == 9) key = KBD_TAB;
- else if (key == 10) key = KBD_ENTER;
- else if (key == 13) key = KBD_ENTER;
- else if (key == 27) key = KBD_ESC;
- else if (key == 127) key = KBD_BS;
- else {
- key += 'A' - 1;
- flags |= KBD_CTRL;
- }
- } else if (!unicode_supported) {
- key = cp2u(key, pm_cp);
- }
- }
-#endif
- debug_call(("T: WM_CHAR: pm_lock"));
- pm_lock();
- debug_call(("T: WM_CHAR: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: WM_CHAR: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: WM_CHAR: return 0"));
- return 0;
- }
- debug_call(("T: WM_CHAR: pm_send_event"));
- pm_send_event(win, E_KEY, key, flags, 0, 0);
- debug_call(("T: WM_CHAR: pm_unlock"));
- pm_unlock();
- debug_call(("T: WM_CHAR: return 0"));
- return 0;
- case WM_BUTTON1DOWN:
- case WM_BUTTON1DBLCLK:
- flags = B_LEFT;
- goto button_down;
- case WM_BUTTON2DOWN:
- case WM_BUTTON2DBLCLK:
- flags = B_RIGHT;
- goto button_down;
- case WM_BUTTON3DOWN:
- case WM_BUTTON3DBLCLK:
- flags = B_MIDDLE;
- goto button_down;
- button_down:
- debug_call(("T: BUTTON_DOWN: pm_lock"));
- pm_lock();
- debug_call(("T: BUTTON_DOWN: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: BUTTON_DOWN: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: BUTTON_DOWN: break"));
- break;
- }
- win->button |= 1 << flags;
- win->lastpos = mouse_pos;
- debug_call(("T: BUTTON_DOWN: pm_send_event (%d)", flags));
- pm_send_event(win, E_MOUSE, win_x(win), win_y(win), B_DOWN | flags, 0);
- debug_call(("T: BUTTON_DOWN: pm_unlock"));
- pm_unlock();
- debug_call(("T: BUTTON_DOWN: SetCapture"));
- SetCapture(hwnd);
- debug_call(("T: BUTTON_DOWN: break"));
- break;
- case WM_BUTTON1UP:
-#ifdef OS2
- case WM_BUTTON1MOTIONEND:
-#endif
- flags = B_LEFT;
- goto button_up;
- case WM_BUTTON2UP:
-#ifdef OS2
- case WM_BUTTON2MOTIONEND:
-#endif
- flags = B_RIGHT;
- goto button_up;
- case WM_BUTTON3UP:
-#ifdef OS2
- case WM_BUTTON3MOTIONEND:
-#endif
- flags = B_MIDDLE;
- goto button_up;
- button_up:
- debug_call(("T: BUTTON_UP: pm_lock"));
- pm_lock();
- debug_call(("T: BUTTON_UP: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: BUTTON_UP: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: BUTTON_UP: break"));
- break;
- }
- if (msg == WM_BUTTON1UP) win->lastpos = mouse_pos;
- if (win->button & (1 << flags)) {
- debug_call(("T: BUTTON_UP: pm_send_event (%d)", flags));
- pm_send_event(win, E_MOUSE, win_x(win), win_y(win), B_UP | flags, 0);
- }
- win->button &= ~(1 << flags);
- debug_call(("T: BUTTON_UP: pm_unlock"));
- pm_unlock();
- if (!win->button) {
- debug_call(("T: BUTTON_UP: ReleaseCapture"));
- ReleaseCapture();
- }
- debug_call(("T: BUTTON_UP: break"));
- break;
-#ifdef WIN
- case WM_XBUTTONDOWN:
- case WM_XBUTTONDBLCLK:
- if (HIWORD(mp1) == XBUTTON1)
- flags = B_FOURTH;
- else if (HIWORD(mp1) == XBUTTON2)
- flags = B_FIFTH;
- else break;
- goto button_down;
- case WM_XBUTTONUP:
- if (HIWORD(mp1) == XBUTTON1)
- flags = B_FOURTH;
- else if (HIWORD(mp1) == XBUTTON2)
- flags = B_FIFTH;
- else break;
- goto button_up;
-#endif
- case WM_MOUSEMOVE:
- debug_call(("T: WM_MOUSEMOVE: pm_lock"));
- pm_lock();
- debug_call(("T: WM_MOUSEMOVE: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: WM_MOUSEMOVE: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: WM_MOUSEMOVE: break"));
- break;
- }
-#ifdef OS2
- debug_call(("T: WM_MOUSEMOVE: %x -> WinQueryCapture", win->button));
- if (win->button && WinQueryCapture(HWND_DESKTOP) != hwnd) {
- debug_call(("T: WM_MOUSEMOVE: clear buttons"));
- for (flags = B_LEFT; flags <= B_SIXTH; flags++)
- if (win->button & (1 << flags))
- pm_send_event(win, E_MOUSE, win_x(win), win_y(win), B_UP | flags, 0);
- win->button = 0;
- }
-#endif
- if (win->lastpos == mouse_pos) {
- debug_call(("T: WM_MOUSEMOVE: pm_unlock"));
- pm_unlock();
- debug_call(("T: WM_MOUSEMOVE: break"));
- break;
- }
- win->lastpos = mouse_pos;
- debug_call(("T: WM_MOUSEMOVE: pm_send_mouse_event"));
- pm_send_mouse_event(win, win_x(win), win_y(win),
- (win->button ? B_DRAG : B_MOVE) |
- (win->button & (1 << B_LEFT) ? B_LEFT :
- win->button & (1 << B_MIDDLE) ? B_MIDDLE :
- win->button & (1 << B_RIGHT) ? B_RIGHT :
- win->button & (1 << B_FOURTH) ? B_FOURTH :
- win->button & (1 << B_FIFTH) ? B_FIFTH :
- win->button & (1 << B_SIXTH) ? B_SIXTH :
- 0));
- debug_call(("T: WM_MOUSEMOVE: pm_unlock"));
- pm_unlock();
- debug_call(("T: WM_MOUSEMOVE: break"));
- break;
-#ifdef WIN
- case WM_CAPTURECHANGED:
- pm_lock();
- if (!(win = pm_lookup_window(hwnd))) { pm_unlock(); break; }
- if ((HWND)mp2 == win->hc) { pm_unlock(); break; }
- for (flags = B_LEFT; flags <= B_SIXTH; flags++)
- if (win->button & (1 << flags))
- pm_send_event(win, E_MOUSE, win_x(win), win_y(win), B_UP | flags, 0);
- win->button = 0;
- pm_unlock();
- break;
-#endif
-#ifdef OS2
- case WM_VSCROLL:
- debug_call(("T: VM_VSCROLL: pm_lock"));
- pm_lock();
- debug_call(("T: VM_VSCROLL: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: VM_VSCROLL: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: VM_VSCROLL: break"));
- break;
- }
- if ((unsigned long)mp2 == SB_LINEUP << 16 || (unsigned long)mp2 == SB_LINEDOWN << 16) {
- debug_call(("T: VM_VSCROLL: pm_send_event"));
- pm_send_event(win, E_MOUSE, win_x(win), win_y(win), ((unsigned long)mp2 == SB_LINEUP << 16 ? B_WHEELUP1 : B_WHEELDOWN1) | B_MOVE, 0);
- }
- debug_call(("T: VM_VSCROLL: pm_unlock"));
- pm_unlock();
- debug_call(("T: VM_VSCROLL: break"));
- break;
- case WM_HSCROLL:
- debug_call(("T: VM_HSCROLL: pm_lock"));
- pm_lock();
- debug_call(("T: VM_HSCROLL: pm_lookup_window"));
- if (!(win = pm_lookup_window(hwnd))) {
- debug_call(("T: VM_HSCROLL: pm_lookup_window failed"));
- pm_unlock();
- debug_call(("T: VM_HSCROLL: break"));
- break;
- }
- if ((unsigned long)mp2 == SB_LINELEFT << 16 || (unsigned long)mp2 == SB_LINERIGHT << 16) {
- debug_call(("T: VM_HSCROLL: pm_send_event"));
- pm_send_event(win, E_MOUSE, win_x(win), win_y(win), ((unsigned long)mp2 == SB_LINELEFT << 16 ? B_WHEELLEFT1 : B_WHEELRIGHT1) | B_MOVE, 0);
- }
- debug_call(("T: VM_HSCROLL: pm_unlock"));
- pm_unlock();
- debug_call(("T: VM_HSCROLL: break"));
- break;
-#endif
-#ifdef WIN
- case WM_MOUSEWHEEL:
- case 0x020e:
- flags = HIWORD(mp1);
- if (!flags) break;
- pm_lock();
- if (!(win = pm_lookup_window(hwnd))) { pm_unlock(); break; }
- pm_send_event(win, E_MOUSE, win_x(win), win_y(win), (flags > 0 && flags < 0x8000 ? (msg == WM_MOUSEWHEEL ? B_WHEELUP : B_WHEELRIGHT) : (msg == WM_MOUSEWHEEL ? B_WHEELDOWN: B_WHEELLEFT)) | B_MOVE, 0);
- pm_unlock();
- break;
-#endif
- }
-#ifdef OS2
- debug_call(("T: WinDefWindowProc: %lx %lx %p %p", hwnd, msg, mp1, mp2));
- ret = WinDefWindowProc(hwnd, msg, mp1, mp2);
- debug_call(("T: WinDefWindowProc returned %p", ret));
- return ret;
-#endif
-#ifdef WIN
- if (!unicode_supported)
- return DefWindowProcA(hwnd, msg, mp1, mp2);
- else
- return DefWindowProcW(hwnd, msg, mp1, mp2);
-#endif
-}
-
-static int pm_thread_shutdown;
-
-#define MSG_CREATE_WINDOW (WM_USER + 0)
-#define MSG_DELETE_WINDOW (WM_USER + 1)
-#define MSG_SET_WINDOW_TITLE (WM_USER + 2)
-#define MSG_SHUTDOWN_THREAD (WM_USER + 3)
-
-static void pm_user_msg(unsigned long msg, void *mp1, void *mp2)
-{
- struct pm_window *win;
- switch (msg) {
- case MSG_CREATE_WINDOW:
- win = mp1;
-#ifdef OS2
- debug_call(("T: WinCreateStdWindow"));
- win->h = WinCreateStdWindow(HWND_DESKTOP, 0, &pm_frame, pm_class_name, "Links", 0, 0, 0, &win->hc);
- debug_call(("T: WinCreateStdWindow: %lx", win->h));
- if (win->h != NULLHANDLE) {
- if (icon != NULLHANDLE) {
- debug_call(("T: WinSendMsg"));
- WinSendMsg(win->h, WM_SETICON, (void *)icon, 0);
- }
- debug_call(("T: WinSetWindowPos"));
- if (!WinSetWindowPos(win->h, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_SHOW | SWP_ZORDER))
- error("WinSetWindowPos failed");
- }
-#endif
-#ifdef WIN
- if (unicode_supported) {
- win->hc = CreateWindowExW(WS_EX_APPWINDOW | WS_EX_LEFT, (void *)(unsigned long)window_class_atom, L"Links", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, module_handle, NULL);
- } else {
- win->hc = CreateWindowExA(WS_EX_APPWINDOW | WS_EX_LEFT, (void *)(unsigned long)window_class_atom, "Links", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, module_handle, NULL);
- }
- if (win->hc != NULL) {
- if (unicode_supported) {
- if (icon_big != NULL) SendMessageW(win->hc, WM_SETICON, ICON_BIG, (LPARAM)icon_big);
- if (icon_small != NULL) SendMessageW(win->hc, WM_SETICON, ICON_SMALL, (LPARAM)icon_small);
- } else {
- if (icon_big != NULL) SendMessageA(win->hc, WM_SETICON, ICON_BIG, (LPARAM)icon_big);
- if (icon_small != NULL) SendMessageA(win->hc, WM_SETICON, ICON_SMALL, (LPARAM)icon_small);
- }
- ShowWindow(win->hc, SW_SHOW);
- /*SetWindowPos(win->hc, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);*/
- SetForegroundWindow(win->hc);
- }
-#endif
- debug_call(("T: pm_lock"));
- pm_lock();
- debug_call(("T: pm_event_signal"));
- pm_event_signal();
- debug_call(("T: break"));
- break;
- case MSG_DELETE_WINDOW:
- win = mp1;
-#ifdef OS2
- debug_call(("T: WinDestroyWindow"));
- if (!WinDestroyWindow(win->h))
- fatal_exit("WinDestroyWindow failed");
-#endif
-#ifdef WIN
- if (!DestroyWindow(win->hc))
- fatal_exit("DestroyWindow failed");
-#endif
- debug_call(("T: pm_lock"));
- pm_lock();
- debug_call(("T: pm_event_signal"));
- pm_event_signal();
- debug_call(("T: break"));
- break;
- case MSG_SET_WINDOW_TITLE:
- win = mp1;
-#ifdef OS2
- debug_call(("T: WinSetWindowText"));
- WinSetWindowText(win->h, mp2);
-#endif
-#ifdef WIN
- if (unicode_supported && unicode_title_supported)
- SetWindowTextW(win->hc, mp2);
- else
- SetWindowTextA(win->hc, mp2);
-#endif
- debug_call(("T: pm_lock"));
- pm_lock();
- debug_call(("T: pm_event_signal"));
- pm_event_signal();
- debug_call(("T: break"));
- break;
- case MSG_SHUTDOWN_THREAD:
- debug_call(("T: pm_thread_shutdown"));
- pm_thread_shutdown = 1;
- break;
- }
-}
-
-static void pm_send_msg(int msg, void *param, void *param2)
-{
-#ifdef OS2
- debug_call(("M: calling WinPostMsg(%d, %p, %p)", msg, param, param2));
- while (!WinPostMsg(hwnd_hidden, msg, (MPARAM)param, (MPARAM)param2)) {
- debug_call(("M: WinPostMsg failed: %lx", WinGetLastError(hab)));
- portable_sleep(1000);
- }
- debug_call(("M: WinPostMsg succeeded"));
-#endif
-#ifdef WIN
- BOOL r;
- if (!GdiFlush())
- {/*error("GdiFlush failed: %u", (unsigned)GetLastError());*/}
- retry:
- if (!unicode_supported)
- r = PostMessageA(hwnd_hidden, msg, (unsigned long)param, (unsigned long)param2);
- else
- r = PostMessageW(hwnd_hidden, msg, (unsigned long)param, (unsigned long)param2);
- if (!r) {
- DWORD err = GetLastError();
- if (err == ERROR_NOT_ENOUGH_QUOTA) {
- portable_sleep(1000);
- goto retry;
- }
- fatal_exit("PostMessage failed: %x", (unsigned)GetLastError());
- }
-#endif
- pm_event_wait();
- debug_call(("M: pm_event_wait succeeded"));
-#ifdef WIN
- if (msg == MSG_SHUTDOWN_THREAD) {
- if (pthread_join(pthread_handle, NULL))
- fatal_exit("pthread_join failed");
- }
-#endif
-}
-
-static void pm_dispatcher(void *p)
-{
-#ifdef OS2
- QMSG msg;
- HWND hwnd_hidden_h;
-#endif
-#ifdef WIN
- MSG msg;
- HCURSOR hcursor;
- WNDCLASSEXW class_w;
- WNDCLASSEXA class_a;
-#endif
- pm_status = NULL;
-#ifdef OS2
- /*DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 1, 0);*/
- /*DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 1, 0);*/
- DosSetPriority(PRTYS_THREAD, PRTYC_NOCHANGE, 1, 0);
- if ((hab_disp = WinInitialize(0)) == NULLHANDLE) {
- pm_status = cast_uchar "WinInitialize failed in pm thread.\n";
- goto os2_fail0;
- }
- if ((hmq = WinCreateMsgQueue(hab_disp, 0)) == NULLHANDLE) {
- ERRORID e = WinGetLastError(hab_disp);
- if ((e & 0xffff) == PMERR_NOT_IN_A_PM_SESSION) pm_status = cast_uchar "Not in a pmshell session.\n";
- else pm_status = cast_uchar "WinCreateMsgQueue failed in pm thread.\n";
- goto os2_fail1;
- }
- if ((pm_cp = WinQueryCp(hmq))) {
- unsigned char a[12];
- snprint(a, 12, pm_cp);
- if ((pm_cp = get_cp_index(a)) < 0 || pm_cp == utf8_table) pm_cp = 0;
- }
- /*{
- ULONG cp_list[100];
- int n, i;
- debug("WinQueryCp: %d", WinQueryCp(hmq));
- n = WinQueryCpList(hab_disp, 100, cp_list);
- debug("%d", n);
- for (i = 0; i < n; i++) fprintf(stderr, "%d, ", cp_list[i]);
- }*/
- if (WinRegisterClass(hab_disp, pm_class_name, pm_window_proc, CS_SIZEREDRAW, 0) == FALSE) {
- pm_status = cast_uchar "WinRegisterClass failed for.\n";
- goto os2_fail2;
- }
- if ((hwnd_hidden_h = WinCreateStdWindow(HWND_DESKTOP, 0, &pm_hidden_frame, pm_class_name, NULL, 0, 0, 0, &hwnd_hidden)) == NULLHANDLE) {
- pm_status = cast_uchar "Could not create hidden window.\n";
- goto os2_fail3;
- }
- if ((hps_hidden = WinGetPS(hwnd_hidden)) == NULLHANDLE) {
- pm_status = cast_uchar "Could not get hidden window ps.\n";
- goto os2_fail4;
- }
- GpiCreateLogColorTable(hps_hidden, 0, LCOLF_RGB, 0, 0, NULL);
-#endif
-#ifdef WIN
- pm_cp = get_windows_cp(0);
-
- hcursor = LoadCursorA(0, (void *)IDC_ARROW);
-
- memset(&class_w, 0, sizeof class_w);
- class_w.cbSize = sizeof class_w;
- class_w.style = CS_HREDRAW | CS_VREDRAW;
- class_w.lpfnWndProc = pm_window_proc;
- class_w.hInstance = module_handle;
- class_w.hCursor = hcursor;
- class_w.lpszClassName = pm_class_name_l;
- window_class_atom = RegisterClassExW(&class_w);
- if (window_class_atom) {
- OSVERSIONINFO v;
- unicode_supported = 1;
- unicode_title_supported = 0;
- v.dwOSVersionInfoSize = sizeof v;
- if (is_winnt() && GetVersionEx(&v) && v.dwMajorVersion >= 5)
- unicode_title_supported = 1;
- } else {
- unicode_supported = 0;
- unicode_title_supported = 0;
- memset(&class_a, 0, sizeof class_a);
- class_a.cbSize = sizeof class_a;
- class_a.style = CS_HREDRAW | CS_VREDRAW;
- class_a.lpfnWndProc = pm_window_proc;
- class_a.hInstance = module_handle;
- class_a.hCursor = hcursor;
- class_a.lpszClassName = pm_class_name;
- window_class_atom = RegisterClassExA(&class_a);
- }
- if (!window_class_atom) {
- pm_status = cast_uchar "Unable to register window class.\n";
- goto win32_fail;
- }
- if (unicode_supported) {
- hwnd_hidden = CreateWindowExW(WS_EX_LEFT, (void *)(unsigned long)window_class_atom, L"Links", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, module_handle, NULL);
- } else {
- hwnd_hidden = CreateWindowExA(WS_EX_LEFT, (void *)(unsigned long)window_class_atom, "Links", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, module_handle, NULL);
- }
- if (!hwnd_hidden) {
- pm_status = cast_uchar "Could not create hidden window.\n";
- goto win32_fail;
- }
- if (!unicode_supported)
- PeekMessageA(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
- else
- PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
-#endif
- pm_event_signal();
- while (!pm_thread_shutdown) {
-#ifdef OS2
- /*BOOL ret;
- debug_call(("T: calling WinPeekMsg"));
- ret = WinPeekMsg(hab_disp, &msg, 0L, 0, 0, PM_REMOVE);
- debug_call(("T: WinPeekMsg: %ld", ret));
- if (!ret) {
- debug_call(("T: calling WinWaitMsg"));
- ret = WinWaitMsg(hab_disp, 0, 0);
- debug_call(("T: WinWaitMsg: %ld", ret));
- continue;
- }*/
- debug_call(("T: calling WinGetMsg"));
- WinGetMsg(hab_disp, &msg, 0L, 0, 0);
- debug_call(("T: WinGetMsg: %lx, %lx, %p, %p, %lx, %lx.%lx, %lx", msg.hwnd, msg.msg, msg.mp1, msg.mp2, msg.time, msg.ptl.x, msg.ptl.y, msg.reserved));
- WinDispatchMsg(hab_disp, &msg);
-#endif
-#ifdef WIN
- if (!unicode_supported)
- GetMessageA(&msg, NULL, 0, 0);
- else
- GetMessageW(&msg, NULL, 0, 0);
- TranslateMessage(&msg);
- if (!unicode_supported)
- DispatchMessageA(&msg);
- else
- DispatchMessageW(&msg);
-#endif
- }
-
-#ifdef OS2
- if (!WinReleasePS(hps_hidden))
- error("WinReleasePS failed");
- os2_fail4:
- if (!WinDestroyWindow(hwnd_hidden_h))
- error("WinDestroyWindow failed");
- os2_fail3:
- os2_fail2:
- if (!WinDestroyMsgQueue(hmq))
- error("WinDestroyMsgQueue failed");
- os2_fail1:
- if (!WinTerminate(hab_disp))
- error("WinTerminate failed");
- if (!WinTerminate(hab_disp))
- error("WinTerminate failed");
- os2_fail0:
-#endif
-#ifdef WIN
- if (!DestroyWindow(hwnd_hidden))
- error("DestroyWindow failed: %u", (unsigned)GetLastError());
- win32_fail:
-#endif
- pm_event_signal();
- return;
-}
-
-#ifdef WIN
-static void *pm_dispatcher_win32(void *p)
-{
- pm_dispatcher(NULL);
- return NULL;
-}
-#endif
-
-static void pm_pipe_error(void)
-{
- error("exception on pm pipe");
- set_handlers(pm_pipe[0], NULL, NULL, NULL);
-}
-
-static void pm_handler(void *p)
-{
- unsigned char c;
- struct pm_window *win = NULL;
- struct pm_event *ev = NULL;
- debug_call(("M: pm_handler: pm_lock"));
- pm_lock();
- debug_call(("M: pm_handler: pm_locked"));
- if (!list_empty(pm_event_windows)) {
- win = list_struct(pm_event_windows.prev, struct pm_window);
- if (!list_empty(win->queue)) {
- ev = list_struct(win->queue.prev, struct pm_event);
- del_from_list(ev);
- }
- if (list_empty(win->queue)) {
- del_from_list(win);
- win->in = 0;
- }
- }
- if (list_empty(pm_event_windows)) {
- int rd;
- debug_call(("M: pm_handler: read"));
- EINTRLOOP(rd, read(pm_pipe[0], &c, 1));
- if (rd != 1) pm_pipe_error();
- }
- debug_call(("M: pm_handler: pm_unlock"));
- pm_unlock();
- debug_call(("M: pm_handler: pm_unlocked: %p", ev));
- if (!ev) return;
- debug_call(("M: pm_handler: event: %d", ev->type));
- switch (ev->type) {
- struct rect r;
- case E_KEY:
- if (win->dev->keyboard_handler)
- win->dev->keyboard_handler(win->dev, ev->x1, ev->y1);
- break;
- case E_MOUSE:
- if (win->dev->mouse_handler)
- win->dev->mouse_handler(win->dev, ev->x1, ev->y1, ev->x2);
- break;
- case E_REDRAW:
- if (win->dev->redraw_handler) {
- r.x1 = ev->x1; r.y1 = ev->y1;
- r.x2 = ev->x2; r.y2 = ev->y2;
- win->dev->redraw_handler(win->dev, &r);
- }
- break;
- case E_RESIZE:
- win->dev->size.x2 = ev->x2;
- win->dev->size.y2 = ev->y2;
- if (win->dev->resize_handler) {
- win->dev->resize_handler(win->dev);
- }
- }
- debug_call(("M: pm_handler: free ev"));
- free(ev);
- debug_call(("M: pm_handler: done"));
-}
-
-#ifdef OS2
-
-#define PM_FLUSH() do { } while (0)
-#define PM_UNFLUSH() do { } while (0)
-
-#endif
-
-#ifdef WIN
-
-static unsigned char flush_in_progress = 0;
-
-static void pm_do_flush(void *ignore)
-{
- flush_in_progress = 0;
- if (!GdiFlush())
- {/*error("GdiFlush failed: %u", (unsigned)GetLastError());*/}
-}
-
-static inline void PM_FLUSH(void)
-{
- if (!flush_in_progress) {
- register_bottom_half(pm_do_flush, NULL);
- flush_in_progress = 1;
- }
-}
-
-#define PM_UNFLUSH() unregister_bottom_half(pm_do_flush, NULL)
-
-#endif
-
-static int pm_bitmap_count = 0;
-
-static unsigned char *pm_get_driver_param(void)
-{
- return NULL;
-}
-
-static unsigned char *pm_get_af_unix_name(void)
-{
- return cast_uchar "";
-}
-
-#ifdef PM_SPAWN_SUBPROC
-
-static int pm_sin, pm_sout, pm_serr, pm_ip[2], pm_op[2], pm_ep[2];
-static int pm_cons_ok = 0;
-
-static void pm_setup_console(int undo)
-{
- int rs;
- if (pm_cons_ok != undo) return;
- if (pm_cons_ok) goto fail9;
- setmode(1, O_BINARY);
- setmode(2, O_BINARY);
- pm_sin = c_dup(0);
- if (pm_sin < 0) goto fail;
- pm_sout = c_dup(1);
- if (pm_sout < 0) goto fail1;
- pm_serr = c_dup(2);
- if (pm_serr < 0) goto fail2;
- if (c_pipe(pm_ip)) goto fail3;
- if (c_pipe(pm_op)) goto fail4;
- if (c_pipe(pm_ep)) goto fail5;
- EINTRLOOP(rs, dup2(pm_ip[0], 0));
- if (rs != 0) goto fail6;
- EINTRLOOP(rs, dup2(pm_op[1], 1));
- if (rs != 1) goto fail7;
- EINTRLOOP(rs, dup2(pm_ep[1], 2));
- if (rs != 2) goto fail8;
- EINTRLOOP(rs, close(pm_ip[0]));
- EINTRLOOP(rs, close(pm_op[1]));
- EINTRLOOP(rs, close(pm_ep[1]));
- pm_cons_ok = 1;
- return;
-fail9:
- EINTRLOOP(rs, dup2(pm_serr, 2));
-fail8:
- EINTRLOOP(rs, dup2(pm_sout, 1));
-fail7:
- EINTRLOOP(rs, dup2(pm_sin, 0));
-fail6:
- EINTRLOOP(rs, close(pm_ep[0]));
- EINTRLOOP(rs, close(pm_ep[1]));
-fail5:
- EINTRLOOP(rs, close(pm_op[0]));
- EINTRLOOP(rs, close(pm_op[1]));
-fail4:
- EINTRLOOP(rs, close(pm_ip[0]));
- EINTRLOOP(rs, close(pm_ip[1]));
-fail3:
- EINTRLOOP(rs, close(pm_serr));
-fail2:
- EINTRLOOP(rs, close(pm_sout));
-fail1:
- EINTRLOOP(rs, close(pm_sin));
-fail: pm_cons_ok = 0;
-}
-
-static int pm_do_console_step(int slp)
-{
-#define CONS_BUF 20
- int did_something = 0;
- unsigned char buffer[CONS_BUF];
- fd_set s;
- struct timeval tv = { 0, 0 };
- int rs;
- int m = pm_op[0] > pm_ep[0] ? pm_op[0] : pm_ep[0];
- int r, w;
- if (pm_sin > m) m = pm_sin;
- m++;
- if (!pm_cons_ok) return -1;
- FD_ZERO(&s);
- /*FD_SET(pm_sin, &s);*/
- if (m > (int)FD_SETSIZE) {
- fatal_exit("too big handle %d", m - 1);
- }
- FD_SET(pm_op[0], &s);
- FD_SET(pm_ep[0], &s);
- EINTRLOOP(rs, select(m, &s, NULL, NULL, slp ? NULL : &tv));
- if (rs <= 0) return -1;
-#define SEL_CHK(ih, oh) \
- if (FD_ISSET(ih, &s)) { \
- EINTRLOOP(r, read(ih, buffer, CONS_BUF)); \
- if (r <= 0) return -1; \
- do { \
- if ((w = hard_write(oh, buffer, r)) <= 0) return -1;\
- did_something = 1; \
- r -= w; \
- } while (r > 0); \
- }
-
- block_signals(0, 0);
- /*SEL_CHK(pm_sin, pm_ip[1]);*/
- SEL_CHK(pm_op[0], pm_sout);
- SEL_CHK(pm_ep[0], pm_serr);
- unblock_signals();
- return did_something;
-#undef SEL_CHK
-}
-
-static void pm_do_console(void)
-{
- while (pm_do_console_step(1) >= 0)
- ;
-}
-
-static void pm_sigcld(void *p)
-{
- int st;
- pid_t w;
- EINTRLOOP(w, wait(&st));
- while (pm_do_console_step(0) > 0)
- ;
- if (w > 0 && WIFEXITED(st)) exit(WEXITSTATUS(st));
- else exit(RET_FATAL);
-}
-
-static unsigned char *pm_spawn_subproc(void)
-{
- unsigned char **arg;
- int rs;
- pid_t pm_child_pid;
-
- if ((unsigned)g_argc > MAXINT / sizeof(unsigned char *) - 1) overalloc();
- arg = mem_alloc((g_argc + 1) * sizeof(unsigned char *));
- memcpy(arg, g_argv, g_argc * sizeof(unsigned char *));
- arg[g_argc] = NULL;
- pm_child_pid = -1;
- install_signal_handler(SIGCHLD, pm_sigcld, NULL, 1);
- pm_setup_console(0);
- pm_child_pid = spawnvp(P_PM, path_to_exe, (char **)arg);
- mem_free(arg);
- if (pm_child_pid < 0) {
- set_sigcld();
- pm_setup_console(1);
- return cast_uchar "Unable to spawn subprocess.\n";
- }
- pm_do_console();
- pm_setup_console(1);
- while (1)
- EINTRLOOP(rs, select(1, NULL, NULL, NULL, NULL));
-
- return cast_uchar "Not reached.\n";
-}
-
-#endif
-
-static unsigned char *pm_init_driver(unsigned char *param, unsigned char *display)
-{
- unsigned char *s;
- int rs;
-
-#ifdef OS2
- if (os2_pib) {
- if (os2_pib->pib_ultype != 3 &&
- os2_pib->pib_ultype != 4) {
-#ifdef PM_SPAWN_SUBPROC
- s = pm_spawn_subproc();
- goto r0;
-#else
- os2_pib->pib_ultype = 3;
-#endif
- }
- }
-
- if ((hab = WinInitialize(0)) == 0) {
- s = cast_uchar "WinInitialize failed.\n";
- goto r0;
- }
-#endif
-#ifdef WIN
- module_handle = GetModuleHandleA(NULL);
- if (!module_handle) {
- s = cast_uchar "Unable to get module handle.\n";
- goto r0;
- }
-#endif
- if (pm_event_init()) {
- s = cast_uchar "Could not create event semaphore.\n";
- goto r1;
- }
- if (c_pipe(pm_pipe)) {
- s = cast_uchar "Could not create pipe.\n";
- goto r2;
- }
- set_nonblock(pm_pipe[1]);
- memset(pm_windows, 0, sizeof(struct pm_window *) * WIN_HASH);
- if (pm_lock_init()) {
- s = cast_uchar "Could not create mutext.\n";
- goto r3;
- }
- pm_thread_shutdown = 0;
-#ifdef OS2
- if (_beginthread(pm_dispatcher, NULL, 65536, NULL) == -1) {
- s = cast_uchar "Could not start thread.\n";
- goto r4;
- }
-#endif
-#ifdef WIN
- if (pthread_create(&pthread_handle, NULL, pm_dispatcher_win32, NULL)) {
- s = cast_uchar "Could not start thread.\n";
- goto r4;
- }
-#endif
- pm_event_wait();
- if (pm_status) {
- s = pm_status;
- goto r4;
- }
-#ifdef OS2
- pmshell_driver.depth = 0xc3;
-
- pm_bitmapinfo = pm_alloc(sizeof(BITMAPINFOHEADER), PM_ALLOC_ZERO);
- pm_bitmapinfo->cbFix = sizeof(BITMAPINFOHEADER);
- pm_bitmapinfo->cPlanes = 1;
- pm_bitmapinfo->cBitCount = 24;
-
- {
- SIZEL sizl = { 0, 0 };
- PSZ data[4] = { "DISPLAY", NULL, NULL, NULL };
- hdc_mem = DevOpenDC(hab, OD_MEMORY, "*", 4L, (PDEVOPENDATA)data, NULLHANDLE);
- if (!hdc_mem) {
- s = cast_uchar "Unable to create memory device context.\n";
- goto r5;
- }
- hps_mem = GpiCreatePS(hab, hdc_mem, &sizl, GPIA_ASSOC | PU_PELS | GPIT_MICRO);
- if (!hps_mem) {
- s = cast_uchar "Unable to create memory presentation space.\n";
- goto r6;
- }
- }
-
- icon = WinLoadPointer(HWND_DESKTOP, 0, 1);
-#endif
-#ifdef WIN
- {
- int bpp;
-
- screen_dc = GetDC(NULL);
- if (!screen_dc) {
- s = cast_uchar "Unable to get screen device context.\n";
- goto r5;
- }
- bpp = GetDeviceCaps(screen_dc, BITSPIXEL);
-
- if (bpp < 24)
- pmshell_driver.depth = 0x7a;
- else
- pmshell_driver.depth = 0xc3;
-
- pm_bitmapinfo = pm_alloc(sizeof(BITMAPINFO), PM_ALLOC_ZERO);
- pm_bitmapinfo->bmiHeader.biSize = sizeof(pm_bitmapinfo->bmiHeader);
- pm_bitmapinfo->bmiHeader.biPlanes = 1;
- pm_bitmapinfo->bmiHeader.biBitCount = bpp < 24 ? 16 : 24;
- pm_bitmapinfo->bmiHeader.biCompression = BI_RGB;
- }
-
- icon_big = LoadImage(module_handle, MAKEINTRESOURCE(1), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
- icon_small = LoadImage(module_handle, MAKEINTRESOURCE(1), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-#endif
- icon_set = 0;
- set_handlers(pm_pipe[0], pm_handler, NULL, NULL);
-
- return NULL;
-
-#ifdef OS2
- r6:
- if (DevCloseDC(hdc_mem) == DEV_ERROR)
- error("DevCloseDC failed");
-#endif
- r5:
- pm_free(pm_bitmapinfo);
- pm_send_msg(MSG_SHUTDOWN_THREAD, NULL, NULL);
- r4:
- pm_lock_close();
- r3:
- EINTRLOOP(rs, close(pm_pipe[0]));
- EINTRLOOP(rs, close(pm_pipe[1]));
- r2:
- pm_event_close();
- r1:
- PM_UNFLUSH();
-#ifdef OS2
- if (!WinTerminate(hab))
- error("WinTerminate failed");
-#endif
- r0:
- return stracpy(s);
-}
-
-static void pm_shutdown_driver(void)
-{
- int rs;
- pm_send_msg(MSG_SHUTDOWN_THREAD, NULL, NULL);
-#ifdef OS2
- if (icon != NULLHANDLE)
- if (!WinDestroyPointer(icon))
- error("WinDestroyPointer failed");
- if (!GpiDestroyPS(hps_mem))
- error("GpiDestroyPS failed");
- if (DevCloseDC(hdc_mem) == DEV_ERROR)
- error("DevCloseDC failed");
-#endif
-#ifdef WIN
- if (icon_small != NULL)
- if (!DestroyIcon(icon_small))
- error("DestroIcon failed: %u", (unsigned)GetLastError());
- if (icon_big != NULL)
- if (!DestroyIcon(icon_big))
- error("DestroIcon failed: %u", (unsigned)GetLastError());
- if (!ReleaseDC(NULL, screen_dc))
- error("ReleaseDC failed: %u", (unsigned)GetLastError());
-#endif
- pm_free(pm_bitmapinfo);
- pm_lock_close();
- close_socket(&pm_pipe[0]);
- EINTRLOOP(rs, close(pm_pipe[1]));
- pm_event_close();
- PM_UNFLUSH();
-#ifdef OS2
- if (!WinTerminate(hab))
- error("WinTerminate failed");
-#endif
- if (pm_bitmap_count) internal("pm_shutdown_driver: %d bitmaps leaked", pm_bitmap_count);
-}
-
-#ifdef OS2
-
-static HPOINTER pmshell_create_icon(void)
-{
- unsigned char *icon_data, *icon_data_2;
- int icon_w, icon_h, icon_skip;
- int size;
- int i, j;
- HBITMAP hbm;
- HPOINTER hicon;
- const int border = 4;
-
- get_links_icon(&icon_data, &icon_w, &icon_h, &icon_skip, 4);
- size = icon_h * icon_skip;
- icon_data_2 = pm_alloc(size * 2, 0);
- for (i = 0; i < icon_h; i++)
- memcpy(icon_data_2 + i * icon_skip, icon_data + (icon_h - 1 - i) * icon_skip, icon_skip);
- free(icon_data);
- for (i = 0; i < size; i++) {
- icon_data_2[i + size] = 0;
- }
-#define set_trans(x, y) memset(icon_data_2 + ((y) + icon_h) * icon_skip + (x) * (pmshell_driver.depth & 7), 0xff, pmshell_driver.depth & 7);
- for (j = 0; j < border; j++) for (i = 0; i < icon_w; i++) set_trans(i, j);
- for (j = icon_h - border; j < icon_h; j++) for (i = 0; i < icon_w; i++) set_trans(i, j);
- for (j = 0; j < icon_h; j++) for (i = 0; i < border; i++) set_trans(i, j);
- for (j = 0; j < icon_h; j++) for (i = icon_w - border; i < icon_w; i++) set_trans(i, j);
-#undef set_trans
- pm_bitmapinfo->cx = icon_w;
- pm_bitmapinfo->cy = icon_h * 2;
- hbm = GpiCreateBitmap(hps_hidden, (PBITMAPINFOHEADER2)pm_bitmapinfo, CBM_INIT, icon_data_2, (PBITMAPINFO2)pm_bitmapinfo);
- pm_free(icon_data_2);
- if (hbm == GPI_ERROR)
- return NULLHANDLE;
- hicon = WinCreatePointer(HWND_DESKTOP, hbm, FALSE, 0, 0);
- if (!hicon)
- error("WinCreatePointer failed");
- if (!GpiDeleteBitmap(hbm))
- error("GpiDeleteBitmap failed");
- return hicon;
-}
-
-#endif
-
-#ifdef WIN
-
-static HICON win32_create_icon(int x, int y)
-{
- unsigned char *icon_data, *zero_data;
- int icon_w, icon_h, icon_skip;
- int left, right, top, bottom;
- int i, j;
- HBITMAP hbm_icon;
- HBITMAP hbm_mask;
- ICONINFO ic;
- HICON hicon = NULL;
- HDC memory_dc;
- HGDIOBJ prev_obj;
-
- get_links_icon(&icon_data, &icon_w, &icon_h, &icon_skip, 4);
- zero_data = pm_alloc(icon_h * icon_skip, 0);
- memcpy(zero_data, icon_data, icon_h * icon_skip);
- free(icon_data);
- icon_data = zero_data;
-
- zero_data = pm_alloc(icon_h * icon_skip, PM_ALLOC_ZERO);
-
- memory_dc = CreateCompatibleDC(NULL);
- if (!memory_dc) {
- error("CreateCompatibleDC failed: %u", (unsigned)GetLastError());
- goto ret1;
- }
-
- hbm_icon = CreateCompatibleBitmap(screen_dc, x, y);
- if (!hbm_icon) {
- error("CreateBitmap failed: %u", (unsigned)GetLastError());
- goto ret2;
- }
- prev_obj = SelectObject(memory_dc, hbm_icon);
- if (!prev_obj) {
- error("SelectObject failed: %u", (unsigned)GetLastError());
- goto ret3;
- }
- pm_bitmapinfo->bmiHeader.biWidth = icon_w;
- pm_bitmapinfo->bmiHeader.biHeight = -icon_h;
- if (!StretchDIBits(memory_dc, 0, 0, x, y, 0, 0, icon_w, icon_h, icon_data, pm_bitmapinfo, DIB_RGB_COLORS, SRCCOPY)) {
- error("StretchDIBits failed: %u", (unsigned)GetLastError());
- prev_obj = SelectObject(memory_dc, prev_obj);
- if (!prev_obj) {
- error("SelectObject failed: %u", (unsigned)GetLastError());
- goto ret3;
- }
- goto ret3;
- }
- prev_obj = SelectObject(memory_dc, prev_obj);
- if (!prev_obj) {
- error("SelectObject failed: %u", (unsigned)GetLastError());
- goto ret3;
- }
- hbm_mask = CreateBitmap(x, y, 1, 1, zero_data);
- if (!hbm_mask) {
- error("CreateCompatibleBitmap failed: %u", (unsigned)GetLastError());
- goto ret3;
- }
- prev_obj = SelectObject(memory_dc, hbm_mask);
- if (!prev_obj) {
- error("SelectObject failed %u", (unsigned)GetLastError());
- goto ret4;
- }
- if (x == 16 && y == 16) {
- top = bottom = left = right = 1;
- if (is_winnt())
- top = 2;
- } else if (x == 32 && y == 32) {
- top = bottom = left = right = 3;
- } else {
- top = bottom = left = right = 0;
- }
- for (j = 0; j < top; j++) for (i = 0; i < x; i++) SetPixel(memory_dc, i, j, 0xffffff);
- for (j = y - bottom; j < y; j++) for (i = 0; i < x; i++) SetPixel(memory_dc, i, j, 0xffffff);
- for (j = 0; j < y; j++) for (i = 0; i < left; i++) SetPixel(memory_dc, i, j, 0xffffff);
- for (j = 0; j < y; j++) for (i = x - left; i < x; i++) SetPixel(memory_dc, i, j, 0xffffff);
- prev_obj = SelectObject(memory_dc, prev_obj);
- if (!prev_obj) {
- error("SelectObject failed %u", (unsigned)GetLastError());
- goto ret4;
- }
- memset(&ic, 0, sizeof ic);
- ic.fIcon = TRUE;
- ic.hbmMask = hbm_mask;
- ic.hbmColor = hbm_icon;
- hicon = CreateIconIndirect(&ic);
- if (!hicon)
- error("CreateIconIndirect failed %u", (unsigned)GetLastError());
-
-ret4:
- if (!DeleteBitmap(hbm_mask))
- error("DeleteBitmap failed %u", (unsigned)GetLastError());
-ret3:
- if (!DeleteBitmap(hbm_icon))
- error("DeleteBitmap failed %u", (unsigned)GetLastError());
-ret2:
- if (!DeleteDC(memory_dc))
- error("DeleteDC failed %u", (unsigned)GetLastError());
-ret1:
- pm_free(icon_data);
- pm_free(zero_data);
- return hicon;
-}
-
-#endif
-
-static struct graphics_device *pm_init_device(void)
-{
- RECTL wr;
- struct graphics_device *dev;
- struct pm_window *win;
-
- if (!icon_set) {
-#ifdef OS2
- if (icon == NULLHANDLE) icon = pmshell_create_icon();
-#endif
-#ifdef WIN
- if (!icon_big) icon_big = win32_create_icon(32, 32);
- if (!icon_small) icon_small = win32_create_icon(16, 16);
-#endif
- }
- icon_set = 1;
-
- win = mem_alloc(sizeof(struct pm_window));
- win->lastpos = -1L;
- win->button = 0;
- init_list(win->queue);
- win->in = 0;
- win->minimized = 0;
- debug_call(("M: pm_init_device: pm_send_msg"));
- pm_send_msg(MSG_CREATE_WINDOW, win, NULL);
- debug_call(("M: pm_init_device: pm_send_msg done"));
-#ifdef OS2
- if (win->h == NULLHANDLE) {
- goto r1;
- }
- debug_call(("M: pm_init_device: WinGetPS"));
- if ((win->ps = WinGetPS(win->hc)) == NULLHANDLE) {
- goto r2;
- }
-#endif
-#ifdef WIN
- win->pen_orig = NULL;
- win->pen_cache = NULL;
- win->pen_cache_color = -1;
- win->brush_cache = NULL;
- win->brush_cache_color = -1;
- if (win->hc == NULL) {
- goto r1;
- }
- if ((win->dc = GetDC(win->hc)) == NULL) {
- goto r2;
- }
-#endif
- dev = mem_calloc(sizeof(struct graphics_device));
- dev->driver_data = win;
- win->dev = dev;
-#ifdef OS2
- debug_call(("M: pm_init_device: WinQueryWindowRect"));
- if (!WinQueryWindowRect(win->hc, &wr)) {
- memset(&wr, 0, sizeof wr);
- }
-#endif
-#ifdef WIN
- if (!GetClientRect(win->hc, &wr)) {
- memset(&wr, 0, sizeof wr);
- }
- wr.yTop = wr.yBottom;
-#endif
- win->x = dev->size.x2 = wr.xRight;
- win->y = dev->size.y2 = wr.yTop;
- dev->clip.x1 = dev->clip.y1 = 0;
- dev->clip.x2 = dev->size.x2;
- dev->clip.y2 = dev->size.y2;
-#ifdef OS2
- debug_call(("M: pm_init_device: GpiCreateLogColorTable"));
- GpiCreateLogColorTable(win->ps, 0, LCOLF_RGB, 0, 0, NULL);
-#endif
- debug_call(("M: pm_init_device: pm_hash_window"));
- pm_hash_window(win);
- debug_call(("M: pm_init_device: pm_unlock"));
- pm_unlock();
- debug_call(("M: pm_init_device: return"));
- return dev;
-
- r2: pm_unlock();
- pm_send_msg(MSG_DELETE_WINDOW, win, NULL);
- r1: if (win->in) del_from_list(win);
- pm_unlock();
- mem_free(win);
- return NULL;
-}
-
-static void pm_shutdown_device(struct graphics_device *dev)
-{
- struct pm_window *win = pm_win(dev);
-#ifdef OS2
- debug_call(("M: pm_shutdown_device: WinReleasePS"));
- if (!WinReleasePS(win->ps))
- error("WinReleasePS failed");
-#endif
-#ifdef WIN
- if (win->pen_orig)
- if (!SelectObject(win->dc, win->pen_orig))
- error("SelectObject failed for original pen %u", (unsigned)GetLastError());
- if (!GdiFlush())
- {/*error("GdiFlush failed %u", (unsigned)GetLastError());*/}
- if (!ReleaseDC(win->hc, win->dc))
- error("ReleaseDC failed %u", (unsigned)GetLastError());
-#endif
- debug_call(("M: pm_shutdown_device: pm_send_msg"));
- pm_send_msg(MSG_DELETE_WINDOW, win, NULL);
-#ifdef WIN
- if (win->pen_cache)
- if (!DeleteObject(win->pen_cache))
- error("DeleteObject failed for pen cache %u", (unsigned)GetLastError());
- if (win->brush_cache)
- if (!DeleteObject(win->brush_cache))
- error("DeleteObject failed for brush cache %u", (unsigned)GetLastError());
-#endif
- debug_call(("M: pm_shutdown_device: pm_unhash_window"));
- pm_unhash_window(win);
- if (win->in) del_from_list(win);
- debug_call(("M: pm_shutdown_device: pm_unlock"));
- pm_unlock();
- debug_call(("M: pm_shutdown_device: free"));
- while (!list_empty(win->queue)) {
- struct pm_event *ev = list_struct(win->queue.next, struct pm_event);
- del_from_list(ev);
- free(ev);
- }
- mem_free(win);
- mem_free(dev);
- debug_call(("M: pm_shutdown_device: return"));
-}
-
-#define MAX_TITLE_SIZE 512
-
-static void pm_set_window_title(struct graphics_device *dev, unsigned char *title)
-{
- unsigned char *text;
- debug_call(("M: pm_set_window_title: start"));
-#ifdef WIN
- if (unicode_supported && unicode_title_supported) {
- int l = 0;
- text = init_str();
- while (*title && l < MAX_TITLE_SIZE * 2) {
- unsigned u;
- GET_UTF_8(title, u);
- if (u > 0 && u <= 0xffff) {
- add_chr_to_str(&text, &l, u & 0xff);
- add_chr_to_str(&text, &l, u >> 8);
- }
- }
- add_chr_to_str(&text, &l, 0);
- } else
-#endif
- {
- text = convert(utf8_table, pm_cp, title, NULL);
- clr_white(text);
- if (strlen(cast_const_char text) > MAX_TITLE_SIZE) text[MAX_TITLE_SIZE] = 0;
- }
-
- debug_call(("M: pm_set_window_title: pm_send_msg"));
- pm_send_msg(MSG_SET_WINDOW_TITLE, pm_win(dev), text);
- debug_call(("M: pm_set_window_title: pm_unlock"));
- pm_unlock();
- /*SendMessage(pm_win(dev)->hc, WM_SETTEXT, NULL, text);*/
- debug_call(("M: pm_set_window_title: mem_free"));
- mem_free(text);
- debug_call(("M: pm_set_window_title: return"));
-}
-
-static int pm_get_empty_bitmap(struct bitmap *bmp)
-{
- unsigned size;
- debug_call(("M: get_empty_bitmap (%dx%d)", bmp->x, bmp->y));
- if ((unsigned)bmp->x > (unsigned)MAXINT / (pmshell_driver.depth & 7) - 4) {
-over:
- bmp->data = NULL;
- bmp->flags = NULL;
- return -1;
- }
- bmp->skip = (bmp->x * (pmshell_driver.depth & 7) + 3) & ~3;
- size = (unsigned)bmp->skip * (unsigned)bmp->y;
- if (bmp->skip && size / (unsigned)bmp->skip != (unsigned)bmp->y) goto over;
- if (size > MAXINT) goto over;
- bmp->data = pm_alloc(size, PM_ALLOC_MAYFAIL);
- if (!bmp->data) goto over;
- bmp->data = (unsigned char *)bmp->data + size - bmp->skip;
- bmp->skip = -bmp->skip;
- debug_call(("M: get_empty_bitmap done"));
- return 0;
-}
-
-static inline unsigned char *bmp_base_pointer(struct bitmap *bmp)
-{
- return (unsigned char *)bmp->data + bmp->skip * (bmp->y - 1);
-}
-
-static void pm_register_bitmap(struct bitmap *bmp)
-{
-#ifdef OS2
- HBITMAP hbm;
- unsigned char *pointer;
-#endif
- debug_call(("M: register_bitmap (%dx%d)", bmp->x, bmp->y));
- pm_bitmap_count++;
-#ifdef OS2
- if (!bmp->data) {
- bmp->flags = (void *)GPI_ERROR;
- return;
- }
- pointer = bmp_base_pointer(bmp);
-again:
- if (bmp->x > OS2_MAX_BITMAP_SIZE || bmp->y > OS2_MAX_BITMAP_SIZE) {
- hbm = GPI_ERROR;
- } else {
- pm_bitmapinfo->cx = bmp->x;
- pm_bitmapinfo->cy = bmp->y;
- hbm = GpiCreateBitmap(hps_hidden, (PBITMAPINFOHEADER2)pm_bitmapinfo, CBM_INIT, pointer, (PBITMAPINFO2)pm_bitmapinfo);
- if (hbm == GPI_ERROR) {
- if (out_of_memory(MF_GPI, NULL, 0))
- goto again;
- }
- }
- bmp->flags = (void *)hbm;
- if (hbm != GPI_ERROR) {
- mem_free(pointer);
- bmp->data = NULL;
- mem_freed_large(-bmp->skip * bmp->y);
- }
- debug_call(("M: register_bitmap done"));
-#endif
-}
-
-static void *pm_prepare_strip(struct bitmap *bmp, int top, int lines)
-{
-#ifdef OS2
- debug_call(("M: prepare_strip (%dx%d)", bmp->x, bmp->y));
- if (bmp->flags == (void *)GPI_ERROR) {
- if (bmp->data)
- goto return_data;
- over:
- bmp->data = NULL;
- return NULL;
- }
- if (bmp->data)
- internal("pm_prepare_strip: bmp->data should not be set here");
- if (-bmp->skip && (unsigned)-bmp->skip * (unsigned)lines / (unsigned)-bmp->skip != (unsigned)lines) goto over;
- if ((unsigned)-bmp->skip * (unsigned)lines > MAXINT) goto over;
- bmp->data = pm_alloc(-bmp->skip * lines, PM_ALLOC_MAYFAIL);
- if (!bmp->data) goto over;
- debug_call(("M: prepare_strip done"));
- return (unsigned char *)bmp->data - bmp->skip * (lines - 1);
-return_data:
-#endif
- return ((unsigned char *)bmp->data) + bmp->skip * top;
-}
-
-static void pm_commit_strip(struct bitmap *bmp, int top, int lines)
-{
-#ifdef OS2
- LONG r;
- HBITMAP old;
- HBITMAP new = (HBITMAP)bmp->flags;
- debug_call(("M: commit_strip (%dx%d)", bmp->x, bmp->y));
- if (new == GPI_ERROR || !bmp->data)
- return;
- debug_call(("M: commit_strip done"));
- old = GpiSetBitmap(hps_mem, new);
- if (old == HBM_ERROR)
- goto ret;
- pm_bitmapinfo->cx = bmp->x;
- pm_bitmapinfo->cy = bmp->y;
-again:
- r = GpiSetBitmapBits(hps_mem, bmp->y - top - lines, lines, bmp->data, (PBITMAPINFO2)pm_bitmapinfo);
- if (r == GPI_ALTERROR) {
- if (out_of_memory(MF_GPI, NULL, 0))
- goto again;
- }
- GpiSetBitmap(hps_mem, old);
- ret:
- pm_free(bmp->data);
- bmp->data = NULL;
- debug_call(("M: commit_strip done"));
-#endif
-}
-
-static void pm_unregister_bitmap(struct bitmap *bmp)
-{
- debug_call(("M: unregister_bitmap (%dx%d)", bmp->x, bmp->y));
- pm_bitmap_count--;
-#ifdef OS2
- if ((HBITMAP)bmp->flags != GPI_ERROR) {
- if (bmp->data)
- internal("pm_unregister_bitmap: bmp->data should not be set here");
- if (!GpiDeleteBitmap((HBITMAP)bmp->flags))
- error("GpiDeleteBitmap failed");
- } else
-#endif
- if (bmp->data) {
- pm_free(bmp_base_pointer(bmp));
- mem_freed_large(-bmp->skip * bmp->y);
- }
- debug_call(("M: unregister_bitmap done"));
-}
-
-static void pm_draw_bitmap(struct graphics_device *dev, struct bitmap *bmp, int x, int y)
-{
- POINTL p;
- RECTL r;
- debug_call(("M: draw_bitmap (%dx%d -> %x,%x)", bmp->x, bmp->y, x, y));
- r.xLeft = x < dev->clip.x1 ? dev->clip.x1 - x : 0;
- r.xRight = x + bmp->x > dev->clip.x2 ? dev->clip.x2 - x : bmp->x;
- r.yTop = bmp->y - (y < dev->clip.y1 ? dev->clip.y1 - y : 0);
- r.yBottom = y + bmp->y > dev->clip.y2 ? bmp->y - dev->clip.y2 + y : 0;
- if (r.xLeft >= r.xRight || r.yTop <= r.yBottom)
- return;
- p.x = x + r.xLeft;
- p.y = pm_win(dev)->y - y - bmp->y + r.yBottom;
-#ifdef OS2
- if ((HBITMAP)bmp->flags != GPI_ERROR) {
- WinDrawBitmap(pm_win(dev)->ps, (HBITMAP)bmp->flags, &r, &p, 0, 1, DBM_NORMAL);
- } else if (!bmp->data) {
- return;
- } else {
- POINTL pp[4];
- if (bmp->x > OS2_MAX_LINE_SIZE) {
- int i;
- unsigned char *data_ptr = (unsigned char *)bmp->data + bmp->skip * (bmp->y - r.yTop) + r.xLeft * (pmshell_driver.depth & 7);
- for (i = r.yTop - r.yBottom - 1; i >= 0; i--) {
- pm_bitmapinfo->cx = r.xRight - r.xLeft;
- pm_bitmapinfo->cy = 1;
- pp[0].x = p.x;
- pp[0].y = p.y + i;
- pp[1].x = p.x + (r.xRight - r.xLeft) - 1;
- pp[1].y = p.y + i;
- pp[2].x = 0;
- pp[2].y = 0;
- pp[3].x = r.xRight - r.xLeft;
- pp[3].y = 1;
- GpiDrawBits(pm_win(dev)->ps, data_ptr, (PBITMAPINFO2)pm_bitmapinfo, 4, pp, ROP_SRCCOPY, 0);
- data_ptr += bmp->skip;
- }
- } else {
- pm_bitmapinfo->cx = bmp->x;
- pm_bitmapinfo->cy = r.yTop - r.yBottom;
- pp[0].x = p.x;
- pp[0].y = p.y;
- pp[1].x = p.x + (r.xRight - r.xLeft) - 1;
- pp[1].y = p.y + (r.yTop - r.yBottom) - 1;
- pp[2].x = r.xLeft;
- pp[2].y = 0;
- pp[3].x = r.xRight;
- pp[3].y = r.yTop - r.yBottom;
- GpiDrawBits(pm_win(dev)->ps, (unsigned char *)bmp->data + bmp->skip * (bmp->y - 1 - r.yBottom), (PBITMAPINFO2)pm_bitmapinfo, 4, pp, ROP_SRCCOPY, 0);
- }
- }
-#endif
-#ifdef WIN
- if (!bmp->data)
- return;
- pm_bitmapinfo->bmiHeader.biWidth = bmp->x;
- pm_bitmapinfo->bmiHeader.biHeight = r.yTop - r.yBottom;
- SetDIBitsToDevice(pm_win(dev)->dc, p.x, pm_win(dev)->y - p.y - (r.yTop - r.yBottom), r.xRight - r.xLeft, r.yTop - r.yBottom, r.xLeft, 0, 0, r.yTop - r.yBottom, (unsigned char *)bmp->data + bmp->skip * (bmp->y - 1 - r.yBottom), pm_bitmapinfo, DIB_RGB_COLORS);
-#endif
- PM_FLUSH();
- debug_call(("M: draw_bitmap done"));
-}
-
-static long pm_get_color(int rgb)
-{
-#ifdef OS2
- return rgb & 0xffffff;
-#endif
-#ifdef WIN
- COLORREF c, d;
- c = ((rgb & 0xff) << 16) | (rgb & 0xff00) | ((rgb & 0xff0000) >> 16);
- d = GetNearestColor(screen_dc, c);
- if (d == CLR_INVALID) return c;
- return d;
-#endif
-}
-
-#ifdef WIN
-
-static int win32_select_brush(struct pm_window *win, int color)
-{
- HBRUSH hbrush;
- if (color == win->brush_cache_color)
- return 0;
- hbrush = CreateSolidBrush(color);
- if (!hbrush) {
- error("CreateSolidBrush failed %u", (unsigned)GetLastError());
- return -1;
- }
- if (win->brush_cache != NULL)
- if (!DeleteObject(win->brush_cache))
- error("DeleteObject failed for previous brush %u", (unsigned)GetLastError());
- win->brush_cache = hbrush;
- win->brush_cache_color = color;
- return 0;
-}
-
-static int win32_select_pen(struct pm_window *win, int color)
-{
- HPEN hpen;
- HGDIOBJ orig;
- if (color == win->pen_cache_color)
- return 0;
- hpen = CreatePen(PS_SOLID, 0, color);
- if (!hpen) {
- error("CreatePen failed %u", (unsigned)GetLastError());
- return -1;
- }
- orig = SelectObject(win->dc, hpen);
- if (!orig) {
- error("SelectObject failed for pen %u", (unsigned)GetLastError());
- if (!DeleteObject(hpen))
- error("DeleteObject failed for pen %u", (unsigned)GetLastError());
- return -1;
- }
- if (!win->pen_orig)
- win->pen_orig = orig;
- else if (!DeleteObject(orig))
- error("DeleteObject failed for previous pen %u", (unsigned)GetLastError());
- win->pen_cache = hpen;
- win->pen_cache_color = color;
- return 0;
-}
-
-#endif
-
-static void pm_fill_area(struct graphics_device *dev, int x1, int y1, int x2, int y2, long color)
-{
- RECTL r;
- debug_call(("M: fill_area (%d,%d)->(%d,%d)", x1, y1, x2, y2));
- if (x1 < dev->clip.x1) x1 = dev->clip.x1;
- if (x2 > dev->clip.x2) x2 = dev->clip.x2;
- if (y1 < dev->clip.y1) y1 = dev->clip.y1;
- if (y2 > dev->clip.y2) y2 = dev->clip.y2;
- if (x1 >= x2 || y1 >= y2) return;
- r.xLeft = x1;
- r.yBottom = y2;
- r.xRight = x2;
- r.yTop = y1;
-#ifdef OS2
- r.yBottom = pm_win(dev)->y - r.yBottom;
- r.yTop = pm_win(dev)->y - r.yTop;
- WinFillRect(pm_win(dev)->ps, &r, color);
-#endif
-#ifdef WIN
- if (win32_select_brush(pm_win(dev), color))
- return;
- if (!FillRect(pm_win(dev)->dc, &r, pm_win(dev)->brush_cache))
- error("FillRect failed %u", (unsigned)GetLastError());
-#endif
- PM_FLUSH();
- debug_call(("M: fill_area done"));
-}
-
-static void pm_draw_hline(struct graphics_device *dev, int x1, int y, int x2, long color)
-{
-#ifdef OS2
- HPS ps = pm_win(dev)->ps;
- POINTL p;
-#endif
- debug_call(("M: draw_hline (%d,%d)->(%d)", x1, y, x2));
- if (y < dev->clip.y1) return;
- if (y >= dev->clip.y2) return;
- if (x1 < dev->clip.x1) x1 = dev->clip.x1;
- if (x2 > dev->clip.x2) x2 = dev->clip.x2;
- if (x1 >= x2) return;
-#ifdef OS2
- GpiSetColor(ps, color);
- p.x = x1;
- p.y = pm_win(dev)->y - y - 1;
- GpiMove(ps, &p);
- p.x = x2 - 1;
- GpiLine(ps, &p);
-#endif
-#ifdef WIN
- if (win32_select_pen(pm_win(dev), color))
- return;
- if (!MoveToEx(pm_win(dev)->dc, x1, y, NULL)) {
- error("MoveToEx failed %u", (unsigned)GetLastError());
- } else if (!LineTo(pm_win(dev)->dc, x2, y)) {
- error("LineTo failed %u", (unsigned)GetLastError());
- }
-#endif
- PM_FLUSH();
- debug_call(("M: draw_hline done"));
-}
-
-static void pm_draw_vline(struct graphics_device *dev, int x, int y1, int y2, long color)
-{
-#ifdef OS2
- HPS ps = pm_win(dev)->ps;
- POINTL p;
-#endif
- debug_call(("M: draw_vline (%d,%d)->(%d)", x, y1, y2));
- if (x < dev->clip.x1) return;
- if (x >= dev->clip.x2) return;
- if (y1 < dev->clip.y1) y1 = dev->clip.y1;
- if (y2 > dev->clip.y2) y2 = dev->clip.y2;
- if (y1 >= y2) return;
-#ifdef OS2
- GpiSetColor(ps, color);
- p.x = x;
- p.y = pm_win(dev)->y - y1 - 1;
- GpiMove(ps, &p);
- p.y = pm_win(dev)->y - y2;
- GpiLine(ps, &p);
-#endif
-#ifdef WIN
- if (win32_select_pen(pm_win(dev), color))
- return;
- if (!MoveToEx(pm_win(dev)->dc, x, y1, NULL)) {
- error("MoveToEx failed %u", (unsigned)GetLastError());
- } else if (!LineTo(pm_win(dev)->dc, x, y2)) {
- error("LineTo failed %u", (unsigned)GetLastError());
- }
-#endif
- PM_FLUSH();
- debug_call(("M: draw_vline done"));
-}
-
-static void pm_hscroll_redraws(struct pm_window *win, struct rect *r, int dir)
-{
- struct pm_event *e;
- pm_cancel_event(win, E_REDRAW, &e);
- if (!e) return;
- if (dir > 0) {
- if (e->x2 > r->x1 && e->x2 < r->x2) {
- e->x2 += dir;
- if (e->x2 > r->x2) e->x2 = r->x2;
- }
- } else if (dir < 0) {
- if (e->x1 > r->x1 && e->x1 < r->x2) {
- e->x1 += dir;
- if (e->x1 < r->x1) e->x1 = r->x1;
- }
- }
-}
-
-static int pm_hscroll(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- RECTL r;
-
- debug_call(("M: hscroll (%d)", sc));
- r.xLeft = dev->clip.x1;
- r.yBottom = dev->clip.y2;
- r.xRight = dev->clip.x2;
- r.yTop = dev->clip.y1;
- pm_lock();
-#ifdef OS2
- r.yBottom = pm_win(dev)->y - r.yBottom;
- r.yTop = pm_win(dev)->y - r.yTop;
- WinScrollWindow(pm_win(dev)->hc, sc, 0, &r, &r, NULLHANDLE, NULL, SW_INVALIDATERGN);
-#endif
-#ifdef WIN
- if (ScrollWindowEx(pm_win(dev)->hc, sc, 0, &r, &r, NULL, NULL, SW_INVALIDATE) == ERROR)
- error("ScrollWindowEx failed %u", (unsigned)GetLastError());
-#endif
- pm_hscroll_redraws(pm_win(dev), &dev->clip, sc);
- pm_unlock();
- PM_FLUSH();
- debug_call(("M: hscroll done"));
- return 0;
-}
-
-static void pm_vscroll_redraws(struct pm_window *win, struct rect *r, int dir)
-{
- struct pm_event *e;
- pm_cancel_event(win, E_REDRAW, &e);
- if (!e) return;
- if (dir > 0) {
- if (e->y2 > r->y1 && e->y2 < r->y2) {
- e->y2 += dir;
- if (e->y2 > r->y2) e->y2 = r->y2;
- }
- } else if (dir < 0) {
- if (e->y1 > r->y1 && e->y1 < r->y2) {
- e->y1 += dir;
- if (e->y1 < r->y1) e->y1 = r->y1;
- }
- }
-}
-
-static int pm_vscroll(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- RECTL r;
-
- debug_call(("M: vscroll (%d)", sc));
- r.xLeft = dev->clip.x1;
- r.yBottom = dev->clip.y2;
- r.xRight = dev->clip.x2;
- r.yTop = dev->clip.y1;
- pm_lock();
-#ifdef OS2
- r.yBottom = pm_win(dev)->y - r.yBottom;
- r.yTop = pm_win(dev)->y - r.yTop;
- WinScrollWindow(pm_win(dev)->hc, 0, -sc, &r, &r, NULLHANDLE, NULL, SW_INVALIDATERGN);
-#endif
-#ifdef WIN
- if (ScrollWindowEx(pm_win(dev)->hc, 0, sc, &r, &r, NULL, NULL, SW_INVALIDATE) == ERROR)
- error("ScrollWindowEx failed %u", (unsigned)GetLastError());
-#endif
- pm_vscroll_redraws(pm_win(dev), &dev->clip, sc);
- pm_unlock();
- PM_FLUSH();
- debug_call(("M: vscroll done"));
- return 0;
-}
-
-#ifdef OS2
-#define pm_flush NULL
-#endif
-#ifdef WIN
-static void pm_flush(struct graphics_device *dev)
-{
- PM_UNFLUSH();
- pm_do_flush(NULL);
-}
-#endif
-
-struct graphics_driver pmshell_driver = {
-#ifdef OS2
- cast_uchar "pmshell",
-#endif
-#ifdef WIN
- cast_uchar "windows",
-#endif
- pm_init_driver,
- pm_init_device,
- pm_shutdown_device,
- pm_shutdown_driver,
- NULL,
- NULL,
- pm_get_driver_param,
- pm_get_af_unix_name,
- NULL,
- NULL,
- pm_get_empty_bitmap,
- pm_register_bitmap,
- pm_prepare_strip,
- pm_commit_strip,
- pm_unregister_bitmap,
- pm_draw_bitmap,
- pm_get_color,
- pm_fill_area,
- pm_draw_hline,
- pm_draw_vline,
- pm_hscroll,
- pm_vscroll,
- generic_set_clip_area,
- pm_flush,
- dummy_block,
- dummy_unblock,
- pm_set_window_title,
- NULL, /* exec */
- NULL, /* set_clipboard_text */
- NULL, /* get_clipboard_text */
- 0, /* depth */
- 0, 0, /* x, y */
- GD_UNICODE_KEYS, /* flags */
- 0, /* codepage */
- NULL, /* shell */
-};
-
-#ifdef _UWIN
-
-int main(int argc, char **argv);
-
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow)
-{
- int i, neednew, quote, clen;
- int argc = 1;
- unsigned char **argv;
- if (!(argv = malloc(2 * sizeof(unsigned char *)))) alloc_err: fatal_exit("can't allocate commandline");
- if (!(argv[0] = cast_uchar strdup("links"))) goto alloc_err;
- argv[1] = NULL;
- neednew = 1;
- quote = 0;
- clen = 0;
- for (i = 0; lpCmdLine[i]; i++) {
- unsigned c = lpCmdLine[i];
- if (c == ' ' && !quote) {
- neednew = 1;
- continue;
- }
- if (c == '"') {
- quote ^= 1;
- continue;
- }
- if (c == '\\' && lpCmdLine[i + 1]) {
- c = lpCmdLine[++i];
- }
- if (neednew) {
- if (!(argv = realloc(argv, (argc + 2) * sizeof(unsigned char *)))) goto alloc_err;
- if (!(argv[argc] = malloc(1))) goto alloc_err;
- argv[argc + 1] = NULL;
- argc++;
- neednew = 0;
- clen = 0;
- }
- if (!(argv[argc - 1] = realloc(argv[argc - 1], clen + 1))) goto alloc_err;
- argv[argc - 1][clen] = c;
- argv[argc - 1][clen + 1] = 0;
- clen++;
- }
- /*debug("cmdline: -%s-", lpCmdLine);*/
- return main(argc, (char **)argv);
-}
-
-#endif
-
-#endif
diff --git a/sched.c b/sched.c
@@ -50,10 +50,7 @@ unsigned long connect_info(int type)
foreach(struct connection, ce, lce, queue) i += ce->state == S_TRANS;
return i;
case CI_KEEP:
-#ifndef DOS
- /* this is very slow on DOS */
check_keepalive_connections();
-#endif
return list_size(&keepalive_connections);
default:
internal("connect_info: bad request");
diff --git a/select.c b/select.c
@@ -54,7 +54,6 @@ struct timer {
static struct list_head timers = { &timers, &timers };
-#ifndef OPENVMS
void portable_sleep(unsigned msec)
{
struct timeval tv;
@@ -65,7 +64,6 @@ void portable_sleep(unsigned msec)
EINTRLOOP(rs, select(0, NULL, NULL, NULL, &tv));
unblock_signals();
}
-#endif
static int can_do_io(int fd, int wr, int sec)
{
@@ -124,7 +122,6 @@ int can_read(int fd)
int close_stderr(void)
{
-#ifndef DOS
int n, h, rs;
fflush(stderr);
n = c_open(cast_uchar "/dev/null", O_WRONLY | O_NOCTTY);
@@ -144,20 +141,17 @@ fail3:
fail2:
EINTRLOOP(rs, close(n));
fail1:
-#endif
return -1;
}
void restore_stderr(int h)
{
-#ifndef DOS
int rs;
fflush(stderr);
if (h == -1)
return;
EINTRLOOP(rs, dup2(h, 2));
EINTRLOOP(rs, close(h));
-#endif
}
diff --git a/session.c b/session.c
@@ -380,11 +380,7 @@ static int close_download_file(struct download *down)
{
int rs;
if (down->handle != -1) {
-#ifndef OPENVMS
- /* a bug in OpenVMS ... the process hangs if quota is exceeded
- and ftruncate + close is executed */
EINTRLOOP(rs, ftruncate(down->handle, down->last_pos - down->file_shift));
-#endif
EINTRLOOP(rs, close(down->handle));
down->handle = -1;
if (rs) return -1;
@@ -447,13 +443,7 @@ int test_abort_downloads_to_file(unsigned char *file, unsigned char *cwd, int ab
struct list_head *ldown;
foreach(struct download, down, ldown, downloads) {
if (strcmp(cast_const_char down->cwd, cast_const_char cwd)) {
-#if defined(DOS_FS)
- if (file[0] && file[1] == ':' && dir_sep(file[2])) goto abs;
-#elif defined(SPAD)
- if (_is_absolute(cast_const_char file) == _ABS_TOTAL) goto abs;
-#else
if (file[0] == '/') goto abs;
-#endif
continue;
}
abs:
@@ -858,7 +848,6 @@ static int download_prealloc(struct download *down, off_t est_length)
{
if (est_length <= 0)
return 0;
-#ifndef OPENVMS
#ifdef HAVE_OPEN_PREALLOC
if (!down->last_pos && !strcmp(cast_const_char down->file, cast_const_char down->orig_file)) {
struct stat st;
@@ -872,7 +861,6 @@ static int download_prealloc(struct download *down, off_t est_length)
return -1;
}
#endif
-#endif
return 0;
}
@@ -1042,20 +1030,6 @@ int create_download_file(struct session *ses, unsigned char *cwd, unsigned char
wd = get_cwd();
set_cwd(cwd);
file = translate_download_file(fi);
-#ifdef WIN
- {
- unsigned char *ext = cast_uchar strrchr(cast_const_char file, '.');
- if (ext && (
- !casestrcmp(ext, cast_uchar ".exe") ||
- !casestrcmp(ext, cast_uchar ".com") ||
- !casestrcmp(ext, cast_uchar ".bat"))) {
- if (perm == 0666)
- perm |= 0111;
- else
- perm |= 0100;
- }
- }
-#endif
#ifdef HAVE_OPEN_PREALLOC
if (siz && !(mode & CDF_NOTRUNC)) {
h = open_prealloc(file, O_CREAT | O_NOCTTY | O_WRONLY | O_TRUNC | (mode & CDF_EXCL ? O_EXCL : 0), perm, siz);
@@ -1175,30 +1149,16 @@ static unsigned char *get_temp_name(unsigned char *url, unsigned char *head)
unsigned char *name, *fn, *fnx;
unsigned char *nm;
unsigned char *directory = NULL;
-#ifdef WIN
- directory = cast_uchar getenv("TMP");
- if (!directory) directory = cast_uchar getenv("TEMP");
-#endif
nm = cast_uchar tempnam(cast_const_char directory, "links");
if (!nm) return NULL;
-#ifdef DOS_FS_8_3
- if (strlen(cast_const_char nm) > 4 && !casestrcmp(nm + strlen(cast_const_char nm) - 4, cast_uchar ".tmp")) nm[strlen(cast_const_char nm) - 4] = 0;
-#endif
name = init_str();
nl = 0;
add_to_str(&name, &nl, nm);
free(nm);
fn = get_filename_from_url(url, head, 1);
-#ifndef DOS_FS_8_3
fnx = cast_uchar strchr(cast_const_char fn, '.');
-#else
- fnx = cast_uchar strrchr(cast_const_char fn, '.');
-#endif
if (fnx) {
unsigned char *s;
-#ifdef DOS_FS_8_3
- if (strlen(cast_const_char fnx) > 4) fnx[4] = 0;
-#endif
s = stracpy(fnx);
check_shell_security(&s);
add_to_str(&name, &nl, s);
@@ -1573,10 +1533,6 @@ static void create_new_frames(struct f_data_c *fd, struct frameset_desc *fs, str
int x, y;
int xp, yp;
-#ifdef JS
- if (fd->onload_frameset_code) mem_free(fd->onload_frameset_code);
- fd->onload_frameset_code = stracpy(fs->onload_code);
-#endif
if (list_size(&fd->loc->subframes) != (unsigned long)fs->n) {
while (!list_empty(fd->loc->subframes))
destroy_location(list_struct(fd->loc->subframes.next, struct location));
@@ -1645,11 +1601,6 @@ static void html_interpret(struct f_data_c *fd, int report_status)
struct list_head *lsf;
int cch;
struct document_options o;
-#ifdef JS
- struct js_event_spec *doc_js;
- struct js_event_spec **link_js;
- int nlink_js;
-#endif
if (!fd->loc) goto d;
if (fd->f_data) {
oxw = fd->f_data->opt.xw;
@@ -1667,11 +1618,7 @@ static void html_interpret(struct f_data_c *fd, int report_status)
if (fd->parent && fd->parent->f_data && !o.hard_assume) {
o.assume_cp = fd->parent->f_data->cp;
}
-#ifdef JS
- o.js_enable = js_enable;
-#else
o.js_enable=0;
-#endif
#ifdef G
o.bfu_aspect=bfu_aspect;
#else
@@ -1713,36 +1660,9 @@ static void html_interpret(struct f_data_c *fd, int report_status)
o.braille = 0;
}
if (!(o.framename = fd->loc->name)) o.framename = NULL;
-#ifdef JS
- doc_js = NULL;
- link_js = DUMMY;
- nlink_js = 0;
- if (fd->f_data) {
- copy_js_event_spec(&doc_js, fd->f_data->js_event);
- if (fd->f_data->nlinks > fd->f_data->nlink_events) nlink_js = fd->f_data->nlinks; else nlink_js = fd->f_data->nlink_events;
- if ((unsigned)nlink_js > MAXINT / sizeof(struct js_event_spec *)) overalloc();
- link_js = mem_alloc(nlink_js * sizeof(struct js_event_spec *));
- for (i = 0; i < fd->f_data->nlinks; i++) copy_js_event_spec(&link_js[i], fd->f_data->links[i].js_event);
- for (; i < fd->f_data->nlink_events; i++) copy_js_event_spec(&link_js[i], fd->f_data->link_events[i]);
- }
-#endif
if (!(fd->f_data = cached_format_html(fd, fd->rq, fd->rq->url, &o, &cch, report_status))) {
-#ifdef JS
- for (i = 0; i < nlink_js; i++) free_js_event_spec(link_js[i]);
- mem_free(link_js);
- free_js_event_spec(doc_js);
-#endif
goto d;
}
-#ifdef JS
- if (join_js_event_spec(&fd->f_data->js_event, doc_js)) fd->f_data->uncacheable = 1;
- for (i = 0; i < fd->f_data->nlink_events; i++) free_js_event_spec(fd->f_data->link_events[i]);
- mem_free(fd->f_data->link_events);
- fd->f_data->link_events = link_js;
- fd->f_data->nlink_events = nlink_js;
- for (i = 0; i < fd->f_data->nlinks && i < nlink_js; i++) if (join_js_event_spec(&fd->f_data->links[i].js_event, link_js[i])) fd->f_data->uncacheable = 1;
- free_js_event_spec(doc_js);
-#endif
/* erase frames if changed */
i = (int)list_size(&fd->subframes);
@@ -1903,14 +1823,8 @@ void reinit_f_data_c(struct f_data_c *fd)
if (fd->ses->wtd_target_base == fd1) fd->ses->wtd_target_base = NULL;
reinit_f_data_c(fd1);
if (fd->ses->wtd_target_base == fd1) fd->ses->wtd_target_base = fd;
-#ifdef JS
- if (fd->ses->defered_target_base == fd1) fd->ses->defered_target_base = fd;
-#endif
}
free_list(struct f_data_c, fd->subframes);
-#ifdef JS
- if (fd->onload_frameset_code)mem_free(fd->onload_frameset_code),fd->onload_frameset_code=NULL;
-#endif
fd->loc = NULL;
if (fd->f_data && fd->f_data->rq) fd->f_data->rq->upcall = NULL;
if (fd->f_data && fd->f_data->af) foreach(struct additional_file, af, laf, fd->f_data->af->af) if (af->rq) {
@@ -2001,22 +1915,6 @@ static void refresh_timer(void *fd_)
}
}
-#ifdef JS
-static int frame_and_all_subframes_loaded(struct f_data_c *fd)
-{
- struct f_data_c *f;
- struct list_head *lf;
- int loaded = fd->done || fd->rq == NULL;
-
- if (loaded) /* this frame is loaded */
- foreach(struct f_data_c, f, lf, fd->subframes) {
- loaded = frame_and_all_subframes_loaded(f);
- if (!loaded) break;
- }
- return loaded;
-}
-#endif
-
void fd_loaded(struct object_request *rq, void *fd_)
{
struct f_data_c *fd = (struct f_data_c *)fd_;
@@ -2041,21 +1939,12 @@ void fd_loaded(struct object_request *rq, void *fd_)
/* it may happen that html_interpret requests load of additional file */
if (!f_is_finished(fd->f_data)) goto more_data;
fn:
-#ifdef JS
- if (fd->f_data->are_there_scripts) {
- jsint_scan_script_tags(fd);
- if (!f_is_finished(fd->f_data)) goto more_data;
- }
-#endif
fd->done = 1;
fd->parsed_done = 0;
if (fd->f_data->refresh) {
if (fd->refresh_timer != NULL) kill_timer(fd->refresh_timer);
fd->refresh_timer = install_timer(fd->f_data->refresh_seconds * 1000, refresh_timer, fd);
}
-#ifdef JS
- jsint_run_queue(fd);
-#endif
} else if (get_time() - fd->last_update >= fd->next_update_interval || (rq == fd->rq && rq->state < 0)) {
uttime t;
if (!fd->parsed_done) {
@@ -2082,22 +1971,6 @@ more_data:
}
priint:
/* process onload handler of a frameset */
-#ifdef JS
- {
- int all_loaded;
-
- /* go to parent and test if all subframes are loaded, if yes, call onload handler */
-
- if (!fd->parent) goto hell; /* this frame has no parent, skip */
- if (!fd->parent->onload_frameset_code)goto hell; /* no onload handler, skip all this */
- all_loaded=frame_and_all_subframes_loaded(fd->parent);
- if (!all_loaded) goto hell;
- /* parent has all subframes loaded */
- jsint_execute_code(fd->parent,fd->parent->onload_frameset_code,strlen(cast_const_char fd->parent->onload_frameset_code),-1,-1,-1, NULL);
- mem_free(fd->parent->onload_frameset_code), fd->parent->onload_frameset_code=NULL;
- hell:;
- }
-#endif
if (rq && (rq->state == O_FAILED || rq->state == O_INCOMPLETE) && (fd->rq == rq || fd->ses->rq == rq) && !rq->dont_print_error) print_error_dialog(fd->ses, &rq->stat, rq->url);
#ifdef LINKS_TESTMODE_DOCUMENT_AUTO_EXIT
if (f_is_finished(fd->f_data))
@@ -2643,21 +2516,7 @@ static void ses_finished_1st_state(struct object_request *rq, void *ses_)
void ses_destroy_defered_jump(struct session *ses)
{
-#ifdef JS
- if (ses->defered_url) mem_free(ses->defered_url), ses->defered_url = NULL;
- if (ses->defered_target) mem_free(ses->defered_target), ses->defered_target = NULL;
- ses->defered_target_base = NULL;
-#endif
-}
-
-#ifdef JS
-/* test if there're any running scripts */
-static inline int any_running_scripts(struct f_data_c *fd)
-{
- if (!fd->js) return 0;
- return (fd->js->active) || (!list_empty(fd->js->queue));
}
-#endif
/* if from_goto_dialog is 1, set prev_url to NULL */
void goto_url_f(struct session *ses, void (*state2)(struct session *), unsigned char *url, unsigned char *target, struct f_data_c *df, int data, int defer, int from_goto_dialog, int refresh)
@@ -2667,9 +2526,6 @@ void goto_url_f(struct session *ses, void (*state2)(struct session *), unsigned
void (*fn)(struct session *, unsigned char *);
int reloadlevel, allow_flags;
if (!state2) state2 = ses_go_to_2nd_state;
-#ifdef JS
- if (ses->defered_url && defer && any_running_scripts(ses->screen)) return;
-#endif
ses_destroy_defered_jump(ses);
if ((fn = get_external_protocol_function(url))) {
if (proxies.only_proxies && url_bypasses_socks(url)) {
@@ -2685,16 +2541,6 @@ void goto_url_f(struct session *ses, void (*state2)(struct session *), unsigned
print_error_dialog(ses, &stat, url);
return;
}
-#ifdef JS
- if (defer && any_running_scripts(ses->screen)) {
- ses->defered_url = u;
- ses->defered_target = stracpy(target);
- ses->defered_target_base = df;
- ses->defered_data = data;
- ses->defered_seq = jsint_execute_seq++;
- return;
- }
-#endif
pos = extract_position(u);
if (ses->wtd == state2 && !strcmp(cast_const_char ses->rq->orig_url, cast_const_char u) && !xstrcmp(ses->wtd_target, target) && ses->wtd_target_base == df) {
mem_free(u);
diff --git a/setup.h b/setup.h
@@ -187,11 +187,7 @@
#define MAX_INPUT_URL_LEN 4096
-#ifdef DOS
-#define SPD_DISP_TIME 1000
-#else
#define SPD_DISP_TIME 200
-#endif
#define CURRENT_SPD_SEC (10000 / SPD_DISP_TIME)
#define CURRENT_SPD_AFTER (20000 / SPD_DISP_TIME)
diff --git a/smb.c b/smb.c
@@ -1,676 +0,0 @@
-#include "links.h"
-
-#ifndef DISABLE_SMB
-
-#define SMBCLIENT 0
-#define SMBC 1
-#define N_CLIENTS 2
-
-static int smb_client = 0;
-
-#define CLIENT_NOT_FOUND_STRING "client not found"
-
-struct smb_connection_info {
- int client;
- int list;
- int cl;
- int ntext;
- unsigned char text[1];
-};
-
-static void smb_got_data(void *);
-static void smb_got_text(void *);
-static void end_smb_connection(struct connection *);
-
-void smb_func(struct connection *c)
-{
- int i;
- int po[2];
- int pe[2];
- unsigned char *host, *user, *pass, *port, *data1, *data, *share, *dir;
- int datal;
- unsigned char *p;
- pid_t r;
- int rs;
- struct smb_connection_info *si;
- si = mem_alloc(sizeof(struct smb_connection_info) + 2);
- memset(si, 0, sizeof(struct smb_connection_info));
- c->info = si;
- si->client = smb_client;
- host = get_host_name(c->url);
- if (!host) {
- setcstate(c, S_INTERNAL);
- abort_connection(c);
- return;
- }
- if (!(user = get_user_name(c->url))) user = stracpy(cast_uchar "");
- if (!(pass = get_pass(c->url))) pass = stracpy(cast_uchar "");
- if (!(port = get_port_str(c->url))) port = stracpy(cast_uchar "");
- if (!(data1 = get_url_data(c->url))) data1 = cast_uchar "";
- data = init_str(), datal = 0;
- add_conv_str(&data, &datal, data1, (int)strlen(cast_const_char data1), -2);
-
- for (i = 0; data[i]; i++) if (data[i] < 32 || data[i] == ';' || (data[i] == '"' && smb_client == SMBCLIENT)) {
-/* ';' shouldn't cause security problems but samba doesn't like it */
-/* '"' is allowed for smbc */
- mem_free(host);
- mem_free(port);
- mem_free(user);
- mem_free(pass);
- mem_free(data);
- setcstate(c, S_BAD_URL);
- abort_connection(c);
- return;
- }
-
- if ((p = cast_uchar strchr(cast_const_char data, '/'))) share = memacpy(data, p - data), dir = p + 1;
- else if (*data) {
- if (!c->cache) {
- if (get_connection_cache_entry(c)) {
- mem_free(host);
- mem_free(port);
- mem_free(user);
- mem_free(pass);
- mem_free(data);
- setcstate(c, S_OUT_OF_MEM);
- abort_connection(c);
- return;
- }
- c->cache->refcount--;
- }
- if (c->cache->redirect) mem_free(c->cache->redirect);
- c->cache->redirect = stracpy(c->url);
- c->cache->redirect_get = 1;
- add_to_strn(&c->cache->redirect, cast_uchar "/");
- c->cache->incomplete = 0;
- mem_free(host);
- mem_free(port);
- mem_free(user);
- mem_free(pass);
- mem_free(data);
- setcstate(c, S__OK);
- abort_connection(c);
- return;
- } else share = stracpy(cast_uchar ""), dir = cast_uchar "";
- if (!*share) si->list = 1;
- else if (!*dir || dir[strlen(cast_const_char dir) - 1] == '/' || dir[strlen(cast_const_char dir) - 1] == '\\') si->list = 2;
- if (c_pipe(po)) {
- int err = errno;
- mem_free(host);
- mem_free(port);
- mem_free(user);
- mem_free(pass);
- mem_free(share);
- mem_free(data);
- setcstate(c, get_error_from_errno(err));
- abort_connection(c);
- return;
- }
- if (c_pipe(pe)) {
- int err = errno;
- mem_free(host);
- mem_free(port);
- mem_free(user);
- mem_free(pass);
- mem_free(share);
- mem_free(data);
- EINTRLOOP(rs, close(po[0]));
- EINTRLOOP(rs, close(po[1]));
- setcstate(c, get_error_from_errno(err));
- abort_connection(c);
- return;
- }
- c->from = 0;
- EINTRLOOP(r, fork());
- if (r == -1) {
- int err = errno;
- mem_free(host);
- mem_free(port);
- mem_free(user);
- mem_free(pass);
- mem_free(share);
- mem_free(data);
- EINTRLOOP(rs, close(po[0]));
- EINTRLOOP(rs, close(po[1]));
- EINTRLOOP(rs, close(pe[0]));
- EINTRLOOP(rs, close(pe[1]));
- setcstate(c, get_error_from_errno(err));
- retry_connection(c);
- return;
- }
- if (!r) {
- int n;
- unsigned char *v[32];
- unsigned char *uphp;
- close_fork_tty();
- EINTRLOOP(rs, close(1));
- if (si->list)
- EINTRLOOP(rs, dup2(pe[1], 1));
- else
- EINTRLOOP(rs, dup2(po[1], 1));
- EINTRLOOP(rs, close(2));
- EINTRLOOP(rs, dup2(pe[1], 2));
- EINTRLOOP(rs, close(0));
- EINTRLOOP(rs, open("/dev/null", O_RDONLY));
- EINTRLOOP(rs, close(po[0]));
- EINTRLOOP(rs, close(pe[0]));
- EINTRLOOP(rs, close(po[1]));
- EINTRLOOP(rs, close(pe[1]));
- n = 0;
- switch (si->client) {
- case SMBCLIENT:
- v[n++] = cast_uchar "smbclient";
- if (!*share) {
- v[n++] = cast_uchar "-L";
- v[n++] = host;
- } else {
- unsigned char *s = stracpy(cast_uchar "//");
- add_to_strn(&s, host);
- add_to_strn(&s, cast_uchar "/");
- add_to_strn(&s, share);
- v[n++] = s;
- if (*pass && !*user) {
- v[n++] = pass;
- }
- }
- v[n++] = cast_uchar "-N";
- v[n++] = cast_uchar "-E";
- if (*port) {
- v[n++] = cast_uchar "-p";
- v[n++] = port;
- }
- if (*user) {
- v[n++] = cast_uchar "-U";
- if (!*pass) {
- v[n++] = user;
- } else {
- unsigned char *s = stracpy(user);
- add_to_strn(&s, cast_uchar "%");
- add_to_strn(&s, pass);
- v[n++] = s;
- }
- }
- if (*share) {
- if (!*dir || dir[strlen(cast_const_char dir) - 1] == '/' || dir[strlen(cast_const_char dir) - 1] == '\\') {
- if (*dir) {
- v[n++] = cast_uchar "-D";
- v[n++] = dir;
- }
- v[n++] = cast_uchar "-c";
- v[n++] = cast_uchar "ls";
- } else {
- unsigned char *ss;
- unsigned char *s = stracpy(cast_uchar "get \"");
- add_to_strn(&s, dir);
- add_to_strn(&s, cast_uchar "\" -");
- while ((ss = cast_uchar strchr(cast_const_char s, '/'))) *ss = '\\';
- v[n++] = cast_uchar "-c";
- v[n++] = s;
- }
- }
- break;
- case SMBC:
- v[n++] = cast_uchar "smbc";
- uphp = stracpy(cast_uchar "");
- if (*user) {
- add_to_strn(&uphp, user);
- if (*pass) {
- add_to_strn(&uphp, cast_uchar ":");
- add_to_strn(&uphp, pass);
- }
- add_to_strn(&uphp, cast_uchar "@");
- }
- add_to_strn(&uphp, host);
- if (*port) {
- add_to_strn(&uphp, cast_uchar ":");
- add_to_strn(&uphp, port);
- }
- if (!*share) {
- v[n++] = cast_uchar "-L";
- v[n++] = uphp;
- } else {
- add_to_strn(&uphp, cast_uchar "/");
- add_to_strn(&uphp, share);
- if (!*dir || dir[strlen(cast_const_char dir) - 1] == '/' || dir[strlen(cast_const_char dir) - 1] == '\\') {
- add_to_strn(&uphp, cast_uchar "/");
- add_to_strn(&uphp, dir);
- v[n++] = uphp;
- v[n++] = cast_uchar "-c";
- v[n++] = cast_uchar "ls";
- } else {
- unsigned char *d = init_str();
- int dl = 0;
- unsigned char *dp = dir;
- v[n++] = uphp;
- v[n++] = cast_uchar "-c";
- add_to_str(&d, &dl, cast_uchar "pipe cat ");
- while (*dp) {
- if (*dp <= ' ' || *dp == '\\' || *dp == '"' || *dp == '\'' || *dp == '*' || *dp == '?') add_chr_to_str(&d, &dl, '\\');
- add_chr_to_str(&d, &dl, *dp);
- dp++;
- }
- v[n++] = d;
- }
- }
- break;
- default:
- internal("unsupported smb client");
- }
- v[n++] = NULL;
- EINTRLOOP(rs, execvp(cast_const_char v[0], (void *)v));
- hard_write(2, cast_uchar CLIENT_NOT_FOUND_STRING, (int)strlen(CLIENT_NOT_FOUND_STRING));
- _exit(1);
- }
- c->pid = r;
- mem_free(host);
- mem_free(port);
- mem_free(user);
- mem_free(pass);
- mem_free(share);
- mem_free(data);
- c->sock1 = po[0];
- c->sock2 = pe[0];
- EINTRLOOP(rs, close(po[1]));
- EINTRLOOP(rs, close(pe[1]));
- set_handlers(po[0], smb_got_data, NULL, c);
- set_handlers(pe[0], smb_got_text, NULL, c);
- setcstate(c, S_CONN);
-}
-
-static int smbc_get_num(unsigned char *text, int *ptr, off_t *res)
-{
- off_t num;
- int dec, dec_order, unit;
- int was_digit;
- int i = *ptr;
- const off_t max_off_t = (((off_t)1 << ((sizeof(off_t) * 8 - 2))) - 1) * 2 + 1;
-
- while (text[i] == ' ' || text[i] == '\t') i++;
- was_digit = 0;
- num = 0;
- while (text[i] >= '0' && text[i] <= '9') {
- if (num >= max_off_t / 10) return -1;
- num = num * 10 + text[i] - '0';
- i++;
- was_digit = 1;
- }
- dec = 0; dec_order = 1;
- if (text[i] == '.') {
- i++;
- while (text[i] >= '0' && text[i] <= '9') {
- if (dec_order < 1000000) {
- dec = dec * 10 + text[i] - '0';
- dec_order *= 10;
- }
- i++;
- was_digit = 1;
- }
- }
- if (!was_digit) return -1;
- if (upcase(text[i]) == 'B') unit = 1;
- else if (upcase(text[i]) == 'K') unit = 1 << 10;
- else if (upcase(text[i]) == 'M') unit = 1 << 20;
- else if (upcase(text[i]) == 'G') unit = 1 << 30;
- else return -1;
- i++;
- *ptr = i;
- if (num >= max_off_t / unit) return -1;
- *res = num * unit + (off_t)((double)dec * ((double)unit / (double)dec_order));
- return 0;
-}
-
-static void smb_read_text(struct connection *c, int sock)
-{
- int r;
- struct smb_connection_info *si = c->info;
- if ((unsigned)sizeof(struct smb_connection_info) + si->ntext + page_size + 2 > MAXINT) overalloc();
- si = mem_realloc(si, sizeof(struct smb_connection_info) + si->ntext + page_size + 2);
- c->info = si;
- EINTRLOOP(r, (int)read(sock, si->text + si->ntext, page_size));
- if (r == -1) {
- setcstate(c, get_error_from_errno(errno));
- retry_connection(c);
- return;
- }
- if (r == 0) {
- if (!si->cl) {
- si->cl = 1;
- set_handlers(sock, NULL, NULL, NULL);
- return;
- }
- end_smb_connection(c);
- return;
- }
- si->ntext += r;
- if (!c->from) setcstate(c, S_GETH);
- if (c->from && si->client == SMBC) {
- int lasti = 0;
- int i = 0;
- si->text[si->ntext] = 0;
- for (i = 0; i + 7 < si->ntext; i++) {
- nexti:
- if ((si->text[i] == '\n' || si->text[i] == '\r') && (si->text[i + 1] == ' ' || (si->text[i + 1] >= '0' && si->text[i + 1] <= '9')) && ((si->text[i + 2] == ' ' && si->text[i + 1] == ' ') || (si->text[i + 2] >= '0' && si->text[i + 2] <= '9')) && (si->text[i + 3] >= '0' && si->text[i + 3] <= '9') && si->text[i + 4] == '%' && si->text[i + 5] == ' ' && si->text[i + 6] == '[') {
- off_t position, total = 0; /* against warning */
- i += 7;
- while (si->text[i] != ']') {
- if (!si->text[i] || si->text[i] == '\n' || si->text[i] == '\r') {
- goto nexti;
- }
- i++;
- }
- i++;
- if (smbc_get_num(si->text, &i, &position)) {
- goto nexti;
- }
- while (si->text[i] == ' ' || si->text[i] == '\t') i++;
- if (si->text[i] != '/') {
- goto nexti;
- }
- i++;
- if (smbc_get_num(si->text, &i, &total)) {
- goto nexti;
- }
- if (total < c->from) total = c->from;
- c->est_length = total;
- lasti = i;
- }
- }
- if (lasti) memmove(si->text, si->text + lasti, si->ntext -= lasti);
- }
-}
-
-static void smb_got_data(void *c_)
-{
- struct connection *c = (struct connection *)c_;
- struct smb_connection_info *si = c->info;
- unsigned char *buffer = mem_alloc(page_size);
- int r;
- int a;
- if (si->list) {
- smb_read_text(c, c->sock1);
- mem_free(buffer);
- return;
- }
- EINTRLOOP(r, (int)read(c->sock1, buffer, page_size));
- if (r == -1) {
- setcstate(c, get_error_from_errno(errno));
- retry_connection(c);
- mem_free(buffer);
- return;
- }
- if (r == 0) {
- mem_free(buffer);
- if (!si->cl) {
- si->cl = 1;
- set_handlers(c->sock1, NULL, NULL, NULL);
- return;
- }
- end_smb_connection(c);
- return;
- }
- setcstate(c, S_TRANS);
- if (!c->cache) {
- if (get_connection_cache_entry(c)) {
- setcstate(c, S_OUT_OF_MEM);
- abort_connection(c);
- mem_free(buffer);
- return;
- }
- c->cache->refcount--;
- }
- if ((off_t)(0UL + c->from + r) < 0) {
- setcstate(c, S_LARGE_FILE);
- abort_connection(c);
- mem_free(buffer);
- return;
- }
- c->received += r;
- a = add_fragment(c->cache, c->from, buffer, r);
- if (a < 0) {
- setcstate(c, a);
- abort_connection(c);
- mem_free(buffer);
- return;
- }
- if (a == 1) c->tries = 0;
- c->from += r;
- mem_free(buffer);
-}
-
-static void smb_got_text(void *c_)
-{
- struct connection *c = (struct connection *)c_;
- smb_read_text(c, c->sock2);
-}
-
-static void end_smb_connection(struct connection *c)
-{
- struct smb_connection_info *si = c->info;
- if (!c->cache) {
- if (get_connection_cache_entry(c)) {
- setcstate(c, S_OUT_OF_MEM);
- abort_connection(c);
- return;
- }
- c->cache->refcount--;
- }
- if (!c->from) {
- int sdir;
- if (si->ntext && si->text[si->ntext - 1] != '\n') si->text[si->ntext++] = '\n';
- si->text[si->ntext] = 0;
- if (!strcmp(cast_const_char si->text, CLIENT_NOT_FOUND_STRING "\n")) {
- setcstate(c, S_NO_SMB_CLIENT);
- if (++si->client < N_CLIENTS) {
- if (si->client > smb_client) smb_client = si->client;
- c->tries = -1;
- retry_connection(c);
- } else {
- smb_client = 0;
- abort_connection(c);
- }
- return;
- }
- sdir = 0;
- if (si->client == SMBC) {
- unsigned char *st = si->text;
- if (!memcmp(st, "ServerName", 10) && strchr(cast_const_char st, '\n')) st = cast_uchar strchr(cast_const_char st, '\n') + 1;
- if (!memcmp(st, "Logged", 6) && strchr(cast_const_char st, '\n')) st = cast_uchar strchr(cast_const_char st, '\n') + 1;
- if (!strstr(cast_const_char st, "ERR")) sdir = 1;
- }
- if (!si->list && *c->url &&
- c->url[strlen(cast_const_char c->url) - 1] != '/' &&
- c->url[strlen(cast_const_char c->url) - 1] != '\\' &&
- (strstr(cast_const_char si->text, "NT_STATUS_FILE_IS_A_DIRECTORY") ||
- strstr(cast_const_char si->text, "NT_STATUS_ACCESS_DENIED") ||
- strstr(cast_const_char si->text, "ERRbadfile") || sdir)) {
- if (c->cache->redirect) mem_free(c->cache->redirect);
- c->cache->redirect = stracpy(c->url);
- c->cache->redirect_get = 1;
- add_to_strn(&c->cache->redirect, cast_uchar "/");
- c->cache->incomplete = 0;
- } else {
- unsigned char *ls, *le, *le2;
- unsigned char *ud;
- unsigned char *t = init_str();
- int l = 0;
- int type = 0;
- int pos = 0;
- int a;
- add_to_str(&t, &l, cast_uchar "<html><head><title>");
- ud = stracpy(c->url);
- if (strchr(cast_const_char ud, POST_CHAR)) *cast_uchar strchr(cast_const_char ud, POST_CHAR) = 0;
- add_conv_str(&t, &l, ud, (int)strlen(cast_const_char ud), -1);
- mem_free(ud);
- add_to_str(&t, &l, cast_uchar "</title></head><body><pre>");
- if (si->list == 1 && si->client == SMBC) {
-/* smbc has a nasty bug that it writes field descriptions to stderr and data to
- stdout. Because of stdout buffer, they'll get mixed in the output. Try to
- demix them. */
-#define SERVER "Server Comment\n------ -------\n"
-#define WORKGR "Workgroup Master\n--------- ------\n"
- unsigned char *spos = cast_uchar strstr(cast_const_char si->text, SERVER);
- unsigned char *gpos;
- unsigned char *p, *pp, *ppp;
- if (spos) memmove(spos, spos + strlen(SERVER), strlen(cast_const_char spos) - strlen(SERVER) + 1);
- gpos = cast_uchar strstr(cast_const_char si->text, WORKGR);
- if (gpos) memmove(gpos, gpos + strlen(WORKGR), strlen(cast_const_char gpos) - strlen(WORKGR) + 1);
- if (!spos && !gpos) goto sc;
- pp = NULL, ppp = NULL, p = si->text;
- while ((p = cast_uchar strstr(cast_const_char p, "\n\n"))) ppp = pp, pp = p + 2, p++;
- if (!pp) goto sc;
- if (!spos || !gpos) ppp = NULL;
- if (spos) {
- if (!ppp) ppp = pp, pp = NULL;
- memmove(ppp + strlen(SERVER), ppp, strlen(cast_const_char ppp) + 1);
- memcpy(ppp, SERVER, strlen(SERVER));
- if (pp) pp += strlen(SERVER);
- }
- if (gpos && pp) {
- memmove(pp + strlen(WORKGR), pp, strlen(cast_const_char pp) + 1);
- memcpy(pp, WORKGR, strlen(WORKGR));
- }
- goto sc;
- }
- sc:
- ls = si->text;
- while ((le = cast_uchar strchr(cast_const_char ls, '\n'))) {
- unsigned char *lx;
- unsigned char *st;
- le2 = cast_uchar strchr(cast_const_char ls, '\r');
- if (!le2 || le2 > le) le2 = le;
- lx = memacpy(ls, le2 - ls);
- if (si->list == 1) {
- unsigned char *ll, *lll;
- if (!*lx) type = 0;
- if (strstr(cast_const_char lx, "Sharename") && (st = cast_uchar strstr(cast_const_char lx, "Type"))) {
- pos = (int)(st - lx);
- type = 1;
- goto af;
- }
- if (strstr(cast_const_char lx, "Server") && strstr(cast_const_char lx, "Comment")) {
- type = 2;
- goto af;
- }
- if (strstr(cast_const_char lx, "Workgroup") && (st = cast_uchar strstr(cast_const_char lx, "Master"))) {
- pos = (int)(st - lx);
- type = 3;
- goto af;
- }
- if (!type) goto af;
- for (ll = lx; *ll; ll++) if (!WHITECHAR(*ll) && *ll != '-') goto np;
- goto af;
- np:
- for (ll = lx; *ll; ll++) if (!WHITECHAR(*ll)) break;
- for (lll = ll; *lll /* && lll[1]*/; lll++) if (WHITECHAR(*lll) /*&& WHITECHAR(lll[1])*/) break;
- if (type == 1) {
- unsigned char *llll;
- if (!strstr(cast_const_char lll, "Disk")) goto af;
- if (pos && (size_t)pos < strlen(cast_const_char lx) && WHITECHAR(*(llll = lx + pos - 1)) && llll > ll) {
- while (llll > ll && WHITECHAR(*llll)) llll--;
- if (!WHITECHAR(*llll)) lll = llll + 1;
- }
- add_conv_str(&t, &l, lx, (int)(ll - lx), 0);
- add_to_str(&t, &l, cast_uchar "<a href=\"/");
- add_conv_str(&t, &l, ll, (int)(lll - ll), 1);
- add_to_str(&t, &l, cast_uchar "/\">");
- add_conv_str(&t, &l, ll, (int)(lll - ll), 0);
- add_to_str(&t, &l, cast_uchar "</a>");
- add_conv_str(&t, &l, lll, (int)strlen(cast_const_char lll), 0);
- } else if (type == 2) {
- sss:
- add_conv_str(&t, &l, lx, (int)(ll - lx), 0);
- add_to_str(&t, &l, cast_uchar "<a href=\"smb://");
- add_conv_str(&t, &l, ll, (int)(lll - ll), 1);
- add_to_str(&t, &l, cast_uchar "/\">");
- add_conv_str(&t, &l, ll, (int)(lll - ll), 0);
- add_to_str(&t, &l, cast_uchar "</a>");
- add_conv_str(&t, &l, lll, (int)strlen(cast_const_char lll), 0);
- } else if (type == 3) {
- if ((size_t)pos < strlen(cast_const_char lx) && pos && WHITECHAR(lx[pos - 1]) && !WHITECHAR(lx[pos])) ll = lx + pos;
- else for (ll = lll; *ll; ll++) if (!WHITECHAR(*ll)) break;
- for (lll = ll; *lll; lll++) if (WHITECHAR(*lll)) break;
- goto sss;
- } else goto af;
- } else if (si->list == 2 && si->client == SMBCLIENT) {
- if (strstr(cast_const_char lx, "NT_STATUS")) {
- le[1] = 0;
- goto af;
- }
- if (le2 - ls >= 5 && ls[0] == ' ' && ls[1] == ' ' && ls[2] != ' ') {
- int dir;
- unsigned char *pp;
- unsigned char *p = ls + 3;
- while (p + 2 <= le2) {
- if (p[0] == ' ' && p[1] == ' ') goto o;
- p++;
- }
- goto af;
- o:
- dir = 0;
- pp = p;
- while (pp < le2 && *pp == ' ') pp++;
- while (pp < le2 && *pp != ' ') {
- if (*pp == 'D') {
- dir = 1;
- break;
- }
- pp++;
- }
- add_to_str(&t, &l, cast_uchar " <a href=\"./");
- add_conv_str(&t, &l, ls + 2, (int)(p - (ls + 2)), 1);
- if (dir) add_chr_to_str(&t, &l, '/');
- add_to_str(&t, &l, cast_uchar "\">");
- add_conv_str(&t, &l, ls + 2, (int)(p - (ls + 2)), 0);
- add_to_str(&t, &l, cast_uchar "</a>");
- add_conv_str(&t, &l, p, (int)(le - p), 0);
- } else goto af;
- } else if (si->list == 2 && si->client == SMBC) {
- unsigned char *d;
- if (le2 - ls <= 17) goto af;
- d = ls + 17;
- smbc_next_chr:
- if (d + 9 >= le2) goto af;
- if (!(d[0] == ':' && d[1] >= '0' && d[1] <= '9' && d[2] >= '0' && d[2] <= '9' && d[3] == ' ' && ((d[4] == '1' && d[5] == '9') || (d[4] == '2' && d[5] >= '0' && d[5] <= '9')) && d[6] >= '0' && d[6] <= '9' && d[7] >= '0' && d[7] <= '9' && d[8] == ' ')) {
- d++;
- goto smbc_next_chr;
- }
- d += 9;
- add_conv_str(&t, &l, ls, (int)(d - ls), 0);
- add_to_str(&t, &l, cast_uchar "<a href=\"./");
- add_conv_str(&t, &l, d, (int)(le2 - d), 1);
- if (ls[4] == 'D') add_chr_to_str(&t, &l, '/');
- add_to_str(&t, &l, cast_uchar "\">");
- add_conv_str(&t, &l, d, (int)(le2 - d), 0);
- add_to_str(&t, &l, cast_uchar "</a>");
- } else af: add_conv_str(&t, &l, ls, (int)(le2 - ls), 0);
- add_chr_to_str(&t, &l, '\n');
- ls = le + 1;
- mem_free(lx);
- }
- /*add_to_str(&t, &l, si->text);*/
- a = add_fragment(c->cache, 0, t, l);
- if (a < 0) {
- mem_free(t);
- setcstate(c, a);
- abort_connection(c);
- return;
- }
- c->from += l;
- truncate_entry(c->cache, l, 1);
- c->cache->incomplete = 0;
- mem_free(t);
- if (!c->cache->head) c->cache->head = stracpy(cast_uchar "\r\n");
- add_to_strn(&c->cache->head, cast_uchar "Content-Type: text/html\r\n");
- }
- } else {
- truncate_entry(c->cache, c->from, 1);
- c->cache->incomplete = 0;
- }
- close_socket(&c->sock1);
- close_socket(&c->sock2);
- setcstate(c, S__OK);
- abort_connection(c);
- return;
-}
-
-#endif
diff --git a/string.c b/string.c
@@ -179,61 +179,6 @@ void safe_strncpy(unsigned char *dst, const unsigned char *src, size_t dst_size)
strncpy(cast_char dst, cast_const_char src, dst_size - 1);
}
-#ifdef JS
-/* deletes all nonprintable characters from string */
-void skip_nonprintable(unsigned char *txt)
-{
- unsigned char *txt1=txt;
-
- if (!txt||!*txt)return;
- for (;*txt;txt++)
- switch(*txt)
- {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- case 19:
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- case 26:
- case 27:
- case 28:
- case 29:
- case 30:
- case 31:
- break;
-
- case 9:
- *txt1=' ';
- txt1++;
- break;
-
- default:
- *txt1=*txt;
- txt1++;
- break;
- }
- *txt1=0;
-}
-#endif
-
/* don't use strcasecmp because it depends on locale */
int casestrcmp(const unsigned char *s1, const unsigned char *s2)
{
diff --git a/svg.c b/svg.c
@@ -1,308 +0,0 @@
-#include "cfg.h"
-
-#ifdef G
-#include "links.h"
-
-#ifdef HAVE_SVG
-
-#include <cairo.h>
-#include <librsvg/rsvg.h>
-#ifdef HAVE_LIBRSVG_RSVG_CAIRO_H
-#include <librsvg/rsvg-cairo.h>
-#endif
-#ifdef HAVE_LIBRSVG_LIBRSVG_FEATURES_H
-#include <librsvg/librsvg-features.h>
-#endif
-
-#if !defined(LIBRSVG_CHECK_VERSION)
-#define LIBRSVG_CHECK_VERSION(a,b,c) 0
-#endif
-
-#if LIBRSVG_CHECK_VERSION(2,40,0) && !LIBRSVG_CHECK_VERSION(2,40,16)
-#define CURRENTCOLOR_HACK
-#endif
-
-#include "bits.h"
-
-#if defined(__CYGWIN__) && defined(HAVE_LIBFONTCONFIG)
-#ifdef HAVE_PTHREADS
-#define BACKGROUND_FONT_INIT
-#endif
-#include <fontconfig/fontconfig.h>
-#include <windows.h>
-#include <w32api/shlobj.h>
-static void set_font_path(void)
-{
- unsigned char *path = cast_uchar "/cygdrive/c/Windows/Fonts";
-#if defined(HAVE_CYGWIN_CONV_PATH)
- unsigned char win32_path[MAX_PATH];
- if (SHGetFolderPathA(NULL, CSIDL_FONTS, NULL, 0, cast_char win32_path) == S_OK) {
- ssize_t l;
- unsigned char *cyg_path;
- l = cygwin_conv_path(CCP_WIN_A_TO_POSIX, win32_path, NULL, 0);
- if (l <= 0)
- goto do_default;
- cyg_path = alloca(l);
- l = cygwin_conv_path(CCP_WIN_A_TO_POSIX, win32_path, cyg_path, l);
- if (l < 0)
- goto do_default;
- path = cyg_path;
- }
- do_default:
-#endif
- FcConfigAppFontAddDir(NULL, path);
-}
-#else
-#define set_font_path() do { } while (0)
-#endif
-
-static void *do_initialize_fonts(void *ptr)
-{
-#if !defined(GLIB_DEPRECATED_IN_2_36)
- g_type_init();
-#endif
-#if !LIBRSVG_CHECK_VERSION(2,36,0)
- rsvg_init();
-#endif
- set_font_path();
- return NULL;
-}
-
-
-#ifdef BACKGROUND_FONT_INIT
-
-#include <pthread.h>
-
-static pthread_t font_thread;
-
-void spawn_font_thread(void)
-{
- int r;
- if ((r = pthread_create(&font_thread, NULL, do_initialize_fonts, NULL)))
- fatal_exit("Could not start thread: %s", strerror(r));
-}
-
-static void wait_for_fonts(void)
-{
- static unsigned char font_initialized = 0;
- if (!font_initialized) {
- int r;
- if ((r = pthread_join(font_thread, NULL)))
- fatal_exit("pthread_join failed: %s", strerror(r));
- font_initialized = 1;
- }
-}
-
-#else
-
-void spawn_font_thread(void)
-{
-}
-
-static void wait_for_fonts(void)
-{
- static unsigned char font_initialized = 0;
- if (!font_initialized) {
- do_initialize_fonts(NULL);
- font_initialized = 1;
- }
-}
-
-#endif
-
-
-struct svg_decoder {
- RsvgHandle *handle;
-#ifdef CURRENTCOLOR_HACK
- unsigned char *buffer;
- int len;
-#endif
-};
-
-void svg_start(struct cached_image *cimg)
-{
- struct svg_decoder *deco;
-
- wait_for_fonts();
-
- deco = mem_alloc(sizeof(struct svg_decoder));
-#ifdef CURRENTCOLOR_HACK
- deco->buffer = init_str();
- deco->len = 0;
-#endif
-
- cimg->decoder = deco;
- deco->handle = rsvg_handle_new();
-}
-
-void svg_restart(struct cached_image *cimg, unsigned char *data, int length)
-{
- struct svg_decoder *deco = (struct svg_decoder *)cimg->decoder;
-#ifndef CURRENTCOLOR_HACK
- GError *er = NULL;
- int h;
-
- h = close_stderr();
- if (!rsvg_handle_write(deco->handle, (const guchar *)data, length, &er)) {
- g_error_free(er);
- restore_stderr(h);
- img_end(cimg);
- }
- restore_stderr(h);
-#else
- add_bytes_to_str(&deco->buffer, &deco->len, data, length);
-#endif
-}
-
-#ifdef CURRENTCOLOR_HACK
-#define find_string "\"currentColor\""
-#define replace_string "\"black\""
-static void svg_hack_buffer(struct svg_decoder *deco)
-{
- unsigned char *new_buffer = init_str();
- int new_len = 0;
- unsigned char *ptr = deco->buffer;
- while (1) {
- int remaining = (int)(deco->buffer + deco->len - ptr);
- unsigned char *f = memmem(ptr, remaining, find_string, strlen(cast_const_char find_string));
- if (!f) {
- if (!new_len) {
- mem_free(new_buffer);
- return;
- }
- add_bytes_to_str(&new_buffer, &new_len, ptr, remaining);
- break;
- } else {
- add_bytes_to_str(&new_buffer, &new_len, ptr, f - ptr);
- add_to_str(&new_buffer, &new_len, cast_uchar replace_string);
- ptr = f + strlen(cast_const_char find_string);
- }
- }
- mem_free(deco->buffer);
- deco->buffer = new_buffer;
- deco->len = new_len;
-}
-#endif
-
-void svg_finish(struct cached_image *cimg)
-{
- struct svg_decoder *deco = (struct svg_decoder *)cimg->decoder;
- GError *er = NULL;
- RsvgDimensionData dim;
- cairo_surface_t *surf;
- cairo_t *cairo;
- unsigned char *end_buffer, *p;
- int h;
-
-#ifdef CURRENTCOLOR_HACK
- svg_hack_buffer(deco);
- h = close_stderr();
- if (!rsvg_handle_write(deco->handle, (const guchar *)deco->buffer, deco->len, &er)) {
- g_error_free(er);
- restore_stderr(h);
- goto end;
- }
- restore_stderr(h);
-#endif
-
- h = close_stderr();
- if (!rsvg_handle_close(deco->handle, &er)) {
- g_error_free(er);
- restore_stderr(h);
- goto end;
- }
- restore_stderr(h);
-
- rsvg_handle_get_dimensions(deco->handle, &dim);
-
- cimg->width = dim.width;
- cimg->height = dim.height;
- cimg->buffer_bytes_per_pixel = 4;
- cimg->red_gamma=cimg->green_gamma=cimg->blue_gamma=(float)sRGB_gamma;
- cimg->strip_optimized=0;
- if (header_dimensions_known(cimg))
- goto end;
-
- surf = cairo_image_surface_create_for_data(cimg->buffer, CAIRO_FORMAT_ARGB32, cimg->width, cimg->height, cimg->width * cimg->buffer_bytes_per_pixel);
- if (cairo_surface_status(surf))
- goto end_surface;
-
- cairo = cairo_create(surf);
- if (cairo_status(cairo))
- goto end_cairo;
-
- if (dim.width && dim.height)
- cairo_scale(cairo, (double)cimg->width / (double)dim.width, (double)cimg->height / (double)dim.height);
-
- h = close_stderr();
- rsvg_handle_render_cairo(deco->handle, cairo);
- cairo_surface_flush(surf);
- restore_stderr(h);
-
- end_buffer = cimg->buffer + cimg->width * cimg->height * cimg->buffer_bytes_per_pixel;
- if (htonl(0x12345678L) != 0x12345678L) {
- for (p = cimg->buffer; p < end_buffer; p += 4) {
-#ifdef t4c
- t4c t = *(t4c *)p;
- t4c r = (t << 16) | (t >> 16);
- *(t4c *)p = (t & 0xff00ff00U) | (r & 0xff00ffU);
-#else
- unsigned char c;
- c = p[0];
- p[0] = p[2];
- p[2] = c;
-#endif
- }
- } else {
- for (p = cimg->buffer; p < end_buffer; p += 4) {
-#ifdef t4c
- t4c t = *(t4c *)p;
- *(t4c *)p = (t << 8) | (t >> 24);
-#else
- unsigned char c;
- c = p[0];
- p[0] = p[1];
- p[1] = p[2];
- p[2] = p[3];
- p[3] = c;
-#endif
- }
- }
-
-end_cairo:
- cairo_destroy(cairo);
-end_surface:
- cairo_surface_destroy(surf);
-end:
- img_end(cimg);
-}
-
-void svg_destroy_decoder(struct cached_image *cimg)
-{
- struct svg_decoder *deco = (struct svg_decoder *)cimg->decoder;
- g_object_unref(deco->handle);
-#ifdef CURRENTCOLOR_HACK
- mem_free(deco->buffer);
-#endif
-}
-
-void add_svg_version(unsigned char **s, int *l)
-{
- add_to_str(s, l, cast_uchar "RSVG (");
-#ifdef LIBRSVG_MAJOR_VERSION
- add_num_to_str(s, l, LIBRSVG_MAJOR_VERSION);
-#endif
-#ifdef LIBRSVG_MINOR_VERSION
- add_chr_to_str(s, l, '.');
- add_num_to_str(s, l, LIBRSVG_MINOR_VERSION);
-#endif
-#ifdef LIBRSVG_MICRO_VERSION
- add_chr_to_str(s, l, '.');
- add_num_to_str(s, l, LIBRSVG_MICRO_VERSION);
-#endif
- add_to_str(s, l, cast_uchar ")");
-}
-
-#endif
-
-#endif
diff --git a/svgalib.c b/svgalib.c
@@ -1,2522 +0,0 @@
-/* svgalib.c
- * (c) 2000-2002 Karel 'Clock' Kulhavy
- * This file is a part of the Links program, released under GPL.
- *
- * This does graphics driver of svgalib, svgalib mouse.
- * This doesn't do svgalib keyboard.
- */
-
-#include "cfg.h"
-
-/*
-:%s/->left/->clip.x1/g
-:%s/->right/->clip.x2/g
-:%s/->top/->clip.y1/g
-:%s/->bottom/->clip.y2/g
-*/
-
-#ifdef GRDRV_SVGALIB
-
-#include "links.h"
-#include "bits.h"
-
-#include <vga.h>
-#include <vgamouse.h>
-#include "arrow.inc"
-
-static struct itrm *svgalib_kbd;
-
-extern struct graphics_driver svga_driver;
-static int mouse_x, mouse_y, mouse_buttons; /* For tracking the state of the mouse */
-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 long mouse_black, mouse_white; /* Mouse arrow pointer colors */
-static int (* mouse_getscansegment)(unsigned char *, int, int, int);
-static int (* mouse_drawscansegment)(unsigned char *, int, int, int);
-static int mouse_works = 0;
-static unsigned char *svga_driver_param; /* NULL by default */
-static int vga_mode; /* The mode that has been selected */
-static struct graphics_device *backup_virtual_device;
-static int mouse_aggregate_flag, mouse_aggregate_action;
-static int flags = 0; /* OR-ed 1: running in background
- * 2: vga_block()-ed
- */
-#ifndef __SPAD__
-static struct timer *svgalib_timer_id;
-#endif
-
-/*---------------------------LIMITATIONS---------------------------------------*/
-/* pixel_set_paged works only for <=8 bytes per pixel.
- * Doesn't work on video cards which have 1 pixel spanning more that 65536 bytes! ( :-) )
- * vga_linewidth%vga_bytes must be zero.
- * The bitmaps have all consecutive data. No vidram mallocing is performed.
- */
-
-/*------------------------STRUCTURES-------------------------------------------*/
-struct modeline{
- char *name;
- int number;
-};
-
-/*-------------- GLOBAL VARIABLES --------------------------------------------*/
-
-#define NUMBER_OF_DEVICES 10
-
-#define TEST_INACTIVITY if (dev!=current_virtual_device) return;
-
-#define TEST_INACTIVITY_0 if (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))
-
-#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();
-
-/* Actual vga mode definition */
-static int vga_linewidth; /* Prepared out from vga_getmodeinfo */
-static int xsize, ysize; /* Prepared out from vga_getmodeinfo */
-static int vga_bytes; /* Prepared out from vga_getmodeinfo */
-static int vga_colors; /* Prepared out from vga_getmodeinfo */
-static int vga_misordered; /* Prepared out from vga_getmodeinfo */
-static int vga_linear; /* 1 linear mode, 0 nonlinear mode (paged) */
-static int palette_depth; /* 6 for normal VGA, 8 for VGA which supports 8 bit DAC */
-static int accel_avail; /* Which accel fns are available */
-static int do_sync; /* Tells the "normal" memory operations (those
- * that do not use accelerator) to do
- * vga_accel(ACCEL_SYNC) before writing into the
- * memory.
- */
-static int vga_page=-1;
-static int mode_x; /* 1 if mode_X organization is set up */
-static int fb_pixelsize; /* Number of bytes per pixel in bitmap */
-static unsigned char *my_graph_mem;
-static unsigned char *scroll_buffer = NULL; /* For paged scrolling only */
-static struct modeline modes[]={
-#ifdef G320x200x16
- {"320x200x16", G320x200x16 },
-#endif
-#ifdef G320x200x256
- {"320x200x256", G320x200x256 },
-#endif
-#ifdef G320x200x32K
- {"320x200x32K", G320x200x32K },
-#endif
-#ifdef G320x200x64K
- {"320x200x64K", G320x200x64K },
-#endif
-#ifdef G320x200x16M
- {"320x200x16M", G320x200x16M },
-#endif
-#ifdef G320x200x16M32
- {"320x200x16M32", G320x200x16M32 },
-#endif
-
-#ifdef G320x240x256
- {"320x240x256", G320x240x256 },
-#endif
-#ifdef G320x240x32K
- {"320x240x32K", G320x240x32K },
-#endif
-#ifdef G320x240x64K
- {"320x240x64K", G320x240x64K },
-#endif
-#ifdef G320x240x16M
- {"320x240x16M", G320x240x16M },
-#endif
-#ifdef G320x240x16M32
- {"320x240x16M32", G320x240x16M32 },
-#endif
-
-#ifdef G320x400x256
- {"320x400x256", G320x400x256 },
-#endif
-#ifdef G320x400x32K
- {"320x400x32K", G320x400x32K },
-#endif
-#ifdef G320x400x64K
- {"320x400x64K", G320x400x64K },
-#endif
-#ifdef G320x400x16M
- {"320x400x16M", G320x400x16M },
-#endif
-#ifdef G320x400x16M32
- {"320x400x16M32", G320x400x16M32 },
-#endif
-
-#ifdef G320x480x256
- {"320x480x256", G320x480x256 },
-#endif
-#ifdef G320x480x32K
- {"320x480x32K", G320x480x32K },
-#endif
-#ifdef G320x480x64K
- {"320x480x64K", G320x480x64K },
-#endif
-#ifdef G320x480x16M
- {"320x480x16M", G320x480x16M },
-#endif
-#ifdef G320x480x16M32
- {"320x480x16M32", G320x480x16M32 },
-#endif
-
-#ifdef G360x480x256
- {"360x480x256", G360x480x256 },
-#endif
-
-#ifdef G400x300x256
- {"400x300x256", G400x300x256 },
-#endif
-#ifdef G400x300x32K
- {"400x300x32K", G400x300x32K },
-#endif
-#ifdef G400x300x64K
- {"400x300x64K", G400x300x64K },
-#endif
-#ifdef G400x300x16M
- {"400x300x16M", G400x300x16M },
-#endif
-#ifdef G400x300x16M32
- {"400x300x16M32", G400x300x16M32 },
-#endif
-
-#ifdef G400x600x256
- {"400x600x256", G400x600x256 },
-#endif
-#ifdef G400x600x32K
- {"400x600x32K", G400x600x32K },
-#endif
-#ifdef G400x600x64K
- {"400x600x64K", G400x600x64K },
-#endif
-#ifdef G400x600x16M
- {"400x600x16M", G400x600x16M },
-#endif
-#ifdef G400x600x16M32
- {"400x600x16M32", G400x600x16M32 },
-#endif
-
-#ifdef G512x384x256
- {"512x384x256", G512x384x256 },
-#endif
-#ifdef G512x384x32K
- {"512x384x32K", G512x384x32K },
-#endif
-#ifdef G512x384x64K
- {"512x384x64K", G512x384x64K },
-#endif
-#ifdef G512x384x16M
- {"512x384x16M", G512x384x16M },
-#endif
-#ifdef G512x384x16M32
- {"512x384x16M32", G512x384x16M32 },
-#endif
-
-#ifdef G512x480x256
- {"512x480x256", G512x480x256 },
-#endif
-#ifdef G512x480x32K
- {"512x480x32K", G512x480x32K },
-#endif
-#ifdef G512x480x64K
- {"512x480x64K", G512x480x64K },
-#endif
-#ifdef G512x480x16M
- {"512x480x16M", G512x480x16M },
-#endif
-#ifdef G512x480x16M32
- {"512x480x16M32", G512x480x16M32 },
-#endif
-
-#ifdef G640x200x16
- {"640x200x16", G640x200x16 },
-#endif
-#ifdef G640x350x16
- {"640x350x16", G640x350x16 },
-#endif
-
-#ifdef G640x400x256
- {"640x400x256", G640x400x256 },
-#endif
-#ifdef G640x400x32K
- {"640x400x32K", G640x400x32K },
-#endif
-#ifdef G640x400x64K
- {"640x400x64K", G640x400x64K },
-#endif
-#ifdef G640x400x16M
- {"640x400x16M", G640x400x16M },
-#endif
-#ifdef G640x400x16M32
- {"640x400x16M32", G640x400x16M32 },
-#endif
-
-#ifdef G640x480x16
- {"640x480x16", G640x480x16 },
-#endif
-#ifdef G640x480x256
- {"640x480x256", G640x480x256 },
-#endif
-#ifdef G640x480x32K
- {"640x480x32K", G640x480x32K },
-#endif
-#ifdef G640x480x64K
- {"640x480x64K", G640x480x64K },
-#endif
-#ifdef G640x480x16M
- {"640x480x16M", G640x480x16M },
-#endif
-#ifdef G640x480x16M32
- {"640x480x16M32", G640x480x16M32 },
-#endif
-
-#ifdef G720x540x256
- {"720x540x256", G720x540x256 },
-#endif
-#ifdef G720x540x32K
- {"720x540x32K", G720x540x32K },
-#endif
-#ifdef G720x540x64K
- {"720x540x64K", G720x540x64K },
-#endif
-#ifdef G720x540x16M
- {"720x540x16M", G720x540x16M },
-#endif
-#ifdef G720x540x16M32
- {"720x540x16M32", G720x540x16M32 },
-#endif
-
-#ifdef G800x600x16
- {"800x600x16", G800x600x16 },
-#endif
-#ifdef G800x600x256
- {"800x600x256", G800x600x256 },
-#endif
-#ifdef G800x600x32K
- {"800x600x32K", G800x600x32K },
-#endif
-#ifdef G800x600x64K
- {"800x600x64K", G800x600x64K },
-#endif
-#ifdef G800x600x16M
- {"800x600x16M", G800x600x16M },
-#endif
-#ifdef G800x600x16M32
- {"800x600x16M32", G800x600x16M32 },
-#endif
-
-#ifdef G848x480x256
- {"848x480x256", G848x480x256 },
-#endif
-#ifdef G848x480x32K
- {"848x480x32K", G848x480x32K },
-#endif
-#ifdef G848x480x64K
- {"848x480x64K", G848x480x64K },
-#endif
-#ifdef G848x480x16M
- {"848x480x16M", G848x480x16M },
-#endif
-#ifdef G848x480x16M32
- {"848x480x16M32", G848x480x16M32 },
-#endif
-
-#ifdef G960x720x256
- {"960x720x256", G960x720x256 },
-#endif
-#ifdef G960x720x32K
- {"960x720x32K", G960x720x32K },
-#endif
-#ifdef G960x720x64K
- {"960x720x64K", G960x720x64K },
-#endif
-#ifdef G960x720x16M
- {"960x720x16M", G960x720x16M },
-#endif
-#ifdef G960x720x16M32
- {"960x720x16M32", G960x720x16M32 },
-#endif
-
-#ifdef G1024x768x16
- {"1024x768x16", G1024x768x16 },
-#endif
-#ifdef G1024x768x256
- {"1024x768x256", G1024x768x256 },
-#endif
-#ifdef G1024x768x32K
- {"1024x768x32K", G1024x768x32K },
-#endif
-#ifdef G1024x768x64K
- {"1024x768x64K", G1024x768x64K },
-#endif
-#ifdef G1024x768x16M
- {"1024x768x16M", G1024x768x16M },
-#endif
-#ifdef G1024x768x16M32
- {"1024x768x16M32", G1024x768x16M32 },
-#endif
-
-#ifdef G1072x600x256
- {"1072x600x256", G1072x600x256 },
-#endif
-#ifdef G1072x600x32K
- {"1072x600x32K", G1072x600x32K },
-#endif
-#ifdef G1072x600x64K
- {"1072x600x64K", G1072x600x64K },
-#endif
-#ifdef G1072x600x16M
- {"1072x600x16M", G1072x600x16M },
-#endif
-#ifdef G1072x600x16M32
- {"1072x600x16M32", G1072x600x16M32 },
-#endif
-
-#ifdef G1152x864x16
- {"1152x864x16", G1152x864x16 },
-#endif
-#ifdef G1152x864x256
- {"1152x864x256", G1152x864x256 },
-#endif
-#ifdef G1152x864x32K
- {"1152x864x32K", G1152x864x32K },
-#endif
-#ifdef G1152x864x64K
- {"1152x864x64K", G1152x864x64K },
-#endif
-#ifdef G1152x864x16M
- {"1152x864x16M", G1152x864x16M },
-#endif
-#ifdef G1152x864x16M32
- {"1152x864x16M32", G1152x864x16M32 },
-#endif
-
-#ifdef G1280x720x256
- {"1280x720x256", G1280x720x256 },
-#endif
-#ifdef G1280x720x32K
- {"1280x720x32K", G1280x720x32K },
-#endif
-#ifdef G1280x720x64K
- {"1280x720x64K", G1280x720x64K },
-#endif
-#ifdef G1280x720x16M
- {"1280x720x16M", G1280x720x16M },
-#endif
-#ifdef G1280x720x16M32
- {"1280x720x16M32", G1280x720x16M32 },
-#endif
-
-#ifdef G1280x1024x16
- {"1280x1024x16", G1280x1024x16 },
-#endif
-#ifdef G1280x1024x256
- {"1280x1024x256", G1280x1024x256 },
-#endif
-#ifdef G1280x1024x32K
- {"1280x1024x32K", G1280x1024x32K },
-#endif
-#ifdef G1280x1024x64K
- {"1280x1024x64K", G1280x1024x64K },
-#endif
-#ifdef G1280x1024x16M
- {"1280x1024x16M", G1280x1024x16M },
-#endif
-#ifdef G1280x1024x16M32
- {"1280x1024x16M32", G1280x1024x16M32 },
-#endif
-
-#ifdef G1360x768x256
- {"1360x768x256", G1360x768x256 },
-#endif
-#ifdef G1360x768x32K
- {"1360x768x32K", G1360x768x32K },
-#endif
-#ifdef G1360x768x64K
- {"1360x768x64K", G1360x768x64K },
-#endif
-#ifdef G1360x768x16M
- {"1360x768x16M", G1360x768x16M },
-#endif
-#ifdef G1360x768x16M32
- {"1360x768x16M32", G1360x768x16M32 },
-#endif
-
-#ifdef G1600x1200x16
- {"1600x1200x16", G1600x1200x16 },
-#endif
-#ifdef G1600x1200x256
- {"1600x1200x256", G1600x1200x256 },
-#endif
-#ifdef G1600x1200x32K
- {"1600x1200x32K", G1600x1200x32K },
-#endif
-#ifdef G1600x1200x64K
- {"1600x1200x64K", G1600x1200x64K },
-#endif
-#ifdef G1600x1200x16M
- {"1600x1200x16M", G1600x1200x16M },
-#endif
-#ifdef G1600x1200x16M32
- {"1600x1200x16M32", G1600x1200x16M32 },
-#endif
-
-#ifdef G1800x1012x256
- {"1800x1012x256", G1800x1012x256 },
-#endif
-#ifdef G1800x1012x32K
- {"1800x1012x32K", G1800x1012x32K },
-#endif
-#ifdef G1800x1012x64K
- {"1800x1012x64K", G1800x1012x64K },
-#endif
-#ifdef G1800x1012x16M
- {"1800x1012x16M", G1800x1012x16M },
-#endif
-#ifdef G1800x1012x16M32
- {"1800x1012x16M32", G1800x1012x16M32 },
-#endif
-
-#ifdef G1920x1080x256
- {"1920x1080x256", G1920x1080x256 },
-#endif
-#ifdef G1920x1080x32K
- {"1920x1080x32K", G1920x1080x32K },
-#endif
-#ifdef G1920x1080x64K
- {"1920x1080x64K", G1920x1080x64K },
-#endif
-#ifdef G1920x1080x16M
- {"1920x1080x16M", G1920x1080x16M },
-#endif
-#ifdef G1920x1080x16M32
- {"1920x1080x16M32", G1920x1080x16M32 },
-#endif
-
-#ifdef G1920x1440x256
- {"1920x1440x256", G1920x1440x256 },
-#endif
-#ifdef G1920x1440x32K
- {"1920x1440x32K", G1920x1440x32K },
-#endif
-#ifdef G1920x1440x64K
- {"1920x1440x64K", G1920x1440x64K },
-#endif
-#ifdef G1920x1440x16M
- {"1920x1440x16M", G1920x1440x16M },
-#endif
-#ifdef G1920x1440x16M32
- {"1920x1440x16M32", G1920x1440x16M32 },
-#endif
-
-#ifdef G2048x1152x256
- {"2048x1152x256", G2048x1152x256 },
-#endif
-#ifdef G2048x1152x32K
- {"2048x1152x32K", G2048x1152x32K },
-#endif
-#ifdef G2048x1152x64K
- {"2048x1152x64K", G2048x1152x64K },
-#endif
-#ifdef G2048x1152x16M
- {"2048x1152x16M", G2048x1152x16M },
-#endif
-#ifdef G2048x1152x16M32
- {"2048x1152x16M32", G2048x1152x16M32 },
-#endif
-
-#ifdef G2048x1536x256
- {"2048x1536x256", G2048x1536x256 },
-#endif
-#ifdef G2048x1536x32K
- {"2048x1536x32K", G2048x1536x32K },
-#endif
-#ifdef G2048x1536x64K
- {"2048x1536x64K", G2048x1536x64K },
-#endif
-#ifdef G2048x1536x16M
- {"2048x1536x16M", G2048x1536x16M },
-#endif
-#ifdef G2048x1536x16M32
- {"2048x1536x16M32", G2048x1536x16M32 },
-#endif
-
-};
-
-/*--------------------------- ROUTINES ---------------------------------------*/
-
-/* Generates these palettes:
- * 7 6 5 4 3 2 1 0
- * +-----+-----+---+
- * | R | G | B |
- * +-----+-----+---+
- *
- *
- * 3 2 1 0
- * +-+---+-+
- * |R| G |B|
- * +-+---+-+
- */
-
-static void show_mouse(void);
-static void hide_mouse(void);
-static void redraw_mouse(void);
-
-/* We must perform a quirkafleg
- * 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 irgb *palette)
-{
- int a;
-
- if (vga_colors==16){
- if (palette_depth==6){
- for (a=0;a<16;a++,palette++)
- {
- palette->r=(a&8)?63:0;
- palette->g=((a>>1)&3)*21;
- palette->b=(a&1)?63:0;
- }
- }else{
- /* palette_depth==8 */
- for (a=0;a<16;a++,palette++)
- {
- palette->r=(a&8)?255:0;
- palette->g=((a>>1)&3)*85;
- palette->b=(a&1)?255:0;
- }
- }
- }else{
- /* vga_colors==256 */
- if (palette_depth==6){
- for (a=0;a<256;a++,palette++){
- palette->r=((a>>5)&7)*9;
- palette->g=((a>>2)&7)*9;
- palette->b=(a&3)*21;
- }
- }else{
- /* palette_depth==8 */
- for (a=0;a<256;a++,palette++){
- palette->r=(((a>>5)&7)*255+3)/7;
- palette->g=(((a>>2)&7)*255+3)/7;
- palette->b=(a&3)*85;
- }
- }
- }
-}
-
-static void set_palette(struct irgb *palette)
-{
- int r,g,b,c;
-
- for (c=0;c<vga_colors;c++){
- r=palette[c].r;
- g=palette[c].g;
- b=palette[c].b;
- vga_setpalette(c,r,g,b);
- }
-}
-
-static void svga_shutdown_driver(void)
-{
- if (scroll_buffer) mem_free(scroll_buffer);
- if (mouse_works){
- mem_free(mouse_buffer);
- mem_free(background_buffer);
- mem_free(new_background_buffer);
- svga_driver.shutdown_device(mouse_graphics_device);
- mouse_close();
- mouse_works=0; /* To keep vga_select disabled */
- }
- shutdown_virtual_devices();
- vga_unlockvc();
-#ifndef __SPAD__
- kill_timer(svgalib_timer_id);
-#endif
- vga_setmode_retry:
- if (vga_setmode(TEXT) < 0) {
- if (out_of_memory(0, NULL, 0))
- goto vga_setmode_retry;
- fatal_exit("ERROR: vga_setmode failed");
- }
- svgalib_free_trm(svgalib_kbd);
- if (svga_driver_param)mem_free(svga_driver_param);
- install_signal_handler(SIGINT, NULL, NULL, 0);
-}
-
-static void svga_register_bitmap(struct bitmap *bmp)
-{
-}
-
-static void svga_unregister_bitmap(struct bitmap *bmp)
-{
- mem_free(bmp->data);
-}
-
-#define SYNC if (do_sync) vga_accel(ACCEL_SYNC);
-
-/* 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 xs=hndl->x,ys=hndl->y;\
- unsigned char *data=hndl->data;\
- int mouse_hidden;\
-\
- 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\
- */\
- TEST_MOUSE (x,x+xs,y,y+ys)
-
-static inline void draw_bitmap_accel(struct graphics_device *dev,
- struct bitmap* hndl, int x, int y)
-{
- CLIP_PREFACE
-
- if (xs*fb_pixelsize==hndl->skip) vga_accel(ACCEL_PUTIMAGE,x,y,xs,ys,data);
- else for(;ys;ys--){
- vga_accel(ACCEL_PUTIMAGE,x,y,xs,1,data);
- data+=hndl->skip;
- y++;
- }
- END_MOUSE
-}
-
-static inline void my_setpage(int page)
-{
- if (vga_page!=page){
- vga_page=page;
- vga_setpage(page);
- }
-}
-
-static inline void paged_memcpy(int lina, unsigned char *src, int len)
-{
- int page=lina>>16;
- int paga=lina&0xffff;
- int remains;
-
- my_setpage(page);
- remains=65536-paga;
- again:
- if (remains>=len){
- memcpy(my_graph_mem+paga,src,len);
- vga_page=page;
- return;
- }else{
- memcpy(my_graph_mem+paga,src,remains);
- paga=0;
- src+=remains;
- len-=remains;
- remains=65536;
- vga_setpage(++page);
- goto again;
- }
-}
-
-
-static inline void draw_bitmap_drawscansegment(struct graphics_device *dev, struct bitmap* hndl, int x, int y)
-{
- int ys0;
-
- CLIP_PREFACE
- SYNC
- for (ys0=ys;ys0;ys0--){
- vga_drawscansegment(data,x,y,xs);
- y++;
- data+=hndl->skip;
- }
- END_MOUSE
-}
-
-static inline void draw_bitmap_paged(struct graphics_device *dev, struct bitmap* hndl, int x, int y)
-{
- int scr_start;
-
- CLIP_PREFACE
- scr_start=y*vga_linewidth+x*vga_bytes;
- SYNC
- for(;ys;ys--){
- paged_memcpy(scr_start,data,xs*vga_bytes);
- data+=hndl->skip;
- scr_start+=vga_linewidth;
- }
- END_MOUSE
-}
-
-static inline void draw_bitmap_linear(struct graphics_device *dev,struct bitmap* hndl, int x, int y)
-{
- unsigned char *scr_start;
-
- CLIP_PREFACE
- SYNC
- scr_start=my_graph_mem+y*vga_linewidth+x*vga_bytes;
- for(;ys;ys--){
- memcpy(scr_start,data,xs*vga_bytes);
- data+=hndl->skip;
- scr_start+=vga_linewidth;
- }
- END_MOUSE
-}
-
-/* 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 svga_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;\
- TEST_MOUSE(left,right,top,bottom)
-
-
-static void fill_area_accel_box(struct graphics_device *dev, int left, int top, int right, int bottom, long color)
-{
- FILL_CLIP_PREFACE
-
- vga_accel(ACCEL_SETFGCOLOR,color);
- vga_accel(ACCEL_FILLBOX,left,top,right-left,bottom-top);
- END_MOUSE
-}
-
-static void fill_area_accel_lines(struct graphics_device *dev, int left, int top, int right, int bottom, long color)
-{
- int y;
-
- FILL_CLIP_PREFACE
- vga_accel(ACCEL_SETFGCOLOR,color);
- for (y=top;y<bottom;y++) vga_accel(ACCEL_DRAWLINE,left,y,right-1,y);
- END_MOUSE
-}
-
-#include "fbcommon.inc"
-
-static void fill_area_linear(struct graphics_device *dev, int left, int top, int right, int bottom, long color)
-{
- unsigned char *dest;
- int y;
-
- FILL_CLIP_PREFACE
- SYNC
- dest=my_graph_mem+top*vga_linewidth+left*vga_bytes;
- for (y=bottom-top;y;y--){
- pixel_set(dest,(right-left)*vga_bytes,&color);
- dest+=vga_linewidth;
- }
- END_MOUSE
-}
-
-/* Params are exactly the same as in pixel_set except lina, which is offset from
- * my_graph_mem in bytes. Works for every vga_bytes. len is in bytes. len must
- * be a whole number of pixels.
- */
-static void pixel_set_paged(int lina, int len, void * color)
-{
- int page=lina>>16; /* Page number */
- int paga=lina&0xffff; /* 16-bit address within a page */
- int remains=65536-paga; /* How many bytes remain within the page*/
- int offset=0; /* Offset inside the pixel */
- unsigned char color0[15];
-
- memcpy(color0,color,vga_bytes);
- memcpy(color0+vga_bytes,color,vga_bytes-1);
-
- my_setpage(page);
- again:
- if (remains>=len){
- int done=len-len%vga_bytes;
- pixel_set(my_graph_mem+paga,done,color0+offset);
- paga+=done;
- if (done<len)
- memcpy(my_graph_mem+paga,color0+offset,len-done);
- vga_page=page;
- return;
- }else{
- int done=remains-remains%vga_bytes;
- pixel_set(my_graph_mem+paga,done,color0+offset);
- paga+=done;
- if (done<remains)
- memcpy(my_graph_mem+paga,color0+offset,remains-done);
- offset+=(remains-done);
- if (offset>=vga_bytes) offset-=vga_bytes;
- len-=remains;
- remains=65536;
- vga_setpage(++page);
- paga=0;
- goto again;
- }
-}
-
-static void fill_area_paged(struct graphics_device *dev, int left, int top, int right, int bottom, long color)
-{
- int dest;
- int y;
- int len;
- FILL_CLIP_PREFACE
- SYNC
- len=(right-left)*vga_bytes;
- dest=top*vga_linewidth+left*vga_bytes;
- for (y=bottom-top;y;y--){
- pixel_set_paged(dest,len,&color);
- dest+=vga_linewidth;
- }
- END_MOUSE
-}
-
-#define HLINE_CLIP_PREFACE \
- int mouse_hidden;\
- TEST_INACTIVITY\
- if (left>=right) return;\
- 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;\
- TEST_MOUSE (left,right,y,y+1)
-
-#define VLINE_CLIP_PREFACE \
- int mouse_hidden;\
- TEST_INACTIVITY\
- if (top>=bottom) return;\
- 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;\
- TEST_MOUSE(x,x+1,top,bottom)
-
-static void draw_hline_accel_line(struct graphics_device *dev, int left, int y, int right, long color)
-{
- HLINE_CLIP_PREFACE
-
- vga_accel(ACCEL_SETFGCOLOR,color);
- vga_accel(ACCEL_DRAWLINE,left,y,right-1,y);
- END_MOUSE
-}
-
-static void draw_hline_accel_box(struct graphics_device *dev, int left, int y, int right, long color)
-{
- HLINE_CLIP_PREFACE
-
- vga_accel(ACCEL_SETFGCOLOR,color);
- vga_accel(ACCEL_FILLBOX,left,y,right-left,1);
- END_MOUSE
-}
-
-static void draw_vline_accel_line(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- VLINE_CLIP_PREFACE
-
- vga_accel(ACCEL_SETFGCOLOR,color);
- vga_accel(ACCEL_DRAWLINE,x,top,x,bottom-1);
- END_MOUSE
-}
-
-static void draw_vline_accel_box(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- VLINE_CLIP_PREFACE
-
- vga_accel(ACCEL_SETFGCOLOR,color);
- vga_accel(ACCEL_FILLBOX,x,top,1,bottom-top);
- END_MOUSE
-}
-
-static void draw_hline_linear(struct graphics_device *dev, int left, int y, int right, long color)
-{
- unsigned char *dest;
- HLINE_CLIP_PREFACE
- SYNC
- dest=my_graph_mem+y*vga_linewidth+left*vga_bytes;
- pixel_set(dest,(right-left)*vga_bytes,&color);
- END_MOUSE
-}
-
-static void draw_vline_linear(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- unsigned char *dest;
- int y;
- VLINE_CLIP_PREFACE
- SYNC
- dest=my_graph_mem+top*vga_linewidth+x*vga_bytes;
- for (y=(bottom-top);y;y--){
- memcpy(dest,&color,vga_bytes);
- dest+=vga_linewidth;
- }
- END_MOUSE
-}
-
-static void draw_hline_paged(struct graphics_device *dev, int left, int y, int right, long color)
-{
- int dest;
- int len;
- HLINE_CLIP_PREFACE
- SYNC
- len=(right-left)*vga_bytes;
-
- dest=y*vga_linewidth+left*vga_bytes;
- pixel_set_paged(dest,len,&color);
- END_MOUSE
-}
-
-/* Works only for pixel length = 1 */
-static void draw_vline_paged_1(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- int dest,n, page,paga,remains;
- int byte=*(unsigned char *)&color;
- VLINE_CLIP_PREFACE;
- SYNC
- dest=top*vga_linewidth+x;
- n=bottom-top;
- page=dest>>16;
- my_setpage(page);
- again:
- paga=dest&0xffff;
- remains=(65535-paga)/vga_linewidth+1;
- if (remains>=n){
- for (;n;n--){
- my_graph_mem[paga]=byte;
- paga+=vga_linewidth;
- }
- vga_page=page;
- END_MOUSE
- return;
- }else{
- dest+=remains*vga_linewidth;
- n-=remains;
- for (;remains;remains--){
- my_graph_mem[paga]=byte;
- paga+=vga_linewidth;
- }
- vga_setpage(++page);
- goto again;
- }
-}
-
-#ifdef t2c
-/* Works only for pixel length 2 */
-static void draw_vline_paged_2(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- int dest,page,n,paga,remains;
- int word=*(t2c *)do_not_optimize_here((void *)&color);
- VLINE_CLIP_PREFACE;
- SYNC
- dest=top*vga_linewidth+(x<<1);
- n=bottom-top;
- page=dest>>16;
- my_setpage(page);
- again:
- paga=dest&0xffff;
- remains=(65534-paga)/vga_linewidth+1;
- if (remains>=n){
- for (;n;n--){
- *(t2c *)(my_graph_mem+paga)=word;
- paga+=vga_linewidth;
- }
- vga_page=page;
- END_MOUSE
- return;
- }else{
- dest+=remains*vga_linewidth;
- n-=remains;
- for (;remains;remains--){
- *(t2c *)(my_graph_mem+paga)=word;
- paga+=vga_linewidth;
- }
- vga_setpage(++page);
- goto again;
- }
-}
-#endif /* #ifdef t2c */
-
-#ifdef t4c
-/* Works only for pixel length 4 */
-static void draw_vline_paged_4(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- unsigned long dest,page,paga,remains,n;
- t4c val=*(t4c *)do_not_optimize_here((void *)&color);
-
- VLINE_CLIP_PREFACE;
- SYNC
- dest=top*(unsigned long)vga_linewidth+(x<<2);
- n=bottom-top;
- page=dest>>16;
- my_setpage(page);
- again:
- paga=dest&0xffffUL;
- remains=(65532-paga)/vga_linewidth+1;
- if (remains>=n){
- for (;n;n--){
- *(t4c *)(my_graph_mem+paga)=val;
- paga+=vga_linewidth;
- }
- vga_page=page;
- END_MOUSE
- return;
- }else{
- dest+=remains*vga_linewidth;
- n-=remains;
- for (;remains;remains--){
- *(t4c *)(my_graph_mem+paga)=color;
- paga+=vga_linewidth;
- }
- vga_setpage(++page);
- goto again;
- }
-}
-#endif /*t4c*/
-
-/* Works only for pixel lengths power of two */
-static void draw_vline_paged_aligned(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- int dest,page,paga,remains,n;
- VLINE_CLIP_PREFACE;
- SYNC
- dest=top*vga_linewidth+x*vga_bytes;
- n=bottom-top;
- page=dest>>16;
- my_setpage(page);
- again:
- paga=dest&0xffff;
- remains=(65536-paga-vga_bytes)/vga_linewidth+1;
- if (remains>=n){
- for (;n;n--){
- memcpy(my_graph_mem+paga,&color,vga_bytes);
- paga+=vga_linewidth;
- }
- vga_page=page;
- END_MOUSE
- return;
- }else{
- dest+=remains*vga_linewidth;
- n-=remains;
- for (;remains;remains--){
- memcpy(my_graph_mem+paga,&color,vga_bytes);
- paga+=vga_linewidth;
- }
- vga_setpage(++page);
- goto again;
- }
-}
-
-/* Works for any pixel length */
-static void draw_vline_paged(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- int lina,page,paga,remains,n;
- /* lina: linear address withing the screen
- * page: page number
- * paga: 16-bit address within the page
- * remains: how many bytes remain in the current page
- * n: how many pixels remain to be drawn
- */
- VLINE_CLIP_PREFACE;
- SYNC
- lina=top*vga_linewidth+x*vga_bytes;
- n=bottom-top;
- page=lina>>16;
- my_setpage(page);
- again:
- /* Invariant here: n>=1
- * lina points to a begin of pixel
- * page is set to page
- */
- paga=lina&0xffff;
- remains=65536-paga;
- if (remains<vga_bytes){
- memcpy(my_graph_mem+paga,&color,remains);
- vga_setpage(++page);
- memcpy(my_graph_mem,(unsigned char *)&color+remains,vga_bytes-remains);
- lina+=vga_linewidth;
- n--;
- if (!n) goto end;
- goto again;
- }
- remains=(remains-vga_bytes)/vga_linewidth+1;
- if (remains>=n){
- for (;n;n--){
- memcpy(my_graph_mem+paga,&color,vga_bytes);
- paga+=vga_linewidth;
- }
-end:
- vga_page=page;
- END_MOUSE
- return;
- }else{
- lina+=remains*vga_linewidth;
- n-=remains;
- for (;remains;remains--){
- memcpy(my_graph_mem+paga,&color,vga_bytes);
- paga+=vga_linewidth;
- }
- if (paga>=65536)vga_setpage(++page);
- goto again;
- }
-}
-
-#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;\
- TEST_MOUSE (dev->clip.x1,dev->clip.x2,dev->clip.y1,dev->clip.y2)
-
-
-/* When sc is <0, moves the data left. Scrolls the whole clip window */
-static int hscroll_accel(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- HSCROLL_CLIP_PREFACE
-
- if (sc>0){
- /* Move data to the right */
- vga_accel(ACCEL_SCREENCOPY,dev->clip.x1,dev->clip.y1,dev->clip.x1+sc,dev->clip.y1
- ,dev->clip.x2-dev->clip.x1-sc,dev->clip.y2-dev->clip.y1);
- }else{
- /* Move data to the left */
- vga_accel(ACCEL_SCREENCOPY,dev->clip.x1-sc,dev->clip.y1,dev->clip.x1,dev->clip.y1
- ,dev->clip.x2-dev->clip.x1+sc,dev->clip.y2-dev->clip.y1);
- }
- END_MOUSE
- return 1;
-}
-
-#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;\
- TEST_MOUSE (dev->clip.x1, dev->clip.x2, dev->clip.y1, dev->clip.y2)
-
-/* Positive sc means data move down */
-static int vscroll_accel(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- VSCROLL_CLIP_PREFACE
-
- if (sc>0){
- /* Move down */
- vga_accel(ACCEL_SCREENCOPY,dev->clip.x1,dev->clip.y1,dev->clip.x1,dev->clip.y1+sc
- ,dev->clip.x2-dev->clip.x1,dev->clip.y2-dev->clip.y1-sc);
- }else{
- /* Move up */
- vga_accel(ACCEL_SCREENCOPY,dev->clip.x1,dev->clip.y1-sc,dev->clip.x1,dev->clip.y1
- ,dev->clip.x2-dev->clip.x1,dev->clip.y2-dev->clip.y1+sc);
- }
- END_MOUSE
- return 1;
-}
-
-static int hscroll_scansegment(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- int y;
- int len;
- HSCROLL_CLIP_PREFACE
- SYNC
- if (sc>0){
- /* Right */
- len=dev->clip.x2-dev->clip.x1-sc;
- for (y=dev->clip.y1;y<dev->clip.y2;y++){
- vga_getscansegment(scroll_buffer,dev->clip.x1,y,len);
- vga_drawscansegment(scroll_buffer,dev->clip.x1+sc,y,len);
- }
- }else{
- /* Left */
- len=dev->clip.x2-dev->clip.x1+sc;
- for (y=dev->clip.y1;y<dev->clip.y2;y++){
- vga_getscansegment(scroll_buffer,dev->clip.x1-sc,y,len);
- vga_drawscansegment(scroll_buffer,dev->clip.x1,y,len);
- }
- }
- END_MOUSE
- return 1;
-}
-
-static int hscroll_linear(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- unsigned char *dest, *src;
- int y;
- int len;
- HSCROLL_CLIP_PREFACE
- SYNC
- if (sc>0){
- len=(dev->clip.x2-dev->clip.x1-sc)*vga_bytes;
- src=my_graph_mem+vga_linewidth*dev->clip.y1+dev->clip.x1*vga_bytes;
- dest=src+sc*vga_bytes;
- for (y=dev->clip.y2-dev->clip.y1;y;y--){
- memmove(dest,src,len);
- dest+=vga_linewidth;
- src+=vga_linewidth;
- }
- }else{
- len=(dev->clip.x2-dev->clip.x1+sc)*vga_bytes;
- dest=my_graph_mem+vga_linewidth*dev->clip.y1+dev->clip.x1*vga_bytes;
- src=dest-sc*vga_bytes;
- for (y=dev->clip.y2-dev->clip.y1;y;y--){
- memmove(dest,src,len);
- dest+=vga_linewidth;
- src+=vga_linewidth;
- }
- }
- END_MOUSE
- return 1;
-}
-
-static int vscroll_scansegment(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- int y;
- int len;
- VSCROLL_CLIP_PREFACE
- SYNC
- len=dev->clip.x2-dev->clip.x1;
- if (sc>0){
- /* Down */
- for (y=dev->clip.y2-1;y>=dev->clip.y1+sc;y--){
- vga_getscansegment(scroll_buffer, dev->clip.x1,y-sc,len);
- vga_drawscansegment(scroll_buffer,dev->clip.x1,y,len);
- }
- }else{
- /* Up */
- for (y=dev->clip.y1-sc;y<dev->clip.y2;y++){
- vga_getscansegment(scroll_buffer,dev->clip.x1,y,len);
- vga_drawscansegment(scroll_buffer, dev->clip.x1,y+sc,len);
- }
- }
- END_MOUSE
- return 1;
-}
-
-static int vscroll_linear(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- unsigned char *dest, *src;
- int y;
- int len;
- VSCROLL_CLIP_PREFACE
- SYNC
- len=(dev->clip.x2-dev->clip.x1)*vga_bytes;
- if (sc>0){
- /* Down */
- dest=my_graph_mem+(dev->clip.y2-1)*vga_linewidth+dev->clip.x1*vga_bytes;
- src=dest-vga_linewidth*sc;
- for (y=dev->clip.y2-dev->clip.y1-sc;y;y--){
- memcpy(dest,src,len);
- dest-=vga_linewidth;
- src-=vga_linewidth;
- }
- }else{
- /* Up */
- dest=my_graph_mem+dev->clip.y1*vga_linewidth+dev->clip.x1*vga_bytes;
- src=dest-vga_linewidth*sc;
- for (y=dev->clip.y2-dev->clip.y1+sc;y;y--){
- memcpy(dest,src,len);
- dest+=vga_linewidth;
- src+=vga_linewidth;
- }
- }
- END_MOUSE
- return 1;
-}
-
-static inline void get_row(unsigned char *bptr, int lina, int len)
-{
- int page=lina>>16;
- int paga=lina&0xffff;
- int remains;
-
- my_setpage(page);
- remains=65536-paga;
- again:
- if (remains>=len){
- memcpy(bptr,my_graph_mem+paga,len);
- vga_page=page;
- return;
- }else{
- memcpy(bptr,my_graph_mem+paga,remains);
- paga=0;
- bptr+=remains;
- len-=remains;
- remains=65536;
- vga_setpage(++page);
- goto again;
- }
-}
-
-static int vscroll_paged(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- int dest,src;
- int y;
- int len;
- VSCROLL_CLIP_PREFACE
- SYNC
- len=(dev->clip.x2-dev->clip.x1)*vga_bytes;
- if (sc>0){
- /* Down */
- dest=(dev->clip.y2-1)*vga_linewidth+dev->clip.x1*vga_bytes;
- src=dest-vga_linewidth*sc;
- for (y=dev->clip.y2-dev->clip.y1-sc;y;y--){
- get_row(scroll_buffer, src,len);
- paged_memcpy(dest,scroll_buffer,len);
- dest-=vga_linewidth;
- src-=vga_linewidth;
- }
- }else{
- /* Up */
- dest=dev->clip.y1*vga_linewidth+dev->clip.x1*vga_bytes;
- src=dest-vga_linewidth*sc;
- for (y=dev->clip.y2-dev->clip.y1+sc;y;y--){
- get_row(scroll_buffer, src,len);
- paged_memcpy(dest,scroll_buffer,len);
- dest+=vga_linewidth;
- src+=vga_linewidth;
- }
- }
- END_MOUSE
- return 1;
-}
-
-static int hscroll_paged(struct graphics_device *dev, struct rect_set **ignore, int sc)
-{
- int dest,src;
- int y;
- int len;
-
- HSCROLL_CLIP_PREFACE
- SYNC
- if (sc>0){
- len=(dev->clip.x2-dev->clip.x1-sc)*vga_bytes;
- src=vga_linewidth*dev->clip.y1+dev->clip.x1*vga_bytes;
- dest=src+sc*vga_bytes;
- for (y=dev->clip.y2-dev->clip.y1;y;y--){
- get_row(scroll_buffer, src,len);
- paged_memcpy(dest,scroll_buffer,len);
- dest+=vga_linewidth;
- src+=vga_linewidth;
- }
- }else{
- len=(dev->clip.x2-dev->clip.x1+sc)*vga_bytes;
- dest=vga_linewidth*dev->clip.y1+dev->clip.x1*vga_bytes;
- src=dest-sc*vga_bytes;
- for (y=dev->clip.y2-dev->clip.y1;y;y--){
- get_row(scroll_buffer, src,len);
- paged_memcpy(dest,scroll_buffer,len);
- dest+=vga_linewidth;
- src+=vga_linewidth;
- }
- }
- END_MOUSE
- return 1;
-}
-
-/* For modes where video memory is not directly accessible through svgalib */
-static inline void fill_area_drawscansegment(struct graphics_device *dev, int left, int top, int right, int bottom, long color)
-{
- int xs;
- int col=*(unsigned char *)&color;
-
- FILL_CLIP_PREFACE
- SYNC
- xs=right-left;
- memset(scroll_buffer,col,xs);
- for (;top<bottom;top++){
- vga_drawscansegment(scroll_buffer,left,top,xs);
- }
- END_MOUSE
-}
-
-/* Emulates horizontal line by calling fill_area */
-static void draw_hline_fill_area(struct graphics_device *dev, int left, int y, int right, long color)
-{
- svga_driver.fill_area(dev,left,y,right,y+1,color);
-}
-
-
-/* Emulates vline by fill_area */
-static void draw_vline_fill_area(struct graphics_device *dev, int x, int top, int bottom, long color)
-{
- svga_driver.fill_area(dev,x,top,x+1,bottom, color);
-}
-
-/* This does no clipping and is used only by the mouse code
- * length is in bytes, not in pixels
- */
-static int drawscansegment_linear(unsigned char *colors, int x, int y, int length)
-{
- unsigned char *ptr=my_graph_mem+vga_linewidth*y+vga_bytes*x;
-
- memcpy (ptr,colors,length);
- return 0;
-}
-
-/* This does no clipping and is used only by the mouse code
- * length is in bytes, not in pixels
- */
-static int getscansegment_linear(unsigned char *colors, int x, int y, int length)
-{
- unsigned char *ptr=my_graph_mem+vga_linewidth*y+vga_bytes*x;
-
- memcpy (colors, ptr, length);
- return 0;
-}
-
-/* This does no clipping and is used only by the mouse code
- * length is in bytes, not in pixels
- */
-static int drawscansegment_paged(unsigned char *colors, int x, int y, int length)
-{
- int lina=vga_linewidth*y+vga_bytes*x;
-
- paged_memcpy(lina, colors, length);
- return 0;
-}
-
-/* This does no clipping and is used only by the mouse code
- * length is in the bytes, not in pixels
- */
-static int getscansegment_paged(unsigned char *colors, int x, int y, int length)
-{
- int lina=vga_linewidth*y+vga_bytes*x;
-
- get_row(colors, lina, length);
- return 0;
-}
-
-static void alloc_scroll_buffer(void)
-{
- if (!scroll_buffer) {
- if ((unsigned)xsize > (unsigned)MAXINT / fb_pixelsize) overalloc();
- scroll_buffer=mem_alloc(xsize*fb_pixelsize);
- }
-}
-
-static void setup_functions(void)
-{
- svga_driver.flags &= ~GD_DONT_USE_SCROLL;
-
- if (accel_avail&ACCELFLAG_SETMODE){
- do_sync=1;
- vga_accel(ACCEL_SETMODE, BLITS_IN_BACKGROUND);
- }else do_sync=0;
-
- svga_driver.get_color=get_color_fn(svga_driver.depth);
- if (!svga_driver.get_color) internal("Unknown bit depth %x", svga_driver.depth);
- switch(vga_colors){
- case 2: internal(
- "2-color modes are not supported by\
- links as they are buggy in svgalib and incapable of colors");
-
- case 16:
- alloc_scroll_buffer();
- svga_driver.draw_bitmap=draw_bitmap_drawscansegment;
- svga_driver.hscroll=hscroll_scansegment;
- svga_driver.vscroll=vscroll_scansegment;
- svga_driver.flags |= GD_DONT_USE_SCROLL;
- svga_driver.fill_area=fill_area_drawscansegment;
- svga_driver.draw_hline=draw_hline_fill_area;
- svga_driver.draw_vline=draw_vline_fill_area;
- mouse_getscansegment=vga_getscansegment;
- mouse_drawscansegment=vga_drawscansegment;
- break;
-
- default:
- mouse_getscansegment=vga_getscansegment;
- mouse_drawscansegment=vga_drawscansegment;
- if (accel_avail&ACCELFLAG_PUTIMAGE){
- svga_driver.draw_bitmap=draw_bitmap_accel;
- }else if (vga_linear){
- svga_driver.draw_bitmap=draw_bitmap_linear;
- }else if (mode_x){
- svga_driver.draw_bitmap=draw_bitmap_drawscansegment;
- }else{
- svga_driver.draw_bitmap=draw_bitmap_paged;
- }
-
- if (accel_avail&ACCELFLAG_FILLBOX) svga_driver.fill_area=fill_area_accel_box;
- else if (accel_avail&ACCELFLAG_DRAWLINE) svga_driver.fill_area=fill_area_accel_lines;
- else if (vga_linear) svga_driver.fill_area=fill_area_linear;
- else if (mode_x) svga_driver.fill_area=fill_area_drawscansegment;
- else svga_driver.fill_area=fill_area_paged;
-
- if (accel_avail&ACCELFLAG_DRAWLINE){
- svga_driver.draw_hline=draw_hline_accel_line;
- svga_driver.draw_vline=draw_vline_accel_line;
- }else if (accel_avail&ACCELFLAG_FILLBOX){
- svga_driver.draw_hline=draw_hline_accel_box;
- svga_driver.draw_vline=draw_vline_accel_box;
- }else if (vga_linear){
- svga_driver.draw_hline=draw_hline_linear;
- svga_driver.draw_vline=draw_vline_linear;
- }else if (mode_x){
- svga_driver.draw_hline=draw_hline_fill_area;
- svga_driver.draw_vline=draw_vline_fill_area;
- }else{
- /* Paged memory access */
- svga_driver.draw_hline=draw_hline_paged;
- switch(vga_bytes)
- {
- case 1:
- svga_driver.draw_vline=draw_vline_paged_1;
- break;
-#ifdef t2c
- case 2:
- svga_driver.draw_vline=draw_vline_paged_2;
- break;
-#endif /* #ifdef t2c */
-
-#ifdef t4c
- case 4:
- svga_driver.draw_vline=draw_vline_paged_4;
- break;
-#endif /* #ifdef t4c */
-
- default:
- if (vga_bytes&(vga_bytes-1))
- svga_driver.draw_vline=draw_vline_paged;
- else
- svga_driver.draw_vline=draw_vline_paged_aligned;
- break;
- }
- }
-
- if (vga_colors>=256){
- if (vga_linear){
- mouse_drawscansegment=drawscansegment_linear;
- mouse_getscansegment=getscansegment_linear;
- }else if (!mode_x){
- mouse_drawscansegment=drawscansegment_paged;
- mouse_getscansegment=getscansegment_paged;
- }
- }
-
- if (accel_avail&ACCELFLAG_SCREENCOPY){
- svga_driver.hscroll=hscroll_accel;
- svga_driver.vscroll=vscroll_accel;
- }else if (vga_linear){
- svga_driver.hscroll=hscroll_linear;
- svga_driver.vscroll=vscroll_linear;
- svga_driver.flags |= GD_DONT_USE_SCROLL;
- }else if (mode_x){
- alloc_scroll_buffer();
- svga_driver.hscroll=hscroll_scansegment;
- svga_driver.vscroll=vscroll_scansegment;
- svga_driver.flags |= GD_DONT_USE_SCROLL;
- }else{
- alloc_scroll_buffer();
- svga_driver.hscroll=hscroll_paged;
- svga_driver.vscroll=vscroll_paged;
- svga_driver.flags |= GD_DONT_USE_SCROLL;
- }
- }
-
-}
-
-#if 0
-void dump_mode_info_into_file(vga_modeinfo* i)
-{
- FILE *f;
-
- f=fopen(".links_svga_modeinfo","w");
- if (!f) return;
- fprintf(f,"Resolution %d*%d\n",i->width,i->height);
- fprintf(f,"%d bytes per screen pixel\n",i->bytesperpixel);
- fprintf(f,"%d colors\n",i->colors);
- fprintf(f,"Linewidth %d bytes\n",i->linewidth);
- fprintf(f,"Maximum logical width %d bytes\n",i->maxlogicalwidth);
- fprintf(f,"Start address rangemask 0x%x\n",i->startaddressrange);
- fprintf(f,"Max. pixels per logical screen %d\n",i->maxpixels);
- fprintf(f,"bitblt %s\n",i->haveblit&HAVE_BITBLIT?"yes":"no");
- fprintf(f,"fillblt %s\n",i->haveblit&HAVE_FILLBLIT?"yes":"no");
- fprintf(f,"imageblt %s\n",i->haveblit&HAVE_IMAGEBLIT?"yes":"no");
- fprintf(f,"hlinelistblt %s\n",i->haveblit&HAVE_HLINELISTBLIT?"yes":"no");
- fprintf(f,"read/write page %s\n",i->flags&HAVE_RWPAGE?"yes":"no");
- fprintf(f,"Interlaced %s\n",i->flags&IS_INTERLACED?"yes":"no");
- fprintf(f,"Mode X layout %s\n",i->flags&IS_MODEX?"yes":"no");
- fprintf(f,"Dynamically loaded %s\n",i->flags&IS_DYNAMICMODE?"yes":"no");
- fprintf(f,"Linear: %s\n",vga_linear?"yes":"no");
- fprintf(f,"Misordered %s\n",i->flags&RGB_MISORDERED?"yes":"no");
- if (!i->flags&EXT_INFO_AVAILABLE){
- fprintf(f,"Old svgalib, extended info is not available\n");
- }else{
- fprintf(f,"Chiptype 0x%x\n",i->chiptype);
- fprintf(f,"Memory %dKB\n",i->memory);
- fprintf(f,"Linewidth Unit %d\n",i->linewidth_unit);
- fprintf(f,"Aperture size %d\n",i->aperture_size);
- }
- fprintf(f,"Accelerated putimage: %s\n",svga_driver.draw_bitmap==draw_bitmap_accel?"yes":"no");
- fclose(f);
-}
-#endif
-
-static void svgalib_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_PASTE) goto skip;
- if ((ev->y & (KBD_CTRL | KBD_ALT)) == KBD_ALT && ev->x >= '0' && ev->x <= '9') {
- switch_virtual_device((ev->x - '1' + 10) % 10);
- return;
- }
-skip:
- if (g_kbd_codepage(&svga_driver) != utf8_table && ev->x >= 128 && ev->x <= 255)
- if ((ev->x = cp2u(ev->x, g_kbd_codepage(&svga_driver))) == -1) return;
- if (current_virtual_device && current_virtual_device->keyboard_handler) current_virtual_device->keyboard_handler(current_virtual_device, ev->x, ev->y);
-}
-
-#ifndef MOUSE_FOURTHBUTTON
-#define MOUSE_FOURTHBUTTON 0
-#endif
-
-#ifndef MOUSE_FIFTHBUTTON
-#define MOUSE_FIFTHBUTTON 0
-#endif
-
-#ifndef MOUSE_SIXTHBUTTON
-#define MOUSE_SIXTHBUTTON 0
-#endif
-
-#define BUTTON_MASK (MOUSE_RIGHTBUTTON | MOUSE_MIDDLEBUTTON | MOUSE_LEFTBUTTON | MOUSE_FOURTHBUTTON | MOUSE_FIFTHBUTTON /*| MOUSE_SIXTHBUTTON*/)
-
-static inline void mouse_aggregate_flush(void)
-{
- if (!mouse_aggregate_flag) return;
- mouse_aggregate_flag=0;
- if (!current_virtual_device) return;
- if (!current_virtual_device->mouse_handler) return;
- current_virtual_device->mouse_handler(current_virtual_device, mouse_x, mouse_y, mouse_aggregate_action);
-}
-
-/* Only calls appropriate callbacks, doesn't draw anything. */
-static void mouse_event_handler(int button, int dx, int dy, int dz, int drx, int dry, int drz)
-{
- int moved,old_mouse_x,old_mouse_y;
- void (*mh)(struct graphics_device *, int, int, int);
- struct graphics_device *cd=current_virtual_device;
-
- mh=cd?cd->mouse_handler:(void(*)(struct graphics_device *dev, int x, int y, int buttons))NULL;
- old_mouse_x=mouse_x;
- old_mouse_y=mouse_y;
-
- mouse_x+=dx;
- if (mouse_x>=xsize) mouse_x=xsize-1;
- else if (mouse_x<0) mouse_x=0;
-
- mouse_y+=dy;
- if (mouse_y>=ysize) mouse_y=ysize-1;
- else if (mouse_y<0) mouse_y=0;
-
- redraw_mouse();
-
- moved=(old_mouse_x!=mouse_x||old_mouse_y!=mouse_y);
-
- /* Test movement without buttons */
- if (!(mouse_buttons & BUTTON_MASK) && moved) {
- mouse_aggregate_flag=1;
- mouse_aggregate_action=B_MOVE;
- }
-
- /* Test presses */
- if ((button&MOUSE_LEFTBUTTON)&&!(mouse_buttons&MOUSE_LEFTBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_LEFT|B_DOWN);
- }
- if ((button&MOUSE_MIDDLEBUTTON)&&!(mouse_buttons&MOUSE_MIDDLEBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_MIDDLE|B_DOWN);
- }
- if ((button&MOUSE_RIGHTBUTTON)&&!(mouse_buttons&MOUSE_RIGHTBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_RIGHT|B_DOWN);
- }
- if ((button&MOUSE_FOURTHBUTTON)&&!(mouse_buttons&MOUSE_FOURTHBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_FOURTH|B_DOWN);
- }
- if ((button&MOUSE_FIFTHBUTTON)&&!(mouse_buttons&MOUSE_FIFTHBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_FIFTH|B_DOWN);
- }
- if ((button&MOUSE_SIXTHBUTTON)&&!(mouse_buttons&MOUSE_SIXTHBUTTON)){
- mouse_aggregate_flush();
- /*if (mh) mh(cd,mouse_x, mouse_y,B_SIXTH|B_DOWN);*/
- switch_virtual_device(VD_NEXT);
- }
-
- /* Test releases */
- if (!(button&MOUSE_LEFTBUTTON)&&(mouse_buttons&MOUSE_LEFTBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_LEFT|B_UP);
- }
- if (!(button&MOUSE_MIDDLEBUTTON)&&(mouse_buttons&MOUSE_MIDDLEBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_MIDDLE|B_UP);
- }
- if (!(button&MOUSE_RIGHTBUTTON)&&(mouse_buttons&MOUSE_RIGHTBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_RIGHT|B_UP);
- }
- if (!(button&MOUSE_FOURTHBUTTON)&&(mouse_buttons&MOUSE_FOURTHBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_FOURTH|B_UP);
- }
- if (!(button&MOUSE_FIFTHBUTTON)&&(mouse_buttons&MOUSE_FIFTHBUTTON)){
- mouse_aggregate_flush();
- if (mh) mh(cd,mouse_x, mouse_y,B_FIFTH|B_UP);
- }
- if (!(button&MOUSE_SIXTHBUTTON)&&(mouse_buttons&MOUSE_SIXTHBUTTON)){
- mouse_aggregate_flush();
- /*if (mh) mh(cd,mouse_x, mouse_y,B_SIXTH|B_UP);*/
- }
-
- if (drx < 0 && mh) mh(cd, mouse_x, mouse_y, B_MOVE | B_WHEELUP);
- if (drx > 0 && mh) mh(cd, mouse_x, mouse_y, B_MOVE | B_WHEELDOWN);
-
- if (dry < 0 && mh) mh(cd, mouse_x, mouse_y, B_MOVE | B_WHEELLEFT);
- if (dry > 0 && mh) mh(cd, mouse_x, mouse_y, B_MOVE | B_WHEELRIGHT);
-
- /* Test drag */
- if (! ((button^mouse_buttons) & BUTTON_MASK ) && moved && (button &
- BUTTON_MASK)){
- mouse_aggregate_flag=1;
- mouse_aggregate_action=(
- button&MOUSE_LEFTBUTTON?B_LEFT:
- button&MOUSE_RIGHTBUTTON?B_RIGHT:
- button&MOUSE_MIDDLEBUTTON?B_MIDDLE:
- button&MOUSE_FOURTHBUTTON?B_FOURTH:
- button&MOUSE_FIFTHBUTTON?B_FIFTH:
- /*button&MOUSE_SIXTHBUTTON?B_SIXTH:*/
- 0) | B_DRAG;
- }
- mouse_buttons=button;
-}
-
-#undef BUTTON_MASK
-
-/* 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;
-
- {
- struct graphics_device * current_virtual_device_backup;
-
- current_virtual_device_backup=current_virtual_device;
- current_virtual_device=mouse_graphics_device;
- svga_driver.draw_bitmap(mouse_graphics_device, &bmp, background_x,
- background_y);
- current_virtual_device=current_virtual_device_backup;
- }
-
-}
-
-/* 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>xsize?xsize-x:arrow_width);
- height=arrow_height+y>ysize?ysize-y:arrow_height;
-
- 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, 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;)
- {
- int mask=1<<(--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;
- {
- struct graphics_device * current_graphics_device_backup;
-
- current_graphics_device_backup=current_virtual_device;
- current_virtual_device=mouse_graphics_device;
- /* We do need to worry about SYNC because draw_bitmap already
- * does it (if necessary)
- */
- svga_driver.draw_bitmap(mouse_graphics_device, &bmp, mouse_x, mouse_y);
- current_virtual_device=current_graphics_device_backup;
- }
- 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;
-
- /* First let's sync to the beam - wait for the beginning of vertical retrace
- * (it would be better to wait for the beginning of the blank, however,
- * svgalib doesn't provide it as VGA and SVGA cards don't provide it
- */
-
- /* This will probably not make any good anyway.
- if (vga_colors>=256)
- vga_waitretrace();
- */
-
- if (mouse_bottom>ysize) mouse_bottom=ysize;
- if (background_bottom>ysize) background_bottom=ysize;
-
- SYNC
- /* We have to sync because mouse_drawscansegment does not wait for
- * the accelerator to finish. But we never waste time here because
- * mouse_drawscansegment is never accelerated.
- */
- /* Let's do the top part */
- if (background_top<mouse_top){
- /* Draw the background */
- background_length=background_right>xsize?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>xsize
- ?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>xsize?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>xsize?xsize-mouse_left:arrow_width;
- background_length=background_right-mouse_right;
- if (background_length+mouse_right>xsize)
- background_length=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>xsize?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>xsize?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 (flags) 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;
- }
- }
-}
-
-
-static unsigned char *svga_get_driver_param(void)
-{
- return svga_driver_param;
-}
-
-static void generate_palette_outer(void)
-{
- if (vga_colors==16||vga_colors==256){
- struct irgb *palette;
- palette=mem_alloc(vga_colors*sizeof(*palette));
- generate_palette(palette);
- set_palette(palette);
- mem_free(palette);
- /* Palette in SVGAlib will be always color cube */
- }
-}
-
-/* This is to be called after vga_setmode and sets up accelerator,
- * svgalib functions */
-static void setup_mode(int mode)
-{
- vga_modeinfo *i;
- int sig;
-
- accel_avail=vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL);
- if (vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_SET)&VGA_CLUT8){
- vga_ext_set(VGA_EXT_SET,VGA_CLUT8);
- palette_depth=8;
- }else palette_depth=6;
- i=vga_getmodeinfo(mode);
- vga_bytes=i->bytesperpixel;
- fb_pixelsize=vga_bytes?vga_bytes:1;
- vga_misordered=!!(i->flags&RGB_MISORDERED);
- mode_x=!!(i->flags&IS_MODEX);
- vga_linear=!!(i->flags&IS_LINEAR);
- /*
- if (!vga_linear && i->flags&CAPABLE_LINEAR && 0<=vga_setlinearaddressing()) vga_linear=1;
- */
- my_graph_mem=vga_getgraphmem();
- svga_driver.x = xsize=i->width;
- svga_driver.y = ysize=i->height;
- vga_colors=i->colors;
- if (xsize==320&&ysize==200&&vga_colors==256) vga_linear=1; /* The mode
- does not need to page :-) */
- vga_linewidth=i->linewidth;
- if (!vga_linear){
- vga_page=-1;
- }
- vga_misordered=!!(i->flags&RGB_MISORDERED);
- /*dump_mode_info_into_file(i);*/
- svga_driver.depth=0;
- svga_driver.depth|=vga_misordered<<8;
- switch (vga_colors){
- case 16:
- sig=4;
- break;
- case 256:
- sig=8;
- break;
- case 32768:
- sig=15;
- break;
- case 65536:
- sig=16;
- break;
- case 16777216:
- sig=24;
- break;
- default:
- sig=0; /* Only to suppress warning */
- break;
- }
- svga_driver.depth|=sig<<3;
- svga_driver.depth|=fb_pixelsize;
-
- /* setup_functions uses depth. */
- setup_functions();
- generate_palette_outer();
-}
-
-#ifndef __SPAD__
-static void vtswitch_handler(void *nothing)
-{
- int oktowrite;
-
- vga_unlockvc();
- vga_lockvc();
- oktowrite=vga_oktowrite();
- if (!oktowrite&&!flags){
- backup_virtual_device=current_virtual_device;
- current_virtual_device=NULL;
- }
- if (flags==1&&oktowrite) current_virtual_device=backup_virtual_device;
- flags=(flags&~1)|!oktowrite;
- svgalib_timer_id=install_timer(100,vtswitch_handler, NULL);
-}
-#endif
-
-static void svga_ctrl_c(void *i_)
-{
- kbd_ctrl_c();
-}
-
-/* Param: one string which is to be compared with one from modes.
- * Copies the svga_driver into gr_driver.
- * Returns: 0 OK
- * 1 Passed mode unknown by svga_driver
- * 2 Passed mode unknown by svgalib
- * mikulas: Change: Returns: NULL: OK
- * non-null: poiner to string with error
- * description, string must be freed
- */
-static unsigned char *svga_init_driver(unsigned char *param, unsigned char *display)
-{
- int j;
-
- kbd_set_raw = 0;
-
- vga_init();
- svga_driver.flags |= GD_NEED_CODEPAGE;
- j = 0;
-
- svga_driver_param=NULL;
- if (!param || !*param) goto not_found;
- svga_driver_param=stracpy(param);
- for (j=0;(size_t)j<sizeof(modes)/sizeof(*modes);j++)
- if (!casestrcmp(cast_uchar modes[j].name, param)) goto found;
- j = 1;
- not_found:
- {
- unsigned char *m = init_str();
- int l = 0;
- int f = 0;
- if (j) {
- add_to_str(&m, &l, cast_uchar "Video mode ");
- add_to_str(&m, &l, param);
- add_to_str(&m, &l,
- j == 1 ? cast_uchar " not supported by svgalib" :
- j == 2 ? cast_uchar " not supported by your video card" :
- cast_uchar " could not be set");
- add_to_str(&m, &l, cast_uchar ".\n");
- } else add_to_str(&m, &l, cast_uchar "There is no default video mode.\n");
- for (j=0;(size_t)j<sizeof(modes)/sizeof(*modes);j++) if (vga_hasmode(modes[j].number)) {
- if (f) add_to_str(&m, &l, cast_uchar ", ");
- else f = 1, add_to_str(&m, &l, cast_uchar "The following modes are supported:\n");
- add_to_str(&m, &l, cast_uchar modes[j].name);
- }
- if (f) add_to_str(&m, &l, cast_uchar "\nUse -mode switch to set video mode.\n");
- else add_to_str(&m, &l, cast_uchar "There are no supported video modes. Links can't run on svgalib.\n");
- if(svga_driver_param)mem_free(svga_driver_param),svga_driver_param=NULL;
- return m;
- }
- found:
- if (!vga_hasmode(modes[j].number)) {
- j = 2;
- goto not_found;
- }
- if (init_virtual_devices(&svga_driver, NUMBER_OF_DEVICES))
- {
- if(svga_driver_param)mem_free(svga_driver_param),svga_driver_param=NULL;
- return stracpy(cast_uchar "Allocation of virtual devices failed.\n");
- }
- if ((vga_getmousetype()&MOUSE_TYPE_MASK)==MOUSE_NONE)
- {
- vga_setmousesupport(0);
- mouse_works=0;
- }else{
- vga_setmousesupport(1);
- mouse_works=1;
- }
- vga_lockvc();
-#ifndef __SPAD__
- svgalib_timer_id=install_timer(100,vtswitch_handler,NULL);
- if (vga_runinbackground_version()>=1) vga_runinbackground(1);
-#endif
- vga_setmode_retry:
- if (vga_setmode(modes[j].number) < 0) {
- if (out_of_memory(0, NULL, 0))
- goto vga_setmode_retry;
-#ifndef __SPAD__
- kill_timer(svgalib_timer_id);
-#endif
- vga_unlockvc();
- shutdown_virtual_devices();
- j = 3;
- goto not_found;
- }
- vga_mode=modes[j].number;
- setup_mode(modes[j].number);
- svgalib_kbd = handle_svgalib_keyboard(svgalib_key_in);
-
- if (mouse_works){
- if ((unsigned)arrow_area > (unsigned)MAXINT / fb_pixelsize) overalloc();
- 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);
- mouse_black=svga_driver.get_color(0);
- mouse_white=svga_driver.get_color(0xffffff);
- mouse_graphics_device=svga_driver.init_device();
- virtual_devices[0] = NULL;
- global_mouse_hidden=1;
- background_x=mouse_x=xsize>>1;
- background_y=mouse_y=ysize>>1;
- show_mouse();
- mouse_seteventhandler((void *)mouse_event_handler);
- }else{
- global_mouse_hidden=1;
- /* To ensure hide_mouse and show_mouse will do nothing */
- }
- ignore_signals();
- errno = 0;
- while (signal(SIGTSTP, SIG_IGN) == SIG_ERR && errno == EINTR) errno = 0;
- install_signal_handler(SIGINT, svga_ctrl_c, svgalib_kbd, 0);
- return NULL;
-}
-
-/* Return value: 0 alloced on heap
- * 1 alloced in vidram
- * 2 alloced in X server shm
- */
-static int svga_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 int vga_block(struct graphics_device *dev)
-{
- int overridden;
-
- overridden=(flags>>1)&1;
- if (!overridden){
- if (!(flags&1)){
- backup_virtual_device=current_virtual_device;
- current_virtual_device=NULL;
- }
- svgalib_block_itrm(svgalib_kbd);
- if (mouse_works){
- hide_mouse();
- /* mouse_close(); This is not necessary as it is
- handled by vga_setmode(TEXT). */
- }
- vga_setmode_retry:
- if (vga_setmode(TEXT) < 0) {
- if (out_of_memory(0, NULL, 0))
- goto vga_setmode_retry;
- fatal_exit("ERROR: vga_setmode failed");
- }
- }
- flags|=2;
- return overridden;
-}
-
-static int vga_unblock(struct graphics_device *dev)
-{
-#ifdef DEBUG
- if (current_virtual_device) {
- internal("vga_unblock called without vga_block");
- return 0;
- }
-#endif /* #ifdef DEBUG */
- flags&=~2;
- if (!flags) current_virtual_device=backup_virtual_device;
- vga_setmousesupport(1);
- vga_setmode_retry:
- if (vga_setmode(vga_mode) < 0) {
- if (out_of_memory(0, NULL, 0))
- goto vga_setmode_retry;
- fatal_exit("ERROR: vga_setmode failed");
- }
- setup_mode(vga_mode);
- if (mouse_works){
- show_mouse();
- mouse_seteventhandler((void *)mouse_event_handler);
- }
- svgalib_unblock_itrm(svgalib_kbd);
- if (current_virtual_device) current_virtual_device->redraw_handler(current_virtual_device
- ,¤t_virtual_device->size);
- return 0;
-}
-
-static void *svga_prepare_strip(struct bitmap *bmp, int top, int lines)
-{
- return ((unsigned char *)bmp->data)+bmp->skip*top;
-}
-
-
-static void svga_commit_strip(struct bitmap *bmp, int top, int lines)
-{
- return;
-}
-
-int vga_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
-{
- int retval,i;
-
- if (drv != &svga_driver) return select(n, readfds, writefds, exceptfds, timeout);
-
- /* The second flag here is to suppress mouse wait
- * in blocked state */
- retval=vga_waitevent((mouse_works&&!(flags&2) ? VGA_MOUSEEVENT : 0)
-#ifdef VGA_REDRAWEVENT
- | VGA_REDRAWEVENT
-#endif
- ,readfds, writefds,
- exceptfds, timeout);
- if (retval<0) return retval;
-#ifdef VGA_REDRAWEVENT
- if (retval&VGA_REDRAWEVENT) {
- struct rect r;
- r.x1 = 0;
- r.y1 = 0;
- r.x2 = svga_driver.x;
- r.y2 = svga_driver.y;
- if (current_virtual_device) current_virtual_device->redraw_handler(current_virtual_device,&r);
- check_bottom_halves();
- }
-#endif
- if (retval&VGA_MOUSEEVENT){
- mouse_aggregate_flush();
- /*redraw_mouse(); mikulas: dal jsem to do mouse_event_handler,
- aby ukazatel mysi nezustaval pozadu za scrollbarem */
- check_bottom_halves();
- }
- retval=0;
- for (i=0;i<n;i++){
- if (readfds&&FD_ISSET(i,readfds)) retval++;
- if (writefds&&FD_ISSET(i,writefds)) retval++;
- if (exceptfds&&FD_ISSET(i,exceptfds)) retval++;
- }
- return retval;
-}
-
-struct graphics_driver svga_driver={
- cast_uchar "svgalib",
- svga_init_driver,
- init_virtual_device,
- shutdown_virtual_device,
- svga_shutdown_driver,
- NULL,
- NULL,
- svga_get_driver_param,
- NULL,
- NULL,
- NULL,
- svga_get_empty_bitmap,
- svga_register_bitmap,
- svga_prepare_strip,
- svga_commit_strip,
- svga_unregister_bitmap,
- NULL, /* svga_draw_bitmap */
- NULL, /* get_color */
- NULL, /* fill_area */
- NULL, /* draw_hline */
- NULL, /* draw_vline */
- NULL, /* hscroll */
- NULL, /* vscroll */
- generic_set_clip_area,
- NULL,
- vga_block, /* block */
- vga_unblock, /* unblock */
- NULL, /* set_title */
- NULL, /* exec */
- NULL, /* set_clipboard_text */
- NULL, /* get_clipboard_text */
- 0, /* depth */
- 0, 0, /* size */
- GD_NO_LIBEVENT
-#ifndef SPAD
- | GD_NOAUTO
-#endif
- , /* flags */
- 0, /* codepage */
- NULL, /* shell */
-};
-
-#endif /* GRDRV_SVGALIB */
diff --git a/terminal.c b/terminal.c
@@ -553,27 +553,13 @@ void free_term_specs(void)
free_list(struct term_spec, term_specs);
}
-#if defined(OS2) || defined(DOS)
-static struct term_spec dumb_term = { init_list_1st(NULL) "", 2, 1, 1, 0, 1, 0, -1, 0, 0, 0, 0, init_list_last(NULL) };
-#else
static struct term_spec dumb_term = { init_list_1st(NULL) "", 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, init_list_last(NULL) };
-#endif
static struct term_spec cygwin_term = { init_list_1st(NULL) "", 2, 1, 1, 0, 1, 0, -1, 0, 0, 0, 0, init_list_last(NULL) };
static struct term_spec *default_term_spec(unsigned char *term)
{
if (!casestrcmp(term, cast_uchar "cygwin"))
return &cygwin_term;
-#ifdef DOS
- {
- static int is_bw = -1;
- if (is_bw == -1) {
- is_bw = dos_is_bw();
- if (is_bw)
- dumb_term.col = 0;
- }
- }
-#endif
return &dumb_term;
}
@@ -639,7 +625,6 @@ struct terminal *init_term(int fdin, int fdout, void (*root_window)(struct windo
static int process_utf_8(struct terminal *term, struct links_event *ev)
{
-#if defined(G) || defined(ENABLE_UTF8)
if (ev->ev == EV_KBD) {
if ((!F && term_charset(term) == utf8_table)
#ifdef G
@@ -666,7 +651,6 @@ static int process_utf_8(struct terminal *term, struct links_event *ev)
direct:
term->utf8_buffer[0] = 0;
}
-#endif
return 1;
}
@@ -937,28 +921,7 @@ static unsigned char frame_restrict[48] = {
179, 0, 0, 0, 0, 0, 0, 0,
};
-#if defined(ENABLE_UTF8) && defined(WIN)
-static inline char_t utf8_hack(char_t c)
-{
- /*
- * These characters produce beeps on Cygwin.
- */
- switch (c) {
- case 0xb7:
- case 0x2022:
- case 0x2024:
- case 0x2026:
- case 0x2219:
- case 0x22c5:
- case 0x30fb:
- return '.';
- default:
- return c;
- }
-}
-#else
#define utf8_hack(x) (x)
-#endif
#define SETPOS(x, y) \
{ \
@@ -1072,9 +1035,6 @@ static void redraw_screen(struct terminal *term)
/*if ((term->screen[p].at & 0x38) == (term->last_screen[p].at & 0x38) && (term->screen[p].ch == 0 || term->screen[p].ch == 1 || term->screen[p].ch == ' ') && (term->last_screen[p].ch == 0 || term->last_screen[p].ch == 1 || term->last_screen[p].ch == ' ') && (x != term->cx || y != term->cy)) continue;*/
/*fprintf(stderr, "%d.%d : %d-%d -> %d-%d\n", x, y, term->last_screen[p].ch, term->last_screen[p].at, term->screen[p].ch, term->screen[p].at);*/
memcpy(&term->last_screen[p], &term->screen[p], sizeof(chr));
-#ifdef OPENVMS
- if (n_chars >= term->x - 6) cy = -1;
-#endif
if (cx == x && cy == y) goto pc;/*PRINT_CHAR(p)*/
else if (cy == y && x - cx < 10 && x - cx > 0) {
for (i = x - cx; i >= 0; i--) {
@@ -1108,30 +1068,7 @@ static void redraw_screen(struct terminal *term)
add_to_str(&a, &l, cast_uchar "H");
}
if (l && term->master) want_draw();
-#ifdef OPENVMS
- {
-/*
- * OpenVMS/VAX has some bug in the terminal driver and corrupts long strings.
- * Also, we need to avoid breaking escape sequences.
- */
-#define PRINT_BATCH 2000
- int i, q;
- for (i = 0; i < l; i += q) {
- int qq;
- q = PRINT_BATCH;
- if (q > l - i) q = l - i;
- for (qq = q - 1; qq > 0; qq--) {
- if (a[i + qq] == 27) {
- q = qq;
- break;
- }
- }
- hard_write(term->fdout, a + i, q);
- }
- }
-#else
hard_write(term->fdout, a, l);
-#endif
if (l && term->master) done_draw();
mem_free(a);
term->dirty = 0;
@@ -1461,13 +1398,9 @@ void exec_on_terminal(struct terminal *term, unsigned char *path, unsigned char
#endif
) {
term->blocked = blockh;
-#ifdef DOS
- unblock_terminal(term);
-#else
set_handlers(blockh, unblock_terminal, NULL, term);
if (!F) set_handlers(term->fdin, NULL, NULL, term);
/*block_itrm(term->fdin);*/
-#endif
} else {
set_handlers(blockh, close_handle, NULL, (void *)(my_intptr_t)blockh);
}
diff --git a/tiff.c b/tiff.c
@@ -1,289 +0,0 @@
-/* tiff.c
- * TIFF image decoding
- * (c) 2002 Petr 'Brain' Kulhavy
- * This file is a part of the Links program, released under GPL.
- *
- * Compiles in graphics mode only and only when HAVE_TIFF.
- */
-#include "cfg.h"
-
-#ifdef G
-#include "links.h"
-
-#ifdef HAVE_TIFF
-#include <tiffio.h>
-#include "bits.h"
-
-struct tiff_decoder{
- unsigned char *tiff_data; /* undecoded data */
- int tiff_size; /* size of undecoded file */
- int tiff_pos;
- int tiff_open; /* 1 if tiff was open, means: tiff_data, tiff_size and tiff_pos are valid */
-};
-
-void tiff_start(struct cached_image *cimg)
-{
- struct tiff_decoder * deco;
-
- deco=mem_alloc(sizeof(struct tiff_decoder));
-
- cimg->decoder=deco;
- deco->tiff_size=0;
- deco->tiff_data=NULL;
- deco->tiff_open=0;
- deco->tiff_pos=0;
-}
-
-
-void tiff_restart(struct cached_image *cimg, unsigned char *data, int length)
-{
- struct tiff_decoder * deco=(struct tiff_decoder*)cimg->decoder;
- unsigned char *p;
-
- if (!deco->tiff_data) {
- if ((unsigned)length > MAXINT) overalloc();
- p=mem_alloc(length);
- } else {
- if ((unsigned)length + (unsigned)deco->tiff_size > MAXINT) overalloc();
- if ((unsigned)length + (unsigned)deco->tiff_size < (unsigned)length) overalloc();
- p=mem_realloc(deco->tiff_data,deco->tiff_size+length);
- }
- deco->tiff_data=p;
- memcpy(deco->tiff_data+deco->tiff_size,data,length);
- deco->tiff_size+=length;
-}
-
-static toff_t tiff_size(thandle_t data)
-{
- struct cached_image *cimg=(struct cached_image *)data;
- struct tiff_decoder *deco=(struct tiff_decoder*)cimg->decoder;
-
- if (!deco->tiff_open)internal("BUG IN LIBTIFF: sizeproc called on closed file. Contact the libtiff authors.\n");
-
- return deco->tiff_size;
-}
-
-
-static tsize_t tiff_read(thandle_t data, tdata_t dest, tsize_t count)
-{
- struct cached_image *cimg=(struct cached_image *)data;
- struct tiff_decoder *deco=(struct tiff_decoder*)cimg->decoder;
-
- if (!deco->tiff_open)internal("BUG IN LIBTIFF: readproc called on closed file. Contact the libtiff authors.\n");
-
- if (count < 0)
- return 0;
-
- if (count > deco->tiff_size-deco->tiff_pos)
- count = deco->tiff_size-deco->tiff_pos;
- memcpy(dest,deco->tiff_data+deco->tiff_pos,count);
- deco->tiff_pos+=(int)count;
- return count;
-}
-
-
-static tsize_t tiff_write(thandle_t data, tdata_t dest, tsize_t count)
-{
- internal("BUG IN LIBTIFF: writeproc called on read-only file. Contact the libtiff authors.\n");
- return 0;
-}
-
-
-static toff_t tiff_seek(thandle_t data, toff_t offset, int whence)
-{
- struct cached_image *cimg=(struct cached_image *)data;
- struct tiff_decoder *deco=(struct tiff_decoder*)cimg->decoder;
- long pos;
-
- if (!deco->tiff_open)internal("BUG IN LIBTIFF: seekproc called on closed file. Contact the libtiff authors.\n");
-
- switch(whence)
- {
- case SEEK_SET:
- pos = offset;
- break;
- case SEEK_CUR:
- pos = (unsigned long)deco->tiff_pos + offset;
- break;
- case SEEK_END:
- pos = (unsigned long)deco->tiff_size + offset;
- break;
- default:
- pos = deco->tiff_pos;
- break;
- }
- if (pos > deco->tiff_size) pos = deco->tiff_size;
- if (pos < 0) pos = 0;
- deco->tiff_pos = (int)pos;
- return deco->tiff_pos;
-}
-
-
-static int tiff_close(void *data)
-{
- struct cached_image *cimg=(struct cached_image *)data;
- struct tiff_decoder *deco=(struct tiff_decoder*)cimg->decoder;
-
- if (!deco->tiff_open)internal("BUG IN LIBTIFF: closeproc called on closed file. Contact the libtiff authors.\n");
- tiff_destroy_decoder(cimg);
- return 0;
-}
-
-
-static int tiff_mmap(thandle_t data, tdata_t *dest, toff_t *len)
-{
- struct cached_image *cimg=(struct cached_image *)data;
- struct tiff_decoder *deco=(struct tiff_decoder*)cimg->decoder;
-
- if (!deco->tiff_open)internal("BUG IN LIBTIFF: mapproc called on closed file. Contact the libtiff authors.\n");
- *dest=deco->tiff_data;
- *len=deco->tiff_size;
- return 0;
-}
-
-
-static void tiff_munmap(thandle_t data, tdata_t dest, toff_t len)
-{
- struct cached_image *cimg=(struct cached_image *)data;
- struct tiff_decoder *deco=(struct tiff_decoder*)cimg->decoder;
-
- if (!deco->tiff_open)internal("BUG IN LIBTIFF: unmapproc called on closed file. Contact the libtiff authors.\n");
-}
-
-
-static void tiff_error_handler(const char* module, const char* fmt, va_list ap)
-{
-}
-
-static void flip_buffer(void *buf,int width,int height)
-{
- if (htonl(0x12345678L)!=0x12345678L) /* little endian --- ja to chci na intelu rychly!!! */
- {
-#ifdef t4c
- t4c* buffer=(t4c*)buf;
- register t4c a,b;
- t4c *p,*q;
- int i,l;
-
- for (l=0,p=buffer,q=buffer+width*(height-1);l<(height>>1);l++,q-=(width<<1))
- for (i=0;i<width;a=*p,b=*q,*p++=b,*q++=a,i++)
- ;
-#else
- unsigned char* buffer=(unsigned char*)buf;
- unsigned char *p,*q;
- int l;
- unsigned char *tmp;
- int w=4*width;
-
- if ((unsigned)w > MAXINT) overalloc();
- tmp=mem_alloc(w);
-
- /* tohle je pomalejsi, protoze se kopiruje pamet->pamet, pamet->pamet */
- /* kdyz mame 4B typek, tak se kopiruje pamet->reg, reg->pamet */
- for (l=0,p=buffer,q=buffer+w*(height-1);l<(height>>1);l++,q-=w,p+=w)
- memcpy(tmp,p,w),memcpy(p,q,w),memcpy(q,tmp,w);
- mem_free(tmp);
-#endif
- }
- else /* big endian */
- {
- unsigned char zakazany_uvolneni[4];
- unsigned char* buffer=(unsigned char*)buf;
- int w=width<<2; /* 4 bytes per pixel */
- unsigned char *p,*q;
- int i,l;
-
- for (l=0,p=buffer,q=buffer+w*(height-1);l<(height>>1);l++,q-=(w<<1))
- for (i=0;i<width;i++,p+=4,q+=4)
- {
- memcpy(zakazany_uvolneni,p,4);
- p[0]=q[3];
- p[1]=q[2];
- p[2]=q[1];
- p[3]=q[0];
- q[0]=zakazany_uvolneni[3];
- q[1]=zakazany_uvolneni[2];
- q[2]=zakazany_uvolneni[1];
- q[3]=zakazany_uvolneni[0];
- }
- if (height&1) /* flip endianity of line in the middle (if the height is odd) */
- for (i=0;i<width;i++,p+=4)
- {
- memcpy(zakazany_uvolneni,p,4);
- p[0]=zakazany_uvolneni[3];
- p[1]=zakazany_uvolneni[2];
- p[2]=zakazany_uvolneni[1];
- p[3]=zakazany_uvolneni[0];
- }
- }
-}
-
-void tiff_finish(struct cached_image *cimg)
-{
- struct tiff_decoder *deco=(struct tiff_decoder*)cimg->decoder;
- int bla;
- TIFF *t;
-
- if (!deco->tiff_size){img_end(cimg);return;}
- deco->tiff_open=1;
- TIFFSetErrorHandler(tiff_error_handler);
- TIFFSetWarningHandler(tiff_error_handler);
- t=TIFFClientOpen(
- "Prave si rek' svy posledni slova. A vybral sis k tomu prihodny misto.",
- "r",
- cimg,
- (TIFFReadWriteProc)tiff_read,
- (TIFFReadWriteProc)tiff_write,
- (TIFFSeekProc)tiff_seek,
- (TIFFCloseProc)tiff_close,
- (TIFFSizeProc)tiff_size,
- (TIFFMapFileProc)tiff_mmap,
- (TIFFUnmapFileProc)tiff_munmap
- );
- if (!t){img_end(cimg);return;}
- bla=TIFFGetField(t, TIFFTAG_IMAGEWIDTH, &(cimg->width));
- if (!bla){TIFFClose(t);img_end(cimg);return;}
- bla=TIFFGetField(t, TIFFTAG_IMAGELENGTH, &(cimg->height));
- if (!bla){TIFFClose(t);img_end(cimg);return;}
- cimg->buffer_bytes_per_pixel=4;
- cimg->red_gamma=cimg->green_gamma=cimg->blue_gamma=(float)sRGB_gamma;
- cimg->strip_optimized=0;
- if (header_dimensions_known(cimg)){TIFFClose(t);img_end(cimg);return;}
-/* int TIFFReadRGBAImage(TIFF* tif, u_long width, u_long height, u_long* raster, int stopOnError) from man page */
- /*TIFFReadRGBAImage(t,cimg->width,cimg->height,(unsigned long*)(cimg->buffer),1);*/ /* 231: warning: passing arg 4 of `TIFFReadRGBAImage' from incompatible pointer type */
- TIFFReadRGBAImage(t,cimg->width,cimg->height,(void*)(cimg->buffer),1);
- TIFFClose(t);
-
- /* For some reason the TIFFReadRGBAImage() function chooses the lower
- * left corner as the origin. Vertically mirror scanlines.
- */
- flip_buffer((void*)(cimg->buffer),cimg->width,cimg->height);
-
- img_end(cimg);
-}
-
-void tiff_destroy_decoder(struct cached_image *cimg)
-{
- struct tiff_decoder *deco=(struct tiff_decoder *)cimg->decoder;
- if (deco->tiff_data) mem_free(deco->tiff_data), deco->tiff_data = NULL;
- deco->tiff_open=0;
-}
-
-void add_tiff_version(unsigned char **s, int *l)
-{
- unsigned char *p, *pp;
- int pl;
- add_to_str(s, l, cast_uchar "TIFF (");
- p = (unsigned char *)TIFFGetVersion();
- pp = cast_uchar strstr(cast_const_char p, "LIBTIFF, ");
- if (pp) p = pp + 9;
- pp = cast_uchar strstr(cast_const_char p, "Version ");
- if (pp) p = pp + 8;
- pl = (int)strcspn(cast_const_char p, " \n");
- add_bytes_to_str(s, l, p, pl);
- add_to_str(s, l, cast_uchar ")");
-}
-
-#endif /* #ifdef HAVE_TIFF */
-
-#endif /* #ifdef G */
diff --git a/types.c b/types.c
@@ -1189,9 +1189,6 @@ no_extended:
x = y;
for (y = x; *y; y++) if (dir_sep(*y)
-#if defined(DOS_FS) || defined(SPAD)
- || *y == ':'
-#endif
) *y = '-';
return x;
}
diff --git a/url.c b/url.c
@@ -22,18 +22,11 @@ static_const struct {
{"http", 80, http_func, NULL, 0, 1, 1, 1, 0},
{"proxy", 3128, proxy_func, NULL, 0, 1, 1, 1, 0},
{"ftp", 21, ftp_func, NULL, 0, 1, 1, 0, 0},
- {"finger", 79, finger_func, NULL, 0, 1, 1, 0, 0},
-#ifndef DISABLE_SMB
- {"smb", 139, smb_func, NULL, 0, 1, 1, 0, 1},
-#endif
{"mailto", 0, NULL, mailto_func, 0, 0, 0, 0, 0},
{"telnet", 0, NULL, telnet_func, 0, 0, 0, 0, 1},
{"tn3270", 0, NULL, tn3270_func, 0, 0, 0, 0, 1},
{"mms", 0, NULL, mms_func, 1, 0, 1, 0, 1},
{"magnet", 0, NULL, magnet_func, 1, 0, 0, 0, 1},
-#ifdef JS
- {"javascript", 0, NULL, javascript_func,1, 0, 0, 0, 0},
-#endif
{NULL, 0, NULL, NULL, 0, 0, 0, 0, 0}
};
@@ -388,7 +381,6 @@ match:
static unsigned char *rewrite_url_mediawiki_svg(unsigned char *n)
{
-#ifndef HAVE_SVG
const unsigned char u1[] = "/media/math/render/svg/";
const unsigned char u2[] = "/media/math/render/png/";
unsigned char *d, *s;
@@ -399,7 +391,6 @@ static unsigned char *rewrite_url_mediawiki_svg(unsigned char *n)
if (!s)
return n;
memcpy(s, u2, strlen(cast_const_char u2));
-#endif
return n;
}
@@ -422,12 +413,6 @@ static void insert_wd(unsigned char **up, unsigned char *cwd)
if (!u || !cwd || !*cwd) return;
if (casecmp(u, cast_uchar "file://", 7)) return;
if (dir_sep(u[7])) return;
-#ifdef DOS_FS
- if (upcase(u[7]) >= 'A' && upcase(u[7]) <= 'Z' && u[8] == ':' && dir_sep(u[9])) return;
-#endif
-#ifdef SPAD
- if (_is_absolute(cast_const_char(u + 7)) != _ABS_NO) return;
-#endif
url = init_str();
url_l = 0;
add_bytes_to_str(&url, &url_l, u, 7);
@@ -623,9 +608,6 @@ unsigned char *translate_url(unsigned char *url, unsigned char *cwd)
}
goto return_nu;
}
-#ifdef DOS_FS
- if (ch == url + 1) goto set_prefix;
-#endif
nu = memacpy(url, ch - url + 1);
add_to_strn(&nu, cast_uchar "//");
add_to_strn(&nu, ch + 1);
diff --git a/view.c b/view.c
@@ -45,137 +45,6 @@ void destroy_vs(struct view_state *vs)
mem_free(vs);
}
-#ifdef JS
-void create_js_event_spec(struct js_event_spec **j)
-{
- if (*j) return;
- *j = mem_calloc(sizeof(struct js_event_spec));
-}
-
-void free_js_event_spec(struct js_event_spec *j)
-{
- if (!j) return;
- if (j->move_code) mem_free(j->move_code);
- if (j->over_code) mem_free(j->over_code);
- if (j->out_code) mem_free(j->out_code);
- if (j->down_code) mem_free(j->down_code);
- if (j->up_code) mem_free(j->up_code);
- if (j->click_code) mem_free(j->click_code);
- if (j->dbl_code) mem_free(j->dbl_code);
- if (j->blur_code) mem_free(j->blur_code);
- if (j->focus_code) mem_free(j->focus_code);
- if (j->change_code) mem_free(j->change_code);
- if (j->keypress_code) mem_free(j->keypress_code);
- if (j->keyup_code) mem_free(j->keyup_code);
- if (j->keydown_code) mem_free(j->keydown_code);
- mem_free(j);
-}
-
-int compare_js_event_spec(struct js_event_spec *j1, struct js_event_spec *j2)
-{
- if (!j1 && !j2) return 0;
- if (!j1 || !j2) return 1;
- return
- xstrcmp(j1->move_code, j2->move_code) ||
- xstrcmp(j1->over_code, j2->over_code) ||
- xstrcmp(j1->out_code, j2->out_code) ||
- xstrcmp(j1->down_code, j2->down_code) ||
- xstrcmp(j1->up_code, j2->up_code) ||
- xstrcmp(j1->click_code, j2->click_code) ||
- xstrcmp(j1->dbl_code, j2->dbl_code) ||
- xstrcmp(j1->blur_code, j2->blur_code) ||
- xstrcmp(j1->focus_code, j2->focus_code) ||
- xstrcmp(j1->change_code, j2->change_code) ||
- xstrcmp(j1->keypress_code, j2->keypress_code) ||
- xstrcmp(j1->keydown_code, j2->keydown_code) ||
- xstrcmp(j1->keyup_code, j2->keyup_code);
-}
-
-void copy_js_event_spec(struct js_event_spec **target, struct js_event_spec *source)
-{
- struct js_event_spec *t;
- *target = NULL;
- if (!source) return;
- create_js_event_spec(target);
- t = *target;
- t->move_code = stracpy(source->move_code);
- t->over_code = stracpy(source->over_code);
- t->out_code = stracpy(source->out_code);
- t->down_code = stracpy(source->down_code);
- t->up_code = stracpy(source->up_code);
- t->click_code = stracpy(source->click_code);
- t->dbl_code = stracpy(source->dbl_code);
- t->blur_code = stracpy(source->blur_code);
- t->focus_code = stracpy(source->focus_code);
- t->change_code = stracpy(source->change_code);
- t->keypress_code = stracpy(source->keypress_code);
- t->keyup_code = stracpy(source->keyup_code);
- t->keydown_code = stracpy(source->keydown_code);
-}
-
-static inline int copy_string(unsigned char **dest, unsigned char *src)
-{
- if (!src) return 0;
- if (*dest) {
- if (!strcmp(cast_const_char src, cast_const_char *dest)) return 0;
- mem_free(*dest);
- }
- *dest = stracpy(src);
- return 1;
-}
-
-int join_js_event_spec(struct js_event_spec **target, struct js_event_spec *source)
-{
- if (!source) return 0;
- create_js_event_spec(target);
- return
- copy_string(&(*target)->move_code, source->move_code) |
- copy_string(&(*target)->over_code, source->over_code) |
- copy_string(&(*target)->out_code, source->out_code) |
- copy_string(&(*target)->down_code, source->down_code) |
- copy_string(&(*target)->up_code, source->up_code) |
- copy_string(&(*target)->click_code, source->click_code) |
- copy_string(&(*target)->dbl_code, source->dbl_code) |
- copy_string(&(*target)->blur_code, source->blur_code) |
- copy_string(&(*target)->focus_code, source->focus_code) |
- copy_string(&(*target)->change_code, source->change_code) |
- copy_string(&(*target)->keypress_code, source->keypress_code) |
- copy_string(&(*target)->keyup_code, source->keyup_code) |
- copy_string(&(*target)->keydown_code, source->keydown_code);
-}
-
-static void add_event_desc(unsigned char **str, int *l, unsigned char *fn, unsigned char *desc)
-{
- if (!fn) return;
- if (*l) add_to_str(str, l, cast_uchar ", ");
- add_to_str(str, l, desc);
- add_to_str(str, l, cast_uchar ":");
- add_to_str(str, l, fn);
-}
-
-unsigned char *print_js_event_spec(struct js_event_spec *j)
-{
- unsigned char *str = init_str();
- int l = 0;
- if (!j) return str;
- add_event_desc(&str, &l, j->click_code, cast_uchar "onclick");
- add_event_desc(&str, &l, j->dbl_code, cast_uchar "ondblclick");
- add_event_desc(&str, &l, j->down_code, cast_uchar "onmousedown");
- add_event_desc(&str, &l, j->up_code, cast_uchar "onmouseup");
- add_event_desc(&str, &l, j->over_code, cast_uchar "onmouseover");
- add_event_desc(&str, &l, j->out_code, cast_uchar "onmouseout");
- add_event_desc(&str, &l, j->move_code, cast_uchar "onmousemove");
- add_event_desc(&str, &l, j->focus_code, cast_uchar "onfocus");
- add_event_desc(&str, &l, j->blur_code, cast_uchar "onblur");
- add_event_desc(&str, &l, j->change_code, cast_uchar "onchange");
- add_event_desc(&str, &l, j->keypress_code, cast_uchar "onkeypress");
- add_event_desc(&str, &l, j->keyup_code, cast_uchar "onkeyup");
- add_event_desc(&str, &l, j->keydown_code, cast_uchar "onkeydown");
- return str;
-}
-
-#else
-
void free_js_event_spec(struct js_event_spec *j)
{
}
@@ -199,8 +68,6 @@ unsigned char *print_js_event_spec(struct js_event_spec *j)
return stracpy(cast_uchar "");
}
-#endif
-
void check_vs(struct f_data_c *f)
{
struct view_state *vs = f->vs;
@@ -601,11 +468,7 @@ static int get_range(struct f_data *f, int y, int yw, int l, int *s1, int *s2)
static int is_in_range(struct f_data *f, int y, int yw, unsigned char *txt, int *min, int *max)
{
-#ifdef ENABLE_UTF8
int utf8 = f->opt.cp == utf8_table;
-#else
- const int utf8 = 0;
-#endif
int found = 0;
int l;
int s1, s2;
@@ -652,11 +515,7 @@ static int is_in_range(struct f_data *f, int y, int yw, unsigned char *txt, int
static int get_searched(struct f_data_c *scr, struct point **pt, int *pl)
{
-#ifdef ENABLE_UTF8
int utf8 = term_charset(scr->ses->term) == utf8_table;
-#else
- const int utf8 = 0;
-#endif
struct f_data *f = scr->f_data;
int xp = scr->xp;
int yp = scr->yp;
@@ -972,11 +831,9 @@ static void draw_form_entry(struct terminal *t, struct f_data_c *f, struct link
if (!*s) {
chr = '_';
} else {
-#ifdef ENABLE_UTF8
if (term_charset(t) == utf8_table) {
GET_UTF_8(s, chr);
} else
-#endif
chr = *s++;
}
x = l->pos[i].x + xp - vx;
@@ -1263,13 +1120,11 @@ int dump_to_file(struct f_data *fd, int h)
if (c == 1) c = ' ';
if (fd->data[y].d[x].at & ATTR_FRAME && c >= 176 && c < 224) c = frame_dumb[c - 176];
}
-#ifdef ENABLE_UTF8
if (fd->opt.cp == utf8_table && c >= 0x80) {
unsigned char *enc = encode_utf_8(c);
strcpy(cast_char(buf + bptr), cast_const_char enc);
bptr += (int)strlen(cast_const_char enc);
} else
-#endif
{
buf[bptr++] = (unsigned char)c;
}
@@ -2176,13 +2031,6 @@ unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form
return NULL;
}
if (onsubmit)*onsubmit=0;
-#ifdef JS
- if (form->onsubmit)
- {
- jsint_execute_code(f,form->onsubmit,strlen(cast_const_char form->onsubmit),-1,form->form_num,form->form_num, NULL);
- if (onsubmit)*onsubmit=1;
- }
-#endif
if (!form->action) return NULL;
get_succesful_controls(f, form, &submit);
cp_from = term_charset(ses->term);
@@ -2320,18 +2168,11 @@ int enter(struct session *ses, struct f_data_c *f, int a)
unsigned char *u;
link = get_current_link(f);
if (!link) return 1;
-#ifdef JS
- if (link->js_event&&link->js_event->click_code)
- jsint_execute_code(f,link->js_event->click_code,strlen(cast_const_char link->js_event->click_code),-1,(link->type==L_BUTTON&&link->form&&link->form->type==FC_SUBMIT)?link->form->form_num:-1,-1, NULL);
-#endif
if (link->type == L_LINK || link->type == L_BUTTON) {
int has_onsubmit;
if (link->type==L_BUTTON&&link->form->type==FC_BUTTON)return 1;
submit:
if ((u = get_link_url(ses, f, link, &has_onsubmit))) {
-#ifdef JS
- struct js_event_spec *s=link->js_event;
-#endif
if (strlen(cast_const_char u) >= 4 && !casecmp(u, cast_uchar "MAP@", 4)) {
goto_imgmap(ses, f, u + 4, stracpy(u + 4), stracpy(link->target));
} else if (ses->ds.target_in_new_window && link->target && *link->target && !find_frame(ses, link->target, f) && can_open_in_new(ses->term)) { /* open in new window */
@@ -2347,11 +2188,7 @@ int enter(struct session *ses, struct f_data_c *f, int a)
link->target,
f,
(link->type==L_BUTTON&&link->form&&link->form->type==FC_SUBMIT)?link->form->form_num:-1,
-#ifdef JS
- (s&&(/*s->keyup_code||s->keydown_code||s->keypress_code||s->change_code||s->blur_code||s->focus_code||s->move_code||s->over_code||s->out_code||*/s->down_code||s->up_code||s->click_code||s->dbl_code))||has_onsubmit
-#else
0
-#endif
,0,0
);
}
@@ -2392,12 +2229,6 @@ int enter(struct session *ses, struct f_data_c *f, int a)
m = clone_select_menu(link->form->menu);
if (!m) return 1;
/* execute onfocus code of the select object */
-#ifdef JS
- if (link->js_event&&link->js_event->focus_code)
- {
- jsint_execute_code(f,link->js_event->focus_code,strlen(cast_const_char link->js_event->focus_code),-1,-1,-1, NULL);
- }
-#endif
add_empty_window(ses->term, free_select_menu, m);
do_select_submenu(ses->term, m, ses);
return 1;
@@ -2405,19 +2236,6 @@ int enter(struct session *ses, struct f_data_c *f, int a)
if (link->type == L_FIELD || link->type == L_AREA) {
/* pri enteru v textovem policku se bude posilat vzdycky -- Brain */
if (!has_form_submit(f->f_data, link->form) && (!a || !F)) goto submit;
-#ifdef JS
- /* process onfocus handler */
- if (
-#ifdef G
- !ses->locked_link&&
-#endif
- f->vs&&f->f_data&&f->vs->current_link>=0&&f->vs->current_link<f->f_data->nlinks)
- {
- struct link *lnk=&(f->f_data->links[f->vs->current_link]);
- if (lnk->js_event&&lnk->js_event->focus_code)
- jsint_execute_code(f,lnk->js_event->focus_code,strlen(cast_const_char lnk->js_event->focus_code),-1,-1,-1, NULL);
- }
-#endif
#ifdef G
if (F && a) {
ses->locked_link = 1;
@@ -2464,9 +2282,6 @@ void selected_item(struct terminal *term, void *pitem, void *ses_)
{
struct session *ses = (struct session *)ses_;
int item = (int)(my_intptr_t)pitem;
-#ifdef JS
- int old_item=item;
-#endif
struct f_data_c *f = current_frame(ses);
struct link *l;
struct form_state *fs;
@@ -2477,9 +2292,6 @@ void selected_item(struct terminal *term, void *pitem, void *ses_)
form = l->form;
fs = find_form_state(f, form);
if (item >= 0 && item < form->nvalues) {
-#ifdef JS
- old_item = fs->state;
-#endif
fs->state = item;
if (fs->value) mem_free(fs->value);
fs->value = stracpy(form->values[item]);
@@ -2492,16 +2304,6 @@ void selected_item(struct terminal *term, void *pitem, void *ses_)
f->yl = -1;
}
#endif
- /* execute onchange handler */
-#ifdef JS
- if (old_item!=item&&l->js_event&&l->js_event->change_code)
- jsint_execute_code(f,l->js_event->change_code,strlen(cast_const_char l->js_event->change_code),-1,-1,-1, NULL);
-#endif
- /* execute onblur handler */
-#ifdef JS
- if (l->js_event&&l->js_event->blur_code)
- jsint_execute_code(f,l->js_event->blur_code,strlen(cast_const_char l->js_event->blur_code),-1,-1,-1, NULL);
-#endif
draw_to_window(ses->win, draw_doc, f);
change_screen_status(ses);
print_screen_status(ses);
@@ -2591,22 +2393,6 @@ static void set_br_pos(struct f_data_c *fd, struct link *l)
set_form_position(fd, l, &ev);
}
-#ifdef JS
-/* executes onkey-press/up/down handler */
-static void field_op_changed(struct f_data_c *f, struct link *lnk)
-{
- /*
- if (lnk->js_event&&lnk->js_event->keydown_code)
- jsint_execute_code(f,lnk->js_event->keydown_code,strlen(cast_const_char lnk->js_event->keydown_code),-1,-1,-1, NULL);
- if (lnk->js_event&&lnk->js_event->keypress_code)
- jsint_execute_code(f,lnk->js_event->keypress_code,strlen(cast_const_char lnk->js_event->keypress_code),-1,-1,-1, NULL);
- if (lnk->js_event&&lnk->js_event->keyup_code)
- jsint_execute_code(f,lnk->js_event->keyup_code,strlen(cast_const_char lnk->js_event->keyup_code),-1,-1,-1, NULL);
- */
-}
-#endif
-
-
int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct links_event *ev, int rep)
{
struct form_control *form = l->form;
@@ -2643,10 +2429,6 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
memmove(v + fs->state + ll, v + fs->state, strlen(cast_const_char(v + fs->state)) + 1);
memcpy(&v[fs->state], nw, ll);
fs->state += ll;
-#ifdef JS
- fs->changed = 1;
- field_op_changed(f, l);
-#endif
}
goto done;
} else if (!(ev->y & (KBD_SHIFT | KBD_CTRL | KBD_ALT)) && ev->x == KBD_ENTER && form->type == FC_TEXTAREA && (!ses->term->spec->braille || f->vs->brl_in_field)) {
@@ -2656,10 +2438,6 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
fs->value = v;
memmove(v + fs->state + 1, v + fs->state, strlen(cast_const_char(v + fs->state)) + 1);
v[fs->state++] = '\n';
-#ifdef JS
- fs->changed = 1;
- field_op_changed(f, l);
-#endif
}
goto done;
}
@@ -2756,10 +2534,6 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
set_clipboard_text(ses->term, fs->value);
if (!form->ro) fs->value[0] = 0;
fs->state = 0;
-#ifdef JS
- fs->changed = 1;
- field_op_changed(f, l);
-#endif
} else if ((ev->x == KBD_INS && ev->y & KBD_SHIFT) || (upcase(ev->x) == 'V' && ev->y & KBD_CTRL)) {
unsigned char *clipboard;
set_br_pos(f, l);
@@ -2778,10 +2552,6 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
fs->state += (int)strlen(cast_const_char clipboard);
}
mem_free(clipboard);
-#ifdef JS
- fs->changed = 1;
- field_op_changed(f, l);
-#endif
} else if (ev->x == KBD_ENTER) {
x = 0;
} else if (ev->x == KBD_BS) {
@@ -2795,10 +2565,6 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
}
memmove(fs->value + fs->state - ll, fs->value + fs->state, strlen(cast_const_char(fs->value + fs->state)) + 1);
fs->state -= ll;
-#ifdef JS
- fs->changed = 1;
- field_op_changed(f, l);
-#endif
}
} else if (ev->x == KBD_DEL || (upcase(ev->x) == 'D' && ev->y & KBD_CTRL)) {
int ll = 1;
@@ -2812,10 +2578,6 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
}
if (!form->ro && (size_t)fs->state < strlen(cast_const_char fs->value)) {
memmove(fs->value + fs->state, fs->value + fs->state + ll, strlen(cast_const_char(fs->value + fs->state + ll)) + 1);
-#ifdef JS
- fs->changed = 1;
- field_op_changed(f, l);
-#endif
}
} else if (upcase(ev->x) == 'U' && ev->y & KBD_CTRL) {
unsigned char *a;
@@ -2827,10 +2589,6 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
memmove(fs->value, fs->value + fs->state, strlen(cast_const_char(fs->value + fs->state)) + 1);
}
fs->state = 0;
-#ifdef JS
- fs->changed = 1;
- field_op_changed(f, l);
-#endif
} else if (upcase(ev->x) == 'K' && ev->y & KBD_CTRL) {
set_br_pos(f, l);
if (!form->ro) {
@@ -2854,10 +2612,6 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
fs->value[fs->state] = 0;
}
}
-#ifdef JS
- fs->changed = 1;
- field_op_changed(f, l);
-#endif
} else {
b:
f->vs->brl_in_field = 0;
@@ -3249,110 +3003,16 @@ static int is_active_frame(struct session *ses, struct f_data_c *f)
return 0;
}
-#ifdef JS
-static int event_catchable(struct links_event *ev)
-{
- if (ev->ev != EV_KBD) return 0;
- if (ev->x == KBD_TAB || ev->x == KBD_ESC || ev->x == KBD_CTRL_C || ev->x == KBD_CLOSE) return 0;
- return 1;
-}
-
-static int call_keyboard_event(struct f_data_c *fd, unsigned char *code, struct links_event *ev)
-{
- int keycode;
- unsigned char *shiftkey, *ctrlkey, *altkey;
- unsigned char *nc;
- int nl;
- shiftkey = ev->y & KBD_SHIFT ? "true" : "false";
- ctrlkey = ev->y & KBD_CTRL ? "true" : "false";
- altkey = ev->y & KBD_ALT ? "true" : "false";
- if (ev->x >= 0) {
- if (ev->x < 0x80 || term_charset(fd->ses->term) == utf8_table) keycode = ev->x;
- else keycode = cp2u(ev->x, term_charset(fd->ses->term));
- }
- else if (ev->x == KBD_ENTER) keycode = 13;
- else if (ev->x == KBD_BS) keycode = 8;
- else if (ev->x == KBD_TAB) keycode = 9;
- else if (ev->x == KBD_ESC) keycode = 27;
- else if (ev->x == KBD_INS) keycode = 45;
- else if (ev->x == KBD_DEL) keycode = 46;
- else if (ev->x == KBD_PAGE_UP) keycode = 33;
- else if (ev->x == KBD_PAGE_DOWN) keycode = 34;
- else if (ev->x == KBD_END) keycode = 35;
- else if (ev->x == KBD_HOME) keycode = 36;
- else if (ev->x == KBD_LEFT) keycode = 37;
- else if (ev->x == KBD_UP) keycode = 38;
- else if (ev->x == KBD_RIGHT) keycode = 39;
- else if (ev->x == KBD_DOWN) keycode = 40;
- else if (ev->x == KBD_F1) keycode = 112;
- else if (ev->x == KBD_F2) keycode = 113;
- else if (ev->x == KBD_F3) keycode = 114;
- else if (ev->x == KBD_F4) keycode = 115;
- else if (ev->x == KBD_F5) keycode = 116;
- else if (ev->x == KBD_F6) keycode = 117;
- else if (ev->x == KBD_F7) keycode = 118;
- else if (ev->x == KBD_F8) keycode = 119;
- else if (ev->x == KBD_F9) keycode = 120;
- else if (ev->x == KBD_F10) keycode = 121;
- else if (ev->x == KBD_F11) keycode = 122;
- else if (ev->x == KBD_F12) keycode = 123;
- else return -1;
- nc = init_str();
- nl = 0;
- add_to_str(&nc, &nl, cast_uchar "event = new Object(); event.keyCode = ");
- add_num_to_str(&nc, &nl, keycode);
- add_to_str(&nc, &nl, cast_uchar "; event.shiftKey = ");
- add_to_str(&nc, &nl, shiftkey);
- add_to_str(&nc, &nl, cast_uchar "; event.ctrlKey = ");
- add_to_str(&nc, &nl, ctrlkey);
- add_to_str(&nc, &nl, cast_uchar "; event.altKey = ");
- add_to_str(&nc, &nl, altkey);
- add_to_str(&nc, &nl, cast_uchar "; ");
- add_to_str(&nc, &nl, code);
- jsint_execute_code(fd, nc, nl, -1, -1, -1, ev);
- mem_free(nc);
- return 0;
-}
-#endif
-
static int send_to_frame(struct session *ses, struct links_event *ev)
{
int r;
struct f_data_c *fd;
-#ifdef JS
- int previous_link;
-#endif
fd = current_frame(ses);
if (!fd) {
/*internal("document not formatted");*/
return 0;
}
-#ifdef JS
- previous_link=fd->vs ? fd->vs->current_link : -1;
- if (!event_catchable(ev) || !fd->f_data || !fd->vs) goto dont_catch;
- if (fd->vs->current_link >= 0 && fd->vs->current_link < fd->f_data->nlinks) {
- struct link *l = &fd->f_data->links[fd->vs->current_link];
- if (ev->b < EVH_LINK_KEYDOWN_PROCESSED && l->js_event && l->js_event->keydown_code) {
- ev->b = EVH_LINK_KEYDOWN_PROCESSED;
- if (!(call_keyboard_event(fd, l->js_event->keydown_code, ev))) return 1;
- }
- if (ev->b < EVH_LINK_KEYPRESS_PROCESSED && l->js_event && l->js_event->keypress_code) {
- ev->b = EVH_LINK_KEYPRESS_PROCESSED;
- if (!(call_keyboard_event(fd, l->js_event->keypress_code, ev))) return 1;
- }
- }
- if (ev->b < EVH_DOCUMENT_KEYDOWN_PROCESSED && fd->f_data->js_event && fd->f_data->js_event->keydown_code) {
- ev->b = EVH_DOCUMENT_KEYDOWN_PROCESSED;
- if (!(call_keyboard_event(fd, fd->f_data->js_event->keydown_code, ev))) return 1;
- }
- if (ev->b < EVH_DOCUMENT_KEYPRESS_PROCESSED && fd->f_data->js_event && fd->f_data->js_event->keypress_code) {
- ev->b = EVH_DOCUMENT_KEYPRESS_PROCESSED;
- if (!(call_keyboard_event(fd, fd->f_data->js_event->keypress_code, ev))) return 1;
- }
- dont_catch:
-#endif
-
if (!F) r = frame_ev(ses, fd, ev);
#ifdef G
else r = g_frame_ev(ses, fd, ev);
@@ -3365,35 +3025,6 @@ static int send_to_frame(struct session *ses, struct links_event *ev)
}
if (r == 3) draw_fd_nrd(fd);
if (!F && fd->vs) {
-#ifdef JS
- if (previous_link!=fd->vs->current_link&&fd->f_data&&previous_link>=0&&previous_link<fd->f_data->nlinks) /* link has changed */
- {
- struct link *l=&(fd->f_data->links[previous_link]);
-
- /* process onchange code, if previous link was a textarea or a textfield and has changed */
- if (l->type==L_FIELD||l->type==L_AREA) {
- struct form_state *fs = find_form_state(fd,l->form);
- if (fs->changed && l->js_event && l->js_event->change_code)
- fs->changed=0, jsint_execute_code(fd, l->js_event->change_code, strlen(cast_const_char l->js_event->change_code), -1, -1, -1, NULL);
- }
-
- /* process blur and mouse-out handlers */
- 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);
- if (l->js_event&&l->js_event->out_code)
- jsint_execute_code(fd,l->js_event->out_code,strlen(cast_const_char l->js_event->out_code),-1,-1,-1, NULL);
- }
- if (previous_link!=fd->vs->current_link&&fd->f_data&&fd->vs->current_link>=0&&fd->vs->current_link<fd->f_data->nlinks)
- {
- struct link *l=&(fd->f_data->links[fd->vs->current_link]);
-
- /* process focus and mouse-over handlers */
- 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);
- if (l->js_event&&l->js_event->over_code)
- jsint_execute_code(fd,l->js_event->over_code,strlen(cast_const_char l->js_event->over_code),-1,-1,-1, NULL);
- }
-#endif
}
return r;
}
@@ -3625,23 +3256,6 @@ void send_event(struct session *ses, struct links_event *ev)
if (ses->locked_link) {
if ((ev->b & BM_ACT) != B_MOVE) {
ses->locked_link = 0;
-#ifdef JS
- /* process onblur handler of current link */
- if (ses->screen&&ses->screen->vs&&ses->screen->f_data&&ses->screen->vs->current_link>=0&&ses->screen->vs->current_link<ses->screen->f_data->nlinks)
- {
- struct link *lnk=&(ses->screen->f_data->links[ses->screen->vs->current_link]);
- /* select se dela jinde */
- if (lnk->type!=L_SELECT&&lnk->js_event&&lnk->js_event->blur_code)
- jsint_execute_code(current_frame(ses),lnk->js_event->blur_code,strlen(cast_const_char lnk->js_event->blur_code),-1,-1,-1, NULL);
-
- /* execute onchange handler of text field/area */
- if ((lnk->type==L_AREA||lnk->type==L_FIELD)) {
- struct form_state *fs = find_form_state(ses->screen,lnk->form);
- if (fs->changed && lnk->js_event && lnk->js_event->change_code)
- fs->changed = 0, jsint_execute_code(current_frame(ses), lnk->js_event->change_code, strlen(cast_const_char lnk->js_event->change_code), -1, -1, -1, NULL);
- }
- }
-#endif
clr_xl(ses->screen);
draw_formatted(ses);
} else return;
diff --git a/view_gr.c b/view_gr.c
@@ -855,20 +855,6 @@ void g_text_mouse(struct f_data_c *fd, struct g_object *a_, int x, int y, int b)
int e;
g_set_current_link(fd, a, x, y, (b == (B_UP | B_LEFT)));
-#ifdef JS
- if (fd->vs && fd->f_data && fd->vs->current_link >= 0 && fd->vs->current_link < fd->f_data->nlinks) {
- /* fd->vs->current links is a valid link */
-
- struct link *l = &fd->f_data->links[fd->vs->current_link];
-
- if (l->js_event && l->js_event->up_code && (b & BM_ACT) == B_UP)
- jsint_execute_code(fd, l->js_event->up_code, strlen(cast_const_char l->js_event->up_code), -1, -1, -1, NULL);
-
- if (l->js_event && l->js_event->down_code && (b & BM_ACT) == B_DOWN)
- jsint_execute_code(fd, l->js_event->down_code, strlen(cast_const_char l->js_event->down_code), -1, -1, -1, NULL);
- }
-#endif
-
if (b == (B_UP | B_LEFT)) {
int ix = ismap_x, iy = ismap_y, il = ismap_link;
ismap_x = x;
@@ -1201,22 +1187,6 @@ int g_frame_ev(struct session *ses, struct f_data_c *fd, struct links_event *ev)
fd->f_data->start_highlight_y = -1;
}
-#ifdef JS
- /* process onmouseover/onmouseout handlers */
- if (previous_link!=fd->vs->current_link)
- {
- struct link* lnk=NULL;
-
- if (previous_link>=0&&previous_link<fd->f_data->nlinks)lnk=&(fd->f_data->links[previous_link]);
- if (lnk&&lnk->js_event&&lnk->js_event->out_code)
- jsint_execute_code(fd,lnk->js_event->out_code,strlen(cast_const_char lnk->js_event->out_code),-1,-1,-1, NULL);
- lnk=NULL;
- if (fd->vs->current_link>=0&&fd->vs->current_link<fd->f_data->nlinks)lnk=&(fd->f_data->links[fd->vs->current_link]);
- if (lnk&&lnk->js_event&&lnk->js_event->over_code)
- jsint_execute_code(fd,lnk->js_event->over_code,strlen(cast_const_char lnk->js_event->over_code),-1,-1,-1, NULL);
- }
-#endif
-
if ((ev->b & BM_ACT) == B_DOWN && (ev->b & BM_BUTT) == B_RIGHT && fd->vs->current_link == -1) goto scrll;
break;
case EV_KBD:
diff --git a/vpipe.inc b/vpipe.inc
@@ -159,10 +159,6 @@ static int vpipe_create(int *fd)
pipe_flags[fd[0]] = 0;
pipe_desc[fd[1]] = desc;
pipe_flags[fd[1]] = VIRTUAL_PIPE_FLAG_WRITE;
-#ifdef DOS
- pipe_flags[fd[0]] |= VIRTUAL_PIPE_FLAG_NONBLOCK;
- pipe_flags[fd[1]] |= VIRTUAL_PIPE_FLAG_NONBLOCK;
-#endif
pipe_unlock();
return 0;
err2:
diff --git a/x.c b/x.c
@@ -230,19 +230,11 @@ static void x_do_flush(void *ignore)
static inline void X_FLUSH(void)
{
-#ifdef INTERIX
- /*
- * Interix has some bug, it locks up in _XWaitForWritable.
- * As a workaround, do synchronous flushes.
- */
- x_do_flush(NULL);
-#else
if (!flush_in_progress)
{
register_bottom_half(x_do_flush, NULL);
flush_in_progress=1;
}
-#endif
}
static int (*old_error_handler)(Display *, XErrorEvent *) = NULL;
@@ -661,10 +653,6 @@ static void x_process_events(void *data)
int last_was_mouse;
int replay_event = 0;
-#ifdef OPENVMS
- clear_events(x_fd, 0);
-#endif
-
process_events_in_progress = 0;
#ifdef SC_DEBUG
@@ -1077,7 +1065,7 @@ static unsigned char *x_init_driver(unsigned char *param, unsigned char *display
}
#endif
x_input_encoding=-1;
-#if defined(HAVE_NL_LANGINFO) && defined(HAVE_LANGINFO_H) && defined(CODESET) && !defined(WIN) && !defined(INTERIX)
+#if defined(HAVE_NL_LANGINFO) && defined(HAVE_LANGINFO_H) && defined(CODESET) && !defined(WIN)
{
unsigned char *cp;
cp = cast_uchar nl_langinfo(CODESET);
@@ -1099,7 +1087,7 @@ static unsigned char *x_init_driver(unsigned char *param, unsigned char *display
*/
if (!display) display = cast_uchar getenv("DISPLAY");
-#if !defined(__linux__) && !defined(OPENVMS)
+#if !defined(__linux__)
/* on Linux, do not assume XWINDOW present if $DISPLAY is not set
--- rather open links on svgalib or framebuffer console */
if (!display) display = cast_uchar ":0.0"; /* needed for MacOS X */
@@ -1415,9 +1403,6 @@ visual_found:;
) x_driver.flags|=GD_NEED_CODEPAGE;
x_fd=XConnectionNumber(x_display);
-#ifdef OPENVMS
- x_fd=vms_x11_fd(x_fd);
-#endif
set_handlers(x_fd, x_process_events, NULL, NULL);
XSync(x_display, False);
X_SCHEDULE_PROCESS_EVENTS();
diff --git a/xbm.c b/xbm.c
@@ -1,300 +0,0 @@
-/* xbm.c
- * portable bitmap format (xbm) decoder
- * (c) 2002 Petr 'Brain' Kulhavy
- * This file is a part of the Links program, released under GPL
- */
-
-#include "cfg.h"
-
-#ifdef G
-
-#include "links.h"
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-
-
-#define XBM_BUFFER_LEN 1024
-
-#ifdef min
-#undef min
-#endif
-#ifdef max
-#undef max
-#endif
-#define min(a,b) (a<b?a:b)
-#define max(a,b) (a>b?a:b)
-
-struct xbm_decoder{
- int width, height; /* rozmery obrazku */
- int partnum; /* buffer skoncil uprostred cisla */
- int *numdest; /* kam se ma ukladat to cislo kdyz je partnum */
- int in_data_block; /* jsme v bloku dat (uz jsme precetli otviraci slozenou zavorku) */
- int image_pos; /* pixelova pozice v cimg->buffer */
- int pixels; /* velikost cimg->buffer v pixelech */
- int state; /* stav automatu na zrani komentaru */
- int actual_eight; /* aktualni cislo, ktere se ma putnout do cimg */
- int line_pos; /* aktualni pozice pixelu na radce (kolik pixelu v cimg->buffer je platnych na momentalne zpracovavane radce) */
- unsigned char barvicky[6]; /* 0-2 background, 3-5 foreground */
-/*
- * stavy:
- * 0 - mimo komentar
- * 1 - za 1. lomitkem
- * 2 - za 1. lomitkem a hvezdickou
- * 3 - za 2. hvezdickou
- */
- int buffer_pos; /* delka platnych dat v bufferu */
- unsigned char buffer[XBM_BUFFER_LEN];
-};
-
-
-static unsigned char *my_memmem(unsigned char *h, int hl, unsigned char *n, int nl)
-{
- for (;hl>=nl;hl--,h++)
- if (*h==*n&&!memcmp(h,n,nl))return h;
- return NULL;
-}
-
-
-void xbm_start(struct cached_image *cimg)
-{
- struct xbm_decoder *deco;
- unsigned short r,g,b;
-
- deco=mem_alloc(sizeof(struct xbm_decoder));
- cimg->decoder=deco;
- deco->state=0;
- deco->width=-1;
- deco->height=-1;
- deco->buffer_pos=0;
- deco->partnum=0;
- deco->in_data_block=0;
-
- round_color_sRGB_to_48(&r,&g,&b,cimg->background_color);
- deco->barvicky[0]=ags_16_to_8(r,(float)display_red_gamma);
- deco->barvicky[1]=ags_16_to_8(g,(float)display_green_gamma);
- deco->barvicky[2]=ags_16_to_8(b,(float)display_blue_gamma);
-
- round_color_sRGB_to_48(&r,&g,&b,get_foreground(cimg->background_color));
- deco->barvicky[3]=ags_16_to_8(r,(float)display_red_gamma);
- deco->barvicky[4]=ags_16_to_8(g,(float)display_green_gamma);
- deco->barvicky[5]=ags_16_to_8(b,(float)display_blue_gamma);
-}
-
-/* vrati cislo, nebo -1, kdyz to neni cislo, a nastavi p a l na posledni necislici */
-static inline int xbm_read_num(unsigned char **p,int *l,int *partnum,int *digits, int *base)
-{
- static int a=-1;
- static int b=10;
- static int d=0;
- int retval;
- int was_partnum=*partnum;
- *partnum=0;
-
- dalsi_runda:
- if (!(*l))return a;
- **p=tolower(**p);
- if (!was_partnum&&b==10&&((**p)<'0'||(**p)>'9'))goto smitec; /* tohle neni cislo, to si strc nekam... */
- if (b==16&&((**p)<'a'||(**p>'f'))&&((**p)<'0'||(**p)>'9'))goto smitec;
- if (a==-1)a=0;
- for (;*l&&(((**p)>='0'&&(**p)<='9')||(b==16&&(**p)>='a'&&(**p)<='f'));(*l)--,(*p)++){d++;a*=b;a+=((**p)>='a'?10+(**p)-'a':(**p)-'0');}
- if (b==10&&!a&&(*l)&&((**p)|32)=='x'){b=16;d=0;(*p)++;(*l)--;if (!*l)*partnum=1;goto dalsi_runda;}
- smitec:
- retval=a;
- if (!*l)*partnum=1;
- else a=-1,*base=b,b=10,*digits=d,d=0;
- return retval;
-}
-
-
-static inline void xbm_skip_space_tab(unsigned char **p, int *l)
-{
- for (;*l&&(**p==' '||**p==9);(*l)--,(*p)++)
- ;
-}
-
-
-static inline void xbm_skip_whitespace(unsigned char **p, int *l)
-{
- for (;*l&&((**p)>'9'||(**p)<'0');(*l)--,(*p)++)
- ;
-}
-
-
-static inline void put_eight(struct cached_image *cimg,int bits)
-{
- struct xbm_decoder *deco=(struct xbm_decoder *)cimg->decoder;
- int ten_napis_v_s3_nekecal;
-
- for (ten_napis_v_s3_nekecal=0;ten_napis_v_s3_nekecal<bits&&deco->image_pos<deco->pixels&&deco->line_pos<cimg->width;ten_napis_v_s3_nekecal++,deco->image_pos++,deco->line_pos++)
- {
- memcpy(cimg->buffer+deco->image_pos*3,deco->barvicky+((deco->actual_eight)&1)*3,3);
- deco->actual_eight>>=1;
- cimg->rows_added=1;
- }
- if (deco->line_pos==cimg->width)
- deco->line_pos=0,deco->actual_eight=0;
-}
-
-
-/* opravdovy dekoder xbm, data jsou bez komentaru */
-/* length is always !=NULL */
-static int xbm_decode(struct cached_image *cimg, unsigned char *data, int length)
-{
- struct xbm_decoder *deco=(struct xbm_decoder *)cimg->decoder;
- /* okurky v decu ;-) */
- int a;
- int must_return=0;
-
-restart_again:
- if (must_return&&!length)return 0;
- must_return=0;
- a=min(length,XBM_BUFFER_LEN-deco->buffer_pos);
- memcpy(deco->buffer+deco->buffer_pos,data,a);
- length-=a;
- deco->buffer_pos+=a;
- if (!deco->buffer_pos)return 0; /* z toho nic plodnyho nevznikne */
- data+=a;
- if (!deco->in_data_block&&deco->partnum)
- {
- unsigned char *p;
- int a;
- int b,d;
- p=deco->buffer;
- a=deco->buffer_pos;
- *(deco->numdest)=xbm_read_num(&p,&a,&(deco->partnum),&d,&b);
- /* p i a ukazuje na 1. neciselnej znak (at uz za mezerama bylo cislo nebo nebylo) */
- memmove(deco->buffer,p,a);
- deco->buffer_pos=a;
- if (deco->partnum){must_return=1;goto restart_again;} /* zase konec bufferu */
- }
- if (deco->width<0||deco->height<0) /* decoding header */
- {
- unsigned char *p,*q;
- int *d;
- int a;
- int base, digits;
-
- p=my_memmem(deco->buffer,deco->buffer_pos,cast_uchar "width",5);
- q=my_memmem(deco->buffer,deco->buffer_pos,cast_uchar "height",6);
-
- if (!p&&!q) /* sezereme zacatek */
- {
- int a=deco->buffer_pos>5?deco->buffer_pos:0; /* nesmime ukrast kus width/height */
- memmove(deco->buffer,deco->buffer+deco->buffer_pos-a,deco->buffer_pos-a); /* sezereme to pred width/height */
- deco->buffer_pos-=a;
- must_return=1;
- goto restart_again;
- }
-
- p=p&&q?min(p,q):max(p,q); /* bereme vetsi, protoze ten 2. je NULL */
- memmove(deco->buffer,p,(deco->buffer_pos)+(deco->buffer)-p); /* sezereme to pred width/height */
- deco->buffer_pos-=(int)(p-deco->buffer);
- /* deco->buffer zacina height/width */
- if (deco->buffer[0]=='w'){p=deco->buffer+5;d=&(deco->width);}
- else {p=deco->buffer+6;d=&(deco->height);}
-
- a=(int)(deco->buffer_pos+deco->buffer-p);
- xbm_skip_space_tab(&p,&a);
- if (!a){must_return=1;goto restart_again;} /* v bufferu je: width/height, whitespace, konec */
- *d=xbm_read_num(&p,&a,&(deco->partnum),&digits, &base);
- if (deco->partnum)deco->numdest=d,must_return=1;
- /* p i a ukazuje na 1. neciselnej znak (at uz za mezerama bylo cislo nebo nebylo) */
- memmove(deco->buffer,p,a);
- deco->buffer_pos=a;
- goto restart_again;
- }
- else /* decoding data */
- {
- unsigned char *p;
- int a;
- int d=0,b=10;
- if (!deco->in_data_block)
- {
- p=memchr(deco->buffer,'{',deco->buffer_pos);
- if (!p){deco->buffer_pos=0;must_return=1;goto restart_again;} /* sezerem celej blok a cekame na zavorku */
-
- cimg->width=deco->width;
- cimg->height=deco->height;
- cimg->buffer_bytes_per_pixel=3;
- cimg->red_gamma=(float)display_red_gamma;
- cimg->green_gamma=(float)display_green_gamma;
- cimg->blue_gamma=(float)display_blue_gamma;
- cimg->strip_optimized=0;
- if (header_dimensions_known(cimg)) {img_end(cimg);return 1;}
-
- deco->in_data_block=1;
- p++;
- memmove(deco->buffer,p,deco->buffer_pos+deco->buffer-p); /* sezereme to pred width/height */
- deco->buffer_pos-=(int)(p-deco->buffer);
- deco->image_pos=0;
- deco->pixels=deco->width*deco->height;
- deco->line_pos=0;
- }
- p=deco->buffer;
- a=deco->buffer_pos;
- if (!deco->partnum) xbm_skip_whitespace(&p,&a);
- if (!a){must_return=1; goto restart_again;}
- deco->actual_eight=xbm_read_num(&p,&a,&(deco->partnum),&d,&b);
- memmove(deco->buffer,p,a);
- deco->buffer_pos=a;
- if (deco->partnum)must_return=1;
- else put_eight(cimg,(b==16&&d>2)||(b==10&&deco->actual_eight>255)?16:8);
- if (deco->image_pos>=deco->pixels) {img_end(cimg);return 1;}
- goto restart_again;
- }
-}
-
-
-/* skip comments and call real decoding function */
-void xbm_restart(struct cached_image *cimg, unsigned char *data, int length)
-{
- struct xbm_decoder *deco=(struct xbm_decoder*)cimg->decoder;
-
-cycle_again:
-
- if (!length)return;
- switch(deco->state)
- {
- case 0: /* mimo komentar */
- {
- unsigned char *p;
- p=memchr(data,'/',length);
- if (!p){xbm_decode(cimg, data, length);return;}
- if (xbm_decode(cimg, data, (int)(p-data))) return;
- length-=(int)(p-data+1);
- data=p+1; /* preskocim lomitko */
- deco->state=1;
- goto cycle_again;
- }
-
- case 1: /* za 1. lomitkem */
- {
- if (*data=='*'){deco->state=2;data++;length--;goto cycle_again;} /* zacal komentar */
- if (xbm_decode(cimg, cast_uchar "/", 1)) return;
- deco->state=0; /* to nebyl komentar */
- goto cycle_again;
- }
-
- case 2: /* za lomeno hvezdicka (uvnitr komentare) */
- {
- unsigned char *p;
- p=memchr(data,'*',length);
- if (!p)return; /* furt komentar */
- length-=(int)(p-data+1);
- data=p+1; /* preskocim hvezdicku */
- deco->state=3;
- goto cycle_again;
- }
-
- case 3: /* za 2. hvezdickou */
- {
- if (*data=='/'){data++;length--;deco->state=0;goto cycle_again;} /* skoncil komentar */
- deco->state=2;
- data++;
- length--;
- goto cycle_again;
- }
- }
-}
-#endif /* G */