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, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30 /* Note on some machines this defines `vector' as a typedef,
31 so make sure we don't use that name in this file. */
37 #include "character.h"
42 #include "intervals.h"
45 #include "blockinput.h"
47 #if defined (HAVE_X_WINDOWS)
50 #endif /* HAVE_MENUS */
53 #define NULL ((POINTER_TYPE *)0)
56 /* Nonzero enables use of dialog boxes for questions
57 asked by mouse commands. */
60 /* Nonzero enables use of a file dialog for file name
61 questions asked by mouse commands. */
64 Lisp_Object Qstring_lessp
, Qprovide
, Qrequire
;
65 Lisp_Object Qyes_or_no_p_history
;
66 Lisp_Object Qcursor_in_echo_area
;
67 Lisp_Object Qwidget_type
;
68 Lisp_Object Qcodeset
, Qdays
, Qmonths
, Qpaper
;
70 static int internal_equal (Lisp_Object
, Lisp_Object
, int, int);
72 extern long get_random (void);
73 extern void seed_random (long);
79 DEFUN ("identity", Fidentity
, Sidentity
, 1, 1, 0,
80 doc
: /* Return the argument unchanged. */)
86 DEFUN ("random", Frandom
, Srandom
, 0, 1, 0,
87 doc
: /* Return a pseudo-random number.
88 All integers representable in Lisp are equally likely.
89 On most systems, this is 29 bits' worth.
90 With positive integer LIMIT, return random number in interval [0,LIMIT).
91 With argument t, set the random number seed from the current time and pid.
92 Other values of LIMIT are ignored. */)
96 Lisp_Object lispy_val
;
97 unsigned long denominator
;
100 seed_random (getpid () + time (NULL
));
101 if (NATNUMP (limit
) && XFASTINT (limit
) != 0)
103 /* Try to take our random number from the higher bits of VAL,
104 not the lower, since (says Gentzel) the low bits of `random'
105 are less random than the higher ones. We do this by using the
106 quotient rather than the remainder. At the high end of the RNG
107 it's possible to get a quotient larger than n; discarding
108 these values eliminates the bias that would otherwise appear
109 when using a large n. */
110 denominator
= ((unsigned long)1 << VALBITS
) / XFASTINT (limit
);
112 val
= get_random () / denominator
;
113 while (val
>= XFASTINT (limit
));
117 XSETINT (lispy_val
, val
);
121 /* Random data-structure functions */
123 DEFUN ("length", Flength
, Slength
, 1, 1, 0,
124 doc
: /* Return the length of vector, list or string SEQUENCE.
125 A byte-code function object is also allowed.
126 If the string contains multibyte characters, this is not necessarily
127 the number of bytes in the string; it is the number of characters.
128 To get the number of bytes, use `string-bytes'. */)
129 (register Lisp_Object sequence
)
131 register Lisp_Object val
;
134 if (STRINGP (sequence
))
135 XSETFASTINT (val
, SCHARS (sequence
));
136 else if (VECTORP (sequence
))
137 XSETFASTINT (val
, ASIZE (sequence
));
138 else if (CHAR_TABLE_P (sequence
))
139 XSETFASTINT (val
, MAX_CHAR
);
140 else if (BOOL_VECTOR_P (sequence
))
141 XSETFASTINT (val
, XBOOL_VECTOR (sequence
)->size
);
142 else if (COMPILEDP (sequence
))
143 XSETFASTINT (val
, ASIZE (sequence
) & PSEUDOVECTOR_SIZE_MASK
);
144 else if (CONSP (sequence
))
147 while (CONSP (sequence
))
149 sequence
= XCDR (sequence
);
152 if (!CONSP (sequence
))
155 sequence
= XCDR (sequence
);
160 CHECK_LIST_END (sequence
, sequence
);
162 val
= make_number (i
);
164 else if (NILP (sequence
))
165 XSETFASTINT (val
, 0);
167 wrong_type_argument (Qsequencep
, sequence
);
172 /* This does not check for quits. That is safe since it must terminate. */
174 DEFUN ("safe-length", Fsafe_length
, Ssafe_length
, 1, 1, 0,
175 doc
: /* Return the length of a list, but avoid error or infinite loop.
176 This function never gets an error. If LIST is not really a list,
177 it returns 0. If LIST is circular, it returns a finite value
178 which is at least the number of distinct elements. */)
181 Lisp_Object tail
, halftail
, length
;
184 /* halftail is used to detect circular lists. */
186 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
188 if (EQ (tail
, halftail
) && len
!= 0)
192 halftail
= XCDR (halftail
);
195 XSETINT (length
, len
);
199 DEFUN ("string-bytes", Fstring_bytes
, Sstring_bytes
, 1, 1, 0,
200 doc
: /* Return the number of bytes in STRING.
201 If STRING is multibyte, this may be greater than the length of STRING. */)
204 CHECK_STRING (string
);
205 return make_number (SBYTES (string
));
208 DEFUN ("string-equal", Fstring_equal
, Sstring_equal
, 2, 2, 0,
209 doc
: /* Return t if two strings have identical contents.
210 Case is significant, but text properties are ignored.
211 Symbols are also allowed; their print names are used instead. */)
212 (register Lisp_Object s1
, Lisp_Object s2
)
215 s1
= SYMBOL_NAME (s1
);
217 s2
= SYMBOL_NAME (s2
);
221 if (SCHARS (s1
) != SCHARS (s2
)
222 || SBYTES (s1
) != SBYTES (s2
)
223 || memcmp (SDATA (s1
), SDATA (s2
), SBYTES (s1
)))
228 DEFUN ("compare-strings", Fcompare_strings
, Scompare_strings
, 6, 7, 0,
229 doc
: /* Compare the contents of two strings, converting to multibyte if needed.
230 In string STR1, skip the first START1 characters and stop at END1.
231 In string STR2, skip the first START2 characters and stop at END2.
232 END1 and END2 default to the full lengths of the respective strings.
234 Case is significant in this comparison if IGNORE-CASE is nil.
235 Unibyte strings are converted to multibyte for comparison.
237 The value is t if the strings (or specified portions) match.
238 If string STR1 is less, the value is a negative number N;
239 - 1 - N is the number of characters that match at the beginning.
240 If string STR1 is greater, the value is a positive number N;
241 N - 1 is the number of characters that match at the beginning. */)
242 (Lisp_Object str1
, Lisp_Object start1
, Lisp_Object end1
, Lisp_Object str2
, Lisp_Object start2
, Lisp_Object end2
, Lisp_Object ignore_case
)
244 register EMACS_INT end1_char
, end2_char
;
245 register EMACS_INT i1
, i1_byte
, i2
, i2_byte
;
250 start1
= make_number (0);
252 start2
= make_number (0);
253 CHECK_NATNUM (start1
);
254 CHECK_NATNUM (start2
);
263 i1_byte
= string_char_to_byte (str1
, i1
);
264 i2_byte
= string_char_to_byte (str2
, i2
);
266 end1_char
= SCHARS (str1
);
267 if (! NILP (end1
) && end1_char
> XINT (end1
))
268 end1_char
= XINT (end1
);
270 end2_char
= SCHARS (str2
);
271 if (! NILP (end2
) && end2_char
> XINT (end2
))
272 end2_char
= XINT (end2
);
274 while (i1
< end1_char
&& i2
< end2_char
)
276 /* When we find a mismatch, we must compare the
277 characters, not just the bytes. */
280 if (STRING_MULTIBYTE (str1
))
281 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c1
, str1
, i1
, i1_byte
);
284 c1
= SREF (str1
, i1
++);
285 MAKE_CHAR_MULTIBYTE (c1
);
288 if (STRING_MULTIBYTE (str2
))
289 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c2
, str2
, i2
, i2_byte
);
292 c2
= SREF (str2
, i2
++);
293 MAKE_CHAR_MULTIBYTE (c2
);
299 if (! NILP (ignore_case
))
303 tem
= Fupcase (make_number (c1
));
305 tem
= Fupcase (make_number (c2
));
312 /* Note that I1 has already been incremented
313 past the character that we are comparing;
314 hence we don't add or subtract 1 here. */
316 return make_number (- i1
+ XINT (start1
));
318 return make_number (i1
- XINT (start1
));
322 return make_number (i1
- XINT (start1
) + 1);
324 return make_number (- i1
+ XINT (start1
) - 1);
329 DEFUN ("string-lessp", Fstring_lessp
, Sstring_lessp
, 2, 2, 0,
330 doc
: /* Return t if first arg string is less than second in lexicographic order.
332 Symbols are also allowed; their print names are used instead. */)
333 (register Lisp_Object s1
, Lisp_Object s2
)
335 register EMACS_INT end
;
336 register EMACS_INT i1
, i1_byte
, i2
, i2_byte
;
339 s1
= SYMBOL_NAME (s1
);
341 s2
= SYMBOL_NAME (s2
);
345 i1
= i1_byte
= i2
= i2_byte
= 0;
348 if (end
> SCHARS (s2
))
353 /* When we find a mismatch, we must compare the
354 characters, not just the bytes. */
357 FETCH_STRING_CHAR_ADVANCE (c1
, s1
, i1
, i1_byte
);
358 FETCH_STRING_CHAR_ADVANCE (c2
, s2
, i2
, i2_byte
);
361 return c1
< c2
? Qt
: Qnil
;
363 return i1
< SCHARS (s2
) ? Qt
: Qnil
;
366 static Lisp_Object
concat (int nargs
, Lisp_Object
*args
,
367 enum Lisp_Type target_type
, int last_special
);
371 concat2 (Lisp_Object s1
, Lisp_Object s2
)
376 return concat (2, args
, Lisp_String
, 0);
381 concat3 (Lisp_Object s1
, Lisp_Object s2
, Lisp_Object s3
)
387 return concat (3, args
, Lisp_String
, 0);
390 DEFUN ("append", Fappend
, Sappend
, 0, MANY
, 0,
391 doc
: /* Concatenate all the arguments and make the result a list.
392 The result is a list whose elements are the elements of all the arguments.
393 Each argument may be a list, vector or string.
394 The last argument is not copied, just used as the tail of the new list.
395 usage: (append &rest SEQUENCES) */)
396 (int nargs
, Lisp_Object
*args
)
398 return concat (nargs
, args
, Lisp_Cons
, 1);
401 DEFUN ("concat", Fconcat
, Sconcat
, 0, MANY
, 0,
402 doc
: /* Concatenate all the arguments and make the result a string.
403 The result is a string whose elements are the elements of all the arguments.
404 Each argument may be a string or a list or vector of characters (integers).
405 usage: (concat &rest SEQUENCES) */)
406 (int nargs
, Lisp_Object
*args
)
408 return concat (nargs
, args
, Lisp_String
, 0);
411 DEFUN ("vconcat", Fvconcat
, Svconcat
, 0, MANY
, 0,
412 doc
: /* Concatenate all the arguments and make the result a vector.
413 The result is a vector whose elements are the elements of all the arguments.
414 Each argument may be a list, vector or string.
415 usage: (vconcat &rest SEQUENCES) */)
416 (int nargs
, Lisp_Object
*args
)
418 return concat (nargs
, args
, Lisp_Vectorlike
, 0);
422 DEFUN ("copy-sequence", Fcopy_sequence
, Scopy_sequence
, 1, 1, 0,
423 doc
: /* Return a copy of a list, vector, string or char-table.
424 The elements of a list or vector are not copied; they are shared
425 with the original. */)
428 if (NILP (arg
)) return arg
;
430 if (CHAR_TABLE_P (arg
))
432 return copy_char_table (arg
);
435 if (BOOL_VECTOR_P (arg
))
439 = ((XBOOL_VECTOR (arg
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
440 / BOOL_VECTOR_BITS_PER_CHAR
);
442 val
= Fmake_bool_vector (Flength (arg
), Qnil
);
443 memcpy (XBOOL_VECTOR (val
)->data
, XBOOL_VECTOR (arg
)->data
,
448 if (!CONSP (arg
) && !VECTORP (arg
) && !STRINGP (arg
))
449 wrong_type_argument (Qsequencep
, arg
);
451 return concat (1, &arg
, CONSP (arg
) ? Lisp_Cons
: XTYPE (arg
), 0);
454 /* This structure holds information of an argument of `concat' that is
455 a string and has text properties to be copied. */
458 int argnum
; /* refer to ARGS (arguments of `concat') */
459 EMACS_INT from
; /* refer to ARGS[argnum] (argument string) */
460 EMACS_INT to
; /* refer to VAL (the target string) */
464 concat (int nargs
, Lisp_Object
*args
, enum Lisp_Type target_type
, int last_special
)
467 register Lisp_Object tail
;
468 register Lisp_Object
this;
470 EMACS_INT toindex_byte
= 0;
471 register EMACS_INT result_len
;
472 register EMACS_INT result_len_byte
;
474 Lisp_Object last_tail
;
477 /* When we make a multibyte string, we can't copy text properties
478 while concatinating each string because the length of resulting
479 string can't be decided until we finish the whole concatination.
480 So, we record strings that have text properties to be copied
481 here, and copy the text properties after the concatination. */
482 struct textprop_rec
*textprops
= NULL
;
483 /* Number of elements in textprops. */
484 int num_textprops
= 0;
489 /* In append, the last arg isn't treated like the others */
490 if (last_special
&& nargs
> 0)
493 last_tail
= args
[nargs
];
498 /* Check each argument. */
499 for (argnum
= 0; argnum
< nargs
; argnum
++)
502 if (!(CONSP (this) || NILP (this) || VECTORP (this) || STRINGP (this)
503 || COMPILEDP (this) || BOOL_VECTOR_P (this)))
504 wrong_type_argument (Qsequencep
, this);
507 /* Compute total length in chars of arguments in RESULT_LEN.
508 If desired output is a string, also compute length in bytes
509 in RESULT_LEN_BYTE, and determine in SOME_MULTIBYTE
510 whether the result should be a multibyte string. */
514 for (argnum
= 0; argnum
< nargs
; argnum
++)
518 len
= XFASTINT (Flength (this));
519 if (target_type
== Lisp_String
)
521 /* We must count the number of bytes needed in the string
522 as well as the number of characters. */
525 EMACS_INT this_len_byte
;
528 for (i
= 0; i
< len
; i
++)
531 CHECK_CHARACTER (ch
);
532 this_len_byte
= CHAR_BYTES (XINT (ch
));
533 result_len_byte
+= this_len_byte
;
534 if (! ASCII_CHAR_P (XINT (ch
)) && ! CHAR_BYTE8_P (XINT (ch
)))
537 else if (BOOL_VECTOR_P (this) && XBOOL_VECTOR (this)->size
> 0)
538 wrong_type_argument (Qintegerp
, Faref (this, make_number (0)));
539 else if (CONSP (this))
540 for (; CONSP (this); this = XCDR (this))
543 CHECK_CHARACTER (ch
);
544 this_len_byte
= CHAR_BYTES (XINT (ch
));
545 result_len_byte
+= this_len_byte
;
546 if (! ASCII_CHAR_P (XINT (ch
)) && ! CHAR_BYTE8_P (XINT (ch
)))
549 else if (STRINGP (this))
551 if (STRING_MULTIBYTE (this))
554 result_len_byte
+= SBYTES (this);
557 result_len_byte
+= count_size_as_multibyte (SDATA (this),
564 error ("String overflow");
567 if (! some_multibyte
)
568 result_len_byte
= result_len
;
570 /* Create the output object. */
571 if (target_type
== Lisp_Cons
)
572 val
= Fmake_list (make_number (result_len
), Qnil
);
573 else if (target_type
== Lisp_Vectorlike
)
574 val
= Fmake_vector (make_number (result_len
), Qnil
);
575 else if (some_multibyte
)
576 val
= make_uninit_multibyte_string (result_len
, result_len_byte
);
578 val
= make_uninit_string (result_len
);
580 /* In `append', if all but last arg are nil, return last arg. */
581 if (target_type
== Lisp_Cons
&& EQ (val
, Qnil
))
584 /* Copy the contents of the args into the result. */
586 tail
= val
, toindex
= -1; /* -1 in toindex is flag we are making a list */
588 toindex
= 0, toindex_byte
= 0;
592 SAFE_ALLOCA (textprops
, struct textprop_rec
*, sizeof (struct textprop_rec
) * nargs
);
594 for (argnum
= 0; argnum
< nargs
; argnum
++)
597 EMACS_INT thisleni
= 0;
598 register EMACS_INT thisindex
= 0;
599 register EMACS_INT thisindex_byte
= 0;
603 thislen
= Flength (this), thisleni
= XINT (thislen
);
605 /* Between strings of the same kind, copy fast. */
606 if (STRINGP (this) && STRINGP (val
)
607 && STRING_MULTIBYTE (this) == some_multibyte
)
609 EMACS_INT thislen_byte
= SBYTES (this);
611 memcpy (SDATA (val
) + toindex_byte
, SDATA (this), SBYTES (this));
612 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
614 textprops
[num_textprops
].argnum
= argnum
;
615 textprops
[num_textprops
].from
= 0;
616 textprops
[num_textprops
++].to
= toindex
;
618 toindex_byte
+= thislen_byte
;
621 /* Copy a single-byte string to a multibyte string. */
622 else if (STRINGP (this) && STRINGP (val
))
624 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
626 textprops
[num_textprops
].argnum
= argnum
;
627 textprops
[num_textprops
].from
= 0;
628 textprops
[num_textprops
++].to
= toindex
;
630 toindex_byte
+= copy_text (SDATA (this),
631 SDATA (val
) + toindex_byte
,
632 SCHARS (this), 0, 1);
636 /* Copy element by element. */
639 register Lisp_Object elt
;
641 /* Fetch next element of `this' arg into `elt', or break if
642 `this' is exhausted. */
643 if (NILP (this)) break;
645 elt
= XCAR (this), this = XCDR (this);
646 else if (thisindex
>= thisleni
)
648 else if (STRINGP (this))
651 if (STRING_MULTIBYTE (this))
653 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, this,
656 XSETFASTINT (elt
, c
);
660 XSETFASTINT (elt
, SREF (this, thisindex
)); thisindex
++;
662 && !ASCII_CHAR_P (XINT (elt
))
663 && XINT (elt
) < 0400)
665 c
= BYTE8_TO_CHAR (XINT (elt
));
670 else if (BOOL_VECTOR_P (this))
673 byte
= XBOOL_VECTOR (this)->data
[thisindex
/ BOOL_VECTOR_BITS_PER_CHAR
];
674 if (byte
& (1 << (thisindex
% BOOL_VECTOR_BITS_PER_CHAR
)))
682 elt
= AREF (this, thisindex
);
686 /* Store this element into the result. */
693 else if (VECTORP (val
))
695 ASET (val
, toindex
, elt
);
702 toindex_byte
+= CHAR_STRING (XINT (elt
),
703 SDATA (val
) + toindex_byte
);
705 SSET (val
, toindex_byte
++, XINT (elt
));
711 XSETCDR (prev
, last_tail
);
713 if (num_textprops
> 0)
716 EMACS_INT last_to_end
= -1;
718 for (argnum
= 0; argnum
< num_textprops
; argnum
++)
720 this = args
[textprops
[argnum
].argnum
];
721 props
= text_property_list (this,
723 make_number (SCHARS (this)),
725 /* If successive arguments have properites, be sure that the
726 value of `composition' property be the copy. */
727 if (last_to_end
== textprops
[argnum
].to
)
728 make_composition_value_copy (props
);
729 add_text_properties_from_list (val
, props
,
730 make_number (textprops
[argnum
].to
));
731 last_to_end
= textprops
[argnum
].to
+ SCHARS (this);
739 static Lisp_Object string_char_byte_cache_string
;
740 static EMACS_INT string_char_byte_cache_charpos
;
741 static EMACS_INT string_char_byte_cache_bytepos
;
744 clear_string_char_byte_cache (void)
746 string_char_byte_cache_string
= Qnil
;
749 /* Return the byte index corresponding to CHAR_INDEX in STRING. */
752 string_char_to_byte (Lisp_Object string
, EMACS_INT char_index
)
755 EMACS_INT best_below
, best_below_byte
;
756 EMACS_INT best_above
, best_above_byte
;
758 best_below
= best_below_byte
= 0;
759 best_above
= SCHARS (string
);
760 best_above_byte
= SBYTES (string
);
761 if (best_above
== best_above_byte
)
764 if (EQ (string
, string_char_byte_cache_string
))
766 if (string_char_byte_cache_charpos
< char_index
)
768 best_below
= string_char_byte_cache_charpos
;
769 best_below_byte
= string_char_byte_cache_bytepos
;
773 best_above
= string_char_byte_cache_charpos
;
774 best_above_byte
= string_char_byte_cache_bytepos
;
778 if (char_index
- best_below
< best_above
- char_index
)
780 unsigned char *p
= SDATA (string
) + best_below_byte
;
782 while (best_below
< char_index
)
784 p
+= BYTES_BY_CHAR_HEAD (*p
);
787 i_byte
= p
- SDATA (string
);
791 unsigned char *p
= SDATA (string
) + best_above_byte
;
793 while (best_above
> char_index
)
796 while (!CHAR_HEAD_P (*p
)) p
--;
799 i_byte
= p
- SDATA (string
);
802 string_char_byte_cache_bytepos
= i_byte
;
803 string_char_byte_cache_charpos
= char_index
;
804 string_char_byte_cache_string
= string
;
809 /* Return the character index corresponding to BYTE_INDEX in STRING. */
812 string_byte_to_char (Lisp_Object string
, EMACS_INT byte_index
)
815 EMACS_INT best_below
, best_below_byte
;
816 EMACS_INT best_above
, best_above_byte
;
818 best_below
= best_below_byte
= 0;
819 best_above
= SCHARS (string
);
820 best_above_byte
= SBYTES (string
);
821 if (best_above
== best_above_byte
)
824 if (EQ (string
, string_char_byte_cache_string
))
826 if (string_char_byte_cache_bytepos
< byte_index
)
828 best_below
= string_char_byte_cache_charpos
;
829 best_below_byte
= string_char_byte_cache_bytepos
;
833 best_above
= string_char_byte_cache_charpos
;
834 best_above_byte
= string_char_byte_cache_bytepos
;
838 if (byte_index
- best_below_byte
< best_above_byte
- byte_index
)
840 unsigned char *p
= SDATA (string
) + best_below_byte
;
841 unsigned char *pend
= SDATA (string
) + byte_index
;
845 p
+= BYTES_BY_CHAR_HEAD (*p
);
849 i_byte
= p
- SDATA (string
);
853 unsigned char *p
= SDATA (string
) + best_above_byte
;
854 unsigned char *pbeg
= SDATA (string
) + byte_index
;
859 while (!CHAR_HEAD_P (*p
)) p
--;
863 i_byte
= p
- SDATA (string
);
866 string_char_byte_cache_bytepos
= i_byte
;
867 string_char_byte_cache_charpos
= i
;
868 string_char_byte_cache_string
= string
;
873 /* Convert STRING to a multibyte string. */
876 string_make_multibyte (Lisp_Object string
)
883 if (STRING_MULTIBYTE (string
))
886 nbytes
= count_size_as_multibyte (SDATA (string
),
888 /* If all the chars are ASCII, they won't need any more bytes
889 once converted. In that case, we can return STRING itself. */
890 if (nbytes
== SBYTES (string
))
893 SAFE_ALLOCA (buf
, unsigned char *, nbytes
);
894 copy_text (SDATA (string
), buf
, SBYTES (string
),
897 ret
= make_multibyte_string (buf
, SCHARS (string
), nbytes
);
904 /* Convert STRING (if unibyte) to a multibyte string without changing
905 the number of characters. Characters 0200 trough 0237 are
906 converted to eight-bit characters. */
909 string_to_multibyte (Lisp_Object string
)
916 if (STRING_MULTIBYTE (string
))
919 nbytes
= parse_str_to_multibyte (SDATA (string
), SBYTES (string
));
920 /* If all the chars are ASCII, they won't need any more bytes once
922 if (nbytes
== SBYTES (string
))
923 return make_multibyte_string (SDATA (string
), nbytes
, nbytes
);
925 SAFE_ALLOCA (buf
, unsigned char *, nbytes
);
926 memcpy (buf
, SDATA (string
), SBYTES (string
));
927 str_to_multibyte (buf
, nbytes
, SBYTES (string
));
929 ret
= make_multibyte_string (buf
, SCHARS (string
), nbytes
);
936 /* Convert STRING to a single-byte string. */
939 string_make_unibyte (Lisp_Object string
)
946 if (! STRING_MULTIBYTE (string
))
949 nchars
= SCHARS (string
);
951 SAFE_ALLOCA (buf
, unsigned char *, nchars
);
952 copy_text (SDATA (string
), buf
, SBYTES (string
),
955 ret
= make_unibyte_string (buf
, nchars
);
961 DEFUN ("string-make-multibyte", Fstring_make_multibyte
, Sstring_make_multibyte
,
963 doc
: /* Return the multibyte equivalent of STRING.
964 If STRING is unibyte and contains non-ASCII characters, the function
965 `unibyte-char-to-multibyte' is used to convert each unibyte character
966 to a multibyte character. In this case, the returned string is a
967 newly created string with no text properties. If STRING is multibyte
968 or entirely ASCII, it is returned unchanged. In particular, when
969 STRING is unibyte and entirely ASCII, the returned string is unibyte.
970 \(When the characters are all ASCII, Emacs primitives will treat the
971 string the same way whether it is unibyte or multibyte.) */)
974 CHECK_STRING (string
);
976 return string_make_multibyte (string
);
979 DEFUN ("string-make-unibyte", Fstring_make_unibyte
, Sstring_make_unibyte
,
981 doc
: /* Return the unibyte equivalent of STRING.
982 Multibyte character codes are converted to unibyte according to
983 `nonascii-translation-table' or, if that is nil, `nonascii-insert-offset'.
984 If the lookup in the translation table fails, this function takes just
985 the low 8 bits of each character. */)
988 CHECK_STRING (string
);
990 return string_make_unibyte (string
);
993 DEFUN ("string-as-unibyte", Fstring_as_unibyte
, Sstring_as_unibyte
,
995 doc
: /* Return a unibyte string with the same individual bytes as STRING.
996 If STRING is unibyte, the result is STRING itself.
997 Otherwise it is a newly created string, with no text properties.
998 If STRING is multibyte and contains a character of charset
999 `eight-bit', it is converted to the corresponding single byte. */)
1000 (Lisp_Object string
)
1002 CHECK_STRING (string
);
1004 if (STRING_MULTIBYTE (string
))
1006 EMACS_INT bytes
= SBYTES (string
);
1007 unsigned char *str
= (unsigned char *) xmalloc (bytes
);
1009 memcpy (str
, SDATA (string
), bytes
);
1010 bytes
= str_as_unibyte (str
, bytes
);
1011 string
= make_unibyte_string (str
, bytes
);
1017 DEFUN ("string-as-multibyte", Fstring_as_multibyte
, Sstring_as_multibyte
,
1019 doc
: /* Return a multibyte string with the same individual bytes as STRING.
1020 If STRING is multibyte, the result is STRING itself.
1021 Otherwise it is a newly created string, with no text properties.
1023 If STRING is unibyte and contains an individual 8-bit byte (i.e. not
1024 part of a correct utf-8 sequence), it is converted to the corresponding
1025 multibyte character of charset `eight-bit'.
1026 See also `string-to-multibyte'.
1028 Beware, this often doesn't really do what you think it does.
1029 It is similar to (decode-coding-string STRING 'utf-8-emacs).
1030 If you're not sure, whether to use `string-as-multibyte' or
1031 `string-to-multibyte', use `string-to-multibyte'. */)
1032 (Lisp_Object string
)
1034 CHECK_STRING (string
);
1036 if (! STRING_MULTIBYTE (string
))
1038 Lisp_Object new_string
;
1039 EMACS_INT nchars
, nbytes
;
1041 parse_str_as_multibyte (SDATA (string
),
1044 new_string
= make_uninit_multibyte_string (nchars
, nbytes
);
1045 memcpy (SDATA (new_string
), SDATA (string
), SBYTES (string
));
1046 if (nbytes
!= SBYTES (string
))
1047 str_as_multibyte (SDATA (new_string
), nbytes
,
1048 SBYTES (string
), NULL
);
1049 string
= new_string
;
1050 STRING_SET_INTERVALS (string
, NULL_INTERVAL
);
1055 DEFUN ("string-to-multibyte", Fstring_to_multibyte
, Sstring_to_multibyte
,
1057 doc
: /* Return a multibyte string with the same individual chars as STRING.
1058 If STRING is multibyte, the result is STRING itself.
1059 Otherwise it is a newly created string, with no text properties.
1061 If STRING is unibyte and contains an 8-bit byte, it is converted to
1062 the corresponding multibyte character of charset `eight-bit'.
1064 This differs from `string-as-multibyte' by converting each byte of a correct
1065 utf-8 sequence to an eight-bit character, not just bytes that don't form a
1066 correct sequence. */)
1067 (Lisp_Object string
)
1069 CHECK_STRING (string
);
1071 return string_to_multibyte (string
);
1074 DEFUN ("string-to-unibyte", Fstring_to_unibyte
, Sstring_to_unibyte
,
1076 doc
: /* Return a unibyte string with the same individual chars as STRING.
1077 If STRING is unibyte, the result is STRING itself.
1078 Otherwise it is a newly created string, with no text properties,
1079 where each `eight-bit' character is converted to the corresponding byte.
1080 If STRING contains a non-ASCII, non-`eight-bit' character,
1081 an error is signaled. */)
1082 (Lisp_Object string
)
1084 CHECK_STRING (string
);
1086 if (STRING_MULTIBYTE (string
))
1088 EMACS_INT chars
= SCHARS (string
);
1089 unsigned char *str
= (unsigned char *) xmalloc (chars
);
1090 EMACS_INT converted
= str_to_unibyte (SDATA (string
), str
, chars
, 0);
1092 if (converted
< chars
)
1093 error ("Can't convert the %dth character to unibyte", converted
);
1094 string
= make_unibyte_string (str
, chars
);
1101 DEFUN ("copy-alist", Fcopy_alist
, Scopy_alist
, 1, 1, 0,
1102 doc
: /* Return a copy of ALIST.
1103 This is an alist which represents the same mapping from objects to objects,
1104 but does not share the alist structure with ALIST.
1105 The objects mapped (cars and cdrs of elements of the alist)
1106 are shared, however.
1107 Elements of ALIST that are not conses are also shared. */)
1110 register Lisp_Object tem
;
1115 alist
= concat (1, &alist
, Lisp_Cons
, 0);
1116 for (tem
= alist
; CONSP (tem
); tem
= XCDR (tem
))
1118 register Lisp_Object car
;
1122 XSETCAR (tem
, Fcons (XCAR (car
), XCDR (car
)));
1127 DEFUN ("substring", Fsubstring
, Ssubstring
, 2, 3, 0,
1128 doc
: /* Return a new string whose contents are a substring of STRING.
1129 The returned string consists of the characters between index FROM
1130 \(inclusive) and index TO (exclusive) of STRING. FROM and TO are
1131 zero-indexed: 0 means the first character of STRING. Negative values
1132 are counted from the end of STRING. If TO is nil, the substring runs
1133 to the end of STRING.
1135 The STRING argument may also be a vector. In that case, the return
1136 value is a new vector that contains the elements between index FROM
1137 \(inclusive) and index TO (exclusive) of that vector argument. */)
1138 (Lisp_Object string
, register Lisp_Object from
, Lisp_Object to
)
1142 EMACS_INT size_byte
= 0;
1143 EMACS_INT from_char
, to_char
;
1144 EMACS_INT from_byte
= 0, to_byte
= 0;
1146 CHECK_VECTOR_OR_STRING (string
);
1147 CHECK_NUMBER (from
);
1149 if (STRINGP (string
))
1151 size
= SCHARS (string
);
1152 size_byte
= SBYTES (string
);
1155 size
= ASIZE (string
);
1160 to_byte
= size_byte
;
1166 to_char
= XINT (to
);
1170 if (STRINGP (string
))
1171 to_byte
= string_char_to_byte (string
, to_char
);
1174 from_char
= XINT (from
);
1177 if (STRINGP (string
))
1178 from_byte
= string_char_to_byte (string
, from_char
);
1180 if (!(0 <= from_char
&& from_char
<= to_char
&& to_char
<= size
))
1181 args_out_of_range_3 (string
, make_number (from_char
),
1182 make_number (to_char
));
1184 if (STRINGP (string
))
1186 res
= make_specified_string (SDATA (string
) + from_byte
,
1187 to_char
- from_char
, to_byte
- from_byte
,
1188 STRING_MULTIBYTE (string
));
1189 copy_text_properties (make_number (from_char
), make_number (to_char
),
1190 string
, make_number (0), res
, Qnil
);
1193 res
= Fvector (to_char
- from_char
, &AREF (string
, from_char
));
1199 DEFUN ("substring-no-properties", Fsubstring_no_properties
, Ssubstring_no_properties
, 1, 3, 0,
1200 doc
: /* Return a substring of STRING, without text properties.
1201 It starts at index FROM and ends before TO.
1202 TO may be nil or omitted; then the substring runs to the end of STRING.
1203 If FROM is nil or omitted, the substring starts at the beginning of STRING.
1204 If FROM or TO is negative, it counts from the end.
1206 With one argument, just copy STRING without its properties. */)
1207 (Lisp_Object string
, register Lisp_Object from
, Lisp_Object to
)
1209 EMACS_INT size
, size_byte
;
1210 EMACS_INT from_char
, to_char
;
1211 EMACS_INT from_byte
, to_byte
;
1213 CHECK_STRING (string
);
1215 size
= SCHARS (string
);
1216 size_byte
= SBYTES (string
);
1219 from_char
= from_byte
= 0;
1222 CHECK_NUMBER (from
);
1223 from_char
= XINT (from
);
1227 from_byte
= string_char_to_byte (string
, from_char
);
1233 to_byte
= size_byte
;
1239 to_char
= XINT (to
);
1243 to_byte
= string_char_to_byte (string
, to_char
);
1246 if (!(0 <= from_char
&& from_char
<= to_char
&& to_char
<= size
))
1247 args_out_of_range_3 (string
, make_number (from_char
),
1248 make_number (to_char
));
1250 return make_specified_string (SDATA (string
) + from_byte
,
1251 to_char
- from_char
, to_byte
- from_byte
,
1252 STRING_MULTIBYTE (string
));
1255 /* Extract a substring of STRING, giving start and end positions
1256 both in characters and in bytes. */
1259 substring_both (Lisp_Object string
, EMACS_INT from
, EMACS_INT from_byte
,
1260 EMACS_INT to
, EMACS_INT to_byte
)
1264 EMACS_INT size_byte
;
1266 CHECK_VECTOR_OR_STRING (string
);
1268 if (STRINGP (string
))
1270 size
= SCHARS (string
);
1271 size_byte
= SBYTES (string
);
1274 size
= ASIZE (string
);
1276 if (!(0 <= from
&& from
<= to
&& to
<= size
))
1277 args_out_of_range_3 (string
, make_number (from
), make_number (to
));
1279 if (STRINGP (string
))
1281 res
= make_specified_string (SDATA (string
) + from_byte
,
1282 to
- from
, to_byte
- from_byte
,
1283 STRING_MULTIBYTE (string
));
1284 copy_text_properties (make_number (from
), make_number (to
),
1285 string
, make_number (0), res
, Qnil
);
1288 res
= Fvector (to
- from
, &AREF (string
, from
));
1293 DEFUN ("nthcdr", Fnthcdr
, Snthcdr
, 2, 2, 0,
1294 doc
: /* Take cdr N times on LIST, return the result. */)
1295 (Lisp_Object n
, Lisp_Object list
)
1297 register int i
, num
;
1300 for (i
= 0; i
< num
&& !NILP (list
); i
++)
1303 CHECK_LIST_CONS (list
, list
);
1309 DEFUN ("nth", Fnth
, Snth
, 2, 2, 0,
1310 doc
: /* Return the Nth element of LIST.
1311 N counts from zero. If LIST is not that long, nil is returned. */)
1312 (Lisp_Object n
, Lisp_Object list
)
1314 return Fcar (Fnthcdr (n
, list
));
1317 DEFUN ("elt", Felt
, Selt
, 2, 2, 0,
1318 doc
: /* Return element of SEQUENCE at index N. */)
1319 (register Lisp_Object sequence
, Lisp_Object n
)
1322 if (CONSP (sequence
) || NILP (sequence
))
1323 return Fcar (Fnthcdr (n
, sequence
));
1325 /* Faref signals a "not array" error, so check here. */
1326 CHECK_ARRAY (sequence
, Qsequencep
);
1327 return Faref (sequence
, n
);
1330 DEFUN ("member", Fmember
, Smember
, 2, 2, 0,
1331 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
1332 The value is actually the tail of LIST whose car is ELT. */)
1333 (register Lisp_Object elt
, Lisp_Object list
)
1335 register Lisp_Object tail
;
1336 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1338 register Lisp_Object tem
;
1339 CHECK_LIST_CONS (tail
, list
);
1341 if (! NILP (Fequal (elt
, tem
)))
1348 DEFUN ("memq", Fmemq
, Smemq
, 2, 2, 0,
1349 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
1350 The value is actually the tail of LIST whose car is ELT. */)
1351 (register Lisp_Object elt
, Lisp_Object list
)
1355 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1359 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1363 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1374 DEFUN ("memql", Fmemql
, Smemql
, 2, 2, 0,
1375 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `eql'.
1376 The value is actually the tail of LIST whose car is ELT. */)
1377 (register Lisp_Object elt
, Lisp_Object list
)
1379 register Lisp_Object tail
;
1382 return Fmemq (elt
, list
);
1384 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1386 register Lisp_Object tem
;
1387 CHECK_LIST_CONS (tail
, list
);
1389 if (FLOATP (tem
) && internal_equal (elt
, tem
, 0, 0))
1396 DEFUN ("assq", Fassq
, Sassq
, 2, 2, 0,
1397 doc
: /* Return non-nil if KEY is `eq' to the car of an element of LIST.
1398 The value is actually the first element of LIST whose car is KEY.
1399 Elements of LIST that are not conses are ignored. */)
1400 (Lisp_Object key
, Lisp_Object list
)
1405 || (CONSP (XCAR (list
))
1406 && EQ (XCAR (XCAR (list
)), key
)))
1411 || (CONSP (XCAR (list
))
1412 && EQ (XCAR (XCAR (list
)), key
)))
1417 || (CONSP (XCAR (list
))
1418 && EQ (XCAR (XCAR (list
)), key
)))
1428 /* Like Fassq but never report an error and do not allow quits.
1429 Use only on lists known never to be circular. */
1432 assq_no_quit (Lisp_Object key
, Lisp_Object list
)
1435 && (!CONSP (XCAR (list
))
1436 || !EQ (XCAR (XCAR (list
)), key
)))
1439 return CAR_SAFE (list
);
1442 DEFUN ("assoc", Fassoc
, Sassoc
, 2, 2, 0,
1443 doc
: /* Return non-nil if KEY is `equal' to the car of an element of LIST.
1444 The value is actually the first element of LIST whose car equals KEY. */)
1445 (Lisp_Object key
, Lisp_Object list
)
1452 || (CONSP (XCAR (list
))
1453 && (car
= XCAR (XCAR (list
)),
1454 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1459 || (CONSP (XCAR (list
))
1460 && (car
= XCAR (XCAR (list
)),
1461 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1466 || (CONSP (XCAR (list
))
1467 && (car
= XCAR (XCAR (list
)),
1468 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1478 /* Like Fassoc but never report an error and do not allow quits.
1479 Use only on lists known never to be circular. */
1482 assoc_no_quit (Lisp_Object key
, Lisp_Object list
)
1485 && (!CONSP (XCAR (list
))
1486 || (!EQ (XCAR (XCAR (list
)), key
)
1487 && NILP (Fequal (XCAR (XCAR (list
)), key
)))))
1490 return CONSP (list
) ? XCAR (list
) : Qnil
;
1493 DEFUN ("rassq", Frassq
, Srassq
, 2, 2, 0,
1494 doc
: /* Return non-nil if KEY is `eq' to the cdr of an element of LIST.
1495 The value is actually the first element of LIST whose cdr is KEY. */)
1496 (register Lisp_Object key
, Lisp_Object list
)
1501 || (CONSP (XCAR (list
))
1502 && EQ (XCDR (XCAR (list
)), key
)))
1507 || (CONSP (XCAR (list
))
1508 && EQ (XCDR (XCAR (list
)), key
)))
1513 || (CONSP (XCAR (list
))
1514 && EQ (XCDR (XCAR (list
)), key
)))
1524 DEFUN ("rassoc", Frassoc
, Srassoc
, 2, 2, 0,
1525 doc
: /* Return non-nil if KEY is `equal' to the cdr of an element of LIST.
1526 The value is actually the first element of LIST whose cdr equals KEY. */)
1527 (Lisp_Object key
, Lisp_Object list
)
1534 || (CONSP (XCAR (list
))
1535 && (cdr
= XCDR (XCAR (list
)),
1536 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1541 || (CONSP (XCAR (list
))
1542 && (cdr
= XCDR (XCAR (list
)),
1543 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1548 || (CONSP (XCAR (list
))
1549 && (cdr
= XCDR (XCAR (list
)),
1550 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1560 DEFUN ("delq", Fdelq
, Sdelq
, 2, 2, 0,
1561 doc
: /* Delete by side effect any occurrences of ELT as a member of LIST.
1562 The modified LIST is returned. Comparison is done with `eq'.
1563 If the first member of LIST is ELT, there is no way to remove it by side effect;
1564 therefore, write `(setq foo (delq element foo))'
1565 to be sure of changing the value of `foo'. */)
1566 (register Lisp_Object elt
, Lisp_Object list
)
1568 register Lisp_Object tail
, prev
;
1569 register Lisp_Object tem
;
1573 while (!NILP (tail
))
1575 CHECK_LIST_CONS (tail
, list
);
1582 Fsetcdr (prev
, XCDR (tail
));
1592 DEFUN ("delete", Fdelete
, Sdelete
, 2, 2, 0,
1593 doc
: /* Delete by side effect any occurrences of ELT as a member of SEQ.
1594 SEQ must be a list, a vector, or a string.
1595 The modified SEQ is returned. Comparison is done with `equal'.
1596 If SEQ is not a list, or the first member of SEQ is ELT, deleting it
1597 is not a side effect; it is simply using a different sequence.
1598 Therefore, write `(setq foo (delete element foo))'
1599 to be sure of changing the value of `foo'. */)
1600 (Lisp_Object elt
, Lisp_Object seq
)
1606 for (i
= n
= 0; i
< ASIZE (seq
); ++i
)
1607 if (NILP (Fequal (AREF (seq
, i
), elt
)))
1610 if (n
!= ASIZE (seq
))
1612 struct Lisp_Vector
*p
= allocate_vector (n
);
1614 for (i
= n
= 0; i
< ASIZE (seq
); ++i
)
1615 if (NILP (Fequal (AREF (seq
, i
), elt
)))
1616 p
->contents
[n
++] = AREF (seq
, i
);
1618 XSETVECTOR (seq
, p
);
1621 else if (STRINGP (seq
))
1623 EMACS_INT i
, ibyte
, nchars
, nbytes
, cbytes
;
1626 for (i
= nchars
= nbytes
= ibyte
= 0;
1628 ++i
, ibyte
+= cbytes
)
1630 if (STRING_MULTIBYTE (seq
))
1632 c
= STRING_CHAR (SDATA (seq
) + ibyte
);
1633 cbytes
= CHAR_BYTES (c
);
1641 if (!INTEGERP (elt
) || c
!= XINT (elt
))
1648 if (nchars
!= SCHARS (seq
))
1652 tem
= make_uninit_multibyte_string (nchars
, nbytes
);
1653 if (!STRING_MULTIBYTE (seq
))
1654 STRING_SET_UNIBYTE (tem
);
1656 for (i
= nchars
= nbytes
= ibyte
= 0;
1658 ++i
, ibyte
+= cbytes
)
1660 if (STRING_MULTIBYTE (seq
))
1662 c
= STRING_CHAR (SDATA (seq
) + ibyte
);
1663 cbytes
= CHAR_BYTES (c
);
1671 if (!INTEGERP (elt
) || c
!= XINT (elt
))
1673 unsigned char *from
= SDATA (seq
) + ibyte
;
1674 unsigned char *to
= SDATA (tem
) + nbytes
;
1680 for (n
= cbytes
; n
--; )
1690 Lisp_Object tail
, prev
;
1692 for (tail
= seq
, prev
= Qnil
; CONSP (tail
); tail
= XCDR (tail
))
1694 CHECK_LIST_CONS (tail
, seq
);
1696 if (!NILP (Fequal (elt
, XCAR (tail
))))
1701 Fsetcdr (prev
, XCDR (tail
));
1712 DEFUN ("nreverse", Fnreverse
, Snreverse
, 1, 1, 0,
1713 doc
: /* Reverse LIST by modifying cdr pointers.
1714 Return the reversed list. */)
1717 register Lisp_Object prev
, tail
, next
;
1719 if (NILP (list
)) return list
;
1722 while (!NILP (tail
))
1725 CHECK_LIST_CONS (tail
, list
);
1727 Fsetcdr (tail
, prev
);
1734 DEFUN ("reverse", Freverse
, Sreverse
, 1, 1, 0,
1735 doc
: /* Reverse LIST, copying. Return the reversed list.
1736 See also the function `nreverse', which is used more often. */)
1741 for (new = Qnil
; CONSP (list
); list
= XCDR (list
))
1744 new = Fcons (XCAR (list
), new);
1746 CHECK_LIST_END (list
, list
);
1750 Lisp_Object
merge (Lisp_Object org_l1
, Lisp_Object org_l2
, Lisp_Object pred
);
1752 DEFUN ("sort", Fsort
, Ssort
, 2, 2, 0,
1753 doc
: /* Sort LIST, stably, comparing elements using PREDICATE.
1754 Returns the sorted list. LIST is modified by side effects.
1755 PREDICATE is called with two elements of LIST, and should return non-nil
1756 if the first element should sort before the second. */)
1757 (Lisp_Object list
, Lisp_Object predicate
)
1759 Lisp_Object front
, back
;
1760 register Lisp_Object len
, tem
;
1761 struct gcpro gcpro1
, gcpro2
;
1762 register int length
;
1765 len
= Flength (list
);
1766 length
= XINT (len
);
1770 XSETINT (len
, (length
/ 2) - 1);
1771 tem
= Fnthcdr (len
, list
);
1773 Fsetcdr (tem
, Qnil
);
1775 GCPRO2 (front
, back
);
1776 front
= Fsort (front
, predicate
);
1777 back
= Fsort (back
, predicate
);
1779 return merge (front
, back
, predicate
);
1783 merge (Lisp_Object org_l1
, Lisp_Object org_l2
, Lisp_Object pred
)
1786 register Lisp_Object tail
;
1788 register Lisp_Object l1
, l2
;
1789 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1796 /* It is sufficient to protect org_l1 and org_l2.
1797 When l1 and l2 are updated, we copy the new values
1798 back into the org_ vars. */
1799 GCPRO4 (org_l1
, org_l2
, pred
, value
);
1819 tem
= call2 (pred
, Fcar (l2
), Fcar (l1
));
1835 Fsetcdr (tail
, tem
);
1841 /* This does not check for quits. That is safe since it must terminate. */
1843 DEFUN ("plist-get", Fplist_get
, Splist_get
, 2, 2, 0,
1844 doc
: /* Extract a value from a property list.
1845 PLIST is a property list, which is a list of the form
1846 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
1847 corresponding to the given PROP, or nil if PROP is not one of the
1848 properties on the list. This function never signals an error. */)
1849 (Lisp_Object plist
, Lisp_Object prop
)
1851 Lisp_Object tail
, halftail
;
1853 /* halftail is used to detect circular lists. */
1854 tail
= halftail
= plist
;
1855 while (CONSP (tail
) && CONSP (XCDR (tail
)))
1857 if (EQ (prop
, XCAR (tail
)))
1858 return XCAR (XCDR (tail
));
1860 tail
= XCDR (XCDR (tail
));
1861 halftail
= XCDR (halftail
);
1862 if (EQ (tail
, halftail
))
1865 #if 0 /* Unsafe version. */
1866 /* This function can be called asynchronously
1867 (setup_coding_system). Don't QUIT in that case. */
1868 if (!interrupt_input_blocked
)
1876 DEFUN ("get", Fget
, Sget
, 2, 2, 0,
1877 doc
: /* Return the value of SYMBOL's PROPNAME property.
1878 This is the last value stored with `(put SYMBOL PROPNAME VALUE)'. */)
1879 (Lisp_Object symbol
, Lisp_Object propname
)
1881 CHECK_SYMBOL (symbol
);
1882 return Fplist_get (XSYMBOL (symbol
)->plist
, propname
);
1885 DEFUN ("plist-put", Fplist_put
, Splist_put
, 3, 3, 0,
1886 doc
: /* Change value in PLIST of PROP to VAL.
1887 PLIST is a property list, which is a list of the form
1888 \(PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol and VAL is any object.
1889 If PROP is already a property on the list, its value is set to VAL,
1890 otherwise the new PROP VAL pair is added. The new plist is returned;
1891 use `(setq x (plist-put x prop val))' to be sure to use the new value.
1892 The PLIST is modified by side effects. */)
1893 (Lisp_Object plist
, register Lisp_Object prop
, Lisp_Object val
)
1895 register Lisp_Object tail
, prev
;
1896 Lisp_Object newcell
;
1898 for (tail
= plist
; CONSP (tail
) && CONSP (XCDR (tail
));
1899 tail
= XCDR (XCDR (tail
)))
1901 if (EQ (prop
, XCAR (tail
)))
1903 Fsetcar (XCDR (tail
), val
);
1910 newcell
= Fcons (prop
, Fcons (val
, NILP (prev
) ? plist
: XCDR (XCDR (prev
))));
1914 Fsetcdr (XCDR (prev
), newcell
);
1918 DEFUN ("put", Fput
, Sput
, 3, 3, 0,
1919 doc
: /* Store SYMBOL's PROPNAME property with value VALUE.
1920 It can be retrieved with `(get SYMBOL PROPNAME)'. */)
1921 (Lisp_Object symbol
, Lisp_Object propname
, Lisp_Object value
)
1923 CHECK_SYMBOL (symbol
);
1924 XSYMBOL (symbol
)->plist
1925 = Fplist_put (XSYMBOL (symbol
)->plist
, propname
, value
);
1929 DEFUN ("lax-plist-get", Flax_plist_get
, Slax_plist_get
, 2, 2, 0,
1930 doc
: /* Extract a value from a property list, comparing with `equal'.
1931 PLIST is a property list, which is a list of the form
1932 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
1933 corresponding to the given PROP, or nil if PROP is not
1934 one of the properties on the list. */)
1935 (Lisp_Object plist
, Lisp_Object prop
)
1940 CONSP (tail
) && CONSP (XCDR (tail
));
1941 tail
= XCDR (XCDR (tail
)))
1943 if (! NILP (Fequal (prop
, XCAR (tail
))))
1944 return XCAR (XCDR (tail
));
1949 CHECK_LIST_END (tail
, prop
);
1954 DEFUN ("lax-plist-put", Flax_plist_put
, Slax_plist_put
, 3, 3, 0,
1955 doc
: /* Change value in PLIST of PROP to VAL, comparing with `equal'.
1956 PLIST is a property list, which is a list of the form
1957 \(PROP1 VALUE1 PROP2 VALUE2 ...). PROP and VAL are any objects.
1958 If PROP is already a property on the list, its value is set to VAL,
1959 otherwise the new PROP VAL pair is added. The new plist is returned;
1960 use `(setq x (lax-plist-put x prop val))' to be sure to use the new value.
1961 The PLIST is modified by side effects. */)
1962 (Lisp_Object plist
, register Lisp_Object prop
, Lisp_Object val
)
1964 register Lisp_Object tail
, prev
;
1965 Lisp_Object newcell
;
1967 for (tail
= plist
; CONSP (tail
) && CONSP (XCDR (tail
));
1968 tail
= XCDR (XCDR (tail
)))
1970 if (! NILP (Fequal (prop
, XCAR (tail
))))
1972 Fsetcar (XCDR (tail
), val
);
1979 newcell
= Fcons (prop
, Fcons (val
, Qnil
));
1983 Fsetcdr (XCDR (prev
), newcell
);
1987 DEFUN ("eql", Feql
, Seql
, 2, 2, 0,
1988 doc
: /* Return t if the two args are the same Lisp object.
1989 Floating-point numbers of equal value are `eql', but they may not be `eq'. */)
1990 (Lisp_Object obj1
, Lisp_Object obj2
)
1993 return internal_equal (obj1
, obj2
, 0, 0) ? Qt
: Qnil
;
1995 return EQ (obj1
, obj2
) ? Qt
: Qnil
;
1998 DEFUN ("equal", Fequal
, Sequal
, 2, 2, 0,
1999 doc
: /* Return t if two Lisp objects have similar structure and contents.
2000 They must have the same data type.
2001 Conses are compared by comparing the cars and the cdrs.
2002 Vectors and strings are compared element by element.
2003 Numbers are compared by value, but integers cannot equal floats.
2004 (Use `=' if you want integers and floats to be able to be equal.)
2005 Symbols must match exactly. */)
2006 (register Lisp_Object o1
, Lisp_Object o2
)
2008 return internal_equal (o1
, o2
, 0, 0) ? Qt
: Qnil
;
2011 DEFUN ("equal-including-properties", Fequal_including_properties
, Sequal_including_properties
, 2, 2, 0,
2012 doc
: /* Return t if two Lisp objects have similar structure and contents.
2013 This is like `equal' except that it compares the text properties
2014 of strings. (`equal' ignores text properties.) */)
2015 (register Lisp_Object o1
, Lisp_Object o2
)
2017 return internal_equal (o1
, o2
, 0, 1) ? Qt
: Qnil
;
2020 /* DEPTH is current depth of recursion. Signal an error if it
2022 PROPS, if non-nil, means compare string text properties too. */
2025 internal_equal (register Lisp_Object o1
, register Lisp_Object o2
, int depth
, int props
)
2028 error ("Stack overflow in equal");
2034 if (XTYPE (o1
) != XTYPE (o2
))
2043 d1
= extract_float (o1
);
2044 d2
= extract_float (o2
);
2045 /* If d is a NaN, then d != d. Two NaNs should be `equal' even
2046 though they are not =. */
2047 return d1
== d2
|| (d1
!= d1
&& d2
!= d2
);
2051 if (!internal_equal (XCAR (o1
), XCAR (o2
), depth
+ 1, props
))
2058 if (XMISCTYPE (o1
) != XMISCTYPE (o2
))
2062 if (!internal_equal (OVERLAY_START (o1
), OVERLAY_START (o2
),
2064 || !internal_equal (OVERLAY_END (o1
), OVERLAY_END (o2
),
2067 o1
= XOVERLAY (o1
)->plist
;
2068 o2
= XOVERLAY (o2
)->plist
;
2073 return (XMARKER (o1
)->buffer
== XMARKER (o2
)->buffer
2074 && (XMARKER (o1
)->buffer
== 0
2075 || XMARKER (o1
)->bytepos
== XMARKER (o2
)->bytepos
));
2079 case Lisp_Vectorlike
:
2082 EMACS_INT size
= ASIZE (o1
);
2083 /* Pseudovectors have the type encoded in the size field, so this test
2084 actually checks that the objects have the same type as well as the
2086 if (ASIZE (o2
) != size
)
2088 /* Boolvectors are compared much like strings. */
2089 if (BOOL_VECTOR_P (o1
))
2092 = ((XBOOL_VECTOR (o1
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
2093 / BOOL_VECTOR_BITS_PER_CHAR
);
2095 if (XBOOL_VECTOR (o1
)->size
!= XBOOL_VECTOR (o2
)->size
)
2097 if (memcmp (XBOOL_VECTOR (o1
)->data
, XBOOL_VECTOR (o2
)->data
,
2102 if (WINDOW_CONFIGURATIONP (o1
))
2103 return compare_window_configurations (o1
, o2
, 0);
2105 /* Aside from them, only true vectors, char-tables, compiled
2106 functions, and fonts (font-spec, font-entity, font-ojbect)
2107 are sensible to compare, so eliminate the others now. */
2108 if (size
& PSEUDOVECTOR_FLAG
)
2110 if (!(size
& (PVEC_COMPILED
2111 | PVEC_CHAR_TABLE
| PVEC_SUB_CHAR_TABLE
| PVEC_FONT
)))
2113 size
&= PSEUDOVECTOR_SIZE_MASK
;
2115 for (i
= 0; i
< size
; i
++)
2120 if (!internal_equal (v1
, v2
, depth
+ 1, props
))
2128 if (SCHARS (o1
) != SCHARS (o2
))
2130 if (SBYTES (o1
) != SBYTES (o2
))
2132 if (memcmp (SDATA (o1
), SDATA (o2
), SBYTES (o1
)))
2134 if (props
&& !compare_string_intervals (o1
, o2
))
2146 DEFUN ("fillarray", Ffillarray
, Sfillarray
, 2, 2, 0,
2147 doc
: /* Store each element of ARRAY with ITEM.
2148 ARRAY is a vector, string, char-table, or bool-vector. */)
2149 (Lisp_Object array
, Lisp_Object item
)
2151 register EMACS_INT size
, index
;
2154 if (VECTORP (array
))
2156 register Lisp_Object
*p
= XVECTOR (array
)->contents
;
2157 size
= ASIZE (array
);
2158 for (index
= 0; index
< size
; index
++)
2161 else if (CHAR_TABLE_P (array
))
2165 for (i
= 0; i
< (1 << CHARTAB_SIZE_BITS_0
); i
++)
2166 XCHAR_TABLE (array
)->contents
[i
] = item
;
2167 XCHAR_TABLE (array
)->defalt
= item
;
2169 else if (STRINGP (array
))
2171 register unsigned char *p
= SDATA (array
);
2172 CHECK_NUMBER (item
);
2173 charval
= XINT (item
);
2174 size
= SCHARS (array
);
2175 if (STRING_MULTIBYTE (array
))
2177 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
2178 int len
= CHAR_STRING (charval
, str
);
2179 EMACS_INT size_byte
= SBYTES (array
);
2180 unsigned char *p1
= p
, *endp
= p
+ size_byte
;
2183 if (size
!= size_byte
)
2186 int this_len
= BYTES_BY_CHAR_HEAD (*p1
);
2187 if (len
!= this_len
)
2188 error ("Attempt to change byte length of a string");
2191 for (i
= 0; i
< size_byte
; i
++)
2192 *p
++ = str
[i
% len
];
2195 for (index
= 0; index
< size
; index
++)
2198 else if (BOOL_VECTOR_P (array
))
2200 register unsigned char *p
= XBOOL_VECTOR (array
)->data
;
2202 = ((XBOOL_VECTOR (array
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
2203 / BOOL_VECTOR_BITS_PER_CHAR
);
2205 charval
= (! NILP (item
) ? -1 : 0);
2206 for (index
= 0; index
< size_in_chars
- 1; index
++)
2208 if (index
< size_in_chars
)
2210 /* Mask out bits beyond the vector size. */
2211 if (XBOOL_VECTOR (array
)->size
% BOOL_VECTOR_BITS_PER_CHAR
)
2212 charval
&= (1 << (XBOOL_VECTOR (array
)->size
% BOOL_VECTOR_BITS_PER_CHAR
)) - 1;
2217 wrong_type_argument (Qarrayp
, array
);
2221 DEFUN ("clear-string", Fclear_string
, Sclear_string
,
2223 doc
: /* Clear the contents of STRING.
2224 This makes STRING unibyte and may change its length. */)
2225 (Lisp_Object string
)
2228 CHECK_STRING (string
);
2229 len
= SBYTES (string
);
2230 memset (SDATA (string
), 0, len
);
2231 STRING_SET_CHARS (string
, len
);
2232 STRING_SET_UNIBYTE (string
);
2238 nconc2 (Lisp_Object s1
, Lisp_Object s2
)
2240 Lisp_Object args
[2];
2243 return Fnconc (2, args
);
2246 DEFUN ("nconc", Fnconc
, Snconc
, 0, MANY
, 0,
2247 doc
: /* Concatenate any number of lists by altering them.
2248 Only the last argument is not altered, and need not be a list.
2249 usage: (nconc &rest LISTS) */)
2250 (int nargs
, Lisp_Object
*args
)
2252 register int argnum
;
2253 register Lisp_Object tail
, tem
, val
;
2257 for (argnum
= 0; argnum
< nargs
; argnum
++)
2260 if (NILP (tem
)) continue;
2265 if (argnum
+ 1 == nargs
) break;
2267 CHECK_LIST_CONS (tem
, tem
);
2276 tem
= args
[argnum
+ 1];
2277 Fsetcdr (tail
, tem
);
2279 args
[argnum
+ 1] = tail
;
2285 /* This is the guts of all mapping functions.
2286 Apply FN to each element of SEQ, one by one,
2287 storing the results into elements of VALS, a C vector of Lisp_Objects.
2288 LENI is the length of VALS, which should also be the length of SEQ. */
2291 mapcar1 (EMACS_INT leni
, Lisp_Object
*vals
, Lisp_Object fn
, Lisp_Object seq
)
2293 register Lisp_Object tail
;
2295 register EMACS_INT i
;
2296 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2300 /* Don't let vals contain any garbage when GC happens. */
2301 for (i
= 0; i
< leni
; i
++)
2304 GCPRO3 (dummy
, fn
, seq
);
2306 gcpro1
.nvars
= leni
;
2310 /* We need not explicitly protect `tail' because it is used only on lists, and
2311 1) lists are not relocated and 2) the list is marked via `seq' so will not
2316 for (i
= 0; i
< leni
; i
++)
2318 dummy
= call1 (fn
, AREF (seq
, i
));
2323 else if (BOOL_VECTOR_P (seq
))
2325 for (i
= 0; i
< leni
; i
++)
2328 byte
= XBOOL_VECTOR (seq
)->data
[i
/ BOOL_VECTOR_BITS_PER_CHAR
];
2329 dummy
= (byte
& (1 << (i
% BOOL_VECTOR_BITS_PER_CHAR
))) ? Qt
: Qnil
;
2330 dummy
= call1 (fn
, dummy
);
2335 else if (STRINGP (seq
))
2339 for (i
= 0, i_byte
= 0; i
< leni
;)
2342 EMACS_INT i_before
= i
;
2344 FETCH_STRING_CHAR_ADVANCE (c
, seq
, i
, i_byte
);
2345 XSETFASTINT (dummy
, c
);
2346 dummy
= call1 (fn
, dummy
);
2348 vals
[i_before
] = dummy
;
2351 else /* Must be a list, since Flength did not get an error */
2354 for (i
= 0; i
< leni
&& CONSP (tail
); i
++)
2356 dummy
= call1 (fn
, XCAR (tail
));
2366 DEFUN ("mapconcat", Fmapconcat
, Smapconcat
, 3, 3, 0,
2367 doc
: /* Apply FUNCTION to each element of SEQUENCE, and concat the results as strings.
2368 In between each pair of results, stick in SEPARATOR. Thus, " " as
2369 SEPARATOR results in spaces between the values returned by FUNCTION.
2370 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2371 (Lisp_Object function
, Lisp_Object sequence
, Lisp_Object separator
)
2374 register EMACS_INT leni
;
2376 register Lisp_Object
*args
;
2377 register EMACS_INT i
;
2378 struct gcpro gcpro1
;
2382 len
= Flength (sequence
);
2383 if (CHAR_TABLE_P (sequence
))
2384 wrong_type_argument (Qlistp
, sequence
);
2386 nargs
= leni
+ leni
- 1;
2387 if (nargs
< 0) return empty_unibyte_string
;
2389 SAFE_ALLOCA_LISP (args
, nargs
);
2392 mapcar1 (leni
, args
, function
, sequence
);
2395 for (i
= leni
- 1; i
> 0; i
--)
2396 args
[i
+ i
] = args
[i
];
2398 for (i
= 1; i
< nargs
; i
+= 2)
2399 args
[i
] = separator
;
2401 ret
= Fconcat (nargs
, args
);
2407 DEFUN ("mapcar", Fmapcar
, Smapcar
, 2, 2, 0,
2408 doc
: /* Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
2409 The result is a list just as long as SEQUENCE.
2410 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2411 (Lisp_Object function
, Lisp_Object sequence
)
2413 register Lisp_Object len
;
2414 register EMACS_INT leni
;
2415 register Lisp_Object
*args
;
2419 len
= Flength (sequence
);
2420 if (CHAR_TABLE_P (sequence
))
2421 wrong_type_argument (Qlistp
, sequence
);
2422 leni
= XFASTINT (len
);
2424 SAFE_ALLOCA_LISP (args
, leni
);
2426 mapcar1 (leni
, args
, function
, sequence
);
2428 ret
= Flist (leni
, args
);
2434 DEFUN ("mapc", Fmapc
, Smapc
, 2, 2, 0,
2435 doc
: /* Apply FUNCTION to each element of SEQUENCE for side effects only.
2436 Unlike `mapcar', don't accumulate the results. Return SEQUENCE.
2437 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2438 (Lisp_Object function
, Lisp_Object sequence
)
2440 register EMACS_INT leni
;
2442 leni
= XFASTINT (Flength (sequence
));
2443 if (CHAR_TABLE_P (sequence
))
2444 wrong_type_argument (Qlistp
, sequence
);
2445 mapcar1 (leni
, 0, function
, sequence
);
2450 /* This is how C code calls `yes-or-no-p' and allows the user
2453 Anything that calls this function must protect from GC! */
2456 do_yes_or_no_p (Lisp_Object prompt
)
2458 return call1 (intern ("yes-or-no-p"), prompt
);
2461 /* Anything that calls this function must protect from GC! */
2463 DEFUN ("yes-or-no-p", Fyes_or_no_p
, Syes_or_no_p
, 1, 1, 0,
2464 doc
: /* Ask user a yes-or-no question. Return t if answer is yes.
2465 Takes one argument, which is the string to display to ask the question.
2466 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
2467 The user must confirm the answer with RET,
2468 and can edit it until it has been confirmed.
2470 Under a windowing system a dialog box will be used if `last-nonmenu-event'
2471 is nil, and `use-dialog-box' is non-nil. */)
2472 (Lisp_Object prompt
)
2474 register Lisp_Object ans
;
2475 Lisp_Object args
[2];
2476 struct gcpro gcpro1
;
2478 CHECK_STRING (prompt
);
2481 if (FRAME_WINDOW_P (SELECTED_FRAME ())
2482 && (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
2486 Lisp_Object pane
, menu
, obj
;
2487 redisplay_preserve_echo_area (4);
2488 pane
= Fcons (Fcons (build_string ("Yes"), Qt
),
2489 Fcons (Fcons (build_string ("No"), Qnil
),
2492 menu
= Fcons (prompt
, pane
);
2493 obj
= Fx_popup_dialog (Qt
, menu
, Qnil
);
2497 #endif /* HAVE_MENUS */
2500 args
[1] = build_string ("(yes or no) ");
2501 prompt
= Fconcat (2, args
);
2507 ans
= Fdowncase (Fread_from_minibuffer (prompt
, Qnil
, Qnil
, Qnil
,
2508 Qyes_or_no_p_history
, Qnil
,
2510 if (SCHARS (ans
) == 3 && !strcmp (SDATA (ans
), "yes"))
2515 if (SCHARS (ans
) == 2 && !strcmp (SDATA (ans
), "no"))
2523 message ("Please answer yes or no.");
2524 Fsleep_for (make_number (2), Qnil
);
2528 DEFUN ("load-average", Fload_average
, Sload_average
, 0, 1, 0,
2529 doc
: /* Return list of 1 minute, 5 minute and 15 minute load averages.
2531 Each of the three load averages is multiplied by 100, then converted
2534 When USE-FLOATS is non-nil, floats will be used instead of integers.
2535 These floats are not multiplied by 100.
2537 If the 5-minute or 15-minute load averages are not available, return a
2538 shortened list, containing only those averages which are available.
2540 An error is thrown if the load average can't be obtained. In some
2541 cases making it work would require Emacs being installed setuid or
2542 setgid so that it can read kernel information, and that usually isn't
2544 (Lisp_Object use_floats
)
2547 int loads
= getloadavg (load_ave
, 3);
2548 Lisp_Object ret
= Qnil
;
2551 error ("load-average not implemented for this operating system");
2555 Lisp_Object load
= (NILP (use_floats
) ?
2556 make_number ((int) (100.0 * load_ave
[loads
]))
2557 : make_float (load_ave
[loads
]));
2558 ret
= Fcons (load
, ret
);
2564 Lisp_Object Vfeatures
, Qsubfeatures
;
2566 DEFUN ("featurep", Ffeaturep
, Sfeaturep
, 1, 2, 0,
2567 doc
: /* Return t if FEATURE is present in this Emacs.
2569 Use this to conditionalize execution of lisp code based on the
2570 presence or absence of Emacs or environment extensions.
2571 Use `provide' to declare that a feature is available. This function
2572 looks at the value of the variable `features'. The optional argument
2573 SUBFEATURE can be used to check a specific subfeature of FEATURE. */)
2574 (Lisp_Object feature
, Lisp_Object subfeature
)
2576 register Lisp_Object tem
;
2577 CHECK_SYMBOL (feature
);
2578 tem
= Fmemq (feature
, Vfeatures
);
2579 if (!NILP (tem
) && !NILP (subfeature
))
2580 tem
= Fmember (subfeature
, Fget (feature
, Qsubfeatures
));
2581 return (NILP (tem
)) ? Qnil
: Qt
;
2584 DEFUN ("provide", Fprovide
, Sprovide
, 1, 2, 0,
2585 doc
: /* Announce that FEATURE is a feature of the current Emacs.
2586 The optional argument SUBFEATURES should be a list of symbols listing
2587 particular subfeatures supported in this version of FEATURE. */)
2588 (Lisp_Object feature
, Lisp_Object subfeatures
)
2590 register Lisp_Object tem
;
2591 CHECK_SYMBOL (feature
);
2592 CHECK_LIST (subfeatures
);
2593 if (!NILP (Vautoload_queue
))
2594 Vautoload_queue
= Fcons (Fcons (make_number (0), Vfeatures
),
2596 tem
= Fmemq (feature
, Vfeatures
);
2598 Vfeatures
= Fcons (feature
, Vfeatures
);
2599 if (!NILP (subfeatures
))
2600 Fput (feature
, Qsubfeatures
, subfeatures
);
2601 LOADHIST_ATTACH (Fcons (Qprovide
, feature
));
2603 /* Run any load-hooks for this file. */
2604 tem
= Fassq (feature
, Vafter_load_alist
);
2606 Fprogn (XCDR (tem
));
2611 /* `require' and its subroutines. */
2613 /* List of features currently being require'd, innermost first. */
2615 Lisp_Object require_nesting_list
;
2618 require_unwind (Lisp_Object old_value
)
2620 return require_nesting_list
= old_value
;
2623 DEFUN ("require", Frequire
, Srequire
, 1, 3, 0,
2624 doc
: /* If feature FEATURE is not loaded, load it from FILENAME.
2625 If FEATURE is not a member of the list `features', then the feature
2626 is not loaded; so load the file FILENAME.
2627 If FILENAME is omitted, the printname of FEATURE is used as the file name,
2628 and `load' will try to load this name appended with the suffix `.elc' or
2629 `.el', in that order. The name without appended suffix will not be used.
2630 If the optional third argument NOERROR is non-nil,
2631 then return nil if the file is not found instead of signaling an error.
2632 Normally the return value is FEATURE.
2633 The normal messages at start and end of loading FILENAME are suppressed. */)
2634 (Lisp_Object feature
, Lisp_Object filename
, Lisp_Object noerror
)
2636 register Lisp_Object tem
;
2637 struct gcpro gcpro1
, gcpro2
;
2638 int from_file
= load_in_progress
;
2640 CHECK_SYMBOL (feature
);
2642 /* Record the presence of `require' in this file
2643 even if the feature specified is already loaded.
2644 But not more than once in any file,
2645 and not when we aren't loading or reading from a file. */
2647 for (tem
= Vcurrent_load_list
; CONSP (tem
); tem
= XCDR (tem
))
2648 if (NILP (XCDR (tem
)) && STRINGP (XCAR (tem
)))
2653 tem
= Fcons (Qrequire
, feature
);
2654 if (NILP (Fmember (tem
, Vcurrent_load_list
)))
2655 LOADHIST_ATTACH (tem
);
2657 tem
= Fmemq (feature
, Vfeatures
);
2661 int count
= SPECPDL_INDEX ();
2664 /* This is to make sure that loadup.el gives a clear picture
2665 of what files are preloaded and when. */
2666 if (! NILP (Vpurify_flag
))
2667 error ("(require %s) while preparing to dump",
2668 SDATA (SYMBOL_NAME (feature
)));
2670 /* A certain amount of recursive `require' is legitimate,
2671 but if we require the same feature recursively 3 times,
2673 tem
= require_nesting_list
;
2674 while (! NILP (tem
))
2676 if (! NILP (Fequal (feature
, XCAR (tem
))))
2681 error ("Recursive `require' for feature `%s'",
2682 SDATA (SYMBOL_NAME (feature
)));
2684 /* Update the list for any nested `require's that occur. */
2685 record_unwind_protect (require_unwind
, require_nesting_list
);
2686 require_nesting_list
= Fcons (feature
, require_nesting_list
);
2688 /* Value saved here is to be restored into Vautoload_queue */
2689 record_unwind_protect (un_autoload
, Vautoload_queue
);
2690 Vautoload_queue
= Qt
;
2692 /* Load the file. */
2693 GCPRO2 (feature
, filename
);
2694 tem
= Fload (NILP (filename
) ? Fsymbol_name (feature
) : filename
,
2695 noerror
, Qt
, Qnil
, (NILP (filename
) ? Qt
: Qnil
));
2698 /* If load failed entirely, return nil. */
2700 return unbind_to (count
, Qnil
);
2702 tem
= Fmemq (feature
, Vfeatures
);
2704 error ("Required feature `%s' was not provided",
2705 SDATA (SYMBOL_NAME (feature
)));
2707 /* Once loading finishes, don't undo it. */
2708 Vautoload_queue
= Qt
;
2709 feature
= unbind_to (count
, feature
);
2715 /* Primitives for work of the "widget" library.
2716 In an ideal world, this section would not have been necessary.
2717 However, lisp function calls being as slow as they are, it turns
2718 out that some functions in the widget library (wid-edit.el) are the
2719 bottleneck of Widget operation. Here is their translation to C,
2720 for the sole reason of efficiency. */
2722 DEFUN ("plist-member", Fplist_member
, Splist_member
, 2, 2, 0,
2723 doc
: /* Return non-nil if PLIST has the property PROP.
2724 PLIST is a property list, which is a list of the form
2725 \(PROP1 VALUE1 PROP2 VALUE2 ...\). PROP is a symbol.
2726 Unlike `plist-get', this allows you to distinguish between a missing
2727 property and a property with the value nil.
2728 The value is actually the tail of PLIST whose car is PROP. */)
2729 (Lisp_Object plist
, Lisp_Object prop
)
2731 while (CONSP (plist
) && !EQ (XCAR (plist
), prop
))
2734 plist
= XCDR (plist
);
2735 plist
= CDR (plist
);
2740 DEFUN ("widget-put", Fwidget_put
, Swidget_put
, 3, 3, 0,
2741 doc
: /* In WIDGET, set PROPERTY to VALUE.
2742 The value can later be retrieved with `widget-get'. */)
2743 (Lisp_Object widget
, Lisp_Object property
, Lisp_Object value
)
2745 CHECK_CONS (widget
);
2746 XSETCDR (widget
, Fplist_put (XCDR (widget
), property
, value
));
2750 DEFUN ("widget-get", Fwidget_get
, Swidget_get
, 2, 2, 0,
2751 doc
: /* In WIDGET, get the value of PROPERTY.
2752 The value could either be specified when the widget was created, or
2753 later with `widget-put'. */)
2754 (Lisp_Object widget
, Lisp_Object property
)
2762 CHECK_CONS (widget
);
2763 tmp
= Fplist_member (XCDR (widget
), property
);
2769 tmp
= XCAR (widget
);
2772 widget
= Fget (tmp
, Qwidget_type
);
2776 DEFUN ("widget-apply", Fwidget_apply
, Swidget_apply
, 2, MANY
, 0,
2777 doc
: /* Apply the value of WIDGET's PROPERTY to the widget itself.
2778 ARGS are passed as extra arguments to the function.
2779 usage: (widget-apply WIDGET PROPERTY &rest ARGS) */)
2780 (int nargs
, Lisp_Object
*args
)
2782 /* This function can GC. */
2783 Lisp_Object newargs
[3];
2784 struct gcpro gcpro1
, gcpro2
;
2787 newargs
[0] = Fwidget_get (args
[0], args
[1]);
2788 newargs
[1] = args
[0];
2789 newargs
[2] = Flist (nargs
- 2, args
+ 2);
2790 GCPRO2 (newargs
[0], newargs
[2]);
2791 result
= Fapply (3, newargs
);
2796 #ifdef HAVE_LANGINFO_CODESET
2797 #include <langinfo.h>
2800 DEFUN ("locale-info", Flocale_info
, Slocale_info
, 1, 1, 0,
2801 doc
: /* Access locale data ITEM for the current C locale, if available.
2802 ITEM should be one of the following:
2804 `codeset', returning the character set as a string (locale item CODESET);
2806 `days', returning a 7-element vector of day names (locale items DAY_n);
2808 `months', returning a 12-element vector of month names (locale items MON_n);
2810 `paper', returning a list (WIDTH HEIGHT) for the default paper size,
2811 both measured in milimeters (locale items PAPER_WIDTH, PAPER_HEIGHT).
2813 If the system can't provide such information through a call to
2814 `nl_langinfo', or if ITEM isn't from the list above, return nil.
2816 See also Info node `(libc)Locales'.
2818 The data read from the system are decoded using `locale-coding-system'. */)
2822 #ifdef HAVE_LANGINFO_CODESET
2824 if (EQ (item
, Qcodeset
))
2826 str
= nl_langinfo (CODESET
);
2827 return build_string (str
);
2830 else if (EQ (item
, Qdays
)) /* e.g. for calendar-day-name-array */
2832 Lisp_Object v
= Fmake_vector (make_number (7), Qnil
);
2833 const int days
[7] = {DAY_1
, DAY_2
, DAY_3
, DAY_4
, DAY_5
, DAY_6
, DAY_7
};
2835 struct gcpro gcpro1
;
2837 synchronize_system_time_locale ();
2838 for (i
= 0; i
< 7; i
++)
2840 str
= nl_langinfo (days
[i
]);
2841 val
= make_unibyte_string (str
, strlen (str
));
2842 /* Fixme: Is this coding system necessarily right, even if
2843 it is consistent with CODESET? If not, what to do? */
2844 Faset (v
, make_number (i
),
2845 code_convert_string_norecord (val
, Vlocale_coding_system
,
2853 else if (EQ (item
, Qmonths
)) /* e.g. for calendar-month-name-array */
2855 Lisp_Object v
= Fmake_vector (make_number (12), Qnil
);
2856 const int months
[12] = {MON_1
, MON_2
, MON_3
, MON_4
, MON_5
, MON_6
, MON_7
,
2857 MON_8
, MON_9
, MON_10
, MON_11
, MON_12
};
2859 struct gcpro gcpro1
;
2861 synchronize_system_time_locale ();
2862 for (i
= 0; i
< 12; i
++)
2864 str
= nl_langinfo (months
[i
]);
2865 val
= make_unibyte_string (str
, strlen (str
));
2866 Faset (v
, make_number (i
),
2867 code_convert_string_norecord (val
, Vlocale_coding_system
, 0));
2873 /* LC_PAPER stuff isn't defined as accessible in glibc as of 2.3.1,
2874 but is in the locale files. This could be used by ps-print. */
2876 else if (EQ (item
, Qpaper
))
2878 return list2 (make_number (nl_langinfo (PAPER_WIDTH
)),
2879 make_number (nl_langinfo (PAPER_HEIGHT
)));
2881 #endif /* PAPER_WIDTH */
2882 #endif /* HAVE_LANGINFO_CODESET*/
2886 /* base64 encode/decode functions (RFC 2045).
2887 Based on code from GNU recode. */
2889 #define MIME_LINE_LENGTH 76
2891 #define IS_ASCII(Character) \
2893 #define IS_BASE64(Character) \
2894 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0)
2895 #define IS_BASE64_IGNORABLE(Character) \
2896 ((Character) == ' ' || (Character) == '\t' || (Character) == '\n' \
2897 || (Character) == '\f' || (Character) == '\r')
2899 /* Used by base64_decode_1 to retrieve a non-base64-ignorable
2900 character or return retval if there are no characters left to
2902 #define READ_QUADRUPLET_BYTE(retval) \
2907 if (nchars_return) \
2908 *nchars_return = nchars; \
2913 while (IS_BASE64_IGNORABLE (c))
2915 /* Table of characters coding the 64 values. */
2916 static const char base64_value_to_char
[64] =
2918 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */
2919 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */
2920 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */
2921 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */
2922 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */
2923 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */
2924 '8', '9', '+', '/' /* 60-63 */
2927 /* Table of base64 values for first 128 characters. */
2928 static const short base64_char_to_value
[128] =
2930 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */
2931 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */
2932 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */
2933 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */
2934 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */
2935 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */
2936 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */
2937 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */
2938 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */
2939 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */
2940 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */
2941 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */
2942 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */
2945 /* The following diagram shows the logical steps by which three octets
2946 get transformed into four base64 characters.
2948 .--------. .--------. .--------.
2949 |aaaaaabb| |bbbbcccc| |ccdddddd|
2950 `--------' `--------' `--------'
2952 .--------+--------+--------+--------.
2953 |00aaaaaa|00bbbbbb|00cccccc|00dddddd|
2954 `--------+--------+--------+--------'
2956 .--------+--------+--------+--------.
2957 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD|
2958 `--------+--------+--------+--------'
2960 The octets are divided into 6 bit chunks, which are then encoded into
2961 base64 characters. */
2964 static EMACS_INT
base64_encode_1 (const char *, char *, EMACS_INT
, int, int);
2965 static EMACS_INT
base64_decode_1 (const char *, char *, EMACS_INT
, int,
2968 DEFUN ("base64-encode-region", Fbase64_encode_region
, Sbase64_encode_region
,
2970 doc
: /* Base64-encode the region between BEG and END.
2971 Return the length of the encoded text.
2972 Optional third argument NO-LINE-BREAK means do not break long lines
2973 into shorter lines. */)
2974 (Lisp_Object beg
, Lisp_Object end
, Lisp_Object no_line_break
)
2977 EMACS_INT allength
, length
;
2978 EMACS_INT ibeg
, iend
, encoded_length
;
2979 EMACS_INT old_pos
= PT
;
2982 validate_region (&beg
, &end
);
2984 ibeg
= CHAR_TO_BYTE (XFASTINT (beg
));
2985 iend
= CHAR_TO_BYTE (XFASTINT (end
));
2986 move_gap_both (XFASTINT (beg
), ibeg
);
2988 /* We need to allocate enough room for encoding the text.
2989 We need 33 1/3% more space, plus a newline every 76
2990 characters, and then we round up. */
2991 length
= iend
- ibeg
;
2992 allength
= length
+ length
/3 + 1;
2993 allength
+= allength
/ MIME_LINE_LENGTH
+ 1 + 6;
2995 SAFE_ALLOCA (encoded
, char *, allength
);
2996 encoded_length
= base64_encode_1 (BYTE_POS_ADDR (ibeg
), encoded
, length
,
2997 NILP (no_line_break
),
2998 !NILP (current_buffer
->enable_multibyte_characters
));
2999 if (encoded_length
> allength
)
3002 if (encoded_length
< 0)
3004 /* The encoding wasn't possible. */
3006 error ("Multibyte character in data for base64 encoding");
3009 /* Now we have encoded the region, so we insert the new contents
3010 and delete the old. (Insert first in order to preserve markers.) */
3011 SET_PT_BOTH (XFASTINT (beg
), ibeg
);
3012 insert (encoded
, encoded_length
);
3014 del_range_byte (ibeg
+ encoded_length
, iend
+ encoded_length
, 1);
3016 /* If point was outside of the region, restore it exactly; else just
3017 move to the beginning of the region. */
3018 if (old_pos
>= XFASTINT (end
))
3019 old_pos
+= encoded_length
- (XFASTINT (end
) - XFASTINT (beg
));
3020 else if (old_pos
> XFASTINT (beg
))
3021 old_pos
= XFASTINT (beg
);
3024 /* We return the length of the encoded text. */
3025 return make_number (encoded_length
);
3028 DEFUN ("base64-encode-string", Fbase64_encode_string
, Sbase64_encode_string
,
3030 doc
: /* Base64-encode STRING and return the result.
3031 Optional second argument NO-LINE-BREAK means do not break long lines
3032 into shorter lines. */)
3033 (Lisp_Object string
, Lisp_Object no_line_break
)
3035 EMACS_INT allength
, length
, encoded_length
;
3037 Lisp_Object encoded_string
;
3040 CHECK_STRING (string
);
3042 /* We need to allocate enough room for encoding the text.
3043 We need 33 1/3% more space, plus a newline every 76
3044 characters, and then we round up. */
3045 length
= SBYTES (string
);
3046 allength
= length
+ length
/3 + 1;
3047 allength
+= allength
/ MIME_LINE_LENGTH
+ 1 + 6;
3049 /* We need to allocate enough room for decoding the text. */
3050 SAFE_ALLOCA (encoded
, char *, allength
);
3052 encoded_length
= base64_encode_1 (SDATA (string
),
3053 encoded
, length
, NILP (no_line_break
),
3054 STRING_MULTIBYTE (string
));
3055 if (encoded_length
> allength
)
3058 if (encoded_length
< 0)
3060 /* The encoding wasn't possible. */
3062 error ("Multibyte character in data for base64 encoding");
3065 encoded_string
= make_unibyte_string (encoded
, encoded_length
);
3068 return encoded_string
;
3072 base64_encode_1 (const char *from
, char *to
, EMACS_INT length
,
3073 int line_break
, int multibyte
)
3086 c
= STRING_CHAR_AND_LENGTH (from
+ i
, bytes
);
3087 if (CHAR_BYTE8_P (c
))
3088 c
= CHAR_TO_BYTE8 (c
);
3096 /* Wrap line every 76 characters. */
3100 if (counter
< MIME_LINE_LENGTH
/ 4)
3109 /* Process first byte of a triplet. */
3111 *e
++ = base64_value_to_char
[0x3f & c
>> 2];
3112 value
= (0x03 & c
) << 4;
3114 /* Process second byte of a triplet. */
3118 *e
++ = base64_value_to_char
[value
];
3126 c
= STRING_CHAR_AND_LENGTH (from
+ i
, bytes
);
3127 if (CHAR_BYTE8_P (c
))
3128 c
= CHAR_TO_BYTE8 (c
);
3136 *e
++ = base64_value_to_char
[value
| (0x0f & c
>> 4)];
3137 value
= (0x0f & c
) << 2;
3139 /* Process third byte of a triplet. */
3143 *e
++ = base64_value_to_char
[value
];
3150 c
= STRING_CHAR_AND_LENGTH (from
+ i
, bytes
);
3151 if (CHAR_BYTE8_P (c
))
3152 c
= CHAR_TO_BYTE8 (c
);
3160 *e
++ = base64_value_to_char
[value
| (0x03 & c
>> 6)];
3161 *e
++ = base64_value_to_char
[0x3f & c
];
3168 DEFUN ("base64-decode-region", Fbase64_decode_region
, Sbase64_decode_region
,
3170 doc
: /* Base64-decode the region between BEG and END.
3171 Return the length of the decoded text.
3172 If the region can't be decoded, signal an error and don't modify the buffer. */)
3173 (Lisp_Object beg
, Lisp_Object end
)
3175 EMACS_INT ibeg
, iend
, length
, allength
;
3177 EMACS_INT old_pos
= PT
;
3178 EMACS_INT decoded_length
;
3179 EMACS_INT inserted_chars
;
3180 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
3183 validate_region (&beg
, &end
);
3185 ibeg
= CHAR_TO_BYTE (XFASTINT (beg
));
3186 iend
= CHAR_TO_BYTE (XFASTINT (end
));
3188 length
= iend
- ibeg
;
3190 /* We need to allocate enough room for decoding the text. If we are
3191 working on a multibyte buffer, each decoded code may occupy at
3193 allength
= multibyte
? length
* 2 : length
;
3194 SAFE_ALLOCA (decoded
, char *, allength
);
3196 move_gap_both (XFASTINT (beg
), ibeg
);
3197 decoded_length
= base64_decode_1 (BYTE_POS_ADDR (ibeg
), decoded
, length
,
3198 multibyte
, &inserted_chars
);
3199 if (decoded_length
> allength
)
3202 if (decoded_length
< 0)
3204 /* The decoding wasn't possible. */
3206 error ("Invalid base64 data");
3209 /* Now we have decoded the region, so we insert the new contents
3210 and delete the old. (Insert first in order to preserve markers.) */
3211 TEMP_SET_PT_BOTH (XFASTINT (beg
), ibeg
);
3212 insert_1_both (decoded
, inserted_chars
, decoded_length
, 0, 1, 0);
3215 /* Delete the original text. */
3216 del_range_both (PT
, PT_BYTE
, XFASTINT (end
) + inserted_chars
,
3217 iend
+ decoded_length
, 1);
3219 /* If point was outside of the region, restore it exactly; else just
3220 move to the beginning of the region. */
3221 if (old_pos
>= XFASTINT (end
))
3222 old_pos
+= inserted_chars
- (XFASTINT (end
) - XFASTINT (beg
));
3223 else if (old_pos
> XFASTINT (beg
))
3224 old_pos
= XFASTINT (beg
);
3225 SET_PT (old_pos
> ZV
? ZV
: old_pos
);
3227 return make_number (inserted_chars
);
3230 DEFUN ("base64-decode-string", Fbase64_decode_string
, Sbase64_decode_string
,
3232 doc
: /* Base64-decode STRING and return the result. */)
3233 (Lisp_Object string
)
3236 EMACS_INT length
, decoded_length
;
3237 Lisp_Object decoded_string
;
3240 CHECK_STRING (string
);
3242 length
= SBYTES (string
);
3243 /* We need to allocate enough room for decoding the text. */
3244 SAFE_ALLOCA (decoded
, char *, length
);
3246 /* The decoded result should be unibyte. */
3247 decoded_length
= base64_decode_1 (SDATA (string
), decoded
, length
,
3249 if (decoded_length
> length
)
3251 else if (decoded_length
>= 0)
3252 decoded_string
= make_unibyte_string (decoded
, decoded_length
);
3254 decoded_string
= Qnil
;
3257 if (!STRINGP (decoded_string
))
3258 error ("Invalid base64 data");
3260 return decoded_string
;
3263 /* Base64-decode the data at FROM of LENGHT bytes into TO. If
3264 MULTIBYTE is nonzero, the decoded result should be in multibyte
3265 form. If NCHARS_RETRUN is not NULL, store the number of produced
3266 characters in *NCHARS_RETURN. */
3269 base64_decode_1 (const char *from
, char *to
, EMACS_INT length
,
3270 int multibyte
, EMACS_INT
*nchars_return
)
3272 EMACS_INT i
= 0; /* Used inside READ_QUADRUPLET_BYTE */
3275 unsigned long value
;
3276 EMACS_INT nchars
= 0;
3280 /* Process first byte of a quadruplet. */
3282 READ_QUADRUPLET_BYTE (e
-to
);
3286 value
= base64_char_to_value
[c
] << 18;
3288 /* Process second byte of a quadruplet. */
3290 READ_QUADRUPLET_BYTE (-1);
3294 value
|= base64_char_to_value
[c
] << 12;
3296 c
= (unsigned char) (value
>> 16);
3297 if (multibyte
&& c
>= 128)
3298 e
+= BYTE8_STRING (c
, e
);
3303 /* Process third byte of a quadruplet. */
3305 READ_QUADRUPLET_BYTE (-1);
3309 READ_QUADRUPLET_BYTE (-1);
3318 value
|= base64_char_to_value
[c
] << 6;
3320 c
= (unsigned char) (0xff & value
>> 8);
3321 if (multibyte
&& c
>= 128)
3322 e
+= BYTE8_STRING (c
, e
);
3327 /* Process fourth byte of a quadruplet. */
3329 READ_QUADRUPLET_BYTE (-1);
3336 value
|= base64_char_to_value
[c
];
3338 c
= (unsigned char) (0xff & value
);
3339 if (multibyte
&& c
>= 128)
3340 e
+= BYTE8_STRING (c
, e
);
3349 /***********************************************************************
3351 ***** Hash Tables *****
3353 ***********************************************************************/
3355 /* Implemented by gerd@gnu.org. This hash table implementation was
3356 inspired by CMUCL hash tables. */
3360 1. For small tables, association lists are probably faster than
3361 hash tables because they have lower overhead.
3363 For uses of hash tables where the O(1) behavior of table
3364 operations is not a requirement, it might therefore be a good idea
3365 not to hash. Instead, we could just do a linear search in the
3366 key_and_value vector of the hash table. This could be done
3367 if a `:linear-search t' argument is given to make-hash-table. */
3370 /* The list of all weak hash tables. Don't staticpro this one. */
3372 struct Lisp_Hash_Table
*weak_hash_tables
;
3374 /* Various symbols. */
3376 Lisp_Object Qhash_table_p
, Qeq
, Qeql
, Qequal
, Qkey
, Qvalue
;
3377 Lisp_Object QCtest
, QCsize
, QCrehash_size
, QCrehash_threshold
, QCweakness
;
3378 Lisp_Object Qhash_table_test
, Qkey_or_value
, Qkey_and_value
;
3380 /* Function prototypes. */
3382 static struct Lisp_Hash_Table
*check_hash_table (Lisp_Object
);
3383 static int get_key_arg (Lisp_Object
, int, Lisp_Object
*, char *);
3384 static void maybe_resize_hash_table (struct Lisp_Hash_Table
*);
3385 static int cmpfn_eql (struct Lisp_Hash_Table
*, Lisp_Object
, unsigned,
3386 Lisp_Object
, unsigned);
3387 static int cmpfn_equal (struct Lisp_Hash_Table
*, Lisp_Object
, unsigned,
3388 Lisp_Object
, unsigned);
3389 static int cmpfn_user_defined (struct Lisp_Hash_Table
*, Lisp_Object
,
3390 unsigned, Lisp_Object
, unsigned);
3391 static unsigned hashfn_eq (struct Lisp_Hash_Table
*, Lisp_Object
);
3392 static unsigned hashfn_eql (struct Lisp_Hash_Table
*, Lisp_Object
);
3393 static unsigned hashfn_equal (struct Lisp_Hash_Table
*, Lisp_Object
);
3394 static unsigned hashfn_user_defined (struct Lisp_Hash_Table
*,
3396 static unsigned sxhash_string (unsigned char *, int);
3397 static unsigned sxhash_list (Lisp_Object
, int);
3398 static unsigned sxhash_vector (Lisp_Object
, int);
3399 static unsigned sxhash_bool_vector (Lisp_Object
);
3400 static int sweep_weak_table (struct Lisp_Hash_Table
*, int);
3404 /***********************************************************************
3406 ***********************************************************************/
3408 /* If OBJ is a Lisp hash table, return a pointer to its struct
3409 Lisp_Hash_Table. Otherwise, signal an error. */
3411 static struct Lisp_Hash_Table
*
3412 check_hash_table (Lisp_Object obj
)
3414 CHECK_HASH_TABLE (obj
);
3415 return XHASH_TABLE (obj
);
3419 /* Value is the next integer I >= N, N >= 0 which is "almost" a prime
3423 next_almost_prime (int n
)
3435 /* Find KEY in ARGS which has size NARGS. Don't consider indices for
3436 which USED[I] is non-zero. If found at index I in ARGS, set
3437 USED[I] and USED[I + 1] to 1, and return I + 1. Otherwise return
3438 -1. This function is used to extract a keyword/argument pair from
3439 a DEFUN parameter list. */
3442 get_key_arg (Lisp_Object key
, int nargs
, Lisp_Object
*args
, char *used
)
3446 for (i
= 0; i
< nargs
- 1; ++i
)
3447 if (!used
[i
] && EQ (args
[i
], key
))
3462 /* Return a Lisp vector which has the same contents as VEC but has
3463 size NEW_SIZE, NEW_SIZE >= VEC->size. Entries in the resulting
3464 vector that are not copied from VEC are set to INIT. */
3467 larger_vector (Lisp_Object vec
, int new_size
, Lisp_Object init
)
3469 struct Lisp_Vector
*v
;
3472 xassert (VECTORP (vec
));
3473 old_size
= ASIZE (vec
);
3474 xassert (new_size
>= old_size
);
3476 v
= allocate_vector (new_size
);
3477 memcpy (v
->contents
, XVECTOR (vec
)->contents
, old_size
* sizeof *v
->contents
);
3478 for (i
= old_size
; i
< new_size
; ++i
)
3479 v
->contents
[i
] = init
;
3480 XSETVECTOR (vec
, v
);
3485 /***********************************************************************
3487 ***********************************************************************/
3489 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
3490 HASH2 in hash table H using `eql'. Value is non-zero if KEY1 and
3491 KEY2 are the same. */
3494 cmpfn_eql (struct Lisp_Hash_Table
*h
, Lisp_Object key1
, unsigned int hash1
, Lisp_Object key2
, unsigned int hash2
)
3496 return (FLOATP (key1
)
3498 && XFLOAT_DATA (key1
) == XFLOAT_DATA (key2
));
3502 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
3503 HASH2 in hash table H using `equal'. Value is non-zero if KEY1 and
3504 KEY2 are the same. */
3507 cmpfn_equal (struct Lisp_Hash_Table
*h
, Lisp_Object key1
, unsigned int hash1
, Lisp_Object key2
, unsigned int hash2
)
3509 return hash1
== hash2
&& !NILP (Fequal (key1
, key2
));
3513 /* Compare KEY1 which has hash code HASH1, and KEY2 with hash code
3514 HASH2 in hash table H using H->user_cmp_function. Value is non-zero
3515 if KEY1 and KEY2 are the same. */
3518 cmpfn_user_defined (struct Lisp_Hash_Table
*h
, Lisp_Object key1
, unsigned int hash1
, Lisp_Object key2
, unsigned int hash2
)
3522 Lisp_Object args
[3];
3524 args
[0] = h
->user_cmp_function
;
3527 return !NILP (Ffuncall (3, args
));
3534 /* Value is a hash code for KEY for use in hash table H which uses
3535 `eq' to compare keys. The hash code returned is guaranteed to fit
3536 in a Lisp integer. */
3539 hashfn_eq (struct Lisp_Hash_Table
*h
, Lisp_Object key
)
3541 unsigned hash
= XUINT (key
) ^ XTYPE (key
);
3542 xassert ((hash
& ~INTMASK
) == 0);
3547 /* Value is a hash code for KEY for use in hash table H which uses
3548 `eql' to compare keys. The hash code returned is guaranteed to fit
3549 in a Lisp integer. */
3552 hashfn_eql (struct Lisp_Hash_Table
*h
, Lisp_Object key
)
3556 hash
= sxhash (key
, 0);
3558 hash
= XUINT (key
) ^ XTYPE (key
);
3559 xassert ((hash
& ~INTMASK
) == 0);
3564 /* Value is a hash code for KEY for use in hash table H which uses
3565 `equal' to compare keys. The hash code returned is guaranteed to fit
3566 in a Lisp integer. */
3569 hashfn_equal (struct Lisp_Hash_Table
*h
, Lisp_Object key
)
3571 unsigned hash
= sxhash (key
, 0);
3572 xassert ((hash
& ~INTMASK
) == 0);
3577 /* Value is a hash code for KEY for use in hash table H which uses as
3578 user-defined function to compare keys. The hash code returned is
3579 guaranteed to fit in a Lisp integer. */
3582 hashfn_user_defined (struct Lisp_Hash_Table
*h
, Lisp_Object key
)
3584 Lisp_Object args
[2], hash
;
3586 args
[0] = h
->user_hash_function
;
3588 hash
= Ffuncall (2, args
);
3589 if (!INTEGERP (hash
))
3590 signal_error ("Invalid hash code returned from user-supplied hash function", hash
);
3591 return XUINT (hash
);
3595 /* Create and initialize a new hash table.
3597 TEST specifies the test the hash table will use to compare keys.
3598 It must be either one of the predefined tests `eq', `eql' or
3599 `equal' or a symbol denoting a user-defined test named TEST with
3600 test and hash functions USER_TEST and USER_HASH.
3602 Give the table initial capacity SIZE, SIZE >= 0, an integer.
3604 If REHASH_SIZE is an integer, it must be > 0, and this hash table's
3605 new size when it becomes full is computed by adding REHASH_SIZE to
3606 its old size. If REHASH_SIZE is a float, it must be > 1.0, and the
3607 table's new size is computed by multiplying its old size with
3610 REHASH_THRESHOLD must be a float <= 1.0, and > 0. The table will
3611 be resized when the ratio of (number of entries in the table) /
3612 (table size) is >= REHASH_THRESHOLD.
3614 WEAK specifies the weakness of the table. If non-nil, it must be
3615 one of the symbols `key', `value', `key-or-value', or `key-and-value'. */
3618 make_hash_table (Lisp_Object test
, Lisp_Object size
, Lisp_Object rehash_size
,
3619 Lisp_Object rehash_threshold
, Lisp_Object weak
,
3620 Lisp_Object user_test
, Lisp_Object user_hash
)
3622 struct Lisp_Hash_Table
*h
;
3624 int index_size
, i
, sz
;
3626 /* Preconditions. */
3627 xassert (SYMBOLP (test
));
3628 xassert (INTEGERP (size
) && XINT (size
) >= 0);
3629 xassert ((INTEGERP (rehash_size
) && XINT (rehash_size
) > 0)
3630 || (FLOATP (rehash_size
) && XFLOATINT (rehash_size
) > 1.0));
3631 xassert (FLOATP (rehash_threshold
)
3632 && XFLOATINT (rehash_threshold
) > 0
3633 && XFLOATINT (rehash_threshold
) <= 1.0);
3635 if (XFASTINT (size
) == 0)
3636 size
= make_number (1);
3638 /* Allocate a table and initialize it. */
3639 h
= allocate_hash_table ();
3641 /* Initialize hash table slots. */
3642 sz
= XFASTINT (size
);
3645 if (EQ (test
, Qeql
))
3647 h
->cmpfn
= cmpfn_eql
;
3648 h
->hashfn
= hashfn_eql
;
3650 else if (EQ (test
, Qeq
))
3653 h
->hashfn
= hashfn_eq
;
3655 else if (EQ (test
, Qequal
))
3657 h
->cmpfn
= cmpfn_equal
;
3658 h
->hashfn
= hashfn_equal
;
3662 h
->user_cmp_function
= user_test
;
3663 h
->user_hash_function
= user_hash
;
3664 h
->cmpfn
= cmpfn_user_defined
;
3665 h
->hashfn
= hashfn_user_defined
;
3669 h
->rehash_threshold
= rehash_threshold
;
3670 h
->rehash_size
= rehash_size
;
3672 h
->key_and_value
= Fmake_vector (make_number (2 * sz
), Qnil
);
3673 h
->hash
= Fmake_vector (size
, Qnil
);
3674 h
->next
= Fmake_vector (size
, Qnil
);
3675 /* Cast to int here avoids losing with gcc 2.95 on Tru64/Alpha... */
3676 index_size
= next_almost_prime ((int) (sz
/ XFLOATINT (rehash_threshold
)));
3677 h
->index
= Fmake_vector (make_number (index_size
), Qnil
);
3679 /* Set up the free list. */
3680 for (i
= 0; i
< sz
- 1; ++i
)
3681 HASH_NEXT (h
, i
) = make_number (i
+ 1);
3682 h
->next_free
= make_number (0);
3684 XSET_HASH_TABLE (table
, h
);
3685 xassert (HASH_TABLE_P (table
));
3686 xassert (XHASH_TABLE (table
) == h
);
3688 /* Maybe add this hash table to the list of all weak hash tables. */
3690 h
->next_weak
= NULL
;
3693 h
->next_weak
= weak_hash_tables
;
3694 weak_hash_tables
= h
;
3701 /* Return a copy of hash table H1. Keys and values are not copied,
3702 only the table itself is. */
3705 copy_hash_table (struct Lisp_Hash_Table
*h1
)
3708 struct Lisp_Hash_Table
*h2
;
3709 struct Lisp_Vector
*next
;
3711 h2
= allocate_hash_table ();
3712 next
= h2
->vec_next
;
3713 memcpy (h2
, h1
, sizeof *h2
);
3714 h2
->vec_next
= next
;
3715 h2
->key_and_value
= Fcopy_sequence (h1
->key_and_value
);
3716 h2
->hash
= Fcopy_sequence (h1
->hash
);
3717 h2
->next
= Fcopy_sequence (h1
->next
);
3718 h2
->index
= Fcopy_sequence (h1
->index
);
3719 XSET_HASH_TABLE (table
, h2
);
3721 /* Maybe add this hash table to the list of all weak hash tables. */
3722 if (!NILP (h2
->weak
))
3724 h2
->next_weak
= weak_hash_tables
;
3725 weak_hash_tables
= h2
;
3732 /* Resize hash table H if it's too full. If H cannot be resized
3733 because it's already too large, throw an error. */
3736 maybe_resize_hash_table (struct Lisp_Hash_Table
*h
)
3738 if (NILP (h
->next_free
))
3740 int old_size
= HASH_TABLE_SIZE (h
);
3741 int i
, new_size
, index_size
;
3744 if (INTEGERP (h
->rehash_size
))
3745 new_size
= old_size
+ XFASTINT (h
->rehash_size
);
3747 new_size
= old_size
* XFLOATINT (h
->rehash_size
);
3748 new_size
= max (old_size
+ 1, new_size
);
3749 index_size
= next_almost_prime ((int)
3751 / XFLOATINT (h
->rehash_threshold
)));
3752 /* Assignment to EMACS_INT stops GCC whining about limited range
3754 nsize
= max (index_size
, 2 * new_size
);
3755 if (nsize
> MOST_POSITIVE_FIXNUM
)
3756 error ("Hash table too large to resize");
3758 h
->key_and_value
= larger_vector (h
->key_and_value
, 2 * new_size
, Qnil
);
3759 h
->next
= larger_vector (h
->next
, new_size
, Qnil
);
3760 h
->hash
= larger_vector (h
->hash
, new_size
, Qnil
);
3761 h
->index
= Fmake_vector (make_number (index_size
), Qnil
);
3763 /* Update the free list. Do it so that new entries are added at
3764 the end of the free list. This makes some operations like
3766 for (i
= old_size
; i
< new_size
- 1; ++i
)
3767 HASH_NEXT (h
, i
) = make_number (i
+ 1);
3769 if (!NILP (h
->next_free
))
3771 Lisp_Object last
, next
;
3773 last
= h
->next_free
;
3774 while (next
= HASH_NEXT (h
, XFASTINT (last
)),
3778 HASH_NEXT (h
, XFASTINT (last
)) = make_number (old_size
);
3781 XSETFASTINT (h
->next_free
, old_size
);
3784 for (i
= 0; i
< old_size
; ++i
)
3785 if (!NILP (HASH_HASH (h
, i
)))
3787 unsigned hash_code
= XUINT (HASH_HASH (h
, i
));
3788 int start_of_bucket
= hash_code
% ASIZE (h
->index
);
3789 HASH_NEXT (h
, i
) = HASH_INDEX (h
, start_of_bucket
);
3790 HASH_INDEX (h
, start_of_bucket
) = make_number (i
);
3796 /* Lookup KEY in hash table H. If HASH is non-null, return in *HASH
3797 the hash code of KEY. Value is the index of the entry in H
3798 matching KEY, or -1 if not found. */
3801 hash_lookup (struct Lisp_Hash_Table
*h
, Lisp_Object key
, unsigned int *hash
)
3804 int start_of_bucket
;
3807 hash_code
= h
->hashfn (h
, key
);
3811 start_of_bucket
= hash_code
% ASIZE (h
->index
);
3812 idx
= HASH_INDEX (h
, start_of_bucket
);
3814 /* We need not gcpro idx since it's either an integer or nil. */
3817 int i
= XFASTINT (idx
);
3818 if (EQ (key
, HASH_KEY (h
, i
))
3820 && h
->cmpfn (h
, key
, hash_code
,
3821 HASH_KEY (h
, i
), XUINT (HASH_HASH (h
, i
)))))
3823 idx
= HASH_NEXT (h
, i
);
3826 return NILP (idx
) ? -1 : XFASTINT (idx
);
3830 /* Put an entry into hash table H that associates KEY with VALUE.
3831 HASH is a previously computed hash code of KEY.
3832 Value is the index of the entry in H matching KEY. */
3835 hash_put (struct Lisp_Hash_Table
*h
, Lisp_Object key
, Lisp_Object value
, unsigned int hash
)
3837 int start_of_bucket
, i
;
3839 xassert ((hash
& ~INTMASK
) == 0);
3841 /* Increment count after resizing because resizing may fail. */
3842 maybe_resize_hash_table (h
);
3845 /* Store key/value in the key_and_value vector. */
3846 i
= XFASTINT (h
->next_free
);
3847 h
->next_free
= HASH_NEXT (h
, i
);
3848 HASH_KEY (h
, i
) = key
;
3849 HASH_VALUE (h
, i
) = value
;
3851 /* Remember its hash code. */
3852 HASH_HASH (h
, i
) = make_number (hash
);
3854 /* Add new entry to its collision chain. */
3855 start_of_bucket
= hash
% ASIZE (h
->index
);
3856 HASH_NEXT (h
, i
) = HASH_INDEX (h
, start_of_bucket
);
3857 HASH_INDEX (h
, start_of_bucket
) = make_number (i
);
3862 /* Remove the entry matching KEY from hash table H, if there is one. */
3865 hash_remove_from_table (struct Lisp_Hash_Table
*h
, Lisp_Object key
)
3868 int start_of_bucket
;
3869 Lisp_Object idx
, prev
;
3871 hash_code
= h
->hashfn (h
, key
);
3872 start_of_bucket
= hash_code
% ASIZE (h
->index
);
3873 idx
= HASH_INDEX (h
, start_of_bucket
);
3876 /* We need not gcpro idx, prev since they're either integers or nil. */
3879 int i
= XFASTINT (idx
);
3881 if (EQ (key
, HASH_KEY (h
, i
))
3883 && h
->cmpfn (h
, key
, hash_code
,
3884 HASH_KEY (h
, i
), XUINT (HASH_HASH (h
, i
)))))
3886 /* Take entry out of collision chain. */
3888 HASH_INDEX (h
, start_of_bucket
) = HASH_NEXT (h
, i
);
3890 HASH_NEXT (h
, XFASTINT (prev
)) = HASH_NEXT (h
, i
);
3892 /* Clear slots in key_and_value and add the slots to
3894 HASH_KEY (h
, i
) = HASH_VALUE (h
, i
) = HASH_HASH (h
, i
) = Qnil
;
3895 HASH_NEXT (h
, i
) = h
->next_free
;
3896 h
->next_free
= make_number (i
);
3898 xassert (h
->count
>= 0);
3904 idx
= HASH_NEXT (h
, i
);
3910 /* Clear hash table H. */
3913 hash_clear (struct Lisp_Hash_Table
*h
)
3917 int i
, size
= HASH_TABLE_SIZE (h
);
3919 for (i
= 0; i
< size
; ++i
)
3921 HASH_NEXT (h
, i
) = i
< size
- 1 ? make_number (i
+ 1) : Qnil
;
3922 HASH_KEY (h
, i
) = Qnil
;
3923 HASH_VALUE (h
, i
) = Qnil
;
3924 HASH_HASH (h
, i
) = Qnil
;
3927 for (i
= 0; i
< ASIZE (h
->index
); ++i
)
3928 ASET (h
->index
, i
, Qnil
);
3930 h
->next_free
= make_number (0);
3937 /************************************************************************
3939 ************************************************************************/
3942 init_weak_hash_tables (void)
3944 weak_hash_tables
= NULL
;
3947 /* Sweep weak hash table H. REMOVE_ENTRIES_P non-zero means remove
3948 entries from the table that don't survive the current GC.
3949 REMOVE_ENTRIES_P zero means mark entries that are in use. Value is
3950 non-zero if anything was marked. */
3953 sweep_weak_table (struct Lisp_Hash_Table
*h
, int remove_entries_p
)
3955 int bucket
, n
, marked
;
3957 n
= ASIZE (h
->index
) & ~ARRAY_MARK_FLAG
;
3960 for (bucket
= 0; bucket
< n
; ++bucket
)
3962 Lisp_Object idx
, next
, prev
;
3964 /* Follow collision chain, removing entries that
3965 don't survive this garbage collection. */
3967 for (idx
= HASH_INDEX (h
, bucket
); !NILP (idx
); idx
= next
)
3969 int i
= XFASTINT (idx
);
3970 int key_known_to_survive_p
= survives_gc_p (HASH_KEY (h
, i
));
3971 int value_known_to_survive_p
= survives_gc_p (HASH_VALUE (h
, i
));
3974 if (EQ (h
->weak
, Qkey
))
3975 remove_p
= !key_known_to_survive_p
;
3976 else if (EQ (h
->weak
, Qvalue
))
3977 remove_p
= !value_known_to_survive_p
;
3978 else if (EQ (h
->weak
, Qkey_or_value
))
3979 remove_p
= !(key_known_to_survive_p
|| value_known_to_survive_p
);
3980 else if (EQ (h
->weak
, Qkey_and_value
))
3981 remove_p
= !(key_known_to_survive_p
&& value_known_to_survive_p
);
3985 next
= HASH_NEXT (h
, i
);
3987 if (remove_entries_p
)
3991 /* Take out of collision chain. */
3993 HASH_INDEX (h
, bucket
) = next
;
3995 HASH_NEXT (h
, XFASTINT (prev
)) = next
;
3997 /* Add to free list. */
3998 HASH_NEXT (h
, i
) = h
->next_free
;
4001 /* Clear key, value, and hash. */
4002 HASH_KEY (h
, i
) = HASH_VALUE (h
, i
) = Qnil
;
4003 HASH_HASH (h
, i
) = Qnil
;
4016 /* Make sure key and value survive. */
4017 if (!key_known_to_survive_p
)
4019 mark_object (HASH_KEY (h
, i
));
4023 if (!value_known_to_survive_p
)
4025 mark_object (HASH_VALUE (h
, i
));
4036 /* Remove elements from weak hash tables that don't survive the
4037 current garbage collection. Remove weak tables that don't survive
4038 from Vweak_hash_tables. Called from gc_sweep. */
4041 sweep_weak_hash_tables (void)
4043 struct Lisp_Hash_Table
*h
, *used
, *next
;
4046 /* Mark all keys and values that are in use. Keep on marking until
4047 there is no more change. This is necessary for cases like
4048 value-weak table A containing an entry X -> Y, where Y is used in a
4049 key-weak table B, Z -> Y. If B comes after A in the list of weak
4050 tables, X -> Y might be removed from A, although when looking at B
4051 one finds that it shouldn't. */
4055 for (h
= weak_hash_tables
; h
; h
= h
->next_weak
)
4057 if (h
->size
& ARRAY_MARK_FLAG
)
4058 marked
|= sweep_weak_table (h
, 0);
4063 /* Remove tables and entries that aren't used. */
4064 for (h
= weak_hash_tables
, used
= NULL
; h
; h
= next
)
4066 next
= h
->next_weak
;
4068 if (h
->size
& ARRAY_MARK_FLAG
)
4070 /* TABLE is marked as used. Sweep its contents. */
4072 sweep_weak_table (h
, 1);
4074 /* Add table to the list of used weak hash tables. */
4075 h
->next_weak
= used
;
4080 weak_hash_tables
= used
;
4085 /***********************************************************************
4086 Hash Code Computation
4087 ***********************************************************************/
4089 /* Maximum depth up to which to dive into Lisp structures. */
4091 #define SXHASH_MAX_DEPTH 3
4093 /* Maximum length up to which to take list and vector elements into
4096 #define SXHASH_MAX_LEN 7
4098 /* Combine two integers X and Y for hashing. */
4100 #define SXHASH_COMBINE(X, Y) \
4101 ((((unsigned)(X) << 4) + (((unsigned)(X) >> 24) & 0x0fffffff)) \
4105 /* Return a hash for string PTR which has length LEN. The hash
4106 code returned is guaranteed to fit in a Lisp integer. */
4109 sxhash_string (unsigned char *ptr
, int len
)
4111 unsigned char *p
= ptr
;
4112 unsigned char *end
= p
+ len
;
4121 hash
= ((hash
<< 4) + (hash
>> 28) + c
);
4124 return hash
& INTMASK
;
4128 /* Return a hash for list LIST. DEPTH is the current depth in the
4129 list. We don't recurse deeper than SXHASH_MAX_DEPTH in it. */
4132 sxhash_list (Lisp_Object list
, int depth
)
4137 if (depth
< SXHASH_MAX_DEPTH
)
4139 CONSP (list
) && i
< SXHASH_MAX_LEN
;
4140 list
= XCDR (list
), ++i
)
4142 unsigned hash2
= sxhash (XCAR (list
), depth
+ 1);
4143 hash
= SXHASH_COMBINE (hash
, hash2
);
4148 unsigned hash2
= sxhash (list
, depth
+ 1);
4149 hash
= SXHASH_COMBINE (hash
, hash2
);
4156 /* Return a hash for vector VECTOR. DEPTH is the current depth in
4157 the Lisp structure. */
4160 sxhash_vector (Lisp_Object vec
, int depth
)
4162 unsigned hash
= ASIZE (vec
);
4165 n
= min (SXHASH_MAX_LEN
, ASIZE (vec
));
4166 for (i
= 0; i
< n
; ++i
)
4168 unsigned hash2
= sxhash (AREF (vec
, i
), depth
+ 1);
4169 hash
= SXHASH_COMBINE (hash
, hash2
);
4176 /* Return a hash for bool-vector VECTOR. */
4179 sxhash_bool_vector (Lisp_Object vec
)
4181 unsigned hash
= XBOOL_VECTOR (vec
)->size
;
4184 n
= min (SXHASH_MAX_LEN
, XBOOL_VECTOR (vec
)->vector_size
);
4185 for (i
= 0; i
< n
; ++i
)
4186 hash
= SXHASH_COMBINE (hash
, XBOOL_VECTOR (vec
)->data
[i
]);
4192 /* Return a hash code for OBJ. DEPTH is the current depth in the Lisp
4193 structure. Value is an unsigned integer clipped to INTMASK. */
4196 sxhash (Lisp_Object obj
, int depth
)
4200 if (depth
> SXHASH_MAX_DEPTH
)
4203 switch (XTYPE (obj
))
4214 obj
= SYMBOL_NAME (obj
);
4218 hash
= sxhash_string (SDATA (obj
), SCHARS (obj
));
4221 /* This can be everything from a vector to an overlay. */
4222 case Lisp_Vectorlike
:
4224 /* According to the CL HyperSpec, two arrays are equal only if
4225 they are `eq', except for strings and bit-vectors. In
4226 Emacs, this works differently. We have to compare element
4228 hash
= sxhash_vector (obj
, depth
);
4229 else if (BOOL_VECTOR_P (obj
))
4230 hash
= sxhash_bool_vector (obj
);
4232 /* Others are `equal' if they are `eq', so let's take their
4238 hash
= sxhash_list (obj
, depth
);
4243 double val
= XFLOAT_DATA (obj
);
4244 unsigned char *p
= (unsigned char *) &val
;
4245 unsigned char *e
= p
+ sizeof val
;
4246 for (hash
= 0; p
< e
; ++p
)
4247 hash
= SXHASH_COMBINE (hash
, *p
);
4255 return hash
& INTMASK
;
4260 /***********************************************************************
4262 ***********************************************************************/
4265 DEFUN ("sxhash", Fsxhash
, Ssxhash
, 1, 1, 0,
4266 doc
: /* Compute a hash code for OBJ and return it as integer. */)
4269 unsigned hash
= sxhash (obj
, 0);
4270 return make_number (hash
);
4274 DEFUN ("make-hash-table", Fmake_hash_table
, Smake_hash_table
, 0, MANY
, 0,
4275 doc
: /* Create and return a new hash table.
4277 Arguments are specified as keyword/argument pairs. The following
4278 arguments are defined:
4280 :test TEST -- TEST must be a symbol that specifies how to compare
4281 keys. Default is `eql'. Predefined are the tests `eq', `eql', and
4282 `equal'. User-supplied test and hash functions can be specified via
4283 `define-hash-table-test'.
4285 :size SIZE -- A hint as to how many elements will be put in the table.
4288 :rehash-size REHASH-SIZE - Indicates how to expand the table when it
4289 fills up. If REHASH-SIZE is an integer, increase the size by that
4290 amount. If it is a float, it must be > 1.0, and the new size is the
4291 old size multiplied by that factor. Default is 1.5.
4293 :rehash-threshold THRESHOLD -- THRESHOLD must a float > 0, and <= 1.0.
4294 Resize the hash table when the ratio (number of entries / table size)
4295 is greater than or equal to THRESHOLD. Default is 0.8.
4297 :weakness WEAK -- WEAK must be one of nil, t, `key', `value',
4298 `key-or-value', or `key-and-value'. If WEAK is not nil, the table
4299 returned is a weak table. Key/value pairs are removed from a weak
4300 hash table when there are no non-weak references pointing to their
4301 key, value, one of key or value, or both key and value, depending on
4302 WEAK. WEAK t is equivalent to `key-and-value'. Default value of WEAK
4305 usage: (make-hash-table &rest KEYWORD-ARGS) */)
4306 (int nargs
, Lisp_Object
*args
)
4308 Lisp_Object test
, size
, rehash_size
, rehash_threshold
, weak
;
4309 Lisp_Object user_test
, user_hash
;
4313 /* The vector `used' is used to keep track of arguments that
4314 have been consumed. */
4315 used
= (char *) alloca (nargs
* sizeof *used
);
4316 memset (used
, 0, nargs
* sizeof *used
);
4318 /* See if there's a `:test TEST' among the arguments. */
4319 i
= get_key_arg (QCtest
, nargs
, args
, used
);
4320 test
= i
< 0 ? Qeql
: args
[i
];
4321 if (!EQ (test
, Qeq
) && !EQ (test
, Qeql
) && !EQ (test
, Qequal
))
4323 /* See if it is a user-defined test. */
4326 prop
= Fget (test
, Qhash_table_test
);
4327 if (!CONSP (prop
) || !CONSP (XCDR (prop
)))
4328 signal_error ("Invalid hash table test", test
);
4329 user_test
= XCAR (prop
);
4330 user_hash
= XCAR (XCDR (prop
));
4333 user_test
= user_hash
= Qnil
;
4335 /* See if there's a `:size SIZE' argument. */
4336 i
= get_key_arg (QCsize
, nargs
, args
, used
);
4337 size
= i
< 0 ? Qnil
: args
[i
];
4339 size
= make_number (DEFAULT_HASH_SIZE
);
4340 else if (!INTEGERP (size
) || XINT (size
) < 0)
4341 signal_error ("Invalid hash table size", size
);
4343 /* Look for `:rehash-size SIZE'. */
4344 i
= get_key_arg (QCrehash_size
, nargs
, args
, used
);
4345 rehash_size
= i
< 0 ? make_float (DEFAULT_REHASH_SIZE
) : args
[i
];
4346 if (!NUMBERP (rehash_size
)
4347 || (INTEGERP (rehash_size
) && XINT (rehash_size
) <= 0)
4348 || XFLOATINT (rehash_size
) <= 1.0)
4349 signal_error ("Invalid hash table rehash size", rehash_size
);
4351 /* Look for `:rehash-threshold THRESHOLD'. */
4352 i
= get_key_arg (QCrehash_threshold
, nargs
, args
, used
);
4353 rehash_threshold
= i
< 0 ? make_float (DEFAULT_REHASH_THRESHOLD
) : args
[i
];
4354 if (!FLOATP (rehash_threshold
)
4355 || XFLOATINT (rehash_threshold
) <= 0.0
4356 || XFLOATINT (rehash_threshold
) > 1.0)
4357 signal_error ("Invalid hash table rehash threshold", rehash_threshold
);
4359 /* Look for `:weakness WEAK'. */
4360 i
= get_key_arg (QCweakness
, nargs
, args
, used
);
4361 weak
= i
< 0 ? Qnil
: args
[i
];
4363 weak
= Qkey_and_value
;
4366 && !EQ (weak
, Qvalue
)
4367 && !EQ (weak
, Qkey_or_value
)
4368 && !EQ (weak
, Qkey_and_value
))
4369 signal_error ("Invalid hash table weakness", weak
);
4371 /* Now, all args should have been used up, or there's a problem. */
4372 for (i
= 0; i
< nargs
; ++i
)
4374 signal_error ("Invalid argument list", args
[i
]);
4376 return make_hash_table (test
, size
, rehash_size
, rehash_threshold
, weak
,
4377 user_test
, user_hash
);
4381 DEFUN ("copy-hash-table", Fcopy_hash_table
, Scopy_hash_table
, 1, 1, 0,
4382 doc
: /* Return a copy of hash table TABLE. */)
4385 return copy_hash_table (check_hash_table (table
));
4389 DEFUN ("hash-table-count", Fhash_table_count
, Shash_table_count
, 1, 1, 0,
4390 doc
: /* Return the number of elements in TABLE. */)
4393 return make_number (check_hash_table (table
)->count
);
4397 DEFUN ("hash-table-rehash-size", Fhash_table_rehash_size
,
4398 Shash_table_rehash_size
, 1, 1, 0,
4399 doc
: /* Return the current rehash size of TABLE. */)
4402 return check_hash_table (table
)->rehash_size
;
4406 DEFUN ("hash-table-rehash-threshold", Fhash_table_rehash_threshold
,
4407 Shash_table_rehash_threshold
, 1, 1, 0,
4408 doc
: /* Return the current rehash threshold of TABLE. */)
4411 return check_hash_table (table
)->rehash_threshold
;
4415 DEFUN ("hash-table-size", Fhash_table_size
, Shash_table_size
, 1, 1, 0,
4416 doc
: /* Return the size of TABLE.
4417 The size can be used as an argument to `make-hash-table' to create
4418 a hash table than can hold as many elements as TABLE holds
4419 without need for resizing. */)
4422 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4423 return make_number (HASH_TABLE_SIZE (h
));
4427 DEFUN ("hash-table-test", Fhash_table_test
, Shash_table_test
, 1, 1, 0,
4428 doc
: /* Return the test TABLE uses. */)
4431 return check_hash_table (table
)->test
;
4435 DEFUN ("hash-table-weakness", Fhash_table_weakness
, Shash_table_weakness
,
4437 doc
: /* Return the weakness of TABLE. */)
4440 return check_hash_table (table
)->weak
;
4444 DEFUN ("hash-table-p", Fhash_table_p
, Shash_table_p
, 1, 1, 0,
4445 doc
: /* Return t if OBJ is a Lisp hash table object. */)
4448 return HASH_TABLE_P (obj
) ? Qt
: Qnil
;
4452 DEFUN ("clrhash", Fclrhash
, Sclrhash
, 1, 1, 0,
4453 doc
: /* Clear hash table TABLE and return it. */)
4456 hash_clear (check_hash_table (table
));
4457 /* Be compatible with XEmacs. */
4462 DEFUN ("gethash", Fgethash
, Sgethash
, 2, 3, 0,
4463 doc
: /* Look up KEY in TABLE and return its associated value.
4464 If KEY is not found, return DFLT which defaults to nil. */)
4465 (Lisp_Object key
, Lisp_Object table
, Lisp_Object dflt
)
4467 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4468 int i
= hash_lookup (h
, key
, NULL
);
4469 return i
>= 0 ? HASH_VALUE (h
, i
) : dflt
;
4473 DEFUN ("puthash", Fputhash
, Sputhash
, 3, 3, 0,
4474 doc
: /* Associate KEY with VALUE in hash table TABLE.
4475 If KEY is already present in table, replace its current value with
4477 (Lisp_Object key
, Lisp_Object value
, Lisp_Object table
)
4479 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4483 i
= hash_lookup (h
, key
, &hash
);
4485 HASH_VALUE (h
, i
) = value
;
4487 hash_put (h
, key
, value
, hash
);
4493 DEFUN ("remhash", Fremhash
, Sremhash
, 2, 2, 0,
4494 doc
: /* Remove KEY from TABLE. */)
4495 (Lisp_Object key
, Lisp_Object table
)
4497 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4498 hash_remove_from_table (h
, key
);
4503 DEFUN ("maphash", Fmaphash
, Smaphash
, 2, 2, 0,
4504 doc
: /* Call FUNCTION for all entries in hash table TABLE.
4505 FUNCTION is called with two arguments, KEY and VALUE. */)
4506 (Lisp_Object function
, Lisp_Object table
)
4508 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
4509 Lisp_Object args
[3];
4512 for (i
= 0; i
< HASH_TABLE_SIZE (h
); ++i
)
4513 if (!NILP (HASH_HASH (h
, i
)))
4516 args
[1] = HASH_KEY (h
, i
);
4517 args
[2] = HASH_VALUE (h
, i
);
4525 DEFUN ("define-hash-table-test", Fdefine_hash_table_test
,
4526 Sdefine_hash_table_test
, 3, 3, 0,
4527 doc
: /* Define a new hash table test with name NAME, a symbol.
4529 In hash tables created with NAME specified as test, use TEST to
4530 compare keys, and HASH for computing hash codes of keys.
4532 TEST must be a function taking two arguments and returning non-nil if
4533 both arguments are the same. HASH must be a function taking one
4534 argument and return an integer that is the hash code of the argument.
4535 Hash code computation should use the whole value range of integers,
4536 including negative integers. */)
4537 (Lisp_Object name
, Lisp_Object test
, Lisp_Object hash
)
4539 return Fput (name
, Qhash_table_test
, list2 (test
, hash
));
4544 /************************************************************************
4546 ************************************************************************/
4550 DEFUN ("md5", Fmd5
, Smd5
, 1, 5, 0,
4551 doc
: /* Return MD5 message digest of OBJECT, a buffer or string.
4553 A message digest is a cryptographic checksum of a document, and the
4554 algorithm to calculate it is defined in RFC 1321.
4556 The two optional arguments START and END are character positions
4557 specifying for which part of OBJECT the message digest should be
4558 computed. If nil or omitted, the digest is computed for the whole
4561 The MD5 message digest is computed from the result of encoding the
4562 text in a coding system, not directly from the internal Emacs form of
4563 the text. The optional fourth argument CODING-SYSTEM specifies which
4564 coding system to encode the text with. It should be the same coding
4565 system that you used or will use when actually writing the text into a
4568 If CODING-SYSTEM is nil or omitted, the default depends on OBJECT. If
4569 OBJECT is a buffer, the default for CODING-SYSTEM is whatever coding
4570 system would be chosen by default for writing this text into a file.
4572 If OBJECT is a string, the most preferred coding system (see the
4573 command `prefer-coding-system') is used.
4575 If NOERROR is non-nil, silently assume the `raw-text' coding if the
4576 guesswork fails. Normally, an error is signaled in such case. */)
4577 (Lisp_Object object
, Lisp_Object start
, Lisp_Object end
, Lisp_Object coding_system
, Lisp_Object noerror
)
4579 unsigned char digest
[16];
4580 unsigned char value
[33];
4583 EMACS_INT size_byte
= 0;
4584 EMACS_INT start_char
= 0, end_char
= 0;
4585 EMACS_INT start_byte
= 0, end_byte
= 0;
4586 register EMACS_INT b
, e
;
4587 register struct buffer
*bp
;
4590 if (STRINGP (object
))
4592 if (NILP (coding_system
))
4594 /* Decide the coding-system to encode the data with. */
4596 if (STRING_MULTIBYTE (object
))
4597 /* use default, we can't guess correct value */
4598 coding_system
= preferred_coding_system ();
4600 coding_system
= Qraw_text
;
4603 if (NILP (Fcoding_system_p (coding_system
)))
4605 /* Invalid coding system. */
4607 if (!NILP (noerror
))
4608 coding_system
= Qraw_text
;
4610 xsignal1 (Qcoding_system_error
, coding_system
);
4613 if (STRING_MULTIBYTE (object
))
4614 object
= code_convert_string (object
, coding_system
, Qnil
, 1, 0, 1);
4616 size
= SCHARS (object
);
4617 size_byte
= SBYTES (object
);
4621 CHECK_NUMBER (start
);
4623 start_char
= XINT (start
);
4628 start_byte
= string_char_to_byte (object
, start_char
);
4634 end_byte
= size_byte
;
4640 end_char
= XINT (end
);
4645 end_byte
= string_char_to_byte (object
, end_char
);
4648 if (!(0 <= start_char
&& start_char
<= end_char
&& end_char
<= size
))
4649 args_out_of_range_3 (object
, make_number (start_char
),
4650 make_number (end_char
));
4654 struct buffer
*prev
= current_buffer
;
4656 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
4658 CHECK_BUFFER (object
);
4660 bp
= XBUFFER (object
);
4661 if (bp
!= current_buffer
)
4662 set_buffer_internal (bp
);
4668 CHECK_NUMBER_COERCE_MARKER (start
);
4676 CHECK_NUMBER_COERCE_MARKER (end
);
4681 temp
= b
, b
= e
, e
= temp
;
4683 if (!(BEGV
<= b
&& e
<= ZV
))
4684 args_out_of_range (start
, end
);
4686 if (NILP (coding_system
))
4688 /* Decide the coding-system to encode the data with.
4689 See fileio.c:Fwrite-region */
4691 if (!NILP (Vcoding_system_for_write
))
4692 coding_system
= Vcoding_system_for_write
;
4695 int force_raw_text
= 0;
4697 coding_system
= XBUFFER (object
)->buffer_file_coding_system
;
4698 if (NILP (coding_system
)
4699 || NILP (Flocal_variable_p (Qbuffer_file_coding_system
, Qnil
)))
4701 coding_system
= Qnil
;
4702 if (NILP (current_buffer
->enable_multibyte_characters
))
4706 if (NILP (coding_system
) && !NILP (Fbuffer_file_name(object
)))
4708 /* Check file-coding-system-alist. */
4709 Lisp_Object args
[4], val
;
4711 args
[0] = Qwrite_region
; args
[1] = start
; args
[2] = end
;
4712 args
[3] = Fbuffer_file_name(object
);
4713 val
= Ffind_operation_coding_system (4, args
);
4714 if (CONSP (val
) && !NILP (XCDR (val
)))
4715 coding_system
= XCDR (val
);
4718 if (NILP (coding_system
)
4719 && !NILP (XBUFFER (object
)->buffer_file_coding_system
))
4721 /* If we still have not decided a coding system, use the
4722 default value of buffer-file-coding-system. */
4723 coding_system
= XBUFFER (object
)->buffer_file_coding_system
;
4727 && !NILP (Ffboundp (Vselect_safe_coding_system_function
)))
4728 /* Confirm that VAL can surely encode the current region. */
4729 coding_system
= call4 (Vselect_safe_coding_system_function
,
4730 make_number (b
), make_number (e
),
4731 coding_system
, Qnil
);
4734 coding_system
= Qraw_text
;
4737 if (NILP (Fcoding_system_p (coding_system
)))
4739 /* Invalid coding system. */
4741 if (!NILP (noerror
))
4742 coding_system
= Qraw_text
;
4744 xsignal1 (Qcoding_system_error
, coding_system
);
4748 object
= make_buffer_string (b
, e
, 0);
4749 if (prev
!= current_buffer
)
4750 set_buffer_internal (prev
);
4751 /* Discard the unwind protect for recovering the current
4755 if (STRING_MULTIBYTE (object
))
4756 object
= code_convert_string (object
, coding_system
, Qnil
, 1, 0, 0);
4759 md5_buffer (SDATA (object
) + start_byte
,
4760 SBYTES (object
) - (size_byte
- end_byte
),
4763 for (i
= 0; i
< 16; i
++)
4764 sprintf (&value
[2 * i
], "%02x", digest
[i
]);
4767 return make_string (value
, 32);
4774 /* Hash table stuff. */
4775 Qhash_table_p
= intern_c_string ("hash-table-p");
4776 staticpro (&Qhash_table_p
);
4777 Qeq
= intern_c_string ("eq");
4779 Qeql
= intern_c_string ("eql");
4781 Qequal
= intern_c_string ("equal");
4782 staticpro (&Qequal
);
4783 QCtest
= intern_c_string (":test");
4784 staticpro (&QCtest
);
4785 QCsize
= intern_c_string (":size");
4786 staticpro (&QCsize
);
4787 QCrehash_size
= intern_c_string (":rehash-size");
4788 staticpro (&QCrehash_size
);
4789 QCrehash_threshold
= intern_c_string (":rehash-threshold");
4790 staticpro (&QCrehash_threshold
);
4791 QCweakness
= intern_c_string (":weakness");
4792 staticpro (&QCweakness
);
4793 Qkey
= intern_c_string ("key");
4795 Qvalue
= intern_c_string ("value");
4796 staticpro (&Qvalue
);
4797 Qhash_table_test
= intern_c_string ("hash-table-test");
4798 staticpro (&Qhash_table_test
);
4799 Qkey_or_value
= intern_c_string ("key-or-value");
4800 staticpro (&Qkey_or_value
);
4801 Qkey_and_value
= intern_c_string ("key-and-value");
4802 staticpro (&Qkey_and_value
);
4805 defsubr (&Smake_hash_table
);
4806 defsubr (&Scopy_hash_table
);
4807 defsubr (&Shash_table_count
);
4808 defsubr (&Shash_table_rehash_size
);
4809 defsubr (&Shash_table_rehash_threshold
);
4810 defsubr (&Shash_table_size
);
4811 defsubr (&Shash_table_test
);
4812 defsubr (&Shash_table_weakness
);
4813 defsubr (&Shash_table_p
);
4814 defsubr (&Sclrhash
);
4815 defsubr (&Sgethash
);
4816 defsubr (&Sputhash
);
4817 defsubr (&Sremhash
);
4818 defsubr (&Smaphash
);
4819 defsubr (&Sdefine_hash_table_test
);
4821 Qstring_lessp
= intern_c_string ("string-lessp");
4822 staticpro (&Qstring_lessp
);
4823 Qprovide
= intern_c_string ("provide");
4824 staticpro (&Qprovide
);
4825 Qrequire
= intern_c_string ("require");
4826 staticpro (&Qrequire
);
4827 Qyes_or_no_p_history
= intern_c_string ("yes-or-no-p-history");
4828 staticpro (&Qyes_or_no_p_history
);
4829 Qcursor_in_echo_area
= intern_c_string ("cursor-in-echo-area");
4830 staticpro (&Qcursor_in_echo_area
);
4831 Qwidget_type
= intern_c_string ("widget-type");
4832 staticpro (&Qwidget_type
);
4834 staticpro (&string_char_byte_cache_string
);
4835 string_char_byte_cache_string
= Qnil
;
4837 require_nesting_list
= Qnil
;
4838 staticpro (&require_nesting_list
);
4840 Fset (Qyes_or_no_p_history
, Qnil
);
4842 DEFVAR_LISP ("features", &Vfeatures
,
4843 doc
: /* A list of symbols which are the features of the executing Emacs.
4844 Used by `featurep' and `require', and altered by `provide'. */);
4845 Vfeatures
= Fcons (intern_c_string ("emacs"), Qnil
);
4846 Qsubfeatures
= intern_c_string ("subfeatures");
4847 staticpro (&Qsubfeatures
);
4849 #ifdef HAVE_LANGINFO_CODESET
4850 Qcodeset
= intern_c_string ("codeset");
4851 staticpro (&Qcodeset
);
4852 Qdays
= intern_c_string ("days");
4854 Qmonths
= intern_c_string ("months");
4855 staticpro (&Qmonths
);
4856 Qpaper
= intern_c_string ("paper");
4857 staticpro (&Qpaper
);
4858 #endif /* HAVE_LANGINFO_CODESET */
4860 DEFVAR_BOOL ("use-dialog-box", &use_dialog_box
,
4861 doc
: /* *Non-nil means mouse commands use dialog boxes to ask questions.
4862 This applies to `y-or-n-p' and `yes-or-no-p' questions asked by commands
4863 invoked by mouse clicks and mouse menu items.
4865 On some platforms, file selection dialogs are also enabled if this is
4869 DEFVAR_BOOL ("use-file-dialog", &use_file_dialog
,
4870 doc
: /* *Non-nil means mouse commands use a file dialog to ask for files.
4871 This applies to commands from menus and tool bar buttons even when
4872 they are initiated from the keyboard. If `use-dialog-box' is nil,
4873 that disables the use of a file dialog, regardless of the value of
4875 use_file_dialog
= 1;
4877 defsubr (&Sidentity
);
4880 defsubr (&Ssafe_length
);
4881 defsubr (&Sstring_bytes
);
4882 defsubr (&Sstring_equal
);
4883 defsubr (&Scompare_strings
);
4884 defsubr (&Sstring_lessp
);
4887 defsubr (&Svconcat
);
4888 defsubr (&Scopy_sequence
);
4889 defsubr (&Sstring_make_multibyte
);
4890 defsubr (&Sstring_make_unibyte
);
4891 defsubr (&Sstring_as_multibyte
);
4892 defsubr (&Sstring_as_unibyte
);
4893 defsubr (&Sstring_to_multibyte
);
4894 defsubr (&Sstring_to_unibyte
);
4895 defsubr (&Scopy_alist
);
4896 defsubr (&Ssubstring
);
4897 defsubr (&Ssubstring_no_properties
);
4910 defsubr (&Snreverse
);
4911 defsubr (&Sreverse
);
4913 defsubr (&Splist_get
);
4915 defsubr (&Splist_put
);
4917 defsubr (&Slax_plist_get
);
4918 defsubr (&Slax_plist_put
);
4921 defsubr (&Sequal_including_properties
);
4922 defsubr (&Sfillarray
);
4923 defsubr (&Sclear_string
);
4927 defsubr (&Smapconcat
);
4928 defsubr (&Syes_or_no_p
);
4929 defsubr (&Sload_average
);
4930 defsubr (&Sfeaturep
);
4931 defsubr (&Srequire
);
4932 defsubr (&Sprovide
);
4933 defsubr (&Splist_member
);
4934 defsubr (&Swidget_put
);
4935 defsubr (&Swidget_get
);
4936 defsubr (&Swidget_apply
);
4937 defsubr (&Sbase64_encode_region
);
4938 defsubr (&Sbase64_decode_region
);
4939 defsubr (&Sbase64_encode_string
);
4940 defsubr (&Sbase64_decode_string
);
4942 defsubr (&Slocale_info
);
4951 /* arch-tag: 787f8219-5b74-46bd-8469-7e1cc475fa31
4952 (do not change this comment) */