pushString: remove unused variables
[nedit-bw.git] / calltipsID.diff
blob1a33e6fe5fa3aa2a4cb29fe1dc9df3cd8f8edf30
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 @@ -123,7 +123,7 @@ static void findAllCB(Widget parent, XtP
13 static Widget createSelectMenu(Widget parent, char *label, int nArgs,
14 char *args[]);
15 static void editTaggedLocation( Widget parent, int i );
16 -static void showMatchingCalltip( Widget parent, int i );
17 +static int showMatchingCalltip( Widget parent, int i );
19 static const char *rcs_strdup(const char *str);
20 static void rcs_free(const char *str);
21 @@ -856,6 +856,11 @@ int LookupTag(const char *name, const ch
22 /*
23 ** This code path is followed if the request came from either
24 ** FindDefinition or FindDefCalltip. This should probably be refactored.
25 +**
26 +** If search_type = TAG,
27 +** returns <= 0 on errors or when no Def found, > 0 when Def found.
28 +** Else,
29 +** returns the calltip ID, or 0 on failure.
31 static int findDef(WindowInfo *window, const char *value, int search_type) {
32 static char tagText[MAX_TAG_LEN + 1];
33 @@ -875,15 +880,19 @@ static int findDef(WindowInfo *window, c
34 tagText[ml] = '\0';
35 /* See if we can find the tip/tag */
36 status = findAllMatches(window, tagText);
37 + if (search_type == TAG && status == 0) {
38 + status++;
39 + }
41 /* If we didn't find a requested calltip, see if we can use a tag */
42 - if (status == 0 && search_type == TIP && TagsFileList != NULL) {
43 + if (status == -1 && search_type == TIP && TagsFileList != NULL) {
44 searchMode = TIP_FROM_TAG;
45 status = findAllMatches(window, tagText);
48 - if (status == 0) {
49 + if (status == -1) {
50 /* Didn't find any matches */
51 + status++;
52 if (searchMode == TIP_FROM_TAG || searchMode == TIP) {
53 sprintf(message, "No match for \"%s\" in calltips or tags.",
54 tagName);
55 @@ -1112,7 +1121,11 @@ static int fakeRegExSearch(WindowInfo *w
57 /* Finds all matches and handles tag "collisions". Prompts user with a
58 list of collided tags in the hash table and allows the user to select
59 - the correct one. */
60 + the correct one.
62 + Returns -2 on error condition, -1 if no matches found and a
63 + number >= 0 if matches were found.
64 + (Note: the value is *not* the number of matches.) */
65 static int findAllMatches(WindowInfo *window, const char *string)
67 Widget dialogParent = window->textArea;
68 @@ -1125,7 +1138,7 @@ static int findAllMatches(WindowInfo *wi
69 /* verify that the string is reasonable as a tag */
70 if (*string == '\0' || strlen(string) > MAX_TAG_LEN) {
71 XBell(TheDisplay, 0);
72 - return -1;
73 + return -2;
75 tagName=string;
77 @@ -1175,7 +1188,7 @@ static int findAllMatches(WindowInfo *wi
79 /* Did we find any matches? */
80 if (!nMatches) {
81 - return 0;
82 + return -1;
85 /* Only one of the matches is in the same dir. as this file. Use it. */
86 @@ -1200,7 +1213,7 @@ static int findAllMatches(WindowInfo *wi
87 if (!(dupTagsList = (char **) malloc(sizeof(char *) * nMatches))) {
88 fprintf(stderr, "nedit: findAllMatches(): out of heap space!\n");
89 XBell(TheDisplay, 0);
90 - return -1;
91 + return -2;
94 for (i=0; i<nMatches; i++) {
95 @@ -1232,7 +1245,7 @@ static int findAllMatches(WindowInfo *wi
96 free(dupTagsList);
98 XBell(TheDisplay, 0);
99 - return -1;
100 + return -2;
103 strcpy(dupTagsList[i],temp);
104 @@ -1241,18 +1254,20 @@ static int findAllMatches(WindowInfo *wi
105 for (i=0; i<nMatches; i++)
106 free(dupTagsList[i]);
107 free(dupTagsList);
108 - return 1;
109 + return 0;
113 ** No need for a dialog list, there is only one tag matching --
114 ** Go directly to the tag
116 - if (searchMode == TAG)
117 + if (searchMode == TAG) {
118 editTaggedLocation( dialogParent, 0 );
119 - else
120 - showMatchingCalltip( dialogParent, 0 );
121 - return 1;
122 + return 0;
124 + else {
125 + return showMatchingCalltip( dialogParent, 0 );
129 /* Callback function for the FindAll widget. Process the users response. */
130 @@ -1315,11 +1330,12 @@ static int moveAheadNLines( char *str, i
131 ** Show the calltip specified by tagFiles[i], tagSearch[i], tagPosInf[i]
132 ** This reads from either a source code file (if searchMode == TIP_FROM_TAG)
133 ** or a calltips file (if searchMode == TIP).
134 +** Returns the calltip ID or 0 in case of failure.
136 -static void showMatchingCalltip( Widget parent, int i )
137 +static int showMatchingCalltip( Widget parent, int i )
139 int startPos=0, fileLen, readLen, tipLen;
140 - int endPos=0;
141 + int endPos=0, calltipID = 0;
142 char *fileString;
143 FILE *fp;
144 struct stat statbuf;
145 @@ -1331,13 +1347,13 @@ static void showMatchingCalltip( Widget
146 if (fp == NULL) {
147 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
148 "OK", tagFiles[i]);
149 - return;
150 + return 0;
152 if (fstat(fileno(fp), &statbuf) != 0) {
153 fclose(fp);
154 DialogF(DF_ERR, parent, 1, "Error opening File", "Error opening %s",
155 "OK", tagFiles[i]);
156 - return;
157 + return 0;
160 /* 2. Read the target file */
161 @@ -1348,7 +1364,7 @@ static void showMatchingCalltip( Widget
162 fclose(fp);
163 DialogF(DF_ERR, parent, 1, "File too large",
164 "File is too large to load", "OK");
165 - return;
166 + return 0;
169 /* Read the file into fileString and terminate with a null */
170 @@ -1358,7 +1374,7 @@ static void showMatchingCalltip( Widget
171 DialogF(DF_ERR, parent, 1, "Error reading File", "Error reading %s",
172 "OK", tagFiles[i]);
173 XtFree(fileString);
174 - return;
175 + return 0;
177 fileString[readLen] = 0;
179 @@ -1378,7 +1394,7 @@ static void showMatchingCalltip( Widget
180 "%s\n not long enough for definition to be on line %d",
181 "OK", tagFiles[i], tagPosInf[i]);
182 XtFree(fileString);
183 - return;
184 + return 0;
186 } else {
187 startPos = tagPosInf[i];
188 @@ -1388,7 +1404,7 @@ static void showMatchingCalltip( Widget
189 "Definition for %s\nnot found in %s", "OK", tagName,
190 tagFiles[i]);
191 XtFree(fileString);
192 - return;
193 + return 0;
197 @@ -1423,15 +1439,16 @@ static void showMatchingCalltip( Widget
198 DialogF(DF_ERR, parent, 1, "Out of Memory",
199 "Can't allocate memory for calltip message", "OK");
200 XtFree(fileString);
201 - return;
202 + return 0;
204 strncpy( message, &fileString[startPos], tipLen );
205 message[tipLen] = 0;
207 /* 6. Display it */
208 - tagsShowCalltip( WidgetToWindow(parent), message );
209 + calltipID = tagsShowCalltip( WidgetToWindow(parent), message );
210 XtFree(message);
211 XtFree(fileString);
212 + return calltipID;
215 /* Open a new (or existing) editor window to the location specified in