Back to index

texmacs  1.0.7.15
env.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : env.hpp
00004 * DESCRIPTION: edit environment for typesetting
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef ENV_H
00013 #define ENV_H
00014 #include "vars.hpp"
00015 #include "drd_info.hpp"
00016 #include "gui.hpp"
00017 #include "font.hpp"
00018 #include "language.hpp"
00019 #include "path.hpp"
00020 #include "hashmap.hpp"
00021 #include "boxes.hpp"
00022 #include "url.hpp"
00023 #include "Graphics/frame.hpp"
00024 #include "link.hpp"
00025 
00026 #define DECORATION (-1)
00027 
00028 /******************************************************************************
00029 * The different types of system environment variables
00030 ******************************************************************************/
00031 
00032 #define Env_User               0
00033 #define Env_Fixed              1
00034 #define Env_Magnification      2
00035 #define Env_Magnify            3
00036 #define Env_Language           4
00037 #define Env_Mode               5
00038 #define Env_Info_Level         6
00039 #define Env_Font               7
00040 #define Env_Font_Size          8
00041 #define Env_Index_Level        9
00042 #define Env_Display_Style     10
00043 #define Env_Math_Condensed    11
00044 #define Env_Vertical_Pos      12
00045 #define Env_Color             13
00046 #define Env_Paragraph         14
00047 #define Env_Page              15
00048 #define Env_Page_Extents      16
00049 #define Env_Preamble          17
00050 #define Env_Geometry          18
00051 #define Env_Frame             19
00052 #define Env_Line_Width        20
00053 #define Env_Grid              21
00054 #define Env_Grid_Aspect       22
00055 #define Env_Src_Style         23
00056 #define Env_Src_Special       24
00057 #define Env_Src_Compact       25
00058 #define Env_Src_Close         26
00059 #define Env_Point_Style       27
00060 #define Env_Dash_Style        28
00061 #define Env_Dash_Style_Unit   29
00062 #define Env_Fill_Color        30
00063 #define Env_Line_Arrows       31
00064 #define Env_Text_At_Halign    32
00065 #define Env_Text_At_Valign    33
00066 
00067 /******************************************************************************
00068 * For style file editing
00069 ******************************************************************************/
00070 
00071 #define STYLE_ANGULAR         0
00072 #define STYLE_SCHEME          1
00073 #define STYLE_LATEX           2
00074 #define STYLE_FUNCTIONAL      3
00075 
00076 #define SPECIAL_RAW           0
00077 #define SPECIAL_FORMAT        1
00078 #define SPECIAL_NORMAL        2
00079 #define SPECIAL_MAXIMAL       3
00080 
00081 #define COMPACT_ALL           0
00082 #define COMPACT_INLINE_ARGS   1
00083 #define COMPACT_INLINE_START  2
00084 #define COMPACT_INLINE        3
00085 #define COMPACT_NONE          4
00086 
00087 #define CLOSE_MINIMAL         0
00088 #define CLOSE_COMPACT         1
00089 #define CLOSE_LONG            2
00090 #define CLOSE_REPEAT          3
00091 
00092 #define INACTIVE_INLINE_RECURSE  0
00093 #define INACTIVE_INLINE_ONCE     1
00094 #define INACTIVE_INLINE_ERROR    2
00095 #define INACTIVE_BLOCK_RECURSE   3
00096 #define INACTIVE_BLOCK_ONCE      4
00097 #define INACTIVE_BLOCK_ERROR     5
00098 
00099 /******************************************************************************
00100 * Other enumerated values
00101 ******************************************************************************/
00102 
00103 #define INFO_NONE          0
00104 #define INFO_MINIMAL       1
00105 #define INFO_SHORT         2
00106 #define INFO_DETAILED      3
00107 #define INFO_PAPER         4
00108 
00109 #define FILL_MODE_NOTHING  0
00110 #define FILL_MODE_NONE     1
00111 #define FILL_MODE_INSIDE   2
00112 #define FILL_MODE_BOTH     3
00113 
00114 /******************************************************************************
00115 * The edit environment
00116 ******************************************************************************/
00117 
00118 class edit_env;
00119 class edit_env_rep: public concrete_struct {
00120 public:
00121   drd_info&                    drd;
00122 private:
00123   hashmap<string,tree>         env;
00124   hashmap<string,tree>         back;
00125 public:
00126   hashmap<string,path>         src;
00127   list<hashmap<string,tree> >  macro_arg;
00128   list<hashmap<string,path> >  macro_src;
00129   array<box>                   decorated_boxes;
00130 
00131   hashmap<string,int>&         var_type;
00132   url                          base_file_name;
00133   url                          cur_file_name;
00134   bool                         secure;
00135   hashmap<string,tree>&        local_ref;
00136   hashmap<string,tree>&        global_ref;
00137   hashmap<string,tree>&        local_aux;
00138   hashmap<string,tree>&        global_aux;
00139   bool                         complete;    // typeset complete document ?
00140   bool                         read_only;   // write-protected ?
00141   link_repository              link_env;
00142 
00143   int          dpi;
00144   double       inch;
00145   double       magn;
00146   double       mgfy;
00147   double       flexibility;
00148   int          mode;
00149   int          mode_op;
00150   language     lan;
00151   int          hl_lan;
00152   font         fn;
00153   int          fn_size;
00154   int          index_level;
00155   bool         display_style;
00156   bool         math_condensed;
00157   int          vert_pos;
00158   int          alpha;
00159   color        col;
00160   SI           lw;
00161   string       point_style;
00162   bool         preamble;
00163   int          info_level;
00164   SI           gw;
00165   SI           gh;
00166   string       gvalign;
00167   frame        fr;
00168   point        clip_lim1;
00169   point        clip_lim2;
00170   int          src_style;
00171   int          src_special;
00172   int          src_compact;
00173   int          src_close;
00174   array<bool>  dash_style;
00175   SI           dash_style_unit;
00176   int          fill_mode;
00177   color        fill_color;
00178   array<tree>  line_arrows;
00179   string       text_at_halign;
00180   string       text_at_valign;
00181  
00182   int          inactive_mode;
00183   tree         recover_env;
00184 
00185   string       page_type;
00186   bool         page_landscape;
00187   bool         page_automatic;
00188   int          page_margin_mode;
00189   SI           page_width;
00190   SI           page_height;
00191   SI           page_user_width;
00192   SI           page_user_height;
00193   SI           page_odd_margin;
00194   SI           page_even_margin;
00195   SI           page_right_margin;
00196   SI           page_top_margin;
00197   SI           page_bottom_margin;
00198 
00199 private:
00200   tree exec_formatting (tree t, string v);
00201   void exec_until_formatting (tree t, path p, string v);
00202   bool exec_until_formatting (tree t, path p, string var, int l, string v);
00203   tree exec_table (tree t);
00204   void exec_until_table (tree t, path p);
00205   bool exec_until_table (tree t, path p, string var, int level);
00206   tree exec_assign (tree t);
00207   tree exec_with (tree t);
00208   void exec_until_with (tree t, path p);
00209   bool exec_until_with (tree t, path p, string var, int level);
00210   tree exec_drd_props (tree t);
00211   tree exec_compound (tree t);
00212   void exec_until_compound (tree t, path p);
00213   bool exec_until_compound (tree t, path p, string var, int level);
00214   tree exec_provides (tree t);
00215   tree exec_value (tree t);
00216   tree exec_quote_value (tree t);
00217   tree exec_arg (tree t);
00218   bool exec_until_arg (tree t, path p, string var, int level);
00219   tree exec_quote_arg (tree t);
00220   tree exec_get_label (tree t);
00221   tree exec_get_arity (tree t);
00222   tree exec_eval_args (tree t);
00223   bool exec_until_mark (tree t, path p, string var, int level);
00224   bool exec_until_quasi (tree t, path p, string var, int level);
00225   tree exec_quasiquoted (tree t);
00226   tree exec_copy (tree t);
00227   tree exec_if (tree t);
00228   bool exec_until_if (tree t, path p, string var, int level);
00229   tree exec_case (tree t);
00230   bool exec_until_case (tree t, path p, string var, int level);
00231   tree exec_while (tree t);
00232   bool exec_until_while (tree t, path p, string var, int level);
00233   tree exec_for_each (tree t);
00234   tree exec_use_package (tree t);
00235   tree exec_use_module (tree t);
00236 
00237   tree exec_or (tree t);
00238   tree exec_xor (tree t);
00239   tree exec_and (tree t);
00240   tree exec_not (tree t);
00241   tree exec_plus_minus (tree t);
00242   tree exec_min_max (tree t);
00243   tree exec_times_over (tree t);
00244   tree exec_divide (tree t);
00245   tree exec_modulo (tree t);
00246   tree exec_math_sqrt (tree t);
00247   tree exec_exp (tree t);
00248   tree exec_log (tree t);
00249   tree exec_pow (tree t);
00250   tree exec_cos (tree t);
00251   tree exec_sin (tree t);
00252   tree exec_tan (tree t);
00253   tree exec_merge (tree t);
00254   tree exec_length (tree t);
00255   tree exec_range (tree t);
00256   tree exec_number (tree t);
00257   tree exec_date (tree t);
00258   tree exec_translate (tree t);
00259   tree exec_change_case (tree t, tree nc, bool exec_flag, bool first);
00260   tree exec_change_case (tree t);
00261   tree exec_find_file (tree t);
00262   tree exec_is_tuple (tree t);
00263   tree exec_lookup (tree t);
00264   tree exec_equal (tree t);
00265   tree exec_unequal (tree t);
00266   tree exec_less (tree t);
00267   tree exec_lesseq (tree t);
00268   tree exec_greater (tree t);
00269   tree exec_greatereq (tree t);
00270 
00271   tree exec_cm_length ();
00272   tree exec_mm_length ();
00273   tree exec_in_length ();
00274   tree exec_pt_length ();
00275   tree exec_bp_length ();
00276   tree exec_dd_length ();
00277   tree exec_pc_length ();
00278   tree exec_cc_length ();
00279   tree exec_fs_length ();
00280   tree exec_fbs_length ();
00281   tree exec_em_length ();
00282   tree exec_ln_length ();
00283   tree exec_sep_length ();
00284   tree exec_yfrac_length ();
00285   tree exec_ex_length ();
00286   tree exec_fn_length ();
00287   tree exec_fns_length ();
00288   tree exec_bls_length ();
00289   tree exec_fnbot_length ();
00290   tree exec_fntop_length ();
00291   tree exec_spc_length ();
00292   tree exec_xspc_length ();
00293   tree exec_par_length ();
00294   tree exec_pag_length ();
00295   tree exec_tmpt_length ();
00296   tree exec_px_length ();
00297   tree exec_gw_length ();
00298   tree exec_gh_length ();
00299   tree exec_msec_length ();
00300   tree exec_sec_length ();
00301   tree exec_min_length ();
00302   tree exec_hr_length ();
00303 
00304   tree exec_hard_id (tree t);
00305   tree exec_script (tree t);
00306   tree exec_set_binding (tree t);
00307   tree exec_get_binding (tree t);
00308 
00309   tree exec_pattern (tree t);
00310 
00311   tree exec_point (tree t);
00312   tree exec_box_info (tree t);
00313   tree exec_frame_direct (tree t);
00314   tree exec_frame_inverse (tree t);
00315 
00316   tree exec_rewrite (tree t);
00317   bool exec_until_rewrite (tree t, path p, string var, int level);
00318   tree rewrite_inactive_arg (tree t, tree var, int i, bool bl, bool fl);
00319   tree rewrite_inactive_raw_data (tree t, tree var, bool block, bool flush);
00320   tree rewrite_inactive_document (tree t, tree var, bool block, bool flush);
00321   tree rewrite_inactive_concat (tree t, tree var, bool block, bool flush);
00322   tree rewrite_inactive_value (tree t, tree var, bool block, bool flush);
00323   tree rewrite_inactive_arg (tree t, tree var, bool block, bool flush);
00324   tree rewrite_inactive_style_with (tree t, tree var, bool b, bool f, bool o);
00325   tree rewrite_inactive_active (tree t, tree var, bool block, bool flush);
00326   tree rewrite_inactive_var_active (tree t, tree var, bool block, bool flush);
00327   tree rewrite_inactive_symbol (tree t, tree var, bool block, bool flush);
00328   tree rewrite_inactive_hybrid (tree t, tree var, bool block, bool flush);
00329   tree rewrite_inactive_default (tree t, tree var, bool block, bool flush);
00330   tree rewrite_inactive (tree t, tree var, bool block, bool flush);
00331   tree rewrite_inactive (tree t, tree var);
00332 
00333 public:
00334   edit_env_rep (drd_info& drd,
00335               url base_file_name,
00336               hashmap<string,tree>& local_ref,
00337               hashmap<string,tree>& global_ref,
00338               hashmap<string,tree>& local_aux,
00339               hashmap<string,tree>& global_aux);
00340   void   style_init_env ();
00341 
00342   /* execution of trees and setting environment variables */
00343   tree   exec (tree t);
00344   void   exec_until (tree t, path p);
00345   bool   exec_until (tree t, path p, string var, int level);
00346   string exec_string (tree t);        /* should be inline */
00347   tree   expand (tree t, bool search_accessible= false);
00348   bool   depends (tree t, string s, int level);
00349   tree   rewrite (tree t);
00350 
00351   inline void monitored_write (string s, tree t) {
00352     back->write_back (s, env); env (s)= t; }
00353   inline void monitored_write_update (string s, tree t) {
00354     back->write_back (s, env); env (s)= t; update (s); }
00355   inline void write (string s, tree t) { env (s)= t; }
00356   inline void write_update (string s, tree t) { env (s)= t; update (s); }
00357   inline tree local_begin (string s, tree t) {
00358     // tree r (env [s]); monitored_write_update (s, t); return r;
00359     tree& val= env (s); tree r (val); val= t; update (s); return r; }
00360   inline void local_end (string s, tree t) {
00361      env (s)= t; update (s); }
00362   inline tree local_begin_script () {
00363     return local_begin (MATH_LEVEL, as_string (index_level+1)); }
00364   inline void local_end_script (tree t) {
00365     local_end (MATH_LEVEL, t); }
00366   inline void assign (string s, tree t) {
00367     tree& val= env (s); t= exec(t); if (val != t) {
00368       back->write_back (s, env); val= t; update (s); } }
00369   inline bool provides (string s) { return env->contains (s); }
00370   inline tree read (string s) { return env [s]; }
00371   tree local_begin_extents (box b);
00372   void local_end_extents (tree t);
00373 
00374   void write_default_env ();
00375   void write_env (hashmap<string,tree> user_env);
00376   void monitored_patch_env (hashmap<string,tree> patch);
00377   void patch_env (hashmap<string,tree> patch);
00378   void read_env (hashmap<string,tree>& ret);
00379   void local_start (hashmap<string,tree>& prev_back);
00380   void local_update (hashmap<string,tree>& oldpat, hashmap<string,tree>& chg);
00381   void local_end (hashmap<string,tree>& prev_back);
00382 
00383   /* updating environment variables */
00384   void   update_page_pars ();
00385   void   get_page_pars (SI& w, SI& h, SI& ww, SI& hh,
00386                      SI& odd, SI& even, SI& top, SI& bottom);
00387   tree   decode_arrow (tree t, string l, string h);
00388   void   update_font ();
00389   void   update_color ();
00390   void   update_mode ();
00391   void   update_info_level ();
00392   void   update_language ();
00393   void   update_geometry ();
00394   void   update_frame ();
00395   void   update_src_style ();
00396   void   update_src_special ();
00397   void   update_src_compact ();
00398   void   update_src_close ();
00399   void   update_dash_style ();
00400   void   update_line_arrows ();
00401   void   update ();
00402   void   update (string env_var);
00403 
00404   /* lengths */
00405   bool      is_length (string s);
00406   bool      is_anylen (tree t);
00407   tree      tmlen_plus (tree t1, tree t2);
00408   tree      tmlen_min (tree t1, tree t2);
00409   tree      tmlen_max (tree t1, tree t2);
00410   tree      tmlen_times (double sc, tree t);
00411   tree      tmlen_over (tree t1, tree t2);
00412   double    tmlen_div (tree t1, tree t2);
00413   tree      tmlen_mod (tree t1, tree t2);
00414 
00415   void      get_length_unit (string l, SI& un, string& un_str);
00416   string    add_lengths (string l1, string l2);
00417   string    multiply_length (double x, string l);
00418   double    divide_lengths (string l1, string l2);
00419 
00420   tree      as_tmlen (tree t);
00421   SI        as_length (tree t);
00422   SI        as_length (tree t, string perc);
00423   space     as_hspace (tree t);
00424   space     as_vspace (tree t);
00425   point     as_point (tree t);
00426 
00427   /* retrieving environment variables */
00428   inline bool get_bool (string var) {
00429     tree t= env [var];
00430     if (is_compound (t)) return false;
00431     return as_bool (t->label); }
00432   inline int get_int (string var) {
00433     tree t= env [var];
00434     if (is_compound (t)) return 0;
00435     return as_int (t->label); }
00436   inline double get_double (string var) {
00437     tree t= env [var];
00438     if (is_compound (t)) return 0.0;
00439     return as_double (t->label); }
00440   inline string get_string (string var) {
00441     tree t= env [var];
00442     if (is_compound (t)) return "";
00443     return t->label; }
00444   inline SI get_length (string var) {
00445     tree t= env [var];
00446     return as_length (t); }
00447   inline space get_vspace (string var) {
00448     tree t= env [var];
00449     return as_vspace (t); }
00450   inline color get_color (string var) {
00451     tree t= env [var];
00452     return named_color (as_string (t), alpha); }
00453 
00454   friend class edit_env;
00455   friend tm_ostream& operator << (tm_ostream& out, edit_env env);
00456 };
00457 
00458 class edit_env {
00459   CONCRETE_NULL(edit_env);
00460   inline edit_env (edit_env_rep* rep2):
00461     rep(rep2) { INC_COUNT_NULL (this->rep); }
00462   edit_env (drd_info& drd,
00463            url base_file_name,
00464            hashmap<string,tree>& local_ref,
00465            hashmap<string,tree>& global_ref,
00466            hashmap<string,tree>& local_aux,
00467            hashmap<string,tree>& global_aux);
00468 };
00469 CONCRETE_NULL_CODE(edit_env);
00470 
00471 tm_ostream& operator << (tm_ostream& out, edit_env env);
00472 tree texmacs_exec (edit_env env, tree cmd);
00473 void extract_format (tree fm, tree* r, int n);
00474 tree load_inclusion (url u); // implemented in tm_file.cpp
00475 tree tree_extents (tree t);
00476 bool is_percentage (tree t, string s);
00477 bool is_percentage (tree t);
00478 double as_percentage (tree t);
00479 bool is_magnification (string s);
00480 double get_magnification (string s);
00481 int decode_alpha (string s);
00482 
00483 void set_graphical_value (tree var, tree val);
00484 bool has_graphical_value (tree var);
00485 tree get_graphical_value (tree var);
00486 bool graphics_needs_update ();
00487 void graphics_require_update (tree var);
00488 void graphics_notify_update (tree var);
00489 
00490 #endif // defined ENV_H