コード例 #1
0
ファイル: text_language.cpp プロジェクト: svn2github/texmacs
text_property
oriental_language_rep::advance (tree t, int& pos) {
  string s= t->label;
  if (pos == N(s)) return &tp_normal_rep;

  if (s[pos] == ' ') {
    pos++;
    return &tp_space_rep;
  }

  if (pos < N(s) && !test (s, pos, "<#")) {
    while (pos < N(s) && s[pos] != ' ' && !test (s, pos, "<#"))
      tm_char_forwards (s, pos);
    return &tp_cjk_no_break_rep;
  }

  int start= pos;
  tm_char_forwards (s, pos);
  string c= s (start, pos);
  int next= pos;
  tm_char_forwards (s, next);
  string x= s (pos, next);

  if (punct->contains (c)) {
    if (punct->contains (x) || pos == N(s))
      return &tp_cjk_no_break_period_rep;
    else return &tp_cjk_period_rep;
  }
  else {
    if (punct->contains (x) || pos == N(s))
      return &tp_cjk_no_break_rep;
    else return &tp_cjk_normal_rep;
  }
}
コード例 #2
0
ファイル: r_language.cpp プロジェクト: KarlHegbloom/texmacs
static void
parse_other_op_index (hashmap<string,string>& t, string s, int& pos) {
  int i;
  i=13 ;
  if( i > N(s) ) i=N(s) ;
  for (i=13; i >= 1; i--) {
    string r=s(pos,pos+i);
    if (t->contains(r) && (t(r)=="op index")) {
      pos=pos+i; return; }
    if (t->contains(r) && (t(r)=="operator")) {
      return; }
    if (t->contains(r) && (t(r)=="op assign")) {
      return; }
  }
}
コード例 #3
0
tree
texmacs_invarianted (tree t, tree p, int c, string src,
                     hashmap<tree,tree> corr,
                     hashmap<tree,tree> pred,
                     hashmap<tree,tree> succ) {
  if (corr->contains (t)) {
    tree oids= corr[t], ids (TUPLE);
    for (int i=0; i<N(oids); i++) {
      int b, e;
      if (get_range (oids[i], b, e, src)) ids << oids[i];
    }
    if (N(ids) >= 1) {
      tree id= texmacs_best_match (ids, p, c, corr, pred, succ);
      if (id != tree (UNINIT)) return compound ("ilx", id);
    }
  }
  if (is_atomic (t)) return t;
  else {
    int i, n= N(t);
    tree r (t, n);
    for (i=0; i<n; i++)
      r[i]= texmacs_invarianted (t[i], t, i, src, corr, pred, succ);
    return r;
  }
}
コード例 #4
0
ファイル: module.cpp プロジェクト: murali-s-iyengar/mesos
// Mapping from module ID to the actual module name.
Try<string> getModuleName(ModuleID id)
{
  if (!moduleNames.contains(id)) {
    return Error("Module '" + stringify(id) + "' not found");
  }
  return moduleNames[id];
}
コード例 #5
0
ファイル: data_cache.cpp プロジェクト: svn2github/texmacs
bool
is_up_to_date (url dir) {
  string name_dir= concretize (dir);
  if (cache_valid->contains (name_dir)) return cache_valid [name_dir];
  int l= last_modified (dir, false);
  if (is_cached ("validate_cache.scm", name_dir)) {
    int r= as_int (cache_get ("validate_cache.scm", name_dir) -> label);
    if (l == r) {
      cache_valid (name_dir)= true;
      return true;
    }
    //cout << name_dir << " no longer up to date " << r << " -> " << l << "\n";
  }
  //else cout << name_dir << " not up to date " << l << "\n";
  cache_set ("validate_cache.scm", name_dir, as_string (l));
  cache_valid (name_dir)= false;
  // FIXME: we should explicitly remove all data concerning files in 'dir'
  // from the various caches.  Indeed, at a next run of TeXmacs, the directory
  // will be regarded as up to date, but the other caches may still contain
  // outdated data.  Careful: invalidating the cache lines should not
  // give rise to a performance penaly (e.g. go through all entries of
  // 'cache_data', or reloading unchanged files many times).
  // See also 'declare_out_of_date'.
  return false;
}
コード例 #6
0
ファイル: universal.cpp プロジェクト: xywei/texmacs
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;
  }
}
コード例 #7
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);
}
コード例 #8
0
ファイル: universal.cpp プロジェクト: xywei/texmacs
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;
  }
}
コード例 #9
0
static void
get_subtree_paths (tree t, path p, hashmap<tree,path>& h) {
  if (h->contains (t)) h (t)= path (-1);
  else h (t)= p;
  if (is_compound (t))
    for (int i=0; i<N(t); i++)
      get_subtree_paths (t[i], p * i, h);
}
コード例 #10
0
ファイル: r_language.cpp プロジェクト: KarlHegbloom/texmacs
static void
parse_constant (hashmap<string,string>& t, string s, int& pos) {
  int i=pos;
  if (pos>=N(s)) return;
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
  string r= s (pos, i);
  if (t->contains (r) && t(r)=="#2060c0") { pos=i; return; }
}
コード例 #11
0
ファイル: hyphenate.cpp プロジェクト: svn2github/texmacs
array<int>
get_hyphens (string s,
             hashmap<string,string> patterns,
             hashmap<string,string> hyphenations, bool utf8) {
  ASSERT (N(s) != 0, "hyphenation of empty string");

  if (utf8) s= cork_to_utf8 (s);

  if (hyphenations->contains (s)) {
    string h= hyphenations [s];
    array<int> penalty (str_length (s, utf8)-1);
    int i=0, j=0;
    while (h[j] == '-') j++;
    i++; goto_next_char (h, j, utf8);
    while (i < N(penalty)+1) {
      penalty[i-1]= HYPH_INVALID;
      while (j < N(h) && h[j] == '-') {
        penalty[i-1]= HYPH_STD;
        j++;
      }
      i++;
      goto_next_char (h, j, utf8);
    }
    //cout << s << " --> " << penalty << "\n";
    return penalty;
  }
  else {
    s= "." * lower_case (s) * ".";
    // cout << s << "\n";
    int i, j, k, l, m, len;
    array<int> T (str_length (s, utf8)+1);
    for (i=0; i<N(T); i++) T[i]=0;
    for (len=1; len < MAX_SEARCH; len++)
      for (i=0, l=0; i<N(s) - len; goto_next_char (s, i, utf8), l++) {
        string r= patterns [s (i, i+len)];
        if (!(r == "?")) {
          // cout << "  " << s (i, i+len) << " => " << r << "\n";
          for (j=0, k=0; j<=len; j++, k++) {
            if ((k<N(r)) && (r[k]>='0') && (r[k]<='9')) {
              m=((int) r[k])-((int) '0');
              k++;
            }
            else m=0;
            if (m>T[l+j]) T[l+j]=m;
          }
        }
      }

    array<int> penalty (N(T)-4);
    for (i=2; i < N(T)-4; i++)
      penalty [i-2]= (((T[i]&1)==1)? HYPH_STD: HYPH_INVALID);
    if (N(penalty)>0) penalty[0] = penalty[N(penalty)-1] = HYPH_INVALID;
    if (N(penalty)>1) penalty[1] = penalty[N(penalty)-2] = HYPH_INVALID;
    if (N(penalty)>2) penalty[N(penalty)-3] = HYPH_INVALID;
    // cout << s << " --> " << penalty << "\n";
    return penalty;
  }
}
コード例 #12
0
ファイル: persistent.cpp プロジェクト: KarlHegbloom/texmacs
string
persistent_get (url dir, string key) {
  string v= local_prefix (dir) * key;
  if (!persistent_has->contains (v)) {
    persistent_init_key (dir, key);
    persistent_retrieve (dir, key, persistent_file [v], persistent_hash [v]);
  }
  return persistent_cache [v];
}
コード例 #13
0
ファイル: language.cpp プロジェクト: KarlHegbloom/texmacs
language
ad_hoc_language (language base, tree hyphs) {
  static hashmap<tree,int> abbrevs;
  if (!abbrevs->contains (hyphs))
    abbrevs (hyphs)= N (abbrevs);
  string name= base->res_name * "-" * as_string (abbrevs [hyphs]);
  if (language::instances -> contains (name)) return language (name);
  return tm_new<ad_hoc_language_rep> (name, base, hyphs);
}
コード例 #14
0
ファイル: language.cpp プロジェクト: KarlHegbloom/texmacs
void
ad_hoc_language_rep::hyphenate (
  string s, int after, string& left, string& right)
{
  if (hyphens->contains (s)) {
    array<int> penalty= get_hyphens (s);
    std_hyphenate (s, after, left, right, penalty[after]);
  }
  else base->hyphenate (s, after, left, right);
}
コード例 #15
0
int
common_len (tree id, tree p, int c, int delta,
            hashmap<tree,tree> corr,
            hashmap<tree,tree> next) {
  int len= 0;
  while (true) {
    c += delta;
    if (c < 0 || c >= N(p)) break;
    if (!corr->contains (p[c])) break;
    tree next_ids= corr[p[c]];
    if (!next->contains (id)) break;
    tree next_id= next[id];
    bool found= false;
    for (int k=0; k<N(next_ids); k++)
      found= found || (next_ids[k] == next_id);
    if (!found) break;
    len++;
  }
  return len;
}
コード例 #16
0
static string
replace (string s, hashmap<int,string> w, hashmap<int,string> b) {
  string r;
  for (int i=0; i<N(s); )
    if (w->contains (i)) {
      r << b[i];
      i += N(w[i]);
    }
    else r << s[i++];
  return r;
}
コード例 #17
0
ファイル: tm_window.cpp プロジェクト: mgubi/texmacs
string
unique_window_name (string name) {
    for (int i=1; true; i++) {
        string wname= name;
        if (i > 1) wname= wname * ":" * as_string (i);
        if (!window_names->contains (wname)) {
            window_names (wname)= name;
            return wname;
        }
    }
}
コード例 #18
0
ファイル: persistent.cpp プロジェクト: KarlHegbloom/texmacs
string
local_prefix (url dir) {
  string name= as_string (dir);
  if (!persistent_pre->contains (name)) {
    string prefix= as_string (N (persistent_pre) + 1) * ":";
    persistent_pre (name)= prefix;
    if (!is_directory (dir)) mkdir (dir);
    if (!is_directory (dir * url ("_"))) mkdir (dir * url ("_"));
  }
  return persistent_pre [name];
}
コード例 #19
0
 int
 add_font (tree fn, int rewr) {
   if (!fn_nr->contains (fn)) {
     int sz= N (fn_spec);
     fn_nr (fn)= sz;
     fn_spec << fn;
     fn_rewr << rewr;
     //cout << "Create " << sz << " -> " << fn << "\n";
   }
   return fn_nr[fn];
 }
コード例 #20
0
ファイル: language.cpp プロジェクト: KarlHegbloom/texmacs
array<int>
ad_hoc_language_rep::get_hyphens (string s) {
  if (hyphens->contains (s)) {
    string h= hyphens[s];
    array<int> penalty;
    for (int i=0; i<N(h); tm_char_forwards (h, i))
      if (h[i] != '-') penalty << HYPH_INVALID;
      else if (N(penalty)>0) penalty[N(penalty)-1]= 0;
    return penalty;
  }
  else return base->get_hyphens (s);
}
コード例 #21
0
ファイル: parsexml.cpp プロジェクト: KarlHegbloom/texmacs
string
xml_html_parser::expand_entity (string s) {
  if (entities->contains (s)) return entities[s];
  else if (s[0] == '&') {
    if (N(s)>1 && s[1] == '#') {
      int i= 2;
      bool okay= false;
      string r= convert_char_entity (s, i, okay);
      if (okay) return r;
      return s;
    }
    else if (html) {
      string ss= s (1, s [N(s)-1] == ';' ? N(s)-1 : N(s));
      if (html_entity->contains (ss))
	// HTML entity references expand to character references
	// so they need to be finalized a second time.
	return expand_entity (html_entity [ss]);
    }
  }
  return s;
}
コード例 #22
0
ファイル: drd_info.cpp プロジェクト: Easycker/itexmacs
static tree
replace (tree t, hashmap<tree,tree> h) {
  if (h->contains (t)) return h[t];
  else if (is_atomic (t)) return t;
  else {
    int i, n= N(t);
    tree r (t, n);
    for (i=0; i<n; i++)
      r[i]= replace (t[i], h);
    return r;
  }
}
コード例 #23
0
ファイル: tm_window.cpp プロジェクト: mgubi/texmacs
void
window_delete (int win) {
    static hashmap<int,bool> busy (false);
    if (busy->contains (win)) return;
    busy (win)= true;
    ASSERT (window_table->contains (win), "window does not exist");
    widget pww= window_table [win];
    window_table->reset (win);
    send_destroy (pww);
    destroy_window_widget (pww);
    busy (win)= false;
}
コード例 #24
0
ファイル: r_language.cpp プロジェクト: KarlHegbloom/texmacs
static void
parse_other_lexeme (hashmap<string,string>& t, string s, int& pos) {
  int i;
  if( s[pos] == '%' )  {
    pos++ ;
    advance_till( s, pos, '%' ) ;
    return ;
  }
  for (i=12; i>=1; i--) {
    string r=s(pos,pos+i);
    if (t->contains(r) && ( (t(r)=="operator") || (t(r)=="op assign") || (t(r)=="op index") )) {
      pos=pos+i; return; }
  }
}
コード例 #25
0
ファイル: rubber_stix_font.cpp プロジェクト: mgubi/texmacs
int
rubber_stix_font_rep::search_font_cached (string s, string& rew, string& ltype) {
  if (mapper->contains (s)) {
    rew= rewriter[s];
    ltype= delimiter[s];
    return mapper[s];
  }
  int nr= search_font_sub (s, rew, ltype);
  mapper(s)= nr;
  rewriter(s)= rew;
  delimiter(s)= ltype;
  //cout << s << " -> " << nr << ", " << rew << ", " << ltype << LF;
  return nr;
}
コード例 #26
0
static void
insert_recursively (array<string>& a, string s, hashmap<string,tree>& h) {
  // cout << "Insert recursively \t" << s << "\n";
  int i= search_backwards ("\t", s);
  if (i != -1) {
    string r= s (0, i);
    if (!h->contains (r)) {
      tree u= h[s][0][0];
      h (r)= tuple (tuple (copy (u (0, N(u)-1)), ""));
      insert_recursively (a, s (0, i), h);
    }
  }
  a << s;
}
コード例 #27
0
ファイル: universal.cpp プロジェクト: xywei/texmacs
string
uni_translit (string s) {
  translit_init ();
  string r;
  int i=0, n=N(s);
  while (i<n) {
    int start= i;
    tm_char_forwards (s, i);
    string ss= s (start, i);
    if (translit_table->contains (ss)) r << translit_table [ss];
    else r << ss;
  }
  return r;
}
コード例 #28
0
static string
rewrite_letters (string s) {
  init_unicode_substitution ();
  string r;
  int i= 0, n= N(s);
  while (i < n) {
    int start= i;
    tm_char_forwards (s, i);
    string ss= s (start, i);
    if (substitution_char->contains (ss)) r << substitution_char[ss];
    else r << ss;
  }
  return r;
}
コード例 #29
0
ファイル: edit_typeset.cpp プロジェクト: svn2github/texmacs
static tree
value_to_compound (tree t, hashmap<string,tree> h) {
  if (is_atomic (t)) return t;
  else if (is_func (t, VALUE, 1) &&
	   is_atomic (t[0]) &&
	   h->contains (t[0]->label))
    return compound (t[0]->label);
  else {
    int i, n= N(t);
    tree r (t, n);
    for (i=0; i<n; i++)
      r[i]= value_to_compound (t[i], h);
    return r;
  }
}
コード例 #30
0
ファイル: r_language.cpp プロジェクト: KarlHegbloom/texmacs
static void
parse_identifier (hashmap<string, string>& t,
		  string s, int& pos, bool postfix) {
  (void) postfix;
  int i=pos;
  if ( pos>=N(s) ) return;

  if( s[pos] == '`' ) {
    pos++ ;
    advance_till( s, pos, '`' ) ;
    return ;
  }
  while (i<N(s) && belongs_to_identifier (s[i])) i++;

  if (!(t->contains (s (pos, i)))) pos= i;
}