comparison src/file-coding.c @ 2531:7de8d9ab7bbd

[xemacs-hg @ 2005-01-29 09:06:37 by ben] Fix recognition of coding magic cookie in autodetection file-coding.c: Use UExtbyte for semantic correctness. file-coding.c: Fix code that recognizes ;;;###coding cookie.
author ben
date Sat, 29 Jan 2005 09:06:40 +0000
parents 3d8143fc88e1
children 9f70af3ac939
comparison
equal deleted inserted replaced
2530:bc47870c97c2 2531:7de8d9ab7bbd
3539 3539
3540 /* Look for a coding system in the string (skipping over leading 3540 /* Look for a coding system in the string (skipping over leading
3541 blanks). If found, return it, otherwise nil. */ 3541 blanks). If found, return it, otherwise nil. */
3542 3542
3543 static Lisp_Object 3543 static Lisp_Object
3544 snarf_coding_system (const Ibyte *p, Bytecount len) 3544 snarf_coding_system (const UExtbyte *p, Bytecount len)
3545 { 3545 {
3546 Bytecount n; 3546 Bytecount n;
3547 Ibyte *name; 3547 UExtbyte *name;
3548 3548
3549 while (*p == ' ' || *p == '\t') p++, len--; 3549 while (*p == ' ' || *p == '\t') p++, len--;
3550 len = min (len, 1000); 3550 len = min (len, 1000);
3551 name = alloca_ibytes (len + 1); 3551 name = alloca_ibytes (len + 1);
3552 memcpy (name, p, len); 3552 memcpy (name, p, len);
3561 "0123456789" 3561 "0123456789"
3562 "!$%&*+-.^_{|}~"); 3562 "!$%&*+-.^_{|}~");
3563 if (n > 0) 3563 if (n > 0)
3564 { 3564 {
3565 name[n] = '\0'; 3565 name[n] = '\0';
3566 return find_coding_system_for_text_file (intern_int (name), 0); 3566 /* This call to intern_int() is OK because we already verified that
3567 there are only ASCII characters in the string */
3568 return find_coding_system_for_text_file (intern_int ((Ibyte *) name), 0);
3567 } 3569 }
3568 3570
3569 return Qnil; 3571 return Qnil;
3570 } 3572 }
3571 3573
3596 static Lisp_Object 3598 static Lisp_Object
3597 look_for_coding_system_magic_cookie (const UExtbyte *data, Bytecount len) 3599 look_for_coding_system_magic_cookie (const UExtbyte *data, Bytecount len)
3598 { 3600 {
3599 const UExtbyte *p; 3601 const UExtbyte *p;
3600 const UExtbyte *scan_end; 3602 const UExtbyte *scan_end;
3603 Bytecount cookie_len;
3601 3604
3602 /* Look for initial "-*-"; mode line prefix */ 3605 /* Look for initial "-*-"; mode line prefix */
3603 for (p = data, 3606 for (p = data,
3604 scan_end = data + len - LENGTH ("-*-coding:?-*-"); 3607 scan_end = data + len - LENGTH ("-*-coding:?-*-");
3605 p <= scan_end 3608 p <= scan_end
3637 break; 3640 break;
3638 } 3641 }
3639 break; 3642 break;
3640 } 3643 }
3641 3644
3642 #if 0 3645 /* Look for ;;;###coding system */
3643 /* #### Totally wrong as is, rewrite */ 3646
3644 /* Look for initial ;;;###coding system */ 3647 cookie_len = LENGTH (";;;###coding system: ");
3645 3648
3649 for (p = data,
3650 scan_end = data + len - cookie_len;
3651 p <= scan_end;
3652 p++)
3646 { 3653 {
3647 Bytecount ind = fast_string_match (QScoding_system_cookie, 3654 if (*p == ';' && !memcmp (p, ";;;###coding system: ", cookie_len))
3648 data, Qnil, 0, len, 0, ERROR_ME_NOT, 3655 {
3649 1); 3656 const UExtbyte *suffix;
3650 if (ind >= 0) 3657
3651 return 3658 p += cookie_len;
3652 snarf_coding_system (data + ind + LENGTH (";;;###coding system: "), 3659 suffix = p;
3653 len - ind - LENGTH (";;;###coding system: ")); 3660 while (suffix < scan_end && !isspace (*suffix))
3661 suffix++;
3662 return snarf_coding_system (p, suffix - p);
3663 }
3654 } 3664 }
3655 #endif /* 0 */
3656 3665
3657 return Qnil; 3666 return Qnil;
3658 } 3667 }
3659 3668
3660 static Lisp_Object 3669 static Lisp_Object