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 version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
15 #include "drd_info.hpp"
18 #include "language.hpp"
20 #include "hashmap.hpp"
23 #include "Graphics/frame.hpp"
26 #define DECORATION (-1)
28 /******************************************************************************
29 * The different types of system environment variables
30 ******************************************************************************/
34 #define Env_Magnification 2
35 #define Env_Language 3
38 #define Env_Font_Size 6
39 #define Env_Index_Level 7
40 #define Env_Display_Style 8
41 #define Env_Math_Condensed 9
42 #define Env_Vertical_Pos 10
44 #define Env_Paragraph 12
46 #define Env_Page_Extents 14
47 #define Env_Preamble 15
48 #define Env_Geometry 16
50 #define Env_Line_Width 18
52 #define Env_Grid_Aspect 20
53 #define Env_Src_Style 21
54 #define Env_Src_Special 22
55 #define Env_Src_Compact 23
56 #define Env_Src_Close 24
57 #define Env_Point_Style 25
58 #define Env_Dash_Style 26
59 #define Env_Dash_Style_Unit 27
60 #define Env_Fill_Color 28
61 #define Env_Line_Arrows 29
62 #define Env_Textat_Halign 30
63 #define Env_Textat_Valign 31
65 /******************************************************************************
66 * For style file editing
67 ******************************************************************************/
69 #define STYLE_ANGULAR 0
70 #define STYLE_SCHEME 1
72 #define STYLE_FUNCTIONAL 3
75 #define SPECIAL_FORMAT 1
76 #define SPECIAL_NORMAL 2
77 #define SPECIAL_MAXIMAL 3
80 #define COMPACT_INLINE_ARGS 1
81 #define COMPACT_INLINE_START 2
82 #define COMPACT_INLINE 3
83 #define COMPACT_NONE 4
85 #define CLOSE_MINIMAL 0
86 #define CLOSE_COMPACT 1
88 #define CLOSE_REPEAT 3
90 #define INACTIVE_INLINE_RECURSE 0
91 #define INACTIVE_INLINE_ONCE 1
92 #define INACTIVE_INLINE_ERROR 2
93 #define INACTIVE_BLOCK_RECURSE 3
94 #define INACTIVE_BLOCK_ONCE 4
95 #define INACTIVE_BLOCK_ERROR 5
97 /******************************************************************************
98 * Other enumerated values
99 ******************************************************************************/
101 #define FILL_MODE_NOTHING 0
102 #define FILL_MODE_NONE 1
103 #define FILL_MODE_INSIDE 2
104 #define FILL_MODE_BOTH 3
106 /******************************************************************************
107 * The edit environment
108 ******************************************************************************/
111 class edit_env_rep
: public concrete_struct
{
115 hashmap
<string
,tree
> env
;
116 hashmap
<string
,tree
> back
;
118 hashmap
<string
,path
> src
;
119 list
<hashmap
<string
,tree
> > macro_arg
;
120 list
<hashmap
<string
,path
> > macro_src
;
121 array
<box
> decorated_boxes
;
123 hashmap
<string
,int>& var_type
;
127 hashmap
<string
,tree
>& local_ref
;
128 hashmap
<string
,tree
>& global_ref
;
129 hashmap
<string
,tree
>& local_aux
;
130 hashmap
<string
,tree
>& global_aux
;
131 bool complete
; // typeset complete document ?
132 bool read_only
; // write-protected ?
133 link_repository link_env
;
161 array
<bool> dash_style
;
165 array
<box
> line_arrows
;
166 string textat_halign
;
167 string textat_valign
;
175 int page_margin_mode
;
182 SI page_right_margin
;
184 SI page_bottom_margin
;
187 tree
exec_formatting (tree t
, string v
);
188 void exec_until_formatting (tree t
, path p
, string v
);
189 bool exec_until_formatting (tree t
, path p
, string var
, int l
, string v
);
190 tree
exec_table (tree t
);
191 void exec_until_table (tree t
, path p
);
192 bool exec_until_table (tree t
, path p
, string var
, int level
);
193 tree
exec_assign (tree t
);
194 tree
exec_with (tree t
);
195 void exec_until_with (tree t
, path p
);
196 bool exec_until_with (tree t
, path p
, string var
, int level
);
197 tree
exec_drd_props (tree t
);
198 tree
exec_compound (tree t
);
199 void exec_until_compound (tree t
, path p
);
200 bool exec_until_compound (tree t
, path p
, string var
, int level
);
201 tree
exec_provides (tree t
);
202 tree
exec_value (tree t
);
203 tree
exec_quote_value (tree t
);
204 tree
exec_arg (tree t
);
205 bool exec_until_arg (tree t
, path p
, string var
, int level
);
206 tree
exec_quote_arg (tree t
);
207 tree
exec_get_label (tree t
);
208 tree
exec_get_arity (tree t
);
209 tree
exec_eval_args (tree t
);
210 bool exec_until_mark (tree t
, path p
, string var
, int level
);
211 bool exec_until_quasi (tree t
, path p
, string var
, int level
);
212 tree
exec_quasiquoted (tree t
);
213 tree
exec_copy (tree t
);
214 tree
exec_if (tree t
);
215 bool exec_until_if (tree t
, path p
, string var
, int level
);
216 tree
exec_case (tree t
);
217 bool exec_until_case (tree t
, path p
, string var
, int level
);
218 tree
exec_while (tree t
);
219 bool exec_until_while (tree t
, path p
, string var
, int level
);
220 tree
exec_for_each (tree t
);
221 tree
exec_use_package (tree t
);
222 tree
exec_use_module (tree t
);
224 tree
exec_or (tree t
);
225 tree
exec_xor (tree t
);
226 tree
exec_and (tree t
);
227 tree
exec_not (tree t
);
228 tree
exec_plus_minus (tree t
);
229 tree
exec_times_over (tree t
);
230 tree
exec_divide (tree t
);
231 tree
exec_modulo (tree t
);
232 tree
exec_math_sqrt (tree t
);
233 tree
exec_exp (tree t
);
234 tree
exec_log (tree t
);
235 tree
exec_pow (tree t
);
236 tree
exec_cos (tree t
);
237 tree
exec_sin (tree t
);
238 tree
exec_tan (tree t
);
239 tree
exec_merge (tree t
);
240 tree
exec_length (tree t
);
241 tree
exec_range (tree t
);
242 tree
exec_number (tree t
);
243 tree
exec_date (tree t
);
244 tree
exec_translate (tree t
);
245 tree
exec_change_case (tree t
, tree nc
, bool exec_flag
, bool first
);
246 tree
exec_change_case (tree t
);
247 tree
exec_find_file (tree t
);
248 tree
exec_is_tuple (tree t
);
249 tree
exec_lookup (tree t
);
250 tree
exec_equal (tree t
);
251 tree
exec_unequal (tree t
);
252 tree
exec_less (tree t
);
253 tree
exec_lesseq (tree t
);
254 tree
exec_greater (tree t
);
255 tree
exec_greatereq (tree t
);
257 tree
exec_cm_length ();
258 tree
exec_mm_length ();
259 tree
exec_in_length ();
260 tree
exec_pt_length ();
261 tree
exec_bp_length ();
262 tree
exec_dd_length ();
263 tree
exec_pc_length ();
264 tree
exec_cc_length ();
265 tree
exec_fs_length ();
266 tree
exec_fbs_length ();
267 tree
exec_em_length ();
268 tree
exec_ln_length ();
269 tree
exec_sep_length ();
270 tree
exec_yfrac_length ();
271 tree
exec_ex_length ();
272 tree
exec_fn_length ();
273 tree
exec_fns_length ();
274 tree
exec_bls_length ();
275 tree
exec_fnbot_length ();
276 tree
exec_fntop_length ();
277 tree
exec_spc_length ();
278 tree
exec_xspc_length ();
279 tree
exec_par_length ();
280 tree
exec_pag_length ();
281 tree
exec_tmpt_length ();
282 tree
exec_px_length ();
283 tree
exec_gw_length ();
284 tree
exec_gh_length ();
285 tree
exec_msec_length ();
286 tree
exec_sec_length ();
287 tree
exec_min_length ();
288 tree
exec_h_length ();
290 tree
exec_hard_id (tree t
);
291 tree
exec_script (tree t
);
292 tree
exec_set_binding (tree t
);
293 tree
exec_get_binding (tree t
);
295 tree
exec_pattern (tree t
);
297 tree
exec_point (tree t
);
298 tree
exec_box_info (tree t
);
299 tree
exec_frame_direct (tree t
);
300 tree
exec_frame_inverse (tree t
);
302 tree
exec_rewrite (tree t
);
303 bool exec_until_rewrite (tree t
, path p
, string var
, int level
);
304 tree
rewrite_inactive_arg (tree t
, tree var
, int i
, bool bl
, bool fl
);
305 tree
rewrite_inactive_raw_data (tree t
, tree var
, bool block
, bool flush
);
306 tree
rewrite_inactive_document (tree t
, tree var
, bool block
, bool flush
);
307 tree
rewrite_inactive_concat (tree t
, tree var
, bool block
, bool flush
);
308 tree
rewrite_inactive_value (tree t
, tree var
, bool block
, bool flush
);
309 tree
rewrite_inactive_arg (tree t
, tree var
, bool block
, bool flush
);
310 tree
rewrite_inactive_style_with (tree t
, tree var
, bool b
, bool f
, bool o
);
311 tree
rewrite_inactive_active (tree t
, tree var
, bool block
, bool flush
);
312 tree
rewrite_inactive_var_active (tree t
, tree var
, bool block
, bool flush
);
313 tree
rewrite_inactive_symbol (tree t
, tree var
, bool block
, bool flush
);
314 tree
rewrite_inactive_hybrid (tree t
, tree var
, bool block
, bool flush
);
315 tree
rewrite_inactive_default (tree t
, tree var
, bool block
, bool flush
);
316 tree
rewrite_inactive (tree t
, tree var
, bool block
, bool flush
);
317 tree
rewrite_inactive (tree t
, tree var
);
320 edit_env_rep (drd_info
& drd
,
322 hashmap
<string
,tree
>& local_ref
,
323 hashmap
<string
,tree
>& global_ref
,
324 hashmap
<string
,tree
>& local_aux
,
325 hashmap
<string
,tree
>& global_aux
);
326 void style_init_env ();
328 /* execution of trees and setting environment variables */
330 void exec_until (tree t
, path p
);
331 bool exec_until (tree t
, path p
, string var
, int level
);
332 string
exec_string (tree t
); /* should be inline */
333 tree
expand (tree t
, bool search_accessible
= false);
334 bool depends (tree t
, string s
, int level
);
335 tree
rewrite (tree t
);
337 inline void monitored_write (string s
, tree t
) {
338 back
->write_back (s
, env
); env (s
)= t
; }
339 inline void monitored_write_update (string s
, tree t
) {
340 back
->write_back (s
, env
); env (s
)= t
; update (s
); }
341 inline void write (string s
, tree t
) { env (s
)= t
; }
342 inline void write_update (string s
, tree t
) { env (s
)= t
; update (s
); }
343 inline tree
local_begin (string s
, tree t
) {
344 // tree r (env [s]); monitored_write_update (s, t); return r;
345 tree
& val
= env (s
); tree
r (val
); val
= t
; update (s
); return r
; }
346 inline void local_end (string s
, tree t
) {
347 env (s
)= t
; update (s
); }
348 inline tree
local_begin_script () {
349 return local_begin (MATH_LEVEL
, as_string (index_level
+1)); }
350 inline void local_end_script (tree t
) {
351 local_end (MATH_LEVEL
, t
); }
352 inline void assign (string s
, tree t
) {
353 tree
& val
= env (s
); t
= exec(t
); if (val
!= t
) {
354 back
->write_back (s
, env
); val
= t
; update (s
); } }
355 inline bool provides (string s
) { return env
->contains (s
); }
356 inline tree
read (string s
) { return env
[s
]; }
358 void write_default_env ();
359 void write_env (hashmap
<string
,tree
> user_env
);
360 void monitored_patch_env (hashmap
<string
,tree
> patch
);
361 void patch_env (hashmap
<string
,tree
> patch
);
362 void read_env (hashmap
<string
,tree
>& ret
);
363 void local_start (hashmap
<string
,tree
>& prev_back
);
364 void local_update (hashmap
<string
,tree
>& oldpat
, hashmap
<string
,tree
>& chg
);
365 void local_end (hashmap
<string
,tree
>& prev_back
);
367 /* updating environment variables */
368 void update_page_pars ();
369 void get_page_pars (SI
& w
, SI
& h
, SI
& ww
, SI
& hh
,
370 SI
& odd
, SI
& even
, SI
& top
, SI
& bottom
);
372 void update_color ();
374 void update_language ();
375 void update_geometry ();
376 void update_frame ();
377 void update_src_style ();
378 void update_src_special ();
379 void update_src_compact ();
380 void update_src_close ();
381 void update_dash_style ();
382 void update_line_arrows ();
384 void update (string env_var
);
387 bool is_length (string s
);
388 bool is_anylen (tree t
);
389 tree
tmlen_plus (tree t1
, tree t2
);
390 tree
tmlen_times (double sc
, tree t
);
391 tree
tmlen_over (tree t1
, tree t2
);
393 void get_length_unit (string l
, SI
& un
, string
& un_str
);
394 string
add_lengths (string l1
, string l2
);
395 string
multiply_length (double x
, string l
);
396 double divide_lengths (string l1
, string l2
);
398 tree
as_tmlen (tree t
);
399 SI
as_length (tree t
);
400 space
as_hspace (tree t
);
401 space
as_vspace (tree t
);
402 point
as_point (tree t
);
404 /* retrieving environment variables */
405 inline bool get_bool (string var
) {
407 if (is_compound (t
)) return false;
408 return as_bool (t
->label
); }
409 inline int get_int (string var
) {
411 if (is_compound (t
)) return 0;
412 return as_int (t
->label
); }
413 inline double get_double (string var
) {
415 if (is_compound (t
)) return 0.0;
416 return as_double (t
->label
); }
417 inline string
get_string (string var
) {
419 if (is_compound (t
)) return "";
421 inline SI
get_length (string var
) {
423 return as_length (t
); }
424 inline space
get_vspace (string var
) {
426 return as_vspace (t
); }
427 inline color
get_color (string var
) {
429 return named_color (as_string (t
)); }
431 friend class edit_env
;
432 friend tm_ostream
& operator << (tm_ostream
& out
, edit_env env
);
436 CONCRETE_NULL(edit_env
);
437 inline edit_env (edit_env_rep
* rep2
):
438 rep(rep2
) { INC_COUNT_NULL (this->rep
); }
439 edit_env (drd_info
& drd
,
441 hashmap
<string
,tree
>& local_ref
,
442 hashmap
<string
,tree
>& global_ref
,
443 hashmap
<string
,tree
>& local_aux
,
444 hashmap
<string
,tree
>& global_aux
);
446 CONCRETE_NULL_CODE(edit_env
);
448 tm_ostream
& operator << (tm_ostream
& out
, edit_env env
);
449 tree
texmacs_exec (edit_env env
, tree cmd
);
450 void extract_format (tree fm
, tree
* r
, int n
);
451 tree
load_inclusion (url u
); // implemented in tm_file.cpp
452 tree
tree_extents (tree t
);
453 bool is_percentage (tree t
, string s
);
454 bool is_percentage (tree t
);
455 double as_percentage (tree t
);
456 bool is_magnification (string s
);
457 double get_magnification (string s
);
459 #endif // defined ENV_H