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 of the License, or
11 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
29 /* On Mac OS, defining this conflicts with precompiled headers. */
31 /* Note on some machines this defines `vector' as a typedef,
32 so make sure we don't use that name in this file. */
36 #endif /* ! MAC_OSX */
40 #include "character.h"
45 #include "intervals.h"
48 #include "blockinput.h"
50 #if defined (HAVE_X_WINDOWS)
52 #elif defined (MAC_OS)
58 #define NULL ((POINTER_TYPE *)0)
61 /* Nonzero enables use of dialog boxes for questions
62 asked by mouse commands. */
65 /* Nonzero enables use of a file dialog for file name
66 questions asked by mouse commands. */
69 extern int minibuffer_auto_raise
;
70 extern Lisp_Object minibuf_window
;
71 extern Lisp_Object Vlocale_coding_system
;
72 extern int load_in_progress
;
74 Lisp_Object Qstring_lessp
, Qprovide
, Qrequire
;
75 Lisp_Object Qyes_or_no_p_history
;
76 Lisp_Object Qcursor_in_echo_area
;
77 Lisp_Object Qwidget_type
;
78 Lisp_Object Qcodeset
, Qdays
, Qmonths
, Qpaper
;
80 extern Lisp_Object Qinput_method_function
;
82 static int internal_equal
P_ ((Lisp_Object
, Lisp_Object
, int, int));
84 extern long get_random ();
85 extern void seed_random
P_ ((long));
91 DEFUN ("identity", Fidentity
, Sidentity
, 1, 1, 0,
92 doc
: /* Return the argument unchanged. */)
99 DEFUN ("random", Frandom
, Srandom
, 0, 1, 0,
100 doc
: /* Return a pseudo-random number.
101 All integers representable in Lisp are equally likely.
102 On most systems, this is 29 bits' worth.
103 With positive integer argument N, return random number in interval [0,N).
104 With argument t, set the random number seed from the current time and pid. */)
109 Lisp_Object lispy_val
;
110 unsigned long denominator
;
113 seed_random (getpid () + time (NULL
));
114 if (NATNUMP (n
) && XFASTINT (n
) != 0)
116 /* Try to take our random number from the higher bits of VAL,
117 not the lower, since (says Gentzel) the low bits of `random'
118 are less random than the higher ones. We do this by using the
119 quotient rather than the remainder. At the high end of the RNG
120 it's possible to get a quotient larger than n; discarding
121 these values eliminates the bias that would otherwise appear
122 when using a large n. */
123 denominator
= ((unsigned long)1 << VALBITS
) / XFASTINT (n
);
125 val
= get_random () / denominator
;
126 while (val
>= XFASTINT (n
));
130 XSETINT (lispy_val
, val
);
134 /* Random data-structure functions */
136 DEFUN ("length", Flength
, Slength
, 1, 1, 0,
137 doc
: /* Return the length of vector, list or string SEQUENCE.
138 A byte-code function object is also allowed.
139 If the string contains multibyte characters, this is not necessarily
140 the number of bytes in the string; it is the number of characters.
141 To get the number of bytes, use `string-bytes'. */)
143 register Lisp_Object sequence
;
145 register Lisp_Object val
;
148 if (STRINGP (sequence
))
149 XSETFASTINT (val
, SCHARS (sequence
));
150 else if (VECTORP (sequence
))
151 XSETFASTINT (val
, ASIZE (sequence
));
152 else if (CHAR_TABLE_P (sequence
))
153 XSETFASTINT (val
, MAX_CHAR
);
154 else if (BOOL_VECTOR_P (sequence
))
155 XSETFASTINT (val
, XBOOL_VECTOR (sequence
)->size
);
156 else if (COMPILEDP (sequence
))
157 XSETFASTINT (val
, ASIZE (sequence
) & PSEUDOVECTOR_SIZE_MASK
);
158 else if (CONSP (sequence
))
161 while (CONSP (sequence
))
163 sequence
= XCDR (sequence
);
166 if (!CONSP (sequence
))
169 sequence
= XCDR (sequence
);
174 CHECK_LIST_END (sequence
, sequence
);
176 val
= make_number (i
);
178 else if (NILP (sequence
))
179 XSETFASTINT (val
, 0);
181 wrong_type_argument (Qsequencep
, sequence
);
186 /* This does not check for quits. That is safe since it must terminate. */
188 DEFUN ("safe-length", Fsafe_length
, Ssafe_length
, 1, 1, 0,
189 doc
: /* Return the length of a list, but avoid error or infinite loop.
190 This function never gets an error. If LIST is not really a list,
191 it returns 0. If LIST is circular, it returns a finite value
192 which is at least the number of distinct elements. */)
196 Lisp_Object tail
, halftail
, length
;
199 /* halftail is used to detect circular lists. */
201 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
203 if (EQ (tail
, halftail
) && len
!= 0)
207 halftail
= XCDR (halftail
);
210 XSETINT (length
, len
);
214 DEFUN ("string-bytes", Fstring_bytes
, Sstring_bytes
, 1, 1, 0,
215 doc
: /* Return the number of bytes in STRING.
216 If STRING is multibyte, this may be greater than the length of STRING. */)
220 CHECK_STRING (string
);
221 return make_number (SBYTES (string
));
224 DEFUN ("string-equal", Fstring_equal
, Sstring_equal
, 2, 2, 0,
225 doc
: /* Return t if two strings have identical contents.
226 Case is significant, but text properties are ignored.
227 Symbols are also allowed; their print names are used instead. */)
229 register Lisp_Object s1
, s2
;
232 s1
= SYMBOL_NAME (s1
);
234 s2
= SYMBOL_NAME (s2
);
238 if (SCHARS (s1
) != SCHARS (s2
)
239 || SBYTES (s1
) != SBYTES (s2
)
240 || bcmp (SDATA (s1
), SDATA (s2
), SBYTES (s1
)))
245 DEFUN ("compare-strings", Fcompare_strings
,
246 Scompare_strings
, 6, 7, 0,
247 doc
: /* Compare the contents of two strings, converting to multibyte if needed.
248 In string STR1, skip the first START1 characters and stop at END1.
249 In string STR2, skip the first START2 characters and stop at END2.
250 END1 and END2 default to the full lengths of the respective strings.
252 Case is significant in this comparison if IGNORE-CASE is nil.
253 Unibyte strings are converted to multibyte for comparison.
255 The value is t if the strings (or specified portions) match.
256 If string STR1 is less, the value is a negative number N;
257 - 1 - N is the number of characters that match at the beginning.
258 If string STR1 is greater, the value is a positive number N;
259 N - 1 is the number of characters that match at the beginning. */)
260 (str1
, start1
, end1
, str2
, start2
, end2
, ignore_case
)
261 Lisp_Object str1
, start1
, end1
, start2
, str2
, end2
, ignore_case
;
263 register int end1_char
, end2_char
;
264 register int i1
, i1_byte
, i2
, i2_byte
;
269 start1
= make_number (0);
271 start2
= make_number (0);
272 CHECK_NATNUM (start1
);
273 CHECK_NATNUM (start2
);
282 i1_byte
= string_char_to_byte (str1
, i1
);
283 i2_byte
= string_char_to_byte (str2
, i2
);
285 end1_char
= SCHARS (str1
);
286 if (! NILP (end1
) && end1_char
> XINT (end1
))
287 end1_char
= XINT (end1
);
289 end2_char
= SCHARS (str2
);
290 if (! NILP (end2
) && end2_char
> XINT (end2
))
291 end2_char
= XINT (end2
);
293 while (i1
< end1_char
&& i2
< end2_char
)
295 /* When we find a mismatch, we must compare the
296 characters, not just the bytes. */
299 if (STRING_MULTIBYTE (str1
))
300 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c1
, str1
, i1
, i1_byte
);
303 c1
= SREF (str1
, i1
++);
304 c1
= unibyte_char_to_multibyte (c1
);
307 if (STRING_MULTIBYTE (str2
))
308 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c2
, str2
, i2
, i2_byte
);
311 c2
= SREF (str2
, i2
++);
312 c2
= unibyte_char_to_multibyte (c2
);
318 if (! NILP (ignore_case
))
322 tem
= Fupcase (make_number (c1
));
324 tem
= Fupcase (make_number (c2
));
331 /* Note that I1 has already been incremented
332 past the character that we are comparing;
333 hence we don't add or subtract 1 here. */
335 return make_number (- i1
+ XINT (start1
));
337 return make_number (i1
- XINT (start1
));
341 return make_number (i1
- XINT (start1
) + 1);
343 return make_number (- i1
+ XINT (start1
) - 1);
348 DEFUN ("string-lessp", Fstring_lessp
, Sstring_lessp
, 2, 2, 0,
349 doc
: /* Return t if first arg string is less than second in lexicographic order.
351 Symbols are also allowed; their print names are used instead. */)
353 register Lisp_Object s1
, s2
;
356 register int i1
, i1_byte
, i2
, i2_byte
;
359 s1
= SYMBOL_NAME (s1
);
361 s2
= SYMBOL_NAME (s2
);
365 i1
= i1_byte
= i2
= i2_byte
= 0;
368 if (end
> SCHARS (s2
))
373 /* When we find a mismatch, we must compare the
374 characters, not just the bytes. */
377 FETCH_STRING_CHAR_ADVANCE (c1
, s1
, i1
, i1_byte
);
378 FETCH_STRING_CHAR_ADVANCE (c2
, s2
, i2
, i2_byte
);
381 return c1
< c2
? Qt
: Qnil
;
383 return i1
< SCHARS (s2
) ? Qt
: Qnil
;
387 /* "gcc -O3" enables automatic function inlining, which optimizes out
388 the arguments for the invocations of this function, whereas it
389 expects these values on the stack. */
390 static Lisp_Object concat
P_ ((int nargs
, Lisp_Object
*args
, enum Lisp_Type target_type
, int last_special
)) __attribute__((noinline
));
391 #else /* !__GNUC__ */
392 static Lisp_Object concat
P_ ((int nargs
, Lisp_Object
*args
, enum Lisp_Type target_type
, int last_special
));
404 return concat (2, args
, Lisp_String
, 0);
406 return concat (2, &s1
, Lisp_String
, 0);
407 #endif /* NO_ARG_ARRAY */
413 Lisp_Object s1
, s2
, s3
;
420 return concat (3, args
, Lisp_String
, 0);
422 return concat (3, &s1
, Lisp_String
, 0);
423 #endif /* NO_ARG_ARRAY */
426 DEFUN ("append", Fappend
, Sappend
, 0, MANY
, 0,
427 doc
: /* Concatenate all the arguments and make the result a list.
428 The result is a list whose elements are the elements of all the arguments.
429 Each argument may be a list, vector or string.
430 The last argument is not copied, just used as the tail of the new list.
431 usage: (append &rest SEQUENCES) */)
436 return concat (nargs
, args
, Lisp_Cons
, 1);
439 DEFUN ("concat", Fconcat
, Sconcat
, 0, MANY
, 0,
440 doc
: /* Concatenate all the arguments and make the result a string.
441 The result is a string whose elements are the elements of all the arguments.
442 Each argument may be a string or a list or vector of characters (integers).
443 usage: (concat &rest SEQUENCES) */)
448 return concat (nargs
, args
, Lisp_String
, 0);
451 DEFUN ("vconcat", Fvconcat
, Svconcat
, 0, MANY
, 0,
452 doc
: /* Concatenate all the arguments and make the result a vector.
453 The result is a vector whose elements are the elements of all the arguments.
454 Each argument may be a list, vector or string.
455 usage: (vconcat &rest SEQUENCES) */)
460 return concat (nargs
, args
, Lisp_Vectorlike
, 0);
464 DEFUN ("copy-sequence", Fcopy_sequence
, Scopy_sequence
, 1, 1, 0,
465 doc
: /* Return a copy of a list, vector, string or char-table.
466 The elements of a list or vector are not copied; they are shared
467 with the original. */)
471 if (NILP (arg
)) return arg
;
473 if (CHAR_TABLE_P (arg
))
475 return copy_char_table (arg
);
478 if (BOOL_VECTOR_P (arg
))
482 = ((XBOOL_VECTOR (arg
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
483 / BOOL_VECTOR_BITS_PER_CHAR
);
485 val
= Fmake_bool_vector (Flength (arg
), Qnil
);
486 bcopy (XBOOL_VECTOR (arg
)->data
, XBOOL_VECTOR (val
)->data
,
491 if (!CONSP (arg
) && !VECTORP (arg
) && !STRINGP (arg
))
492 wrong_type_argument (Qsequencep
, arg
);
494 return concat (1, &arg
, CONSP (arg
) ? Lisp_Cons
: XTYPE (arg
), 0);
497 /* This structure holds information of an argument of `concat' that is
498 a string and has text properties to be copied. */
501 int argnum
; /* refer to ARGS (arguments of `concat') */
502 int from
; /* refer to ARGS[argnum] (argument string) */
503 int to
; /* refer to VAL (the target string) */
507 concat (nargs
, args
, target_type
, last_special
)
510 enum Lisp_Type target_type
;
514 register Lisp_Object tail
;
515 register Lisp_Object
this;
517 int toindex_byte
= 0;
518 register int result_len
;
519 register int result_len_byte
;
521 Lisp_Object last_tail
;
524 /* When we make a multibyte string, we can't copy text properties
525 while concatinating each string because the length of resulting
526 string can't be decided until we finish the whole concatination.
527 So, we record strings that have text properties to be copied
528 here, and copy the text properties after the concatination. */
529 struct textprop_rec
*textprops
= NULL
;
530 /* Number of elments in textprops. */
531 int num_textprops
= 0;
536 /* In append, the last arg isn't treated like the others */
537 if (last_special
&& nargs
> 0)
540 last_tail
= args
[nargs
];
545 /* Check each argument. */
546 for (argnum
= 0; argnum
< nargs
; argnum
++)
549 if (!(CONSP (this) || NILP (this) || VECTORP (this) || STRINGP (this)
550 || COMPILEDP (this) || BOOL_VECTOR_P (this)))
551 wrong_type_argument (Qsequencep
, this);
554 /* Compute total length in chars of arguments in RESULT_LEN.
555 If desired output is a string, also compute length in bytes
556 in RESULT_LEN_BYTE, and determine in SOME_MULTIBYTE
557 whether the result should be a multibyte string. */
561 for (argnum
= 0; argnum
< nargs
; argnum
++)
565 len
= XFASTINT (Flength (this));
566 if (target_type
== Lisp_String
)
568 /* We must count the number of bytes needed in the string
569 as well as the number of characters. */
575 for (i
= 0; i
< len
; i
++)
578 CHECK_CHARACTER (ch
);
579 this_len_byte
= CHAR_BYTES (XINT (ch
));
580 result_len_byte
+= this_len_byte
;
581 if (! ASCII_CHAR_P (XINT (ch
)) && ! CHAR_BYTE8_P (XINT (ch
)))
584 else if (BOOL_VECTOR_P (this) && XBOOL_VECTOR (this)->size
> 0)
585 wrong_type_argument (Qintegerp
, Faref (this, make_number (0)));
586 else if (CONSP (this))
587 for (; CONSP (this); this = XCDR (this))
590 CHECK_CHARACTER (ch
);
591 this_len_byte
= CHAR_BYTES (XINT (ch
));
592 result_len_byte
+= this_len_byte
;
593 if (! ASCII_CHAR_P (XINT (ch
)) && ! CHAR_BYTE8_P (XINT (ch
)))
596 else if (STRINGP (this))
598 if (STRING_MULTIBYTE (this))
601 result_len_byte
+= SBYTES (this);
604 result_len_byte
+= count_size_as_multibyte (SDATA (this),
612 if (! some_multibyte
)
613 result_len_byte
= result_len
;
615 /* Create the output object. */
616 if (target_type
== Lisp_Cons
)
617 val
= Fmake_list (make_number (result_len
), Qnil
);
618 else if (target_type
== Lisp_Vectorlike
)
619 val
= Fmake_vector (make_number (result_len
), Qnil
);
620 else if (some_multibyte
)
621 val
= make_uninit_multibyte_string (result_len
, result_len_byte
);
623 val
= make_uninit_string (result_len
);
625 /* In `append', if all but last arg are nil, return last arg. */
626 if (target_type
== Lisp_Cons
&& EQ (val
, Qnil
))
629 /* Copy the contents of the args into the result. */
631 tail
= val
, toindex
= -1; /* -1 in toindex is flag we are making a list */
633 toindex
= 0, toindex_byte
= 0;
637 SAFE_ALLOCA (textprops
, struct textprop_rec
*, sizeof (struct textprop_rec
) * nargs
);
639 for (argnum
= 0; argnum
< nargs
; argnum
++)
643 register unsigned int thisindex
= 0;
644 register unsigned int thisindex_byte
= 0;
648 thislen
= Flength (this), thisleni
= XINT (thislen
);
650 /* Between strings of the same kind, copy fast. */
651 if (STRINGP (this) && STRINGP (val
)
652 && STRING_MULTIBYTE (this) == some_multibyte
)
654 int thislen_byte
= SBYTES (this);
656 bcopy (SDATA (this), SDATA (val
) + toindex_byte
,
658 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
660 textprops
[num_textprops
].argnum
= argnum
;
661 textprops
[num_textprops
].from
= 0;
662 textprops
[num_textprops
++].to
= toindex
;
664 toindex_byte
+= thislen_byte
;
666 STRING_SET_CHARS (val
, SCHARS (val
));
668 /* Copy a single-byte string to a multibyte string. */
669 else if (STRINGP (this) && STRINGP (val
))
671 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
673 textprops
[num_textprops
].argnum
= argnum
;
674 textprops
[num_textprops
].from
= 0;
675 textprops
[num_textprops
++].to
= toindex
;
677 toindex_byte
+= copy_text (SDATA (this),
678 SDATA (val
) + toindex_byte
,
679 SCHARS (this), 0, 1);
683 /* Copy element by element. */
686 register Lisp_Object elt
;
688 /* Fetch next element of `this' arg into `elt', or break if
689 `this' is exhausted. */
690 if (NILP (this)) break;
692 elt
= XCAR (this), this = XCDR (this);
693 else if (thisindex
>= thisleni
)
695 else if (STRINGP (this))
698 if (STRING_MULTIBYTE (this))
700 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, this,
703 XSETFASTINT (elt
, c
);
707 XSETFASTINT (elt
, SREF (this, thisindex
)); thisindex
++;
709 && XINT (elt
) >= 0200
710 && XINT (elt
) < 0400)
712 c
= unibyte_char_to_multibyte (XINT (elt
));
717 else if (BOOL_VECTOR_P (this))
720 byte
= XBOOL_VECTOR (this)->data
[thisindex
/ BOOL_VECTOR_BITS_PER_CHAR
];
721 if (byte
& (1 << (thisindex
% BOOL_VECTOR_BITS_PER_CHAR
)))
729 elt
= AREF (this, thisindex
);
733 /* Store this element into the result. */
740 else if (VECTORP (val
))
742 ASET (val
, toindex
, elt
);
749 toindex_byte
+= CHAR_STRING (XINT (elt
),
750 SDATA (val
) + toindex_byte
);
752 SSET (val
, toindex_byte
++, XINT (elt
));
758 XSETCDR (prev
, last_tail
);
760 if (num_textprops
> 0)
763 int last_to_end
= -1;
765 for (argnum
= 0; argnum
< num_textprops
; argnum
++)
767 this = args
[textprops
[argnum
].argnum
];
768 props
= text_property_list (this,
770 make_number (SCHARS (this)),
772 /* If successive arguments have properites, be sure that the
773 value of `composition' property be the copy. */
774 if (last_to_end
== textprops
[argnum
].to
)
775 make_composition_value_copy (props
);
776 add_text_properties_from_list (val
, props
,
777 make_number (textprops
[argnum
].to
));
778 last_to_end
= textprops
[argnum
].to
+ SCHARS (this);
786 static Lisp_Object string_char_byte_cache_string
;
787 static EMACS_INT string_char_byte_cache_charpos
;
788 static EMACS_INT string_char_byte_cache_bytepos
;
791 clear_string_char_byte_cache ()
793 string_char_byte_cache_string
= Qnil
;
796 /* Return the byte index corresponding to CHAR_INDEX in STRING. */
799 string_char_to_byte (string
, char_index
)
801 EMACS_INT char_index
;
804 EMACS_INT best_below
, best_below_byte
;
805 EMACS_INT best_above
, best_above_byte
;
807 best_below
= best_below_byte
= 0;
808 best_above
= SCHARS (string
);
809 best_above_byte
= SBYTES (string
);
810 if (best_above
== best_above_byte
)
813 if (EQ (string
, string_char_byte_cache_string
))
815 if (string_char_byte_cache_charpos
< char_index
)
817 best_below
= string_char_byte_cache_charpos
;
818 best_below_byte
= string_char_byte_cache_bytepos
;
822 best_above
= string_char_byte_cache_charpos
;
823 best_above_byte
= string_char_byte_cache_bytepos
;
827 if (char_index
- best_below
< best_above
- char_index
)
829 unsigned char *p
= SDATA (string
) + best_below_byte
;
831 while (best_below
< char_index
)
833 p
+= BYTES_BY_CHAR_HEAD (*p
);
836 i_byte
= p
- SDATA (string
);
840 unsigned char *p
= SDATA (string
) + best_above_byte
;
842 while (best_above
> char_index
)
845 while (!CHAR_HEAD_P (*p
)) p
--;
848 i_byte
= p
- SDATA (string
);
851 string_char_byte_cache_bytepos
= i_byte
;
852 string_char_byte_cache_charpos
= char_index
;
853 string_char_byte_cache_string
= string
;
858 /* Return the character index corresponding to BYTE_INDEX in STRING. */
861 string_byte_to_char (string
, byte_index
)
863 EMACS_INT byte_index
;
866 EMACS_INT best_below
, best_below_byte
;
867 EMACS_INT best_above
, best_above_byte
;
869 best_below
= best_below_byte
= 0;
870 best_above
= SCHARS (string
);
871 best_above_byte
= SBYTES (string
);
872 if (best_above
== best_above_byte
)
875 if (EQ (string
, string_char_byte_cache_string
))
877 if (string_char_byte_cache_bytepos
< byte_index
)
879 best_below
= string_char_byte_cache_charpos
;
880 best_below_byte
= string_char_byte_cache_bytepos
;
884 best_above
= string_char_byte_cache_charpos
;
885 best_above_byte
= string_char_byte_cache_bytepos
;
889 if (byte_index
- best_below_byte
< best_above_byte
- byte_index
)
891 unsigned char *p
= SDATA (string
) + best_below_byte
;
892 unsigned char *pend
= SDATA (string
) + byte_index
;
896 p
+= BYTES_BY_CHAR_HEAD (*p
);
900 i_byte
= p
- SDATA (string
);
904 unsigned char *p
= SDATA (string
) + best_above_byte
;
905 unsigned char *pbeg
= SDATA (string
) + byte_index
;
910 while (!CHAR_HEAD_P (*p
)) p
--;
914 i_byte
= p
- SDATA (string
);
917 string_char_byte_cache_bytepos
= i_byte
;
918 string_char_byte_cache_charpos
= i
;
919 string_char_byte_cache_string
= string
;
924 /* Convert STRING to a multibyte string. */
927 string_make_multibyte (string
)
935 if (STRING_MULTIBYTE (string
))
938 nbytes
= count_size_as_multibyte (SDATA (string
),
940 /* If all the chars are ASCII, they won't need any more bytes
941 once converted. In that case, we can return STRING itself. */
942 if (nbytes
== SBYTES (string
))
945 SAFE_ALLOCA (buf
, unsigned char *, nbytes
);
946 copy_text (SDATA (string
), buf
, SBYTES (string
),
949 ret
= make_multibyte_string (buf
, SCHARS (string
), nbytes
);
956 /* Convert STRING (if unibyte) to a multibyte string without changing
957 the number of characters. Characters 0200 trough 0237 are
958 converted to eight-bit characters. */
961 string_to_multibyte (string
)
969 if (STRING_MULTIBYTE (string
))
972 nbytes
= parse_str_to_multibyte (SDATA (string
), SBYTES (string
));
973 /* If all the chars are ASCII, they won't need any more bytes once
975 if (nbytes
== SBYTES (string
))
976 return make_multibyte_string (SDATA (string
), nbytes
, nbytes
);
978 SAFE_ALLOCA (buf
, unsigned char *, nbytes
);
979 bcopy (SDATA (string
), buf
, SBYTES (string
));
980 str_to_multibyte (buf
, nbytes
, SBYTES (string
));
982 ret
= make_multibyte_string (buf
, SCHARS (string
), nbytes
);
989 /* Convert STRING to a single-byte string. */
992 string_make_unibyte (string
)
1000 if (! STRING_MULTIBYTE (string
))
1003 nchars
= SCHARS (string
);
1005 SAFE_ALLOCA (buf
, unsigned char *, nchars
);
1006 copy_text (SDATA (string
), buf
, SBYTES (string
),
1009 ret
= make_unibyte_string (buf
, nchars
);
1015 DEFUN ("string-make-multibyte", Fstring_make_multibyte
, Sstring_make_multibyte
,
1017 doc
: /* Return the multibyte equivalent of STRING.
1018 If STRING is unibyte and contains non-ASCII characters, the function
1019 `unibyte-char-to-multibyte' is used to convert each unibyte character
1020 to a multibyte character. In this case, the returned string is a
1021 newly created string with no text properties. If STRING is multibyte
1022 or entirely ASCII, it is returned unchanged. In particular, when
1023 STRING is unibyte and entirely ASCII, the returned string is unibyte.
1024 \(When the characters are all ASCII, Emacs primitives will treat the
1025 string the same way whether it is unibyte or multibyte.) */)
1029 CHECK_STRING (string
);
1031 return string_make_multibyte (string
);
1034 DEFUN ("string-make-unibyte", Fstring_make_unibyte
, Sstring_make_unibyte
,
1036 doc
: /* Return the unibyte equivalent of STRING.
1037 Multibyte character codes are converted to unibyte according to
1038 `nonascii-translation-table' or, if that is nil, `nonascii-insert-offset'.
1039 If the lookup in the translation table fails, this function takes just
1040 the low 8 bits of each character. */)
1044 CHECK_STRING (string
);
1046 return string_make_unibyte (string
);
1049 DEFUN ("string-as-unibyte", Fstring_as_unibyte
, Sstring_as_unibyte
,
1051 doc
: /* Return a unibyte string with the same individual bytes as STRING.
1052 If STRING is unibyte, the result is STRING itself.
1053 Otherwise it is a newly created string, with no text properties.
1054 If STRING is multibyte and contains a character of charset
1055 `eight-bit', it is converted to the corresponding single byte. */)
1059 CHECK_STRING (string
);
1061 if (STRING_MULTIBYTE (string
))
1063 int bytes
= SBYTES (string
);
1064 unsigned char *str
= (unsigned char *) xmalloc (bytes
);
1066 bcopy (SDATA (string
), str
, bytes
);
1067 bytes
= str_as_unibyte (str
, bytes
);
1068 string
= make_unibyte_string (str
, bytes
);
1074 DEFUN ("string-as-multibyte", Fstring_as_multibyte
, Sstring_as_multibyte
,
1076 doc
: /* Return a multibyte string with the same individual bytes as STRING.
1077 If STRING is multibyte, the result is STRING itself.
1078 Otherwise it is a newly created string, with no text properties.
1080 If STRING is unibyte and contains an individual 8-bit byte (i.e. not
1081 part of a correct utf-8 sequence), it is converted to the corresponding
1082 multibyte character of charset `eight-bit'.
1083 See also `string-to-multibyte'.
1085 Beware, this often doesn't really do what you think it does.
1086 It is similar to (decode-coding-string STRING 'utf-8-emacs).
1087 If you're not sure, whether to use `string-as-multibyte' or
1088 `string-to-multibyte', use `string-to-multibyte'. */)
1092 CHECK_STRING (string
);
1094 if (! STRING_MULTIBYTE (string
))
1096 Lisp_Object new_string
;
1099 parse_str_as_multibyte (SDATA (string
),
1102 new_string
= make_uninit_multibyte_string (nchars
, nbytes
);
1103 bcopy (SDATA (string
), SDATA (new_string
),
1105 if (nbytes
!= SBYTES (string
))
1106 str_as_multibyte (SDATA (new_string
), nbytes
,
1107 SBYTES (string
), NULL
);
1108 string
= new_string
;
1109 STRING_SET_INTERVALS (string
, NULL_INTERVAL
);
1114 DEFUN ("string-to-multibyte", Fstring_to_multibyte
, Sstring_to_multibyte
,
1116 doc
: /* Return a multibyte string with the same individual chars as STRING.
1117 If STRING is multibyte, the result is STRING itself.
1118 Otherwise it is a newly created string, with no text properties.
1120 If STRING is unibyte and contains an 8-bit byte, it is converted to
1121 the corresponding multibyte character of charset `eight-bit'.
1123 This differs from `string-as-multibyte' by converting each byte of a correct
1124 utf-8 sequence to an eight-bit character, not just bytes that don't form a
1125 correct sequence. */)
1129 CHECK_STRING (string
);
1131 return string_to_multibyte (string
);
1135 DEFUN ("copy-alist", Fcopy_alist
, Scopy_alist
, 1, 1, 0,
1136 doc
: /* Return a copy of ALIST.
1137 This is an alist which represents the same mapping from objects to objects,
1138 but does not share the alist structure with ALIST.
1139 The objects mapped (cars and cdrs of elements of the alist)
1140 are shared, however.
1141 Elements of ALIST that are not conses are also shared. */)
1145 register Lisp_Object tem
;
1150 alist
= concat (1, &alist
, Lisp_Cons
, 0);
1151 for (tem
= alist
; CONSP (tem
); tem
= XCDR (tem
))
1153 register Lisp_Object car
;
1157 XSETCAR (tem
, Fcons (XCAR (car
), XCDR (car
)));
1162 DEFUN ("substring", Fsubstring
, Ssubstring
, 2, 3, 0,
1163 doc
: /* Return a substring of STRING, starting at index FROM and ending before TO.
1164 TO may be nil or omitted; then the substring runs to the end of STRING.
1165 FROM and TO start at 0. If either is negative, it counts from the end.
1167 This function allows vectors as well as strings. */)
1170 register Lisp_Object from
, to
;
1175 int from_char
, to_char
;
1176 int from_byte
= 0, to_byte
= 0;
1178 CHECK_VECTOR_OR_STRING (string
);
1179 CHECK_NUMBER (from
);
1181 if (STRINGP (string
))
1183 size
= SCHARS (string
);
1184 size_byte
= SBYTES (string
);
1187 size
= ASIZE (string
);
1192 to_byte
= size_byte
;
1198 to_char
= XINT (to
);
1202 if (STRINGP (string
))
1203 to_byte
= string_char_to_byte (string
, to_char
);
1206 from_char
= XINT (from
);
1209 if (STRINGP (string
))
1210 from_byte
= string_char_to_byte (string
, from_char
);
1212 if (!(0 <= from_char
&& from_char
<= to_char
&& to_char
<= size
))
1213 args_out_of_range_3 (string
, make_number (from_char
),
1214 make_number (to_char
));
1216 if (STRINGP (string
))
1218 res
= make_specified_string (SDATA (string
) + from_byte
,
1219 to_char
- from_char
, to_byte
- from_byte
,
1220 STRING_MULTIBYTE (string
));
1221 copy_text_properties (make_number (from_char
), make_number (to_char
),
1222 string
, make_number (0), res
, Qnil
);
1225 res
= Fvector (to_char
- from_char
, &AREF (string
, from_char
));
1231 DEFUN ("substring-no-properties", Fsubstring_no_properties
, Ssubstring_no_properties
, 1, 3, 0,
1232 doc
: /* Return a substring of STRING, without text properties.
1233 It starts at index FROM and ending before TO.
1234 TO may be nil or omitted; then the substring runs to the end of STRING.
1235 If FROM is nil or omitted, the substring starts at the beginning of STRING.
1236 If FROM or TO is negative, it counts from the end.
1238 With one argument, just copy STRING without its properties. */)
1241 register Lisp_Object from
, to
;
1243 int size
, size_byte
;
1244 int from_char
, to_char
;
1245 int from_byte
, to_byte
;
1247 CHECK_STRING (string
);
1249 size
= SCHARS (string
);
1250 size_byte
= SBYTES (string
);
1253 from_char
= from_byte
= 0;
1256 CHECK_NUMBER (from
);
1257 from_char
= XINT (from
);
1261 from_byte
= string_char_to_byte (string
, from_char
);
1267 to_byte
= size_byte
;
1273 to_char
= XINT (to
);
1277 to_byte
= string_char_to_byte (string
, to_char
);
1280 if (!(0 <= from_char
&& from_char
<= to_char
&& to_char
<= size
))
1281 args_out_of_range_3 (string
, make_number (from_char
),
1282 make_number (to_char
));
1284 return make_specified_string (SDATA (string
) + from_byte
,
1285 to_char
- from_char
, to_byte
- from_byte
,
1286 STRING_MULTIBYTE (string
));
1289 /* Extract a substring of STRING, giving start and end positions
1290 both in characters and in bytes. */
1293 substring_both (string
, from
, from_byte
, to
, to_byte
)
1295 int from
, from_byte
, to
, to_byte
;
1301 CHECK_VECTOR_OR_STRING (string
);
1303 if (STRINGP (string
))
1305 size
= SCHARS (string
);
1306 size_byte
= SBYTES (string
);
1309 size
= ASIZE (string
);
1311 if (!(0 <= from
&& from
<= to
&& to
<= size
))
1312 args_out_of_range_3 (string
, make_number (from
), make_number (to
));
1314 if (STRINGP (string
))
1316 res
= make_specified_string (SDATA (string
) + from_byte
,
1317 to
- from
, to_byte
- from_byte
,
1318 STRING_MULTIBYTE (string
));
1319 copy_text_properties (make_number (from
), make_number (to
),
1320 string
, make_number (0), res
, Qnil
);
1323 res
= Fvector (to
- from
, &AREF (string
, from
));
1328 DEFUN ("nthcdr", Fnthcdr
, Snthcdr
, 2, 2, 0,
1329 doc
: /* Take cdr N times on LIST, returns the result. */)
1332 register Lisp_Object list
;
1334 register int i
, num
;
1337 for (i
= 0; i
< num
&& !NILP (list
); i
++)
1340 CHECK_LIST_CONS (list
, list
);
1346 DEFUN ("nth", Fnth
, Snth
, 2, 2, 0,
1347 doc
: /* Return the Nth element of LIST.
1348 N counts from zero. If LIST is not that long, nil is returned. */)
1350 Lisp_Object n
, list
;
1352 return Fcar (Fnthcdr (n
, list
));
1355 DEFUN ("elt", Felt
, Selt
, 2, 2, 0,
1356 doc
: /* Return element of SEQUENCE at index N. */)
1358 register Lisp_Object sequence
, n
;
1361 if (CONSP (sequence
) || NILP (sequence
))
1362 return Fcar (Fnthcdr (n
, sequence
));
1364 /* Faref signals a "not array" error, so check here. */
1365 CHECK_ARRAY (sequence
, Qsequencep
);
1366 return Faref (sequence
, n
);
1369 DEFUN ("member", Fmember
, Smember
, 2, 2, 0,
1370 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
1371 The value is actually the tail of LIST whose car is ELT. */)
1373 register Lisp_Object elt
;
1376 register Lisp_Object tail
;
1377 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1379 register Lisp_Object tem
;
1380 CHECK_LIST_CONS (tail
, list
);
1382 if (! NILP (Fequal (elt
, tem
)))
1389 DEFUN ("memq", Fmemq
, Smemq
, 2, 2, 0,
1390 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
1391 The value is actually the tail of LIST whose car is ELT. */)
1393 register Lisp_Object elt
, list
;
1397 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1401 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1405 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1416 DEFUN ("memql", Fmemql
, Smemql
, 2, 2, 0,
1417 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `eql'.
1418 The value is actually the tail of LIST whose car is ELT. */)
1420 register Lisp_Object elt
;
1423 register Lisp_Object tail
;
1426 return Fmemq (elt
, list
);
1428 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1430 register Lisp_Object tem
;
1431 CHECK_LIST_CONS (tail
, list
);
1433 if (FLOATP (tem
) && internal_equal (elt
, tem
, 0, 0))
1440 DEFUN ("assq", Fassq
, Sassq
, 2, 2, 0,
1441 doc
: /* Return non-nil if KEY is `eq' to the car of an element of LIST.
1442 The value is actually the first element of LIST whose car is KEY.
1443 Elements of LIST that are not conses are ignored. */)
1445 Lisp_Object key
, list
;
1450 || (CONSP (XCAR (list
))
1451 && EQ (XCAR (XCAR (list
)), key
)))
1456 || (CONSP (XCAR (list
))
1457 && EQ (XCAR (XCAR (list
)), key
)))
1462 || (CONSP (XCAR (list
))
1463 && EQ (XCAR (XCAR (list
)), key
)))
1473 /* Like Fassq but never report an error and do not allow quits.
1474 Use only on lists known never to be circular. */
1477 assq_no_quit (key
, list
)
1478 Lisp_Object key
, list
;
1481 && (!CONSP (XCAR (list
))
1482 || !EQ (XCAR (XCAR (list
)), key
)))
1485 return CAR_SAFE (list
);
1488 DEFUN ("assoc", Fassoc
, Sassoc
, 2, 2, 0,
1489 doc
: /* Return non-nil if KEY is `equal' to the car of an element of LIST.
1490 The value is actually the first element of LIST whose car equals KEY. */)
1492 Lisp_Object key
, list
;
1499 || (CONSP (XCAR (list
))
1500 && (car
= XCAR (XCAR (list
)),
1501 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1506 || (CONSP (XCAR (list
))
1507 && (car
= XCAR (XCAR (list
)),
1508 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1513 || (CONSP (XCAR (list
))
1514 && (car
= XCAR (XCAR (list
)),
1515 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1525 /* Like Fassoc but never report an error and do not allow quits.
1526 Use only on lists known never to be circular. */
1529 assoc_no_quit (key
, list
)
1530 Lisp_Object key
, list
;
1533 && (!CONSP (XCAR (list
))
1534 || (!EQ (XCAR (XCAR (list
)), key
)
1535 && NILP (Fequal (XCAR (XCAR (list
)), key
)))))
1538 return CONSP (list
) ? XCAR (list
) : Qnil
;
1541 DEFUN ("rassq", Frassq
, Srassq
, 2, 2, 0,
1542 doc
: /* Return non-nil if KEY is `eq' to the cdr of an element of LIST.
1543 The value is actually the first element of LIST whose cdr is KEY. */)
1545 register Lisp_Object key
;
1551 || (CONSP (XCAR (list
))
1552 && EQ (XCDR (XCAR (list
)), key
)))
1557 || (CONSP (XCAR (list
))
1558 && EQ (XCDR (XCAR (list
)), key
)))
1563 || (CONSP (XCAR (list
))
1564 && EQ (XCDR (XCAR (list
)), key
)))
1574 DEFUN ("rassoc", Frassoc
, Srassoc
, 2, 2, 0,
1575 doc
: /* Return non-nil if KEY is `equal' to the cdr of an element of LIST.
1576 The value is actually the first element of LIST whose cdr equals KEY. */)
1578 Lisp_Object key
, list
;
1585 || (CONSP (XCAR (list
))
1586 && (cdr
= XCDR (XCAR (list
)),
1587 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1592 || (CONSP (XCAR (list
))
1593 && (cdr
= XCDR (XCAR (list
)),
1594 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1599 || (CONSP (XCAR (list
))
1600 && (cdr
= XCDR (XCAR (list
)),
1601 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1611 DEFUN ("delq", Fdelq
, Sdelq
, 2, 2, 0,
1612 doc
: /* Delete by side effect any occurrences of ELT as a member of LIST.
1613 The modified LIST is returned. Comparison is done with `eq'.
1614 If the first member of LIST is ELT, there is no way to remove it by side effect;
1615 therefore, write `(setq foo (delq element foo))'
1616 to be sure of changing the value of `foo'. */)
1618 register Lisp_Object elt
;
1621 register Lisp_Object tail
, prev
;
1622 register Lisp_Object tem
;
1626 while (!NILP (tail
))
1628 CHECK_LIST_CONS (tail
, list
);
1635 Fsetcdr (prev
, XCDR (tail
));
1645 DEFUN ("delete", Fdelete
, Sdelete
, 2, 2, 0,
1646 doc
: /* Delete by side effect any occurrences of ELT as a member of SEQ.
1647 SEQ must be a list, a vector, or a string.
1648 The modified SEQ is returned. Comparison is done with `equal'.
1649 If SEQ is not a list, or the first member of SEQ is ELT, deleting it
1650 is not a side effect; it is simply using a different sequence.
1651 Therefore, write `(setq foo (delete element foo))'
1652 to be sure of changing the value of `foo'. */)
1654 Lisp_Object elt
, seq
;
1660 for (i
= n
= 0; i
< ASIZE (seq
); ++i
)
1661 if (NILP (Fequal (AREF (seq
, i
), elt
)))
1664 if (n
!= ASIZE (seq
))
1666 struct Lisp_Vector
*p
= allocate_vector (n
);
1668 for (i
= n
= 0; i
< ASIZE (seq
); ++i
)
1669 if (NILP (Fequal (AREF (seq
, i
), elt
)))
1670 p
->contents
[n
++] = AREF (seq
, i
);
1672 XSETVECTOR (seq
, p
);
1675 else if (STRINGP (seq
))
1677 EMACS_INT i
, ibyte
, nchars
, nbytes
, cbytes
;
1680 for (i
= nchars
= nbytes
= ibyte
= 0;
1682 ++i
, ibyte
+= cbytes
)
1684 if (STRING_MULTIBYTE (seq
))
1686 c
= STRING_CHAR (SDATA (seq
) + ibyte
,
1687 SBYTES (seq
) - ibyte
);
1688 cbytes
= CHAR_BYTES (c
);
1696 if (!INTEGERP (elt
) || c
!= XINT (elt
))
1703 if (nchars
!= SCHARS (seq
))
1707 tem
= make_uninit_multibyte_string (nchars
, nbytes
);
1708 if (!STRING_MULTIBYTE (seq
))
1709 STRING_SET_UNIBYTE (tem
);
1711 for (i
= nchars
= nbytes
= ibyte
= 0;
1713 ++i
, ibyte
+= cbytes
)
1715 if (STRING_MULTIBYTE (seq
))
1717 c
= STRING_CHAR (SDATA (seq
) + ibyte
,
1718 SBYTES (seq
) - ibyte
);
1719 cbytes
= CHAR_BYTES (c
);
1727 if (!INTEGERP (elt
) || c
!= XINT (elt
))
1729 unsigned char *from
= SDATA (seq
) + ibyte
;
1730 unsigned char *to
= SDATA (tem
) + nbytes
;
1736 for (n
= cbytes
; n
--; )
1746 Lisp_Object tail
, prev
;
1748 for (tail
= seq
, prev
= Qnil
; CONSP (tail
); tail
= XCDR (tail
))
1750 CHECK_LIST_CONS (tail
, seq
);
1752 if (!NILP (Fequal (elt
, XCAR (tail
))))
1757 Fsetcdr (prev
, XCDR (tail
));
1768 DEFUN ("nreverse", Fnreverse
, Snreverse
, 1, 1, 0,
1769 doc
: /* Reverse LIST by modifying cdr pointers.
1770 Return the reversed list. */)
1774 register Lisp_Object prev
, tail
, next
;
1776 if (NILP (list
)) return list
;
1779 while (!NILP (tail
))
1782 CHECK_LIST_CONS (tail
, list
);
1784 Fsetcdr (tail
, prev
);
1791 DEFUN ("reverse", Freverse
, Sreverse
, 1, 1, 0,
1792 doc
: /* Reverse LIST, copying. Return the reversed list.
1793 See also the function `nreverse', which is used more often. */)
1799 for (new = Qnil
; CONSP (list
); list
= XCDR (list
))
1802 new = Fcons (XCAR (list
), new);
1804 CHECK_LIST_END (list
, list
);
1808 Lisp_Object
merge ();
1810 DEFUN ("sort", Fsort
, Ssort
, 2, 2, 0,
1811 doc
: /* Sort LIST, stably, comparing elements using PREDICATE.
1812 Returns the sorted list. LIST is modified by side effects.
1813 PREDICATE is called with two elements of LIST, and should return non-nil
1814 if the first element should sort before the second. */)
1816 Lisp_Object list
, predicate
;
1818 Lisp_Object front
, back
;
1819 register Lisp_Object len
, tem
;
1820 struct gcpro gcpro1
, gcpro2
;
1821 register int length
;
1824 len
= Flength (list
);
1825 length
= XINT (len
);
1829 XSETINT (len
, (length
/ 2) - 1);
1830 tem
= Fnthcdr (len
, list
);
1832 Fsetcdr (tem
, Qnil
);
1834 GCPRO2 (front
, back
);
1835 front
= Fsort (front
, predicate
);
1836 back
= Fsort (back
, predicate
);
1838 return merge (front
, back
, predicate
);
1842 merge (org_l1
, org_l2
, pred
)
1843 Lisp_Object org_l1
, org_l2
;
1847 register Lisp_Object tail
;
1849 register Lisp_Object l1
, l2
;
1850 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1857 /* It is sufficient to protect org_l1 and org_l2.
1858 When l1 and l2 are updated, we copy the new values
1859 back into the org_ vars. */
1860 GCPRO4 (org_l1
, org_l2
, pred
, value
);
1880 tem
= call2 (pred
, Fcar (l2
), Fcar (l1
));
1896 Fsetcdr (tail
, tem
);
1902 #if 0 /* Unsafe version. */
1903 DEFUN ("plist-get", Fplist_get
, Splist_get
, 2, 2, 0,
1904 doc
: /* Extract a value from a property list.
1905 PLIST is a property list, which is a list of the form
1906 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
1907 corresponding to the given PROP, or nil if PROP is not
1908 one of the properties on the list. */)
1916 CONSP (tail
) && CONSP (XCDR (tail
));
1917 tail
= XCDR (XCDR (tail
)))
1919 if (EQ (prop
, XCAR (tail
)))
1920 return XCAR (XCDR (tail
));
1922 /* This function can be called asynchronously
1923 (setup_coding_system). Don't QUIT in that case. */
1924 if (!interrupt_input_blocked
)
1928 CHECK_LIST_END (tail
, prop
);
1934 /* This does not check for quits. That is safe since it must terminate. */
1936 DEFUN ("plist-get", Fplist_get
, Splist_get
, 2, 2, 0,
1937 doc
: /* Extract a value from a property list.
1938 PLIST is a property list, which is a list of the form
1939 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
1940 corresponding to the given PROP, or nil if PROP is not one of the
1941 properties on the list. This function never signals an error. */)
1946 Lisp_Object tail
, halftail
;
1948 /* halftail is used to detect circular lists. */
1949 tail
= halftail
= plist
;
1950 while (CONSP (tail
) && CONSP (XCDR (tail
)))
1952 if (EQ (prop
, XCAR (tail
)))
1953 return XCAR (XCDR (tail
));
1955 tail
= XCDR (XCDR (tail
));
1956 halftail
= XCDR (halftail
);
1957 if (EQ (tail
, halftail
))
1964 DEFUN ("get", Fget
, Sget
, 2, 2, 0,
1965 doc
: /* Return the value of SYMBOL's PROPNAME property.
1966 This is the last value stored with `(put SYMBOL PROPNAME VALUE)'. */)
1968 Lisp_Object symbol
, propname
;
1970 CHECK_SYMBOL (symbol
);
1971 return Fplist_get (XSYMBOL (symbol
)->plist
, propname
);
1974 DEFUN ("plist-put", Fplist_put
, Splist_put
, 3, 3, 0,
1975 doc
: /* Change value in PLIST of PROP to VAL.
1976 PLIST is a property list, which is a list of the form
1977 \(PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol and VAL is any object.
1978 If PROP is already a property on the list, its value is set to VAL,
1979 otherwise the new PROP VAL pair is added. The new plist is returned;
1980 use `(setq x (plist-put x prop val))' to be sure to use the new value.
1981 The PLIST is modified by side effects. */)
1984 register Lisp_Object prop
;
1987 register Lisp_Object tail
, prev
;
1988 Lisp_Object newcell
;
1990 for (tail
= plist
; CONSP (tail
) && CONSP (XCDR (tail
));
1991 tail
= XCDR (XCDR (tail
)))
1993 if (EQ (prop
, XCAR (tail
)))
1995 Fsetcar (XCDR (tail
), val
);
2002 newcell
= Fcons (prop
, Fcons (val
, NILP (prev
) ? plist
: XCDR (XCDR (prev
))));
2006 Fsetcdr (XCDR (prev
), newcell
);
2010 DEFUN ("put", Fput
, Sput
, 3, 3, 0,
2011 doc
: /* Store SYMBOL's PROPNAME property with value VALUE.
2012 It can be retrieved with `(get SYMBOL PROPNAME)'. */)
2013 (symbol
, propname
, value
)
2014 Lisp_Object symbol
, propname
, value
;
2016 CHECK_SYMBOL (symbol
);
2017 XSYMBOL (symbol
)->plist
2018 = Fplist_put (XSYMBOL (symbol
)->plist
, propname
, value
);
2022 DEFUN ("lax-plist-get", Flax_plist_get
, Slax_plist_get
, 2, 2, 0,
2023 doc
: /* Extract a value from a property list, comparing with `equal'.
2024 PLIST is a property list, which is a list of the form
2025 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
2026 corresponding to the given PROP, or nil if PROP is not
2027 one of the properties on the list. */)
2035 CONSP (tail
) && CONSP (XCDR (tail
));
2036 tail
= XCDR (XCDR (tail
)))
2038 if (! NILP (Fequal (prop
, XCAR (tail
))))
2039 return XCAR (XCDR (tail
));
2044 CHECK_LIST_END (tail
, prop
);
2049 DEFUN ("lax-plist-put", Flax_plist_put
, Slax_plist_put
, 3, 3, 0,
2050 doc
: /* Change value in PLIST of PROP to VAL, comparing with `equal'.
2051 PLIST is a property list, which is a list of the form
2052 \(PROP1 VALUE1 PROP2 VALUE2 ...). PROP and VAL are any objects.
2053 If PROP is already a property on the list, its value is set to VAL,
2054 otherwise the new PROP VAL pair is added. The new plist is returned;
2055 use `(setq x (lax-plist-put x prop val))' to be sure to use the new value.
2056 The PLIST is modified by side effects. */)
2059 register Lisp_Object prop
;
2062 register Lisp_Object tail
, prev
;
2063 Lisp_Object newcell
;
2065 for (tail
= plist
; CONSP (tail
) && CONSP (XCDR (tail
));
2066 tail
= XCDR (XCDR (tail
)))
2068 if (! NILP (Fequal (prop
, XCAR (tail
))))
2070 Fsetcar (XCDR (tail
), val
);
2077 newcell
= Fcons (prop
, Fcons (val
, Qnil
));
2081 Fsetcdr (XCDR (prev
), newcell
);
2085 DEFUN ("eql", Feql
, Seql
, 2, 2, 0,
2086 doc
: /* Return t if the two args are the same Lisp object.
2087 Floating-point numbers of equal value are `eql', but they may not be `eq'. */)
2089 Lisp_Object obj1
, obj2
;
2092 return internal_equal (obj1
, obj2
, 0, 0) ? Qt
: Qnil
;
2094 return EQ (obj1
, obj2
) ? Qt
: Qnil
;
2097 DEFUN ("equal", Fequal
, Sequal
, 2, 2, 0,
2098 doc
: /* Return t if two Lisp objects have similar structure and contents.
2099 They must have the same data type.
2100 Conses are compared by comparing the cars and the cdrs.
2101 Vectors and strings are compared element by element.
2102 Numbers are compared by value, but integers cannot equal floats.
2103 (Use `=' if you want integers and floats to be able to be equal.)
2104 Symbols must match exactly. */)
2106 register Lisp_Object o1
, o2
;
2108 return internal_equal (o1
, o2
, 0, 0) ? Qt
: Qnil
;
2111 DEFUN ("equal-including-properties", Fequal_including_properties
, Sequal_including_properties
, 2, 2, 0,
2112 doc
: /* Return t if two Lisp objects have similar structure and contents.
2113 This is like `equal' except that it compares the text properties
2114 of strings. (`equal' ignores text properties.) */)
2116 register Lisp_Object o1
, o2
;
2118 return internal_equal (o1
, o2
, 0, 1) ? Qt
: Qnil
;
2121 /* DEPTH is current depth of recursion. Signal an error if it
2123 PROPS, if non-nil, means compare string text properties too. */
2126 internal_equal (o1
, o2
, depth
, props
)
2127 register Lisp_Object o1
, o2
;
2131 error ("Stack overflow in equal");
2137 if (XTYPE (o1
) != XTYPE (o2
))
2146 d1
= extract_float (o1
);
2147 d2
= extract_float (o2
);
2148 /* If d is a NaN, then d != d. Two NaNs should be `equal' even
2149 though they are not =. */
2150 return d1
== d2
|| (d1
!= d1
&& d2
!= d2
);
2154 if (!internal_equal (XCAR (o1
), XCAR (o2
), depth
+ 1, props
))
2161 if (XMISCTYPE (o1
) != XMISCTYPE (o2
))
2165 if (!internal_equal (OVERLAY_START (o1
), OVERLAY_START (o2
),
2167 || !internal_equal (OVERLAY_END (o1
), OVERLAY_END (o2
),
2170 o1
= XOVERLAY (o1
)->plist
;
2171 o2
= XOVERLAY (o2
)->plist
;
2176 return (XMARKER (o1
)->buffer
== XMARKER (o2
)->buffer
2177 && (XMARKER (o1
)->buffer
== 0
2178 || XMARKER (o1
)->bytepos
== XMARKER (o2
)->bytepos
));
2182 case Lisp_Vectorlike
:
2185 EMACS_INT size
= ASIZE (o1
);
2186 /* Pseudovectors have the type encoded in the size field, so this test
2187 actually checks that the objects have the same type as well as the
2189 if (ASIZE (o2
) != size
)
2191 /* Boolvectors are compared much like strings. */
2192 if (BOOL_VECTOR_P (o1
))
2195 = ((XBOOL_VECTOR (o1
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
2196 / BOOL_VECTOR_BITS_PER_CHAR
);
2198 if (XBOOL_VECTOR (o1
)->size
!= XBOOL_VECTOR (o2
)->size
)
2200 if (bcmp (XBOOL_VECTOR (o1
)->data
, XBOOL_VECTOR (o2
)->data
,
2205 if (WINDOW_CONFIGURATIONP (o1
))
2206 return compare_window_configurations (o1
, o2
, 0);
2208 /* Aside from them, only true vectors, char-tables, compiled
2209 functions, and fonts (font-spec, font-entity, font-ojbect)
2210 are sensible to compare, so eliminate the others now. */
2211 if (size
& PSEUDOVECTOR_FLAG
)
2213 if (!(size
& (PVEC_COMPILED
2214 | PVEC_CHAR_TABLE
| PVEC_SUB_CHAR_TABLE
| PVEC_FONT
)))
2216 size
&= PSEUDOVECTOR_SIZE_MASK
;
2218 for (i
= 0; i
< size
; i
++)
2223 if (!internal_equal (v1
, v2
, depth
+ 1, props
))
2231 if (SCHARS (o1
) != SCHARS (o2
))
2233 if (SBYTES (o1
) != SBYTES (o2
))
2235 if (bcmp (SDATA (o1
), SDATA (o2
),
2238 if (props
&& !compare_string_intervals (o1
, o2
))
2244 case Lisp_Type_Limit
:
2251 extern Lisp_Object
Fmake_char_internal ();
2253 DEFUN ("fillarray", Ffillarray
, Sfillarray
, 2, 2, 0,
2254 doc
: /* Store each element of ARRAY with ITEM.
2255 ARRAY is a vector, string, char-table, or bool-vector. */)
2257 Lisp_Object array
, item
;
2259 register int size
, index
, charval
;
2260 if (VECTORP (array
))
2262 register Lisp_Object
*p
= XVECTOR (array
)->contents
;
2263 size
= ASIZE (array
);
2264 for (index
= 0; index
< size
; index
++)
2267 else if (CHAR_TABLE_P (array
))
2271 for (i
= 0; i
< (1 << CHARTAB_SIZE_BITS_0
); i
++)
2272 XCHAR_TABLE (array
)->contents
[i
] = item
;
2273 XCHAR_TABLE (array
)->defalt
= item
;
2275 else if (STRINGP (array
))
2277 register unsigned char *p
= SDATA (array
);
2278 CHECK_NUMBER (item
);
2279 charval
= XINT (item
);
2280 size
= SCHARS (array
);
2281 if (STRING_MULTIBYTE (array
))
2283 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
2284 int len
= CHAR_STRING (charval
, str
);
2285 int size_byte
= SBYTES (array
);
2286 unsigned char *p1
= p
, *endp
= p
+ size_byte
;
2289 if (size
!= size_byte
)
2292 int this_len
= MULTIBYTE_FORM_LENGTH (p1
, endp
- p1
);
2293 if (len
!= this_len
)
2294 error ("Attempt to change byte length of a string");
2297 for (i
= 0; i
< size_byte
; i
++)
2298 *p
++ = str
[i
% len
];
2301 for (index
= 0; index
< size
; index
++)
2304 else if (BOOL_VECTOR_P (array
))
2306 register unsigned char *p
= XBOOL_VECTOR (array
)->data
;
2308 = ((XBOOL_VECTOR (array
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
2309 / BOOL_VECTOR_BITS_PER_CHAR
);
2311 charval
= (! NILP (item
) ? -1 : 0);
2312 for (index
= 0; index
< size_in_chars
- 1; index
++)
2314 if (index
< size_in_chars
)
2316 /* Mask out bits beyond the vector size. */
2317 if (XBOOL_VECTOR (array
)->size
% BOOL_VECTOR_BITS_PER_CHAR
)
2318 charval
&= (1 << (XBOOL_VECTOR (array
)->size
% BOOL_VECTOR_BITS_PER_CHAR
)) - 1;
2323 wrong_type_argument (Qarrayp
, array
);
2327 DEFUN ("clear-string", Fclear_string
, Sclear_string
,
2329 doc
: /* Clear the contents of STRING.
2330 This makes STRING unibyte and may change its length. */)
2335 CHECK_STRING (string
);
2336 len
= SBYTES (string
);
2337 bzero (SDATA (string
), len
);
2338 STRING_SET_CHARS (string
, len
);
2339 STRING_SET_UNIBYTE (string
);
2349 Lisp_Object args
[2];
2352 return Fnconc (2, args
);
2354 return Fnconc (2, &s1
);
2355 #endif /* NO_ARG_ARRAY */
2358 DEFUN ("nconc", Fnconc
, Snconc
, 0, MANY
, 0,
2359 doc
: /* Concatenate any number of lists by altering them.
2360 Only the last argument is not altered, and need not be a list.
2361 usage: (nconc &rest LISTS) */)
2366 register int argnum
;
2367 register Lisp_Object tail
, tem
, val
;
2371 for (argnum
= 0; argnum
< nargs
; argnum
++)
2374 if (NILP (tem
)) continue;
2379 if (argnum
+ 1 == nargs
) break;
2381 CHECK_LIST_CONS (tem
, tem
);
2390 tem
= args
[argnum
+ 1];
2391 Fsetcdr (tail
, tem
);
2393 args
[argnum
+ 1] = tail
;
2399 /* This is the guts of all mapping functions.
2400 Apply FN to each element of SEQ, one by one,
2401 storing the results into elements of VALS, a C vector of Lisp_Objects.
2402 LENI is the length of VALS, which should also be the length of SEQ. */
2405 mapcar1 (leni
, vals
, fn
, seq
)
2408 Lisp_Object fn
, seq
;
2410 register Lisp_Object tail
;
2413 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2417 /* Don't let vals contain any garbage when GC happens. */
2418 for (i
= 0; i
< leni
; i
++)
2421 GCPRO3 (dummy
, fn
, seq
);
2423 gcpro1
.nvars
= leni
;
2427 /* We need not explicitly protect `tail' because it is used only on lists, and
2428 1) lists are not relocated and 2) the list is marked via `seq' so will not
2433 for (i
= 0; i
< leni
; i
++)
2435 dummy
= call1 (fn
, AREF (seq
, i
));
2440 else if (BOOL_VECTOR_P (seq
))
2442 for (i
= 0; i
< leni
; i
++)
2445 byte
= XBOOL_VECTOR (seq
)->data
[i
/ BOOL_VECTOR_BITS_PER_CHAR
];
2446 dummy
= (byte
& (1 << (i
% BOOL_VECTOR_BITS_PER_CHAR
))) ? Qt
: Qnil
;
2447 dummy
= call1 (fn
, dummy
);
2452 else if (STRINGP (seq
))
2456 for (i
= 0, i_byte
= 0; i
< leni
;)
2461 FETCH_STRING_CHAR_ADVANCE (c
, seq
, i
, i_byte
);
2462 XSETFASTINT (dummy
, c
);
2463 dummy
= call1 (fn
, dummy
);
2465 vals
[i_before
] = dummy
;
2468 else /* Must be a list, since Flength did not get an error */
2471 for (i
= 0; i
< leni
&& CONSP (tail
); i
++)
2473 dummy
= call1 (fn
, XCAR (tail
));
2483 DEFUN ("mapconcat", Fmapconcat
, Smapconcat
, 3, 3, 0,
2484 doc
: /* Apply FUNCTION to each element of SEQUENCE, and concat the results as strings.
2485 In between each pair of results, stick in SEPARATOR. Thus, " " as
2486 SEPARATOR results in spaces between the values returned by FUNCTION.
2487 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2488 (function
, sequence
, separator
)
2489 Lisp_Object function
, sequence
, separator
;
2494 register Lisp_Object
*args
;
2496 struct gcpro gcpro1
;
2500 len
= Flength (sequence
);
2501 if (CHAR_TABLE_P (sequence
))
2502 wrong_type_argument (Qlistp
, sequence
);
2504 nargs
= leni
+ leni
- 1;
2505 if (nargs
< 0) return empty_unibyte_string
;
2507 SAFE_ALLOCA_LISP (args
, nargs
);
2510 mapcar1 (leni
, args
, function
, sequence
);
2513 for (i
= leni
- 1; i
> 0; i
--)
2514 args
[i
+ i
] = args
[i
];
2516 for (i
= 1; i
< nargs
; i
+= 2)
2517 args
[i
] = separator
;
2519 ret
= Fconcat (nargs
, args
);
2525 DEFUN ("mapcar", Fmapcar
, Smapcar
, 2, 2, 0,
2526 doc
: /* Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
2527 The result is a list just as long as SEQUENCE.
2528 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2529 (function
, sequence
)
2530 Lisp_Object function
, sequence
;
2532 register Lisp_Object len
;
2534 register Lisp_Object
*args
;
2538 len
= Flength (sequence
);
2539 if (CHAR_TABLE_P (sequence
))
2540 wrong_type_argument (Qlistp
, sequence
);
2541 leni
= XFASTINT (len
);
2543 SAFE_ALLOCA_LISP (args
, leni
);
2545 mapcar1 (leni
, args
, function
, sequence
);
2547 ret
= Flist (leni
, args
);
2553 DEFUN ("mapc", Fmapc
, Smapc
, 2, 2, 0,
2554 doc
: /* Apply FUNCTION to each element of SEQUENCE for side effects only.
2555 Unlike `mapcar', don't accumulate the results. Return SEQUENCE.
2556 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2557 (function
, sequence
)
2558 Lisp_Object function
, sequence
;
2562 leni
= XFASTINT (Flength (sequence
));
2563 if (CHAR_TABLE_P (sequence
))
2564 wrong_type_argument (Qlistp
, sequence
);
2565 mapcar1 (leni
, 0, function
, sequence
);
2570 /* Anything that calls this function must protect from GC! */
2572 DEFUN ("y-or-n-p", Fy_or_n_p
, Sy_or_n_p
, 1, 1, 0,
2573 doc
: /* Ask user a "y or n" question. Return t if answer is "y".
2574 Takes one argument, which is the string to display to ask the question.
2575 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
2576 No confirmation of the answer is requested; a single character is enough.
2577 Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses
2578 the bindings in `query-replace-map'; see the documentation of that variable
2579 for more information. In this case, the useful bindings are `act', `skip',
2580 `recenter', and `quit'.\)
2582 Under a windowing system a dialog box will be used if `last-nonmenu-event'
2583 is nil and `use-dialog-box' is non-nil. */)
2587 register Lisp_Object obj
, key
, def
, map
;
2588 register int answer
;
2589 Lisp_Object xprompt
;
2590 Lisp_Object args
[2];
2591 struct gcpro gcpro1
, gcpro2
;
2592 int count
= SPECPDL_INDEX ();
2594 specbind (Qcursor_in_echo_area
, Qt
);
2596 map
= Fsymbol_value (intern ("query-replace-map"));
2598 CHECK_STRING (prompt
);
2600 GCPRO2 (prompt
, xprompt
);
2602 #ifdef HAVE_WINDOW_SYSTEM
2603 if (display_hourglass_p
)
2604 cancel_hourglass ();
2611 if (FRAME_WINDOW_P (SELECTED_FRAME ())
2612 && (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
2616 Lisp_Object pane
, menu
;
2617 redisplay_preserve_echo_area (3);
2618 pane
= Fcons (Fcons (build_string ("Yes"), Qt
),
2619 Fcons (Fcons (build_string ("No"), Qnil
),
2621 menu
= Fcons (prompt
, pane
);
2622 obj
= Fx_popup_dialog (Qt
, menu
, Qnil
);
2623 answer
= !NILP (obj
);
2626 #endif /* HAVE_MENUS */
2627 cursor_in_echo_area
= 1;
2628 choose_minibuf_frame ();
2631 Lisp_Object pargs
[3];
2633 /* Colorize prompt according to `minibuffer-prompt' face. */
2634 pargs
[0] = build_string ("%s(y or n) ");
2635 pargs
[1] = intern ("face");
2636 pargs
[2] = intern ("minibuffer-prompt");
2637 args
[0] = Fpropertize (3, pargs
);
2642 if (minibuffer_auto_raise
)
2644 Lisp_Object mini_frame
;
2646 mini_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
2648 Fraise_frame (mini_frame
);
2651 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
2652 obj
= read_filtered_event (1, 0, 0, 0, Qnil
);
2653 cursor_in_echo_area
= 0;
2654 /* If we need to quit, quit with cursor_in_echo_area = 0. */
2657 key
= Fmake_vector (make_number (1), obj
);
2658 def
= Flookup_key (map
, key
, Qt
);
2660 if (EQ (def
, intern ("skip")))
2665 else if (EQ (def
, intern ("act")))
2670 else if (EQ (def
, intern ("recenter")))
2676 else if (EQ (def
, intern ("quit")))
2678 /* We want to exit this command for exit-prefix,
2679 and this is the only way to do it. */
2680 else if (EQ (def
, intern ("exit-prefix")))
2685 /* If we don't clear this, then the next call to read_char will
2686 return quit_char again, and we'll enter an infinite loop. */
2691 if (EQ (xprompt
, prompt
))
2693 args
[0] = build_string ("Please answer y or n. ");
2695 xprompt
= Fconcat (2, args
);
2700 if (! noninteractive
)
2702 cursor_in_echo_area
= -1;
2703 message_with_string (answer
? "%s(y or n) y" : "%s(y or n) n",
2707 unbind_to (count
, Qnil
);
2708 return answer
? Qt
: Qnil
;
2711 /* This is how C code calls `yes-or-no-p' and allows the user
2714 Anything that calls this function must protect from GC! */
2717 do_yes_or_no_p (prompt
)
2720 return call1 (intern ("yes-or-no-p"), prompt
);
2723 /* Anything that calls this function must protect from GC! */
2725 DEFUN ("yes-or-no-p", Fyes_or_no_p
, Syes_or_no_p
, 1, 1, 0,
2726 doc
: /* Ask user a yes-or-no question. Return t if answer is yes.
2727 Takes one argument, which is the string to display to ask the question.
2728 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
2729 The user must confirm the answer with RET,
2730 and can edit it until it has been confirmed.
2732 Under a windowing system a dialog box will be used if `last-nonmenu-event'
2733 is nil, and `use-dialog-box' is non-nil. */)
2737 register Lisp_Object ans
;
2738 Lisp_Object args
[2];
2739 struct gcpro gcpro1
;
2741 CHECK_STRING (prompt
);
2744 if (FRAME_WINDOW_P (SELECTED_FRAME ())
2745 && (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
2749 Lisp_Object pane
, menu
, obj
;
2750 redisplay_preserve_echo_area (4);
2751 pane
= Fcons (Fcons (build_string ("Yes"), Qt
),
2752 Fcons (Fcons (build_string ("No"), Qnil
),
2755 menu
= Fcons (prompt
, pane
);
2756 obj
= Fx_popup_dialog (Qt
, menu
, Qnil
);
2760 #endif /* HAVE_MENUS */
2763 args
[1] = build_string ("(yes or no) ");
2764 prompt
= Fconcat (2, args
);
2770 ans
= Fdowncase (Fread_from_minibuffer (prompt
, Qnil
, Qnil
, Qnil
,
2771 Qyes_or_no_p_history
, Qnil
,
2773 if (SCHARS (ans
) == 3 && !strcmp (SDATA (ans
), "yes"))
2778 if (SCHARS (ans
) == 2 && !strcmp (SDATA (ans
), "no"))
2786 message ("Please answer yes or no.");
2787 Fsleep_for (make_number (2), Qnil
);
2791 DEFUN ("load-average", Fload_average
, Sload_average
, 0, 1, 0,
2792 doc
: /* Return list of 1 minute, 5 minute and 15 minute load averages.
2794 Each of the three load averages is multiplied by 100, then converted
2797 When USE-FLOATS is non-nil, floats will be used instead of integers.
2798 These floats are not multiplied by 100.
2800 If the 5-minute or 15-minute load averages are not available, return a
2801 shortened list, containing only those averages which are available.
2803 An error is thrown if the load average can't be obtained. In some
2804 cases making it work would require Emacs being installed setuid or
2805 setgid so that it can read kernel information, and that usually isn't
2808 Lisp_Object use_floats
;
2811 int loads
= getloadavg (load_ave
, 3);
2812 Lisp_Object ret
= Qnil
;
2815 error ("load-average not implemented for this operating system");
2819 Lisp_Object load
= (NILP (use_floats
) ?
2820 make_number ((int) (100.0 * load_ave
[loads
]))
2821 : make_float (load_ave
[loads
]));
2822 ret
= Fcons (load
, ret
);
2828 Lisp_Object Vfeatures
, Qsubfeatures
;
2829 extern Lisp_Object Vafter_load_alist
;
2831 DEFUN ("featurep", Ffeaturep
, Sfeaturep
, 1, 2, 0,
2832 doc
: /* Returns t if FEATURE is present in this Emacs.
2834 Use this to conditionalize execution of lisp code based on the
2835 presence or absence of Emacs or environment extensions.
2836 Use `provide' to declare that a feature is available. This function
2837 looks at the value of the variable `features'. The optional argument
2838 SUBFEATURE can be used to check a specific subfeature of FEATURE. */)
2839 (feature
, subfeature
)
2840 Lisp_Object feature
, subfeature
;
2842 register Lisp_Object tem
;
2843 CHECK_SYMBOL (feature
);
2844 tem
= Fmemq (feature
, Vfeatures
);
2845 if (!NILP (tem
) && !NILP (subfeature
))
2846 tem
= Fmember (subfeature
, Fget (feature
, Qsubfeatures
));
2847 return (NILP (tem
)) ? Qnil
: Qt
;
2850 DEFUN ("provide", Fprovide
, Sprovide
, 1, 2, 0,
2851 doc
: /* Announce that FEATURE is a feature of the current Emacs.
2852 The optional argument SUBFEATURES should be a list of symbols listing
2853 particular subfeatures supported in this version of FEATURE. */)
2854 (feature
, subfeatures
)
2855 Lisp_Object feature
, subfeatures
;
2857 register Lisp_Object tem
;
2858 CHECK_SYMBOL (feature
);
2859 CHECK_LIST (subfeatures
);
2860 if (!NILP (Vautoload_queue
))
2861 Vautoload_queue
= Fcons (Fcons (make_number (0), Vfeatures
),
2863 tem
= Fmemq (feature
, Vfeatures
);
2865 Vfeatures
= Fcons (feature
, Vfeatures
);
2866 if (!NILP (subfeatures
))
2867 Fput (feature
, Qsubfeatures
, subfeatures
);
2868 LOADHIST_ATTACH (Fcons (Qprovide
, feature
));
2870 /* Run any load-hooks for this file. */
2871 tem
= Fassq (feature
, Vafter_load_alist
);
2873 Fprogn (XCDR (tem
));
2878 /* `require' and its subroutines. */
2880 /* List of features currently being require'd, innermost first. */
2882 Lisp_Object require_nesting_list
;
2885 require_unwind (old_value
)
2886 Lisp_Object old_value
;
2888 return require_nesting_list
= old_value
;
2891 DEFUN ("require", Frequire
, Srequire
, 1, 3, 0,
2892 doc
: /* If feature FEATURE is not loaded, load it from FILENAME.
2893 If FEATURE is not a member of the list `features', then the feature
2894 is not loaded; so load the file FILENAME.
2895 If FILENAME is omitted, the printname of FEATURE is used as the file name,
2896 and `load' will try to load this name appended with the suffix `.elc' or
2897 `.el', in that order. The name without appended suffix will not be used.
2898 If the optional third argument NOERROR is non-nil,
2899 then return nil if the file is not found instead of signaling an error.
2900 Normally the return value is FEATURE.
2901 The normal messages at start and end of loading FILENAME are suppressed. */)
2902 (feature
, filename
, noerror
)
2903 Lisp_Object feature
, filename
, noerror
;
2905 register Lisp_Object tem
;
2906 struct gcpro gcpro1
, gcpro2
;
2907 int from_file
= load_in_progress
;
2909 CHECK_SYMBOL (feature
);
2911 /* Record the presence of `require' in this file
2912 even if the feature specified is already loaded.
2913 But not more than once in any file,
2914 and not when we aren't loading or reading from a file. */
2916 for (tem
= Vcurrent_load_list
; CONSP (tem
); tem
= XCDR (tem
))
2917 if (NILP (XCDR (tem
)) && STRINGP (XCAR (tem
)))
2922 tem
= Fcons (Qrequire
, feature
);
2923 if (NILP (Fmember (tem
, Vcurrent_load_list
)))
2924 LOADHIST_ATTACH (tem
);
2926 tem
= Fmemq (feature
, Vfeatures
);
2930 int count
= SPECPDL_INDEX ();
2933 /* This is to make sure that loadup.el gives a clear picture
2934 of what files are preloaded and when. */
2935 if (! NILP (Vpurify_flag
))
2936 error ("(require %s) while preparing to dump",
2937 SDATA (SYMBOL_NAME (feature
)));
2939 /* A certain amount of recursive `require' is legitimate,
2940 but if we require the same feature recursively 3 times,
2942 tem
= require_nesting_list
;
2943 while (! NILP (tem
))
2945 if (! NILP (Fequal (feature
, XCAR (tem
))))
2950 error ("Recursive `require' for feature `%s'",
2951 SDATA (SYMBOL_NAME (feature
)));
2953 /* Update the list for any nested `require's that occur. */
2954 record_unwind_protect (require_unwind
, require_nesting_list
);
2955 require_nesting_list
= Fcons (feature
, require_nesting_list
);
2957 /* Value saved here is to be restored into Vautoload_queue */
2958 record_unwind_protect (un_autoload
, Vautoload_queue
);
2959 Vautoload_queue
= Qt
;
2961 /* Load the file. */
2962 GCPRO2 (feature
, filename
);
2963 tem
= Fload (NILP (filename
) ? Fsymbol_name (feature
) : filename
,
2964 noerror
, Qt
, Qnil
, (NILP (filename
) ? Qt
: Qnil
));
2967 /* If load failed entirely, return nil. */
2969 return unbind_to (count
, Qnil
);
2971 tem
= Fmemq (feature
, Vfeatures
);
2973 error ("Required feature `%s' was not provided",
2974 SDATA (SYMBOL_NAME (feature
)));
2976 /* Once loading finishes, don't undo it. */
2977 Vautoload_queue
= Qt
;
2978 feature
= unbind_to (count
, feature
);
2984 /* Primitives for work of the "widget" library.
2985 In an ideal world, this section would not have been necessary.
2986 However, lisp function calls being as slow as they are, it turns
2987 out that some functions in the widget library (wid-edit.el) are the
2988 bottleneck of Widget operation. Here is their translation to C,
2989 for the sole reason of efficiency. */
2991 DEFUN ("plist-member", Fplist_member
, Splist_member
, 2, 2, 0,
2992 doc
: /* Return non-nil if PLIST has the property PROP.
2993 PLIST is a property list, which is a list of the form
2994 \(PROP1 VALUE1 PROP2 VALUE2 ...\). PROP is a symbol.
2995 Unlike `plist-get', this allows you to distinguish between a missing
2996 property and a property with the value nil.
2997 The value is actually the tail of PLIST whose car is PROP. */)
2999 Lisp_Object plist
, prop
;
3001 while (CONSP (plist
) && !EQ (XCAR (plist
), prop
))
3004 plist
= XCDR (plist
);
3005 plist
= CDR (plist
);
3010 DEFUN ("widget-put", Fwidget_put
, Swidget_put
, 3, 3, 0,
3011 doc
: /* In WIDGET, set PROPERTY to VALUE.
3012 The value can later be retrieved with `widget-get'. */)
3013 (widget
, property
, value
)
3014 Lisp_Object widget
, property
, value
;
3016 CHECK_CONS (widget
);
3017 XSETCDR (widget
, Fplist_put (XCDR (widget
), property
, value
));
3021 DEFUN ("widget-get", Fwidget_get
, Swidget_get
, 2, 2, 0,
3022 doc
: /* In WIDGET, get the value of PROPERTY.
3023 The value could either be specified when the widget was created, or
3024 later with `widget-put'. */)
3026 Lisp_Object widget
, property
;
3034 CHECK_CONS (widget
);
3035 tmp
= Fplist_member (XCDR (widget
), property
);
3041 tmp
= XCAR (widget
);
3044 widget
= Fget (tmp
, Qwidget_type
);
3048 DEFUN ("widget-apply", Fwidget_apply
, Swidget_apply
, 2, MANY
, 0,
3049 doc
: /* Apply the value of WIDGET's PROPERTY to the widget itself.
3050 ARGS are passed as extra arguments to the function.
3051 usage: (widget-apply WIDGET PROPERTY &rest ARGS) */)
3056 /* This function can GC. */
3057 Lisp_Object newargs
[3];
3058 struct gcpro gcpro1
, gcpro2
;
3061 newargs
[0] = Fwidget_get (args
[0], args
[1]);
3062 newargs
[1] = args
[0];
3063 newargs
[2] = Flist (nargs
- 2, args
+ 2);
3064 GCPRO2 (newargs
[0], newargs
[2]);
3065 result
= Fapply (3, newargs
);
3070 #ifdef HAVE_LANGINFO_CODESET
3071 #include <langinfo.h>
3074 DEFUN ("locale-info", Flocale_info
, Slocale_info
, 1, 1, 0,
3075 doc
: /* Access locale data ITEM for the current C locale, if available.
3076 ITEM should be one of the following:
3078 `codeset', returning the character set as a string (locale item CODESET);
3080 `days', returning a 7-element vector of day names (locale items DAY_n);
3082 `months', returning a 12-element vector of month names (locale items MON_n);
3084 `paper', returning a list (WIDTH HEIGHT) for the default paper size,
3085 both measured in milimeters (locale items PAPER_WIDTH, PAPER_HEIGHT).
3087 If the system can't provide such information through a call to
3088 `nl_langinfo', or if ITEM isn't from the list above, return nil.
3090 See also Info node `(libc)Locales'.
3092 The data read from the system are decoded using `locale-coding-system'. */)
3097 #ifdef HAVE_LANGINFO_CODESET
3099 if (EQ (item
, Qcodeset
))
3101 str
= nl_langinfo (CODESET
);
3102 return build_string (str
);
3105 else if (EQ (item
, Qdays
)) /* e.g. for calendar-day-name-array */
3107 Lisp_Object v
= Fmake_vector (make_number (7), Qnil
);
3108 int days
[7] = {DAY_1
, DAY_2
, DAY_3
, DAY_4
, DAY_5
, DAY_6
, DAY_7
};
3110 synchronize_system_time_locale ();
3111 for (i
= 0; i
< 7; i
++)
3113 str
= nl_langinfo (days
[i
]);
3114 val
= make_unibyte_string (str
, strlen (str
));
3115 /* Fixme: Is this coding system necessarily right, even if
3116 it is consistent with CODESET? If not, what to do? */
3117 Faset (v
, make_number (i
),
3118 code_convert_string_norecord (val
, Vlocale_coding_system
,
3125 else if (EQ (item
, Qmonths
)) /* e.g. for calendar-month-name-array */
3127 struct Lisp_Vector
*p
= allocate_vector (12);
3128 int months
[12] = {MON_1
, MON_2
, MON_3
, MON_4
, MON_5
, MON_6
, MON_7
,
3129 MON_8
, MON_9
, MON_10
, MON_11
, MON_12
};
3131 synchronize_system_time_locale ();
3132 for (i
= 0; i
< 12; i
++)
3134 str
= nl_langinfo (months
[i
]);
3135 val
= make_unibyte_string (str
, strlen (str
));
3137 code_convert_string_norecord (val
, Vlocale_coding_system
, 0);
3139 XSETVECTOR (val
, p
);
3143 /* LC_PAPER stuff isn't defined as accessible in glibc as of 2.3.1,
3144 but is in the locale files. This could be used by ps-print. */
3146 else if (EQ (item
, Qpaper
))
3148 return list2 (make_number (nl_langinfo (PAPER_WIDTH
)),
3149 make_number (nl_langinfo (PAPER_HEIGHT
)));
3151 #endif /* PAPER_WIDTH */
3152 #endif /* HAVE_LANGINFO_CODESET*/
3156 /* base64 encode/decode functions (RFC 2045).
3157 Based on code from GNU recode. */
3159 #define MIME_LINE_LENGTH 76
3161 #define IS_ASCII(Character) \
3163 #define IS_BASE64(Character) \
3164 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0)
3165 #define IS_BASE64_IGNORABLE(Character) \
3166 ((Character) == ' ' || (Character) == '\t' || (Character) == '\n' \
3167 || (Character) == '\f' || (Character) == '\r')
3169 /* Used by base64_decode_1 to retrieve a non-base64-ignorable
3170 character or return retval if there are no characters left to
3172 #define READ_QUADRUPLET_BYTE(retval) \
3177 if (nchars_return) \
3178 *nchars_return = nchars; \
3183 while (IS_BASE64_IGNORABLE (c))
3185 /* Table of characters coding the 64 values. */
3186 static char base64_value_to_char
[64] =
3188 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */
3189 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */
3190 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */
3191 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */
3192 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */
3193 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */
3194 '8', '9', '+', '/' /* 60-63 */
3197 /* Table of base64 values for first 128 characters. */
3198 static short base64_char_to_value
[128] =
3200 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */
3201 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */
3202 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */
3203 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */
3204 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */
3205 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */
3206 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */
3207 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */
3208 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */
3209 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */
3210 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */
3211 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */
3212 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */
3215 /* The following diagram shows the logical steps by which three octets
3216 get transformed into four base64 characters.
3218 .--------. .--------. .--------.
3219 |aaaaaabb| |bbbbcccc| |ccdddddd|
3220 `--------' `--------' `--------'
3222 .--------+--------+--------+--------.
3223 |00aaaaaa|00bbbbbb|00cccccc|00dddddd|
3224 `--------+--------+--------+--------'
3226 .--------+--------+--------+--------.
3227 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD|
3228 `--------+--------+--------+--------'
3230 The octets are divided into 6 bit chunks, which are then encoded into
3231 base64 characters. */
3234 static int base64_encode_1
P_ ((const char *, char *, int, int, int));
3235 static int base64_decode_1
P_ ((const char *, char *, int, int, int *));
3237 DEFUN ("base64-encode-region", Fbase64_encode_region
, Sbase64_encode_region
,
3239 doc
: /* Base64-encode the region between BEG and END.
3240 Return the length of the encoded text.
3241 Optional third argument NO-LINE-BREAK means do not break long lines
3242 into shorter lines. */)
3243 (beg
, end
, no_line_break
)
3244 Lisp_Object beg
, end
, no_line_break
;
3247 int allength
, length
;
3248 int ibeg
, iend
, encoded_length
;
3252 validate_region (&beg
, &end
);
3254 ibeg
= CHAR_TO_BYTE (XFASTINT (beg
));
3255 iend
= CHAR_TO_BYTE (XFASTINT (end
));
3256 move_gap_both (XFASTINT (beg
), ibeg
);
3258 /* We need to allocate enough room for encoding the text.
3259 We need 33 1/3% more space, plus a newline every 76
3260 characters, and then we round up. */
3261 length
= iend
- ibeg
;
3262 allength
= length
+ length
/3 + 1;
3263 allength
+= allength
/ MIME_LINE_LENGTH
+ 1 + 6;
3265 SAFE_ALLOCA (encoded
, char *, allength
);
3266 encoded_length
= base64_encode_1 (BYTE_POS_ADDR (ibeg
), encoded
, length
,
3267 NILP (no_line_break
),
3268 !NILP (current_buffer
->enable_multibyte_characters
));
3269 if (encoded_length
> allength
)
3272 if (encoded_length
< 0)
3274 /* The encoding wasn't possible. */
3276 error ("Multibyte character in data for base64 encoding");
3279 /* Now we have encoded the region, so we insert the new contents
3280 and delete the old. (Insert first in order to preserve markers.) */
3281 SET_PT_BOTH (XFASTINT (beg
), ibeg
);
3282 insert (encoded
, encoded_length
);
3284 del_range_byte (ibeg
+ encoded_length
, iend
+ encoded_length
, 1);
3286 /* If point was outside of the region, restore it exactly; else just
3287 move to the beginning of the region. */
3288 if (old_pos
>= XFASTINT (end
))
3289 old_pos
+= encoded_length
- (XFASTINT (end
) - XFASTINT (beg
));
3290 else if (old_pos
> XFASTINT (beg
))
3291 old_pos
= XFASTINT (beg
);
3294 /* We return the length of the encoded text. */
3295 return make_number (encoded_length
);
3298 DEFUN ("base64-encode-string", Fbase64_encode_string
, Sbase64_encode_string
,
3300 doc
: /* Base64-encode STRING and return the result.
3301 Optional second argument NO-LINE-BREAK means do not break long lines
3302 into shorter lines. */)
3303 (string
, no_line_break
)
3304 Lisp_Object string
, no_line_break
;
3306 int allength
, length
, encoded_length
;
3308 Lisp_Object encoded_string
;
3311 CHECK_STRING (string
);
3313 /* We need to allocate enough room for encoding the text.
3314 We need 33 1/3% more space, plus a newline every 76
3315 characters, and then we round up. */
3316 length
= SBYTES (string
);
3317 allength
= length
+ length
/3 + 1;
3318 allength
+= allength
/ MIME_LINE_LENGTH
+ 1 + 6;
3320 /* We need to allocate enough room for decoding the text. */
3321 SAFE_ALLOCA (encoded
, char *, allength
);
3323 encoded_length
= base64_encode_1 (SDATA (string
),
3324 encoded
, length
, NILP (no_line_break
),
3325 STRING_MULTIBYTE (string
));
3326 if (encoded_length
> allength
)
3329 if (encoded_length
< 0)
3331 /* The encoding wasn't possible. */
3333 error ("Multibyte character in data for base64 encoding");
3336 encoded_string
= make_unibyte_string (encoded
, encoded_length
);
3339 return encoded_string
;
3343 base64_encode_1 (from
, to
, length
, line_break
, multibyte
)
3350 int counter
= 0, i
= 0;
3360 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
3361 if (CHAR_BYTE8_P (c
))
3362 c
= CHAR_TO_BYTE8 (c
);
3370 /* Wrap line every 76 characters. */
3374 if (counter
< MIME_LINE_LENGTH
/ 4)
3383 /* Process first byte of a triplet. */
3385 *e
++ = base64_value_to_char
[0x3f & c
>> 2];
3386 value
= (0x03 & c
) << 4;
3388 /* Process second byte of a triplet. */
3392 *e
++ = base64_value_to_char
[value
];
3400 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
3401 if (CHAR_BYTE8_P (c
))
3402 c
= CHAR_TO_BYTE8 (c
);
3410 *e
++ = base64_value_to_char
[value
| (0x0f & c
>> 4)];
3411 value
= (0x0f & c
) << 2;
3413 /* Process third byte of a triplet. */
3417 *e
++ = base64_value_to_char
[value
];
3424 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
3425 if (CHAR_BYTE8_P (c
))
3426 c
= CHAR_TO_BYTE8 (c
);
3434 *e
++ = base64_value_to_char
[value
| (0x03 & c
>> 6)];
3435 *e
++ = base64_value_to_char
[0x3f & c
];
3442 DEFUN ("base64-decode-region", Fbase64_decode_region
, Sbase64_decode_region
,
3444 doc
: /* Base64-decode the region between BEG and END.
3445 Return the length of the decoded text.
3446 If the region can't be decoded, signal an error and don't modify the buffer. */)
3448 Lisp_Object beg
, end
;
3450 int ibeg
, iend
, length
, allength
;
3455 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3458 validate_region (&beg
, &end
);
3460 ibeg
= CHAR_TO_BYTE (XFASTINT (beg
));
3461 iend
= CHAR_TO_BYTE (XFASTINT (end
));
3463 length
= iend
- ibeg
;
3465 /* We need to allocate enough room for decoding the text. If we are
3466 working on a multibyte buffer, each decoded code may occupy at
3468 allength
= multibyte
? length
* 2 : length
;
3469 SAFE_ALLOCA (decoded
, char *, allength
);
3471 move_gap_both (XFASTINT (beg
), ibeg
);
3472 decoded_length
= base64_decode_1 (BYTE_POS_ADDR (ibeg
), decoded
, length
,
3473 multibyte
, &inserted_chars
);
3474 if (decoded_length
> allength
)
3477 if (decoded_length
< 0)
3479 /* The decoding wasn't possible. */
3481 error ("Invalid base64 data");
3484 /* Now we have decoded the region, so we insert the new contents
3485 and delete the old. (Insert first in order to preserve markers.) */
3486 TEMP_SET_PT_BOTH (XFASTINT (beg
), ibeg
);
3487 insert_1_both (decoded
, inserted_chars
, decoded_length
, 0, 1, 0);
3490 /* Delete the original text. */
3491 del_range_both (PT
, PT_BYTE
, XFASTINT (end
) + inserted_chars
,
3492 iend
+ decoded_length
, 1);
3494 /* If point was outside of the region, restore it exactly; else just
3495 move to the beginning of the region. */
3496 if (old_pos
>= XFASTINT (end
))
3497 old_pos
+= inserted_chars
- (XFASTINT (end
) - XFASTINT (beg
));
3498 else if (old_pos
> XFASTINT (beg
))
3499 old_pos
= XFASTINT (beg
);
3500 SET_PT (old_pos
> ZV
? ZV
: old_pos
);
3502 return make_number (inserted_chars
);
3505 DEFUN ("base64-decode-string", Fbase64_decode_string
, Sbase64_decode_string
,
3507 doc
: /* Base64-decode STRING and return the result. */)
3512 int length
, decoded_length
;
3513 Lisp_Object decoded_string
;
3516 CHECK_STRING (string
);
3518 length
= SBYTES (string
);
3519 /* We need to allocate enough room for decoding the text. */
3520 SAFE_ALLOCA (decoded
, char *, length
);
3522 /* The decoded result should be unibyte. */
3523 decoded_length
= base64_decode_1 (SDATA (string
), decoded
, length
,
3525 if (decoded_length
> length
)
3527 else if (decoded_length
>= 0)
3528 decoded_string
= make_unibyte_string (decoded
, decoded_length
);
3530 decoded_string
= Qnil
;
3533 if (!STRINGP (decoded_string
))
3534 error ("Invalid base64 data");
3536 return decoded_string
;
3539 /* Base64-decode the data at FROM of LENGHT bytes into TO. If
3540 MULTIBYTE is nonzero, the decoded result should be in multibyte
3541 form. If NCHARS_RETRUN is not NULL, store the number of produced
3542 characters in *NCHARS_RETURN. */
3545 base64_decode_1 (from
, to
, length
, multibyte
, nchars_return
)
3555 unsigned long value
;
3560 /* Process first byte of a quadruplet. */
3562 READ_QUADRUPLET_BYTE (e
-to
);
3566 value
= base64_char_to_value
[c
] << 18;
3568 /* Process second byte of a quadruplet. */
3570 READ_QUADRUPLET_BYTE (-1);
3574 value
|= base64_char_to_value
[c
] << 12;
3576 c
= (unsigned char) (value
>> 16);
3577 if (multibyte
&& c
>= 128)
3578 e
+= BYTE8_STRING (c
, e
);
3583 /* Process third byte of a quadruplet. */
3585 READ_QUADRUPLET_BYTE (-1);
3589 READ_QUADRUPLET_BYTE (-1);
3598 value
|= base64_char_to_value
[c
] << 6;
3600 c
= (unsigned char) (0xff & value
>> 8);
3601 if (multibyte
&& c
>= 128)
3602 e
+= BYTE8_STRING (c
, e
);
3607 /* Process fourth byte of a quadruplet. */
3609 READ_QUADRUPLET_BYTE (-1);
3616 value
|= base64_char_to_value
[c
];
3618 c
= (unsigned char) (0xff & value
);
3619 if (multibyte
&& c
>= 128)
3620 e
+= BYTE8_STRING (c
, e
);
3629 /***********************************************************************
3631 ***** Hash Tables *****
3633 ***********************************************************************/
3635 /* Implemented by gerd@gnu.org. This hash table implementation was
3636 inspired by CMUCL hash tables. */
3640 1. For small tables, association lists are probably faster than
3641 hash tables because they have lower overhead.
3643 For uses of hash tables where the O(1) behavior of table
3644 operations is not a requirement, it might therefore be a good idea
3645 not to hash. Instead, we could just do a linear search in the
3646 key_and_value vector of the hash table. This could be done
3647 if a `:linear-search t' argument is given to make-hash-table. */
3650 /* The list of all weak hash tables. Don't staticpro this one. */
3652 struct Lisp_Hash_Table
*weak_hash_tables
;
3654 /* Various symbols. */
3656 Lisp_Object Qhash_table_p
, Qeq
, Qeql
, Qequal
, Qkey
, Qvalue
;
3657 Lisp_Object QCtest
, QCsize
, QCrehash_size
, QCrehash_threshold
, QCweakness
;
3658 Lisp_Object Qhash_table_test
, Qkey_or_value
, Qkey_and_value
;
3660 /* Function prototypes. */
3662 static struct Lisp_Hash_Table
*check_hash_table
P_ ((Lisp_Object
));
3663 static int get_key_arg
P_ ((Lisp_Object
, int, Lisp_Object
*, char *));
3664 static void maybe_resize_hash_table
P_ ((struct Lisp_Hash_Table
*));
3665 static int cmpfn_eql
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
, unsigned,
3666 Lisp_Object
, unsigned));
3667 static int cmpfn_equal
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
, unsigned,
3668 Lisp_Object
, unsigned));
3669 static int cmpfn_user_defined
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
,
3670 unsigned, Lisp_Object
, unsigned));
3671 static unsigned hashfn_eq
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
3672 static unsigned hashfn_eql
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
3673 static unsigned hashfn_equal
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
3674 static unsigned hashfn_user_defined
P_ ((struct Lisp_Hash_Table
*,
3676 static unsigned sxhash_string
P_ ((unsigned char *, int));
3677 static unsigned sxhash_list
P_ ((Lisp_Object
, int));
3678 static unsigned sxhash_vector
P_ ((Lisp_Object
, int));
3679 static unsigned sxhash_bool_vector
P_ ((Lisp_Object
));
3680 static int sweep_weak_table
P_ ((struct Lisp_Hash_Table
*, int));
3684 /***********************************************************************
3686 ***********************************************************************/
3688 /* If OBJ is a Lisp hash table, return a pointer to its struct
3689 Lisp_Hash_Table. Otherwise, signal an error. */
3691 static struct Lisp_Hash_Table
*
3692 check_hash_table (obj
)
3695 CHECK_HASH_TABLE (obj
);
3696 return XHASH_TABLE (obj
);
3700 /* Value is the next integer I >= N, N >= 0 which is "almost" a prime
3704 next_almost_prime (n
)
3717 /* Find KEY in ARGS which has size NARGS. Don't consider indices for
3718 which USED[I] is non-zero. If found at index I in ARGS, set
3719 USED[I] and USED[I + 1] to 1, and return I + 1. Otherwise return
3720 -1. This function is used to extract a keyword/argument pair from
3721 a DEFUN parameter list. */
3724 get_key_arg (key
, nargs
, args
, used
)
3732 for (i
= 0; i
< nargs
- 1; ++i
)
3733 if (!used
[i
] && EQ (args
[i
], key
))
3748 /* Return a Lisp vector which has the same contents as VEC but has
3749 size NEW_SIZE, NEW_SIZE >= VEC->size. Entries in the resulting
3750 vector that are not copied from VEC are set to INIT. */
3753 larger_vector (vec
, new_size
, init
)
3758 struct Lisp_Vector
*v
;
3761 xassert (VECTORP (vec
));
3762 old_size
= ASIZE (vec
);
3763 xassert (new_size
>= old_size
);
3765 v
= allocate_vector (new_size
);
3766 bcopy (XVECTOR (vec
)->contents
, v
->contents
,
3767 old_size
* sizeof *v
->contents
);
3768 for (i
= old_size
; i
< new_size
; ++i
)
3769 v
->contents
[i
] = init
;
3770 XSETVECTOR (vec
, v
);
3775 /***********************************************************************
3777 ***********************************************************************/
3779 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
3780 HASH2 in hash table H using `eql'. Value is non-zero if KEY1 and
3781 KEY2 are the same. */
3784 cmpfn_eql (h
, key1
, hash1
, key2
, hash2
)
3785 struct Lisp_Hash_Table
*h
;
3786 Lisp_Object key1
, key2
;
3787 unsigned hash1
, hash2
;
3789 return (FLOATP (key1
)
3791 && XFLOAT_DATA (key1
) == XFLOAT_DATA (key2
));
3795 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
3796 HASH2 in hash table H using `equal'. Value is non-zero if KEY1 and
3797 KEY2 are the same. */
3800 cmpfn_equal (h
, key1
, hash1
, key2
, hash2
)
3801 struct Lisp_Hash_Table
*h
;
3802 Lisp_Object key1
, key2
;
3803 unsigned hash1
, hash2
;
3805 return hash1
== hash2
&& !NILP (Fequal (key1
, key2
));
3809 /* Compare KEY1 which has hash code HASH1, and KEY2 with hash code
3810 HASH2 in hash table H using H->user_cmp_function. Value is non-zero
3811 if KEY1 and KEY2 are the same. */
3814 cmpfn_user_defined (h
, key1
, hash1
, key2
, hash2
)
3815 struct Lisp_Hash_Table
*h
;
3816 Lisp_Object key1
, key2
;
3817 unsigned hash1
, hash2
;
3821 Lisp_Object args
[3];
3823 args
[0] = h
->user_cmp_function
;
3826 return !NILP (Ffuncall (3, args
));
3833 /* Value is a hash code for KEY for use in hash table H which uses
3834 `eq' to compare keys. The hash code returned is guaranteed to fit
3835 in a Lisp integer. */
3839 struct Lisp_Hash_Table
*h
;
3842 unsigned hash
= XUINT (key
) ^ XTYPE (key
);
3843 xassert ((hash
& ~INTMASK
) == 0);
3848 /* Value is a hash code for KEY for use in hash table H which uses
3849 `eql' to compare keys. The hash code returned is guaranteed to fit
3850 in a Lisp integer. */
3854 struct Lisp_Hash_Table
*h
;
3859 hash
= sxhash (key
, 0);
3861 hash
= XUINT (key
) ^ XTYPE (key
);
3862 xassert ((hash
& ~INTMASK
) == 0);
3867 /* Value is a hash code for KEY for use in hash table H which uses
3868 `equal' to compare keys. The hash code returned is guaranteed to fit
3869 in a Lisp integer. */
3872 hashfn_equal (h
, key
)
3873 struct Lisp_Hash_Table
*h
;
3876 unsigned hash
= sxhash (key
, 0);
3877 xassert ((hash
& ~INTMASK
) == 0);
3882 /* Value is a hash code for KEY for use in hash table H which uses as
3883 user-defined function to compare keys. The hash code returned is
3884 guaranteed to fit in a Lisp integer. */
3887 hashfn_user_defined (h
, key
)
3888 struct Lisp_Hash_Table
*h
;
3891 Lisp_Object args
[2], hash
;
3893 args
[0] = h
->user_hash_function
;
3895 hash
= Ffuncall (2, args
);
3896 if (!INTEGERP (hash
))
3897 signal_error ("Invalid hash code returned from user-supplied hash function", hash
);
3898 return XUINT (hash
);
3902 /* Create and initialize a new hash table.
3904 TEST specifies the test the hash table will use to compare keys.
3905 It must be either one of the predefined tests `eq', `eql' or
3906 `equal' or a symbol denoting a user-defined test named TEST with
3907 test and hash functions USER_TEST and USER_HASH.
3909 Give the table initial capacity SIZE, SIZE >= 0, an integer.
3911 If REHASH_SIZE is an integer, it must be > 0, and this hash table's
3912 new size when it becomes full is computed by adding REHASH_SIZE to
3913 its old size. If REHASH_SIZE is a float, it must be > 1.0, and the
3914 table's new size is computed by multiplying its old size with
3917 REHASH_THRESHOLD must be a float <= 1.0, and > 0. The table will
3918 be resized when the ratio of (number of entries in the table) /
3919 (table size) is >= REHASH_THRESHOLD.
3921 WEAK specifies the weakness of the table. If non-nil, it must be
3922 one of the symbols `key', `value', `key-or-value', or `key-and-value'. */
3925 make_hash_table (test
, size
, rehash_size
, rehash_threshold
, weak
,
3926 user_test
, user_hash
)
3927 Lisp_Object test
, size
, rehash_size
, rehash_threshold
, weak
;
3928 Lisp_Object user_test
, user_hash
;
3930 struct Lisp_Hash_Table
*h
;
3932 int index_size
, i
, sz
;
3934 /* Preconditions. */
3935 xassert (SYMBOLP (test
));
3936 xassert (INTEGERP (size
) && XINT (size
) >= 0);
3937 xassert ((INTEGERP (rehash_size
) && XINT (rehash_size
) > 0)
3938 || (FLOATP (rehash_size
) && XFLOATINT (rehash_size
) > 1.0));
3939 xassert (FLOATP (rehash_threshold
)
3940 && XFLOATINT (rehash_threshold
) > 0
3941 && XFLOATINT (rehash_threshold
) <= 1.0);
3943 if (XFASTINT (size
) == 0)
3944 size
= make_number (1);
3946 /* Allocate a table and initialize it. */
3947 h
= allocate_hash_table ();
3949 /* Initialize hash table slots. */
3950 sz
= XFASTINT (size
);
3953 if (EQ (test
, Qeql
))
3955 h
->cmpfn
= cmpfn_eql
;
3956 h
->hashfn
= hashfn_eql
;
3958 else if (EQ (test
, Qeq
))
3961 h
->hashfn
= hashfn_eq
;
3963 else if (EQ (test
, Qequal
))
3965 h
->cmpfn
= cmpfn_equal
;
3966 h
->hashfn
= hashfn_equal
;
3970 h
->user_cmp_function
= user_test
;
3971 h
->user_hash_function
= user_hash
;
3972 h
->cmpfn
= cmpfn_user_defined
;
3973 h
->hashfn
= hashfn_user_defined
;
3977 h
->rehash_threshold
= rehash_threshold
;
3978 h
->rehash_size
= rehash_size
;
3980 h
->key_and_value
= Fmake_vector (make_number (2 * sz
), Qnil
);
3981 h
->hash
= Fmake_vector (size
, Qnil
);
3982 h
->next
= Fmake_vector (size
, Qnil
);
3983 /* Cast to int here avoids losing with gcc 2.95 on Tru64/Alpha... */
3984 index_size
= next_almost_prime ((int) (sz
/ XFLOATINT (rehash_threshold
)));
3985 h
->index
= Fmake_vector (make_number (index_size
), Qnil
);
3987 /* Set up the free list. */
3988 for (i
= 0; i
< sz
- 1; ++i
)
3989 HASH_NEXT (h
, i
) = make_number (i
+ 1);
3990 h
->next_free
= make_number (0);
3992 XSET_HASH_TABLE (table
, h
);
3993 xassert (HASH_TABLE_P (table
));
3994 xassert (XHASH_TABLE (table
) == h
);
3996 /* Maybe add this hash table to the list of all weak hash tables. */
3998 h
->next_weak
= NULL
;
4001 h
->next_weak
= weak_hash_tables
;
4002 weak_hash_tables
= h
;
4009 /* Return a copy of hash table H1. Keys and values are not copied,
4010 only the table itself is. */
4013 copy_hash_table (h1
)
4014 struct Lisp_Hash_Table
*h1
;
4017 struct Lisp_Hash_Table
*h2
;
4018 struct Lisp_Vector
*next
;
4020 h2
= allocate_hash_table ();
4021 next
= h2
->vec_next
;
4022 bcopy (h1
, h2
, sizeof *h2
);
4023 h2
->vec_next
= next
;
4024 h2
->key_and_value
= Fcopy_sequence (h1
->key_and_value
);
4025 h2
->hash
= Fcopy_sequence (h1
->hash
);
4026 h2
->next
= Fcopy_sequence (h1
->next
);
4027 h2
->index
= Fcopy_sequence (h1
->index
);
4028 XSET_HASH_TABLE (table
, h2
);
4030 /* Maybe add this hash table to the list of all weak hash tables. */
4031 if (!NILP (h2
->weak
))
4033 h2
->next_weak
= weak_hash_tables
;
4034 weak_hash_tables
= h2
;
4041 /* Resize hash table H if it's too full. If H cannot be resized
4042 because it's already too large, throw an error. */
4045 maybe_resize_hash_table (h
)
4046 struct Lisp_Hash_Table
*h
;
4048 if (NILP (h
->next_free
))
4050 int old_size
= HASH_TABLE_SIZE (h
);
4051 int i
, new_size
, index_size
;
4054 if (INTEGERP (h
->rehash_size
))
4055 new_size
= old_size
+ XFASTINT (h
->rehash_size
);
4057 new_size
= old_size
* XFLOATINT (h
->rehash_size
);
4058 new_size
= max (old_size
+ 1, new_size
);
4059 index_size
= next_almost_prime ((int)
4061 / XFLOATINT (h
->rehash_threshold
)));
4062 /* Assignment to EMACS_INT stops GCC whining about limited range
4064 nsize
= max (index_size
, 2 * new_size
);
4065 if (nsize
> MOST_POSITIVE_FIXNUM
)
4066 error ("Hash table too large to resize");
4068 h
->key_and_value
= larger_vector (h
->key_and_value
, 2 * new_size
, Qnil
);
4069 h
->next
= larger_vector (h
->next
, new_size
, Qnil
);
4070 h
->hash
= larger_vector (h
->hash
, new_size
, Qnil
);
4071 h
->index
= Fmake_vector (make_number (index_size
), Qnil
);
4073 /* Update the free list. Do it so that new entries are added at
4074 the end of the free list. This makes some operations like
4076 for (i
= old_size
; i
< new_size
- 1; ++i
)
4077 HASH_NEXT (h
, i
) = make_number (i
+ 1);
4079 if (!NILP (h
->next_free
))
4081 Lisp_Object last
, next
;
4083 last
= h
->next_free
;
4084 while (next
= HASH_NEXT (h
, XFASTINT (last
)),
4088 HASH_NEXT (h
, XFASTINT (last
)) = make_number (old_size
);
4091 XSETFASTINT (h
->next_free
, old_size
);
4094 for (i
= 0; i
< old_size
; ++i
)
4095 if (!NILP (HASH_HASH (h
, i
)))
4097 unsigned hash_code
= XUINT (HASH_HASH (h
, i
));
4098 int start_of_bucket
= hash_code
% ASIZE (h
->index
);
4099 HASH_NEXT (h
, i
) = HASH_INDEX (h
, start_of_bucket
);
4100 HASH_INDEX (h
, start_of_bucket
) = make_number (i
);
4106 /* Lookup KEY in hash table H. If HASH is non-null, return in *HASH
4107 the hash code of KEY. Value is the index of the entry in H
4108 matching KEY, or -1 if not found. */
4111 hash_lookup (h
, key
, hash
)
4112 struct Lisp_Hash_Table
*h
;
4117 int start_of_bucket
;
4120 hash_code
= h
->hashfn (h
, key
);
4124 start_of_bucket
= hash_code
% ASIZE (h
->index
);
4125 idx
= HASH_INDEX (h
, start_of_bucket
);
4127 /* We need not gcpro idx since it's either an integer or nil. */
4130 int i
= XFASTINT (idx
);
4131 if (EQ (key
, HASH_KEY (h
, i
))
4133 && h
->cmpfn (h
, key
, hash_code
,
4134 HASH_KEY (h
, i
), XUINT (HASH_HASH (h
, i
)))))
4136 idx
= HASH_NEXT (h
, i
);
4139 return NILP (idx
) ? -1 : XFASTINT (idx
);
4143 /* Put an entry into hash table H that associates KEY with VALUE.
4144 HASH is a previously computed hash code of KEY.
4145 Value is the index of the entry in H matching KEY. */
4148 hash_put (h
, key
, value
, hash
)
4149 struct Lisp_Hash_Table
*h
;
4150 Lisp_Object key
, value
;
4153 int start_of_bucket
, i
;
4155 xassert ((hash
& ~INTMASK
) == 0);
4157 /* Increment count after resizing because resizing may fail. */
4158 maybe_resize_hash_table (h
);
4161 /* Store key/value in the key_and_value vector. */
4162 i
= XFASTINT (h
->next_free
);
4163 h
->next_free
= HASH_NEXT (h
, i
);
4164 HASH_KEY (h
, i
) = key
;
4165 HASH_VALUE (h
, i
) = value
;
4167 /* Remember its hash code. */
4168 HASH_HASH (h
, i
) = make_number (hash
);
4170 /* Add new entry to its collision chain. */
4171 start_of_bucket
= hash
% ASIZE (h
->index
);
4172 HASH_NEXT (h
, i
) = HASH_INDEX (h
, start_of_bucket
);
4173 HASH_INDEX (h
, start_of_bucket
) = make_number (i
);
4178 /* Remove the entry matching KEY from hash table H, if there is one. */
4181 hash_remove (h
, key
)
4182 struct Lisp_Hash_Table
*h
;
4186 int start_of_bucket
;
4187 Lisp_Object idx
, prev
;
4189 hash_code
= h
->hashfn (h
, key
);
4190 start_of_bucket
= hash_code
% ASIZE (h
->index
);
4191 idx
= HASH_INDEX (h
, start_of_bucket
);
4194 /* We need not gcpro idx, prev since they're either integers or nil. */
4197 int i
= XFASTINT (idx
);
4199 if (EQ (key
, HASH_KEY (h
, i
))
4201 && h
->cmpfn (h
, key
, hash_code
,
4202 HASH_KEY (h
, i
), XUINT (HASH_HASH (h
, i
)))))
4204 /* Take entry out of collision chain. */
4206 HASH_INDEX (h
, start_of_bucket
) = HASH_NEXT (h
, i
);
4208 HASH_NEXT (h
, XFASTINT (prev
)) = HASH_NEXT (h
, i
);
4210 /* Clear slots in key_and_value and add the slots to
4212 HASH_KEY (h
, i
) = HASH_VALUE (h
, i
) = HASH_HASH (h
, i
) = Qnil
;
4213 HASH_NEXT (h
, i
) = h
->next_free
;
4214 h
->next_free
= make_number (i
);
4216 xassert (h
->count
>= 0);
4222 idx
= HASH_NEXT (h
, i
);
4228 /* Clear hash table H. */
4232 struct Lisp_Hash_Table
*h
;
4236 int i
, size
= HASH_TABLE_SIZE (h
);
4238 for (i
= 0; i
< size
; ++i
)
4240 HASH_NEXT (h
, i
) = i
< size
- 1 ? make_number (i
+ 1) : Qnil
;
4241 HASH_KEY (h
, i
) = Qnil
;
4242 HASH_VALUE (h
, i
) = Qnil
;
4243 HASH_HASH (h
, i
) = Qnil
;
4246 for (i
= 0; i
< ASIZE (h
->index
); ++i
)
4247 ASET (h
->index
, i
, Qnil
);
4249 h
->next_free
= make_number (0);
4256 /************************************************************************
4258 ************************************************************************/
4261 init_weak_hash_tables ()
4263 weak_hash_tables
= NULL
;
4266 /* Sweep weak hash table H. REMOVE_ENTRIES_P non-zero means remove
4267 entries from the table that don't survive the current GC.
4268 REMOVE_ENTRIES_P zero means mark entries that are in use. Value is
4269 non-zero if anything was marked. */
4272 sweep_weak_table (h
, remove_entries_p
)
4273 struct Lisp_Hash_Table
*h
;
4274 int remove_entries_p
;
4276 int bucket
, n
, marked
;
4278 n
= ASIZE (h
->index
) & ~ARRAY_MARK_FLAG
;
4281 for (bucket
= 0; bucket
< n
; ++bucket
)
4283 Lisp_Object idx
, next
, prev
;
4285 /* Follow collision chain, removing entries that
4286 don't survive this garbage collection. */
4288 for (idx
= HASH_INDEX (h
, bucket
); !NILP (idx
); idx
= next
)
4290 int i
= XFASTINT (idx
);
4291 int key_known_to_survive_p
= survives_gc_p (HASH_KEY (h
, i
));
4292 int value_known_to_survive_p
= survives_gc_p (HASH_VALUE (h
, i
));
4295 if (EQ (h
->weak
, Qkey
))
4296 remove_p
= !key_known_to_survive_p
;
4297 else if (EQ (h
->weak
, Qvalue
))
4298 remove_p
= !value_known_to_survive_p
;
4299 else if (EQ (h
->weak
, Qkey_or_value
))
4300 remove_p
= !(key_known_to_survive_p
|| value_known_to_survive_p
);
4301 else if (EQ (h
->weak
, Qkey_and_value
))
4302 remove_p
= !(key_known_to_survive_p
&& value_known_to_survive_p
);
4306 next
= HASH_NEXT (h
, i
);
4308 if (remove_entries_p
)
4312 /* Take out of collision chain. */
4314 HASH_INDEX (h
, bucket
) = next
;
4316 HASH_NEXT (h
, XFASTINT (prev
)) = next
;
4318 /* Add to free list. */
4319 HASH_NEXT (h
, i
) = h
->next_free
;
4322 /* Clear key, value, and hash. */
4323 HASH_KEY (h
, i
) = HASH_VALUE (h
, i
) = Qnil
;
4324 HASH_HASH (h
, i
) = Qnil
;
4337 /* Make sure key and value survive. */
4338 if (!key_known_to_survive_p
)
4340 mark_object (HASH_KEY (h
, i
));
4344 if (!value_known_to_survive_p
)
4346 mark_object (HASH_VALUE (h
, i
));
4357 /* Remove elements from weak hash tables that don't survive the
4358 current garbage collection. Remove weak tables that don't survive
4359 from Vweak_hash_tables. Called from gc_sweep. */
4362 sweep_weak_hash_tables ()
4364 struct Lisp_Hash_Table
*h
, *used
, *next
;
4367 /* Mark all keys and values that are in use. Keep on marking until
4368 there is no more change. This is necessary for cases like
4369 value-weak table A containing an entry X -> Y, where Y is used in a
4370 key-weak table B, Z -> Y. If B comes after A in the list of weak
4371 tables, X -> Y might be removed from A, although when looking at B
4372 one finds that it shouldn't. */
4376 for (h
= weak_hash_tables
; h
; h
= h
->next_weak
)
4378 if (h
->size
& ARRAY_MARK_FLAG
)
4379 marked
|= sweep_weak_table (h
, 0);
4384 /* Remove tables and entries that aren't used. */
4385 for (h
= weak_hash_tables
, used
= NULL
; h
; h
= next
)
4387 next
= h
->next_weak
;
4389 if (h
->size
& ARRAY_MARK_FLAG
)
4391 /* TABLE is marked as used. Sweep its contents. */
4393 sweep_weak_table (h
, 1);
4395 /* Add table to the list of used weak hash tables. */
4396 h
->next_weak
= used
;
4401 weak_hash_tables
= used
;
4406 /***********************************************************************
4407 Hash Code Computation
4408 ***********************************************************************/
4410 /* Maximum depth up to which to dive into Lisp structures. */
4412 #define SXHASH_MAX_DEPTH 3
4414 /* Maximum length up to which to take list and vector elements into
4417 #define SXHASH_MAX_LEN 7
4419 /* Combine two integers X and Y for hashing. */
4421 #define SXHASH_COMBINE(X, Y) \
4422 ((((unsigned)(X) << 4) + (((unsigned)(X) >> 24) & 0x0fffffff)) \
4426 /* Return a hash for string PTR which has length LEN. The hash
4427 code returned is guaranteed to fit in a Lisp integer. */
4430 sxhash_string (ptr
, len
)
4434 unsigned char *p
= ptr
;
4435 unsigned char *end
= p
+ len
;
4444 hash
= ((hash
<< 4) + (hash
>> 28) + c
);
4447 return hash
& INTMASK
;
4451 /* Return a hash for list LIST. DEPTH is the current depth in the
4452 list. We don't recurse deeper than SXHASH_MAX_DEPTH in it. */
4455 sxhash_list (list
, depth
)
4462 if (depth
< SXHASH_MAX_DEPTH
)
4464 CONSP (list
) && i
< SXHASH_MAX_LEN
;
4465 list
= XCDR (list
), ++i
)
4467 unsigned hash2
= sxhash (XCAR (list
), depth
+ 1);
4468 hash
= SXHASH_COMBINE (hash
, hash2
);
4473 unsigned hash2
= sxhash (list
, depth
+ 1);
4474 hash
= SXHASH_COMBINE (hash
, hash2
);
4481 /* Return a hash for vector VECTOR. DEPTH is the current depth in
4482 the Lisp structure. */
4485 sxhash_vector (vec
, depth
)
4489 unsigned hash
= ASIZE (vec
);
4492 n
= min (SXHASH_MAX_LEN
, ASIZE (vec
));
4493 for (i
= 0; i
< n
; ++i
)
4495 unsigned hash2
= sxhash (AREF (vec
, i
), depth
+ 1);
4496 hash
= SXHASH_COMBINE (hash
, hash2
);
4503 /* Return a hash for bool-vector VECTOR. */
4506 sxhash_bool_vector (vec
)
4509 unsigned hash
= XBOOL_VECTOR (vec
)->size
;
4512 n
= min (SXHASH_MAX_LEN
, XBOOL_VECTOR (vec
)->vector_size
);
4513 for (i
= 0; i
< n
; ++i
)
4514 hash
= SXHASH_COMBINE (hash
, XBOOL_VECTOR (vec
)->data
[i
]);
4520 /* Return a hash code for OBJ. DEPTH is the current depth in the Lisp
4521 structure. Value is an unsigned integer clipped to INTMASK. */
4530 if (depth
> SXHASH_MAX_DEPTH
)
4533 switch (XTYPE (obj
))
4544 obj
= SYMBOL_NAME (obj
);
4548 hash
= sxhash_string (SDATA (obj
), SCHARS (obj
));
4551 /* This can be everything from a vector to an overlay. */
4552 case Lisp_Vectorlike
:
4554 /* According to the CL HyperSpec, two arrays are equal only if
4555 they are `eq', except for strings and bit-vectors. In
4556 Emacs, this works differently. We have to compare element
4558 hash
= sxhash_vector (obj
, depth
);
4559 else if (BOOL_VECTOR_P (obj
))
4560 hash
= sxhash_bool_vector (obj
);
4562 /* Others are `equal' if they are `eq', so let's take their
4568 hash
= sxhash_list (obj
, depth
);
4573 unsigned char *p
= (unsigned char *) &XFLOAT_DATA (obj
);
4574 unsigned char *e
= p
+ sizeof XFLOAT_DATA (obj
);
4575 for (hash
= 0; p
< e
; ++p
)
4576 hash
= SXHASH_COMBINE (hash
, *p
);
4584 return hash
& INTMASK
;
4589 /***********************************************************************
4591 ***********************************************************************/
4594 DEFUN ("sxhash", Fsxhash
, Ssxhash
, 1, 1, 0,
4595 doc
: /* Compute a hash code for OBJ and return it as integer. */)
4599 unsigned hash
= sxhash (obj
, 0);
4600 return make_number (hash
);
4604 DEFUN ("make-hash-table", Fmake_hash_table
, Smake_hash_table
, 0, MANY
, 0,
4605 doc
: /* Create and return a new hash table.
4607 Arguments are specified as keyword/argument pairs. The following
4608 arguments are defined:
4610 :test TEST -- TEST must be a symbol that specifies how to compare
4611 keys. Default is `eql'. Predefined are the tests `eq', `eql', and
4612 `equal'. User-supplied test and hash functions can be specified via
4613 `define-hash-table-test'.
4615 :size SIZE -- A hint as to how many elements will be put in the table.
4618 :rehash-size REHASH-SIZE - Indicates how to expand the table when it
4619 fills up. If REHASH-SIZE is an integer, add that many space. If it
4620 is a float, it must be > 1.0, and the new size is computed by
4621 multiplying the old size with that factor. Default is 1.5.
4623 :rehash-threshold THRESHOLD -- THRESHOLD must a float > 0, and <= 1.0.
4624 Resize the hash table when ratio of the number of entries in the
4625 table. Default is 0.8.
4627 :weakness WEAK -- WEAK must be one of nil, t, `key', `value',
4628 `key-or-value', or `key-and-value'. If WEAK is not nil, the table
4629 returned is a weak table. Key/value pairs are removed from a weak
4630 hash table when there are no non-weak references pointing to their
4631 key, value, one of key or value, or both key and value, depending on
4632 WEAK. WEAK t is equivalent to `key-and-value'. Default value of WEAK
4635 usage: (make-hash-table &rest KEYWORD-ARGS) */)
4640 Lisp_Object test
, size
, rehash_size
, rehash_threshold
, weak
;
4641 Lisp_Object user_test
, user_hash
;
4645 /* The vector `used' is used to keep track of arguments that
4646 have been consumed. */
4647 used
= (char *) alloca (nargs
* sizeof *used
);
4648 bzero (used
, nargs
* sizeof *used
);
4650 /* See if there's a `:test TEST' among the arguments. */
4651 i
= get_key_arg (QCtest
, nargs
, args
, used
);
4652 test
= i
< 0 ? Qeql
: args
[i
];
4653 if (!EQ (test
, Qeq
) && !EQ (test
, Qeql
) && !EQ (test
, Qequal
))
4655 /* See if it is a user-defined test. */
4658 prop
= Fget (test
, Qhash_table_test
);
4659 if (!CONSP (prop
) || !CONSP (XCDR (prop
)))
4660 signal_error ("Invalid hash table test", test
);
4661 user_test
= XCAR (prop
);
4662 user_hash
= XCAR (XCDR (prop
));
4665 user_test
= user_hash
= Qnil
;
4667 /* See if there's a `:size SIZE' argument. */
4668 i
= get_key_arg (QCsize
, nargs
, args
, used
);
4669 size
= i
< 0 ? Qnil
: args
[i
];
4671 size
= make_number (DEFAULT_HASH_SIZE
);
4672 else if (!INTEGERP (size
) || XINT (size
) < 0)
4673 signal_error ("Invalid hash table size", size
);
4675 /* Look for `:rehash-size SIZE'. */
4676 i
= get_key_arg (QCrehash_size
, nargs
, args
, used
);
4677 rehash_size
= i
< 0 ? make_float (DEFAULT_REHASH_SIZE
) : args
[i
];
4678 if (!NUMBERP (rehash_size
)
4679 || (INTEGERP (rehash_size
) && XINT (rehash_size
) <= 0)
4680 || XFLOATINT (rehash_size
) <= 1.0)
4681 signal_error ("Invalid hash table rehash size", rehash_size
);
4683 /* Look for `:rehash-threshold THRESHOLD'. */
4684 i
= get_key_arg (QCrehash_threshold
, nargs
, args
, used
);
4685 rehash_threshold
= i
< 0 ? make_float (DEFAULT_REHASH_THRESHOLD
) : args
[i
];
4686 if (!FLOATP (rehash_threshold
)
4687 || XFLOATINT (rehash_threshold
) <= 0.0
4688 || XFLOATINT (rehash_threshold
) > 1.0)
4689 signal_error ("Invalid hash table rehash threshold", rehash_threshold
);
4691 /* Look for `:weakness WEAK'. */
4692 i
= get_key_arg (QCweakness
, nargs
, args
, used
);
4693 weak
= i
< 0 ? Qnil
: args
[i
];
4695 weak
= Qkey_and_value
;
4698 && !EQ (weak
, Qvalue
)
4699 && !EQ (weak
, Qkey_or_value
)
4700 && !EQ (weak
, Qkey_and_value
))
4701 signal_error ("Invalid hash table weakness", weak
);
4703 /* Now, all args should have been used up, or there's a problem. */
4704 for (i
= 0; i
< nargs
; ++i
)
4706 signal_error ("Invalid argument list", args
[i
]);
4708 return make_hash_table (test
, size
, rehash_size
, rehash_threshold
, weak
,
4709 user_test
, user_hash
);
4713 DEFUN ("copy-hash-table", Fcopy_hash_table
, Scopy_hash_table
, 1, 1, 0,
4714 doc
: /* Return a copy of hash table TABLE. */)
4718 return copy_hash_table (check_hash_table (table
));
4722 DEFUN ("hash-table-count", Fhash_table_count
, Shash_table_count
, 1, 1, 0,
4723 doc
: /* Return the number of elements in TABLE. */)
4727 return make_number (check_hash_table (table
)->count
);
4731 DEFUN ("hash-table-rehash-size", Fhash_table_rehash_size
,
4732 Shash_table_rehash_size
, 1, 1, 0,
4733 doc
: /* Return the current rehash size of TABLE. */)
4737 return check_hash_table (table
)->rehash_size
;
4741 DEFUN ("hash-table-rehash-threshold", Fhash_table_rehash_threshold
,
4742 Shash_table_rehash_threshold
, 1, 1, 0,
4743 doc
: /* Return the current rehash threshold of TABLE. */)
4747 return check_hash_table (table
)->rehash_threshold
;
4751 DEFUN ("hash-table-size", Fhash_table_size
, Shash_table_size
, 1, 1, 0,
4752 doc
: /* Return the size of TABLE.
4753 The size can be used as an argument to `make-hash-table' to create
4754 a hash table than can hold as many elements of TABLE holds
4755 without need for resizing. */)
4759 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4760 return make_number (HASH_TABLE_SIZE (h
));
4764 DEFUN ("hash-table-test", Fhash_table_test
, Shash_table_test
, 1, 1, 0,
4765 doc
: /* Return the test TABLE uses. */)
4769 return check_hash_table (table
)->test
;
4773 DEFUN ("hash-table-weakness", Fhash_table_weakness
, Shash_table_weakness
,
4775 doc
: /* Return the weakness of TABLE. */)
4779 return check_hash_table (table
)->weak
;
4783 DEFUN ("hash-table-p", Fhash_table_p
, Shash_table_p
, 1, 1, 0,
4784 doc
: /* Return t if OBJ is a Lisp hash table object. */)
4788 return HASH_TABLE_P (obj
) ? Qt
: Qnil
;
4792 DEFUN ("clrhash", Fclrhash
, Sclrhash
, 1, 1, 0,
4793 doc
: /* Clear hash table TABLE and return it. */)
4797 hash_clear (check_hash_table (table
));
4798 /* Be compatible with XEmacs. */
4803 DEFUN ("gethash", Fgethash
, Sgethash
, 2, 3, 0,
4804 doc
: /* Look up KEY in TABLE and return its associated value.
4805 If KEY is not found, return DFLT which defaults to nil. */)
4807 Lisp_Object key
, table
, dflt
;
4809 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4810 int i
= hash_lookup (h
, key
, NULL
);
4811 return i
>= 0 ? HASH_VALUE (h
, i
) : dflt
;
4815 DEFUN ("puthash", Fputhash
, Sputhash
, 3, 3, 0,
4816 doc
: /* Associate KEY with VALUE in hash table TABLE.
4817 If KEY is already present in table, replace its current value with
4820 Lisp_Object key
, value
, table
;
4822 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4826 i
= hash_lookup (h
, key
, &hash
);
4828 HASH_VALUE (h
, i
) = value
;
4830 hash_put (h
, key
, value
, hash
);
4836 DEFUN ("remhash", Fremhash
, Sremhash
, 2, 2, 0,
4837 doc
: /* Remove KEY from TABLE. */)
4839 Lisp_Object key
, table
;
4841 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4842 hash_remove (h
, key
);
4847 DEFUN ("maphash", Fmaphash
, Smaphash
, 2, 2, 0,
4848 doc
: /* Call FUNCTION for all entries in hash table TABLE.
4849 FUNCTION is called with two arguments, KEY and VALUE. */)
4851 Lisp_Object function
, table
;
4853 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4854 Lisp_Object args
[3];
4857 for (i
= 0; i
< HASH_TABLE_SIZE (h
); ++i
)
4858 if (!NILP (HASH_HASH (h
, i
)))
4861 args
[1] = HASH_KEY (h
, i
);
4862 args
[2] = HASH_VALUE (h
, i
);
4870 DEFUN ("define-hash-table-test", Fdefine_hash_table_test
,
4871 Sdefine_hash_table_test
, 3, 3, 0,
4872 doc
: /* Define a new hash table test with name NAME, a symbol.
4874 In hash tables created with NAME specified as test, use TEST to
4875 compare keys, and HASH for computing hash codes of keys.
4877 TEST must be a function taking two arguments and returning non-nil if
4878 both arguments are the same. HASH must be a function taking one
4879 argument and return an integer that is the hash code of the argument.
4880 Hash code computation should use the whole value range of integers,
4881 including negative integers. */)
4883 Lisp_Object name
, test
, hash
;
4885 return Fput (name
, Qhash_table_test
, list2 (test
, hash
));
4890 /************************************************************************
4892 ************************************************************************/
4896 DEFUN ("md5", Fmd5
, Smd5
, 1, 5, 0,
4897 doc
: /* Return MD5 message digest of OBJECT, a buffer or string.
4899 A message digest is a cryptographic checksum of a document, and the
4900 algorithm to calculate it is defined in RFC 1321.
4902 The two optional arguments START and END are character positions
4903 specifying for which part of OBJECT the message digest should be
4904 computed. If nil or omitted, the digest is computed for the whole
4907 The MD5 message digest is computed from the result of encoding the
4908 text in a coding system, not directly from the internal Emacs form of
4909 the text. The optional fourth argument CODING-SYSTEM specifies which
4910 coding system to encode the text with. It should be the same coding
4911 system that you used or will use when actually writing the text into a
4914 If CODING-SYSTEM is nil or omitted, the default depends on OBJECT. If
4915 OBJECT is a buffer, the default for CODING-SYSTEM is whatever coding
4916 system would be chosen by default for writing this text into a file.
4918 If OBJECT is a string, the most preferred coding system (see the
4919 command `prefer-coding-system') is used.
4921 If NOERROR is non-nil, silently assume the `raw-text' coding if the
4922 guesswork fails. Normally, an error is signaled in such case. */)
4923 (object
, start
, end
, coding_system
, noerror
)
4924 Lisp_Object object
, start
, end
, coding_system
, noerror
;
4926 unsigned char digest
[16];
4927 unsigned char value
[33];
4931 int start_char
= 0, end_char
= 0;
4932 int start_byte
= 0, end_byte
= 0;
4934 register struct buffer
*bp
;
4937 if (STRINGP (object
))
4939 if (NILP (coding_system
))
4941 /* Decide the coding-system to encode the data with. */
4943 if (STRING_MULTIBYTE (object
))
4944 /* use default, we can't guess correct value */
4945 coding_system
= preferred_coding_system ();
4947 coding_system
= Qraw_text
;
4950 if (NILP (Fcoding_system_p (coding_system
)))
4952 /* Invalid coding system. */
4954 if (!NILP (noerror
))
4955 coding_system
= Qraw_text
;
4957 xsignal1 (Qcoding_system_error
, coding_system
);
4960 if (STRING_MULTIBYTE (object
))
4961 object
= code_convert_string (object
, coding_system
, Qnil
, 1, 0, 1);
4963 size
= SCHARS (object
);
4964 size_byte
= SBYTES (object
);
4968 CHECK_NUMBER (start
);
4970 start_char
= XINT (start
);
4975 start_byte
= string_char_to_byte (object
, start_char
);
4981 end_byte
= size_byte
;
4987 end_char
= XINT (end
);
4992 end_byte
= string_char_to_byte (object
, end_char
);
4995 if (!(0 <= start_char
&& start_char
<= end_char
&& end_char
<= size
))
4996 args_out_of_range_3 (object
, make_number (start_char
),
4997 make_number (end_char
));
5001 struct buffer
*prev
= current_buffer
;
5003 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5005 CHECK_BUFFER (object
);
5007 bp
= XBUFFER (object
);
5008 if (bp
!= current_buffer
)
5009 set_buffer_internal (bp
);
5015 CHECK_NUMBER_COERCE_MARKER (start
);
5023 CHECK_NUMBER_COERCE_MARKER (end
);
5028 temp
= b
, b
= e
, e
= temp
;
5030 if (!(BEGV
<= b
&& e
<= ZV
))
5031 args_out_of_range (start
, end
);
5033 if (NILP (coding_system
))
5035 /* Decide the coding-system to encode the data with.
5036 See fileio.c:Fwrite-region */
5038 if (!NILP (Vcoding_system_for_write
))
5039 coding_system
= Vcoding_system_for_write
;
5042 int force_raw_text
= 0;
5044 coding_system
= XBUFFER (object
)->buffer_file_coding_system
;
5045 if (NILP (coding_system
)
5046 || NILP (Flocal_variable_p (Qbuffer_file_coding_system
, Qnil
)))
5048 coding_system
= Qnil
;
5049 if (NILP (current_buffer
->enable_multibyte_characters
))
5053 if (NILP (coding_system
) && !NILP (Fbuffer_file_name(object
)))
5055 /* Check file-coding-system-alist. */
5056 Lisp_Object args
[4], val
;
5058 args
[0] = Qwrite_region
; args
[1] = start
; args
[2] = end
;
5059 args
[3] = Fbuffer_file_name(object
);
5060 val
= Ffind_operation_coding_system (4, args
);
5061 if (CONSP (val
) && !NILP (XCDR (val
)))
5062 coding_system
= XCDR (val
);
5065 if (NILP (coding_system
)
5066 && !NILP (XBUFFER (object
)->buffer_file_coding_system
))
5068 /* If we still have not decided a coding system, use the
5069 default value of buffer-file-coding-system. */
5070 coding_system
= XBUFFER (object
)->buffer_file_coding_system
;
5074 && !NILP (Ffboundp (Vselect_safe_coding_system_function
)))
5075 /* Confirm that VAL can surely encode the current region. */
5076 coding_system
= call4 (Vselect_safe_coding_system_function
,
5077 make_number (b
), make_number (e
),
5078 coding_system
, Qnil
);
5081 coding_system
= Qraw_text
;
5084 if (NILP (Fcoding_system_p (coding_system
)))
5086 /* Invalid coding system. */
5088 if (!NILP (noerror
))
5089 coding_system
= Qraw_text
;
5091 xsignal1 (Qcoding_system_error
, coding_system
);
5095 object
= make_buffer_string (b
, e
, 0);
5096 if (prev
!= current_buffer
)
5097 set_buffer_internal (prev
);
5098 /* Discard the unwind protect for recovering the current
5102 if (STRING_MULTIBYTE (object
))
5103 object
= code_convert_string (object
, coding_system
, Qnil
, 1, 0, 0);
5106 md5_buffer (SDATA (object
) + start_byte
,
5107 SBYTES (object
) - (size_byte
- end_byte
),
5110 for (i
= 0; i
< 16; i
++)
5111 sprintf (&value
[2 * i
], "%02x", digest
[i
]);
5114 return make_string (value
, 32);
5121 /* Hash table stuff. */
5122 Qhash_table_p
= intern ("hash-table-p");
5123 staticpro (&Qhash_table_p
);
5124 Qeq
= intern ("eq");
5126 Qeql
= intern ("eql");
5128 Qequal
= intern ("equal");
5129 staticpro (&Qequal
);
5130 QCtest
= intern (":test");
5131 staticpro (&QCtest
);
5132 QCsize
= intern (":size");
5133 staticpro (&QCsize
);
5134 QCrehash_size
= intern (":rehash-size");
5135 staticpro (&QCrehash_size
);
5136 QCrehash_threshold
= intern (":rehash-threshold");
5137 staticpro (&QCrehash_threshold
);
5138 QCweakness
= intern (":weakness");
5139 staticpro (&QCweakness
);
5140 Qkey
= intern ("key");
5142 Qvalue
= intern ("value");
5143 staticpro (&Qvalue
);
5144 Qhash_table_test
= intern ("hash-table-test");
5145 staticpro (&Qhash_table_test
);
5146 Qkey_or_value
= intern ("key-or-value");
5147 staticpro (&Qkey_or_value
);
5148 Qkey_and_value
= intern ("key-and-value");
5149 staticpro (&Qkey_and_value
);
5152 defsubr (&Smake_hash_table
);
5153 defsubr (&Scopy_hash_table
);
5154 defsubr (&Shash_table_count
);
5155 defsubr (&Shash_table_rehash_size
);
5156 defsubr (&Shash_table_rehash_threshold
);
5157 defsubr (&Shash_table_size
);
5158 defsubr (&Shash_table_test
);
5159 defsubr (&Shash_table_weakness
);
5160 defsubr (&Shash_table_p
);
5161 defsubr (&Sclrhash
);
5162 defsubr (&Sgethash
);
5163 defsubr (&Sputhash
);
5164 defsubr (&Sremhash
);
5165 defsubr (&Smaphash
);
5166 defsubr (&Sdefine_hash_table_test
);
5168 Qstring_lessp
= intern ("string-lessp");
5169 staticpro (&Qstring_lessp
);
5170 Qprovide
= intern ("provide");
5171 staticpro (&Qprovide
);
5172 Qrequire
= intern ("require");
5173 staticpro (&Qrequire
);
5174 Qyes_or_no_p_history
= intern ("yes-or-no-p-history");
5175 staticpro (&Qyes_or_no_p_history
);
5176 Qcursor_in_echo_area
= intern ("cursor-in-echo-area");
5177 staticpro (&Qcursor_in_echo_area
);
5178 Qwidget_type
= intern ("widget-type");
5179 staticpro (&Qwidget_type
);
5181 staticpro (&string_char_byte_cache_string
);
5182 string_char_byte_cache_string
= Qnil
;
5184 require_nesting_list
= Qnil
;
5185 staticpro (&require_nesting_list
);
5187 Fset (Qyes_or_no_p_history
, Qnil
);
5189 DEFVAR_LISP ("features", &Vfeatures
,
5190 doc
: /* A list of symbols which are the features of the executing Emacs.
5191 Used by `featurep' and `require', and altered by `provide'. */);
5192 Vfeatures
= Fcons (intern ("emacs"), Qnil
);
5193 Qsubfeatures
= intern ("subfeatures");
5194 staticpro (&Qsubfeatures
);
5196 #ifdef HAVE_LANGINFO_CODESET
5197 Qcodeset
= intern ("codeset");
5198 staticpro (&Qcodeset
);
5199 Qdays
= intern ("days");
5201 Qmonths
= intern ("months");
5202 staticpro (&Qmonths
);
5203 Qpaper
= intern ("paper");
5204 staticpro (&Qpaper
);
5205 #endif /* HAVE_LANGINFO_CODESET */
5207 DEFVAR_BOOL ("use-dialog-box", &use_dialog_box
,
5208 doc
: /* *Non-nil means mouse commands use dialog boxes to ask questions.
5209 This applies to `y-or-n-p' and `yes-or-no-p' questions asked by commands
5210 invoked by mouse clicks and mouse menu items. */);
5213 DEFVAR_BOOL ("use-file-dialog", &use_file_dialog
,
5214 doc
: /* *Non-nil means mouse commands use a file dialog to ask for files.
5215 This applies to commands from menus and tool bar buttons even when
5216 they are initiated from the keyboard. The value of `use-dialog-box'
5217 takes precedence over this variable, so a file dialog is only used if
5218 both `use-dialog-box' and this variable are non-nil. */);
5219 use_file_dialog
= 1;
5221 defsubr (&Sidentity
);
5224 defsubr (&Ssafe_length
);
5225 defsubr (&Sstring_bytes
);
5226 defsubr (&Sstring_equal
);
5227 defsubr (&Scompare_strings
);
5228 defsubr (&Sstring_lessp
);
5231 defsubr (&Svconcat
);
5232 defsubr (&Scopy_sequence
);
5233 defsubr (&Sstring_make_multibyte
);
5234 defsubr (&Sstring_make_unibyte
);
5235 defsubr (&Sstring_as_multibyte
);
5236 defsubr (&Sstring_as_unibyte
);
5237 defsubr (&Sstring_to_multibyte
);
5238 defsubr (&Scopy_alist
);
5239 defsubr (&Ssubstring
);
5240 defsubr (&Ssubstring_no_properties
);
5253 defsubr (&Snreverse
);
5254 defsubr (&Sreverse
);
5256 defsubr (&Splist_get
);
5258 defsubr (&Splist_put
);
5260 defsubr (&Slax_plist_get
);
5261 defsubr (&Slax_plist_put
);
5264 defsubr (&Sequal_including_properties
);
5265 defsubr (&Sfillarray
);
5266 defsubr (&Sclear_string
);
5270 defsubr (&Smapconcat
);
5271 defsubr (&Sy_or_n_p
);
5272 defsubr (&Syes_or_no_p
);
5273 defsubr (&Sload_average
);
5274 defsubr (&Sfeaturep
);
5275 defsubr (&Srequire
);
5276 defsubr (&Sprovide
);
5277 defsubr (&Splist_member
);
5278 defsubr (&Swidget_put
);
5279 defsubr (&Swidget_get
);
5280 defsubr (&Swidget_apply
);
5281 defsubr (&Sbase64_encode_region
);
5282 defsubr (&Sbase64_decode_region
);
5283 defsubr (&Sbase64_encode_string
);
5284 defsubr (&Sbase64_decode_string
);
5286 defsubr (&Slocale_info
);
5295 /* arch-tag: 787f8219-5b74-46bd-8469-7e1cc475fa31
5296 (do not change this comment) */