X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=src%2Ffile-coding.c;h=fe42ebdf0b4869793638f3c05bed93f9491908fd;hp=8635316d51c3188a8ea2015cfe5475d8cf34d16d;hb=ac7d0619aad74b1d57c4748ebb3ab29d9c32e3d8;hpb=dbf2768f7b146e97e37a27316f70bb313f1acf15 diff --git a/src/file-coding.c b/src/file-coding.c index 8635316..fe42ebd 100644 --- a/src/file-coding.c +++ b/src/file-coding.c @@ -1785,6 +1785,8 @@ coding_system_from_mask (int mask) that should be unnecessary with the explicit eol-type argument. */ #define LENGTH(string_constant) (sizeof (string_constant) - 1) +/* number of leading lines to check for a coding cookie */ +#define LINES_TO_CHECK 2 void determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out, @@ -1808,13 +1810,13 @@ determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out, Extbyte *p; Lstream_data_count nread = Lstream_read (stream, buf, sizeof (buf)); Extbyte *scan_end; + int lines_checked = 0; /* Look for initial "-*-"; mode line prefix */ for (p = buf, scan_end = buf + nread - LENGTH ("-*-coding:?-*-"); p <= scan_end - && *p != '\n' - && *p != '\r'; + && lines_checked < LINES_TO_CHECK; p++) if (*p == '-' && *(p+1) == '*' && *(p+2) == '-') { @@ -1823,8 +1825,7 @@ determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out, for (p = local_vars_beg, scan_end = buf + nread - LENGTH ("-*-"); p <= scan_end - && *p != '\n' - && *p != '\r'; + && lines_checked < LINES_TO_CHECK; p++) if (*p == '-' && *(p+1) == '*' && *(p+2) == '-') { @@ -1866,8 +1867,24 @@ determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out, } break; } + /* #### file must use standard EOLs or we miss 2d line */ + /* #### not to mention this is broken for UTF-16 DOS files */ + else if (*p == '\n' || *p == '\r') + { + lines_checked++; + /* skip past multibyte (DOS) newline */ + if (*p == '\r' && *(p+1) == '\n') p++; + } break; } + /* #### file must use standard EOLs or we miss 2d line */ + /* #### not to mention this is broken for UTF-16 DOS files */ + else if (*p == '\n' || *p == '\r') + { + lines_checked++; + /* skip past multibyte (DOS) newline */ + if (*p == '\r' && *(p+1) == '\n') p++; + } if (NILP (coding_system)) do