#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
#include "lisp.h"
#include "commands.h"
-#ifdef MULTI_SCREEN
-#include "screen.h"
-#endif
-
#include "buffer.h"
+#include "keyboard.h"
Lisp_Object Qstring_lessp;
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);
}
"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;
while (!NILP (tail))
{
tem = Fcar (tail);
- if (Fequal (elt, tem))
+ if (! NILP (Fequal (elt, tem)))
{
if (NILP (prev))
list = Fcdr (tail);
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);
+ v1 = internal_equal (Fcar (o1), Fcar (o2), depth + 1);
if (NILP (v1))
return v1;
o1 = Fcdr (o1), o2 = Fcdr (o2);
&& 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)
Lisp_Object v, v1, v2;
v1 = XVECTOR (o1)->contents [index];
v2 = XVECTOR (o2)->contents [index];
- v = Fequal (v1, v2, depth + 1);
+ v = internal_equal (v1, v2, depth + 1);
if (NILP (v)) return v;
}
return Qt;
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);
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 ();
}
}
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
/* 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;
{
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;
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;
-#undef channel
-#undef initialized
-#undef nl
+ if (loads < 0)
+ error ("load-average not implemented for this operating system");
+
+ ret = Qnil;
+ while (loads > 0)
+ ret = Fcons (make_number ((int) (load_ave[--loads] * 100.0)), ret);
+
+ return ret;
+}
\f
Lisp_Object Vfeatures;