Esempio n. 1
0
url
delta_sub (url base, url u) {
  if (is_atomic (base))
    return u;
  if (is_concat (base) && is_concat (u) && (base[1] == u[1])) {
    if (is_special_root (base[1]) &&
	is_concat (base[2]) && is_concat (u[2]) &&
	base[2][1] != u[2][1])
      return url_none ();
    return delta_sub (base[2], u[2]);
  }
  if (is_concat (base) && !is_semi_root (base))
    return url_parent () * delta_sub (head (base), u);
  return url_none ();
}
Esempio n. 2
0
url
resolve_tex (url name) {
  string s= as_string (name);
  if (is_cached ("font_cache.scm", s)) {
    url u= url_system (cache_get ("font_cache.scm", s) -> label);
    if (exists (u)) return u;
    cache_reset ("font_cache.scm", s);
  }

  bench_start ("resolve tex");
  url u= url_none ();
  if (ends (s, "mf" )) {
    u= resolve_tfm (name);
#ifdef OS_WIN32
    if (is_none (u))
      u= resolve_tfm (replace (s, ".mf", ".tfm"));
#endif
  }
  if (ends (s, "tfm")) u= resolve_tfm (name);
  if (ends (s, "pk" )) u= resolve_pk  (name);
  if (ends (s, "pfb")) u= resolve_pfb (name);
  bench_cumul ("resolve tex");

  if (!is_none (u)) cache_set ("font_cache.scm", s, as_string (u));
  //cout << "Resolve " << name << " -> " << u << "\n";
  return u;
}
Esempio n. 3
0
static void
init_main_paths () {
#ifdef __MINGW32__
  if (is_none (get_env_path ("TEXMACS_HOME_PATH", get_env ("APPDATA") * "/TeXmacs"))) {
#else
  if (is_none (get_env_path ("TEXMACS_HOME_PATH", "~/.TeXmacs"))) {
#endif
    boot_error << "\n";
    boot_error << "Installation problem: please send a bug report.\n";
    boot_error << "'TEXMACS_HOME_PATH' could not be set to '~/.TeXmacs'.\n";
    boot_error << "You may try to set this environment variable manually\n";
    boot_error << "\n";
    FAILED ("installation problem");
    exit (1);
  }
}

/******************************************************************************
* Directory for temporary files
******************************************************************************/

static string main_tmp_dir= "$TEXMACS_HOME_PATH/system/tmp";

static void
make_dir (url which) {
  if (!is_directory (which)) {
    make_dir (head (which));
    mkdir (which);
  }
}

static url
url_temp_dir_sub () {
#ifdef __MINGW32__
  static url tmp_dir=
    url_system (main_tmp_dir) * url_system (as_string (time (NULL)));
#else
  static url tmp_dir=
    url_system (main_tmp_dir) * url_system (as_string ((int) getpid ()));
#endif
  return (tmp_dir);
}

url
url_temp_dir () {
  static url u;
  if (u == url_none()) {
    u= url_temp_dir_sub ();
    make_dir (u);
  }
  return u;
}

bool
process_running (int pid) {
  string cmd= "ps -p " * as_string (pid);
  string ret= eval_system (cmd);
  return occurs ("texmacs", ret) && occurs (as_string (pid), ret);
}
Esempio n. 4
0
url
get_from_web (url name) {
    if (!is_rooted_web (name)) return url_none ();
    url res= get_cache (name);
    if (!is_none (res)) return res;

#ifdef OS_WIN32
    string urlString = as_string (name);
    url tmp = url_temp();

    if (starts (urlString, "www."))
        urlString = "http://" * urlString;
    else if (starts (urlString, "ftp."))
        urlString = "ftp://" * urlString;
    else if (starts (urlString, "ftp://"))
        urlPath = NULL;
    else if (starts (urlString, "http://"))
        urlPath = NULL;
    else
        urlString = "http://" * urlString;
    urlString= web_encode (urlString);

    c_string urlPath (urlString);
    c_string tempFilePath (as_string (tmp));

    if(!URL_Get(urlPath, tempFilePath))
        return url_none();
    else return set_cache (name, tmp);
#else
    string test= var_eval_system ("which wget");
    if (!ends (test, "wget")) return url_none ();
    url tmp= url_temp ();
    string tmp_s= escape_sh (concretize (tmp));
    string cmd= "wget --header='User-Agent: TeXmacs-" TEXMACS_VERSION "' -q";
    cmd << " -O " << tmp_s << " " << escape_sh (web_encode (as_string (name)));
    // cout << cmd << "\n";
    system (cmd);
    // cout << "got " << name << " as " << tmp << "\n";

    if (var_eval_system ("cat " * tmp_s * " 2> /dev/null") == "") {
        remove (tmp);
        return url_none ();
    }
    else return set_cache (name, tmp);
#endif
}
Esempio n. 5
0
url
get_from_ramdisc (url u) {
    if (!is_ramdisc (u)) return url_none ();
    url res= get_cache (u);
    if (!is_none (res)) return (res);
    url tmp= url_temp (string (".") * suffix (u));
    save_string (tmp, u[1][2]->t->label);
    return set_cache (u, tmp);
}
Esempio n. 6
0
tm_window_rep::tm_window_rep (tree doc, command quit):
    win (texmacs_widget (0, quit)),
    wid (win), id (url_none ()),
    serial (tm_window_serial++),
    menu_current (object ()), menu_cache (widget ()),
    text_ptr (NULL)
{
    (void) doc;
    zoomf= get_server () -> get_default_zoom_factor ();
}
Esempio n. 7
0
void
reset_pfb_path () {
  string pfb= get_setting ("PFB");
  the_pfb_path=
    url_here () |
    search_sub_dirs ("$TEXMACS_HOME_PATH/fonts/type1") |
    search_sub_dirs ("$TEXMACS_PATH/fonts/type1") |
    "$TEX_PFB_PATH" |
    (pfb == ""? url_none (): url_system (pfb));
  the_pfb_path= expand (factor (the_pfb_path));
}
Esempio n. 8
0
static url
url_get_path (string s, int type= URL_STANDARD, int i=0) {
  char sep= (type == URL_SYSTEM)? URL_SEPARATOR: ':';
  int start= i, n= N(s);
  if (i == n) return url_none ();
  while ((i<n) && (s[i] != sep)) i++;
  url u= url_general (s (start, i), type);
  if (i == n) return u;
  if (start == i) return url_get_path (s, type, i+1);
  return u | url_get_path (s, type, i+1);
}
Esempio n. 9
0
static url
get_kpsepath (string s) {
  // FIXME: adapt to WIN32
  if (get_setting ("KPSEPATH") != "true") return url_none ();
  string r= var_eval_system ("kpsepath " * s);
  if (N(r)==0) return url_none ();

  int i, start, end;
  url p= url_none ();
  for (i=0; i<N(r); i++) {
    while ((i<N(r)) && (r[i]=='!')) i++;
    start=i;
    while ((i<N(r)) && (r[i]!=':')) i++;
    end=i;
    while ((end>start) && (r[end-1]=='/')) end--;
    string dir= r (start, end);
    if (dir == ".") continue;
    p= expand (complete (dir * url_wildcard (), "dr")) | p;
  }
  return p;
}
Esempio n. 10
0
url
find_bib_file (url base, string fname,
               string suffix= ".bib", bool rooted= false) {
  if (!ends (fname, suffix)) fname= fname * suffix;
  url bibf (fname);
  if (exists (bibf) && (!rooted || is_rooted (bibf)))
    return bibf;
  if (exists (relative (base, bibf)))
    return relative (base, bibf);
  if (exists (expand (relative (base, url_ancestor () * bibf))))
    return resolve (expand (relative (base, url_ancestor () * bibf)));
  return url_none ();
}
Esempio n. 11
0
url
get_from_server (url u) {
    if (!is_rooted_tmfs (u)) return url_none ();
    url res= get_cache (u);
    if (!is_none (res)) return res;

    string name= as_string (u);
    if (ends (name, "~") || ends (name, "#")) {
        if (!is_rooted_tmfs (name)) return url_none ();
        if (!as_bool (call ("tmfs-can-autosave?", unglue (u, 1))))
            return url_none ();
    }
    string r= as_string (call ("tmfs-load", object (name)));
    if (r == "") return url_none ();
    url tmp= url_temp ();
    (void) save_string (tmp, r, true);

    //return set_cache (u, tmp);
    return tmp;
    // FIXME: certain files could be cached, but others not
    // for instance, files which are loaded in a delayed fashion
    // would always be cached as empty files, which is erroneous.
}
Esempio n. 12
0
url
operator * (url u1, url u2) {
  //cout << "concat " << u1->t << " * " << u2->t << "\n";
  if (is_root (u2) || (is_concat (u2) && is_root (u2[1]))) {
    if (is_concat (u1) && is_root_web (u1[1])) {
      if (is_root (u2, "default") ||
          (is_concat (u2) && is_root (u2[1], "default")))
        {
          url v= u1[2];
          while (is_concat (v)) v= v[1];
          if (is_root (u2)) return u1[1] * v;
          return u1[1] * v * u2[2];
        }
      if (is_root (u2, "blank") ||
          (is_concat (u2) && is_root (u2[1], "blank")))
        return reroot (u2, u1[1][1]->t->label);
    }
    return u2;
  }
  if (is_here (u1) || (u1->t == "")) return u2;
  if (is_here (u2)) return u1;
  if (is_none (u1)) return url_none ();
  if (is_none (u2)) return url_none ();
  if (u2 == url_parent ()) {
    if (is_root (u1)) return u1;
    if (is_pseudo_atomic (u1) && (!is_parent (u1))) return url_here ();
    if (is_semi_root (u1)) return u1;
  }
  if (is_concat (u2) && (u2[1] == url_parent ())) {
    if (is_root (u1)) return u1 * u2[2];
    if (is_pseudo_atomic (u1) && (!is_parent (u1))) return u2[2];
    if (is_semi_root (u1)) return u1 * u2[2];
  }
  if (is_concat (u1)) return u1[1] * (u1[2] * u2);
  return as_url (tuple ("concat", u1->t, u2->t));
}
Esempio n. 13
0
static url
url_get_atom (string s, int type) {
  if (type < URL_STANDARD) {
    if (s == "~") return url_system (get_env ("HOME"));
    if (starts (s, "$")) {
      string val= get_env (s (1, N(s)));
      if (val == "") return url_none ();
      return unblank (url_system (val));
    }
  }
  if (occurs ("*", s)) return url_wildcard (s);
#ifdef WINPATHS
  if(N(s)==2 && ends (s, ":")) s->resize(1);	// remove the ':' after unit letter
#endif
  return as_url (tree (s));
}
Esempio n. 14
0
void
reset_pk_path (bool rehash) { (void) rehash;
  // if (rehash && (get_setting ("TEXHASH") == "true")) system ("texhash");
  string pk= get_setting ("PK");
  the_pk_path=
    url_here () |
    search_sub_dirs ("$TEXMACS_HOME_PATH/fonts/pk") |
    search_sub_dirs ("$TEXMACS_PATH/fonts/pk") |
    "$TEX_PK_PATH" |
    (pk == ""? url_none (): pk);
  if ((get_setting ("MAKEPK") != "false") ||
      (get_setting ("TEXHASH") == "true"))
    if (get_setting ("KPSEWHICH") != "true")
      the_pk_path= the_pk_path | get_kpsepath ("pk");
  the_pk_path= expand (factor (the_pk_path));
}
Esempio n. 15
0
void
reset_tfm_path (bool rehash) { (void) rehash;
  // if (rehash && (get_setting ("TEXHASH") == "true")) system ("texhash");
  string tfm= get_setting ("TFM");
  the_tfm_path=
    url_here () |
    search_sub_dirs ("$TEXMACS_HOME_PATH/fonts/tfm") |
    search_sub_dirs ("$TEXMACS_PATH/fonts/tfm") |
    "$TEX_TFM_PATH" |
    (tfm == ""? url_none (): tfm);
  if ((get_setting ("MAKETFM") != "false") ||
      (get_setting ("TEXHASH") == "true"))
    if (get_setting ("KPSEWHICH") != "true")
      the_tfm_path= the_tfm_path | get_kpsepath ("tfm");
  the_tfm_path= expand (factor (the_tfm_path));
}
Esempio n. 16
0
static url
get_cache (url name) {
    if (web_cache_resolve->contains (name->t)) {
        int i, j;
        tree tmp= web_cache_resolve [name->t];
        for (i=0; i<MAX_CACHED; i++)
            if (web_cache[i] == name->t) {
                // cout << name << " in cache as " << tmp << " at " << i << "\n";
                for (j=i; ((j+1) % MAX_CACHED) != web_nr; j= (j+1) % MAX_CACHED)
                    web_cache[j]= web_cache[(j+1) % MAX_CACHED];
                web_cache[j]= name->t;
                break;
            }
        return as_url (tmp); // url_system (tmp);
    }
    return url_none ();
}
Esempio n. 17
0
void
concater_rep::typeset_sound (tree t, path ip) {
  if (N(t) != 1) { typeset_error (t, ip); return; }
  player pl= get_player (env->get_animation_ip (ip));
  tree sound_t= env->exec (t[0]);
  url sound= url_none ();
  if (is_atomic (sound_t)) {
    url sound_u= sound_t->label;
    sound= resolve (relative (env->base_file_name, sound_u));
  }
  if (!is_none (sound)) {
    int sz= script (env->fn_size, env->index_level);
    font gfn (tex_font ("cmr", sz, (int) (env->magn*env->dpi)));
    print (sound_box (ip, pl, sound, gfn->yx));
    flag ("sound", ip, brown);
  }
  else typeset_dynamic (tree (ERROR, "bad sound", t[0]), ip);
}
Esempio n. 18
0
void
edit_main_rep::print_buffer (string first, string last) {
  // in Qt this is the main entry point to the printing subsystem.
  // the other routines (print_to_file, ...) are overriden since all fine tuning 
  // is made here via the Qt print dialog
  bool to_file, landscape;
  url name = url_none();
  string printer;
  string paper_type;
  if (qt_print (to_file, landscape, printer, name, first, last, paper_type)) {
      if (!to_file) name = url_temp (".ps");
      print (name, false, as_int (first), as_int (last));
      if (!to_file) {
        string cmd = printing_cmd * " -P" * printer;
        system (cmd, name);  
        ::remove (name);
      }
  }
}
Esempio n. 19
0
void
concater_rep::typeset_video (tree t, path ip) {
  if (N(t) != 5) { typeset_error (t, ip); return; }
  player pl= get_player (env->get_animation_ip (ip));
  tree video_t= env->exec (t[0]);
  url video= url_none ();
  if (is_atomic (video_t)) {
    url video_u= video_t->label;
    video= resolve (relative (env->base_file_name, video_u));
  }
  if (!is_none (video)) {
    SI   w  = env->as_length (env->exec (t[1]));
    SI   h  = env->as_length (env->exec (t[2]));
    int  len= env->as_length (env->exec (t[3]));
    bool rep= env->exec (t[4]) != "false";
    print (video_box (ip, pl, video, w, h, env->alpha, len, rep, env->pixel));
  }
  else typeset_dynamic (tree (ERROR, "bad video", t[0]), ip);
}
Esempio n. 20
0
url
tmfs_get_root (string prj) {
  collection c= tmfs_query (seq ("root", prj, "?url"), "?url");
  if (N(c) != 1) return url_none ();
  return url (first (c));
}
Esempio n. 21
0
url
picture_rep::get_name () {
    return url_none ();
}
Esempio n. 22
0
url
complete (url base, url u, string filter, bool flag) {
  // cout << "complete " << base << " |||| " << u << LF;
  if (!is_rooted(u)) {
     if (is_none (base)) return base;
     if (is_none (u)) return u;
     if ((!is_root (base)) && (!is_rooted_name (base))) {
        failed_error << "base= " << base << LF;
        FAILED ("invalid base url");
     }
  }
  if (is_name (u) || (is_concat (u) && is_root (u[1]) && is_name (u[2]))) {
    url comp= base * u;
    if (is_rooted (comp, "default") || is_rooted (comp, "file")) {
      if (is_of_type (comp, filter)) return reroot (u, "default");
      return url_none ();
    }
    if (is_rooted_web (comp) || is_rooted_tmfs (comp) || is_ramdisc (comp)) {
      if (is_of_type (comp, filter)) return u;
      return url_none ();
    }
    failed_error << "base= " << base << LF;
    failed_error << "u= " << u << LF;
    ASSERT (is_rooted (comp), "unrooted url");
    FAILED ("bad protocol in url");
  }
  if (is_root (u)) {
    // FIXME: test filter flags here
    return u;
  }
  if (is_concat (u) && is_wildcard (u[1], 0) && is_wildcard (u[2], 1)) {
    // FIXME: ret= ret | ... is unefficient (quadratic) in main loop
    if (!(is_rooted (base, "default") || is_rooted (base, "file"))) {
      failed_error << "base= " << base << LF;
      FAILED ("wildcards only implemented for files");
    }
    url ret= url_none ();
    bool error_flag;
    array<string> dir= read_directory (base, error_flag);
    int i, n= N(dir);
    for (i=0; i<n; i++) {
      if ((!is_none (ret)) && flag) return ret;
      if ((dir[i] == ".") || (dir[i] == "..")) continue;
      if (starts (dir[i], "http://") || starts (dir[i], "ftp://"))
        if (is_directory (base * dir[i])) continue;
      ret= ret | (dir[i] * complete (base * dir[i], u, filter, flag));
      if (match_wildcard (dir[i], u[2][1]->t->label))
	ret= ret | complete (base, dir[i], filter, flag);
    }
    return ret;
  }
  if (is_concat (u)) {
    url sub= complete (base, u[1], "", false);
    // "" should often be faster than the more correct "d" here
    return complete (base, sub, u[2], filter, flag);
  }
  if (is_or (u)) {
    url res1= complete (base, u[1], filter, flag);
    if ((!is_none (res1)) && flag) return res1;
    return res1 | complete (base, u[2], filter, flag);
  }
  if (is_wildcard (u)) {
    // FIXME: ret= ret | ... is unefficient (quadratic) in main loop
    if (!(is_rooted (base, "default") || is_rooted (base, "file"))) {
      failed_error << "base= " << base << LF;
      FAILED ("wildcards only implemented for files");
    }
    url ret= url_none ();
    if (is_wildcard (u, 0) && is_of_type (base, filter)) ret= url_here ();
    bool error_flag;
    array<string> dir= read_directory (base, error_flag);
    int i, n= N(dir);
    for (i=0; i<n; i++) {
      if ((!is_none (ret)) && flag) return ret;
      if ((dir[i] == ".") || (dir[i] == "..")) continue;
      if (starts (dir[i], "http://") || starts (dir[i], "ftp://"))
        if (is_directory (base * dir[i])) continue;
      if (is_wildcard (u, 0))
	ret= ret | (dir[i] * complete (base * dir[i], u, filter, flag));
      else if (match_wildcard (dir[i], u[1]->t->label))
	ret= ret | complete (base, dir[i], filter, flag);
    }
    return ret;
  }
  failed_error << "url= " << u << LF;
  FAILED ("bad url");
  return u;
}
Esempio n. 23
0
#include "config.h"
#include "tm_server.hpp"
#include "drd_std.hpp"
#include "convert.hpp"
#include "connect.hpp"
#include "sys_utils.hpp"
#include "file.hpp"
#include "analyze.hpp"
#include "dictionary.hpp"
#include "tm_link.hpp"
#include "socket_notifier.hpp"
#include "new_style.hpp"

server* the_server= NULL;
bool texmacs_started= false;
url tm_init_file= url_none ();
url my_init_file= url_none ();
string my_init_cmds= "";

/******************************************************************************
* Execution of commands
******************************************************************************/

void reset_inclusions ();
extern string printing_dpi;
extern string printing_cmd;
extern string printing_on;
extern int nr_windows;

/******************************************************************************
* Texmacs server constructor and destructor
Esempio n. 24
0
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/

#include "tex_files.hpp"
#include "boot.hpp"
#include "file.hpp"
#include "sys_utils.hpp"
#include "path.hpp"
#include "hashmap.hpp"
#include "analyze.hpp"
#include "timer.hpp"
#include "data_cache.hpp"

static url the_tfm_path= url_none ();
static url the_pk_path = url_none ();
static url the_pfb_path= url_none ();

/******************************************************************************
* Finding a TeX font
******************************************************************************/

static string
kpsewhich (string name) {
  bench_start ("kpsewhich");
  string which= var_eval_system ("kpsewhich " * name);
  bench_cumul ("kpsewhich");
  return which;
}