442
|
1 /* Utility routines for XEmacs on Windows 9x, NT and Cygwin.
|
2367
|
2 Copyright (C) 2000, 2001, 2002, 2004 Ben Wing.
|
442
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to the Free
|
|
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
19 02111-1307, USA. */
|
|
20
|
|
21 #include <config.h>
|
|
22 #include "lisp.h"
|
|
23
|
|
24 #include "buffer.h"
|
771
|
25 #include "console-msw.h"
|
611
|
26
|
771
|
27 #include "sysfile.h"
|
|
28 #include "sysproc.h"
|
859
|
29 #include "syssignal.h"
|
611
|
30 #include "systime.h"
|
442
|
31
|
2367
|
32
|
|
33
|
|
34 /*
|
|
35
|
|
36 Info on Windows issues:
|
|
37
|
|
38 (Info-goto-node "(internals)Interface to MS Windows")
|
|
39
|
|
40 ------- @file{src/config.h}.in vs. @file{nt/xemacs.mak} -------
|
|
41
|
|
42 See @file{src/config.h.in} more more info.
|
|
43 */
|
|
44
|
771
|
45 /* Control conversion of upper case file names to lower case.
|
|
46 nil means no, t means yes. */
|
|
47 Lisp_Object Vmswindows_downcase_file_names;
|
|
48
|
|
49 int mswindows_windows9x_p;
|
|
50
|
442
|
51 pfSwitchToThread_t xSwitchToThread;
|
|
52
|
771
|
53 pfNetUserEnum_t xNetUserEnum;
|
|
54 pfNetApiBufferFree_t xNetApiBufferFree;
|
|
55
|
|
56 /* Convert a filename in standard Win32 format into our internal format
|
|
57 (which may be significantly different if we're running on Cygwin), and
|
|
58 turn it into a file: URL. Return a newly malloc()ed string.
|
442
|
59
|
771
|
60 #### This comes from code that just prepended `file:', which is not
|
|
61 good. See comment in mswindows_dde_callback(), case XTYP_EXECUTE.
|
|
62 */
|
867
|
63 Ibyte *
|
|
64 urlify_filename (Ibyte *filename)
|
771
|
65 {
|
867
|
66 Ibyte *pseudo_url;
|
771
|
67
|
|
68 WIN32_TO_LOCAL_FILE_FORMAT (filename, filename);
|
867
|
69 pseudo_url = xnew_array (Ibyte, 5 + qxestrlen (filename) + 1);
|
2367
|
70 qxestrcpy_ascii (pseudo_url, "file:");
|
771
|
71 qxestrcat (pseudo_url, filename);
|
|
72 /* URL's only have /, no backslash */
|
|
73 for (filename = pseudo_url; *filename; filename++)
|
|
74 {
|
|
75 if (*filename == '\\')
|
|
76 *filename = '/';
|
|
77 }
|
442
|
78
|
771
|
79 return pseudo_url;
|
|
80 }
|
531
|
81
|
826
|
82 /* Convert a Win32 file name in tstr format into a local-format file name
|
|
83 in internal format. */
|
|
84
|
442
|
85 Lisp_Object
|
826
|
86 tstr_to_local_file_format (Extbyte *path)
|
442
|
87 {
|
867
|
88 Ibyte *ttlff;
|
771
|
89
|
826
|
90 TSTR_TO_C_STRING (path, ttlff);
|
771
|
91 WIN32_TO_LOCAL_FILE_FORMAT (ttlff, ttlff);
|
|
92
|
|
93 return build_intstring (ttlff);
|
|
94 }
|
|
95
|
|
96 /* Normalize filename by converting all path separators to the specified
|
|
97 separator. Also conditionally convert all-upper-case path name
|
|
98 components to lower case. Return a newly malloc()ed string.
|
|
99 */
|
|
100
|
867
|
101 Ibyte *
|
|
102 mswindows_canonicalize_filename (Ibyte *name)
|
771
|
103 {
|
867
|
104 Ibyte *fp = name;
|
771
|
105 DECLARE_EISTRING (newname);
|
|
106 DECLARE_EISTRING (component);
|
|
107 int do_casefrob = 1;
|
442
|
108
|
771
|
109 /* Always lower-case drive letters a-z, even if the filesystem
|
|
110 preserves case in filenames.
|
|
111 This is so filenames can be compared by string comparison
|
|
112 functions that are case-sensitive. Even case-preserving filesystems
|
|
113 do not distinguish case in drive letters. */
|
|
114 if (name[0] >= 'A' && name[0] <= 'Z' && name[1] == ':')
|
|
115 {
|
|
116 eicat_ch (newname, name[0] + 'a' - 'A');
|
|
117 eicat_ch (newname, ':');
|
|
118 fp += 2;
|
|
119 }
|
|
120
|
|
121 while (1)
|
|
122 {
|
867
|
123 Ichar ch = itext_ichar (fp);
|
771
|
124 if (LOWERCASEP (0, ch))
|
|
125 do_casefrob = 0; /* don't convert this element */
|
442
|
126
|
771
|
127 if (ch == 0 || IS_ANY_SEP (ch))
|
|
128 {
|
|
129 if (do_casefrob && !NILP (Vmswindows_downcase_file_names))
|
|
130 eilwr (component);
|
|
131 do_casefrob = 1;
|
|
132 eicat_ei (newname, component);
|
|
133 eireset (component);
|
|
134 if (IS_DIRECTORY_SEP (ch))
|
|
135 eicat_ch (newname, DIRECTORY_SEP);
|
|
136 else if (ch)
|
|
137 eicat_ch (newname, ch);
|
|
138 else
|
|
139 break;
|
|
140 }
|
|
141 else
|
|
142 eicat_ch (component, ch);
|
|
143
|
867
|
144 INC_IBYTEPTR (fp);
|
771
|
145 }
|
|
146
|
|
147 return eicpyout_malloc (newname, 0);
|
442
|
148 }
|
|
149
|
814
|
150 Extbyte *
|
|
151 mswindows_get_module_file_name (void)
|
|
152 {
|
|
153 Extbyte *path = NULL;
|
|
154 int bufsize = 4096;
|
|
155 int cchpathsize;
|
|
156
|
|
157 while (1)
|
|
158 {
|
|
159 path = (Extbyte *) xrealloc (path, bufsize * XETCHAR_SIZE);
|
|
160 cchpathsize = qxeGetModuleFileName (NULL, path, bufsize);
|
|
161 if (!cchpathsize)
|
|
162 return 0;
|
|
163 if (cchpathsize + 1 <= bufsize)
|
|
164 break;
|
|
165 bufsize *= 2;
|
|
166 }
|
|
167
|
|
168 return path;
|
|
169 }
|
|
170
|
442
|
171 static void
|
|
172 init_potentially_nonexistent_functions (void)
|
|
173 {
|
771
|
174 HMODULE h_kernel = qxeGetModuleHandle (XETEXT ("kernel32"));
|
531
|
175 /* the following does not seem to get mapped in automatically */
|
771
|
176 HMODULE h_netapi = qxeLoadLibrary (XETEXT ("netapi32.dll"));
|
442
|
177
|
|
178 if (h_kernel)
|
|
179 {
|
|
180 xSwitchToThread =
|
|
181 (pfSwitchToThread_t) GetProcAddress (h_kernel, "SwitchToThread");
|
|
182 }
|
|
183
|
531
|
184 if (h_netapi)
|
|
185 {
|
|
186 xNetUserEnum =
|
|
187 (pfNetUserEnum_t) GetProcAddress (h_netapi, "NetUserEnum");
|
|
188 xNetApiBufferFree =
|
|
189 (pfNetApiBufferFree_t) GetProcAddress (h_netapi, "NetApiBufferFree");
|
|
190 }
|
442
|
191 }
|
|
192
|
771
|
193 static Lisp_Object
|
|
194 mswindows_lisp_error_1 (int errnum, int no_recurse)
|
|
195 {
|
|
196 LPTSTR lpMsgBuf;
|
|
197 Lisp_Object result;
|
867
|
198 Ibyte *inres;
|
771
|
199 Bytecount len;
|
|
200 int i;
|
|
201
|
|
202 /* The docs for FormatMessage say:
|
|
203
|
|
204 If you pass a specific LANGID in this parameter, FormatMessage
|
|
205 will return a message for that LANGID only. If the function
|
|
206 cannot find a message for that LANGID, it returns
|
|
207 ERROR_RESOURCE_LANG_NOT_FOUND. If you pass in zero, FormatMessage
|
|
208 looks for a message for LANGIDs in the following order:
|
|
209
|
|
210 Language neutral
|
|
211 Thread LANGID, based on the thread's locale value
|
|
212 User default LANGID, based on the user's default locale value
|
|
213 System default LANGID, based on the system default locale value
|
|
214 US English
|
|
215
|
|
216 If FormatMessage doesn't find a message for any of the preceding
|
|
217 LANGIDs, it returns any language message string that is present. If
|
|
218 that fails, it returns ERROR_RESOURCE_LANG_NOT_FOUND. (Note, this is
|
|
219 returned through GetLastError(), not the return value.)
|
|
220
|
|
221 #### what the hell is "language neutral"? i can find no info on this.
|
|
222 so let's do our own language first.
|
|
223 */
|
|
224
|
|
225 for (i = 0; ; i++)
|
|
226 {
|
|
227 int lang = 0;
|
|
228 int retval;
|
|
229
|
|
230 switch (i)
|
|
231 {
|
|
232 #ifdef MULE
|
|
233 /* Urk! Windows 95 doesn't let you set the thread locale!
|
|
234 so we have to maintain our own. */
|
|
235 case 0: lang = LANGIDFROMLCID (mswindows_current_locale ()); break;
|
|
236 case 1: lang = 0; break;
|
|
237 #else
|
|
238 case 0: lang = 0; break;
|
|
239 #endif
|
2500
|
240 default: ABORT ();
|
771
|
241 }
|
|
242
|
|
243 retval = qxeFormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
|
|
244 | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
245 NULL, errnum, lang,
|
|
246 /* yeah, i'm casting a char ** to a char *.
|
|
247 ya gotta problem widdat? */
|
|
248 (Extbyte *) &lpMsgBuf, 0, NULL);
|
|
249
|
|
250 if (!retval)
|
|
251 {
|
|
252 if (lang != 0)
|
|
253 continue;
|
|
254
|
|
255 if (no_recurse)
|
|
256 return emacs_sprintf_string
|
|
257 ("Unknown error code %d (error return %ld from FormatMessage())",
|
|
258 errnum, GetLastError ());
|
|
259 else
|
|
260 return emacs_sprintf_string
|
|
261 ("Unknown error code %d (error return %s from FormatMessage())",
|
|
262 /* It's OK, emacs_sprintf_string disables GC explicitly */
|
|
263 errnum, XSTRING_DATA (mswindows_lisp_error_1 (errnum, 1)));
|
|
264 }
|
|
265 else
|
|
266 break;
|
|
267 }
|
|
268
|
|
269 TSTR_TO_C_STRING (lpMsgBuf, inres);
|
|
270 len = qxestrlen (inres);
|
|
271 /* Messages tend to end with a period and newline */
|
2367
|
272 if (len >= 3 && !qxestrcmp_ascii (inres + len - 3, ".\r\n"))
|
771
|
273 len -= 3;
|
|
274 result = make_string (inres, len);
|
|
275
|
|
276 LocalFree (lpMsgBuf);
|
|
277 return result;
|
|
278 }
|
|
279
|
|
280 Lisp_Object
|
|
281 mswindows_lisp_error (int errnum)
|
|
282 {
|
|
283 return mswindows_lisp_error_1 (errnum, 0);
|
|
284 }
|
|
285
|
|
286 void
|
|
287 mswindows_output_last_error (char *frob)
|
|
288 {
|
|
289 int errval = GetLastError ();
|
|
290 Lisp_Object errmess = mswindows_lisp_error (errval);
|
|
291
|
|
292 stderr_out ("last error during %s is %d: %s\n",
|
|
293 frob, errval, XSTRING_DATA (errmess));
|
|
294 }
|
|
295
|
|
296 DOESNT_RETURN
|
|
297 mswindows_report_process_error (const char *string, Lisp_Object data,
|
|
298 int errnum)
|
|
299 {
|
|
300 report_file_type_error (Qprocess_error, mswindows_lisp_error (errnum),
|
|
301 string, data);
|
|
302 }
|
|
303
|
442
|
304 DEFUN ("mswindows-shell-execute", Fmswindows_shell_execute, 2, 4, 0, /*
|
|
305 Get Windows to perform OPERATION on DOCUMENT.
|
|
306 This is a wrapper around the ShellExecute system function, which
|
|
307 invokes the application registered to handle OPERATION for DOCUMENT.
|
|
308 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
|
|
309 nil for the default action), and DOCUMENT is typically the name of a
|
|
310 document file or URL, but can also be a program executable to run or
|
|
311 a directory to open in the Windows Explorer.
|
|
312
|
|
313 If DOCUMENT is a program executable, PARAMETERS can be a string
|
|
314 containing command line parameters, but otherwise should be nil.
|
|
315
|
|
316 SHOW-FLAG can be used to control whether the invoked application is hidden
|
|
317 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
|
|
318 otherwise it is an integer representing a ShowWindow flag:
|
|
319
|
|
320 0 - start hidden
|
|
321 1 - start normally
|
|
322 3 - start maximized
|
|
323 6 - start minimized
|
|
324 */
|
|
325 (operation, document, parameters, show_flag))
|
|
326 {
|
|
327 /* Encode filename and current directory. */
|
|
328 Lisp_Object current_dir = Ffile_name_directory (document);
|
|
329 int ret;
|
|
330
|
|
331 CHECK_STRING (document);
|
|
332
|
|
333 if (NILP (current_dir))
|
|
334 current_dir = current_buffer->directory;
|
|
335
|
771
|
336 {
|
|
337 Extbyte *opext = NULL;
|
|
338 Extbyte *parmext = NULL;
|
|
339 Extbyte *path = NULL;
|
|
340 Extbyte *doc = NULL;
|
442
|
341
|
771
|
342 if (STRINGP (operation))
|
|
343 LISP_STRING_TO_TSTR (operation, opext);
|
|
344 if (STRINGP (parameters))
|
|
345 LISP_STRING_TO_TSTR (parameters, parmext);
|
|
346 if (STRINGP (current_dir))
|
|
347 LOCAL_FILE_FORMAT_TO_TSTR (current_dir, path);
|
826
|
348 if (STRINGP (document))
|
|
349 LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR (document, doc);
|
442
|
350
|
771
|
351 ret = (int) qxeShellExecute (NULL, opext, doc, parmext, path,
|
|
352 (INTP (show_flag) ?
|
|
353 XINT (show_flag) : SW_SHOWDEFAULT));
|
|
354 }
|
442
|
355
|
771
|
356 if (ret <= 32)
|
|
357 {
|
|
358 /* Convert to more standard errors */
|
|
359 #define FROB(a, b) if (ret == a) ret = b
|
|
360 FROB (SE_ERR_ACCESSDENIED, ERROR_ACCESS_DENIED);
|
|
361 FROB (SE_ERR_ASSOCINCOMPLETE, ERROR_NO_ASSOCIATION);
|
|
362 FROB (SE_ERR_DDEBUSY, ERROR_DDE_FAIL);
|
|
363 FROB (SE_ERR_DDEFAIL, ERROR_DDE_FAIL);
|
|
364 FROB (SE_ERR_DDETIMEOUT, ERROR_DDE_FAIL);
|
|
365 FROB (SE_ERR_DLLNOTFOUND, ERROR_DLL_NOT_FOUND);
|
|
366 FROB (SE_ERR_FNF, ERROR_FILE_NOT_FOUND);
|
|
367 FROB (SE_ERR_NOASSOC, ERROR_NO_ASSOCIATION);
|
|
368 FROB (SE_ERR_OOM, ERROR_NOT_ENOUGH_MEMORY);
|
|
369 FROB (SE_ERR_PNF, ERROR_PATH_NOT_FOUND);
|
|
370 FROB (SE_ERR_SHARE, ERROR_SHARING_VIOLATION);
|
|
371 #undef FROB
|
|
372
|
|
373 mswindows_report_process_error ("Running ShellExecute",
|
|
374 ret == ERROR_PATH_NOT_FOUND ?
|
|
375 list4 (Qunbound, operation, document,
|
|
376 current_dir) :
|
|
377 list3 (Qunbound, operation, document),
|
|
378 ret);
|
|
379 }
|
442
|
380
|
771
|
381 return Qt;
|
442
|
382 }
|
|
383
|
673
|
384 #ifdef CYGWIN
|
|
385 DEFUN ("mswindows-cygwin-to-win32-path", Fmswindows_cygwin_to_win32_path, 1, 1, 0, /*
|
|
386 Get the cygwin environment to convert the Unix PATH to win32 format.
|
|
387 No expansion is performed, all conversion is done by the cygwin runtime.
|
|
388 */
|
|
389 (path))
|
|
390 {
|
867
|
391 Ibyte *p;
|
673
|
392 CHECK_STRING (path);
|
|
393
|
|
394 /* There appears to be a bug in the cygwin conversion routines in
|
|
395 that they are not idempotent. */
|
|
396 p = XSTRING_DATA (path);
|
|
397 if (isalpha (p[0]) && (IS_DEVICE_SEP (p[1])))
|
|
398 return path;
|
|
399
|
|
400 /* Use mule and cygwin-safe APIs top get at file data. */
|
771
|
401 LOCAL_TO_WIN32_FILE_FORMAT (p, p);
|
|
402 return build_intstring (p);
|
673
|
403 }
|
|
404 #endif
|
|
405
|
613
|
406 #if defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS)
|
|
407
|
|
408 /* setitimer() does not exist on native MS Windows, and appears broken
|
|
409 on Cygwin (random lockups when BROKEN_SIGIO is defined), so we
|
|
410 emulate in both cases by using multimedia timers. Furthermore,
|
|
411 the lockups still occur on Cygwin even when we do nothing but
|
|
412 use the standard signalling mechanism -- so we have to emulate
|
|
413 that, too. (But only for timeouts -- we have to use the standard
|
|
414 mechanism for SIGCHLD. Yuck.)
|
|
415 */
|
|
416
|
|
417
|
|
418 /*--------------------------------------------------------------------*/
|
|
419 /* Signal support */
|
|
420 /*--------------------------------------------------------------------*/
|
|
421
|
|
422 #define sigmask(nsig) (1U << nsig)
|
|
423
|
|
424 /* We can support as many signals as fit into word */
|
|
425 #define SIG_MAX 32
|
|
426
|
|
427 /* Signal handlers. Initial value = 0 = SIG_DFL */
|
|
428 static mswindows_sighandler signal_handlers[SIG_MAX] = {0};
|
|
429
|
|
430 /* Signal block mask: bit set to 1 means blocked */
|
|
431 unsigned signal_block_mask = 0;
|
|
432
|
|
433 /* Signal pending mask: bit set to 1 means sig is pending */
|
|
434 unsigned signal_pending_mask = 0;
|
|
435
|
|
436 mswindows_sighandler
|
|
437 mswindows_sigset (int nsig, mswindows_sighandler handler)
|
|
438 {
|
|
439 /* We delegate some signals to the system function */
|
|
440 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
|
|
441 return signal (nsig, handler);
|
|
442
|
|
443 if (nsig < 0 || nsig > SIG_MAX)
|
|
444 {
|
|
445 errno = EINVAL;
|
|
446 return NULL;
|
|
447 }
|
|
448
|
|
449 /* Store handler ptr */
|
|
450 {
|
|
451 mswindows_sighandler old_handler = signal_handlers[nsig];
|
|
452 signal_handlers[nsig] = handler;
|
|
453 return old_handler;
|
|
454 }
|
|
455 }
|
|
456
|
|
457 int
|
|
458 mswindows_sighold (int nsig)
|
|
459 {
|
|
460 if (nsig < 0 || nsig > SIG_MAX)
|
|
461 return errno = EINVAL;
|
|
462
|
|
463 signal_block_mask |= sigmask (nsig);
|
|
464 return 0;
|
|
465 }
|
|
466
|
|
467 int
|
|
468 mswindows_sigrelse (int nsig)
|
|
469 {
|
|
470 if (nsig < 0 || nsig > SIG_MAX)
|
|
471 return errno = EINVAL;
|
|
472
|
|
473 signal_block_mask &= ~sigmask (nsig);
|
|
474
|
|
475 if (signal_pending_mask & sigmask (nsig))
|
|
476 mswindows_raise (nsig);
|
|
477
|
|
478 return 0;
|
|
479 }
|
|
480
|
|
481 int
|
2286
|
482 mswindows_sigpause (int UNUSED (nsig))
|
613
|
483 {
|
|
484 /* This is currently not called, because the only call to sigpause
|
|
485 inside XEmacs is with SIGCHLD parameter. Just in case, we put an
|
2286
|
486 assert here, so anyone who adds a call to sigpause will be surprised
|
613
|
487 (or surprise someone else...) */
|
|
488 assert (0);
|
|
489 return 0;
|
|
490 }
|
|
491
|
|
492 int
|
|
493 mswindows_raise (int nsig)
|
|
494 {
|
|
495 /* We delegate some raises to the system routine */
|
|
496 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
|
|
497 return raise (nsig);
|
|
498
|
|
499 if (nsig < 0 || nsig > SIG_MAX)
|
|
500 return errno = EINVAL;
|
|
501
|
|
502 /* If the signal is blocked, remember to issue later */
|
|
503 if (signal_block_mask & sigmask (nsig))
|
|
504 {
|
|
505 signal_pending_mask |= sigmask (nsig);
|
|
506 return 0;
|
|
507 }
|
|
508
|
|
509 if (signal_handlers[nsig] == SIG_IGN)
|
|
510 return 0;
|
|
511
|
|
512 if (signal_handlers[nsig] != SIG_DFL)
|
|
513 {
|
|
514 (*signal_handlers[nsig]) (nsig);
|
|
515 return 0;
|
|
516 }
|
|
517
|
|
518 /* Default signal actions */
|
|
519 if (nsig == SIGALRM || nsig == SIGPROF)
|
|
520 exit (3);
|
|
521
|
|
522 /* Other signals are ignored by default */
|
|
523 return 0;
|
|
524 }
|
|
525
|
611
|
526
|
|
527 /*--------------------------------------------------------------------*/
|
|
528 /* Async timers */
|
|
529 /*--------------------------------------------------------------------*/
|
|
530
|
|
531 /* We emulate two timers, one for SIGALRM, another for SIGPROF.
|
|
532
|
|
533 itimerproc() function has an implementation limitation: it does
|
|
534 not allow to set *both* interval and period. If an attempt is
|
|
535 made to set both, and then they are unequal, the function
|
|
536 asserts.
|
|
537
|
|
538 Minimum timer resolution on Win32 systems varies, and is greater
|
|
539 than or equal than 1 ms. The resolution is always wrapped not to
|
|
540 attempt to get below the system defined limit.
|
|
541 */
|
|
542
|
|
543 /* Timer precision, denominator of one fraction: for 100 ms
|
|
544 interval, request 10 ms precision
|
|
545 */
|
|
546 const int setitimer_helper_timer_prec = 10;
|
|
547
|
|
548 /* Last itimervals, as set by calls to setitimer */
|
|
549 static struct itimerval it_alarm;
|
|
550 static struct itimerval it_prof;
|
|
551
|
|
552 /* Timer IDs as returned by MM */
|
|
553 MMRESULT tid_alarm = 0;
|
|
554 MMRESULT tid_prof = 0;
|
|
555
|
|
556 static void CALLBACK
|
2286
|
557 setitimer_helper_proc (UINT UNUSED (uID), UINT UNUSED (uMsg), DWORD dwUser,
|
|
558 DWORD UNUSED (dw1), DWORD UNUSED (dw2))
|
611
|
559 {
|
|
560 /* Just raise the signal indicated by the dwUser parameter */
|
|
561 mswindows_raise (dwUser);
|
|
562 }
|
|
563
|
|
564 /* Divide time in ms specified by IT by DENOM. Return 1 ms
|
|
565 if division results in zero */
|
|
566 static UINT
|
853
|
567 setitimer_helper_period (const struct itimerval *it, UINT denom)
|
611
|
568 {
|
|
569 static TIMECAPS time_caps;
|
|
570
|
|
571 UINT res;
|
853
|
572 const struct timeval *tv =
|
611
|
573 (it->it_value.tv_sec == 0 && it->it_value.tv_usec == 0)
|
|
574 ? &it->it_interval : &it->it_value;
|
|
575
|
|
576 /* Zero means stop timer */
|
|
577 if (tv->tv_sec == 0 && tv->tv_usec == 0)
|
|
578 return 0;
|
|
579
|
|
580 /* Convert to ms and divide by denom */
|
|
581 res = (tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000) / denom;
|
|
582
|
|
583 /* Converge to minimum timer resolution */
|
|
584 if (time_caps.wPeriodMin == 0)
|
|
585 timeGetDevCaps (&time_caps, sizeof(time_caps));
|
|
586
|
|
587 if (res < time_caps.wPeriodMin)
|
|
588 res = time_caps.wPeriodMin;
|
|
589
|
|
590 return res;
|
|
591 }
|
|
592
|
|
593 static int
|
853
|
594 setitimer_helper (const struct itimerval *itnew,
|
|
595 struct itimerval *itold, struct itimerval *itcurrent,
|
|
596 MMRESULT *tid, DWORD sigkind)
|
611
|
597 {
|
|
598 UINT delay, resolution, event_type;
|
|
599
|
|
600 /* First stop the old timer */
|
|
601 if (*tid)
|
|
602 {
|
|
603 timeKillEvent (*tid);
|
|
604 timeEndPeriod (setitimer_helper_period (itcurrent,
|
|
605 setitimer_helper_timer_prec));
|
|
606 *tid = 0;
|
|
607 }
|
|
608
|
|
609 /* Return old itimerval if requested */
|
|
610 if (itold)
|
|
611 *itold = *itcurrent;
|
|
612
|
|
613 *itcurrent = *itnew;
|
|
614
|
|
615 /* Determine if to start new timer */
|
|
616 delay = setitimer_helper_period (itnew, 1);
|
|
617 if (delay)
|
|
618 {
|
|
619 resolution = setitimer_helper_period (itnew,
|
|
620 setitimer_helper_timer_prec);
|
|
621 event_type = (itnew->it_value.tv_sec == 0 &&
|
|
622 itnew->it_value.tv_usec == 0)
|
|
623 ? TIME_ONESHOT : TIME_PERIODIC;
|
|
624 timeBeginPeriod (resolution);
|
|
625 *tid = timeSetEvent (delay, resolution, setitimer_helper_proc, sigkind,
|
|
626 event_type);
|
|
627 }
|
|
628
|
|
629 return !delay || *tid;
|
|
630 }
|
|
631
|
|
632 int
|
|
633 mswindows_setitimer (int kind, const struct itimerval *itnew,
|
|
634 struct itimerval *itold)
|
|
635 {
|
|
636 /* In this version, both interval and value are allowed
|
|
637 only if they are equal. */
|
|
638 assert ((itnew->it_value.tv_sec == 0 && itnew->it_value.tv_usec == 0)
|
|
639 || (itnew->it_interval.tv_sec == 0 &&
|
|
640 itnew->it_interval.tv_usec == 0)
|
|
641 || (itnew->it_value.tv_sec == itnew->it_interval.tv_sec &&
|
|
642 itnew->it_value.tv_usec == itnew->it_interval.tv_usec));
|
|
643
|
|
644 if (kind == ITIMER_REAL)
|
|
645 return setitimer_helper (itnew, itold, &it_alarm, &tid_alarm, SIGALRM);
|
|
646 else if (kind == ITIMER_PROF)
|
|
647 return setitimer_helper (itnew, itold, &it_prof, &tid_prof, SIGPROF);
|
|
648 else
|
|
649 return errno = EINVAL;
|
|
650 }
|
|
651
|
613
|
652 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) */
|
|
653
|
611
|
654
|
442
|
655 void
|
|
656 syms_of_win32 (void)
|
|
657 {
|
|
658 DEFSUBR (Fmswindows_shell_execute);
|
673
|
659 #ifdef CYGWIN
|
|
660 DEFSUBR (Fmswindows_cygwin_to_win32_path);
|
|
661 #endif
|
442
|
662 }
|
|
663
|
|
664 void
|
771
|
665 vars_of_win32 (void)
|
|
666 {
|
|
667 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /*
|
|
668 Non-nil means convert all-upper case file names to lower case.
|
|
669 This applies when performing completions and file name expansion.
|
|
670 */ );
|
|
671 Vmswindows_downcase_file_names = Qnil;
|
|
672 }
|
|
673
|
|
674 void
|
442
|
675 init_win32 (void)
|
|
676 {
|
|
677 init_potentially_nonexistent_functions ();
|
|
678 }
|
771
|
679
|
|
680 void
|
2367
|
681 init_win32_very_very_early (void)
|
771
|
682 {
|
|
683 mswindows_windows9x_p = GetVersion () & 0x80000000;
|
|
684 }
|