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