1
|
1 // variables.cc -*- C++ -*- |
|
2 /* |
|
3 |
296
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
|
28 #include <sys/types.h> |
|
29 #ifdef HAVE_UNISTD_H |
|
30 #include <unistd.h> |
|
31 #endif |
|
32 #include <ctype.h> |
|
33 #include <iostream.h> |
279
|
34 #include <strstream.h> |
1
|
35 |
|
36 #include "statdefs.h" |
|
37 #include "tree-const.h" |
|
38 #include "variables.h" |
195
|
39 #include "user-prefs.h" |
1
|
40 #include "symtab.h" |
195
|
41 #include "builtins.h" |
|
42 #include "g-builtins.h" |
|
43 #include "t-builtins.h" |
1
|
44 #include "error.h" |
|
45 #include "utils.h" |
|
46 #include "tree.h" |
164
|
47 #include "help.h" |
1
|
48 |
|
49 // Symbol table for symbols at the top level. |
|
50 symbol_table *top_level_sym_tab; |
|
51 |
|
52 // Symbol table for the current scope. |
|
53 symbol_table *curr_sym_tab; |
|
54 |
|
55 // Symbol table for global symbols. |
|
56 symbol_table *global_sym_tab; |
|
57 |
195
|
58 void |
|
59 initialize_symbol_tables (void) |
|
60 { |
|
61 global_sym_tab = new symbol_table (); |
|
62 |
|
63 top_level_sym_tab = new symbol_table (); |
|
64 |
|
65 curr_sym_tab = top_level_sym_tab; |
|
66 } |
|
67 |
1
|
68 /* |
|
69 * Is there a corresponding M-file that is newer than the symbol |
|
70 * definition? |
|
71 */ |
|
72 int |
|
73 symbol_out_of_date (symbol_record *sr) |
|
74 { |
195
|
75 int ignore = user_pref.ignore_function_time_stamp; |
|
76 |
|
77 if (ignore == 2) |
|
78 return 0; |
|
79 |
1
|
80 if (sr != (symbol_record *) NULL) |
|
81 { |
|
82 tree *ans = sr->def (); |
|
83 if (ans != NULL_TREE) |
|
84 { |
|
85 char *mf = ans->m_file_name (); |
195
|
86 if (! (mf == (char *) NULL |
|
87 || (ignore && ans->is_system_m_file ()))) |
1
|
88 { |
|
89 time_t tp = ans->time_parsed (); |
195
|
90 char *fname = m_file_in_path (mf); |
|
91 int status = is_newer (fname, tp); |
|
92 delete [] fname; |
|
93 if (status > 0) |
|
94 return 1; |
1
|
95 } |
|
96 } |
|
97 } |
195
|
98 return 0; |
1
|
99 } |
|
100 |
195
|
101 void |
|
102 document_symbol (const char *name, const char *help) |
1
|
103 { |
195
|
104 if (is_builtin_variable (name)) |
1
|
105 { |
195
|
106 error ("sorry, can't redefine help for builtin variables"); |
|
107 } |
|
108 else |
|
109 { |
|
110 symbol_record *sym_rec = curr_sym_tab->lookup (name, 0); |
|
111 if (sym_rec == (symbol_record *) NULL) |
1
|
112 { |
195
|
113 error ("document: no such symbol `%s'", name); |
1
|
114 } |
|
115 else |
|
116 { |
195
|
117 sym_rec->document (help); |
1
|
118 } |
|
119 } |
195
|
120 } |
1
|
121 |
195
|
122 void |
|
123 install_builtin_mapper_function (builtin_mapper_functions *mf) |
|
124 { |
|
125 symbol_record *sym_rec = global_sym_tab->lookup (mf->name, 1); |
|
126 sym_rec->unprotect (); |
|
127 |
|
128 Mapper_fcn mfcn; |
330
|
129 mfcn.can_return_complex_for_real_arg = mf->can_return_complex_for_real_arg; |
|
130 mfcn.lower_limit = mf->lower_limit; |
|
131 mfcn.upper_limit = mf->upper_limit; |
195
|
132 mfcn.d_d_mapper = mf->d_d_mapper; |
|
133 mfcn.d_c_mapper = mf->d_c_mapper; |
|
134 mfcn.c_c_mapper = mf->c_c_mapper; |
|
135 |
330
|
136 tree_builtin *def = new tree_builtin (2, 1, mfcn, mf->name); |
195
|
137 |
|
138 sym_rec->define (def); |
|
139 |
|
140 sym_rec->document (mf->help_string); |
|
141 sym_rec->make_eternal (); |
|
142 sym_rec->protect (); |
|
143 } |
|
144 |
|
145 void |
|
146 install_builtin_text_function (builtin_text_functions *tf) |
|
147 { |
|
148 symbol_record *sym_rec = global_sym_tab->lookup (tf->name, 1); |
|
149 sym_rec->unprotect (); |
|
150 |
|
151 tree_builtin *def = new tree_builtin (tf->nargin_max, 1, |
|
152 tf->text_fcn, tf->name); |
|
153 |
|
154 sym_rec->define (def); |
|
155 |
|
156 sym_rec->document (tf->help_string); |
|
157 sym_rec->make_eternal (); |
|
158 sym_rec->protect (); |
|
159 |
1
|
160 } |
|
161 |
195
|
162 void |
|
163 install_builtin_general_function (builtin_general_functions *gf) |
|
164 { |
|
165 symbol_record *sym_rec = global_sym_tab->lookup (gf->name, 1); |
|
166 sym_rec->unprotect (); |
|
167 |
|
168 tree_builtin *def = new tree_builtin (gf->nargin_max, |
|
169 gf->nargout_max, |
|
170 gf->general_fcn, gf->name); |
|
171 |
|
172 sym_rec->define (def); |
|
173 |
|
174 sym_rec->document (gf->help_string); |
|
175 sym_rec->make_eternal (); |
|
176 sym_rec->protect (); |
|
177 } |
|
178 |
|
179 void |
|
180 install_builtin_variable (builtin_string_variables *sv) |
1
|
181 { |
195
|
182 tree_constant *val = new tree_constant (sv->value); |
|
183 |
|
184 bind_builtin_variable (sv->name, val, 0, 1, sv->sv_function, |
|
185 sv->help_string); |
|
186 } |
|
187 |
|
188 void |
|
189 install_builtin_variable_as_function (const char *name, tree_constant *val, |
|
190 int protect = 0, int eternal = 0) |
|
191 { |
|
192 symbol_record *sym_rec = global_sym_tab->lookup (name, 1); |
|
193 sym_rec->unprotect (); |
|
194 |
|
195 char *tmp_help = sym_rec->help (); |
1
|
196 |
195
|
197 sym_rec->define_as_fcn (val); |
|
198 |
|
199 sym_rec->document (tmp_help); |
|
200 |
|
201 if (protect) |
|
202 sym_rec->protect (); |
|
203 |
|
204 if (eternal) |
|
205 sym_rec->make_eternal (); |
|
206 } |
|
207 |
|
208 void |
|
209 bind_nargin_and_nargout (symbol_table *sym_tab, int nargin, int nargout) |
|
210 { |
|
211 tree_constant *tmp; |
1
|
212 symbol_record *sr; |
|
213 |
195
|
214 sr = sym_tab->lookup ("nargin", 1, 0); |
|
215 sr->unprotect (); |
|
216 tmp = new tree_constant (nargin-1); |
|
217 sr->define (tmp); |
|
218 sr->protect (); |
|
219 |
|
220 sr = sym_tab->lookup ("nargout", 1, 0); |
|
221 sr->unprotect (); |
|
222 tmp = new tree_constant (nargout); |
|
223 sr->define (tmp); |
|
224 sr->protect (); |
1
|
225 } |
|
226 |
|
227 /* |
195
|
228 * Give a global variable a definition. This will insert the symbol |
|
229 * in the global table if necessary. |
|
230 */ |
|
231 void |
|
232 bind_builtin_variable (const char *varname, tree_constant *val, |
|
233 int protect = 0, int eternal = 0, |
|
234 sv_Function sv_fcn = (sv_Function) 0, |
|
235 const char *help = (char *) 0) |
|
236 { |
|
237 symbol_record *sr = global_sym_tab->lookup (varname, 1, 0); |
|
238 |
|
239 // It is a programming error for a builtin symbol to be missing. |
|
240 // Besides, we just inserted it, so it must be there. |
|
241 |
|
242 assert (sr != (symbol_record *) NULL); |
|
243 |
|
244 sr->unprotect (); |
|
245 |
|
246 // Must do this before define, since define will call the special |
|
247 // variable function only if it knows about it, and it needs to, so |
|
248 // that user prefs can be properly initialized. |
|
249 |
|
250 if (sv_fcn) |
|
251 sr->set_sv_function (sv_fcn); |
|
252 |
|
253 sr->define_builtin_var (val); |
|
254 |
|
255 if (protect) |
|
256 sr->protect (); |
|
257 |
|
258 if (eternal) |
|
259 sr->make_eternal (); |
|
260 |
|
261 if (help) |
|
262 sr->document (help); |
|
263 } |
|
264 |
|
265 /* |
|
266 * Look for the given name in the global symbol table. If it refers |
|
267 * to a string, return a new copy. If not, return NULL. |
1
|
268 */ |
|
269 char * |
195
|
270 builtin_string_variable (const char *name) |
1
|
271 { |
195
|
272 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
|
273 |
|
274 // It is a prorgramming error to look for builtins that aren't. |
|
275 |
|
276 assert (sr != (symbol_record *) NULL); |
|
277 |
1
|
278 char *retval = (char *) NULL; |
|
279 |
|
280 tree *defn = sr->def (); |
195
|
281 |
1
|
282 if (defn != NULL_TREE) |
|
283 { |
|
284 tree_constant val = defn->eval (0); |
195
|
285 |
|
286 if (! error_state && val.is_string_type ()) |
1
|
287 { |
|
288 char *s = val.string_value (); |
|
289 if (s != (char *) NULL) |
|
290 retval = strsave (s); |
|
291 } |
|
292 } |
|
293 |
|
294 return retval; |
|
295 } |
|
296 |
|
297 /* |
195
|
298 * Look for the given name in the global symbol table. If it refers |
|
299 * to a real scalar, place the value in d and return 0. Otherwise, |
|
300 * return -1. |
1
|
301 */ |
|
302 int |
195
|
303 builtin_real_scalar_variable (const char *name, double& d) |
1
|
304 { |
|
305 int status = -1; |
195
|
306 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
|
307 |
|
308 // It is a prorgramming error to look for builtins that aren't. |
|
309 |
|
310 assert (sr != (symbol_record *) NULL); |
1
|
311 |
|
312 tree *defn = sr->def (); |
195
|
313 |
1
|
314 if (defn != NULL_TREE) |
|
315 { |
|
316 tree_constant val = defn->eval (0); |
195
|
317 |
|
318 if (! error_state |
|
319 && val.const_type () == tree_constant_rep::scalar_constant) |
1
|
320 { |
|
321 d = val.double_value (); |
|
322 status = 0; |
|
323 } |
|
324 } |
|
325 |
|
326 return status; |
|
327 } |
|
328 |
|
329 /* |
195
|
330 * Make the definition of the symbol record sr be the same as the |
|
331 * definition of the global variable of the same name, creating it if |
|
332 * it doesn't already exist. |
|
333 */ |
|
334 void |
|
335 link_to_global_variable (symbol_record *sr) |
|
336 { |
|
337 if (sr->is_linked_to_global ()) |
|
338 return; |
|
339 |
|
340 symbol_record *gsr = global_sym_tab->lookup (sr->name (), 1, 0); |
|
341 |
|
342 if (sr->is_formal_parameter ()) |
|
343 { |
|
344 error ("can't make function parameter `%s' global", sr->name ()); |
|
345 return; |
|
346 } |
|
347 |
|
348 // There must be a better way to do this. XXX FIXME XXX |
|
349 |
|
350 if (sr->is_variable ()) |
|
351 { |
|
352 // Would be nice not to have this cast. XXX FIXME XXX |
|
353 tree_constant *tmp = (tree_constant *) sr->def (); |
207
|
354 if (tmp == NULL_TREE_CONST) |
|
355 tmp = new tree_constant (); |
|
356 else |
|
357 tmp = new tree_constant (*tmp); |
195
|
358 gsr->define (tmp); |
|
359 } |
|
360 else |
|
361 { |
|
362 sr->clear (); |
|
363 } |
|
364 |
|
365 // If the global symbol is currently defined as a function, we need to |
|
366 // hide it with a variable. |
|
367 |
|
368 if (gsr->is_function ()) |
|
369 gsr->define (NULL_TREE_CONST); |
|
370 |
|
371 sr->alias (gsr, 1); |
|
372 sr->mark_as_linked_to_global (); |
|
373 } |
|
374 |
|
375 /* |
|
376 * Make the definition of the symbol record sr be the same as the |
|
377 * definition of the builtin variable of the same name. |
|
378 */ |
|
379 void |
|
380 link_to_builtin_variable (symbol_record *sr) |
|
381 { |
|
382 symbol_record *tmp_sym = global_sym_tab->lookup (sr->name (), 0, 0); |
|
383 |
|
384 if (tmp_sym != (symbol_record *) NULL) |
|
385 { |
|
386 if (tmp_sym->is_builtin_variable ()) |
|
387 { |
|
388 sr->alias (tmp_sym); |
|
389 } |
|
390 } |
|
391 } |
|
392 |
|
393 /* |
|
394 * Make the definition of the symbol record sr be the same as the |
|
395 * definition of the builtin variable or function, or user function of |
|
396 * the same name, provided that the name has not been used as a formal |
|
397 * parameter. |
|
398 */ |
|
399 void |
|
400 link_to_builtin_or_function (symbol_record *sr) |
|
401 { |
|
402 symbol_record *tmp_sym = global_sym_tab->lookup (sr->name (), 0, 0); |
|
403 |
|
404 if (tmp_sym != (symbol_record *) NULL) |
|
405 { |
|
406 if ((tmp_sym->is_builtin_variable () || tmp_sym->is_function ()) |
|
407 && ! tmp_sym->is_formal_parameter ()) |
|
408 { |
|
409 sr->alias (tmp_sym); |
|
410 } |
|
411 } |
|
412 } |
|
413 |
|
414 /* |
|
415 * Force a link to a function in the current symbol table. This is |
|
416 * used just after defining a function to avoid different behavior |
|
417 * depending on whether or not the function has been evaluated after |
|
418 * being defined. |
|
419 * |
|
420 * Return without doing anything if there isn't a function with the |
|
421 * given name defined in the global symbol table. |
|
422 */ |
|
423 void |
|
424 force_link_to_function (const char *id_name) |
|
425 { |
|
426 symbol_record *gsr = global_sym_tab->lookup (id_name, 1, 0); |
|
427 if (gsr->is_function ()) |
|
428 { |
|
429 curr_sym_tab->clear (id_name); |
|
430 symbol_record *csr = curr_sym_tab->lookup (id_name, 1, 0); |
|
431 csr->alias (gsr); |
|
432 } |
|
433 } |
|
434 |
|
435 /* |
|
436 * Return 1 if the argument names a globally visible variable. |
|
437 * Otherwise, return 0. |
|
438 */ |
|
439 int |
|
440 is_globally_visible (const char *name) |
|
441 { |
|
442 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); |
|
443 return (sr != (symbol_record *) NULL && sr->is_linked_to_global ()); |
|
444 } |
|
445 |
|
446 /* |
1
|
447 * Extract a keyword and its value from a file. Input should look |
|
448 * something like: |
|
449 * |
|
450 * #[ \t]*keyword[ \t]*:[ \t]*string-value\n |
279
|
451 * |
312
|
452 * Returns a pointer to new storage. The caller is responsible for |
|
453 * deleting it. |
1
|
454 */ |
279
|
455 char * |
|
456 extract_keyword (istream& is, char *keyword) |
1
|
457 { |
279
|
458 ostrstream buf; |
1
|
459 |
312
|
460 char *retval = (char *) NULL; |
1
|
461 |
|
462 char c; |
|
463 while (is.get (c)) |
|
464 { |
|
465 if (c == '#') |
|
466 { |
|
467 while (is.get (c) && (c == ' ' || c == '\t' || c == '#')) |
|
468 ; // Skip whitespace and comment characters. |
|
469 |
|
470 if (isalpha (c)) |
279
|
471 buf << c; |
1
|
472 |
|
473 while (is.get (c) && isalpha (c)) |
279
|
474 buf << c; |
1
|
475 |
279
|
476 buf << ends; |
|
477 char *tmp = buf.str (); |
|
478 int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); |
|
479 delete [] tmp; |
|
480 |
|
481 if (match) |
1
|
482 { |
279
|
483 ostrstream value; |
1
|
484 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) |
|
485 ; // Skip whitespace and the colon. |
|
486 |
|
487 if (c != '\n') |
|
488 { |
279
|
489 value << c; |
1
|
490 while (is.get (c) && c != '\n') |
279
|
491 value << c; |
1
|
492 } |
279
|
493 value << ends; |
|
494 retval = value.str (); |
1
|
495 break; |
|
496 } |
|
497 } |
|
498 } |
279
|
499 return retval; |
1
|
500 } |
|
501 |
|
502 int |
|
503 extract_keyword (istream& is, char *keyword, int& value) |
|
504 { |
279
|
505 ostrstream buf; |
1
|
506 |
|
507 int status = 0; |
|
508 value = 0; |
|
509 |
|
510 char c; |
|
511 while (is.get (c)) |
|
512 { |
|
513 if (c == '#') |
|
514 { |
|
515 while (is.get (c) && (c == ' ' || c == '\t' || c == '#')) |
|
516 ; // Skip whitespace and comment characters. |
|
517 |
|
518 if (isalpha (c)) |
279
|
519 buf << c; |
1
|
520 |
|
521 while (is.get (c) && isalpha (c)) |
279
|
522 buf << c; |
1
|
523 |
279
|
524 buf << ends; |
|
525 char *tmp = buf.str (); |
|
526 int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); |
|
527 delete [] tmp; |
|
528 |
|
529 if (match) |
1
|
530 { |
|
531 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) |
|
532 ; // Skip whitespace and the colon. |
|
533 |
|
534 is.putback (c); |
|
535 if (c != '\n') |
|
536 is >> value; |
|
537 if (is) |
|
538 status = 1; |
|
539 while (is.get (c) && c != '\n') |
|
540 ; // Skip to beginning of next line; |
|
541 break; |
|
542 } |
|
543 } |
|
544 } |
|
545 return status; |
|
546 } |
|
547 |
|
548 /* |
|
549 * Skip trailing white space and |
|
550 */ |
|
551 void |
|
552 skip_comments (istream& is) |
|
553 { |
|
554 char c = '\0'; |
|
555 while (is.get (c)) |
|
556 { |
|
557 if (c == ' ' || c == '\t' || c == '\n') |
|
558 ; // Skip whitespace on way to beginning of next line. |
|
559 else |
|
560 break; |
|
561 } |
|
562 |
|
563 for (;;) |
|
564 { |
|
565 if (is && c == '#') |
|
566 while (is.get (c) && c != '\n') |
|
567 ; // Skip to beginning of next line, ignoring everything. |
|
568 else |
|
569 break; |
|
570 } |
|
571 } |
|
572 |
|
573 /* |
|
574 * Is `s' a valid identifier? |
|
575 */ |
|
576 int |
|
577 valid_identifier (char *s) |
|
578 { |
|
579 if (s == (char *) NULL || ! (isalnum (*s) || *s == '_')) |
|
580 return 0; |
|
581 |
|
582 while (*++s != '\0') |
|
583 if (! (isalnum (*s) || *s == '_')) |
|
584 return 0; |
|
585 |
|
586 return 1; |
|
587 } |
|
588 |
|
589 /* |
|
590 * See if the identifier is in scope. |
|
591 */ |
|
592 int |
|
593 identifier_exists (char *name) |
|
594 { |
159
|
595 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); |
|
596 if (sr == (symbol_record *) NULL) |
|
597 sr = global_sym_tab->lookup (name, 0, 0); |
1
|
598 |
159
|
599 if (sr != (symbol_record *) NULL && sr->is_variable ()) |
|
600 return 1; |
|
601 else if (sr != (symbol_record *) NULL && sr->is_function ()) |
|
602 return 2; |
1
|
603 else |
|
604 { |
|
605 char *path = m_file_in_path (name); |
|
606 if (path != (char *) NULL) |
|
607 { |
|
608 delete [] path; |
159
|
609 return 2; |
1
|
610 } |
|
611 else |
|
612 { |
|
613 struct stat buf; |
|
614 if (stat (name, &buf) == 0 && S_ISREG (buf.st_mode)) |
159
|
615 return 2; |
1
|
616 } |
|
617 } |
159
|
618 return 0; |
1
|
619 } |
|
620 |
|
621 /* |
195
|
622 * Is this variable a builtin? |
|
623 */ |
|
624 int |
|
625 is_builtin_variable (const char *name) |
|
626 { |
|
627 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
|
628 return (sr != (symbol_record *) NULL && sr->is_builtin_variable ()); |
|
629 } |
|
630 |
|
631 /* |
1
|
632 * Is this tree_constant a valid function? |
|
633 */ |
|
634 tree * |
|
635 is_valid_function (tree_constant& arg, char *warn_for, int warn = 0) |
|
636 { |
|
637 tree *ans = NULL_TREE; |
|
638 |
|
639 if (! arg.is_string_type ()) |
|
640 { |
|
641 if (warn) |
217
|
642 error ("%s: expecting function name as argument", warn_for); |
1
|
643 return ans; |
|
644 } |
|
645 |
|
646 char *fcn_name = arg.string_value (); |
|
647 symbol_record *sr = global_sym_tab->lookup (fcn_name, 0, 0); |
|
648 |
|
649 if (sr == (symbol_record *) NULL) |
|
650 { |
|
651 sr = global_sym_tab->lookup (fcn_name, 1, 0); |
|
652 tree_identifier tmp (sr); |
|
653 tmp.parse_m_file (0); |
|
654 } |
|
655 else if (symbol_out_of_date (sr)) |
|
656 { |
|
657 tree_identifier tmp (sr); |
|
658 tmp.parse_m_file (0); |
|
659 } |
|
660 |
|
661 ans = sr->def (); |
|
662 if (ans == NULL_TREE || ! sr->is_function ()) |
|
663 { |
|
664 if (warn) |
217
|
665 error ("%s: the symbol `%s' is not valid as a function", |
|
666 warn_for, fcn_name); |
1
|
667 ans = NULL_TREE; |
|
668 } |
|
669 |
|
670 return ans; |
|
671 } |
|
672 |
|
673 /* |
|
674 * Does this function take the right number of arguments? |
|
675 */ |
|
676 int |
|
677 takes_correct_nargs (tree *fcn, int expected_nargin, char *warn_for, |
|
678 int warn = 0) |
|
679 { |
|
680 int nargs = fcn->max_expected_args () - 1; |
|
681 int e_nargs = expected_nargin - 1; |
|
682 if (nargs != e_nargs) |
|
683 { |
|
684 if (warn) |
217
|
685 error ("%s: expecting function to take %d argument%c", |
|
686 warn_for, e_nargs, s_plural (e_nargs)); |
1
|
687 return 0; |
|
688 } |
|
689 return 1; |
|
690 } |
|
691 |
195
|
692 // It's not likely that this does the right thing now. XXX FIXME XXX |
|
693 |
1
|
694 char ** |
|
695 make_name_list (void) |
|
696 { |
|
697 int key_len = 0; |
|
698 int glb_len = 0; |
|
699 int top_len = 0; |
|
700 int lcl_len = 0; |
|
701 int mfl_len = 0; |
|
702 |
|
703 char **key = (char **) NULL; |
|
704 char **glb = (char **) NULL; |
|
705 char **top = (char **) NULL; |
|
706 char **lcl = (char **) NULL; |
|
707 char **mfl = (char **) NULL; |
|
708 |
244
|
709 // Each of these functions returns a new vector of pointers to new |
|
710 // strings. |
|
711 |
1
|
712 key = names (keyword_help (), key_len); |
|
713 glb = global_sym_tab->list (glb_len); |
|
714 top = top_level_sym_tab->list (top_len); |
|
715 if (top_level_sym_tab != curr_sym_tab) |
|
716 lcl = curr_sym_tab->list (lcl_len); |
|
717 mfl = get_m_file_names (mfl_len, 1); |
|
718 |
|
719 int total_len = key_len + glb_len + top_len + lcl_len + mfl_len; |
|
720 |
|
721 char **list = new char * [total_len+1]; |
|
722 |
244
|
723 // Put all the symbols in one big list. Only copy pointers, not the |
|
724 // strings they point to, then only delete the original array of |
|
725 // pointers, and not the strings they point to. |
|
726 |
1
|
727 int j = 0; |
|
728 int i = 0; |
|
729 for (i = 0; i < key_len; i++) |
244
|
730 list[j++] = key[i]; |
1
|
731 |
|
732 for (i = 0; i < glb_len; i++) |
244
|
733 list[j++] = glb[i]; |
1
|
734 |
|
735 for (i = 0; i < top_len; i++) |
244
|
736 list[j++] = top[i]; |
1
|
737 |
|
738 for (i = 0; i < lcl_len; i++) |
244
|
739 list[j++] = lcl[i]; |
1
|
740 |
|
741 for (i = 0; i < mfl_len; i++) |
244
|
742 list[j++] = mfl[i]; |
1
|
743 |
|
744 list[j] = (char *) NULL; |
|
745 |
|
746 delete [] key; |
|
747 delete [] glb; |
|
748 delete [] top; |
|
749 delete [] lcl; |
|
750 delete [] mfl; |
|
751 |
|
752 return list; |
|
753 } |
|
754 |
|
755 /* |
|
756 ;;; Local Variables: *** |
|
757 ;;; mode: C++ *** |
|
758 ;;; page-delimiter: "^/\\*" *** |
|
759 ;;; End: *** |
|
760 */ |