(_getpty): Declare this, not _get_pty.
[bpt/emacs.git] / src / fns.c
index fc9abd9..75c0dfb 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -20,57 +20,16 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "config.h"
 
-#ifdef LOAD_AVE_TYPE
-#ifdef BSD
-/* It appears param.h defines BSD and BSD4_3 in 4.3
-   and is not considerate enough to avoid bombing out
-   if they are already defined.  */
-#undef BSD
-#ifdef BSD4_3
-#undef BSD4_3
-#define XBSD4_3 /* XBSD4_3 says BSD4_3 is supposed to be defined.  */
-#endif
-#include <sys/param.h>
-/* Now if BSD or BSD4_3 was defined and is no longer,
-   define it again.  */
-#ifndef BSD
-#define BSD
-#endif
-#ifdef XBSD4_3
-#ifndef BSD4_3
-#define BSD4_3
-#endif
-#endif /* XBSD4_3 */
-#endif /* BSD */
-#ifndef VMS
-#ifndef NLIST_STRUCT
-#include <a.out.h> 
-#else /* NLIST_STRUCT */
-#include <nlist.h>
-#endif /* NLIST_STRUCT */
-#endif /* not VMS */
-#endif /* LOAD_AVE_TYPE */
-
-#ifdef DGUX
-#include <sys/dg_sys_info.h>  /* for load average info - DJB */
-#endif
-
 /* Note on some machines this defines `vector' as a typedef,
    so make sure we don't use that name in this file.  */
 #undef vector
 #define vector *****
 
-#ifdef NULL
-#undef NULL
-#endif
 #include "lisp.h"
 #include "commands.h"
 
-#ifdef MULTI_SCREEN
-#include "screen.h"
-#endif
-
 #include "buffer.h"
+#include "keyboard.h"
 
 Lisp_Object Qstring_lessp;
 
@@ -90,27 +49,27 @@ On most systems all integers representable in Lisp are equally likely.\n\
   This is 24 bits' worth.\n\
 With argument N, return random number in interval [0,N).\n\
 With argument t, set the random number seed from the current time and pid.")
-  (arg)
-     Lisp_Object arg;
+  (limit)
+     Lisp_Object limit;
 {
   int val;
   extern long random ();
   extern srandom ();
   extern long time ();
 
-  if (EQ (arg, Qt))
+  if (EQ (limit, Qt))
     srandom (getpid () + time (0));
   val = random ();
-  if (XTYPE (arg) == Lisp_Int && XINT (arg) != 0)
+  if (XTYPE (limit) == Lisp_Int && XINT (limit) != 0)
     {
       /* Try to take our random number from the higher bits of VAL,
         not the lower, since (says Gentzel) the low bits of `random'
         are less random than the higher ones.  */
       val &= 0xfffffff;                /* Ensure positive.  */
       val >>= 5;
-      if (XINT (arg) < 10000)
+      if (XINT (limit) < 10000)
        val >>= 6;
-      val %= XINT (arg);
+      val %= XINT (limit);
     }
   return make_number (val);
 }
@@ -132,7 +91,7 @@ A byte-code function object is also allowed.")
     return Farray_length (obj);
   else if (CONSP (obj))
     {
-      for (i = 0, tail = obj; !NULL(tail); i++)
+      for (i = 0, tail = obj; !NILP(tail); i++)
        {
          QUIT;
          tail = Fcdr (tail);
@@ -141,7 +100,7 @@ A byte-code function object is also allowed.")
       XFASTINT (val) = i;
       return val;
     }
-  else if (NULL(obj))
+  else if (NILP(obj))
     {
       XFASTINT (val) = 0;
       return val;
@@ -226,7 +185,7 @@ DEFUN ("append", Fappend, Sappend, 0, MANY, 0,
   "Concatenate all the arguments and make the result a list.\n\
 The result is a list whose elements are the elements of all the arguments.\n\
 Each argument may be a list, vector or string.\n\
-The last argument is not copied if it is a list.")
+The last argument is not copied, just used as the tail of the new list.")
   (nargs, args)
      int nargs;
      Lisp_Object *args;
@@ -263,7 +222,7 @@ with the original.")
   (arg)
      Lisp_Object arg;
 {
-  if (NULL (arg)) return arg;
+  if (NILP (arg)) return arg;
   if (!CONSP (arg) && XTYPE (arg) != Lisp_Vector && XTYPE (arg) != Lisp_String)
     arg = wrong_type_argument (Qsequencep, arg);
   return concat (1, &arg, CONSP (arg) ? Lisp_Cons : XTYPE (arg), 0);
@@ -298,7 +257,7 @@ concat (nargs, args, target_type, last_special)
   for (argnum = 0; argnum < nargs; argnum++)
     {
       this = args[argnum];
-      if (!(CONSP (this) || NULL (this)
+      if (!(CONSP (this) || NILP (this)
            || XTYPE (this) == Lisp_Vector || XTYPE (this) == Lisp_String
            || XTYPE (this) == Lisp_Compiled))
        {
@@ -351,7 +310,7 @@ concat (nargs, args, target_type, last_special)
          register Lisp_Object elt;
 
          /* Fetch next element of `this' arg into `elt', or break if `this' is exhausted. */
-         if (NULL (this)) break;
+         if (NILP (this)) break;
          if (CONSP (this))
            elt = Fcar (this), this = Fcdr (this);
          else
@@ -389,7 +348,7 @@ concat (nargs, args, target_type, last_special)
            }
        }
     }
-  if (!NULL (prev))
+  if (!NILP (prev))
     XCONS (prev)->cdr = last_tail;
 
   return val;  
@@ -408,7 +367,7 @@ Elements of ALIST that are not conses are also shared.")
   register Lisp_Object tem;
 
   CHECK_LIST (alist, 0);
-  if (NULL (alist))
+  if (NILP (alist))
     return alist;
   alist = concat (1, &alist, Lisp_Cons, 0);
   for (tem = alist; CONSP (tem); tem = XCONS (tem)->cdr)
@@ -432,7 +391,7 @@ If FROM or TO is negative, it counts from the end.")
 {
   CHECK_STRING (string, 0);
   CHECK_NUMBER (from, 1);
-  if (NULL (to))
+  if (NILP (to))
     to = Flength (string);
   else
     CHECK_NUMBER (to, 2);
@@ -458,7 +417,7 @@ DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2, 0,
   register int i, num;
   CHECK_NUMBER (n, 0);
   num = XINT (n);
-  for (i = 0; i < num && !NULL (list); i++)
+  for (i = 0; i < num && !NILP (list); i++)
     {
       QUIT;
       list = Fcdr (list);
@@ -483,7 +442,7 @@ DEFUN ("elt", Felt, Selt, 2, 2, 0,
   CHECK_NUMBER (n, 0);
   while (1)
     {
-      if (XTYPE (seq) == Lisp_Cons || NULL (seq))
+      if (XTYPE (seq) == Lisp_Cons || NILP (seq))
        return Fcar (Fnthcdr (n, seq));
       else if (XTYPE (seq) == Lisp_String
               || XTYPE (seq) == Lisp_Vector)
@@ -501,11 +460,11 @@ The value is actually the tail of LIST whose car is ELT.")
      Lisp_Object list;
 {
   register Lisp_Object tail;
-  for (tail = list; !NULL (tail); tail = Fcdr (tail))
+  for (tail = list; !NILP (tail); tail = Fcdr (tail))
     {
       register Lisp_Object tem;
       tem = Fcar (tail);
-      if (! NULL (Fequal (elt, tem)))
+      if (! NILP (Fequal (elt, tem)))
        return tail;
       QUIT;
     }
@@ -520,7 +479,7 @@ The value is actually the tail of LIST whose car is ELT.")
      Lisp_Object list;
 {
   register Lisp_Object tail;
-  for (tail = list; !NULL (tail); tail = Fcdr (tail))
+  for (tail = list; !NILP (tail); tail = Fcdr (tail))
     {
       register Lisp_Object tem;
       tem = Fcar (tail);
@@ -539,7 +498,7 @@ Elements of LIST that are not conses are ignored.")
      Lisp_Object list;
 {
   register Lisp_Object tail;
-  for (tail = list; !NULL (tail); tail = Fcdr (tail))
+  for (tail = list; !NILP (tail); tail = Fcdr (tail))
     {
       register Lisp_Object elt, tem;
       elt = Fcar (tail);
@@ -579,13 +538,13 @@ The value is actually the element of LIST whose car is ELT.")
      Lisp_Object list;
 {
   register Lisp_Object tail;
-  for (tail = list; !NULL (tail); tail = Fcdr (tail))
+  for (tail = list; !NILP (tail); tail = Fcdr (tail))
     {
       register Lisp_Object elt, tem;
       elt = Fcar (tail);
       if (!CONSP (elt)) continue;
       tem = Fequal (Fcar (elt), key);
-      if (!NULL (tem)) return elt;
+      if (!NILP (tem)) return elt;
       QUIT;
     }
   return Qnil;
@@ -599,7 +558,7 @@ The value is actually the element of LIST whose cdr is ELT.")
      Lisp_Object list;
 {
   register Lisp_Object tail;
-  for (tail = list; !NULL (tail); tail = Fcdr (tail))
+  for (tail = list; !NILP (tail); tail = Fcdr (tail))
     {
       register Lisp_Object elt, tem;
       elt = Fcar (tail);
@@ -626,12 +585,45 @@ to be sure of changing the value of `foo'.")
 
   tail = list;
   prev = Qnil;
-  while (!NULL (tail))
+  while (!NILP (tail))
     {
       tem = Fcar (tail);
       if (EQ (elt, tem))
        {
-         if (NULL (prev))
+         if (NILP (prev))
+           list = Fcdr (tail);
+         else
+           Fsetcdr (prev, Fcdr (tail));
+       }
+      else
+       prev = tail;
+      tail = Fcdr (tail);
+      QUIT;
+    }
+  return list;
+}
+
+DEFUN ("delete", Fdelete, Sdelete, 2, 2, 0,
+  "Delete by side effect any occurrences of ELT as a member of LIST.\n\
+The modified LIST is returned.  Comparison is done with `equal'.\n\
+If the first member of LIST is ELT, there is no way to remove it by side effect;\n\
+therefore, write `(setq foo (delete element foo))'\n\
+to be sure of changing the value of `foo'.")
+  (elt, list)
+     register Lisp_Object elt;
+     Lisp_Object list;
+{
+  register Lisp_Object tail, prev;
+  register Lisp_Object tem;
+
+  tail = list;
+  prev = Qnil;
+  while (!NILP (tail))
+    {
+      tem = Fcar (tail);
+      if (! NILP (Fequal (elt, tem)))
+       {
+         if (NILP (prev))
            list = Fcdr (tail);
          else
            Fsetcdr (prev, Fcdr (tail));
@@ -652,10 +644,10 @@ Returns the beginning of the reversed list.")
 {
   register Lisp_Object prev, tail, next;
 
-  if (NULL (list)) return list;
+  if (NILP (list)) return list;
   prev = Qnil;
   tail = list;
-  while (!NULL (tail))
+  while (!NILP (tail))
     {
       QUIT;
       next = Fcdr (tail);
@@ -741,24 +733,24 @@ merge (org_l1, org_l2, pred)
 
   while (1)
     {
-      if (NULL (l1))
+      if (NILP (l1))
        {
          UNGCPRO;
-         if (NULL (tail))
+         if (NILP (tail))
            return l2;
          Fsetcdr (tail, l2);
          return value;
        }
-      if (NULL (l2))
+      if (NILP (l2))
        {
          UNGCPRO;
-         if (NULL (tail))
+         if (NILP (tail))
            return l1;
          Fsetcdr (tail, l1);
          return value;
        }
       tem = call2 (pred, Fcar (l2), Fcar (l1));
-      if (NULL (tem))
+      if (NILP (tem))
        {
          tem = l1;
          l1 = Fcdr (l1);
@@ -770,7 +762,7 @@ merge (org_l1, org_l2, pred)
          l2 = Fcdr (l2);
          org_l2 = l2;
        }
-      if (NULL (tail))
+      if (NILP (tail))
        value = tem;
       else
        Fsetcdr (tail, tem);
@@ -786,7 +778,7 @@ This is the last VALUE stored with `(put SYMBOL PROPNAME VALUE)'.")
      register Lisp_Object prop;
 {
   register Lisp_Object tail;
-  for (tail = Fsymbol_plist (sym); !NULL (tail); tail = Fcdr (Fcdr (tail)))
+  for (tail = Fsymbol_plist (sym); !NILP (tail); tail = Fcdr (Fcdr (tail)))
     {
       register Lisp_Object tem;
       tem = Fcar (tail);
@@ -807,7 +799,7 @@ It can be retrieved with `(get SYMBOL PROPNAME)'.")
   register Lisp_Object tail, prev;
   Lisp_Object newcell;
   prev = Qnil;
-  for (tail = Fsymbol_plist (sym); !NULL (tail); tail = Fcdr (Fcdr (tail)))
+  for (tail = Fsymbol_plist (sym); !NILP (tail); tail = Fcdr (Fcdr (tail)))
     {
       register Lisp_Object tem;
       tem = Fcar (tail);
@@ -816,7 +808,7 @@ It can be retrieved with `(get SYMBOL PROPNAME)'.")
       prev = tail;
     }
   newcell = Fcons (prop, Fcons (val, Qnil));
-  if (NULL (prev))
+  if (NILP (prev))
     Fsetplist (sym, newcell);
   else
     Fsetcdr (Fcdr (prev), newcell);
@@ -844,13 +836,19 @@ internal_equal (o1, o2, depth)
     error ("Stack overflow in equal");
 do_cdr:
   QUIT;
+  if (EQ (o1, o2)) return Qt;
+#ifdef LISP_FLOAT_TYPE
+  if (NUMBERP (o1) && NUMBERP (o2))
+    {
+      return (extract_float (o1) == extract_float (o2)) ? Qt : Qnil;
+    }
+#endif
   if (XTYPE (o1) != XTYPE (o2)) return Qnil;
-  if (XINT (o1) == XINT (o2)) return Qt;
   if (XTYPE (o1) == Lisp_Cons)
     {
       Lisp_Object v1;
-      v1 = Fequal (Fcar (o1), Fcar (o2), depth + 1);
-      if (NULL (v1))
+      v1 = internal_equal (Fcar (o1), Fcar (o2), depth + 1);
+      if (NILP (v1))
        return v1;
       o1 = Fcdr (o1), o2 = Fcdr (o2);
       goto do_cdr;
@@ -861,7 +859,8 @@ do_cdr:
              && XMARKER (o1)->bufpos == XMARKER (o2)->bufpos)
        ? Qt : Qnil;
     }
-  if (XTYPE (o1) == Lisp_Vector)
+  if (XTYPE (o1) == Lisp_Vector
+      || XTYPE (o1) == Lisp_Compiled)
     {
       register int index;
       if (XVECTOR (o1)->size != XVECTOR (o2)->size)
@@ -871,8 +870,8 @@ do_cdr:
          Lisp_Object v, v1, v2;
          v1 = XVECTOR (o1)->contents [index];
          v2 = XVECTOR (o2)->contents [index];
-         v = Fequal (v1, v2, depth + 1);
-         if (NULL (v)) return v;
+         v = internal_equal (v1, v2, depth + 1);
+         if (NILP (v)) return v;
        }
       return Qt;
     }
@@ -948,9 +947,9 @@ Only the last argument is not altered, and need not be a list.")
   for (argnum = 0; argnum < nargs; argnum++)
     {
       tem = args[argnum];
-      if (NULL (tem)) continue;
+      if (NILP (tem)) continue;
 
-      if (NULL (val))
+      if (NILP (val))
        val = tem;
 
       if (argnum + 1 == nargs) break;
@@ -967,7 +966,7 @@ Only the last argument is not altered, and need not be a list.")
 
       tem = args[argnum + 1];
       Fsetcdr (tail, tem);
-      if (NULL (tem))
+      if (NILP (tem))
        args[argnum + 1] = tail;
     }
 
@@ -1087,18 +1086,22 @@ SEQUENCE may be a list, a vector or a string.")
 
 DEFUN ("y-or-n-p", Fy_or_n_p, Sy_or_n_p, 1, 1, 0,
   "Ask user a \"y or n\" question.  Return t if answer is \"y\".\n\
+Takes one argument, which is the string to display to ask the question.\n\
+It should end in a space; `y-or-n-p' adds `(y or n) ' to it.\n\
 No confirmation of the answer is requested; a single character is enough.\n\
 Also accepts Space to mean yes, or Delete to mean no.")
   (prompt)
      Lisp_Object prompt;
 {
-  register Lisp_Object obj
-  register int ans;
+  register Lisp_Object obj, key, def, answer_string, map;
+  register int answer;
   Lisp_Object xprompt;
   Lisp_Object args[2];
   int ocech = cursor_in_echo_area;
   struct gcpro gcpro1, gcpro2;
 
+  map = Fsymbol_value (intern ("query-replace-map"));
+
   CHECK_STRING (prompt, 0);
   xprompt = prompt;
   GCPRO2 (prompt, xprompt);
@@ -1108,25 +1111,34 @@ Also accepts Space to mean yes, or Delete to mean no.")
       message ("%s(y or n) ", XSTRING (xprompt)->data);
       cursor_in_echo_area = 1;
 
-      obj = read_char (0);
-      if (XTYPE (obj) == Lisp_Int)
-       ans = XINT (obj);
-      else
-       continue;
+      obj = read_char (0, 0, 0, Qnil, 0);
+      key = Fmake_vector (make_number (1), obj);
+      def = Flookup_key (map, key);
+      answer_string = Fsingle_key_description (obj);
 
       cursor_in_echo_area = -1;
-      message ("%s(y or n) %c", XSTRING (xprompt)->data, ans);
+      message ("%s(y or n) %s", XSTRING (xprompt)->data,
+              XSTRING (answer_string)->data);
       cursor_in_echo_area = ocech;
-      /* Accept a C-g or C-] (abort-recursive-edit) as quit requests.  */
-      if (ans == 7 || ans == '\035')
+
+      if (EQ (def, intern ("skip")))
+       {
+         answer = 0;
+         break;
+       }
+      else if (EQ (def, intern ("act")))
+       {
+         answer = 1;
+         break;
+       }
+      else if (EQ (def, intern ("quit")))
        Vquit_flag = Qt;
+
       QUIT;
-      if (ans >= 0)
-       ans = DOWNCASE (ans);
-      if (ans == 'y' || ans == ' ')
-       { ans = 'y'; break; }
-      if (ans == 'n' || ans == 127)
-       break;
+
+      /* If we don't clear this, then the next call to read_char will
+        return quit_char again, and we'll enter an infinite loop.  */
+      Vquit_flag = Qnil;
 
       Fding (Qnil);
       Fdiscard_input ();
@@ -1138,7 +1150,10 @@ Also accepts Space to mean yes, or Delete to mean no.")
        }
     }
   UNGCPRO;
-  return (ans == 'y' ? Qt : Qnil);
+
+  message ("%s(y or n) %c", XSTRING (xprompt)->data, answer ? 'y' : 'n');
+
+  return answer ? Qt : Qnil;
 }
 \f
 /* This is how C code calls `yes-or-no-p' and allows the user
@@ -1156,9 +1171,11 @@ do_yes_or_no_p (prompt)
 /* Anything that calls this function must protect from GC!  */
 
 DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
-  "Ask user a yes or no question.  Return t if answer is yes.\n\
-The user must confirm the answer with a newline,\n\
-and can rub it out if not confirmed.")
+  "Ask user a yes-or-no question.  Return t if answer is yes.\n\
+Takes one argument, which is the string to display to ask the question.\n\
+It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.\n\
+The user must confirm the answer with RET,\n\
+and can edit it until it as been confirmed.")
   (prompt)
      Lisp_Object prompt;
 {
@@ -1175,8 +1192,7 @@ and can rub it out if not confirmed.")
   GCPRO1 (prompt);
   while (1)
     {
-      ans = Fdowncase (read_minibuf (Vminibuffer_local_map,
-                                    Qnil, prompt, Qnil, 0));
+      ans = Fdowncase (Fread_string (prompt, Qnil));
       if (XSTRING (ans)->size == 3 && !strcmp (XSTRING (ans)->data, "yes"))
        {
          UNGCPRO;
@@ -1191,176 +1207,32 @@ and can rub it out if not confirmed.")
       Fding (Qnil);
       Fdiscard_input ();
       message ("Please answer yes or no.");
-      Fsleep_for (make_number (2));
+      Fsleep_for (make_number (2), Qnil);
     }
   UNGCPRO;
 }
 \f
-/* Avoid static vars inside a function since in HPUX they dump as pure.  */
-#ifdef DGUX
-static struct dg_sys_info_load_info load_info;  /* what-a-mouthful! */
-
-#else /* Not DGUX */
-
-static int ldav_initialized;
-static int ldav_channel;
-#ifdef LOAD_AVE_TYPE
-#ifndef VMS
-static struct nlist ldav_nl[2];
-#endif /* VMS */
-#endif /* LOAD_AVE_TYPE */
-
-#define channel ldav_channel
-#define initialized ldav_initialized
-#define nl ldav_nl
-#endif /* Not DGUX */
-
 DEFUN ("load-average", Fload_average, Sload_average, 0, 0, 0,
   "Return list of 1 minute, 5 minute and 15 minute load averages.\n\
 Each of the three load averages is multiplied by 100,\n\
-then converted to integer.")
+then converted to integer.\n\
+If the 5-minute or 15-minute load averages are not available, return a\n\
+shortened list, containing only those averages which are available.")
   ()
 {
-#ifdef DGUX
-  /* perhaps there should be a "sys_load_avg" call in sysdep.c?! - DJB */
-  load_info.one_minute     = 0.0;      /* just in case there is an error */
-  load_info.five_minute    = 0.0;
-  load_info.fifteen_minute = 0.0;
-  dg_sys_info (&load_info, DG_SYS_INFO_LOAD_INFO_TYPE,
-              DG_SYS_INFO_LOAD_VERSION_0);
-
-  return Fcons (make_number ((int)(load_info.one_minute * 100.0)),
-               Fcons (make_number ((int)(load_info.five_minute * 100.0)),
-                      Fcons (make_number ((int)(load_info.fifteen_minute * 100.0)),
-                             Qnil)));
-#else /* not DGUX */
-#ifndef LOAD_AVE_TYPE
-  error ("load-average not implemented for this operating system");
-
-#else /* LOAD_AVE_TYPE defined */
-
-  LOAD_AVE_TYPE load_ave[3];
-#ifdef VMS
-#ifndef eunice
-#include <iodef.h>
-#include <descrip.h>
-#else
-#include <vms/iodef.h>
-  struct {int dsc$w_length; char *dsc$a_pointer;} descriptor;
-#endif /* eunice */
-#endif /* VMS */
-
-  /* If this fails for any reason, we can return (0 0 0) */
-  load_ave[0] = 0.0; load_ave[1] = 0.0; load_ave[2] = 0.0;
-
-#ifdef VMS
-  /*
-   *   VMS specific code -- read from the Load Ave driver
-   */
-
-  /*
-   *   Ensure that there is a channel open to the load ave device
-   */
-  if (initialized == 0)
-    {
-      /* Attempt to open the channel */
-#ifdef eunice
-      descriptor.size = 18;
-      descriptor.ptr  = "$$VMS_LOAD_AVERAGE";
-#else
-      $DESCRIPTOR(descriptor, "LAV0:");
-#endif
-      if (sys$assign (&descriptor, &channel, 0, 0) & 1)
-       initialized = 1;
-    }
-  /*
-   *   Read the load average vector
-   */
-  if (initialized)
-    {
-      if (!(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0,
-                    load_ave, 12, 0, 0, 0, 0)
-           & 1))
-       {
-         sys$dassgn (channel);
-         initialized = 0;
-       }
-    }
-#else  /* not VMS */
-  /*
-   *   4.2BSD UNIX-specific code -- read _avenrun from /dev/kmem
-   */
-
-  /*
-   *   Make sure we have the address of _avenrun
-   */
-  if (nl[0].n_value == 0)
-    {
-      /*
-       *       Get the address of _avenrun
-       */
-#ifndef NLIST_STRUCT
-      strcpy (nl[0].n_name, LDAV_SYMBOL);
-      nl[1].n_zeroes = 0;
-#else /* NLIST_STRUCT */
-#ifdef convex
-      nl[0].n_un.n_name = LDAV_SYMBOL;
-      nl[1].n_un.n_name = 0;
-#else /* not convex */
-      nl[0].n_name = LDAV_SYMBOL;
-      nl[1].n_name = 0;
-#endif /* not convex */
-#endif /* NLIST_STRUCT */
-
-      nlist (KERNEL_FILE, nl);
-
-#ifdef FIXUP_KERNEL_SYMBOL_ADDR
-      FIXUP_KERNEL_SYMBOL_ADDR (nl);
-#endif /* FIXUP_KERNEL_SYMBOL_ADDR */
-    }
-  /*
-   *   Make sure we have /dev/kmem open
-   */
-  if (initialized == 0)
-    {
-      /*
-       *       Open /dev/kmem
-       */
-      channel = open ("/dev/kmem", 0);
-      if (channel >= 0) initialized = 1;
-    }
-  /*
-   *   If we can, get the load ave values
-   */
-  if ((nl[0].n_value != 0) && (initialized != 0))
-    {
-      /*
-       *       Seek to the correct address
-       */
-      lseek (channel, (long) nl[0].n_value, 0);
-      if (read (channel, load_ave, sizeof load_ave)
-         != sizeof(load_ave))
-       {
-         close (channel);
-         initialized = 0;
-       }
-    }
-#endif /* not VMS */
-
-  /*
-   *   Return the list of load average values
-   */
-  return Fcons (make_number (LOAD_AVE_CVT (load_ave[0])),
-               Fcons (make_number (LOAD_AVE_CVT (load_ave[1])),
-                      Fcons (make_number (LOAD_AVE_CVT (load_ave[2])),
-                             Qnil)));
-#endif /* LOAD_AVE_TYPE */
-#endif /* not DGUX */
-}
+  double load_ave[3];
+  int loads = getloadavg (load_ave, 3);
+  Lisp_Object ret;
+
+  if (loads < 0)
+    error ("load-average not implemented for this operating system");
 
-#undef channel
-#undef initialized
-#undef nl
+  ret = Qnil;
+  while (loads > 0)
+    ret = Fcons (make_number ((int) (load_ave[--loads] * 100.0)), ret);
+
+  return ret;
+}
 \f
 Lisp_Object Vfeatures;
 
@@ -1376,7 +1248,7 @@ This function looks at the value of the variable `features'.")
   register Lisp_Object tem;
   CHECK_SYMBOL (feature, 0);
   tem = Fmemq (feature, Vfeatures);
-  return (NULL (tem)) ? Qnil : Qt;
+  return (NILP (tem)) ? Qnil : Qt;
 }
 
 DEFUN ("provide", Fprovide, Sprovide, 1, 1, 0,
@@ -1386,10 +1258,10 @@ DEFUN ("provide", Fprovide, Sprovide, 1, 1, 0,
 {
   register Lisp_Object tem;
   CHECK_SYMBOL (feature, 0);
-  if (!NULL (Vautoload_queue))
+  if (!NILP (Vautoload_queue))
     Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue);
   tem = Fmemq (feature, Vfeatures);
-  if (NULL (tem))
+  if (NILP (tem))
     Vfeatures = Fcons (feature, Vfeatures);
   return feature;
 }
@@ -1405,7 +1277,7 @@ If FILENAME is omitted, the printname of FEATURE is used as the file name.")
   register Lisp_Object tem;
   CHECK_SYMBOL (feature, 0);
   tem = Fmemq (feature, Vfeatures);
-  if (NULL (tem))
+  if (NILP (tem))
     {
       int count = specpdl_ptr - specpdl;
 
@@ -1413,11 +1285,11 @@ If FILENAME is omitted, the printname of FEATURE is used as the file name.")
       record_unwind_protect (un_autoload, Vautoload_queue);
       Vautoload_queue = Qt;
 
-      Fload (NULL (file_name) ? Fsymbol_name (feature) : file_name,
+      Fload (NILP (file_name) ? Fsymbol_name (feature) : file_name,
             Qnil, Qt, Qnil);
 
       tem = Fmemq (feature, Vfeatures);
-      if (NULL (tem))
+      if (NILP (tem))
        error ("Required feature %s was not provided",
               XSYMBOL (feature)->name->data );
 
@@ -1458,6 +1330,7 @@ Used by `featurep' and `require', and altered by `provide'.");
   defsubr (&Sassoc);
   defsubr (&Srassq);
   defsubr (&Sdelq);
+  defsubr (&Sdelete);
   defsubr (&Snreverse);
   defsubr (&Sreverse);
   defsubr (&Ssort);