diff options
| author | Gerd Moellmann | 2000-12-02 11:25:35 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-12-02 11:25:35 +0000 |
| commit | 5c302da454d4120139f5c92db160d1ac3191bc4d (patch) | |
| tree | e9a1c4a6498929f06c410ac85b203472b8f092f6 | |
| parent | 8c7178105c42b1e952043af0f2dc8657faebf875 (diff) | |
| download | emacs-5c302da454d4120139f5c92db160d1ac3191bc4d.tar.gz emacs-5c302da454d4120139f5c92db160d1ac3191bc4d.zip | |
(Fmd5): Use a different logic to decide the coding system
to use.
| -rw-r--r-- | src/fns.c | 123 |
1 files changed, 83 insertions, 40 deletions
| @@ -4964,11 +4964,13 @@ integers, including negative integers.") | |||
| 4964 | } | 4964 | } |
| 4965 | 4965 | ||
| 4966 | 4966 | ||
| 4967 | |||
| 4968 | |||
| 4969 | |||
| 4970 | 4967 | ||
| 4968 | /************************************************************************ | ||
| 4969 | MD5 | ||
| 4970 | ************************************************************************/ | ||
| 4971 | |||
| 4971 | #include "md5.h" | 4972 | #include "md5.h" |
| 4973 | #include "coding.h" | ||
| 4972 | 4974 | ||
| 4973 | DEFUN ("md5", Fmd5, Smd5, 1, 5, 0, | 4975 | DEFUN ("md5", Fmd5, Smd5, 1, 5, 0, |
| 4974 | "Return MD5 message digest of OBJECT, a buffer or string.\n\ | 4976 | "Return MD5 message digest of OBJECT, a buffer or string.\n\ |
| @@ -4997,42 +4999,33 @@ Emacsen and is ignored.") | |||
| 4997 | register struct buffer *bp; | 4999 | register struct buffer *bp; |
| 4998 | int temp; | 5000 | int temp; |
| 4999 | 5001 | ||
| 5000 | if (STRINGP(object)) | 5002 | if (STRINGP (object)) |
| 5001 | { | 5003 | { |
| 5002 | if (NILP (coding_system)) | 5004 | if (NILP (coding_system)) |
| 5003 | { | 5005 | { |
| 5004 | /* we should guess coding system */ | 5006 | /* Decide the coding-system to encode the data with. */ |
| 5005 | if (STRING_MULTIBYTE (object)) | ||
| 5006 | { | ||
| 5007 | /* we make a unibyte string and guess it's coding system | ||
| 5008 | (is this correct?) */ | ||
| 5009 | object = string_make_unibyte (object); | ||
| 5010 | coding_system = detect_coding_system | ||
| 5011 | (XSTRING(object)->data, STRING_BYTES(XSTRING (object)), 1); | ||
| 5012 | } | ||
| 5013 | else | ||
| 5014 | { | ||
| 5015 | /* guess coding system */ | ||
| 5016 | coding_system = detect_coding_system | ||
| 5017 | (XSTRING(object)->data, STRING_BYTES(XSTRING (object)), 1); | ||
| 5018 | } | ||
| 5019 | 5007 | ||
| 5020 | /* encode unibyte string into desired coding system | 5008 | if (STRING_MULTIBYTE (object)) |
| 5021 | (yes encoding functions handle unibyte source) */ | 5009 | /* use default, we can't guess correct value */ |
| 5022 | object = code_convert_string1 (object, coding_system, Qnil, 1); | 5010 | coding_system = XSYMBOL (XCAR (Vcoding_category_list))->value; |
| 5011 | else | ||
| 5012 | coding_system = Qraw_text; | ||
| 5023 | } | 5013 | } |
| 5024 | else | 5014 | |
| 5015 | if (NILP (Fcoding_system_p (coding_system))) | ||
| 5025 | { | 5016 | { |
| 5026 | /* convert string into given coding system */ | 5017 | /* Invalid coding system. */ |
| 5027 | if (STRING_MULTIBYTE (object)) | 5018 | |
| 5028 | { | 5019 | if (!NILP (noerror)) |
| 5029 | /* just encode it */ | 5020 | coding_system = Qraw_text; |
| 5030 | object = code_convert_string1 (object, coding_system, Qnil, 1); | 5021 | else |
| 5031 | } else { | 5022 | while (1) |
| 5032 | /* assume string is encoded */ | 5023 | Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); |
| 5033 | } | ||
| 5034 | } | 5024 | } |
| 5035 | 5025 | ||
| 5026 | if (STRING_MULTIBYTE (object)) | ||
| 5027 | object = code_convert_string1 (object, coding_system, Qnil, 1); | ||
| 5028 | |||
| 5036 | size = XSTRING (object)->size; | 5029 | size = XSTRING (object)->size; |
| 5037 | size_byte = STRING_BYTES (XSTRING (object)); | 5030 | size_byte = STRING_BYTES (XSTRING (object)); |
| 5038 | 5031 | ||
| @@ -5071,7 +5064,7 @@ Emacsen and is ignored.") | |||
| 5071 | } | 5064 | } |
| 5072 | else | 5065 | else |
| 5073 | { | 5066 | { |
| 5074 | CHECK_BUFFER(object, 0); | 5067 | CHECK_BUFFER (object, 0); |
| 5075 | 5068 | ||
| 5076 | bp = XBUFFER (object); | 5069 | bp = XBUFFER (object); |
| 5077 | 5070 | ||
| @@ -5099,13 +5092,63 @@ Emacsen and is ignored.") | |||
| 5099 | 5092 | ||
| 5100 | if (NILP (coding_system)) | 5093 | if (NILP (coding_system)) |
| 5101 | { | 5094 | { |
| 5102 | /* we should guess coding system of buffer */ | 5095 | /* Decide the coding-system to encode the data with. |
| 5103 | coding_system = XBUFFER (object)->buffer_file_coding_system; | 5096 | See fileio.c:Fwrite-region */ |
| 5104 | if (NILP (coding_system)) | 5097 | |
| 5098 | if (!NILP (Vcoding_system_for_write)) | ||
| 5099 | coding_system = Vcoding_system_for_write; | ||
| 5100 | else | ||
| 5101 | { | ||
| 5102 | int force_raw_text = 0; | ||
| 5103 | |||
| 5104 | coding_system = XBUFFER (object)->buffer_file_coding_system; | ||
| 5105 | if (NILP (coding_system) | ||
| 5106 | || NILP (Flocal_variable_p (Qbuffer_file_coding_system, Qnil))) | ||
| 5107 | { | ||
| 5108 | coding_system = Qnil; | ||
| 5109 | if (NILP (current_buffer->enable_multibyte_characters)) | ||
| 5110 | force_raw_text = 1; | ||
| 5111 | } | ||
| 5112 | |||
| 5113 | if (NILP (coding_system) && !NILP (Fbuffer_file_name(object))) | ||
| 5114 | { | ||
| 5115 | /* Check file-coding-system-alist. */ | ||
| 5116 | Lisp_Object args[4], val; | ||
| 5117 | |||
| 5118 | args[0] = Qwrite_region; args[1] = start; args[2] = end; | ||
| 5119 | args[3] = Fbuffer_file_name(object); | ||
| 5120 | val = Ffind_operation_coding_system (4, args); | ||
| 5121 | if (CONSP (val) && !NILP (XCDR (val))) | ||
| 5122 | coding_system = XCDR (val); | ||
| 5123 | } | ||
| 5124 | |||
| 5125 | if (NILP (coding_system) | ||
| 5126 | && !NILP (XBUFFER (object)->buffer_file_coding_system)) | ||
| 5127 | { | ||
| 5128 | /* If we still have not decided a coding system, use the | ||
| 5129 | default value of buffer-file-coding-system. */ | ||
| 5130 | coding_system = XBUFFER (object)->buffer_file_coding_system; | ||
| 5131 | } | ||
| 5132 | |||
| 5133 | if (!force_raw_text | ||
| 5134 | && !NILP (Ffboundp (Vselect_safe_coding_system_function))) | ||
| 5135 | /* Confirm that VAL can surely encode the current region. */ | ||
| 5136 | coding_system = call3 (Vselect_safe_coding_system_function, | ||
| 5137 | b, e, coding_system); | ||
| 5138 | |||
| 5139 | if (force_raw_text) | ||
| 5140 | coding_system = Qraw_text; | ||
| 5141 | } | ||
| 5142 | |||
| 5143 | if (NILP (Fcoding_system_p (coding_system))) | ||
| 5105 | { | 5144 | { |
| 5106 | /* xxx this can (and should) be handled. I do not know how. */ | 5145 | /* Invalid coding system. */ |
| 5107 | Fsignal (Qerror, | 5146 | |
| 5108 | Fcons (build_string ("No coding system found"), Qnil)); | 5147 | if (!NILP (noerror)) |
| 5148 | coding_system = Qraw_text; | ||
| 5149 | else | ||
| 5150 | while (1) | ||
| 5151 | Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil)); | ||
| 5109 | } | 5152 | } |
| 5110 | } | 5153 | } |
| 5111 | 5154 | ||
| @@ -5115,12 +5158,12 @@ Emacsen and is ignored.") | |||
| 5115 | object = code_convert_string1 (object, coding_system, Qnil, 1); | 5158 | object = code_convert_string1 (object, coding_system, Qnil, 1); |
| 5116 | } | 5159 | } |
| 5117 | 5160 | ||
| 5118 | md5_buffer (XSTRING(object)->data + start_byte, | 5161 | md5_buffer (XSTRING (object)->data + start_byte, |
| 5119 | STRING_BYTES(XSTRING (object)) - (size_byte - end_byte), | 5162 | STRING_BYTES(XSTRING (object)) - (size_byte - end_byte), |
| 5120 | digest); | 5163 | digest); |
| 5121 | 5164 | ||
| 5122 | for (i = 0; i < 16; i++) | 5165 | for (i = 0; i < 16; i++) |
| 5123 | sprintf (&value[2*i], "%02x", digest[i]); | 5166 | sprintf (&value[2 * i], "%02x", digest[i]); |
| 5124 | value[32] = '\0'; | 5167 | value[32] = '\0'; |
| 5125 | 5168 | ||
| 5126 | return make_string (value, 32); | 5169 | return make_string (value, 32); |