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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/* DOS specific routines
*/
#include <HTUtils.h>
#include <LYUtils.h>
#include <HTDOS.h>
#include <LYStrings.h>
#include <LYLeaks.h>
/*
* 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 = strlen(source);
HTSprintf0(result, "%-*s", length + 10, 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;
#ifdef SH_EX
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';
#else
for (; *cp_url != '\0'; cp_url++)
if (*cp_url == '\\')
*cp_url = '/'; /* convert dos backslash to unix-style */
#endif
wwwname_len = 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(char *wwwname)
{
#ifdef _WINDOWS /* 1998/04/02 (Thu) 08:47:20 */
extern char windows_drive[];
char temp_buff[LY_MAXPATH];
#endif
static char *result = NULL;
int joe;
copy_plus(&result, wwwname);
#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++) ;
}
#ifdef _WINDOWS /* 1998/04/02 (Thu) 08:59:48 */
if (LYLastPathSep(result) != NULL
&& !LYIsDosDrive(result)) {
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(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) && defined(DJGPP_KEYHANDLER)
/* PUBLIC getxkey()
* Replaces libc's getxkey() with polling of tcp/ip
* library (WatTcp or Watt-32). This is required to
* be able to finish off dead sockets, answer pings etc.
*
* ON EXIT:
* returns extended keypress.
*/
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pc.h>
#include <dpmi.h>
#include <libc/farptrgs.h>
#include <go32.h>
int getxkey(void)
{
__dpmi_regs r;
/* poll tcp/ip lib and yield to DPMI-host while nothing in
* keyboard buffer (head = tail) (simpler than kbhit).
*/
while (_farpeekw(_dos_ds, 0x41a) == _farpeekw(_dos_ds, 0x41c)) {
tcp_tick(NULL);
__dpmi_yield();
}
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;
}
#endif /* DJGPP && DJGPP_KEYHANDLER */
|