]> granicus.if.org Git - vim/commitdiff
updated for version 7.2-100 v7.2.100
authorBram Moolenaar <Bram@vim.org>
Wed, 4 Feb 2009 16:50:47 +0000 (16:50 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 4 Feb 2009 16:50:47 +0000 (16:50 +0000)
src/ex_cmds2.c
src/version.c

index 2c0f80dfe747c69f7e3b5c00f2917f8bc4e5a50c..704c7abc3ac09b25a23e474a7e3b5ce0d102b47e 100644 (file)
@@ -2842,6 +2842,7 @@ do_source(fname, check_other, is_vimrc)
     linenr_T               save_sourcing_lnum;
     char_u                 *p;
     char_u                 *fname_exp;
+    char_u                 *firstline = NULL;
     int                            retval = FAIL;
 #ifdef FEAT_EVAL
     scid_T                 save_current_SID;
@@ -2992,23 +2993,6 @@ do_source(fname, check_other, is_vimrc)
 
     cookie.level = ex_nesting_level;
 #endif
-#ifdef FEAT_MBYTE
-    cookie.conv.vc_type = CONV_NONE;           /* no conversion */
-
-    /* Try reading the first few bytes to check for a UTF-8 BOM. */
-    {
-       char_u      buf[3];
-
-       if (fread((char *)buf, sizeof(char_u), (size_t)3, cookie.fp)
-                                                                 == (size_t)3
-               && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
-           /* Found BOM, setup conversion and skip over it. */
-           convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
-       else
-           /* No BOM found, rewind. */
-           fseek(cookie.fp, 0L, SEEK_SET);
-    }
-#endif
 
     /*
      * Keep the sourcing name/lnum, for recursive calls.
@@ -3018,6 +3002,25 @@ do_source(fname, check_other, is_vimrc)
     save_sourcing_lnum = sourcing_lnum;
     sourcing_lnum = 0;
 
+#ifdef FEAT_MBYTE
+    cookie.conv.vc_type = CONV_NONE;           /* no conversion */
+
+    /* Read the first line so we can check for a UTF-8 BOM. */
+    firstline = getsourceline(0, (void *)&cookie, 0);
+    if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
+                             && firstline[1] == 0xbb && firstline[2] == 0xbf)
+    {
+       /* Found BOM; setup conversion, skip over BOM and recode the line. */
+       convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
+       p = string_convert(&cookie.conv, firstline + 3, NULL);
+       if (p != NULL)
+       {
+           vim_free(firstline);
+           firstline = p;
+       }
+    }
+#endif
+
 #ifdef STARTUPTIME
     time_push(&tv_rel, &tv_start);
 #endif
@@ -3111,9 +3114,8 @@ do_source(fname, check_other, is_vimrc)
     /*
      * Call do_cmdline, which will call getsourceline() to get the lines.
      */
-    do_cmdline(NULL, getsourceline, (void *)&cookie,
+    do_cmdline(firstline, getsourceline, (void *)&cookie,
                                     DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
-
     retval = OK;
 
 #ifdef FEAT_PROFILE
@@ -3171,6 +3173,7 @@ almosttheend:
 #endif
     fclose(cookie.fp);
     vim_free(cookie.nextline);
+    vim_free(firstline);
 #ifdef FEAT_MBYTE
     convert_setup(&cookie.conv, NULL, NULL);
 #endif
index 8a7c1da7832c8f2fc665b195b43c71b7e3516ab6..6676f4ab32d9c728dbfdfc1b277dfbaaa5084bf7 100644 (file)
@@ -676,6 +676,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    100,
 /**/
     99,
 /**/