To: vim-dev@vim.org Subject: patch 5.5.021 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.5.021 Problem: When checking if a file name in the tags file is relative, environment variables were not expanded. Solution: Expand the file name before checking if it is relative. (Madsen) Files: src/tag.c *** ../vim-5.5.20/src/tag.c Wed Sep 22 10:06:29 1999 --- src/tag.c Tue Oct 12 15:39:31 1999 *************** *** 75,81 **** static int test_for_static __ARGS((struct tag_pointers *)); static int parse_match __ARGS((char_u *lbuf, struct tag_pointers *tagp)); static char_u *tag_full_fname __ARGS((struct tag_pointers *tagp)); ! static char_u *expand_rel_name __ARGS((char_u *fname, char_u *tag_fname)); #ifdef EMACS_TAGS static int test_for_current __ARGS((int, char_u *, char_u *, char_u *)); #else --- 75,81 ---- static int test_for_static __ARGS((struct tag_pointers *)); static int parse_match __ARGS((char_u *lbuf, struct tag_pointers *tagp)); static char_u *tag_full_fname __ARGS((struct tag_pointers *tagp)); ! static char_u *expand_tag_fname __ARGS((char_u *fname, char_u *tag_fname, int expand)); #ifdef EMACS_TAGS static int test_for_current __ARGS((int, char_u *, char_u *, char_u *)); #else *************** *** 2167,2173 **** tag_full_fname(tagp) struct tag_pointers *tagp; { ! char_u *relname; int c; #ifdef EMACS_TAGS --- 2167,2173 ---- tag_full_fname(tagp) struct tag_pointers *tagp; { ! char_u *fullname; int c; #ifdef EMACS_TAGS *************** *** 2179,2192 **** c = *tagp->fname_end; *tagp->fname_end = NUL; } ! relname = expand_rel_name(tagp->fname, tagp->tag_fname); #ifdef EMACS_TAGS if (!tagp->is_etag) #endif *tagp->fname_end = c; ! return relname; } /* --- 2179,2192 ---- c = *tagp->fname_end; *tagp->fname_end = NUL; } ! fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, FALSE); #ifdef EMACS_TAGS if (!tagp->is_etag) #endif *tagp->fname_end = c; ! return fullname; } /* *************** *** 2207,2213 **** char_u *str; char_u *pbuf; /* search pattern buffer */ char_u *pbuf_end; - char_u *expanded_fname = NULL; char_u *tofree_fname = NULL; char_u *fname; struct tag_pointers tagp; --- 2207,2212 ---- *************** *** 2262,2279 **** } /* ! * expand file name (for environment variables) ! */ ! expand_context = EXPAND_FILES; ! expanded_fname = ExpandOne((char_u *)fname, NULL, ! WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); ! if (expanded_fname != NULL) ! fname = expanded_fname; ! ! /* ! * if 'tagrelative' option set, may change file name */ ! fname = expand_rel_name(fname, tagp.tag_fname); if (fname == NULL) goto erret; tofree_fname = fname; /* free() it later */ --- 2261,2270 ---- } /* ! * Expand file name, when needed (for environment variables). ! * If 'tagrelative' option set, may change file name. */ ! fname = expand_tag_fname(fname, tagp.tag_fname, TRUE); if (fname == NULL) goto erret; tofree_fname = fname; /* free() it later */ *************** *** 2515,2557 **** *tagp.fname_end = csave; vim_free(pbuf); vim_free(tofree_fname); - vim_free(expanded_fname); vim_free(full_fname); return retval; } /* * If 'tagrelative' option set, change fname (name of file containing tag) * according to tag_fname (name of tag file containing fname). * Returns a pointer to allocated memory (or NULL when out of memory). */ static char_u * ! expand_rel_name(fname, tag_fname) char_u *fname; char_u *tag_fname; { char_u *p; char_u *retval; if ((p_tr || curbuf->b_help) && !mch_isFullName(fname) && (p = gettail(tag_fname)) != tag_fname) { retval = alloc(MAXPATHL); ! if (retval == NULL) ! return NULL; ! ! STRCPY(retval, tag_fname); ! STRNCPY(retval + (p - tag_fname), fname, MAXPATHL - (p - tag_fname)); ! /* ! * Translate names like "src/a/../b/file.c" into "src/b/file.c". ! */ ! simplify_filename(retval); } else retval = vim_strsave(fname); return retval; } --- 2506,2564 ---- *tagp.fname_end = csave; vim_free(pbuf); vim_free(tofree_fname); vim_free(full_fname); return retval; } /* + * If "expand" is TRUE, expand wildcards in fname. * If 'tagrelative' option set, change fname (name of file containing tag) * according to tag_fname (name of tag file containing fname). * Returns a pointer to allocated memory (or NULL when out of memory). */ static char_u * ! expand_tag_fname(fname, tag_fname, expand) char_u *fname; char_u *tag_fname; + int expand; { char_u *p; char_u *retval; + char_u *expanded_fname = NULL; + + /* + * Expand file name (for environment variables) when needed. + */ + if (expand && mch_has_wildcard(fname)) + { + expand_context = EXPAND_FILES; + expanded_fname = ExpandOne((char_u *)fname, NULL, + WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); + if (expanded_fname != NULL) + fname = expanded_fname; + } if ((p_tr || curbuf->b_help) && !mch_isFullName(fname) && (p = gettail(tag_fname)) != tag_fname) { retval = alloc(MAXPATHL); ! if (retval != NULL) ! { ! STRCPY(retval, tag_fname); ! STRNCPY(retval + (p - tag_fname), fname, ! MAXPATHL - (p - tag_fname)); ! /* ! * Translate names like "src/a/../b/file.c" into "src/b/file.c". ! */ ! simplify_filename(retval); ! } } else retval = vim_strsave(fname); + vim_free(expanded_fname); return retval; } *************** *** 2662,2668 **** { int c; int retval = FALSE; ! char_u *relname; if (curbuf->b_ffname != NULL) /* if the current buffer has a name */ { --- 2669,2675 ---- { int c; int retval = FALSE; ! char_u *fullname; if (curbuf->b_ffname != NULL) /* if the current buffer has a name */ { *************** *** 2675,2685 **** c = *fname_end; *fname_end = NUL; } ! relname = expand_rel_name(fname, tag_fname); ! if (relname != NULL) { ! retval = (fullpathcmp(relname, curbuf->b_ffname, TRUE) & FPC_SAME); ! vim_free(relname); } #ifdef EMACS_TAGS if (!is_etag) --- 2682,2692 ---- c = *fname_end; *fname_end = NUL; } ! fullname = expand_tag_fname(fname, tag_fname, TRUE); ! if (fullname != NULL) { ! retval = (fullpathcmp(fullname, curbuf->b_ffname, TRUE) & FPC_SAME); ! vim_free(fullname); } #ifdef EMACS_TAGS if (!is_etag) *** ../vim-5.5.20/src/version.c Tue Oct 12 19:48:51 1999 --- src/version.c Tue Oct 12 19:49:40 1999 *************** *** 420,420 **** --- 420,421 ---- { /* Add new patch number below this line */ + 21, -- There are 2 kinds of people in my world: those who know Unix, Perl, Vim, GNU, Linux, etc, and those who know COBOL. It gets very difficult for me at parties, not knowing which group to socialise with :-) Sitaram Chamarty --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\-- \ \ www.vim.org/iccf www.moolenaar.net www.vim.org / /