annotate src/os_win16.c @ 1535:eb0504d00480 v7.1.250

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