annotate src/os_win16.c @ 1703:ad8f5bdc7274 v7.2.001

updated for version 7.2-001
author vimboss
date Sun, 17 Aug 2008 21:03:18 +0000
parents 18ee39301b82
children 1ddec6983d9e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 * os_win16.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 * Win16 (Windows 3.1x) system-dependent routines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * Carved brutally from os_win32.c by Vince Negri <vn@aslnet.co.uk>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #ifdef __BORLANDC__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 # pragma warn -par
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 # pragma warn -ucp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 # pragma warn -use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 # pragma warn -aus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 # pragma warn -obs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 379
diff changeset
23 #include "vimio.h"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 #include <dos.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 #include <string.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 #include <sys/types.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 #include <errno.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 #include <signal.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 #include <limits.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #include <process.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 #undef chdir
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #include <direct.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 #include <shellapi.h> /* required for FindExecutable() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 /* Record all output and all keyboard & mouse input */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 /* #define MCH_WRITE_DUMP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 #ifdef MCH_WRITE_DUMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 FILE* fdDump = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 * When generating prototypes for Win32 on Unix, these lines make the syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 * errors disappear. They do not need to be correct.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 #ifdef PROTO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 typedef int HANDLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 typedef int SMALL_RECT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 typedef int COORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 typedef int SHORT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 typedef int WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 typedef int DWORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 typedef int BOOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 typedef int LPSTR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 typedef int LPTSTR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 typedef int KEY_EVENT_RECORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 typedef int MOUSE_EVENT_RECORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 # define WINAPI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 typedef int CONSOLE_CURSOR_INFO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 typedef char * LPCSTR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 # define WINBASEAPI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 typedef int INPUT_RECORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 # define _cdecl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 #ifdef __BORLANDC__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 /* being a more ANSI compliant compiler, BorlandC doesn't define _stricoll:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 * but it does in BC 5.02! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 # if __BORLANDC__ < 0x502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 int _stricoll(char *a, char *b);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 /* cproto doesn't create a prototype for main() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 int _cdecl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 VimMain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 __ARGS((int argc, char **argv));
379
d6d6ca943713 updated for version 7.0098
vimboss
parents: 7
diff changeset
83 static int (_cdecl *pmain)(int, char **);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 #ifndef PROTO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 void _cdecl SaveInst(HINSTANCE hInst);
379
d6d6ca943713 updated for version 7.0098
vimboss
parents: 7
diff changeset
87 static void (_cdecl *pSaveInst)(HINSTANCE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 int WINAPI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 WinMain(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 HINSTANCE hInstance,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 HINSTANCE hPrevInst,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 LPSTR lpszCmdLine,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 int nCmdShow)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 int argc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 char **argv;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 char *tofree;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 char prog[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 * Ron: added full path name so that the $VIM variable will get set to our
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 * startup path (so the .vimrc file can be found w/o a VIM env. var.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 * Remove the ".exe" extension, and find the 1st non-space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 GetModuleFileName(hInstance, prog, 255);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 if (*prog != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 exe_name = FullName_save((char_u *)prog, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 /* Separate the command line into arguments. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 argc = get_cmd_args(prog, (char *)lpszCmdLine, &argv, &tofree);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 if (argc == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 /* Error message? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 pSaveInst = SaveInst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 pmain = VimMain;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 pSaveInst(hInstance);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 pmain(argc, argv);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 free(argv);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 free(tofree);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 * For the GUI the mouse handling is in gui_w32.c.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 mch_setmouse(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 int on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 #endif /* FEAT_MOUSE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 * GUI version of mch_init().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 mch_init()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 extern int _fmode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 /* Let critical errors result in a failure, not in a dialog box. Required
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 * for the timestamp test to work on removed floppies. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 SetErrorMode(SEM_FAILCRITICALERRORS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 _fmode = O_BINARY; /* we do our own CR-LF translation */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 /* Specify window size. Is there a place to get the default from? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 Rows = 25;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 Columns = 80;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 #ifdef FEAT_CLIPBOARD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 clip_init(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 * Vim's own clipboard format recognises whether the text is char, line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 * or rectangular block. Only useful for copying between two Vims.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 * "VimClipboard" was used for previous versions, using the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 * character to specify MCHAR, MLINE or MBLOCK.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 clip_star.format = RegisterClipboardFormat("VimClipboard2");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 * Do we have an interactive window?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 mch_check_win(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 int argc,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 char **argv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 return OK; /* GUI always has a tty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 * return process ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 mch_get_pid()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 return (long)GetCurrentTask();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 * Specialised version of system().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 * This version proceeds as follows:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 * 1. Start the program with WinExec
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 * 2. Wait for the module use count of the program to go to 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 * (This is the best way of detecting the program has finished)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 mch_system(char *cmd, int options)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 DWORD ret = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 UINT wShowWindow;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 UINT h_module;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 MSG msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 BOOL again = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 * It's nicer to run a filter command in a minimized window, but in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 if (options & SHELL_DOOUT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 wShowWindow = SW_SHOWMINIMIZED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 wShowWindow = SW_SHOWNORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 /* Now, run the command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 h_module = WinExec((LPCSTR)cmd, wShowWindow);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 if (h_module < 32)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 /*error*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 ret = -h_module;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 /* Wait for the command to terminate before continuing */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 while (GetModuleUsage((HINSTANCE)h_module) > 0 && again )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) && again )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 if(msg.message == WM_QUIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 PostQuitMessage(msg.wParam);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 again = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 TranslateMessage(&msg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 DispatchMessage(&msg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 * Either execute a command by calling the shell or start a new shell
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 mch_call_shell(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 char_u *cmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 int options) /* SHELL_, see vim.h */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 int tmode = cur_tmode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 #ifdef MCH_WRITE_DUMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 if (fdDump)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 fflush(fdDump);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 * Catch all deadly signals while running the external command, because a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 signal(SIGINT, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 signal(SIGILL, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 signal(SIGFPE, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 signal(SIGSEGV, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 signal(SIGTERM, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 signal(SIGABRT, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 if (options & SHELL_COOKED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 settmode(TMODE_COOK); /* set to normal mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 if (cmd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 x = mch_system(p_sh, options);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 /* we use "command" or "cmd" to start the shell; slow but easy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 char_u *newcmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 newcmd = lalloc(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 if (newcmd != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 if (STRNICMP(cmd, "start ", 6) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 sprintf((char *)newcmd, "%s\0", cmd+6);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 if (WinExec((LPCSTR)newcmd, SW_SHOWNORMAL) > 31)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 x = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 x = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 sprintf((char *)newcmd, "%s%s %s %s",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 "",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 p_sh,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 p_shcf,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 x = mch_system((char *)newcmd, options);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 vim_free(newcmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 if (tmode == TMODE_RAW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 settmode(TMODE_RAW); /* set to raw mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 if (x && !(options & SHELL_SILENT) && !emsg_silent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 smsg(_("shell returned %d"), x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 #ifdef FEAT_TITLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 resettitle();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 signal(SIGINT, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 signal(SIGILL, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 signal(SIGFPE, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 signal(SIGSEGV, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 signal(SIGTERM, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 signal(SIGABRT, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 return x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 * Delay for half a second.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 mch_delay(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 long msec,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 int ignoreinput)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 #ifdef MUST_FIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 Sleep((int)msec); /* never wait for input */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 * check for an "interrupt signal": CTRL-break or CTRL-C
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 mch_breakcheck()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 /* never used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 * How much memory is available?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 long_u
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 mch_avail_mem(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 int special)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 return GetFreeSpace(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 * Like rename(), returns 0 upon success, non-zero upon failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 * Should probably set errno appropriately when errors occur.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 mch_rename(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 const char *pszOldFile,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 const char *pszNewFile)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 * No need to play tricks, this isn't rubbish like Windows 95 <g>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 return rename(pszOldFile, pszNewFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 * Get the default shell for the current hardware platform
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 char*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 default_shell()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 char* psz = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 psz = "command.com";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 return psz;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 }