diff options
author | Jim Blandy <jimb@redhat.com> | 1993-02-22 14:27:14 +0000 |
---|---|---|
committer | Jim Blandy <jimb@redhat.com> | 1993-02-22 14:27:14 +0000 |
commit | 25e40a4bb9c59f53907809c5a8d3e850993c8147 (patch) | |
tree | 1e869892ef9f4228ea19f6497095f3c6726fd8d0 /src/data.c | |
parent | 1dc4f30a69aff5dc9eb142ec178939bb45164c58 (diff) | |
download | emacs-25e40a4bb9c59f53907809c5a8d3e850993c8147.tar.gz |
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
lisp parse consistently on different operating systems.
#include <ctype.h> to help with this.
* data.c (Fstring_to_int): Rename this to Fstring_to_number, since
it parses floats as well as integers. Fix docstring.
(syms_of_data): Fix defsubr.
(wrong_type_argument): Change use.
(Fint_to_string): Doc fix.
* lisp.h (Fstring_to_int): Change extern declaration.
* data.c (wrong_type_argument): Pass the correct number of
arguments to Fstring_to_int.
* data.c (arithcompare): Add a default case which aborts, just to
make me happy.
Diffstat (limited to 'src/data.c')
-rw-r--r-- | src/data.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/data.c b/src/data.c index 071cfe853b7..f5003641b38 100644 --- a/src/data.c +++ b/src/data.c @@ -19,6 +19,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <signal.h> +#include <ctype.h> #include "config.h" #include "lisp.h" @@ -67,7 +68,7 @@ wrong_type_argument (predicate, value) { if (XTYPE (value) == Lisp_String && (EQ (predicate, Qintegerp) || EQ (predicate, Qinteger_or_marker_p))) - return Fstring_to_int (value, Qt); + return Fstring_to_number (value); if (XTYPE (value) == Lisp_Int && EQ (predicate, Qstringp)) return Fint_to_string (value); } @@ -1344,6 +1345,9 @@ arithcompare (num1, num2, comparison) if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2)) return Qt; return Qnil; + + default: + abort (); } } @@ -1420,8 +1424,9 @@ DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "T if NUMBER is zero.") } DEFUN ("int-to-string", Fint_to_string, Sint_to_string, 1, 1, 0, - "Convert INT to a string by printing it in decimal.\n\ -Uses a minus sign if negative.") + "Convert NUM to a string by printing it in decimal.\n\ +Uses a minus sign if negative.\n\ +NUM may be an integer or a floating point number.") (num) Lisp_Object num; { @@ -1445,19 +1450,29 @@ Uses a minus sign if negative.") return build_string (buffer); } -DEFUN ("string-to-int", Fstring_to_int, Sstring_to_int, 1, 1, 0, - "Convert STRING to an integer by parsing it as a decimal number.") +DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 1, 0, + "Convert STRING to a number by parsing it as a decimal number.\n\ +This parses both integers and floating point numbers.") (str) register Lisp_Object str; { + char *p; + CHECK_STRING (str, 0); + p = XSTRING (str)->data; + + /* Skip any whitespace at the front of the number. Some versions of + atoi do this anyway, so we might as well make Emacs lisp consistent. */ + while (isspace (*p)) + p++; + #ifdef LISP_FLOAT_TYPE - if (isfloat_string (XSTRING (str)->data)) - return make_float (atof (XSTRING (str)->data)); + if (isfloat_string (p)) + return make_float (atof (p)); #endif /* LISP_FLOAT_TYPE */ - return make_number (atoi (XSTRING (str)->data)); + return make_number (atoi (p)); } enum arithop @@ -2061,7 +2076,7 @@ syms_of_data () defsubr (&Saref); defsubr (&Saset); defsubr (&Sint_to_string); - defsubr (&Sstring_to_int); + defsubr (&Sstring_to_number); defsubr (&Seqlsign); defsubr (&Slss); defsubr (&Sgtr); |