4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
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)
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
23 linenr_T save_sourcing_lnum;
26 + char_u *firstline = NULL;
29 scid_T save_current_SID;
33 cookie.level = ex_nesting_level;
36 - cookie.conv.vc_type = CONV_NONE; /* no conversion */
38 - /* Try reading the first few bytes to check for a UTF-8 BOM. */
42 - if (fread((char *)buf, sizeof(char_u), (size_t)3, cookie.fp)
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);
48 - /* No BOM found, rewind. */
49 - fseek(cookie.fp, 0L, SEEK_SET);
54 * Keep the sourcing name/lnum, for recursive calls.
59 save_sourcing_lnum = sourcing_lnum;
63 + cookie.conv.vc_type = CONV_NONE; /* no conversion */
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)
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);
75 + vim_free(firstline);
82 time_push(&tv_rel, &tv_start);
87 * Call do_cmdline, which will call getsourceline() to get the lines.
89 ! do_cmdline(NULL, getsourceline, (void *)&cookie,
90 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
97 * Call do_cmdline, which will call getsourceline() to get the lines.
99 ! do_cmdline(firstline, getsourceline, (void *)&cookie,
100 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
109 vim_free(cookie.nextline);
110 + vim_free(firstline);
112 convert_setup(&cookie.conv, NULL, NULL);
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
119 { /* Add new patch number below this line */
125 Well, you come from nothing, you go back to nothing... What have you
127 -- Monty Python: The life of Brian
129 /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///