Changeset View
Changeset View
Standalone View
Standalone View
head/bin/sh/arith_yylex.c
Show All 29 Lines | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <ctype.h> | |||||
#include <errno.h> | |||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "shell.h" | #include "shell.h" | ||||
#include "arith_yacc.h" | #include "arith_yacc.h" | ||||
#include "expand.h" | #include "expand.h" | ||||
#include "error.h" | #include "error.h" | ||||
#include "memalloc.h" | #include "memalloc.h" | ||||
#include "parser.h" | #include "parser.h" | ||||
#include "syntax.h" | #include "syntax.h" | ||||
#if ARITH_BOR + 11 != ARITH_BORASS || ARITH_ASS + 11 != ARITH_EQ | #if ARITH_BOR + 11 != ARITH_BORASS || ARITH_ASS + 11 != ARITH_EQ | ||||
#error Arithmetic tokens are out of order. | #error Arithmetic tokens are out of order. | ||||
#endif | #endif | ||||
arith_t | |||||
strtoarith_t(const char *restrict nptr, char **restrict endptr) | |||||
{ | |||||
arith_t val; | |||||
while (isspace((unsigned char)*nptr)) | |||||
nptr++; | |||||
switch (*nptr) { | |||||
case '-': | |||||
return strtoimax(nptr, endptr, 0); | |||||
case '0': | |||||
return (arith_t)strtoumax(nptr, endptr, 0); | |||||
default: | |||||
val = (arith_t)strtoumax(nptr, endptr, 0); | |||||
if (val >= 0) | |||||
return val; | |||||
else if (val == ARITH_MIN) { | |||||
errno = ERANGE; | |||||
return ARITH_MIN; | |||||
} else { | |||||
errno = ERANGE; | |||||
return ARITH_MAX; | |||||
} | |||||
} | |||||
} | |||||
int | int | ||||
yylex(void) | yylex(void) | ||||
{ | { | ||||
int value; | int value; | ||||
const char *buf = arith_buf; | const char *buf = arith_buf; | ||||
char *end; | char *end; | ||||
const char *p; | const char *p; | ||||
Show All 12 Lines | for (;;) { | ||||
case '2': | case '2': | ||||
case '3': | case '3': | ||||
case '4': | case '4': | ||||
case '5': | case '5': | ||||
case '6': | case '6': | ||||
case '7': | case '7': | ||||
case '8': | case '8': | ||||
case '9': | case '9': | ||||
yylval.val = strtoarith_t(buf, &end, 0); | yylval.val = strtoarith_t(buf, &end); | ||||
arith_buf = end; | arith_buf = end; | ||||
return ARITH_NUM; | return ARITH_NUM; | ||||
case 'A': | case 'A': | ||||
case 'B': | case 'B': | ||||
case 'C': | case 'C': | ||||
case 'D': | case 'D': | ||||
case 'E': | case 'E': | ||||
case 'F': | case 'F': | ||||
▲ Show 20 Lines • Show All 159 Lines • Show Last 20 Lines |