add cast to XtCalloc() call
[nedit-bw.git] / calltipsID.diff
blob4ba43e3fa38c36e041039e0fdafa5a36e5ec6438
1 From: Joerg Fischer <jf505@gmx.de>
2 Subject: fix return of calltipID
4 ---
6 source/tags.c | 63 ++++++++++++++++++++++++++++++++++++----------------------
7 1 file changed, 40 insertions(+), 23 deletions(-)
9 diff --quilt old/source/tags.c new/source/tags.c
10 --- old/source/tags.c
11 +++ 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,
16 char *args[]);
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
28 /*
29 ** This code path is followed if the request came from either
30 ** FindDefinition or FindDefCalltip. This should probably be refactored.
31 +**
32 +** If search_type = TAG,
33 +** returns <= 0 on errors or when no Def found, > 0 when Def found.
34 +** Else,
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];
39 const char *p;
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);
44 tagText[ml] = '\0';
45 /* See if we can find the tip/tag */
46 status = findAllMatches(window, tagText);
47 + if (search_type == TAG && status == 0) {
48 + status++;
49 + }
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);
58 - if (status == 0) {
59 + if (status == -1) {
60 /* Didn't find any matches */
61 + status++;
62 if (searchMode == TIP_FROM_TAG || searchMode == TIP) {
63 sprintf(message, "No match for \"%s\" in calltips or tags.",
64 tagName);
65 tagsShowCalltip( window, message );
66 } else
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
73 - the correct one. */
74 + the correct one.
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) {
89 XBell(TheDisplay, 0);
90 - return -1;
91 + return -2;
93 tagName=string;
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
98 string = NULL;
101 /* Did we find any matches? */
102 if (!nMatches) {
103 - return 0;
104 + return -1;
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
112 if (nMatches>1) {
113 if (!(dupTagsList = (char **) malloc(sizeof(char *) * nMatches))) {
114 fprintf(stderr, "nedit: findAllMatches(): out of heap space!\n");
115 XBell(TheDisplay, 0);
116 - return -1;
117 + return -2;
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]);
126 free(dupTagsList);
128 XBell(TheDisplay, 0);
129 - return -1;
130 + return -2;
133 strcpy(dupTagsList[i],temp);
135 createSelectMenu(dialogParent, "Duplicate Tags", nMatches, dupTagsList);
136 for (i=0; i<nMatches; i++)
137 free(dupTagsList[i]);
138 free(dupTagsList);
139 - return 1;
140 + return 0;
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 );
150 - else
151 - showMatchingCalltip( dialogParent, 0 );
152 - return 1;
153 + return 0;
155 + else {
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;
175 - int endPos=0;
176 + int endPos=0, calltipID = 0;
177 char *fileString;
178 FILE *fp;
179 struct stat statbuf;
180 char *message;
182 @@ -1329,38 +1345,38 @@ static void showMatchingCalltip( Widget
183 NormalizePathname(tagFiles[i], NULL);
184 fp = fopen(tagFiles[i], "r");
185 if (fp == NULL) {
186 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
187 "OK", tagFiles[i]);
188 - return;
189 + return 0;
191 if (fstat(fileno(fp), &statbuf) != 0) {
192 fclose(fp);
193 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
194 "OK", tagFiles[i]);
195 - return;
196 + return 0;
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) {
204 fclose(fp);
205 DialogF(DF_ERR, parent, 1, "File too large",
206 "File is too large to load", "OK");
207 - return;
208 + return 0;
211 /* Read the file into fileString and terminate with a null */
212 readLen = fread(fileString, sizeof(char), fileLen, fp);
213 if (ferror(fp)) {
214 fclose(fp);
215 DialogF(DF_ERR, parent, 1, "Error reading File", "Error reading %s",
216 "OK", tagFiles[i]);
217 XtFree(fileString);
218 - return;
219 + return 0;
221 fileString[readLen] = 0;
223 /* Close the file */
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]);
230 XtFree(fileString);
231 - return;
232 + return 0;
234 } else {
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,
240 tagFiles[i]);
241 XtFree(fileString);
242 - return;
243 + return 0;
247 if (searchMode == TIP) {
248 int dummy, found;
249 @@ -1421,19 +1437,20 @@ static void showMatchingCalltip( Widget
250 if (message == NULL)
252 DialogF(DF_ERR, parent, 1, "Out of Memory",
253 "Can't allocate memory for calltip message", "OK");
254 XtFree(fileString);
255 - return;
256 + return 0;
258 strncpy( message, &fileString[startPos], tipLen );
259 message[tipLen] = 0;
261 /* 6. Display it */
262 - tagsShowCalltip( WidgetToWindow(parent), message );
263 + calltipID = tagsShowCalltip( WidgetToWindow(parent), message );
264 XtFree(message);
265 XtFree(fileString);
266 + return calltipID;
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 )