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