delete MAkefile target links on realclean
[nedit-bw.git] / calltipsID.diff
blob41fc8a1a17f2664abf58a5182d9208c4a88bed74
1 ---
3 source/tags.c | 63 ++++++++++++++++++++++++++++++++++++----------------------
4 1 file changed, 40 insertions(+), 23 deletions(-)
6 diff --quilt old/source/tags.c new/source/tags.c
7 --- old/source/tags.c
8 +++ 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,
13 char *args[]);
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
25 /*
26 ** This code path is followed if the request came from either
27 ** FindDefinition or FindDefCalltip. This should probably be refactored.
28 +**
29 +** If search_type = TAG,
30 +** returns <= 0 on errors or when no Def found, > 0 when Def found.
31 +** Else,
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];
36 const char *p;
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);
41 tagText[ml] = '\0';
42 /* See if we can find the tip/tag */
43 status = findAllMatches(window, tagText);
44 + if (search_type == TAG && status == 0) {
45 + status++;
46 + }
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);
55 - if (status == 0) {
56 + if (status == -1) {
57 /* Didn't find any matches */
58 + status++;
59 if (searchMode == TIP_FROM_TAG || searchMode == TIP) {
60 sprintf(message, "No match for \"%s\" in calltips or tags.",
61 tagName);
62 tagsShowCalltip( window, message );
63 } else
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
70 - the correct one. */
71 + the correct one.
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) {
86 XBell(TheDisplay, 0);
87 - return -1;
88 + return -2;
90 tagName=string;
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
95 string = NULL;
98 /* Did we find any matches? */
99 if (!nMatches) {
100 - return 0;
101 + return -1;
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
109 if (nMatches>1) {
110 if (!(dupTagsList = (char **) malloc(sizeof(char *) * nMatches))) {
111 fprintf(stderr, "nedit: findAllMatches(): out of heap space!\n");
112 XBell(TheDisplay, 0);
113 - return -1;
114 + return -2;
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]);
123 free(dupTagsList);
125 XBell(TheDisplay, 0);
126 - return -1;
127 + return -2;
130 strcpy(dupTagsList[i],temp);
132 createSelectMenu(dialogParent, "Duplicate Tags", nMatches, dupTagsList);
133 for (i=0; i<nMatches; i++)
134 free(dupTagsList[i]);
135 free(dupTagsList);
136 - return 1;
137 + return 0;
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 );
147 - else
148 - showMatchingCalltip( dialogParent, 0 );
149 - return 1;
150 + return 0;
152 + else {
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;
172 - int endPos=0;
173 + int endPos=0, calltipID = 0;
174 char *fileString;
175 FILE *fp;
176 struct stat statbuf;
177 char *message;
179 @@ -1329,38 +1345,38 @@ static void showMatchingCalltip( Widget
180 NormalizePathname(tagFiles[i], NULL);
181 fp = fopen(tagFiles[i], "r");
182 if (fp == NULL) {
183 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
184 "OK", tagFiles[i]);
185 - return;
186 + return 0;
188 if (fstat(fileno(fp), &statbuf) != 0) {
189 fclose(fp);
190 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
191 "OK", tagFiles[i]);
192 - return;
193 + return 0;
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) {
201 fclose(fp);
202 DialogF(DF_ERR, parent, 1, "File too large",
203 "File is too large to load", "OK");
204 - return;
205 + return 0;
208 /* Read the file into fileString and terminate with a null */
209 readLen = fread(fileString, sizeof(char), fileLen, fp);
210 if (ferror(fp)) {
211 fclose(fp);
212 DialogF(DF_ERR, parent, 1, "Error reading File", "Error reading %s",
213 "OK", tagFiles[i]);
214 XtFree(fileString);
215 - return;
216 + return 0;
218 fileString[readLen] = 0;
220 /* Close the file */
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]);
227 XtFree(fileString);
228 - return;
229 + return 0;
231 } else {
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,
237 tagFiles[i]);
238 XtFree(fileString);
239 - return;
240 + return 0;
244 if (searchMode == TIP) {
245 int dummy, found;
246 @@ -1421,19 +1437,20 @@ static void showMatchingCalltip( Widget
247 if (message == NULL)
249 DialogF(DF_ERR, parent, 1, "Out of Memory",
250 "Can't allocate memory for calltip message", "OK");
251 XtFree(fileString);
252 - return;
253 + return 0;
255 strncpy( message, &fileString[startPos], tipLen );
256 message[tipLen] = 0;
258 /* 6. Display it */
259 - tagsShowCalltip( WidgetToWindow(parent), message );
260 + calltipID = tagsShowCalltip( WidgetToWindow(parent), message );
261 XtFree(message);
262 XtFree(fileString);
263 + return calltipID;
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 )