2506
|
1 Octave depends on being able to call the GNU info reader with the |
|
2 command line arguments |
|
3 |
|
4 --index-search STRING |
|
5 |
|
6 to find individual entries in the manual. The following patch |
|
7 implements this option. It is relative to the version of info |
|
8 distributed with texinfo-3.9. |
|
9 |
|
10 The patch has already been applied to the info sources distributed |
|
11 with Octave. It is only provided here in case you want to add this |
|
12 option to some other version of info that you may have. |
|
13 |
|
14 This patch has been submitted to the maintainers of Texinfo, so maybe |
|
15 someday it will not be necessary. |
|
16 |
|
17 jwe |
|
18 |
|
19 |
|
20 Tue Nov 12 14:44:00 1996 John W. Eaton <jwe@bevo.che.wisc.edu> |
|
21 |
|
22 * info/session.c (initialize_info_session): New arg, |
|
23 clear_screen. Change all callers. |
|
24 |
|
25 * info/info.c (main): Handle new option, --index-search STRING. |
|
26 (index_search_p, index_search_string): New static variables, used |
|
27 to handle --index-search option. |
|
28 |
|
29 * info/indices.h (do_info_index_search, index_intry_exists): |
|
30 Provide declarations here. |
|
31 |
|
32 * info/indices.c (do_info_index_search): New function, extracted |
|
33 from info_index_search. |
|
34 (info_index_search): Simply call do_info_index_search() with |
|
35 search_string set to NULL. |
|
36 (index_entry_exists): New function. |
|
37 |
|
38 |
|
39 diff -cNr texinfo-3.9/info/indices.c texinfo-3.9.local/info/indices.c |
|
40 *** texinfo-3.9/info/indices.c Fri Jun 16 12:59:55 1995 |
|
41 --- texinfo-3.9.local/info/indices.c Tue Nov 12 15:09:58 1996 |
|
42 *************** |
|
43 *** 174,180 **** |
|
44 } |
|
45 |
|
46 DECLARE_INFO_COMMAND (info_index_search, |
|
47 ! "Look up a string in the index for this file") |
|
48 { |
|
49 FILE_BUFFER *fb; |
|
50 char *line; |
|
51 --- 174,191 ---- |
|
52 } |
|
53 |
|
54 DECLARE_INFO_COMMAND (info_index_search, |
|
55 ! "Look up a string in the index for this file") |
|
56 ! { |
|
57 ! do_info_index_search (window, count, 0); |
|
58 ! } |
|
59 ! |
|
60 ! /* Look up SEARCH_STRING in the index for this file. If SEARCH_STRING |
|
61 ! is NULL, prompt user for input. */ |
|
62 ! void |
|
63 ! do_info_index_search (window, count, search_string) |
|
64 ! WINDOW *window; |
|
65 ! int count; |
|
66 ! char *search_string; |
|
67 { |
|
68 FILE_BUFFER *fb; |
|
69 char *line; |
|
70 *************** |
|
71 *** 204,239 **** |
|
72 return; |
|
73 } |
|
74 |
|
75 ! /* Okay, there is an index. Let the user select one of the members of it. */ |
|
76 ! line = |
|
77 ! info_read_maybe_completing (window, "Index entry: ", index_index); |
|
78 ! |
|
79 ! window = active_window; |
|
80 ! |
|
81 ! /* User aborted? */ |
|
82 ! if (!line) |
|
83 { |
|
84 ! info_abort_key (active_window, 1, 0); |
|
85 ! return; |
|
86 ! } |
|
87 |
|
88 ! /* Empty line means move to the Index node. */ |
|
89 ! if (!*line) |
|
90 ! { |
|
91 ! free (line); |
|
92 |
|
93 ! if (initial_index_filename && initial_index_nodename) |
|
94 { |
|
95 ! NODE *node; |
|
96 ! |
|
97 ! node = |
|
98 ! info_get_node (initial_index_filename, initial_index_nodename); |
|
99 ! set_remembered_pagetop_and_point (window); |
|
100 ! window_set_node_of_window (window, node); |
|
101 ! remember_window_and_node (window, node); |
|
102 ! window_clear_echo_area (); |
|
103 return; |
|
104 } |
|
105 } |
|
106 |
|
107 /* The user typed either a completed index label, or a partial string. |
|
108 --- 215,256 ---- |
|
109 return; |
|
110 } |
|
111 |
|
112 ! /* Okay, there is an index. Look for SEARCH_STRING, or, if it is |
|
113 ! empty, prompt for one. */ |
|
114 ! if (search_string && *search_string) |
|
115 ! line = strdup (search_string); |
|
116 ! else |
|
117 { |
|
118 ! line = |
|
119 ! info_read_maybe_completing (window, "Index entry: ", index_index); |
|
120 |
|
121 ! window = active_window; |
|
122 |
|
123 ! /* User aborted? */ |
|
124 ! if (!line) |
|
125 { |
|
126 ! info_abort_key (active_window, 1, 0); |
|
127 return; |
|
128 } |
|
129 + |
|
130 + /* Empty line means move to the Index node. */ |
|
131 + if (!*line) |
|
132 + { |
|
133 + free (line); |
|
134 + |
|
135 + if (initial_index_filename && initial_index_nodename) |
|
136 + { |
|
137 + NODE *node; |
|
138 + |
|
139 + node = |
|
140 + info_get_node (initial_index_filename, initial_index_nodename); |
|
141 + set_remembered_pagetop_and_point (window); |
|
142 + window_set_node_of_window (window, node); |
|
143 + remember_window_and_node (window, node); |
|
144 + window_clear_echo_area (); |
|
145 + return; |
|
146 + } |
|
147 + } |
|
148 } |
|
149 |
|
150 /* The user typed either a completed index label, or a partial string. |
|
151 *************** |
|
152 *** 265,270 **** |
|
153 --- 282,334 ---- |
|
154 if (index_offset == old_offset) |
|
155 index_offset = 0; |
|
156 } |
|
157 + } |
|
158 + |
|
159 + int |
|
160 + index_entry_exists (window, string) |
|
161 + WINDOW *window; |
|
162 + char *string; |
|
163 + { |
|
164 + register int i; |
|
165 + FILE_BUFFER *fb; |
|
166 + |
|
167 + /* If there is no previous search string, the user hasn't built an index |
|
168 + yet. */ |
|
169 + if (!string) |
|
170 + return 0; |
|
171 + |
|
172 + fb = file_buffer_of_window (window); |
|
173 + if (!initial_index_filename || |
|
174 + (strcmp (initial_index_filename, fb->filename) != 0)) |
|
175 + { |
|
176 + info_free_references (index_index); |
|
177 + index_index = info_indices_of_file_buffer (fb); |
|
178 + } |
|
179 + |
|
180 + /* If there is no index, that is an error. */ |
|
181 + if (!index_index) |
|
182 + return 0; |
|
183 + |
|
184 + for (i = 0; (i > -1) && (index_index[i]); i++) |
|
185 + if (strcmp (string, index_index[i]->label) == 0) |
|
186 + break; |
|
187 + |
|
188 + /* If that failed, look for the next substring match. */ |
|
189 + if ((i < 0) || (!index_index[i])) |
|
190 + { |
|
191 + for (i = 0; (i > -1) && (index_index[i]); i++) |
|
192 + if (string_in_line (string, index_index[i]->label) != -1) |
|
193 + break; |
|
194 + |
|
195 + if ((i > -1) && (index_index[i])) |
|
196 + string_in_line (string, index_index[i]->label); |
|
197 + } |
|
198 + |
|
199 + /* If that failed, return 0. */ |
|
200 + if ((i < 0) || (!index_index[i])) |
|
201 + return 0; |
|
202 + |
|
203 + return 1; |
|
204 } |
|
205 |
|
206 DECLARE_INFO_COMMAND (info_next_index_match, |
|
207 diff -cNr texinfo-3.9/info/indices.h texinfo-3.9.local/info/indices.h |
|
208 *** texinfo-3.9/info/indices.h Fri Jun 16 13:01:54 1995 |
|
209 --- texinfo-3.9.local/info/indices.h Tue Nov 12 15:01:54 1996 |
|
210 *************** |
|
211 *** 35,39 **** |
|
212 --- 35,41 ---- |
|
213 |
|
214 /* User visible functions declared in indices.c. */ |
|
215 extern void info_index_search (), info_next_index_match (); |
|
216 + extern void do_info_index_search (); |
|
217 + extern int index_intry_exists (); |
|
218 |
|
219 #endif /* !_INDICES_H_ */ |
|
220 diff -cNr texinfo-3.9/info/info.c texinfo-3.9.local/info/info.c |
|
221 *** texinfo-3.9/info/info.c Fri Oct 4 13:19:54 1996 |
|
222 --- texinfo-3.9.local/info/info.c Tue Nov 12 15:21:19 1996 |
|
223 *************** |
|
224 *** 39,44 **** |
|
225 --- 39,52 ---- |
|
226 /* Variable containing the string to search for when apropos_p is non-zero. */ |
|
227 static char *apropos_search_string = (char *)NULL; |
|
228 |
|
229 + /* Non-zero means search all indices for INDEX_SEARCH_STRING. Unlike |
|
230 + apropos, this puts the user at the node, running info. */ |
|
231 + static int index_search_p = 0; |
|
232 + |
|
233 + /* Variable containing the string to search for when index_search_p is |
|
234 + non-zero. */ |
|
235 + static char *index_search_string = (char *)NULL; |
|
236 + |
|
237 /* Non-zero means print version info only. */ |
|
238 static int print_version_p = 0; |
|
239 |
|
240 *************** |
|
241 *** 70,75 **** |
|
242 --- 78,84 ---- |
|
243 #define APROPOS_OPTION 1 |
|
244 #define DRIBBLE_OPTION 2 |
|
245 #define RESTORE_OPTION 3 |
|
246 + #define IDXSRCH_OPTION 4 |
|
247 static struct option long_options[] = { |
|
248 { "apropos", 1, 0, APROPOS_OPTION }, |
|
249 { "directory", 1, 0, 'd' }, |
|
250 *************** |
|
251 *** 81,86 **** |
|
252 --- 90,96 ---- |
|
253 { "version", 0, &print_version_p, 1 }, |
|
254 { "dribble", 1, 0, DRIBBLE_OPTION }, |
|
255 { "restore", 1, 0, RESTORE_OPTION }, |
|
256 + { "index-search", 1, 0, IDXSRCH_OPTION }, |
|
257 {NULL, 0, NULL, 0} |
|
258 }; |
|
259 |
|
260 *************** |
|
261 *** 181,186 **** |
|
262 --- 191,203 ---- |
|
263 info_set_input_from_file (optarg); |
|
264 break; |
|
265 |
|
266 + /* User has specified a string to search all indices for. */ |
|
267 + case IDXSRCH_OPTION: |
|
268 + index_search_p = 1; |
|
269 + maybe_free (index_search_string); |
|
270 + index_search_string = strdup (optarg); |
|
271 + break; |
|
272 + |
|
273 default: |
|
274 usage (); |
|
275 } |
|
276 *************** |
|
277 *** 286,291 **** |
|
278 --- 303,345 ---- |
|
279 begin_multiple_window_info_session (user_filename, user_nodenames); |
|
280 |
|
281 exit (0); |
|
282 + } |
|
283 + |
|
284 + /* If the user specified `--index-search string', start the info |
|
285 + session in the node corresponding to the first match. */ |
|
286 + if (index_search_p) |
|
287 + { |
|
288 + int status = 0; |
|
289 + |
|
290 + initialize_info_session (initial_node, 0); |
|
291 + |
|
292 + if (index_entry_exists (windows, index_search_string)) |
|
293 + { |
|
294 + terminal_clear_screen (); |
|
295 + terminal_prep_terminal (); |
|
296 + display_update_display (windows); |
|
297 + info_last_executed_command = (VFunction *)NULL; |
|
298 + |
|
299 + do_info_index_search (windows, 0, index_search_string); |
|
300 + |
|
301 + info_read_and_dispatch (); |
|
302 + |
|
303 + terminal_unprep_terminal (); |
|
304 + |
|
305 + /* On program exit, leave the cursor at the bottom of the |
|
306 + window, and restore the terminal IO. */ |
|
307 + terminal_goto_xy (0, screenheight - 1); |
|
308 + terminal_clear_to_eol (); |
|
309 + fflush (stdout); |
|
310 + } |
|
311 + else |
|
312 + { |
|
313 + fprintf (stderr, "no entries found\n"); |
|
314 + status = -1; |
|
315 + } |
|
316 + |
|
317 + close_dribble_file (); |
|
318 + exit (status); |
|
319 } |
|
320 |
|
321 /* If there are arguments remaining, they are the names of menu items |
|
322 diff -cNr texinfo-3.9/info/session.c texinfo-3.9.local/info/session.c |
|
323 *** texinfo-3.9/info/session.c Fri Jul 19 09:56:01 1996 |
|
324 --- texinfo-3.9.local/info/session.c Tue Nov 12 15:33:08 1996 |
|
325 *************** |
|
326 *** 92,98 **** |
|
327 /* If this is the first node, initialize the info session. */ |
|
328 if (!window) |
|
329 { |
|
330 ! initialize_info_session (node); |
|
331 window = active_window; |
|
332 } |
|
333 else |
|
334 --- 92,98 ---- |
|
335 /* If this is the first node, initialize the info session. */ |
|
336 if (!window) |
|
337 { |
|
338 ! initialize_info_session (node, 1); |
|
339 window = active_window; |
|
340 } |
|
341 else |
|
342 *************** |
|
343 *** 145,151 **** |
|
344 char *format; |
|
345 void *arg; |
|
346 { |
|
347 ! initialize_info_session (initial_node); |
|
348 info_error (format, arg, (void *)NULL); |
|
349 info_session (); |
|
350 } |
|
351 --- 145,151 ---- |
|
352 char *format; |
|
353 void *arg; |
|
354 { |
|
355 ! initialize_info_session (initial_node, 1); |
|
356 info_error (format, arg, (void *)NULL); |
|
357 info_session (); |
|
358 } |
|
359 *************** |
|
360 *** 155,161 **** |
|
361 begin_info_session (initial_node) |
|
362 NODE *initial_node; |
|
363 { |
|
364 ! initialize_info_session (initial_node); |
|
365 display_startup_message_and_start (); |
|
366 } |
|
367 |
|
368 --- 155,161 ---- |
|
369 begin_info_session (initial_node) |
|
370 NODE *initial_node; |
|
371 { |
|
372 ! initialize_info_session (initial_node, 1); |
|
373 display_startup_message_and_start (); |
|
374 } |
|
375 |
|
376 *************** |
|
377 *** 260,269 **** |
|
378 extern void initialize_info_signal_handler (); |
|
379 |
|
380 /* Initialize the first info session by starting the terminal, window, |
|
381 ! and display systems. */ |
|
382 void |
|
383 ! initialize_info_session (node) |
|
384 NODE *node; |
|
385 { |
|
386 char *getenv (), *term_name; |
|
387 |
|
388 --- 260,271 ---- |
|
389 extern void initialize_info_signal_handler (); |
|
390 |
|
391 /* Initialize the first info session by starting the terminal, window, |
|
392 ! and display systems. If CLEAR_SCREEN is 0, don't clear the |
|
393 ! screen. */ |
|
394 void |
|
395 ! initialize_info_session (node, clear_screen) |
|
396 NODE *node; |
|
397 + int clear_screen; |
|
398 { |
|
399 char *getenv (), *term_name; |
|
400 |
|
401 *************** |
|
402 *** 279,285 **** |
|
403 exit (1); |
|
404 } |
|
405 |
|
406 ! terminal_clear_screen (); |
|
407 initialize_info_keymaps (); |
|
408 window_initialize_windows (screenwidth, screenheight); |
|
409 initialize_info_signal_handler (); |
|
410 --- 281,289 ---- |
|
411 exit (1); |
|
412 } |
|
413 |
|
414 ! if (clear_screen) |
|
415 ! terminal_clear_screen (); |
|
416 ! |
|
417 initialize_info_keymaps (); |
|
418 window_initialize_windows (screenwidth, screenheight); |
|
419 initialize_info_signal_handler (); |
|
420 |