annotate src/os_win16.c @ 3316:7b17a38eb223 v7.3.425

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