NOTE: This patch has been committed.
src/ChangeLog addition:
2005-01-29 Ben Wing <ben(a)xemacs.org>
* file-coding.c (snarf_coding_system):
Use UExtbyte for semantic correctness.
* file-coding.c (look_for_coding_system_magic_cookie):
Fix code that recognizes ;;;###coding cookie.
docs-misc source patch:
Diff command: bash -ci "cvs-diff --show-c-function -no-changelog "
Files affected: src/file-coding.c
Index: src/file-coding.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/file-coding.c,v
retrieving revision 1.42
diff -u -p -r1.42 file-coding.c
--- src/file-coding.c 2005/01/24 23:33:54 1.42
+++ src/file-coding.c 2005/01/29 09:04:30
@@ -3541,10 +3541,10 @@ detected_coding_system (struct detection
blanks). If found, return it, otherwise nil. */
static Lisp_Object
-snarf_coding_system (const Ibyte *p, Bytecount len)
+snarf_coding_system (const UExtbyte *p, Bytecount len)
{
Bytecount n;
- Ibyte *name;
+ UExtbyte *name;
while (*p == ' ' || *p == '\t') p++, len--;
len = min (len, 1000);
@@ -3563,7 +3563,9 @@ snarf_coding_system (const Ibyte *p, Byt
if (n > 0)
{
name[n] = '\0';
- return find_coding_system_for_text_file (intern_int (name), 0);
+ /* This call to intern_int() is OK because we already verified that
+ there are only ASCII characters in the string */
+ return find_coding_system_for_text_file (intern_int ((Ibyte *) name), 0);
}
return Qnil;
@@ -3598,6 +3600,7 @@ look_for_coding_system_magic_cookie (con
{
const UExtbyte *p;
const UExtbyte *scan_end;
+ Bytecount cookie_len;
/* Look for initial "-*-"; mode line prefix */
for (p = data,
@@ -3639,20 +3642,26 @@ look_for_coding_system_magic_cookie (con
break;
}
-#if 0
- /* #### Totally wrong as is, rewrite */
- /* Look for initial ;;;###coding system */
+ /* Look for ;;;###coding system */
+ cookie_len = LENGTH (";;;###coding system: ");
+
+ for (p = data,
+ scan_end = data + len - cookie_len;
+ p <= scan_end;
+ p++)
{
- Bytecount ind = fast_string_match (QScoding_system_cookie,
- data, Qnil, 0, len, 0, ERROR_ME_NOT,
- 1);
- if (ind >= 0)
- return
- snarf_coding_system (data + ind + LENGTH (";;;###coding system: "),
- len - ind - LENGTH (";;;###coding system: "));
+ if (*p == ';' && !memcmp (p, ";;;###coding system: ",
cookie_len))
+ {
+ const UExtbyte *suffix;
+
+ p += cookie_len;
+ suffix = p;
+ while (suffix < scan_end && !isspace (*suffix))
+ suffix++;
+ return snarf_coding_system (p, suffix - p);
+ }
}
-#endif /* 0 */
return Qnil;
}
Show replies by date