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