Mercurial > octave-nkf
comparison src/variables.cc @ 1271:ffecaa9b9892
[project @ 1995-04-20 20:23:21 by jwe]
author | jwe |
---|---|
date | Thu, 20 Apr 1995 20:23:21 +0000 |
parents | 8c3727b6d185 |
children | db4f4009d6e8 |
comparison
equal
deleted
inserted
replaced
1270:0a5e9e8892a0 | 1271:ffecaa9b9892 |
---|---|
305 | 305 |
306 char *p1 = s; | 306 char *p1 = s; |
307 char *p2 = p1; | 307 char *p2 = p1; |
308 char *pdest = retval; | 308 char *pdest = retval; |
309 | 309 |
310 // Is this really a good way to do this? | 310 // Is this really a good way to do this? |
311 | 311 |
312 while (count >= 0) | 312 while (count >= 0) |
313 { | 313 { |
314 p2 = strstr (p1, prefix); | 314 p2 = strstr (p1, prefix); |
315 | 315 |
642 | 642 |
643 FILE *ffile = get_input_from_file (ff, 0); | 643 FILE *ffile = get_input_from_file (ff, 0); |
644 | 644 |
645 if (ffile) | 645 if (ffile) |
646 { | 646 { |
647 // Check to see if this file defines a function or is just a list of | 647 // Check to see if this file defines a function or is just a |
648 // commands. | 648 // list of commands. |
649 | 649 |
650 char *tmp_help_txt = gobble_leading_white_space (ffile); | 650 char *tmp_help_txt = gobble_leading_white_space (ffile); |
651 | 651 |
652 if (is_function_file (ffile)) | 652 if (is_function_file (ffile)) |
653 { | 653 { |
682 global_sym_tab->clear (curr_fcn_file_name); | 682 global_sym_tab->clear (curr_fcn_file_name); |
683 } | 683 } |
684 } | 684 } |
685 else if (exec_script) | 685 else if (exec_script) |
686 { | 686 { |
687 // The value of `reading_fcn_file' will be restored to the proper value | 687 // We don't need this now. |
688 // when we unwind from this frame. | 688 |
689 delete [] tmp_help_txt; | |
690 | |
691 // The value of `reading_fcn_file' will be restored to the | |
692 // proper value when we unwind from this frame. | |
693 | |
689 reading_fcn_file = old_reading_fcn_file_state; | 694 reading_fcn_file = old_reading_fcn_file_state; |
690 | 695 |
691 unwind_protect_int (reading_script_file); | 696 unwind_protect_int (reading_script_file); |
692 reading_script_file = 1; | 697 reading_script_file = 1; |
693 | 698 |
708 { | 713 { |
709 int script_file_executed = 0; | 714 int script_file_executed = 0; |
710 | 715 |
711 char *nm = sym_rec->name (); | 716 char *nm = sym_rec->name (); |
712 | 717 |
713 // This is needed by yyparse. | 718 // This is needed by yyparse. |
714 | 719 |
715 curr_fcn_file_name = nm; | 720 curr_fcn_file_name = nm; |
716 | 721 |
717 #ifdef WITH_DLD | 722 #ifdef WITH_DLD |
718 | 723 |
741 } | 746 } |
742 | 747 |
743 int | 748 int |
744 lookup (symbol_record *sym_rec, int exec_script) | 749 lookup (symbol_record *sym_rec, int exec_script) |
745 { | 750 { |
746 int script_file_executed = 0; | 751 int script_executed = 0; |
747 | 752 |
748 if (! sym_rec->is_linked_to_global ()) | 753 if (! sym_rec->is_linked_to_global ()) |
749 { | 754 { |
750 if (sym_rec->is_defined ()) | 755 if (sym_rec->is_defined ()) |
751 { | 756 { |
752 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) | 757 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
753 script_file_executed = load_fcn_from_file (sym_rec, exec_script); | 758 script_executed = load_fcn_from_file (sym_rec, exec_script); |
754 } | 759 } |
755 else if (! sym_rec->is_formal_parameter ()) | 760 else if (! sym_rec->is_formal_parameter ()) |
756 { | 761 { |
757 link_to_builtin_or_function (sym_rec); | 762 link_to_builtin_or_function (sym_rec); |
758 | 763 |
759 if (! sym_rec->is_defined ()) | 764 if (! sym_rec->is_defined ()) |
760 script_file_executed = load_fcn_from_file (sym_rec, exec_script); | 765 script_executed = load_fcn_from_file (sym_rec, exec_script); |
761 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) | 766 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
762 script_file_executed = load_fcn_from_file (sym_rec, exec_script); | 767 script_executed = load_fcn_from_file (sym_rec, exec_script); |
763 } | 768 } |
764 } | 769 } |
765 | 770 |
766 return script_file_executed; | 771 return script_executed; |
767 } | 772 } |
768 | 773 |
769 // Get the symbol record for the given name that is visible in the | 774 // Get the symbol record for the given name that is visible in the |
770 // current scope. Reread any function definitions that appear to be | 775 // current scope. Reread any function definitions that appear to be |
771 // out of date. If a function is available in a file but is not | 776 // out of date. If a function is available in a file but is not |
806 char * | 811 char * |
807 builtin_string_variable (const char *name) | 812 builtin_string_variable (const char *name) |
808 { | 813 { |
809 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); | 814 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
810 | 815 |
811 // It is a prorgramming error to look for builtins that aren't. | 816 // It is a prorgramming error to look for builtins that aren't. |
812 | 817 |
813 assert (sr); | 818 assert (sr); |
814 | 819 |
815 char *retval = 0; | 820 char *retval = 0; |
816 | 821 |
840 builtin_real_scalar_variable (const char *name, double& d) | 845 builtin_real_scalar_variable (const char *name, double& d) |
841 { | 846 { |
842 int status = -1; | 847 int status = -1; |
843 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); | 848 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
844 | 849 |
845 // It is a prorgramming error to look for builtins that aren't. | 850 // It is a prorgramming error to look for builtins that aren't. |
846 | 851 |
847 assert (sr); | 852 assert (sr); |
848 | 853 |
849 tree_fvc *defn = sr->def (); | 854 tree_fvc *defn = sr->def (); |
850 | 855 |
869 { | 874 { |
870 tree_constant retval; | 875 tree_constant retval; |
871 | 876 |
872 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); | 877 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
873 | 878 |
874 // It is a prorgramming error to look for builtins that aren't. | 879 // It is a prorgramming error to look for builtins that aren't. |
875 | 880 |
876 assert (sr); | 881 assert (sr); |
877 | 882 |
878 tree_fvc *defn = sr->def (); | 883 tree_fvc *defn = sr->def (); |
879 | 884 |
901 { | 906 { |
902 error ("can't make function parameter `%s' global", sr->name ()); | 907 error ("can't make function parameter `%s' global", sr->name ()); |
903 return; | 908 return; |
904 } | 909 } |
905 | 910 |
906 // There must be a better way to do this. XXX FIXME XXX | 911 // There must be a better way to do this. XXX FIXME XXX |
907 | 912 |
908 if (sr->is_variable ()) | 913 if (sr->is_variable ()) |
909 { | 914 { |
910 // Would be nice not to have this cast. XXX FIXME XXX | 915 // Would be nice not to have this cast. XXX FIXME XXX |
916 | |
911 tree_constant *tmp = (tree_constant *) sr->def (); | 917 tree_constant *tmp = (tree_constant *) sr->def (); |
912 if (tmp) | 918 if (tmp) |
913 tmp = new tree_constant (*tmp); | 919 tmp = new tree_constant (*tmp); |
914 else | 920 else |
915 tmp = new tree_constant (); | 921 tmp = new tree_constant (); |
916 gsr->define (tmp); | 922 gsr->define (tmp); |
917 } | 923 } |
918 else | 924 else |
919 sr->clear (); | 925 sr->clear (); |
920 | 926 |
921 // If the global symbol is currently defined as a function, we need to | 927 // If the global symbol is currently defined as a function, we need |
922 // hide it with a variable. | 928 // to hide it with a variable. |
923 | 929 |
924 if (gsr->is_function ()) | 930 if (gsr->is_function ()) |
925 gsr->define ((tree_constant *) 0); | 931 gsr->define ((tree_constant *) 0); |
926 | 932 |
927 sr->alias (gsr, 1); | 933 sr->alias (gsr, 1); |
993 char **glb = 0; | 999 char **glb = 0; |
994 char **top = 0; | 1000 char **top = 0; |
995 char **lcl = 0; | 1001 char **lcl = 0; |
996 char **ffl = 0; | 1002 char **ffl = 0; |
997 | 1003 |
998 // Each of these functions returns a new vector of pointers to new | 1004 // Each of these functions returns a new vector of pointers to new |
999 // strings. | 1005 // strings. |
1000 | 1006 |
1001 key = names (keyword_help (), key_len); | 1007 key = names (keyword_help (), key_len); |
1002 glb = global_sym_tab->list (glb_len); | 1008 glb = global_sym_tab->list (glb_len); |
1003 top = top_level_sym_tab->list (top_len); | 1009 top = top_level_sym_tab->list (top_len); |
1004 if (top_level_sym_tab != curr_sym_tab) | 1010 if (top_level_sym_tab != curr_sym_tab) |
1007 | 1013 |
1008 int total_len = key_len + glb_len + top_len + lcl_len + ffl_len; | 1014 int total_len = key_len + glb_len + top_len + lcl_len + ffl_len; |
1009 | 1015 |
1010 char **list = new char * [total_len+1]; | 1016 char **list = new char * [total_len+1]; |
1011 | 1017 |
1012 // Put all the symbols in one big list. Only copy pointers, not the | 1018 // Put all the symbols in one big list. Only copy pointers, not the |
1013 // strings they point to, then only delete the original array of | 1019 // strings they point to, then only delete the original array of |
1014 // pointers, and not the strings they point to. | 1020 // pointers, and not the strings they point to. |
1015 | 1021 |
1016 int j = 0; | 1022 int j = 0; |
1017 int i = 0; | 1023 int i = 0; |
1018 for (i = 0; i < key_len; i++) | 1024 for (i = 0; i < key_len; i++) |
1019 list[j++] = key[i]; | 1025 list[j++] = key[i]; |
1189 warning ("%s: unrecognized option `%s'", my_name, *argv); | 1195 warning ("%s: unrecognized option `%s'", my_name, *argv); |
1190 else | 1196 else |
1191 break; | 1197 break; |
1192 } | 1198 } |
1193 | 1199 |
1194 // If the user specified -l and nothing else, show variables. If | 1200 // If the user specified -l and nothing else, show variables. If |
1195 // evaluating this at the top level, also show functions. | 1201 // evaluating this at the top level, also show functions. |
1196 | 1202 |
1197 if (show_verbose && ! (show_builtins || show_functions || show_variables)) | 1203 if (show_verbose && ! (show_builtins || show_functions || show_variables)) |
1198 { | 1204 { |
1199 show_functions = (curr_sym_tab == top_level_sym_tab); | 1205 show_functions = (curr_sym_tab == top_level_sym_tab); |
1200 show_variables = 1; | 1206 show_variables = 1; |
1429 int protect, int eternal, sv_Function sv_fcn, | 1435 int protect, int eternal, sv_Function sv_fcn, |
1430 const char *help) | 1436 const char *help) |
1431 { | 1437 { |
1432 symbol_record *sr = global_sym_tab->lookup (varname, 1, 0); | 1438 symbol_record *sr = global_sym_tab->lookup (varname, 1, 0); |
1433 | 1439 |
1434 // It is a programming error for a builtin symbol to be missing. | 1440 // It is a programming error for a builtin symbol to be missing. |
1435 // Besides, we just inserted it, so it must be there. | 1441 // Besides, we just inserted it, so it must be there. |
1436 | 1442 |
1437 assert (sr); | 1443 assert (sr); |
1438 | 1444 |
1439 sr->unprotect (); | 1445 sr->unprotect (); |
1440 | 1446 |
1441 // Must do this before define, since define will call the special | 1447 // Must do this before define, since define will call the special |
1442 // variable function only if it knows about it, and it needs to, so | 1448 // variable function only if it knows about it, and it needs to, so |
1443 // that user prefs can be properly initialized. | 1449 // that user prefs can be properly initialized. |
1444 | 1450 |
1445 if (sv_fcn) | 1451 if (sv_fcn) |
1446 sr->set_sv_function (sv_fcn); | 1452 sr->set_sv_function (sv_fcn); |
1447 | 1453 |
1448 sr->define_builtin_var (val); | 1454 sr->define_builtin_var (val); |
1458 } | 1464 } |
1459 | 1465 |
1460 void | 1466 void |
1461 install_builtin_variables (void) | 1467 install_builtin_variables (void) |
1462 { | 1468 { |
1463 // XXX FIXME XX -- these should probably be moved to where they | 1469 // XXX FIXME XX -- these should probably be moved to where they |
1464 // logically belong instead of being all grouped here. | 1470 // logically belong instead of being all grouped here. |
1465 | 1471 |
1466 DEFVAR ("EDITOR", SBV_EDITOR, editor, 0, 0, 1, sv_editor, | 1472 DEFVAR ("EDITOR", SBV_EDITOR, editor, 0, 0, 1, sv_editor, |
1467 "name of the editor to be invoked by the edit_history command"); | 1473 "name of the editor to be invoked by the edit_history command"); |
1468 | 1474 |
1469 DEFVAR ("I", SBV_I, Complex (0.0, 1.0), 0, 1, 1, 0, | 1475 DEFVAR ("I", SBV_I, Complex (0.0, 1.0), 0, 1, 1, 0, |
1719 DEFINE_ARGV("clear"); | 1725 DEFINE_ARGV("clear"); |
1720 | 1726 |
1721 argc--; | 1727 argc--; |
1722 argv++; | 1728 argv++; |
1723 | 1729 |
1724 // Always clear the local table, but don't clear currently compiled | 1730 // Always clear the local table, but don't clear currently compiled |
1725 // functions unless we are at the top level. (Allowing that to happen | 1731 // functions unless we are at the top level. (Allowing that to |
1726 // inside functions would result in pretty odd behavior...) | 1732 // happen inside functions would result in pretty odd behavior...) |
1727 | 1733 |
1728 int clear_user_functions = (curr_sym_tab == top_level_sym_tab); | 1734 int clear_user_functions = (curr_sym_tab == top_level_sym_tab); |
1729 | 1735 |
1730 if (argc == 0) | 1736 if (argc == 0) |
1731 { | 1737 { |