/* Random utility Lisp functions.
Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997,
1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <unistd.h>
#endif
#include <time.h>
-
-#ifndef MAC_OS
-/* On Mac OS, defining this conflicts with precompiled headers. */
+#include <setjmp.h>
/* 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 *****
-#endif /* ! MAC_OSX */
-
#include "lisp.h"
#include "commands.h"
#include "character.h"
#ifdef HAVE_MENUS
#if defined (HAVE_X_WINDOWS)
#include "xterm.h"
-#elif defined (MAC_OS)
-#include "macterm.h"
-#endif
#endif
+#endif /* HAVE_MENUS */
#ifndef NULL
#define NULL ((POINTER_TYPE *)0)
extern Lisp_Object Qinput_method_function;
-static int internal_equal P_ ((Lisp_Object , Lisp_Object, int, int));
+static int internal_equal (Lisp_Object , Lisp_Object, int, int);
-extern long get_random ();
-extern void seed_random P_ ((long));
+extern long get_random (void);
+extern void seed_random (long);
#ifndef HAVE_UNISTD_H
extern long time ();
doc: /* Return a pseudo-random number.
All integers representable in Lisp are equally likely.
On most systems, this is 29 bits' worth.
-With positive integer argument N, return random number in interval [0,N).
-With argument t, set the random number seed from the current time and pid. */)
- (n)
- Lisp_Object n;
+With positive integer LIMIT, return random number in interval [0,LIMIT).
+With argument t, set the random number seed from the current time and pid.
+Other values of LIMIT are ignored. */)
+ (limit)
+ Lisp_Object limit;
{
EMACS_INT val;
Lisp_Object lispy_val;
unsigned long denominator;
- if (EQ (n, Qt))
+ if (EQ (limit, Qt))
seed_random (getpid () + time (NULL));
- if (NATNUMP (n) && XFASTINT (n) != 0)
+ if (NATNUMP (limit) && XFASTINT (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'
it's possible to get a quotient larger than n; discarding
these values eliminates the bias that would otherwise appear
when using a large n. */
- denominator = ((unsigned long)1 << VALBITS) / XFASTINT (n);
+ denominator = ((unsigned long)1 << VALBITS) / XFASTINT (limit);
do
val = get_random () / denominator;
- while (val >= XFASTINT (n));
+ while (val >= XFASTINT (limit));
}
else
val = get_random ();
if (SCHARS (s1) != SCHARS (s2)
|| SBYTES (s1) != SBYTES (s2)
- || bcmp (SDATA (s1), SDATA (s2), SBYTES (s1)))
+ || memcmp (SDATA (s1), SDATA (s2), SBYTES (s1)))
return Qnil;
return Qt;
}
else
{
c1 = SREF (str1, i1++);
- c1 = unibyte_char_to_multibyte (c1);
+ MAKE_CHAR_MULTIBYTE (c1);
}
if (STRING_MULTIBYTE (str2))
else
{
c2 = SREF (str2, i2++);
- c2 = unibyte_char_to_multibyte (c2);
+ MAKE_CHAR_MULTIBYTE (c2);
}
if (c1 == c2)
/* "gcc -O3" enables automatic function inlining, which optimizes out
the arguments for the invocations of this function, whereas it
expects these values on the stack. */
-static Lisp_Object concat P_ ((int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special)) __attribute__((noinline));
+static Lisp_Object concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special) __attribute__((noinline));
#else /* !__GNUC__ */
-static Lisp_Object concat P_ ((int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special));
+static Lisp_Object concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special);
#endif
/* ARGSUSED */
Lisp_Object
-concat2 (s1, s2)
- Lisp_Object s1, s2;
+concat2 (Lisp_Object s1, Lisp_Object s2)
{
-#ifdef NO_ARG_ARRAY
Lisp_Object args[2];
args[0] = s1;
args[1] = s2;
return concat (2, args, Lisp_String, 0);
-#else
- return concat (2, &s1, Lisp_String, 0);
-#endif /* NO_ARG_ARRAY */
}
/* ARGSUSED */
Lisp_Object
-concat3 (s1, s2, s3)
- Lisp_Object s1, s2, s3;
+concat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
{
-#ifdef NO_ARG_ARRAY
Lisp_Object args[3];
args[0] = s1;
args[1] = s2;
args[2] = s3;
return concat (3, args, Lisp_String, 0);
-#else
- return concat (3, &s1, Lisp_String, 0);
-#endif /* NO_ARG_ARRAY */
}
DEFUN ("append", Fappend, Sappend, 0, MANY, 0,
/ BOOL_VECTOR_BITS_PER_CHAR);
val = Fmake_bool_vector (Flength (arg), Qnil);
- bcopy (XBOOL_VECTOR (arg)->data, XBOOL_VECTOR (val)->data,
- size_in_chars);
+ memcpy (XBOOL_VECTOR (val)->data, XBOOL_VECTOR (arg)->data,
+ size_in_chars);
return val;
}
};
static Lisp_Object
-concat (nargs, args, target_type, last_special)
- int nargs;
- Lisp_Object *args;
- enum Lisp_Type target_type;
- int last_special;
+concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special)
{
Lisp_Object val;
register Lisp_Object tail;
So, we record strings that have text properties to be copied
here, and copy the text properties after the concatination. */
struct textprop_rec *textprops = NULL;
- /* Number of elments in textprops. */
+ /* Number of elements in textprops. */
int num_textprops = 0;
USE_SAFE_ALLOCA;
}
result_len += len;
+ if (result_len < 0)
+ error ("String overflow");
}
if (! some_multibyte)
{
int thislen_byte = SBYTES (this);
- bcopy (SDATA (this), SDATA (val) + toindex_byte,
- SBYTES (this));
+ memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this));
if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
{
textprops[num_textprops].argnum = argnum;
}
toindex_byte += thislen_byte;
toindex += thisleni;
- STRING_SET_CHARS (val, SCHARS (val));
}
/* Copy a single-byte string to a multibyte string. */
else if (STRINGP (this) && STRINGP (val))
{
XSETFASTINT (elt, SREF (this, thisindex)); thisindex++;
if (some_multibyte
- && XINT (elt) >= 0200
+ && !ASCII_CHAR_P (XINT (elt))
&& XINT (elt) < 0400)
{
- c = unibyte_char_to_multibyte (XINT (elt));
+ c = BYTE8_TO_CHAR (XINT (elt));
XSETINT (elt, c);
}
}
static EMACS_INT string_char_byte_cache_bytepos;
void
-clear_string_char_byte_cache ()
+clear_string_char_byte_cache (void)
{
string_char_byte_cache_string = Qnil;
}
/* Return the byte index corresponding to CHAR_INDEX in STRING. */
EMACS_INT
-string_char_to_byte (string, char_index)
- Lisp_Object string;
- EMACS_INT char_index;
+string_char_to_byte (Lisp_Object string, EMACS_INT char_index)
{
EMACS_INT i_byte;
EMACS_INT best_below, best_below_byte;
/* Return the character index corresponding to BYTE_INDEX in STRING. */
EMACS_INT
-string_byte_to_char (string, byte_index)
- Lisp_Object string;
- EMACS_INT byte_index;
+string_byte_to_char (Lisp_Object string, EMACS_INT byte_index)
{
EMACS_INT i, i_byte;
EMACS_INT best_below, best_below_byte;
/* Convert STRING to a multibyte string. */
Lisp_Object
-string_make_multibyte (string)
- Lisp_Object string;
+string_make_multibyte (Lisp_Object string)
{
unsigned char *buf;
EMACS_INT nbytes;
converted to eight-bit characters. */
Lisp_Object
-string_to_multibyte (string)
- Lisp_Object string;
+string_to_multibyte (Lisp_Object string)
{
unsigned char *buf;
EMACS_INT nbytes;
return make_multibyte_string (SDATA (string), nbytes, nbytes);
SAFE_ALLOCA (buf, unsigned char *, nbytes);
- bcopy (SDATA (string), buf, SBYTES (string));
+ memcpy (buf, SDATA (string), SBYTES (string));
str_to_multibyte (buf, nbytes, SBYTES (string));
ret = make_multibyte_string (buf, SCHARS (string), nbytes);
/* Convert STRING to a single-byte string. */
Lisp_Object
-string_make_unibyte (string)
- Lisp_Object string;
+string_make_unibyte (Lisp_Object string)
{
int nchars;
unsigned char *buf;
int bytes = SBYTES (string);
unsigned char *str = (unsigned char *) xmalloc (bytes);
- bcopy (SDATA (string), str, bytes);
+ memcpy (str, SDATA (string), bytes);
bytes = str_as_unibyte (str, bytes);
string = make_unibyte_string (str, bytes);
xfree (str);
SBYTES (string),
&nchars, &nbytes);
new_string = make_uninit_multibyte_string (nchars, nbytes);
- bcopy (SDATA (string), SDATA (new_string),
- SBYTES (string));
+ memcpy (SDATA (new_string), SDATA (string), SBYTES (string));
if (nbytes != SBYTES (string))
str_as_multibyte (SDATA (new_string), nbytes,
SBYTES (string), NULL);
return string_to_multibyte (string);
}
+DEFUN ("string-to-unibyte", Fstring_to_unibyte, Sstring_to_unibyte,
+ 1, 1, 0,
+ doc: /* Return a unibyte string with the same individual chars as STRING.
+If STRING is unibyte, the result is STRING itself.
+Otherwise it is a newly created string, with no text properties,
+where each `eight-bit' character is converted to the corresponding byte.
+If STRING contains a non-ASCII, non-`eight-bit' character,
+an error is signaled. */)
+ (string)
+ Lisp_Object string;
+{
+ CHECK_STRING (string);
+
+ if (STRING_MULTIBYTE (string))
+ {
+ EMACS_INT chars = SCHARS (string);
+ unsigned char *str = (unsigned char *) xmalloc (chars);
+ EMACS_INT converted = str_to_unibyte (SDATA (string), str, chars, 0);
+
+ if (converted < chars)
+ error ("Can't convert the %dth character to unibyte", converted);
+ string = make_unibyte_string (str, chars);
+ xfree (str);
+ }
+ return string;
+}
+
\f
DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0,
doc: /* Return a copy of ALIST.
}
DEFUN ("substring", Fsubstring, Ssubstring, 2, 3, 0,
- doc: /* Return a substring of STRING, starting at index FROM and ending before TO.
-TO may be nil or omitted; then the substring runs to the end of STRING.
-FROM and TO start at 0. If either is negative, it counts from the end.
-
-This function allows vectors as well as strings. */)
+ doc: /* Return a new string whose contents are a substring of STRING.
+The returned string consists of the characters between index FROM
+\(inclusive) and index TO (exclusive) of STRING. FROM and TO are
+zero-indexed: 0 means the first character of STRING. Negative values
+are counted from the end of STRING. If TO is nil, the substring runs
+to the end of STRING.
+
+The STRING argument may also be a vector. In that case, the return
+value is a new vector that contains the elements between index FROM
+\(inclusive) and index TO (exclusive) of that vector argument. */)
(string, from, to)
Lisp_Object string;
register Lisp_Object from, to;
both in characters and in bytes. */
Lisp_Object
-substring_both (string, from, from_byte, to, to_byte)
- Lisp_Object string;
- int from, from_byte, to, to_byte;
+substring_both (Lisp_Object string, int from, int from_byte, int to, int to_byte)
{
Lisp_Object res;
int size;
Use only on lists known never to be circular. */
Lisp_Object
-assq_no_quit (key, list)
- Lisp_Object key, list;
+assq_no_quit (Lisp_Object key, Lisp_Object list)
{
while (CONSP (list)
&& (!CONSP (XCAR (list))
Use only on lists known never to be circular. */
Lisp_Object
-assoc_no_quit (key, list)
- Lisp_Object key, list;
+assoc_no_quit (Lisp_Object key, Lisp_Object list)
{
while (CONSP (list)
&& (!CONSP (XCAR (list))
{
if (STRING_MULTIBYTE (seq))
{
- c = STRING_CHAR (SDATA (seq) + ibyte,
- SBYTES (seq) - ibyte);
+ c = STRING_CHAR (SDATA (seq) + ibyte);
cbytes = CHAR_BYTES (c);
}
else
{
if (STRING_MULTIBYTE (seq))
{
- c = STRING_CHAR (SDATA (seq) + ibyte,
- SBYTES (seq) - ibyte);
+ c = STRING_CHAR (SDATA (seq) + ibyte);
cbytes = CHAR_BYTES (c);
}
else
return new;
}
\f
-Lisp_Object merge ();
+Lisp_Object merge (Lisp_Object org_l1, Lisp_Object org_l2, Lisp_Object pred);
DEFUN ("sort", Fsort, Ssort, 2, 2, 0,
doc: /* Sort LIST, stably, comparing elements using PREDICATE.
}
Lisp_Object
-merge (org_l1, org_l2, pred)
- Lisp_Object org_l1, org_l2;
- Lisp_Object pred;
+merge (Lisp_Object org_l1, Lisp_Object org_l2, Lisp_Object pred)
{
Lisp_Object value;
register Lisp_Object tail;
}
\f
-#if 0 /* Unsafe version. */
-DEFUN ("plist-get", Fplist_get, Splist_get, 2, 2, 0,
- doc: /* Extract a value from a property list.
-PLIST is a property list, which is a list of the form
-\(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
-corresponding to the given PROP, or nil if PROP is not
-one of the properties on the list. */)
- (plist, prop)
- Lisp_Object plist;
- Lisp_Object prop;
-{
- Lisp_Object tail;
-
- for (tail = plist;
- CONSP (tail) && CONSP (XCDR (tail));
- tail = XCDR (XCDR (tail)))
- {
- if (EQ (prop, XCAR (tail)))
- return XCAR (XCDR (tail));
-
- /* This function can be called asynchronously
- (setup_coding_system). Don't QUIT in that case. */
- if (!interrupt_input_blocked)
- QUIT;
- }
-
- CHECK_LIST_END (tail, prop);
-
- return Qnil;
-}
-#endif
-
/* This does not check for quits. That is safe since it must terminate. */
DEFUN ("plist-get", Fplist_get, Splist_get, 2, 2, 0,
halftail = XCDR (halftail);
if (EQ (tail, halftail))
break;
+
+#if 0 /* Unsafe version. */
+ /* This function can be called asynchronously
+ (setup_coding_system). Don't QUIT in that case. */
+ if (!interrupt_input_blocked)
+ QUIT;
+#endif
}
return Qnil;
PROPS, if non-nil, means compare string text properties too. */
static int
-internal_equal (o1, o2, depth, props)
- register Lisp_Object o1, o2;
- int depth, props;
+internal_equal (register Lisp_Object o1, register Lisp_Object o2, int depth, int props)
{
if (depth > 200)
error ("Stack overflow in equal");
if (XBOOL_VECTOR (o1)->size != XBOOL_VECTOR (o2)->size)
return 0;
- if (bcmp (XBOOL_VECTOR (o1)->data, XBOOL_VECTOR (o2)->data,
- size_in_chars))
+ if (memcmp (XBOOL_VECTOR (o1)->data, XBOOL_VECTOR (o2)->data,
+ size_in_chars))
return 0;
return 1;
}
return 0;
if (SBYTES (o1) != SBYTES (o2))
return 0;
- if (bcmp (SDATA (o1), SDATA (o2),
- SBYTES (o1)))
+ if (memcmp (SDATA (o1), SDATA (o2), SBYTES (o1)))
return 0;
if (props && !compare_string_intervals (o1, o2))
return 0;
return 1;
- case Lisp_Int:
- case Lisp_Symbol:
- case Lisp_Type_Limit:
+ default:
break;
}
return 0;
}
\f
-extern Lisp_Object Fmake_char_internal ();
DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0,
doc: /* Store each element of ARRAY with ITEM.
if (size != size_byte)
while (p1 < endp)
{
- int this_len = MULTIBYTE_FORM_LENGTH (p1, endp - p1);
+ int this_len = BYTES_BY_CHAR_HEAD (*p1);
if (len != this_len)
error ("Attempt to change byte length of a string");
p1 += this_len;
int len;
CHECK_STRING (string);
len = SBYTES (string);
- bzero (SDATA (string), len);
+ memset (SDATA (string), 0, len);
STRING_SET_CHARS (string, len);
STRING_SET_UNIBYTE (string);
return Qnil;
\f
/* ARGSUSED */
Lisp_Object
-nconc2 (s1, s2)
- Lisp_Object s1, s2;
+nconc2 (Lisp_Object s1, Lisp_Object s2)
{
-#ifdef NO_ARG_ARRAY
Lisp_Object args[2];
args[0] = s1;
args[1] = s2;
return Fnconc (2, args);
-#else
- return Fnconc (2, &s1);
-#endif /* NO_ARG_ARRAY */
}
DEFUN ("nconc", Fnconc, Snconc, 0, MANY, 0,
LENI is the length of VALS, which should also be the length of SEQ. */
static void
-mapcar1 (leni, vals, fn, seq)
- int leni;
- Lisp_Object *vals;
- Lisp_Object fn, seq;
+mapcar1 (int leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
{
register Lisp_Object tail;
Lisp_Object dummy;
Anything that calls this function must protect from GC! */
Lisp_Object
-do_yes_or_no_p (prompt)
- Lisp_Object prompt;
+do_yes_or_no_p (Lisp_Object prompt)
{
return call1 (intern ("yes-or-no-p"), prompt);
}
Lisp_Object require_nesting_list;
Lisp_Object
-require_unwind (old_value)
- Lisp_Object old_value;
+require_unwind (Lisp_Object old_value)
{
return require_nesting_list = old_value;
}
else if (EQ (item, Qdays)) /* e.g. for calendar-day-name-array */
{
Lisp_Object v = Fmake_vector (make_number (7), Qnil);
- int days[7] = {DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7};
+ const int days[7] = {DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7};
int i;
+ struct gcpro gcpro1;
+ GCPRO1 (v);
synchronize_system_time_locale ();
for (i = 0; i < 7; i++)
{
code_convert_string_norecord (val, Vlocale_coding_system,
0));
}
+ UNGCPRO;
return v;
}
#endif /* DAY_1 */
#ifdef MON_1
else if (EQ (item, Qmonths)) /* e.g. for calendar-month-name-array */
{
- struct Lisp_Vector *p = allocate_vector (12);
- int months[12] = {MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7,
- MON_8, MON_9, MON_10, MON_11, MON_12};
+ Lisp_Object v = Fmake_vector (make_number (12), Qnil);
+ const int months[12] = {MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7,
+ MON_8, MON_9, MON_10, MON_11, MON_12};
int i;
+ struct gcpro gcpro1;
+ GCPRO1 (v);
synchronize_system_time_locale ();
for (i = 0; i < 12; i++)
{
str = nl_langinfo (months[i]);
val = make_unibyte_string (str, strlen (str));
- p->contents[i] =
- code_convert_string_norecord (val, Vlocale_coding_system, 0);
+ Faset (v, make_number (i),
+ code_convert_string_norecord (val, Vlocale_coding_system, 0));
}
- XSETVECTOR (val, p);
- return val;
+ UNGCPRO;
+ return v;
}
#endif /* MON_1 */
/* LC_PAPER stuff isn't defined as accessible in glibc as of 2.3.1,
while (IS_BASE64_IGNORABLE (c))
/* Table of characters coding the 64 values. */
-static char base64_value_to_char[64] =
+static const char base64_value_to_char[64] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */
};
/* Table of base64 values for first 128 characters. */
-static short base64_char_to_value[128] =
+static const short base64_char_to_value[128] =
{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */
base64 characters. */
-static int base64_encode_1 P_ ((const char *, char *, int, int, int));
-static int base64_decode_1 P_ ((const char *, char *, int, int, int *));
+static int base64_encode_1 (const char *, char *, int, int, int);
+static int base64_decode_1 (const char *, char *, int, int, int *);
DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region,
2, 3, "r",
}
static int
-base64_encode_1 (from, to, length, line_break, multibyte)
- const char *from;
- char *to;
- int length;
- int line_break;
- int multibyte;
+base64_encode_1 (const char *from, char *to, int length, int line_break, int multibyte)
{
int counter = 0, i = 0;
char *e = to;
{
if (multibyte)
{
- c = STRING_CHAR_AND_LENGTH (from + i, length - i, bytes);
+ c = STRING_CHAR_AND_LENGTH (from + i, bytes);
if (CHAR_BYTE8_P (c))
c = CHAR_TO_BYTE8 (c);
else if (c >= 256)
if (multibyte)
{
- c = STRING_CHAR_AND_LENGTH (from + i, length - i, bytes);
+ c = STRING_CHAR_AND_LENGTH (from + i, bytes);
if (CHAR_BYTE8_P (c))
c = CHAR_TO_BYTE8 (c);
else if (c >= 256)
if (multibyte)
{
- c = STRING_CHAR_AND_LENGTH (from + i, length - i, bytes);
+ c = STRING_CHAR_AND_LENGTH (from + i, bytes);
if (CHAR_BYTE8_P (c))
c = CHAR_TO_BYTE8 (c);
else if (c >= 256)
characters in *NCHARS_RETURN. */
static int
-base64_decode_1 (from, to, length, multibyte, nchars_return)
- const char *from;
- char *to;
- int length;
- int multibyte;
- int *nchars_return;
+base64_decode_1 (const char *from, char *to, int length, int multibyte, int *nchars_return)
{
int i = 0;
char *e = to;
/* Function prototypes. */
-static struct Lisp_Hash_Table *check_hash_table P_ ((Lisp_Object));
-static int get_key_arg P_ ((Lisp_Object, int, Lisp_Object *, char *));
-static void maybe_resize_hash_table P_ ((struct Lisp_Hash_Table *));
-static int cmpfn_eql P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned,
- Lisp_Object, unsigned));
-static int cmpfn_equal P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned,
- Lisp_Object, unsigned));
-static int cmpfn_user_defined P_ ((struct Lisp_Hash_Table *, Lisp_Object,
- unsigned, Lisp_Object, unsigned));
-static unsigned hashfn_eq P_ ((struct Lisp_Hash_Table *, Lisp_Object));
-static unsigned hashfn_eql P_ ((struct Lisp_Hash_Table *, Lisp_Object));
-static unsigned hashfn_equal P_ ((struct Lisp_Hash_Table *, Lisp_Object));
-static unsigned hashfn_user_defined P_ ((struct Lisp_Hash_Table *,
- Lisp_Object));
-static unsigned sxhash_string P_ ((unsigned char *, int));
-static unsigned sxhash_list P_ ((Lisp_Object, int));
-static unsigned sxhash_vector P_ ((Lisp_Object, int));
-static unsigned sxhash_bool_vector P_ ((Lisp_Object));
-static int sweep_weak_table P_ ((struct Lisp_Hash_Table *, int));
+static struct Lisp_Hash_Table *check_hash_table (Lisp_Object);
+static int get_key_arg (Lisp_Object, int, Lisp_Object *, char *);
+static void maybe_resize_hash_table (struct Lisp_Hash_Table *);
+static int cmpfn_eql (struct Lisp_Hash_Table *, Lisp_Object, unsigned,
+ Lisp_Object, unsigned);
+static int cmpfn_equal (struct Lisp_Hash_Table *, Lisp_Object, unsigned,
+ Lisp_Object, unsigned);
+static int cmpfn_user_defined (struct Lisp_Hash_Table *, Lisp_Object,
+ unsigned, Lisp_Object, unsigned);
+static unsigned hashfn_eq (struct Lisp_Hash_Table *, Lisp_Object);
+static unsigned hashfn_eql (struct Lisp_Hash_Table *, Lisp_Object);
+static unsigned hashfn_equal (struct Lisp_Hash_Table *, Lisp_Object);
+static unsigned hashfn_user_defined (struct Lisp_Hash_Table *,
+ Lisp_Object);
+static unsigned sxhash_string (unsigned char *, int);
+static unsigned sxhash_list (Lisp_Object, int);
+static unsigned sxhash_vector (Lisp_Object, int);
+static unsigned sxhash_bool_vector (Lisp_Object);
+static int sweep_weak_table (struct Lisp_Hash_Table *, int);
\f
Lisp_Hash_Table. Otherwise, signal an error. */
static struct Lisp_Hash_Table *
-check_hash_table (obj)
- Lisp_Object obj;
+check_hash_table (Lisp_Object obj)
{
CHECK_HASH_TABLE (obj);
return XHASH_TABLE (obj);
number. */
int
-next_almost_prime (n)
- int n;
+next_almost_prime (int n)
{
if (n % 2 == 0)
n += 1;
a DEFUN parameter list. */
static int
-get_key_arg (key, nargs, args, used)
- Lisp_Object key;
- int nargs;
- Lisp_Object *args;
- char *used;
+get_key_arg (Lisp_Object key, int nargs, Lisp_Object *args, char *used)
{
int i;
vector that are not copied from VEC are set to INIT. */
Lisp_Object
-larger_vector (vec, new_size, init)
- Lisp_Object vec;
- int new_size;
- Lisp_Object init;
+larger_vector (Lisp_Object vec, int new_size, Lisp_Object init)
{
struct Lisp_Vector *v;
int i, old_size;
xassert (new_size >= old_size);
v = allocate_vector (new_size);
- bcopy (XVECTOR (vec)->contents, v->contents,
- old_size * sizeof *v->contents);
+ memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents);
for (i = old_size; i < new_size; ++i)
v->contents[i] = init;
XSETVECTOR (vec, v);
KEY2 are the same. */
static int
-cmpfn_eql (h, key1, hash1, key2, hash2)
- struct Lisp_Hash_Table *h;
- Lisp_Object key1, key2;
- unsigned hash1, hash2;
+cmpfn_eql (struct Lisp_Hash_Table *h, Lisp_Object key1, unsigned int hash1, Lisp_Object key2, unsigned int hash2)
{
return (FLOATP (key1)
&& FLOATP (key2)
KEY2 are the same. */
static int
-cmpfn_equal (h, key1, hash1, key2, hash2)
- struct Lisp_Hash_Table *h;
- Lisp_Object key1, key2;
- unsigned hash1, hash2;
+cmpfn_equal (struct Lisp_Hash_Table *h, Lisp_Object key1, unsigned int hash1, Lisp_Object key2, unsigned int hash2)
{
return hash1 == hash2 && !NILP (Fequal (key1, key2));
}
if KEY1 and KEY2 are the same. */
static int
-cmpfn_user_defined (h, key1, hash1, key2, hash2)
- struct Lisp_Hash_Table *h;
- Lisp_Object key1, key2;
- unsigned hash1, hash2;
+cmpfn_user_defined (struct Lisp_Hash_Table *h, Lisp_Object key1, unsigned int hash1, Lisp_Object key2, unsigned int hash2)
{
if (hash1 == hash2)
{
in a Lisp integer. */
static unsigned
-hashfn_eq (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hashfn_eq (struct Lisp_Hash_Table *h, Lisp_Object key)
{
unsigned hash = XUINT (key) ^ XTYPE (key);
xassert ((hash & ~INTMASK) == 0);
in a Lisp integer. */
static unsigned
-hashfn_eql (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hashfn_eql (struct Lisp_Hash_Table *h, Lisp_Object key)
{
unsigned hash;
if (FLOATP (key))
in a Lisp integer. */
static unsigned
-hashfn_equal (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hashfn_equal (struct Lisp_Hash_Table *h, Lisp_Object key)
{
unsigned hash = sxhash (key, 0);
xassert ((hash & ~INTMASK) == 0);
guaranteed to fit in a Lisp integer. */
static unsigned
-hashfn_user_defined (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hashfn_user_defined (struct Lisp_Hash_Table *h, Lisp_Object key)
{
Lisp_Object args[2], hash;
only the table itself is. */
Lisp_Object
-copy_hash_table (h1)
- struct Lisp_Hash_Table *h1;
+copy_hash_table (struct Lisp_Hash_Table *h1)
{
Lisp_Object table;
struct Lisp_Hash_Table *h2;
h2 = allocate_hash_table ();
next = h2->vec_next;
- bcopy (h1, h2, sizeof *h2);
+ memcpy (h2, h1, sizeof *h2);
h2->vec_next = next;
h2->key_and_value = Fcopy_sequence (h1->key_and_value);
h2->hash = Fcopy_sequence (h1->hash);
because it's already too large, throw an error. */
static INLINE void
-maybe_resize_hash_table (h)
- struct Lisp_Hash_Table *h;
+maybe_resize_hash_table (struct Lisp_Hash_Table *h)
{
if (NILP (h->next_free))
{
matching KEY, or -1 if not found. */
int
-hash_lookup (h, key, hash)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
- unsigned *hash;
+hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, unsigned int *hash)
{
unsigned hash_code;
int start_of_bucket;
Value is the index of the entry in H matching KEY. */
int
-hash_put (h, key, value, hash)
- struct Lisp_Hash_Table *h;
- Lisp_Object key, value;
- unsigned hash;
+hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value, unsigned int hash)
{
int start_of_bucket, i;
/* Remove the entry matching KEY from hash table H, if there is one. */
-void
-hash_remove (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+static void
+hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
{
unsigned hash_code;
int start_of_bucket;
/* Clear hash table H. */
void
-hash_clear (h)
- struct Lisp_Hash_Table *h;
+hash_clear (struct Lisp_Hash_Table *h)
{
if (h->count > 0)
{
************************************************************************/
void
-init_weak_hash_tables ()
+init_weak_hash_tables (void)
{
weak_hash_tables = NULL;
}
non-zero if anything was marked. */
static int
-sweep_weak_table (h, remove_entries_p)
- struct Lisp_Hash_Table *h;
- int remove_entries_p;
+sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p)
{
int bucket, n, marked;
from Vweak_hash_tables. Called from gc_sweep. */
void
-sweep_weak_hash_tables ()
+sweep_weak_hash_tables (void)
{
struct Lisp_Hash_Table *h, *used, *next;
int marked;
code returned is guaranteed to fit in a Lisp integer. */
static unsigned
-sxhash_string (ptr, len)
- unsigned char *ptr;
- int len;
+sxhash_string (unsigned char *ptr, int len)
{
unsigned char *p = ptr;
unsigned char *end = p + len;
list. We don't recurse deeper than SXHASH_MAX_DEPTH in it. */
static unsigned
-sxhash_list (list, depth)
- Lisp_Object list;
- int depth;
+sxhash_list (Lisp_Object list, int depth)
{
unsigned hash = 0;
int i;
the Lisp structure. */
static unsigned
-sxhash_vector (vec, depth)
- Lisp_Object vec;
- int depth;
+sxhash_vector (Lisp_Object vec, int depth)
{
unsigned hash = ASIZE (vec);
int i, n;
/* Return a hash for bool-vector VECTOR. */
static unsigned
-sxhash_bool_vector (vec)
- Lisp_Object vec;
+sxhash_bool_vector (Lisp_Object vec)
{
unsigned hash = XBOOL_VECTOR (vec)->size;
int i, n;
structure. Value is an unsigned integer clipped to INTMASK. */
unsigned
-sxhash (obj, depth)
- Lisp_Object obj;
- int depth;
+sxhash (Lisp_Object obj, int depth)
{
unsigned hash;
switch (XTYPE (obj))
{
- case Lisp_Int:
+ case_Lisp_Int:
hash = XUINT (obj);
break;
case Lisp_Float:
{
- unsigned char *p = (unsigned char *) &XFLOAT_DATA (obj);
- unsigned char *e = p + sizeof XFLOAT_DATA (obj);
+ double val = XFLOAT_DATA (obj);
+ unsigned char *p = (unsigned char *) &val;
+ unsigned char *e = p + sizeof val;
for (hash = 0; p < e; ++p)
hash = SXHASH_COMBINE (hash, *p);
break;
/* The vector `used' is used to keep track of arguments that
have been consumed. */
used = (char *) alloca (nargs * sizeof *used);
- bzero (used, nargs * sizeof *used);
+ memset (used, 0, nargs * sizeof *used);
/* See if there's a `:test TEST' among the arguments. */
i = get_key_arg (QCtest, nargs, args, used);
Lisp_Object key, table;
{
struct Lisp_Hash_Table *h = check_hash_table (table);
- hash_remove (h, key);
+ hash_remove_from_table (h, key);
return Qnil;
}
\f
void
-syms_of_fns ()
+syms_of_fns (void)
{
/* Hash table stuff. */
- Qhash_table_p = intern ("hash-table-p");
+ Qhash_table_p = intern_c_string ("hash-table-p");
staticpro (&Qhash_table_p);
- Qeq = intern ("eq");
+ Qeq = intern_c_string ("eq");
staticpro (&Qeq);
- Qeql = intern ("eql");
+ Qeql = intern_c_string ("eql");
staticpro (&Qeql);
- Qequal = intern ("equal");
+ Qequal = intern_c_string ("equal");
staticpro (&Qequal);
- QCtest = intern (":test");
+ QCtest = intern_c_string (":test");
staticpro (&QCtest);
- QCsize = intern (":size");
+ QCsize = intern_c_string (":size");
staticpro (&QCsize);
- QCrehash_size = intern (":rehash-size");
+ QCrehash_size = intern_c_string (":rehash-size");
staticpro (&QCrehash_size);
- QCrehash_threshold = intern (":rehash-threshold");
+ QCrehash_threshold = intern_c_string (":rehash-threshold");
staticpro (&QCrehash_threshold);
- QCweakness = intern (":weakness");
+ QCweakness = intern_c_string (":weakness");
staticpro (&QCweakness);
- Qkey = intern ("key");
+ Qkey = intern_c_string ("key");
staticpro (&Qkey);
- Qvalue = intern ("value");
+ Qvalue = intern_c_string ("value");
staticpro (&Qvalue);
- Qhash_table_test = intern ("hash-table-test");
+ Qhash_table_test = intern_c_string ("hash-table-test");
staticpro (&Qhash_table_test);
- Qkey_or_value = intern ("key-or-value");
+ Qkey_or_value = intern_c_string ("key-or-value");
staticpro (&Qkey_or_value);
- Qkey_and_value = intern ("key-and-value");
+ Qkey_and_value = intern_c_string ("key-and-value");
staticpro (&Qkey_and_value);
defsubr (&Ssxhash);
defsubr (&Smaphash);
defsubr (&Sdefine_hash_table_test);
- Qstring_lessp = intern ("string-lessp");
+ Qstring_lessp = intern_c_string ("string-lessp");
staticpro (&Qstring_lessp);
- Qprovide = intern ("provide");
+ Qprovide = intern_c_string ("provide");
staticpro (&Qprovide);
- Qrequire = intern ("require");
+ Qrequire = intern_c_string ("require");
staticpro (&Qrequire);
- Qyes_or_no_p_history = intern ("yes-or-no-p-history");
+ Qyes_or_no_p_history = intern_c_string ("yes-or-no-p-history");
staticpro (&Qyes_or_no_p_history);
- Qcursor_in_echo_area = intern ("cursor-in-echo-area");
+ Qcursor_in_echo_area = intern_c_string ("cursor-in-echo-area");
staticpro (&Qcursor_in_echo_area);
- Qwidget_type = intern ("widget-type");
+ Qwidget_type = intern_c_string ("widget-type");
staticpro (&Qwidget_type);
staticpro (&string_char_byte_cache_string);
DEFVAR_LISP ("features", &Vfeatures,
doc: /* A list of symbols which are the features of the executing Emacs.
Used by `featurep' and `require', and altered by `provide'. */);
- Vfeatures = Fcons (intern ("emacs"), Qnil);
- Qsubfeatures = intern ("subfeatures");
+ Vfeatures = Fcons (intern_c_string ("emacs"), Qnil);
+ Qsubfeatures = intern_c_string ("subfeatures");
staticpro (&Qsubfeatures);
#ifdef HAVE_LANGINFO_CODESET
- Qcodeset = intern ("codeset");
+ Qcodeset = intern_c_string ("codeset");
staticpro (&Qcodeset);
- Qdays = intern ("days");
+ Qdays = intern_c_string ("days");
staticpro (&Qdays);
- Qmonths = intern ("months");
+ Qmonths = intern_c_string ("months");
staticpro (&Qmonths);
- Qpaper = intern ("paper");
+ Qpaper = intern_c_string ("paper");
staticpro (&Qpaper);
#endif /* HAVE_LANGINFO_CODESET */
DEFVAR_BOOL ("use-dialog-box", &use_dialog_box,
doc: /* *Non-nil means mouse commands use dialog boxes to ask questions.
This applies to `y-or-n-p' and `yes-or-no-p' questions asked by commands
-invoked by mouse clicks and mouse menu items. */);
+invoked by mouse clicks and mouse menu items.
+
+On some platforms, file selection dialogs are also enabled if this is
+non-nil. */);
use_dialog_box = 1;
DEFVAR_BOOL ("use-file-dialog", &use_file_dialog,
doc: /* *Non-nil means mouse commands use a file dialog to ask for files.
This applies to commands from menus and tool bar buttons even when
-they are initiated from the keyboard. The value of `use-dialog-box'
-takes precedence over this variable, so a file dialog is only used if
-both `use-dialog-box' and this variable are non-nil. */);
+they are initiated from the keyboard. If `use-dialog-box' is nil,
+that disables the use of a file dialog, regardless of the value of
+this variable. */);
use_file_dialog = 1;
defsubr (&Sidentity);
defsubr (&Sstring_as_multibyte);
defsubr (&Sstring_as_unibyte);
defsubr (&Sstring_to_multibyte);
+ defsubr (&Sstring_to_unibyte);
defsubr (&Scopy_alist);
defsubr (&Ssubstring);
defsubr (&Ssubstring_no_properties);
void
-init_fns ()
+init_fns (void)
{
}