Hi,
Currently when using cscope with vim and being several levels deep from
project root directory (with cscope.out located in this directory), the
cscope queries fail because of lack of prefix. Using a cscope prefix on
a per-project basis is hard. So, this patch introduces a boolean
variable setting which vim will be able use (in the absence of an
already existing prefix path) the prefix of cscope.out to canonicalize
the path obtained from 'cs find'. I have also tested it and it works
fine.

--------------------------
Raghavendra Prabhu
GPG Id : D72BE977
Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977

From 6296ddbecde5023ffc414bb7a92bd887a1b516c1 Mon Sep 17 00:00:00 2001
From: Raghavendra D Prabhu <[email protected]>
Date: Sat, 16 Apr 2011 16:36:04 +0530
Subject: [PATCH 1/2] Added cscopeoutppath (csop)

Currently, the only way to obtain canonical path for cscope is to use
ppath. However, using it on per project basis can be annoying. So this
introduces a boolean flag - csop - setting which makes vim use the
dirname of path of cscope out file (usually located in the root of
project directory) as the prefix in the absence of an already existing
ppath.

Signed-off-by: Raghavendra D Prabhu <[email protected]>
---
 src/if_cscope.c |   10 +++++++++-
 src/if_cscope.h |    2 +-
 src/option.c    |    9 ++++++++-
 src/option.h    |    1 +
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/if_cscope.c b/src/if_cscope.c
index 82c5173..6e454b5 100644
--- a/src/if_cscope.c
+++ b/src/if_cscope.c
@@ -2480,6 +2480,7 @@ cs_resolve_file(i, name)
     char *name;
 {
     char *fullname;
+    char *prefix;
     int len;
 
     /*
@@ -2490,6 +2491,9 @@ cs_resolve_file(i, name)
     len = (int)(strlen(name) + 2);
     if (csinfo[i].ppath != NULL)
        len += (int)strlen(csinfo[i].ppath);
+    else if (p_csop) {
+       len += (int)strlen(dirname(strdup(csinfo[i].fname)));
+    }
 
     if ((fullname = (char *)alloc(len)) == NULL)
        return NULL;
@@ -2508,7 +2512,11 @@ cs_resolve_file(i, name)
        )
        (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name);
     else
-       (void)sprintf(fullname, "%s", name);
+       if (p_csop && csinfo[i].fname != NULL) {
+           (void)sprintf(fullname, "%s/%s", 
dirname(strdup(csinfo[i].fname)),name);
+       } 
+       else
+           (void)sprintf(fullname, "%s", name);
 
     return fullname;
 } /* cs_resolve_file */
diff --git a/src/if_cscope.h b/src/if_cscope.h
index 5620eb3..ddfee28 100644
--- a/src/if_cscope.h
+++ b/src/if_cscope.h
@@ -10,7 +10,7 @@
  */
 
 #if defined(FEAT_CSCOPE) || defined(PROTO)
-
+#include <libgen.h>
 #if defined(UNIX)
 # include <sys/types.h>                /* pid_t */
 # include <sys/stat.h>         /* dev_t, ino_t */
diff --git a/src/option.c b/src/option.c
index b633466..3f5e695 100644
--- a/src/option.c
+++ b/src/option.c
@@ -898,13 +898,20 @@ static struct vimoption
                            {(char_u *)0L, (char_u *)0L}
 #endif
                            SCRIPTID_INIT},
+    {"cscopeoutppath", "csop", P_BOOL|P_VI_DEF|P_VIM, 
+#ifdef FEAT_CSCOPE
+                           (char_u *)&p_csop, PV_NONE,
+#else
+                           (char_u *)NULL, PV_NONE,
+#endif
+                           {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
     {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
                            (char_u *)&p_csqf, PV_NONE,
                            {(char_u *)"", (char_u *)0L}
 #else
                            (char_u *)NULL, PV_NONE,
-                           {(char_u *)0L, (char_u *)0L}
+                           {(char_u *)0L, (char_u *)0L}  
 #endif
                            SCRIPTID_INIT},
     {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
diff --git a/src/option.h b/src/option.h
index e2e65a0..149a156 100644
--- a/src/option.h
+++ b/src/option.h
@@ -391,6 +391,7 @@ EXTERN long p_ph;           /* 'pumheight' */
 EXTERN char_u  *p_cpo;         /* 'cpoptions' */
 #ifdef FEAT_CSCOPE
 EXTERN char_u  *p_csprg;       /* 'cscopeprg' */
+EXTERN int       p_csop;        /*  'cscopeoutppath' */
 # ifdef FEAT_QUICKFIX
 EXTERN char_u  *p_csqf;        /* 'cscopequickfix' */
 #  define      CSQF_CMDS   "sgdctefi"
-- 
1.7.4.4

From e54faee6e8e660ac0c9af5513ec2530644c54f93 Mon Sep 17 00:00:00 2001
From: Raghavendra D Prabhu <[email protected]>
Date: Sat, 16 Apr 2011 17:01:38 +0530
Subject: [PATCH 2/2] Updated documentation for cscopeoutppath


Signed-off-by: Raghavendra D Prabhu <[email protected]>
---
 runtime/doc/if_cscop.txt |    7 +++++++
 runtime/doc/options.txt  |    9 +++++++++
 runtime/doc/quickref.txt |    1 +
 runtime/doc/tags         |    1 +
 4 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/runtime/doc/if_cscop.txt b/runtime/doc/if_cscop.txt
index 91dd4c6..19509d6 100644
--- a/runtime/doc/if_cscop.txt
+++ b/runtime/doc/if_cscop.txt
@@ -271,6 +271,13 @@ tag files.  The default is off.  Examples: >
        :set cst
        :set nocst
 <
+                                                       *cscopeoutppath* *csop*
+If 'cscopeoutppath' set, then in absence of a prefix givent to cscope, prefix
+of cscope.out path (usually the project root directory)  will be used as the
+prefix path. The default is off. Examples: >
+       :set csop
+       :set nocsop
+<
                                                        *cscopetagorder* *csto*
 The value of 'csto' determines the order in which |:cstag| performs a search.
 If 'csto' is set to zero, cscope database(s) are searched first, followed
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 166c0aa..8fd9f6b 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2184,6 +2184,15 @@ A jump table for the options with a short description 
can be found at |Q_op|.
        Determines how many components of the path to show in a list of tags.
        See |cscopepathcomp|.
 
+                                               *'cscopeoutppath'* *'csop'*
+'cscopeoutppath' 'csop' boolean (default off)
+                        global
+                       {not available when compiled without the |+cscope|
+                       feature}
+                       {not in Vi}
+       In the absence of prefix path for cscope. setting this option enables
+       to use the prefix of cscope.out path as the prefix.
+
                                                *'cscopeprg'* *'csprg'*
 'cscopeprg' 'csprg'    string  (default "cscope")
                        global
diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt
index 5bf410e..e1e7212 100644
--- a/runtime/doc/quickref.txt
+++ b/runtime/doc/quickref.txt
@@ -655,6 +655,7 @@ Short explanation of each option:           *option-list*
 'cpoptions'      'cpo'     flags for Vi-compatible behavior
 'cryptmethod'    'cm'      type of encryption to use for file writing
 'cscopepathcomp'  'cspc'    how many components of the path to show
+'cscopeoutppath'  'csop'    Use cscope.out prefix as ppath
 'cscopeprg'       'csprg'   command to execute cscope
 'cscopequickfix'  'csqf'    use quickfix window for cscope results
 'cscopetag'       'cst'     use cscope for tag commands
diff --git a/runtime/doc/tags b/runtime/doc/tags
index bee39c1..ca09b65 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -152,6 +152,7 @@ $VIMRUNTIME starting.txt    /*$VIMRUNTIME*
 'crb'  options.txt     /*'crb'*
 'cryptmethod'  options.txt     /*'cryptmethod'*
 'cscopepathcomp'       options.txt     /*'cscopepathcomp'*
+'cscopeoutppath'       options.txt     /*'cscopeoutppath'*
 'cscopeprg'    options.txt     /*'cscopeprg'*
 'cscopequickfix'       options.txt     /*'cscopequickfix'*
 'cscopetag'    options.txt     /*'cscopetag'*
-- 
1.7.4.4

Attachment: pgpVyCqMGdi7y.pgp
Description: PGP signature

Raspunde prin e-mail lui