* floatfns.c (Flogb): Always implement this by calling Flog, even
[bpt/emacs.git] / src / data.c
index 9b45fc6..f500364 100644 (file)
@@ -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"
@@ -45,6 +46,7 @@ Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
 Lisp_Object Qintegerp, Qnatnump, Qsymbolp, Qlistp, Qconsp;
 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
+Lisp_Object Qbuffer_or_string_p;
 Lisp_Object Qboundp, Qfboundp;
 Lisp_Object Qcdr;
 
@@ -66,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);
        }
@@ -255,8 +257,8 @@ DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "T if OBJECT is a built-in function.")
   return Qnil;
 }
 
-DEFUN ("compiled-function-p", Fcompiled_function_p, Scompiled_function_p,
-       1, 1, 0, "T if OBJECT is a compiled function object.")
+DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
+       1, 1, 0, "T if OBJECT is a byte-compiled function object.")
   (obj)
      Lisp_Object obj;
 {
@@ -307,13 +309,10 @@ DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
   (obj)
      Lisp_Object obj;
 {
-  if (0
-#ifdef LISP_FLOAT_TYPE
-      || XTYPE (obj) == Lisp_Float
-#endif
-      || XTYPE (obj) == Lisp_Int)
+  if (NUMBERP (obj))
     return Qt;
-  return Qnil;
+  else
+    return Qnil;
 }
 
 DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
@@ -322,10 +321,7 @@ DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
   (obj)
      Lisp_Object obj;
 {
-  if (XTYPE (obj) == Lisp_Int
-#ifdef LISP_FLOAT_TYPE
-      || XTYPE (obj) == Lisp_Float
-#endif
+  if (NUMBERP (obj)
       || XTYPE (obj) == Lisp_Marker)
     return Qt;
   return Qnil;
@@ -640,14 +636,17 @@ swap_in_symval_forwarding (sym, valcontents)
      (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
      
      CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
-     local_var_alist, that being the element whose car is this variable.
-     Or it can be a pointer to the (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER
-     does not have an element in its alist for this variable.
-     
-     If the current buffer is not BUFFER, we store the current REALVALUE value into
-     CURRENT-ALIST-ELEMENT, then find the appropriate alist element for
-     the buffer now current and set up CURRENT-ALIST-ELEMENT.
-     Then we set REALVALUE out of that element, and store into BUFFER.
+     local_var_alist, that being the element whose car is this
+     variable.  Or it can be a pointer to the
+     (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have
+     an element in its alist for this variable.
+
+     If the current buffer is not BUFFER, we store the current
+     REALVALUE value into CURRENT-ALIST-ELEMENT, then find the
+     appropriate alist element for the buffer now current and set up
+     CURRENT-ALIST-ELEMENT.  Then we set REALVALUE out of that
+     element, and store into BUFFER.
+
      Note that REALVALUE can be a forwarding pointer. */
 
   register Lisp_Object tem1;
@@ -797,7 +796,8 @@ DEFUN ("set", Fset, Sset, 2, 2, 0,
       if ((current_buffer
           != XBUFFER (XCONS (XCONS (valcontents)->cdr)->car))
          || (XTYPE (valcontents) == Lisp_Buffer_Local_Value
-             && XCONS (current_alist_element)->car == current_alist_element))
+             && EQ (XCONS (current_alist_element)->car,
+                    current_alist_element)))
        {
          /* Write out the cached value for the old buffer; copy it
             back to its alist element.  This works if the current
@@ -1004,6 +1004,8 @@ not have their own values for this variable.")
   return val;
 }
 \f
+/* Lisp functions for creating and removing buffer-local variables.  */
+
 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local,
   1, 1, "vMake Variable Buffer Local: ",
   "Make VARIABLE have a separate value for each buffer.\n\
@@ -1098,8 +1100,18 @@ just as if the variable were set.")
        if (current_buffer == XBUFFER (XCONS (XCONS (xs)->cdr)->car))
          XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->car = Qnil; 
       }
-
     }
+
+  /* If the symbol forwards into a C variable, then swap in the
+     variable for this buffer immediately.  If C code modifies the
+     variable before we swap in, then that new value will clobber the
+     default value the next time we swap.  */
+  valcontents = XCONS (XSYMBOL (sym)->value)->car;
+  if (XTYPE (valcontents) == Lisp_Intfwd
+      || XTYPE (valcontents) == Lisp_Boolfwd
+      || XTYPE (valcontents) == Lisp_Objfwd)
+    swap_in_symval_forwarding (sym, XSYMBOL (sym)->value);
+
   return sym;
 }
 
@@ -1162,7 +1174,7 @@ From now on the default value will apply in this buffer.")
    This is like Findirect_function, except that it doesn't signal an
    error if the chain ends up unbound.  */
 Lisp_Object
-indirect_function (object, error)
+indirect_function (object)
   register Lisp_Object object;
 {
   Lisp_Object tortise, hare;
@@ -1333,6 +1345,9 @@ arithcompare (num1, num2, comparison)
       if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2))
        return Qt;
       return Qnil;
+
+    default:
+      abort ();
     }
 }
 
@@ -1409,8 +1424,9 @@ DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "T if NUMBER is zero.")
 }
 \f
 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;
 {
@@ -1434,24 +1450,36 @@ 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));
 }
 \f  
 enum arithop
   { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin };
 
+extern Lisp_Object float_arith_driver ();
+
 Lisp_Object
 arith_driver
   (code, nargs, args)
@@ -1649,7 +1677,7 @@ Both must be numbers or markers.")
 
       f1 = XTYPE (num1) == Lisp_Float ? XFLOAT (num1)->data : XINT (num1);
       f2 = XTYPE (num2) == Lisp_Float ? XFLOAT (num2)->data : XINT (num2);
-#ifdef USG
+#if defined (USG) || defined (sun) || defined (ultrix) || defined (hpux)
       f1 = fmod (f1, f2);
 #else
       f1 = drem (f1, f2);
@@ -1844,6 +1872,7 @@ syms_of_data ()
   Qvectorp = intern ("vectorp");
   Qchar_or_string_p = intern ("char-or-string-p");
   Qmarkerp = intern ("markerp");
+  Qbuffer_or_string_p = intern ("buffer-or-string-p");
   Qinteger_or_marker_p = intern ("integer-or-marker-p");
   Qboundp = intern ("boundp");
   Qfboundp = intern ("fboundp");
@@ -1983,6 +2012,7 @@ syms_of_data ()
   staticpro (&Qvectorp);
   staticpro (&Qchar_or_string_p);
   staticpro (&Qmarkerp);
+  staticpro (&Qbuffer_or_string_p);
   staticpro (&Qinteger_or_marker_p);
 #ifdef LISP_FLOAT_TYPE
   staticpro (&Qfloatp);
@@ -2016,7 +2046,7 @@ syms_of_data ()
   defsubr (&Sbufferp);
   defsubr (&Smarkerp);
   defsubr (&Ssubrp);
-  defsubr (&Scompiled_function_p);
+  defsubr (&Sbyte_code_function_p);
   defsubr (&Schar_or_string_p);
   defsubr (&Scar);
   defsubr (&Scdr);
@@ -2046,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);