Mercurial > hg > octave-thorsten
changeset 3165:e4bbfc196e53
[project @ 1998-04-16 03:01:47 by jwe]
author | jwe |
---|---|
date | Thu, 16 Apr 1998 03:05:03 +0000 |
parents | 45490c020e47 |
children | c3409a0cafa8 |
files | src/ChangeLog src/input.cc src/input.h src/lex.h src/lex.l src/ov-usr-fcn.cc src/ov-usr-fcn.h src/parse.y src/pt-plot.cc src/pt-plot.h src/pt-pr-code.cc src/pt-pr-code.h src/pt-walk.h src/variables.cc |
diffstat | 14 files changed, 323 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,30 @@ +Wed Apr 15 01:03:05 1998 John W. Eaton <jwe@bevo.che.wisc.edu> + + * input.cc (Vlast_prompt_time): New global variable. + (octave_gets): Set it. + * ov-usr-fcn.h (octave_user_function::time_checked): New function. + (octave_user_function::mark_fcn_file_up_to_date): Ditto. + (octave_user_function::t_checked): New data member. + * variables.cc (symbol_out_of_date): Only check file time stamp if + a prompt has been printed since the last time check. + + * pt-plot.h, pt-plot.cc (subplot_axes): New class. + (subplot): Handle axes. + (Vgnuplot_command_axes): New static variable. + (gnuplot_command_axes): New function. + (symbols_of_pt_plot): DEFVAR gnuplot_command_axes. + * pt-walk.h (tree_walker::visit_subplot_axes): New virtual function. + * parse.y (plot_options): Handle axes. + * lex.l (plot_axes_token): New function. + (is_keyword): Use it. + (is_plot_keyword): Recognize "axes" and "axis". + * lex.h (class lexical_feedback): New field, in_plot_axes. + (lexical_feedback::init): Reset it. + +Tue Apr 14 23:32:27 1998 John W. Eaton <jwe@bevo.che.wisc.edu> + + * parse.y (parse_fcn_file): New arg, force_script. Change callers. + Fri Apr 10 11:01:27 1998 John W. Eaton <jwe@bevo.che.wisc.edu> * help.cc (type): Also print values of variables.
--- a/src/input.cc +++ b/src/input.cc @@ -86,6 +86,9 @@ // more than one state can be active at once. int Vecho_executing_commands; +// The time we last printed a prompt. +time_t Vlast_prompt_time; + // Character to append after successful command-line completion attempts. static char Vcompletion_append_char; @@ -192,6 +195,8 @@ { string retval; + Vlast_prompt_time = time (0); + if ((interactive || forced_interactive) && (! (reading_fcn_file || reading_script_file))) {
--- a/src/input.h +++ b/src/input.h @@ -26,6 +26,7 @@ #define octave_input_h 1 #include <cstdio> +#include <ctime> #include <string> @@ -85,6 +86,8 @@ extern int Vecho_executing_commands; +extern time_t Vlast_prompt_time; + #endif /*
--- a/src/lex.h +++ b/src/lex.h @@ -161,6 +161,9 @@ // TRUE means we're looking at the style part of a plot command. bool in_plot_style; + // TRUE means we're looking at the axes part of a plot command. + bool in_plot_axes; + // TRUE means we're looking at an indirect reference to a // structure element. bool looking_at_indirect_ref;
--- a/src/lex.l +++ b/src/lex.l @@ -835,6 +835,38 @@ return retval; } +// Check to see if a character string matches any of the possible axes +// tags for plots. + +static string +plot_axes_token (const string& s) +{ + string retval; + + static char *plot_axes[] = + { + "x1y1", + "x1y2", + "x2y1", + "x2y2", + 0, + }; + + char **tmp = plot_axes; + while (*tmp) + { + if (almost_match (*tmp, s.c_str ())) + { + retval = *tmp; + break; + } + + tmp++; + } + + return retval; +} + // Check to see if a character string matches any one of the plot // option keywords. Don't match abbreviations for clear, since that's // not a gnuplot keyword (users will probably only expect to be able @@ -858,6 +890,11 @@ lexer_flags.in_plot_style = true; return WITH; } + else if (almost_match ("axes", t) || almost_match ("axis", t)) + { + lexer_flags.in_plot_axes = true; + return AXES; + } else if (strcmp ("clear", t) == 0) { return CLEAR; @@ -873,17 +910,32 @@ static int is_keyword (const string& s) { - if (lexer_flags.plotting && lexer_flags.in_plot_style) + if (lexer_flags.plotting) { - string sty = plot_style_token (s); - - if (! sty.empty ()) + if (lexer_flags.in_plot_style) { - lexer_flags.in_plot_style = false; - yylval.tok_val = new token (sty); - token_stack.push (yylval.tok_val); - return STYLE; + string sty = plot_style_token (s); + + if (! sty.empty ()) + { + lexer_flags.in_plot_style = false; + yylval.tok_val = new token (sty); + token_stack.push (yylval.tok_val); + return STYLE; + } } + else if (lexer_flags.in_plot_axes) + { + string axes = plot_axes_token (s); + + if (! axes.empty ()) + { + lexer_flags.in_plot_axes = false; + yylval.tok_val = new token (axes); + token_stack.push (yylval.tok_val); + return AXES_TAG; + } + } } int l = input_line_number; @@ -1860,6 +1912,7 @@ doing_set = false; in_plot_range = false; in_plot_style = false; + in_plot_axes = false; in_plot_using = false; past_plot_range = false; plotting = false;
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -80,10 +80,10 @@ : octave_function (string (), string ()), param_list (pl), ret_list (rl), cmd_list (cl), sym_tab (st), file_name (), fcn_name (), t_parsed (0), - system_fcn_file (false), call_depth (0), num_named_args (0), - args_passed (), num_args_passed (0), curr_va_arg_number (0), - vr_list (0), symtab_entry (0), argn_sr (0), nargin_sr (0), - nargout_sr (0) + t_checked (0), system_fcn_file (false), call_depth (0), + num_named_args (0), args_passed (), num_args_passed (0), + curr_va_arg_number (0), vr_list (0), symtab_entry (0), + argn_sr (0), nargin_sr (0), nargout_sr (0) { install_automatic_vars ();
--- a/src/ov-usr-fcn.h +++ b/src/ov-usr-fcn.h @@ -73,8 +73,14 @@ void stash_fcn_file_name (void); + void mark_fcn_file_up_to_date (time_t t) + { t_checked = t; } + void stash_fcn_file_time (time_t t) - { t_parsed = t; } + { + t_parsed = t; + mark_fcn_file_up_to_date (t); + } void stash_symtab_ptr (symbol_record *sr) { symtab_entry = sr; } @@ -85,6 +91,9 @@ time_t time_parsed (void) const { return t_parsed; } + time_t time_checked (void) const + { return t_checked; } + void mark_as_system_fcn_file (void); bool is_system_fcn_file (void) const @@ -157,6 +166,10 @@ // The time the file was parsed. time_t t_parsed; + // The time the file was last checked to see if it needs to be + // parsed again. + time_t t_checked; + // True if this function came from a file that is considered to be a // system function. This affects whether we check the time stamp // on the file to see if it has changed.
--- a/src/parse.y +++ b/src/parse.y @@ -324,6 +324,7 @@ plot_range *plot_range_type; subplot_using *subplot_using_type; subplot_style *subplot_style_type; + subplot_axes *subplot_axes_type; octave_user_function *octave_user_function_type; } @@ -342,7 +343,7 @@ %token <tok_val> NAME %token <tok_val> END %token <tok_val> PLOT -%token <tok_val> TEXT STYLE +%token <tok_val> TEXT STYLE AXES_TAG %token <tok_val> FOR WHILE %token <tok_val> IF ELSEIF ELSE %token <tok_val> SWITCH CASE OTHERWISE @@ -354,7 +355,7 @@ // Other tokens. %token END_OF_INPUT LEXICAL_ERROR %token FCN ELLIPSIS ALL_VA_ARGS -%token USING TITLE WITH COLON OPEN_BRACE CLOSE_BRACE CLEAR +%token USING TITLE WITH AXES COLON OPEN_BRACE CLOSE_BRACE CLEAR // Nonterminals we construct. %type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep @@ -392,6 +393,7 @@ %type <plot_range_type> ranges1 %type <subplot_using_type> using using1 %type <subplot_style_type> style +%type <subplot_axes_type> axes // Precedence and associativity. %left ';' ',' '\n' @@ -1177,39 +1179,68 @@ plot_command2 : expression { $$ = new subplot ($1); } | expression plot_options - { $$ = $2->set_data ($1); } + { $$ = $2->add_data ($1); } ; plot_options : using - { $$ = new subplot ($1, 0, 0); } + { + subplot *tmp = new subplot (); + $$ = tmp->add_clause ($1); + } | title - { $$ = new subplot (0, $1, 0); } + { + subplot *tmp = new subplot (); + $$ = tmp->add_clause ($1); + } | style - { $$ = new subplot (0, 0, $1); } - | using title - { $$ = new subplot ($1, $2, 0); } - | title using - { $$ = new subplot ($2, $1, 0); } - | using style - { $$ = new subplot ($1, 0, $2); } - | style using - { $$ = new subplot ($2, 0, $1); } - | title style - { $$ = new subplot (0, $1, $2); } - | style title - { $$ = new subplot (0, $2, $1); } - | using title style - { $$ = new subplot ($1, $2, $3); } - | using style title - { $$ = new subplot ($1, $3, $2); } - | title using style - { $$ = new subplot ($2, $1, $3); } - | title style using - { $$ = new subplot ($3, $1, $2); } - | style using title - { $$ = new subplot ($2, $3, $1); } - | style title using - { $$ = new subplot ($3, $2, $1); } + { + subplot *tmp = new subplot (); + $$ = tmp->add_clause ($1); + } + | axes + { + subplot *tmp = new subplot (); + $$ = tmp->add_clause ($1); + } + | plot_options using + { + if (! ($$ = $1->add_clause ($2))) + { + yyerror ("only one using option may be specified"); + ABORT_PARSE; + } + } + | plot_options title + { + if (! ($$ = $1->add_clause ($2))) + { + yyerror ("only one title option my be specified"); + ABORT_PARSE; + } + } + | plot_options style + { + if (! ($$ = $1->add_clause ($2))) + { + yyerror ("only one style option my be specified"); + ABORT_PARSE; + } + } + | plot_options axes + { + if (! ($$ = $1->add_clause ($2))) + { + yyerror ("only one axes option may be specified"); + ABORT_PARSE; + } + } + ; + +axes : AXES AXES_TAG + { + lexer_flags.in_plot_axes = false; + $$ = new subplot_axes ($2->text ()); + } ; using : using1 @@ -2750,7 +2781,7 @@ } static bool -parse_fcn_file (bool exec_script, const string& ff) +parse_fcn_file (const string& ff, bool exec_script, bool force_script = false) { unwind_protect::begin_frame ("parse_fcn_file"); @@ -2785,7 +2816,7 @@ // Check to see if this file defines a function or is just a // list of commands. - if (is_function_file (ffile)) + if (! force_script && is_function_file (ffile)) { // XXX FIXME XXX -- we shouldn't need both the // command_history object and the @@ -2886,7 +2917,7 @@ curr_fcn_file_full_name = ff; if (ff.length () > 0) - script_file_executed = parse_fcn_file (exec_script, ff); + script_file_executed = parse_fcn_file (ff, exec_script); if (! (error_state || script_file_executed)) force_link_to_function (nm); @@ -2915,7 +2946,7 @@ { file = file_ops::tilde_expand (file); - parse_fcn_file (true, file); + parse_fcn_file (file, true, true); if (error_state) error ("source: error sourcing file `%s'", file.c_str ());
--- a/src/pt-plot.cc +++ b/src/pt-plot.cc @@ -107,6 +107,7 @@ static string Vgnuplot_command_splot; static string Vgnuplot_command_using; static string Vgnuplot_command_with; +static string Vgnuplot_command_axes; static string Vgnuplot_command_title; static string Vgnuplot_command_end; @@ -625,12 +626,28 @@ tw.visit_subplot_style (*this); } +int +subplot_axes::print (ostrstream& plot_buf) +{ + if (! sp_axes.empty ()) + plot_buf << " " << Vgnuplot_command_axes << " " << sp_axes; + + return 0; +} + +void +subplot_axes::accept (tree_walker& tw) +{ + tw.visit_subplot_axes (*this); +} + subplot::~subplot (void) { delete sp_plot_data; delete sp_using_clause; delete sp_title_clause; delete sp_style_clause; + delete sp_axes_clause; } octave_value @@ -760,6 +777,13 @@ if (status < 0) return -1; + if (sp_axes_clause) + { + int status = sp_axes_clause->print (plot_buf); + if (status < 0) + return -1; + } + if (sp_title_clause) { octave_value tmp = sp_title_clause->rvalue (); @@ -1151,6 +1175,12 @@ } static int +gnuplot_command_axes (void) +{ + return set_string_var (Vgnuplot_command_axes, "gnuplot_command_axes"); +} + +static int gnuplot_command_title (void) { return set_string_var (Vgnuplot_command_title, "gnuplot_command_title"); @@ -1202,6 +1232,9 @@ DEFVAR (gnuplot_command_with, "w", 0, gnuplot_command_with, ""); + DEFVAR (gnuplot_command_axes, "ax", 0, gnuplot_command_axes, + ""); + DEFVAR (gnuplot_command_title, "t", 0, gnuplot_command_title, "");
--- a/src/pt-plot.h +++ b/src/pt-plot.h @@ -36,6 +36,7 @@ class plot_range; class subplot_using; class subplot_style; +class subplot_axes; class subplot; class subplot_list; @@ -265,26 +266,94 @@ }; class +subplot_axes +{ +public: + + subplot_axes (const string& s = string ()) + : sp_axes (s) { } + + ~subplot_axes (void) { } + + int print (ostrstream& plot_buf); + + string axes (void) { return sp_axes; } + + void accept (tree_walker& tw); + +private: + + // The axes we are using: `x1y1', `x1y2', etc. + string sp_axes; + + // No copying! + + subplot_axes (const subplot_axes&); + + subplot_axes& operator = (const subplot_axes&); +}; + +class subplot { public: subplot (tree_expression *data = 0) : sp_plot_data (data), sp_using_clause (0), sp_title_clause (0), - sp_style_clause (0) { } - - subplot (subplot_using *u, tree_expression *t, subplot_style *s) - : sp_plot_data (0), sp_using_clause (u), sp_title_clause (t), - sp_style_clause (s) { } + sp_style_clause (0), sp_axes_clause (0) { } ~subplot (void); - subplot *set_data (tree_expression *data) + subplot *add_data (tree_expression *data) { sp_plot_data = data; return this; } + subplot *add_clause (subplot_using *u) + { + if (! sp_using_clause) + { + sp_using_clause = u; + return this; + } + else + return 0; + } + + subplot *add_clause (tree_expression *t) + { + if (! sp_title_clause) + { + sp_title_clause = t; + return this; + } + else + return 0; + } + + subplot *add_clause (subplot_style *s) + { + if (! sp_style_clause) + { + sp_style_clause = s; + return this; + } + else + return 0; + } + + subplot *add_clause (subplot_axes *a) + { + if (! sp_axes_clause) + { + sp_axes_clause = a; + return this; + } + else + return 0; + } + octave_value extract_plot_data (int ndim, octave_value& data); int handle_plot_data (int ndim, ostrstream& plot_buf); @@ -299,6 +368,8 @@ subplot_style *style_clause (void) { return sp_style_clause; } + subplot_axes *axes_clause (void) { return sp_axes_clause; } + void accept (tree_walker& tw); private: @@ -315,6 +386,9 @@ // The `style' option subplot_style *sp_style_clause; + // The `axes' option + subplot_axes *sp_axes_clause; + // No copying! subplot (const subplot&);
--- a/src/pt-pr-code.cc +++ b/src/pt-pr-code.cc @@ -793,6 +793,11 @@ sp_plot_data->accept (*this); } + subplot_axes *sp_axes_clause = cmd.axes_clause (); + + if (sp_axes_clause) + sp_axes_clause->accept (*this); + subplot_using *sp_using_clause = cmd.using_clause (); if (sp_using_clause) @@ -810,6 +815,12 @@ } void +tree_print_code::visit_subplot_axes (subplot_axes& cmd) +{ + os << " axes " << cmd.axes (); +} + +void tree_print_code::visit_subplot_list (subplot_list& lst) { Pix p = lst.first ();
--- a/src/pt-pr-code.h +++ b/src/pt-pr-code.h @@ -116,6 +116,8 @@ void visit_subplot (subplot&); + void visit_subplot_axes (subplot_axes&); + void visit_subplot_list (subplot_list&); void visit_subplot_style (subplot_style&);
--- a/src/pt-walk.h +++ b/src/pt-walk.h @@ -59,6 +59,7 @@ class tree_statement; class tree_statement_list; class subplot; +class subplot_axes; class subplot_list; class subplot_style; class subplot_using; @@ -180,6 +181,9 @@ visit_subplot (subplot&) = 0; virtual void + visit_subplot_axes (subplot_axes&) = 0; + + virtual void visit_subplot_list (subplot_list&) = 0; virtual void
--- a/src/variables.cc +++ b/src/variables.cc @@ -41,6 +41,7 @@ #include "error.h" #include "gripes.h" #include "help.h" +#include "input.h" #include "lex.h" #include "oct-map.h" #include "oct-obj.h" @@ -510,14 +511,19 @@ || (Vignore_function_time_stamp && tmp->is_system_fcn_file ()))) { - time_t tp = tmp->time_parsed (); + if (tmp->time_checked () < Vlast_prompt_time) + { + time_t tp = tmp->time_parsed (); - string fname = fcn_file_in_path (ff); + string fname = fcn_file_in_path (ff); - file_stat fs (fname); + tmp->mark_fcn_file_up_to_date (time (0)); + + file_stat fs (fname); - if (fs && fs.is_newer (tp)) - retval = true; + if (fs && fs.is_newer (tp)) + retval = true; + } } } }