annotate src/os_win16.c @ 6586:9ac723b9f54d v7.4.619

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