Back to index

texmacs  1.0.7.15
Classes | Functions
fromtm.cpp File Reference
#include "convert.hpp"
#include "path.hpp"
#include "vars.hpp"
#include "drd_std.hpp"

Go to the source code of this file.

Classes

struct  tm_reader

Functions

static void get_collection (tree &u, tree t)
static void flush (tree &D, tree &C, string &S, bool &spc_flag, bool &ret_flag)
tree texmacs_to_tree (string s)
tree texmacs_to_tree (string s, string version)
static bool is_apply (tree t, string s, int n)
static bool is_expand (tree t, string s, int n)
tree texmacs_document_to_tree (string s)
tree extract (tree doc, string attr)
tree extract_document (tree doc)
tree change_doc_attr (tree doc, string attr, tree val)

Function Documentation

tree change_doc_attr ( tree  doc,
string  attr,
tree  val 
)

Definition at line 498 of file fromtm.cpp.

                                                  {
  int i, n= arity (doc);
  tree r (doc, n);
  bool done= false;
  for (i=0; i<n; i++)
    if (is_compound (doc[i], attr, 1)) {
      r[i]= tree (L(doc[i]), val);
      done= true;
    }
    else r[i]= doc[i];
  if (!done) r << compound (attr, val);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree extract ( tree  doc,
string  attr 
)

Definition at line 422 of file fromtm.cpp.

                                {
  int i, n= arity (doc);
  for (i=0; i<n; i++)
    if (is_compound (doc[i], attr, 1) ||
       is_expand (doc[i], attr, 1) ||
       is_apply (doc[i], attr, 1))
      {
       tree r= doc[i][N(doc[i])-1];
       if ((attr == "body") && (!is_document (r))) return tree (DOCUMENT, r);
       if (attr == "style") {
         if (r == "none") return tree (TUPLE);
         if (r == "") return tree (TUPLE);
         if (r == "style") return tree (TUPLE);
         if (is_atomic (r)) return tree (TUPLE, r);
         if (!is_func (r, TUPLE)) return tree (TUPLE);
       }
       return r;
      }

  if (attr == "TeXmacs") return "";
  if (attr == "body") return tree (DOCUMENT, "");
  if (attr == "project") return "";
  if (attr == "style") return tree (TUPLE);
  if (attr == "initial") return tree (COLLECTION);
  if (attr == "final") return tree (COLLECTION);
  if (attr == "references") return tree (COLLECTION);
  if (attr == "auxiliary") return tree (COLLECTION);
  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 453 of file fromtm.cpp.

                            {
  if (is_func (doc, ERROR)) return doc;
  tree body= extract (doc, "body");
  tree init= extract (doc, "initial");
  if (is_func (init, COLLECTION)) {
    tree w (WITH);
    int i, n= N(init);
    for (i=0; i<n; i++)
      if (is_func (init[i], ASSOCIATE, 2)) {
       tree l= init[i][0];
       tree r= init[i][1];
       if ((l == PAGE_MEDIUM) ||
           (l == PAGE_PRINTED) ||
           (l == PAGE_TYPE) ||
           (l == PAGE_ORIENTATION) ||
           (l == PAGE_WIDTH_MARGIN) ||
           (l == PAGE_SCREEN_MARGIN) ||
           (l == PAGE_NR) ||
           (l == PAGE_WIDTH) ||
           (l == PAGE_HEIGHT) ||
           (l == PAGE_ODD) ||
           (l == PAGE_EVEN) ||
           (l == PAGE_RIGHT) ||
           (l == PAGE_ODD_SHIFT) ||
           (l == PAGE_EVEN_SHIFT) ||
           (l == PAGE_TOP) ||
           (l == PAGE_BOT) ||
           (l == PAGE_SCREEN_WIDTH) ||
           (l == PAGE_SCREEN_HEIGHT) ||
           (l == PAGE_SCREEN_LEFT) ||
           (l == PAGE_SCREEN_RIGHT) ||
           (l == PAGE_SCREEN_TOP) ||
           (l == PAGE_SCREEN_BOT) ||
           (l == PAGE_SHOW_HF)) continue;
       w << l << r;
      }
    if (N(w)>0) {
      w << body;
      body= w;
    }
  }
  return body;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void flush ( tree D,
tree C,
string S,
bool &  spc_flag,
bool &  ret_flag 
) [static]

Definition at line 220 of file fromtm.cpp.

                                                                    {
  if (spc_flag) S << " ";
  if (S != "") {
    if ((N(C) == 0) || (!is_atomic (C[N(C)-1]))) C << S;
    else C[N(C)-1]->label << S;
    S= "";
    spc_flag= false;
  }

  if (ret_flag) {
    if (N(C) == 0) D << "";
    else if (N(C) == 1) D << C[0];
    else D << C;
    C= tree (CONCAT);
    ret_flag= false;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void get_collection ( tree u,
tree  t 
) [static]

Definition at line 177 of file fromtm.cpp.

                                 {
  if (is_func (t, COLLECTION) ||
          is_func (t, DOCUMENT) ||
          is_func (t, CONCAT)) {
    int i;
    for (i=0; i<N(t); i++)
      get_collection (u, t[i]);
  }
  else if (is_compound (t)) u << t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool is_apply ( tree  t,
string  s,
int  n 
) [static]

Definition at line 351 of file fromtm.cpp.

                                   {
  return (L(t) == APPLY) && (N(t) == n+1) && (t[0] == s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool is_expand ( tree  t,
string  s,
int  n 
) [static]

Definition at line 356 of file fromtm.cpp.

                                    {
  return (L(t) == EXPAND) && (N(t) == n+1) && (t[0] == s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 361 of file fromtm.cpp.

                                    {
  tree error (ERROR, "bad format or data");
  if (starts (s, "edit") ||
      starts (s, "TeXmacs") ||
      starts (s, "\\(\\)(TeXmacs"))
  {
    string version= "0.0.0.0";
    tree t= string_to_tree (s, version);
    if (is_tuple (t) && (N(t)>0)) t= t (1, N(t));
    int n= arity (t);

    tree doc (DOCUMENT);
    doc << compound ("TeXmacs", version);
    if (n<3) return error;
    else if (n<4)
      doc << compound ("body", t[2])
         << compound ("style", t[0])
         << compound ("initial", t[1]);
    else if (n<7)
      doc << compound ("body", t[0])
         << compound ("style", t[1])
         << compound ("initial", t[2])
         << compound ("references", t[3]);
    else
      doc << compound ("body", t[0])
         << compound ("project", t[1])
         << compound ("style", t[2])
         << compound ("initial", t[3])
         << compound ("final", t[4])
         << compound ("references", t[5])
         << compound ("auxiliary", t[6]);
    return upgrade (doc, version);
  }

  if (starts (s, "<TeXmacs|")) {
    int i;
    for (i=9; i<N(s); i++)
      if (s[i] == '>') break;
    string version= s (9, i);
    tree doc= texmacs_to_tree (s, version);
    if (is_compound (doc, "TeXmacs", 1) ||
       is_expand (doc, "TeXmacs", 1) ||
       is_apply (doc, "TeXmacs", 1))
      doc= tree (DOCUMENT, doc);
    if (!is_document (doc)) return error;
    if (N(doc) == 0 || !is_compound (doc[0], "TeXmacs", 1)) {
      tree d (DOCUMENT);
      d << compound ("TeXmacs", version);
      d << A(doc);
      doc= d;
    }
    return upgrade (doc, version);
  }
  return error;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 335 of file fromtm.cpp.

                           {
  tm_reader tmr (s);
  return tmr.read (true);
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree texmacs_to_tree ( string  s,
string  version 
)

Definition at line 341 of file fromtm.cpp.

                                           {
  tm_reader tmr (s, version);
  return tmr.read (true);
}

Here is the call graph for this function: