home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.1 / 7.1.292 < prev    next >
Encoding:
Internet Message Format  |  2008-04-08  |  6.5 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.1.292
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.1.292
  11. Problem:    When using a pattern with "\@<=" the submatches can be wrong.
  12.         (Brett Stahlman)
  13. Solution:   Save the submatches when attempting a look-behind match.
  14. Files:        src/regexp.c
  15.  
  16.  
  17. *** ../vim-7.1.291/src/regexp.c    Sat Jan 19 15:55:51 2008
  18. --- src/regexp.c    Tue Apr  1 18:15:47 2008
  19. ***************
  20. *** 3039,3044 ****
  21. --- 3039,3053 ----
  22.       } se_u;
  23.   } save_se_T;
  24.   
  25. + /* used for BEHIND and NOBEHIND matching */
  26. + typedef struct regbehind_S
  27. + {
  28. +     regsave_T    save_after;
  29. +     regsave_T    save_behind;
  30. +     save_se_T   save_start[NSUBEXP];
  31. +     save_se_T   save_end[NSUBEXP];
  32. + } regbehind_T;
  33.   static char_u    *reg_getline __ARGS((linenr_T lnum));
  34.   static long    vim_regexec_both __ARGS((char_u *line, colnr_T col, proftime_T *tm));
  35.   static long    regtry __ARGS((regprog_T *prog, colnr_T col));
  36. ***************
  37. *** 3046,3051 ****
  38. --- 3055,3062 ----
  39.   #ifdef FEAT_SYN_HL
  40.   static void    cleanup_zsubexpr __ARGS((void));
  41.   #endif
  42. + static void    save_subexpr __ARGS((regbehind_T *bp));
  43. + static void    restore_subexpr __ARGS((regbehind_T *bp));
  44.   static void    reg_nextline __ARGS((void));
  45.   static void    reg_save __ARGS((regsave_T *save, garray_T *gap));
  46.   static void    reg_restore __ARGS((regsave_T *save, garray_T *gap));
  47. ***************
  48. *** 3166,3184 ****
  49.       save_se_T  sesave;
  50.       regsave_T  regsave;
  51.       } rs_un;            /* room for saving reginput */
  52. !     short    rs_no;        /* submatch nr */
  53.   } regitem_T;
  54.   
  55.   static regitem_T *regstack_push __ARGS((regstate_T state, char_u *scan));
  56.   static void regstack_pop __ARGS((char_u **scan));
  57.   
  58. - /* used for BEHIND and NOBEHIND matching */
  59. - typedef struct regbehind_S
  60. - {
  61. -     regsave_T    save_after;
  62. -     regsave_T    save_behind;
  63. - } regbehind_T;
  64.   /* used for STAR, PLUS and BRACE_SIMPLE matching */
  65.   typedef struct regstar_S
  66.   {
  67. --- 3177,3188 ----
  68.       save_se_T  sesave;
  69.       regsave_T  regsave;
  70.       } rs_un;            /* room for saving reginput */
  71. !     short    rs_no;        /* submatch nr or BEHIND/NOBEHIND */
  72.   } regitem_T;
  73.   
  74.   static regitem_T *regstack_push __ARGS((regstate_T state, char_u *scan));
  75.   static void regstack_pop __ARGS((char_u **scan));
  76.   
  77.   /* used for STAR, PLUS and BRACE_SIMPLE matching */
  78.   typedef struct regstar_S
  79.   {
  80. ***************
  81. *** 4888,4893 ****
  82. --- 4892,4901 ----
  83.               status = RA_FAIL;
  84.           else
  85.           {
  86. +             /* Need to save the subexpr to be able to restore them
  87. +              * when there is a match but we don't use it. */
  88. +             save_subexpr(((regbehind_T *)rp) - 1);
  89.               rp->rs_no = op;
  90.               reg_save(&rp->rs_un.regsave, &backpos);
  91.               /* First try if what follows matches.  If it does then we
  92. ***************
  93. *** 5118,5132 ****
  94.               reg_restore(&(((regbehind_T *)rp) - 1)->save_after,
  95.                                       &backpos);
  96.           else
  97. !             /* But we didn't want a match. */
  98.               status = RA_NOMATCH;
  99.           regstack_pop(&scan);
  100.           regstack.ga_len -= sizeof(regbehind_T);
  101.           }
  102.           else
  103.           {
  104. !         /* No match: Go back one character.  May go to previous
  105. !          * line once. */
  106.           no = OK;
  107.           if (REG_MULTI)
  108.           {
  109. --- 5126,5145 ----
  110.               reg_restore(&(((regbehind_T *)rp) - 1)->save_after,
  111.                                       &backpos);
  112.           else
  113. !         {
  114. !             /* But we didn't want a match.  Need to restore the
  115. !              * subexpr, because what follows matched, so they have
  116. !              * been set. */
  117.               status = RA_NOMATCH;
  118. +             restore_subexpr(((regbehind_T *)rp) - 1);
  119. +         }
  120.           regstack_pop(&scan);
  121.           regstack.ga_len -= sizeof(regbehind_T);
  122.           }
  123.           else
  124.           {
  125. !         /* No match or a match that doesn't end where we want it: Go
  126. !          * back one character.  May go to previous line once. */
  127.           no = OK;
  128.           if (REG_MULTI)
  129.           {
  130. ***************
  131. *** 5160,5165 ****
  132. --- 5173,5185 ----
  133.               /* Advanced, prepare for finding match again. */
  134.               reg_restore(&rp->rs_un.regsave, &backpos);
  135.               scan = OPERAND(rp->rs_scan);
  136. +             if (status == RA_MATCH)
  137. +             {
  138. +             /* We did match, so subexpr may have been changed,
  139. +              * need to restore them for the next try. */
  140. +             status = RA_NOMATCH;
  141. +             restore_subexpr(((regbehind_T *)rp) - 1);
  142. +             }
  143.           }
  144.           else
  145.           {
  146. ***************
  147. *** 5172,5178 ****
  148.               status = RA_MATCH;
  149.               }
  150.               else
  151. !             status = RA_NOMATCH;
  152.               regstack_pop(&scan);
  153.               regstack.ga_len -= sizeof(regbehind_T);
  154.           }
  155. --- 5192,5207 ----
  156.               status = RA_MATCH;
  157.               }
  158.               else
  159. !             {
  160. !             /* We do want a proper match.  Need to restore the
  161. !              * subexpr if we had a match, because they may have
  162. !              * been set. */
  163. !             if (status == RA_MATCH)
  164. !             {
  165. !                 status = RA_NOMATCH;
  166. !                 restore_subexpr(((regbehind_T *)rp) - 1);
  167. !             }
  168. !             }
  169.               regstack_pop(&scan);
  170.               regstack.ga_len -= sizeof(regbehind_T);
  171.           }
  172. ***************
  173. *** 5820,5825 ****
  174. --- 5849,5903 ----
  175.   #endif
  176.   
  177.   /*
  178. +  * Save the current subexpr to "bp", so that they can be restored
  179. +  * later by restore_subexpr().
  180. +  */
  181. +     static void
  182. + save_subexpr(bp)
  183. +     regbehind_T *bp;
  184. + {
  185. +     int i;
  186. +     for (i = 0; i < NSUBEXP; ++i)
  187. +     {
  188. +     if (REG_MULTI)
  189. +     {
  190. +         bp->save_start[i].se_u.pos = reg_startpos[i];
  191. +         bp->save_end[i].se_u.pos = reg_endpos[i];
  192. +     }
  193. +     else
  194. +     {
  195. +         bp->save_start[i].se_u.ptr = reg_startp[i];
  196. +         bp->save_end[i].se_u.ptr = reg_endp[i];
  197. +     }
  198. +     }
  199. + }
  200. + /*
  201. +  * Restore the subexpr from "bp".
  202. +  */
  203. +     static void
  204. + restore_subexpr(bp)
  205. +     regbehind_T *bp;
  206. + {
  207. +     int i;
  208. +     for (i = 0; i < NSUBEXP; ++i)
  209. +     {
  210. +     if (REG_MULTI)
  211. +     {
  212. +         reg_startpos[i] = bp->save_start[i].se_u.pos;
  213. +         reg_endpos[i] = bp->save_end[i].se_u.pos;
  214. +     }
  215. +     else
  216. +     {
  217. +         reg_startp[i] = bp->save_start[i].se_u.ptr;
  218. +         reg_endp[i] = bp->save_end[i].se_u.ptr;
  219. +     }
  220. +     }
  221. + }
  222. + /*
  223.    * Advance reglnum, regline and reginput to the next line.
  224.    */
  225.       static void
  226. *** ../vim-7.1.291/src/version.c    Tue Apr  1 20:58:23 2008
  227. --- src/version.c    Wed Apr  9 12:12:33 2008
  228. ***************
  229. *** 668,669 ****
  230. --- 673,676 ----
  231.   {   /* Add new patch number below this line */
  232. + /**/
  233. +     292,
  234.   /**/
  235.  
  236. -- 
  237. hundred-and-one symptoms of being an internet addict:
  238. 259. When you enter your name in the AltaVista search engine, the top ten
  239.      matches do indeed refer to you.
  240.  
  241.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  242. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  243. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  244.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  245.