about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTDOS.c
blob: 582a7626b0dd7345f7bdc8e99b17d6c575e2779a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
// $LynxId: lynx_cfg.h,v 1.3 2009/11/21 16:33:41 tom Exp $
// definitions abstracted from makefile.msc

#ifndef LYNX_CFG_H
#define LYNX_CFG_H 1

#define __WIN32__
#define _WINDOWS
#define _WIN32_WINNT 0x0400
#define WIN32_LEAN_AND_MEAN 1	pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * $LynxId: HTDOS.c,v 1.39 2011/06/04 18:45:09 tom Exp $
 *							DOS specific routines
 */

#include <HTUtils.h>
#include <LYUtils.h>
#include <HTDOS.h>
#include <LYStrings.h>

#include <LYLeaks.h>

#ifdef _WINDOWS
#include <LYGlobalDefs.h>
#include <HTAlert.h>
#endif

/*
 * Make a copy of the source argument in the result, allowing some extra
 * space so we can append directly onto the result without reallocating.
 */
static char *copy_plus(char **result, const char *source)
{
    int length = (int) strlen(source);
    int extra = 10;
    int n;

    for (n = 0; n < length; ++n) {
	if (source[n] == ' ')
	    ++extra;
    }

    HTSprintf0(result, "%-*s", length + extra, source);
    (*result)[length] = 0;
    return (*result);
}

/* PUBLIC							HTDOS_wwwName()
 *		CONVERTS DOS Name into WWW Name
 * ON ENTRY:
 *	dosname		DOS file specification (NO NODE)
 *
 * ON EXIT:
 *	returns		WWW file specification
 *
 */
const char *HTDOS_wwwName(const char *dosname)
{
    static char *wwwname = NULL;
    char *cp_url = copy_plus(&wwwname, dosname);
    int wwwname_len;
    char ch;

    while ((ch = *dosname) != '\0') {
	switch (ch) {
	case '\\':
	    /* convert dos backslash to unix-style */
	    *cp_url++ = '/';
	    break;
	case ' ':
	    *cp_url++ = '%';
	    *cp_url++ = '2';
	    *cp_url++ = '0';
	    break;
	default:
	    *cp_url++ = ch;
	    break;
	}
	dosname++;
    }
    *cp_url = '\0';

    wwwname_len = (int) strlen(wwwname);
    if (wwwname_len > 1)
	cp_url--;		/* point last char */

    if (wwwname_len > 3 && *cp_url == '/') {
	cp_url++;
	*cp_url = '\0';
    }
    return (wwwname);
}

/*
 * Convert slashes from Unix to DOS
 */
char *HTDOS_slashes(char *path)
{
    char *s;

    for (s = path; *s != '\0'; ++s) {
	if (*s == '/') {
	    *s = '\\';
	}
    }
    return path;
}

/* PUBLIC							HTDOS_name()
 *		CONVERTS WWW name into a DOS name
 * ON ENTRY:
 *	wwwname		WWW file name
 *
 * ON EXIT:
 *	returns		DOS file specification
 */
char *HTDOS_name(const char *wwwname)
{
    static char *result = NULL;
    int joe;

#if defined(SH_EX)		/* 2000/03/07 (Tue) 18:32:42 */
    if (unsafe_filename(wwwname)) {
	HTUserMsg2("unsafe filename : %s", wwwname);
	copy_plus(&result, "BAD_LOCAL_FILE_NAME");
    } else {
	copy_plus(&result, wwwname);
    }
#else
    copy_plus(&result, wwwname);
#endif
#ifdef __DJGPP__
    if (result[0] == '/'
	&& result[1] == 'd'
	&& result[2] == 'e'
	&& result[3] == 'v'
	&& result[4] == '/'
	&& isalpha(result[5])) {
	return (result);
    }
#endif /* __DJGPP__ */

    (void) HTDOS_slashes(result);

    /* pesky leading slash, rudiment from file://localhost/  */
    /* the rest of path may be with or without drive letter  */
    if ((result[1] != '\\') && (result[0] == '\\')) {
	for (joe = 0; (result[joe] = result[joe + 1]) != 0; joe++) ;
    }
    /* convert '|' after the drive letter to ':' */
    if (isalpha(UCH(result[0])) && result[1] == '|') {
	result[1] = ':';
    }
#ifdef _WINDOWS			/* 1998/04/02 (Thu) 08:59:48 */
    if (LYLastPathSep(result) != NULL
	&& !LYIsDosDrive(result)) {
	char temp_buff[LY_MAXPATH];

	sprintf(temp_buff, "%.3s\\%.*s", windows_drive,
		(int) (sizeof(temp_buff) - 5), result);
	StrAllocCopy(result, temp_buff);
    }
#endif
    /*
     * If we have only a device, add a trailing slash.  Otherwise it just
     * refers to the current directory on the given device.
     */
    if (LYLastPathSep(result) == NULL
	&& LYIsDosDrive(result))
	LYAddPathSep0(result);

    CTRACE((tfp, "HTDOS_name changed `%s' to `%s'\n", wwwname, result));
    return (result);
}

#ifdef WIN_EX
char *HTDOS_short_name(const char *path)
{
    static char sbuf[LY_MAXPATH];
    char *ret;
    DWORD r;

    if (strchr(path, '/'))
	path = HTDOS_name(path);
    r = GetShortPathName(path, sbuf, sizeof sbuf);
    if (r >= sizeof(sbuf) || r == 0) {
	ret = LYStrNCpy(sbuf, path, sizeof(sbuf));
    } else {
	ret = sbuf;
    }
    return ret;
}
#endif

#if defined(DJGPP)
/*
 * Poll tcp/ip lib and yield to DPMI-host while nothing in
 * keyboard buffer (head = tail) (simpler than kbhit).
 * This is required to be able to finish off dead sockets,
 * answer pings etc.
 */
#include <pc.h>
#include <dpmi.h>
#include <libc/farptrgs.h>
#include <go32.h>

void djgpp_idle_loop(void)
{
    while (_farpeekw(_dos_ds, 0x41a) == _farpeekw(_dos_ds, 0x41c)) {
	tcp_tick(NULL);
	__dpmi_yield();
#if defined(USE_SLANG)
	if (SLang_input_pending(1))
	    break;
#endif
    }
}

/* PUBLIC       getxkey()
 *              Replaces libc's getxkey() with polling of tcp/ip
 *              library (WatTcp or Watt-32). *
 * ON EXIT:
 *      returns extended keypress.
 */

/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */

int getxkey(void)
{
#if defined(DJGPP_KEYHANDLER)
    __dpmi_regs r;

    djgpp_idle_loop();

    r.h.ah = 0x10;
    __dpmi_int(0x16, &r);

    if (r.h.al == 0x00)
	return 0x0100 | r.h.ah;
    if (r.h.al == 0xe0)
	return 0x0200 | r.h.ah;
    return r.h.al;

#elif defined(USE_SLANG)
    djgpp_idle_loop();
    return SLkp_getkey();
#else
    /* PDcurses uses myGetChar() in LYString.c */
#endif
}
#endif /* DJGPP */