Esempio n. 1
0
bool
do_cache_file (string name) {
  return
    !ends (name, ".ts") &&
    (starts (name, texmacs_path_string) ||
     starts (name, texmacs_font_path_string));
}
Esempio n. 2
0
// Takes text and tags
// Removes the tags from the start and end of the text
// Returns a string
string trim(read r, read t1, read t2, read t3) {

	// Copy the text into a string
	string s = r;

	// Remove the tags from the start of the string until gone
	while (true) {

		if      (starts(s, t1)) s = clip(s, length(t1), -1);
		else if (starts(s, t2)) s = clip(s, length(t2), -1);
		else if (starts(s, t3)) s = clip(s, length(t3), -1);
		else                    break;
	}

	// Remove the tags from the end of the string until gone
	while (true) {

		if      (trails(s, t1)) s = clip(s, 0, length(s) - length(t1));
		else if (trails(s, t2)) s = clip(s, 0, length(s) - length(t2));
		else if (trails(s, t3)) s = clip(s, 0, length(s) - length(t3));
		else                    break;
	}

	// Return the string
	return s;
}
Esempio n. 3
0
bool
do_cache_stat (string name) {
  return
    starts (name, texmacs_path_string) ||
    starts (name, texmacs_font_path_string) ||
    starts (name, texmacs_doc_path_string);
}
Esempio n. 4
0
static bool
is_special (string s) {
  if (N (special_table) == 0) {
    special_table ("*")= "";
    special_table ("<noplus>")= "";
    special_table ("<nocomma>")= "";
    special_table ("<nospace>")= "";
    special_table ("<nobracket>")= "";
    special_table ("<nosymbol>")= "";
    special_table ("-")= "<minus>";
    special_table ("|")= "<mid>";
    special_table ("'")= "<#2B9>";
    special_table ("`")= "<backprime>";
  }
  if (starts (s, "<big-."))
    special_table (s)= "";
  if (starts (s, "<big-") && (ends (s, "-1>") || ends (s, "-2>"))) {
    string ss= s (0, N(s)-3) * ">";
    //cout << "Search " << ss << "\n";
    if (unicode_provides (ss))
      special_table (s)= ss;
    ss= "<big" * s (5, N(s)-3) * ">";
    //cout << "Search " << ss << "\n";
    if (unicode_provides (ss))
      special_table (s)= ss;
    ss= "<" * s (5, N(s)-3) * ">";
    if (ends (ss, "lim>")) ss= ss (0, N(ss)-4) * ">";
    //cout << "Search " << ss << "\n";
    if (unicode_provides (ss))
      special_table (s)= ss;
  }
  return special_table->contains (s);
}
Esempio n. 5
0
bool
do_cache_stat_fail (string name) {
  return
    !ends (name, ".ts") &&
    (starts (name, texmacs_path_string) ||
     starts (name, texmacs_doc_path_string));
}
Esempio n. 6
0
bool
edit_interface_rep::try_shortcut (string comb) {
  int     status;
  command cmd;
  string  shorth;
  string  help;

  sv->get_keycomb (comb, status, cmd, shorth, help);
  //cout << "Try " << comb << " -> " << shorth << ", " << help
  //<< "; " << sh_mark << ", " << status << "\n";
  if (status != 0) {
    if (status >= 3) {
      interrupt_shortcut ();
      status -= 3;
      if (status == 0) return false;
    }
    else {
      if (sh_mark != 0 && !mark_cancel (sh_mark)) {
        sh_mark= 0;
        return false;
      }
    }
    sh_s= comb;
    sh_mark= new_marker ();
    mark_start (sh_mark);
    archive_state ();
    string rew_s= sv->kbd_post_rewrite (sh_s);
    tree rew= sv->kbd_system_rewrite (rew_s);
    if (N(help)>0) set_message (help, rew);
    tree rhs= (shorth == rew_s? tree (""): sv->kbd_system_rewrite (shorth));
    //cout << "Shortcut: " << sh_s << " -> " << rew << "\n";
    if ((search_forwards (" ", comb) >= 0 && comb != " ") ||
	(search_forwards ("-", comb) >= 0 && comb != "-")) {
      tree t= rhs;
      if (is_compound (t, "render-key", 1)) t= t[0];
      if (is_func (t, WITH)) t= t[N(t)-1];
      string r= as_string (t);
      if (starts (r, "<") && !starts (r, "<#"))
        if (cork_to_utf8 (r) != r)
          rhs= tree (CONCAT, rhs, " (" * r(1, N(r)-1) * ")");
      call ("set-temporary-message",
	    tree (CONCAT, "keyboard shortcut: ", rew), rhs,
	    shorth == ""? 1: 3000);
    }
    if ((status & 1) == 1) cmd ();
    else if (N(shorth) > 0) call ("kbd-insert", shorth);
    //cout << "Mark= " << sh_mark << "\n";
    return true;    
  }

  return false;
}
Esempio n. 7
0
url
resolve_in_path (url u) {
  if (use_which) {
    string name = escape_sh (as_string (u));
    string which= var_eval_system ("which " * name * " 2> /dev/null");
    if (ends (which, name))
      return which;
    else if ((which != "") &&
	     (!starts (which, "which: ")) &&
	     (!starts (which, "no ")))
      cout << "TeXmacs] " << which << "\n";
  }
  return resolve (url_path ("$PATH") * u, "x");
}
Esempio n. 8
0
// Takes text and tag, and direction and matching
// Confirms the text starts or ends with the tag, inserting it if necessary
// Returns a string
string on(read r, read t, direction d, matching m) {

	string s = r;
	if (d == Forward) { if (!starts(s, t, m)) s = t + s; } // Confirm the text starts with the tag
	else              { if (!trails(s, t, m)) s = s + t; } // Confirm the text ends with the tag
	return s;
}
Esempio n. 9
0
tree
edit_interface_rep::compute_text_footer (tree st) {
  string r;
  language lan= get_env_language ();
  int end  = last_item (tp);
  int start= end;
  tm_char_backwards (st->label, start);
  r= st->label (start, end);
  if (r == "") r= "start";
  if (r == " ") r= "space";
  if (r == "space" && get_env_string (MODE) == "math") r= "apply";
  if (starts (r, "<") && !starts (r, "<#"))
    if (cork_to_utf8 (r) != r)
      r= r * " (" * r(1, N(r)-1) * ")";
  return r;
}
Esempio n. 10
0
string
uni_locase_char (string s) {
  if (N(s) == 1) {
    unsigned char c= s[0];
    if ((c >= 'A' && c <= 'Z') ||
	(c >= ((unsigned char) 0x80) && (c <= ((unsigned char) 0x9F))) ||
	(c >= ((unsigned char) 0xC0) && (c <= ((unsigned char) 0xDF))))
      return string ((char) (c + 0x20));
    return s;
  }
  else if (starts (s, "<#") && ends (s, ">")) {
    int code= from_hexadecimal (s (2, N(s) - 1));
    if (code >= 0x386 && code <= 0x3AB) {
      if      (code >= 0x391 && code <= 0x3AB) code += 0x20;
      else if (code >= 0x386 && code <= 0x386) code += 0x26;
      else if (code >= 0x388 && code <= 0x38A) code += 0x25;
      else if (code >= 0x38C && code <= 0x38C) code += 0x40;
      else if (code >= 0x38E && code <= 0x38F) code += 0x3f;
    }
    else if (code >= 0x400 && code <= 0x40F) code += 0x50;
    else if (code >= 0x410 && code <= 0x42F) code += 0x20;
    else if (code >= 0x460 && code <= 0x4FF) {
      if ((code & 1) == 0) code += 1;
    }
    return "<#" * as_hexadecimal (code) * ">";
  }
  else {
    init_case_tables ();
    if (locase_tab->contains (s)) return locase_tab[s];
    return s;
  }
}
Esempio n. 11
0
string
uni_upcase_char (string s) {
  if (N(s) == 1) {
    unsigned char c= s[0];
    if ((c >= 'a' && c <= 'z') ||
	(c >= ((unsigned char) 0xA0) && (c <= ((unsigned char) 0xBF))) ||
	(c >= ((unsigned char) 0xE0)))
      return string ((char) (c - 0x20));
    return s;
  }
  else if (starts (s, "<#") && ends (s, ">")) {
    int code= from_hexadecimal (s (2, N(s) - 1));
    if (code >= 0x3AC && code <= 0x3CE) {
      if      (code >= 0x3B1 && code <= 0x3CB) code -= 0x20;
      else if (code >= 0x3AC && code <= 0x3AC) code -= 0x26;
      else if (code >= 0x3AD && code <= 0x3AF) code -= 0x25;
      else if (code >= 0x3CC && code <= 0x3CC) code -= 0x40;
      else if (code >= 0x3CD && code <= 0x3CE) code -= 0x3f;
    }
    else if (code >= 0x450 && code <= 0x45F) code -= 0x50;
    else if (code >= 0x430 && code <= 0x44F) code -= 0x20;
    else if (code >= 0x460 && code <= 0x4FF) {
      if ((code & 1) == 1) code -= 1;
    }
    return "<#" * as_hexadecimal (code) * ">";
  }
  else {
    init_case_tables ();
    if (upcase_tab->contains (s)) return upcase_tab[s];
    return s;
  }
}
Esempio n. 12
0
bool
edit_interface_rep::complete_try () {
  tree st= subtree (et, path_up (tp));
  if (is_compound (st)) return false;
  string s= st->label, ss;
  int end= last_item (tp);
  array<string> a;
  if (inside (LABEL) || inside (REFERENCE) || inside (PAGEREF)) {
    if (end != N(s)) return false;
    ss= copy (s);
    tree t= get_labels ();
    int i, n= N(t);
    for (i=0; i<n; i++)
      if (is_atomic (t[i]) && starts (t[i]->label, s))
	a << string (t[i]->label (N(s), N(t[i]->label)));
  }
  else {
    if ((end==0) || (!is_iso_alpha (s[end-1])) ||
	((end!=N(s)) && is_iso_alpha (s[end]))) return false;
    int start= end-1;
    while ((start>0) && is_iso_alpha (s[start-1])) start--;
    ss= s (start, end);
    a= find_completions (drd, et, ss);
  }
  if (N(a) == 0) return false;
  complete_start (ss, a);
  return true;
}
Esempio n. 13
0
static void
find_completions (
  drd_info drd, tree t, hashset<string>& h, string prefix= "")
{
  if (is_atomic (t)) {
    string s= t->label;
    int i= 0, n= N(s);
    while (i<n) {
      if (is_iso_alpha (s[i])) {
	int start= i;
	while ((i<n) && (is_iso_alpha (s[i]))) i++;
	string r= s (start, i);
	if (starts (r, prefix) && (r != prefix))
	  h->insert (r (N(prefix), N(r)));
      }
      else skip_symbol (s, i);
    }
  }
  else {
    int i, n= N(t);
    for (i=0; i<n; i++)
      if (drd->is_accessible_child (t, i))
	find_completions (drd, t[i], h, prefix);
  }
}
Esempio n. 14
0
// Takes text and tag, and direction and matching
// Confirms the text does not start or end with the tag, removing multiple instances of it if necessary
// Returns a string
string off(read r, read t, direction d, matching m) {

	string s = r;
	if (d == Forward) { while(starts(s, t, m)) s = clip(s, length(t), -1); }            // Remove the tag from the start of the string
	else              { while(trails(s, t, m)) s = clip(s, 0, length(s) - length(t)); } // Remove the tag from the end of the string
	return s;
}
Esempio n. 15
0
void
edit_interface_rep::key_press (string gkey) {
  string zero= "a"; zero[0]= '\0';
  string key= replace (gkey, "<#0>", zero);
  if (pre_edit_mark != 0) {
    ASSERT (sh_mark == 0, "invalid shortcut during pre-edit");
    mark_cancel (pre_edit_mark);
    pre_edit_s= "";
    pre_edit_mark= 0;
  }
  if (starts (key, "pre-edit:") ) {
    interrupt_shortcut ();
    string s= key (9, N(key));
    if (s == "") return;
    int i, n= N(s), pos= N(s);
    for (i=0; i<n; i++)
      if (s[i] == ':' && is_int (s (0, i))) {
        int k= as_int (s (0, i));
        s= s (i+1, n);
        pos= 0;
        for (int j=0; j<k && pos<N(s); j++)
          tm_char_forwards (s, pos);
        break;
      }
    pre_edit_s= s;
    pre_edit_mark= new_marker ();
    mark_start (pre_edit_mark);
    archive_state ();
    insert_tree (compound ("pre-edit", s), path (0, pos));
    return;
  }
  
  string new_sh= N(sh_s)==0? key: sh_s * " " * key;
  if (try_shortcut (new_sh)) return;
  if (new_sh != key) {
    interrupt_shortcut ();
    if (try_shortcut (key)) return;
  }
  
  string rew= sv->kbd_post_rewrite (key);
  if (N(rew) == 1) {
    int i ((unsigned char) rew[0]);
    if ((i >= 32 && i <= 127) || (i >= 128 && i <= 255) || (i == 25))
      if (!inside_active_graphics ()) {
        archive_state ();
        call ("kbd-insert", rew);
      }
    interrupt_shortcut ();
  }
  else if (contains_unicode_char (rew)) {
    archive_state ();
    call ("kbd-insert", key);
    interrupt_shortcut ();    
  }
  else if (DEBUG_KEYBOARD)
    debug_keyboard
      << "unrecognized key " << key << ". "
      << "Undefined shortcut or key missing in the encoding files.\n";
}
Esempio n. 16
0
bool
sane_font (array<string> r, font_metric fnm, string family,
           string range, int test) {
  if (!contains (range, r)) return true;
  if (!really_exists (fnm, test)) return false;
  // Many Apple fonts (especially the CJK ones) provide ugly support
  // for Greek and/or Cyrillic characters
  if (starts (locase_all (family), "pilgi")) return false;
  if (starts (locase_all (family), "unpilgi")) return false;
  if (contains (string ("CJK"), r)) {
    metric_struct* m= fnm->get (test);
    int pw= m->x4 - m->x3;
    int lw= m->x2 - m->x1;
    if (7 * pw < 6 * lw) return false;
  }
  return true;
}
Esempio n. 17
0
string
find_attribute_value (array<string> a, string s) {
  string s2= s * "=";
  for (int i=0; i<N(a); i++)
    if (starts (a[i], s2))
      return a[i] (N(s2), N(a[i]));
  return "";
}
Esempio n. 18
0
static string
large_type (string s) {
  int pos= search_backwards ("-", N(s), s);
  if (pos > 6 && s[pos-1] == '-') pos--;
  if (pos > 6) return s (1, pos);
  else if (!starts (s, "<") || !ends (s, ">")) return s;
  else return s (1, N(s) - 1);
}
Esempio n. 19
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. 20
0
font
smart_font (string family, string variant, string series, string shape,
            int sz, int dpi) {
  if (!new_fonts) return find_font (family, variant, series, shape, sz, dpi);
  if (starts (family, "tc"))
    // FIXME: temporary hack for symbols from std-symbol.ts
    return find_font (family, variant, series, shape, sz, dpi);
  if (starts (family, "sys-")) {
    if (family == "sys-chinese") {
      string name= default_chinese_font_name ();
      family= "cjk=" * name * ",roman";
    }
    if (family == "sys-japanese") {
      string name= default_japanese_font_name ();
      family= "cjk=" * name * ",roman";
    }
    if (family == "sys-korean") {
      string name= default_korean_font_name ();
      family= "cjk=" * name * ",roman";
    }
  }

  string name=
    family * "-" * variant * "-" *
    series * "-" * shape * "-" *
    as_string (sz) * "-" * as_string (dpi) * "-smart";
  if (font::instances->contains (name)) return font (name);
  if (starts (shape, "math")) {
    array<string> a= trimmed_tokenize (family, ","), b;
    for (int i=0; i<N(a); i++)
      if (starts (a[i], "math=")) b << a[i] (5, N(a[i]));
      else b << a[i];
    family= recompose (b, ",");
  }
  string sh= shape;
  if (shape == "mathitalic" || shape == "mathshape") sh= "right";
  string mfam= main_family (family);
  font base_fn= closest_font (mfam, variant, series, sh, sz, dpi);
  if (is_nil (base_fn)) return font ();
  font sec_fn= closest_font ("roman", "ss", "medium", "right", sz, dpi);
  font err_fn= error_font (sec_fn);
  return make (font, name,
               tm_new<smart_font_rep> (name, base_fn, err_fn, family, variant,
                                       series, shape, sz, dpi));
}
Esempio n. 21
0
static void
report_missing (hashmap<string,tree> missing) {
  array<string> a;
  for (iterator<string> it= iterate (missing); it->busy(); a << it->next ());
  merge_sort (a);
  for (int i=0; i<N(a); i++)
    if (!starts (a[i], "bib-"))
      typeset_warning << "Undefined reference " << a[i] << LF;
}
Esempio n. 22
0
void
use_modules (tree t) {
  if (is_tuple (t))
    for (int i=0; i<N(t); i++) {
      string s= as_string (t[i]);
      if (starts (s, "(")) eval ("(use-modules " * s * ")");
      else if (s != "") eval ("(plugin-initialize '" * s * ")");
    }
}
Esempio n. 23
0
tree
remove_start_space (tree t) {
  if (is_atomic (t)) {
    string s= t->label;
    if (starts (s, " ")) return s (1, N(s));
    else return s;
  }
  else return t;
}
Esempio n. 24
0
 int
 add_char (tree fn, string c) {
   //cout << "Add " << c << " to " << fn << "\n";
   add_font (fn, REWRITE_NONE);
   int nr= fn_nr [fn];
   if (starts (c, "<")) cht (c)= nr;
   else chv [(int) (unsigned char) c[0]]= nr;
   return nr;
 }
Esempio n. 25
0
void
analyze_range (font fn, font_metric fnm, array<string>& r, string family) {
  bool ec= starts (family, "ec") && ends (family, "10");
  string lfn= locase_all (family);
  if (starts (lfn, "lastresort") ||
      starts (lfn, "tex ams blackboard bold") ||
      (starts (lfn, "tex blackboard bold") &&
       !starts (lfn, "tex blackboard bold variant")) ||
      starts (lfn, "tex calligraphic capitals") ||
      starts (lfn, "tex double stroke") ||
      starts (lfn, "tex ralph smith"))
    return;
  if (range_exists (fnm, 0x21, 0x7e) || ec)
    r << string ("Ascii");
  if (range_exists (fnm, 0xc0, 0xff) || ec)
    r << string ("Latin");
  if (range_percentage (fnm, 0x391, 0x3ce) > 66.6 || ec)
    r << string ("Greek");
  if (range_percentage (fnm, 0x410, 0x44f) > 66.6 || ec)
    r << string ("Cyrillic");

  if (range_percentage (fnm, 0x4e00, 0x4eff) > 0.0) {
    double perc= range_percentage (fnm, 0x4e00, 0x9fcc);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("CJK");
  }
  if (range_percentage (fnm, 0xac00, 0xacff) > 0.0) {
    double perc= range_percentage (fnm, 0xac00, 0xd7af);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("Hangul");
  }

  if (range_percentage (fnm, 0x2100, 0x21ff) > 0.0) {
    double perc= range_percentage (fnm, 0x2000, 0x23ff);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("MathSymbols");
  }
  if (range_percentage (fnm, 0x2900, 0x29ff) > 0.0) {
    double perc= range_percentage (fnm, 0x2900, 0x2e7f);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("MathExtra");
  }
  if (range_percentage (fnm, 0x1d400, 0x1d4ff) > 0.0) {
    double perc= range_percentage (fnm, 0x1d400, 0x1d7ff);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("MathLetters");
  }

  if (!sane_font (r, fnm, family, "Greek", 0x391) && !ec)
    r= exclude (r, "Greek");
  if (!sane_font (r, fnm, family, "Cyrillic", 0x430) && !ec)
    r= exclude (r, "Cyrillic");
}
 bool cdata( const XMLByte* const data, const Count_t count )
 {
     if( starts( data, count, cdata_start_ ) )
         cdata_ = true;
     else if( cdata_ && equals( data, count, cdata_end_ ) )
         cdata_ = false;
     else
         return cdata_;
     return true;
 }
Esempio n. 27
0
static tree
downgrade_bracket (tree t, bool large) {
  if (!is_atomic (t)) return t;
  string s= t->label;
  if (large) {
    if (t == "<nobracket>") return tree (".");
    if (starts (s, "<") && ends (s, ">")) return s (1, N(s)-1);
  }
  else if (s == "<nobracket>") return "";
  return t;
}
Esempio n. 28
0
static string name_irctolocal(string& n) {
        string playername = n;
        if (starts(playername , "@")){
                playername = after(playername , "@");
        }
        string k(ofpprefix);
        int p = playername.find(k, 0);
        if (p >= 0) {
                return string(playername, p + k.size());
        }
        return playername;
}              
Esempio n. 29
0
player
accelerate (player pl, tree kind) {
  if (kind == "reverse") return reverse_player (pl);
  if (kind == "fade-in") return fade_in_player (pl);
  if (kind == "fade-out") return fade_out_player (pl);
  if (kind == "faded") return faded_player (pl);
  if (kind == "bump") return bump_player (pl);
  if (is_atomic (kind) && starts (kind->label, "reverse-"))
    return reverse_player (accelerate (pl, kind->label (8, N(kind->label))));
  if (is_tuple (kind, "fixed", 1) && is_atomic (kind[1]))
    return fixed_player (pl, as_double (kind[1]));
  return pl;
}
Esempio n. 30
0
translator&
operator << (translator& trl, string s) {
  if (N(s)>0) {
    if (N(s)>1) s= "<" * s * ">";
    trl->dict(s) = trl->cur_c;
    if (starts (s, "<large-")) {
      string sub= s (7, N(s)-1);
      trl->dict ("<left-"  * sub * ">") = trl->cur_c;
      trl->dict ("<mid-"   * sub * ">") = trl->cur_c;
      trl->dict ("<right-" * sub * ">") = trl->cur_c;
      if (ends (s, "-0>")) return trl << s (1, N(s)-3);
    }
  }
  trl->cur_c++;
  return trl;
}