994 |
{ |
{ |
995 |
unsigned char *buf; |
unsigned char *buf; |
996 |
int nbytes; |
int nbytes; |
997 |
|
Lisp_Object ret; |
998 |
|
USE_SAFE_ALLOCA; |
999 |
|
|
1000 |
if (STRING_MULTIBYTE (string)) |
if (STRING_MULTIBYTE (string)) |
1001 |
return string; |
return string; |
1007 |
if (nbytes == SBYTES (string)) |
if (nbytes == SBYTES (string)) |
1008 |
return string; |
return string; |
1009 |
|
|
1010 |
buf = (unsigned char *) alloca (nbytes); |
SAFE_ALLOCA (buf, unsigned char *, nbytes); |
1011 |
copy_text (SDATA (string), buf, SBYTES (string), |
copy_text (SDATA (string), buf, SBYTES (string), |
1012 |
0, 1); |
0, 1); |
1013 |
|
|
1014 |
return make_multibyte_string (buf, SCHARS (string), nbytes); |
ret = make_multibyte_string (buf, SCHARS (string), nbytes); |
1015 |
|
SAFE_FREE (nbytes); |
1016 |
|
|
1017 |
|
return ret; |
1018 |
} |
} |
1019 |
|
|
1020 |
|
|
1029 |
{ |
{ |
1030 |
unsigned char *buf; |
unsigned char *buf; |
1031 |
int nbytes; |
int nbytes; |
1032 |
|
Lisp_Object ret; |
1033 |
|
USE_SAFE_ALLOCA; |
1034 |
|
|
1035 |
if (STRING_MULTIBYTE (string)) |
if (STRING_MULTIBYTE (string)) |
1036 |
return string; |
return string; |
1041 |
if (nbytes == SBYTES (string)) |
if (nbytes == SBYTES (string)) |
1042 |
return make_multibyte_string (SDATA (string), nbytes, nbytes); |
return make_multibyte_string (SDATA (string), nbytes, nbytes); |
1043 |
|
|
1044 |
buf = (unsigned char *) alloca (nbytes); |
SAFE_ALLOCA (buf, unsigned char *, nbytes); |
1045 |
bcopy (SDATA (string), buf, SBYTES (string)); |
bcopy (SDATA (string), buf, SBYTES (string)); |
1046 |
str_to_multibyte (buf, nbytes, SBYTES (string)); |
str_to_multibyte (buf, nbytes, SBYTES (string)); |
1047 |
|
|
1048 |
return make_multibyte_string (buf, SCHARS (string), nbytes); |
ret = make_multibyte_string (buf, SCHARS (string), nbytes); |
1049 |
|
SAFE_FREE (nbytes); |
1050 |
|
|
1051 |
|
return ret; |
1052 |
} |
} |
1053 |
|
|
1054 |
|
|
1058 |
string_make_unibyte (string) |
string_make_unibyte (string) |
1059 |
Lisp_Object string; |
Lisp_Object string; |
1060 |
{ |
{ |
1061 |
|
int nchars; |
1062 |
unsigned char *buf; |
unsigned char *buf; |
1063 |
Lisp_Object ret; |
Lisp_Object ret; |
1064 |
|
USE_SAFE_ALLOCA; |
1065 |
|
|
1066 |
if (! STRING_MULTIBYTE (string)) |
if (! STRING_MULTIBYTE (string)) |
1067 |
return string; |
return string; |
1068 |
|
|
1069 |
/* We can not use alloca here, because string might be very long. |
nchars = SCHARS (string); |
|
For example when selecting megabytes of text and then pasting it to |
|
|
another application. */ |
|
|
buf = (unsigned char *) xmalloc (SCHARS (string)); |
|
1070 |
|
|
1071 |
|
SAFE_ALLOCA (buf, unsigned char *, nchars); |
1072 |
copy_text (SDATA (string), buf, SBYTES (string), |
copy_text (SDATA (string), buf, SBYTES (string), |
1073 |
1, 0); |
1, 0); |
1074 |
|
|
1075 |
ret = make_unibyte_string (buf, SCHARS (string)); |
ret = make_unibyte_string (buf, nchars); |
1076 |
|
SAFE_FREE (nchars); |
|
xfree (buf); |
|
1077 |
|
|
1078 |
return ret; |
return ret; |
1079 |
} |
} |
3000 |
register Lisp_Object *args; |
register Lisp_Object *args; |
3001 |
register int i; |
register int i; |
3002 |
struct gcpro gcpro1; |
struct gcpro gcpro1; |
3003 |
|
Lisp_Object ret; |
3004 |
|
USE_SAFE_ALLOCA; |
3005 |
|
|
3006 |
len = Flength (sequence); |
len = Flength (sequence); |
3007 |
leni = XINT (len); |
leni = XINT (len); |
3008 |
nargs = leni + leni - 1; |
nargs = leni + leni - 1; |
3009 |
if (nargs < 0) return build_string (""); |
if (nargs < 0) return build_string (""); |
3010 |
|
|
3011 |
args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); |
SAFE_ALLOCA_LISP (args, nargs); |
3012 |
|
|
3013 |
GCPRO1 (separator); |
GCPRO1 (separator); |
3014 |
mapcar1 (leni, args, function, sequence); |
mapcar1 (leni, args, function, sequence); |
3020 |
for (i = 1; i < nargs; i += 2) |
for (i = 1; i < nargs; i += 2) |
3021 |
args[i] = separator; |
args[i] = separator; |
3022 |
|
|
3023 |
return Fconcat (nargs, args); |
GCPRO1 (*args); |
3024 |
|
gcpro1.nvars = nargs; |
3025 |
|
ret = Fconcat (nargs, args); |
3026 |
|
UNGCPRO; |
3027 |
|
|
3028 |
|
SAFE_FREE_LISP (nargs); |
3029 |
|
|
3030 |
|
return ret; |
3031 |
} |
} |
3032 |
|
|
3033 |
DEFUN ("mapcar", Fmapcar, Smapcar, 2, 2, 0, |
DEFUN ("mapcar", Fmapcar, Smapcar, 2, 2, 0, |
3040 |
register Lisp_Object len; |
register Lisp_Object len; |
3041 |
register int leni; |
register int leni; |
3042 |
register Lisp_Object *args; |
register Lisp_Object *args; |
3043 |
|
struct gcpro gcpro1; |
3044 |
|
Lisp_Object ret; |
3045 |
|
USE_SAFE_ALLOCA; |
3046 |
|
|
3047 |
len = Flength (sequence); |
len = Flength (sequence); |
3048 |
leni = XFASTINT (len); |
leni = XFASTINT (len); |
3049 |
args = (Lisp_Object *) alloca (leni * sizeof (Lisp_Object)); |
|
3050 |
|
SAFE_ALLOCA_LISP (args, leni); |
3051 |
|
|
3052 |
mapcar1 (leni, args, function, sequence); |
mapcar1 (leni, args, function, sequence); |
3053 |
|
|
3054 |
return Flist (leni, args); |
GCPRO1 (*args); |
3055 |
|
gcpro1.nvars = leni; |
3056 |
|
ret = Flist (leni, args); |
3057 |
|
UNGCPRO; |
3058 |
|
|
3059 |
|
SAFE_FREE_LISP (leni); |
3060 |
|
|
3061 |
|
return ret; |
3062 |
} |
} |
3063 |
|
|
3064 |
DEFUN ("mapc", Fmapc, Smapc, 2, 2, 0, |
DEFUN ("mapc", Fmapc, Smapc, 2, 2, 0, |
3673 |
} \ |
} \ |
3674 |
while (IS_BASE64_IGNORABLE (c)) |
while (IS_BASE64_IGNORABLE (c)) |
3675 |
|
|
|
/* Don't use alloca for regions larger than this, lest we overflow |
|
|
their stack. */ |
|
|
#define MAX_ALLOCA 16*1024 |
|
|
|
|
3676 |
/* Table of characters coding the 64 values. */ |
/* Table of characters coding the 64 values. */ |
3677 |
static char base64_value_to_char[64] = |
static char base64_value_to_char[64] = |
3678 |
{ |
{ |
3738 |
int allength, length; |
int allength, length; |
3739 |
int ibeg, iend, encoded_length; |
int ibeg, iend, encoded_length; |
3740 |
int old_pos = PT; |
int old_pos = PT; |
3741 |
|
USE_SAFE_ALLOCA; |
3742 |
|
|
3743 |
validate_region (&beg, &end); |
validate_region (&beg, &end); |
3744 |
|
|
3753 |
allength = length + length/3 + 1; |
allength = length + length/3 + 1; |
3754 |
allength += allength / MIME_LINE_LENGTH + 1 + 6; |
allength += allength / MIME_LINE_LENGTH + 1 + 6; |
3755 |
|
|
3756 |
if (allength <= MAX_ALLOCA) |
SAFE_ALLOCA (encoded, char *, allength); |
|
encoded = (char *) alloca (allength); |
|
|
else |
|
|
encoded = (char *) xmalloc (allength); |
|
3757 |
encoded_length = base64_encode_1 (BYTE_POS_ADDR (ibeg), encoded, length, |
encoded_length = base64_encode_1 (BYTE_POS_ADDR (ibeg), encoded, length, |
3758 |
NILP (no_line_break), |
NILP (no_line_break), |
3759 |
!NILP (current_buffer->enable_multibyte_characters)); |
!NILP (current_buffer->enable_multibyte_characters)); |
3763 |
if (encoded_length < 0) |
if (encoded_length < 0) |
3764 |
{ |
{ |
3765 |
/* The encoding wasn't possible. */ |
/* The encoding wasn't possible. */ |
3766 |
if (length > MAX_ALLOCA) |
SAFE_FREE (allength); |
|
xfree (encoded); |
|
3767 |
error ("Multibyte character in data for base64 encoding"); |
error ("Multibyte character in data for base64 encoding"); |
3768 |
} |
} |
3769 |
|
|
3771 |
and delete the old. (Insert first in order to preserve markers.) */ |
and delete the old. (Insert first in order to preserve markers.) */ |
3772 |
SET_PT_BOTH (XFASTINT (beg), ibeg); |
SET_PT_BOTH (XFASTINT (beg), ibeg); |
3773 |
insert (encoded, encoded_length); |
insert (encoded, encoded_length); |
3774 |
if (allength > MAX_ALLOCA) |
SAFE_FREE (allength); |
|
xfree (encoded); |
|
3775 |
del_range_byte (ibeg + encoded_length, iend + encoded_length, 1); |
del_range_byte (ibeg + encoded_length, iend + encoded_length, 1); |
3776 |
|
|
3777 |
/* If point was outside of the region, restore it exactly; else just |
/* If point was outside of the region, restore it exactly; else just |
3797 |
int allength, length, encoded_length; |
int allength, length, encoded_length; |
3798 |
char *encoded; |
char *encoded; |
3799 |
Lisp_Object encoded_string; |
Lisp_Object encoded_string; |
3800 |
|
USE_SAFE_ALLOCA; |
3801 |
|
|
3802 |
CHECK_STRING (string); |
CHECK_STRING (string); |
3803 |
|
|
3809 |
allength += allength / MIME_LINE_LENGTH + 1 + 6; |
allength += allength / MIME_LINE_LENGTH + 1 + 6; |
3810 |
|
|
3811 |
/* We need to allocate enough room for decoding the text. */ |
/* We need to allocate enough room for decoding the text. */ |
3812 |
if (allength <= MAX_ALLOCA) |
SAFE_ALLOCA (encoded, char *, allength); |
|
encoded = (char *) alloca (allength); |
|
|
else |
|
|
encoded = (char *) xmalloc (allength); |
|
3813 |
|
|
3814 |
encoded_length = base64_encode_1 (SDATA (string), |
encoded_length = base64_encode_1 (SDATA (string), |
3815 |
encoded, length, NILP (no_line_break), |
encoded, length, NILP (no_line_break), |
3820 |
if (encoded_length < 0) |
if (encoded_length < 0) |
3821 |
{ |
{ |
3822 |
/* The encoding wasn't possible. */ |
/* The encoding wasn't possible. */ |
3823 |
if (length > MAX_ALLOCA) |
SAFE_FREE (allength); |
|
xfree (encoded); |
|
3824 |
error ("Multibyte character in data for base64 encoding"); |
error ("Multibyte character in data for base64 encoding"); |
3825 |
} |
} |
3826 |
|
|
3827 |
encoded_string = make_unibyte_string (encoded, encoded_length); |
encoded_string = make_unibyte_string (encoded, encoded_length); |
3828 |
if (allength > MAX_ALLOCA) |
SAFE_FREE (allength); |
|
xfree (encoded); |
|
3829 |
|
|
3830 |
return encoded_string; |
return encoded_string; |
3831 |
} |
} |
3938 |
int decoded_length; |
int decoded_length; |
3939 |
int inserted_chars; |
int inserted_chars; |
3940 |
int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
3941 |
|
USE_SAFE_ALLOCA; |
3942 |
|
|
3943 |
validate_region (&beg, &end); |
validate_region (&beg, &end); |
3944 |
|
|
3951 |
working on a multibyte buffer, each decoded code may occupy at |
working on a multibyte buffer, each decoded code may occupy at |
3952 |
most two bytes. */ |
most two bytes. */ |
3953 |
allength = multibyte ? length * 2 : length; |
allength = multibyte ? length * 2 : length; |
3954 |
if (allength <= MAX_ALLOCA) |
SAFE_ALLOCA (decoded, char *, allength); |
|
decoded = (char *) alloca (allength); |
|
|
else |
|
|
decoded = (char *) xmalloc (allength); |
|
3955 |
|
|
3956 |
move_gap_both (XFASTINT (beg), ibeg); |
move_gap_both (XFASTINT (beg), ibeg); |
3957 |
decoded_length = base64_decode_1 (BYTE_POS_ADDR (ibeg), decoded, length, |
decoded_length = base64_decode_1 (BYTE_POS_ADDR (ibeg), decoded, length, |
3962 |
if (decoded_length < 0) |
if (decoded_length < 0) |
3963 |
{ |
{ |
3964 |
/* The decoding wasn't possible. */ |
/* The decoding wasn't possible. */ |
3965 |
if (allength > MAX_ALLOCA) |
SAFE_FREE (allength); |
|
xfree (decoded); |
|
3966 |
error ("Invalid base64 data"); |
error ("Invalid base64 data"); |
3967 |
} |
} |
3968 |
|
|
3970 |
and delete the old. (Insert first in order to preserve markers.) */ |
and delete the old. (Insert first in order to preserve markers.) */ |
3971 |
TEMP_SET_PT_BOTH (XFASTINT (beg), ibeg); |
TEMP_SET_PT_BOTH (XFASTINT (beg), ibeg); |
3972 |
insert_1_both (decoded, inserted_chars, decoded_length, 0, 1, 0); |
insert_1_both (decoded, inserted_chars, decoded_length, 0, 1, 0); |
3973 |
if (allength > MAX_ALLOCA) |
SAFE_FREE (allength); |
3974 |
xfree (decoded); |
|
3975 |
/* Delete the original text. */ |
/* Delete the original text. */ |
3976 |
del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars, |
del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars, |
3977 |
iend + decoded_length, 1); |
iend + decoded_length, 1); |
3996 |
char *decoded; |
char *decoded; |
3997 |
int length, decoded_length; |
int length, decoded_length; |
3998 |
Lisp_Object decoded_string; |
Lisp_Object decoded_string; |
3999 |
|
USE_SAFE_ALLOCA; |
4000 |
|
|
4001 |
CHECK_STRING (string); |
CHECK_STRING (string); |
4002 |
|
|
4003 |
length = SBYTES (string); |
length = SBYTES (string); |
4004 |
/* We need to allocate enough room for decoding the text. */ |
/* We need to allocate enough room for decoding the text. */ |
4005 |
if (length <= MAX_ALLOCA) |
SAFE_ALLOCA (decoded, char *, length); |
|
decoded = (char *) alloca (length); |
|
|
else |
|
|
decoded = (char *) xmalloc (length); |
|
4006 |
|
|
4007 |
/* The decoded result should be unibyte. */ |
/* The decoded result should be unibyte. */ |
4008 |
decoded_length = base64_decode_1 (SDATA (string), decoded, length, |
decoded_length = base64_decode_1 (SDATA (string), decoded, length, |
4014 |
else |
else |
4015 |
decoded_string = Qnil; |
decoded_string = Qnil; |
4016 |
|
|
4017 |
if (length > MAX_ALLOCA) |
SAFE_FREE (length); |
|
xfree (decoded); |
|
4018 |
if (!STRINGP (decoded_string)) |
if (!STRINGP (decoded_string)) |
4019 |
error ("Invalid base64 data"); |
error ("Invalid base64 data"); |
4020 |
|
|