3 source/tags.c | 63 ++++++++++++++++++++++++++++++++++++----------------------
4 1 file changed, 40 insertions(+), 23 deletions(-)
6 diff --quilt old/source/tags.c new/source/tags.c
9 @@ -121,11 +121,11 @@ static int findDef(WindowInfo *window, c
10 static int findAllMatches(WindowInfo *window, const char *string);
11 static void findAllCB(Widget parent, XtPointer client_data, XtPointer call_data);
12 static Widget createSelectMenu(Widget parent, char *label, int nArgs,
14 static void editTaggedLocation( Widget parent, int i );
15 -static void showMatchingCalltip( Widget parent, int i );
16 +static int showMatchingCalltip( Widget parent, int i );
18 static const char *rcs_strdup(const char *str);
19 static void rcs_free(const char *str);
20 static int searchLine(char *line, const char *regex);
21 static void rstrip( char *dst, const char *src );
22 @@ -854,10 +854,15 @@ int LookupTag(const char *name, const ch
26 ** This code path is followed if the request came from either
27 ** FindDefinition or FindDefCalltip. This should probably be refactored.
29 +** If search_type = TAG,
30 +** returns <= 0 on errors or when no Def found, > 0 when Def found.
32 +** returns the calltip ID, or 0 on failure.
34 static int findDef(WindowInfo *window, const char *value, int search_type) {
35 static char tagText[MAX_TAG_LEN + 1];
37 char message[MAX_TAG_LEN+40];
38 @@ -873,19 +878,23 @@ static int findDef(WindowInfo *window, c
39 ml = ((l < MAX_TAG_LEN) ? (l) : (MAX_TAG_LEN));
40 strncpy(tagText, value, ml);
42 /* See if we can find the tip/tag */
43 status = findAllMatches(window, tagText);
44 + if (search_type == TAG && status == 0) {
48 /* If we didn't find a requested calltip, see if we can use a tag */
49 - if (status == 0 && search_type == TIP && TagsFileList != NULL) {
50 + if (status == -1 && search_type == TIP && TagsFileList != NULL) {
51 searchMode = TIP_FROM_TAG;
52 status = findAllMatches(window, tagText);
57 /* Didn't find any matches */
59 if (searchMode == TIP_FROM_TAG || searchMode == TIP) {
60 sprintf(message, "No match for \"%s\" in calltips or tags.",
62 tagsShowCalltip( window, message );
64 @@ -1110,11 +1119,15 @@ static int fakeRegExSearch(WindowInfo *w
68 /* Finds all matches and handles tag "collisions". Prompts user with a
69 list of collided tags in the hash table and allows the user to select
73 + Returns -2 on error condition, -1 if no matches found and a
74 + number >= 0 if matches were found.
75 + (Note: the value is *not* the number of matches.) */
76 static int findAllMatches(WindowInfo *window, const char *string)
78 Widget dialogParent = window->textArea;
79 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
80 char temp[32+2*MAXPATHLEN+MAXLINE];
81 @@ -1123,11 +1136,11 @@ static int findAllMatches(WindowInfo *wi
82 int startPos, i, pathMatch=0, samePath=0, langMode, nMatches=0;
84 /* verify that the string is reasonable as a tag */
85 if (*string == '\0' || strlen(string) > MAX_TAG_LEN) {
92 /* First look up all of the matching tags */
93 while (LookupTag(string, &fileToSearch, &langMode, &searchString, &startPos,
94 @@ -1173,11 +1186,11 @@ static int findAllMatches(WindowInfo *wi
98 /* Did we find any matches? */
104 /* Only one of the matches is in the same dir. as this file. Use it. */
105 if (GetPrefSmartTags() && samePath == 1 && nMatches > 1) {
106 strcpy(tagFiles[0],tagFiles[pathMatch]);
107 @@ -1198,11 +1211,11 @@ static int findAllMatches(WindowInfo *wi
110 if (!(dupTagsList = (char **) malloc(sizeof(char *) * nMatches))) {
111 fprintf(stderr, "nedit: findAllMatches(): out of heap space!\n");
112 XBell(TheDisplay, 0);
117 for (i=0; i<nMatches; i++) {
118 ParseFilename(tagFiles[i], filename, pathname, NULL);
119 if ((i<nMatches-1 && !strcmp(tagFiles[i],tagFiles[i+1])) ||
120 @@ -1230,31 +1243,33 @@ static int findAllMatches(WindowInfo *wi
121 free(dupTagsList[j]);
125 XBell(TheDisplay, 0);
130 strcpy(dupTagsList[i],temp);
132 createSelectMenu(dialogParent, "Duplicate Tags", nMatches, dupTagsList);
133 for (i=0; i<nMatches; i++)
134 free(dupTagsList[i]);
141 ** No need for a dialog list, there is only one tag matching --
142 ** Go directly to the tag
144 - if (searchMode == TAG)
145 + if (searchMode == TAG) {
146 editTaggedLocation( dialogParent, 0 );
148 - showMatchingCalltip( dialogParent, 0 );
153 + return showMatchingCalltip( dialogParent, 0 );
157 /* Callback function for the FindAll widget. Process the users response. */
158 static void findAllCB(Widget parent, XtPointer client_data, XtPointer call_data)
160 @@ -1313,15 +1328,16 @@ static int moveAheadNLines( char *str, i
163 ** Show the calltip specified by tagFiles[i], tagSearch[i], tagPosInf[i]
164 ** This reads from either a source code file (if searchMode == TIP_FROM_TAG)
165 ** or a calltips file (if searchMode == TIP).
166 +** Returns the calltip ID or 0 in case of failure.
168 -static void showMatchingCalltip( Widget parent, int i )
169 +static int showMatchingCalltip( Widget parent, int i )
171 int startPos=0, fileLen, readLen, tipLen;
173 + int endPos=0, calltipID = 0;
179 @@ -1329,38 +1345,38 @@ static void showMatchingCalltip( Widget
180 NormalizePathname(tagFiles[i], NULL);
181 fp = fopen(tagFiles[i], "r");
183 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
188 if (fstat(fileno(fp), &statbuf) != 0) {
190 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
196 /* 2. Read the target file */
197 /* Allocate space for the whole contents of the file (unfortunately) */
198 fileLen = statbuf.st_size;
199 fileString = XtMalloc(fileLen+1); /* +1 = space for null */
200 if (fileString == NULL) {
202 DialogF(DF_ERR, parent, 1, "File too large",
203 "File is too large to load", "OK");
208 /* Read the file into fileString and terminate with a null */
209 readLen = fread(fileString, sizeof(char), fileLen, fp);
212 DialogF(DF_ERR, parent, 1, "Error reading File", "Error reading %s",
218 fileString[readLen] = 0;
221 if (fclose(fp) != 0) {
222 @@ -1376,21 +1392,21 @@ static void showMatchingCalltip( Widget
223 if ((moveAheadNLines( fileString, &startPos, tagPosInf[i]-1 )) >= 0) {
224 DialogF(DF_ERR, parent, 1, "Tags Error",
225 "%s\n not long enough for definition to be on line %d",
226 "OK", tagFiles[i], tagPosInf[i]);
232 startPos = tagPosInf[i];
233 if(!fakeRegExSearch(WidgetToWindow(parent), fileString, tagSearch[i],
234 &startPos, &endPos)){
235 DialogF(DF_WARN, parent, 1, "Tag not found",
236 "Definition for %s\nnot found in %s", "OK", tagName,
244 if (searchMode == TIP) {
246 @@ -1421,19 +1437,20 @@ static void showMatchingCalltip( Widget
249 DialogF(DF_ERR, parent, 1, "Out of Memory",
250 "Can't allocate memory for calltip message", "OK");
255 strncpy( message, &fileString[startPos], tipLen );
259 - tagsShowCalltip( WidgetToWindow(parent), message );
260 + calltipID = tagsShowCalltip( WidgetToWindow(parent), message );
266 /* Open a new (or existing) editor window to the location specified in
267 tagFiles[i], tagSearch[i], tagPosInf[i] */
268 static void editTaggedLocation( Widget parent, int i )