2 Subject: fix return of calltipID
6 source/tags.c | 63 ++++++++++++++++++++++++++++++++++++----------------------
7 1 file changed, 40 insertions(+), 23 deletions(-)
9 diff --quilt old/source/tags.c new/source/tags.c
12 @@ -121,11 +121,11 @@ static int findDef(WindowInfo *window, c
13 static int findAllMatches(WindowInfo *window, const char *string);
14 static void findAllCB(Widget parent, XtPointer client_data, XtPointer call_data);
15 static Widget createSelectMenu(Widget parent, char *label, int nArgs,
17 static void editTaggedLocation( Widget parent, int i );
18 -static void showMatchingCalltip( Widget parent, int i );
19 +static int showMatchingCalltip( Widget parent, int i );
21 static const char *rcs_strdup(const char *str);
22 static void rcs_free(const char *str);
23 static int searchLine(char *line, const char *regex);
24 static void rstrip( char *dst, const char *src );
25 @@ -854,10 +854,15 @@ int LookupTag(const char *name, const ch
29 ** This code path is followed if the request came from either
30 ** FindDefinition or FindDefCalltip. This should probably be refactored.
32 +** If search_type = TAG,
33 +** returns <= 0 on errors or when no Def found, > 0 when Def found.
35 +** returns the calltip ID, or 0 on failure.
37 static int findDef(WindowInfo *window, const char *value, int search_type) {
38 static char tagText[MAX_TAG_LEN + 1];
40 char message[MAX_TAG_LEN+40];
41 @@ -873,19 +878,23 @@ static int findDef(WindowInfo *window, c
42 ml = ((l < MAX_TAG_LEN) ? (l) : (MAX_TAG_LEN));
43 strncpy(tagText, value, ml);
45 /* See if we can find the tip/tag */
46 status = findAllMatches(window, tagText);
47 + if (search_type == TAG && status == 0) {
51 /* If we didn't find a requested calltip, see if we can use a tag */
52 - if (status == 0 && search_type == TIP && TagsFileList != NULL) {
53 + if (status == -1 && search_type == TIP && TagsFileList != NULL) {
54 searchMode = TIP_FROM_TAG;
55 status = findAllMatches(window, tagText);
60 /* Didn't find any matches */
62 if (searchMode == TIP_FROM_TAG || searchMode == TIP) {
63 sprintf(message, "No match for \"%s\" in calltips or tags.",
65 tagsShowCalltip( window, message );
67 @@ -1110,11 +1119,15 @@ static int fakeRegExSearch(WindowInfo *w
71 /* Finds all matches and handles tag "collisions". Prompts user with a
72 list of collided tags in the hash table and allows the user to select
76 + Returns -2 on error condition, -1 if no matches found and a
77 + number >= 0 if matches were found.
78 + (Note: the value is *not* the number of matches.) */
79 static int findAllMatches(WindowInfo *window, const char *string)
81 Widget dialogParent = window->textArea;
82 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
83 char temp[32+2*MAXPATHLEN+MAXLINE];
84 @@ -1123,11 +1136,11 @@ static int findAllMatches(WindowInfo *wi
85 int startPos, i, pathMatch=0, samePath=0, langMode, nMatches=0;
87 /* verify that the string is reasonable as a tag */
88 if (*string == '\0' || strlen(string) > MAX_TAG_LEN) {
95 /* First look up all of the matching tags */
96 while (LookupTag(string, &fileToSearch, &langMode, &searchString, &startPos,
97 @@ -1173,11 +1186,11 @@ static int findAllMatches(WindowInfo *wi
101 /* Did we find any matches? */
107 /* Only one of the matches is in the same dir. as this file. Use it. */
108 if (GetPrefSmartTags() && samePath == 1 && nMatches > 1) {
109 strcpy(tagFiles[0],tagFiles[pathMatch]);
110 @@ -1198,11 +1211,11 @@ static int findAllMatches(WindowInfo *wi
113 if (!(dupTagsList = (char **) malloc(sizeof(char *) * nMatches))) {
114 fprintf(stderr, "nedit: findAllMatches(): out of heap space!\n");
115 XBell(TheDisplay, 0);
120 for (i=0; i<nMatches; i++) {
121 ParseFilename(tagFiles[i], filename, pathname, NULL);
122 if ((i<nMatches-1 && !strcmp(tagFiles[i],tagFiles[i+1])) ||
123 @@ -1230,31 +1243,33 @@ static int findAllMatches(WindowInfo *wi
124 free(dupTagsList[j]);
128 XBell(TheDisplay, 0);
133 strcpy(dupTagsList[i],temp);
135 createSelectMenu(dialogParent, "Duplicate Tags", nMatches, dupTagsList);
136 for (i=0; i<nMatches; i++)
137 free(dupTagsList[i]);
144 ** No need for a dialog list, there is only one tag matching --
145 ** Go directly to the tag
147 - if (searchMode == TAG)
148 + if (searchMode == TAG) {
149 editTaggedLocation( dialogParent, 0 );
151 - showMatchingCalltip( dialogParent, 0 );
156 + return showMatchingCalltip( dialogParent, 0 );
160 /* Callback function for the FindAll widget. Process the users response. */
161 static void findAllCB(Widget parent, XtPointer client_data, XtPointer call_data)
163 @@ -1313,15 +1328,16 @@ static int moveAheadNLines( char *str, i
166 ** Show the calltip specified by tagFiles[i], tagSearch[i], tagPosInf[i]
167 ** This reads from either a source code file (if searchMode == TIP_FROM_TAG)
168 ** or a calltips file (if searchMode == TIP).
169 +** Returns the calltip ID or 0 in case of failure.
171 -static void showMatchingCalltip( Widget parent, int i )
172 +static int showMatchingCalltip( Widget parent, int i )
174 int startPos=0, fileLen, readLen, tipLen;
176 + int endPos=0, calltipID = 0;
182 @@ -1329,38 +1345,38 @@ static void showMatchingCalltip( Widget
183 NormalizePathname(tagFiles[i], NULL);
184 fp = fopen(tagFiles[i], "r");
186 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
191 if (fstat(fileno(fp), &statbuf) != 0) {
193 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
199 /* 2. Read the target file */
200 /* Allocate space for the whole contents of the file (unfortunately) */
201 fileLen = statbuf.st_size;
202 fileString = XtMalloc(fileLen+1); /* +1 = space for null */
203 if (fileString == NULL) {
205 DialogF(DF_ERR, parent, 1, "File too large",
206 "File is too large to load", "OK");
211 /* Read the file into fileString and terminate with a null */
212 readLen = fread(fileString, sizeof(char), fileLen, fp);
215 DialogF(DF_ERR, parent, 1, "Error reading File", "Error reading %s",
221 fileString[readLen] = 0;
224 if (fclose(fp) != 0) {
225 @@ -1376,21 +1392,21 @@ static void showMatchingCalltip( Widget
226 if ((moveAheadNLines( fileString, &startPos, tagPosInf[i]-1 )) >= 0) {
227 DialogF(DF_ERR, parent, 1, "Tags Error",
228 "%s\n not long enough for definition to be on line %d",
229 "OK", tagFiles[i], tagPosInf[i]);
235 startPos = tagPosInf[i];
236 if(!fakeRegExSearch(WidgetToWindow(parent), fileString, tagSearch[i],
237 &startPos, &endPos)){
238 DialogF(DF_WARN, parent, 1, "Tag not found",
239 "Definition for %s\nnot found in %s", "OK", tagName,
247 if (searchMode == TIP) {
249 @@ -1421,19 +1437,20 @@ static void showMatchingCalltip( Widget
252 DialogF(DF_ERR, parent, 1, "Out of Memory",
253 "Can't allocate memory for calltip message", "OK");
258 strncpy( message, &fileString[startPos], tipLen );
262 - tagsShowCalltip( WidgetToWindow(parent), message );
263 + calltipID = tagsShowCalltip( WidgetToWindow(parent), message );
269 /* Open a new (or existing) editor window to the location specified in
270 tagFiles[i], tagSearch[i], tagPosInf[i] */
271 static void editTaggedLocation( Widget parent, int i )