1 /*
2     Gri - A language for scientific graphics programming
3     Copyright (C) 2008 Daniel Kelley
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #include	<string>
21 #include	<stdio.h>
22 #include        "gr.hh"
23 #include	"defaults.hh"
24 #include	"private.hh"
25 #include	"types.hh"
26 #include        "gr_coll.hh"
27 #include        "GMatrix.hh"
28 #include        "GriState.hh"
29 #include        "Synonym.hh"
30 #include        "Variable.hh"
31 
32 using namespace std;		// needed for g++-3
33 char source_indicator[256];	// BUG: length not checked
34 
35 // Globals from gr.
36 extern char     _grTempString[]; /* String available to all code. */
37 /*
38  * The following globals have symbolic names associated with
39  * them, and MUST be updated whenever these names are assigned to.  See
40  * the note in put_var() in variable.c.  The reason for the parallel C
41  * storage is that the following are accessed for every data point
42  * plotted.  Certain other symbolic variables (like ..publication.. for
43  * example) are not accessed frequently, and hence have no parallel C
44  * storage as the following do.  Thus they are safe against breakage.
45  */
46 output_file_type _output_file_type;
47 GriState        _griState;	// present state
48 bool            _user_set_x_axis = false;
49 bool            _user_set_y_axis = false;
50 double          _xleft;		/* ..xleft.. */
51 double          _xright;	/* ..xright.. */
52 double          _x_labelling;	/* ..xlabelling.. */
53 bool            _x_gave_labelling;
54 double          _ybottom;	/* ..ybottom.. */
55 double          _ytop;		/* ..ytop.. */
56 double          _y_labelling;	/* ..ylabelling.. */
57 bool            _y_gave_labelling;
58 // Globals used elsewhere (variables begin with _).
59 int             _arrow_type;
60 bool            _warn_offpage;
61 std::vector<double>       _dash;
62 std::vector<DataFile>     _dataFILE;
63 std::vector<CmdFile>      _cmdFILE;
64 std::vector<const char*>  _gri_argv;
65 
66 
67 char            _input_data_separator; // ' ' (general whitespace) or '\t'
68 char *          _cmd_being_done_IP[cmd_being_done_LEN];
69 int             _cmd_being_done_code[cmd_being_done_LEN];
70 int             _cmd_being_done = 0;
71 char *          _cmdLine;
72 char *          _cmdLineCOPY;
73 std::string     _contourFmt;
74 std::string     _current_directory;
75 int             _error_action = 0; // 0=message/exit(1), 1=message/dump core/exit(1)
76 char *          _errorMsg;
77 std::string     _lib_directory;
78 std::string     _margin;
79 std::string     _prompt;
80 char           *_word[MAX_nword];
81 char           *_Words2[MAX_nword];
82 char           *_Words3[MAX_nword];
83 std::string     _xFmt;
84 std::string     _yFmt;
85 double          _clipxleft, _clipxright, _clipybottom, _clipytop;
86 double          _cm_per_u, _cm_per_v;
87 double         *_dstack;
88 double          _gri_eof = 0.0;
89 double          _top_of_plot;
90 GriMatrix<double>  _f_xy;
91 double          _f_min, _f_max, *_xmatrix, *_ymatrix;
92 double          _xinc;
93 double          _yinc;
94 double          _zinc;
95 double          _axes_offset = 0.0;
96 int             _axesStyle;
97 bool            _gri_beep = false;
98 bool            _user_gave_bounding_box = false;
99 rectangle       _page_size;
100 rectangle       _bounding_box_user;
101 rectangle       _bounding_box;	// in cm on page
102 int             _braceLevel = 0;
103 int             _chatty;
104 int             _clipData = 0;
105 int             _debugFlag = 0;		      // used in debugging
106 int             _done = 0;		      // 1=`quit'; 2=`return'
107 bool            _drawingstarted = false;
108 bool            _error_in_cmd;
109 int             _exit_value = 0;
110 gr_font         _font;
111 bool            _first;
112 bool            _ignore_eof = false;
113 bool            _ignore_error;
114 GriMatrix<bool>  _legit_xy;
115 bool            _need_x_axis = true;
116 bool            _need_y_axis = true;
117 unsigned int    _nword;
118 bool            _xatbottom;
119 bool            _xincreasing = true;
120 int             _xsubdiv = 1;
121 vector<double>  _x_label_positions;
122 vector<string>  _x_labels;
123 gr_axis_properties _xtype;
124 char            _xtype_map = ' '; // could be "EWNS "
125 gr_axis_properties _ytype;
126 char            _ytype_map = ' '; // could be "EWNS "
127 bool            _yatleft;
128 bool            _yincreasing = true;
129 int             _ysubdiv = 1;
130 vector<string>  _y_labels;
131 vector<double>  _y_label_positions;
132 /* numbers of items existing */
133 int             _num_command = 0;	/* commands */
134 unsigned int    _num_xmatrix_data;
135 unsigned int    _num_ymatrix_data;
136 /* Version number */
137 double          _version;	/* this version */
138 double          _version_expected = 0.0;	/* expected version (if any) */
139 /* flags for whether things exist yet (set in  */
140 bool            _columns_exist;
141 bool            _grid_exists;
142 bool            _uscale_exists;
143 bool            _vscale_exists;
144 bool            _xgrid_exists;
145 bool            _xgrid_increasing;
146 bool            _xscale_exists;
147 bool            _ygrid_exists;
148 bool            _ygrid_increasing;
149 bool            _yscale_exists;
150 bool            _use_default_for_query = false;
151 
152 /*
153  * Matrices
154  */
155 GriColumn _colU;
156 GriColumn _colV;
157 GriColumn _colX;
158 GriColumn _colY;
159 GriColumn _colZ;
160 GriColumn _colWEIGHT;
161 
162 // Command stack
163 #define	COMMAND_STACK_SIZE	1000
164 typedef struct {
165 	char           *syntax;	        // The 'name' of command
166 	char           *help;           // Help, if any
167 	char           *procedure;	// Commands to do
168 	char           *filename;	// Where defined
169 	int             fileline;	// Where defined
170 }               GRI_COMMAND;
171 GRI_COMMAND     _command[COMMAND_STACK_SIZE];
172 
173 int _function_indent = 4;
174 
175 
176 int
gri_main(int argc,char ** argv)177 gri_main(int argc, char **argv)
178 {
179 	start_up(argc, argv);
180 	do {
181 		do_command_line();
182 	} while (!_done);
183 	warning("\\\\");		// notify of pending repeated warnings
184 	end_up();
185 	return _exit_value;
186 }
187