1
|
1 // variables.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 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 |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
1343
|
28 #include <cfloat> |
|
29 #include <cstring> |
605
|
30 |
1350
|
31 #include <strstream.h> |
|
32 |
|
33 #ifdef HAVE_UNISTD_H |
1
|
34 #include <sys/types.h> |
|
35 #include <unistd.h> |
|
36 #endif |
|
37 |
605
|
38 #include "defaults.h" |
1352
|
39 #include "defun.h" |
|
40 #include "dirfns.h" |
704
|
41 #include "dynamic-ld.h" |
1352
|
42 #include "error.h" |
|
43 #include "help.h" |
|
44 #include "input.h" |
|
45 #include "lex.h" |
|
46 #include "oct-obj.h" |
581
|
47 #include "octave-hist.h" |
529
|
48 #include "octave.h" |
605
|
49 #include "pager.h" |
1352
|
50 #include "parse.h" |
|
51 #include "statdefs.h" |
|
52 #include "symtab.h" |
|
53 #include "sysdep.h" |
|
54 #include "tree-base.h" |
|
55 #include "tree-const.h" |
|
56 #include "tree-expr.h" |
|
57 #include "unwind-prot.h" |
|
58 #include "user-prefs.h" |
1
|
59 #include "utils.h" |
1352
|
60 #include "variables.h" |
|
61 #include "version.h" |
529
|
62 |
|
63 extern "C" |
|
64 { |
581
|
65 #include <readline/readline.h> |
529
|
66 |
|
67 #include "fnmatch.h" |
|
68 } |
1
|
69 |
|
70 // Symbol table for symbols at the top level. |
581
|
71 symbol_table *top_level_sym_tab = 0; |
1
|
72 |
|
73 // Symbol table for the current scope. |
581
|
74 symbol_table *curr_sym_tab = 0; |
1
|
75 |
|
76 // Symbol table for global symbols. |
581
|
77 symbol_table *global_sym_tab = 0; |
1
|
78 |
593
|
79 // Initialization. |
|
80 |
|
81 // Create the initial symbol tables and set the current scope at the |
|
82 // top level. |
|
83 |
195
|
84 void |
|
85 initialize_symbol_tables (void) |
|
86 { |
581
|
87 if (! global_sym_tab) |
|
88 global_sym_tab = new symbol_table (); |
195
|
89 |
581
|
90 if (! top_level_sym_tab) |
|
91 top_level_sym_tab = new symbol_table (); |
195
|
92 |
|
93 curr_sym_tab = top_level_sym_tab; |
|
94 } |
|
95 |
593
|
96 // Attributes of variables and functions. |
|
97 |
|
98 // Is this variable a builtin? |
|
99 |
|
100 int |
|
101 is_builtin_variable (const char *name) |
|
102 { |
|
103 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
|
104 return (sr && sr->is_builtin_variable ()); |
|
105 } |
|
106 |
|
107 // Is this a text-style function? |
|
108 |
|
109 int |
|
110 is_text_function_name (const char *s) |
|
111 { |
|
112 symbol_record *sr = global_sym_tab->lookup (s); |
|
113 return (sr && sr->is_text_function ()); |
|
114 } |
|
115 |
|
116 // Is this function globally in this scope? |
|
117 |
605
|
118 int |
593
|
119 is_globally_visible (const char *name) |
|
120 { |
|
121 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); |
|
122 return (sr && sr->is_linked_to_global ()); |
|
123 } |
|
124 |
|
125 // Is this tree_constant a valid function? |
|
126 |
|
127 tree_fvc * |
|
128 is_valid_function (const tree_constant& arg, char *warn_for, int warn) |
|
129 { |
|
130 tree_fvc *ans = 0; |
|
131 |
1363
|
132 const char *fcn_name = arg.string_value (); |
636
|
133 |
|
134 if (error_state) |
593
|
135 { |
|
136 if (warn) |
|
137 error ("%s: expecting function name as argument", warn_for); |
|
138 return ans; |
|
139 } |
|
140 |
|
141 symbol_record *sr = 0; |
|
142 if (fcn_name) |
|
143 sr = lookup_by_name (fcn_name); |
|
144 |
|
145 if (sr) |
|
146 ans = sr->def (); |
|
147 |
|
148 if (! sr || ! ans || ! sr->is_function ()) |
|
149 { |
|
150 if (warn) |
|
151 error ("%s: the symbol `%s' is not valid as a function", |
|
152 warn_for, fcn_name); |
|
153 ans = 0; |
|
154 } |
|
155 |
|
156 return ans; |
|
157 } |
|
158 |
|
159 // Does this function take the right number of arguments? |
|
160 |
|
161 int |
|
162 takes_correct_nargs (tree_fvc *fcn, int expected_nargin, char *warn_for, |
|
163 int warn) |
|
164 { |
712
|
165 int nargin = fcn->max_expected_args (); |
|
166 int e_nargin = expected_nargin; |
593
|
167 if (nargin != e_nargin) |
|
168 { |
|
169 if (warn) |
1418
|
170 error ("%s: expecting function to take %d argument%s", |
593
|
171 warn_for, e_nargin, (e_nargin == 1 ? "" : "s")); |
|
172 return 0; |
|
173 } |
|
174 return 1; |
|
175 } |
|
176 |
712
|
177 DEFUN ("is_global", Fis_global, Sis_global, 1, 1, |
593
|
178 "is_global (X): return 1 if the string X names a global variable\n\ |
|
179 otherwise, return 0.") |
|
180 { |
|
181 Octave_object retval = 0.0; |
|
182 |
712
|
183 int nargin = args.length (); |
|
184 |
|
185 if (nargin != 1) |
593
|
186 { |
|
187 print_usage ("is_global"); |
|
188 return retval; |
|
189 } |
|
190 |
1363
|
191 const char *name = args(0).string_value (); |
593
|
192 |
636
|
193 if (error_state) |
|
194 { |
|
195 error ("is_global: expecting string argument"); |
|
196 return retval; |
|
197 } |
|
198 |
593
|
199 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); |
|
200 |
|
201 retval = (double) (sr && sr->is_linked_to_global ()); |
|
202 |
|
203 return retval; |
|
204 } |
|
205 |
712
|
206 DEFUN ("exist", Fexist, Sexist, 1, 1, |
593
|
207 "exist (NAME): check if variable or file exists\n\ |
|
208 \n\ |
|
209 return 0 if NAME is undefined, 1 if it is a variable, or 2 if it is\n\ |
1418
|
210 a function.") |
593
|
211 { |
|
212 Octave_object retval; |
|
213 |
712
|
214 int nargin = args.length (); |
|
215 |
|
216 if (nargin != 1) |
593
|
217 { |
|
218 print_usage ("exist"); |
|
219 return retval; |
|
220 } |
|
221 |
1277
|
222 char *name = strsave (args(0).string_value ()); |
593
|
223 |
636
|
224 if (error_state) |
|
225 { |
|
226 error ("exist: expecting string argument"); |
1277
|
227 delete [] name; |
636
|
228 return retval; |
|
229 } |
|
230 |
1277
|
231 char *struct_elts = strchr (name, '.'); |
|
232 if (struct_elts) |
|
233 { |
|
234 *struct_elts = '\0'; |
|
235 struct_elts++; |
|
236 } |
|
237 |
593
|
238 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); |
|
239 if (! sr) |
|
240 sr = global_sym_tab->lookup (name, 0, 0); |
|
241 |
|
242 retval = 0.0; |
|
243 |
|
244 if (sr && sr->is_variable () && sr->is_defined ()) |
1277
|
245 { |
|
246 retval = 1.0; |
|
247 tree_fvc *def = sr->def (); |
|
248 if (struct_elts) |
|
249 { |
|
250 retval = 0.0; |
|
251 if (def->is_constant ()) |
|
252 { |
|
253 tree_constant *tmp = (tree_constant *) def; |
|
254 tree_constant ult; |
|
255 ult = tmp->lookup_map_element (struct_elts, 0, 1); |
|
256 if (ult.is_defined ()) |
|
257 retval = 1.0; |
|
258 } |
|
259 } |
|
260 } |
1421
|
261 else if (sr && sr->is_builtin_function ()) |
|
262 { |
|
263 retval = 5.0; |
|
264 } |
|
265 else if (sr && sr->is_user_function ()) |
|
266 { |
|
267 retval = 2.0; |
|
268 } |
593
|
269 else |
|
270 { |
|
271 char *path = fcn_file_in_path (name); |
|
272 if (path) |
|
273 { |
|
274 delete [] path; |
|
275 retval = 2.0; |
|
276 } |
|
277 else |
|
278 { |
1421
|
279 path = oct_file_in_path (name); |
|
280 if (path) |
|
281 { |
|
282 delete [] path; |
|
283 retval = 3.0; |
|
284 } |
|
285 else |
|
286 { |
|
287 struct stat buf; |
|
288 if (stat (name, &buf) == 0 && S_ISREG (buf.st_mode)) |
|
289 retval = 2.0; |
|
290 } |
593
|
291 } |
|
292 } |
|
293 |
1277
|
294 delete [] name; |
|
295 |
593
|
296 return retval; |
|
297 } |
|
298 |
|
299 // XXX FIXME XXX -- should these really be here? |
|
300 |
|
301 static char * |
|
302 octave_home (void) |
|
303 { |
|
304 char *oh = getenv ("OCTAVE_HOME"); |
666
|
305 |
|
306 return (oh ? oh : OCTAVE_PREFIX); |
|
307 } |
|
308 |
|
309 static char * |
|
310 subst_octave_home (char *s) |
|
311 { |
|
312 char *home = octave_home (); |
|
313 char *prefix = OCTAVE_PREFIX; |
|
314 |
|
315 char *retval; |
|
316 |
|
317 if (strcmp (home, prefix) == 0) |
|
318 retval = strsave (s); |
593
|
319 else |
666
|
320 { |
|
321 int len_home = strlen (home); |
|
322 int len_prefix = strlen (prefix); |
|
323 |
|
324 int count = 0; |
|
325 char *ptr = s; |
811
|
326 char *next = 0; |
|
327 while ((next = strstr (ptr, prefix))) |
666
|
328 { |
811
|
329 ptr = next + len_prefix; |
666
|
330 count++; |
|
331 } |
|
332 |
|
333 int grow_size = count * (len_home - len_prefix); |
|
334 |
811
|
335 int len_s = strlen (s); |
|
336 |
|
337 int len_retval = len_s + count * grow_size; |
666
|
338 |
|
339 retval = new char [len_retval+1]; |
|
340 |
|
341 char *p1 = s; |
|
342 char *p2 = p1; |
|
343 char *pdest = retval; |
|
344 |
1271
|
345 // Is this really a good way to do this? |
811
|
346 |
|
347 while (count >= 0) |
666
|
348 { |
|
349 p2 = strstr (p1, prefix); |
1418
|
350 |
666
|
351 if (! p2) |
770
|
352 { |
811
|
353 memcpy (pdest, p1, strlen (p1)+1); |
|
354 break; |
770
|
355 } |
811
|
356 else if (p1 == p2) |
666
|
357 { |
|
358 memcpy (pdest, home, len_home); |
|
359 pdest += len_home; |
|
360 p1 += len_prefix; |
811
|
361 count--; |
666
|
362 } |
|
363 else |
|
364 { |
|
365 int len = (int) (p2 - p1); |
|
366 memcpy (pdest, p1, len); |
|
367 pdest += len; |
|
368 p1 += len; |
|
369 } |
|
370 |
|
371 } |
|
372 } |
|
373 |
|
374 return retval; |
593
|
375 } |
|
376 |
|
377 static char * |
|
378 octave_info_dir (void) |
|
379 { |
666
|
380 static char *retval = subst_octave_home (OCTAVE_INFODIR); |
|
381 return retval; |
|
382 } |
|
383 |
686
|
384 char * |
666
|
385 octave_arch_lib_dir (void) |
|
386 { |
|
387 static char *retval = subst_octave_home (OCTAVE_ARCHLIBDIR); |
|
388 return retval; |
593
|
389 } |
|
390 |
798
|
391 char * |
|
392 octave_bin_dir (void) |
|
393 { |
|
394 static char *retval = subst_octave_home (OCTAVE_BINDIR); |
|
395 return retval; |
|
396 } |
|
397 |
593
|
398 static char * |
|
399 default_pager (void) |
|
400 { |
|
401 static char *pager_binary = 0; |
|
402 delete [] pager_binary; |
|
403 char *pgr = getenv ("PAGER"); |
|
404 if (pgr) |
|
405 pager_binary = strsave (pgr); |
|
406 else |
|
407 #ifdef DEFAULT_PAGER |
|
408 pager_binary = strsave (DEFAULT_PAGER); |
|
409 #else |
|
410 pager_binary = strsave (""); |
|
411 #endif |
|
412 |
|
413 return pager_binary; |
|
414 } |
|
415 |
1121
|
416 // Always returns a new string. |
|
417 |
|
418 char * |
|
419 maybe_add_default_load_path (const char *p) |
|
420 { |
|
421 static char *std_path = subst_octave_home (OCTAVE_FCNFILEPATH); |
|
422 |
|
423 char *pathstring = strsave (p); |
|
424 |
|
425 if (pathstring[0] == SEPCHAR) |
|
426 { |
|
427 char *tmp = pathstring; |
|
428 pathstring = strconcat (std_path, pathstring); |
|
429 delete [] tmp; |
|
430 } |
|
431 |
|
432 int tmp_len = strlen (pathstring); |
|
433 if (pathstring[tmp_len-1] == SEPCHAR) |
|
434 { |
|
435 char *tmp = pathstring; |
|
436 pathstring = strconcat (pathstring, std_path); |
|
437 delete [] tmp; |
|
438 } |
|
439 |
|
440 return pathstring; |
|
441 } |
|
442 |
593
|
443 char * |
|
444 octave_lib_dir (void) |
|
445 { |
666
|
446 static char *retval = subst_octave_home (OCTAVE_LIBDIR); |
|
447 return retval; |
593
|
448 } |
|
449 |
|
450 // Handle OCTAVE_PATH from the environment like TeX handles TEXINPUTS. |
|
451 // If the path starts with `:', prepend the standard path. If it ends |
|
452 // with `:' append the standard path. If it begins and ends with |
|
453 // `:', do both (which is useless, but the luser asked for it...). |
|
454 // |
|
455 // This function may eventually be called more than once, so be |
1418
|
456 // careful not to create memory leaks. |
593
|
457 |
|
458 char * |
|
459 default_path (void) |
|
460 { |
1121
|
461 static char *std_path = subst_octave_home (OCTAVE_FCNFILEPATH); |
|
462 |
|
463 static char *oct_path = getenv ("OCTAVE_PATH"); |
|
464 |
593
|
465 static char *pathstring = 0; |
|
466 delete [] pathstring; |
|
467 |
1121
|
468 return oct_path ? strsave (oct_path) : strsave (std_path); |
593
|
469 } |
|
470 |
|
471 char * |
|
472 default_info_file (void) |
|
473 { |
|
474 static char *info_file_string = 0; |
|
475 delete [] info_file_string; |
|
476 char *oct_info_file = getenv ("OCTAVE_INFO_FILE"); |
|
477 if (oct_info_file) |
|
478 info_file_string = strsave (oct_info_file); |
|
479 else |
|
480 { |
|
481 char *infodir = octave_info_dir (); |
|
482 info_file_string = strconcat (infodir, "/octave.info"); |
|
483 } |
|
484 return info_file_string; |
|
485 } |
|
486 |
|
487 char * |
|
488 default_editor (void) |
|
489 { |
|
490 static char *editor_string = 0; |
|
491 delete [] editor_string; |
|
492 char *env_editor = getenv ("EDITOR"); |
|
493 if (env_editor && *env_editor) |
|
494 editor_string = strsave (env_editor); |
|
495 else |
|
496 editor_string = strsave ("vi"); |
|
497 return editor_string; |
|
498 } |
|
499 |
|
500 char * |
|
501 get_site_defaults (void) |
|
502 { |
731
|
503 static char *startupdir = subst_octave_home (OCTAVE_STARTUPFILEDIR); |
|
504 static char *sd = strconcat (startupdir, "/octaverc"); |
593
|
505 return sd; |
|
506 } |
|
507 |
|
508 // Functions for looking up variables and functions. |
|
509 |
581
|
510 // Is there a corresponding function file that is newer than the |
|
511 // symbol definition? |
|
512 |
593
|
513 static int |
1
|
514 symbol_out_of_date (symbol_record *sr) |
|
515 { |
195
|
516 int ignore = user_pref.ignore_function_time_stamp; |
|
517 |
|
518 if (ignore == 2) |
|
519 return 0; |
|
520 |
529
|
521 if (sr) |
1
|
522 { |
490
|
523 tree_fvc *ans = sr->def (); |
529
|
524 if (ans) |
1
|
525 { |
339
|
526 char *ff = ans->fcn_file_name (); |
529
|
527 if (ff && ! (ignore && ans->is_system_fcn_file ())) |
1
|
528 { |
|
529 time_t tp = ans->time_parsed (); |
339
|
530 char *fname = fcn_file_in_path (ff); |
195
|
531 int status = is_newer (fname, tp); |
|
532 delete [] fname; |
|
533 if (status > 0) |
|
534 return 1; |
1
|
535 } |
|
536 } |
|
537 } |
195
|
538 return 0; |
1
|
539 } |
|
540 |
991
|
541 static int |
|
542 looks_like_octave_copyright (char *s) |
|
543 { |
|
544 if (s && strncmp (s, " Copyright (C) ", 15) == 0) |
|
545 { |
|
546 s = strchr (s, '\n'); |
|
547 if (s) |
|
548 { |
|
549 s++; |
|
550 s = strchr (s, '\n'); |
|
551 if (s) |
|
552 { |
|
553 s++; |
|
554 if (strncmp (s, " This file is part of Octave.", 29) == 0) |
|
555 return 1; |
|
556 } |
|
557 } |
|
558 } |
|
559 return 0; |
|
560 } |
|
561 |
1419
|
562 // Eat whitespace and comments from FFILE, returning the text of the |
|
563 // comments read if it doesn't look like a copyright notice. If |
|
564 // IN_PARTS, consider each block of comments separately; otherwise, |
|
565 // grab them all at once. |
1418
|
566 |
991
|
567 static char * |
1419
|
568 gobble_leading_white_space (FILE *ffile, int in_parts) |
581
|
569 { |
991
|
570 ostrstream buf; |
|
571 |
|
572 int first_comments_seen = 0; |
|
573 int have_help_text = 0; |
581
|
574 int in_comment = 0; |
|
575 int c; |
|
576 while ((c = getc (ffile)) != EOF) |
|
577 { |
984
|
578 current_input_column++; |
581
|
579 if (in_comment) |
|
580 { |
991
|
581 if (! have_help_text) |
|
582 { |
|
583 first_comments_seen = 1; |
|
584 buf << (char) c; |
|
585 } |
|
586 |
581
|
587 if (c == '\n') |
984
|
588 { |
|
589 input_line_number++; |
|
590 current_input_column = 0; |
|
591 in_comment = 0; |
1419
|
592 if (in_parts) |
1418
|
593 { |
1419
|
594 if ((c = getc (ffile)) != EOF) |
|
595 { |
|
596 current_input_column--; |
|
597 ungetc (c, ffile); |
|
598 if (c == '\n') |
|
599 break; |
|
600 } |
|
601 else |
1418
|
602 break; |
|
603 } |
984
|
604 } |
581
|
605 } |
|
606 else |
|
607 { |
984
|
608 switch (c) |
581
|
609 { |
984
|
610 case ' ': |
|
611 case '\t': |
991
|
612 if (first_comments_seen) |
|
613 have_help_text = 1; |
984
|
614 break; |
|
615 |
|
616 case '\n': |
993
|
617 if (first_comments_seen) |
|
618 have_help_text = 1; |
984
|
619 input_line_number++; |
|
620 current_input_column = 0; |
|
621 continue; |
|
622 |
|
623 case '%': |
|
624 case '#': |
|
625 in_comment = 1; |
|
626 break; |
|
627 |
|
628 default: |
|
629 current_input_column--; |
581
|
630 ungetc (c, ffile); |
991
|
631 goto done; |
581
|
632 } |
|
633 } |
|
634 } |
991
|
635 |
|
636 done: |
|
637 |
|
638 buf << ends; |
|
639 char *help_txt = buf.str (); |
|
640 |
1419
|
641 if (help_txt) |
991
|
642 { |
1419
|
643 if (looks_like_octave_copyright (help_txt)) |
|
644 { |
|
645 delete [] help_txt; |
|
646 help_txt = 0; |
|
647 } |
|
648 |
|
649 if (in_parts && ! help_txt) |
|
650 help_txt = gobble_leading_white_space (ffile, in_parts); |
1418
|
651 } |
|
652 |
|
653 if (help_txt && ! *help_txt) |
|
654 { |
|
655 delete [] help_txt; |
991
|
656 help_txt = 0; |
|
657 } |
|
658 |
|
659 return help_txt; |
581
|
660 } |
|
661 |
|
662 static int |
|
663 is_function_file (FILE *ffile) |
|
664 { |
|
665 int status = 0; |
|
666 |
|
667 long pos = ftell (ffile); |
|
668 |
|
669 char buf [10]; |
|
670 fgets (buf, 10, ffile); |
|
671 int len = strlen (buf); |
|
672 if (len > 8 && strncmp (buf, "function", 8) == 0 |
|
673 && ! (isalnum (buf[8]) || buf[8] == '_')) |
|
674 status = 1; |
|
675 |
|
676 fseek (ffile, pos, SEEK_SET); |
|
677 |
|
678 return status; |
|
679 } |
|
680 |
|
681 static int |
|
682 parse_fcn_file (int exec_script, char *ff) |
|
683 { |
|
684 begin_unwind_frame ("parse_fcn_file"); |
|
685 |
|
686 int script_file_executed = 0; |
|
687 |
|
688 assert (ff); |
|
689 |
1358
|
690 // Open function file and parse. |
581
|
691 |
|
692 int old_reading_fcn_file_state = reading_fcn_file; |
|
693 |
|
694 unwind_protect_ptr (rl_instream); |
|
695 unwind_protect_ptr (ff_instream); |
|
696 |
|
697 unwind_protect_int (using_readline); |
|
698 unwind_protect_int (input_line_number); |
|
699 unwind_protect_int (current_input_column); |
|
700 unwind_protect_int (reading_fcn_file); |
|
701 |
|
702 using_readline = 0; |
|
703 reading_fcn_file = 1; |
|
704 input_line_number = 0; |
|
705 current_input_column = 1; |
|
706 |
|
707 FILE *ffile = get_input_from_file (ff, 0); |
|
708 |
|
709 if (ffile) |
|
710 { |
1271
|
711 // Check to see if this file defines a function or is just a |
|
712 // list of commands. |
581
|
713 |
1418
|
714 char *tmp_help_txt = gobble_leading_white_space (ffile, 0); |
991
|
715 |
581
|
716 if (is_function_file (ffile)) |
|
717 { |
|
718 unwind_protect_int (echo_input); |
|
719 unwind_protect_int (saving_history); |
|
720 unwind_protect_int (reading_fcn_file); |
|
721 |
|
722 echo_input = 0; |
|
723 saving_history = 0; |
|
724 reading_fcn_file = 1; |
|
725 |
|
726 YY_BUFFER_STATE old_buf = current_buffer (); |
|
727 YY_BUFFER_STATE new_buf = create_buffer (ffile); |
|
728 |
|
729 add_unwind_protect (restore_input_buffer, (void *) old_buf); |
|
730 add_unwind_protect (delete_input_buffer, (void *) new_buf); |
|
731 |
|
732 switch_to_buffer (new_buf); |
|
733 |
|
734 unwind_protect_ptr (curr_sym_tab); |
|
735 |
|
736 reset_parser (); |
|
737 |
991
|
738 delete [] help_buf; |
|
739 help_buf = tmp_help_txt; |
|
740 |
581
|
741 int status = yyparse (); |
|
742 |
|
743 if (status != 0) |
|
744 { |
|
745 error ("parse error while reading function file %s", ff); |
|
746 global_sym_tab->clear (curr_fcn_file_name); |
|
747 } |
|
748 } |
|
749 else if (exec_script) |
|
750 { |
1271
|
751 // We don't need this now. |
|
752 |
|
753 delete [] tmp_help_txt; |
|
754 |
|
755 // The value of `reading_fcn_file' will be restored to the |
|
756 // proper value when we unwind from this frame. |
|
757 |
581
|
758 reading_fcn_file = old_reading_fcn_file_state; |
|
759 |
|
760 unwind_protect_int (reading_script_file); |
|
761 reading_script_file = 1; |
|
762 |
|
763 parse_and_execute (ffile, 1); |
|
764 |
|
765 script_file_executed = 1; |
|
766 } |
|
767 fclose (ffile); |
|
768 } |
|
769 |
|
770 run_unwind_frame ("parse_fcn_file"); |
|
771 |
|
772 return script_file_executed; |
|
773 } |
|
774 |
593
|
775 static int |
581
|
776 load_fcn_from_file (symbol_record *sym_rec, int exec_script) |
|
777 { |
|
778 int script_file_executed = 0; |
|
779 |
|
780 char *nm = sym_rec->name (); |
|
781 |
1271
|
782 // This is needed by yyparse. |
704
|
783 |
581
|
784 curr_fcn_file_name = nm; |
|
785 |
704
|
786 #ifdef WITH_DLD |
581
|
787 |
704
|
788 if (load_octave_oct_file (nm)) |
|
789 { |
|
790 force_link_to_function (nm); |
|
791 } |
|
792 else |
581
|
793 |
704
|
794 #endif |
581
|
795 |
|
796 { |
704
|
797 char *ff = fcn_file_in_path (nm); |
581
|
798 |
|
799 if (ff) |
|
800 { |
|
801 script_file_executed = parse_fcn_file (exec_script, ff); |
|
802 delete [] ff; |
|
803 } |
|
804 |
|
805 if (! (error_state || script_file_executed)) |
|
806 force_link_to_function (nm); |
|
807 } |
|
808 |
|
809 return script_file_executed; |
|
810 } |
|
811 |
|
812 int |
|
813 lookup (symbol_record *sym_rec, int exec_script) |
|
814 { |
1271
|
815 int script_executed = 0; |
581
|
816 |
|
817 if (! sym_rec->is_linked_to_global ()) |
|
818 { |
|
819 if (sym_rec->is_defined ()) |
|
820 { |
|
821 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
822 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
823 } |
|
824 else if (! sym_rec->is_formal_parameter ()) |
|
825 { |
|
826 link_to_builtin_or_function (sym_rec); |
1271
|
827 |
581
|
828 if (! sym_rec->is_defined ()) |
1271
|
829 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
830 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
831 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
832 } |
|
833 } |
|
834 |
1271
|
835 return script_executed; |
581
|
836 } |
|
837 |
|
838 // Get the symbol record for the given name that is visible in the |
|
839 // current scope. Reread any function definitions that appear to be |
|
840 // out of date. If a function is available in a file but is not |
|
841 // currently loaded, this will load it and insert the name in the |
|
842 // current symbol table. |
|
843 |
|
844 symbol_record * |
|
845 lookup_by_name (const char *nm, int exec_script) |
|
846 { |
|
847 symbol_record *sym_rec = curr_sym_tab->lookup (nm, 1, 0); |
|
848 |
|
849 lookup (sym_rec, exec_script); |
|
850 |
|
851 return sym_rec; |
|
852 } |
|
853 |
991
|
854 char * |
993
|
855 get_help_from_file (const char *path) |
991
|
856 { |
|
857 if (path && *path) |
|
858 { |
|
859 FILE *fptr = fopen (path, "r"); |
|
860 if (fptr) |
|
861 { |
1418
|
862 char *help_txt = gobble_leading_white_space (fptr, 1); |
991
|
863 fclose (fptr); |
|
864 return help_txt; |
|
865 } |
|
866 } |
|
867 return 0; |
|
868 } |
|
869 |
593
|
870 // Variable values. |
195
|
871 |
581
|
872 // Look for the given name in the global symbol table. If it refers |
|
873 // to a string, return a new copy. If not, return 0; |
|
874 |
1
|
875 char * |
195
|
876 builtin_string_variable (const char *name) |
1
|
877 { |
195
|
878 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
|
879 |
1271
|
880 // It is a prorgramming error to look for builtins that aren't. |
195
|
881 |
529
|
882 assert (sr); |
195
|
883 |
529
|
884 char *retval = 0; |
1
|
885 |
490
|
886 tree_fvc *defn = sr->def (); |
195
|
887 |
529
|
888 if (defn) |
1
|
889 { |
|
890 tree_constant val = defn->eval (0); |
195
|
891 |
610
|
892 if (! error_state && val.is_string ()) |
1
|
893 { |
1363
|
894 const char *s = val.string_value (); |
636
|
895 |
529
|
896 if (s) |
1
|
897 retval = strsave (s); |
|
898 } |
|
899 } |
|
900 |
|
901 return retval; |
|
902 } |
|
903 |
581
|
904 // Look for the given name in the global symbol table. If it refers |
|
905 // to a real scalar, place the value in d and return 0. Otherwise, |
1418
|
906 // return -1. |
581
|
907 |
1
|
908 int |
195
|
909 builtin_real_scalar_variable (const char *name, double& d) |
1
|
910 { |
|
911 int status = -1; |
195
|
912 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
|
913 |
1271
|
914 // It is a prorgramming error to look for builtins that aren't. |
195
|
915 |
529
|
916 assert (sr); |
1
|
917 |
490
|
918 tree_fvc *defn = sr->def (); |
195
|
919 |
529
|
920 if (defn) |
1
|
921 { |
|
922 tree_constant val = defn->eval (0); |
195
|
923 |
598
|
924 if (! error_state && val.is_scalar_type ()) |
1
|
925 { |
|
926 d = val.double_value (); |
|
927 status = 0; |
|
928 } |
|
929 } |
|
930 |
|
931 return status; |
|
932 } |
|
933 |
1093
|
934 // Look for the given name in the global symbol table. |
|
935 |
|
936 tree_constant |
|
937 builtin_any_variable (const char *name) |
|
938 { |
|
939 tree_constant retval; |
|
940 |
|
941 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
|
942 |
1271
|
943 // It is a prorgramming error to look for builtins that aren't. |
1093
|
944 |
|
945 assert (sr); |
|
946 |
|
947 tree_fvc *defn = sr->def (); |
|
948 |
|
949 if (defn) |
|
950 retval = defn->eval (0); |
|
951 |
|
952 return retval; |
|
953 } |
|
954 |
593
|
955 // Global stuff and links to builtin variables and functions. |
|
956 |
581
|
957 // Make the definition of the symbol record sr be the same as the |
|
958 // definition of the global variable of the same name, creating it if |
1418
|
959 // it doesn't already exist. |
581
|
960 |
195
|
961 void |
|
962 link_to_global_variable (symbol_record *sr) |
|
963 { |
|
964 if (sr->is_linked_to_global ()) |
|
965 return; |
|
966 |
|
967 symbol_record *gsr = global_sym_tab->lookup (sr->name (), 1, 0); |
|
968 |
|
969 if (sr->is_formal_parameter ()) |
|
970 { |
|
971 error ("can't make function parameter `%s' global", sr->name ()); |
|
972 return; |
|
973 } |
|
974 |
1271
|
975 // There must be a better way to do this. XXX FIXME XXX |
195
|
976 |
|
977 if (sr->is_variable ()) |
|
978 { |
1271
|
979 // Would be nice not to have this cast. XXX FIXME XXX |
|
980 |
195
|
981 tree_constant *tmp = (tree_constant *) sr->def (); |
529
|
982 if (tmp) |
|
983 tmp = new tree_constant (*tmp); |
|
984 else |
207
|
985 tmp = new tree_constant (); |
195
|
986 gsr->define (tmp); |
|
987 } |
|
988 else |
529
|
989 sr->clear (); |
195
|
990 |
1271
|
991 // If the global symbol is currently defined as a function, we need |
|
992 // to hide it with a variable. |
195
|
993 |
|
994 if (gsr->is_function ()) |
529
|
995 gsr->define ((tree_constant *) 0); |
195
|
996 |
|
997 sr->alias (gsr, 1); |
|
998 sr->mark_as_linked_to_global (); |
|
999 } |
|
1000 |
581
|
1001 // Make the definition of the symbol record sr be the same as the |
|
1002 // definition of the builtin variable of the same name. |
|
1003 |
195
|
1004 void |
|
1005 link_to_builtin_variable (symbol_record *sr) |
|
1006 { |
|
1007 symbol_record *tmp_sym = global_sym_tab->lookup (sr->name (), 0, 0); |
|
1008 |
529
|
1009 if (tmp_sym && tmp_sym->is_builtin_variable ()) |
|
1010 sr->alias (tmp_sym); |
195
|
1011 } |
|
1012 |
581
|
1013 // Make the definition of the symbol record sr be the same as the |
|
1014 // definition of the builtin variable or function, or user function of |
|
1015 // the same name, provided that the name has not been used as a formal |
|
1016 // parameter. |
|
1017 |
195
|
1018 void |
|
1019 link_to_builtin_or_function (symbol_record *sr) |
|
1020 { |
|
1021 symbol_record *tmp_sym = global_sym_tab->lookup (sr->name (), 0, 0); |
|
1022 |
529
|
1023 if (tmp_sym |
|
1024 && (tmp_sym->is_builtin_variable () || tmp_sym->is_function ()) |
|
1025 && ! tmp_sym->is_formal_parameter ()) |
|
1026 sr->alias (tmp_sym); |
195
|
1027 } |
|
1028 |
581
|
1029 // Force a link to a function in the current symbol table. This is |
|
1030 // used just after defining a function to avoid different behavior |
|
1031 // depending on whether or not the function has been evaluated after |
|
1032 // being defined. |
|
1033 // |
|
1034 // Return without doing anything if there isn't a function with the |
|
1035 // given name defined in the global symbol table. |
|
1036 |
195
|
1037 void |
|
1038 force_link_to_function (const char *id_name) |
|
1039 { |
|
1040 symbol_record *gsr = global_sym_tab->lookup (id_name, 1, 0); |
|
1041 if (gsr->is_function ()) |
|
1042 { |
|
1043 curr_sym_tab->clear (id_name); |
|
1044 symbol_record *csr = curr_sym_tab->lookup (id_name, 1, 0); |
|
1045 csr->alias (gsr); |
|
1046 } |
|
1047 } |
|
1048 |
605
|
1049 // Help stuff. Shouldn't this go in help.cc? |
593
|
1050 |
|
1051 // It's not likely that this does the right thing now. XXX FIXME XXX |
|
1052 |
|
1053 char ** |
|
1054 make_name_list (void) |
|
1055 { |
|
1056 int key_len = 0; |
|
1057 int glb_len = 0; |
|
1058 int top_len = 0; |
|
1059 int lcl_len = 0; |
|
1060 int ffl_len = 0; |
|
1061 |
|
1062 char **key = 0; |
|
1063 char **glb = 0; |
|
1064 char **top = 0; |
|
1065 char **lcl = 0; |
|
1066 char **ffl = 0; |
|
1067 |
1271
|
1068 // Each of these functions returns a new vector of pointers to new |
|
1069 // strings. |
593
|
1070 |
|
1071 key = names (keyword_help (), key_len); |
|
1072 glb = global_sym_tab->list (glb_len); |
|
1073 top = top_level_sym_tab->list (top_len); |
|
1074 if (top_level_sym_tab != curr_sym_tab) |
|
1075 lcl = curr_sym_tab->list (lcl_len); |
|
1076 ffl = get_fcn_file_names (ffl_len, 1); |
|
1077 |
|
1078 int total_len = key_len + glb_len + top_len + lcl_len + ffl_len; |
|
1079 |
|
1080 char **list = new char * [total_len+1]; |
1418
|
1081 |
1271
|
1082 // Put all the symbols in one big list. Only copy pointers, not the |
|
1083 // strings they point to, then only delete the original array of |
|
1084 // pointers, and not the strings they point to. |
593
|
1085 |
|
1086 int j = 0; |
|
1087 int i = 0; |
|
1088 for (i = 0; i < key_len; i++) |
|
1089 list[j++] = key[i]; |
|
1090 |
|
1091 for (i = 0; i < glb_len; i++) |
|
1092 list[j++] = glb[i]; |
|
1093 |
|
1094 for (i = 0; i < top_len; i++) |
|
1095 list[j++] = top[i]; |
|
1096 |
|
1097 for (i = 0; i < lcl_len; i++) |
|
1098 list[j++] = lcl[i]; |
|
1099 |
|
1100 for (i = 0; i < ffl_len; i++) |
|
1101 list[j++] = ffl[i]; |
|
1102 |
|
1103 list[j] = 0; |
|
1104 |
|
1105 delete [] key; |
|
1106 delete [] glb; |
|
1107 delete [] top; |
|
1108 delete [] lcl; |
|
1109 delete [] ffl; |
|
1110 |
|
1111 return list; |
|
1112 } |
|
1113 |
|
1114 // List variable names. |
|
1115 |
|
1116 static void |
|
1117 print_symbol_info_line (ostrstream& output_buf, const symbol_record_info& s) |
|
1118 { |
|
1119 output_buf << (s.is_read_only () ? " -" : " w"); |
|
1120 output_buf << (s.is_eternal () ? "- " : "d "); |
|
1121 #if 0 |
|
1122 output_buf << (s.hides_fcn () ? "f" : (s.hides_builtin () ? "F" : "-")); |
|
1123 #endif |
|
1124 output_buf.form (" %-16s", s.type_as_string ()); |
|
1125 if (s.is_function ()) |
|
1126 output_buf << " - -"; |
|
1127 else |
|
1128 { |
|
1129 output_buf.form ("%7d", s.rows ()); |
|
1130 output_buf.form ("%7d", s.columns ()); |
|
1131 } |
|
1132 output_buf << " " << s.name () << "\n"; |
|
1133 } |
|
1134 |
|
1135 static void |
|
1136 print_long_listing (ostrstream& output_buf, symbol_record_info *s) |
|
1137 { |
|
1138 if (! s) |
|
1139 return; |
|
1140 |
|
1141 symbol_record_info *ptr = s; |
|
1142 while (ptr->is_defined ()) |
|
1143 { |
|
1144 print_symbol_info_line (output_buf, *ptr); |
|
1145 ptr++; |
|
1146 } |
|
1147 } |
|
1148 |
|
1149 static int |
867
|
1150 maybe_list (const char *header, char **argv, int argc, |
|
1151 ostrstream& output_buf, int show_verbose, symbol_table |
|
1152 *sym_tab, unsigned type, unsigned scope) |
593
|
1153 { |
|
1154 int count; |
|
1155 int status = 0; |
|
1156 if (show_verbose) |
|
1157 { |
|
1158 symbol_record_info *symbols; |
867
|
1159 symbols = sym_tab->long_list (count, argv, argc, 1, type, scope); |
593
|
1160 if (symbols && count > 0) |
|
1161 { |
|
1162 output_buf << "\n" << header << "\n\n" |
|
1163 << "prot type rows cols name\n" |
|
1164 << "==== ==== ==== ==== ====\n"; |
|
1165 |
|
1166 print_long_listing (output_buf, symbols); |
|
1167 status = 1; |
|
1168 } |
|
1169 delete [] symbols; |
|
1170 } |
|
1171 else |
|
1172 { |
867
|
1173 char **symbols = sym_tab->list (count, argv, argc, 1, type, scope); |
593
|
1174 if (symbols && count > 0) |
|
1175 { |
|
1176 output_buf << "\n" << header << "\n\n"; |
|
1177 list_in_columns (output_buf, symbols); |
|
1178 status = 1; |
|
1179 } |
|
1180 delete [] symbols; |
|
1181 } |
|
1182 return status; |
|
1183 } |
|
1184 |
|
1185 DEFUN_TEXT ("document", Fdocument, Sdocument, -1, 1, |
|
1186 "document symbol string ...\n\ |
|
1187 \n\ |
|
1188 Associate a cryptic message with a variable name.") |
|
1189 { |
|
1190 Octave_object retval; |
|
1191 |
|
1192 DEFINE_ARGV("document"); |
|
1193 |
|
1194 if (argc == 3) |
|
1195 { |
|
1196 char *name = argv[1]; |
|
1197 char *help = argv[2]; |
|
1198 |
|
1199 if (is_builtin_variable (name)) |
|
1200 error ("sorry, can't redefine help for builtin variables"); |
|
1201 else |
|
1202 { |
|
1203 symbol_record *sym_rec = curr_sym_tab->lookup (name, 0); |
|
1204 |
|
1205 if (sym_rec) |
|
1206 sym_rec->document (help); |
|
1207 else |
|
1208 error ("document: no such symbol `%s'", name); |
|
1209 } |
|
1210 } |
|
1211 else |
|
1212 print_usage ("document"); |
|
1213 |
|
1214 DELETE_ARGV; |
|
1215 |
|
1216 return retval; |
|
1217 } |
|
1218 |
584
|
1219 // XXX FIXME XXX -- this should take a list of regular expressions |
|
1220 // naming the variables to look for. |
|
1221 |
581
|
1222 static Octave_object |
|
1223 do_who (int argc, char **argv, int nargout) |
529
|
1224 { |
|
1225 Octave_object retval; |
|
1226 |
|
1227 int show_builtins = 0; |
|
1228 int show_functions = (curr_sym_tab == top_level_sym_tab); |
|
1229 int show_variables = 1; |
|
1230 int show_verbose = 0; |
|
1231 |
584
|
1232 char *my_name = argv[0]; |
|
1233 |
529
|
1234 if (argc > 1) |
|
1235 { |
|
1236 show_functions = 0; |
|
1237 show_variables = 0; |
|
1238 } |
|
1239 |
867
|
1240 while (--argc > 0) |
529
|
1241 { |
|
1242 argv++; |
867
|
1243 |
529
|
1244 if (strcmp (*argv, "-all") == 0 || strcmp (*argv, "-a") == 0) |
|
1245 { |
|
1246 show_builtins++; |
|
1247 show_functions++; |
1418
|
1248 show_variables++; |
529
|
1249 } |
605
|
1250 else if (strcmp (*argv, "-builtins") == 0 || strcmp (*argv, "-b") == 0) |
529
|
1251 show_builtins++; |
605
|
1252 else if (strcmp (*argv, "-functions") == 0 || strcmp (*argv, "-f") == 0) |
529
|
1253 show_functions++; |
605
|
1254 else if (strcmp (*argv, "-long") == 0 || strcmp (*argv, "-l") == 0) |
|
1255 show_verbose++; |
|
1256 else if (strcmp (*argv, "-variables") == 0 || strcmp (*argv, "-v") == 0) |
529
|
1257 show_variables++; |
867
|
1258 else if (*argv[0] == '-') |
|
1259 warning ("%s: unrecognized option `%s'", my_name, *argv); |
529
|
1260 else |
867
|
1261 break; |
529
|
1262 } |
|
1263 |
1271
|
1264 // If the user specified -l and nothing else, show variables. If |
|
1265 // evaluating this at the top level, also show functions. |
529
|
1266 |
|
1267 if (show_verbose && ! (show_builtins || show_functions || show_variables)) |
|
1268 { |
|
1269 show_functions = (curr_sym_tab == top_level_sym_tab); |
|
1270 show_variables = 1; |
|
1271 } |
|
1272 |
|
1273 ostrstream output_buf; |
|
1274 int pad_after = 0; |
|
1275 |
|
1276 if (show_builtins) |
|
1277 { |
867
|
1278 pad_after += maybe_list ("*** built-in variables:", argv, argc, |
529
|
1279 output_buf, show_verbose, global_sym_tab, |
|
1280 symbol_def::BUILTIN_VARIABLE, |
|
1281 SYMTAB_ALL_SCOPES); |
|
1282 |
867
|
1283 pad_after += maybe_list ("*** built-in functions:", argv, argc, |
529
|
1284 output_buf, show_verbose, global_sym_tab, |
|
1285 symbol_def::BUILTIN_FUNCTION, |
|
1286 SYMTAB_ALL_SCOPES); |
|
1287 } |
|
1288 |
|
1289 if (show_functions) |
|
1290 { |
|
1291 pad_after += maybe_list ("*** currently compiled functions:", |
867
|
1292 argv, argc, output_buf, show_verbose, |
|
1293 global_sym_tab, symbol_def::USER_FUNCTION, |
529
|
1294 SYMTAB_ALL_SCOPES); |
|
1295 } |
|
1296 |
|
1297 if (show_variables) |
|
1298 { |
867
|
1299 pad_after += maybe_list ("*** local user variables:", argv, argc, |
529
|
1300 output_buf, show_verbose, curr_sym_tab, |
|
1301 symbol_def::USER_VARIABLE, |
1418
|
1302 SYMTAB_LOCAL_SCOPE); |
529
|
1303 |
|
1304 pad_after += maybe_list ("*** globally visible user variables:", |
867
|
1305 argv, argc, output_buf, show_verbose, |
|
1306 curr_sym_tab, symbol_def::USER_VARIABLE, |
529
|
1307 SYMTAB_GLOBAL_SCOPE); |
|
1308 } |
|
1309 |
|
1310 if (pad_after) |
|
1311 output_buf << "\n"; |
|
1312 |
|
1313 output_buf << ends; |
|
1314 maybe_page_output (output_buf); |
|
1315 |
581
|
1316 return retval; |
|
1317 } |
|
1318 |
|
1319 DEFUN_TEXT ("who", Fwho, Swho, -1, 1, |
|
1320 "who [-all] [-builtins] [-functions] [-long] [-variables]\n\ |
|
1321 \n\ |
|
1322 List currently defined symbol(s). Options may be shortened to one\n\ |
|
1323 character, but may not be combined.") |
|
1324 { |
|
1325 Octave_object retval; |
|
1326 |
|
1327 DEFINE_ARGV("who"); |
|
1328 |
|
1329 retval = do_who (argc, argv, nargout); |
|
1330 |
529
|
1331 DELETE_ARGV; |
|
1332 |
|
1333 return retval; |
|
1334 } |
|
1335 |
581
|
1336 DEFUN_TEXT ("whos", Fwhos, Swhos, -1, 1, |
|
1337 "whos [-all] [-builtins] [-functions] [-long] [-variables]\n\ |
|
1338 \n\ |
|
1339 List currently defined symbol(s). Options may be shortened to one\n\ |
|
1340 character, but may not be combined.") |
|
1341 { |
|
1342 Octave_object retval; |
|
1343 |
712
|
1344 int nargin = args.length (); |
|
1345 |
742
|
1346 Octave_object tmp_args; |
|
1347 for (int i = nargin; i > 0; i--) |
|
1348 tmp_args(i) = args(i-1); |
|
1349 tmp_args(0) = "-long"; |
581
|
1350 |
742
|
1351 int argc = tmp_args.length () + 1; |
581
|
1352 char **argv = make_argv (tmp_args, "whos"); |
|
1353 |
|
1354 if (error_state) |
|
1355 return retval; |
|
1356 |
|
1357 retval = do_who (argc, argv, nargout); |
|
1358 |
|
1359 while (--argc >= 0) |
|
1360 delete [] argv[argc]; |
|
1361 delete [] argv; |
|
1362 |
|
1363 return retval; |
|
1364 } |
|
1365 |
593
|
1366 // Install variables and functions in the symbol tables. |
529
|
1367 |
593
|
1368 void |
|
1369 install_builtin_mapper (builtin_mapper_function *mf) |
529
|
1370 { |
593
|
1371 symbol_record *sym_rec = global_sym_tab->lookup (mf->name, 1); |
|
1372 sym_rec->unprotect (); |
|
1373 |
|
1374 Mapper_fcn mfcn; |
628
|
1375 mfcn.name = strsave (mf->name); |
593
|
1376 mfcn.can_return_complex_for_real_arg = mf->can_return_complex_for_real_arg; |
|
1377 mfcn.lower_limit = mf->lower_limit; |
|
1378 mfcn.upper_limit = mf->upper_limit; |
|
1379 mfcn.d_d_mapper = mf->d_d_mapper; |
|
1380 mfcn.d_c_mapper = mf->d_c_mapper; |
|
1381 mfcn.c_c_mapper = mf->c_c_mapper; |
|
1382 |
722
|
1383 tree_builtin *def = new tree_builtin (1, 1, mfcn, mf->name); |
593
|
1384 |
|
1385 sym_rec->define (def); |
|
1386 |
|
1387 sym_rec->document (mf->help_string); |
|
1388 sym_rec->make_eternal (); |
|
1389 sym_rec->protect (); |
|
1390 } |
|
1391 |
|
1392 void |
|
1393 install_builtin_function (builtin_function *f) |
|
1394 { |
|
1395 symbol_record *sym_rec = global_sym_tab->lookup (f->name, 1); |
|
1396 sym_rec->unprotect (); |
|
1397 |
|
1398 tree_builtin *def = new tree_builtin (f->nargin_max, f->nargout_max, |
|
1399 f->fcn, f->name); |
|
1400 |
|
1401 sym_rec->define (def, f->is_text_fcn); |
|
1402 |
|
1403 sym_rec->document (f->help_string); |
|
1404 sym_rec->make_eternal (); |
|
1405 sym_rec->protect (); |
|
1406 } |
|
1407 |
|
1408 void |
|
1409 install_builtin_variable (builtin_variable *v) |
|
1410 { |
|
1411 if (v->install_as_function) |
|
1412 install_builtin_variable_as_function (v->name, v->value, v->protect, |
|
1413 v->eternal, v->help_string); |
529
|
1414 else |
593
|
1415 bind_builtin_variable (v->name, v->value, v->protect, v->eternal, |
|
1416 v->sv_function, v->help_string); |
529
|
1417 } |
|
1418 |
593
|
1419 void |
|
1420 install_builtin_variable_as_function (const char *name, tree_constant *val, |
|
1421 int protect, int eternal, |
|
1422 const char *help) |
529
|
1423 { |
593
|
1424 symbol_record *sym_rec = global_sym_tab->lookup (name, 1); |
|
1425 sym_rec->unprotect (); |
|
1426 |
|
1427 const char *tmp_help = help; |
|
1428 if (! help) |
|
1429 tmp_help = sym_rec->help (); |
|
1430 |
|
1431 sym_rec->define_as_fcn (val); |
|
1432 |
|
1433 sym_rec->document (tmp_help); |
|
1434 |
|
1435 if (protect) |
|
1436 sym_rec->protect (); |
|
1437 |
|
1438 if (eternal) |
|
1439 sym_rec->make_eternal (); |
|
1440 } |
|
1441 |
|
1442 void |
|
1443 alias_builtin (const char *alias, const char *name) |
|
1444 { |
|
1445 symbol_record *sr_name = global_sym_tab->lookup (name, 0, 0); |
|
1446 if (! sr_name) |
|
1447 panic ("can't alias to undefined name!"); |
|
1448 |
|
1449 symbol_record *sr_alias = global_sym_tab->lookup (alias, 1, 0); |
|
1450 |
|
1451 if (sr_alias) |
|
1452 sr_alias->alias (sr_name); |
|
1453 else |
770
|
1454 panic ("can't find symbol record for builtin function `%s'", alias); |
529
|
1455 } |
|
1456 |
593
|
1457 // Defining variables. |
|
1458 |
1161
|
1459 #if 0 |
593
|
1460 void |
|
1461 bind_nargin_and_nargout (symbol_table *sym_tab, int nargin, int nargout) |
529
|
1462 { |
593
|
1463 tree_constant *tmp; |
|
1464 symbol_record *sr; |
|
1465 |
|
1466 sr = sym_tab->lookup ("nargin", 1, 0); |
|
1467 sr->unprotect (); |
712
|
1468 tmp = new tree_constant (nargin); |
593
|
1469 sr->define (tmp); |
|
1470 |
|
1471 sr = sym_tab->lookup ("nargout", 1, 0); |
|
1472 sr->unprotect (); |
|
1473 tmp = new tree_constant (nargout); |
|
1474 sr->define (tmp); |
|
1475 } |
1161
|
1476 #endif |
593
|
1477 |
1162
|
1478 void |
|
1479 bind_ans (const tree_constant& val, int print) |
|
1480 { |
|
1481 static symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); |
|
1482 |
1281
|
1483 tree_identifier *ans_id = new tree_identifier (sr); |
1162
|
1484 tree_constant *tmp = new tree_constant (val); |
|
1485 |
1281
|
1486 // XXX FIXME XXX -- making ans_id static, passing its address to |
|
1487 // tree_simple_assignment_expression along with a flag to not delete |
|
1488 // it seems to create a memory leak. Hmm. |
|
1489 |
|
1490 tree_simple_assignment_expression tmp_ass (ans_id, tmp, 0, 1); |
1162
|
1491 |
|
1492 tmp_ass.eval (print); |
|
1493 } |
|
1494 |
593
|
1495 // Give a global variable a definition. This will insert the symbol |
|
1496 // in the global table if necessary. |
|
1497 |
|
1498 // How is this different than install_builtin_variable? Are both |
|
1499 // functions needed? |
|
1500 |
|
1501 void |
|
1502 bind_builtin_variable (const char *varname, tree_constant *val, |
|
1503 int protect, int eternal, sv_Function sv_fcn, |
|
1504 const char *help) |
|
1505 { |
|
1506 symbol_record *sr = global_sym_tab->lookup (varname, 1, 0); |
|
1507 |
1271
|
1508 // It is a programming error for a builtin symbol to be missing. |
|
1509 // Besides, we just inserted it, so it must be there. |
593
|
1510 |
|
1511 assert (sr); |
|
1512 |
|
1513 sr->unprotect (); |
|
1514 |
1271
|
1515 // Must do this before define, since define will call the special |
|
1516 // variable function only if it knows about it, and it needs to, so |
|
1517 // that user prefs can be properly initialized. |
593
|
1518 |
|
1519 if (sv_fcn) |
|
1520 sr->set_sv_function (sv_fcn); |
|
1521 |
|
1522 sr->define_builtin_var (val); |
|
1523 |
|
1524 if (protect) |
|
1525 sr->protect (); |
|
1526 |
|
1527 if (eternal) |
|
1528 sr->make_eternal (); |
|
1529 |
|
1530 if (help) |
1418
|
1531 sr->document (help); |
529
|
1532 } |
|
1533 |
593
|
1534 void |
1406
|
1535 bind_builtin_variable (const char *varname, const tree_constant& val, |
|
1536 int protect, int eternal, sv_Function sv_fcn, |
|
1537 const char *help) |
|
1538 { |
|
1539 tree_constant *tc = new tree_constant (val); |
|
1540 bind_builtin_variable (varname, tc, protect, eternal, sv_fcn, help); |
|
1541 } |
|
1542 |
|
1543 void |
593
|
1544 install_builtin_variables (void) |
529
|
1545 { |
1271
|
1546 // XXX FIXME XX -- these should probably be moved to where they |
|
1547 // logically belong instead of being all grouped here. |
593
|
1548 |
1418
|
1549 DEFVAR ("EDITOR", SBV_EDITOR, editor, 0, sv_editor, |
593
|
1550 "name of the editor to be invoked by the edit_history command"); |
|
1551 |
1418
|
1552 DEFCONST ("I", SBV_I, Complex (0.0, 1.0), 0, 0, |
593
|
1553 "sqrt (-1)"); |
|
1554 |
1418
|
1555 DEFCONST ("Inf", SBV_Inf, octave_Inf, 0, 0, |
593
|
1556 "infinity"); |
|
1557 |
1418
|
1558 DEFVAR ("INFO_FILE", SBV_INFO_FILE, info_file, 0, sv_info_file, |
593
|
1559 "name of the Octave info file"); |
|
1560 |
1418
|
1561 DEFCONST ("J", SBV_J, Complex (0.0, 1.0), 0, 0, |
593
|
1562 "sqrt (-1)"); |
529
|
1563 |
1418
|
1564 DEFCONST ("NaN", SBV_NaN, octave_NaN, 0, 0, |
593
|
1565 "not a number"); |
|
1566 |
1418
|
1567 DEFVAR ("LOADPATH", SBV_LOADPATH, load_path, 0, sv_loadpath, |
593
|
1568 "colon separated list of directories to search for scripts"); |
|
1569 |
1418
|
1570 DEFVAR ("IMAGEPATH", SBV_IMAGEPATH, OCTAVE_IMAGEPATH, 0, |
686
|
1571 sv_imagepath, |
|
1572 "colon separated list of directories to search for image files"); |
|
1573 |
1418
|
1574 DEFCONST ("OCTAVE_VERSION", SBV_version, OCTAVE_VERSION, 0, 0, |
664
|
1575 "Octave version"); |
|
1576 |
1418
|
1577 DEFVAR ("PAGER", SBV_PAGER, default_pager (), 0, sv_pager_binary, |
593
|
1578 "path to pager binary"); |
|
1579 |
1418
|
1580 DEFVAR ("PS1", SBV_PS1, "\\s:\\#> ", 0, sv_ps1, |
593
|
1581 "primary prompt string"); |
|
1582 |
1418
|
1583 DEFVAR ("PS2", SBV_PS2, "> ", 0, sv_ps2, |
593
|
1584 "secondary prompt string"); |
|
1585 |
1418
|
1586 DEFVAR ("PS4", SBV_PS4, "+ ", 0, sv_ps4, |
1044
|
1587 "string printed before echoed input (enabled by --echo-input)"); |
|
1588 |
1418
|
1589 DEFCONST ("PWD", SBV_PWD, |
|
1590 get_working_directory ("initialize_globals"), 0, sv_pwd, |
593
|
1591 "current working directory"); |
|
1592 |
1418
|
1593 DEFCONST ("SEEK_SET", SBV_SEEK_SET, 0.0, 0, 0, |
593
|
1594 "used with fseek to position file relative to the beginning"); |
529
|
1595 |
1418
|
1596 DEFCONST ("SEEK_CUR", SBV_SEEK_CUR, 1.0, 0, 0, |
593
|
1597 "used with fseek to position file relative to the current position"); |
|
1598 |
1418
|
1599 DEFCONST ("SEEK_END", SBV_SEEK_END, 2.0, 0, 0, |
593
|
1600 "used with fseek to position file relative to the end"); |
|
1601 |
1418
|
1602 DEFVAR ("ans", SBV_ans, , 0, 0, |
593
|
1603 ""); |
|
1604 |
1418
|
1605 DEFCONST ("argv", SBV_argv, , 0, 0, |
1343
|
1606 "the command line arguments this program was invoked with"); |
|
1607 |
661
|
1608 DEFVAR ("automatic_replot", SBV_automatic_replot, "false", |
1418
|
1609 0, automatic_replot, |
661
|
1610 "if true, auto-insert a replot command when a plot changes"); |
|
1611 |
1423
|
1612 DEFVAR ("beep_on_error", SBV_beep_on_error, "false", 0, |
|
1613 beep_on_error, |
|
1614 "if true, beep before printing error messages"); |
|
1615 |
1429
|
1616 DEFVAR ("completion_append_char", SBV_completion_append_char, " ", |
|
1617 0, sv_completion_append_char, |
|
1618 "the string to append after successful command-line completion\n\ |
|
1619 attempts"); |
|
1620 |
1093
|
1621 DEFVAR ("default_return_value", SBV_default_return_value, Matrix (), |
1418
|
1622 0, 0, |
1093
|
1623 "the default for value for unitialized variables returned from\n\ |
|
1624 functions. Only used if the variable initialize_return_values is\n\ |
|
1625 set to \"true\"."); |
593
|
1626 |
605
|
1627 DEFVAR ("default_save_format", SBV_default_save_format, "ascii", |
1418
|
1628 0, sv_default_save_format, |
997
|
1629 "default format for files created with save, may be one of\n\ |
1418
|
1630 \"binary\", \"text\", or \"mat-binary\""); |
605
|
1631 |
1407
|
1632 DEFVAR ("define_all_return_values", SBV_define_all_return_values, |
1418
|
1633 "false", 0, define_all_return_values, |
1407
|
1634 "control whether values returned from functions should have a\n\ |
|
1635 value even if one has not been explicitly assigned. See also\n\ |
1418
|
1636 default_return_value"); |
1407
|
1637 |
1418
|
1638 DEFVAR ("do_fortran_indexing", SBV_do_fortran_indexing, "false", 0, |
|
1639 do_fortran_indexing, |
593
|
1640 "allow single indices for matrices"); |
|
1641 |
1418
|
1642 DEFVAR ("empty_list_elements_ok", SBV_empty_list_elements_ok, |
|
1643 "warn", 0, empty_list_elements_ok, |
593
|
1644 "ignore the empty element in expressions like `a = [[], 1]'"); |
529
|
1645 |
1418
|
1646 DEFCONST ("eps", SBV_eps, DBL_EPSILON, 0, 0, |
593
|
1647 "machine precision"); |
|
1648 |
1418
|
1649 DEFVAR ("gnuplot_binary", SBV_gnuplot_binary, "gnuplot", 0, |
593
|
1650 sv_gnuplot_binary, |
|
1651 "path to gnuplot binary"); |
|
1652 |
1418
|
1653 DEFCONST ("i", SBV_i, Complex (0.0, 1.0), 1, 0, |
593
|
1654 "sqrt (-1)"); |
529
|
1655 |
1418
|
1656 DEFVAR ("ignore_function_time_stamp", |
|
1657 SBV_ignore_function_time_stamp, "system", 0, |
593
|
1658 ignore_function_time_stamp, |
|
1659 "don't check to see if function files have changed since they were\n\ |
|
1660 last compiled. Possible values are \"system\" and \"all\""); |
|
1661 |
1418
|
1662 DEFVAR ("implicit_str_to_num_ok", SBV_implicit_str_to_num_ok, |
|
1663 "false", 0, implicit_str_to_num_ok, |
593
|
1664 "allow implicit string to number conversion"); |
|
1665 |
1418
|
1666 DEFCONST ("inf", SBV_inf, octave_Inf, 0, 0, |
593
|
1667 "infinity"); |
|
1668 |
1418
|
1669 DEFCONST ("j", SBV_j, Complex (0.0, 1.0), 1, 0, |
593
|
1670 "sqrt (-1)"); |
529
|
1671 |
1418
|
1672 DEFCONST ("nan", SBV_nan, octave_NaN, 0, 0, |
593
|
1673 "not a number"); |
|
1674 |
|
1675 DEFVAR ("ok_to_lose_imaginary_part", SBV_ok_to_lose_imaginary_part, |
1418
|
1676 "warn", 0, ok_to_lose_imaginary_part, |
593
|
1677 "silently convert from complex to real by dropping imaginary part"); |
|
1678 |
1418
|
1679 DEFVAR ("output_max_field_width", SBV_output_max_field_width, 10.0, |
|
1680 0, set_output_max_field_width, |
593
|
1681 "maximum width of an output field for numeric output"); |
|
1682 |
1418
|
1683 DEFVAR ("output_precision", SBV_output_precision, 5.0, 0, |
593
|
1684 set_output_precision, |
|
1685 "number of significant figures to display for numeric output"); |
|
1686 |
1418
|
1687 DEFVAR ("page_screen_output", SBV_page_screen_output, "true", 0, |
593
|
1688 page_screen_output, |
|
1689 "if possible, send output intended for the screen through the pager"); |
529
|
1690 |
1418
|
1691 DEFCONST ("pi", SBV_pi, 4.0 * atan (1.0), 0, 0, |
593
|
1692 "ratio of the circumference of a circle to its diameter"); |
|
1693 |
1418
|
1694 DEFVAR ("prefer_column_vectors", SBV_prefer_column_vectors, "true", |
|
1695 0, prefer_column_vectors, |
593
|
1696 "prefer column/row vectors"); |
|
1697 |
|
1698 DEFVAR ("prefer_zero_one_indexing", SBV_prefer_zero_one_indexing, |
1418
|
1699 "false", 0, prefer_zero_one_indexing, |
593
|
1700 "when there is a conflict, prefer zero-one style indexing"); |
|
1701 |
|
1702 DEFVAR ("print_answer_id_name", SBV_print_answer_id_name, "true", 0, |
1418
|
1703 print_answer_id_name, |
593
|
1704 "set output style to print `var_name = ...'"); |
|
1705 |
1418
|
1706 DEFVAR ("print_empty_dimensions", SBV_print_empty_dimensions, |
|
1707 "true", 0, print_empty_dimensions, |
593
|
1708 "also print dimensions of empty matrices"); |
|
1709 |
1418
|
1710 DEFCONST ("program_invocation_name", SBV_program_invocation_name, |
|
1711 raw_prog_name, 0, 0, |
1343
|
1712 "the full name of the current program or script, including the\n\ |
|
1713 directory specification"); |
|
1714 |
1418
|
1715 DEFCONST ("program_name", SBV_program_name, prog_name, 0, 0, |
1343
|
1716 "the name of the current program or script"); |
|
1717 |
593
|
1718 DEFVAR ("propagate_empty_matrices", SBV_propagate_empty_matrices, |
1418
|
1719 "true", 0, propagate_empty_matrices, |
593
|
1720 "operations on empty matrices return an empty matrix, not an error"); |
529
|
1721 |
1045
|
1722 #if 0 |
|
1723 DEFVAR ("read_only_constants", SBV_read_only_constants, "true", 0, |
1418
|
1724 read_only_constants, |
1045
|
1725 "allow built-in constants to be modified"); |
|
1726 #endif |
|
1727 |
1418
|
1728 DEFCONST ("realmax", SBV_realmax, DBL_MAX, 0, 0, |
868
|
1729 "realmax (): return largest representable floating point number"); |
|
1730 |
1418
|
1731 DEFCONST ("realmin", SBV_realmin, DBL_MIN, 0, 0, |
868
|
1732 "realmin (): return smallest representable floating point number"); |
|
1733 |
1418
|
1734 DEFVAR ("resize_on_range_error", SBV_resize_on_range_error, "true", |
|
1735 0, resize_on_range_error, |
593
|
1736 "enlarge matrices on assignment"); |
|
1737 |
1418
|
1738 DEFVAR ("return_last_computed_value", |
|
1739 SBV_return_last_computed_value, "false", 0, |
593
|
1740 return_last_computed_value, |
|
1741 "if a function does not return any values explicitly, return the\n\ |
|
1742 last computed value"); |
|
1743 |
1418
|
1744 DEFVAR ("save_precision", SBV_save_precision, 17.0, 0, |
593
|
1745 set_save_precision, |
|
1746 "number of significant figures kept by the ASCII save command"); |
|
1747 |
1418
|
1748 DEFVAR ("silent_functions", SBV_silent_functions, "false", 0, |
593
|
1749 silent_functions, |
|
1750 "suppress printing results in called functions"); |
|
1751 |
1418
|
1752 DEFVAR ("split_long_rows", SBV_split_long_rows, "true", 0, |
593
|
1753 split_long_rows, |
|
1754 "split long matrix rows instead of wrapping"); |
529
|
1755 |
1198
|
1756 DEFVAR ("struct_levels_to_print", SBV_struct_levels_to_print, 2.0, |
1418
|
1757 0, struct_levels_to_print, |
1198
|
1758 "number of levels of structure elements to print"); |
|
1759 |
1139
|
1760 #ifdef USE_GNU_INFO |
1116
|
1761 DEFVAR ("suppress_verbose_help_message", |
1418
|
1762 SBV_suppress_verbose_help_message, "false", 0, |
1116
|
1763 suppress_verbose_help_message, |
|
1764 "suppress printing of message pointing to additional help in the\n\ |
|
1765 help and usage functions"); |
1139
|
1766 #endif |
1116
|
1767 |
1418
|
1768 DEFCONST ("stdin", SBV_stdin, 0.0, 0, 0, |
593
|
1769 "file number of the standard input stream"); |
|
1770 |
1418
|
1771 DEFCONST ("stdout", SBV_stdout, 1.0, 0, 0, |
593
|
1772 "file number of the standard output stream"); |
|
1773 |
1418
|
1774 DEFCONST ("stderr", SBV_stderr, 2.0, 0, 0, |
593
|
1775 "file number of the standard error stream"); |
|
1776 |
|
1777 DEFVAR ("treat_neg_dim_as_zero", SBV_treat_neg_dim_as_zero, "false", |
1418
|
1778 0, treat_neg_dim_as_zero, |
593
|
1779 "convert negative dimensions to zero"); |
|
1780 |
1418
|
1781 DEFVAR ("warn_assign_as_truth_value", |
|
1782 SBV_warn_assign_as_truth_value, "true", 0, |
593
|
1783 warn_assign_as_truth_value, |
|
1784 "produce warning for assignments used as truth values"); |
|
1785 |
|
1786 DEFVAR ("warn_comma_in_global_decl", SBV_warn_comma_in_global_decl, |
1418
|
1787 "true", 0, warn_comma_in_global_decl, |
593
|
1788 "produce warning for commas in global declarations"); |
|
1789 |
1418
|
1790 DEFVAR ("warn_divide_by_zero", SBV_warn_divide_by_zero, "true", 0, |
|
1791 warn_divide_by_zero, |
593
|
1792 "on IEEE machines, allow divide by zero errors to be suppressed"); |
1037
|
1793 |
|
1794 DEFVAR ("warn_function_name_clash", SBV_warn_function_name_clash, |
1418
|
1795 "true", 0, warn_function_name_clash, |
1037
|
1796 "produce warning if function name conflicts with file name"); |
1093
|
1797 |
1418
|
1798 DEFVAR ("whitespace_in_literal_matrix", |
|
1799 SBV_whitespace_in_literal_matrix, "", 0, |
|
1800 whitespace_in_literal_matrix, |
1093
|
1801 "control auto-insertion of commas and semicolons in literal matrices"); |
529
|
1802 } |
|
1803 |
593
|
1804 // Deleting names from the symbol tables. |
|
1805 |
|
1806 DEFUN_TEXT ("clear", Fclear, Sclear, -1, 1, |
668
|
1807 "clear [-x] [name ...]\n\ |
|
1808 \n\ |
|
1809 Clear symbol(s) matching a list of globbing patterns.\n\ |
593
|
1810 \n\ |
668
|
1811 If no arguments are given, clear all user-defined variables and |
|
1812 functions.\n\ |
|
1813 \n\ |
|
1814 With -x, exclude the named variables") |
529
|
1815 { |
593
|
1816 Octave_object retval; |
|
1817 |
|
1818 DEFINE_ARGV("clear"); |
|
1819 |
668
|
1820 argc--; |
|
1821 argv++; |
|
1822 |
1271
|
1823 // Always clear the local table, but don't clear currently compiled |
|
1824 // functions unless we are at the top level. (Allowing that to |
|
1825 // happen inside functions would result in pretty odd behavior...) |
593
|
1826 |
|
1827 int clear_user_functions = (curr_sym_tab == top_level_sym_tab); |
|
1828 |
668
|
1829 if (argc == 0) |
593
|
1830 { |
|
1831 curr_sym_tab->clear (); |
|
1832 global_sym_tab->clear (clear_user_functions); |
|
1833 } |
529
|
1834 else |
|
1835 { |
668
|
1836 int exclusive = 0; |
|
1837 |
|
1838 if (argc > 0) |
|
1839 { |
|
1840 if (strcmp (*argv, "-x") == 0) |
|
1841 { |
|
1842 exclusive = 1; |
|
1843 argv++; |
|
1844 argc--; |
|
1845 } |
|
1846 } |
|
1847 |
|
1848 int lcount = 0; |
|
1849 int gcount = 0; |
|
1850 int fcount = 0; |
529
|
1851 |
668
|
1852 char **lvars = 0; |
|
1853 char **gvars = 0; |
|
1854 char **fcns = 0; |
|
1855 |
|
1856 if (argc > 0) |
593
|
1857 { |
893
|
1858 lvars = curr_sym_tab->list (lcount, 0, 0, 0, |
1418
|
1859 SYMTAB_VARIABLES, |
668
|
1860 SYMTAB_LOCAL_SCOPE); |
|
1861 |
893
|
1862 gvars = curr_sym_tab->list (gcount, 0, 0, 0, |
1418
|
1863 SYMTAB_VARIABLES, |
668
|
1864 SYMTAB_GLOBAL_SCOPE); |
|
1865 |
893
|
1866 fcns = global_sym_tab->list (fcount, 0, 0, 0, |
|
1867 symbol_def::USER_FUNCTION, |
864
|
1868 SYMTAB_ALL_SCOPES); |
668
|
1869 } |
|
1870 |
|
1871 while (argc > 0) |
|
1872 { |
|
1873 char *pat = *argv; |
|
1874 |
|
1875 if (pat) |
593
|
1876 { |
|
1877 int i; |
|
1878 for (i = 0; i < lcount; i++) |
|
1879 { |
668
|
1880 char *nm = lvars[i]; |
|
1881 int match = (fnmatch (pat, nm, __FNM_FLAGS) == 0); |
|
1882 if ((exclusive && ! match) || (! exclusive && match)) |
|
1883 curr_sym_tab->clear (nm); |
593
|
1884 } |
529
|
1885 |
593
|
1886 int count; |
|
1887 for (i = 0; i < gcount; i++) |
|
1888 { |
668
|
1889 char *nm = gvars[i]; |
|
1890 int match = (fnmatch (pat, nm, __FNM_FLAGS) == 0); |
|
1891 if ((exclusive && ! match) || (! exclusive && match)) |
593
|
1892 { |
668
|
1893 count = curr_sym_tab->clear (nm); |
593
|
1894 if (count > 0) |
668
|
1895 global_sym_tab->clear (nm, clear_user_functions); |
593
|
1896 } |
|
1897 } |
529
|
1898 |
593
|
1899 for (i = 0; i < fcount; i++) |
|
1900 { |
668
|
1901 char *nm = fcns[i]; |
|
1902 int match = (fnmatch (pat, nm, __FNM_FLAGS) == 0); |
|
1903 if ((exclusive && ! match) || (! exclusive && match)) |
593
|
1904 { |
668
|
1905 count = curr_sym_tab->clear (nm); |
864
|
1906 global_sym_tab->clear (nm, clear_user_functions); |
593
|
1907 } |
|
1908 } |
|
1909 } |
668
|
1910 |
|
1911 argc--; |
|
1912 argv++; |
593
|
1913 } |
529
|
1914 |
593
|
1915 delete [] lvars; |
|
1916 delete [] gvars; |
|
1917 delete [] fcns; |
|
1918 |
|
1919 } |
|
1920 |
|
1921 DELETE_ARGV; |
|
1922 |
|
1923 return retval; |
529
|
1924 } |
|
1925 |
1
|
1926 /* |
|
1927 ;;; Local Variables: *** |
|
1928 ;;; mode: C++ *** |
|
1929 ;;; page-delimiter: "^/\\*" *** |
|
1930 ;;; End: *** |
|
1931 */ |