3 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001
4 Free Software Foundation, Inc.
5 Written by James Clark (jjc@jclark.com)
7 This file is part of groff.
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License along
20 with groff; see the file COPYING. If not, write to the Free Software
21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
36 #define LONG_MAX 2147483647
40 #define LONG_MIN (-LONG_MAX-1)
44 #define ISASCII(c) isascii(c)
46 #define ISASCII(c) (1)
49 long strtol(str
, ptr
, base
)
57 static char digits
[] = "0123456789abcdefghijklmnopqrstuvwxyz";
59 while (ISASCII((unsigned char)*str
) && isspace((unsigned char)*str
))
68 if (str
[1] == 'x' || str
[1] == 'X') {
78 if (base
< 2 || base
> 36)
80 else if (base
== 16 && *str
== '0' && (str
[1] == 'x' || str
[1] == 'X'))
83 p
= strchr(digits
, (ISASCII((unsigned char)*str
)
84 && isupper((unsigned char)*str
)
85 ? tolower((unsigned char)*str
)
87 if (p
== 0 || (val
= (p
- digits
)) >= base
) {
88 if (base
== 16 && str
> start
&& (str
[-1] == 'x' || str
[-1] == 'X')) {
102 while (*++str
!= '\0') {
105 p
= strchr(digits
, (ISASCII((unsigned char)*str
)
106 && isupper((unsigned char)*str
)
107 ? tolower((unsigned char)*str
) : *str
));
114 if (-(unsigned long)val
> (-(unsigned long)LONG_MIN
- n
)/base
) {
122 if (val
> (LONG_MAX
- n
)/base
) {