diff options
| author | Gerd Moellmann | 2000-03-16 13:23:06 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-03-16 13:23:06 +0000 |
| commit | bf5d1a173b0c8360a54f55f189a1fb3248ae586f (patch) | |
| tree | d3a92960d7158902c1308ef6adb1a2d23297c495 /src | |
| parent | 99633e97e9550fdf274c64f213de0d59c759bc98 (diff) | |
| download | emacs-bf5d1a173b0c8360a54f55f189a1fb3248ae586f.tar.gz emacs-bf5d1a173b0c8360a54f55f189a1fb3248ae586f.zip | |
(read_integer): New function.
(read1): Support read syntax #o, #x, #b, #r.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/lread.c b/src/lread.c index 5e373bee9a2..14c6f608b86 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1596,6 +1596,69 @@ read_escape (readcharfun, stringp) | |||
| 1596 | } | 1596 | } |
| 1597 | } | 1597 | } |
| 1598 | 1598 | ||
| 1599 | |||
| 1600 | /* Read an integer in radix RADIX using READCHARFUN to read | ||
| 1601 | characters. RADIX must be in the interval [2..36]; if it isn't, a | ||
| 1602 | read error is signaled . Value is the integer read. Signals an | ||
| 1603 | error if encountering invalid read syntax or if RADIX is out of | ||
| 1604 | range. */ | ||
| 1605 | |||
| 1606 | static Lisp_Object | ||
| 1607 | read_integer (readcharfun, radix) | ||
| 1608 | Lisp_Object readcharfun; | ||
| 1609 | int radix; | ||
| 1610 | { | ||
| 1611 | int number, ndigits, invalid_p, c, sign; | ||
| 1612 | |||
| 1613 | if (radix < 2 || radix > 36) | ||
| 1614 | invalid_p = 1; | ||
| 1615 | else | ||
| 1616 | { | ||
| 1617 | number = ndigits = invalid_p = 0; | ||
| 1618 | sign = 1; | ||
| 1619 | |||
| 1620 | c = READCHAR; | ||
| 1621 | if (c == '-') | ||
| 1622 | { | ||
| 1623 | c = READCHAR; | ||
| 1624 | sign = -1; | ||
| 1625 | } | ||
| 1626 | else if (c == '+') | ||
| 1627 | c = READCHAR; | ||
| 1628 | |||
| 1629 | while (c >= 0) | ||
| 1630 | { | ||
| 1631 | int digit; | ||
| 1632 | |||
| 1633 | if (c >= '0' && c <= '9') | ||
| 1634 | digit = c - '0'; | ||
| 1635 | else if (c >= 'a' && c <= 'z') | ||
| 1636 | digit = c - 'a' + 10; | ||
| 1637 | else if (c >= 'A' && c <= 'Z') | ||
| 1638 | digit = c - 'A' + 10; | ||
| 1639 | else | ||
| 1640 | break; | ||
| 1641 | |||
| 1642 | if (digit < 0 || digit >= radix) | ||
| 1643 | invalid_p = 1; | ||
| 1644 | |||
| 1645 | number = radix * number + digit; | ||
| 1646 | ++ndigits; | ||
| 1647 | c = READCHAR; | ||
| 1648 | } | ||
| 1649 | } | ||
| 1650 | |||
| 1651 | if (ndigits == 0 || invalid_p) | ||
| 1652 | { | ||
| 1653 | char buf[50]; | ||
| 1654 | sprintf (buf, "integer, radix %d", radix); | ||
| 1655 | Fsignal (Qinvalid_read_syntax, Fcons (build_string (buf), Qnil)); | ||
| 1656 | } | ||
| 1657 | |||
| 1658 | return make_number (sign * number); | ||
| 1659 | } | ||
| 1660 | |||
| 1661 | |||
| 1599 | /* If the next token is ')' or ']' or '.', we store that character | 1662 | /* If the next token is ')' or ']' or '.', we store that character |
| 1600 | in *PCH and the return value is not interesting. Else, we store | 1663 | in *PCH and the return value is not interesting. Else, we store |
| 1601 | zero in *PCH and we read and return one lisp object. | 1664 | zero in *PCH and we read and return one lisp object. |
| @@ -1868,8 +1931,17 @@ read1 (readcharfun, pch, first_in_list) | |||
| 1868 | return XCDR (tem); | 1931 | return XCDR (tem); |
| 1869 | /* Fall through to error message. */ | 1932 | /* Fall through to error message. */ |
| 1870 | } | 1933 | } |
| 1934 | else if (c == 'r' || c == 'R') | ||
| 1935 | return read_integer (readcharfun, n); | ||
| 1936 | |||
| 1871 | /* Fall through to error message. */ | 1937 | /* Fall through to error message. */ |
| 1872 | } | 1938 | } |
| 1939 | else if (c == 'x' || c == 'X') | ||
| 1940 | return read_integer (readcharfun, 16); | ||
| 1941 | else if (c == 'o' || c == 'O') | ||
| 1942 | return read_integer (readcharfun, 8); | ||
| 1943 | else if (c == 'b' || c == 'B') | ||
| 1944 | return read_integer (readcharfun, 2); | ||
| 1873 | 1945 | ||
| 1874 | UNREAD (c); | 1946 | UNREAD (c); |
| 1875 | Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil)); | 1947 | Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil)); |