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

version» Context lines:

pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:1: - // $Id: Terminfo.pmod,v 1.20 2005/01/07 10:37:46 grubba Exp $ + // $Id: Terminfo.pmod,v 1.21 2006/01/07 16:39:02 nilsson Exp $   #pike __REAL_VERSION__         #if constant(thread_create)   #define LOCK object m_key = mutex->lock()   #define UNLOCK destruct(m_key)   #define MUTEX static private object(Thread.Mutex) mutex = Thread.Mutex();   #else   #define LOCK   #define UNLOCK   #define MUTEX   #endif      MUTEX      static private array ctrlcharsfrom = -  Array.map(indices(allocate(32)), +  map(indices(allocate(32)),    lambda(int z) { return sprintf("^%c",z+64); })+ -  Array.map(indices(allocate(32)), +  map(indices(allocate(32)),    lambda(int z) { return sprintf("^%c",z+96); });   static private array ctrlcharsto = -  Array.map(indices(allocate(32)), +  map(indices(allocate(32)),    lambda(int z) { return sprintf("%c",z); })+ -  Array.map(indices(allocate(32)), +  map(indices(allocate(32)),    lambda(int z) { return sprintf("%c",z); });         static private class TermMachine {       mapping(string:string|int) map = ([]);       int tgetflag(string id)    {    return map[id]==1;
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:327:    {    // Delay stuff completely ignored...    string pre, post;    while (3==sscanf(s, "%s$<%*[0-9.]>%s", pre, post))    s = pre+post;    return s;    }       static private string swab(string s)    { -  return Array.map(s/2, reverse)*""; +  return predef::map(s/2, reverse)*"";    }       static 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)    return 0;
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:369:    {    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);    }    if(sizeof(strbuf)!=sstr)    return 0; -  array(string) strarr = Array.map(array_sscanf(stroffs, "%2c"*nstr), +  array(string) strarr = predef::map(array_sscanf(stroffs, "%2c"*nstr),    lambda(int offs, string buf) {    return offs<0xfffe &&    buf[offs..    search(buf, "\0", offs)-1];    }, strbuf+"\0");    if (sizeof(strarr)>sizeof(strnames))    strarr = strarr[..sizeof(strnames)-1];    mapping(string:string) tmp = mkmapping(strnames[..sizeof(strarr)-1],    strarr);    foreach (strnames[..sizeof(strarr)-1], string name)
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:535:    UNLOCK;    return sort(indices(cache));    }       array(Termcap) _values()    {    array(object|int) res = ({});    mapping(int:string) extra = ([]);    LOCK;    if (complete_index) -  res = Array.map(sort(indices(cache)), +  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]);    return cache[name];    }, extra);    else {    array(string) resi = ({});    string cap;    int i = 1;
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:563:    extra[o] = cap;    }    res += ({ o }) * sizeof(names);    resi += names;    }    sort(resi, res);    complete_index = 1;    }    UNLOCK;    return [array(Termcap)] -  Array.map(res, +  predef::map(res,    lambda(int|Termcap x, mapping(int:Termcap) y) {    return objectp(x)? x : y[x];    },    mkmapping(indices(extra), -  Array.map(values(extra), +  predef::map(values(extra),    Termcap, this)));    }       static private string read_next(string find) // quick search    {    for (;;)    {    int i, j;       if (buf=="" && !more_data()) return 0; // eof
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:700:    if(zero_type(cache[b]))    cache[b] = 0;    complete_index = 1;    }    UNLOCK;    return sort(indices(cache));    }       array(object) _values()    { -  return Array.map(_indices(), +  return predef::map(_indices(),    [function(string:object(Terminfo))]    lambda(string name) {    return cache[name] ||    Terminfo(dir+name[..0]+"/"+name);    });    }       Terminfo load(string term)    {    Terminfo ti;