pike.git / lib / modules / Stdio.pmod / Terminfo.pmod

version» Context lines:

pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:242:    else // weird    {    // ignore    }    }       return clears;    }       //! -  void create(string cap, TermcapDB|void tcdb, int|void maxrecurse) +  protected void create(string cap, TermcapDB|void tcdb, int|void maxrecurse)    {    int i=0;    while((i=search(cap, "\\\n", i))>=0) {    string capr;    if(2!=sscanf(cap[i..], "\\\n%*[ \t\r]%s", capr))    break;    cap = cap[..i-1]+capr;    }    multiset(string) clears = load_cap(cap);    if(map->tc) {
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:271:    map |= mkmapping(indices(clears), allocate(sizeof(clears)));    }   }         //! Terminfo terminal description object   class Terminfo {       inherit TermMachine;    +  protected local constant MAGIC = 0432; // SysV +  protected local constant MAGIC2 = 01036; // Ncurses 6 +     //!    array(string) aliases;       protected private constant boolnames =    ({ "bw","am","xb","xs","xn","eo","gn","hc","km","hs","in","da","db","mi",    "ms","os","es","xt","hz","ul","xo","nx","5i","HC","NR","NP","ND","cc",    "ut","hl","YA","YB","YC","YD","YE","YF","YG" });    protected private constant numnames =    ({ "co","it","li","lm","sg","pb","vt","ws","Nl","lh","lw","ma","MW","Co",    "pa","NC","Ya","Yb","Yc","Yd","Ye","Yf","Yg","Yh","Yi","Yj","Yk","Yl",
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:335:    {    return predef::map(s/2, reverse)*"";    }       protected private int load_cap(.File f, int|void bug_compat)    {    int magic, sname, nbool, nnum, nstr, sstr;       if (6!=sscanf(swab(f->read(12)), "%2c%2c%2c%2c%2c%2c",    magic, sname, nbool, nnum, nstr, sstr) || -  magic != 0432) +  (magic != MAGIC && magic != MAGIC2))    return 0;    aliases = (f->read(sname)-"\0")/"|";    {    int blen = nbool;    if(((nbool+sname)&1) && !bug_compat)    blen++;    array(int) bools = values(f->read(blen)[..nbool-1]);    if (sizeof(bools)>sizeof(boolnames))    bools = bools[..sizeof(boolnames)-1];    map = mkmapping(boolnames[..sizeof(bools)-1], bools);    }    { -  array(int) nums = [array(int)] +  array(int) nums; +  if (magic == MAGIC2) { +  // 32-bit little-endian integers. +  nums = array_sscanf(f->read(nnum*4), "%-4c"*nnum); +  } else { +  nums = [array(int)]    array_sscanf(swab(f->read(nnum*2)), "%2c"*nnum); -  +  }    if (sizeof(nums)>sizeof(numnames))    nums = nums[..sizeof(numnames)-1];    mapping(string:int) tmp = mkmapping(numnames[..sizeof(nums)-1], nums); -  foreach (numnames[..sizeof(nums)-1], string name) -  if (tmp[name]>=0xfffe) +  foreach (numnames[..sizeof(nums)-1], string name) { +  if (tmp[name]>=0xfffe) { +  if ((magic == MAGIC) || (tmp[name] >= 0xfffffffe))    m_delete(tmp, name); -  +  } +  }    map += tmp;    }    {    string stroffs = swab(f->read(nstr*2));    string strbuf = f->read(sstr);    if(sizeof(strbuf)==sstr-1 && !bug_compat && (nbool&1)) {    // Ugh. Someone didn't pad their bool array properly (one suspects).    f->seek(0);    return load_cap(f, 1);    }
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:388:    strarr);    foreach (strnames[..sizeof(strarr)-1], string name)    if (!tmp[name])    m_delete(tmp, name);    map += tmp;    }    return 1;    }       //! -  void create(string filename) +  protected void create(string filename)    {    .File f = .File();    if (!f->open(filename, "r"))    error("Terminfo: unable to open terminfo file \"%s\"\n", filename);    int r = load_cap(f);    f->close();    if (!r)    error("Terminfo: unparsable terminfo file \"%s\"\n", filename);    }   }
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:411:   class TermcapDB {       MUTEX       protected private inherit .File;       protected private string buf="";    protected private mapping(string:int|Termcap) cache=([]);    protected private int complete_index=0;    -  void create(string|void filename) +  protected void create(string|void filename)    {    if (!filename) {    string tce = [string]getenv("TERMCAP");    if (tce && sizeof(tce) && tce[0]=='/')    filename = tce;    else if ((getenv("OSTYPE") == "msys") &&    (filename = getenv("SHELL"))) {    // MinGW    // Usually something like "C:/msys/1.0/bin/sh"    // Termcap is in "C:/msys/1.0/etc/termcap"
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:527:       return res;    }       protected private string readat(int pos)    {    rewind(pos);    return read();    }    -  array(string) _indices() +  protected array(string) _indices()    {    LOCK;    if(!complete_index) {    rewind();    while(read());    complete_index = 1;    }    UNLOCK;    return sort(indices(cache));    }    -  array(Termcap) _values() +  protected array(Termcap) _values()    {    array(object|int) res = ({});    mapping(int:string) extra = ([]);    LOCK;    if (complete_index)    res = predef::map(sort(indices(cache)),    [function(string,mapping(int:string):Termcap)]    lambda(string name, mapping(int:string) extra) {    if (!objectp(cache[name]) && !extra[cache[name]])    extra[cache[name]] = readat(cache[name]);
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:615:    buf = buf[i+1..];       continue;    }    for(j=-1; (i=search(buf,"\n",j+1))>=0; j=i);    buf = buf[j+1..];    if (!more_data()) return 0; // eof    }    }    -  Termcap load(string term, int|void maxrecurse) +  protected Termcap load(string term, int|void maxrecurse)    {    int|string|Termcap cap;       LOCK; -  if (zero_type(cache[term])) +  if (!has_index(cache, term))    {    if (!complete_index)    {    rewind();    do    cap = read_next(term);    while(cap && search(get_names(cap), term)<0);    }    }    else if (intp(cap=cache[term])) {
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:649:    {    LOCK;    foreach(names, string name)    cache[name] = [object(Termcap)]cap;    UNLOCK;    }    }    return objectp(cap) && [object(Termcap)]cap;    }    -  Termcap `[](string name) +  protected Termcap `[](string name)    {    return load(name);    }   }      //! Terminfo database for a single directory.   class TerminfoDB {       MUTEX       protected private string dir;    protected private mapping(string:Terminfo) cache = ([]);    protected private int complete_index=0;    -  protected string _sprintf() +  protected string _sprintf(int c)    {    return sprintf("Stdio.Terminfo.TerminfoDB(%O)", dir);    }       protected void create(string|void dirname)    {    if (!dirname)    {    // This is retained for compat.    // Typical initialization is now via MetaTerminfoDB.
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:700:    }    }       if(sizeof(dirname)<1 || dirname[-1]!='/')    dirname += "/";       if (!get_dir(dir = dirname))    error("failed to read terminfo dir %O\n", dirname);    }    -  array(string) _indices() +  protected array(string) _indices()    {    LOCK;    if (!complete_index) {    foreach (get_dir(dir), string a)    if (sizeof(a) == 1)    foreach (get_dir(dir+a), string b) -  if(zero_type(cache[b])) +  if(!has_index(cache, b))    cache[b] = 0;    complete_index = 1;    }    UNLOCK;    return sort(indices(cache));    }    -  array(object) _values() +  protected array(object) _values()    {    return predef::map(_indices(),    [function(string:object(Terminfo))]    lambda(string name) {    return cache[name] ||    Terminfo(dir+name[..0]+"/"+name);    });    }    -  Terminfo load(string term) +  protected Terminfo load(string term)    {    Terminfo ti;       if (!sizeof(term))    return 0;    LOCK;    if (!(ti = cache[term]))    {    if (file_stat(dir+term[..0]+"/"+term)) {    // Traditional Terminfo layout.
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:748:    // MacOS X Terminfo layout.    ti = Terminfo(sprintf("%s%02x/%s", dir, term[0], term));    }    if (ti)    cache[term] = ti;    }    UNLOCK;    return ti;    }    -  Terminfo `[](string name) +  protected Terminfo `[](string name)    {    return load(name);    }   }      //! @[TerminfoDB] that merges several directorys.   class MetaTerminfoDB {    protected array(TerminfoDB) dbs = ({});       //! Create a new Meta @[TerminfoDB].
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:793:    "/usr/share/termcap", "/usr/share/misc/terminfo",    });    }    foreach(dbs, string|TerminfoDB db) {    if (stringp(db)) {    .Stat st = file_stat(db);    if (!st || !st->isdir) continue;    db = TerminfoDB(db);    }    if (!db) continue; -  this_program::dbs += ({ db }); +  this::dbs += ({ db });    } -  // werror("TerminfoDBs: %O\n", this_program::dbs); -  if (!sizeof(this_program::dbs)) { +  // werror("TerminfoDBs: %O\n", this::dbs); +  if (!sizeof(this::dbs)) {    destruct(this);    }    }    -  Terminfo `[](string name) +  protected Terminfo `[](string name)    {    foreach(dbs, TerminfoDB db) {    Terminfo ti = db[name];    if (ti) return ti;    }    return 0;    }   }      protected private Termcap defterm;
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:888:    if (!defterm)    defterm = t;    UNLOCK;    }    return t;    }    return getTerminfo(term) || getTermcap(term) || getFallbackTerm(term);   }      //! Returns an object describing the fallback terminal for the terminal - //! @[term]. This is usually equvivalent to @[Stdio.Terminfo.getTerm("dumb")]. + //! @[term]. This is usually equivalent to @[Stdio.Terminfo.getTerm("dumb")].   //!   //! @seealso   //! Stdio.Terminfo.getTerm   protected Termcap getFallbackTerm(string term)   {    return (term=="dumb"? Termcap("dumb:\\\n\t:am:co#80:do=^J:") :    getTerm("dumb"));   }      protected int is_tty_cache;