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.2 1999/03/17 23:17:42 marcus Exp $ + // $Id: Terminfo.pmod,v 1.3 1999/03/17 23:26:03 marcus Exp $         #if constant(thread_create)   #define LOCK object m_key = mutex->lock()   #define UNLOCK destruct(m_key)   #define MUTEX static private object mutex = Thread.Mutex();   #else   #define LOCK   #define UNLOCK   #define MUTEX
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:317:    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)*"";    }    -  static private int load_cap(object f) +  static private int load_cap(object 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")/"|";    { -  array(int) bools = values(f->read(nbool/*+(nbool&1)*/)/*[..nbool-1]*/); +  int blen = nbool; +  if((nbool&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_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)    m_delete(tmp, name);    map += tmp;    }    {    string stroffs = swab(f->read(nstr*2));    string strbuf = f->read(sstr); -  +  if(strlen(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(strlen(strbuf)!=sstr)    return 0;    array(string) strarr = Array.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];