3381 |
int longest_format; |
int longest_format; |
3382 |
Lisp_Object val; |
Lisp_Object val; |
3383 |
int arg_intervals = 0; |
int arg_intervals = 0; |
3384 |
|
USE_SAFE_ALLOCA; |
3385 |
|
|
3386 |
/* discarded[I] is 1 if byte I of the format |
/* discarded[I] is 1 if byte I of the format |
3387 |
string was not copied into the output. |
string was not copied into the output. |
3430 |
longest_format = 0; |
longest_format = 0; |
3431 |
|
|
3432 |
/* Make room in result for all the non-%-codes in the control string. */ |
/* Make room in result for all the non-%-codes in the control string. */ |
3433 |
total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]); |
total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]) + 1; |
3434 |
|
|
3435 |
/* Allocate the info and discarded tables. */ |
/* Allocate the info and discarded tables. */ |
3436 |
{ |
{ |
3623 |
|
|
3624 |
/* Allocate the space for the result. |
/* Allocate the space for the result. |
3625 |
Note that TOTAL is an overestimate. */ |
Note that TOTAL is an overestimate. */ |
3626 |
if (total < 1000) |
SAFE_ALLOCA (buf, char *, total); |
|
buf = (char *) alloca (total + 1); |
|
|
else |
|
|
buf = (char *) xmalloc (total + 1); |
|
3627 |
|
|
3628 |
p = buf; |
p = buf; |
3629 |
nchars = 0; |
nchars = 0; |
3756 |
maybe_combine_byte = 1; |
maybe_combine_byte = 1; |
3757 |
this_nchars = strlen (p); |
this_nchars = strlen (p); |
3758 |
if (multibyte) |
if (multibyte) |
3759 |
p += str_to_multibyte (p, buf + total - p, this_nchars); |
p += str_to_multibyte (p, buf + total - 1 - p, this_nchars); |
3760 |
else |
else |
3761 |
p += this_nchars; |
p += this_nchars; |
3762 |
nchars += this_nchars; |
nchars += this_nchars; |
3793 |
*p++ = *format++, nchars++; |
*p++ = *format++, nchars++; |
3794 |
} |
} |
3795 |
|
|
3796 |
if (p > buf + total + 1) |
if (p > buf + total) |
3797 |
abort (); |
abort (); |
3798 |
|
|
3799 |
if (maybe_combine_byte) |
if (maybe_combine_byte) |
3801 |
val = make_specified_string (buf, nchars, p - buf, multibyte); |
val = make_specified_string (buf, nchars, p - buf, multibyte); |
3802 |
|
|
3803 |
/* If we allocated BUF with malloc, free it too. */ |
/* If we allocated BUF with malloc, free it too. */ |
3804 |
if (total >= 1000) |
SAFE_FREE (total); |
|
xfree (buf); |
|
3805 |
|
|
3806 |
/* If the format string has text properties, or any of the string |
/* If the format string has text properties, or any of the string |
3807 |
arguments has text properties, set up text properties of the |
arguments has text properties, set up text properties of the |
4170 |
/* First region smaller than second. */ |
/* First region smaller than second. */ |
4171 |
if (len1_byte < len2_byte) |
if (len1_byte < len2_byte) |
4172 |
{ |
{ |
4173 |
/* We use alloca only if it is small, |
USE_SAFE_ALLOCA; |
4174 |
because we want to avoid stack overflow. */ |
|
4175 |
if (len2_byte > 20000) |
SAFE_ALLOCA (temp, unsigned char *, len2_byte); |
|
temp = (unsigned char *) xmalloc (len2_byte); |
|
|
else |
|
|
temp = (unsigned char *) alloca (len2_byte); |
|
4176 |
|
|
4177 |
/* Don't precompute these addresses. We have to compute them |
/* Don't precompute these addresses. We have to compute them |
4178 |
at the last minute, because the relocating allocator might |
at the last minute, because the relocating allocator might |
4183 |
bcopy (start2_addr, temp, len2_byte); |
bcopy (start2_addr, temp, len2_byte); |
4184 |
bcopy (start1_addr, start1_addr + len2_byte, len1_byte); |
bcopy (start1_addr, start1_addr + len2_byte, len1_byte); |
4185 |
bcopy (temp, start1_addr, len2_byte); |
bcopy (temp, start1_addr, len2_byte); |
4186 |
if (len2_byte > 20000) |
SAFE_FREE (len2_byte); |
|
xfree (temp); |
|
4187 |
} |
} |
4188 |
else |
else |
4189 |
/* First region not smaller than second. */ |
/* First region not smaller than second. */ |
4190 |
{ |
{ |
4191 |
if (len1_byte > 20000) |
USE_SAFE_ALLOCA; |
4192 |
temp = (unsigned char *) xmalloc (len1_byte); |
|
4193 |
else |
SAFE_ALLOCA (temp, unsigned char *, len1_byte); |
|
temp = (unsigned char *) alloca (len1_byte); |
|
4194 |
start1_addr = BYTE_POS_ADDR (start1_byte); |
start1_addr = BYTE_POS_ADDR (start1_byte); |
4195 |
start2_addr = BYTE_POS_ADDR (start2_byte); |
start2_addr = BYTE_POS_ADDR (start2_byte); |
4196 |
bcopy (start1_addr, temp, len1_byte); |
bcopy (start1_addr, temp, len1_byte); |
4197 |
bcopy (start2_addr, start1_addr, len2_byte); |
bcopy (start2_addr, start1_addr, len2_byte); |
4198 |
bcopy (temp, start1_addr + len2_byte, len1_byte); |
bcopy (temp, start1_addr + len2_byte, len1_byte); |
4199 |
if (len1_byte > 20000) |
SAFE_FREE (len1_byte); |
|
xfree (temp); |
|
4200 |
} |
} |
4201 |
graft_intervals_into_buffer (tmp_interval1, start1 + len2, |
graft_intervals_into_buffer (tmp_interval1, start1 + len2, |
4202 |
len1, current_buffer, 0); |
len1, current_buffer, 0); |
4213 |
if (len1_byte == len2_byte) |
if (len1_byte == len2_byte) |
4214 |
/* Regions are same size, though, how nice. */ |
/* Regions are same size, though, how nice. */ |
4215 |
{ |
{ |
4216 |
|
USE_SAFE_ALLOCA; |
4217 |
|
|
4218 |
modify_region (current_buffer, start1, end1); |
modify_region (current_buffer, start1, end1); |
4219 |
modify_region (current_buffer, start2, end2); |
modify_region (current_buffer, start2, end2); |
4220 |
record_change (start1, len1); |
record_change (start1, len1); |
4226 |
Fset_text_properties (make_number (start2), make_number (end2), |
Fset_text_properties (make_number (start2), make_number (end2), |
4227 |
Qnil, Qnil); |
Qnil, Qnil); |
4228 |
|
|
4229 |
if (len1_byte > 20000) |
SAFE_ALLOCA (temp, unsigned char *, len1_byte); |
|
temp = (unsigned char *) xmalloc (len1_byte); |
|
|
else |
|
|
temp = (unsigned char *) alloca (len1_byte); |
|
4230 |
start1_addr = BYTE_POS_ADDR (start1_byte); |
start1_addr = BYTE_POS_ADDR (start1_byte); |
4231 |
start2_addr = BYTE_POS_ADDR (start2_byte); |
start2_addr = BYTE_POS_ADDR (start2_byte); |
4232 |
bcopy (start1_addr, temp, len1_byte); |
bcopy (start1_addr, temp, len1_byte); |
4233 |
bcopy (start2_addr, start1_addr, len2_byte); |
bcopy (start2_addr, start1_addr, len2_byte); |
4234 |
bcopy (temp, start2_addr, len1_byte); |
bcopy (temp, start2_addr, len1_byte); |
4235 |
if (len1_byte > 20000) |
SAFE_FREE (len1_byte); |
4236 |
xfree (temp); |
|
4237 |
graft_intervals_into_buffer (tmp_interval1, start2, |
graft_intervals_into_buffer (tmp_interval1, start2, |
4238 |
len1, current_buffer, 0); |
len1, current_buffer, 0); |
4239 |
graft_intervals_into_buffer (tmp_interval2, start1, |
graft_intervals_into_buffer (tmp_interval2, start1, |
4243 |
else if (len1_byte < len2_byte) /* Second region larger than first */ |
else if (len1_byte < len2_byte) /* Second region larger than first */ |
4244 |
/* Non-adjacent & unequal size, area between must also be shifted. */ |
/* Non-adjacent & unequal size, area between must also be shifted. */ |
4245 |
{ |
{ |
4246 |
|
USE_SAFE_ALLOCA; |
4247 |
|
|
4248 |
modify_region (current_buffer, start1, end2); |
modify_region (current_buffer, start1, end2); |
4249 |
record_change (start1, (end2 - start1)); |
record_change (start1, (end2 - start1)); |
4250 |
tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
4254 |
Qnil, Qnil); |
Qnil, Qnil); |
4255 |
|
|
4256 |
/* holds region 2 */ |
/* holds region 2 */ |
4257 |
if (len2_byte > 20000) |
SAFE_ALLOCA (temp, unsigned char *, len2_byte); |
|
temp = (unsigned char *) xmalloc (len2_byte); |
|
|
else |
|
|
temp = (unsigned char *) alloca (len2_byte); |
|
4258 |
start1_addr = BYTE_POS_ADDR (start1_byte); |
start1_addr = BYTE_POS_ADDR (start1_byte); |
4259 |
start2_addr = BYTE_POS_ADDR (start2_byte); |
start2_addr = BYTE_POS_ADDR (start2_byte); |
4260 |
bcopy (start2_addr, temp, len2_byte); |
bcopy (start2_addr, temp, len2_byte); |
4261 |
bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte); |
bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte); |
4262 |
safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); |
safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); |
4263 |
bcopy (temp, start1_addr, len2_byte); |
bcopy (temp, start1_addr, len2_byte); |
4264 |
if (len2_byte > 20000) |
SAFE_FREE (len2_byte); |
4265 |
xfree (temp); |
|
4266 |
graft_intervals_into_buffer (tmp_interval1, end2 - len1, |
graft_intervals_into_buffer (tmp_interval1, end2 - len1, |
4267 |
len1, current_buffer, 0); |
len1, current_buffer, 0); |
4268 |
graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, |
graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, |
4273 |
else |
else |
4274 |
/* Second region smaller than first. */ |
/* Second region smaller than first. */ |
4275 |
{ |
{ |
4276 |
|
USE_SAFE_ALLOCA; |
4277 |
|
|
4278 |
record_change (start1, (end2 - start1)); |
record_change (start1, (end2 - start1)); |
4279 |
modify_region (current_buffer, start1, end2); |
modify_region (current_buffer, start1, end2); |
4280 |
|
|
4285 |
Qnil, Qnil); |
Qnil, Qnil); |
4286 |
|
|
4287 |
/* holds region 1 */ |
/* holds region 1 */ |
4288 |
if (len1_byte > 20000) |
SAFE_ALLOCA (temp, unsigned char *, len1_byte); |
|
temp = (unsigned char *) xmalloc (len1_byte); |
|
|
else |
|
|
temp = (unsigned char *) alloca (len1_byte); |
|
4289 |
start1_addr = BYTE_POS_ADDR (start1_byte); |
start1_addr = BYTE_POS_ADDR (start1_byte); |
4290 |
start2_addr = BYTE_POS_ADDR (start2_byte); |
start2_addr = BYTE_POS_ADDR (start2_byte); |
4291 |
bcopy (start1_addr, temp, len1_byte); |
bcopy (start1_addr, temp, len1_byte); |
4292 |
bcopy (start2_addr, start1_addr, len2_byte); |
bcopy (start2_addr, start1_addr, len2_byte); |
4293 |
bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); |
bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); |
4294 |
bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte); |
bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte); |
4295 |
if (len1_byte > 20000) |
SAFE_FREE (len1_byte); |
4296 |
xfree (temp); |
|
4297 |
graft_intervals_into_buffer (tmp_interval1, end2 - len1, |
graft_intervals_into_buffer (tmp_interval1, end2 - len1, |
4298 |
len1, current_buffer, 0); |
len1, current_buffer, 0); |
4299 |
graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, |
graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, |