Mercurial > hg > xemacs-beta
comparison src/file-coding.c @ 1347:8d350b095c21
[xemacs-hg @ 2003-03-09 12:59:36 by ben]
oops, C++ bites again
widget.texi: Fix Turnbull typos.
config.inc.samp: Note that relative directories are a no-no in BUILD_DIR and
SOURCE_DIR. Use paths relative to $(MAKEROOT) instead.
file-coding.c: Fix up internal magic-cookie code to also check for
`;;;###coding system', already handled by the (redundant)
code in files.el.
regex.c: Fix problem with ordering of initializations and statements -- OK in
C++, not in C.
search.c: Indentation.
author | ben |
---|---|
date | Sun, 09 Mar 2003 12:59:45 +0000 |
parents | b531bf8658e9 |
children | 31b70e3e9ce7 |
comparison
equal
deleted
inserted
replaced
1346:01c57eb70ae9 | 1347:8d350b095c21 |
---|---|
478 Lisp_Object Qnearly_impossible; | 478 Lisp_Object Qnearly_impossible; |
479 | 479 |
480 Lisp_Object Qdo_eol, Qdo_coding; | 480 Lisp_Object Qdo_eol, Qdo_coding; |
481 | 481 |
482 Lisp_Object Qcanonicalize_after_coding; | 482 Lisp_Object Qcanonicalize_after_coding; |
483 | |
484 Lisp_Object QScoding_system_cookie; | |
483 | 485 |
484 /* This is used to convert autodetected coding systems into existing | 486 /* This is used to convert autodetected coding systems into existing |
485 systems. For example, the chain undecided->convert-eol-autodetect may | 487 systems. For example, the chain undecided->convert-eol-autodetect may |
486 have its separate parts detected as mswindows-multibyte and | 488 have its separate parts detected as mswindows-multibyte and |
487 convert-eol-crlf, and the result needs to be mapped to | 489 convert-eol-crlf, and the result needs to be mapped to |
3749 | 3751 |
3750 return Fget_coding_system (Qraw_text); | 3752 return Fget_coding_system (Qraw_text); |
3751 } | 3753 } |
3752 } | 3754 } |
3753 | 3755 |
3756 /* Look for a coding system in the string (skipping over leading | |
3757 blanks). If found, return it, otherwise nil. */ | |
3758 | |
3759 static Lisp_Object | |
3760 snarf_coding_system (const Ibyte *p, Bytecount len) | |
3761 { | |
3762 Bytecount n; | |
3763 Ibyte *name; | |
3764 | |
3765 while (*p == ' ' || *p == '\t') p++, len--; | |
3766 len = min (len, 1000); | |
3767 name = alloca_ibytes (len + 1); | |
3768 memcpy (name, p, len); | |
3769 name[len] = '\0'; | |
3770 | |
3771 /* Get coding system name */ | |
3772 /* Characters valid in a MIME charset name (rfc 1521), | |
3773 and in a Lisp symbol name. */ | |
3774 n = qxestrspn (name, | |
3775 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
3776 "abcdefghijklmnopqrstuvwxyz" | |
3777 "0123456789" | |
3778 "!$%&*+-.^_{|}~"); | |
3779 if (n > 0) | |
3780 { | |
3781 name[n] = '\0'; | |
3782 return find_coding_system_for_text_file (intern_int (name), 0); | |
3783 } | |
3784 | |
3785 return Qnil; | |
3786 } | |
3787 | |
3754 /* Given a seekable read stream and potential coding system and EOL type | 3788 /* Given a seekable read stream and potential coding system and EOL type |
3755 as specified, do any autodetection that is called for. If the | 3789 as specified, do any autodetection that is called for. If the |
3756 coding system and/or EOL type are not `autodetect', they will be left | 3790 coding system and/or EOL type are not `autodetect', they will be left |
3757 alone; but this function will never return an autodetect coding system | 3791 alone; but this function will never return an autodetect coding system |
3758 or EOL type. | 3792 or EOL type. |
3770 free_detection_state (st); | 3804 free_detection_state (st); |
3771 free_opaque_ptr (opaque); | 3805 free_opaque_ptr (opaque); |
3772 return Qnil; | 3806 return Qnil; |
3773 } | 3807 } |
3774 | 3808 |
3809 /* #### This duplicates code in `find-coding-system-magic-cookie-in-file' | |
3810 in files.el. Look into combining them. */ | |
3811 | |
3775 static Lisp_Object | 3812 static Lisp_Object |
3776 look_for_coding_system_magic_cookie (const UExtbyte *data, Bytecount len) | 3813 look_for_coding_system_magic_cookie (const UExtbyte *data, Bytecount len) |
3777 { | 3814 { |
3778 Lisp_Object coding_system = Qnil; | |
3779 const UExtbyte *p; | 3815 const UExtbyte *p; |
3780 const UExtbyte *scan_end; | 3816 const UExtbyte *scan_end; |
3781 | 3817 |
3782 /* Look for initial "-*-"; mode line prefix */ | 3818 /* Look for initial "-*-"; mode line prefix */ |
3783 for (p = data, | 3819 for (p = data, |
3808 && (p == local_vars_beg | 3844 && (p == local_vars_beg |
3809 || (*(p-1) == ' ' || | 3845 || (*(p-1) == ' ' || |
3810 *(p-1) == '\t' || | 3846 *(p-1) == '\t' || |
3811 *(p-1) == ';'))) | 3847 *(p-1) == ';'))) |
3812 { | 3848 { |
3813 Bytecount n; | |
3814 Ibyte *name; | |
3815 | |
3816 p += LENGTH ("coding:"); | 3849 p += LENGTH ("coding:"); |
3817 while (*p == ' ' || *p == '\t') p++; | 3850 return snarf_coding_system (p, suffix - p); |
3818 name = alloca_ibytes (suffix - p + 1); | |
3819 memcpy (name, p, suffix - p); | |
3820 name[suffix - p] = '\0'; | |
3821 | |
3822 /* Get coding system name */ | |
3823 /* Characters valid in a MIME charset name (rfc 1521), | |
3824 and in a Lisp symbol name. */ | |
3825 n = qxestrspn (name, | |
3826 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
3827 "abcdefghijklmnopqrstuvwxyz" | |
3828 "0123456789" | |
3829 "!$%&*+-.^_{|}~"); | |
3830 if (n > 0) | |
3831 { | |
3832 name[n] = '\0'; | |
3833 coding_system = | |
3834 find_coding_system_for_text_file (intern_int (name), | |
3835 0); | |
3836 } | |
3837 break; | 3851 break; |
3838 } | 3852 } |
3839 break; | 3853 break; |
3840 } | 3854 } |
3841 break; | 3855 break; |
3842 } | 3856 } |
3843 | 3857 |
3844 return coding_system; | 3858 /* Look for initial ;;;###coding system */ |
3859 | |
3860 { | |
3861 Bytecount ind = fast_string_match (QScoding_system_cookie, | |
3862 data, Qnil, 0, len, 0, ERROR_ME_NOT, | |
3863 1); | |
3864 if (ind >= 0) | |
3865 return | |
3866 snarf_coding_system (data + ind + LENGTH (";;;###coding system: "), | |
3867 len - ind - LENGTH (";;;###coding system: ")); | |
3868 } | |
3869 | |
3870 return Qnil; | |
3845 } | 3871 } |
3846 | 3872 |
3847 static Lisp_Object | 3873 static Lisp_Object |
3848 determine_real_coding_system (Lstream *stream) | 3874 determine_real_coding_system (Lstream *stream) |
3849 { | 3875 { |
4754 reinit_vars_of_file_coding (); | 4780 reinit_vars_of_file_coding (); |
4755 | 4781 |
4756 /* We always have file-coding support */ | 4782 /* We always have file-coding support */ |
4757 Fprovide (intern ("file-coding")); | 4783 Fprovide (intern ("file-coding")); |
4758 | 4784 |
4785 QScoding_system_cookie = build_string (";;;###coding system: "); | |
4786 staticpro (&QScoding_system_cookie); | |
4787 | |
4759 #ifdef HAVE_DEFAULT_EOL_DETECTION | 4788 #ifdef HAVE_DEFAULT_EOL_DETECTION |
4760 /* WARNING: The existing categories are intimately tied to the function | 4789 /* WARNING: The existing categories are intimately tied to the function |
4761 `coding-system-category' in coding.el. If you change a category, or | 4790 `coding-system-category' in coding.el. If you change a category, or |
4762 change the layout of any coding system associated with a category, you | 4791 change the layout of any coding system associated with a category, you |
4763 need to check that function and make sure it's written properly. */ | 4792 need to check that function and make sure it's written properly. */ |