Make Emacs functions such as Fatom 'static' by default.
[bpt/emacs.git] / src / editfns.c
index e55502b..0c34a95 100644 (file)
@@ -101,14 +101,14 @@ static void general_insert_function (void (*) (const char *, EMACS_INT),
                                     void (*) (Lisp_Object, EMACS_INT,
                                               EMACS_INT, EMACS_INT,
                                               EMACS_INT, int),
-                                    int, int, Lisp_Object *);
+                                    int, size_t, Lisp_Object *);
 static Lisp_Object subst_char_in_region_unwind (Lisp_Object);
 static Lisp_Object subst_char_in_region_unwind_1 (Lisp_Object);
 static void transpose_markers (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT,
                               EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT);
 
 Lisp_Object Qbuffer_access_fontify_functions;
-Lisp_Object Fuser_full_name (Lisp_Object);
+INFUN (Fuser_full_name, 1);
 
 /* Symbol for the text property used to mark fields.  */
 
@@ -122,7 +122,7 @@ Lisp_Object Qboundary;
 void
 init_editfns (void)
 {
-  char *user_name;
+  const char *user_name;
   register char *p;
   struct passwd *pw;   /* password entry for the current user */
   Lisp_Object tem;
@@ -136,7 +136,7 @@ init_editfns (void)
     return;
 #endif /* not CANNOT_DUMP */
 
-  pw = (struct passwd *) getpwuid (getuid ());
+  pw = getpwuid (getuid ());
 #ifdef MSDOS
   /* We let the real user name default to "root" because that's quite
      accurate on MSDOG and because it lets Emacs find the init file.
@@ -148,17 +148,17 @@ init_editfns (void)
 
   /* Get the effective user name, by consulting environment variables,
      or the effective uid if those are unset.  */
-  user_name = (char *) getenv ("LOGNAME");
+  user_name = getenv ("LOGNAME");
   if (!user_name)
 #ifdef WINDOWSNT
-    user_name = (char *) getenv ("USERNAME");  /* it's USERNAME on NT */
+    user_name = getenv ("USERNAME");   /* it's USERNAME on NT */
 #else  /* WINDOWSNT */
-    user_name = (char *) getenv ("USER");
+    user_name = getenv ("USER");
 #endif /* WINDOWSNT */
   if (!user_name)
     {
-      pw = (struct passwd *) getpwuid (geteuid ());
-      user_name = (char *) (pw ? pw->pw_name : "unknown");
+      pw = getpwuid (geteuid ());
+      user_name = pw ? pw->pw_name : "unknown";
     }
   Vuser_login_name = build_string (user_name);
 
@@ -185,7 +185,7 @@ init_editfns (void)
 #endif
 }
 \f
-DEFUN ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0,
+DEFUE ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0,
        doc: /* Convert arg CHAR to a string containing that character.
 usage: (char-to-string CHAR)  */)
   (Lisp_Object character)
@@ -239,7 +239,7 @@ buildmark (EMACS_INT charpos, EMACS_INT bytepos)
   return mark;
 }
 
-DEFUN ("point", Fpoint, Spoint, 0, 0, 0,
+DEFUE ("point", Fpoint, Spoint, 0, 0, 0,
        doc: /* Return value of point, as an integer.
 Beginning of buffer is position (point-min).  */)
   (void)
@@ -249,7 +249,7 @@ Beginning of buffer is position (point-min).  */)
   return temp;
 }
 
-DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
+DEFUE ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
        doc: /* Return value of point, as a marker object.  */)
   (void)
 {
@@ -267,7 +267,7 @@ clip_to_bounds (EMACS_INT lower, EMACS_INT num, EMACS_INT upper)
     return num;
 }
 
-DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
+DEFUE ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
        doc: /* Set point to POSITION, a number or marker.
 Beginning of buffer is position (point-min), end is (point-max).
 
@@ -663,7 +663,7 @@ is before LIMIT, then LIMIT will be returned instead.  */)
   return make_number (beg);
 }
 
-DEFUN ("field-end", Ffield_end, Sfield_end, 0, 3, 0,
+DEFUE ("field-end", Ffield_end, Sfield_end, 0, 3, 0,
        doc: /* Return the end of the field surrounding POS.
 A field is a region of text with the same `field' property.
 If POS is nil, the value of point is used for POS.
@@ -678,7 +678,7 @@ is after LIMIT, then LIMIT will be returned instead.  */)
   return make_number (end);
 }
 
-DEFUN ("constrain-to-field", Fconstrain_to_field, Sconstrain_to_field, 2, 5, 0,
+DEFUE ("constrain-to-field", Fconstrain_to_field, Sconstrain_to_field, 2, 5, 0,
        doc: /* Return the position closest to NEW-POS that is in the same field as OLD-POS.
 
 A field is a region of text with the same `field' property.
@@ -750,7 +750,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.  */)
     /* It is possible that NEW_POS is not within the same field as
        OLD_POS; try to move NEW_POS so that it is.  */
     {
-      int shortage;
+      EMACS_INT shortage;
       Lisp_Object field_bound;
 
       if (fwd)
@@ -787,7 +787,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.  */)
 }
 
 \f
-DEFUN ("line-beginning-position",
+DEFUE ("line-beginning-position",
        Fline_beginning_position, Sline_beginning_position, 0, 1, 0,
        doc: /* Return the character position of the first character on the current line.
 With argument N not nil or 1, move forward N - 1 lines first.
@@ -829,7 +829,7 @@ This function does not move point.  */)
                              Qt, Qnil);
 }
 
-DEFUN ("line-end-position", Fline_end_position, Sline_end_position, 0, 1, 0,
+DEFUE ("line-end-position", Fline_end_position, Sline_end_position, 0, 1, 0,
        doc: /* Return the character position of the last character on the current line.
 With argument N not nil or 1, move forward N - 1 lines first.
 If scan reaches end of buffer, return that position.
@@ -928,18 +928,21 @@ save_excursion_restore (Lisp_Object info)
   tem1 = BVAR (current_buffer, mark_active);
   BVAR (current_buffer, mark_active) = tem;
 
-  if (!NILP (Vrun_hooks))
+  /* If mark is active now, and either was not active
+     or was at a different place, run the activate hook.  */
+  if (! NILP (tem))
     {
-      /* If mark is active now, and either was not active
-        or was at a different place, run the activate hook.  */
-      if (! NILP (BVAR (current_buffer, mark_active)))
-       {
-         if (! EQ (omark, nmark))
-           call1 (Vrun_hooks, intern ("activate-mark-hook"));
-       }
-      /* If mark has ceased to be active, run deactivate hook.  */
-      else if (! NILP (tem1))
-       call1 (Vrun_hooks, intern ("deactivate-mark-hook"));
+      if (! EQ (omark, nmark))
+        {
+          tem = intern ("activate-mark-hook");
+          Frun_hooks (1, &tem);
+        }
+    }
+  /* If mark has ceased to be active, run deactivate hook.  */
+  else if (! NILP (tem1))
+    {
+      tem = intern ("deactivate-mark-hook");
+      Frun_hooks (1, &tem);
     }
 
   /* If buffer was visible in a window, and a different window was
@@ -1045,7 +1048,7 @@ is in effect, in which case it is less.  */)
   return temp;
 }
 
-DEFUN ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 0, 0,
+DEFUE ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 0, 0,
        doc: /* Return a marker to the maximum permissible value of point in this buffer.
 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
 is in effect, in which case it is less.  */)
@@ -1096,7 +1099,7 @@ If BYTEPOS is out of range, the value is nil.  */)
   return make_number (BYTE_TO_CHAR (XINT (bytepos)));
 }
 \f
-DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0,
+DEFUE ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0,
        doc: /* Return the character following point, as a number.
 At the end of the buffer or accessible region, return 0.  */)
   (void)
@@ -1109,7 +1112,7 @@ At the end of the buffer or accessible region, return 0.  */)
   return temp;
 }
 
-DEFUN ("preceding-char", Fprevious_char, Sprevious_char, 0, 0, 0,
+DEFUE ("preceding-char", Fprevious_char, Sprevious_char, 0, 0, 0,
        doc: /* Return the character preceding point, as a number.
 At the beginning of the buffer or accessible region, return 0.  */)
   (void)
@@ -1128,7 +1131,7 @@ At the beginning of the buffer or accessible region, return 0.  */)
   return temp;
 }
 
-DEFUN ("bobp", Fbobp, Sbobp, 0, 0, 0,
+DEFUE ("bobp", Fbobp, Sbobp, 0, 0, 0,
        doc: /* Return t if point is at the beginning of the buffer.
 If the buffer is narrowed, this means the beginning of the narrowed part.  */)
   (void)
@@ -1138,7 +1141,7 @@ If the buffer is narrowed, this means the beginning of the narrowed part.  */)
   return Qnil;
 }
 
-DEFUN ("eobp", Feobp, Seobp, 0, 0, 0,
+DEFUE ("eobp", Feobp, Seobp, 0, 0, 0,
        doc: /* Return t if point is at the end of the buffer.
 If the buffer is narrowed, this means the end of the narrowed part.  */)
   (void)
@@ -1148,7 +1151,7 @@ If the buffer is narrowed, this means the end of the narrowed part.  */)
   return Qnil;
 }
 
-DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0,
+DEFUE ("bolp", Fbolp, Sbolp, 0, 0, 0,
        doc: /* Return t if point is at the beginning of a line.  */)
   (void)
 {
@@ -1157,7 +1160,7 @@ DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0,
   return Qnil;
 }
 
-DEFUN ("eolp", Feolp, Seolp, 0, 0, 0,
+DEFUE ("eolp", Feolp, Seolp, 0, 0, 0,
        doc: /* Return t if point is at the end of a line.
 `End of a line' includes point being at the end of the buffer.  */)
   (void)
@@ -1167,7 +1170,7 @@ DEFUN ("eolp", Feolp, Seolp, 0, 0, 0,
   return Qnil;
 }
 
-DEFUN ("char-after", Fchar_after, Schar_after, 0, 1, 0,
+DEFUE ("char-after", Fchar_after, Schar_after, 0, 1, 0,
        doc: /* Return character in current buffer at position POS.
 POS is an integer or a marker and defaults to point.
 If POS is out of range, the value is nil.  */)
@@ -1244,7 +1247,7 @@ If POS is out of range, the value is nil.  */)
    return val;
 }
 \f
-DEFUN ("user-login-name", Fuser_login_name, Suser_login_name, 0, 1, 0,
+DEFUE ("user-login-name", Fuser_login_name, Suser_login_name, 0, 1, 0,
        doc: /* Return the name under which the user logged in, as a string.
 This is based on the effective uid, not the real uid.
 Also, if the environment variables LOGNAME or USER are set,
@@ -1266,9 +1269,9 @@ of the user with that uid, or nil if there is no such user.  */)
   if (NILP (uid))
     return Vuser_login_name;
 
-  id = (uid_t)XFLOATINT (uid);
+  id = XFLOATINT (uid);
   BLOCK_INPUT;
-  pw = (struct passwd *) getpwuid (id);
+  pw = getpwuid (id);
   UNBLOCK_INPUT;
   return (pw ? build_string (pw->pw_name) : Qnil);
 }
@@ -1300,7 +1303,7 @@ Value is an integer or a float, depending on the value.  */)
   /* Make sure we don't produce a negative UID due to signed integer
      overflow.  */
   if (euid < 0)
-    return make_float ((double)geteuid ());
+    return make_float (geteuid ());
   return make_fixnum_or_float (euid);
 }
 
@@ -1316,7 +1319,7 @@ Value is an integer or a float, depending on the value.  */)
   /* Make sure we don't produce a negative UID due to signed integer
      overflow.  */
   if (uid < 0)
-    return make_float ((double)getuid ());
+    return make_float (getuid ());
   return make_fixnum_or_float (uid);
 }
 
@@ -1339,14 +1342,15 @@ name, or nil if there is no such user.  */)
     return Vuser_full_name;
   else if (NUMBERP (uid))
     {
+      uid_t u = XFLOATINT (uid);
       BLOCK_INPUT;
-      pw = (struct passwd *) getpwuid ((uid_t) XFLOATINT (uid));
+      pw = getpwuid (u);
       UNBLOCK_INPUT;
     }
   else if (STRINGP (uid))
     {
       BLOCK_INPUT;
-      pw = (struct passwd *) getpwnam (SSDATA (uid));
+      pw = getpwnam (SSDATA (uid));
       UNBLOCK_INPUT;
     }
   else
@@ -1374,7 +1378,7 @@ name, or nil if there is no such user.  */)
       memcpy (r, p, q - p);
       r[q - p] = 0;
       strcat (r, SSDATA (login));
-      r[q - p] = UPCASE ((unsigned char) r[q - p]);
+      r[q - p] = upcase ((unsigned char) r[q - p]);
       strcat (r, q + 1);
       full = build_string (r);
     }
@@ -1383,15 +1387,13 @@ name, or nil if there is no such user.  */)
   return full;
 }
 
-DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,
+DEFUE ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,
        doc: /* Return the host name of the machine you are running on, as a string.  */)
   (void)
 {
   return Vsystem_name;
 }
 
-/* For the benefit of callers who don't want to include lisp.h */
-
 const char *
 get_system_name (void)
 {
@@ -1439,12 +1441,17 @@ static EMACS_INT
 hi_time (time_t t)
 {
   time_t hi = t >> 16;
-  if ((TYPE_SIGNED (time_t)
-       && TIME_T_MIN >> 16 < MOST_NEGATIVE_FIXNUM
-       && hi < MOST_NEGATIVE_FIXNUM)
-      || (MOST_POSITIVE_FIXNUM < TIME_T_MAX >> 16
-         && MOST_POSITIVE_FIXNUM < hi))
+
+  /* Check for overflow, helping the compiler for common cases where
+     no runtime check is needed, and taking care not to convert
+     negative numbers to unsigned before comparing them.  */
+  if (! ((! TYPE_SIGNED (time_t)
+         || MOST_NEGATIVE_FIXNUM <= TIME_T_MIN >> 16
+         || MOST_NEGATIVE_FIXNUM <= hi)
+        && (TIME_T_MAX >> 16 <= MOST_POSITIVE_FIXNUM
+            || hi <= MOST_POSITIVE_FIXNUM)))
     time_overflow ();
+
   return hi;
 }
 
@@ -1455,7 +1462,7 @@ lo_time (time_t t)
   return t & ((1 << 16) - 1);
 }
 
-DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
+DEFUE ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
        doc: /* Return the current time, as the number of seconds since 1970-01-01 00:00:00.
 The time is returned as a list of three integers.  The first has the
 most significant 16 bits of the seconds, while the second has the
@@ -1474,7 +1481,7 @@ resolution finer than a second.  */)
                make_number (EMACS_USECS (t)));
 }
 
-DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
+DEFUE ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
        0, 0, 0,
        doc: /* Return the current run time used by Emacs.
 The time is returned as a list of three integers.  The first has the
@@ -1551,6 +1558,7 @@ lisp_time_argument (Lisp_Object specified_time, time_t *result, int *usec)
   else
     {
       Lisp_Object high, low;
+      EMACS_INT hi;
       high = Fcar (specified_time);
       CHECK_NUMBER (high);
       low = Fcdr (specified_time);
@@ -1574,8 +1582,21 @@ lisp_time_argument (Lisp_Object specified_time, time_t *result, int *usec)
       else if (usec)
         *usec = 0;
       CHECK_NUMBER (low);
-      *result = (XINT (high) << 16) + (XINT (low) & 0xffff);
-      return *result >> 16 == XINT (high);
+      hi = XINT (high);
+
+      /* Check for overflow, helping the compiler for common cases
+        where no runtime check is needed, and taking care not to
+        convert negative numbers to unsigned before comparing them.  */
+      if (! ((TYPE_SIGNED (time_t)
+             ? (TIME_T_MIN >> 16 <= MOST_NEGATIVE_FIXNUM
+                || TIME_T_MIN >> 16 <= hi)
+             : 0 <= hi)
+            && (MOST_POSITIVE_FIXNUM <= TIME_T_MAX >> 16
+                || hi <= TIME_T_MAX >> 16)))
+       return 0;
+
+      *result = (hi << 16) + (XINT (low) & 0xffff);
+      return 1;
     }
 }
 
@@ -1703,7 +1724,7 @@ The modifiers are `E' and `O'.  For certain characters X,
 %OX is like %X, but uses the locale's number symbols.
 
 For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z".  */)
-  (Lisp_Object format_string, Lisp_Object time, Lisp_Object universal)
+  (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal)
 {
   time_t value;
   int size;
@@ -1714,7 +1735,7 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z".  */)
 
   CHECK_STRING (format_string);
 
-  if (! (lisp_time_argument (time, &value, &usec)
+  if (! (lisp_time_argument (timeval, &value, &usec)
         && 0 <= usec && usec < 1000000))
     error ("Invalid time specification");
   ns = usec * 1000;
@@ -1850,9 +1871,9 @@ Years before 1970 are not guaranteed to work.  On some systems,
 year values as low as 1901 do work.
 
 usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE)  */)
-  (int nargs, register Lisp_Object *args)
+  (size_t nargs, register Lisp_Object *args)
 {
-  time_t time;
+  time_t value;
   struct tm tm;
   Lisp_Object zone = (nargs > 6 ? args[nargs - 1] : Qnil);
 
@@ -1869,7 +1890,7 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE)  */)
   if (NILP (zone))
     {
       BLOCK_INPUT;
-      time = mktime (&tm);
+      value = mktime (&tm);
       UNBLOCK_INPUT;
     }
   else
@@ -1897,7 +1918,7 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE)  */)
       set_time_zone_rule (tzstring);
 
       BLOCK_INPUT;
-      time = mktime (&tm);
+      value = mktime (&tm);
       UNBLOCK_INPUT;
 
       /* Restore TZ to previous value.  */
@@ -1909,10 +1930,10 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE)  */)
 #endif
     }
 
-  if (time == (time_t) -1)
+  if (value == (time_t) -1)
     time_overflow ();
 
-  return make_time (time);
+  return make_time (value);
 }
 
 DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0,
@@ -2186,9 +2207,9 @@ general_insert_function (void (*insert_func)
                         void (*insert_from_string_func)
                              (Lisp_Object, EMACS_INT, EMACS_INT,
                               EMACS_INT, EMACS_INT, int),
-                        int inherit, int nargs, Lisp_Object *args)
+                        int inherit, size_t nargs, Lisp_Object *args)
 {
-  register int argnum;
+  register size_t argnum;
   register Lisp_Object val;
 
   for (argnum = 0; argnum < nargs; argnum++)
@@ -2205,7 +2226,7 @@ general_insert_function (void (*insert_func)
            {
              str[0] = (ASCII_CHAR_P (XINT (val))
                        ? XINT (val)
-                       : multibyte_char_to_unibyte (XINT (val), Qnil));
+                       : multibyte_char_to_unibyte (XINT (val)));
              len = 1;
            }
          (*insert_func) ((char *) str, len);
@@ -2234,7 +2255,7 @@ insert1 (Lisp_Object arg)
    not be used after calling insert or insert_from_string, so
    we don't care if it gets trashed.  */
 
-DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0,
+DEFUE ("insert", Finsert, Sinsert, 0, MANY, 0,
        doc: /* Insert the arguments, either strings or characters, at point.
 Point and before-insertion markers move forward to end up
  after the inserted text.
@@ -2251,7 +2272,7 @@ buffer; to accomplish this, apply `string-as-multibyte' to the string
 and insert the result.
 
 usage: (insert &rest ARGS)  */)
-  (int nargs, register Lisp_Object *args)
+  (size_t nargs, register Lisp_Object *args)
 {
   general_insert_function (insert, insert_from_string, 0, nargs, args);
   return Qnil;
@@ -2270,7 +2291,7 @@ If the current buffer is unibyte, multibyte strings are converted
 to unibyte for insertion.
 
 usage: (insert-and-inherit &rest ARGS)  */)
-  (int nargs, register Lisp_Object *args)
+  (size_t nargs, register Lisp_Object *args)
 {
   general_insert_function (insert_and_inherit, insert_from_string, 1,
                           nargs, args);
@@ -2287,7 +2308,7 @@ If the current buffer is unibyte, multibyte strings are converted
 to unibyte for insertion.
 
 usage: (insert-before-markers &rest ARGS)  */)
-  (int nargs, register Lisp_Object *args)
+  (size_t nargs, register Lisp_Object *args)
 {
   general_insert_function (insert_before_markers,
                           insert_from_string_before_markers, 0,
@@ -2306,7 +2327,7 @@ If the current buffer is unibyte, multibyte strings are converted
 to unibyte for insertion.
 
 usage: (insert-before-markers-and-inherit &rest ARGS)  */)
-  (int nargs, register Lisp_Object *args)
+  (size_t nargs, register Lisp_Object *args)
 {
   general_insert_function (insert_before_markers_and_inherit,
                           insert_from_string_before_markers, 1,
@@ -2314,7 +2335,7 @@ usage: (insert-before-markers-and-inherit &rest ARGS)  */)
   return Qnil;
 }
 \f
-DEFUN ("insert-char", Finsert_char, Sinsert_char, 2, 3, 0,
+DEFUE ("insert-char", Finsert_char, Sinsert_char, 2, 3, 0,
        doc: /* Insert COUNT copies of CHARACTER.
 Point, and before-insertion markers, are relocated as in the function `insert'.
 The optional third arg INHERIT, if non-nil, says to inherit text properties
@@ -2322,7 +2343,7 @@ from adjoining text, if those properties are sticky.  */)
   (Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
 {
   register char *string;
-  register EMACS_INT strlen;
+  register EMACS_INT stringlen;
   register int i;
   register EMACS_INT n;
   int len;
@@ -2340,18 +2361,18 @@ from adjoining text, if those properties are sticky.  */)
   n = XINT (count) * len;
   if (n <= 0)
     return Qnil;
-  strlen = min (n, 256 * len);
-  string = (char *) alloca (strlen);
-  for (i = 0; i < strlen; i++)
+  stringlen = min (n, 256 * len);
+  string = (char *) alloca (stringlen);
+  for (i = 0; i < stringlen; i++)
     string[i] = str[i % len];
-  while (n >= strlen)
+  while (n >= stringlen)
     {
       QUIT;
       if (!NILP (inherit))
-       insert_and_inherit (string, strlen);
+       insert_and_inherit (string, stringlen);
       else
-       insert (string, strlen);
-      n -= strlen;
+       insert (string, stringlen);
+      n -= stringlen;
     }
   if (n > 0)
     {
@@ -2488,7 +2509,7 @@ update_buffer_properties (EMACS_INT start, EMACS_INT end)
     }
 }
 
-DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0,
+DEFUE ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0,
        doc: /* Return the contents of part of the current buffer as a string.
 The two arguments START and END are character positions;
 they can be in either order.
@@ -2524,7 +2545,7 @@ they can be in either order.  */)
   return make_buffer_string (b, e, 0);
 }
 
-DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,
+DEFUE ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,
        doc: /* Return the contents of the current buffer as a string.
 If narrowing is in effect, this function returns only the visible part
 of the buffer.  */)
@@ -3010,8 +3031,7 @@ It returns the number of characters changed.  */)
   EMACS_INT size;              /* Size of translate table. */
   EMACS_INT pos, pos_byte, end_pos;
   int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
-  int string_multibyte;
-  Lisp_Object val;
+  int string_multibyte IF_LINT (= 0);
 
   validate_region (&start, &end);
   if (CHAR_TABLE_P (table))
@@ -3163,7 +3183,7 @@ It returns the number of characters changed.  */)
   return make_number (cnt);
 }
 
-DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r",
+DEFUE ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r",
        doc: /* Delete the text between point and mark.
 
 When called from a program, expects two arguments,
@@ -3186,7 +3206,7 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
   return del_range_1 (XINT (start), XINT (end), 1, 1);
 }
 \f
-DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
+DEFUE ("widen", Fwiden, Swiden, 0, 0, "",
        doc: /* Remove restrictions (narrowing) from current buffer.
 This allows the buffer's full text to be seen and edited.  */)
   (void)
@@ -3201,7 +3221,7 @@ This allows the buffer's full text to be seen and edited.  */)
   return Qnil;
 }
 
-DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r",
+DEFUE ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r",
        doc: /* Restrict editing in this buffer to the current region.
 The rest of the text becomes temporarily invisible and untouchable
 but is not deleted; if you save the buffer in a file, the invisible
@@ -3362,7 +3382,7 @@ static char *message_text;
 /* Allocated length of that buffer.  */
 static int message_length;
 
-DEFUN ("message", Fmessage, Smessage, 1, MANY, 0,
+DEFUE ("message", Fmessage, Smessage, 1, MANY, 0,
        doc: /* Display a message at the bottom of the screen.
 The message also goes into the `*Messages*' buffer.
 \(In keyboard macros, that's all it does.)
@@ -3379,7 +3399,7 @@ any existing message; this lets the minibuffer contents show.  See
 also `current-message'.
 
 usage: (message FORMAT-STRING &rest ARGS)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   if (NILP (args[0])
       || (STRINGP (args[0])
@@ -3407,7 +3427,7 @@ If the first argument is nil or the empty string, clear any existing
 message; let the minibuffer contents show.
 
 usage: (message-box FORMAT-STRING &rest ARGS)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   if (NILP (args[0]))
     {
@@ -3424,12 +3444,12 @@ usage: (message-box FORMAT-STRING &rest ARGS)  */)
       if (FRAME_WINDOW_P (XFRAME (selected_frame))
          || FRAME_MSDOS_P (XFRAME (selected_frame)))
       {
-       Lisp_Object pane, menu, obj;
+       Lisp_Object pane, menu;
        struct gcpro gcpro1;
        pane = Fcons (Fcons (build_string ("OK"), Qt), Qnil);
        GCPRO1 (pane);
        menu = Fcons (val, pane);
-       obj = Fx_popup_dialog (Qt, menu, Qt);
+       Fx_popup_dialog (Qt, menu, Qt);
        UNGCPRO;
        return val;
       }
@@ -3464,7 +3484,7 @@ If the first argument is nil or the empty string, clear any existing
 message; let the minibuffer contents show.
 
 usage: (message-or-box FORMAT-STRING &rest ARGS)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
 #ifdef HAVE_MENUS
   if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
@@ -3474,7 +3494,7 @@ usage: (message-or-box FORMAT-STRING &rest ARGS)  */)
   return Fmessage (nargs, args);
 }
 
-DEFUN ("current-message", Fcurrent_message, Scurrent_message, 0, 0, 0,
+DEFUE ("current-message", Fcurrent_message, Scurrent_message, 0, 0, 0,
        doc: /* Return the string currently displayed in the echo area, or nil if none.  */)
   (void)
 {
@@ -3488,14 +3508,14 @@ First argument is the string to copy.
 Remaining arguments form a sequence of PROPERTY VALUE pairs for text
 properties to add to the result.
 usage: (propertize STRING &rest PROPERTIES)  */)
-  (int nargs, Lisp_Object *args)
+  (size_t nargs, Lisp_Object *args)
 {
   Lisp_Object properties, string;
   struct gcpro gcpro1, gcpro2;
-  int i;
+  size_t i;
 
   /* Number of args must be odd.  */
-  if ((nargs & 1) == 0 || nargs < 1)
+  if ((nargs & 1) == 0)
     error ("Wrong number of arguments");
 
   properties = string = Qnil;
@@ -3523,7 +3543,7 @@ usage: (propertize STRING &rest PROPERTIES)  */)
    ? count_size_as_multibyte (SDATA (STRING), SBYTES (STRING))         \
    : SBYTES (STRING))
 
-DEFUN ("format", Fformat, Sformat, 1, MANY, 0,
+DEFUE ("format", Fformat, Sformat, 1, MANY, 0,
        doc: /* Format a string out of a format-string and arguments.
 The first argument is a format control string.
 The other arguments are substituted into it to make the result, a string.
@@ -3570,10 +3590,10 @@ decimal point itself is omitted.  For %s and %S, the precision
 specifier truncates the string to the given width.
 
 usage: (format STRING &rest OBJECTS)  */)
-  (int nargs, register Lisp_Object *args)
+  (size_t nargs, register Lisp_Object *args)
 {
-  register int n;              /* The number of the next arg to substitute */
-  register EMACS_INT total;    /* An estimate of the final length */
+  register size_t n;           /* The number of the next arg to substitute */
+  register size_t total;       /* An estimate of the final length */
   char *buf, *p;
   register char *format, *end, *format_start;
   int nchars;
@@ -3649,12 +3669,12 @@ usage: (format STRING &rest OBJECTS)  */)
 
   /* Allocate the info and discarded tables.  */
   {
-    int nbytes = (nargs+1) * sizeof *info;
-    int i;
+    size_t nbytes = (nargs+1) * sizeof *info;
+    size_t i;
     if (!info)
       info = (struct info *) alloca (nbytes);
     memset (info, 0, nbytes);
-    for (i = 0; i <= nargs; i++)
+    for (i = 0; i < nargs + 1; i++)
       info[i].start = -1;
     if (!discarded)
       SAFE_ALLOCA (discarded, char *, SBYTES (args[0]));
@@ -3782,7 +3802,7 @@ usage: (format STRING &rest OBJECTS)  */)
            if (*format == 'c')
              {
                if (! ASCII_CHAR_P (XINT (args[n]))
-                   /* Note: No one can remeber why we have to treat
+                   /* Note: No one can remember why we have to treat
                       the character 0 as a multibyte character here.
                       But, until it causes a real problem, let's
                       don't change it.  */
@@ -3796,12 +3816,6 @@ usage: (format STRING &rest OBJECTS)  */)
                    args[n] = Fchar_to_string (args[n]);
                    thissize = SBYTES (args[n]);
                  }
-               else if (! ASCII_BYTE_P (XINT (args[n])) && multibyte)
-                 {
-                   args[n]
-                     = Fchar_to_string (Funibyte_char_to_multibyte (args[n]));
-                   thissize = SBYTES (args[n]);
-                 }
              }
          }
        else if (FLOATP (args[n]) && *format != 's')
@@ -3910,7 +3924,7 @@ usage: (format STRING &rest OBJECTS)  */)
              /* handle case (precision[n] >= 0) */
 
              int width, padding;
-             EMACS_INT nbytes, start, end;
+             EMACS_INT nbytes, start;
              EMACS_INT nchars_string;
 
              /* lisp_string_width ignores a precision of 0, but GNU
@@ -3942,7 +3956,6 @@ usage: (format STRING &rest OBJECTS)  */)
 
              info[n].start = start = nchars;
              nchars += nchars_string;
-             end = nchars;
 
              if (p > buf
                  && multibyte
@@ -4194,7 +4207,7 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer.  */)
 {
   int i1, i2;
   /* Check they're chars, not just integers, otherwise we could get array
-     bounds violations in DOWNCASE.  */
+     bounds violations in downcase.  */
   CHECK_CHARACTER (c1);
   CHECK_CHARACTER (c2);
 
@@ -4203,9 +4216,6 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer.  */)
   if (NILP (BVAR (current_buffer, case_fold_search)))
     return Qnil;
 
-  /* Do these in separate statements,
-     then compare the variables.
-     because of the way DOWNCASE uses temp variables.  */
   i1 = XFASTINT (c1);
   if (NILP (BVAR (current_buffer, enable_multibyte_characters))
       && ! ASCII_CHAR_P (i1))
@@ -4218,9 +4228,7 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer.  */)
     {
       MAKE_CHAR_MULTIBYTE (i2);
     }
-  i1 = DOWNCASE (i1);
-  i2 = DOWNCASE (i2);
-  return (i1 == i2 ? Qt :  Qnil);
+  return (downcase (i1) == downcase (i2) ? Qt :  Qnil);
 }
 \f
 /* Transpose the markers in two regions of the current buffer, and