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.26 2008/01/04 11:33:18 grubba Exp $ + // $Id: Terminfo.pmod,v 1.27 2008/06/28 16:37:00 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 = + protected private array ctrlcharsfrom =    map(indices(allocate(32)),    lambda(int z) { return sprintf("^%c",z+64); })+    map(indices(allocate(32)),    lambda(int z) { return sprintf("^%c",z+96); }); - static private array ctrlcharsto = + protected private array ctrlcharsto =    map(indices(allocate(32)),    lambda(int z) { return sprintf("%c",z); })+    map(indices(allocate(32)),    lambda(int z) { return sprintf("%c",z); });       - static private class TermMachine { + protected private class TermMachine {       mapping(string:string|int) map = ([]);       int tgetflag(string id)    {    return map[id]==1;    }       int tgetnum(string id)    {
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:144:   }      //! Termcap terminal description object.   class Termcap {       inherit TermMachine;       //!    array(string) aliases;    -  static Termcap parent; +  protected Termcap parent;       //! Put termcap string    string tputs(string s)    {    // Delay stuff completely ignored...    sscanf(s, "%*d%s", s);    return s;    }    -  private static multiset(string) load_cap(string en) +  private protected multiset(string) load_cap(string en)    {    string br=":";    int i=search(en,":");    int j=search(en,",");    multiset(string) clears = (<>);       if (i==-1) { i=j; br=","; }    else if (j!=-1) { i=min(i,j); if (i==j) br=","; }    if (i<1)    error("Termcap: Unparsable entry\n");
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:275:         //! Terminfo terminal description object   class Terminfo {       inherit TermMachine;       //!    array(string) aliases;    -  static private constant boolnames = +  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" }); -  static private constant numnames = +  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",    "Ym","Yn","BT","Yo","Yp" }); -  static private constant strnames = +  protected private constant strnames =    ({ "bt","bl","cr","cs","ct","cl","ce","cd","ch","CC","cm","do","ho","vi",    "le","CM","ve","nd","ll","up","vs","dc","dl","ds","hd","as","mb","md",    "ti","dm","mh","im","mk","mp","mr","so","us","ec","ae","me","te","ed",    "ei","se","ue","vb","ff","fs","i1","is","i3","if","ic","al","ip","kb",    "ka","kC","kt","kD","kL","kd","kM","kE","kS","k0","k1","k;","k2","k3",    "k4","k5","k6","k7","k8","k9","kh","kI","kA","kl","kH","kN","kP","kr",    "kF","kR","kT","ku","ke","ks","l0","l1","la","l2","l3","l4","l5","l6",    "l7","l8","l9","mo","mm","nw","pc","DC","DL","DO","IC","SF","AL","LE",    "RI","SR","UP","pk","pl","px","ps","pf","po","rp","r1","r2","r3","rf",    "rc","cv","sc","sf","sr","sa","st","wi","ta","ts","uc","hu","iP","K1",
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:325:    //! Document this function    string tputs(string s)    {    // 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) +  protected private string swab(string s)    {    return predef::map(s/2, reverse)*"";    }    -  static private int load_cap(.File f, int|void bug_compat) +  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)    return 0;    aliases = (f->read(sname)-"\0")/"|";    {    int blen = nbool;
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:405:    f->close();    if (!r)    error("Terminfo: unparsable terminfo file \"%s\"\n", filename);    }   }      class TermcapDB {       MUTEX    -  static private inherit .File; +  protected private inherit .File;    -  static private string buf=""; -  static private mapping(string:int|Termcap) cache=([]); -  static private int complete_index=0; +  protected private string buf=""; +  protected private mapping(string:int|Termcap) cache=([]); +  protected private int complete_index=0;       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
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:441:    break;    }    }    }    }    if (!::open(filename, "r")) {    error("failed to open termcap file %O\n", filename);    }    }    -  static private void rewind(int|void pos) +  protected private void rewind(int|void pos)    {    ::seek(pos);    buf="";    }    -  static private int more_data() +  protected private int more_data()    {    string q;    q=::read(8192);    if (q=="" || !q) return 0;    buf+=q;    return 1;    }    -  static private array(string) get_names(string cap) +  protected private array(string) get_names(string cap)    {    sscanf(cap, "%s:", cap);    sscanf(cap, "%s,", cap);    return cap/"|";    }    -  static private string read() +  protected private string read()    {    int i, st;    string res="";    for (;;)    {    if (buf=="" && !more_data()) return 0; // eof       sscanf(buf,"%*[ \t\r\n]%s",buf);    if (buf=="") continue;   
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:521:    res+=buf[..i-1];    buf=buf[i+1..];       foreach(get_names(res), string name)    if(!objectp(cache[name]))    cache[name]=st;       return res;    }    -  static private string readat(int pos) +  protected private string readat(int pos)    {    rewind(pos);    return read();    }       array(string) _indices()    {    LOCK;    if(!complete_index) {    rewind();
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:582:    return [array(Termcap)]    predef::map(res,    lambda(int|Termcap x, mapping(int:Termcap) y) {    return objectp(x)? [object(Termcap)]x : y[x];    },    mkmapping(indices(extra),    predef::map(values(extra),    Termcap, this)));    }    -  static private string read_next(string find) // quick search +  protected private string read_next(string find) // quick search    {    for (;;)    {    int i, j;       if (buf=="" && !more_data()) return 0; // eof       i=search(buf,find);    if (i!=-1)    {
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:660:    {    return load(name);    }   }         class TerminfoDB {       MUTEX    -  static private string dir; -  static private mapping(string:Terminfo) cache = ([]); -  static private int complete_index=0; +  protected private string dir; +  protected private mapping(string:Terminfo) cache = ([]); +  protected private int complete_index=0;       void create(string|void dirname)    {    if (!dirname)    {    foreach (({"/usr/share/lib/terminfo", "/usr/share/terminfo",    "/usr/share/termcap",    "/usr/lib/terminfo", "/usr/share/misc/terminfo"}), string dn)    {    .Stat s = file_stat(dn);
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:746:    UNLOCK;    return ti;    }       Terminfo `[](string name)    {    return load(name);    }   }    - static private Termcap defterm; - static private TermcapDB deftermcap; - static private TerminfoDB defterminfo; + protected private Termcap defterm; + protected private TermcapDB deftermcap; + protected private TerminfoDB defterminfo;      TermcapDB defaultTermcapDB()   {    TermcapDB tcdb;    LOCK;    catch { tcdb = deftermcap || (deftermcap = TermcapDB()); };    UNLOCK;    return tcdb;   }   
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:827:    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")].   //!   //! @seealso   //! Stdio.Terminfo.getTerm - static Termcap getFallbackTerm(string term) + protected Termcap getFallbackTerm(string term)   {    return (term=="dumb"? Termcap("dumb:\\\n\t:am:co#80:do=^J:") :    getTerm("dumb"));   }    - static int is_tty_cache; + protected int is_tty_cache;      int is_tty()   //! Returns 1 if @[Stdio.stdin] is connected to an interactive   //! terminal that can handle backspacing, carriage return without   //! linefeed, and the like.   {    if(!is_tty_cache)    {   #ifdef __NT__    is_tty_cache=1;