2
/******************************************************************************
4
* DESCRIPTION: edit environment for typesetting
5
* COPYRIGHT : (C) 1999 Joris van der Hoeven
6
*******************************************************************************
7
* This software falls under the GNU general public license and comes WITHOUT
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11
******************************************************************************/
16
#include "drd_info.hpp"
18
#include "language.hpp"
20
#include "hashmap.hpp"
23
#include "Graphics/frame.hpp"
25
#define DECORATION (-1)
27
/******************************************************************************
28
* The different types of system environment variables
29
******************************************************************************/
33
#define Env_Magnification 2
34
#define Env_Language 3
37
#define Env_Font_Size 6
38
#define Env_Index_Level 7
39
#define Env_Display_Style 8
40
#define Env_Math_Condensed 9
41
#define Env_Vertical_Pos 10
43
#define Env_Paragraph 12
45
#define Env_Preamble 14
47
#define Env_Clipping 16
48
#define Env_Line_Width 17
50
/******************************************************************************
51
* The edit environment
52
******************************************************************************/
54
class edit_env_rep: public concrete_struct {
59
hashmap<string,tree> env;
60
hashmap<string,tree> back;
62
hashmap<string,path> src;
63
list<hashmap<string,tree> > macro_arg;
64
list<hashmap<string,path> > macro_src;
65
array<box> decorated_boxes;
67
hashmap<string,int>& var_type;
69
hashmap<string,tree>& local_ref;
70
hashmap<string,tree>& global_ref;
71
hashmap<string,tree>& local_aux;
72
hashmap<string,tree>& global_aux;
73
bool complete; // typeset complete document ?
74
bool read_only; // write-protected ?
95
tree exec_extra_list (tree t, int pos);
96
tree exec_extra_tuple (tree t, int pos);
99
tree exec_formatting (tree t, string v);
100
void exec_until_formatting (tree t, path p, string v);
101
bool exec_until_formatting (tree t, path p, string var, int l, string v);
102
tree exec_table (tree t);
103
void exec_until_table (tree t, path p);
104
bool exec_until_table (tree t, path p, string var, int level);
105
tree exec_assign (tree t);
106
tree exec_with (tree t);
107
void exec_until_with (tree t, path p);
108
bool exec_until_with (tree t, path p, string var, int level);
109
tree exec_drd_props (tree t);
110
tree exec_provides (tree t);
111
tree exec_value (tree t);
112
tree exec_argument (tree t);
113
bool exec_until_argument (tree t, path p, string var, int level);
114
tree exec_get_label (tree t);
115
tree exec_get_arity (tree t);
116
tree exec_eval_args (tree t);
117
tree exec_delay (tree t);
118
tree exec_quasiquoted (tree t);
119
tree exec_compound (tree t);
120
void exec_until_compound (tree t, path p);
121
bool exec_until_compound (tree t, path p, string var, int level);
123
tree exec_or (tree t);
124
tree exec_xor (tree t);
125
tree exec_and (tree t);
126
tree exec_not (tree t);
127
tree exec_plus (tree t);
128
tree exec_minus (tree t);
129
tree exec_times (tree t);
130
tree exec_over (tree t);
131
tree exec_divide (tree t);
132
tree exec_modulo (tree t);
133
tree exec_merge (tree t);
134
tree exec_length (tree t);
135
tree exec_range (tree t);
136
tree exec_number (tree t);
137
tree exec_date (tree t);
138
tree exec_translate (tree t);
139
tree exec_find_file (tree t);
140
tree exec_is_tuple (tree t);
141
tree exec_lookup (tree t);
142
tree exec_equal (tree t);
143
tree exec_unequal (tree t);
144
tree exec_less (tree t);
145
tree exec_lesseq (tree t);
146
tree exec_greater (tree t);
147
tree exec_greatereq (tree t);
148
tree exec_if (tree t);
149
tree exec_case (tree t);
150
tree exec_while (tree t);
151
tree exec_rewrite (tree t);
153
tree exec_mod_active (tree t, tree_label which);
154
void exec_until_mod_active (tree t, path p);
155
bool exec_until_mod_active (tree t, path p, string var, int level);
157
tree exec_point (tree t);
160
edit_env_rep (display dis,
163
hashmap<string,tree>& local_ref,
164
hashmap<string,tree>& global_ref,
165
hashmap<string,tree>& local_aux,
166
hashmap<string,tree>& global_aux);
167
void style_init_env ();
169
/* execution of trees and setting environment variables */
171
void exec_until (tree t, path p);
172
bool exec_until (tree t, path p, string var, int level);
173
string exec_string (tree t); /* should be inline */
174
tree expand (tree t);
175
bool depends (tree t, string s, int level);
176
tree rewrite (tree t);
178
inline void monitored_write (string s, tree t) {
179
back->write_back (s, env); env (s)= t; }
180
inline void monitored_write_update (string s, tree t) {
181
back->write_back (s, env); env (s)= t; update (s); }
182
inline void write (string s, tree t) { env (s)= t; }
183
inline void write_update (string s, tree t) { env (s)= t; update (s); }
184
inline tree local_begin (string s, tree t) {
185
// tree r (env [s]); monitored_write_update (s, t); return r;
186
tree& val= env (s); tree r (val); val= t; update (s); return r; }
187
inline void local_end (string s, tree t) {
188
env (s)= t; update (s); }
189
inline tree local_begin_script () {
190
return local_begin (MATH_LEVEL, as_string (index_level+1)); }
191
inline void local_end_script (tree t) {
192
local_end (MATH_LEVEL, t); }
193
inline void assign (string s, tree t) {
194
tree& val= env (s); t= exec(t); if (val != t) {
195
back->write_back (s, env); val= t; update (s); } }
196
inline bool provides (string s) { return env->contains (s); }
197
inline tree read (string s) { return env [s]; }
199
void write_default_env ();
200
void write_env (hashmap<string,tree> user_env);
201
void monitored_patch_env (hashmap<string,tree> patch);
202
void patch_env (hashmap<string,tree> patch);
203
void read_env (hashmap<string,tree>& ret);
204
void local_start (hashmap<string,tree>& prev_back);
205
void local_update (hashmap<string,tree>& oldpat, hashmap<string,tree>& chg);
206
void local_end (hashmap<string,tree>& prev_back);
208
/* updating environment variables */
210
void update_color ();
212
void update_language ();
213
void update_frame ();
214
void update_clipping ();
216
void update (string env_var);
218
/* miscellaneous and utilities */
219
SI decode_length (string l);
220
point decode_point (tree t);
221
space decode_space (string l);
222
inline SI decode_length (tree l) { return decode_length (as_string (l)); }
223
void get_length_unit (string l, SI& un, string& un_str);
224
string add_lengths (string l1, string l2);
225
string multiply_length (double x, string l);
226
bool is_length (string s);
227
double divide_lengths (string l1, string l2);
228
void get_page_pars (SI& w, SI& h, SI& ww, SI& hh,
229
SI& odd, SI& even, SI& top, SI& bottom);
231
/* retrieving environment variables */
232
inline bool get_bool (string var) {
234
if (is_compound (t)) return false;
235
return as_bool (t->label); }
236
inline int get_int (string var) {
238
if (is_compound (t)) return 0;
239
return as_int (t->label); }
240
inline double get_double (string var) {
242
if (is_compound (t)) return 0.0;
243
return as_double (t->label); }
244
inline string get_string (string var) {
246
if (is_compound (t)) return "";
248
inline SI get_length (string var) {
250
if (is_compound (t)) return 0;
251
return decode_length (t->label); }
252
inline space get_space (string var) {
254
if (is_compound (t)) return 0;
255
return decode_space (t->label); }
257
friend class edit_env;
258
friend ostream& operator << (ostream& out, edit_env env);
263
edit_env (display dis,
266
hashmap<string,tree>& local_ref,
267
hashmap<string,tree>& global_ref,
268
hashmap<string,tree>& local_aux,
269
hashmap<string,tree>& global_aux);
271
CONCRETE_CODE(edit_env);
273
void extract_format (tree fm, tree* r, int n);
274
tree load_inclusion (url u); // implented in tm_file.cpp
276
#endif // defined ENV_H