Hello,

        I send you some modifications I have done to cscope and I hope can be
useful for other users.

Patch 0001: Use VISUAL variable when it is avaible and the terminal is not a
            dumb terminal. I have to add this patch because I usually have to
            connect to system which terminal interfaces dumb type, so my
            EDITOR and VISUAL variables have different values, but I usually
            want see sources with vi and not with ex.

Patch 0002: This patch is only a small addition to the manual page, because
            the assignmenet case was not showed in it.

Patch 0003: This patch adds a way of filtering the results in finddef function,
            since we have information about the kind of symbol. I have add
            a solution which doesn't increment the number of options in the
            graphical interface (it is already big), and it is basically
            add the kind of definition in the search pattern. I don't have
            modified the manual page, because I don't know if this change
            will be good for you. 


        I would like listen your opinion about these changes and if they
must be modified or something.


Best regards, 


-- 
Roberto E. Vargas Caballero
----------------------------
k...@shike2.com
http://www.shike2.com
>From ca309eb459979d66be45c09f4a29a57f20525a31 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Fri, 19 Oct 2012 20:20:10 +0200
Subject: [PATCH 1/3] Use EDITOR variable when VISUAL is not defined or we
 have a dumb terminal

VISUAL is the environment variable which says what editor must be used when
our terminal is a graphical one. In other case, the varible which must be
used is EDITOR. It is strange today a terminal dumb, but in some situations
there are persons who had different values in EDITOR and in VISUAL.
---
 doc/cscope.1 |    5 ++++-
 src/main.c   |    4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/doc/cscope.1 b/doc/cscope.1
index e1bf0e7..a815e94 100644
--- a/doc/cscope.1
+++ b/doc/cscope.1
@@ -404,7 +404,7 @@ character of an input line is ``^d'' or ``q''.
 .SH "ENVIRONMENT VARIABLES"
 .TP
 .B CSCOPE_EDITOR
-Overrides the EDITOR and VIEWER variables. Use this if you wish to use
+Overrides the EDITOR, VISUAL and VIEWER variables. Use this if you wish to use
 a different editor with cscope than that specified by your
 EDITOR/VIEWER variables.
 .TP
@@ -425,6 +425,9 @@ the example from CSCOPE_LINEFLAG, above: if your editor 
needs to see
 ``editor file -#number'', set this environment variable. Users of most
 standard editors (vi, emacs) do not need to set this variable.
 .TP
+.B VISUAL
+Preferred editor in screen-oriented terminals.
+.TP
 .B EDITOR
 Preferred editor, which defaults to vi.
 .TP
diff --git a/src/main.c b/src/main.c
index fc31723..6c39a61 100644
--- a/src/main.c
+++ b/src/main.c
@@ -291,7 +291,7 @@ main(int argc, char **argv)
     int        oldnum;                 /* number in old cross-ref */
     char path[PATHLEN + 1];    /* file path */
     FILE *oldrefs;     /* old cross-reference file */
-    char *s;
+    char *s, *term;
     int c;
     unsigned int i;
     pid_t pid;
@@ -485,6 +485,8 @@ cscope: reffile too long, cannot be > %d characters\n", 
sizeof(path) - 3);
 #endif
     /* read the environment */
     editor = mygetenv("EDITOR", EDITOR);
+    if ((term = getenv("TERM")) && strcmp(term, "dumb"))
+       editor = mygetenv("VISUAL", editor);
     editor = mygetenv("VIEWER", editor); /* use viewer if set */
     editor = mygetenv("CSCOPE_EDITOR", editor);        /* has last word */
     home = mygetenv("HOME", HOME);
-- 
1.7.10.4

>From 10da9f709e7c8b62e55b0fae4ba5d2d0f7e030b6 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Mon, 24 Jun 2013 19:11:28 +0200
Subject: [PATCH 2/3] Add assignment case in the manual page

---
 doc/cscope.1 |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/cscope.1 b/doc/cscope.1
index a815e94..e0d7afc 100644
--- a/doc/cscope.1
+++ b/doc/cscope.1
@@ -219,6 +219,8 @@ After the cross-reference is ready, cscope will display 
this menu:
 .B  Find this file:
 .TP
 .B  Find files #including this file:
+.TP
+.B Find assignments to this symbol:
 .PD 1
 .PP
 Press the <Up> or <Down> keys repeatedly to move to the desired input
-- 
1.7.10.4

>From f010ba12f54bd42d9bf7e2ed4422d185fb68b373 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Mon, 24 Jun 2013 20:22:45 +0200
Subject: [PATCH 3/3] Filter symbol definition based in the type

---
 src/constants.h |    1 +
 src/display.c   |   15 +++++++++++----
 src/find.c      |   57 ++++++++++++++++++++++++++++++++++++++++++-------------
 src/global.h    |   20 +++++++++----------
 src/scanner.h   |    1 +
 5 files changed, 67 insertions(+), 27 deletions(-)

diff --git a/src/constants.h b/src/constants.h
index 65a63a4..8e8f55f 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -68,6 +68,7 @@
 #define        NUMLEN  10              /* line number length */
 #define        PATHLEN 250             /* file pathname length */
 #define        PATLEN  250             /* symbol pattern length */
+#define        TYPELEN 15              /* symbol type lenght */
 #define TEMPSTRING_LEN 8191     /* max strlen() of the global temp string */
 #define        REFFILE "cscope.out"    /* cross-reference output file */
 #define        NAMEFILE "cscope.files" /* default list-of-files file */
diff --git a/src/display.c b/src/display.c
index bf5965b..0c86e3d 100644
--- a/src/display.c
+++ b/src/display.c
@@ -91,7 +91,7 @@ static        char    helpstring[] = "Press the ? key for 
help";
 static char    selprompt[] = 
        "Select lines to change (press the ? key for help): ";
 
-typedef char * (*FP)(char *);  /* pointer to function returning a character 
pointer */
+typedef char * (*FP)(char *, char*);   /* pointer to function returning a 
character pointer */
 
 /* HBB 2000/05/05: I removed the casts to function pointer type. It is
  * fundamentally unsafe to call a function through a pointer of a
@@ -411,11 +411,13 @@ BOOL
 search(void)
 {
        char    *findresult = NULL;     /* find function output */
-       BOOL    funcexist = YES;                /* find "function" error */
+       BOOL    funcexist = YES;        /* find "function" error */
        FINDINIT rc = NOERROR;          /* findinit return code */
        sighandler_t savesig;           /* old value of signal */
        FP      f;                      /* searching function */
+       char    type[TYPELEN];          /* type of symbol in finddef */
        int     c;
+       char    *cp;
        
        /* open the references found file for writing */
        if (writerefsfound() == NO) {
@@ -427,18 +429,23 @@ search(void)
        }
        searchcount = 0;
        savesig = signal(SIGINT, jumpback);
+       type[0] = '\0';
        if (sigsetjmp(env, 1) == 0) {
                f = fields[field].findfcn;
                if (f == findregexp || f == findstring) {
-                       findresult = (*f)(Pattern);
+                       findresult = (*f)(Pattern, type);
                } else {
                        if ((nonglobalrefs = myfopen(temp2, "wb")) == NULL) {
                                cannotopen(temp2);
                                return(NO);
                        }
+                       if (f == finddef && (cp = strchr(Pattern, '@'))) {
+                               *cp++ = '\0';
+                               strcpy(type, cp);
+                       }
                        if ((rc = findinit(Pattern)) == NOERROR) {
                                (void) dbseek(0L); /* read the first block */
-                               findresult = (*f)(Pattern);
+                               findresult = (*f)(Pattern, type);
                                if (f == findcalledby) 
                                        funcexist = (*findresult == 'y');
                                findcleanup();
diff --git a/src/find.c b/src/find.c
index d8da542..4a335ab 100644
--- a/src/find.c
+++ b/src/find.c
@@ -88,14 +88,14 @@ static      void    putsource(int seemore, FILE *output);
 /* find the symbol in the cross-reference */
 
 char *
-findsymbol(char *pattern)
+findsymbol(char *pattern, char *dummy)
 {
     return find_symbol_or_assignment(pattern, NO);
 }
 
 /* find the symbol in the cross-reference, and look for assignments */
 char *
-findassign(char *pattern)
+findassign(char *pattern, char *dummy)
 {
     return find_symbol_or_assignment(pattern, YES);
 }
@@ -359,9 +359,35 @@ find_symbol_or_assignment(char *pattern, BOOL assign_flag)
 /* find the function definition or #define */
 
 char *
-finddef(char *pattern)
+finddef(char *pattern, char *type)
 {
        char    file[PATHLEN + 1];      /* source file name */
+       char    t;
+
+       if (type) {
+               if (*type == '\0') {
+                       t = ANYDEF;
+               } else if (!strcmp(type, "define")) {
+                       t = DEFINE;
+               } else if (!strcmp(type, "function")) {
+                       t = FCNDEF;
+               } else if (!strcmp(type, "class")) {
+                       t = CLASSDEF;
+               } else if (!strcmp(type, "enum")) {
+                       t = ENUMDEF;
+               } else if (!strcmp(type, "member")) {
+                       t = MEMBERDEF;
+               } else if (!strcmp(type, "struct")) {
+                       t = STRUCTDEF;
+               } else if (!strcmp(type, "typedef")) {
+                       t = TYPEDEF;
+               } else if (!strcmp(type, "union")) {
+                       t = UNIONDEF;
+               } else if (!strcmp(type, "global")) {
+                       t = GLOBALDEF;
+               } else
+                       t = -1;         /* incorrect type, don't show any 
result */
+       }
 
        if (invertedindex == YES) {
                POSTING *p;
@@ -378,6 +404,8 @@ finddef(char *pattern)
                        case TYPEDEF:
                        case UNIONDEF:
                        case GLOBALDEF:/* other global definition */
+                               if (t != ANYDEF && t != p->type)
+                                       continue;
                                putpostingref(p, pattern);
                        }
                }
@@ -407,6 +435,8 @@ finddef(char *pattern)
                case TYPEDEF:
                case UNIONDEF:
                case GLOBALDEF:         /* other global definition */
+                       if (t != ANYDEF && t != *blockp)
+                               continue;
                        skiprefchar();  /* match name to pattern */
                        if (match()) {
                
@@ -419,15 +449,16 @@ finddef(char *pattern)
        
        return NULL;
 }
+
 /* find all function definitions (used by samuel only) */
 
 char *
-findallfcns(char *dummy)
+findallfcns(char *dummy1, char *dummy2)
 {
        char    file[PATHLEN + 1];      /* source file name */
        char    function[PATLEN + 1];   /* function name */
 
-       (void) dummy;           /* unused argument */
+       (void) dummy1;          /* unused argument */
 
        /* find the next file name or definition */
        while (scanpast('\t') != NULL) {
@@ -462,7 +493,7 @@ findallfcns(char *dummy)
 /* find the functions calling this function */
 
 char *
-findcalling(char *pattern)
+findcalling(char *pattern, char *dummy)
 {
        char    file[PATHLEN + 1];      /* source file name */
        char    function[PATLEN + 1];   /* function name */
@@ -554,7 +585,7 @@ findcalling(char *pattern)
 /* find the text in the source files */
 
 char *
-findstring(char *pattern)
+findstring(char *pattern, char *dummy)
 {
        char    egreppat[2 * PATLEN];
        char    *cp, *pp;
@@ -570,13 +601,13 @@ findstring(char *pattern)
        *cp = '\0';
        
        /* search the source files */
-       return(findregexp(egreppat));
+       return(findregexp(egreppat, NULL));
 }
 
 /* find this regular expression in the source files */
 
 char *
-findregexp(char *egreppat)
+findregexp(char *egreppat, char *dummy)
 {
     unsigned int i;
     char *egreperror;
@@ -600,11 +631,11 @@ findregexp(char *egreppat)
 /* find matching file names */
 
 char *
-findfile(char *dummy)
+findfile(char *dummy1, char *dummy2)
 {
     unsigned int i;
        
-    (void) dummy;              /* unused argument */
+    (void) dummy1;             /* unused argument */
 
     for (i = 0; i < nsrcfiles; ++i) {
        char *s;
@@ -626,7 +657,7 @@ findfile(char *dummy)
 /* find files #including this file */
 
 char *
-findinclude(char *pattern)
+findinclude(char *pattern, char *dummy)
 {
        char    file[PATHLEN + 1];      /* source file name */
 
@@ -1043,7 +1074,7 @@ lcasify(char *s)
  * 'n', for the boolean result values YES and NO */
 
 char *
-findcalledby(char *pattern)
+findcalledby(char *pattern, char *dummy)
 {
        char    file[PATHLEN + 1];      /* source file name */
        static char found_caller = 'n'; /* seen calling function? */
diff --git a/src/global.h b/src/global.h
index cda29aa..b6dddc1 100644
--- a/src/global.h
+++ b/src/global.h
@@ -336,16 +336,16 @@ extern    BOOL    unixpcmouse;            /* UNIX PC 
mouse interface */
 /* cscope functions called from more than one function or between files */ 
 
 char   *filepath(char *file);
-char   *findcalledby(char *pattern);
-char   *findcalling(char *pattern);
-char   *findallfcns(char *dummy);
-char   *finddef(char *pattern);
-char   *findfile(char *dummy);
-char   *findinclude(char *pattern);
-char   *findsymbol(char *pattern);
-char   *findassign(char *pattern);
-char   *findregexp(char *egreppat);
-char   *findstring(char *pattern);
+char   *findcalledby(char *pattern,char *dummy);
+char   *findcalling(char *pattern, char *dummy);
+char   *findallfcns(char *dummy1, char *dummy2);
+char   *finddef(char *pattern, char *type);
+char   *findfile(char *dummy1, char *dummy2);
+char   *findinclude(char *pattern, char *dummy);
+char   *findsymbol(char *pattern, char *dummy);
+char   *findassign(char *pattern, char *dummy);
+char   *findregexp(char *egreppat, char *dummy);
+char   *findstring(char *pattern, char *dummy);
 char   *inviewpath(char *file);
 char   *lookup(char *ident);
 char   *pathcomponents(char *path, int components);
diff --git a/src/scanner.h b/src/scanner.h
index 8f2dd1c..e53533e 100644
--- a/src/scanner.h
+++ b/src/scanner.h
@@ -44,6 +44,7 @@
 /* cross-reference database mark characters (when new ones are added, 
  * update the cscope.out format description in cscope.1)
  */
+#define ANYDEF         ' '
 #define CLASSDEF       'c'
 #define        DEFINE          '#'
 #define        DEFINEEND       ')'
-- 
1.7.10.4

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Cscope-devel mailing list
Cscope-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cscope-devel

Reply via email to