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