#ifdef __BORLANDC__
# pragma warn -par
# pragma warn -ucp
# pragma warn -use
# pragma warn -aus
# pragma warn -obs
#endif
#include "vimio.h"
#include "vim.h"
#include <fcntl.h>
#include <dos.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <signal.h>
#include <limits.h>
#include <process.h>
#undef chdir
#include <direct.h>
#include <shellapi.h>
#ifdef MCH_WRITE_DUMP
FILE* fdDump = NULL;
#endif
#ifdef PROTO
typedef int HANDLE;
typedef int SMALL_RECT;
typedef int COORD;
typedef int SHORT;
typedef int WORD;
typedef int DWORD;
typedef int BOOL;
typedef int LPSTR;
typedef int LPTSTR;
typedef int KEY_EVENT_RECORD;
typedef int MOUSE_EVENT_RECORD;
# define WINAPI
typedef int CONSOLE_CURSOR_INFO;
typedef char * LPCSTR;
# define WINBASEAPI
typedef int INPUT_RECORD;
# define _cdecl
#endif
#ifdef __BORLANDC__
# if __BORLANDC__ < 0x502
int _stricoll(char *a, char *b);
# endif
#endif
int _cdecl
VimMain
__ARGS((int argc, char **argv));
static int (_cdecl *pmain)(int, char **);
#ifndef PROTO
void _cdecl SaveInst(HINSTANCE hInst);
static void (_cdecl *pSaveInst)(HINSTANCE);
int WINAPI
WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
int argc;
char **argv;
char *tofree;
char prog[256];
GetModuleFileName(hInstance, prog, 255);
if (*prog != NUL)
exe_name = FullName_save((char_u *)prog, FALSE);
argc = get_cmd_args(prog, (char *)lpszCmdLine, &argv, &tofree);
if (argc == 0)
{
return 0;
}
pSaveInst = SaveInst;
pmain = VimMain;
pSaveInst(hInstance);
pmain(argc, argv);
free(argv);
free(tofree);
return 0;
}
#endif
#ifdef FEAT_MOUSE
void
mch_setmouse(
int on)
{
}
#endif
void
mch_init()
{
extern int _fmode;
SetErrorMode(SEM_FAILCRITICALERRORS);
_fmode = O_BINARY;
Rows = 25;
Columns = 80;
set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0);
#ifdef FEAT_CLIPBOARD
clip_init(TRUE);
clip_star.format = RegisterClipboardFormat("VimClipboard2");
clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
#endif
}
int
mch_check_win(
int argc,
char **argv)
{
int i;
return OK;
}
long
mch_get_pid()
{
return (long)GetCurrentTask();
}
static int
mch_system(char *cmd, int options)
{
DWORD ret = 0;
UINT wShowWindow;
UINT h_module;
MSG msg;
BOOL again = TRUE;
if (options & SHELL_DOOUT)
wShowWindow = SW_SHOWMINIMIZED;
else
wShowWindow = SW_SHOWNORMAL;
h_module = WinExec((LPCSTR)cmd, wShowWindow);
if (h_module < 32)
{
ret = -h_module;
}
else
{
while (GetModuleUsage((HINSTANCE)h_module) > 0 && again )
{
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) && again )
{
if(msg.message == WM_QUIT)
{
PostQuitMessage(msg.wParam);
again = FALSE;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return ret;
}
int
mch_call_shell(
char_u *cmd,
int options)
{
int x;
int tmode = cur_tmode;
out_flush();
#ifdef MCH_WRITE_DUMP
if (fdDump)
{
fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options);
fflush(fdDump);
}
#endif
signal(SIGINT, SIG_IGN);
signal(SIGILL, SIG_IGN);
signal(SIGFPE, SIG_IGN);
signal(SIGSEGV, SIG_IGN);
signal(SIGTERM, SIG_IGN);
signal(SIGABRT, SIG_IGN);
if (options & SHELL_COOKED)
settmode(TMODE_COOK);
if (cmd == NULL)
{
x = mch_system(p_sh, options);
}
else
{
char_u *newcmd;
newcmd = lalloc(
STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10, TRUE);
if (newcmd != NULL)
{
if (STRNICMP(cmd, "start ", 6) == 0)
{
sprintf((char *)newcmd, "%s\0", cmd+6);
if (WinExec((LPCSTR)newcmd, SW_SHOWNORMAL) > 31)
x = 0;
else
x = -1;
}
else
{
sprintf((char *)newcmd, "%s%s %s %s",
"",
p_sh,
p_shcf,
cmd);
x = mch_system((char *)newcmd, options);
}
vim_free(newcmd);
}
}
if (tmode == TMODE_RAW)
settmode(TMODE_RAW);
if (x && !(options & SHELL_SILENT) && !emsg_silent)
{
smsg(_("shell returned %d"), x);
msg_putchar('\n');
}
#ifdef FEAT_TITLE
resettitle();
#endif
signal(SIGINT, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGFPE, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGABRT, SIG_DFL);
return x;
}
void
mch_delay(
long msec,
int ignoreinput)
{
#ifdef MUST_FIX
Sleep((int)msec);
#endif
}
void
mch_breakcheck()
{
}
long_u
mch_avail_mem(
int special)
{
return GetFreeSpace(0);
}
int
mch_rename(
const char *pszOldFile,
const char *pszNewFile)
{
return rename(pszOldFile, pszNewFile);
}
char*
default_shell()
{
char* psz = NULL;
psz = "command.com";
return psz;
}