|
1 To: [email protected] |
|
2 Subject: Patch 7.2.100 |
|
3 Fcc: outbox |
|
4 From: Bram Moolenaar <[email protected]> |
|
5 Mime-Version: 1.0 |
|
6 Content-Type: text/plain; charset=ISO-8859-1 |
|
7 Content-Transfer-Encoding: 8bit |
|
8 ------------ |
|
9 |
|
10 Patch 7.2.100 |
|
11 Problem: When using ":source" on a FIFO or something else that can't rewind |
|
12 the first three bytes are skipped. |
|
13 Solution: Instead of rewinding read the first line and detect a BOM in that. |
|
14 (mostly by James Vega) |
|
15 Files: src/ex_cmds2.c |
|
16 |
|
17 |
|
18 *** ../vim-7.2.099/src/ex_cmds2.c Sat Nov 15 14:10:23 2008 |
|
19 --- src/ex_cmds2.c Wed Feb 4 16:05:51 2009 |
|
20 *************** |
|
21 *** 2842,2847 **** |
|
22 --- 2842,2848 ---- |
|
23 linenr_T save_sourcing_lnum; |
|
24 char_u *p; |
|
25 char_u *fname_exp; |
|
26 + char_u *firstline = NULL; |
|
27 int retval = FAIL; |
|
28 #ifdef FEAT_EVAL |
|
29 scid_T save_current_SID; |
|
30 *************** |
|
31 *** 2992,3014 **** |
|
32 |
|
33 cookie.level = ex_nesting_level; |
|
34 #endif |
|
35 - #ifdef FEAT_MBYTE |
|
36 - cookie.conv.vc_type = CONV_NONE; /* no conversion */ |
|
37 - |
|
38 - /* Try reading the first few bytes to check for a UTF-8 BOM. */ |
|
39 - { |
|
40 - char_u buf[3]; |
|
41 - |
|
42 - if (fread((char *)buf, sizeof(char_u), (size_t)3, cookie.fp) |
|
43 - == (size_t)3 |
|
44 - && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf) |
|
45 - /* Found BOM, setup conversion and skip over it. */ |
|
46 - convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); |
|
47 - else |
|
48 - /* No BOM found, rewind. */ |
|
49 - fseek(cookie.fp, 0L, SEEK_SET); |
|
50 - } |
|
51 - #endif |
|
52 |
|
53 /* |
|
54 * Keep the sourcing name/lnum, for recursive calls. |
|
55 --- 2993,2998 ---- |
|
56 *************** |
|
57 *** 3018,3023 **** |
|
58 --- 3002,3026 ---- |
|
59 save_sourcing_lnum = sourcing_lnum; |
|
60 sourcing_lnum = 0; |
|
61 |
|
62 + #ifdef FEAT_MBYTE |
|
63 + cookie.conv.vc_type = CONV_NONE; /* no conversion */ |
|
64 + |
|
65 + /* Read the first line so we can check for a UTF-8 BOM. */ |
|
66 + firstline = getsourceline(0, (void *)&cookie, 0); |
|
67 + if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef |
|
68 + && firstline[1] == 0xbb && firstline[2] == 0xbf) |
|
69 + { |
|
70 + /* Found BOM; setup conversion, skip over BOM and recode the line. */ |
|
71 + convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); |
|
72 + p = string_convert(&cookie.conv, firstline + 3, NULL); |
|
73 + if (p != NULL) |
|
74 + { |
|
75 + vim_free(firstline); |
|
76 + firstline = p; |
|
77 + } |
|
78 + } |
|
79 + #endif |
|
80 + |
|
81 #ifdef STARTUPTIME |
|
82 time_push(&tv_rel, &tv_start); |
|
83 #endif |
|
84 *************** |
|
85 *** 3111,3119 **** |
|
86 /* |
|
87 * Call do_cmdline, which will call getsourceline() to get the lines. |
|
88 */ |
|
89 ! do_cmdline(NULL, getsourceline, (void *)&cookie, |
|
90 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); |
|
91 - |
|
92 retval = OK; |
|
93 |
|
94 #ifdef FEAT_PROFILE |
|
95 --- 3114,3121 ---- |
|
96 /* |
|
97 * Call do_cmdline, which will call getsourceline() to get the lines. |
|
98 */ |
|
99 ! do_cmdline(firstline, getsourceline, (void *)&cookie, |
|
100 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); |
|
101 retval = OK; |
|
102 |
|
103 #ifdef FEAT_PROFILE |
|
104 *************** |
|
105 *** 3171,3176 **** |
|
106 --- 3173,3179 ---- |
|
107 #endif |
|
108 fclose(cookie.fp); |
|
109 vim_free(cookie.nextline); |
|
110 + vim_free(firstline); |
|
111 #ifdef FEAT_MBYTE |
|
112 convert_setup(&cookie.conv, NULL, NULL); |
|
113 #endif |
|
114 *** ../vim-7.2.099/src/version.c Wed Feb 4 17:27:50 2009 |
|
115 --- src/version.c Wed Feb 4 17:48:47 2009 |
|
116 *************** |
|
117 *** 678,679 **** |
|
118 --- 678,681 ---- |
|
119 { /* Add new patch number below this line */ |
|
120 + /**/ |
|
121 + 100, |
|
122 /**/ |
|
123 |
|
124 -- |
|
125 Well, you come from nothing, you go back to nothing... What have you |
|
126 lost? Nothing! |
|
127 -- Monty Python: The life of Brian |
|
128 |
|
129 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ |
|
130 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ |
|
131 \\\ download, build and distribute -- http://www.A-A-P.org /// |
|
132 \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |