root/gtags-cscope/find.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. common
  2. findsymbol
  3. finddef
  4. findcalledby
  5. findcalling
  6. findstring
  7. findregexp
  8. findfile
  9. findinclude

   1 /*
   2  * Copyright (c) 2011 Tama Communications Corporation
   3  *
   4  * This file is part of GNU GLOBAL.
   5  *
   6  * This program is free software: you can redistribute it and/or modify
   7  * it under the terms of the GNU General Public License as published by
   8  * the Free Software Foundation, either version 3 of the License, or
   9  * (at your option) any later version.
  10  * 
  11  * This program is distributed in the hope that it will be useful,
  12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  * GNU General Public License for more details.
  15  * 
  16  * You should have received a copy of the GNU General Public License
  17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18  */
  19 #include "global-cscope.h"
  20 #include "char.h"
  21 #include "gparam.h"
  22 
  23 #define FAILED "global command failed"
  24 
  25 static char comline[MAXFILLEN];
  26 
  27 static char *
  28 common(void)
  29 {
  30         static char com[80];
  31         snprintf(com, sizeof(com), "%s --encode-path=\" \t\" --result=cscope%s%s",
  32                 global_command, (caseless == YES) ? " -i" : "", (absolutepath == YES) ? " -a" : ""); 
  33         return com;
  34 }
  35 /*
  36  * [display.c]
  37  *
  38  * {"Find this", "C symbol",                       findsymbol},
  39  */
  40 char *
  41 findsymbol(char *pattern)
  42 {
  43         snprintf(comline, sizeof(comline), "%s -d %s > %s", common(), quote_shell(pattern), temp1);
  44         if (system(comline) != 0)
  45                 return FAILED;
  46         snprintf(comline, sizeof(comline), "%s -rs %s >> %s", common(), quote_shell(pattern), temp1);
  47         if (system(comline) != 0)
  48                 return FAILED;
  49         return NULL;
  50 }
  51 
  52 /*
  53  * [display.c]
  54  *
  55  * {"Find this", "global definition",              finddef},
  56  */
  57 char *
  58 finddef(char *pattern)
  59 {
  60         snprintf(comline, sizeof(comline), "%s -d %s > %s", common(), quote_shell(pattern), temp1);
  61         if (system(comline) != 0)
  62                 return FAILED;
  63         return NULL;
  64 }
  65 
  66 /*
  67  * [display.c]
  68  *
  69  * {"Find", "functions called by this function (N/A)",     findcalledby},
  70  *
  71  * This facility is not implemented, because GLOBAL doesn't have such a facility.
  72  * Instead, this command is replaced with a more useful one, that is, context jump.
  73  * It is available in the line mode (with the -l option) of gtags-cscope.
  74  */
  75 char *
  76 findcalledby(char *pattern)
  77 {
  78         char *p;
  79 
  80         /*
  81          * <symbol>:<line number>:<path>
  82          */
  83         for (p = pattern; *p && *p != ':'; p++)
  84                 ;
  85         *p++ = '\0';
  86         snprintf(comline, sizeof(comline), "%s --from-here=\"%s\" %s > %s", common(), p, quote_shell(pattern), temp1);
  87         if (system(comline) != 0)
  88                 return FAILED;
  89         return NULL;
  90 }
  91 
  92 /*
  93  * [display.c]
  94  *
  95  * {"Find", "functions calling this function",     findcalling},
  96  */
  97 char *
  98 findcalling(char *pattern)
  99 {
 100         snprintf(comline, sizeof(comline), "%s -r %s > %s", common(), quote_shell(pattern), temp1);
 101         if (system(comline) != 0)
 102                 return FAILED;
 103         return NULL;
 104 }
 105 
 106 /*
 107  * [display.c]
 108  *
 109  * {"Find this", "text string",                    findstring},
 110  */
 111 char *
 112 findstring(char *pattern)
 113 {
 114         snprintf(comline, sizeof(comline), "%s -g --literal %s > %s", common(), quote_shell(pattern), temp1);
 115         if (system(comline) != 0)
 116                 return FAILED;
 117         return NULL;
 118 }
 119 
 120 /*
 121  * [display.c]
 122  *
 123  * {"Change this", "text string",                  findstring},
 124  */
 125 /*
 126  * [display.c]
 127  *
 128         {"Find this", "egrep pattern",                  findregexp},
 129  */
 130 char *
 131 findregexp(char *pattern)
 132 {
 133         snprintf(comline, sizeof(comline), "%s -g %s > %s", common(), quote_shell(pattern), temp1);
 134         if (system(comline) != 0)
 135                 return FAILED;
 136         return NULL;
 137 }
 138 
 139 /*
 140  * [display.c]
 141  *
 142  * {"Find this", "file",                           findfile},
 143  */
 144 char *
 145 findfile(char *pattern)
 146 {
 147         snprintf(comline, sizeof(comline), "%s -P %s > %s", common(), quote_shell(pattern), temp1);
 148         if (system(comline) != 0)
 149                 return FAILED;
 150         return NULL;
 151 }
 152 
 153 /*
 154  * [display.c]
 155  *
 156  * {"Find", "files #including this file",          findinclude},
 157  */
 158 char *
 159 findinclude(char *pattern)
 160 {
 161 #if defined(_WIN32) && !defined(__CYGWIN__)
 162 #define INCLUDE "\"^[ \t]*#[ \t]*include[ \t].*[<\\\"/\\]%s[\\\">]\""
 163 #elif defined(__DJGPP__)
 164 #define INCLUDE "'^[ \t]*#[ \t]*include[ \t].*[\"</\\]%s[\">]'"
 165 #else
 166 #define INCLUDE "'^[ \t]*#[ \t]*include[ \t].*[\"</]%s[\">]'"
 167 #endif
 168         snprintf(comline, sizeof(comline), "%s -g " INCLUDE " | sed \"s/<unknown>/<global>/\" > %s",
 169                 common(), quote_string(pattern), temp1);
 170         if (system(comline) != 0)
 171                 return FAILED;
 172         return NULL;
 173 }

/* [previous][next][first][last][top][bottom][index][help] */