From: tomo Date: Mon, 16 Aug 1999 14:39:47 +0000 (+0000) Subject: (determine_real_coding_system): Treat `coding:' cookie. X-Git-Tag: r21-2-19-tomo-3~4 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=a604b7a805bdd2b2ce7890911f7ccdf39fa9a817;p=chise%2Fxemacs-chise.git- (determine_real_coding_system): Treat `coding:' cookie. --- diff --git a/src/file-coding.c b/src/file-coding.c index 352b2c2..5b55da9 100644 --- a/src/file-coding.c +++ b/src/file-coding.c @@ -1620,26 +1620,78 @@ determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out, if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT || *eol_type_in_out == EOL_AUTODETECT) { + unsigned char random_buffer[4096]; + int nread; - while (1) + nread = Lstream_read (stream, random_buffer, sizeof (random_buffer)); + if (nread) { - unsigned char random_buffer[4096]; - int nread; + unsigned char *cp = random_buffer; + Lisp_Object coding_system = Qnil; - nread = Lstream_read (stream, random_buffer, sizeof (random_buffer)); - if (!nread) - break; - if (detect_coding_type (&decst, random_buffer, nread, - XCODING_SYSTEM_TYPE (*codesys_in_out) != - CODESYS_AUTODETECT)) - break; - } + while (cp < random_buffer + 4096) + { + if ((*cp++ == 'c') && + (*cp++ == 'o') && + (*cp++ == 'd') && + (*cp++ == 'i') && + (*cp++ == 'n') && + (*cp++ == 'g') && + (*cp++ == ':')) + { + unsigned char coding_system_name[4096 - 6]; + unsigned char *np = coding_system_name; - *eol_type_in_out = decst.eol_type; - if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT) - *codesys_in_out = coding_system_from_mask (decst.mask); - } + while ( (*cp == ' ') || (*cp == '\t') ) + { + cp++; + } + while ( (cp < random_buffer + 4096) && + (*cp != ' ') && (*cp != '\t') && (*cp != ';') ) + { + *np++ = *cp++; + } + *np = 0; + coding_system + = Ffind_coding_system (intern + (build_string + (coding_system_name))); + break; + } + } + if (!EQ(coding_system, Qnil)) + { + if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT) + *codesys_in_out = coding_system; + } + else + { + while (1) + { + nread + = Lstream_read (stream, + random_buffer, sizeof (random_buffer)); + if (!nread) + break; + if (detect_coding_type + (&decst, random_buffer, nread, + XCODING_SYSTEM_TYPE (*codesys_in_out) != + CODESYS_AUTODETECT)) + break; + } + *eol_type_in_out = decst.eol_type; + if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT) + *codesys_in_out = coding_system_from_mask (decst.mask); + } + } + else + { + *eol_type_in_out = decst.eol_type; + if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT) + *codesys_in_out = coding_system_from_mask (decst.mask); + } + } /* If we absolutely can't determine the EOL type, just assume LF. */ if (*eol_type_in_out == EOL_AUTODETECT) *eol_type_in_out = EOL_LF;