Mercurial > vim
comparison src/fileio.c @ 6618:a871b5070d59 v7.4.635
updated for version 7.4.635
Problem: If no NL or CR is found in the first block of a file then the
'fileformat' may be set to "mac". (Issue 77)
Solution: Check if a CR was found. (eswald)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 17 Feb 2015 14:15:19 +0100 |
parents | a5ba0921efcb |
children | a532340f3940 |
comparison
equal
deleted
inserted
replaced
6617:ee31638d1adf | 6618:a871b5070d59 |
---|---|
2099 /* First try finding a NL, for Dos and Unix */ | 2099 /* First try finding a NL, for Dos and Unix */ |
2100 if (try_dos || try_unix) | 2100 if (try_dos || try_unix) |
2101 { | 2101 { |
2102 for (p = ptr; p < ptr + size; ++p) | 2102 for (p = ptr; p < ptr + size; ++p) |
2103 { | 2103 { |
2104 /* Reset the carriage return counter. */ | |
2105 if (try_mac) | |
2106 try_mac = 1; | |
2107 | |
2104 if (*p == NL) | 2108 if (*p == NL) |
2105 { | 2109 { |
2106 if (!try_unix | 2110 if (!try_unix |
2107 || (try_dos && p > ptr && p[-1] == CAR)) | 2111 || (try_dos && p > ptr && p[-1] == CAR)) |
2108 fileformat = EOL_DOS; | 2112 fileformat = EOL_DOS; |
2109 else | 2113 else |
2110 fileformat = EOL_UNIX; | 2114 fileformat = EOL_UNIX; |
2111 break; | 2115 break; |
2112 } | 2116 } |
2117 else if (*p == CAR && try_mac) | |
2118 try_mac++; | |
2113 } | 2119 } |
2114 | 2120 |
2115 /* Don't give in to EOL_UNIX if EOL_MAC is more likely */ | 2121 /* Don't give in to EOL_UNIX if EOL_MAC is more likely */ |
2116 if (fileformat == EOL_UNIX && try_mac) | 2122 if (fileformat == EOL_UNIX && try_mac) |
2117 { | 2123 { |
2131 } | 2137 } |
2132 if (try_mac > try_unix) | 2138 if (try_mac > try_unix) |
2133 fileformat = EOL_MAC; | 2139 fileformat = EOL_MAC; |
2134 } | 2140 } |
2135 } | 2141 } |
2142 else if (fileformat == EOL_UNKNOWN && try_mac == 1) | |
2143 /* Looking for CR but found no end-of-line markers at | |
2144 * all: use the default format. */ | |
2145 fileformat = default_fileformat(); | |
2136 } | 2146 } |
2137 | 2147 |
2138 /* No NL found: may use Mac format */ | 2148 /* No NL found: may use Mac format */ |
2139 if (fileformat == EOL_UNKNOWN && try_mac) | 2149 if (fileformat == EOL_UNKNOWN && try_mac) |
2140 fileformat = EOL_MAC; | 2150 fileformat = EOL_MAC; |