1 /* Win32 support fo ELinks. It has pretty different life than rest of ELinks. */
7 /* Get SHGFP_TYPE_CURRENT from <shlobj.h>. */
8 #define _WIN32_IE 0x500
13 #include "osdep/system.h"
28 #include "main/select.h"
29 #include "osdep/win32/win32.h"
30 #include "osdep/osdep.h"
31 #include "terminal/terminal.h"
37 #ifdef CONFIG_OS_WIN32
39 WORD ver
= MAKEWORD(1,1);
43 if (WSAStartup(ver
,&ws
) != 0) {
44 printf("Failed to initialise Winsock ver %d.%d\n", ver
>> 8, ver
& 255);
49 setlocale(LC_ALL
, "");
56 if (!getenv("CHARSET") && cp
> 0)
58 snprintf (buf
, sizeof(buf
), "CHARSET=cp%u", cp
);
78 handle_terminal_resize(int fd
, void (*fn
)())
83 unhandle_terminal_resize(int fd
)
88 get_terminal_size(int fd
, int *x
, int *y
)
90 CONSOLE_SCREEN_BUFFER_INFO csbi
;
92 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE
), &csbi
);
95 *x
= get_e("COLUMNS");
97 *x
= csbi
.srWindow
.Right
- csbi
.srWindow
.Left
+ 1;
102 *y
= csbi
.srWindow
.Bottom
- csbi
.srWindow
.Top
+ 1;
108 exe(unsigned char *path
)
111 unsigned char *shell
= get_shell();
112 unsigned char *x
= *path
!= '"' ? " /c start /wait " : " /c start /wait \"\" ";
113 unsigned char *p
= malloc((strlen(shell
) + strlen(x
) + strlen(path
)) * 2 + 1);
124 memmove(x
+ 1, x
, strlen(x
) + 1);
140 return get_input_handle();
144 #if defined(HAVE_BEGINTHREAD)
147 void (*fn
)(void *, int);
149 unsigned char data
[1];
152 extern void bgt(struct tdata
*t
);
155 start_thread(void (*fn
)(void *, int), void *ptr
, int l
)
163 t
= malloc(sizeof(*t
) + l
);
168 memcpy(t
->data
, ptr
, l
);
169 if (_beginthread((void (*)(void *)) bgt
, 65536, t
) == -1) {
182 get_input_handle(void)
184 static HANDLE hStdIn
= INVALID_HANDLE_VALUE
;
186 if (hStdIn
== INVALID_HANDLE_VALUE
) {
189 SetConsoleTitle("ELinks - Console mode browser");
191 hStdIn
= GetStdHandle(STD_INPUT_HANDLE
);
192 GetConsoleMode(hStdIn
, &dwMode
);
193 dwMode
&= ~(ENABLE_LINE_INPUT
| ENABLE_ECHO_INPUT
);
194 dwMode
|= (ENABLE_WINDOW_INPUT
| ENABLE_MOUSE_INPUT
);
195 SetConsoleMode(hStdIn
, dwMode
);
201 get_output_handle(void)
203 static HANDLE hStdOut
= INVALID_HANDLE_VALUE
;
205 if (hStdOut
== INVALID_HANDLE_VALUE
)
206 hStdOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
207 return (int) hStdOut
;
211 gettimeofday(struct timeval
* p
, void* tz
)
214 long long ns100
; /*time since 1 Jan 1601 in 100ns units */
219 GetSystemTimeAsFileTime (&_now
.ft
);
220 p
->tv_usec
= (long) ((_now
.ns100
/ 10LL) % 1000000LL);
221 p
->tv_sec
= (long) ((_now
.ns100
- 116444736000000000LL) / 10000000LL);
227 mkstemp(char *template)
229 char tempname
[MAX_PATH
];
230 char pathname
[MAX_PATH
];
232 /* Get the directory for temp files */
233 GetTempPath(MAX_PATH
, pathname
);
235 /* Create a temporary file. */
236 GetTempFileName(pathname
, template, 0, tempname
);
238 return open(tempname
, O_CREAT
| O_WRONLY
| O_EXCL
| O_BINARY
);
242 tcgetattr(int fd
, struct termios
*_termios_p
)
250 tcsetattr(int fd
, int _optional_actions
, const struct termios
*_termios_p
)
253 (void) _optional_actions
;
260 gettext__parse(void *arg
)
267 user_appdata_directory(void)
269 #if _WIN32_WINNT >= 0x0500
270 HWND hwnd
= GetConsoleWindow();
277 hr
= SHGetFolderPath(hwnd
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, path
);
278 if (hr
== S_OK
) /* Don't even allow S_FALSE. */
279 return stracpy(path
);