annotate src/win32.c @ 707:a307f9a2021d

[xemacs-hg @ 2001-12-20 05:49:28 by andyp] sync with 21-4-6-windows
author andyp
date Thu, 20 Dec 2001 05:49:48 +0000
parents 685b588e92d8
children 943eaba38521
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1 /* Utility routines for XEmacs on Windows 9x, NT and Cygwin.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
2 Copyright (C) 2000 Ben Wing.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
3
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
4 This file is part of XEmacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
5
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
9 later version.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
10
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
14 for more details.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
15
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to the Free
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
19 02111-1307, USA. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
20
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
21 #include <config.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
22 #include "lisp.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
23
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
24 #include "buffer.h"
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
25
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
26 #include "syssignal.h"
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
27 #include "systime.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
28 #include "syswindows.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
29
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
30 typedef BOOL (WINAPI *pfSwitchToThread_t) (VOID);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
31 pfSwitchToThread_t xSwitchToThread;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
32
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
33 typedef HKL (WINAPI *pfGetKeyboardLayout_t) (DWORD);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
34 pfGetKeyboardLayout_t xGetKeyboardLayout;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
35 typedef BOOL (WINAPI *pfSetMenuDefaultItem_t) (HMENU, UINT, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
36 pfSetMenuDefaultItem_t xSetMenuDefaultItem;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
37 typedef BOOL (WINAPI *pfInsertMenuItemA_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
38 (HMENU, UINT, BOOL, LPCMENUITEMINFOA);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
39 pfInsertMenuItemA_t xInsertMenuItemA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
40 typedef BOOL (WINAPI *pfInsertMenuItemW_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
41 (HMENU, UINT, BOOL, LPCMENUITEMINFOW);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
42 pfInsertMenuItemW_t xInsertMenuItemW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
43 typedef HANDLE (WINAPI *pfLoadImageA_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
44 (HINSTANCE, LPCSTR, UINT, int, int, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
45 pfLoadImageA_t xLoadImageA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
46 typedef HANDLE (WINAPI *pfLoadImageW_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
47 (HINSTANCE, LPCWSTR, UINT, int, int, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
48 pfLoadImageW_t xLoadImageW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
49 typedef ATOM (WINAPI *pfRegisterClassExA_t) (CONST WNDCLASSEXA *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
50 pfRegisterClassExA_t xRegisterClassExA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
51 typedef ATOM (WINAPI *pfRegisterClassExW_t) (CONST WNDCLASSEXW *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
52 pfRegisterClassExW_t xRegisterClassExW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
53
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
54 typedef int (WINAPI *pfEnumFontFamiliesExA_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
55 (HDC, LPLOGFONTA, FONTENUMPROCA, LPARAM, DWORD);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
56 pfEnumFontFamiliesExA_t xEnumFontFamiliesExA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
57 typedef int (WINAPI *pfEnumFontFamiliesExW_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
58 (HDC, LPLOGFONTW, FONTENUMPROCW, LPARAM, DWORD);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
59 pfEnumFontFamiliesExW_t xEnumFontFamiliesExW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
60
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
61 typedef DWORD (WINAPI *pfSHGetFileInfoA_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
62 (LPCSTR, DWORD, SHFILEINFOA FAR *, UINT, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
63 pfSHGetFileInfoA_t xSHGetFileInfoA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
64 typedef DWORD (WINAPI *pfSHGetFileInfoW_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
65 (LPCWSTR, DWORD, SHFILEINFOW FAR *, UINT, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
66 pfSHGetFileInfoW_t xSHGetFileInfoW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
67
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
68 typedef NET_API_STATUS (NET_API_FUNCTION *pfNetUserEnum_t)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
69 (
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
70 IN LPCWSTR servername OPTIONAL,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
71 IN DWORD level,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
72 IN DWORD filter,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
73 OUT LPBYTE *bufptr,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
74 IN DWORD prefmaxlen,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
75 OUT LPDWORD entriesread,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
76 OUT LPDWORD totalentries,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
77 IN OUT LPDWORD resume_handle OPTIONAL
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
78 );
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
79 pfNetUserEnum_t xNetUserEnum;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
80
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
81 typedef NET_API_STATUS (NET_API_FUNCTION *pfNetApiBufferFree_t)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
82 (
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
83 IN LPVOID Buffer
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
84 );
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
85 pfNetApiBufferFree_t xNetApiBufferFree;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
86
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
87 Lisp_Object
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
88 tstr_to_local_file_format (Extbyte *pathout)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
89 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 613
diff changeset
90 Intbyte *ttlff;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
91 Lisp_Object in;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
92
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
93 EXTERNAL_TO_C_STRING (pathout, ttlff, Qmswindows_tstr);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
94 WIN32_TO_LOCAL_FILE_FORMAT (ttlff, in);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
95
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
96 return in;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
97 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
98
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
99 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
100 init_potentially_nonexistent_functions (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
101 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
102 HMODULE h_kernel = GetModuleHandle ("kernel32");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
103 HMODULE h_user = GetModuleHandle ("user32");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
104 HMODULE h_gdi = GetModuleHandle ("gdi32");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
105 HMODULE h_shell = GetModuleHandle ("shell32");
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
106 /* the following does not seem to get mapped in automatically */
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
107 HMODULE h_netapi = LoadLibrary ("netapi32.dll");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
108
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
109 if (h_kernel)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
110 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
111 xSwitchToThread =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
112 (pfSwitchToThread_t) GetProcAddress (h_kernel, "SwitchToThread");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
113 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
114
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
115 if (h_user)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
116 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
117 xGetKeyboardLayout =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
118 (pfGetKeyboardLayout_t) GetProcAddress (h_user, "GetKeyboardLayout");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
119 xSetMenuDefaultItem =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
120 (pfSetMenuDefaultItem_t) GetProcAddress (h_user, "SetMenuDefaultItem");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
121 xInsertMenuItemA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
122 (pfInsertMenuItemA_t) GetProcAddress (h_user, "InsertMenuItemA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
123 xInsertMenuItemW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
124 (pfInsertMenuItemW_t) GetProcAddress (h_user, "InsertMenuItemW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
125 xLoadImageA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
126 (pfLoadImageA_t) GetProcAddress (h_user, "LoadImageA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
127 xLoadImageW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
128 (pfLoadImageW_t) GetProcAddress (h_user, "LoadImageW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
129 xRegisterClassExA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
130 (pfRegisterClassExA_t) GetProcAddress (h_user, "RegisterClassExA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
131 xRegisterClassExW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
132 (pfRegisterClassExW_t) GetProcAddress (h_user, "RegisterClassExW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
133 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
134
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
135 if (h_gdi)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
136 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
137 xEnumFontFamiliesExA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
138 (pfEnumFontFamiliesExA_t) GetProcAddress (h_gdi, "EnumFontFamiliesExA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
139 xEnumFontFamiliesExW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
140 (pfEnumFontFamiliesExW_t) GetProcAddress (h_gdi, "EnumFontFamiliesExW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
141 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
142
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
143 if (h_shell)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
144 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
145 xSHGetFileInfoA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
146 (pfSHGetFileInfoA_t) GetProcAddress (h_shell, "SHGetFileInfoA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
147 xSHGetFileInfoW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
148 (pfSHGetFileInfoW_t) GetProcAddress (h_shell, "SHGetFileInfoW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
149 }
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
150
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
151 if (h_netapi)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
152 {
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
153 xNetUserEnum =
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
154 (pfNetUserEnum_t) GetProcAddress (h_netapi, "NetUserEnum");
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
155 xNetApiBufferFree =
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
156 (pfNetApiBufferFree_t) GetProcAddress (h_netapi, "NetApiBufferFree");
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
157 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
158 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
159
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
160 DEFUN ("mswindows-shell-execute", Fmswindows_shell_execute, 2, 4, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
161 Get Windows to perform OPERATION on DOCUMENT.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
162 This is a wrapper around the ShellExecute system function, which
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
163 invokes the application registered to handle OPERATION for DOCUMENT.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
164 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
165 nil for the default action), and DOCUMENT is typically the name of a
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
166 document file or URL, but can also be a program executable to run or
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
167 a directory to open in the Windows Explorer.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
168
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
169 If DOCUMENT is a program executable, PARAMETERS can be a string
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
170 containing command line parameters, but otherwise should be nil.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
171
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
172 SHOW-FLAG can be used to control whether the invoked application is hidden
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
173 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
174 otherwise it is an integer representing a ShowWindow flag:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
175
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
176 0 - start hidden
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
177 1 - start normally
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
178 3 - start maximized
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
179 6 - start minimized
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
180 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
181 (operation, document, parameters, show_flag))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
182 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
183 /* Encode filename and current directory. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
184 Lisp_Object current_dir = Ffile_name_directory (document);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
185 char* path = NULL;
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
186 #ifdef CYGWIN
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
187 char* fname1, *fname2;
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
188 int pos, sz;
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
189 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
190 char* doc = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
191 int ret;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
192 struct gcpro gcpro1, gcpro2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
193
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
194 CHECK_STRING (document);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
195
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
196 if (NILP (current_dir))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
197 current_dir = current_buffer->directory;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
198
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
199 GCPRO2 (current_dir, document);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
200
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
201 /* Use mule and cygwin-safe APIs top get at file data. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
202 if (STRINGP (current_dir))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
203 {
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
204 LOCAL_TO_WIN32_FILE_FORMAT (current_dir, path);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
205 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
206
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
207 if (STRINGP (document))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
208 {
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
209 doc = XSTRING_DATA (document);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
210 #ifdef CYGWIN
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
211 if ((fname1 = strchr (doc, ':')) != NULL
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
212 && *++fname1 == '/' && *++fname1 == '/')
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
213 {
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
214 // URL-style if we get here, but we must only convert file
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
215 // arguments, since win32 paths are illegal in http etc.
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
216 if (strncmp (doc, "file://", 7) == 0)
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
217 {
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
218 fname1++;
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
219 pos = fname1 - doc;
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
220 if (!(isalpha (fname1[0]) && (IS_DEVICE_SEP (fname1[1]))))
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
221 {
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
222 sz = cygwin_posix_to_win32_path_list_buf_size (fname1);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
223 fname2 = alloca (sz + pos);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
224 strncpy (fname2, doc, pos);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
225 doc = fname2;
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
226 fname2 += pos;
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
227 cygwin_posix_to_win32_path_list (fname1, fname2);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
228 }
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
229 }
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
230 }
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
231 else {
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 673
diff changeset
232 // Not URL-style, must be a straight filename.
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
233 LOCAL_TO_WIN32_FILE_FORMAT (document, doc);
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
234 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
235 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
236 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
237
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
238 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
239
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
240 ret = (int) ShellExecute (NULL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
241 (STRINGP (operation) ?
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 578
diff changeset
242 /* !!#### more mule bogosity */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 578
diff changeset
243 (char *) XSTRING_DATA (operation) : NULL),
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
244 doc,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
245 (STRINGP (parameters) ?
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 578
diff changeset
246 /* !!#### more mule bogosity */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 578
diff changeset
247 (char *) XSTRING_DATA (parameters) : NULL),
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
248 path,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
249 (INTP (show_flag) ?
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
250 XINT (show_flag) : SW_SHOWDEFAULT));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
251
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
252 if (ret > 32)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
253 return Qt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
254
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
255 if (ret == ERROR_FILE_NOT_FOUND)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 531
diff changeset
256 signal_error (Qfile_error, "file not found", document);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
257 else if (ret == ERROR_PATH_NOT_FOUND)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 531
diff changeset
258 signal_error (Qfile_error, "path not found", current_dir);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
259 else if (ret == ERROR_BAD_FORMAT)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 531
diff changeset
260 signal_error (Qfile_error, "bad executable format", document);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
261 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 531
diff changeset
262 signal_error (Qinternal_error, "internal error", Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
263
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
264 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
265 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
266
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
267 #ifdef CYGWIN
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
268 DEFUN ("mswindows-cygwin-to-win32-path", Fmswindows_cygwin_to_win32_path, 1, 1, 0, /*
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
269 Get the cygwin environment to convert the Unix PATH to win32 format.
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
270 No expansion is performed, all conversion is done by the cygwin runtime.
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
271 */
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
272 (path))
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
273 {
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
274 Extbyte* f;
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
275 Intbyte* p;
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
276 CHECK_STRING (path);
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
277
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
278 /* There appears to be a bug in the cygwin conversion routines in
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
279 that they are not idempotent. */
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
280 p = XSTRING_DATA (path);
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
281 if (isalpha (p[0]) && (IS_DEVICE_SEP (p[1])))
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
282 return path;
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
283
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
284 /* Use mule and cygwin-safe APIs top get at file data. */
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
285 LOCAL_TO_WIN32_FILE_FORMAT (path, f);
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
286 return build_ext_string (f, Qnative);
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
287 }
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
288 #endif
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
289
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
290 #if defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
291
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
292 /* setitimer() does not exist on native MS Windows, and appears broken
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
293 on Cygwin (random lockups when BROKEN_SIGIO is defined), so we
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
294 emulate in both cases by using multimedia timers. Furthermore,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
295 the lockups still occur on Cygwin even when we do nothing but
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
296 use the standard signalling mechanism -- so we have to emulate
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
297 that, too. (But only for timeouts -- we have to use the standard
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
298 mechanism for SIGCHLD. Yuck.)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
299 */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
300
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
301
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
302 /*--------------------------------------------------------------------*/
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
303 /* Signal support */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
304 /*--------------------------------------------------------------------*/
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
305
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
306 #define sigmask(nsig) (1U << nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
307
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
308 /* We can support as many signals as fit into word */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
309 #define SIG_MAX 32
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
310
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
311 /* Signal handlers. Initial value = 0 = SIG_DFL */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
312 static mswindows_sighandler signal_handlers[SIG_MAX] = {0};
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
313
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
314 /* Signal block mask: bit set to 1 means blocked */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
315 unsigned signal_block_mask = 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
316
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
317 /* Signal pending mask: bit set to 1 means sig is pending */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
318 unsigned signal_pending_mask = 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
319
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
320 mswindows_sighandler
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
321 mswindows_sigset (int nsig, mswindows_sighandler handler)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
322 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
323 /* We delegate some signals to the system function */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
324 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
325 return signal (nsig, handler);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
326
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
327 if (nsig < 0 || nsig > SIG_MAX)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
328 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
329 errno = EINVAL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
330 return NULL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
331 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
332
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
333 /* Store handler ptr */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
334 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
335 mswindows_sighandler old_handler = signal_handlers[nsig];
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
336 signal_handlers[nsig] = handler;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
337 return old_handler;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
338 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
339 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
340
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
341 int
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
342 mswindows_sighold (int nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
343 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
344 if (nsig < 0 || nsig > SIG_MAX)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
345 return errno = EINVAL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
346
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
347 signal_block_mask |= sigmask (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
348 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
349 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
350
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
351 int
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
352 mswindows_sigrelse (int nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
353 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
354 if (nsig < 0 || nsig > SIG_MAX)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
355 return errno = EINVAL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
356
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
357 signal_block_mask &= ~sigmask (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
358
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
359 if (signal_pending_mask & sigmask (nsig))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
360 mswindows_raise (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
361
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
362 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
363 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
364
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
365 int
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
366 mswindows_sigpause (int nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
367 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
368 /* This is currently not called, because the only call to sigpause
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
369 inside XEmacs is with SIGCHLD parameter. Just in case, we put an
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
370 assert here, so anyone adds a call to sigpause will be surprised
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
371 (or surprise someone else...) */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
372 assert (0);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
373 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
374 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
375
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
376 int
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
377 mswindows_raise (int nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
378 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
379 /* We delegate some raises to the system routine */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
380 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
381 return raise (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
382
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
383 if (nsig < 0 || nsig > SIG_MAX)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
384 return errno = EINVAL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
385
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
386 /* If the signal is blocked, remember to issue later */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
387 if (signal_block_mask & sigmask (nsig))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
388 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
389 signal_pending_mask |= sigmask (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
390 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
391 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
392
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
393 if (signal_handlers[nsig] == SIG_IGN)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
394 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
395
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
396 if (signal_handlers[nsig] != SIG_DFL)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
397 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
398 (*signal_handlers[nsig]) (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
399 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
400 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
401
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
402 /* Default signal actions */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
403 if (nsig == SIGALRM || nsig == SIGPROF)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
404 exit (3);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
405
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
406 /* Other signals are ignored by default */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
407 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
408 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
409
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
410
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
411 /*--------------------------------------------------------------------*/
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
412 /* Async timers */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
413 /*--------------------------------------------------------------------*/
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
414
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
415 /* We emulate two timers, one for SIGALRM, another for SIGPROF.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
416
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
417 itimerproc() function has an implementation limitation: it does
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
418 not allow to set *both* interval and period. If an attempt is
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
419 made to set both, and then they are unequal, the function
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
420 asserts.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
421
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
422 Minimum timer resolution on Win32 systems varies, and is greater
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
423 than or equal than 1 ms. The resolution is always wrapped not to
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
424 attempt to get below the system defined limit.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
425 */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
426
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
427 /* Timer precision, denominator of one fraction: for 100 ms
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
428 interval, request 10 ms precision
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
429 */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
430 const int setitimer_helper_timer_prec = 10;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
431
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
432 /* Last itimervals, as set by calls to setitimer */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
433 static struct itimerval it_alarm;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
434 static struct itimerval it_prof;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
435
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
436 /* Timer IDs as returned by MM */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
437 MMRESULT tid_alarm = 0;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
438 MMRESULT tid_prof = 0;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
439
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
440 static void CALLBACK
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
441 setitimer_helper_proc (UINT uID, UINT uMsg, DWORD dwUser,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
442 DWORD dw1, DWORD dw2)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
443 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
444 /* Just raise the signal indicated by the dwUser parameter */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
445 mswindows_raise (dwUser);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
446 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
447
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
448 /* Divide time in ms specified by IT by DENOM. Return 1 ms
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
449 if division results in zero */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
450 static UINT
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
451 setitimer_helper_period (const struct itimerval* it, UINT denom)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
452 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
453 static TIMECAPS time_caps;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
454
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
455 UINT res;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
456 const struct timeval* tv =
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
457 (it->it_value.tv_sec == 0 && it->it_value.tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
458 ? &it->it_interval : &it->it_value;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
459
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
460 /* Zero means stop timer */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
461 if (tv->tv_sec == 0 && tv->tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
462 return 0;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
463
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
464 /* Convert to ms and divide by denom */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
465 res = (tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000) / denom;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
466
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
467 /* Converge to minimum timer resolution */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
468 if (time_caps.wPeriodMin == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
469 timeGetDevCaps (&time_caps, sizeof(time_caps));
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
470
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
471 if (res < time_caps.wPeriodMin)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
472 res = time_caps.wPeriodMin;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
473
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
474 return res;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
475 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
476
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
477 static int
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
478 setitimer_helper (const struct itimerval* itnew,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
479 struct itimerval* itold, struct itimerval* itcurrent,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
480 MMRESULT* tid, DWORD sigkind)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
481 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
482 UINT delay, resolution, event_type;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
483
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
484 /* First stop the old timer */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
485 if (*tid)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
486 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
487 timeKillEvent (*tid);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
488 timeEndPeriod (setitimer_helper_period (itcurrent,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
489 setitimer_helper_timer_prec));
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
490 *tid = 0;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
491 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
492
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
493 /* Return old itimerval if requested */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
494 if (itold)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
495 *itold = *itcurrent;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
496
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
497 *itcurrent = *itnew;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
498
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
499 /* Determine if to start new timer */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
500 delay = setitimer_helper_period (itnew, 1);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
501 if (delay)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
502 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
503 resolution = setitimer_helper_period (itnew,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
504 setitimer_helper_timer_prec);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
505 event_type = (itnew->it_value.tv_sec == 0 &&
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
506 itnew->it_value.tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
507 ? TIME_ONESHOT : TIME_PERIODIC;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
508 timeBeginPeriod (resolution);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
509 *tid = timeSetEvent (delay, resolution, setitimer_helper_proc, sigkind,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
510 event_type);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
511 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
512
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
513 return !delay || *tid;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
514 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
515
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
516 int
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
517 mswindows_setitimer (int kind, const struct itimerval *itnew,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
518 struct itimerval *itold)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
519 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
520 /* In this version, both interval and value are allowed
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
521 only if they are equal. */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
522 assert ((itnew->it_value.tv_sec == 0 && itnew->it_value.tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
523 || (itnew->it_interval.tv_sec == 0 &&
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
524 itnew->it_interval.tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
525 || (itnew->it_value.tv_sec == itnew->it_interval.tv_sec &&
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
526 itnew->it_value.tv_usec == itnew->it_interval.tv_usec));
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
527
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
528 if (kind == ITIMER_REAL)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
529 return setitimer_helper (itnew, itold, &it_alarm, &tid_alarm, SIGALRM);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
530 else if (kind == ITIMER_PROF)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
531 return setitimer_helper (itnew, itold, &it_prof, &tid_prof, SIGPROF);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
532 else
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
533 return errno = EINVAL;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
534 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
535
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
536 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
537
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
538
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
539 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
540 syms_of_win32 (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
541 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
542 DEFSUBR (Fmswindows_shell_execute);
673
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
543 #ifdef CYGWIN
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
544 DEFSUBR (Fmswindows_cygwin_to_win32_path);
685b588e92d8 [xemacs-hg @ 2001-10-30 05:13:26 by andyp]
andyp
parents: 665
diff changeset
545 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
546 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
547
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
548 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
549 init_win32 (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
550 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
551 init_potentially_nonexistent_functions ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
552 }