/* * Convert a string into an integer of type intmax_t. Alow trailing spaces. */ intmax_t atomax(const char *s, int base) { char *p; intmax_t r; errno = 0; r = strtoimax(s, &p, base); if (errno != 0) badnum(s); /* * Disallow completely blank strings in non-arithmetic (base != 0) * contexts. */ if (p == s && base) badnum(s); while (isspace((unsigned char)*p)) p++; if (*p) badnum(s); return r; }
static void b_shift(char **av) { int shift = (av[1] == NULL ? 1 : a2u(av[1])); List *s, *dollarzero; if (av[1] != NULL && av[2] != NULL) { arg_count("shift"); return; } if (shift < 0) { badnum(av[1]); return; } s = varlookup("*")->n; dollarzero = varlookup("0"); while (s != NULL && shift != 0) { s = s->n; --shift; } if (s == NULL && shift != 0) { fprint(2, "cannot shift\n"); set(FALSE); } else { varassign("*", append(dollarzero, s), FALSE); set(TRUE); } }
int number(const char *s) { intmax_t n = atomax10(s); if (n < 0 || n > INT_MAX) badnum(s); return n; }
static void b_wait(char **av) { int status; pid_t pid; if (av[1] == NULL) { waitforall(); return; } if (av[2] != NULL) { arg_count("wait"); return; } if ((pid = a2u(av[1])) < 0) { badnum(av[1]); return; } if (rc_wait4(pid, &status, FALSE) > 0) setstatus(pid, status); else set(FALSE); sigchk(); }