Skip to content

Commit 942d6b2

Browse files
committed
patch 7.4.1283
Problem: The job feature isn't available on MS-Windows. Solution: Add the job feature. Fix argument of job_stop(). (Yasuhiro Matsumoto)
1 parent 768ce24 commit 942d6b2

5 files changed

Lines changed: 63 additions & 5 deletions

File tree

src/eval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8205,7 +8205,7 @@ static struct fst
82058205
#ifdef FEAT_JOB
82068206
{"job_start", 1, 2, f_job_start},
82078207
{"job_status", 1, 1, f_job_status},
8208-
{"job_stop", 1, 1, f_job_stop},
8208+
{"job_stop", 1, 2, f_job_stop},
82098209
#endif
82108210
{"join", 1, 2, f_join},
82118211
{"jsdecode", 1, 1, f_jsdecode},
@@ -14286,7 +14286,7 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1428614286

1428714287
rettv->vval.v_job->jv_status = JOB_FAILED;
1428814288
#ifndef USE_ARGV
14289-
ga_init2(&ga, 200);
14289+
ga_init2(&ga, (int)sizeof(char*), 20);
1429014290
#endif
1429114291

1429214292
if (argvars[0].v_type == VAR_STRING)

src/feature.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,9 +1262,9 @@
12621262
#endif
12631263

12641264
/*
1265-
* The +job feature requires Unix and +eval.
1265+
* The +job feature requires +eval and Unix or MS-Widndows.
12661266
*/
1267-
#if defined(UNIX) && defined(FEAT_EVAL)
1267+
#if (defined(UNIX) || defined(WIN32)) && defined(FEAT_EVAL)
12681268
# define FEAT_JOB
12691269
#endif
12701270

src/os_win32.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4155,7 +4155,7 @@ mch_system_classic(char *cmd, int options)
41554155
si.cbReserved2 = 0;
41564156
si.lpReserved2 = NULL;
41574157

4158-
/* There is a strange error on Windows 95 when using "c:\\command.com".
4158+
/* There is a strange error on Windows 95 when using "c:\command.com".
41594159
* When the "c:\\" is left out it works OK...? */
41604160
if (mch_windows95()
41614161
&& (STRNICMP(cmd, "c:/command.com", 14) == 0
@@ -5032,6 +5032,59 @@ mch_call_shell(
50325032
return x;
50335033
}
50345034

5035+
#if defined(FEAT_JOB) || defined(PROTO)
5036+
void
5037+
mch_start_job(char *cmd, job_T *job)
5038+
{
5039+
STARTUPINFO si;
5040+
PROCESS_INFORMATION pi;
5041+
5042+
ZeroMemory(&si, sizeof(si));
5043+
si.cb = sizeof(si);
5044+
5045+
if (!vim_create_process(cmd, FALSE,
5046+
CREATE_DEFAULT_ERROR_MODE |
5047+
CREATE_NEW_PROCESS_GROUP |
5048+
CREATE_NO_WINDOW,
5049+
&si, &pi))
5050+
job->jv_status = JOB_FAILED;
5051+
else
5052+
{
5053+
job->jf_pi = pi;
5054+
job->jv_status = JOB_STARTED;
5055+
}
5056+
}
5057+
5058+
char *
5059+
mch_job_status(job_T *job)
5060+
{
5061+
DWORD dwExitCode = 0;
5062+
5063+
if (!GetExitCodeProcess(job->jf_pi.hProcess, &dwExitCode))
5064+
return "dead";
5065+
if (dwExitCode != STILL_ACTIVE)
5066+
{
5067+
CloseHandle(job->jf_pi.hProcess);
5068+
CloseHandle(job->jf_pi.hThread);
5069+
return "dead";
5070+
}
5071+
return "run";
5072+
}
5073+
5074+
int
5075+
mch_stop_job(job_T *job, char_u *how)
5076+
{
5077+
if (STRCMP(how, "kill") == 0)
5078+
TerminateProcess(job->jf_pi.hProcess, 0);
5079+
else
5080+
return GenerateConsoleCtrlEvent(
5081+
STRCMP(how, "hup") == 0 ?
5082+
CTRL_BREAK_EVENT : CTRL_C_EVENT,
5083+
job->jf_pi.dwProcessId) ? OK : FAIL;
5084+
return OK;
5085+
}
5086+
#endif
5087+
50355088

50365089
#ifndef FEAT_GUI_W32
50375090

src/proto/os_win32.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ void mch_set_shellsize(void);
4040
void mch_new_shellsize(void);
4141
void mch_set_winsize_now(void);
4242
int mch_call_shell(char_u *cmd, int options);
43+
void mch_start_job(char *cmd, job_T *job);
44+
char *mch_job_status(job_T *job);
45+
int mch_stop_job(job_T *job, char_u *how);
4346
void mch_set_normal_colors(void);
4447
void mch_write(char_u *s, int len);
4548
void mch_delay(long msec, int ignoreinput);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ static char *(features[]) =
747747

748748
static int included_patches[] =
749749
{ /* Add new patch number below this line */
750+
/**/
751+
1283,
750752
/**/
751753
1282,
752754
/**/

0 commit comments

Comments
 (0)