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
|
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 {
|
665
|
75 Intbyte *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
|
|
88 Intbyte *
|
|
89 mswindows_canonicalize_filename (Intbyte *name)
|
|
90 {
|
|
91 Intbyte *fp = name;
|
|
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 {
|
|
110 Emchar ch = charptr_emchar (fp);
|
|
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
|
|
131 INC_CHARPTR (fp);
|
|
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;
|
|
185 Intbyte *inres;
|
|
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));
|
826
|
341
|
|
342 xfree (doc);
|
771
|
343 }
|
442
|
344
|
771
|
345 if (ret <= 32)
|
|
346 {
|
|
347 /* Convert to more standard errors */
|
|
348 #define FROB(a, b) if (ret == a) ret = b
|
|
349 FROB (SE_ERR_ACCESSDENIED, ERROR_ACCESS_DENIED);
|
|
350 FROB (SE_ERR_ASSOCINCOMPLETE, ERROR_NO_ASSOCIATION);
|
|
351 FROB (SE_ERR_DDEBUSY, ERROR_DDE_FAIL);
|
|
352 FROB (SE_ERR_DDEFAIL, ERROR_DDE_FAIL);
|
|
353 FROB (SE_ERR_DDETIMEOUT, ERROR_DDE_FAIL);
|
|
354 FROB (SE_ERR_DLLNOTFOUND, ERROR_DLL_NOT_FOUND);
|
|
355 FROB (SE_ERR_FNF, ERROR_FILE_NOT_FOUND);
|
|
356 FROB (SE_ERR_NOASSOC, ERROR_NO_ASSOCIATION);
|
|
357 FROB (SE_ERR_OOM, ERROR_NOT_ENOUGH_MEMORY);
|
|
358 FROB (SE_ERR_PNF, ERROR_PATH_NOT_FOUND);
|
|
359 FROB (SE_ERR_SHARE, ERROR_SHARING_VIOLATION);
|
|
360 #undef FROB
|
|
361
|
|
362 mswindows_report_process_error ("Running ShellExecute",
|
|
363 ret == ERROR_PATH_NOT_FOUND ?
|
|
364 list4 (Qunbound, operation, document,
|
|
365 current_dir) :
|
|
366 list3 (Qunbound, operation, document),
|
|
367 ret);
|
|
368 }
|
442
|
369
|
771
|
370 return Qt;
|
442
|
371 }
|
|
372
|
673
|
373 #ifdef CYGWIN
|
|
374 DEFUN ("mswindows-cygwin-to-win32-path", Fmswindows_cygwin_to_win32_path, 1, 1, 0, /*
|
|
375 Get the cygwin environment to convert the Unix PATH to win32 format.
|
|
376 No expansion is performed, all conversion is done by the cygwin runtime.
|
|
377 */
|
|
378 (path))
|
|
379 {
|
771
|
380 Intbyte *p;
|
673
|
381 CHECK_STRING (path);
|
|
382
|
|
383 /* There appears to be a bug in the cygwin conversion routines in
|
|
384 that they are not idempotent. */
|
|
385 p = XSTRING_DATA (path);
|
|
386 if (isalpha (p[0]) && (IS_DEVICE_SEP (p[1])))
|
|
387 return path;
|
|
388
|
|
389 /* Use mule and cygwin-safe APIs top get at file data. */
|
771
|
390 LOCAL_TO_WIN32_FILE_FORMAT (p, p);
|
|
391 return build_intstring (p);
|
673
|
392 }
|
|
393 #endif
|
|
394
|
613
|
395 #if defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS)
|
|
396
|
|
397 /* setitimer() does not exist on native MS Windows, and appears broken
|
|
398 on Cygwin (random lockups when BROKEN_SIGIO is defined), so we
|
|
399 emulate in both cases by using multimedia timers. Furthermore,
|
|
400 the lockups still occur on Cygwin even when we do nothing but
|
|
401 use the standard signalling mechanism -- so we have to emulate
|
|
402 that, too. (But only for timeouts -- we have to use the standard
|
|
403 mechanism for SIGCHLD. Yuck.)
|
|
404 */
|
|
405
|
|
406
|
|
407 /*--------------------------------------------------------------------*/
|
|
408 /* Signal support */
|
|
409 /*--------------------------------------------------------------------*/
|
|
410
|
|
411 #define sigmask(nsig) (1U << nsig)
|
|
412
|
|
413 /* We can support as many signals as fit into word */
|
|
414 #define SIG_MAX 32
|
|
415
|
|
416 /* Signal handlers. Initial value = 0 = SIG_DFL */
|
|
417 static mswindows_sighandler signal_handlers[SIG_MAX] = {0};
|
|
418
|
|
419 /* Signal block mask: bit set to 1 means blocked */
|
|
420 unsigned signal_block_mask = 0;
|
|
421
|
|
422 /* Signal pending mask: bit set to 1 means sig is pending */
|
|
423 unsigned signal_pending_mask = 0;
|
|
424
|
|
425 mswindows_sighandler
|
|
426 mswindows_sigset (int nsig, mswindows_sighandler handler)
|
|
427 {
|
|
428 /* We delegate some signals to the system function */
|
|
429 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
|
|
430 return signal (nsig, handler);
|
|
431
|
|
432 if (nsig < 0 || nsig > SIG_MAX)
|
|
433 {
|
|
434 errno = EINVAL;
|
|
435 return NULL;
|
|
436 }
|
|
437
|
|
438 /* Store handler ptr */
|
|
439 {
|
|
440 mswindows_sighandler old_handler = signal_handlers[nsig];
|
|
441 signal_handlers[nsig] = handler;
|
|
442 return old_handler;
|
|
443 }
|
|
444 }
|
|
445
|
|
446 int
|
|
447 mswindows_sighold (int nsig)
|
|
448 {
|
|
449 if (nsig < 0 || nsig > SIG_MAX)
|
|
450 return errno = EINVAL;
|
|
451
|
|
452 signal_block_mask |= sigmask (nsig);
|
|
453 return 0;
|
|
454 }
|
|
455
|
|
456 int
|
|
457 mswindows_sigrelse (int nsig)
|
|
458 {
|
|
459 if (nsig < 0 || nsig > SIG_MAX)
|
|
460 return errno = EINVAL;
|
|
461
|
|
462 signal_block_mask &= ~sigmask (nsig);
|
|
463
|
|
464 if (signal_pending_mask & sigmask (nsig))
|
|
465 mswindows_raise (nsig);
|
|
466
|
|
467 return 0;
|
|
468 }
|
|
469
|
|
470 int
|
|
471 mswindows_sigpause (int nsig)
|
|
472 {
|
|
473 /* This is currently not called, because the only call to sigpause
|
|
474 inside XEmacs is with SIGCHLD parameter. Just in case, we put an
|
|
475 assert here, so anyone adds a call to sigpause will be surprised
|
|
476 (or surprise someone else...) */
|
|
477 assert (0);
|
|
478 return 0;
|
|
479 }
|
|
480
|
|
481 int
|
|
482 mswindows_raise (int nsig)
|
|
483 {
|
|
484 /* We delegate some raises to the system routine */
|
|
485 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
|
|
486 return raise (nsig);
|
|
487
|
|
488 if (nsig < 0 || nsig > SIG_MAX)
|
|
489 return errno = EINVAL;
|
|
490
|
|
491 /* If the signal is blocked, remember to issue later */
|
|
492 if (signal_block_mask & sigmask (nsig))
|
|
493 {
|
|
494 signal_pending_mask |= sigmask (nsig);
|
|
495 return 0;
|
|
496 }
|
|
497
|
|
498 if (signal_handlers[nsig] == SIG_IGN)
|
|
499 return 0;
|
|
500
|
|
501 if (signal_handlers[nsig] != SIG_DFL)
|
|
502 {
|
|
503 (*signal_handlers[nsig]) (nsig);
|
|
504 return 0;
|
|
505 }
|
|
506
|
|
507 /* Default signal actions */
|
|
508 if (nsig == SIGALRM || nsig == SIGPROF)
|
|
509 exit (3);
|
|
510
|
|
511 /* Other signals are ignored by default */
|
|
512 return 0;
|
|
513 }
|
|
514
|
611
|
515
|
|
516 /*--------------------------------------------------------------------*/
|
|
517 /* Async timers */
|
|
518 /*--------------------------------------------------------------------*/
|
|
519
|
|
520 /* We emulate two timers, one for SIGALRM, another for SIGPROF.
|
|
521
|
|
522 itimerproc() function has an implementation limitation: it does
|
|
523 not allow to set *both* interval and period. If an attempt is
|
|
524 made to set both, and then they are unequal, the function
|
|
525 asserts.
|
|
526
|
|
527 Minimum timer resolution on Win32 systems varies, and is greater
|
|
528 than or equal than 1 ms. The resolution is always wrapped not to
|
|
529 attempt to get below the system defined limit.
|
|
530 */
|
|
531
|
|
532 /* Timer precision, denominator of one fraction: for 100 ms
|
|
533 interval, request 10 ms precision
|
|
534 */
|
|
535 const int setitimer_helper_timer_prec = 10;
|
|
536
|
|
537 /* Last itimervals, as set by calls to setitimer */
|
|
538 static struct itimerval it_alarm;
|
|
539 static struct itimerval it_prof;
|
|
540
|
|
541 /* Timer IDs as returned by MM */
|
|
542 MMRESULT tid_alarm = 0;
|
|
543 MMRESULT tid_prof = 0;
|
|
544
|
|
545 static void CALLBACK
|
|
546 setitimer_helper_proc (UINT uID, UINT uMsg, DWORD dwUser,
|
|
547 DWORD dw1, DWORD dw2)
|
|
548 {
|
|
549 /* Just raise the signal indicated by the dwUser parameter */
|
|
550 mswindows_raise (dwUser);
|
|
551 }
|
|
552
|
|
553 /* Divide time in ms specified by IT by DENOM. Return 1 ms
|
|
554 if division results in zero */
|
|
555 static UINT
|
|
556 setitimer_helper_period (const struct itimerval* it, UINT denom)
|
|
557 {
|
|
558 static TIMECAPS time_caps;
|
|
559
|
|
560 UINT res;
|
|
561 const struct timeval* tv =
|
|
562 (it->it_value.tv_sec == 0 && it->it_value.tv_usec == 0)
|
|
563 ? &it->it_interval : &it->it_value;
|
|
564
|
|
565 /* Zero means stop timer */
|
|
566 if (tv->tv_sec == 0 && tv->tv_usec == 0)
|
|
567 return 0;
|
|
568
|
|
569 /* Convert to ms and divide by denom */
|
|
570 res = (tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000) / denom;
|
|
571
|
|
572 /* Converge to minimum timer resolution */
|
|
573 if (time_caps.wPeriodMin == 0)
|
|
574 timeGetDevCaps (&time_caps, sizeof(time_caps));
|
|
575
|
|
576 if (res < time_caps.wPeriodMin)
|
|
577 res = time_caps.wPeriodMin;
|
|
578
|
|
579 return res;
|
|
580 }
|
|
581
|
|
582 static int
|
|
583 setitimer_helper (const struct itimerval* itnew,
|
|
584 struct itimerval* itold, struct itimerval* itcurrent,
|
|
585 MMRESULT* tid, DWORD sigkind)
|
|
586 {
|
|
587 UINT delay, resolution, event_type;
|
|
588
|
|
589 /* First stop the old timer */
|
|
590 if (*tid)
|
|
591 {
|
|
592 timeKillEvent (*tid);
|
|
593 timeEndPeriod (setitimer_helper_period (itcurrent,
|
|
594 setitimer_helper_timer_prec));
|
|
595 *tid = 0;
|
|
596 }
|
|
597
|
|
598 /* Return old itimerval if requested */
|
|
599 if (itold)
|
|
600 *itold = *itcurrent;
|
|
601
|
|
602 *itcurrent = *itnew;
|
|
603
|
|
604 /* Determine if to start new timer */
|
|
605 delay = setitimer_helper_period (itnew, 1);
|
|
606 if (delay)
|
|
607 {
|
|
608 resolution = setitimer_helper_period (itnew,
|
|
609 setitimer_helper_timer_prec);
|
|
610 event_type = (itnew->it_value.tv_sec == 0 &&
|
|
611 itnew->it_value.tv_usec == 0)
|
|
612 ? TIME_ONESHOT : TIME_PERIODIC;
|
|
613 timeBeginPeriod (resolution);
|
|
614 *tid = timeSetEvent (delay, resolution, setitimer_helper_proc, sigkind,
|
|
615 event_type);
|
|
616 }
|
|
617
|
|
618 return !delay || *tid;
|
|
619 }
|
|
620
|
|
621 int
|
|
622 mswindows_setitimer (int kind, const struct itimerval *itnew,
|
|
623 struct itimerval *itold)
|
|
624 {
|
|
625 /* In this version, both interval and value are allowed
|
|
626 only if they are equal. */
|
|
627 assert ((itnew->it_value.tv_sec == 0 && itnew->it_value.tv_usec == 0)
|
|
628 || (itnew->it_interval.tv_sec == 0 &&
|
|
629 itnew->it_interval.tv_usec == 0)
|
|
630 || (itnew->it_value.tv_sec == itnew->it_interval.tv_sec &&
|
|
631 itnew->it_value.tv_usec == itnew->it_interval.tv_usec));
|
|
632
|
|
633 if (kind == ITIMER_REAL)
|
|
634 return setitimer_helper (itnew, itold, &it_alarm, &tid_alarm, SIGALRM);
|
|
635 else if (kind == ITIMER_PROF)
|
|
636 return setitimer_helper (itnew, itold, &it_prof, &tid_prof, SIGPROF);
|
|
637 else
|
|
638 return errno = EINVAL;
|
|
639 }
|
|
640
|
613
|
641 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) */
|
|
642
|
611
|
643
|
442
|
644 void
|
|
645 syms_of_win32 (void)
|
|
646 {
|
|
647 DEFSUBR (Fmswindows_shell_execute);
|
673
|
648 #ifdef CYGWIN
|
|
649 DEFSUBR (Fmswindows_cygwin_to_win32_path);
|
|
650 #endif
|
442
|
651 }
|
|
652
|
|
653 void
|
771
|
654 vars_of_win32 (void)
|
|
655 {
|
|
656 DEFVAR_LISP ("mswindows-downcase-file-names", &Vmswindows_downcase_file_names /*
|
|
657 Non-nil means convert all-upper case file names to lower case.
|
|
658 This applies when performing completions and file name expansion.
|
|
659 */ );
|
|
660 Vmswindows_downcase_file_names = Qnil;
|
|
661 }
|
|
662
|
|
663 void
|
442
|
664 init_win32 (void)
|
|
665 {
|
|
666 init_potentially_nonexistent_functions ();
|
|
667 }
|
771
|
668
|
|
669 void
|
|
670 init_win32_very_early (void)
|
|
671 {
|
|
672 mswindows_windows9x_p = GetVersion () & 0x80000000;
|
|
673 }
|