aboutsummaryrefslogtreecommitdiffstats
path: root/src/fns.c
diff options
context:
space:
mode:
authorStefan Monnier2010-09-30 01:28:20 +0200
committerStefan Monnier2010-09-30 01:28:20 +0200
commita01a7932080e8a6e7bc8472c58cefabcc2c37df3 (patch)
tree94b28b19c8f1536e76ffe7d5826811b74a79e3a5 /src/fns.c
parentcc390e46c7ba95b76ea133d98fd386214cd01709 (diff)
parent6b0f7311f16646e0de2045b2410e20921901c616 (diff)
downloademacs-a01a7932080e8a6e7bc8472c58cefabcc2c37df3.tar.gz
emacs-a01a7932080e8a6e7bc8472c58cefabcc2c37df3.zip
Merge from trunk
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c139
1 files changed, 73 insertions, 66 deletions
diff --git a/src/fns.c b/src/fns.c
index be4b99d50e6..7bae3bb0fae 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -241,8 +241,8 @@ If string STR1 is greater, the value is a positive number N;
241 N - 1 is the number of characters that match at the beginning. */) 241 N - 1 is the number of characters that match at the beginning. */)
242 (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2, Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case) 242 (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2, Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case)
243{ 243{
244 register int end1_char, end2_char; 244 register EMACS_INT end1_char, end2_char;
245 register int i1, i1_byte, i2, i2_byte; 245 register EMACS_INT i1, i1_byte, i2, i2_byte;
246 246
247 CHECK_STRING (str1); 247 CHECK_STRING (str1);
248 CHECK_STRING (str2); 248 CHECK_STRING (str2);
@@ -332,8 +332,8 @@ Case is significant.
332Symbols are also allowed; their print names are used instead. */) 332Symbols are also allowed; their print names are used instead. */)
333 (register Lisp_Object s1, Lisp_Object s2) 333 (register Lisp_Object s1, Lisp_Object s2)
334{ 334{
335 register int end; 335 register EMACS_INT end;
336 register int i1, i1_byte, i2, i2_byte; 336 register EMACS_INT i1, i1_byte, i2, i2_byte;
337 337
338 if (SYMBOLP (s1)) 338 if (SYMBOLP (s1))
339 s1 = SYMBOL_NAME (s1); 339 s1 = SYMBOL_NAME (s1);
@@ -456,8 +456,8 @@ with the original. */)
456struct textprop_rec 456struct textprop_rec
457{ 457{
458 int argnum; /* refer to ARGS (arguments of `concat') */ 458 int argnum; /* refer to ARGS (arguments of `concat') */
459 int from; /* refer to ARGS[argnum] (argument string) */ 459 EMACS_INT from; /* refer to ARGS[argnum] (argument string) */
460 int to; /* refer to VAL (the target string) */ 460 EMACS_INT to; /* refer to VAL (the target string) */
461}; 461};
462 462
463static Lisp_Object 463static Lisp_Object
@@ -466,10 +466,10 @@ concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_speci
466 Lisp_Object val; 466 Lisp_Object val;
467 register Lisp_Object tail; 467 register Lisp_Object tail;
468 register Lisp_Object this; 468 register Lisp_Object this;
469 int toindex; 469 EMACS_INT toindex;
470 int toindex_byte = 0; 470 EMACS_INT toindex_byte = 0;
471 register int result_len; 471 register EMACS_INT result_len;
472 register int result_len_byte; 472 register EMACS_INT result_len_byte;
473 register int argnum; 473 register int argnum;
474 Lisp_Object last_tail; 474 Lisp_Object last_tail;
475 Lisp_Object prev; 475 Lisp_Object prev;
@@ -513,16 +513,16 @@ concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_speci
513 some_multibyte = 0; 513 some_multibyte = 0;
514 for (argnum = 0; argnum < nargs; argnum++) 514 for (argnum = 0; argnum < nargs; argnum++)
515 { 515 {
516 int len; 516 EMACS_INT len;
517 this = args[argnum]; 517 this = args[argnum];
518 len = XFASTINT (Flength (this)); 518 len = XFASTINT (Flength (this));
519 if (target_type == Lisp_String) 519 if (target_type == Lisp_String)
520 { 520 {
521 /* We must count the number of bytes needed in the string 521 /* We must count the number of bytes needed in the string
522 as well as the number of characters. */ 522 as well as the number of characters. */
523 int i; 523 EMACS_INT i;
524 Lisp_Object ch; 524 Lisp_Object ch;
525 int this_len_byte; 525 EMACS_INT this_len_byte;
526 526
527 if (VECTORP (this) || FUNVECP (this)) 527 if (VECTORP (this) || FUNVECP (this))
528 for (i = 0; i < len; i++) 528 for (i = 0; i < len; i++)
@@ -594,9 +594,9 @@ concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_speci
594 for (argnum = 0; argnum < nargs; argnum++) 594 for (argnum = 0; argnum < nargs; argnum++)
595 { 595 {
596 Lisp_Object thislen; 596 Lisp_Object thislen;
597 int thisleni = 0; 597 EMACS_INT thisleni = 0;
598 register unsigned int thisindex = 0; 598 register EMACS_INT thisindex = 0;
599 register unsigned int thisindex_byte = 0; 599 register EMACS_INT thisindex_byte = 0;
600 600
601 this = args[argnum]; 601 this = args[argnum];
602 if (!CONSP (this)) 602 if (!CONSP (this))
@@ -606,7 +606,7 @@ concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_speci
606 if (STRINGP (this) && STRINGP (val) 606 if (STRINGP (this) && STRINGP (val)
607 && STRING_MULTIBYTE (this) == some_multibyte) 607 && STRING_MULTIBYTE (this) == some_multibyte)
608 { 608 {
609 int thislen_byte = SBYTES (this); 609 EMACS_INT thislen_byte = SBYTES (this);
610 610
611 memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this)); 611 memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this));
612 if (! NULL_INTERVAL_P (STRING_INTERVALS (this))) 612 if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
@@ -713,7 +713,7 @@ concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_speci
713 if (num_textprops > 0) 713 if (num_textprops > 0)
714 { 714 {
715 Lisp_Object props; 715 Lisp_Object props;
716 int last_to_end = -1; 716 EMACS_INT last_to_end = -1;
717 717
718 for (argnum = 0; argnum < num_textprops; argnum++) 718 for (argnum = 0; argnum < num_textprops; argnum++)
719 { 719 {
@@ -938,7 +938,7 @@ string_to_multibyte (Lisp_Object string)
938Lisp_Object 938Lisp_Object
939string_make_unibyte (Lisp_Object string) 939string_make_unibyte (Lisp_Object string)
940{ 940{
941 int nchars; 941 EMACS_INT nchars;
942 unsigned char *buf; 942 unsigned char *buf;
943 Lisp_Object ret; 943 Lisp_Object ret;
944 USE_SAFE_ALLOCA; 944 USE_SAFE_ALLOCA;
@@ -1003,7 +1003,7 @@ If STRING is multibyte and contains a character of charset
1003 1003
1004 if (STRING_MULTIBYTE (string)) 1004 if (STRING_MULTIBYTE (string))
1005 { 1005 {
1006 int bytes = SBYTES (string); 1006 EMACS_INT bytes = SBYTES (string);
1007 unsigned char *str = (unsigned char *) xmalloc (bytes); 1007 unsigned char *str = (unsigned char *) xmalloc (bytes);
1008 1008
1009 memcpy (str, SDATA (string), bytes); 1009 memcpy (str, SDATA (string), bytes);
@@ -1036,7 +1036,7 @@ If you're not sure, whether to use `string-as-multibyte' or
1036 if (! STRING_MULTIBYTE (string)) 1036 if (! STRING_MULTIBYTE (string))
1037 { 1037 {
1038 Lisp_Object new_string; 1038 Lisp_Object new_string;
1039 int nchars, nbytes; 1039 EMACS_INT nchars, nbytes;
1040 1040
1041 parse_str_as_multibyte (SDATA (string), 1041 parse_str_as_multibyte (SDATA (string),
1042 SBYTES (string), 1042 SBYTES (string),
@@ -1138,10 +1138,10 @@ value is a new vector that contains the elements between index FROM
1138 (Lisp_Object string, register Lisp_Object from, Lisp_Object to) 1138 (Lisp_Object string, register Lisp_Object from, Lisp_Object to)
1139{ 1139{
1140 Lisp_Object res; 1140 Lisp_Object res;
1141 int size; 1141 EMACS_INT size;
1142 int size_byte = 0; 1142 EMACS_INT size_byte = 0;
1143 int from_char, to_char; 1143 EMACS_INT from_char, to_char;
1144 int from_byte = 0, to_byte = 0; 1144 EMACS_INT from_byte = 0, to_byte = 0;
1145 1145
1146 CHECK_VECTOR_OR_STRING (string); 1146 CHECK_VECTOR_OR_STRING (string);
1147 CHECK_NUMBER (from); 1147 CHECK_NUMBER (from);
@@ -1206,9 +1206,9 @@ If FROM or TO is negative, it counts from the end.
1206With one argument, just copy STRING without its properties. */) 1206With one argument, just copy STRING without its properties. */)
1207 (Lisp_Object string, register Lisp_Object from, Lisp_Object to) 1207 (Lisp_Object string, register Lisp_Object from, Lisp_Object to)
1208{ 1208{
1209 int size, size_byte; 1209 EMACS_INT size, size_byte;
1210 int from_char, to_char; 1210 EMACS_INT from_char, to_char;
1211 int from_byte, to_byte; 1211 EMACS_INT from_byte, to_byte;
1212 1212
1213 CHECK_STRING (string); 1213 CHECK_STRING (string);
1214 1214
@@ -1256,11 +1256,12 @@ With one argument, just copy STRING without its properties. */)
1256 both in characters and in bytes. */ 1256 both in characters and in bytes. */
1257 1257
1258Lisp_Object 1258Lisp_Object
1259substring_both (Lisp_Object string, int from, int from_byte, int to, int to_byte) 1259substring_both (Lisp_Object string, EMACS_INT from, EMACS_INT from_byte,
1260 EMACS_INT to, EMACS_INT to_byte)
1260{ 1261{
1261 Lisp_Object res; 1262 Lisp_Object res;
1262 int size; 1263 EMACS_INT size;
1263 int size_byte; 1264 EMACS_INT size_byte;
1264 1265
1265 CHECK_VECTOR_OR_STRING (string); 1266 CHECK_VECTOR_OR_STRING (string);
1266 1267
@@ -2150,7 +2151,9 @@ DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0,
2150ARRAY is a vector, string, char-table, or bool-vector. */) 2151ARRAY is a vector, string, char-table, or bool-vector. */)
2151 (Lisp_Object array, Lisp_Object item) 2152 (Lisp_Object array, Lisp_Object item)
2152{ 2153{
2153 register int size, index, charval; 2154 register EMACS_INT size, index;
2155 int charval;
2156
2154 if (VECTORP (array)) 2157 if (VECTORP (array))
2155 { 2158 {
2156 register Lisp_Object *p = XVECTOR (array)->contents; 2159 register Lisp_Object *p = XVECTOR (array)->contents;
@@ -2176,7 +2179,7 @@ ARRAY is a vector, string, char-table, or bool-vector. */)
2176 { 2179 {
2177 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2180 unsigned char str[MAX_MULTIBYTE_LENGTH];
2178 int len = CHAR_STRING (charval, str); 2181 int len = CHAR_STRING (charval, str);
2179 int size_byte = SBYTES (array); 2182 EMACS_INT size_byte = SBYTES (array);
2180 unsigned char *p1 = p, *endp = p + size_byte; 2183 unsigned char *p1 = p, *endp = p + size_byte;
2181 int i; 2184 int i;
2182 2185
@@ -2224,7 +2227,7 @@ DEFUN ("clear-string", Fclear_string, Sclear_string,
2224This makes STRING unibyte and may change its length. */) 2227This makes STRING unibyte and may change its length. */)
2225 (Lisp_Object string) 2228 (Lisp_Object string)
2226{ 2229{
2227 int len; 2230 EMACS_INT len;
2228 CHECK_STRING (string); 2231 CHECK_STRING (string);
2229 len = SBYTES (string); 2232 len = SBYTES (string);
2230 memset (SDATA (string), 0, len); 2233 memset (SDATA (string), 0, len);
@@ -2288,11 +2291,11 @@ usage: (nconc &rest LISTS) */)
2288 LENI is the length of VALS, which should also be the length of SEQ. */ 2291 LENI is the length of VALS, which should also be the length of SEQ. */
2289 2292
2290static void 2293static void
2291mapcar1 (int leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) 2294mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
2292{ 2295{
2293 register Lisp_Object tail; 2296 register Lisp_Object tail;
2294 Lisp_Object dummy; 2297 Lisp_Object dummy;
2295 register int i; 2298 register EMACS_INT i;
2296 struct gcpro gcpro1, gcpro2, gcpro3; 2299 struct gcpro gcpro1, gcpro2, gcpro3;
2297 2300
2298 if (vals) 2301 if (vals)
@@ -2334,12 +2337,12 @@ mapcar1 (int leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
2334 } 2337 }
2335 else if (STRINGP (seq)) 2338 else if (STRINGP (seq))
2336 { 2339 {
2337 int i_byte; 2340 EMACS_INT i_byte;
2338 2341
2339 for (i = 0, i_byte = 0; i < leni;) 2342 for (i = 0, i_byte = 0; i < leni;)
2340 { 2343 {
2341 int c; 2344 int c;
2342 int i_before = i; 2345 EMACS_INT i_before = i;
2343 2346
2344 FETCH_STRING_CHAR_ADVANCE (c, seq, i, i_byte); 2347 FETCH_STRING_CHAR_ADVANCE (c, seq, i, i_byte);
2345 XSETFASTINT (dummy, c); 2348 XSETFASTINT (dummy, c);
@@ -2371,10 +2374,10 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2371 (Lisp_Object function, Lisp_Object sequence, Lisp_Object separator) 2374 (Lisp_Object function, Lisp_Object sequence, Lisp_Object separator)
2372{ 2375{
2373 Lisp_Object len; 2376 Lisp_Object len;
2374 register int leni; 2377 register EMACS_INT leni;
2375 int nargs; 2378 int nargs;
2376 register Lisp_Object *args; 2379 register Lisp_Object *args;
2377 register int i; 2380 register EMACS_INT i;
2378 struct gcpro gcpro1; 2381 struct gcpro gcpro1;
2379 Lisp_Object ret; 2382 Lisp_Object ret;
2380 USE_SAFE_ALLOCA; 2383 USE_SAFE_ALLOCA;
@@ -2411,7 +2414,7 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2411 (Lisp_Object function, Lisp_Object sequence) 2414 (Lisp_Object function, Lisp_Object sequence)
2412{ 2415{
2413 register Lisp_Object len; 2416 register Lisp_Object len;
2414 register int leni; 2417 register EMACS_INT leni;
2415 register Lisp_Object *args; 2418 register Lisp_Object *args;
2416 Lisp_Object ret; 2419 Lisp_Object ret;
2417 USE_SAFE_ALLOCA; 2420 USE_SAFE_ALLOCA;
@@ -2437,7 +2440,7 @@ Unlike `mapcar', don't accumulate the results. Return SEQUENCE.
2437SEQUENCE may be a list, a vector, a bool-vector, or a string. */) 2440SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2438 (Lisp_Object function, Lisp_Object sequence) 2441 (Lisp_Object function, Lisp_Object sequence)
2439{ 2442{
2440 register int leni; 2443 register EMACS_INT leni;
2441 2444
2442 leni = XFASTINT (Flength (sequence)); 2445 leni = XFASTINT (Flength (sequence));
2443 if (CHAR_TABLE_P (sequence)) 2446 if (CHAR_TABLE_P (sequence))
@@ -2961,8 +2964,9 @@ static const short base64_char_to_value[128] =
2961 base64 characters. */ 2964 base64 characters. */
2962 2965
2963 2966
2964static int base64_encode_1 (const char *, char *, int, int, int); 2967static EMACS_INT base64_encode_1 (const char *, char *, EMACS_INT, int, int);
2965static int base64_decode_1 (const char *, char *, int, int, int *); 2968static EMACS_INT base64_decode_1 (const char *, char *, EMACS_INT, int,
2969 EMACS_INT *);
2966 2970
2967DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region, 2971DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region,
2968 2, 3, "r", 2972 2, 3, "r",
@@ -2973,9 +2977,9 @@ into shorter lines. */)
2973 (Lisp_Object beg, Lisp_Object end, Lisp_Object no_line_break) 2977 (Lisp_Object beg, Lisp_Object end, Lisp_Object no_line_break)
2974{ 2978{
2975 char *encoded; 2979 char *encoded;
2976 int allength, length; 2980 EMACS_INT allength, length;
2977 int ibeg, iend, encoded_length; 2981 EMACS_INT ibeg, iend, encoded_length;
2978 int old_pos = PT; 2982 EMACS_INT old_pos = PT;
2979 USE_SAFE_ALLOCA; 2983 USE_SAFE_ALLOCA;
2980 2984
2981 validate_region (&beg, &end); 2985 validate_region (&beg, &end);
@@ -3031,7 +3035,7 @@ Optional second argument NO-LINE-BREAK means do not break long lines
3031into shorter lines. */) 3035into shorter lines. */)
3032 (Lisp_Object string, Lisp_Object no_line_break) 3036 (Lisp_Object string, Lisp_Object no_line_break)
3033{ 3037{
3034 int allength, length, encoded_length; 3038 EMACS_INT allength, length, encoded_length;
3035 char *encoded; 3039 char *encoded;
3036 Lisp_Object encoded_string; 3040 Lisp_Object encoded_string;
3037 USE_SAFE_ALLOCA; 3041 USE_SAFE_ALLOCA;
@@ -3067,10 +3071,12 @@ into shorter lines. */)
3067 return encoded_string; 3071 return encoded_string;
3068} 3072}
3069 3073
3070static int 3074static EMACS_INT
3071base64_encode_1 (const char *from, char *to, int length, int line_break, int multibyte) 3075base64_encode_1 (const char *from, char *to, EMACS_INT length,
3076 int line_break, int multibyte)
3072{ 3077{
3073 int counter = 0, i = 0; 3078 int counter = 0;
3079 EMACS_INT i = 0;
3074 char *e = to; 3080 char *e = to;
3075 int c; 3081 int c;
3076 unsigned int value; 3082 unsigned int value;
@@ -3169,11 +3175,11 @@ Return the length of the decoded text.
3169If the region can't be decoded, signal an error and don't modify the buffer. */) 3175If the region can't be decoded, signal an error and don't modify the buffer. */)
3170 (Lisp_Object beg, Lisp_Object end) 3176 (Lisp_Object beg, Lisp_Object end)
3171{ 3177{
3172 int ibeg, iend, length, allength; 3178 EMACS_INT ibeg, iend, length, allength;
3173 char *decoded; 3179 char *decoded;
3174 int old_pos = PT; 3180 EMACS_INT old_pos = PT;
3175 int decoded_length; 3181 EMACS_INT decoded_length;
3176 int inserted_chars; 3182 EMACS_INT inserted_chars;
3177 int multibyte = !NILP (current_buffer->enable_multibyte_characters); 3183 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
3178 USE_SAFE_ALLOCA; 3184 USE_SAFE_ALLOCA;
3179 3185
@@ -3230,7 +3236,7 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
3230 (Lisp_Object string) 3236 (Lisp_Object string)
3231{ 3237{
3232 char *decoded; 3238 char *decoded;
3233 int length, decoded_length; 3239 EMACS_INT length, decoded_length;
3234 Lisp_Object decoded_string; 3240 Lisp_Object decoded_string;
3235 USE_SAFE_ALLOCA; 3241 USE_SAFE_ALLOCA;
3236 3242
@@ -3262,14 +3268,15 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
3262 form. If NCHARS_RETRUN is not NULL, store the number of produced 3268 form. If NCHARS_RETRUN is not NULL, store the number of produced
3263 characters in *NCHARS_RETURN. */ 3269 characters in *NCHARS_RETURN. */
3264 3270
3265static int 3271static EMACS_INT
3266base64_decode_1 (const char *from, char *to, int length, int multibyte, int *nchars_return) 3272base64_decode_1 (const char *from, char *to, EMACS_INT length,
3273 int multibyte, EMACS_INT *nchars_return)
3267{ 3274{
3268 int i = 0; 3275 EMACS_INT i = 0; /* Used inside READ_QUADRUPLET_BYTE */
3269 char *e = to; 3276 char *e = to;
3270 unsigned char c; 3277 unsigned char c;
3271 unsigned long value; 3278 unsigned long value;
3272 int nchars = 0; 3279 EMACS_INT nchars = 0;
3273 3280
3274 while (1) 3281 while (1)
3275 { 3282 {
@@ -4575,13 +4582,13 @@ guesswork fails. Normally, an error is signaled in such case. */)
4575 unsigned char digest[16]; 4582 unsigned char digest[16];
4576 unsigned char value[33]; 4583 unsigned char value[33];
4577 int i; 4584 int i;
4578 int size; 4585 EMACS_INT size;
4579 int size_byte = 0; 4586 EMACS_INT size_byte = 0;
4580 int start_char = 0, end_char = 0; 4587 EMACS_INT start_char = 0, end_char = 0;
4581 int start_byte = 0, end_byte = 0; 4588 EMACS_INT start_byte = 0, end_byte = 0;
4582 register int b, e; 4589 register EMACS_INT b, e;
4583 register struct buffer *bp; 4590 register struct buffer *bp;
4584 int temp; 4591 EMACS_INT temp;
4585 4592
4586 if (STRINGP (object)) 4593 if (STRINGP (object))
4587 { 4594 {