Back to index

texmacs  1.0.7.15
env.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : env.cpp
00004 * DESCRIPTION: the environment of the math_editor
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 #include "env.hpp"
00013 #include "iterator.hpp"
00014 extern hashmap<string,int> default_var_type;
00015 void initialize_default_var_type ();
00016 extern hashmap<string,tree> default_env;
00017 void initialize_default_env ();
00018 #include "page_type.hpp"
00019 
00020 /******************************************************************************
00021 * Initialization
00022 ******************************************************************************/
00023 
00024 edit_env_rep::edit_env_rep (drd_info& drd2,
00025                          url base_file_name2,
00026                          hashmap<string,tree>& local_ref2,
00027                          hashmap<string,tree>& global_ref2,
00028                          hashmap<string,tree>& local_aux2,
00029                          hashmap<string,tree>& global_aux2):
00030   drd (drd2),
00031   env (UNINIT), back (UNINIT), src (path (DECORATION)),
00032   var_type (default_var_type),
00033   base_file_name (base_file_name2),
00034   cur_file_name (base_file_name2),
00035   secure (is_secure (base_file_name2)),
00036   local_ref (local_ref2), global_ref (global_ref2),
00037   local_aux (local_aux2), global_aux (global_aux2)
00038 {
00039   initialize_default_env ();
00040   initialize_default_var_type ();
00041   env= copy (default_env);
00042   style_init_env ();
00043   update ();
00044   complete= false;
00045   recover_env= tuple ();
00046 }
00047 
00048 edit_env::edit_env (drd_info& drd,
00049                   url base_file_name,
00050                   hashmap<string,tree>& local_ref,
00051                   hashmap<string,tree>& global_ref,
00052                   hashmap<string,tree>& local_aux,
00053                   hashmap<string,tree>& global_aux):
00054   rep (tm_new<edit_env_rep> (drd, base_file_name,
00055                       local_ref, global_ref, local_aux, global_aux)) {}
00056 
00057 void
00058 edit_env_rep::style_init_env () {
00059   dpi = get_int (DPI);
00060   inch= ((double) dpi*PIXEL);
00061   flexibility= get_double (PAGE_FLEXIBILITY);
00062   back= hashmap<string,tree> (UNINIT);
00063   update_page_pars ();
00064 }
00065 
00066 /******************************************************************************
00067 * Modification of environment variables
00068 ******************************************************************************/
00069 
00070 /*
00071 void
00072 edit_env_rep::set (string s, tree t) {
00073   // cout << "Set " << s << " := " << t << "\n";
00074   tree r= exec (t); // Replacing r by exec(t) below yields bug when optimizing
00075   // cout << "Do " << s << " := " << r << "\n";
00076   monitored_write (s, tree (BACKUP, r, read(s)));
00077   update (s);
00078 }
00079 
00080 void
00081 edit_env_rep::reset (string s) {
00082   // cout << "Reset " << s << "\n";
00083   if (is_func (read(s), BACKUP, 2)) monitored_write (s, read(s)[1]);
00084   update (s);
00085 }
00086 
00087 void
00088 edit_env_rep::assign (string s, tree t) {
00089   // cout << "Assign " << s << " := " << t << "\n";
00090   t= exec (t);
00091   // cout << "Do     " << s << " := " << t << "\n";
00092   if (is_func (read(s), BACKUP, 2)) {
00093     if (read(s)[0] != t) {
00094       monitored_write (s, tree (BACKUP, t, read(s)[1]));
00095       update (s);
00096     }
00097   }
00098   else {
00099     if (read(s) != t) {
00100       monitored_write (s, t);
00101       update (s);
00102     }
00103   }
00104 }
00105 */
00106 
00107 tree
00108 edit_env_rep::local_begin_extents (box b) {
00109   tree old= tree (TUPLE,
00110                 env ["w-length"], env ["h-length"],
00111                 env ["l-length"], env ["b-length"],
00112                 env ["r-length"], env ["t-length"]);
00113   env ("w-length")= as_string (b->w ()) * "tmpt";
00114   env ("h-length")= as_string (b->h ()) * "tmpt";
00115   env ("l-length")= as_string (b->x1) * "tmpt";
00116   env ("b-length")= as_string (b->y1) * "tmpt";
00117   env ("r-length")= as_string (b->x2) * "tmpt";
00118   env ("t-length")= as_string (b->y2) * "tmpt";
00119   return old;
00120 }
00121 
00122 void
00123 edit_env_rep::local_end_extents (tree t) {
00124   env ("w-length")= t[0];
00125   env ("h-length")= t[1];
00126   env ("l-length")= t[2];
00127   env ("b-length")= t[3];
00128   env ("r-length")= t[4];
00129   env ("t-length")= t[5];
00130 }
00131 
00132 /******************************************************************************
00133 * Global manipulations of the environment
00134 ******************************************************************************/
00135 
00136 void
00137 edit_env_rep::write_default_env () {
00138   env= copy (default_env);
00139 }
00140 
00141 void
00142 edit_env_rep::write_env (hashmap<string,tree> user_env) {
00143   env= copy (user_env);
00144 }
00145 
00146 void
00147 edit_env_rep::monitored_patch_env (hashmap<string,tree> patch) {
00148   if (patch->size == 0) return;
00149   int i=0, n=patch->n;
00150   for (; i<n; i++) {
00151     list<hashentry<string,tree> > l=patch->a[i];
00152     for (; !is_nil(l); l=l->next)
00153       monitored_write_update (l->item.key, l->item.im);
00154   }
00155 }
00156 
00157 void
00158 edit_env_rep::patch_env (hashmap<string,tree> patch) {
00159   if (patch->size == 0) return;
00160   int i=0, n=patch->n;
00161   for (; i<n; i++) {
00162     list<hashentry<string,tree> > l=patch->a[i];
00163     for (; !is_nil(l); l=l->next)
00164       write_update (l->item.key, l->item.im);
00165   }
00166 }
00167 
00168 void
00169 edit_env_rep::read_env (hashmap<string,tree>& ret) {
00170   ret= copy (env);
00171 }
00172 
00173 void
00174 edit_env_rep::local_start (hashmap<string,tree>& prev_back) {
00175   prev_back= back;
00176   back= hashmap<string,tree> (UNINIT);  
00177 }
00178 
00179 void
00180 edit_env_rep::local_update (hashmap<string,tree>& old_patch,
00181                          hashmap<string,tree>& change)
00182 {
00183   old_patch->pre_patch (back, env);
00184   old_patch->post_patch (change, env);
00185   change= invert (back, env);
00186 }
00187 
00188 void
00189 edit_env_rep::local_end (hashmap<string,tree>& prev_back) {
00190   int i=0, n=back->n;
00191   for (; i<n; i++) {
00192     list<hashentry<string,tree> > l=back->a[i];
00193     for (; !is_nil(l); l=l->next)
00194       prev_back->write_back (l->item.key, back);
00195   }
00196   back= prev_back;
00197 }
00198 
00199 tm_ostream&
00200 operator << (tm_ostream& out, edit_env env) {
00201   return out << env->env;
00202 }