Karsten Hopp 5267cd
To: vim-dev@vim.org
Karsten Hopp 5267cd
Subject: Patch 7.2.100
Karsten Hopp 5267cd
Fcc: outbox
Karsten Hopp 5267cd
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 5267cd
Mime-Version: 1.0
Karsten Hopp 5267cd
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 5267cd
Content-Transfer-Encoding: 8bit
Karsten Hopp 5267cd
------------
Karsten Hopp 5267cd
Karsten Hopp 5267cd
Patch 7.2.100
Karsten Hopp 5267cd
Problem:    When using ":source" on a FIFO or something else that can't rewind
Karsten Hopp 5267cd
	    the first three bytes are skipped.
Karsten Hopp 5267cd
Solution:   Instead of rewinding read the first line and detect a BOM in that.
Karsten Hopp 5267cd
	    (mostly by James Vega)
Karsten Hopp 5267cd
Files:	    src/ex_cmds2.c
Karsten Hopp 5267cd
Karsten Hopp 5267cd
Karsten Hopp 5267cd
*** ../vim-7.2.099/src/ex_cmds2.c	Sat Nov 15 14:10:23 2008
Karsten Hopp 5267cd
--- src/ex_cmds2.c	Wed Feb  4 16:05:51 2009
Karsten Hopp 5267cd
***************
Karsten Hopp 5267cd
*** 2842,2847 ****
Karsten Hopp 5267cd
--- 2842,2848 ----
Karsten Hopp 5267cd
      linenr_T		    save_sourcing_lnum;
Karsten Hopp 5267cd
      char_u		    *p;
Karsten Hopp 5267cd
      char_u		    *fname_exp;
Karsten Hopp 5267cd
+     char_u		    *firstline = NULL;
Karsten Hopp 5267cd
      int			    retval = FAIL;
Karsten Hopp 5267cd
  #ifdef FEAT_EVAL
Karsten Hopp 5267cd
      scid_T		    save_current_SID;
Karsten Hopp 5267cd
***************
Karsten Hopp 5267cd
*** 2992,3014 ****
Karsten Hopp 5267cd
  
Karsten Hopp 5267cd
      cookie.level = ex_nesting_level;
Karsten Hopp 5267cd
  #endif
Karsten Hopp 5267cd
- #ifdef FEAT_MBYTE
Karsten Hopp 5267cd
-     cookie.conv.vc_type = CONV_NONE;		/* no conversion */
Karsten Hopp 5267cd
- 
Karsten Hopp 5267cd
-     /* Try reading the first few bytes to check for a UTF-8 BOM. */
Karsten Hopp 5267cd
-     {
Karsten Hopp 5267cd
- 	char_u	    buf[3];
Karsten Hopp 5267cd
- 
Karsten Hopp 5267cd
- 	if (fread((char *)buf, sizeof(char_u), (size_t)3, cookie.fp)
Karsten Hopp 5267cd
- 								  == (size_t)3
Karsten Hopp 5267cd
- 		&& buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
Karsten Hopp 5267cd
- 	    /* Found BOM, setup conversion and skip over it. */
Karsten Hopp 5267cd
- 	    convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
Karsten Hopp 5267cd
- 	else
Karsten Hopp 5267cd
- 	    /* No BOM found, rewind. */
Karsten Hopp 5267cd
- 	    fseek(cookie.fp, 0L, SEEK_SET);
Karsten Hopp 5267cd
-     }
Karsten Hopp 5267cd
- #endif
Karsten Hopp 5267cd
  
Karsten Hopp 5267cd
      /*
Karsten Hopp 5267cd
       * Keep the sourcing name/lnum, for recursive calls.
Karsten Hopp 5267cd
--- 2993,2998 ----
Karsten Hopp 5267cd
***************
Karsten Hopp 5267cd
*** 3018,3023 ****
Karsten Hopp 5267cd
--- 3002,3026 ----
Karsten Hopp 5267cd
      save_sourcing_lnum = sourcing_lnum;
Karsten Hopp 5267cd
      sourcing_lnum = 0;
Karsten Hopp 5267cd
  
Karsten Hopp 5267cd
+ #ifdef FEAT_MBYTE
Karsten Hopp 5267cd
+     cookie.conv.vc_type = CONV_NONE;		/* no conversion */
Karsten Hopp 5267cd
+ 
Karsten Hopp 5267cd
+     /* Read the first line so we can check for a UTF-8 BOM. */
Karsten Hopp 5267cd
+     firstline = getsourceline(0, (void *)&cookie, 0);
Karsten Hopp 5267cd
+     if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
Karsten Hopp 5267cd
+ 			      && firstline[1] == 0xbb && firstline[2] == 0xbf)
Karsten Hopp 5267cd
+     {
Karsten Hopp 5267cd
+ 	/* Found BOM; setup conversion, skip over BOM and recode the line. */
Karsten Hopp 5267cd
+ 	convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
Karsten Hopp 5267cd
+ 	p = string_convert(&cookie.conv, firstline + 3, NULL);
Karsten Hopp 5267cd
+ 	if (p != NULL)
Karsten Hopp 5267cd
+ 	{
Karsten Hopp 5267cd
+ 	    vim_free(firstline);
Karsten Hopp 5267cd
+ 	    firstline = p;
Karsten Hopp 5267cd
+ 	}
Karsten Hopp 5267cd
+     }
Karsten Hopp 5267cd
+ #endif
Karsten Hopp 5267cd
+ 
Karsten Hopp 5267cd
  #ifdef STARTUPTIME
Karsten Hopp 5267cd
      time_push(&tv_rel, &tv_start);
Karsten Hopp 5267cd
  #endif
Karsten Hopp 5267cd
***************
Karsten Hopp 5267cd
*** 3111,3119 ****
Karsten Hopp 5267cd
      /*
Karsten Hopp 5267cd
       * Call do_cmdline, which will call getsourceline() to get the lines.
Karsten Hopp 5267cd
       */
Karsten Hopp 5267cd
!     do_cmdline(NULL, getsourceline, (void *)&cookie,
Karsten Hopp 5267cd
  				     DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
Karsten Hopp 5267cd
- 
Karsten Hopp 5267cd
      retval = OK;
Karsten Hopp 5267cd
  
Karsten Hopp 5267cd
  #ifdef FEAT_PROFILE
Karsten Hopp 5267cd
--- 3114,3121 ----
Karsten Hopp 5267cd
      /*
Karsten Hopp 5267cd
       * Call do_cmdline, which will call getsourceline() to get the lines.
Karsten Hopp 5267cd
       */
Karsten Hopp 5267cd
!     do_cmdline(firstline, getsourceline, (void *)&cookie,
Karsten Hopp 5267cd
  				     DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
Karsten Hopp 5267cd
      retval = OK;
Karsten Hopp 5267cd
  
Karsten Hopp 5267cd
  #ifdef FEAT_PROFILE
Karsten Hopp 5267cd
***************
Karsten Hopp 5267cd
*** 3171,3176 ****
Karsten Hopp 5267cd
--- 3173,3179 ----
Karsten Hopp 5267cd
  #endif
Karsten Hopp 5267cd
      fclose(cookie.fp);
Karsten Hopp 5267cd
      vim_free(cookie.nextline);
Karsten Hopp 5267cd
+     vim_free(firstline);
Karsten Hopp 5267cd
  #ifdef FEAT_MBYTE
Karsten Hopp 5267cd
      convert_setup(&cookie.conv, NULL, NULL);
Karsten Hopp 5267cd
  #endif
Karsten Hopp 5267cd
*** ../vim-7.2.099/src/version.c	Wed Feb  4 17:27:50 2009
Karsten Hopp 5267cd
--- src/version.c	Wed Feb  4 17:48:47 2009
Karsten Hopp 5267cd
***************
Karsten Hopp 5267cd
*** 678,679 ****
Karsten Hopp 5267cd
--- 678,681 ----
Karsten Hopp 5267cd
  {   /* Add new patch number below this line */
Karsten Hopp 5267cd
+ /**/
Karsten Hopp 5267cd
+     100,
Karsten Hopp 5267cd
  /**/
Karsten Hopp 5267cd
Karsten Hopp 5267cd
-- 
Karsten Hopp 5267cd
Well, you come from nothing, you go back to nothing...  What have you
Karsten Hopp 5267cd
lost?  Nothing!
Karsten Hopp 5267cd
				-- Monty Python: The life of Brian
Karsten Hopp 5267cd
Karsten Hopp 5267cd
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 5267cd
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 5267cd
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 5267cd
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///