1 /* Random utility Lisp functions.
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
31 /* On Mac OS, defining this conflicts with precompiled headers. */
33 /* Note on some machines this defines `vector' as a typedef,
34 so make sure we don't use that name in this file. */
38 #endif /* ! MAC_OSX */
42 #include "character.h"
47 #include "intervals.h"
50 #include "blockinput.h"
52 #if defined (HAVE_X_WINDOWS)
54 #elif defined (MAC_OS)
60 #define NULL ((POINTER_TYPE *)0)
63 /* Nonzero enables use of dialog boxes for questions
64 asked by mouse commands. */
67 /* Nonzero enables use of a file dialog for file name
68 questions asked by mouse commands. */
71 extern int minibuffer_auto_raise
;
72 extern Lisp_Object minibuf_window
;
73 extern Lisp_Object Vlocale_coding_system
;
74 extern int load_in_progress
;
76 Lisp_Object Qstring_lessp
, Qprovide
, Qrequire
;
77 Lisp_Object Qyes_or_no_p_history
;
78 Lisp_Object Qcursor_in_echo_area
;
79 Lisp_Object Qwidget_type
;
80 Lisp_Object Qcodeset
, Qdays
, Qmonths
, Qpaper
;
82 extern Lisp_Object Qinput_method_function
;
84 static int internal_equal
P_ ((Lisp_Object
, Lisp_Object
, int, int));
86 extern long get_random ();
87 extern void seed_random
P_ ((long));
93 DEFUN ("identity", Fidentity
, Sidentity
, 1, 1, 0,
94 doc
: /* Return the argument unchanged. */)
101 DEFUN ("random", Frandom
, Srandom
, 0, 1, 0,
102 doc
: /* Return a pseudo-random number.
103 All integers representable in Lisp are equally likely.
104 On most systems, this is 29 bits' worth.
105 With positive integer argument N, return random number in interval [0,N).
106 With argument t, set the random number seed from the current time and pid. */)
111 Lisp_Object lispy_val
;
112 unsigned long denominator
;
115 seed_random (getpid () + time (NULL
));
116 if (NATNUMP (n
) && XFASTINT (n
) != 0)
118 /* Try to take our random number from the higher bits of VAL,
119 not the lower, since (says Gentzel) the low bits of `random'
120 are less random than the higher ones. We do this by using the
121 quotient rather than the remainder. At the high end of the RNG
122 it's possible to get a quotient larger than n; discarding
123 these values eliminates the bias that would otherwise appear
124 when using a large n. */
125 denominator
= ((unsigned long)1 << VALBITS
) / XFASTINT (n
);
127 val
= get_random () / denominator
;
128 while (val
>= XFASTINT (n
));
132 XSETINT (lispy_val
, val
);
136 /* Random data-structure functions */
138 DEFUN ("length", Flength
, Slength
, 1, 1, 0,
139 doc
: /* Return the length of vector, list or string SEQUENCE.
140 A byte-code function object is also allowed.
141 If the string contains multibyte characters, this is not necessarily
142 the number of bytes in the string; it is the number of characters.
143 To get the number of bytes, use `string-bytes'. */)
145 register Lisp_Object sequence
;
147 register Lisp_Object val
;
150 if (STRINGP (sequence
))
151 XSETFASTINT (val
, SCHARS (sequence
));
152 else if (VECTORP (sequence
))
153 XSETFASTINT (val
, ASIZE (sequence
));
154 else if (CHAR_TABLE_P (sequence
))
155 XSETFASTINT (val
, MAX_CHAR
);
156 else if (BOOL_VECTOR_P (sequence
))
157 XSETFASTINT (val
, XBOOL_VECTOR (sequence
)->size
);
158 else if (COMPILEDP (sequence
))
159 XSETFASTINT (val
, ASIZE (sequence
) & PSEUDOVECTOR_SIZE_MASK
);
160 else if (CONSP (sequence
))
163 while (CONSP (sequence
))
165 sequence
= XCDR (sequence
);
168 if (!CONSP (sequence
))
171 sequence
= XCDR (sequence
);
176 CHECK_LIST_END (sequence
, sequence
);
178 val
= make_number (i
);
180 else if (NILP (sequence
))
181 XSETFASTINT (val
, 0);
183 wrong_type_argument (Qsequencep
, sequence
);
188 /* This does not check for quits. That is safe since it must terminate. */
190 DEFUN ("safe-length", Fsafe_length
, Ssafe_length
, 1, 1, 0,
191 doc
: /* Return the length of a list, but avoid error or infinite loop.
192 This function never gets an error. If LIST is not really a list,
193 it returns 0. If LIST is circular, it returns a finite value
194 which is at least the number of distinct elements. */)
198 Lisp_Object tail
, halftail
, length
;
201 /* halftail is used to detect circular lists. */
203 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
205 if (EQ (tail
, halftail
) && len
!= 0)
209 halftail
= XCDR (halftail
);
212 XSETINT (length
, len
);
216 DEFUN ("string-bytes", Fstring_bytes
, Sstring_bytes
, 1, 1, 0,
217 doc
: /* Return the number of bytes in STRING.
218 If STRING is multibyte, this may be greater than the length of STRING. */)
222 CHECK_STRING (string
);
223 return make_number (SBYTES (string
));
226 DEFUN ("string-equal", Fstring_equal
, Sstring_equal
, 2, 2, 0,
227 doc
: /* Return t if two strings have identical contents.
228 Case is significant, but text properties are ignored.
229 Symbols are also allowed; their print names are used instead. */)
231 register Lisp_Object s1
, s2
;
234 s1
= SYMBOL_NAME (s1
);
236 s2
= SYMBOL_NAME (s2
);
240 if (SCHARS (s1
) != SCHARS (s2
)
241 || SBYTES (s1
) != SBYTES (s2
)
242 || bcmp (SDATA (s1
), SDATA (s2
), SBYTES (s1
)))
247 DEFUN ("compare-strings", Fcompare_strings
,
248 Scompare_strings
, 6, 7, 0,
249 doc
: /* Compare the contents of two strings, converting to multibyte if needed.
250 In string STR1, skip the first START1 characters and stop at END1.
251 In string STR2, skip the first START2 characters and stop at END2.
252 END1 and END2 default to the full lengths of the respective strings.
254 Case is significant in this comparison if IGNORE-CASE is nil.
255 Unibyte strings are converted to multibyte for comparison.
257 The value is t if the strings (or specified portions) match.
258 If string STR1 is less, the value is a negative number N;
259 - 1 - N is the number of characters that match at the beginning.
260 If string STR1 is greater, the value is a positive number N;
261 N - 1 is the number of characters that match at the beginning. */)
262 (str1
, start1
, end1
, str2
, start2
, end2
, ignore_case
)
263 Lisp_Object str1
, start1
, end1
, start2
, str2
, end2
, ignore_case
;
265 register int end1_char
, end2_char
;
266 register int i1
, i1_byte
, i2
, i2_byte
;
271 start1
= make_number (0);
273 start2
= make_number (0);
274 CHECK_NATNUM (start1
);
275 CHECK_NATNUM (start2
);
284 i1_byte
= string_char_to_byte (str1
, i1
);
285 i2_byte
= string_char_to_byte (str2
, i2
);
287 end1_char
= SCHARS (str1
);
288 if (! NILP (end1
) && end1_char
> XINT (end1
))
289 end1_char
= XINT (end1
);
291 end2_char
= SCHARS (str2
);
292 if (! NILP (end2
) && end2_char
> XINT (end2
))
293 end2_char
= XINT (end2
);
295 while (i1
< end1_char
&& i2
< end2_char
)
297 /* When we find a mismatch, we must compare the
298 characters, not just the bytes. */
301 if (STRING_MULTIBYTE (str1
))
302 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c1
, str1
, i1
, i1_byte
);
305 c1
= SREF (str1
, i1
++);
306 c1
= unibyte_char_to_multibyte (c1
);
309 if (STRING_MULTIBYTE (str2
))
310 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c2
, str2
, i2
, i2_byte
);
313 c2
= SREF (str2
, i2
++);
314 c2
= unibyte_char_to_multibyte (c2
);
320 if (! NILP (ignore_case
))
324 tem
= Fupcase (make_number (c1
));
326 tem
= Fupcase (make_number (c2
));
333 /* Note that I1 has already been incremented
334 past the character that we are comparing;
335 hence we don't add or subtract 1 here. */
337 return make_number (- i1
+ XINT (start1
));
339 return make_number (i1
- XINT (start1
));
343 return make_number (i1
- XINT (start1
) + 1);
345 return make_number (- i1
+ XINT (start1
) - 1);
350 DEFUN ("string-lessp", Fstring_lessp
, Sstring_lessp
, 2, 2, 0,
351 doc
: /* Return t if first arg string is less than second in lexicographic order.
353 Symbols are also allowed; their print names are used instead. */)
355 register Lisp_Object s1
, s2
;
358 register int i1
, i1_byte
, i2
, i2_byte
;
361 s1
= SYMBOL_NAME (s1
);
363 s2
= SYMBOL_NAME (s2
);
367 i1
= i1_byte
= i2
= i2_byte
= 0;
370 if (end
> SCHARS (s2
))
375 /* When we find a mismatch, we must compare the
376 characters, not just the bytes. */
379 FETCH_STRING_CHAR_ADVANCE (c1
, s1
, i1
, i1_byte
);
380 FETCH_STRING_CHAR_ADVANCE (c2
, s2
, i2
, i2_byte
);
383 return c1
< c2
? Qt
: Qnil
;
385 return i1
< SCHARS (s2
) ? Qt
: Qnil
;
389 /* "gcc -O3" enables automatic function inlining, which optimizes out
390 the arguments for the invocations of this function, whereas it
391 expects these values on the stack. */
392 static Lisp_Object concat
P_ ((int nargs
, Lisp_Object
*args
, enum Lisp_Type target_type
, int last_special
)) __attribute__((noinline
));
393 #else /* !__GNUC__ */
394 static Lisp_Object concat
P_ ((int nargs
, Lisp_Object
*args
, enum Lisp_Type target_type
, int last_special
));
406 return concat (2, args
, Lisp_String
, 0);
408 return concat (2, &s1
, Lisp_String
, 0);
409 #endif /* NO_ARG_ARRAY */
415 Lisp_Object s1
, s2
, s3
;
422 return concat (3, args
, Lisp_String
, 0);
424 return concat (3, &s1
, Lisp_String
, 0);
425 #endif /* NO_ARG_ARRAY */
428 DEFUN ("append", Fappend
, Sappend
, 0, MANY
, 0,
429 doc
: /* Concatenate all the arguments and make the result a list.
430 The result is a list whose elements are the elements of all the arguments.
431 Each argument may be a list, vector or string.
432 The last argument is not copied, just used as the tail of the new list.
433 usage: (append &rest SEQUENCES) */)
438 return concat (nargs
, args
, Lisp_Cons
, 1);
441 DEFUN ("concat", Fconcat
, Sconcat
, 0, MANY
, 0,
442 doc
: /* Concatenate all the arguments and make the result a string.
443 The result is a string whose elements are the elements of all the arguments.
444 Each argument may be a string or a list or vector of characters (integers).
445 usage: (concat &rest SEQUENCES) */)
450 return concat (nargs
, args
, Lisp_String
, 0);
453 DEFUN ("vconcat", Fvconcat
, Svconcat
, 0, MANY
, 0,
454 doc
: /* Concatenate all the arguments and make the result a vector.
455 The result is a vector whose elements are the elements of all the arguments.
456 Each argument may be a list, vector or string.
457 usage: (vconcat &rest SEQUENCES) */)
462 return concat (nargs
, args
, Lisp_Vectorlike
, 0);
466 DEFUN ("copy-sequence", Fcopy_sequence
, Scopy_sequence
, 1, 1, 0,
467 doc
: /* Return a copy of a list, vector, string or char-table.
468 The elements of a list or vector are not copied; they are shared
469 with the original. */)
473 if (NILP (arg
)) return arg
;
475 if (CHAR_TABLE_P (arg
))
477 return copy_char_table (arg
);
480 if (BOOL_VECTOR_P (arg
))
484 = ((XBOOL_VECTOR (arg
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
485 / BOOL_VECTOR_BITS_PER_CHAR
);
487 val
= Fmake_bool_vector (Flength (arg
), Qnil
);
488 bcopy (XBOOL_VECTOR (arg
)->data
, XBOOL_VECTOR (val
)->data
,
493 if (!CONSP (arg
) && !VECTORP (arg
) && !STRINGP (arg
))
494 wrong_type_argument (Qsequencep
, arg
);
496 return concat (1, &arg
, CONSP (arg
) ? Lisp_Cons
: XTYPE (arg
), 0);
499 /* This structure holds information of an argument of `concat' that is
500 a string and has text properties to be copied. */
503 int argnum
; /* refer to ARGS (arguments of `concat') */
504 int from
; /* refer to ARGS[argnum] (argument string) */
505 int to
; /* refer to VAL (the target string) */
509 concat (nargs
, args
, target_type
, last_special
)
512 enum Lisp_Type target_type
;
516 register Lisp_Object tail
;
517 register Lisp_Object
this;
519 int toindex_byte
= 0;
520 register int result_len
;
521 register int result_len_byte
;
523 Lisp_Object last_tail
;
526 /* When we make a multibyte string, we can't copy text properties
527 while concatinating each string because the length of resulting
528 string can't be decided until we finish the whole concatination.
529 So, we record strings that have text properties to be copied
530 here, and copy the text properties after the concatination. */
531 struct textprop_rec
*textprops
= NULL
;
532 /* Number of elments in textprops. */
533 int num_textprops
= 0;
538 /* In append, the last arg isn't treated like the others */
539 if (last_special
&& nargs
> 0)
542 last_tail
= args
[nargs
];
547 /* Check each argument. */
548 for (argnum
= 0; argnum
< nargs
; argnum
++)
551 if (!(CONSP (this) || NILP (this) || VECTORP (this) || STRINGP (this)
552 || COMPILEDP (this) || BOOL_VECTOR_P (this)))
553 wrong_type_argument (Qsequencep
, this);
556 /* Compute total length in chars of arguments in RESULT_LEN.
557 If desired output is a string, also compute length in bytes
558 in RESULT_LEN_BYTE, and determine in SOME_MULTIBYTE
559 whether the result should be a multibyte string. */
563 for (argnum
= 0; argnum
< nargs
; argnum
++)
567 len
= XFASTINT (Flength (this));
568 if (target_type
== Lisp_String
)
570 /* We must count the number of bytes needed in the string
571 as well as the number of characters. */
577 for (i
= 0; i
< len
; i
++)
580 CHECK_CHARACTER (ch
);
581 this_len_byte
= CHAR_BYTES (XINT (ch
));
582 result_len_byte
+= this_len_byte
;
583 if (! ASCII_CHAR_P (XINT (ch
)) && ! CHAR_BYTE8_P (XINT (ch
)))
586 else if (BOOL_VECTOR_P (this) && XBOOL_VECTOR (this)->size
> 0)
587 wrong_type_argument (Qintegerp
, Faref (this, make_number (0)));
588 else if (CONSP (this))
589 for (; CONSP (this); this = XCDR (this))
592 CHECK_CHARACTER (ch
);
593 this_len_byte
= CHAR_BYTES (XINT (ch
));
594 result_len_byte
+= this_len_byte
;
595 if (! ASCII_CHAR_P (XINT (ch
)) && ! CHAR_BYTE8_P (XINT (ch
)))
598 else if (STRINGP (this))
600 if (STRING_MULTIBYTE (this))
603 result_len_byte
+= SBYTES (this);
606 result_len_byte
+= count_size_as_multibyte (SDATA (this),
614 if (! some_multibyte
)
615 result_len_byte
= result_len
;
617 /* Create the output object. */
618 if (target_type
== Lisp_Cons
)
619 val
= Fmake_list (make_number (result_len
), Qnil
);
620 else if (target_type
== Lisp_Vectorlike
)
621 val
= Fmake_vector (make_number (result_len
), Qnil
);
622 else if (some_multibyte
)
623 val
= make_uninit_multibyte_string (result_len
, result_len_byte
);
625 val
= make_uninit_string (result_len
);
627 /* In `append', if all but last arg are nil, return last arg. */
628 if (target_type
== Lisp_Cons
&& EQ (val
, Qnil
))
631 /* Copy the contents of the args into the result. */
633 tail
= val
, toindex
= -1; /* -1 in toindex is flag we are making a list */
635 toindex
= 0, toindex_byte
= 0;
639 SAFE_ALLOCA (textprops
, struct textprop_rec
*, sizeof (struct textprop_rec
) * nargs
);
641 for (argnum
= 0; argnum
< nargs
; argnum
++)
645 register unsigned int thisindex
= 0;
646 register unsigned int thisindex_byte
= 0;
650 thislen
= Flength (this), thisleni
= XINT (thislen
);
652 /* Between strings of the same kind, copy fast. */
653 if (STRINGP (this) && STRINGP (val
)
654 && STRING_MULTIBYTE (this) == some_multibyte
)
656 int thislen_byte
= SBYTES (this);
658 bcopy (SDATA (this), SDATA (val
) + toindex_byte
,
660 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
662 textprops
[num_textprops
].argnum
= argnum
;
663 textprops
[num_textprops
].from
= 0;
664 textprops
[num_textprops
++].to
= toindex
;
666 toindex_byte
+= thislen_byte
;
668 STRING_SET_CHARS (val
, SCHARS (val
));
670 /* Copy a single-byte string to a multibyte string. */
671 else if (STRINGP (this) && STRINGP (val
))
673 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
675 textprops
[num_textprops
].argnum
= argnum
;
676 textprops
[num_textprops
].from
= 0;
677 textprops
[num_textprops
++].to
= toindex
;
679 toindex_byte
+= copy_text (SDATA (this),
680 SDATA (val
) + toindex_byte
,
681 SCHARS (this), 0, 1);
685 /* Copy element by element. */
688 register Lisp_Object elt
;
690 /* Fetch next element of `this' arg into `elt', or break if
691 `this' is exhausted. */
692 if (NILP (this)) break;
694 elt
= XCAR (this), this = XCDR (this);
695 else if (thisindex
>= thisleni
)
697 else if (STRINGP (this))
700 if (STRING_MULTIBYTE (this))
702 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, this,
705 XSETFASTINT (elt
, c
);
709 XSETFASTINT (elt
, SREF (this, thisindex
)); thisindex
++;
711 && XINT (elt
) >= 0200
712 && XINT (elt
) < 0400)
714 c
= unibyte_char_to_multibyte (XINT (elt
));
719 else if (BOOL_VECTOR_P (this))
722 byte
= XBOOL_VECTOR (this)->data
[thisindex
/ BOOL_VECTOR_BITS_PER_CHAR
];
723 if (byte
& (1 << (thisindex
% BOOL_VECTOR_BITS_PER_CHAR
)))
731 elt
= AREF (this, thisindex
);
735 /* Store this element into the result. */
742 else if (VECTORP (val
))
744 ASET (val
, toindex
, elt
);
751 toindex_byte
+= CHAR_STRING (XINT (elt
),
752 SDATA (val
) + toindex_byte
);
754 SSET (val
, toindex_byte
++, XINT (elt
));
760 XSETCDR (prev
, last_tail
);
762 if (num_textprops
> 0)
765 int last_to_end
= -1;
767 for (argnum
= 0; argnum
< num_textprops
; argnum
++)
769 this = args
[textprops
[argnum
].argnum
];
770 props
= text_property_list (this,
772 make_number (SCHARS (this)),
774 /* If successive arguments have properites, be sure that the
775 value of `composition' property be the copy. */
776 if (last_to_end
== textprops
[argnum
].to
)
777 make_composition_value_copy (props
);
778 add_text_properties_from_list (val
, props
,
779 make_number (textprops
[argnum
].to
));
780 last_to_end
= textprops
[argnum
].to
+ SCHARS (this);
788 static Lisp_Object string_char_byte_cache_string
;
789 static EMACS_INT string_char_byte_cache_charpos
;
790 static EMACS_INT string_char_byte_cache_bytepos
;
793 clear_string_char_byte_cache ()
795 string_char_byte_cache_string
= Qnil
;
798 /* Return the byte index corresponding to CHAR_INDEX in STRING. */
801 string_char_to_byte (string
, char_index
)
803 EMACS_INT char_index
;
806 EMACS_INT best_below
, best_below_byte
;
807 EMACS_INT best_above
, best_above_byte
;
809 best_below
= best_below_byte
= 0;
810 best_above
= SCHARS (string
);
811 best_above_byte
= SBYTES (string
);
812 if (best_above
== best_above_byte
)
815 if (EQ (string
, string_char_byte_cache_string
))
817 if (string_char_byte_cache_charpos
< char_index
)
819 best_below
= string_char_byte_cache_charpos
;
820 best_below_byte
= string_char_byte_cache_bytepos
;
824 best_above
= string_char_byte_cache_charpos
;
825 best_above_byte
= string_char_byte_cache_bytepos
;
829 if (char_index
- best_below
< best_above
- char_index
)
831 unsigned char *p
= SDATA (string
) + best_below_byte
;
833 while (best_below
< char_index
)
835 p
+= BYTES_BY_CHAR_HEAD (*p
);
838 i_byte
= p
- SDATA (string
);
842 unsigned char *p
= SDATA (string
) + best_above_byte
;
844 while (best_above
> char_index
)
847 while (!CHAR_HEAD_P (*p
)) p
--;
850 i_byte
= p
- SDATA (string
);
853 string_char_byte_cache_bytepos
= i_byte
;
854 string_char_byte_cache_charpos
= char_index
;
855 string_char_byte_cache_string
= string
;
860 /* Return the character index corresponding to BYTE_INDEX in STRING. */
863 string_byte_to_char (string
, byte_index
)
865 EMACS_INT byte_index
;
868 EMACS_INT best_below
, best_below_byte
;
869 EMACS_INT best_above
, best_above_byte
;
871 best_below
= best_below_byte
= 0;
872 best_above
= SCHARS (string
);
873 best_above_byte
= SBYTES (string
);
874 if (best_above
== best_above_byte
)
877 if (EQ (string
, string_char_byte_cache_string
))
879 if (string_char_byte_cache_bytepos
< byte_index
)
881 best_below
= string_char_byte_cache_charpos
;
882 best_below_byte
= string_char_byte_cache_bytepos
;
886 best_above
= string_char_byte_cache_charpos
;
887 best_above_byte
= string_char_byte_cache_bytepos
;
891 if (byte_index
- best_below_byte
< best_above_byte
- byte_index
)
893 unsigned char *p
= SDATA (string
) + best_below_byte
;
894 unsigned char *pend
= SDATA (string
) + byte_index
;
898 p
+= BYTES_BY_CHAR_HEAD (*p
);
902 i_byte
= p
- SDATA (string
);
906 unsigned char *p
= SDATA (string
) + best_above_byte
;
907 unsigned char *pbeg
= SDATA (string
) + byte_index
;
912 while (!CHAR_HEAD_P (*p
)) p
--;
916 i_byte
= p
- SDATA (string
);
919 string_char_byte_cache_bytepos
= i_byte
;
920 string_char_byte_cache_charpos
= i
;
921 string_char_byte_cache_string
= string
;
926 /* Convert STRING to a multibyte string. */
929 string_make_multibyte (string
)
937 if (STRING_MULTIBYTE (string
))
940 nbytes
= count_size_as_multibyte (SDATA (string
),
942 /* If all the chars are ASCII, they won't need any more bytes
943 once converted. In that case, we can return STRING itself. */
944 if (nbytes
== SBYTES (string
))
947 SAFE_ALLOCA (buf
, unsigned char *, nbytes
);
948 copy_text (SDATA (string
), buf
, SBYTES (string
),
951 ret
= make_multibyte_string (buf
, SCHARS (string
), nbytes
);
958 /* Convert STRING (if unibyte) to a multibyte string without changing
959 the number of characters. Characters 0200 trough 0237 are
960 converted to eight-bit characters. */
963 string_to_multibyte (string
)
971 if (STRING_MULTIBYTE (string
))
974 nbytes
= parse_str_to_multibyte (SDATA (string
), SBYTES (string
));
975 /* If all the chars are ASCII, they won't need any more bytes once
977 if (nbytes
== SBYTES (string
))
978 return make_multibyte_string (SDATA (string
), nbytes
, nbytes
);
980 SAFE_ALLOCA (buf
, unsigned char *, nbytes
);
981 bcopy (SDATA (string
), buf
, SBYTES (string
));
982 str_to_multibyte (buf
, nbytes
, SBYTES (string
));
984 ret
= make_multibyte_string (buf
, SCHARS (string
), nbytes
);
991 /* Convert STRING to a single-byte string. */
994 string_make_unibyte (string
)
1002 if (! STRING_MULTIBYTE (string
))
1005 nchars
= SCHARS (string
);
1007 SAFE_ALLOCA (buf
, unsigned char *, nchars
);
1008 copy_text (SDATA (string
), buf
, SBYTES (string
),
1011 ret
= make_unibyte_string (buf
, nchars
);
1017 DEFUN ("string-make-multibyte", Fstring_make_multibyte
, Sstring_make_multibyte
,
1019 doc
: /* Return the multibyte equivalent of STRING.
1020 If STRING is unibyte and contains non-ASCII characters, the function
1021 `unibyte-char-to-multibyte' is used to convert each unibyte character
1022 to a multibyte character. In this case, the returned string is a
1023 newly created string with no text properties. If STRING is multibyte
1024 or entirely ASCII, it is returned unchanged. In particular, when
1025 STRING is unibyte and entirely ASCII, the returned string is unibyte.
1026 \(When the characters are all ASCII, Emacs primitives will treat the
1027 string the same way whether it is unibyte or multibyte.) */)
1031 CHECK_STRING (string
);
1033 return string_make_multibyte (string
);
1036 DEFUN ("string-make-unibyte", Fstring_make_unibyte
, Sstring_make_unibyte
,
1038 doc
: /* Return the unibyte equivalent of STRING.
1039 Multibyte character codes are converted to unibyte according to
1040 `nonascii-translation-table' or, if that is nil, `nonascii-insert-offset'.
1041 If the lookup in the translation table fails, this function takes just
1042 the low 8 bits of each character. */)
1046 CHECK_STRING (string
);
1048 return string_make_unibyte (string
);
1051 DEFUN ("string-as-unibyte", Fstring_as_unibyte
, Sstring_as_unibyte
,
1053 doc
: /* Return a unibyte string with the same individual bytes as STRING.
1054 If STRING is unibyte, the result is STRING itself.
1055 Otherwise it is a newly created string, with no text properties.
1056 If STRING is multibyte and contains a character of charset
1057 `eight-bit', it is converted to the corresponding single byte. */)
1061 CHECK_STRING (string
);
1063 if (STRING_MULTIBYTE (string
))
1065 int bytes
= SBYTES (string
);
1066 unsigned char *str
= (unsigned char *) xmalloc (bytes
);
1068 bcopy (SDATA (string
), str
, bytes
);
1069 bytes
= str_as_unibyte (str
, bytes
);
1070 string
= make_unibyte_string (str
, bytes
);
1076 DEFUN ("string-as-multibyte", Fstring_as_multibyte
, Sstring_as_multibyte
,
1078 doc
: /* Return a multibyte string with the same individual bytes as STRING.
1079 If STRING is multibyte, the result is STRING itself.
1080 Otherwise it is a newly created string, with no text properties.
1082 If STRING is unibyte and contains an individual 8-bit byte (i.e. not
1083 part of a correct utf-8 sequence), it is converted to the corresponding
1084 multibyte character of charset `eight-bit'.
1085 See also `string-to-multibyte'.
1087 Beware, this often doesn't really do what you think it does.
1088 It is similar to (decode-coding-string STRING 'utf-8-emacs).
1089 If you're not sure, whether to use `string-as-multibyte' or
1090 `string-to-multibyte', use `string-to-multibyte'. */)
1094 CHECK_STRING (string
);
1096 if (! STRING_MULTIBYTE (string
))
1098 Lisp_Object new_string
;
1101 parse_str_as_multibyte (SDATA (string
),
1104 new_string
= make_uninit_multibyte_string (nchars
, nbytes
);
1105 bcopy (SDATA (string
), SDATA (new_string
),
1107 if (nbytes
!= SBYTES (string
))
1108 str_as_multibyte (SDATA (new_string
), nbytes
,
1109 SBYTES (string
), NULL
);
1110 string
= new_string
;
1111 STRING_SET_INTERVALS (string
, NULL_INTERVAL
);
1116 DEFUN ("string-to-multibyte", Fstring_to_multibyte
, Sstring_to_multibyte
,
1118 doc
: /* Return a multibyte string with the same individual chars as STRING.
1119 If STRING is multibyte, the result is STRING itself.
1120 Otherwise it is a newly created string, with no text properties.
1122 If STRING is unibyte and contains an 8-bit byte, it is converted to
1123 the corresponding multibyte character of charset `eight-bit'.
1125 This differs from `string-as-multibyte' by converting each byte of a correct
1126 utf-8 sequence to an eight-bit character, not just bytes that don't form a
1127 correct sequence. */)
1131 CHECK_STRING (string
);
1133 return string_to_multibyte (string
);
1137 DEFUN ("copy-alist", Fcopy_alist
, Scopy_alist
, 1, 1, 0,
1138 doc
: /* Return a copy of ALIST.
1139 This is an alist which represents the same mapping from objects to objects,
1140 but does not share the alist structure with ALIST.
1141 The objects mapped (cars and cdrs of elements of the alist)
1142 are shared, however.
1143 Elements of ALIST that are not conses are also shared. */)
1147 register Lisp_Object tem
;
1152 alist
= concat (1, &alist
, Lisp_Cons
, 0);
1153 for (tem
= alist
; CONSP (tem
); tem
= XCDR (tem
))
1155 register Lisp_Object car
;
1159 XSETCAR (tem
, Fcons (XCAR (car
), XCDR (car
)));
1164 DEFUN ("substring", Fsubstring
, Ssubstring
, 2, 3, 0,
1165 doc
: /* Return a substring of STRING, starting at index FROM and ending before TO.
1166 TO may be nil or omitted; then the substring runs to the end of STRING.
1167 FROM and TO start at 0. If either is negative, it counts from the end.
1169 This function allows vectors as well as strings. */)
1172 register Lisp_Object from
, to
;
1177 int from_char
, to_char
;
1178 int from_byte
= 0, to_byte
= 0;
1180 CHECK_VECTOR_OR_STRING (string
);
1181 CHECK_NUMBER (from
);
1183 if (STRINGP (string
))
1185 size
= SCHARS (string
);
1186 size_byte
= SBYTES (string
);
1189 size
= ASIZE (string
);
1194 to_byte
= size_byte
;
1200 to_char
= XINT (to
);
1204 if (STRINGP (string
))
1205 to_byte
= string_char_to_byte (string
, to_char
);
1208 from_char
= XINT (from
);
1211 if (STRINGP (string
))
1212 from_byte
= string_char_to_byte (string
, from_char
);
1214 if (!(0 <= from_char
&& from_char
<= to_char
&& to_char
<= size
))
1215 args_out_of_range_3 (string
, make_number (from_char
),
1216 make_number (to_char
));
1218 if (STRINGP (string
))
1220 res
= make_specified_string (SDATA (string
) + from_byte
,
1221 to_char
- from_char
, to_byte
- from_byte
,
1222 STRING_MULTIBYTE (string
));
1223 copy_text_properties (make_number (from_char
), make_number (to_char
),
1224 string
, make_number (0), res
, Qnil
);
1227 res
= Fvector (to_char
- from_char
, &AREF (string
, from_char
));
1233 DEFUN ("substring-no-properties", Fsubstring_no_properties
, Ssubstring_no_properties
, 1, 3, 0,
1234 doc
: /* Return a substring of STRING, without text properties.
1235 It starts at index FROM and ending before TO.
1236 TO may be nil or omitted; then the substring runs to the end of STRING.
1237 If FROM is nil or omitted, the substring starts at the beginning of STRING.
1238 If FROM or TO is negative, it counts from the end.
1240 With one argument, just copy STRING without its properties. */)
1243 register Lisp_Object from
, to
;
1245 int size
, size_byte
;
1246 int from_char
, to_char
;
1247 int from_byte
, to_byte
;
1249 CHECK_STRING (string
);
1251 size
= SCHARS (string
);
1252 size_byte
= SBYTES (string
);
1255 from_char
= from_byte
= 0;
1258 CHECK_NUMBER (from
);
1259 from_char
= XINT (from
);
1263 from_byte
= string_char_to_byte (string
, from_char
);
1269 to_byte
= size_byte
;
1275 to_char
= XINT (to
);
1279 to_byte
= string_char_to_byte (string
, to_char
);
1282 if (!(0 <= from_char
&& from_char
<= to_char
&& to_char
<= size
))
1283 args_out_of_range_3 (string
, make_number (from_char
),
1284 make_number (to_char
));
1286 return make_specified_string (SDATA (string
) + from_byte
,
1287 to_char
- from_char
, to_byte
- from_byte
,
1288 STRING_MULTIBYTE (string
));
1291 /* Extract a substring of STRING, giving start and end positions
1292 both in characters and in bytes. */
1295 substring_both (string
, from
, from_byte
, to
, to_byte
)
1297 int from
, from_byte
, to
, to_byte
;
1303 CHECK_VECTOR_OR_STRING (string
);
1305 if (STRINGP (string
))
1307 size
= SCHARS (string
);
1308 size_byte
= SBYTES (string
);
1311 size
= ASIZE (string
);
1313 if (!(0 <= from
&& from
<= to
&& to
<= size
))
1314 args_out_of_range_3 (string
, make_number (from
), make_number (to
));
1316 if (STRINGP (string
))
1318 res
= make_specified_string (SDATA (string
) + from_byte
,
1319 to
- from
, to_byte
- from_byte
,
1320 STRING_MULTIBYTE (string
));
1321 copy_text_properties (make_number (from
), make_number (to
),
1322 string
, make_number (0), res
, Qnil
);
1325 res
= Fvector (to
- from
, &AREF (string
, from
));
1330 DEFUN ("nthcdr", Fnthcdr
, Snthcdr
, 2, 2, 0,
1331 doc
: /* Take cdr N times on LIST, returns the result. */)
1334 register Lisp_Object list
;
1336 register int i
, num
;
1339 for (i
= 0; i
< num
&& !NILP (list
); i
++)
1342 CHECK_LIST_CONS (list
, list
);
1348 DEFUN ("nth", Fnth
, Snth
, 2, 2, 0,
1349 doc
: /* Return the Nth element of LIST.
1350 N counts from zero. If LIST is not that long, nil is returned. */)
1352 Lisp_Object n
, list
;
1354 return Fcar (Fnthcdr (n
, list
));
1357 DEFUN ("elt", Felt
, Selt
, 2, 2, 0,
1358 doc
: /* Return element of SEQUENCE at index N. */)
1360 register Lisp_Object sequence
, n
;
1363 if (CONSP (sequence
) || NILP (sequence
))
1364 return Fcar (Fnthcdr (n
, sequence
));
1366 /* Faref signals a "not array" error, so check here. */
1367 CHECK_ARRAY (sequence
, Qsequencep
);
1368 return Faref (sequence
, n
);
1371 DEFUN ("member", Fmember
, Smember
, 2, 2, 0,
1372 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
1373 The value is actually the tail of LIST whose car is ELT. */)
1375 register Lisp_Object elt
;
1378 register Lisp_Object tail
;
1379 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1381 register Lisp_Object tem
;
1382 CHECK_LIST_CONS (tail
, list
);
1384 if (! NILP (Fequal (elt
, tem
)))
1391 DEFUN ("memq", Fmemq
, Smemq
, 2, 2, 0,
1392 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
1393 The value is actually the tail of LIST whose car is ELT. */)
1395 register Lisp_Object elt
, list
;
1399 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1403 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1407 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1418 DEFUN ("memql", Fmemql
, Smemql
, 2, 2, 0,
1419 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `eql'.
1420 The value is actually the tail of LIST whose car is ELT. */)
1422 register Lisp_Object elt
;
1425 register Lisp_Object tail
;
1428 return Fmemq (elt
, list
);
1430 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1432 register Lisp_Object tem
;
1433 CHECK_LIST_CONS (tail
, list
);
1435 if (FLOATP (tem
) && internal_equal (elt
, tem
, 0, 0))
1442 DEFUN ("assq", Fassq
, Sassq
, 2, 2, 0,
1443 doc
: /* Return non-nil if KEY is `eq' to the car of an element of LIST.
1444 The value is actually the first element of LIST whose car is KEY.
1445 Elements of LIST that are not conses are ignored. */)
1447 Lisp_Object key
, list
;
1452 || (CONSP (XCAR (list
))
1453 && EQ (XCAR (XCAR (list
)), key
)))
1458 || (CONSP (XCAR (list
))
1459 && EQ (XCAR (XCAR (list
)), key
)))
1464 || (CONSP (XCAR (list
))
1465 && EQ (XCAR (XCAR (list
)), key
)))
1475 /* Like Fassq but never report an error and do not allow quits.
1476 Use only on lists known never to be circular. */
1479 assq_no_quit (key
, list
)
1480 Lisp_Object key
, list
;
1483 && (!CONSP (XCAR (list
))
1484 || !EQ (XCAR (XCAR (list
)), key
)))
1487 return CAR_SAFE (list
);
1490 DEFUN ("assoc", Fassoc
, Sassoc
, 2, 2, 0,
1491 doc
: /* Return non-nil if KEY is `equal' to the car of an element of LIST.
1492 The value is actually the first element of LIST whose car equals KEY. */)
1494 Lisp_Object key
, list
;
1501 || (CONSP (XCAR (list
))
1502 && (car
= XCAR (XCAR (list
)),
1503 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1508 || (CONSP (XCAR (list
))
1509 && (car
= XCAR (XCAR (list
)),
1510 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1515 || (CONSP (XCAR (list
))
1516 && (car
= XCAR (XCAR (list
)),
1517 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1527 /* Like Fassoc but never report an error and do not allow quits.
1528 Use only on lists known never to be circular. */
1531 assoc_no_quit (key
, list
)
1532 Lisp_Object key
, list
;
1535 && (!CONSP (XCAR (list
))
1536 || (!EQ (XCAR (XCAR (list
)), key
)
1537 && NILP (Fequal (XCAR (XCAR (list
)), key
)))))
1540 return CONSP (list
) ? XCAR (list
) : Qnil
;
1543 DEFUN ("rassq", Frassq
, Srassq
, 2, 2, 0,
1544 doc
: /* Return non-nil if KEY is `eq' to the cdr of an element of LIST.
1545 The value is actually the first element of LIST whose cdr is KEY. */)
1547 register Lisp_Object key
;
1553 || (CONSP (XCAR (list
))
1554 && EQ (XCDR (XCAR (list
)), key
)))
1559 || (CONSP (XCAR (list
))
1560 && EQ (XCDR (XCAR (list
)), key
)))
1565 || (CONSP (XCAR (list
))
1566 && EQ (XCDR (XCAR (list
)), key
)))
1576 DEFUN ("rassoc", Frassoc
, Srassoc
, 2, 2, 0,
1577 doc
: /* Return non-nil if KEY is `equal' to the cdr of an element of LIST.
1578 The value is actually the first element of LIST whose cdr equals KEY. */)
1580 Lisp_Object key
, list
;
1587 || (CONSP (XCAR (list
))
1588 && (cdr
= XCDR (XCAR (list
)),
1589 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1594 || (CONSP (XCAR (list
))
1595 && (cdr
= XCDR (XCAR (list
)),
1596 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1601 || (CONSP (XCAR (list
))
1602 && (cdr
= XCDR (XCAR (list
)),
1603 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1613 DEFUN ("delq", Fdelq
, Sdelq
, 2, 2, 0,
1614 doc
: /* Delete by side effect any occurrences of ELT as a member of LIST.
1615 The modified LIST is returned. Comparison is done with `eq'.
1616 If the first member of LIST is ELT, there is no way to remove it by side effect;
1617 therefore, write `(setq foo (delq element foo))'
1618 to be sure of changing the value of `foo'. */)
1620 register Lisp_Object elt
;
1623 register Lisp_Object tail
, prev
;
1624 register Lisp_Object tem
;
1628 while (!NILP (tail
))
1630 CHECK_LIST_CONS (tail
, list
);
1637 Fsetcdr (prev
, XCDR (tail
));
1647 DEFUN ("delete", Fdelete
, Sdelete
, 2, 2, 0,
1648 doc
: /* Delete by side effect any occurrences of ELT as a member of SEQ.
1649 SEQ must be a list, a vector, or a string.
1650 The modified SEQ is returned. Comparison is done with `equal'.
1651 If SEQ is not a list, or the first member of SEQ is ELT, deleting it
1652 is not a side effect; it is simply using a different sequence.
1653 Therefore, write `(setq foo (delete element foo))'
1654 to be sure of changing the value of `foo'. */)
1656 Lisp_Object elt
, seq
;
1662 for (i
= n
= 0; i
< ASIZE (seq
); ++i
)
1663 if (NILP (Fequal (AREF (seq
, i
), elt
)))
1666 if (n
!= ASIZE (seq
))
1668 struct Lisp_Vector
*p
= allocate_vector (n
);
1670 for (i
= n
= 0; i
< ASIZE (seq
); ++i
)
1671 if (NILP (Fequal (AREF (seq
, i
), elt
)))
1672 p
->contents
[n
++] = AREF (seq
, i
);
1674 XSETVECTOR (seq
, p
);
1677 else if (STRINGP (seq
))
1679 EMACS_INT i
, ibyte
, nchars
, nbytes
, cbytes
;
1682 for (i
= nchars
= nbytes
= ibyte
= 0;
1684 ++i
, ibyte
+= cbytes
)
1686 if (STRING_MULTIBYTE (seq
))
1688 c
= STRING_CHAR (SDATA (seq
) + ibyte
,
1689 SBYTES (seq
) - ibyte
);
1690 cbytes
= CHAR_BYTES (c
);
1698 if (!INTEGERP (elt
) || c
!= XINT (elt
))
1705 if (nchars
!= SCHARS (seq
))
1709 tem
= make_uninit_multibyte_string (nchars
, nbytes
);
1710 if (!STRING_MULTIBYTE (seq
))
1711 STRING_SET_UNIBYTE (tem
);
1713 for (i
= nchars
= nbytes
= ibyte
= 0;
1715 ++i
, ibyte
+= cbytes
)
1717 if (STRING_MULTIBYTE (seq
))
1719 c
= STRING_CHAR (SDATA (seq
) + ibyte
,
1720 SBYTES (seq
) - ibyte
);
1721 cbytes
= CHAR_BYTES (c
);
1729 if (!INTEGERP (elt
) || c
!= XINT (elt
))
1731 unsigned char *from
= SDATA (seq
) + ibyte
;
1732 unsigned char *to
= SDATA (tem
) + nbytes
;
1738 for (n
= cbytes
; n
--; )
1748 Lisp_Object tail
, prev
;
1750 for (tail
= seq
, prev
= Qnil
; CONSP (tail
); tail
= XCDR (tail
))
1752 CHECK_LIST_CONS (tail
, seq
);
1754 if (!NILP (Fequal (elt
, XCAR (tail
))))
1759 Fsetcdr (prev
, XCDR (tail
));
1770 DEFUN ("nreverse", Fnreverse
, Snreverse
, 1, 1, 0,
1771 doc
: /* Reverse LIST by modifying cdr pointers.
1772 Return the reversed list. */)
1776 register Lisp_Object prev
, tail
, next
;
1778 if (NILP (list
)) return list
;
1781 while (!NILP (tail
))
1784 CHECK_LIST_CONS (tail
, list
);
1786 Fsetcdr (tail
, prev
);
1793 DEFUN ("reverse", Freverse
, Sreverse
, 1, 1, 0,
1794 doc
: /* Reverse LIST, copying. Return the reversed list.
1795 See also the function `nreverse', which is used more often. */)
1801 for (new = Qnil
; CONSP (list
); list
= XCDR (list
))
1804 new = Fcons (XCAR (list
), new);
1806 CHECK_LIST_END (list
, list
);
1810 Lisp_Object
merge ();
1812 DEFUN ("sort", Fsort
, Ssort
, 2, 2, 0,
1813 doc
: /* Sort LIST, stably, comparing elements using PREDICATE.
1814 Returns the sorted list. LIST is modified by side effects.
1815 PREDICATE is called with two elements of LIST, and should return non-nil
1816 if the first element should sort before the second. */)
1818 Lisp_Object list
, predicate
;
1820 Lisp_Object front
, back
;
1821 register Lisp_Object len
, tem
;
1822 struct gcpro gcpro1
, gcpro2
;
1823 register int length
;
1826 len
= Flength (list
);
1827 length
= XINT (len
);
1831 XSETINT (len
, (length
/ 2) - 1);
1832 tem
= Fnthcdr (len
, list
);
1834 Fsetcdr (tem
, Qnil
);
1836 GCPRO2 (front
, back
);
1837 front
= Fsort (front
, predicate
);
1838 back
= Fsort (back
, predicate
);
1840 return merge (front
, back
, predicate
);
1844 merge (org_l1
, org_l2
, pred
)
1845 Lisp_Object org_l1
, org_l2
;
1849 register Lisp_Object tail
;
1851 register Lisp_Object l1
, l2
;
1852 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1859 /* It is sufficient to protect org_l1 and org_l2.
1860 When l1 and l2 are updated, we copy the new values
1861 back into the org_ vars. */
1862 GCPRO4 (org_l1
, org_l2
, pred
, value
);
1882 tem
= call2 (pred
, Fcar (l2
), Fcar (l1
));
1898 Fsetcdr (tail
, tem
);
1904 #if 0 /* Unsafe version. */
1905 DEFUN ("plist-get", Fplist_get
, Splist_get
, 2, 2, 0,
1906 doc
: /* Extract a value from a property list.
1907 PLIST is a property list, which is a list of the form
1908 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
1909 corresponding to the given PROP, or nil if PROP is not
1910 one of the properties on the list. */)
1918 CONSP (tail
) && CONSP (XCDR (tail
));
1919 tail
= XCDR (XCDR (tail
)))
1921 if (EQ (prop
, XCAR (tail
)))
1922 return XCAR (XCDR (tail
));
1924 /* This function can be called asynchronously
1925 (setup_coding_system). Don't QUIT in that case. */
1926 if (!interrupt_input_blocked
)
1930 CHECK_LIST_END (tail
, prop
);
1936 /* This does not check for quits. That is safe since it must terminate. */
1938 DEFUN ("plist-get", Fplist_get
, Splist_get
, 2, 2, 0,
1939 doc
: /* Extract a value from a property list.
1940 PLIST is a property list, which is a list of the form
1941 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
1942 corresponding to the given PROP, or nil if PROP is not one of the
1943 properties on the list. This function never signals an error. */)
1948 Lisp_Object tail
, halftail
;
1950 /* halftail is used to detect circular lists. */
1951 tail
= halftail
= plist
;
1952 while (CONSP (tail
) && CONSP (XCDR (tail
)))
1954 if (EQ (prop
, XCAR (tail
)))
1955 return XCAR (XCDR (tail
));
1957 tail
= XCDR (XCDR (tail
));
1958 halftail
= XCDR (halftail
);
1959 if (EQ (tail
, halftail
))
1966 DEFUN ("get", Fget
, Sget
, 2, 2, 0,
1967 doc
: /* Return the value of SYMBOL's PROPNAME property.
1968 This is the last value stored with `(put SYMBOL PROPNAME VALUE)'. */)
1970 Lisp_Object symbol
, propname
;
1972 CHECK_SYMBOL (symbol
);
1973 return Fplist_get (XSYMBOL (symbol
)->plist
, propname
);
1976 DEFUN ("plist-put", Fplist_put
, Splist_put
, 3, 3, 0,
1977 doc
: /* Change value in PLIST of PROP to VAL.
1978 PLIST is a property list, which is a list of the form
1979 \(PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol and VAL is any object.
1980 If PROP is already a property on the list, its value is set to VAL,
1981 otherwise the new PROP VAL pair is added. The new plist is returned;
1982 use `(setq x (plist-put x prop val))' to be sure to use the new value.
1983 The PLIST is modified by side effects. */)
1986 register Lisp_Object prop
;
1989 register Lisp_Object tail
, prev
;
1990 Lisp_Object newcell
;
1992 for (tail
= plist
; CONSP (tail
) && CONSP (XCDR (tail
));
1993 tail
= XCDR (XCDR (tail
)))
1995 if (EQ (prop
, XCAR (tail
)))
1997 Fsetcar (XCDR (tail
), val
);
2004 newcell
= Fcons (prop
, Fcons (val
, NILP (prev
) ? plist
: XCDR (XCDR (prev
))));
2008 Fsetcdr (XCDR (prev
), newcell
);
2012 DEFUN ("put", Fput
, Sput
, 3, 3, 0,
2013 doc
: /* Store SYMBOL's PROPNAME property with value VALUE.
2014 It can be retrieved with `(get SYMBOL PROPNAME)'. */)
2015 (symbol
, propname
, value
)
2016 Lisp_Object symbol
, propname
, value
;
2018 CHECK_SYMBOL (symbol
);
2019 XSYMBOL (symbol
)->plist
2020 = Fplist_put (XSYMBOL (symbol
)->plist
, propname
, value
);
2024 DEFUN ("lax-plist-get", Flax_plist_get
, Slax_plist_get
, 2, 2, 0,
2025 doc
: /* Extract a value from a property list, comparing with `equal'.
2026 PLIST is a property list, which is a list of the form
2027 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
2028 corresponding to the given PROP, or nil if PROP is not
2029 one of the properties on the list. */)
2037 CONSP (tail
) && CONSP (XCDR (tail
));
2038 tail
= XCDR (XCDR (tail
)))
2040 if (! NILP (Fequal (prop
, XCAR (tail
))))
2041 return XCAR (XCDR (tail
));
2046 CHECK_LIST_END (tail
, prop
);
2051 DEFUN ("lax-plist-put", Flax_plist_put
, Slax_plist_put
, 3, 3, 0,
2052 doc
: /* Change value in PLIST of PROP to VAL, comparing with `equal'.
2053 PLIST is a property list, which is a list of the form
2054 \(PROP1 VALUE1 PROP2 VALUE2 ...). PROP and VAL are any objects.
2055 If PROP is already a property on the list, its value is set to VAL,
2056 otherwise the new PROP VAL pair is added. The new plist is returned;
2057 use `(setq x (lax-plist-put x prop val))' to be sure to use the new value.
2058 The PLIST is modified by side effects. */)
2061 register Lisp_Object prop
;
2064 register Lisp_Object tail
, prev
;
2065 Lisp_Object newcell
;
2067 for (tail
= plist
; CONSP (tail
) && CONSP (XCDR (tail
));
2068 tail
= XCDR (XCDR (tail
)))
2070 if (! NILP (Fequal (prop
, XCAR (tail
))))
2072 Fsetcar (XCDR (tail
), val
);
2079 newcell
= Fcons (prop
, Fcons (val
, Qnil
));
2083 Fsetcdr (XCDR (prev
), newcell
);
2087 DEFUN ("eql", Feql
, Seql
, 2, 2, 0,
2088 doc
: /* Return t if the two args are the same Lisp object.
2089 Floating-point numbers of equal value are `eql', but they may not be `eq'. */)
2091 Lisp_Object obj1
, obj2
;
2094 return internal_equal (obj1
, obj2
, 0, 0) ? Qt
: Qnil
;
2096 return EQ (obj1
, obj2
) ? Qt
: Qnil
;
2099 DEFUN ("equal", Fequal
, Sequal
, 2, 2, 0,
2100 doc
: /* Return t if two Lisp objects have similar structure and contents.
2101 They must have the same data type.
2102 Conses are compared by comparing the cars and the cdrs.
2103 Vectors and strings are compared element by element.
2104 Numbers are compared by value, but integers cannot equal floats.
2105 (Use `=' if you want integers and floats to be able to be equal.)
2106 Symbols must match exactly. */)
2108 register Lisp_Object o1
, o2
;
2110 return internal_equal (o1
, o2
, 0, 0) ? Qt
: Qnil
;
2113 DEFUN ("equal-including-properties", Fequal_including_properties
, Sequal_including_properties
, 2, 2, 0,
2114 doc
: /* Return t if two Lisp objects have similar structure and contents.
2115 This is like `equal' except that it compares the text properties
2116 of strings. (`equal' ignores text properties.) */)
2118 register Lisp_Object o1
, o2
;
2120 return internal_equal (o1
, o2
, 0, 1) ? Qt
: Qnil
;
2123 /* DEPTH is current depth of recursion. Signal an error if it
2125 PROPS, if non-nil, means compare string text properties too. */
2128 internal_equal (o1
, o2
, depth
, props
)
2129 register Lisp_Object o1
, o2
;
2133 error ("Stack overflow in equal");
2139 if (XTYPE (o1
) != XTYPE (o2
))
2148 d1
= extract_float (o1
);
2149 d2
= extract_float (o2
);
2150 /* If d is a NaN, then d != d. Two NaNs should be `equal' even
2151 though they are not =. */
2152 return d1
== d2
|| (d1
!= d1
&& d2
!= d2
);
2156 if (!internal_equal (XCAR (o1
), XCAR (o2
), depth
+ 1, props
))
2163 if (XMISCTYPE (o1
) != XMISCTYPE (o2
))
2167 if (!internal_equal (OVERLAY_START (o1
), OVERLAY_START (o2
),
2169 || !internal_equal (OVERLAY_END (o1
), OVERLAY_END (o2
),
2172 o1
= XOVERLAY (o1
)->plist
;
2173 o2
= XOVERLAY (o2
)->plist
;
2178 return (XMARKER (o1
)->buffer
== XMARKER (o2
)->buffer
2179 && (XMARKER (o1
)->buffer
== 0
2180 || XMARKER (o1
)->bytepos
== XMARKER (o2
)->bytepos
));
2184 case Lisp_Vectorlike
:
2187 EMACS_INT size
= ASIZE (o1
);
2188 /* Pseudovectors have the type encoded in the size field, so this test
2189 actually checks that the objects have the same type as well as the
2191 if (ASIZE (o2
) != size
)
2193 /* Boolvectors are compared much like strings. */
2194 if (BOOL_VECTOR_P (o1
))
2197 = ((XBOOL_VECTOR (o1
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
2198 / BOOL_VECTOR_BITS_PER_CHAR
);
2200 if (XBOOL_VECTOR (o1
)->size
!= XBOOL_VECTOR (o2
)->size
)
2202 if (bcmp (XBOOL_VECTOR (o1
)->data
, XBOOL_VECTOR (o2
)->data
,
2207 if (WINDOW_CONFIGURATIONP (o1
))
2208 return compare_window_configurations (o1
, o2
, 0);
2210 /* Aside from them, only true vectors, char-tables, and compiled
2211 functions are sensible to compare, so eliminate the others now. */
2212 if (size
& PSEUDOVECTOR_FLAG
)
2214 if (!(size
& (PVEC_COMPILED
2215 | PVEC_CHAR_TABLE
| PVEC_SUB_CHAR_TABLE
)))
2217 size
&= PSEUDOVECTOR_SIZE_MASK
;
2219 for (i
= 0; i
< size
; i
++)
2224 if (!internal_equal (v1
, v2
, depth
+ 1, props
))
2232 if (SCHARS (o1
) != SCHARS (o2
))
2234 if (SBYTES (o1
) != SBYTES (o2
))
2236 if (bcmp (SDATA (o1
), SDATA (o2
),
2239 if (props
&& !compare_string_intervals (o1
, o2
))
2245 case Lisp_Type_Limit
:
2252 extern Lisp_Object
Fmake_char_internal ();
2254 DEFUN ("fillarray", Ffillarray
, Sfillarray
, 2, 2, 0,
2255 doc
: /* Store each element of ARRAY with ITEM.
2256 ARRAY is a vector, string, char-table, or bool-vector. */)
2258 Lisp_Object array
, item
;
2260 register int size
, index
, charval
;
2261 if (VECTORP (array
))
2263 register Lisp_Object
*p
= XVECTOR (array
)->contents
;
2264 size
= ASIZE (array
);
2265 for (index
= 0; index
< size
; index
++)
2268 else if (CHAR_TABLE_P (array
))
2272 for (i
= 0; i
< (1 << CHARTAB_SIZE_BITS_0
); i
++)
2273 XCHAR_TABLE (array
)->contents
[i
] = item
;
2274 XCHAR_TABLE (array
)->defalt
= item
;
2276 else if (STRINGP (array
))
2278 register unsigned char *p
= SDATA (array
);
2279 CHECK_NUMBER (item
);
2280 charval
= XINT (item
);
2281 size
= SCHARS (array
);
2282 if (STRING_MULTIBYTE (array
))
2284 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
2285 int len
= CHAR_STRING (charval
, str
);
2286 int size_byte
= SBYTES (array
);
2287 unsigned char *p1
= p
, *endp
= p
+ size_byte
;
2290 if (size
!= size_byte
)
2293 int this_len
= MULTIBYTE_FORM_LENGTH (p1
, endp
- p1
);
2294 if (len
!= this_len
)
2295 error ("Attempt to change byte length of a string");
2298 for (i
= 0; i
< size_byte
; i
++)
2299 *p
++ = str
[i
% len
];
2302 for (index
= 0; index
< size
; index
++)
2305 else if (BOOL_VECTOR_P (array
))
2307 register unsigned char *p
= XBOOL_VECTOR (array
)->data
;
2309 = ((XBOOL_VECTOR (array
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
2310 / BOOL_VECTOR_BITS_PER_CHAR
);
2312 charval
= (! NILP (item
) ? -1 : 0);
2313 for (index
= 0; index
< size_in_chars
- 1; index
++)
2315 if (index
< size_in_chars
)
2317 /* Mask out bits beyond the vector size. */
2318 if (XBOOL_VECTOR (array
)->size
% BOOL_VECTOR_BITS_PER_CHAR
)
2319 charval
&= (1 << (XBOOL_VECTOR (array
)->size
% BOOL_VECTOR_BITS_PER_CHAR
)) - 1;
2324 wrong_type_argument (Qarrayp
, array
);
2328 DEFUN ("clear-string", Fclear_string
, Sclear_string
,
2330 doc
: /* Clear the contents of STRING.
2331 This makes STRING unibyte and may change its length. */)
2336 CHECK_STRING (string
);
2337 len
= SBYTES (string
);
2338 bzero (SDATA (string
), len
);
2339 STRING_SET_CHARS (string
, len
);
2340 STRING_SET_UNIBYTE (string
);
2350 Lisp_Object args
[2];
2353 return Fnconc (2, args
);
2355 return Fnconc (2, &s1
);
2356 #endif /* NO_ARG_ARRAY */
2359 DEFUN ("nconc", Fnconc
, Snconc
, 0, MANY
, 0,
2360 doc
: /* Concatenate any number of lists by altering them.
2361 Only the last argument is not altered, and need not be a list.
2362 usage: (nconc &rest LISTS) */)
2367 register int argnum
;
2368 register Lisp_Object tail
, tem
, val
;
2372 for (argnum
= 0; argnum
< nargs
; argnum
++)
2375 if (NILP (tem
)) continue;
2380 if (argnum
+ 1 == nargs
) break;
2382 CHECK_LIST_CONS (tem
, tem
);
2391 tem
= args
[argnum
+ 1];
2392 Fsetcdr (tail
, tem
);
2394 args
[argnum
+ 1] = tail
;
2400 /* This is the guts of all mapping functions.
2401 Apply FN to each element of SEQ, one by one,
2402 storing the results into elements of VALS, a C vector of Lisp_Objects.
2403 LENI is the length of VALS, which should also be the length of SEQ. */
2406 mapcar1 (leni
, vals
, fn
, seq
)
2409 Lisp_Object fn
, seq
;
2411 register Lisp_Object tail
;
2414 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2418 /* Don't let vals contain any garbage when GC happens. */
2419 for (i
= 0; i
< leni
; i
++)
2422 GCPRO3 (dummy
, fn
, seq
);
2424 gcpro1
.nvars
= leni
;
2428 /* We need not explicitly protect `tail' because it is used only on lists, and
2429 1) lists are not relocated and 2) the list is marked via `seq' so will not
2434 for (i
= 0; i
< leni
; i
++)
2436 dummy
= call1 (fn
, AREF (seq
, i
));
2441 else if (BOOL_VECTOR_P (seq
))
2443 for (i
= 0; i
< leni
; i
++)
2446 byte
= XBOOL_VECTOR (seq
)->data
[i
/ BOOL_VECTOR_BITS_PER_CHAR
];
2447 dummy
= (byte
& (1 << (i
% BOOL_VECTOR_BITS_PER_CHAR
))) ? Qt
: Qnil
;
2448 dummy
= call1 (fn
, dummy
);
2453 else if (STRINGP (seq
))
2457 for (i
= 0, i_byte
= 0; i
< leni
;)
2462 FETCH_STRING_CHAR_ADVANCE (c
, seq
, i
, i_byte
);
2463 XSETFASTINT (dummy
, c
);
2464 dummy
= call1 (fn
, dummy
);
2466 vals
[i_before
] = dummy
;
2469 else /* Must be a list, since Flength did not get an error */
2472 for (i
= 0; i
< leni
&& CONSP (tail
); i
++)
2474 dummy
= call1 (fn
, XCAR (tail
));
2484 DEFUN ("mapconcat", Fmapconcat
, Smapconcat
, 3, 3, 0,
2485 doc
: /* Apply FUNCTION to each element of SEQUENCE, and concat the results as strings.
2486 In between each pair of results, stick in SEPARATOR. Thus, " " as
2487 SEPARATOR results in spaces between the values returned by FUNCTION.
2488 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2489 (function
, sequence
, separator
)
2490 Lisp_Object function
, sequence
, separator
;
2495 register Lisp_Object
*args
;
2497 struct gcpro gcpro1
;
2501 len
= Flength (sequence
);
2502 if (CHAR_TABLE_P (sequence
))
2503 wrong_type_argument (Qlistp
, sequence
);
2505 nargs
= leni
+ leni
- 1;
2506 if (nargs
< 0) return empty_unibyte_string
;
2508 SAFE_ALLOCA_LISP (args
, nargs
);
2511 mapcar1 (leni
, args
, function
, sequence
);
2514 for (i
= leni
- 1; i
> 0; i
--)
2515 args
[i
+ i
] = args
[i
];
2517 for (i
= 1; i
< nargs
; i
+= 2)
2518 args
[i
] = separator
;
2520 ret
= Fconcat (nargs
, args
);
2526 DEFUN ("mapcar", Fmapcar
, Smapcar
, 2, 2, 0,
2527 doc
: /* Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
2528 The result is a list just as long as SEQUENCE.
2529 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2530 (function
, sequence
)
2531 Lisp_Object function
, sequence
;
2533 register Lisp_Object len
;
2535 register Lisp_Object
*args
;
2539 len
= Flength (sequence
);
2540 if (CHAR_TABLE_P (sequence
))
2541 wrong_type_argument (Qlistp
, sequence
);
2542 leni
= XFASTINT (len
);
2544 SAFE_ALLOCA_LISP (args
, leni
);
2546 mapcar1 (leni
, args
, function
, sequence
);
2548 ret
= Flist (leni
, args
);
2554 DEFUN ("mapc", Fmapc
, Smapc
, 2, 2, 0,
2555 doc
: /* Apply FUNCTION to each element of SEQUENCE for side effects only.
2556 Unlike `mapcar', don't accumulate the results. Return SEQUENCE.
2557 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2558 (function
, sequence
)
2559 Lisp_Object function
, sequence
;
2563 leni
= XFASTINT (Flength (sequence
));
2564 if (CHAR_TABLE_P (sequence
))
2565 wrong_type_argument (Qlistp
, sequence
);
2566 mapcar1 (leni
, 0, function
, sequence
);
2571 /* Anything that calls this function must protect from GC! */
2573 DEFUN ("y-or-n-p", Fy_or_n_p
, Sy_or_n_p
, 1, 1, 0,
2574 doc
: /* Ask user a "y or n" question. Return t if answer is "y".
2575 Takes one argument, which is the string to display to ask the question.
2576 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
2577 No confirmation of the answer is requested; a single character is enough.
2578 Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses
2579 the bindings in `query-replace-map'; see the documentation of that variable
2580 for more information. In this case, the useful bindings are `act', `skip',
2581 `recenter', and `quit'.\)
2583 Under a windowing system a dialog box will be used if `last-nonmenu-event'
2584 is nil and `use-dialog-box' is non-nil. */)
2588 register Lisp_Object obj
, key
, def
, map
;
2589 register int answer
;
2590 Lisp_Object xprompt
;
2591 Lisp_Object args
[2];
2592 struct gcpro gcpro1
, gcpro2
;
2593 int count
= SPECPDL_INDEX ();
2595 specbind (Qcursor_in_echo_area
, Qt
);
2597 map
= Fsymbol_value (intern ("query-replace-map"));
2599 CHECK_STRING (prompt
);
2601 GCPRO2 (prompt
, xprompt
);
2603 #ifdef HAVE_WINDOW_SYSTEM
2604 if (display_hourglass_p
)
2605 cancel_hourglass ();
2612 if (FRAME_WINDOW_P (SELECTED_FRAME ())
2613 && (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
2617 Lisp_Object pane
, menu
;
2618 redisplay_preserve_echo_area (3);
2619 pane
= Fcons (Fcons (build_string ("Yes"), Qt
),
2620 Fcons (Fcons (build_string ("No"), Qnil
),
2622 menu
= Fcons (prompt
, pane
);
2623 obj
= Fx_popup_dialog (Qt
, menu
, Qnil
);
2624 answer
= !NILP (obj
);
2627 #endif /* HAVE_MENUS */
2628 cursor_in_echo_area
= 1;
2629 choose_minibuf_frame ();
2632 Lisp_Object pargs
[3];
2634 /* Colorize prompt according to `minibuffer-prompt' face. */
2635 pargs
[0] = build_string ("%s(y or n) ");
2636 pargs
[1] = intern ("face");
2637 pargs
[2] = intern ("minibuffer-prompt");
2638 args
[0] = Fpropertize (3, pargs
);
2643 if (minibuffer_auto_raise
)
2645 Lisp_Object mini_frame
;
2647 mini_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
2649 Fraise_frame (mini_frame
);
2652 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
2653 obj
= read_filtered_event (1, 0, 0, 0, Qnil
);
2654 cursor_in_echo_area
= 0;
2655 /* If we need to quit, quit with cursor_in_echo_area = 0. */
2658 key
= Fmake_vector (make_number (1), obj
);
2659 def
= Flookup_key (map
, key
, Qt
);
2661 if (EQ (def
, intern ("skip")))
2666 else if (EQ (def
, intern ("act")))
2671 else if (EQ (def
, intern ("recenter")))
2677 else if (EQ (def
, intern ("quit")))
2679 /* We want to exit this command for exit-prefix,
2680 and this is the only way to do it. */
2681 else if (EQ (def
, intern ("exit-prefix")))
2686 /* If we don't clear this, then the next call to read_char will
2687 return quit_char again, and we'll enter an infinite loop. */
2692 if (EQ (xprompt
, prompt
))
2694 args
[0] = build_string ("Please answer y or n. ");
2696 xprompt
= Fconcat (2, args
);
2701 if (! noninteractive
)
2703 cursor_in_echo_area
= -1;
2704 message_with_string (answer
? "%s(y or n) y" : "%s(y or n) n",
2708 unbind_to (count
, Qnil
);
2709 return answer
? Qt
: Qnil
;
2712 /* This is how C code calls `yes-or-no-p' and allows the user
2715 Anything that calls this function must protect from GC! */
2718 do_yes_or_no_p (prompt
)
2721 return call1 (intern ("yes-or-no-p"), prompt
);
2724 /* Anything that calls this function must protect from GC! */
2726 DEFUN ("yes-or-no-p", Fyes_or_no_p
, Syes_or_no_p
, 1, 1, 0,
2727 doc
: /* Ask user a yes-or-no question. Return t if answer is yes.
2728 Takes one argument, which is the string to display to ask the question.
2729 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
2730 The user must confirm the answer with RET,
2731 and can edit it until it has been confirmed.
2733 Under a windowing system a dialog box will be used if `last-nonmenu-event'
2734 is nil, and `use-dialog-box' is non-nil. */)
2738 register Lisp_Object ans
;
2739 Lisp_Object args
[2];
2740 struct gcpro gcpro1
;
2742 CHECK_STRING (prompt
);
2745 if (FRAME_WINDOW_P (SELECTED_FRAME ())
2746 && (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
2750 Lisp_Object pane
, menu
, obj
;
2751 redisplay_preserve_echo_area (4);
2752 pane
= Fcons (Fcons (build_string ("Yes"), Qt
),
2753 Fcons (Fcons (build_string ("No"), Qnil
),
2756 menu
= Fcons (prompt
, pane
);
2757 obj
= Fx_popup_dialog (Qt
, menu
, Qnil
);
2761 #endif /* HAVE_MENUS */
2764 args
[1] = build_string ("(yes or no) ");
2765 prompt
= Fconcat (2, args
);
2771 ans
= Fdowncase (Fread_from_minibuffer (prompt
, Qnil
, Qnil
, Qnil
,
2772 Qyes_or_no_p_history
, Qnil
,
2774 if (SCHARS (ans
) == 3 && !strcmp (SDATA (ans
), "yes"))
2779 if (SCHARS (ans
) == 2 && !strcmp (SDATA (ans
), "no"))
2787 message ("Please answer yes or no.");
2788 Fsleep_for (make_number (2), Qnil
);
2792 DEFUN ("load-average", Fload_average
, Sload_average
, 0, 1, 0,
2793 doc
: /* Return list of 1 minute, 5 minute and 15 minute load averages.
2795 Each of the three load averages is multiplied by 100, then converted
2798 When USE-FLOATS is non-nil, floats will be used instead of integers.
2799 These floats are not multiplied by 100.
2801 If the 5-minute or 15-minute load averages are not available, return a
2802 shortened list, containing only those averages which are available.
2804 An error is thrown if the load average can't be obtained. In some
2805 cases making it work would require Emacs being installed setuid or
2806 setgid so that it can read kernel information, and that usually isn't
2809 Lisp_Object use_floats
;
2812 int loads
= getloadavg (load_ave
, 3);
2813 Lisp_Object ret
= Qnil
;
2816 error ("load-average not implemented for this operating system");
2820 Lisp_Object load
= (NILP (use_floats
) ?
2821 make_number ((int) (100.0 * load_ave
[loads
]))
2822 : make_float (load_ave
[loads
]));
2823 ret
= Fcons (load
, ret
);
2829 Lisp_Object Vfeatures
, Qsubfeatures
;
2830 extern Lisp_Object Vafter_load_alist
;
2832 DEFUN ("featurep", Ffeaturep
, Sfeaturep
, 1, 2, 0,
2833 doc
: /* Returns t if FEATURE is present in this Emacs.
2835 Use this to conditionalize execution of lisp code based on the
2836 presence or absence of Emacs or environment extensions.
2837 Use `provide' to declare that a feature is available. This function
2838 looks at the value of the variable `features'. The optional argument
2839 SUBFEATURE can be used to check a specific subfeature of FEATURE. */)
2840 (feature
, subfeature
)
2841 Lisp_Object feature
, subfeature
;
2843 register Lisp_Object tem
;
2844 CHECK_SYMBOL (feature
);
2845 tem
= Fmemq (feature
, Vfeatures
);
2846 if (!NILP (tem
) && !NILP (subfeature
))
2847 tem
= Fmember (subfeature
, Fget (feature
, Qsubfeatures
));
2848 return (NILP (tem
)) ? Qnil
: Qt
;
2851 DEFUN ("provide", Fprovide
, Sprovide
, 1, 2, 0,
2852 doc
: /* Announce that FEATURE is a feature of the current Emacs.
2853 The optional argument SUBFEATURES should be a list of symbols listing
2854 particular subfeatures supported in this version of FEATURE. */)
2855 (feature
, subfeatures
)
2856 Lisp_Object feature
, subfeatures
;
2858 register Lisp_Object tem
;
2859 CHECK_SYMBOL (feature
);
2860 CHECK_LIST (subfeatures
);
2861 if (!NILP (Vautoload_queue
))
2862 Vautoload_queue
= Fcons (Fcons (make_number (0), Vfeatures
),
2864 tem
= Fmemq (feature
, Vfeatures
);
2866 Vfeatures
= Fcons (feature
, Vfeatures
);
2867 if (!NILP (subfeatures
))
2868 Fput (feature
, Qsubfeatures
, subfeatures
);
2869 LOADHIST_ATTACH (Fcons (Qprovide
, feature
));
2871 /* Run any load-hooks for this file. */
2872 tem
= Fassq (feature
, Vafter_load_alist
);
2874 Fprogn (XCDR (tem
));
2879 /* `require' and its subroutines. */
2881 /* List of features currently being require'd, innermost first. */
2883 Lisp_Object require_nesting_list
;
2886 require_unwind (old_value
)
2887 Lisp_Object old_value
;
2889 return require_nesting_list
= old_value
;
2892 DEFUN ("require", Frequire
, Srequire
, 1, 3, 0,
2893 doc
: /* If feature FEATURE is not loaded, load it from FILENAME.
2894 If FEATURE is not a member of the list `features', then the feature
2895 is not loaded; so load the file FILENAME.
2896 If FILENAME is omitted, the printname of FEATURE is used as the file name,
2897 and `load' will try to load this name appended with the suffix `.elc' or
2898 `.el', in that order. The name without appended suffix will not be used.
2899 If the optional third argument NOERROR is non-nil,
2900 then return nil if the file is not found instead of signaling an error.
2901 Normally the return value is FEATURE.
2902 The normal messages at start and end of loading FILENAME are suppressed. */)
2903 (feature
, filename
, noerror
)
2904 Lisp_Object feature
, filename
, noerror
;
2906 register Lisp_Object tem
;
2907 struct gcpro gcpro1
, gcpro2
;
2908 int from_file
= load_in_progress
;
2910 CHECK_SYMBOL (feature
);
2912 /* Record the presence of `require' in this file
2913 even if the feature specified is already loaded.
2914 But not more than once in any file,
2915 and not when we aren't loading or reading from a file. */
2917 for (tem
= Vcurrent_load_list
; CONSP (tem
); tem
= XCDR (tem
))
2918 if (NILP (XCDR (tem
)) && STRINGP (XCAR (tem
)))
2923 tem
= Fcons (Qrequire
, feature
);
2924 if (NILP (Fmember (tem
, Vcurrent_load_list
)))
2925 LOADHIST_ATTACH (tem
);
2927 tem
= Fmemq (feature
, Vfeatures
);
2931 int count
= SPECPDL_INDEX ();
2934 /* This is to make sure that loadup.el gives a clear picture
2935 of what files are preloaded and when. */
2936 if (! NILP (Vpurify_flag
))
2937 error ("(require %s) while preparing to dump",
2938 SDATA (SYMBOL_NAME (feature
)));
2940 /* A certain amount of recursive `require' is legitimate,
2941 but if we require the same feature recursively 3 times,
2943 tem
= require_nesting_list
;
2944 while (! NILP (tem
))
2946 if (! NILP (Fequal (feature
, XCAR (tem
))))
2951 error ("Recursive `require' for feature `%s'",
2952 SDATA (SYMBOL_NAME (feature
)));
2954 /* Update the list for any nested `require's that occur. */
2955 record_unwind_protect (require_unwind
, require_nesting_list
);
2956 require_nesting_list
= Fcons (feature
, require_nesting_list
);
2958 /* Value saved here is to be restored into Vautoload_queue */
2959 record_unwind_protect (un_autoload
, Vautoload_queue
);
2960 Vautoload_queue
= Qt
;
2962 /* Load the file. */
2963 GCPRO2 (feature
, filename
);
2964 tem
= Fload (NILP (filename
) ? Fsymbol_name (feature
) : filename
,
2965 noerror
, Qt
, Qnil
, (NILP (filename
) ? Qt
: Qnil
));
2968 /* If load failed entirely, return nil. */
2970 return unbind_to (count
, Qnil
);
2972 tem
= Fmemq (feature
, Vfeatures
);
2974 error ("Required feature `%s' was not provided",
2975 SDATA (SYMBOL_NAME (feature
)));
2977 /* Once loading finishes, don't undo it. */
2978 Vautoload_queue
= Qt
;
2979 feature
= unbind_to (count
, feature
);
2985 /* Primitives for work of the "widget" library.
2986 In an ideal world, this section would not have been necessary.
2987 However, lisp function calls being as slow as they are, it turns
2988 out that some functions in the widget library (wid-edit.el) are the
2989 bottleneck of Widget operation. Here is their translation to C,
2990 for the sole reason of efficiency. */
2992 DEFUN ("plist-member", Fplist_member
, Splist_member
, 2, 2, 0,
2993 doc
: /* Return non-nil if PLIST has the property PROP.
2994 PLIST is a property list, which is a list of the form
2995 \(PROP1 VALUE1 PROP2 VALUE2 ...\). PROP is a symbol.
2996 Unlike `plist-get', this allows you to distinguish between a missing
2997 property and a property with the value nil.
2998 The value is actually the tail of PLIST whose car is PROP. */)
3000 Lisp_Object plist
, prop
;
3002 while (CONSP (plist
) && !EQ (XCAR (plist
), prop
))
3005 plist
= XCDR (plist
);
3006 plist
= CDR (plist
);
3011 DEFUN ("widget-put", Fwidget_put
, Swidget_put
, 3, 3, 0,
3012 doc
: /* In WIDGET, set PROPERTY to VALUE.
3013 The value can later be retrieved with `widget-get'. */)
3014 (widget
, property
, value
)
3015 Lisp_Object widget
, property
, value
;
3017 CHECK_CONS (widget
);
3018 XSETCDR (widget
, Fplist_put (XCDR (widget
), property
, value
));
3022 DEFUN ("widget-get", Fwidget_get
, Swidget_get
, 2, 2, 0,
3023 doc
: /* In WIDGET, get the value of PROPERTY.
3024 The value could either be specified when the widget was created, or
3025 later with `widget-put'. */)
3027 Lisp_Object widget
, property
;
3035 CHECK_CONS (widget
);
3036 tmp
= Fplist_member (XCDR (widget
), property
);
3042 tmp
= XCAR (widget
);
3045 widget
= Fget (tmp
, Qwidget_type
);
3049 DEFUN ("widget-apply", Fwidget_apply
, Swidget_apply
, 2, MANY
, 0,
3050 doc
: /* Apply the value of WIDGET's PROPERTY to the widget itself.
3051 ARGS are passed as extra arguments to the function.
3052 usage: (widget-apply WIDGET PROPERTY &rest ARGS) */)
3057 /* This function can GC. */
3058 Lisp_Object newargs
[3];
3059 struct gcpro gcpro1
, gcpro2
;
3062 newargs
[0] = Fwidget_get (args
[0], args
[1]);
3063 newargs
[1] = args
[0];
3064 newargs
[2] = Flist (nargs
- 2, args
+ 2);
3065 GCPRO2 (newargs
[0], newargs
[2]);
3066 result
= Fapply (3, newargs
);
3071 #ifdef HAVE_LANGINFO_CODESET
3072 #include <langinfo.h>
3075 DEFUN ("locale-info", Flocale_info
, Slocale_info
, 1, 1, 0,
3076 doc
: /* Access locale data ITEM for the current C locale, if available.
3077 ITEM should be one of the following:
3079 `codeset', returning the character set as a string (locale item CODESET);
3081 `days', returning a 7-element vector of day names (locale items DAY_n);
3083 `months', returning a 12-element vector of month names (locale items MON_n);
3085 `paper', returning a list (WIDTH HEIGHT) for the default paper size,
3086 both measured in milimeters (locale items PAPER_WIDTH, PAPER_HEIGHT).
3088 If the system can't provide such information through a call to
3089 `nl_langinfo', or if ITEM isn't from the list above, return nil.
3091 See also Info node `(libc)Locales'.
3093 The data read from the system are decoded using `locale-coding-system'. */)
3098 #ifdef HAVE_LANGINFO_CODESET
3100 if (EQ (item
, Qcodeset
))
3102 str
= nl_langinfo (CODESET
);
3103 return build_string (str
);
3106 else if (EQ (item
, Qdays
)) /* e.g. for calendar-day-name-array */
3108 Lisp_Object v
= Fmake_vector (make_number (7), Qnil
);
3109 int days
[7] = {DAY_1
, DAY_2
, DAY_3
, DAY_4
, DAY_5
, DAY_6
, DAY_7
};
3111 synchronize_system_time_locale ();
3112 for (i
= 0; i
< 7; i
++)
3114 str
= nl_langinfo (days
[i
]);
3115 val
= make_unibyte_string (str
, strlen (str
));
3116 /* Fixme: Is this coding system necessarily right, even if
3117 it is consistent with CODESET? If not, what to do? */
3118 Faset (v
, make_number (i
),
3119 code_convert_string_norecord (val
, Vlocale_coding_system
,
3126 else if (EQ (item
, Qmonths
)) /* e.g. for calendar-month-name-array */
3128 struct Lisp_Vector
*p
= allocate_vector (12);
3129 int months
[12] = {MON_1
, MON_2
, MON_3
, MON_4
, MON_5
, MON_6
, MON_7
,
3130 MON_8
, MON_9
, MON_10
, MON_11
, MON_12
};
3132 synchronize_system_time_locale ();
3133 for (i
= 0; i
< 12; i
++)
3135 str
= nl_langinfo (months
[i
]);
3136 val
= make_unibyte_string (str
, strlen (str
));
3138 code_convert_string_norecord (val
, Vlocale_coding_system
, 0);
3140 XSETVECTOR (val
, p
);
3144 /* LC_PAPER stuff isn't defined as accessible in glibc as of 2.3.1,
3145 but is in the locale files. This could be used by ps-print. */
3147 else if (EQ (item
, Qpaper
))
3149 return list2 (make_number (nl_langinfo (PAPER_WIDTH
)),
3150 make_number (nl_langinfo (PAPER_HEIGHT
)));
3152 #endif /* PAPER_WIDTH */
3153 #endif /* HAVE_LANGINFO_CODESET*/
3157 /* base64 encode/decode functions (RFC 2045).
3158 Based on code from GNU recode. */
3160 #define MIME_LINE_LENGTH 76
3162 #define IS_ASCII(Character) \
3164 #define IS_BASE64(Character) \
3165 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0)
3166 #define IS_BASE64_IGNORABLE(Character) \
3167 ((Character) == ' ' || (Character) == '\t' || (Character) == '\n' \
3168 || (Character) == '\f' || (Character) == '\r')
3170 /* Used by base64_decode_1 to retrieve a non-base64-ignorable
3171 character or return retval if there are no characters left to
3173 #define READ_QUADRUPLET_BYTE(retval) \
3178 if (nchars_return) \
3179 *nchars_return = nchars; \
3184 while (IS_BASE64_IGNORABLE (c))
3186 /* Table of characters coding the 64 values. */
3187 static char base64_value_to_char
[64] =
3189 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */
3190 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */
3191 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */
3192 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */
3193 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */
3194 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */
3195 '8', '9', '+', '/' /* 60-63 */
3198 /* Table of base64 values for first 128 characters. */
3199 static short base64_char_to_value
[128] =
3201 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */
3202 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */
3203 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */
3204 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */
3205 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */
3206 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */
3207 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */
3208 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */
3209 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */
3210 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */
3211 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */
3212 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */
3213 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */
3216 /* The following diagram shows the logical steps by which three octets
3217 get transformed into four base64 characters.
3219 .--------. .--------. .--------.
3220 |aaaaaabb| |bbbbcccc| |ccdddddd|
3221 `--------' `--------' `--------'
3223 .--------+--------+--------+--------.
3224 |00aaaaaa|00bbbbbb|00cccccc|00dddddd|
3225 `--------+--------+--------+--------'
3227 .--------+--------+--------+--------.
3228 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD|
3229 `--------+--------+--------+--------'
3231 The octets are divided into 6 bit chunks, which are then encoded into
3232 base64 characters. */
3235 static int base64_encode_1
P_ ((const char *, char *, int, int, int));
3236 static int base64_decode_1
P_ ((const char *, char *, int, int, int *));
3238 DEFUN ("base64-encode-region", Fbase64_encode_region
, Sbase64_encode_region
,
3240 doc
: /* Base64-encode the region between BEG and END.
3241 Return the length of the encoded text.
3242 Optional third argument NO-LINE-BREAK means do not break long lines
3243 into shorter lines. */)
3244 (beg
, end
, no_line_break
)
3245 Lisp_Object beg
, end
, no_line_break
;
3248 int allength
, length
;
3249 int ibeg
, iend
, encoded_length
;
3253 validate_region (&beg
, &end
);
3255 ibeg
= CHAR_TO_BYTE (XFASTINT (beg
));
3256 iend
= CHAR_TO_BYTE (XFASTINT (end
));
3257 move_gap_both (XFASTINT (beg
), ibeg
);
3259 /* We need to allocate enough room for encoding the text.
3260 We need 33 1/3% more space, plus a newline every 76
3261 characters, and then we round up. */
3262 length
= iend
- ibeg
;
3263 allength
= length
+ length
/3 + 1;
3264 allength
+= allength
/ MIME_LINE_LENGTH
+ 1 + 6;
3266 SAFE_ALLOCA (encoded
, char *, allength
);
3267 encoded_length
= base64_encode_1 (BYTE_POS_ADDR (ibeg
), encoded
, length
,
3268 NILP (no_line_break
),
3269 !NILP (current_buffer
->enable_multibyte_characters
));
3270 if (encoded_length
> allength
)
3273 if (encoded_length
< 0)
3275 /* The encoding wasn't possible. */
3277 error ("Multibyte character in data for base64 encoding");
3280 /* Now we have encoded the region, so we insert the new contents
3281 and delete the old. (Insert first in order to preserve markers.) */
3282 SET_PT_BOTH (XFASTINT (beg
), ibeg
);
3283 insert (encoded
, encoded_length
);
3285 del_range_byte (ibeg
+ encoded_length
, iend
+ encoded_length
, 1);
3287 /* If point was outside of the region, restore it exactly; else just
3288 move to the beginning of the region. */
3289 if (old_pos
>= XFASTINT (end
))
3290 old_pos
+= encoded_length
- (XFASTINT (end
) - XFASTINT (beg
));
3291 else if (old_pos
> XFASTINT (beg
))
3292 old_pos
= XFASTINT (beg
);
3295 /* We return the length of the encoded text. */
3296 return make_number (encoded_length
);
3299 DEFUN ("base64-encode-string", Fbase64_encode_string
, Sbase64_encode_string
,
3301 doc
: /* Base64-encode STRING and return the result.
3302 Optional second argument NO-LINE-BREAK means do not break long lines
3303 into shorter lines. */)
3304 (string
, no_line_break
)
3305 Lisp_Object string
, no_line_break
;
3307 int allength
, length
, encoded_length
;
3309 Lisp_Object encoded_string
;
3312 CHECK_STRING (string
);
3314 /* We need to allocate enough room for encoding the text.
3315 We need 33 1/3% more space, plus a newline every 76
3316 characters, and then we round up. */
3317 length
= SBYTES (string
);
3318 allength
= length
+ length
/3 + 1;
3319 allength
+= allength
/ MIME_LINE_LENGTH
+ 1 + 6;
3321 /* We need to allocate enough room for decoding the text. */
3322 SAFE_ALLOCA (encoded
, char *, allength
);
3324 encoded_length
= base64_encode_1 (SDATA (string
),
3325 encoded
, length
, NILP (no_line_break
),
3326 STRING_MULTIBYTE (string
));
3327 if (encoded_length
> allength
)
3330 if (encoded_length
< 0)
3332 /* The encoding wasn't possible. */
3334 error ("Multibyte character in data for base64 encoding");
3337 encoded_string
= make_unibyte_string (encoded
, encoded_length
);
3340 return encoded_string
;
3344 base64_encode_1 (from
, to
, length
, line_break
, multibyte
)
3351 int counter
= 0, i
= 0;
3361 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
3362 if (CHAR_BYTE8_P (c
))
3363 c
= CHAR_TO_BYTE8 (c
);
3371 /* Wrap line every 76 characters. */
3375 if (counter
< MIME_LINE_LENGTH
/ 4)
3384 /* Process first byte of a triplet. */
3386 *e
++ = base64_value_to_char
[0x3f & c
>> 2];
3387 value
= (0x03 & c
) << 4;
3389 /* Process second byte of a triplet. */
3393 *e
++ = base64_value_to_char
[value
];
3401 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
3402 if (CHAR_BYTE8_P (c
))
3403 c
= CHAR_TO_BYTE8 (c
);
3411 *e
++ = base64_value_to_char
[value
| (0x0f & c
>> 4)];
3412 value
= (0x0f & c
) << 2;
3414 /* Process third byte of a triplet. */
3418 *e
++ = base64_value_to_char
[value
];
3425 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
3426 if (CHAR_BYTE8_P (c
))
3427 c
= CHAR_TO_BYTE8 (c
);
3435 *e
++ = base64_value_to_char
[value
| (0x03 & c
>> 6)];
3436 *e
++ = base64_value_to_char
[0x3f & c
];
3443 DEFUN ("base64-decode-region", Fbase64_decode_region
, Sbase64_decode_region
,
3445 doc
: /* Base64-decode the region between BEG and END.
3446 Return the length of the decoded text.
3447 If the region can't be decoded, signal an error and don't modify the buffer. */)
3449 Lisp_Object beg
, end
;
3451 int ibeg
, iend
, length
, allength
;
3456 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3459 validate_region (&beg
, &end
);
3461 ibeg
= CHAR_TO_BYTE (XFASTINT (beg
));
3462 iend
= CHAR_TO_BYTE (XFASTINT (end
));
3464 length
= iend
- ibeg
;
3466 /* We need to allocate enough room for decoding the text. If we are
3467 working on a multibyte buffer, each decoded code may occupy at
3469 allength
= multibyte
? length
* 2 : length
;
3470 SAFE_ALLOCA (decoded
, char *, allength
);
3472 move_gap_both (XFASTINT (beg
), ibeg
);
3473 decoded_length
= base64_decode_1 (BYTE_POS_ADDR (ibeg
), decoded
, length
,
3474 multibyte
, &inserted_chars
);
3475 if (decoded_length
> allength
)
3478 if (decoded_length
< 0)
3480 /* The decoding wasn't possible. */
3482 error ("Invalid base64 data");
3485 /* Now we have decoded the region, so we insert the new contents
3486 and delete the old. (Insert first in order to preserve markers.) */
3487 TEMP_SET_PT_BOTH (XFASTINT (beg
), ibeg
);
3488 insert_1_both (decoded
, inserted_chars
, decoded_length
, 0, 1, 0);
3491 /* Delete the original text. */
3492 del_range_both (PT
, PT_BYTE
, XFASTINT (end
) + inserted_chars
,
3493 iend
+ decoded_length
, 1);
3495 /* If point was outside of the region, restore it exactly; else just
3496 move to the beginning of the region. */
3497 if (old_pos
>= XFASTINT (end
))
3498 old_pos
+= inserted_chars
- (XFASTINT (end
) - XFASTINT (beg
));
3499 else if (old_pos
> XFASTINT (beg
))
3500 old_pos
= XFASTINT (beg
);
3501 SET_PT (old_pos
> ZV
? ZV
: old_pos
);
3503 return make_number (inserted_chars
);
3506 DEFUN ("base64-decode-string", Fbase64_decode_string
, Sbase64_decode_string
,
3508 doc
: /* Base64-decode STRING and return the result. */)
3513 int length
, decoded_length
;
3514 Lisp_Object decoded_string
;
3517 CHECK_STRING (string
);
3519 length
= SBYTES (string
);
3520 /* We need to allocate enough room for decoding the text. */
3521 SAFE_ALLOCA (decoded
, char *, length
);
3523 /* The decoded result should be unibyte. */
3524 decoded_length
= base64_decode_1 (SDATA (string
), decoded
, length
,
3526 if (decoded_length
> length
)
3528 else if (decoded_length
>= 0)
3529 decoded_string
= make_unibyte_string (decoded
, decoded_length
);
3531 decoded_string
= Qnil
;
3534 if (!STRINGP (decoded_string
))
3535 error ("Invalid base64 data");
3537 return decoded_string
;
3540 /* Base64-decode the data at FROM of LENGHT bytes into TO. If
3541 MULTIBYTE is nonzero, the decoded result should be in multibyte
3542 form. If NCHARS_RETRUN is not NULL, store the number of produced
3543 characters in *NCHARS_RETURN. */
3546 base64_decode_1 (from
, to
, length
, multibyte
, nchars_return
)
3556 unsigned long value
;
3561 /* Process first byte of a quadruplet. */
3563 READ_QUADRUPLET_BYTE (e
-to
);
3567 value
= base64_char_to_value
[c
] << 18;
3569 /* Process second byte of a quadruplet. */
3571 READ_QUADRUPLET_BYTE (-1);
3575 value
|= base64_char_to_value
[c
] << 12;
3577 c
= (unsigned char) (value
>> 16);
3578 if (multibyte
&& c
>= 128)
3579 e
+= BYTE8_STRING (c
, e
);
3584 /* Process third byte of a quadruplet. */
3586 READ_QUADRUPLET_BYTE (-1);
3590 READ_QUADRUPLET_BYTE (-1);
3599 value
|= base64_char_to_value
[c
] << 6;
3601 c
= (unsigned char) (0xff & value
>> 8);
3602 if (multibyte
&& c
>= 128)
3603 e
+= BYTE8_STRING (c
, e
);
3608 /* Process fourth byte of a quadruplet. */
3610 READ_QUADRUPLET_BYTE (-1);
3617 value
|= base64_char_to_value
[c
];
3619 c
= (unsigned char) (0xff & value
);
3620 if (multibyte
&& c
>= 128)
3621 e
+= BYTE8_STRING (c
, e
);
3630 /***********************************************************************
3632 ***** Hash Tables *****
3634 ***********************************************************************/
3636 /* Implemented by gerd@gnu.org. This hash table implementation was
3637 inspired by CMUCL hash tables. */
3641 1. For small tables, association lists are probably faster than
3642 hash tables because they have lower overhead.
3644 For uses of hash tables where the O(1) behavior of table
3645 operations is not a requirement, it might therefore be a good idea
3646 not to hash. Instead, we could just do a linear search in the
3647 key_and_value vector of the hash table. This could be done
3648 if a `:linear-search t' argument is given to make-hash-table. */
3651 /* The list of all weak hash tables. Don't staticpro this one. */
3653 struct Lisp_Hash_Table
*weak_hash_tables
;
3655 /* Various symbols. */
3657 Lisp_Object Qhash_table_p
, Qeq
, Qeql
, Qequal
, Qkey
, Qvalue
;
3658 Lisp_Object QCtest
, QCsize
, QCrehash_size
, QCrehash_threshold
, QCweakness
;
3659 Lisp_Object Qhash_table_test
, Qkey_or_value
, Qkey_and_value
;
3661 /* Function prototypes. */
3663 static struct Lisp_Hash_Table
*check_hash_table
P_ ((Lisp_Object
));
3664 static int get_key_arg
P_ ((Lisp_Object
, int, Lisp_Object
*, char *));
3665 static void maybe_resize_hash_table
P_ ((struct Lisp_Hash_Table
*));
3666 static int cmpfn_eql
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
, unsigned,
3667 Lisp_Object
, unsigned));
3668 static int cmpfn_equal
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
, unsigned,
3669 Lisp_Object
, unsigned));
3670 static int cmpfn_user_defined
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
,
3671 unsigned, Lisp_Object
, unsigned));
3672 static unsigned hashfn_eq
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
3673 static unsigned hashfn_eql
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
3674 static unsigned hashfn_equal
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
3675 static unsigned hashfn_user_defined
P_ ((struct Lisp_Hash_Table
*,
3677 static unsigned sxhash_string
P_ ((unsigned char *, int));
3678 static unsigned sxhash_list
P_ ((Lisp_Object
, int));
3679 static unsigned sxhash_vector
P_ ((Lisp_Object
, int));
3680 static unsigned sxhash_bool_vector
P_ ((Lisp_Object
));
3681 static int sweep_weak_table
P_ ((struct Lisp_Hash_Table
*, int));
3685 /***********************************************************************
3687 ***********************************************************************/
3689 /* If OBJ is a Lisp hash table, return a pointer to its struct
3690 Lisp_Hash_Table. Otherwise, signal an error. */
3692 static struct Lisp_Hash_Table
*
3693 check_hash_table (obj
)
3696 CHECK_HASH_TABLE (obj
);
3697 return XHASH_TABLE (obj
);
3701 /* Value is the next integer I >= N, N >= 0 which is "almost" a prime
3705 next_almost_prime (n
)
3718 /* Find KEY in ARGS which has size NARGS. Don't consider indices for
3719 which USED[I] is non-zero. If found at index I in ARGS, set
3720 USED[I] and USED[I + 1] to 1, and return I + 1. Otherwise return
3721 -1. This function is used to extract a keyword/argument pair from
3722 a DEFUN parameter list. */
3725 get_key_arg (key
, nargs
, args
, used
)
3733 for (i
= 0; i
< nargs
- 1; ++i
)
3734 if (!used
[i
] && EQ (args
[i
], key
))
3749 /* Return a Lisp vector which has the same contents as VEC but has
3750 size NEW_SIZE, NEW_SIZE >= VEC->size. Entries in the resulting
3751 vector that are not copied from VEC are set to INIT. */
3754 larger_vector (vec
, new_size
, init
)
3759 struct Lisp_Vector
*v
;
3762 xassert (VECTORP (vec
));
3763 old_size
= ASIZE (vec
);
3764 xassert (new_size
>= old_size
);
3766 v
= allocate_vector (new_size
);
3767 bcopy (XVECTOR (vec
)->contents
, v
->contents
,
3768 old_size
* sizeof *v
->contents
);
3769 for (i
= old_size
; i
< new_size
; ++i
)
3770 v
->contents
[i
] = init
;
3771 XSETVECTOR (vec
, v
);
3776 /***********************************************************************
3778 ***********************************************************************/
3780 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
3781 HASH2 in hash table H using `eql'. Value is non-zero if KEY1 and
3782 KEY2 are the same. */
3785 cmpfn_eql (h
, key1
, hash1
, key2
, hash2
)
3786 struct Lisp_Hash_Table
*h
;
3787 Lisp_Object key1
, key2
;
3788 unsigned hash1
, hash2
;
3790 return (FLOATP (key1
)
3792 && XFLOAT_DATA (key1
) == XFLOAT_DATA (key2
));
3796 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
3797 HASH2 in hash table H using `equal'. Value is non-zero if KEY1 and
3798 KEY2 are the same. */
3801 cmpfn_equal (h
, key1
, hash1
, key2
, hash2
)
3802 struct Lisp_Hash_Table
*h
;
3803 Lisp_Object key1
, key2
;
3804 unsigned hash1
, hash2
;
3806 return hash1
== hash2
&& !NILP (Fequal (key1
, key2
));
3810 /* Compare KEY1 which has hash code HASH1, and KEY2 with hash code
3811 HASH2 in hash table H using H->user_cmp_function. Value is non-zero
3812 if KEY1 and KEY2 are the same. */
3815 cmpfn_user_defined (h
, key1
, hash1
, key2
, hash2
)
3816 struct Lisp_Hash_Table
*h
;
3817 Lisp_Object key1
, key2
;
3818 unsigned hash1
, hash2
;
3822 Lisp_Object args
[3];
3824 args
[0] = h
->user_cmp_function
;
3827 return !NILP (Ffuncall (3, args
));
3834 /* Value is a hash code for KEY for use in hash table H which uses
3835 `eq' to compare keys. The hash code returned is guaranteed to fit
3836 in a Lisp integer. */
3840 struct Lisp_Hash_Table
*h
;
3843 unsigned hash
= XUINT (key
) ^ XTYPE (key
);
3844 xassert ((hash
& ~INTMASK
) == 0);
3849 /* Value is a hash code for KEY for use in hash table H which uses
3850 `eql' to compare keys. The hash code returned is guaranteed to fit
3851 in a Lisp integer. */
3855 struct Lisp_Hash_Table
*h
;
3860 hash
= sxhash (key
, 0);
3862 hash
= XUINT (key
) ^ XTYPE (key
);
3863 xassert ((hash
& ~INTMASK
) == 0);
3868 /* Value is a hash code for KEY for use in hash table H which uses
3869 `equal' to compare keys. The hash code returned is guaranteed to fit
3870 in a Lisp integer. */
3873 hashfn_equal (h
, key
)
3874 struct Lisp_Hash_Table
*h
;
3877 unsigned hash
= sxhash (key
, 0);
3878 xassert ((hash
& ~INTMASK
) == 0);
3883 /* Value is a hash code for KEY for use in hash table H which uses as
3884 user-defined function to compare keys. The hash code returned is
3885 guaranteed to fit in a Lisp integer. */
3888 hashfn_user_defined (h
, key
)
3889 struct Lisp_Hash_Table
*h
;
3892 Lisp_Object args
[2], hash
;
3894 args
[0] = h
->user_hash_function
;
3896 hash
= Ffuncall (2, args
);
3897 if (!INTEGERP (hash
))
3898 signal_error ("Invalid hash code returned from user-supplied hash function", hash
);
3899 return XUINT (hash
);
3903 /* Create and initialize a new hash table.
3905 TEST specifies the test the hash table will use to compare keys.
3906 It must be either one of the predefined tests `eq', `eql' or
3907 `equal' or a symbol denoting a user-defined test named TEST with
3908 test and hash functions USER_TEST and USER_HASH.
3910 Give the table initial capacity SIZE, SIZE >= 0, an integer.
3912 If REHASH_SIZE is an integer, it must be > 0, and this hash table's
3913 new size when it becomes full is computed by adding REHASH_SIZE to
3914 its old size. If REHASH_SIZE is a float, it must be > 1.0, and the
3915 table's new size is computed by multiplying its old size with
3918 REHASH_THRESHOLD must be a float <= 1.0, and > 0. The table will
3919 be resized when the ratio of (number of entries in the table) /
3920 (table size) is >= REHASH_THRESHOLD.
3922 WEAK specifies the weakness of the table. If non-nil, it must be
3923 one of the symbols `key', `value', `key-or-value', or `key-and-value'. */
3926 make_hash_table (test
, size
, rehash_size
, rehash_threshold
, weak
,
3927 user_test
, user_hash
)
3928 Lisp_Object test
, size
, rehash_size
, rehash_threshold
, weak
;
3929 Lisp_Object user_test
, user_hash
;
3931 struct Lisp_Hash_Table
*h
;
3933 int index_size
, i
, sz
;
3935 /* Preconditions. */
3936 xassert (SYMBOLP (test
));
3937 xassert (INTEGERP (size
) && XINT (size
) >= 0);
3938 xassert ((INTEGERP (rehash_size
) && XINT (rehash_size
) > 0)
3939 || (FLOATP (rehash_size
) && XFLOATINT (rehash_size
) > 1.0));
3940 xassert (FLOATP (rehash_threshold
)
3941 && XFLOATINT (rehash_threshold
) > 0
3942 && XFLOATINT (rehash_threshold
) <= 1.0);
3944 if (XFASTINT (size
) == 0)
3945 size
= make_number (1);
3947 /* Allocate a table and initialize it. */
3948 h
= allocate_hash_table ();
3950 /* Initialize hash table slots. */
3951 sz
= XFASTINT (size
);
3954 if (EQ (test
, Qeql
))
3956 h
->cmpfn
= cmpfn_eql
;
3957 h
->hashfn
= hashfn_eql
;
3959 else if (EQ (test
, Qeq
))
3962 h
->hashfn
= hashfn_eq
;
3964 else if (EQ (test
, Qequal
))
3966 h
->cmpfn
= cmpfn_equal
;
3967 h
->hashfn
= hashfn_equal
;
3971 h
->user_cmp_function
= user_test
;
3972 h
->user_hash_function
= user_hash
;
3973 h
->cmpfn
= cmpfn_user_defined
;
3974 h
->hashfn
= hashfn_user_defined
;
3978 h
->rehash_threshold
= rehash_threshold
;
3979 h
->rehash_size
= rehash_size
;
3981 h
->key_and_value
= Fmake_vector (make_number (2 * sz
), Qnil
);
3982 h
->hash
= Fmake_vector (size
, Qnil
);
3983 h
->next
= Fmake_vector (size
, Qnil
);
3984 /* Cast to int here avoids losing with gcc 2.95 on Tru64/Alpha... */
3985 index_size
= next_almost_prime ((int) (sz
/ XFLOATINT (rehash_threshold
)));
3986 h
->index
= Fmake_vector (make_number (index_size
), Qnil
);
3988 /* Set up the free list. */
3989 for (i
= 0; i
< sz
- 1; ++i
)
3990 HASH_NEXT (h
, i
) = make_number (i
+ 1);
3991 h
->next_free
= make_number (0);
3993 XSET_HASH_TABLE (table
, h
);
3994 xassert (HASH_TABLE_P (table
));
3995 xassert (XHASH_TABLE (table
) == h
);
3997 /* Maybe add this hash table to the list of all weak hash tables. */
3999 h
->next_weak
= NULL
;
4002 h
->next_weak
= weak_hash_tables
;
4003 weak_hash_tables
= h
;
4010 /* Return a copy of hash table H1. Keys and values are not copied,
4011 only the table itself is. */
4014 copy_hash_table (h1
)
4015 struct Lisp_Hash_Table
*h1
;
4018 struct Lisp_Hash_Table
*h2
;
4019 struct Lisp_Vector
*next
;
4021 h2
= allocate_hash_table ();
4022 next
= h2
->vec_next
;
4023 bcopy (h1
, h2
, sizeof *h2
);
4024 h2
->vec_next
= next
;
4025 h2
->key_and_value
= Fcopy_sequence (h1
->key_and_value
);
4026 h2
->hash
= Fcopy_sequence (h1
->hash
);
4027 h2
->next
= Fcopy_sequence (h1
->next
);
4028 h2
->index
= Fcopy_sequence (h1
->index
);
4029 XSET_HASH_TABLE (table
, h2
);
4031 /* Maybe add this hash table to the list of all weak hash tables. */
4032 if (!NILP (h2
->weak
))
4034 h2
->next_weak
= weak_hash_tables
;
4035 weak_hash_tables
= h2
;
4042 /* Resize hash table H if it's too full. If H cannot be resized
4043 because it's already too large, throw an error. */
4046 maybe_resize_hash_table (h
)
4047 struct Lisp_Hash_Table
*h
;
4049 if (NILP (h
->next_free
))
4051 int old_size
= HASH_TABLE_SIZE (h
);
4052 int i
, new_size
, index_size
;
4055 if (INTEGERP (h
->rehash_size
))
4056 new_size
= old_size
+ XFASTINT (h
->rehash_size
);
4058 new_size
= old_size
* XFLOATINT (h
->rehash_size
);
4059 new_size
= max (old_size
+ 1, new_size
);
4060 index_size
= next_almost_prime ((int)
4062 / XFLOATINT (h
->rehash_threshold
)));
4063 /* Assignment to EMACS_INT stops GCC whining about limited range
4065 nsize
= max (index_size
, 2 * new_size
);
4066 if (nsize
> MOST_POSITIVE_FIXNUM
)
4067 error ("Hash table too large to resize");
4069 h
->key_and_value
= larger_vector (h
->key_and_value
, 2 * new_size
, Qnil
);
4070 h
->next
= larger_vector (h
->next
, new_size
, Qnil
);
4071 h
->hash
= larger_vector (h
->hash
, new_size
, Qnil
);
4072 h
->index
= Fmake_vector (make_number (index_size
), Qnil
);
4074 /* Update the free list. Do it so that new entries are added at
4075 the end of the free list. This makes some operations like
4077 for (i
= old_size
; i
< new_size
- 1; ++i
)
4078 HASH_NEXT (h
, i
) = make_number (i
+ 1);
4080 if (!NILP (h
->next_free
))
4082 Lisp_Object last
, next
;
4084 last
= h
->next_free
;
4085 while (next
= HASH_NEXT (h
, XFASTINT (last
)),
4089 HASH_NEXT (h
, XFASTINT (last
)) = make_number (old_size
);
4092 XSETFASTINT (h
->next_free
, old_size
);
4095 for (i
= 0; i
< old_size
; ++i
)
4096 if (!NILP (HASH_HASH (h
, i
)))
4098 unsigned hash_code
= XUINT (HASH_HASH (h
, i
));
4099 int start_of_bucket
= hash_code
% ASIZE (h
->index
);
4100 HASH_NEXT (h
, i
) = HASH_INDEX (h
, start_of_bucket
);
4101 HASH_INDEX (h
, start_of_bucket
) = make_number (i
);
4107 /* Lookup KEY in hash table H. If HASH is non-null, return in *HASH
4108 the hash code of KEY. Value is the index of the entry in H
4109 matching KEY, or -1 if not found. */
4112 hash_lookup (h
, key
, hash
)
4113 struct Lisp_Hash_Table
*h
;
4118 int start_of_bucket
;
4121 hash_code
= h
->hashfn (h
, key
);
4125 start_of_bucket
= hash_code
% ASIZE (h
->index
);
4126 idx
= HASH_INDEX (h
, start_of_bucket
);
4128 /* We need not gcpro idx since it's either an integer or nil. */
4131 int i
= XFASTINT (idx
);
4132 if (EQ (key
, HASH_KEY (h
, i
))
4134 && h
->cmpfn (h
, key
, hash_code
,
4135 HASH_KEY (h
, i
), XUINT (HASH_HASH (h
, i
)))))
4137 idx
= HASH_NEXT (h
, i
);
4140 return NILP (idx
) ? -1 : XFASTINT (idx
);
4144 /* Put an entry into hash table H that associates KEY with VALUE.
4145 HASH is a previously computed hash code of KEY.
4146 Value is the index of the entry in H matching KEY. */
4149 hash_put (h
, key
, value
, hash
)
4150 struct Lisp_Hash_Table
*h
;
4151 Lisp_Object key
, value
;
4154 int start_of_bucket
, i
;
4156 xassert ((hash
& ~INTMASK
) == 0);
4158 /* Increment count after resizing because resizing may fail. */
4159 maybe_resize_hash_table (h
);
4162 /* Store key/value in the key_and_value vector. */
4163 i
= XFASTINT (h
->next_free
);
4164 h
->next_free
= HASH_NEXT (h
, i
);
4165 HASH_KEY (h
, i
) = key
;
4166 HASH_VALUE (h
, i
) = value
;
4168 /* Remember its hash code. */
4169 HASH_HASH (h
, i
) = make_number (hash
);
4171 /* Add new entry to its collision chain. */
4172 start_of_bucket
= hash
% ASIZE (h
->index
);
4173 HASH_NEXT (h
, i
) = HASH_INDEX (h
, start_of_bucket
);
4174 HASH_INDEX (h
, start_of_bucket
) = make_number (i
);
4179 /* Remove the entry matching KEY from hash table H, if there is one. */
4182 hash_remove (h
, key
)
4183 struct Lisp_Hash_Table
*h
;
4187 int start_of_bucket
;
4188 Lisp_Object idx
, prev
;
4190 hash_code
= h
->hashfn (h
, key
);
4191 start_of_bucket
= hash_code
% ASIZE (h
->index
);
4192 idx
= HASH_INDEX (h
, start_of_bucket
);
4195 /* We need not gcpro idx, prev since they're either integers or nil. */
4198 int i
= XFASTINT (idx
);
4200 if (EQ (key
, HASH_KEY (h
, i
))
4202 && h
->cmpfn (h
, key
, hash_code
,
4203 HASH_KEY (h
, i
), XUINT (HASH_HASH (h
, i
)))))
4205 /* Take entry out of collision chain. */
4207 HASH_INDEX (h
, start_of_bucket
) = HASH_NEXT (h
, i
);
4209 HASH_NEXT (h
, XFASTINT (prev
)) = HASH_NEXT (h
, i
);
4211 /* Clear slots in key_and_value and add the slots to
4213 HASH_KEY (h
, i
) = HASH_VALUE (h
, i
) = HASH_HASH (h
, i
) = Qnil
;
4214 HASH_NEXT (h
, i
) = h
->next_free
;
4215 h
->next_free
= make_number (i
);
4217 xassert (h
->count
>= 0);
4223 idx
= HASH_NEXT (h
, i
);
4229 /* Clear hash table H. */
4233 struct Lisp_Hash_Table
*h
;
4237 int i
, size
= HASH_TABLE_SIZE (h
);
4239 for (i
= 0; i
< size
; ++i
)
4241 HASH_NEXT (h
, i
) = i
< size
- 1 ? make_number (i
+ 1) : Qnil
;
4242 HASH_KEY (h
, i
) = Qnil
;
4243 HASH_VALUE (h
, i
) = Qnil
;
4244 HASH_HASH (h
, i
) = Qnil
;
4247 for (i
= 0; i
< ASIZE (h
->index
); ++i
)
4248 ASET (h
->index
, i
, Qnil
);
4250 h
->next_free
= make_number (0);
4257 /************************************************************************
4259 ************************************************************************/
4261 /* Sweep weak hash table H. REMOVE_ENTRIES_P non-zero means remove
4262 entries from the table that don't survive the current GC.
4263 REMOVE_ENTRIES_P zero means mark entries that are in use. Value is
4264 non-zero if anything was marked. */
4267 sweep_weak_table (h
, remove_entries_p
)
4268 struct Lisp_Hash_Table
*h
;
4269 int remove_entries_p
;
4271 int bucket
, n
, marked
;
4273 n
= ASIZE (h
->index
) & ~ARRAY_MARK_FLAG
;
4276 for (bucket
= 0; bucket
< n
; ++bucket
)
4278 Lisp_Object idx
, next
, prev
;
4280 /* Follow collision chain, removing entries that
4281 don't survive this garbage collection. */
4283 for (idx
= HASH_INDEX (h
, bucket
); !NILP (idx
); idx
= next
)
4285 int i
= XFASTINT (idx
);
4286 int key_known_to_survive_p
= survives_gc_p (HASH_KEY (h
, i
));
4287 int value_known_to_survive_p
= survives_gc_p (HASH_VALUE (h
, i
));
4290 if (EQ (h
->weak
, Qkey
))
4291 remove_p
= !key_known_to_survive_p
;
4292 else if (EQ (h
->weak
, Qvalue
))
4293 remove_p
= !value_known_to_survive_p
;
4294 else if (EQ (h
->weak
, Qkey_or_value
))
4295 remove_p
= !(key_known_to_survive_p
|| value_known_to_survive_p
);
4296 else if (EQ (h
->weak
, Qkey_and_value
))
4297 remove_p
= !(key_known_to_survive_p
&& value_known_to_survive_p
);
4301 next
= HASH_NEXT (h
, i
);
4303 if (remove_entries_p
)
4307 /* Take out of collision chain. */
4309 HASH_INDEX (h
, bucket
) = next
;
4311 HASH_NEXT (h
, XFASTINT (prev
)) = next
;
4313 /* Add to free list. */
4314 HASH_NEXT (h
, i
) = h
->next_free
;
4317 /* Clear key, value, and hash. */
4318 HASH_KEY (h
, i
) = HASH_VALUE (h
, i
) = Qnil
;
4319 HASH_HASH (h
, i
) = Qnil
;
4332 /* Make sure key and value survive. */
4333 if (!key_known_to_survive_p
)
4335 mark_object (HASH_KEY (h
, i
));
4339 if (!value_known_to_survive_p
)
4341 mark_object (HASH_VALUE (h
, i
));
4352 /* Remove elements from weak hash tables that don't survive the
4353 current garbage collection. Remove weak tables that don't survive
4354 from Vweak_hash_tables. Called from gc_sweep. */
4357 sweep_weak_hash_tables ()
4359 struct Lisp_Hash_Table
*h
, *used
, *next
;
4362 /* Mark all keys and values that are in use. Keep on marking until
4363 there is no more change. This is necessary for cases like
4364 value-weak table A containing an entry X -> Y, where Y is used in a
4365 key-weak table B, Z -> Y. If B comes after A in the list of weak
4366 tables, X -> Y might be removed from A, although when looking at B
4367 one finds that it shouldn't. */
4371 for (h
= weak_hash_tables
; h
; h
= h
->next_weak
)
4373 if (h
->size
& ARRAY_MARK_FLAG
)
4374 marked
|= sweep_weak_table (h
, 0);
4379 /* Remove tables and entries that aren't used. */
4380 for (h
= weak_hash_tables
, used
= NULL
; h
; h
= next
)
4382 next
= h
->next_weak
;
4384 if (h
->size
& ARRAY_MARK_FLAG
)
4386 /* TABLE is marked as used. Sweep its contents. */
4388 sweep_weak_table (h
, 1);
4390 /* Add table to the list of used weak hash tables. */
4391 h
->next_weak
= used
;
4396 weak_hash_tables
= used
;
4401 /***********************************************************************
4402 Hash Code Computation
4403 ***********************************************************************/
4405 /* Maximum depth up to which to dive into Lisp structures. */
4407 #define SXHASH_MAX_DEPTH 3
4409 /* Maximum length up to which to take list and vector elements into
4412 #define SXHASH_MAX_LEN 7
4414 /* Combine two integers X and Y for hashing. */
4416 #define SXHASH_COMBINE(X, Y) \
4417 ((((unsigned)(X) << 4) + (((unsigned)(X) >> 24) & 0x0fffffff)) \
4421 /* Return a hash for string PTR which has length LEN. The hash
4422 code returned is guaranteed to fit in a Lisp integer. */
4425 sxhash_string (ptr
, len
)
4429 unsigned char *p
= ptr
;
4430 unsigned char *end
= p
+ len
;
4439 hash
= ((hash
<< 4) + (hash
>> 28) + c
);
4442 return hash
& INTMASK
;
4446 /* Return a hash for list LIST. DEPTH is the current depth in the
4447 list. We don't recurse deeper than SXHASH_MAX_DEPTH in it. */
4450 sxhash_list (list
, depth
)
4457 if (depth
< SXHASH_MAX_DEPTH
)
4459 CONSP (list
) && i
< SXHASH_MAX_LEN
;
4460 list
= XCDR (list
), ++i
)
4462 unsigned hash2
= sxhash (XCAR (list
), depth
+ 1);
4463 hash
= SXHASH_COMBINE (hash
, hash2
);
4468 unsigned hash2
= sxhash (list
, depth
+ 1);
4469 hash
= SXHASH_COMBINE (hash
, hash2
);
4476 /* Return a hash for vector VECTOR. DEPTH is the current depth in
4477 the Lisp structure. */
4480 sxhash_vector (vec
, depth
)
4484 unsigned hash
= ASIZE (vec
);
4487 n
= min (SXHASH_MAX_LEN
, ASIZE (vec
));
4488 for (i
= 0; i
< n
; ++i
)
4490 unsigned hash2
= sxhash (AREF (vec
, i
), depth
+ 1);
4491 hash
= SXHASH_COMBINE (hash
, hash2
);
4498 /* Return a hash for bool-vector VECTOR. */
4501 sxhash_bool_vector (vec
)
4504 unsigned hash
= XBOOL_VECTOR (vec
)->size
;
4507 n
= min (SXHASH_MAX_LEN
, XBOOL_VECTOR (vec
)->vector_size
);
4508 for (i
= 0; i
< n
; ++i
)
4509 hash
= SXHASH_COMBINE (hash
, XBOOL_VECTOR (vec
)->data
[i
]);
4515 /* Return a hash code for OBJ. DEPTH is the current depth in the Lisp
4516 structure. Value is an unsigned integer clipped to INTMASK. */
4525 if (depth
> SXHASH_MAX_DEPTH
)
4528 switch (XTYPE (obj
))
4539 obj
= SYMBOL_NAME (obj
);
4543 hash
= sxhash_string (SDATA (obj
), SCHARS (obj
));
4546 /* This can be everything from a vector to an overlay. */
4547 case Lisp_Vectorlike
:
4549 /* According to the CL HyperSpec, two arrays are equal only if
4550 they are `eq', except for strings and bit-vectors. In
4551 Emacs, this works differently. We have to compare element
4553 hash
= sxhash_vector (obj
, depth
);
4554 else if (BOOL_VECTOR_P (obj
))
4555 hash
= sxhash_bool_vector (obj
);
4557 /* Others are `equal' if they are `eq', so let's take their
4563 hash
= sxhash_list (obj
, depth
);
4568 unsigned char *p
= (unsigned char *) &XFLOAT_DATA (obj
);
4569 unsigned char *e
= p
+ sizeof XFLOAT_DATA (obj
);
4570 for (hash
= 0; p
< e
; ++p
)
4571 hash
= SXHASH_COMBINE (hash
, *p
);
4579 return hash
& INTMASK
;
4584 /***********************************************************************
4586 ***********************************************************************/
4589 DEFUN ("sxhash", Fsxhash
, Ssxhash
, 1, 1, 0,
4590 doc
: /* Compute a hash code for OBJ and return it as integer. */)
4594 unsigned hash
= sxhash (obj
, 0);
4595 return make_number (hash
);
4599 DEFUN ("make-hash-table", Fmake_hash_table
, Smake_hash_table
, 0, MANY
, 0,
4600 doc
: /* Create and return a new hash table.
4602 Arguments are specified as keyword/argument pairs. The following
4603 arguments are defined:
4605 :test TEST -- TEST must be a symbol that specifies how to compare
4606 keys. Default is `eql'. Predefined are the tests `eq', `eql', and
4607 `equal'. User-supplied test and hash functions can be specified via
4608 `define-hash-table-test'.
4610 :size SIZE -- A hint as to how many elements will be put in the table.
4613 :rehash-size REHASH-SIZE - Indicates how to expand the table when it
4614 fills up. If REHASH-SIZE is an integer, add that many space. If it
4615 is a float, it must be > 1.0, and the new size is computed by
4616 multiplying the old size with that factor. Default is 1.5.
4618 :rehash-threshold THRESHOLD -- THRESHOLD must a float > 0, and <= 1.0.
4619 Resize the hash table when ratio of the number of entries in the
4620 table. Default is 0.8.
4622 :weakness WEAK -- WEAK must be one of nil, t, `key', `value',
4623 `key-or-value', or `key-and-value'. If WEAK is not nil, the table
4624 returned is a weak table. Key/value pairs are removed from a weak
4625 hash table when there are no non-weak references pointing to their
4626 key, value, one of key or value, or both key and value, depending on
4627 WEAK. WEAK t is equivalent to `key-and-value'. Default value of WEAK
4630 usage: (make-hash-table &rest KEYWORD-ARGS) */)
4635 Lisp_Object test
, size
, rehash_size
, rehash_threshold
, weak
;
4636 Lisp_Object user_test
, user_hash
;
4640 /* The vector `used' is used to keep track of arguments that
4641 have been consumed. */
4642 used
= (char *) alloca (nargs
* sizeof *used
);
4643 bzero (used
, nargs
* sizeof *used
);
4645 /* See if there's a `:test TEST' among the arguments. */
4646 i
= get_key_arg (QCtest
, nargs
, args
, used
);
4647 test
= i
< 0 ? Qeql
: args
[i
];
4648 if (!EQ (test
, Qeq
) && !EQ (test
, Qeql
) && !EQ (test
, Qequal
))
4650 /* See if it is a user-defined test. */
4653 prop
= Fget (test
, Qhash_table_test
);
4654 if (!CONSP (prop
) || !CONSP (XCDR (prop
)))
4655 signal_error ("Invalid hash table test", test
);
4656 user_test
= XCAR (prop
);
4657 user_hash
= XCAR (XCDR (prop
));
4660 user_test
= user_hash
= Qnil
;
4662 /* See if there's a `:size SIZE' argument. */
4663 i
= get_key_arg (QCsize
, nargs
, args
, used
);
4664 size
= i
< 0 ? Qnil
: args
[i
];
4666 size
= make_number (DEFAULT_HASH_SIZE
);
4667 else if (!INTEGERP (size
) || XINT (size
) < 0)
4668 signal_error ("Invalid hash table size", size
);
4670 /* Look for `:rehash-size SIZE'. */
4671 i
= get_key_arg (QCrehash_size
, nargs
, args
, used
);
4672 rehash_size
= i
< 0 ? make_float (DEFAULT_REHASH_SIZE
) : args
[i
];
4673 if (!NUMBERP (rehash_size
)
4674 || (INTEGERP (rehash_size
) && XINT (rehash_size
) <= 0)
4675 || XFLOATINT (rehash_size
) <= 1.0)
4676 signal_error ("Invalid hash table rehash size", rehash_size
);
4678 /* Look for `:rehash-threshold THRESHOLD'. */
4679 i
= get_key_arg (QCrehash_threshold
, nargs
, args
, used
);
4680 rehash_threshold
= i
< 0 ? make_float (DEFAULT_REHASH_THRESHOLD
) : args
[i
];
4681 if (!FLOATP (rehash_threshold
)
4682 || XFLOATINT (rehash_threshold
) <= 0.0
4683 || XFLOATINT (rehash_threshold
) > 1.0)
4684 signal_error ("Invalid hash table rehash threshold", rehash_threshold
);
4686 /* Look for `:weakness WEAK'. */
4687 i
= get_key_arg (QCweakness
, nargs
, args
, used
);
4688 weak
= i
< 0 ? Qnil
: args
[i
];
4690 weak
= Qkey_and_value
;
4693 && !EQ (weak
, Qvalue
)
4694 && !EQ (weak
, Qkey_or_value
)
4695 && !EQ (weak
, Qkey_and_value
))
4696 signal_error ("Invalid hash table weakness", weak
);
4698 /* Now, all args should have been used up, or there's a problem. */
4699 for (i
= 0; i
< nargs
; ++i
)
4701 signal_error ("Invalid argument list", args
[i
]);
4703 return make_hash_table (test
, size
, rehash_size
, rehash_threshold
, weak
,
4704 user_test
, user_hash
);
4708 DEFUN ("copy-hash-table", Fcopy_hash_table
, Scopy_hash_table
, 1, 1, 0,
4709 doc
: /* Return a copy of hash table TABLE. */)
4713 return copy_hash_table (check_hash_table (table
));
4717 DEFUN ("hash-table-count", Fhash_table_count
, Shash_table_count
, 1, 1, 0,
4718 doc
: /* Return the number of elements in TABLE. */)
4722 return make_number (check_hash_table (table
)->count
);
4726 DEFUN ("hash-table-rehash-size", Fhash_table_rehash_size
,
4727 Shash_table_rehash_size
, 1, 1, 0,
4728 doc
: /* Return the current rehash size of TABLE. */)
4732 return check_hash_table (table
)->rehash_size
;
4736 DEFUN ("hash-table-rehash-threshold", Fhash_table_rehash_threshold
,
4737 Shash_table_rehash_threshold
, 1, 1, 0,
4738 doc
: /* Return the current rehash threshold of TABLE. */)
4742 return check_hash_table (table
)->rehash_threshold
;
4746 DEFUN ("hash-table-size", Fhash_table_size
, Shash_table_size
, 1, 1, 0,
4747 doc
: /* Return the size of TABLE.
4748 The size can be used as an argument to `make-hash-table' to create
4749 a hash table than can hold as many elements of TABLE holds
4750 without need for resizing. */)
4754 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4755 return make_number (HASH_TABLE_SIZE (h
));
4759 DEFUN ("hash-table-test", Fhash_table_test
, Shash_table_test
, 1, 1, 0,
4760 doc
: /* Return the test TABLE uses. */)
4764 return check_hash_table (table
)->test
;
4768 DEFUN ("hash-table-weakness", Fhash_table_weakness
, Shash_table_weakness
,
4770 doc
: /* Return the weakness of TABLE. */)
4774 return check_hash_table (table
)->weak
;
4778 DEFUN ("hash-table-p", Fhash_table_p
, Shash_table_p
, 1, 1, 0,
4779 doc
: /* Return t if OBJ is a Lisp hash table object. */)
4783 return HASH_TABLE_P (obj
) ? Qt
: Qnil
;
4787 DEFUN ("clrhash", Fclrhash
, Sclrhash
, 1, 1, 0,
4788 doc
: /* Clear hash table TABLE and return it. */)
4792 hash_clear (check_hash_table (table
));
4793 /* Be compatible with XEmacs. */
4798 DEFUN ("gethash", Fgethash
, Sgethash
, 2, 3, 0,
4799 doc
: /* Look up KEY in TABLE and return its associated value.
4800 If KEY is not found, return DFLT which defaults to nil. */)
4802 Lisp_Object key
, table
, dflt
;
4804 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4805 int i
= hash_lookup (h
, key
, NULL
);
4806 return i
>= 0 ? HASH_VALUE (h
, i
) : dflt
;
4810 DEFUN ("puthash", Fputhash
, Sputhash
, 3, 3, 0,
4811 doc
: /* Associate KEY with VALUE in hash table TABLE.
4812 If KEY is already present in table, replace its current value with
4815 Lisp_Object key
, value
, table
;
4817 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4821 i
= hash_lookup (h
, key
, &hash
);
4823 HASH_VALUE (h
, i
) = value
;
4825 hash_put (h
, key
, value
, hash
);
4831 DEFUN ("remhash", Fremhash
, Sremhash
, 2, 2, 0,
4832 doc
: /* Remove KEY from TABLE. */)
4834 Lisp_Object key
, table
;
4836 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4837 hash_remove (h
, key
);
4842 DEFUN ("maphash", Fmaphash
, Smaphash
, 2, 2, 0,
4843 doc
: /* Call FUNCTION for all entries in hash table TABLE.
4844 FUNCTION is called with two arguments, KEY and VALUE. */)
4846 Lisp_Object function
, table
;
4848 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4849 Lisp_Object args
[3];
4852 for (i
= 0; i
< HASH_TABLE_SIZE (h
); ++i
)
4853 if (!NILP (HASH_HASH (h
, i
)))
4856 args
[1] = HASH_KEY (h
, i
);
4857 args
[2] = HASH_VALUE (h
, i
);
4865 DEFUN ("define-hash-table-test", Fdefine_hash_table_test
,
4866 Sdefine_hash_table_test
, 3, 3, 0,
4867 doc
: /* Define a new hash table test with name NAME, a symbol.
4869 In hash tables created with NAME specified as test, use TEST to
4870 compare keys, and HASH for computing hash codes of keys.
4872 TEST must be a function taking two arguments and returning non-nil if
4873 both arguments are the same. HASH must be a function taking one
4874 argument and return an integer that is the hash code of the argument.
4875 Hash code computation should use the whole value range of integers,
4876 including negative integers. */)
4878 Lisp_Object name
, test
, hash
;
4880 return Fput (name
, Qhash_table_test
, list2 (test
, hash
));
4885 /************************************************************************
4887 ************************************************************************/
4891 DEFUN ("md5", Fmd5
, Smd5
, 1, 5, 0,
4892 doc
: /* Return MD5 message digest of OBJECT, a buffer or string.
4894 A message digest is a cryptographic checksum of a document, and the
4895 algorithm to calculate it is defined in RFC 1321.
4897 The two optional arguments START and END are character positions
4898 specifying for which part of OBJECT the message digest should be
4899 computed. If nil or omitted, the digest is computed for the whole
4902 The MD5 message digest is computed from the result of encoding the
4903 text in a coding system, not directly from the internal Emacs form of
4904 the text. The optional fourth argument CODING-SYSTEM specifies which
4905 coding system to encode the text with. It should be the same coding
4906 system that you used or will use when actually writing the text into a
4909 If CODING-SYSTEM is nil or omitted, the default depends on OBJECT. If
4910 OBJECT is a buffer, the default for CODING-SYSTEM is whatever coding
4911 system would be chosen by default for writing this text into a file.
4913 If OBJECT is a string, the most preferred coding system (see the
4914 command `prefer-coding-system') is used.
4916 If NOERROR is non-nil, silently assume the `raw-text' coding if the
4917 guesswork fails. Normally, an error is signaled in such case. */)
4918 (object
, start
, end
, coding_system
, noerror
)
4919 Lisp_Object object
, start
, end
, coding_system
, noerror
;
4921 unsigned char digest
[16];
4922 unsigned char value
[33];
4926 int start_char
= 0, end_char
= 0;
4927 int start_byte
= 0, end_byte
= 0;
4929 register struct buffer
*bp
;
4932 if (STRINGP (object
))
4934 if (NILP (coding_system
))
4936 /* Decide the coding-system to encode the data with. */
4938 if (STRING_MULTIBYTE (object
))
4939 /* use default, we can't guess correct value */
4940 coding_system
= preferred_coding_system ();
4942 coding_system
= Qraw_text
;
4945 if (NILP (Fcoding_system_p (coding_system
)))
4947 /* Invalid coding system. */
4949 if (!NILP (noerror
))
4950 coding_system
= Qraw_text
;
4952 xsignal1 (Qcoding_system_error
, coding_system
);
4955 if (STRING_MULTIBYTE (object
))
4956 object
= code_convert_string (object
, coding_system
, Qnil
, 1, 0, 1);
4958 size
= SCHARS (object
);
4959 size_byte
= SBYTES (object
);
4963 CHECK_NUMBER (start
);
4965 start_char
= XINT (start
);
4970 start_byte
= string_char_to_byte (object
, start_char
);
4976 end_byte
= size_byte
;
4982 end_char
= XINT (end
);
4987 end_byte
= string_char_to_byte (object
, end_char
);
4990 if (!(0 <= start_char
&& start_char
<= end_char
&& end_char
<= size
))
4991 args_out_of_range_3 (object
, make_number (start_char
),
4992 make_number (end_char
));
4996 struct buffer
*prev
= current_buffer
;
4998 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5000 CHECK_BUFFER (object
);
5002 bp
= XBUFFER (object
);
5003 if (bp
!= current_buffer
)
5004 set_buffer_internal (bp
);
5010 CHECK_NUMBER_COERCE_MARKER (start
);
5018 CHECK_NUMBER_COERCE_MARKER (end
);
5023 temp
= b
, b
= e
, e
= temp
;
5025 if (!(BEGV
<= b
&& e
<= ZV
))
5026 args_out_of_range (start
, end
);
5028 if (NILP (coding_system
))
5030 /* Decide the coding-system to encode the data with.
5031 See fileio.c:Fwrite-region */
5033 if (!NILP (Vcoding_system_for_write
))
5034 coding_system
= Vcoding_system_for_write
;
5037 int force_raw_text
= 0;
5039 coding_system
= XBUFFER (object
)->buffer_file_coding_system
;
5040 if (NILP (coding_system
)
5041 || NILP (Flocal_variable_p (Qbuffer_file_coding_system
, Qnil
)))
5043 coding_system
= Qnil
;
5044 if (NILP (current_buffer
->enable_multibyte_characters
))
5048 if (NILP (coding_system
) && !NILP (Fbuffer_file_name(object
)))
5050 /* Check file-coding-system-alist. */
5051 Lisp_Object args
[4], val
;
5053 args
[0] = Qwrite_region
; args
[1] = start
; args
[2] = end
;
5054 args
[3] = Fbuffer_file_name(object
);
5055 val
= Ffind_operation_coding_system (4, args
);
5056 if (CONSP (val
) && !NILP (XCDR (val
)))
5057 coding_system
= XCDR (val
);
5060 if (NILP (coding_system
)
5061 && !NILP (XBUFFER (object
)->buffer_file_coding_system
))
5063 /* If we still have not decided a coding system, use the
5064 default value of buffer-file-coding-system. */
5065 coding_system
= XBUFFER (object
)->buffer_file_coding_system
;
5069 && !NILP (Ffboundp (Vselect_safe_coding_system_function
)))
5070 /* Confirm that VAL can surely encode the current region. */
5071 coding_system
= call4 (Vselect_safe_coding_system_function
,
5072 make_number (b
), make_number (e
),
5073 coding_system
, Qnil
);
5076 coding_system
= Qraw_text
;
5079 if (NILP (Fcoding_system_p (coding_system
)))
5081 /* Invalid coding system. */
5083 if (!NILP (noerror
))
5084 coding_system
= Qraw_text
;
5086 xsignal1 (Qcoding_system_error
, coding_system
);
5090 object
= make_buffer_string (b
, e
, 0);
5091 if (prev
!= current_buffer
)
5092 set_buffer_internal (prev
);
5093 /* Discard the unwind protect for recovering the current
5097 if (STRING_MULTIBYTE (object
))
5098 object
= code_convert_string (object
, coding_system
, Qnil
, 1, 0, 0);
5101 md5_buffer (SDATA (object
) + start_byte
,
5102 SBYTES (object
) - (size_byte
- end_byte
),
5105 for (i
= 0; i
< 16; i
++)
5106 sprintf (&value
[2 * i
], "%02x", digest
[i
]);
5109 return make_string (value
, 32);
5116 /* Hash table stuff. */
5117 Qhash_table_p
= intern ("hash-table-p");
5118 staticpro (&Qhash_table_p
);
5119 Qeq
= intern ("eq");
5121 Qeql
= intern ("eql");
5123 Qequal
= intern ("equal");
5124 staticpro (&Qequal
);
5125 QCtest
= intern (":test");
5126 staticpro (&QCtest
);
5127 QCsize
= intern (":size");
5128 staticpro (&QCsize
);
5129 QCrehash_size
= intern (":rehash-size");
5130 staticpro (&QCrehash_size
);
5131 QCrehash_threshold
= intern (":rehash-threshold");
5132 staticpro (&QCrehash_threshold
);
5133 QCweakness
= intern (":weakness");
5134 staticpro (&QCweakness
);
5135 Qkey
= intern ("key");
5137 Qvalue
= intern ("value");
5138 staticpro (&Qvalue
);
5139 Qhash_table_test
= intern ("hash-table-test");
5140 staticpro (&Qhash_table_test
);
5141 Qkey_or_value
= intern ("key-or-value");
5142 staticpro (&Qkey_or_value
);
5143 Qkey_and_value
= intern ("key-and-value");
5144 staticpro (&Qkey_and_value
);
5147 defsubr (&Smake_hash_table
);
5148 defsubr (&Scopy_hash_table
);
5149 defsubr (&Shash_table_count
);
5150 defsubr (&Shash_table_rehash_size
);
5151 defsubr (&Shash_table_rehash_threshold
);
5152 defsubr (&Shash_table_size
);
5153 defsubr (&Shash_table_test
);
5154 defsubr (&Shash_table_weakness
);
5155 defsubr (&Shash_table_p
);
5156 defsubr (&Sclrhash
);
5157 defsubr (&Sgethash
);
5158 defsubr (&Sputhash
);
5159 defsubr (&Sremhash
);
5160 defsubr (&Smaphash
);
5161 defsubr (&Sdefine_hash_table_test
);
5163 Qstring_lessp
= intern ("string-lessp");
5164 staticpro (&Qstring_lessp
);
5165 Qprovide
= intern ("provide");
5166 staticpro (&Qprovide
);
5167 Qrequire
= intern ("require");
5168 staticpro (&Qrequire
);
5169 Qyes_or_no_p_history
= intern ("yes-or-no-p-history");
5170 staticpro (&Qyes_or_no_p_history
);
5171 Qcursor_in_echo_area
= intern ("cursor-in-echo-area");
5172 staticpro (&Qcursor_in_echo_area
);
5173 Qwidget_type
= intern ("widget-type");
5174 staticpro (&Qwidget_type
);
5176 staticpro (&string_char_byte_cache_string
);
5177 string_char_byte_cache_string
= Qnil
;
5179 require_nesting_list
= Qnil
;
5180 staticpro (&require_nesting_list
);
5182 Fset (Qyes_or_no_p_history
, Qnil
);
5184 DEFVAR_LISP ("features", &Vfeatures
,
5185 doc
: /* A list of symbols which are the features of the executing Emacs.
5186 Used by `featurep' and `require', and altered by `provide'. */);
5187 Vfeatures
= Fcons (intern ("emacs"), Qnil
);
5188 Qsubfeatures
= intern ("subfeatures");
5189 staticpro (&Qsubfeatures
);
5191 #ifdef HAVE_LANGINFO_CODESET
5192 Qcodeset
= intern ("codeset");
5193 staticpro (&Qcodeset
);
5194 Qdays
= intern ("days");
5196 Qmonths
= intern ("months");
5197 staticpro (&Qmonths
);
5198 Qpaper
= intern ("paper");
5199 staticpro (&Qpaper
);
5200 #endif /* HAVE_LANGINFO_CODESET */
5202 DEFVAR_BOOL ("use-dialog-box", &use_dialog_box
,
5203 doc
: /* *Non-nil means mouse commands use dialog boxes to ask questions.
5204 This applies to `y-or-n-p' and `yes-or-no-p' questions asked by commands
5205 invoked by mouse clicks and mouse menu items. */);
5208 DEFVAR_BOOL ("use-file-dialog", &use_file_dialog
,
5209 doc
: /* *Non-nil means mouse commands use a file dialog to ask for files.
5210 This applies to commands from menus and tool bar buttons even when
5211 they are initiated from the keyboard. The value of `use-dialog-box'
5212 takes precedence over this variable, so a file dialog is only used if
5213 both `use-dialog-box' and this variable are non-nil. */);
5214 use_file_dialog
= 1;
5216 defsubr (&Sidentity
);
5219 defsubr (&Ssafe_length
);
5220 defsubr (&Sstring_bytes
);
5221 defsubr (&Sstring_equal
);
5222 defsubr (&Scompare_strings
);
5223 defsubr (&Sstring_lessp
);
5226 defsubr (&Svconcat
);
5227 defsubr (&Scopy_sequence
);
5228 defsubr (&Sstring_make_multibyte
);
5229 defsubr (&Sstring_make_unibyte
);
5230 defsubr (&Sstring_as_multibyte
);
5231 defsubr (&Sstring_as_unibyte
);
5232 defsubr (&Sstring_to_multibyte
);
5233 defsubr (&Scopy_alist
);
5234 defsubr (&Ssubstring
);
5235 defsubr (&Ssubstring_no_properties
);
5248 defsubr (&Snreverse
);
5249 defsubr (&Sreverse
);
5251 defsubr (&Splist_get
);
5253 defsubr (&Splist_put
);
5255 defsubr (&Slax_plist_get
);
5256 defsubr (&Slax_plist_put
);
5259 defsubr (&Sequal_including_properties
);
5260 defsubr (&Sfillarray
);
5261 defsubr (&Sclear_string
);
5265 defsubr (&Smapconcat
);
5266 defsubr (&Sy_or_n_p
);
5267 defsubr (&Syes_or_no_p
);
5268 defsubr (&Sload_average
);
5269 defsubr (&Sfeaturep
);
5270 defsubr (&Srequire
);
5271 defsubr (&Sprovide
);
5272 defsubr (&Splist_member
);
5273 defsubr (&Swidget_put
);
5274 defsubr (&Swidget_get
);
5275 defsubr (&Swidget_apply
);
5276 defsubr (&Sbase64_encode_region
);
5277 defsubr (&Sbase64_decode_region
);
5278 defsubr (&Sbase64_encode_string
);
5279 defsubr (&Sbase64_decode_string
);
5281 defsubr (&Slocale_info
);
5288 weak_hash_tables
= NULL
;
5291 /* arch-tag: 787f8219-5b74-46bd-8469-7e1cc475fa31
5292 (do not change this comment) */