a bit oksh-inspired getn return value checking, plus some code optimisation
This commit is contained in:
parent
a1ba509bb9
commit
b7332de28c
8
exec.c
8
exec.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.150 2015/04/19 14:23:26 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.151 2015/04/19 14:40:08 tg Exp $");
|
||||||
|
|
||||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||||
@ -1597,9 +1597,9 @@ do_selectargs(const char **ap, bool print_menu)
|
|||||||
if (call_builtin(findcom("read", FC_BI), read_args, Tselect,
|
if (call_builtin(findcom("read", FC_BI), read_args, Tselect,
|
||||||
false))
|
false))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
s = str_val(global("REPLY"));
|
if (*(s = str_val(global("REPLY"))))
|
||||||
if (*s && getn(s, &i))
|
return ((getn(s, &i) && i >= 1 && i <= argct) ?
|
||||||
return ((i >= 1 && i <= argct) ? ap[i - 1] : null);
|
ap[i - 1] : null);
|
||||||
print_menu = true;
|
print_menu = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
jobs.c
14
jobs.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.111 2015/04/19 14:23:26 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.112 2015/04/19 14:40:09 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
#define mksh_killpg killpg
|
#define mksh_killpg killpg
|
||||||
@ -1644,8 +1644,7 @@ j_lookup(const char *cp, int *ecodep)
|
|||||||
size_t len;
|
size_t len;
|
||||||
int job = 0;
|
int job = 0;
|
||||||
|
|
||||||
if (ksh_isdigit(*cp)) {
|
if (ksh_isdigit(*cp) && getn(cp, &job)) {
|
||||||
getn(cp, &job);
|
|
||||||
/* Look for last_proc->pid (what $! returns) first... */
|
/* Look for last_proc->pid (what $! returns) first... */
|
||||||
for (j = job_list; j != NULL; j = j->next)
|
for (j = job_list; j != NULL; j = j->next)
|
||||||
if (j->last_proc && j->last_proc->pid == job)
|
if (j->last_proc && j->last_proc->pid == job)
|
||||||
@ -1657,11 +1656,10 @@ j_lookup(const char *cp, int *ecodep)
|
|||||||
for (j = job_list; j != NULL; j = j->next)
|
for (j = job_list; j != NULL; j = j->next)
|
||||||
if (j->pgrp && j->pgrp == job)
|
if (j->pgrp && j->pgrp == job)
|
||||||
return (j);
|
return (j);
|
||||||
if (ecodep)
|
goto j_lookup_nosuch;
|
||||||
*ecodep = JL_NOSUCH;
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
if (*cp != '%') {
|
if (*cp != '%') {
|
||||||
|
j_lookup_invalid:
|
||||||
if (ecodep)
|
if (ecodep)
|
||||||
*ecodep = JL_INVALID;
|
*ecodep = JL_INVALID;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@ -1681,7 +1679,8 @@ j_lookup(const char *cp, int *ecodep)
|
|||||||
|
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
getn(cp, &job);
|
if (!getn(cp, &job))
|
||||||
|
goto j_lookup_invalid;
|
||||||
for (j = job_list; j != NULL; j = j->next)
|
for (j = job_list; j != NULL; j = j->next)
|
||||||
if (j->job == job)
|
if (j->job == job)
|
||||||
return (j);
|
return (j);
|
||||||
@ -1721,6 +1720,7 @@ j_lookup(const char *cp, int *ecodep)
|
|||||||
return (last_match);
|
return (last_match);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
j_lookup_nosuch:
|
||||||
if (ecodep)
|
if (ecodep)
|
||||||
*ecodep = JL_NOSUCH;
|
*ecodep = JL_NOSUCH;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user