thanks to the nice property of my reimplementation of getn to also

return a value in case of an error (0 or the partial result, which
is the full result in case of trailing junk even), using it to rid
atoi() is possible, saving 9t 4d 1i
This commit is contained in:
tg 2006-11-10 04:03:59 +00:00
parent d91d7feff0
commit a1ff719ba4
4 changed files with 18 additions and 14 deletions

4
exec.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.17 2006/11/10 01:44:39 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.18 2006/11/10 04:03:58 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, char **,
int volatile);
@ -1216,7 +1216,7 @@ do_selectargs(char **ap, bool print_menu)
return NULL;
s = str_val(global("REPLY"));
if (*s) {
i = atoi(s);
getn(s, &i);
return (i >= 1 && i <= argct) ? ap[i - 1] : null;
}
print_menu = 1;

View File

@ -3,7 +3,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.28 2006/11/10 03:50:05 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.29 2006/11/10 04:03:59 tg Exp $");
#if !defined(__sun__)
#define DO_HISTORY
@ -481,8 +481,9 @@ findhistrel(const char *str)
{
int maxhist = histptr - history;
int start = maxhist - 1;
int rec = atoi(str);
int rec;
getn(str, &rec);
if (rec == 0)
return -1;
if (rec > 0) {

6
jobs.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.12 2006/11/09 22:08:07 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.13 2006/11/10 04:03:59 tg Exp $");
/* Order important! */
#define PRUNNING 0
@ -1302,7 +1302,7 @@ j_lookup(const char *cp, int *ecodep)
int len, job = 0;
if (digit(*cp)) {
job = atoi(cp);
getn(cp, &job);
/* Look for last_proc->pid (what $! returns) first... */
for (j = job_list; j != NULL; j = j->next)
if (j->last_proc && j->last_proc->pid == job)
@ -1336,7 +1336,7 @@ j_lookup(const char *cp, int *ecodep)
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
job = atoi(cp);
getn(cp, &job);
for (j = job_list; j != NULL; j = j->next)
if (j->job == job)
return j;

17
misc.c
View File

@ -3,7 +3,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.31 2006/11/10 03:54:38 tg Exp $\t"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.32 2006/11/10 04:03:59 tg Exp $\t"
MKSH_SH_H_ID);
unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */
@ -416,7 +416,7 @@ parse_args(char **argv,
int
getn(const char *s, int *ai)
{
int i, c;
int i, c, rv = 0;
bool neg = false;
do {
@ -427,19 +427,22 @@ getn(const char *s, int *ai)
c = *s++;
} else if (c == '+')
c = *s++;
i = 0;
*ai = i = 0;
do {
*ai = i;
if (!isdigit(c))
return (0);
goto getn_out;
i *= 10;
if (i < *ai)
/* overflow */
return (0);
goto getn_out;
i += c - '0';
*ai = i;
} while ((c = *s++));
rv = 1;
*ai = neg ? -i : i;
getn_out:
if (neg)
*ai = -*ai;
return (1);
}