aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorJim Blandy1993-02-22 14:27:14 +0000
committerJim Blandy1993-02-22 14:27:14 +0000
commit25e40a4bb9c59f53907809c5a8d3e850993c8147 (patch)
tree1e869892ef9f4228ea19f6497095f3c6726fd8d0 /src/data.c
parent1dc4f30a69aff5dc9eb142ec178939bb45164c58 (diff)
downloademacs-25e40a4bb9c59f53907809c5a8d3e850993c8147.tar.gz
emacs-25e40a4bb9c59f53907809c5a8d3e850993c8147.zip
* 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.c33
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. */
19 19
20 20
21#include <signal.h> 21#include <signal.h>
22#include <ctype.h>
22 23
23#include "config.h" 24#include "config.h"
24#include "lisp.h" 25#include "lisp.h"
@@ -67,7 +68,7 @@ wrong_type_argument (predicate, value)
67 { 68 {
68 if (XTYPE (value) == Lisp_String && 69 if (XTYPE (value) == Lisp_String &&
69 (EQ (predicate, Qintegerp) || EQ (predicate, Qinteger_or_marker_p))) 70 (EQ (predicate, Qintegerp) || EQ (predicate, Qinteger_or_marker_p)))
70 return Fstring_to_int (value, Qt); 71 return Fstring_to_number (value);
71 if (XTYPE (value) == Lisp_Int && EQ (predicate, Qstringp)) 72 if (XTYPE (value) == Lisp_Int && EQ (predicate, Qstringp))
72 return Fint_to_string (value); 73 return Fint_to_string (value);
73 } 74 }
@@ -1344,6 +1345,9 @@ arithcompare (num1, num2, comparison)
1344 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2)) 1345 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2))
1345 return Qt; 1346 return Qt;
1346 return Qnil; 1347 return Qnil;
1348
1349 default:
1350 abort ();
1347 } 1351 }
1348} 1352}
1349 1353
@@ -1420,8 +1424,9 @@ DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "T if NUMBER is zero.")
1420} 1424}
1421 1425
1422DEFUN ("int-to-string", Fint_to_string, Sint_to_string, 1, 1, 0, 1426DEFUN ("int-to-string", Fint_to_string, Sint_to_string, 1, 1, 0,
1423 "Convert INT to a string by printing it in decimal.\n\ 1427 "Convert NUM to a string by printing it in decimal.\n\
1424Uses a minus sign if negative.") 1428Uses a minus sign if negative.\n\
1429NUM may be an integer or a floating point number.")
1425 (num) 1430 (num)
1426 Lisp_Object num; 1431 Lisp_Object num;
1427{ 1432{
@@ -1445,19 +1450,29 @@ Uses a minus sign if negative.")
1445 return build_string (buffer); 1450 return build_string (buffer);
1446} 1451}
1447 1452
1448DEFUN ("string-to-int", Fstring_to_int, Sstring_to_int, 1, 1, 0, 1453DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 1, 0,
1449 "Convert STRING to an integer by parsing it as a decimal number.") 1454 "Convert STRING to a number by parsing it as a decimal number.\n\
1455This parses both integers and floating point numbers.")
1450 (str) 1456 (str)
1451 register Lisp_Object str; 1457 register Lisp_Object str;
1452{ 1458{
1459 char *p;
1460
1453 CHECK_STRING (str, 0); 1461 CHECK_STRING (str, 0);
1454 1462
1463 p = XSTRING (str)->data;
1464
1465 /* Skip any whitespace at the front of the number. Some versions of
1466 atoi do this anyway, so we might as well make Emacs lisp consistent. */
1467 while (isspace (*p))
1468 p++;
1469
1455#ifdef LISP_FLOAT_TYPE 1470#ifdef LISP_FLOAT_TYPE
1456 if (isfloat_string (XSTRING (str)->data)) 1471 if (isfloat_string (p))
1457 return make_float (atof (XSTRING (str)->data)); 1472 return make_float (atof (p));
1458#endif /* LISP_FLOAT_TYPE */ 1473#endif /* LISP_FLOAT_TYPE */
1459 1474
1460 return make_number (atoi (XSTRING (str)->data)); 1475 return make_number (atoi (p));
1461} 1476}
1462 1477
1463enum arithop 1478enum arithop
@@ -2061,7 +2076,7 @@ syms_of_data ()
2061 defsubr (&Saref); 2076 defsubr (&Saref);
2062 defsubr (&Saset); 2077 defsubr (&Saset);
2063 defsubr (&Sint_to_string); 2078 defsubr (&Sint_to_string);
2064 defsubr (&Sstring_to_int); 2079 defsubr (&Sstring_to_number);
2065 defsubr (&Seqlsign); 2080 defsubr (&Seqlsign);
2066 defsubr (&Slss); 2081 defsubr (&Slss);
2067 defsubr (&Sgtr); 2082 defsubr (&Sgtr);