Convert (most) functions in src to standard C.
[bpt/emacs.git] / src / data.c
index a56b112..156c900 100644 (file)
@@ -50,7 +50,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <math.h>
 
 #if !defined (atof)
-extern double atof ();
+extern double atof (const char *);
 #endif /* !atof */
 
 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qsubr, Qunbound;
@@ -97,16 +97,14 @@ Lisp_Object Vmost_positive_fixnum, Vmost_negative_fixnum;
 
 
 void
-circular_list_error (list)
-     Lisp_Object list;
+circular_list_error (Lisp_Object list)
 {
   xsignal (Qcircular_list, list);
 }
 
 
 Lisp_Object
-wrong_type_argument (predicate, value)
-     register Lisp_Object predicate, value;
+wrong_type_argument (register Lisp_Object predicate, register Lisp_Object value)
 {
   /* If VALUE is not even a valid Lisp object, we'd want to abort here
      where we can get a backtrace showing where it came from.  We used
@@ -119,21 +117,19 @@ wrong_type_argument (predicate, value)
 }
 
 void
-pure_write_error ()
+pure_write_error (void)
 {
   error ("Attempt to modify read-only object");
 }
 
 void
-args_out_of_range (a1, a2)
-     Lisp_Object a1, a2;
+args_out_of_range (Lisp_Object a1, Lisp_Object a2)
 {
   xsignal2 (Qargs_out_of_range, a1, a2);
 }
 
 void
-args_out_of_range_3 (a1, a2, a3)
-     Lisp_Object a1, a2, a3;
+args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
 {
   xsignal3 (Qargs_out_of_range, a1, a2, a3);
 }
@@ -146,8 +142,7 @@ int sign_extend_temp;
 /* On a few machines, XINT can only be done by calling this.  */
 
 int
-sign_extend_lisp_int (num)
-     EMACS_INT num;
+sign_extend_lisp_int (EMACS_INT num)
 {
   if (num & (((EMACS_INT) 1) << (VALBITS - 1)))
     return num | (((EMACS_INT) (-1)) << VALBITS);
@@ -840,8 +835,7 @@ Value, if non-nil, is a list \(interactive SPEC).  */)
    indirections contains a loop.  */
 
 struct Lisp_Symbol *
-indirect_variable (symbol)
-     struct Lisp_Symbol *symbol;
+indirect_variable (struct Lisp_Symbol *symbol)
 {
   struct Lisp_Symbol *tortoise, *hare;
 
@@ -892,8 +886,7 @@ variable chain of symbols.  */)
   ((blv)->forwarded ? do_symval_forwarding (BLV_FWD (blv)) : BLV_VALUE (blv))
 
 Lisp_Object
-do_symval_forwarding (valcontents)
-     register union Lisp_Fwd *valcontents;
+do_symval_forwarding (register union Lisp_Fwd *valcontents)
 {
   register Lisp_Object val;
   switch (XFWDTYPE (valcontents))
@@ -947,11 +940,11 @@ do_symval_forwarding (valcontents)
   } while (0)
 
 static void
-store_symval_forwarding (/* symbol, */ valcontents, newval, buf)
+store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newval, struct buffer *buf)
      /* struct Lisp_Symbol *symbol; */
-     union Lisp_Fwd *valcontents;
-     register Lisp_Object newval;
-     struct buffer *buf;
+                                 
+                                 
+                        
 {
   switch (XFWDTYPE (valcontents))
     {
@@ -959,14 +952,14 @@ store_symval_forwarding (/* symbol, */ valcontents, newval, buf)
       CHECK_NUMBER (newval);
       *XINTFWD (valcontents)->intvar = XINT (newval);
       break;
-      
+
     case Lisp_Fwd_Bool:
       *XBOOLFWD (valcontents)->boolvar = !NILP (newval);
       break;
-      
+
     case Lisp_Fwd_Obj:
       *XOBJFWD (valcontents)->objvar = newval;
-      
+
       /* If this variable is a default for something stored
         in the buffer itself, such as default-fill-column,
         find the buffers that don't have local values for it
@@ -977,12 +970,12 @@ store_symval_forwarding (/* symbol, */ valcontents, newval, buf)
          int offset = ((char *) XOBJFWD (valcontents)->objvar
                        - (char *) &buffer_defaults);
          int idx = PER_BUFFER_IDX (offset);
-         
+
          Lisp_Object tail;
-         
+
          if (idx <= 0)
            break;
-         
+
          for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
            {
              Lisp_Object buf;
@@ -1032,8 +1025,7 @@ store_symval_forwarding (/* symbol, */ valcontents, newval, buf)
    This makes it safe to alter the status of other bindings.  */
 
 void
-swap_in_global_binding (symbol)
-     struct Lisp_Symbol *symbol;
+swap_in_global_binding (struct Lisp_Symbol *symbol)
 {
   struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (symbol);
 
@@ -1059,9 +1051,7 @@ swap_in_global_binding (symbol)
    This could be another forwarding pointer.  */
 
 static void
-swap_in_symval_forwarding (symbol, blv)
-     struct Lisp_Symbol *symbol;
-     struct Lisp_Buffer_Local_Value *blv;
+swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_Value *blv)
 {
   register Lisp_Object tem1;
 
@@ -1111,8 +1101,7 @@ swap_in_symval_forwarding (symbol, blv)
    within this function.  Great care is required for this.  */
 
 Lisp_Object
-find_symbol_value (symbol)
-     Lisp_Object symbol;
+find_symbol_value (Lisp_Object symbol)
 {
   struct Lisp_Symbol *sym;
 
@@ -1156,7 +1145,7 @@ DEFUN ("set", Fset, Sset, 2, 2, 0,
      (symbol, newval)
      register Lisp_Object symbol, newval;
 {
-  set_internal (symbol, newval, current_buffer, 0);
+  set_internal (symbol, newval, Qnil, 0);
   return newval;
 }
 
@@ -1183,8 +1172,7 @@ let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol)
 }
 
 static int
-let_shadows_global_binding_p (symbol)
-     Lisp_Object symbol;
+let_shadows_global_binding_p (Lisp_Object symbol)
 {
   struct specbinding *p;
 
@@ -1196,29 +1184,23 @@ let_shadows_global_binding_p (symbol)
 }
 
 /* Store the value NEWVAL into SYMBOL.
-   If buffer-locality is an issue, BUF specifies which buffer to use.
-   (0 stands for the current buffer.)
+   If buffer/frame-locality is an issue, WHERE specifies which context to use.
+   (nil stands for the current buffer/frame).
 
    If BINDFLAG is zero, then if this symbol is supposed to become
    local in every buffer where it is set, then we make it local.
    If BINDFLAG is nonzero, we don't do that.  */
 
 void
-set_internal (symbol, newval, buf, bindflag)
-     register Lisp_Object symbol, newval;
-     struct buffer *buf;
-     int bindflag;
+set_internal (register Lisp_Object symbol, register Lisp_Object newval, register Lisp_Object where, int bindflag)
 {
   int voide = EQ (newval, Qunbound);
   struct Lisp_Symbol *sym;
   Lisp_Object tem1;
 
-  if (buf == 0)
-    buf = current_buffer;
-
   /* If restoring in a dead buffer, do nothing.  */
-  if (NILP (buf->name))
-    return;
+  /* if (BUFFERP (where) && NILP (XBUFFER (where)->name))
+      return; */
 
   CHECK_SYMBOL (symbol);
   if (SYMBOL_CONSTANT_P (symbol))
@@ -1241,15 +1223,19 @@ set_internal (symbol, newval, buf, bindflag)
     case SYMBOL_LOCALIZED:
       {
        struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
-       Lisp_Object tmp; XSETBUFFER (tmp, buf);
-
+       if (NILP (where))
+         {
+           if (blv->frame_local)
+             where = selected_frame;
+           else
+             XSETBUFFER (where, current_buffer);
+         }
        /* If the current buffer is not the buffer whose binding is
           loaded, or if there may be frame-local bindings and the frame
           isn't the right one, or if it's a Lisp_Buffer_Local_Value and
           the default binding is loaded, the loaded binding may be the
           wrong one.  */
-       if (!EQ (blv->where,
-                blv->frame_local ? selected_frame : tmp)
+       if (!EQ (blv->where, where)
            /* Also unload a global binding (if the var is local_if_set). */
            || (EQ (blv->valcell, blv->defcell)))
          {
@@ -1261,19 +1247,12 @@ set_internal (symbol, newval, buf, bindflag)
              SET_BLV_VALUE (blv, do_symval_forwarding (blv->fwd));
 
            /* Find the new binding.  */
-           {
-             XSETSYMBOL (symbol, sym); /* May have changed via aliasing.  */
-             if (blv->frame_local)
-               {
-                 tem1 = Fassq (symbol, XFRAME (selected_frame)->param_alist);
-                 blv->where = selected_frame;
-               }
-             else
-               {
-                 tem1 = Fassq (symbol, buf->local_var_alist);
-                 blv->where = tmp;
-               }
-           }
+           XSETSYMBOL (symbol, sym); /* May have changed via aliasing.  */
+           tem1 = Fassq (symbol,
+                         (blv->frame_local
+                          ? XFRAME (where)->param_alist
+                          : XBUFFER (where)->local_var_alist));
+           blv->where = where;
            blv->found = 1;
 
            if (NILP (tem1))
@@ -1303,8 +1282,8 @@ set_internal (symbol, newval, buf, bindflag)
                       bindings, not for frame-local bindings.  */
                    eassert (!blv->frame_local);
                    tem1 = Fcons (symbol, XCDR (blv->defcell));
-                   buf->local_var_alist
-                     = Fcons (tem1, buf->local_var_alist);
+                   XBUFFER (where)->local_var_alist
+                     = Fcons (tem1, XBUFFER (where)->local_var_alist);
                  }
              }
 
@@ -1322,12 +1301,16 @@ set_internal (symbol, newval, buf, bindflag)
                 buffer-local indicator, not through Lisp_Objfwd, etc.  */
              blv->fwd = NULL;
            else
-             store_symval_forwarding (blv->fwd, newval, buf);
+             store_symval_forwarding (blv->fwd, newval,
+                                      BUFFERP (where)
+                                      ? XBUFFER (where) : current_buffer);
          }
        break;
       }
     case SYMBOL_FORWARDED:
       {
+       struct buffer *buf
+         = BUFFERP (where) ? XBUFFER (where) : current_buffer;
        union Lisp_Fwd *innercontents = SYMBOL_FWD (sym);
        if (BUFFER_OBJFWDP (innercontents))
          {
@@ -1360,8 +1343,7 @@ set_internal (symbol, newval, buf, bindflag)
    Return Qunbound if it is void.  */
 
 Lisp_Object
-default_value (symbol)
-     Lisp_Object symbol;
+default_value (Lisp_Object symbol)
 {
   struct Lisp_Symbol *sym;
 
@@ -1558,10 +1540,14 @@ make_blv (struct Lisp_Symbol *sym, int forwarded, union Lisp_Val_Fwd valcontents
 {
   struct Lisp_Buffer_Local_Value *blv
     = xmalloc (sizeof (struct Lisp_Buffer_Local_Value));
-  Lisp_Object symbol; XSETSYMBOL (symbol, sym);
-  Lisp_Object tem = Fcons (symbol, (forwarded
-                                   ? do_symval_forwarding (valcontents.fwd)
-                                   : valcontents.value));
+  Lisp_Object symbol;
+  Lisp_Object tem;
+
+ XSETSYMBOL (symbol, sym);
+ tem = Fcons (symbol, (forwarded
+                       ? do_symval_forwarding (valcontents.fwd)
+                       : valcontents.value));
+
   /* Buffer_Local_Values cannot have as realval a buffer-local
      or keyboard-local forwarding.  */
   eassert (!(forwarded && BUFFER_OBJFWDP (valcontents.fwd)));
@@ -1639,8 +1625,8 @@ The function `default-value' gets the default value and `set-default' sets it.
        Lisp_Object symbol;
        XSETSYMBOL (symbol, sym); /* In case `variable' is aliased.  */
        if (let_shadows_global_binding_p (symbol))
-       error ("Making %s buffer-local while let-bound!",
-              SDATA (SYMBOL_NAME (variable)));
+         message ("Making %s buffer-local while let-bound!",
+                  SDATA (SYMBOL_NAME (variable)));
       }
     }
 
@@ -1702,7 +1688,8 @@ Instead, use `add-hook' and specify t for the LOCAL argument.  */)
     }
 
   if (sym->constant)
-    error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable)));
+    error ("Symbol %s may not be buffer-local",
+          SDATA (SYMBOL_NAME (variable)));
 
   if (blv ? blv->local_if_set
       : (forwarded && BUFFER_OBJFWDP (valcontents.fwd)))
@@ -1722,8 +1709,9 @@ Instead, use `add-hook' and specify t for the LOCAL argument.  */)
        Lisp_Object symbol;
        XSETSYMBOL (symbol, sym); /* In case `variable' is aliased.  */
        if (let_shadows_global_binding_p (symbol))
-         error ("Making %s local to %s while let-bound!",
-                SDATA (SYMBOL_NAME (variable)), SDATA (current_buffer->name));
+         message ("Making %s local to %s while let-bound!",
+                  SDATA (SYMBOL_NAME (variable)),
+                  SDATA (current_buffer->name));
       }
     }
 
@@ -1899,6 +1887,13 @@ frame-local bindings).  */)
   blv->frame_local = 1;
   sym->redirect = SYMBOL_LOCALIZED;
   SET_SYMBOL_BLV (sym, blv);
+  {
+    Lisp_Object symbol;
+    XSETSYMBOL (symbol, sym); /* In case `variable' is aliased.  */
+    if (let_shadows_global_binding_p (symbol))
+      message ("Making %s frame-local while let-bound!",
+              SDATA (SYMBOL_NAME (variable)));
+  }
   return variable;
 }
 
@@ -1933,7 +1928,7 @@ BUFFER defaults to the current buffer.  */)
        Lisp_Object tail, elt, tmp;
        struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
        XSETBUFFER (tmp, buf);
-       
+
        for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
          {
            elt = XCAR (tail);
@@ -2047,7 +2042,7 @@ If the current binding is global (the default), the value is nil.  */)
 /* This code is disabled now that we use the selected frame to return
    keyboard-local-values. */
 #if 0
-extern struct terminal *get_terminal P_ ((Lisp_Object display, int));
+extern struct terminal *get_terminal (Lisp_Object display, int);
 
 DEFUN ("terminal-local-value", Fterminal_local_value, Sterminal_local_value, 2, 2, 0,
        doc: /* Return the terminal-local value of SYMBOL on TERMINAL.
@@ -2099,8 +2094,7 @@ selected frame's terminal device).  */)
    This is like Findirect_function, except that it doesn't signal an
    error if the chain ends up unbound.  */
 Lisp_Object
-indirect_function (object)
-     register Lisp_Object object;
+indirect_function (register Lisp_Object object)
 {
   Lisp_Object tortoise, hare;
 
@@ -2264,7 +2258,7 @@ bool-vector.  IDX starts at 0.  */)
 
       idxval_byte = string_char_to_byte (array, idxval);
       p1 = SDATA (array) + idxval_byte;
-      PARSE_MULTIBYTE_SEQ (p1, nbytes - idxval_byte, prev_bytes);
+      prev_bytes = BYTES_BY_CHAR_HEAD (*p1);
       new_bytes = CHAR_STRING (XINT (newelt), p0);
       if (prev_bytes != new_bytes)
        {
@@ -2316,9 +2310,7 @@ bool-vector.  IDX starts at 0.  */)
 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
 
 Lisp_Object
-arithcompare (num1, num2, comparison)
-     Lisp_Object num1, num2;
-     enum comparison comparison;
+arithcompare (Lisp_Object num1, Lisp_Object num2, enum comparison comparison)
 {
   double f1 = 0, f2 = 0;
   int floatp = 0;
@@ -2444,8 +2436,7 @@ DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0,
    when the value fits in one.  */
 
 Lisp_Object
-long_to_cons (i)
-     unsigned long i;
+long_to_cons (long unsigned int i)
 {
   unsigned long top = i >> 16;
   unsigned int bot = i & 0xFFFF;
@@ -2457,8 +2448,7 @@ long_to_cons (i)
 }
 
 unsigned long
-cons_to_long (c)
-     Lisp_Object c;
+cons_to_long (Lisp_Object c)
 {
   Lisp_Object top, bot;
   if (INTEGERP (c))
@@ -2499,8 +2489,7 @@ NUMBER may be an integer or a floating point number.  */)
 }
 
 INLINE static int
-digit_to_number (character, base)
-     int character, base;
+digit_to_number (int character, int base)
 {
   int digit;
 
@@ -2595,15 +2584,12 @@ enum arithop
     Amin
   };
 
-static Lisp_Object float_arith_driver P_ ((double, int, enum arithop,
-                                          int, Lisp_Object *));
+static Lisp_Object float_arith_driver (double, int, enum arithop,
+                                       int, Lisp_Object *);
 extern Lisp_Object fmod_float ();
 
 Lisp_Object
-arith_driver (code, nargs, args)
-     enum arithop code;
-     int nargs;
-     register Lisp_Object *args;
+arith_driver (enum arithop code, int nargs, register Lisp_Object *args)
 {
   register Lisp_Object val;
   register int argnum;
@@ -2688,12 +2674,7 @@ arith_driver (code, nargs, args)
 #define isnan(x) ((x) != (x))
 
 static Lisp_Object
-float_arith_driver (accum, argnum, code, nargs, args)
-     double accum;
-     register int argnum;
-     enum arithop code;
-     int nargs;
-     register Lisp_Object *args;
+float_arith_driver (double accum, register int argnum, enum arithop code, int nargs, register Lisp_Object *args)
 {
   register Lisp_Object val;
   double next;
@@ -3028,7 +3009,7 @@ lowercase l) for small endian machines.  */)
 
 \f
 void
-syms_of_data ()
+syms_of_data (void)
 {
   Lisp_Object error_tail, arith_tail;
 
@@ -3457,8 +3438,7 @@ syms_of_data ()
 }
 
 SIGTYPE
-arith_error (signo)
-     int signo;
+arith_error (int signo)
 {
   sigsetmask (SIGEMPTYMASK);
 
@@ -3467,7 +3447,7 @@ arith_error (signo)
 }
 
 void
-init_data ()
+init_data (void)
 {
   /* Don't do this if just dumping out.
      We don't want to call `signal' in this case