Back to index

texmacs  1.0.7.15
bridge_rewrite.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : bridge_rewrite.cpp
00004 * DESCRIPTION: Bridge between logical and physical long macro expansions
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 "bridge.hpp"
00013 
00014 /******************************************************************************
00015 * The bridge_rewrite_rep class
00016 ******************************************************************************/
00017 
00018 class bridge_rewrite_rep: public bridge_rep {
00019 protected:
00020   bridge body;
00021 
00022 public:
00023   bridge_rewrite_rep (typesetter ttt, tree st, path ip);
00024   void initialize (tree body_t);
00025 
00026   void notify_assign (path p, tree u);
00027   bool notify_macro  (int type, string var, int l, path p, tree u);
00028   void notify_change ();
00029 
00030   void my_typeset (int desired_status);
00031 };
00032 
00033 bridge_rewrite_rep::bridge_rewrite_rep (typesetter ttt, tree st, path ip):
00034   bridge_rep (ttt, st, ip) {}
00035 
00036 void
00037 bridge_rewrite_rep::initialize (tree body_t) {
00038   if (is_nil (body)) body= make_bridge (ttt, attach_right (body_t, ip));
00039   else replace_bridge (body, attach_right (body_t, ip));
00040 }
00041 
00042 bridge
00043 bridge_rewrite (typesetter ttt, tree st, path ip) {
00044   return tm_new<bridge_rewrite_rep> (ttt, st, ip);
00045 }
00046 
00047 /******************************************************************************
00048 * Event notification
00049 ******************************************************************************/
00050 
00051 void
00052 bridge_rewrite_rep::notify_assign (path p, tree u) {
00053   // cout << "Assign " << p << ", " << u << " in " << st << "\n";
00054   status= CORRUPTED;
00055   st= substitute (st, p, u);
00056 }
00057 
00058 bool
00059 bridge_rewrite_rep::notify_macro (int tp, string v, int l, path p, tree u) {
00060   (void) tp; (void) p; (void) u;
00061   bool flag= env->depends (st, v, l);
00062   if (flag) status= CORRUPTED;
00063   return flag;
00064 }
00065 
00066 void
00067 bridge_rewrite_rep::notify_change () {
00068   status= CORRUPTED;
00069 }
00070 
00071 /******************************************************************************
00072 * Typesetting
00073 ******************************************************************************/
00074 
00075 void
00076 bridge_rewrite_rep::my_typeset (int desired_status) {
00077   initialize (env->rewrite (st));
00078   ttt->insert_marker (st, ip);
00079   if (is_func (st, INCLUDE)) {
00080     url save_name= env->cur_file_name;
00081     env->cur_file_name= relative (env->base_file_name, as_string (st[0]));
00082     env->secure= is_secure (env->cur_file_name);
00083     body->typeset (desired_status);
00084     env->cur_file_name= save_name;
00085     env->secure= is_secure (env->cur_file_name);
00086   }
00087   else body->typeset (desired_status);
00088 }