1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
12 * Win16 (Windows 3.1x) system-dependent routines.
13 * Carved brutally from os_win32.c by Vince Negri <vn@aslnet.co.uk>
28 #include <sys/types.h>
36 #include <shellapi.h> /* required for FindExecutable() */
39 /* Record all output and all keyboard & mouse input */
40 /* #define MCH_WRITE_DUMP */
48 * When generating prototypes for Win32 on Unix, these lines make the syntax
49 * errors disappear. They do not need to be correct.
53 typedef int SMALL_RECT
;
61 typedef int KEY_EVENT_RECORD
;
62 typedef int MOUSE_EVENT_RECORD
;
64 typedef int CONSOLE_CURSOR_INFO
;
65 typedef char * LPCSTR
;
67 typedef int INPUT_RECORD
;
72 /* being a more ANSI compliant compiler, BorlandC doesn't define _stricoll:
73 * but it does in BC 5.02! */
74 # if __BORLANDC__ < 0x502
75 int _stricoll(char *a
, char *b
);
79 /* cproto doesn't create a prototype for main() */
82 __ARGS((int argc
, char **argv
));
83 static int (_cdecl
*pmain
)(int, char **);
86 void _cdecl
SaveInst(HINSTANCE hInst
);
87 static void (_cdecl
*pSaveInst
)(HINSTANCE
);
102 * Ron: added full path name so that the $VIM variable will get set to our
103 * startup path (so the .vimrc file can be found w/o a VIM env. var.)
104 * Remove the ".exe" extension, and find the 1st non-space.
106 GetModuleFileName(hInstance
, prog
, 255);
108 exe_name
= FullName_save((char_u
*)prog
, FALSE
);
110 /* Separate the command line into arguments. */
111 argc
= get_cmd_args(prog
, (char *)lpszCmdLine
, &argv
, &tofree
);
118 pSaveInst
= SaveInst
;
120 pSaveInst(hInstance
);
138 * For the GUI the mouse handling is in gui_w32.c.
145 #endif /* FEAT_MOUSE */
150 * GUI version of mch_init().
158 /* Let critical errors result in a failure, not in a dialog box. Required
159 * for the timestamp test to work on removed floppies. */
160 SetErrorMode(SEM_FAILCRITICALERRORS
);
162 _fmode
= O_BINARY
; /* we do our own CR-LF translation */
164 /* Specify window size. Is there a place to get the default from? */
169 set_option_value((char_u
*)"grepprg", 0, (char_u
*)"grep -n", 0);
171 #ifdef FEAT_CLIPBOARD
175 * Vim's own clipboard format recognises whether the text is char, line,
176 * or rectangular block. Only useful for copying between two Vims.
177 * "VimClipboard" was used for previous versions, using the first
178 * character to specify MCHAR, MLINE or MBLOCK.
180 clip_star
.format
= RegisterClipboardFormat("VimClipboard2");
181 clip_star
.format_raw
= RegisterClipboardFormat("VimRawBytes");
188 * Do we have an interactive window?
197 return OK
; /* GUI always has a tty */
207 return (long)GetCurrentTask();
212 * Specialised version of system().
213 * This version proceeds as follows:
214 * 1. Start the program with WinExec
215 * 2. Wait for the module use count of the program to go to 0
216 * (This is the best way of detecting the program has finished)
220 mch_system(char *cmd
, int options
)
229 * It's nicer to run a filter command in a minimized window, but in
231 if (options
& SHELL_DOOUT
)
232 wShowWindow
= SW_SHOWMINIMIZED
;
234 wShowWindow
= SW_SHOWNORMAL
;
236 /* Now, run the command */
237 h_module
= WinExec((LPCSTR
)cmd
, wShowWindow
);
246 /* Wait for the command to terminate before continuing */
247 while (GetModuleUsage((HINSTANCE
)h_module
) > 0 && again
)
249 while( PeekMessage( &msg
, NULL
, 0, 0, PM_REMOVE
) && again
)
251 if(msg
.message
== WM_QUIT
)
254 PostQuitMessage(msg
.wParam
);
257 TranslateMessage(&msg
);
258 DispatchMessage(&msg
);
267 * Either execute a command by calling the shell or start a new shell
272 int options
) /* SHELL_, see vim.h */
275 int tmode
= cur_tmode
;
280 #ifdef MCH_WRITE_DUMP
283 fprintf(fdDump
, "mch_call_shell(\"%s\", %d)\n", cmd
, options
);
289 * Catch all deadly signals while running the external command, because a
290 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us.
292 signal(SIGINT
, SIG_IGN
);
293 signal(SIGILL
, SIG_IGN
);
294 signal(SIGFPE
, SIG_IGN
);
295 signal(SIGSEGV
, SIG_IGN
);
296 signal(SIGTERM
, SIG_IGN
);
297 signal(SIGABRT
, SIG_IGN
);
299 if (options
& SHELL_COOKED
)
300 settmode(TMODE_COOK
); /* set to normal mode */
304 x
= mch_system(p_sh
, options
);
308 /* we use "command" or "cmd" to start the shell; slow but easy */
312 STRLEN(p_sh
) + STRLEN(p_shcf
) + STRLEN(cmd
) + 10, TRUE
);
315 if (STRNICMP(cmd
, "start ", 6) == 0)
317 sprintf((char *)newcmd
, "%s\0", cmd
+6);
318 if (WinExec((LPCSTR
)newcmd
, SW_SHOWNORMAL
) > 31)
325 sprintf((char *)newcmd
, "%s%s %s %s",
330 x
= mch_system((char *)newcmd
, options
);
336 if (tmode
== TMODE_RAW
)
337 settmode(TMODE_RAW
); /* set to raw mode */
339 if (x
&& !(options
& SHELL_SILENT
) && !emsg_silent
)
341 smsg(_("shell returned %d"), x
);
348 signal(SIGINT
, SIG_DFL
);
349 signal(SIGILL
, SIG_DFL
);
350 signal(SIGFPE
, SIG_DFL
);
351 signal(SIGSEGV
, SIG_DFL
);
352 signal(SIGTERM
, SIG_DFL
);
353 signal(SIGABRT
, SIG_DFL
);
361 * Delay for half a second.
369 Sleep((int)msec
); /* never wait for input */
375 * check for an "interrupt signal": CTRL-break or CTRL-C
385 * How much memory is available?
391 return GetFreeSpace(0);
396 * Like rename(), returns 0 upon success, non-zero upon failure.
397 * Should probably set errno appropriately when errors occur.
401 const char *pszOldFile
,
402 const char *pszNewFile
)
406 * No need to play tricks, this isn't rubbish like Windows 95 <g>
408 return rename(pszOldFile
, pszNewFile
);
413 * Get the default shell for the current hardware platform