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 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
31 /* On Mac OS, defining this conflicts with precompiled headers. */
33 /* Note on some machines this defines `vector' as a typedef,
34 so make sure we don't use that name in this file. */
38 #endif /* ! MAC_OSX */
47 #include "intervals.h"
50 #include "blockinput.h"
52 #if defined (HAVE_X_WINDOWS)
54 #elif defined (MAC_OS)
60 #define NULL ((POINTER_TYPE *)0)
63 /* Nonzero enables use of dialog boxes for questions
64 asked by mouse commands. */
67 /* Nonzero enables use of a file dialog for file name
68 questions asked by mouse commands. */
71 extern int minibuffer_auto_raise
;
72 extern Lisp_Object minibuf_window
;
73 extern Lisp_Object Vlocale_coding_system
;
74 extern int load_in_progress
;
76 Lisp_Object Qstring_lessp
, Qprovide
, Qrequire
;
77 Lisp_Object Qyes_or_no_p_history
;
78 Lisp_Object Qcursor_in_echo_area
;
79 Lisp_Object Qwidget_type
;
80 Lisp_Object Qcodeset
, Qdays
, Qmonths
, Qpaper
;
82 extern Lisp_Object Qinput_method_function
;
84 static int internal_equal
P_ ((Lisp_Object
, Lisp_Object
, int, int));
86 extern long get_random ();
87 extern void seed_random
P_ ((long));
93 DEFUN ("identity", Fidentity
, Sidentity
, 1, 1, 0,
94 doc
: /* Return the argument unchanged. */)
101 DEFUN ("random", Frandom
, Srandom
, 0, 1, 0,
102 doc
: /* Return a pseudo-random number.
103 All integers representable in Lisp are equally likely.
104 On most systems, this is 29 bits' worth.
105 With positive integer argument N, return random number in interval [0,N).
106 With argument t, set the random number seed from the current time and pid. */)
111 Lisp_Object lispy_val
;
112 unsigned long denominator
;
115 seed_random (getpid () + time (NULL
));
116 if (NATNUMP (n
) && XFASTINT (n
) != 0)
118 /* Try to take our random number from the higher bits of VAL,
119 not the lower, since (says Gentzel) the low bits of `random'
120 are less random than the higher ones. We do this by using the
121 quotient rather than the remainder. At the high end of the RNG
122 it's possible to get a quotient larger than n; discarding
123 these values eliminates the bias that would otherwise appear
124 when using a large n. */
125 denominator
= ((unsigned long)1 << VALBITS
) / XFASTINT (n
);
127 val
= get_random () / denominator
;
128 while (val
>= XFASTINT (n
));
132 XSETINT (lispy_val
, val
);
136 /* Random data-structure functions */
138 DEFUN ("length", Flength
, Slength
, 1, 1, 0,
139 doc
: /* Return the length of vector, list or string SEQUENCE.
140 A byte-code function object is also allowed.
141 If the string contains multibyte characters, this is not necessarily
142 the number of bytes in the string; it is the number of characters.
143 To get the number of bytes, use `string-bytes'. */)
145 register Lisp_Object sequence
;
147 register Lisp_Object val
;
150 if (STRINGP (sequence
))
151 XSETFASTINT (val
, SCHARS (sequence
));
152 else if (VECTORP (sequence
))
153 XSETFASTINT (val
, ASIZE (sequence
));
154 else if (SUB_CHAR_TABLE_P (sequence
))
155 XSETFASTINT (val
, SUB_CHAR_TABLE_ORDINARY_SLOTS
);
156 else if (CHAR_TABLE_P (sequence
))
157 XSETFASTINT (val
, MAX_CHAR
);
158 else if (BOOL_VECTOR_P (sequence
))
159 XSETFASTINT (val
, XBOOL_VECTOR (sequence
)->size
);
160 else if (COMPILEDP (sequence
))
161 XSETFASTINT (val
, ASIZE (sequence
) & PSEUDOVECTOR_SIZE_MASK
);
162 else if (CONSP (sequence
))
165 while (CONSP (sequence
))
167 sequence
= XCDR (sequence
);
170 if (!CONSP (sequence
))
173 sequence
= XCDR (sequence
);
178 CHECK_LIST_END (sequence
, sequence
);
180 val
= make_number (i
);
182 else if (NILP (sequence
))
183 XSETFASTINT (val
, 0);
185 wrong_type_argument (Qsequencep
, sequence
);
190 /* This does not check for quits. That is safe since it must terminate. */
192 DEFUN ("safe-length", Fsafe_length
, Ssafe_length
, 1, 1, 0,
193 doc
: /* Return the length of a list, but avoid error or infinite loop.
194 This function never gets an error. If LIST is not really a list,
195 it returns 0. If LIST is circular, it returns a finite value
196 which is at least the number of distinct elements. */)
200 Lisp_Object tail
, halftail
, length
;
203 /* halftail is used to detect circular lists. */
205 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
207 if (EQ (tail
, halftail
) && len
!= 0)
211 halftail
= XCDR (halftail
);
214 XSETINT (length
, len
);
218 DEFUN ("string-bytes", Fstring_bytes
, Sstring_bytes
, 1, 1, 0,
219 doc
: /* Return the number of bytes in STRING.
220 If STRING is a multibyte string, this is greater than the length of STRING. */)
224 CHECK_STRING (string
);
225 return make_number (SBYTES (string
));
228 DEFUN ("string-equal", Fstring_equal
, Sstring_equal
, 2, 2, 0,
229 doc
: /* Return t if two strings have identical contents.
230 Case is significant, but text properties are ignored.
231 Symbols are also allowed; their print names are used instead. */)
233 register Lisp_Object s1
, s2
;
236 s1
= SYMBOL_NAME (s1
);
238 s2
= SYMBOL_NAME (s2
);
242 if (SCHARS (s1
) != SCHARS (s2
)
243 || SBYTES (s1
) != SBYTES (s2
)
244 || bcmp (SDATA (s1
), SDATA (s2
), SBYTES (s1
)))
249 DEFUN ("compare-strings", Fcompare_strings
,
250 Scompare_strings
, 6, 7, 0,
251 doc
: /* Compare the contents of two strings, converting to multibyte if needed.
252 In string STR1, skip the first START1 characters and stop at END1.
253 In string STR2, skip the first START2 characters and stop at END2.
254 END1 and END2 default to the full lengths of the respective strings.
256 Case is significant in this comparison if IGNORE-CASE is nil.
257 Unibyte strings are converted to multibyte for comparison.
259 The value is t if the strings (or specified portions) match.
260 If string STR1 is less, the value is a negative number N;
261 - 1 - N is the number of characters that match at the beginning.
262 If string STR1 is greater, the value is a positive number N;
263 N - 1 is the number of characters that match at the beginning. */)
264 (str1
, start1
, end1
, str2
, start2
, end2
, ignore_case
)
265 Lisp_Object str1
, start1
, end1
, start2
, str2
, end2
, ignore_case
;
267 register int end1_char
, end2_char
;
268 register int i1
, i1_byte
, i2
, i2_byte
;
273 start1
= make_number (0);
275 start2
= make_number (0);
276 CHECK_NATNUM (start1
);
277 CHECK_NATNUM (start2
);
286 i1_byte
= string_char_to_byte (str1
, i1
);
287 i2_byte
= string_char_to_byte (str2
, i2
);
289 end1_char
= SCHARS (str1
);
290 if (! NILP (end1
) && end1_char
> XINT (end1
))
291 end1_char
= XINT (end1
);
293 end2_char
= SCHARS (str2
);
294 if (! NILP (end2
) && end2_char
> XINT (end2
))
295 end2_char
= XINT (end2
);
297 while (i1
< end1_char
&& i2
< end2_char
)
299 /* When we find a mismatch, we must compare the
300 characters, not just the bytes. */
303 if (STRING_MULTIBYTE (str1
))
304 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c1
, str1
, i1
, i1_byte
);
307 c1
= SREF (str1
, i1
++);
308 c1
= unibyte_char_to_multibyte (c1
);
311 if (STRING_MULTIBYTE (str2
))
312 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c2
, str2
, i2
, i2_byte
);
315 c2
= SREF (str2
, i2
++);
316 c2
= unibyte_char_to_multibyte (c2
);
322 if (! NILP (ignore_case
))
326 tem
= Fupcase (make_number (c1
));
328 tem
= Fupcase (make_number (c2
));
335 /* Note that I1 has already been incremented
336 past the character that we are comparing;
337 hence we don't add or subtract 1 here. */
339 return make_number (- i1
+ XINT (start1
));
341 return make_number (i1
- XINT (start1
));
345 return make_number (i1
- XINT (start1
) + 1);
347 return make_number (- i1
+ XINT (start1
) - 1);
352 DEFUN ("string-lessp", Fstring_lessp
, Sstring_lessp
, 2, 2, 0,
353 doc
: /* Return t if first arg string is less than second in lexicographic order.
355 Symbols are also allowed; their print names are used instead. */)
357 register Lisp_Object s1
, s2
;
360 register int i1
, i1_byte
, i2
, i2_byte
;
363 s1
= SYMBOL_NAME (s1
);
365 s2
= SYMBOL_NAME (s2
);
369 i1
= i1_byte
= i2
= i2_byte
= 0;
372 if (end
> SCHARS (s2
))
377 /* When we find a mismatch, we must compare the
378 characters, not just the bytes. */
381 FETCH_STRING_CHAR_ADVANCE (c1
, s1
, i1
, i1_byte
);
382 FETCH_STRING_CHAR_ADVANCE (c2
, s2
, i2
, i2_byte
);
385 return c1
< c2
? Qt
: Qnil
;
387 return i1
< SCHARS (s2
) ? Qt
: Qnil
;
391 /* "gcc -O3" enables automatic function inlining, which optimizes out
392 the arguments for the invocations of this function, whereas it
393 expects these values on the stack. */
394 static Lisp_Object concat
P_ ((int nargs
, Lisp_Object
*args
, enum Lisp_Type target_type
, int last_special
)) __attribute__((noinline
));
395 #else /* !__GNUC__ */
396 static Lisp_Object concat
P_ ((int nargs
, Lisp_Object
*args
, enum Lisp_Type target_type
, int last_special
));
408 return concat (2, args
, Lisp_String
, 0);
410 return concat (2, &s1
, Lisp_String
, 0);
411 #endif /* NO_ARG_ARRAY */
417 Lisp_Object s1
, s2
, s3
;
424 return concat (3, args
, Lisp_String
, 0);
426 return concat (3, &s1
, Lisp_String
, 0);
427 #endif /* NO_ARG_ARRAY */
430 DEFUN ("append", Fappend
, Sappend
, 0, MANY
, 0,
431 doc
: /* Concatenate all the arguments and make the result a list.
432 The result is a list whose elements are the elements of all the arguments.
433 Each argument may be a list, vector or string.
434 The last argument is not copied, just used as the tail of the new list.
435 usage: (append &rest SEQUENCES) */)
440 return concat (nargs
, args
, Lisp_Cons
, 1);
443 DEFUN ("concat", Fconcat
, Sconcat
, 0, MANY
, 0,
444 doc
: /* Concatenate all the arguments and make the result a string.
445 The result is a string whose elements are the elements of all the arguments.
446 Each argument may be a string or a list or vector of characters (integers).
447 usage: (concat &rest SEQUENCES) */)
452 return concat (nargs
, args
, Lisp_String
, 0);
455 DEFUN ("vconcat", Fvconcat
, Svconcat
, 0, MANY
, 0,
456 doc
: /* Concatenate all the arguments and make the result a vector.
457 The result is a vector whose elements are the elements of all the arguments.
458 Each argument may be a list, vector or string.
459 usage: (vconcat &rest SEQUENCES) */)
464 return concat (nargs
, args
, Lisp_Vectorlike
, 0);
467 /* Return a copy of a sub char table ARG. The elements except for a
468 nested sub char table are not copied. */
470 copy_sub_char_table (arg
)
473 Lisp_Object copy
= make_sub_char_table (Qnil
);
476 XCHAR_TABLE (copy
)->defalt
= XCHAR_TABLE (arg
)->defalt
;
477 /* Copy all the contents. */
478 bcopy (XCHAR_TABLE (arg
)->contents
, XCHAR_TABLE (copy
)->contents
,
479 SUB_CHAR_TABLE_ORDINARY_SLOTS
* sizeof (Lisp_Object
));
480 /* Recursively copy any sub char-tables in the ordinary slots. */
481 for (i
= 32; i
< SUB_CHAR_TABLE_ORDINARY_SLOTS
; i
++)
482 if (SUB_CHAR_TABLE_P (XCHAR_TABLE (arg
)->contents
[i
]))
483 XCHAR_TABLE (copy
)->contents
[i
]
484 = copy_sub_char_table (XCHAR_TABLE (copy
)->contents
[i
]);
490 DEFUN ("copy-sequence", Fcopy_sequence
, Scopy_sequence
, 1, 1, 0,
491 doc
: /* Return a copy of a list, vector, string or char-table.
492 The elements of a list or vector are not copied; they are shared
493 with the original. */)
497 if (NILP (arg
)) return arg
;
499 if (CHAR_TABLE_P (arg
))
504 copy
= Fmake_char_table (XCHAR_TABLE (arg
)->purpose
, Qnil
);
505 /* Copy all the slots, including the extra ones. */
506 bcopy (XVECTOR (arg
)->contents
, XVECTOR (copy
)->contents
,
507 ((XCHAR_TABLE (arg
)->size
& PSEUDOVECTOR_SIZE_MASK
)
508 * sizeof (Lisp_Object
)));
510 /* Recursively copy any sub char tables in the ordinary slots
511 for multibyte characters. */
512 for (i
= CHAR_TABLE_SINGLE_BYTE_SLOTS
;
513 i
< CHAR_TABLE_ORDINARY_SLOTS
; i
++)
514 if (SUB_CHAR_TABLE_P (XCHAR_TABLE (arg
)->contents
[i
]))
515 XCHAR_TABLE (copy
)->contents
[i
]
516 = copy_sub_char_table (XCHAR_TABLE (copy
)->contents
[i
]);
521 if (BOOL_VECTOR_P (arg
))
525 = ((XBOOL_VECTOR (arg
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
526 / BOOL_VECTOR_BITS_PER_CHAR
);
528 val
= Fmake_bool_vector (Flength (arg
), Qnil
);
529 bcopy (XBOOL_VECTOR (arg
)->data
, XBOOL_VECTOR (val
)->data
,
534 if (!CONSP (arg
) && !VECTORP (arg
) && !STRINGP (arg
))
535 wrong_type_argument (Qsequencep
, arg
);
537 return concat (1, &arg
, CONSP (arg
) ? Lisp_Cons
: XTYPE (arg
), 0);
540 /* This structure holds information of an argument of `concat' that is
541 a string and has text properties to be copied. */
544 int argnum
; /* refer to ARGS (arguments of `concat') */
545 int from
; /* refer to ARGS[argnum] (argument string) */
546 int to
; /* refer to VAL (the target string) */
550 concat (nargs
, args
, target_type
, last_special
)
553 enum Lisp_Type target_type
;
557 register Lisp_Object tail
;
558 register Lisp_Object
this;
560 int toindex_byte
= 0;
561 register int result_len
;
562 register int result_len_byte
;
564 Lisp_Object last_tail
;
567 /* When we make a multibyte string, we can't copy text properties
568 while concatinating each string because the length of resulting
569 string can't be decided until we finish the whole concatination.
570 So, we record strings that have text properties to be copied
571 here, and copy the text properties after the concatination. */
572 struct textprop_rec
*textprops
= NULL
;
573 /* Number of elments in textprops. */
574 int num_textprops
= 0;
579 /* In append, the last arg isn't treated like the others */
580 if (last_special
&& nargs
> 0)
583 last_tail
= args
[nargs
];
588 /* Check each argument. */
589 for (argnum
= 0; argnum
< nargs
; argnum
++)
592 if (!(CONSP (this) || NILP (this) || VECTORP (this) || STRINGP (this)
593 || COMPILEDP (this) || BOOL_VECTOR_P (this)))
594 wrong_type_argument (Qsequencep
, this);
597 /* Compute total length in chars of arguments in RESULT_LEN.
598 If desired output is a string, also compute length in bytes
599 in RESULT_LEN_BYTE, and determine in SOME_MULTIBYTE
600 whether the result should be a multibyte string. */
604 for (argnum
= 0; argnum
< nargs
; argnum
++)
608 len
= XFASTINT (Flength (this));
609 if (target_type
== Lisp_String
)
611 /* We must count the number of bytes needed in the string
612 as well as the number of characters. */
618 for (i
= 0; i
< len
; i
++)
622 this_len_byte
= CHAR_BYTES (XINT (ch
));
623 result_len_byte
+= this_len_byte
;
624 if (!SINGLE_BYTE_CHAR_P (XINT (ch
)))
627 else if (BOOL_VECTOR_P (this) && XBOOL_VECTOR (this)->size
> 0)
628 wrong_type_argument (Qintegerp
, Faref (this, make_number (0)));
629 else if (CONSP (this))
630 for (; CONSP (this); this = XCDR (this))
634 this_len_byte
= CHAR_BYTES (XINT (ch
));
635 result_len_byte
+= this_len_byte
;
636 if (!SINGLE_BYTE_CHAR_P (XINT (ch
)))
639 else if (STRINGP (this))
641 if (STRING_MULTIBYTE (this))
644 result_len_byte
+= SBYTES (this);
647 result_len_byte
+= count_size_as_multibyte (SDATA (this),
655 if (! some_multibyte
)
656 result_len_byte
= result_len
;
658 /* Create the output object. */
659 if (target_type
== Lisp_Cons
)
660 val
= Fmake_list (make_number (result_len
), Qnil
);
661 else if (target_type
== Lisp_Vectorlike
)
662 val
= Fmake_vector (make_number (result_len
), Qnil
);
663 else if (some_multibyte
)
664 val
= make_uninit_multibyte_string (result_len
, result_len_byte
);
666 val
= make_uninit_string (result_len
);
668 /* In `append', if all but last arg are nil, return last arg. */
669 if (target_type
== Lisp_Cons
&& EQ (val
, Qnil
))
672 /* Copy the contents of the args into the result. */
674 tail
= val
, toindex
= -1; /* -1 in toindex is flag we are making a list */
676 toindex
= 0, toindex_byte
= 0;
680 SAFE_ALLOCA (textprops
, struct textprop_rec
*, sizeof (struct textprop_rec
) * nargs
);
682 for (argnum
= 0; argnum
< nargs
; argnum
++)
686 register unsigned int thisindex
= 0;
687 register unsigned int thisindex_byte
= 0;
691 thislen
= Flength (this), thisleni
= XINT (thislen
);
693 /* Between strings of the same kind, copy fast. */
694 if (STRINGP (this) && STRINGP (val
)
695 && STRING_MULTIBYTE (this) == some_multibyte
)
697 int thislen_byte
= SBYTES (this);
699 bcopy (SDATA (this), SDATA (val
) + toindex_byte
,
701 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
703 textprops
[num_textprops
].argnum
= argnum
;
704 textprops
[num_textprops
].from
= 0;
705 textprops
[num_textprops
++].to
= toindex
;
707 toindex_byte
+= thislen_byte
;
709 STRING_SET_CHARS (val
, SCHARS (val
));
711 /* Copy a single-byte string to a multibyte string. */
712 else if (STRINGP (this) && STRINGP (val
))
714 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
716 textprops
[num_textprops
].argnum
= argnum
;
717 textprops
[num_textprops
].from
= 0;
718 textprops
[num_textprops
++].to
= toindex
;
720 toindex_byte
+= copy_text (SDATA (this),
721 SDATA (val
) + toindex_byte
,
722 SCHARS (this), 0, 1);
726 /* Copy element by element. */
729 register Lisp_Object elt
;
731 /* Fetch next element of `this' arg into `elt', or break if
732 `this' is exhausted. */
733 if (NILP (this)) break;
735 elt
= XCAR (this), this = XCDR (this);
736 else if (thisindex
>= thisleni
)
738 else if (STRINGP (this))
741 if (STRING_MULTIBYTE (this))
743 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, this,
746 XSETFASTINT (elt
, c
);
750 XSETFASTINT (elt
, SREF (this, thisindex
)); thisindex
++;
752 && (XINT (elt
) >= 0240
753 || (XINT (elt
) >= 0200
754 && ! NILP (Vnonascii_translation_table
)))
755 && XINT (elt
) < 0400)
757 c
= unibyte_char_to_multibyte (XINT (elt
));
762 else if (BOOL_VECTOR_P (this))
765 byte
= XBOOL_VECTOR (this)->data
[thisindex
/ BOOL_VECTOR_BITS_PER_CHAR
];
766 if (byte
& (1 << (thisindex
% BOOL_VECTOR_BITS_PER_CHAR
)))
773 elt
= AREF (this, thisindex
++);
775 /* Store this element into the result. */
782 else if (VECTORP (val
))
783 AREF (val
, toindex
++) = elt
;
787 if (SINGLE_BYTE_CHAR_P (XINT (elt
)))
791 += CHAR_STRING (XINT (elt
),
792 SDATA (val
) + toindex_byte
);
794 SSET (val
, toindex_byte
++, XINT (elt
));
798 /* If we have any multibyte characters,
799 we already decided to make a multibyte string. */
802 /* P exists as a variable
803 to avoid a bug on the Masscomp C compiler. */
804 unsigned char *p
= SDATA (val
) + toindex_byte
;
806 toindex_byte
+= CHAR_STRING (c
, p
);
813 XSETCDR (prev
, last_tail
);
815 if (num_textprops
> 0)
818 int last_to_end
= -1;
820 for (argnum
= 0; argnum
< num_textprops
; argnum
++)
822 this = args
[textprops
[argnum
].argnum
];
823 props
= text_property_list (this,
825 make_number (SCHARS (this)),
827 /* If successive arguments have properites, be sure that the
828 value of `composition' property be the copy. */
829 if (last_to_end
== textprops
[argnum
].to
)
830 make_composition_value_copy (props
);
831 add_text_properties_from_list (val
, props
,
832 make_number (textprops
[argnum
].to
));
833 last_to_end
= textprops
[argnum
].to
+ SCHARS (this);
841 static Lisp_Object string_char_byte_cache_string
;
842 static int string_char_byte_cache_charpos
;
843 static int string_char_byte_cache_bytepos
;
846 clear_string_char_byte_cache ()
848 string_char_byte_cache_string
= Qnil
;
851 /* Return the character index corresponding to CHAR_INDEX in STRING. */
854 string_char_to_byte (string
, char_index
)
859 int best_below
, best_below_byte
;
860 int best_above
, best_above_byte
;
862 best_below
= best_below_byte
= 0;
863 best_above
= SCHARS (string
);
864 best_above_byte
= SBYTES (string
);
865 if (best_above
== best_above_byte
)
868 if (EQ (string
, string_char_byte_cache_string
))
870 if (string_char_byte_cache_charpos
< char_index
)
872 best_below
= string_char_byte_cache_charpos
;
873 best_below_byte
= string_char_byte_cache_bytepos
;
877 best_above
= string_char_byte_cache_charpos
;
878 best_above_byte
= string_char_byte_cache_bytepos
;
882 if (char_index
- best_below
< best_above
- char_index
)
884 while (best_below
< char_index
)
887 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, string
,
888 best_below
, best_below_byte
);
891 i_byte
= best_below_byte
;
895 while (best_above
> char_index
)
897 unsigned char *pend
= SDATA (string
) + best_above_byte
;
898 unsigned char *pbeg
= pend
- best_above_byte
;
899 unsigned char *p
= pend
- 1;
902 while (p
> pbeg
&& !CHAR_HEAD_P (*p
)) p
--;
903 PARSE_MULTIBYTE_SEQ (p
, pend
- p
, bytes
);
904 if (bytes
== pend
- p
)
905 best_above_byte
-= bytes
;
906 else if (bytes
> pend
- p
)
907 best_above_byte
-= (pend
- p
);
913 i_byte
= best_above_byte
;
916 string_char_byte_cache_bytepos
= i_byte
;
917 string_char_byte_cache_charpos
= i
;
918 string_char_byte_cache_string
= string
;
923 /* Return the character index corresponding to BYTE_INDEX in STRING. */
926 string_byte_to_char (string
, byte_index
)
931 int best_below
, best_below_byte
;
932 int best_above
, best_above_byte
;
934 best_below
= best_below_byte
= 0;
935 best_above
= SCHARS (string
);
936 best_above_byte
= SBYTES (string
);
937 if (best_above
== best_above_byte
)
940 if (EQ (string
, string_char_byte_cache_string
))
942 if (string_char_byte_cache_bytepos
< byte_index
)
944 best_below
= string_char_byte_cache_charpos
;
945 best_below_byte
= string_char_byte_cache_bytepos
;
949 best_above
= string_char_byte_cache_charpos
;
950 best_above_byte
= string_char_byte_cache_bytepos
;
954 if (byte_index
- best_below_byte
< best_above_byte
- byte_index
)
956 while (best_below_byte
< byte_index
)
959 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, string
,
960 best_below
, best_below_byte
);
963 i_byte
= best_below_byte
;
967 while (best_above_byte
> byte_index
)
969 unsigned char *pend
= SDATA (string
) + best_above_byte
;
970 unsigned char *pbeg
= pend
- best_above_byte
;
971 unsigned char *p
= pend
- 1;
974 while (p
> pbeg
&& !CHAR_HEAD_P (*p
)) p
--;
975 PARSE_MULTIBYTE_SEQ (p
, pend
- p
, bytes
);
976 if (bytes
== pend
- p
)
977 best_above_byte
-= bytes
;
978 else if (bytes
> pend
- p
)
979 best_above_byte
-= (pend
- p
);
985 i_byte
= best_above_byte
;
988 string_char_byte_cache_bytepos
= i_byte
;
989 string_char_byte_cache_charpos
= i
;
990 string_char_byte_cache_string
= string
;
995 /* Convert STRING to a multibyte string.
996 Single-byte characters 0240 through 0377 are converted
997 by adding nonascii_insert_offset to each. */
1000 string_make_multibyte (string
)
1008 if (STRING_MULTIBYTE (string
))
1011 nbytes
= count_size_as_multibyte (SDATA (string
),
1013 /* If all the chars are ASCII, they won't need any more bytes
1014 once converted. In that case, we can return STRING itself. */
1015 if (nbytes
== SBYTES (string
))
1018 SAFE_ALLOCA (buf
, unsigned char *, nbytes
);
1019 copy_text (SDATA (string
), buf
, SBYTES (string
),
1022 ret
= make_multibyte_string (buf
, SCHARS (string
), nbytes
);
1029 /* Convert STRING to a multibyte string without changing each
1030 character codes. Thus, characters 0200 trough 0237 are converted
1031 to eight-bit-control characters, and characters 0240 through 0377
1032 are converted eight-bit-graphic characters. */
1035 string_to_multibyte (string
)
1043 if (STRING_MULTIBYTE (string
))
1046 nbytes
= parse_str_to_multibyte (SDATA (string
), SBYTES (string
));
1047 /* If all the chars are ASCII or eight-bit-graphic, they won't need
1048 any more bytes once converted. */
1049 if (nbytes
== SBYTES (string
))
1050 return make_multibyte_string (SDATA (string
), nbytes
, nbytes
);
1052 SAFE_ALLOCA (buf
, unsigned char *, nbytes
);
1053 bcopy (SDATA (string
), buf
, SBYTES (string
));
1054 str_to_multibyte (buf
, nbytes
, SBYTES (string
));
1056 ret
= make_multibyte_string (buf
, SCHARS (string
), nbytes
);
1063 /* Convert STRING to a single-byte string. */
1066 string_make_unibyte (string
)
1074 if (! STRING_MULTIBYTE (string
))
1077 nchars
= SCHARS (string
);
1079 SAFE_ALLOCA (buf
, unsigned char *, nchars
);
1080 copy_text (SDATA (string
), buf
, SBYTES (string
),
1083 ret
= make_unibyte_string (buf
, nchars
);
1089 DEFUN ("string-make-multibyte", Fstring_make_multibyte
, Sstring_make_multibyte
,
1091 doc
: /* Return the multibyte equivalent of STRING.
1092 If STRING is unibyte and contains non-ASCII characters, the function
1093 `unibyte-char-to-multibyte' is used to convert each unibyte character
1094 to a multibyte character. In this case, the returned string is a
1095 newly created string with no text properties. If STRING is multibyte
1096 or entirely ASCII, it is returned unchanged. In particular, when
1097 STRING is unibyte and entirely ASCII, the returned string is unibyte.
1098 \(When the characters are all ASCII, Emacs primitives will treat the
1099 string the same way whether it is unibyte or multibyte.) */)
1103 CHECK_STRING (string
);
1105 return string_make_multibyte (string
);
1108 DEFUN ("string-make-unibyte", Fstring_make_unibyte
, Sstring_make_unibyte
,
1110 doc
: /* Return the unibyte equivalent of STRING.
1111 Multibyte character codes are converted to unibyte according to
1112 `nonascii-translation-table' or, if that is nil, `nonascii-insert-offset'.
1113 If the lookup in the translation table fails, this function takes just
1114 the low 8 bits of each character. */)
1118 CHECK_STRING (string
);
1120 return string_make_unibyte (string
);
1123 DEFUN ("string-as-unibyte", Fstring_as_unibyte
, Sstring_as_unibyte
,
1125 doc
: /* Return a unibyte string with the same individual bytes as STRING.
1126 If STRING is unibyte, the result is STRING itself.
1127 Otherwise it is a newly created string, with no text properties.
1128 If STRING is multibyte and contains a character of charset
1129 `eight-bit-control' or `eight-bit-graphic', it is converted to the
1130 corresponding single byte. */)
1134 CHECK_STRING (string
);
1136 if (STRING_MULTIBYTE (string
))
1138 int bytes
= SBYTES (string
);
1139 unsigned char *str
= (unsigned char *) xmalloc (bytes
);
1141 bcopy (SDATA (string
), str
, bytes
);
1142 bytes
= str_as_unibyte (str
, bytes
);
1143 string
= make_unibyte_string (str
, bytes
);
1149 DEFUN ("string-as-multibyte", Fstring_as_multibyte
, Sstring_as_multibyte
,
1151 doc
: /* Return a multibyte string with the same individual bytes as STRING.
1152 If STRING is multibyte, the result is STRING itself.
1153 Otherwise it is a newly created string, with no text properties.
1154 If STRING is unibyte and contains an individual 8-bit byte (i.e. not
1155 part of a multibyte form), it is converted to the corresponding
1156 multibyte character of charset `eight-bit-control' or `eight-bit-graphic'.
1157 Beware, this often doesn't really do what you think it does.
1158 It is similar to (decode-coding-string STRING 'emacs-mule-unix).
1159 If you're not sure, whether to use `string-as-multibyte' or
1160 `string-to-multibyte', use `string-to-multibyte'. Beware:
1161 (aref (string-as-multibyte "\\201") 0) -> 129 (aka ?\\201)
1162 (aref (string-as-multibyte "\\300") 0) -> 192 (aka ?\\300)
1163 (aref (string-as-multibyte "\\300\\201") 0) -> 192 (aka ?\\300)
1164 (aref (string-as-multibyte "\\300\\201") 1) -> 129 (aka ?\\201)
1166 (aref (string-as-multibyte "\\201\\300") 0) -> 2240
1167 (aref (string-as-multibyte "\\201\\300") 1) -> <error> */)
1171 CHECK_STRING (string
);
1173 if (! STRING_MULTIBYTE (string
))
1175 Lisp_Object new_string
;
1178 parse_str_as_multibyte (SDATA (string
),
1181 new_string
= make_uninit_multibyte_string (nchars
, nbytes
);
1182 bcopy (SDATA (string
), SDATA (new_string
),
1184 if (nbytes
!= SBYTES (string
))
1185 str_as_multibyte (SDATA (new_string
), nbytes
,
1186 SBYTES (string
), NULL
);
1187 string
= new_string
;
1188 STRING_SET_INTERVALS (string
, NULL_INTERVAL
);
1193 DEFUN ("string-to-multibyte", Fstring_to_multibyte
, Sstring_to_multibyte
,
1195 doc
: /* Return a multibyte string with the same individual chars as STRING.
1196 If STRING is multibyte, the result is STRING itself.
1197 Otherwise it is a newly created string, with no text properties.
1198 Characters 0200 through 0237 are converted to eight-bit-control
1199 characters of the same character code. Characters 0240 through 0377
1200 are converted to eight-bit-graphic characters of the same character
1202 This is similar to (decode-coding-string STRING 'binary) */)
1206 CHECK_STRING (string
);
1208 return string_to_multibyte (string
);
1212 DEFUN ("copy-alist", Fcopy_alist
, Scopy_alist
, 1, 1, 0,
1213 doc
: /* Return a copy of ALIST.
1214 This is an alist which represents the same mapping from objects to objects,
1215 but does not share the alist structure with ALIST.
1216 The objects mapped (cars and cdrs of elements of the alist)
1217 are shared, however.
1218 Elements of ALIST that are not conses are also shared. */)
1222 register Lisp_Object tem
;
1227 alist
= concat (1, &alist
, Lisp_Cons
, 0);
1228 for (tem
= alist
; CONSP (tem
); tem
= XCDR (tem
))
1230 register Lisp_Object car
;
1234 XSETCAR (tem
, Fcons (XCAR (car
), XCDR (car
)));
1239 DEFUN ("substring", Fsubstring
, Ssubstring
, 2, 3, 0,
1240 doc
: /* Return a substring of STRING, starting at index FROM and ending before TO.
1241 TO may be nil or omitted; then the substring runs to the end of STRING.
1242 FROM and TO start at 0. If either is negative, it counts from the end.
1244 This function allows vectors as well as strings. */)
1247 register Lisp_Object from
, to
;
1252 int from_char
, to_char
;
1253 int from_byte
= 0, to_byte
= 0;
1255 CHECK_VECTOR_OR_STRING (string
);
1256 CHECK_NUMBER (from
);
1258 if (STRINGP (string
))
1260 size
= SCHARS (string
);
1261 size_byte
= SBYTES (string
);
1264 size
= ASIZE (string
);
1269 to_byte
= size_byte
;
1275 to_char
= XINT (to
);
1279 if (STRINGP (string
))
1280 to_byte
= string_char_to_byte (string
, to_char
);
1283 from_char
= XINT (from
);
1286 if (STRINGP (string
))
1287 from_byte
= string_char_to_byte (string
, from_char
);
1289 if (!(0 <= from_char
&& from_char
<= to_char
&& to_char
<= size
))
1290 args_out_of_range_3 (string
, make_number (from_char
),
1291 make_number (to_char
));
1293 if (STRINGP (string
))
1295 res
= make_specified_string (SDATA (string
) + from_byte
,
1296 to_char
- from_char
, to_byte
- from_byte
,
1297 STRING_MULTIBYTE (string
));
1298 copy_text_properties (make_number (from_char
), make_number (to_char
),
1299 string
, make_number (0), res
, Qnil
);
1302 res
= Fvector (to_char
- from_char
, &AREF (string
, from_char
));
1308 DEFUN ("substring-no-properties", Fsubstring_no_properties
, Ssubstring_no_properties
, 1, 3, 0,
1309 doc
: /* Return a substring of STRING, without text properties.
1310 It starts at index FROM and ending before TO.
1311 TO may be nil or omitted; then the substring runs to the end of STRING.
1312 If FROM is nil or omitted, the substring starts at the beginning of STRING.
1313 If FROM or TO is negative, it counts from the end.
1315 With one argument, just copy STRING without its properties. */)
1318 register Lisp_Object from
, to
;
1320 int size
, size_byte
;
1321 int from_char
, to_char
;
1322 int from_byte
, to_byte
;
1324 CHECK_STRING (string
);
1326 size
= SCHARS (string
);
1327 size_byte
= SBYTES (string
);
1330 from_char
= from_byte
= 0;
1333 CHECK_NUMBER (from
);
1334 from_char
= XINT (from
);
1338 from_byte
= string_char_to_byte (string
, from_char
);
1344 to_byte
= size_byte
;
1350 to_char
= XINT (to
);
1354 to_byte
= string_char_to_byte (string
, to_char
);
1357 if (!(0 <= from_char
&& from_char
<= to_char
&& to_char
<= size
))
1358 args_out_of_range_3 (string
, make_number (from_char
),
1359 make_number (to_char
));
1361 return make_specified_string (SDATA (string
) + from_byte
,
1362 to_char
- from_char
, to_byte
- from_byte
,
1363 STRING_MULTIBYTE (string
));
1366 /* Extract a substring of STRING, giving start and end positions
1367 both in characters and in bytes. */
1370 substring_both (string
, from
, from_byte
, to
, to_byte
)
1372 int from
, from_byte
, to
, to_byte
;
1378 CHECK_VECTOR_OR_STRING (string
);
1380 if (STRINGP (string
))
1382 size
= SCHARS (string
);
1383 size_byte
= SBYTES (string
);
1386 size
= ASIZE (string
);
1388 if (!(0 <= from
&& from
<= to
&& to
<= size
))
1389 args_out_of_range_3 (string
, make_number (from
), make_number (to
));
1391 if (STRINGP (string
))
1393 res
= make_specified_string (SDATA (string
) + from_byte
,
1394 to
- from
, to_byte
- from_byte
,
1395 STRING_MULTIBYTE (string
));
1396 copy_text_properties (make_number (from
), make_number (to
),
1397 string
, make_number (0), res
, Qnil
);
1400 res
= Fvector (to
- from
, &AREF (string
, from
));
1405 DEFUN ("nthcdr", Fnthcdr
, Snthcdr
, 2, 2, 0,
1406 doc
: /* Take cdr N times on LIST, returns the result. */)
1409 register Lisp_Object list
;
1411 register int i
, num
;
1414 for (i
= 0; i
< num
&& !NILP (list
); i
++)
1417 CHECK_LIST_CONS (list
, list
);
1423 DEFUN ("nth", Fnth
, Snth
, 2, 2, 0,
1424 doc
: /* Return the Nth element of LIST.
1425 N counts from zero. If LIST is not that long, nil is returned. */)
1427 Lisp_Object n
, list
;
1429 return Fcar (Fnthcdr (n
, list
));
1432 DEFUN ("elt", Felt
, Selt
, 2, 2, 0,
1433 doc
: /* Return element of SEQUENCE at index N. */)
1435 register Lisp_Object sequence
, n
;
1438 if (CONSP (sequence
) || NILP (sequence
))
1439 return Fcar (Fnthcdr (n
, sequence
));
1441 /* Faref signals a "not array" error, so check here. */
1442 CHECK_ARRAY (sequence
, Qsequencep
);
1443 return Faref (sequence
, n
);
1446 DEFUN ("member", Fmember
, Smember
, 2, 2, 0,
1447 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `equal'.
1448 The value is actually the tail of LIST whose car is ELT. */)
1450 register Lisp_Object elt
;
1453 register Lisp_Object tail
;
1454 for (tail
= list
; !NILP (tail
); tail
= XCDR (tail
))
1456 register Lisp_Object tem
;
1457 CHECK_LIST_CONS (tail
, list
);
1459 if (! NILP (Fequal (elt
, tem
)))
1466 DEFUN ("memq", Fmemq
, Smemq
, 2, 2, 0,
1467 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `eq'.
1468 The value is actually the tail of LIST whose car is ELT. */)
1470 register Lisp_Object elt
, list
;
1474 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1478 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1482 if (!CONSP (list
) || EQ (XCAR (list
), elt
))
1493 DEFUN ("memql", Fmemql
, Smemql
, 2, 2, 0,
1494 doc
: /* Return non-nil if ELT is an element of LIST. Comparison done with `eql'.
1495 The value is actually the tail of LIST whose car is ELT. */)
1497 register Lisp_Object elt
;
1500 register Lisp_Object tail
;
1503 return Fmemq (elt
, list
);
1505 for (tail
= list
; !NILP (tail
); tail
= XCDR (tail
))
1507 register Lisp_Object tem
;
1508 CHECK_LIST_CONS (tail
, list
);
1510 if (FLOATP (tem
) && internal_equal (elt
, tem
, 0, 0))
1517 DEFUN ("assq", Fassq
, Sassq
, 2, 2, 0,
1518 doc
: /* Return non-nil if KEY is `eq' to the car of an element of LIST.
1519 The value is actually the first element of LIST whose car is KEY.
1520 Elements of LIST that are not conses are ignored. */)
1522 Lisp_Object key
, list
;
1527 || (CONSP (XCAR (list
))
1528 && EQ (XCAR (XCAR (list
)), key
)))
1533 || (CONSP (XCAR (list
))
1534 && EQ (XCAR (XCAR (list
)), key
)))
1539 || (CONSP (XCAR (list
))
1540 && EQ (XCAR (XCAR (list
)), key
)))
1550 /* Like Fassq but never report an error and do not allow quits.
1551 Use only on lists known never to be circular. */
1554 assq_no_quit (key
, list
)
1555 Lisp_Object key
, list
;
1558 && (!CONSP (XCAR (list
))
1559 || !EQ (XCAR (XCAR (list
)), key
)))
1562 return CAR_SAFE (list
);
1565 DEFUN ("assoc", Fassoc
, Sassoc
, 2, 2, 0,
1566 doc
: /* Return non-nil if KEY is `equal' to the car of an element of LIST.
1567 The value is actually the first element of LIST whose car equals KEY. */)
1569 Lisp_Object key
, list
;
1576 || (CONSP (XCAR (list
))
1577 && (car
= XCAR (XCAR (list
)),
1578 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1583 || (CONSP (XCAR (list
))
1584 && (car
= XCAR (XCAR (list
)),
1585 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1590 || (CONSP (XCAR (list
))
1591 && (car
= XCAR (XCAR (list
)),
1592 EQ (car
, key
) || !NILP (Fequal (car
, key
)))))
1602 DEFUN ("rassq", Frassq
, Srassq
, 2, 2, 0,
1603 doc
: /* Return non-nil if KEY is `eq' to the cdr of an element of LIST.
1604 The value is actually the first element of LIST whose cdr is KEY. */)
1606 register Lisp_Object key
;
1612 || (CONSP (XCAR (list
))
1613 && EQ (XCDR (XCAR (list
)), key
)))
1618 || (CONSP (XCAR (list
))
1619 && EQ (XCDR (XCAR (list
)), key
)))
1624 || (CONSP (XCAR (list
))
1625 && EQ (XCDR (XCAR (list
)), key
)))
1635 DEFUN ("rassoc", Frassoc
, Srassoc
, 2, 2, 0,
1636 doc
: /* Return non-nil if KEY is `equal' to the cdr of an element of LIST.
1637 The value is actually the first element of LIST whose cdr equals KEY. */)
1639 Lisp_Object key
, list
;
1646 || (CONSP (XCAR (list
))
1647 && (cdr
= XCDR (XCAR (list
)),
1648 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1653 || (CONSP (XCAR (list
))
1654 && (cdr
= XCDR (XCAR (list
)),
1655 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1660 || (CONSP (XCAR (list
))
1661 && (cdr
= XCDR (XCAR (list
)),
1662 EQ (cdr
, key
) || !NILP (Fequal (cdr
, key
)))))
1672 DEFUN ("delq", Fdelq
, Sdelq
, 2, 2, 0,
1673 doc
: /* Delete by side effect any occurrences of ELT as a member of LIST.
1674 The modified LIST is returned. Comparison is done with `eq'.
1675 If the first member of LIST is ELT, there is no way to remove it by side effect;
1676 therefore, write `(setq foo (delq element foo))'
1677 to be sure of changing the value of `foo'. */)
1679 register Lisp_Object elt
;
1682 register Lisp_Object tail
, prev
;
1683 register Lisp_Object tem
;
1687 while (!NILP (tail
))
1689 CHECK_LIST_CONS (tail
, list
);
1696 Fsetcdr (prev
, XCDR (tail
));
1706 DEFUN ("delete", Fdelete
, Sdelete
, 2, 2, 0,
1707 doc
: /* Delete by side effect any occurrences of ELT as a member of SEQ.
1708 SEQ must be a list, a vector, or a string.
1709 The modified SEQ is returned. Comparison is done with `equal'.
1710 If SEQ is not a list, or the first member of SEQ is ELT, deleting it
1711 is not a side effect; it is simply using a different sequence.
1712 Therefore, write `(setq foo (delete element foo))'
1713 to be sure of changing the value of `foo'. */)
1715 Lisp_Object elt
, seq
;
1721 for (i
= n
= 0; i
< ASIZE (seq
); ++i
)
1722 if (NILP (Fequal (AREF (seq
, i
), elt
)))
1725 if (n
!= ASIZE (seq
))
1727 struct Lisp_Vector
*p
= allocate_vector (n
);
1729 for (i
= n
= 0; i
< ASIZE (seq
); ++i
)
1730 if (NILP (Fequal (AREF (seq
, i
), elt
)))
1731 p
->contents
[n
++] = AREF (seq
, i
);
1733 XSETVECTOR (seq
, p
);
1736 else if (STRINGP (seq
))
1738 EMACS_INT i
, ibyte
, nchars
, nbytes
, cbytes
;
1741 for (i
= nchars
= nbytes
= ibyte
= 0;
1743 ++i
, ibyte
+= cbytes
)
1745 if (STRING_MULTIBYTE (seq
))
1747 c
= STRING_CHAR (SDATA (seq
) + ibyte
,
1748 SBYTES (seq
) - ibyte
);
1749 cbytes
= CHAR_BYTES (c
);
1757 if (!INTEGERP (elt
) || c
!= XINT (elt
))
1764 if (nchars
!= SCHARS (seq
))
1768 tem
= make_uninit_multibyte_string (nchars
, nbytes
);
1769 if (!STRING_MULTIBYTE (seq
))
1770 STRING_SET_UNIBYTE (tem
);
1772 for (i
= nchars
= nbytes
= ibyte
= 0;
1774 ++i
, ibyte
+= cbytes
)
1776 if (STRING_MULTIBYTE (seq
))
1778 c
= STRING_CHAR (SDATA (seq
) + ibyte
,
1779 SBYTES (seq
) - ibyte
);
1780 cbytes
= CHAR_BYTES (c
);
1788 if (!INTEGERP (elt
) || c
!= XINT (elt
))
1790 unsigned char *from
= SDATA (seq
) + ibyte
;
1791 unsigned char *to
= SDATA (tem
) + nbytes
;
1797 for (n
= cbytes
; n
--; )
1807 Lisp_Object tail
, prev
;
1809 for (tail
= seq
, prev
= Qnil
; !NILP (tail
); tail
= XCDR (tail
))
1811 CHECK_LIST_CONS (tail
, seq
);
1813 if (!NILP (Fequal (elt
, XCAR (tail
))))
1818 Fsetcdr (prev
, XCDR (tail
));
1829 DEFUN ("nreverse", Fnreverse
, Snreverse
, 1, 1, 0,
1830 doc
: /* Reverse LIST by modifying cdr pointers.
1831 Return the reversed list. */)
1835 register Lisp_Object prev
, tail
, next
;
1837 if (NILP (list
)) return list
;
1840 while (!NILP (tail
))
1843 CHECK_LIST_CONS (tail
, list
);
1845 Fsetcdr (tail
, prev
);
1852 DEFUN ("reverse", Freverse
, Sreverse
, 1, 1, 0,
1853 doc
: /* Reverse LIST, copying. Return the reversed list.
1854 See also the function `nreverse', which is used more often. */)
1860 for (new = Qnil
; CONSP (list
); list
= XCDR (list
))
1863 new = Fcons (XCAR (list
), new);
1865 CHECK_LIST_END (list
, list
);
1869 Lisp_Object
merge ();
1871 DEFUN ("sort", Fsort
, Ssort
, 2, 2, 0,
1872 doc
: /* Sort LIST, stably, comparing elements using PREDICATE.
1873 Returns the sorted list. LIST is modified by side effects.
1874 PREDICATE is called with two elements of LIST, and should return non-nil
1875 if the first element should sort before the second. */)
1877 Lisp_Object list
, predicate
;
1879 Lisp_Object front
, back
;
1880 register Lisp_Object len
, tem
;
1881 struct gcpro gcpro1
, gcpro2
;
1882 register int length
;
1885 len
= Flength (list
);
1886 length
= XINT (len
);
1890 XSETINT (len
, (length
/ 2) - 1);
1891 tem
= Fnthcdr (len
, list
);
1893 Fsetcdr (tem
, Qnil
);
1895 GCPRO2 (front
, back
);
1896 front
= Fsort (front
, predicate
);
1897 back
= Fsort (back
, predicate
);
1899 return merge (front
, back
, predicate
);
1903 merge (org_l1
, org_l2
, pred
)
1904 Lisp_Object org_l1
, org_l2
;
1908 register Lisp_Object tail
;
1910 register Lisp_Object l1
, l2
;
1911 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1918 /* It is sufficient to protect org_l1 and org_l2.
1919 When l1 and l2 are updated, we copy the new values
1920 back into the org_ vars. */
1921 GCPRO4 (org_l1
, org_l2
, pred
, value
);
1941 tem
= call2 (pred
, Fcar (l2
), Fcar (l1
));
1957 Fsetcdr (tail
, tem
);
1963 #if 0 /* Unsafe version. */
1964 DEFUN ("plist-get", Fplist_get
, Splist_get
, 2, 2, 0,
1965 doc
: /* Extract a value from a property list.
1966 PLIST is a property list, which is a list of the form
1967 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
1968 corresponding to the given PROP, or nil if PROP is not
1969 one of the properties on the list. */)
1977 CONSP (tail
) && CONSP (XCDR (tail
));
1978 tail
= XCDR (XCDR (tail
)))
1980 if (EQ (prop
, XCAR (tail
)))
1981 return XCAR (XCDR (tail
));
1983 /* This function can be called asynchronously
1984 (setup_coding_system). Don't QUIT in that case. */
1985 if (!interrupt_input_blocked
)
1989 CHECK_LIST_END (tail
, prop
);
1995 /* This does not check for quits. That is safe since it must terminate. */
1997 DEFUN ("plist-get", Fplist_get
, Splist_get
, 2, 2, 0,
1998 doc
: /* Extract a value from a property list.
1999 PLIST is a property list, which is a list of the form
2000 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
2001 corresponding to the given PROP, or nil if PROP is not one of the
2002 properties on the list. This function never signals an error. */)
2007 Lisp_Object tail
, halftail
;
2009 /* halftail is used to detect circular lists. */
2010 tail
= halftail
= plist
;
2011 while (CONSP (tail
) && CONSP (XCDR (tail
)))
2013 if (EQ (prop
, XCAR (tail
)))
2014 return XCAR (XCDR (tail
));
2016 tail
= XCDR (XCDR (tail
));
2017 halftail
= XCDR (halftail
);
2018 if (EQ (tail
, halftail
))
2025 DEFUN ("get", Fget
, Sget
, 2, 2, 0,
2026 doc
: /* Return the value of SYMBOL's PROPNAME property.
2027 This is the last value stored with `(put SYMBOL PROPNAME VALUE)'. */)
2029 Lisp_Object symbol
, propname
;
2031 CHECK_SYMBOL (symbol
);
2032 return Fplist_get (XSYMBOL (symbol
)->plist
, propname
);
2035 DEFUN ("plist-put", Fplist_put
, Splist_put
, 3, 3, 0,
2036 doc
: /* Change value in PLIST of PROP to VAL.
2037 PLIST is a property list, which is a list of the form
2038 \(PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol and VAL is any object.
2039 If PROP is already a property on the list, its value is set to VAL,
2040 otherwise the new PROP VAL pair is added. The new plist is returned;
2041 use `(setq x (plist-put x prop val))' to be sure to use the new value.
2042 The PLIST is modified by side effects. */)
2045 register Lisp_Object prop
;
2048 register Lisp_Object tail
, prev
;
2049 Lisp_Object newcell
;
2051 for (tail
= plist
; CONSP (tail
) && CONSP (XCDR (tail
));
2052 tail
= XCDR (XCDR (tail
)))
2054 if (EQ (prop
, XCAR (tail
)))
2056 Fsetcar (XCDR (tail
), val
);
2063 newcell
= Fcons (prop
, Fcons (val
, Qnil
));
2067 Fsetcdr (XCDR (prev
), newcell
);
2071 DEFUN ("put", Fput
, Sput
, 3, 3, 0,
2072 doc
: /* Store SYMBOL's PROPNAME property with value VALUE.
2073 It can be retrieved with `(get SYMBOL PROPNAME)'. */)
2074 (symbol
, propname
, value
)
2075 Lisp_Object symbol
, propname
, value
;
2077 CHECK_SYMBOL (symbol
);
2078 XSYMBOL (symbol
)->plist
2079 = Fplist_put (XSYMBOL (symbol
)->plist
, propname
, value
);
2083 DEFUN ("lax-plist-get", Flax_plist_get
, Slax_plist_get
, 2, 2, 0,
2084 doc
: /* Extract a value from a property list, comparing with `equal'.
2085 PLIST is a property list, which is a list of the form
2086 \(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
2087 corresponding to the given PROP, or nil if PROP is not
2088 one of the properties on the list. */)
2096 CONSP (tail
) && CONSP (XCDR (tail
));
2097 tail
= XCDR (XCDR (tail
)))
2099 if (! NILP (Fequal (prop
, XCAR (tail
))))
2100 return XCAR (XCDR (tail
));
2105 CHECK_LIST_END (tail
, prop
);
2110 DEFUN ("lax-plist-put", Flax_plist_put
, Slax_plist_put
, 3, 3, 0,
2111 doc
: /* Change value in PLIST of PROP to VAL, comparing with `equal'.
2112 PLIST is a property list, which is a list of the form
2113 \(PROP1 VALUE1 PROP2 VALUE2 ...). PROP and VAL are any objects.
2114 If PROP is already a property on the list, its value is set to VAL,
2115 otherwise the new PROP VAL pair is added. The new plist is returned;
2116 use `(setq x (lax-plist-put x prop val))' to be sure to use the new value.
2117 The PLIST is modified by side effects. */)
2120 register Lisp_Object prop
;
2123 register Lisp_Object tail
, prev
;
2124 Lisp_Object newcell
;
2126 for (tail
= plist
; CONSP (tail
) && CONSP (XCDR (tail
));
2127 tail
= XCDR (XCDR (tail
)))
2129 if (! NILP (Fequal (prop
, XCAR (tail
))))
2131 Fsetcar (XCDR (tail
), val
);
2138 newcell
= Fcons (prop
, Fcons (val
, Qnil
));
2142 Fsetcdr (XCDR (prev
), newcell
);
2146 DEFUN ("eql", Feql
, Seql
, 2, 2, 0,
2147 doc
: /* Return t if the two args are the same Lisp object.
2148 Floating-point numbers of equal value are `eql', but they may not be `eq'. */)
2150 Lisp_Object obj1
, obj2
;
2153 return internal_equal (obj1
, obj2
, 0, 0) ? Qt
: Qnil
;
2155 return EQ (obj1
, obj2
) ? Qt
: Qnil
;
2158 DEFUN ("equal", Fequal
, Sequal
, 2, 2, 0,
2159 doc
: /* Return t if two Lisp objects have similar structure and contents.
2160 They must have the same data type.
2161 Conses are compared by comparing the cars and the cdrs.
2162 Vectors and strings are compared element by element.
2163 Numbers are compared by value, but integers cannot equal floats.
2164 (Use `=' if you want integers and floats to be able to be equal.)
2165 Symbols must match exactly. */)
2167 register Lisp_Object o1
, o2
;
2169 return internal_equal (o1
, o2
, 0, 0) ? Qt
: Qnil
;
2172 DEFUN ("equal-including-properties", Fequal_including_properties
, Sequal_including_properties
, 2, 2, 0,
2173 doc
: /* Return t if two Lisp objects have similar structure and contents.
2174 This is like `equal' except that it compares the text properties
2175 of strings. (`equal' ignores text properties.) */)
2177 register Lisp_Object o1
, o2
;
2179 return internal_equal (o1
, o2
, 0, 1) ? Qt
: Qnil
;
2182 /* DEPTH is current depth of recursion. Signal an error if it
2184 PROPS, if non-nil, means compare string text properties too. */
2187 internal_equal (o1
, o2
, depth
, props
)
2188 register Lisp_Object o1
, o2
;
2192 error ("Stack overflow in equal");
2198 if (XTYPE (o1
) != XTYPE (o2
))
2207 d1
= extract_float (o1
);
2208 d2
= extract_float (o2
);
2209 /* If d is a NaN, then d != d. Two NaNs should be `equal' even
2210 though they are not =. */
2211 return d1
== d2
|| (d1
!= d1
&& d2
!= d2
);
2215 if (!internal_equal (XCAR (o1
), XCAR (o2
), depth
+ 1, props
))
2222 if (XMISCTYPE (o1
) != XMISCTYPE (o2
))
2226 if (!internal_equal (OVERLAY_START (o1
), OVERLAY_START (o2
),
2228 || !internal_equal (OVERLAY_END (o1
), OVERLAY_END (o2
),
2231 o1
= XOVERLAY (o1
)->plist
;
2232 o2
= XOVERLAY (o2
)->plist
;
2237 return (XMARKER (o1
)->buffer
== XMARKER (o2
)->buffer
2238 && (XMARKER (o1
)->buffer
== 0
2239 || XMARKER (o1
)->bytepos
== XMARKER (o2
)->bytepos
));
2243 case Lisp_Vectorlike
:
2246 EMACS_INT size
= ASIZE (o1
);
2247 /* Pseudovectors have the type encoded in the size field, so this test
2248 actually checks that the objects have the same type as well as the
2250 if (ASIZE (o2
) != size
)
2252 /* Boolvectors are compared much like strings. */
2253 if (BOOL_VECTOR_P (o1
))
2256 = ((XBOOL_VECTOR (o1
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
2257 / BOOL_VECTOR_BITS_PER_CHAR
);
2259 if (XBOOL_VECTOR (o1
)->size
!= XBOOL_VECTOR (o2
)->size
)
2261 if (bcmp (XBOOL_VECTOR (o1
)->data
, XBOOL_VECTOR (o2
)->data
,
2266 if (WINDOW_CONFIGURATIONP (o1
))
2267 return compare_window_configurations (o1
, o2
, 0);
2269 /* Aside from them, only true vectors, char-tables, and compiled
2270 functions are sensible to compare, so eliminate the others now. */
2271 if (size
& PSEUDOVECTOR_FLAG
)
2273 if (!(size
& (PVEC_COMPILED
| PVEC_CHAR_TABLE
)))
2275 size
&= PSEUDOVECTOR_SIZE_MASK
;
2277 for (i
= 0; i
< size
; i
++)
2282 if (!internal_equal (v1
, v2
, depth
+ 1, props
))
2290 if (SCHARS (o1
) != SCHARS (o2
))
2292 if (SBYTES (o1
) != SBYTES (o2
))
2294 if (bcmp (SDATA (o1
), SDATA (o2
),
2297 if (props
&& !compare_string_intervals (o1
, o2
))
2303 case Lisp_Type_Limit
:
2310 extern Lisp_Object
Fmake_char_internal ();
2312 DEFUN ("fillarray", Ffillarray
, Sfillarray
, 2, 2, 0,
2313 doc
: /* Store each element of ARRAY with ITEM.
2314 ARRAY is a vector, string, char-table, or bool-vector. */)
2316 Lisp_Object array
, item
;
2318 register int size
, index
, charval
;
2319 if (VECTORP (array
))
2321 register Lisp_Object
*p
= XVECTOR (array
)->contents
;
2322 size
= ASIZE (array
);
2323 for (index
= 0; index
< size
; index
++)
2326 else if (CHAR_TABLE_P (array
))
2328 register Lisp_Object
*p
= XCHAR_TABLE (array
)->contents
;
2329 size
= CHAR_TABLE_ORDINARY_SLOTS
;
2330 for (index
= 0; index
< size
; index
++)
2332 XCHAR_TABLE (array
)->defalt
= Qnil
;
2334 else if (STRINGP (array
))
2336 register unsigned char *p
= SDATA (array
);
2337 CHECK_NUMBER (item
);
2338 charval
= XINT (item
);
2339 size
= SCHARS (array
);
2340 if (STRING_MULTIBYTE (array
))
2342 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
2343 int len
= CHAR_STRING (charval
, str
);
2344 int size_byte
= SBYTES (array
);
2345 unsigned char *p1
= p
, *endp
= p
+ size_byte
;
2348 if (size
!= size_byte
)
2351 int this_len
= MULTIBYTE_FORM_LENGTH (p1
, endp
- p1
);
2352 if (len
!= this_len
)
2353 error ("Attempt to change byte length of a string");
2356 for (i
= 0; i
< size_byte
; i
++)
2357 *p
++ = str
[i
% len
];
2360 for (index
= 0; index
< size
; index
++)
2363 else if (BOOL_VECTOR_P (array
))
2365 register unsigned char *p
= XBOOL_VECTOR (array
)->data
;
2367 = ((XBOOL_VECTOR (array
)->size
+ BOOL_VECTOR_BITS_PER_CHAR
- 1)
2368 / BOOL_VECTOR_BITS_PER_CHAR
);
2370 charval
= (! NILP (item
) ? -1 : 0);
2371 for (index
= 0; index
< size_in_chars
- 1; index
++)
2373 if (index
< size_in_chars
)
2375 /* Mask out bits beyond the vector size. */
2376 if (XBOOL_VECTOR (array
)->size
% BOOL_VECTOR_BITS_PER_CHAR
)
2377 charval
&= (1 << (XBOOL_VECTOR (array
)->size
% BOOL_VECTOR_BITS_PER_CHAR
)) - 1;
2382 wrong_type_argument (Qarrayp
, array
);
2386 DEFUN ("clear-string", Fclear_string
, Sclear_string
,
2388 doc
: /* Clear the contents of STRING.
2389 This makes STRING unibyte and may change its length. */)
2394 CHECK_STRING (string
);
2395 len
= SBYTES (string
);
2396 bzero (SDATA (string
), len
);
2397 STRING_SET_CHARS (string
, len
);
2398 STRING_SET_UNIBYTE (string
);
2402 DEFUN ("char-table-subtype", Fchar_table_subtype
, Schar_table_subtype
,
2404 doc
: /* Return the subtype of char-table CHAR-TABLE. The value is a symbol. */)
2406 Lisp_Object char_table
;
2408 CHECK_CHAR_TABLE (char_table
);
2410 return XCHAR_TABLE (char_table
)->purpose
;
2413 DEFUN ("char-table-parent", Fchar_table_parent
, Schar_table_parent
,
2415 doc
: /* Return the parent char-table of CHAR-TABLE.
2416 The value is either nil or another char-table.
2417 If CHAR-TABLE holds nil for a given character,
2418 then the actual applicable value is inherited from the parent char-table
2419 \(or from its parents, if necessary). */)
2421 Lisp_Object char_table
;
2423 CHECK_CHAR_TABLE (char_table
);
2425 return XCHAR_TABLE (char_table
)->parent
;
2428 DEFUN ("set-char-table-parent", Fset_char_table_parent
, Sset_char_table_parent
,
2430 doc
: /* Set the parent char-table of CHAR-TABLE to PARENT.
2431 Return PARENT. PARENT must be either nil or another char-table. */)
2432 (char_table
, parent
)
2433 Lisp_Object char_table
, parent
;
2437 CHECK_CHAR_TABLE (char_table
);
2441 CHECK_CHAR_TABLE (parent
);
2443 for (temp
= parent
; !NILP (temp
); temp
= XCHAR_TABLE (temp
)->parent
)
2444 if (EQ (temp
, char_table
))
2445 error ("Attempt to make a chartable be its own parent");
2448 XCHAR_TABLE (char_table
)->parent
= parent
;
2453 DEFUN ("char-table-extra-slot", Fchar_table_extra_slot
, Schar_table_extra_slot
,
2455 doc
: /* Return the value of CHAR-TABLE's extra-slot number N. */)
2457 Lisp_Object char_table
, n
;
2459 CHECK_CHAR_TABLE (char_table
);
2462 || XINT (n
) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table
)))
2463 args_out_of_range (char_table
, n
);
2465 return XCHAR_TABLE (char_table
)->extras
[XINT (n
)];
2468 DEFUN ("set-char-table-extra-slot", Fset_char_table_extra_slot
,
2469 Sset_char_table_extra_slot
,
2471 doc
: /* Set CHAR-TABLE's extra-slot number N to VALUE. */)
2472 (char_table
, n
, value
)
2473 Lisp_Object char_table
, n
, value
;
2475 CHECK_CHAR_TABLE (char_table
);
2478 || XINT (n
) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table
)))
2479 args_out_of_range (char_table
, n
);
2481 return XCHAR_TABLE (char_table
)->extras
[XINT (n
)] = value
;
2485 char_table_range (table
, from
, to
, defalt
)
2492 if (! NILP (XCHAR_TABLE (table
)->defalt
))
2493 defalt
= XCHAR_TABLE (table
)->defalt
;
2494 val
= XCHAR_TABLE (table
)->contents
[from
];
2495 if (SUB_CHAR_TABLE_P (val
))
2496 val
= char_table_range (val
, 32, 127, defalt
);
2497 else if (NILP (val
))
2499 for (from
++; from
<= to
; from
++)
2501 Lisp_Object this_val
;
2503 this_val
= XCHAR_TABLE (table
)->contents
[from
];
2504 if (SUB_CHAR_TABLE_P (this_val
))
2505 this_val
= char_table_range (this_val
, 32, 127, defalt
);
2506 else if (NILP (this_val
))
2508 if (! EQ (val
, this_val
))
2509 error ("Characters in the range have inconsistent values");
2515 DEFUN ("char-table-range", Fchar_table_range
, Schar_table_range
,
2517 doc
: /* Return the value in CHAR-TABLE for a range of characters RANGE.
2518 RANGE should be nil (for the default value),
2519 a vector which identifies a character set or a row of a character set,
2520 a character set name, or a character code.
2521 If the characters in the specified range have different values,
2522 an error is signaled.
2524 Note that this function doesn't check the parent of CHAR-TABLE. */)
2526 Lisp_Object char_table
, range
;
2528 int charset_id
, c1
= 0, c2
= 0;
2530 Lisp_Object ch
, val
, current_default
;
2532 CHECK_CHAR_TABLE (char_table
);
2534 if (EQ (range
, Qnil
))
2535 return XCHAR_TABLE (char_table
)->defalt
;
2536 if (INTEGERP (range
))
2538 int c
= XINT (range
);
2539 if (! CHAR_VALID_P (c
, 0))
2540 error ("Invalid character code: %d", c
);
2542 SPLIT_CHAR (c
, charset_id
, c1
, c2
);
2544 else if (SYMBOLP (range
))
2546 Lisp_Object charset_info
;
2548 charset_info
= Fget (range
, Qcharset
);
2549 CHECK_VECTOR (charset_info
);
2550 charset_id
= XINT (AREF (charset_info
, 0));
2551 ch
= Fmake_char_internal (make_number (charset_id
),
2552 make_number (0), make_number (0));
2554 else if (VECTORP (range
))
2556 size
= ASIZE (range
);
2558 args_out_of_range (range
, make_number (0));
2559 CHECK_NUMBER (AREF (range
, 0));
2560 charset_id
= XINT (AREF (range
, 0));
2563 CHECK_NUMBER (AREF (range
, 1));
2564 c1
= XINT (AREF (range
, 1));
2567 CHECK_NUMBER (AREF (range
, 2));
2568 c2
= XINT (AREF (range
, 2));
2572 /* This checks if charset_id, c0, and c1 are all valid or not. */
2573 ch
= Fmake_char_internal (make_number (charset_id
),
2574 make_number (c1
), make_number (c2
));
2577 error ("Invalid RANGE argument to `char-table-range'");
2579 if (c1
> 0 && (CHARSET_DIMENSION (charset_id
) == 1 || c2
> 0))
2581 /* Fully specified character. */
2582 Lisp_Object parent
= XCHAR_TABLE (char_table
)->parent
;
2584 XCHAR_TABLE (char_table
)->parent
= Qnil
;
2585 val
= Faref (char_table
, ch
);
2586 XCHAR_TABLE (char_table
)->parent
= parent
;
2590 current_default
= XCHAR_TABLE (char_table
)->defalt
;
2591 if (charset_id
== CHARSET_ASCII
2592 || charset_id
== CHARSET_8_BIT_CONTROL
2593 || charset_id
== CHARSET_8_BIT_GRAPHIC
)
2595 int from
, to
, defalt
;
2597 if (charset_id
== CHARSET_ASCII
)
2598 from
= 0, to
= 127, defalt
= CHAR_TABLE_DEFAULT_SLOT_ASCII
;
2599 else if (charset_id
== CHARSET_8_BIT_CONTROL
)
2600 from
= 128, to
= 159, defalt
= CHAR_TABLE_DEFAULT_SLOT_8_BIT_CONTROL
;
2602 from
= 160, to
= 255, defalt
= CHAR_TABLE_DEFAULT_SLOT_8_BIT_GRAPHIC
;
2603 if (! NILP (XCHAR_TABLE (char_table
)->contents
[defalt
]))
2604 current_default
= XCHAR_TABLE (char_table
)->contents
[defalt
];
2605 return char_table_range (char_table
, from
, to
, current_default
);
2608 val
= XCHAR_TABLE (char_table
)->contents
[128 + charset_id
];
2609 if (! SUB_CHAR_TABLE_P (val
))
2610 return (NILP (val
) ? current_default
: val
);
2611 if (! NILP (XCHAR_TABLE (val
)->defalt
))
2612 current_default
= XCHAR_TABLE (val
)->defalt
;
2614 return char_table_range (val
, 32, 127, current_default
);
2615 val
= XCHAR_TABLE (val
)->contents
[c1
];
2616 if (! SUB_CHAR_TABLE_P (val
))
2617 return (NILP (val
) ? current_default
: val
);
2618 if (! NILP (XCHAR_TABLE (val
)->defalt
))
2619 current_default
= XCHAR_TABLE (val
)->defalt
;
2620 return char_table_range (val
, 32, 127, current_default
);
2623 DEFUN ("set-char-table-range", Fset_char_table_range
, Sset_char_table_range
,
2625 doc
: /* Set the value in CHAR-TABLE for a range of characters RANGE to VALUE.
2626 RANGE should be t (for all characters), nil (for the default value),
2627 a character set, a vector which identifies a character set, a row of a
2628 character set, or a character code. Return VALUE. */)
2629 (char_table
, range
, value
)
2630 Lisp_Object char_table
, range
, value
;
2634 CHECK_CHAR_TABLE (char_table
);
2637 for (i
= 0; i
< CHAR_TABLE_ORDINARY_SLOTS
; i
++)
2639 /* Don't set these special slots used for default values of
2640 ascii, eight-bit-control, and eight-bit-graphic. */
2641 if (i
!= CHAR_TABLE_DEFAULT_SLOT_ASCII
2642 && i
!= CHAR_TABLE_DEFAULT_SLOT_8_BIT_CONTROL
2643 && i
!= CHAR_TABLE_DEFAULT_SLOT_8_BIT_GRAPHIC
)
2644 XCHAR_TABLE (char_table
)->contents
[i
] = value
;
2646 else if (EQ (range
, Qnil
))
2647 XCHAR_TABLE (char_table
)->defalt
= value
;
2648 else if (SYMBOLP (range
))
2650 Lisp_Object charset_info
;
2653 charset_info
= Fget (range
, Qcharset
);
2654 if (! VECTORP (charset_info
)
2655 || ! NATNUMP (AREF (charset_info
, 0))
2656 || (charset_id
= XINT (AREF (charset_info
, 0)),
2657 ! CHARSET_DEFINED_P (charset_id
)))
2658 error ("Invalid charset: %s", SDATA (SYMBOL_NAME (range
)));
2660 if (charset_id
== CHARSET_ASCII
)
2661 for (i
= 0; i
< 128; i
++)
2662 XCHAR_TABLE (char_table
)->contents
[i
] = value
;
2663 else if (charset_id
== CHARSET_8_BIT_CONTROL
)
2664 for (i
= 128; i
< 160; i
++)
2665 XCHAR_TABLE (char_table
)->contents
[i
] = value
;
2666 else if (charset_id
== CHARSET_8_BIT_GRAPHIC
)
2667 for (i
= 160; i
< 256; i
++)
2668 XCHAR_TABLE (char_table
)->contents
[i
] = value
;
2670 XCHAR_TABLE (char_table
)->contents
[charset_id
+ 128] = value
;
2672 else if (INTEGERP (range
))
2673 Faset (char_table
, range
, value
);
2674 else if (VECTORP (range
))
2676 int size
= ASIZE (range
);
2677 Lisp_Object
*val
= XVECTOR (range
)->contents
;
2678 Lisp_Object ch
= Fmake_char_internal (size
<= 0 ? Qnil
: val
[0],
2679 size
<= 1 ? Qnil
: val
[1],
2680 size
<= 2 ? Qnil
: val
[2]);
2681 Faset (char_table
, ch
, value
);
2684 error ("Invalid RANGE argument to `set-char-table-range'");
2689 DEFUN ("set-char-table-default", Fset_char_table_default
,
2690 Sset_char_table_default
, 3, 3, 0,
2691 doc
: /* Set the default value in CHAR-TABLE for generic character CH to VALUE.
2692 The generic character specifies the group of characters.
2693 If CH is a normal character, set the default value for a group of
2694 characters to which CH belongs.
2695 See also the documentation of `make-char'. */)
2696 (char_table
, ch
, value
)
2697 Lisp_Object char_table
, ch
, value
;
2699 int c
, charset
, code1
, code2
;
2702 CHECK_CHAR_TABLE (char_table
);
2706 SPLIT_CHAR (c
, charset
, code1
, code2
);
2708 /* Since we may want to set the default value for a character set
2709 not yet defined, we check only if the character set is in the
2710 valid range or not, instead of it is already defined or not. */
2711 if (! CHARSET_VALID_P (charset
))
2712 invalid_character (c
);
2714 if (SINGLE_BYTE_CHAR_P (c
))
2716 /* We use special slots for the default values of single byte
2719 = (c
< 0x80 ? CHAR_TABLE_DEFAULT_SLOT_ASCII
2720 : c
< 0xA0 ? CHAR_TABLE_DEFAULT_SLOT_8_BIT_CONTROL
2721 : CHAR_TABLE_DEFAULT_SLOT_8_BIT_GRAPHIC
);
2723 return (XCHAR_TABLE (char_table
)->contents
[default_slot
] = value
);
2726 /* Even if C is not a generic char, we had better behave as if a
2727 generic char is specified. */
2728 if (!CHARSET_DEFINED_P (charset
) || CHARSET_DIMENSION (charset
) == 1)
2730 temp
= XCHAR_TABLE (char_table
)->contents
[charset
+ 128];
2731 if (! SUB_CHAR_TABLE_P (temp
))
2733 temp
= make_sub_char_table (temp
);
2734 XCHAR_TABLE (char_table
)->contents
[charset
+ 128] = temp
;
2738 XCHAR_TABLE (temp
)->defalt
= value
;
2742 temp
= XCHAR_TABLE (char_table
)->contents
[code1
];
2743 if (SUB_CHAR_TABLE_P (temp
))
2744 XCHAR_TABLE (temp
)->defalt
= value
;
2746 XCHAR_TABLE (char_table
)->contents
[code1
] = value
;
2750 /* Look up the element in TABLE at index CH,
2751 and return it as an integer.
2752 If the element is nil, return CH itself.
2753 (Actually we do that for any non-integer.) */
2756 char_table_translate (table
, ch
)
2761 value
= Faref (table
, make_number (ch
));
2762 if (! INTEGERP (value
))
2764 return XINT (value
);
2768 optimize_sub_char_table (table
, chars
)
2776 from
= 33, to
= 127;
2778 from
= 32, to
= 128;
2780 if (!SUB_CHAR_TABLE_P (*table
)
2781 || ! NILP (XCHAR_TABLE (*table
)->defalt
))
2783 elt
= XCHAR_TABLE (*table
)->contents
[from
++];
2784 for (; from
< to
; from
++)
2785 if (NILP (Fequal (elt
, XCHAR_TABLE (*table
)->contents
[from
])))
2790 DEFUN ("optimize-char-table", Foptimize_char_table
, Soptimize_char_table
,
2791 1, 1, 0, doc
: /* Optimize char table TABLE. */)
2799 CHECK_CHAR_TABLE (table
);
2801 for (i
= CHAR_TABLE_SINGLE_BYTE_SLOTS
; i
< CHAR_TABLE_ORDINARY_SLOTS
; i
++)
2803 elt
= XCHAR_TABLE (table
)->contents
[i
];
2804 if (!SUB_CHAR_TABLE_P (elt
))
2806 dim
= CHARSET_DIMENSION (i
- 128);
2807 chars
= CHARSET_CHARS (i
- 128);
2809 for (j
= 32; j
< SUB_CHAR_TABLE_ORDINARY_SLOTS
; j
++)
2810 optimize_sub_char_table (XCHAR_TABLE (elt
)->contents
+ j
, chars
);
2811 optimize_sub_char_table (XCHAR_TABLE (table
)->contents
+ i
, chars
);
2817 /* Map C_FUNCTION or FUNCTION over SUBTABLE, calling it for each
2818 character or group of characters that share a value.
2819 DEPTH is the current depth in the originally specified
2820 chartable, and INDICES contains the vector indices
2821 for the levels our callers have descended.
2823 ARG is passed to C_FUNCTION when that is called. */
2826 map_char_table (c_function
, function
, table
, subtable
, arg
, depth
, indices
)
2827 void (*c_function
) P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
2828 Lisp_Object function
, table
, subtable
, arg
;
2829 int depth
, *indices
;
2832 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2834 GCPRO4 (arg
, table
, subtable
, function
);
2838 /* At first, handle ASCII and 8-bit European characters. */
2839 for (i
= 0; i
< CHAR_TABLE_SINGLE_BYTE_SLOTS
; i
++)
2841 Lisp_Object elt
= XCHAR_TABLE (subtable
)->contents
[i
];
2843 elt
= XCHAR_TABLE (subtable
)->defalt
;
2845 elt
= Faref (subtable
, make_number (i
));
2847 (*c_function
) (arg
, make_number (i
), elt
);
2849 call2 (function
, make_number (i
), elt
);
2851 #if 0 /* If the char table has entries for higher characters,
2852 we should report them. */
2853 if (NILP (current_buffer
->enable_multibyte_characters
))
2859 to
= CHAR_TABLE_ORDINARY_SLOTS
;
2863 int charset
= indices
[0] - 128;
2866 to
= SUB_CHAR_TABLE_ORDINARY_SLOTS
;
2867 if (CHARSET_CHARS (charset
) == 94)
2876 elt
= XCHAR_TABLE (subtable
)->contents
[i
];
2878 charset
= indices
[0] - 128;
2880 && (!CHARSET_DEFINED_P (charset
)
2881 || charset
== CHARSET_8_BIT_CONTROL
2882 || charset
== CHARSET_8_BIT_GRAPHIC
))
2885 if (SUB_CHAR_TABLE_P (elt
))
2888 error ("Too deep char table");
2889 map_char_table (c_function
, function
, table
, elt
, arg
, depth
+ 1, indices
);
2895 c1
= depth
>= 1 ? indices
[1] : 0;
2896 c2
= depth
>= 2 ? indices
[2] : 0;
2897 c
= MAKE_CHAR (charset
, c1
, c2
);
2900 elt
= XCHAR_TABLE (subtable
)->defalt
;
2902 elt
= Faref (table
, make_number (c
));
2905 (*c_function
) (arg
, make_number (c
), elt
);
2907 call2 (function
, make_number (c
), elt
);
2913 static void void_call2
P_ ((Lisp_Object a
, Lisp_Object b
, Lisp_Object c
));
2915 void_call2 (a
, b
, c
)
2916 Lisp_Object a
, b
, c
;
2921 DEFUN ("map-char-table", Fmap_char_table
, Smap_char_table
,
2923 doc
: /* Call FUNCTION for each (normal and generic) characters in CHAR-TABLE.
2924 FUNCTION is called with two arguments--a key and a value.
2925 The key is always a possible IDX argument to `aref'. */)
2926 (function
, char_table
)
2927 Lisp_Object function
, char_table
;
2929 /* The depth of char table is at most 3. */
2932 CHECK_CHAR_TABLE (char_table
);
2934 /* When Lisp_Object is represented as a union, `call2' cannot directly
2935 be passed to map_char_table because it returns a Lisp_Object rather
2936 than returning nothing.
2937 Casting leads to crashes on some architectures. --Stef */
2938 map_char_table (void_call2
, Qnil
, char_table
, char_table
, function
, 0, indices
);
2942 /* Return a value for character C in char-table TABLE. Store the
2943 actual index for that value in *IDX. Ignore the default value of
2947 char_table_ref_and_index (table
, c
, idx
)
2951 int charset
, c1
, c2
;
2954 if (SINGLE_BYTE_CHAR_P (c
))
2957 return XCHAR_TABLE (table
)->contents
[c
];
2959 SPLIT_CHAR (c
, charset
, c1
, c2
);
2960 elt
= XCHAR_TABLE (table
)->contents
[charset
+ 128];
2961 *idx
= MAKE_CHAR (charset
, 0, 0);
2962 if (!SUB_CHAR_TABLE_P (elt
))
2964 if (c1
< 32 || NILP (XCHAR_TABLE (elt
)->contents
[c1
]))
2965 return XCHAR_TABLE (elt
)->defalt
;
2966 elt
= XCHAR_TABLE (elt
)->contents
[c1
];
2967 *idx
= MAKE_CHAR (charset
, c1
, 0);
2968 if (!SUB_CHAR_TABLE_P (elt
))
2970 if (c2
< 32 || NILP (XCHAR_TABLE (elt
)->contents
[c2
]))
2971 return XCHAR_TABLE (elt
)->defalt
;
2973 return XCHAR_TABLE (elt
)->contents
[c2
];
2983 Lisp_Object args
[2];
2986 return Fnconc (2, args
);
2988 return Fnconc (2, &s1
);
2989 #endif /* NO_ARG_ARRAY */
2992 DEFUN ("nconc", Fnconc
, Snconc
, 0, MANY
, 0,
2993 doc
: /* Concatenate any number of lists by altering them.
2994 Only the last argument is not altered, and need not be a list.
2995 usage: (nconc &rest LISTS) */)
3000 register int argnum
;
3001 register Lisp_Object tail
, tem
, val
;
3005 for (argnum
= 0; argnum
< nargs
; argnum
++)
3008 if (NILP (tem
)) continue;
3013 if (argnum
+ 1 == nargs
) break;
3015 CHECK_LIST_CONS (tem
, tem
);
3024 tem
= args
[argnum
+ 1];
3025 Fsetcdr (tail
, tem
);
3027 args
[argnum
+ 1] = tail
;
3033 /* This is the guts of all mapping functions.
3034 Apply FN to each element of SEQ, one by one,
3035 storing the results into elements of VALS, a C vector of Lisp_Objects.
3036 LENI is the length of VALS, which should also be the length of SEQ. */
3039 mapcar1 (leni
, vals
, fn
, seq
)
3042 Lisp_Object fn
, seq
;
3044 register Lisp_Object tail
;
3047 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3051 /* Don't let vals contain any garbage when GC happens. */
3052 for (i
= 0; i
< leni
; i
++)
3055 GCPRO3 (dummy
, fn
, seq
);
3057 gcpro1
.nvars
= leni
;
3061 /* We need not explicitly protect `tail' because it is used only on lists, and
3062 1) lists are not relocated and 2) the list is marked via `seq' so will not
3067 for (i
= 0; i
< leni
; i
++)
3069 dummy
= call1 (fn
, AREF (seq
, i
));
3074 else if (BOOL_VECTOR_P (seq
))
3076 for (i
= 0; i
< leni
; i
++)
3079 byte
= XBOOL_VECTOR (seq
)->data
[i
/ BOOL_VECTOR_BITS_PER_CHAR
];
3080 dummy
= (byte
& (1 << (i
% BOOL_VECTOR_BITS_PER_CHAR
))) ? Qt
: Qnil
;
3081 dummy
= call1 (fn
, dummy
);
3086 else if (STRINGP (seq
))
3090 for (i
= 0, i_byte
= 0; i
< leni
;)
3095 FETCH_STRING_CHAR_ADVANCE (c
, seq
, i
, i_byte
);
3096 XSETFASTINT (dummy
, c
);
3097 dummy
= call1 (fn
, dummy
);
3099 vals
[i_before
] = dummy
;
3102 else /* Must be a list, since Flength did not get an error */
3105 for (i
= 0; i
< leni
&& CONSP (tail
); i
++)
3107 dummy
= call1 (fn
, XCAR (tail
));
3117 DEFUN ("mapconcat", Fmapconcat
, Smapconcat
, 3, 3, 0,
3118 doc
: /* Apply FUNCTION to each element of SEQUENCE, and concat the results as strings.
3119 In between each pair of results, stick in SEPARATOR. Thus, " " as
3120 SEPARATOR results in spaces between the values returned by FUNCTION.
3121 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
3122 (function
, sequence
, separator
)
3123 Lisp_Object function
, sequence
, separator
;
3128 register Lisp_Object
*args
;
3130 struct gcpro gcpro1
;
3134 len
= Flength (sequence
);
3136 nargs
= leni
+ leni
- 1;
3137 if (nargs
< 0) return empty_unibyte_string
;
3139 SAFE_ALLOCA_LISP (args
, nargs
);
3142 mapcar1 (leni
, args
, function
, sequence
);
3145 for (i
= leni
- 1; i
> 0; i
--)
3146 args
[i
+ i
] = args
[i
];
3148 for (i
= 1; i
< nargs
; i
+= 2)
3149 args
[i
] = separator
;
3151 ret
= Fconcat (nargs
, args
);
3157 DEFUN ("mapcar", Fmapcar
, Smapcar
, 2, 2, 0,
3158 doc
: /* Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
3159 The result is a list just as long as SEQUENCE.
3160 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
3161 (function
, sequence
)
3162 Lisp_Object function
, sequence
;
3164 register Lisp_Object len
;
3166 register Lisp_Object
*args
;
3170 len
= Flength (sequence
);
3171 leni
= XFASTINT (len
);
3173 SAFE_ALLOCA_LISP (args
, leni
);
3175 mapcar1 (leni
, args
, function
, sequence
);
3177 ret
= Flist (leni
, args
);
3183 DEFUN ("mapc", Fmapc
, Smapc
, 2, 2, 0,
3184 doc
: /* Apply FUNCTION to each element of SEQUENCE for side effects only.
3185 Unlike `mapcar', don't accumulate the results. Return SEQUENCE.
3186 SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
3187 (function
, sequence
)
3188 Lisp_Object function
, sequence
;
3192 leni
= XFASTINT (Flength (sequence
));
3193 mapcar1 (leni
, 0, function
, sequence
);
3198 /* Anything that calls this function must protect from GC! */
3200 DEFUN ("y-or-n-p", Fy_or_n_p
, Sy_or_n_p
, 1, 1, 0,
3201 doc
: /* Ask user a "y or n" question. Return t if answer is "y".
3202 Takes one argument, which is the string to display to ask the question.
3203 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
3204 No confirmation of the answer is requested; a single character is enough.
3205 Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses
3206 the bindings in `query-replace-map'; see the documentation of that variable
3207 for more information. In this case, the useful bindings are `act', `skip',
3208 `recenter', and `quit'.\)
3210 Under a windowing system a dialog box will be used if `last-nonmenu-event'
3211 is nil and `use-dialog-box' is non-nil. */)
3215 register Lisp_Object obj
, key
, def
, map
;
3216 register int answer
;
3217 Lisp_Object xprompt
;
3218 Lisp_Object args
[2];
3219 struct gcpro gcpro1
, gcpro2
;
3220 int count
= SPECPDL_INDEX ();
3222 specbind (Qcursor_in_echo_area
, Qt
);
3224 map
= Fsymbol_value (intern ("query-replace-map"));
3226 CHECK_STRING (prompt
);
3228 GCPRO2 (prompt
, xprompt
);
3230 #ifdef HAVE_X_WINDOWS
3231 if (display_hourglass_p
)
3232 cancel_hourglass ();
3239 if (FRAME_WINDOW_P (SELECTED_FRAME ())
3240 && (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
3244 Lisp_Object pane
, menu
;
3245 redisplay_preserve_echo_area (3);
3246 pane
= Fcons (Fcons (build_string ("Yes"), Qt
),
3247 Fcons (Fcons (build_string ("No"), Qnil
),
3249 menu
= Fcons (prompt
, pane
);
3250 obj
= Fx_popup_dialog (Qt
, menu
, Qnil
);
3251 answer
= !NILP (obj
);
3254 #endif /* HAVE_MENUS */
3255 cursor_in_echo_area
= 1;
3256 choose_minibuf_frame ();
3259 Lisp_Object pargs
[3];
3261 /* Colorize prompt according to `minibuffer-prompt' face. */
3262 pargs
[0] = build_string ("%s(y or n) ");
3263 pargs
[1] = intern ("face");
3264 pargs
[2] = intern ("minibuffer-prompt");
3265 args
[0] = Fpropertize (3, pargs
);
3270 if (minibuffer_auto_raise
)
3272 Lisp_Object mini_frame
;
3274 mini_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
3276 Fraise_frame (mini_frame
);
3279 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
3280 obj
= read_filtered_event (1, 0, 0, 0, Qnil
);
3281 cursor_in_echo_area
= 0;
3282 /* If we need to quit, quit with cursor_in_echo_area = 0. */
3285 key
= Fmake_vector (make_number (1), obj
);
3286 def
= Flookup_key (map
, key
, Qt
);
3288 if (EQ (def
, intern ("skip")))
3293 else if (EQ (def
, intern ("act")))
3298 else if (EQ (def
, intern ("recenter")))
3304 else if (EQ (def
, intern ("quit")))
3306 /* We want to exit this command for exit-prefix,
3307 and this is the only way to do it. */
3308 else if (EQ (def
, intern ("exit-prefix")))
3313 /* If we don't clear this, then the next call to read_char will
3314 return quit_char again, and we'll enter an infinite loop. */
3319 if (EQ (xprompt
, prompt
))
3321 args
[0] = build_string ("Please answer y or n. ");
3323 xprompt
= Fconcat (2, args
);
3328 if (! noninteractive
)
3330 cursor_in_echo_area
= -1;
3331 message_with_string (answer
? "%s(y or n) y" : "%s(y or n) n",
3335 unbind_to (count
, Qnil
);
3336 return answer
? Qt
: Qnil
;
3339 /* This is how C code calls `yes-or-no-p' and allows the user
3342 Anything that calls this function must protect from GC! */
3345 do_yes_or_no_p (prompt
)
3348 return call1 (intern ("yes-or-no-p"), prompt
);
3351 /* Anything that calls this function must protect from GC! */
3353 DEFUN ("yes-or-no-p", Fyes_or_no_p
, Syes_or_no_p
, 1, 1, 0,
3354 doc
: /* Ask user a yes-or-no question. Return t if answer is yes.
3355 Takes one argument, which is the string to display to ask the question.
3356 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
3357 The user must confirm the answer with RET,
3358 and can edit it until it has been confirmed.
3360 Under a windowing system a dialog box will be used if `last-nonmenu-event'
3361 is nil, and `use-dialog-box' is non-nil. */)
3365 register Lisp_Object ans
;
3366 Lisp_Object args
[2];
3367 struct gcpro gcpro1
;
3369 CHECK_STRING (prompt
);
3372 if (FRAME_WINDOW_P (SELECTED_FRAME ())
3373 && (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
3377 Lisp_Object pane
, menu
, obj
;
3378 redisplay_preserve_echo_area (4);
3379 pane
= Fcons (Fcons (build_string ("Yes"), Qt
),
3380 Fcons (Fcons (build_string ("No"), Qnil
),
3383 menu
= Fcons (prompt
, pane
);
3384 obj
= Fx_popup_dialog (Qt
, menu
, Qnil
);
3388 #endif /* HAVE_MENUS */
3391 args
[1] = build_string ("(yes or no) ");
3392 prompt
= Fconcat (2, args
);
3398 ans
= Fdowncase (Fread_from_minibuffer (prompt
, Qnil
, Qnil
, Qnil
,
3399 Qyes_or_no_p_history
, Qnil
,
3401 if (SCHARS (ans
) == 3 && !strcmp (SDATA (ans
), "yes"))
3406 if (SCHARS (ans
) == 2 && !strcmp (SDATA (ans
), "no"))
3414 message ("Please answer yes or no.");
3415 Fsleep_for (make_number (2), Qnil
);
3419 DEFUN ("load-average", Fload_average
, Sload_average
, 0, 1, 0,
3420 doc
: /* Return list of 1 minute, 5 minute and 15 minute load averages.
3422 Each of the three load averages is multiplied by 100, then converted
3425 When USE-FLOATS is non-nil, floats will be used instead of integers.
3426 These floats are not multiplied by 100.
3428 If the 5-minute or 15-minute load averages are not available, return a
3429 shortened list, containing only those averages which are available.
3431 An error is thrown if the load average can't be obtained. In some
3432 cases making it work would require Emacs being installed setuid or
3433 setgid so that it can read kernel information, and that usually isn't
3436 Lisp_Object use_floats
;
3439 int loads
= getloadavg (load_ave
, 3);
3440 Lisp_Object ret
= Qnil
;
3443 error ("load-average not implemented for this operating system");
3447 Lisp_Object load
= (NILP (use_floats
) ?
3448 make_number ((int) (100.0 * load_ave
[loads
]))
3449 : make_float (load_ave
[loads
]));
3450 ret
= Fcons (load
, ret
);
3456 Lisp_Object Vfeatures
, Qsubfeatures
;
3457 extern Lisp_Object Vafter_load_alist
;
3459 DEFUN ("featurep", Ffeaturep
, Sfeaturep
, 1, 2, 0,
3460 doc
: /* Returns t if FEATURE is present in this Emacs.
3462 Use this to conditionalize execution of lisp code based on the
3463 presence or absence of Emacs or environment extensions.
3464 Use `provide' to declare that a feature is available. This function
3465 looks at the value of the variable `features'. The optional argument
3466 SUBFEATURE can be used to check a specific subfeature of FEATURE. */)
3467 (feature
, subfeature
)
3468 Lisp_Object feature
, subfeature
;
3470 register Lisp_Object tem
;
3471 CHECK_SYMBOL (feature
);
3472 tem
= Fmemq (feature
, Vfeatures
);
3473 if (!NILP (tem
) && !NILP (subfeature
))
3474 tem
= Fmember (subfeature
, Fget (feature
, Qsubfeatures
));
3475 return (NILP (tem
)) ? Qnil
: Qt
;
3478 DEFUN ("provide", Fprovide
, Sprovide
, 1, 2, 0,
3479 doc
: /* Announce that FEATURE is a feature of the current Emacs.
3480 The optional argument SUBFEATURES should be a list of symbols listing
3481 particular subfeatures supported in this version of FEATURE. */)
3482 (feature
, subfeatures
)
3483 Lisp_Object feature
, subfeatures
;
3485 register Lisp_Object tem
;
3486 CHECK_SYMBOL (feature
);
3487 CHECK_LIST (subfeatures
);
3488 if (!NILP (Vautoload_queue
))
3489 Vautoload_queue
= Fcons (Fcons (make_number (0), Vfeatures
),
3491 tem
= Fmemq (feature
, Vfeatures
);
3493 Vfeatures
= Fcons (feature
, Vfeatures
);
3494 if (!NILP (subfeatures
))
3495 Fput (feature
, Qsubfeatures
, subfeatures
);
3496 LOADHIST_ATTACH (Fcons (Qprovide
, feature
));
3498 /* Run any load-hooks for this file. */
3499 tem
= Fassq (feature
, Vafter_load_alist
);
3501 Fprogn (XCDR (tem
));
3506 /* `require' and its subroutines. */
3508 /* List of features currently being require'd, innermost first. */
3510 Lisp_Object require_nesting_list
;
3513 require_unwind (old_value
)
3514 Lisp_Object old_value
;
3516 return require_nesting_list
= old_value
;
3519 DEFUN ("require", Frequire
, Srequire
, 1, 3, 0,
3520 doc
: /* If feature FEATURE is not loaded, load it from FILENAME.
3521 If FEATURE is not a member of the list `features', then the feature
3522 is not loaded; so load the file FILENAME.
3523 If FILENAME is omitted, the printname of FEATURE is used as the file name,
3524 and `load' will try to load this name appended with the suffix `.elc' or
3525 `.el', in that order. The name without appended suffix will not be used.
3526 If the optional third argument NOERROR is non-nil,
3527 then return nil if the file is not found instead of signaling an error.
3528 Normally the return value is FEATURE.
3529 The normal messages at start and end of loading FILENAME are suppressed. */)
3530 (feature
, filename
, noerror
)
3531 Lisp_Object feature
, filename
, noerror
;
3533 register Lisp_Object tem
;
3534 struct gcpro gcpro1
, gcpro2
;
3535 int from_file
= load_in_progress
;
3537 CHECK_SYMBOL (feature
);
3539 /* Record the presence of `require' in this file
3540 even if the feature specified is already loaded.
3541 But not more than once in any file,
3542 and not when we aren't loading or reading from a file. */
3544 for (tem
= Vcurrent_load_list
; CONSP (tem
); tem
= XCDR (tem
))
3545 if (NILP (XCDR (tem
)) && STRINGP (XCAR (tem
)))
3550 tem
= Fcons (Qrequire
, feature
);
3551 if (NILP (Fmember (tem
, Vcurrent_load_list
)))
3552 LOADHIST_ATTACH (tem
);
3554 tem
= Fmemq (feature
, Vfeatures
);
3558 int count
= SPECPDL_INDEX ();
3561 /* This is to make sure that loadup.el gives a clear picture
3562 of what files are preloaded and when. */
3563 if (! NILP (Vpurify_flag
))
3564 error ("(require %s) while preparing to dump",
3565 SDATA (SYMBOL_NAME (feature
)));
3567 /* A certain amount of recursive `require' is legitimate,
3568 but if we require the same feature recursively 3 times,
3570 tem
= require_nesting_list
;
3571 while (! NILP (tem
))
3573 if (! NILP (Fequal (feature
, XCAR (tem
))))
3578 error ("Recursive `require' for feature `%s'",
3579 SDATA (SYMBOL_NAME (feature
)));
3581 /* Update the list for any nested `require's that occur. */
3582 record_unwind_protect (require_unwind
, require_nesting_list
);
3583 require_nesting_list
= Fcons (feature
, require_nesting_list
);
3585 /* Value saved here is to be restored into Vautoload_queue */
3586 record_unwind_protect (un_autoload
, Vautoload_queue
);
3587 Vautoload_queue
= Qt
;
3589 /* Load the file. */
3590 GCPRO2 (feature
, filename
);
3591 tem
= Fload (NILP (filename
) ? Fsymbol_name (feature
) : filename
,
3592 noerror
, Qt
, Qnil
, (NILP (filename
) ? Qt
: Qnil
));
3595 /* If load failed entirely, return nil. */
3597 return unbind_to (count
, Qnil
);
3599 tem
= Fmemq (feature
, Vfeatures
);
3601 error ("Required feature `%s' was not provided",
3602 SDATA (SYMBOL_NAME (feature
)));
3604 /* Once loading finishes, don't undo it. */
3605 Vautoload_queue
= Qt
;
3606 feature
= unbind_to (count
, feature
);
3612 /* Primitives for work of the "widget" library.
3613 In an ideal world, this section would not have been necessary.
3614 However, lisp function calls being as slow as they are, it turns
3615 out that some functions in the widget library (wid-edit.el) are the
3616 bottleneck of Widget operation. Here is their translation to C,
3617 for the sole reason of efficiency. */
3619 DEFUN ("plist-member", Fplist_member
, Splist_member
, 2, 2, 0,
3620 doc
: /* Return non-nil if PLIST has the property PROP.
3621 PLIST is a property list, which is a list of the form
3622 \(PROP1 VALUE1 PROP2 VALUE2 ...\). PROP is a symbol.
3623 Unlike `plist-get', this allows you to distinguish between a missing
3624 property and a property with the value nil.
3625 The value is actually the tail of PLIST whose car is PROP. */)
3627 Lisp_Object plist
, prop
;
3629 while (CONSP (plist
) && !EQ (XCAR (plist
), prop
))
3632 plist
= XCDR (plist
);
3633 plist
= CDR (plist
);
3638 DEFUN ("widget-put", Fwidget_put
, Swidget_put
, 3, 3, 0,
3639 doc
: /* In WIDGET, set PROPERTY to VALUE.
3640 The value can later be retrieved with `widget-get'. */)
3641 (widget
, property
, value
)
3642 Lisp_Object widget
, property
, value
;
3644 CHECK_CONS (widget
);
3645 XSETCDR (widget
, Fplist_put (XCDR (widget
), property
, value
));
3649 DEFUN ("widget-get", Fwidget_get
, Swidget_get
, 2, 2, 0,
3650 doc
: /* In WIDGET, get the value of PROPERTY.
3651 The value could either be specified when the widget was created, or
3652 later with `widget-put'. */)
3654 Lisp_Object widget
, property
;
3662 CHECK_CONS (widget
);
3663 tmp
= Fplist_member (XCDR (widget
), property
);
3669 tmp
= XCAR (widget
);
3672 widget
= Fget (tmp
, Qwidget_type
);
3676 DEFUN ("widget-apply", Fwidget_apply
, Swidget_apply
, 2, MANY
, 0,
3677 doc
: /* Apply the value of WIDGET's PROPERTY to the widget itself.
3678 ARGS are passed as extra arguments to the function.
3679 usage: (widget-apply WIDGET PROPERTY &rest ARGS) */)
3684 /* This function can GC. */
3685 Lisp_Object newargs
[3];
3686 struct gcpro gcpro1
, gcpro2
;
3689 newargs
[0] = Fwidget_get (args
[0], args
[1]);
3690 newargs
[1] = args
[0];
3691 newargs
[2] = Flist (nargs
- 2, args
+ 2);
3692 GCPRO2 (newargs
[0], newargs
[2]);
3693 result
= Fapply (3, newargs
);
3698 #ifdef HAVE_LANGINFO_CODESET
3699 #include <langinfo.h>
3702 DEFUN ("locale-info", Flocale_info
, Slocale_info
, 1, 1, 0,
3703 doc
: /* Access locale data ITEM for the current C locale, if available.
3704 ITEM should be one of the following:
3706 `codeset', returning the character set as a string (locale item CODESET);
3708 `days', returning a 7-element vector of day names (locale items DAY_n);
3710 `months', returning a 12-element vector of month names (locale items MON_n);
3712 `paper', returning a list (WIDTH HEIGHT) for the default paper size,
3713 both measured in milimeters (locale items PAPER_WIDTH, PAPER_HEIGHT).
3715 If the system can't provide such information through a call to
3716 `nl_langinfo', or if ITEM isn't from the list above, return nil.
3718 See also Info node `(libc)Locales'.
3720 The data read from the system are decoded using `locale-coding-system'. */)
3725 #ifdef HAVE_LANGINFO_CODESET
3727 if (EQ (item
, Qcodeset
))
3729 str
= nl_langinfo (CODESET
);
3730 return build_string (str
);
3733 else if (EQ (item
, Qdays
)) /* e.g. for calendar-day-name-array */
3735 Lisp_Object v
= Fmake_vector (make_number (7), Qnil
);
3736 int days
[7] = {DAY_1
, DAY_2
, DAY_3
, DAY_4
, DAY_5
, DAY_6
, DAY_7
};
3738 synchronize_system_time_locale ();
3739 for (i
= 0; i
< 7; i
++)
3741 str
= nl_langinfo (days
[i
]);
3742 val
= make_unibyte_string (str
, strlen (str
));
3743 /* Fixme: Is this coding system necessarily right, even if
3744 it is consistent with CODESET? If not, what to do? */
3745 Faset (v
, make_number (i
),
3746 code_convert_string_norecord (val
, Vlocale_coding_system
,
3753 else if (EQ (item
, Qmonths
)) /* e.g. for calendar-month-name-array */
3755 struct Lisp_Vector
*p
= allocate_vector (12);
3756 int months
[12] = {MON_1
, MON_2
, MON_3
, MON_4
, MON_5
, MON_6
, MON_7
,
3757 MON_8
, MON_9
, MON_10
, MON_11
, MON_12
};
3759 synchronize_system_time_locale ();
3760 for (i
= 0; i
< 12; i
++)
3762 str
= nl_langinfo (months
[i
]);
3763 val
= make_unibyte_string (str
, strlen (str
));
3765 code_convert_string_norecord (val
, Vlocale_coding_system
, 0);
3767 XSETVECTOR (val
, p
);
3771 /* LC_PAPER stuff isn't defined as accessible in glibc as of 2.3.1,
3772 but is in the locale files. This could be used by ps-print. */
3774 else if (EQ (item
, Qpaper
))
3776 return list2 (make_number (nl_langinfo (PAPER_WIDTH
)),
3777 make_number (nl_langinfo (PAPER_HEIGHT
)));
3779 #endif /* PAPER_WIDTH */
3780 #endif /* HAVE_LANGINFO_CODESET*/
3784 /* base64 encode/decode functions (RFC 2045).
3785 Based on code from GNU recode. */
3787 #define MIME_LINE_LENGTH 76
3789 #define IS_ASCII(Character) \
3791 #define IS_BASE64(Character) \
3792 (IS_ASCII (Character) && base64_char_to_value[Character] >= 0)
3793 #define IS_BASE64_IGNORABLE(Character) \
3794 ((Character) == ' ' || (Character) == '\t' || (Character) == '\n' \
3795 || (Character) == '\f' || (Character) == '\r')
3797 /* Used by base64_decode_1 to retrieve a non-base64-ignorable
3798 character or return retval if there are no characters left to
3800 #define READ_QUADRUPLET_BYTE(retval) \
3805 if (nchars_return) \
3806 *nchars_return = nchars; \
3811 while (IS_BASE64_IGNORABLE (c))
3813 /* Table of characters coding the 64 values. */
3814 static char base64_value_to_char
[64] =
3816 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', /* 0- 9 */
3817 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 10-19 */
3818 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', /* 20-29 */
3819 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 30-39 */
3820 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', /* 40-49 */
3821 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', /* 50-59 */
3822 '8', '9', '+', '/' /* 60-63 */
3825 /* Table of base64 values for first 128 characters. */
3826 static short base64_char_to_value
[128] =
3828 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0- 9 */
3829 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10- 19 */
3830 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20- 29 */
3831 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30- 39 */
3832 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, /* 40- 49 */
3833 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, /* 50- 59 */
3834 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, /* 60- 69 */
3835 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 70- 79 */
3836 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, /* 80- 89 */
3837 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, /* 90- 99 */
3838 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, /* 100-109 */
3839 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, /* 110-119 */
3840 49, 50, 51, -1, -1, -1, -1, -1 /* 120-127 */
3843 /* The following diagram shows the logical steps by which three octets
3844 get transformed into four base64 characters.
3846 .--------. .--------. .--------.
3847 |aaaaaabb| |bbbbcccc| |ccdddddd|
3848 `--------' `--------' `--------'
3850 .--------+--------+--------+--------.
3851 |00aaaaaa|00bbbbbb|00cccccc|00dddddd|
3852 `--------+--------+--------+--------'
3854 .--------+--------+--------+--------.
3855 |AAAAAAAA|BBBBBBBB|CCCCCCCC|DDDDDDDD|
3856 `--------+--------+--------+--------'
3858 The octets are divided into 6 bit chunks, which are then encoded into
3859 base64 characters. */
3862 static int base64_encode_1
P_ ((const char *, char *, int, int, int));
3863 static int base64_decode_1
P_ ((const char *, char *, int, int, int *));
3865 DEFUN ("base64-encode-region", Fbase64_encode_region
, Sbase64_encode_region
,
3867 doc
: /* Base64-encode the region between BEG and END.
3868 Return the length of the encoded text.
3869 Optional third argument NO-LINE-BREAK means do not break long lines
3870 into shorter lines. */)
3871 (beg
, end
, no_line_break
)
3872 Lisp_Object beg
, end
, no_line_break
;
3875 int allength
, length
;
3876 int ibeg
, iend
, encoded_length
;
3880 validate_region (&beg
, &end
);
3882 ibeg
= CHAR_TO_BYTE (XFASTINT (beg
));
3883 iend
= CHAR_TO_BYTE (XFASTINT (end
));
3884 move_gap_both (XFASTINT (beg
), ibeg
);
3886 /* We need to allocate enough room for encoding the text.
3887 We need 33 1/3% more space, plus a newline every 76
3888 characters, and then we round up. */
3889 length
= iend
- ibeg
;
3890 allength
= length
+ length
/3 + 1;
3891 allength
+= allength
/ MIME_LINE_LENGTH
+ 1 + 6;
3893 SAFE_ALLOCA (encoded
, char *, allength
);
3894 encoded_length
= base64_encode_1 (BYTE_POS_ADDR (ibeg
), encoded
, length
,
3895 NILP (no_line_break
),
3896 !NILP (current_buffer
->enable_multibyte_characters
));
3897 if (encoded_length
> allength
)
3900 if (encoded_length
< 0)
3902 /* The encoding wasn't possible. */
3904 error ("Multibyte character in data for base64 encoding");
3907 /* Now we have encoded the region, so we insert the new contents
3908 and delete the old. (Insert first in order to preserve markers.) */
3909 SET_PT_BOTH (XFASTINT (beg
), ibeg
);
3910 insert (encoded
, encoded_length
);
3912 del_range_byte (ibeg
+ encoded_length
, iend
+ encoded_length
, 1);
3914 /* If point was outside of the region, restore it exactly; else just
3915 move to the beginning of the region. */
3916 if (old_pos
>= XFASTINT (end
))
3917 old_pos
+= encoded_length
- (XFASTINT (end
) - XFASTINT (beg
));
3918 else if (old_pos
> XFASTINT (beg
))
3919 old_pos
= XFASTINT (beg
);
3922 /* We return the length of the encoded text. */
3923 return make_number (encoded_length
);
3926 DEFUN ("base64-encode-string", Fbase64_encode_string
, Sbase64_encode_string
,
3928 doc
: /* Base64-encode STRING and return the result.
3929 Optional second argument NO-LINE-BREAK means do not break long lines
3930 into shorter lines. */)
3931 (string
, no_line_break
)
3932 Lisp_Object string
, no_line_break
;
3934 int allength
, length
, encoded_length
;
3936 Lisp_Object encoded_string
;
3939 CHECK_STRING (string
);
3941 /* We need to allocate enough room for encoding the text.
3942 We need 33 1/3% more space, plus a newline every 76
3943 characters, and then we round up. */
3944 length
= SBYTES (string
);
3945 allength
= length
+ length
/3 + 1;
3946 allength
+= allength
/ MIME_LINE_LENGTH
+ 1 + 6;
3948 /* We need to allocate enough room for decoding the text. */
3949 SAFE_ALLOCA (encoded
, char *, allength
);
3951 encoded_length
= base64_encode_1 (SDATA (string
),
3952 encoded
, length
, NILP (no_line_break
),
3953 STRING_MULTIBYTE (string
));
3954 if (encoded_length
> allength
)
3957 if (encoded_length
< 0)
3959 /* The encoding wasn't possible. */
3961 error ("Multibyte character in data for base64 encoding");
3964 encoded_string
= make_unibyte_string (encoded
, encoded_length
);
3967 return encoded_string
;
3971 base64_encode_1 (from
, to
, length
, line_break
, multibyte
)
3978 int counter
= 0, i
= 0;
3988 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
3996 /* Wrap line every 76 characters. */
4000 if (counter
< MIME_LINE_LENGTH
/ 4)
4009 /* Process first byte of a triplet. */
4011 *e
++ = base64_value_to_char
[0x3f & c
>> 2];
4012 value
= (0x03 & c
) << 4;
4014 /* Process second byte of a triplet. */
4018 *e
++ = base64_value_to_char
[value
];
4026 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
4034 *e
++ = base64_value_to_char
[value
| (0x0f & c
>> 4)];
4035 value
= (0x0f & c
) << 2;
4037 /* Process third byte of a triplet. */
4041 *e
++ = base64_value_to_char
[value
];
4048 c
= STRING_CHAR_AND_LENGTH (from
+ i
, length
- i
, bytes
);
4056 *e
++ = base64_value_to_char
[value
| (0x03 & c
>> 6)];
4057 *e
++ = base64_value_to_char
[0x3f & c
];
4064 DEFUN ("base64-decode-region", Fbase64_decode_region
, Sbase64_decode_region
,
4066 doc
: /* Base64-decode the region between BEG and END.
4067 Return the length of the decoded text.
4068 If the region can't be decoded, signal an error and don't modify the buffer. */)
4070 Lisp_Object beg
, end
;
4072 int ibeg
, iend
, length
, allength
;
4077 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
4080 validate_region (&beg
, &end
);
4082 ibeg
= CHAR_TO_BYTE (XFASTINT (beg
));
4083 iend
= CHAR_TO_BYTE (XFASTINT (end
));
4085 length
= iend
- ibeg
;
4087 /* We need to allocate enough room for decoding the text. If we are
4088 working on a multibyte buffer, each decoded code may occupy at
4090 allength
= multibyte
? length
* 2 : length
;
4091 SAFE_ALLOCA (decoded
, char *, allength
);
4093 move_gap_both (XFASTINT (beg
), ibeg
);
4094 decoded_length
= base64_decode_1 (BYTE_POS_ADDR (ibeg
), decoded
, length
,
4095 multibyte
, &inserted_chars
);
4096 if (decoded_length
> allength
)
4099 if (decoded_length
< 0)
4101 /* The decoding wasn't possible. */
4103 error ("Invalid base64 data");
4106 /* Now we have decoded the region, so we insert the new contents
4107 and delete the old. (Insert first in order to preserve markers.) */
4108 TEMP_SET_PT_BOTH (XFASTINT (beg
), ibeg
);
4109 insert_1_both (decoded
, inserted_chars
, decoded_length
, 0, 1, 0);
4112 /* Delete the original text. */
4113 del_range_both (PT
, PT_BYTE
, XFASTINT (end
) + inserted_chars
,
4114 iend
+ decoded_length
, 1);
4116 /* If point was outside of the region, restore it exactly; else just
4117 move to the beginning of the region. */
4118 if (old_pos
>= XFASTINT (end
))
4119 old_pos
+= inserted_chars
- (XFASTINT (end
) - XFASTINT (beg
));
4120 else if (old_pos
> XFASTINT (beg
))
4121 old_pos
= XFASTINT (beg
);
4122 SET_PT (old_pos
> ZV
? ZV
: old_pos
);
4124 return make_number (inserted_chars
);
4127 DEFUN ("base64-decode-string", Fbase64_decode_string
, Sbase64_decode_string
,
4129 doc
: /* Base64-decode STRING and return the result. */)
4134 int length
, decoded_length
;
4135 Lisp_Object decoded_string
;
4138 CHECK_STRING (string
);
4140 length
= SBYTES (string
);
4141 /* We need to allocate enough room for decoding the text. */
4142 SAFE_ALLOCA (decoded
, char *, length
);
4144 /* The decoded result should be unibyte. */
4145 decoded_length
= base64_decode_1 (SDATA (string
), decoded
, length
,
4147 if (decoded_length
> length
)
4149 else if (decoded_length
>= 0)
4150 decoded_string
= make_unibyte_string (decoded
, decoded_length
);
4152 decoded_string
= Qnil
;
4155 if (!STRINGP (decoded_string
))
4156 error ("Invalid base64 data");
4158 return decoded_string
;
4161 /* Base64-decode the data at FROM of LENGHT bytes into TO. If
4162 MULTIBYTE is nonzero, the decoded result should be in multibyte
4163 form. If NCHARS_RETRUN is not NULL, store the number of produced
4164 characters in *NCHARS_RETURN. */
4167 base64_decode_1 (from
, to
, length
, multibyte
, nchars_return
)
4177 unsigned long value
;
4182 /* Process first byte of a quadruplet. */
4184 READ_QUADRUPLET_BYTE (e
-to
);
4188 value
= base64_char_to_value
[c
] << 18;
4190 /* Process second byte of a quadruplet. */
4192 READ_QUADRUPLET_BYTE (-1);
4196 value
|= base64_char_to_value
[c
] << 12;
4198 c
= (unsigned char) (value
>> 16);
4200 e
+= CHAR_STRING (c
, e
);
4205 /* Process third byte of a quadruplet. */
4207 READ_QUADRUPLET_BYTE (-1);
4211 READ_QUADRUPLET_BYTE (-1);
4220 value
|= base64_char_to_value
[c
] << 6;
4222 c
= (unsigned char) (0xff & value
>> 8);
4224 e
+= CHAR_STRING (c
, e
);
4229 /* Process fourth byte of a quadruplet. */
4231 READ_QUADRUPLET_BYTE (-1);
4238 value
|= base64_char_to_value
[c
];
4240 c
= (unsigned char) (0xff & value
);
4242 e
+= CHAR_STRING (c
, e
);
4251 /***********************************************************************
4253 ***** Hash Tables *****
4255 ***********************************************************************/
4257 /* Implemented by gerd@gnu.org. This hash table implementation was
4258 inspired by CMUCL hash tables. */
4262 1. For small tables, association lists are probably faster than
4263 hash tables because they have lower overhead.
4265 For uses of hash tables where the O(1) behavior of table
4266 operations is not a requirement, it might therefore be a good idea
4267 not to hash. Instead, we could just do a linear search in the
4268 key_and_value vector of the hash table. This could be done
4269 if a `:linear-search t' argument is given to make-hash-table. */
4272 /* The list of all weak hash tables. Don't staticpro this one. */
4274 struct Lisp_Hash_Table
*weak_hash_tables
;
4276 /* Various symbols. */
4278 Lisp_Object Qhash_table_p
, Qeq
, Qeql
, Qequal
, Qkey
, Qvalue
;
4279 Lisp_Object QCtest
, QCsize
, QCrehash_size
, QCrehash_threshold
, QCweakness
;
4280 Lisp_Object Qhash_table_test
, Qkey_or_value
, Qkey_and_value
;
4282 /* Function prototypes. */
4284 static struct Lisp_Hash_Table
*check_hash_table
P_ ((Lisp_Object
));
4285 static int get_key_arg
P_ ((Lisp_Object
, int, Lisp_Object
*, char *));
4286 static void maybe_resize_hash_table
P_ ((struct Lisp_Hash_Table
*));
4287 static int cmpfn_eql
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
, unsigned,
4288 Lisp_Object
, unsigned));
4289 static int cmpfn_equal
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
, unsigned,
4290 Lisp_Object
, unsigned));
4291 static int cmpfn_user_defined
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
,
4292 unsigned, Lisp_Object
, unsigned));
4293 static unsigned hashfn_eq
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
4294 static unsigned hashfn_eql
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
4295 static unsigned hashfn_equal
P_ ((struct Lisp_Hash_Table
*, Lisp_Object
));
4296 static unsigned hashfn_user_defined
P_ ((struct Lisp_Hash_Table
*,
4298 static unsigned sxhash_string
P_ ((unsigned char *, int));
4299 static unsigned sxhash_list
P_ ((Lisp_Object
, int));
4300 static unsigned sxhash_vector
P_ ((Lisp_Object
, int));
4301 static unsigned sxhash_bool_vector
P_ ((Lisp_Object
));
4302 static int sweep_weak_table
P_ ((struct Lisp_Hash_Table
*, int));
4306 /***********************************************************************
4308 ***********************************************************************/
4310 /* If OBJ is a Lisp hash table, return a pointer to its struct
4311 Lisp_Hash_Table. Otherwise, signal an error. */
4313 static struct Lisp_Hash_Table
*
4314 check_hash_table (obj
)
4317 CHECK_HASH_TABLE (obj
);
4318 return XHASH_TABLE (obj
);
4322 /* Value is the next integer I >= N, N >= 0 which is "almost" a prime
4326 next_almost_prime (n
)
4339 /* Find KEY in ARGS which has size NARGS. Don't consider indices for
4340 which USED[I] is non-zero. If found at index I in ARGS, set
4341 USED[I] and USED[I + 1] to 1, and return I + 1. Otherwise return
4342 -1. This function is used to extract a keyword/argument pair from
4343 a DEFUN parameter list. */
4346 get_key_arg (key
, nargs
, args
, used
)
4354 for (i
= 0; i
< nargs
- 1; ++i
)
4355 if (!used
[i
] && EQ (args
[i
], key
))
4370 /* Return a Lisp vector which has the same contents as VEC but has
4371 size NEW_SIZE, NEW_SIZE >= VEC->size. Entries in the resulting
4372 vector that are not copied from VEC are set to INIT. */
4375 larger_vector (vec
, new_size
, init
)
4380 struct Lisp_Vector
*v
;
4383 xassert (VECTORP (vec
));
4384 old_size
= ASIZE (vec
);
4385 xassert (new_size
>= old_size
);
4387 v
= allocate_vector (new_size
);
4388 bcopy (XVECTOR (vec
)->contents
, v
->contents
,
4389 old_size
* sizeof *v
->contents
);
4390 for (i
= old_size
; i
< new_size
; ++i
)
4391 v
->contents
[i
] = init
;
4392 XSETVECTOR (vec
, v
);
4397 /***********************************************************************
4399 ***********************************************************************/
4401 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
4402 HASH2 in hash table H using `eql'. Value is non-zero if KEY1 and
4403 KEY2 are the same. */
4406 cmpfn_eql (h
, key1
, hash1
, key2
, hash2
)
4407 struct Lisp_Hash_Table
*h
;
4408 Lisp_Object key1
, key2
;
4409 unsigned hash1
, hash2
;
4411 return (FLOATP (key1
)
4413 && XFLOAT_DATA (key1
) == XFLOAT_DATA (key2
));
4417 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
4418 HASH2 in hash table H using `equal'. Value is non-zero if KEY1 and
4419 KEY2 are the same. */
4422 cmpfn_equal (h
, key1
, hash1
, key2
, hash2
)
4423 struct Lisp_Hash_Table
*h
;
4424 Lisp_Object key1
, key2
;
4425 unsigned hash1
, hash2
;
4427 return hash1
== hash2
&& !NILP (Fequal (key1
, key2
));
4431 /* Compare KEY1 which has hash code HASH1, and KEY2 with hash code
4432 HASH2 in hash table H using H->user_cmp_function. Value is non-zero
4433 if KEY1 and KEY2 are the same. */
4436 cmpfn_user_defined (h
, key1
, hash1
, key2
, hash2
)
4437 struct Lisp_Hash_Table
*h
;
4438 Lisp_Object key1
, key2
;
4439 unsigned hash1
, hash2
;
4443 Lisp_Object args
[3];
4445 args
[0] = h
->user_cmp_function
;
4448 return !NILP (Ffuncall (3, args
));
4455 /* Value is a hash code for KEY for use in hash table H which uses
4456 `eq' to compare keys. The hash code returned is guaranteed to fit
4457 in a Lisp integer. */
4461 struct Lisp_Hash_Table
*h
;
4464 unsigned hash
= XUINT (key
) ^ XGCTYPE (key
);
4465 xassert ((hash
& ~INTMASK
) == 0);
4470 /* Value is a hash code for KEY for use in hash table H which uses
4471 `eql' to compare keys. The hash code returned is guaranteed to fit
4472 in a Lisp integer. */
4476 struct Lisp_Hash_Table
*h
;
4481 hash
= sxhash (key
, 0);
4483 hash
= XUINT (key
) ^ XGCTYPE (key
);
4484 xassert ((hash
& ~INTMASK
) == 0);
4489 /* Value is a hash code for KEY for use in hash table H which uses
4490 `equal' to compare keys. The hash code returned is guaranteed to fit
4491 in a Lisp integer. */
4494 hashfn_equal (h
, key
)
4495 struct Lisp_Hash_Table
*h
;
4498 unsigned hash
= sxhash (key
, 0);
4499 xassert ((hash
& ~INTMASK
) == 0);
4504 /* Value is a hash code for KEY for use in hash table H which uses as
4505 user-defined function to compare keys. The hash code returned is
4506 guaranteed to fit in a Lisp integer. */
4509 hashfn_user_defined (h
, key
)
4510 struct Lisp_Hash_Table
*h
;
4513 Lisp_Object args
[2], hash
;
4515 args
[0] = h
->user_hash_function
;
4517 hash
= Ffuncall (2, args
);
4518 if (!INTEGERP (hash
))
4519 signal_error ("Invalid hash code returned from user-supplied hash function", hash
);
4520 return XUINT (hash
);
4524 /* Create and initialize a new hash table.
4526 TEST specifies the test the hash table will use to compare keys.
4527 It must be either one of the predefined tests `eq', `eql' or
4528 `equal' or a symbol denoting a user-defined test named TEST with
4529 test and hash functions USER_TEST and USER_HASH.
4531 Give the table initial capacity SIZE, SIZE >= 0, an integer.
4533 If REHASH_SIZE is an integer, it must be > 0, and this hash table's
4534 new size when it becomes full is computed by adding REHASH_SIZE to
4535 its old size. If REHASH_SIZE is a float, it must be > 1.0, and the
4536 table's new size is computed by multiplying its old size with
4539 REHASH_THRESHOLD must be a float <= 1.0, and > 0. The table will
4540 be resized when the ratio of (number of entries in the table) /
4541 (table size) is >= REHASH_THRESHOLD.
4543 WEAK specifies the weakness of the table. If non-nil, it must be
4544 one of the symbols `key', `value', `key-or-value', or `key-and-value'. */
4547 make_hash_table (test
, size
, rehash_size
, rehash_threshold
, weak
,
4548 user_test
, user_hash
)
4549 Lisp_Object test
, size
, rehash_size
, rehash_threshold
, weak
;
4550 Lisp_Object user_test
, user_hash
;
4552 struct Lisp_Hash_Table
*h
;
4554 int index_size
, i
, sz
;
4556 /* Preconditions. */
4557 xassert (SYMBOLP (test
));
4558 xassert (INTEGERP (size
) && XINT (size
) >= 0);
4559 xassert ((INTEGERP (rehash_size
) && XINT (rehash_size
) > 0)
4560 || (FLOATP (rehash_size
) && XFLOATINT (rehash_size
) > 1.0));
4561 xassert (FLOATP (rehash_threshold
)
4562 && XFLOATINT (rehash_threshold
) > 0
4563 && XFLOATINT (rehash_threshold
) <= 1.0);
4565 if (XFASTINT (size
) == 0)
4566 size
= make_number (1);
4568 /* Allocate a table and initialize it. */
4569 h
= allocate_hash_table ();
4571 /* Initialize hash table slots. */
4572 sz
= XFASTINT (size
);
4575 if (EQ (test
, Qeql
))
4577 h
->cmpfn
= cmpfn_eql
;
4578 h
->hashfn
= hashfn_eql
;
4580 else if (EQ (test
, Qeq
))
4583 h
->hashfn
= hashfn_eq
;
4585 else if (EQ (test
, Qequal
))
4587 h
->cmpfn
= cmpfn_equal
;
4588 h
->hashfn
= hashfn_equal
;
4592 h
->user_cmp_function
= user_test
;
4593 h
->user_hash_function
= user_hash
;
4594 h
->cmpfn
= cmpfn_user_defined
;
4595 h
->hashfn
= hashfn_user_defined
;
4599 h
->rehash_threshold
= rehash_threshold
;
4600 h
->rehash_size
= rehash_size
;
4601 h
->count
= make_number (0);
4602 h
->key_and_value
= Fmake_vector (make_number (2 * sz
), Qnil
);
4603 h
->hash
= Fmake_vector (size
, Qnil
);
4604 h
->next
= Fmake_vector (size
, Qnil
);
4605 /* Cast to int here avoids losing with gcc 2.95 on Tru64/Alpha... */
4606 index_size
= next_almost_prime ((int) (sz
/ XFLOATINT (rehash_threshold
)));
4607 h
->index
= Fmake_vector (make_number (index_size
), Qnil
);
4609 /* Set up the free list. */
4610 for (i
= 0; i
< sz
- 1; ++i
)
4611 HASH_NEXT (h
, i
) = make_number (i
+ 1);
4612 h
->next_free
= make_number (0);
4614 XSET_HASH_TABLE (table
, h
);
4615 xassert (HASH_TABLE_P (table
));
4616 xassert (XHASH_TABLE (table
) == h
);
4618 /* Maybe add this hash table to the list of all weak hash tables. */
4620 h
->next_weak
= NULL
;
4623 h
->next_weak
= weak_hash_tables
;
4624 weak_hash_tables
= h
;
4631 /* Return a copy of hash table H1. Keys and values are not copied,
4632 only the table itself is. */
4635 copy_hash_table (h1
)
4636 struct Lisp_Hash_Table
*h1
;
4639 struct Lisp_Hash_Table
*h2
;
4640 struct Lisp_Vector
*next
;
4642 h2
= allocate_hash_table ();
4643 next
= h2
->vec_next
;
4644 bcopy (h1
, h2
, sizeof *h2
);
4645 h2
->vec_next
= next
;
4646 h2
->key_and_value
= Fcopy_sequence (h1
->key_and_value
);
4647 h2
->hash
= Fcopy_sequence (h1
->hash
);
4648 h2
->next
= Fcopy_sequence (h1
->next
);
4649 h2
->index
= Fcopy_sequence (h1
->index
);
4650 XSET_HASH_TABLE (table
, h2
);
4652 /* Maybe add this hash table to the list of all weak hash tables. */
4653 if (!NILP (h2
->weak
))
4655 h2
->next_weak
= weak_hash_tables
;
4656 weak_hash_tables
= h2
;
4663 /* Resize hash table H if it's too full. If H cannot be resized
4664 because it's already too large, throw an error. */
4667 maybe_resize_hash_table (h
)
4668 struct Lisp_Hash_Table
*h
;
4670 if (NILP (h
->next_free
))
4672 int old_size
= HASH_TABLE_SIZE (h
);
4673 int i
, new_size
, index_size
;
4676 if (INTEGERP (h
->rehash_size
))
4677 new_size
= old_size
+ XFASTINT (h
->rehash_size
);
4679 new_size
= old_size
* XFLOATINT (h
->rehash_size
);
4680 new_size
= max (old_size
+ 1, new_size
);
4681 index_size
= next_almost_prime ((int)
4683 / XFLOATINT (h
->rehash_threshold
)));
4684 /* Assignment to EMACS_INT stops GCC whining about limited range
4686 nsize
= max (index_size
, 2 * new_size
);
4687 if (nsize
> MOST_POSITIVE_FIXNUM
)
4688 error ("Hash table too large to resize");
4690 h
->key_and_value
= larger_vector (h
->key_and_value
, 2 * new_size
, Qnil
);
4691 h
->next
= larger_vector (h
->next
, new_size
, Qnil
);
4692 h
->hash
= larger_vector (h
->hash
, new_size
, Qnil
);
4693 h
->index
= Fmake_vector (make_number (index_size
), Qnil
);
4695 /* Update the free list. Do it so that new entries are added at
4696 the end of the free list. This makes some operations like
4698 for (i
= old_size
; i
< new_size
- 1; ++i
)
4699 HASH_NEXT (h
, i
) = make_number (i
+ 1);
4701 if (!NILP (h
->next_free
))
4703 Lisp_Object last
, next
;
4705 last
= h
->next_free
;
4706 while (next
= HASH_NEXT (h
, XFASTINT (last
)),
4710 HASH_NEXT (h
, XFASTINT (last
)) = make_number (old_size
);
4713 XSETFASTINT (h
->next_free
, old_size
);
4716 for (i
= 0; i
< old_size
; ++i
)
4717 if (!NILP (HASH_HASH (h
, i
)))
4719 unsigned hash_code
= XUINT (HASH_HASH (h
, i
));
4720 int start_of_bucket
= hash_code
% ASIZE (h
->index
);
4721 HASH_NEXT (h
, i
) = HASH_INDEX (h
, start_of_bucket
);
4722 HASH_INDEX (h
, start_of_bucket
) = make_number (i
);
4728 /* Lookup KEY in hash table H. If HASH is non-null, return in *HASH
4729 the hash code of KEY. Value is the index of the entry in H
4730 matching KEY, or -1 if not found. */
4733 hash_lookup (h
, key
, hash
)
4734 struct Lisp_Hash_Table
*h
;
4739 int start_of_bucket
;
4742 hash_code
= h
->hashfn (h
, key
);
4746 start_of_bucket
= hash_code
% ASIZE (h
->index
);
4747 idx
= HASH_INDEX (h
, start_of_bucket
);
4749 /* We need not gcpro idx since it's either an integer or nil. */
4752 int i
= XFASTINT (idx
);
4753 if (EQ (key
, HASH_KEY (h
, i
))
4755 && h
->cmpfn (h
, key
, hash_code
,
4756 HASH_KEY (h
, i
), XUINT (HASH_HASH (h
, i
)))))
4758 idx
= HASH_NEXT (h
, i
);
4761 return NILP (idx
) ? -1 : XFASTINT (idx
);
4765 /* Put an entry into hash table H that associates KEY with VALUE.
4766 HASH is a previously computed hash code of KEY.
4767 Value is the index of the entry in H matching KEY. */
4770 hash_put (h
, key
, value
, hash
)
4771 struct Lisp_Hash_Table
*h
;
4772 Lisp_Object key
, value
;
4775 int start_of_bucket
, i
;
4777 xassert ((hash
& ~INTMASK
) == 0);
4779 /* Increment count after resizing because resizing may fail. */
4780 maybe_resize_hash_table (h
);
4781 h
->count
= make_number (XFASTINT (h
->count
) + 1);
4783 /* Store key/value in the key_and_value vector. */
4784 i
= XFASTINT (h
->next_free
);
4785 h
->next_free
= HASH_NEXT (h
, i
);
4786 HASH_KEY (h
, i
) = key
;
4787 HASH_VALUE (h
, i
) = value
;
4789 /* Remember its hash code. */
4790 HASH_HASH (h
, i
) = make_number (hash
);
4792 /* Add new entry to its collision chain. */
4793 start_of_bucket
= hash
% ASIZE (h
->index
);
4794 HASH_NEXT (h
, i
) = HASH_INDEX (h
, start_of_bucket
);
4795 HASH_INDEX (h
, start_of_bucket
) = make_number (i
);
4800 /* Remove the entry matching KEY from hash table H, if there is one. */
4803 hash_remove (h
, key
)
4804 struct Lisp_Hash_Table
*h
;
4808 int start_of_bucket
;
4809 Lisp_Object idx
, prev
;
4811 hash_code
= h
->hashfn (h
, key
);
4812 start_of_bucket
= hash_code
% ASIZE (h
->index
);
4813 idx
= HASH_INDEX (h
, start_of_bucket
);
4816 /* We need not gcpro idx, prev since they're either integers or nil. */
4819 int i
= XFASTINT (idx
);
4821 if (EQ (key
, HASH_KEY (h
, i
))
4823 && h
->cmpfn (h
, key
, hash_code
,
4824 HASH_KEY (h
, i
), XUINT (HASH_HASH (h
, i
)))))
4826 /* Take entry out of collision chain. */
4828 HASH_INDEX (h
, start_of_bucket
) = HASH_NEXT (h
, i
);
4830 HASH_NEXT (h
, XFASTINT (prev
)) = HASH_NEXT (h
, i
);
4832 /* Clear slots in key_and_value and add the slots to
4834 HASH_KEY (h
, i
) = HASH_VALUE (h
, i
) = HASH_HASH (h
, i
) = Qnil
;
4835 HASH_NEXT (h
, i
) = h
->next_free
;
4836 h
->next_free
= make_number (i
);
4837 h
->count
= make_number (XFASTINT (h
->count
) - 1);
4838 xassert (XINT (h
->count
) >= 0);
4844 idx
= HASH_NEXT (h
, i
);
4850 /* Clear hash table H. */
4854 struct Lisp_Hash_Table
*h
;
4856 if (XFASTINT (h
->count
) > 0)
4858 int i
, size
= HASH_TABLE_SIZE (h
);
4860 for (i
= 0; i
< size
; ++i
)
4862 HASH_NEXT (h
, i
) = i
< size
- 1 ? make_number (i
+ 1) : Qnil
;
4863 HASH_KEY (h
, i
) = Qnil
;
4864 HASH_VALUE (h
, i
) = Qnil
;
4865 HASH_HASH (h
, i
) = Qnil
;
4868 for (i
= 0; i
< ASIZE (h
->index
); ++i
)
4869 AREF (h
->index
, i
) = Qnil
;
4871 h
->next_free
= make_number (0);
4872 h
->count
= make_number (0);
4878 /************************************************************************
4880 ************************************************************************/
4882 /* Sweep weak hash table H. REMOVE_ENTRIES_P non-zero means remove
4883 entries from the table that don't survive the current GC.
4884 REMOVE_ENTRIES_P zero means mark entries that are in use. Value is
4885 non-zero if anything was marked. */
4888 sweep_weak_table (h
, remove_entries_p
)
4889 struct Lisp_Hash_Table
*h
;
4890 int remove_entries_p
;
4892 int bucket
, n
, marked
;
4894 n
= ASIZE (h
->index
) & ~ARRAY_MARK_FLAG
;
4897 for (bucket
= 0; bucket
< n
; ++bucket
)
4899 Lisp_Object idx
, next
, prev
;
4901 /* Follow collision chain, removing entries that
4902 don't survive this garbage collection. */
4904 for (idx
= HASH_INDEX (h
, bucket
); !GC_NILP (idx
); idx
= next
)
4906 int i
= XFASTINT (idx
);
4907 int key_known_to_survive_p
= survives_gc_p (HASH_KEY (h
, i
));
4908 int value_known_to_survive_p
= survives_gc_p (HASH_VALUE (h
, i
));
4911 if (EQ (h
->weak
, Qkey
))
4912 remove_p
= !key_known_to_survive_p
;
4913 else if (EQ (h
->weak
, Qvalue
))
4914 remove_p
= !value_known_to_survive_p
;
4915 else if (EQ (h
->weak
, Qkey_or_value
))
4916 remove_p
= !(key_known_to_survive_p
|| value_known_to_survive_p
);
4917 else if (EQ (h
->weak
, Qkey_and_value
))
4918 remove_p
= !(key_known_to_survive_p
&& value_known_to_survive_p
);
4922 next
= HASH_NEXT (h
, i
);
4924 if (remove_entries_p
)
4928 /* Take out of collision chain. */
4930 HASH_INDEX (h
, bucket
) = next
;
4932 HASH_NEXT (h
, XFASTINT (prev
)) = next
;
4934 /* Add to free list. */
4935 HASH_NEXT (h
, i
) = h
->next_free
;
4938 /* Clear key, value, and hash. */
4939 HASH_KEY (h
, i
) = HASH_VALUE (h
, i
) = Qnil
;
4940 HASH_HASH (h
, i
) = Qnil
;
4942 h
->count
= make_number (XFASTINT (h
->count
) - 1);
4953 /* Make sure key and value survive. */
4954 if (!key_known_to_survive_p
)
4956 mark_object (HASH_KEY (h
, i
));
4960 if (!value_known_to_survive_p
)
4962 mark_object (HASH_VALUE (h
, i
));
4973 /* Remove elements from weak hash tables that don't survive the
4974 current garbage collection. Remove weak tables that don't survive
4975 from weak_hash_tables. Called from gc_sweep. */
4978 sweep_weak_hash_tables ()
4980 struct Lisp_Hash_Table
*h
, *used
, *next
;
4983 /* Mark all keys and values that are in use. Keep on marking until
4984 there is no more change. This is necessary for cases like
4985 value-weak table A containing an entry X -> Y, where Y is used in a
4986 key-weak table B, Z -> Y. If B comes after A in the list of weak
4987 tables, X -> Y might be removed from A, although when looking at B
4988 one finds that it shouldn't. */
4992 for (h
= weak_hash_tables
; h
; h
= h
->next_weak
)
4994 if (h
->size
& ARRAY_MARK_FLAG
)
4995 marked
|= sweep_weak_table (h
, 0);
5000 /* Remove tables and entries that aren't used. */
5001 for (h
= weak_hash_tables
, used
= NULL
; h
; h
= next
)
5003 next
= h
->next_weak
;
5005 if (h
->size
& ARRAY_MARK_FLAG
)
5007 /* TABLE is marked as used. Sweep its contents. */
5008 if (XFASTINT (h
->count
) > 0)
5009 sweep_weak_table (h
, 1);
5011 /* Add table to the list of used weak hash tables. */
5012 h
->next_weak
= used
;
5017 weak_hash_tables
= used
;
5022 /***********************************************************************
5023 Hash Code Computation
5024 ***********************************************************************/
5026 /* Maximum depth up to which to dive into Lisp structures. */
5028 #define SXHASH_MAX_DEPTH 3
5030 /* Maximum length up to which to take list and vector elements into
5033 #define SXHASH_MAX_LEN 7
5035 /* Combine two integers X and Y for hashing. */
5037 #define SXHASH_COMBINE(X, Y) \
5038 ((((unsigned)(X) << 4) + (((unsigned)(X) >> 24) & 0x0fffffff)) \
5042 /* Return a hash for string PTR which has length LEN. The hash
5043 code returned is guaranteed to fit in a Lisp integer. */
5046 sxhash_string (ptr
, len
)
5050 unsigned char *p
= ptr
;
5051 unsigned char *end
= p
+ len
;
5060 hash
= ((hash
<< 4) + (hash
>> 28) + c
);
5063 return hash
& INTMASK
;
5067 /* Return a hash for list LIST. DEPTH is the current depth in the
5068 list. We don't recurse deeper than SXHASH_MAX_DEPTH in it. */
5071 sxhash_list (list
, depth
)
5078 if (depth
< SXHASH_MAX_DEPTH
)
5080 CONSP (list
) && i
< SXHASH_MAX_LEN
;
5081 list
= XCDR (list
), ++i
)
5083 unsigned hash2
= sxhash (XCAR (list
), depth
+ 1);
5084 hash
= SXHASH_COMBINE (hash
, hash2
);
5089 unsigned hash2
= sxhash (list
, depth
+ 1);
5090 hash
= SXHASH_COMBINE (hash
, hash2
);
5097 /* Return a hash for vector VECTOR. DEPTH is the current depth in
5098 the Lisp structure. */
5101 sxhash_vector (vec
, depth
)
5105 unsigned hash
= ASIZE (vec
);
5108 n
= min (SXHASH_MAX_LEN
, ASIZE (vec
));
5109 for (i
= 0; i
< n
; ++i
)
5111 unsigned hash2
= sxhash (AREF (vec
, i
), depth
+ 1);
5112 hash
= SXHASH_COMBINE (hash
, hash2
);
5119 /* Return a hash for bool-vector VECTOR. */
5122 sxhash_bool_vector (vec
)
5125 unsigned hash
= XBOOL_VECTOR (vec
)->size
;
5128 n
= min (SXHASH_MAX_LEN
, XBOOL_VECTOR (vec
)->vector_size
);
5129 for (i
= 0; i
< n
; ++i
)
5130 hash
= SXHASH_COMBINE (hash
, XBOOL_VECTOR (vec
)->data
[i
]);
5136 /* Return a hash code for OBJ. DEPTH is the current depth in the Lisp
5137 structure. Value is an unsigned integer clipped to INTMASK. */
5146 if (depth
> SXHASH_MAX_DEPTH
)
5149 switch (XTYPE (obj
))
5160 obj
= SYMBOL_NAME (obj
);
5164 hash
= sxhash_string (SDATA (obj
), SCHARS (obj
));
5167 /* This can be everything from a vector to an overlay. */
5168 case Lisp_Vectorlike
:
5170 /* According to the CL HyperSpec, two arrays are equal only if
5171 they are `eq', except for strings and bit-vectors. In
5172 Emacs, this works differently. We have to compare element
5174 hash
= sxhash_vector (obj
, depth
);
5175 else if (BOOL_VECTOR_P (obj
))
5176 hash
= sxhash_bool_vector (obj
);
5178 /* Others are `equal' if they are `eq', so let's take their
5184 hash
= sxhash_list (obj
, depth
);
5189 unsigned char *p
= (unsigned char *) &XFLOAT_DATA (obj
);
5190 unsigned char *e
= p
+ sizeof XFLOAT_DATA (obj
);
5191 for (hash
= 0; p
< e
; ++p
)
5192 hash
= SXHASH_COMBINE (hash
, *p
);
5200 return hash
& INTMASK
;
5205 /***********************************************************************
5207 ***********************************************************************/
5210 DEFUN ("sxhash", Fsxhash
, Ssxhash
, 1, 1, 0,
5211 doc
: /* Compute a hash code for OBJ and return it as integer. */)
5215 unsigned hash
= sxhash (obj
, 0);
5216 return make_number (hash
);
5220 DEFUN ("make-hash-table", Fmake_hash_table
, Smake_hash_table
, 0, MANY
, 0,
5221 doc
: /* Create and return a new hash table.
5223 Arguments are specified as keyword/argument pairs. The following
5224 arguments are defined:
5226 :test TEST -- TEST must be a symbol that specifies how to compare
5227 keys. Default is `eql'. Predefined are the tests `eq', `eql', and
5228 `equal'. User-supplied test and hash functions can be specified via
5229 `define-hash-table-test'.
5231 :size SIZE -- A hint as to how many elements will be put in the table.
5234 :rehash-size REHASH-SIZE - Indicates how to expand the table when it
5235 fills up. If REHASH-SIZE is an integer, add that many space. If it
5236 is a float, it must be > 1.0, and the new size is computed by
5237 multiplying the old size with that factor. Default is 1.5.
5239 :rehash-threshold THRESHOLD -- THRESHOLD must a float > 0, and <= 1.0.
5240 Resize the hash table when ratio of the number of entries in the
5241 table. Default is 0.8.
5243 :weakness WEAK -- WEAK must be one of nil, t, `key', `value',
5244 `key-or-value', or `key-and-value'. If WEAK is not nil, the table
5245 returned is a weak table. Key/value pairs are removed from a weak
5246 hash table when there are no non-weak references pointing to their
5247 key, value, one of key or value, or both key and value, depending on
5248 WEAK. WEAK t is equivalent to `key-and-value'. Default value of WEAK
5251 usage: (make-hash-table &rest KEYWORD-ARGS) */)
5256 Lisp_Object test
, size
, rehash_size
, rehash_threshold
, weak
;
5257 Lisp_Object user_test
, user_hash
;
5261 /* The vector `used' is used to keep track of arguments that
5262 have been consumed. */
5263 used
= (char *) alloca (nargs
* sizeof *used
);
5264 bzero (used
, nargs
* sizeof *used
);
5266 /* See if there's a `:test TEST' among the arguments. */
5267 i
= get_key_arg (QCtest
, nargs
, args
, used
);
5268 test
= i
< 0 ? Qeql
: args
[i
];
5269 if (!EQ (test
, Qeq
) && !EQ (test
, Qeql
) && !EQ (test
, Qequal
))
5271 /* See if it is a user-defined test. */
5274 prop
= Fget (test
, Qhash_table_test
);
5275 if (!CONSP (prop
) || !CONSP (XCDR (prop
)))
5276 signal_error ("Invalid hash table test", test
);
5277 user_test
= XCAR (prop
);
5278 user_hash
= XCAR (XCDR (prop
));
5281 user_test
= user_hash
= Qnil
;
5283 /* See if there's a `:size SIZE' argument. */
5284 i
= get_key_arg (QCsize
, nargs
, args
, used
);
5285 size
= i
< 0 ? Qnil
: args
[i
];
5287 size
= make_number (DEFAULT_HASH_SIZE
);
5288 else if (!INTEGERP (size
) || XINT (size
) < 0)
5289 signal_error ("Invalid hash table size", size
);
5291 /* Look for `:rehash-size SIZE'. */
5292 i
= get_key_arg (QCrehash_size
, nargs
, args
, used
);
5293 rehash_size
= i
< 0 ? make_float (DEFAULT_REHASH_SIZE
) : args
[i
];
5294 if (!NUMBERP (rehash_size
)
5295 || (INTEGERP (rehash_size
) && XINT (rehash_size
) <= 0)
5296 || XFLOATINT (rehash_size
) <= 1.0)
5297 signal_error ("Invalid hash table rehash size", rehash_size
);
5299 /* Look for `:rehash-threshold THRESHOLD'. */
5300 i
= get_key_arg (QCrehash_threshold
, nargs
, args
, used
);
5301 rehash_threshold
= i
< 0 ? make_float (DEFAULT_REHASH_THRESHOLD
) : args
[i
];
5302 if (!FLOATP (rehash_threshold
)
5303 || XFLOATINT (rehash_threshold
) <= 0.0
5304 || XFLOATINT (rehash_threshold
) > 1.0)
5305 signal_error ("Invalid hash table rehash threshold", rehash_threshold
);
5307 /* Look for `:weakness WEAK'. */
5308 i
= get_key_arg (QCweakness
, nargs
, args
, used
);
5309 weak
= i
< 0 ? Qnil
: args
[i
];
5311 weak
= Qkey_and_value
;
5314 && !EQ (weak
, Qvalue
)
5315 && !EQ (weak
, Qkey_or_value
)
5316 && !EQ (weak
, Qkey_and_value
))
5317 signal_error ("Invalid hash table weakness", weak
);
5319 /* Now, all args should have been used up, or there's a problem. */
5320 for (i
= 0; i
< nargs
; ++i
)
5322 signal_error ("Invalid argument list", args
[i
]);
5324 return make_hash_table (test
, size
, rehash_size
, rehash_threshold
, weak
,
5325 user_test
, user_hash
);
5329 DEFUN ("copy-hash-table", Fcopy_hash_table
, Scopy_hash_table
, 1, 1, 0,
5330 doc
: /* Return a copy of hash table TABLE. */)
5334 return copy_hash_table (check_hash_table (table
));
5338 DEFUN ("hash-table-count", Fhash_table_count
, Shash_table_count
, 1, 1, 0,
5339 doc
: /* Return the number of elements in TABLE. */)
5343 return check_hash_table (table
)->count
;
5347 DEFUN ("hash-table-rehash-size", Fhash_table_rehash_size
,
5348 Shash_table_rehash_size
, 1, 1, 0,
5349 doc
: /* Return the current rehash size of TABLE. */)
5353 return check_hash_table (table
)->rehash_size
;
5357 DEFUN ("hash-table-rehash-threshold", Fhash_table_rehash_threshold
,
5358 Shash_table_rehash_threshold
, 1, 1, 0,
5359 doc
: /* Return the current rehash threshold of TABLE. */)
5363 return check_hash_table (table
)->rehash_threshold
;
5367 DEFUN ("hash-table-size", Fhash_table_size
, Shash_table_size
, 1, 1, 0,
5368 doc
: /* Return the size of TABLE.
5369 The size can be used as an argument to `make-hash-table' to create
5370 a hash table than can hold as many elements of TABLE holds
5371 without need for resizing. */)
5375 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
5376 return make_number (HASH_TABLE_SIZE (h
));
5380 DEFUN ("hash-table-test", Fhash_table_test
, Shash_table_test
, 1, 1, 0,
5381 doc
: /* Return the test TABLE uses. */)
5385 return check_hash_table (table
)->test
;
5389 DEFUN ("hash-table-weakness", Fhash_table_weakness
, Shash_table_weakness
,
5391 doc
: /* Return the weakness of TABLE. */)
5395 return check_hash_table (table
)->weak
;
5399 DEFUN ("hash-table-p", Fhash_table_p
, Shash_table_p
, 1, 1, 0,
5400 doc
: /* Return t if OBJ is a Lisp hash table object. */)
5404 return HASH_TABLE_P (obj
) ? Qt
: Qnil
;
5408 DEFUN ("clrhash", Fclrhash
, Sclrhash
, 1, 1, 0,
5409 doc
: /* Clear hash table TABLE. */)
5413 hash_clear (check_hash_table (table
));
5418 DEFUN ("gethash", Fgethash
, Sgethash
, 2, 3, 0,
5419 doc
: /* Look up KEY in TABLE and return its associated value.
5420 If KEY is not found, return DFLT which defaults to nil. */)
5422 Lisp_Object key
, table
, dflt
;
5424 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
5425 int i
= hash_lookup (h
, key
, NULL
);
5426 return i
>= 0 ? HASH_VALUE (h
, i
) : dflt
;
5430 DEFUN ("puthash", Fputhash
, Sputhash
, 3, 3, 0,
5431 doc
: /* Associate KEY with VALUE in hash table TABLE.
5432 If KEY is already present in table, replace its current value with
5435 Lisp_Object key
, value
, table
;
5437 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
5441 i
= hash_lookup (h
, key
, &hash
);
5443 HASH_VALUE (h
, i
) = value
;
5445 hash_put (h
, key
, value
, hash
);
5451 DEFUN ("remhash", Fremhash
, Sremhash
, 2, 2, 0,
5452 doc
: /* Remove KEY from TABLE. */)
5454 Lisp_Object key
, table
;
5456 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
5457 hash_remove (h
, key
);
5462 DEFUN ("maphash", Fmaphash
, Smaphash
, 2, 2, 0,
5463 doc
: /* Call FUNCTION for all entries in hash table TABLE.
5464 FUNCTION is called with two arguments, KEY and VALUE. */)
5466 Lisp_Object function
, table
;
5468 struct Lisp_Hash_Table
*h
= check_hash_table (table
);
5469 Lisp_Object args
[3];
5472 for (i
= 0; i
< HASH_TABLE_SIZE (h
); ++i
)
5473 if (!NILP (HASH_HASH (h
, i
)))
5476 args
[1] = HASH_KEY (h
, i
);
5477 args
[2] = HASH_VALUE (h
, i
);
5485 DEFUN ("define-hash-table-test", Fdefine_hash_table_test
,
5486 Sdefine_hash_table_test
, 3, 3, 0,
5487 doc
: /* Define a new hash table test with name NAME, a symbol.
5489 In hash tables created with NAME specified as test, use TEST to
5490 compare keys, and HASH for computing hash codes of keys.
5492 TEST must be a function taking two arguments and returning non-nil if
5493 both arguments are the same. HASH must be a function taking one
5494 argument and return an integer that is the hash code of the argument.
5495 Hash code computation should use the whole value range of integers,
5496 including negative integers. */)
5498 Lisp_Object name
, test
, hash
;
5500 return Fput (name
, Qhash_table_test
, list2 (test
, hash
));
5505 /************************************************************************
5507 ************************************************************************/
5512 DEFUN ("md5", Fmd5
, Smd5
, 1, 5, 0,
5513 doc
: /* Return MD5 message digest of OBJECT, a buffer or string.
5515 A message digest is a cryptographic checksum of a document, and the
5516 algorithm to calculate it is defined in RFC 1321.
5518 The two optional arguments START and END are character positions
5519 specifying for which part of OBJECT the message digest should be
5520 computed. If nil or omitted, the digest is computed for the whole
5523 The MD5 message digest is computed from the result of encoding the
5524 text in a coding system, not directly from the internal Emacs form of
5525 the text. The optional fourth argument CODING-SYSTEM specifies which
5526 coding system to encode the text with. It should be the same coding
5527 system that you used or will use when actually writing the text into a
5530 If CODING-SYSTEM is nil or omitted, the default depends on OBJECT. If
5531 OBJECT is a buffer, the default for CODING-SYSTEM is whatever coding
5532 system would be chosen by default for writing this text into a file.
5534 If OBJECT is a string, the most preferred coding system (see the
5535 command `prefer-coding-system') is used.
5537 If NOERROR is non-nil, silently assume the `raw-text' coding if the
5538 guesswork fails. Normally, an error is signaled in such case. */)
5539 (object
, start
, end
, coding_system
, noerror
)
5540 Lisp_Object object
, start
, end
, coding_system
, noerror
;
5542 unsigned char digest
[16];
5543 unsigned char value
[33];
5547 int start_char
= 0, end_char
= 0;
5548 int start_byte
= 0, end_byte
= 0;
5550 register struct buffer
*bp
;
5553 if (STRINGP (object
))
5555 if (NILP (coding_system
))
5557 /* Decide the coding-system to encode the data with. */
5559 if (STRING_MULTIBYTE (object
))
5560 /* use default, we can't guess correct value */
5561 coding_system
= SYMBOL_VALUE (XCAR (Vcoding_category_list
));
5563 coding_system
= Qraw_text
;
5566 if (NILP (Fcoding_system_p (coding_system
)))
5568 /* Invalid coding system. */
5570 if (!NILP (noerror
))
5571 coding_system
= Qraw_text
;
5573 xsignal1 (Qcoding_system_error
, coding_system
);
5576 if (STRING_MULTIBYTE (object
))
5577 object
= code_convert_string1 (object
, coding_system
, Qnil
, 1);
5579 size
= SCHARS (object
);
5580 size_byte
= SBYTES (object
);
5584 CHECK_NUMBER (start
);
5586 start_char
= XINT (start
);
5591 start_byte
= string_char_to_byte (object
, start_char
);
5597 end_byte
= size_byte
;
5603 end_char
= XINT (end
);
5608 end_byte
= string_char_to_byte (object
, end_char
);
5611 if (!(0 <= start_char
&& start_char
<= end_char
&& end_char
<= size
))
5612 args_out_of_range_3 (object
, make_number (start_char
),
5613 make_number (end_char
));
5617 struct buffer
*prev
= current_buffer
;
5619 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5621 CHECK_BUFFER (object
);
5623 bp
= XBUFFER (object
);
5624 if (bp
!= current_buffer
)
5625 set_buffer_internal (bp
);
5631 CHECK_NUMBER_COERCE_MARKER (start
);
5639 CHECK_NUMBER_COERCE_MARKER (end
);
5644 temp
= b
, b
= e
, e
= temp
;
5646 if (!(BEGV
<= b
&& e
<= ZV
))
5647 args_out_of_range (start
, end
);
5649 if (NILP (coding_system
))
5651 /* Decide the coding-system to encode the data with.
5652 See fileio.c:Fwrite-region */
5654 if (!NILP (Vcoding_system_for_write
))
5655 coding_system
= Vcoding_system_for_write
;
5658 int force_raw_text
= 0;
5660 coding_system
= XBUFFER (object
)->buffer_file_coding_system
;
5661 if (NILP (coding_system
)
5662 || NILP (Flocal_variable_p (Qbuffer_file_coding_system
, Qnil
)))
5664 coding_system
= Qnil
;
5665 if (NILP (current_buffer
->enable_multibyte_characters
))
5669 if (NILP (coding_system
) && !NILP (Fbuffer_file_name(object
)))
5671 /* Check file-coding-system-alist. */
5672 Lisp_Object args
[4], val
;
5674 args
[0] = Qwrite_region
; args
[1] = start
; args
[2] = end
;
5675 args
[3] = Fbuffer_file_name(object
);
5676 val
= Ffind_operation_coding_system (4, args
);
5677 if (CONSP (val
) && !NILP (XCDR (val
)))
5678 coding_system
= XCDR (val
);
5681 if (NILP (coding_system
)
5682 && !NILP (XBUFFER (object
)->buffer_file_coding_system
))
5684 /* If we still have not decided a coding system, use the
5685 default value of buffer-file-coding-system. */
5686 coding_system
= XBUFFER (object
)->buffer_file_coding_system
;
5690 && !NILP (Ffboundp (Vselect_safe_coding_system_function
)))
5691 /* Confirm that VAL can surely encode the current region. */
5692 coding_system
= call4 (Vselect_safe_coding_system_function
,
5693 make_number (b
), make_number (e
),
5694 coding_system
, Qnil
);
5697 coding_system
= Qraw_text
;
5700 if (NILP (Fcoding_system_p (coding_system
)))
5702 /* Invalid coding system. */
5704 if (!NILP (noerror
))
5705 coding_system
= Qraw_text
;
5707 xsignal1 (Qcoding_system_error
, coding_system
);
5711 object
= make_buffer_string (b
, e
, 0);
5712 if (prev
!= current_buffer
)
5713 set_buffer_internal (prev
);
5714 /* Discard the unwind protect for recovering the current
5718 if (STRING_MULTIBYTE (object
))
5719 object
= code_convert_string1 (object
, coding_system
, Qnil
, 1);
5722 md5_buffer (SDATA (object
) + start_byte
,
5723 SBYTES (object
) - (size_byte
- end_byte
),
5726 for (i
= 0; i
< 16; i
++)
5727 sprintf (&value
[2 * i
], "%02x", digest
[i
]);
5730 return make_string (value
, 32);
5737 /* Hash table stuff. */
5738 Qhash_table_p
= intern ("hash-table-p");
5739 staticpro (&Qhash_table_p
);
5740 Qeq
= intern ("eq");
5742 Qeql
= intern ("eql");
5744 Qequal
= intern ("equal");
5745 staticpro (&Qequal
);
5746 QCtest
= intern (":test");
5747 staticpro (&QCtest
);
5748 QCsize
= intern (":size");
5749 staticpro (&QCsize
);
5750 QCrehash_size
= intern (":rehash-size");
5751 staticpro (&QCrehash_size
);
5752 QCrehash_threshold
= intern (":rehash-threshold");
5753 staticpro (&QCrehash_threshold
);
5754 QCweakness
= intern (":weakness");
5755 staticpro (&QCweakness
);
5756 Qkey
= intern ("key");
5758 Qvalue
= intern ("value");
5759 staticpro (&Qvalue
);
5760 Qhash_table_test
= intern ("hash-table-test");
5761 staticpro (&Qhash_table_test
);
5762 Qkey_or_value
= intern ("key-or-value");
5763 staticpro (&Qkey_or_value
);
5764 Qkey_and_value
= intern ("key-and-value");
5765 staticpro (&Qkey_and_value
);
5768 defsubr (&Smake_hash_table
);
5769 defsubr (&Scopy_hash_table
);
5770 defsubr (&Shash_table_count
);
5771 defsubr (&Shash_table_rehash_size
);
5772 defsubr (&Shash_table_rehash_threshold
);
5773 defsubr (&Shash_table_size
);
5774 defsubr (&Shash_table_test
);
5775 defsubr (&Shash_table_weakness
);
5776 defsubr (&Shash_table_p
);
5777 defsubr (&Sclrhash
);
5778 defsubr (&Sgethash
);
5779 defsubr (&Sputhash
);
5780 defsubr (&Sremhash
);
5781 defsubr (&Smaphash
);
5782 defsubr (&Sdefine_hash_table_test
);
5784 Qstring_lessp
= intern ("string-lessp");
5785 staticpro (&Qstring_lessp
);
5786 Qprovide
= intern ("provide");
5787 staticpro (&Qprovide
);
5788 Qrequire
= intern ("require");
5789 staticpro (&Qrequire
);
5790 Qyes_or_no_p_history
= intern ("yes-or-no-p-history");
5791 staticpro (&Qyes_or_no_p_history
);
5792 Qcursor_in_echo_area
= intern ("cursor-in-echo-area");
5793 staticpro (&Qcursor_in_echo_area
);
5794 Qwidget_type
= intern ("widget-type");
5795 staticpro (&Qwidget_type
);
5797 staticpro (&string_char_byte_cache_string
);
5798 string_char_byte_cache_string
= Qnil
;
5800 require_nesting_list
= Qnil
;
5801 staticpro (&require_nesting_list
);
5803 Fset (Qyes_or_no_p_history
, Qnil
);
5805 DEFVAR_LISP ("features", &Vfeatures
,
5806 doc
: /* A list of symbols which are the features of the executing Emacs.
5807 Used by `featurep' and `require', and altered by `provide'. */);
5808 Vfeatures
= Fcons (intern ("emacs"), Qnil
);
5809 Qsubfeatures
= intern ("subfeatures");
5810 staticpro (&Qsubfeatures
);
5812 #ifdef HAVE_LANGINFO_CODESET
5813 Qcodeset
= intern ("codeset");
5814 staticpro (&Qcodeset
);
5815 Qdays
= intern ("days");
5817 Qmonths
= intern ("months");
5818 staticpro (&Qmonths
);
5819 Qpaper
= intern ("paper");
5820 staticpro (&Qpaper
);
5821 #endif /* HAVE_LANGINFO_CODESET */
5823 DEFVAR_BOOL ("use-dialog-box", &use_dialog_box
,
5824 doc
: /* *Non-nil means mouse commands use dialog boxes to ask questions.
5825 This applies to `y-or-n-p' and `yes-or-no-p' questions asked by commands
5826 invoked by mouse clicks and mouse menu items. */);
5829 DEFVAR_BOOL ("use-file-dialog", &use_file_dialog
,
5830 doc
: /* *Non-nil means mouse commands use a file dialog to ask for files.
5831 This applies to commands from menus and tool bar buttons. The value of
5832 `use-dialog-box' takes precedence over this variable, so a file dialog is only
5833 used if both `use-dialog-box' and this variable are non-nil. */);
5834 use_file_dialog
= 1;
5836 defsubr (&Sidentity
);
5839 defsubr (&Ssafe_length
);
5840 defsubr (&Sstring_bytes
);
5841 defsubr (&Sstring_equal
);
5842 defsubr (&Scompare_strings
);
5843 defsubr (&Sstring_lessp
);
5846 defsubr (&Svconcat
);
5847 defsubr (&Scopy_sequence
);
5848 defsubr (&Sstring_make_multibyte
);
5849 defsubr (&Sstring_make_unibyte
);
5850 defsubr (&Sstring_as_multibyte
);
5851 defsubr (&Sstring_as_unibyte
);
5852 defsubr (&Sstring_to_multibyte
);
5853 defsubr (&Scopy_alist
);
5854 defsubr (&Ssubstring
);
5855 defsubr (&Ssubstring_no_properties
);
5868 defsubr (&Snreverse
);
5869 defsubr (&Sreverse
);
5871 defsubr (&Splist_get
);
5873 defsubr (&Splist_put
);
5875 defsubr (&Slax_plist_get
);
5876 defsubr (&Slax_plist_put
);
5879 defsubr (&Sequal_including_properties
);
5880 defsubr (&Sfillarray
);
5881 defsubr (&Sclear_string
);
5882 defsubr (&Schar_table_subtype
);
5883 defsubr (&Schar_table_parent
);
5884 defsubr (&Sset_char_table_parent
);
5885 defsubr (&Schar_table_extra_slot
);
5886 defsubr (&Sset_char_table_extra_slot
);
5887 defsubr (&Schar_table_range
);
5888 defsubr (&Sset_char_table_range
);
5889 defsubr (&Sset_char_table_default
);
5890 defsubr (&Soptimize_char_table
);
5891 defsubr (&Smap_char_table
);
5895 defsubr (&Smapconcat
);
5896 defsubr (&Sy_or_n_p
);
5897 defsubr (&Syes_or_no_p
);
5898 defsubr (&Sload_average
);
5899 defsubr (&Sfeaturep
);
5900 defsubr (&Srequire
);
5901 defsubr (&Sprovide
);
5902 defsubr (&Splist_member
);
5903 defsubr (&Swidget_put
);
5904 defsubr (&Swidget_get
);
5905 defsubr (&Swidget_apply
);
5906 defsubr (&Sbase64_encode_region
);
5907 defsubr (&Sbase64_decode_region
);
5908 defsubr (&Sbase64_encode_string
);
5909 defsubr (&Sbase64_decode_string
);
5911 defsubr (&Slocale_info
);
5918 weak_hash_tables
= NULL
;
5921 /* arch-tag: 787f8219-5b74-46bd-8469-7e1cc475fa31
5922 (do not change this comment) */