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.29 2008/11/03 08:42:40 stewa Exp $ + // $Id: Terminfo.pmod,v 1.30 2010/06/05 12:40:37 grubba Exp $   #pike __REAL_VERSION__         #if constant(thread_create)   #define LOCK object m_key = mutex->lock()   #define UNLOCK destruct(m_key)   #define MUTEX protected private object(Thread.Mutex) mutex = Thread.Mutex();   #else   #define LOCK   #define UNLOCK
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:401:    .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);    }   }    + //! Termcap database   class TermcapDB {       MUTEX       protected private inherit .File;       protected private string buf="";    protected private mapping(string:int|Termcap) cache=([]);    protected private int complete_index=0;   
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:655:    }    return objectp(cap) && [object(Termcap)]cap;    }       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;    -  void create(string|void dirname) +  protected string _sprintf()    { -  +  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.    foreach (({"/usr/share/lib/terminfo", "/usr/share/terminfo",    "/usr/share/termcap", -  "/usr/lib/terminfo", "/usr/share/misc/terminfo"}), string dn) +  "/usr/lib/terminfo", "/usr/share/misc/terminfo", +  "/lib/terminfo", "/etc/terminfo" }), string dn)    {    .Stat s = file_stat(dn);    if (s && s->type=="dir")    {    dirname = dn;    break;    }    }    if (!dirname) {    destruct(this);
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:746:    UNLOCK;    return ti;    }       Terminfo `[](string name)    {    return load(name);    }   }    + //! @[TerminfoDB] that merges several directorys. + class MetaTerminfoDB { +  protected array(TerminfoDB) dbs = ({}); +  +  //! Create a new Meta @[TerminfoDB]. +  //! +  //! @param dbs +  //! Array with elements in priority order. Elements may be either +  //! @mixed +  //! @type TerminfoDB +  //! An active @[TerminfoDB]. +  //! @type string +  //! A directory that may exist and contain a terminfo database. +  //! @endarray +  //! +  //! @returns +  //! If the resulting set of @[TerminfoDB]'s is empty, +  //! the object will be destructed. +  protected void create(array(TerminfoDB|string)|void dbs) +  { +  if (!dbs) { +  // Terminfo locations in priority order. +  dbs = ({ +  // Local terminfo. +  "/etc/terminfo", +  // Operating System terminfo. +  "/lib/terminfo", "/usr/lib/terminfo", +  // Extra terminfo. These are often symlinks to the above. +  "/usr/share/lib/terminfo", "/usr/share/terminfo", +  "/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 }); +  } +  // werror("TerminfoDBs: %O\n", this_program::dbs); +  if (!sizeof(this_program::dbs)) { +  destruct(this); +  } +  } +  +  Terminfo `[](string name) +  { +  foreach(dbs, TerminfoDB db) { +  Terminfo ti = db[name]; +  if (ti) return ti; +  } +  return 0; +  } + } +    protected private Termcap defterm;   protected private TermcapDB deftermcap; - protected private TerminfoDB defterminfo; + protected private MetaTerminfoDB defterminfo;      TermcapDB defaultTermcapDB()   {    TermcapDB tcdb;    LOCK;    catch { tcdb = deftermcap || (deftermcap = TermcapDB()); };    UNLOCK;    return tcdb;   }    - TerminfoDB defaultTerminfoDB() + MetaTerminfoDB defaultTerminfoDB()   { -  TerminfoDB tidb; +  MetaTerminfoDB tidb;    LOCK; -  catch { tidb = defterminfo || (defterminfo = TerminfoDB()); }; +  catch { tidb = defterminfo || (defterminfo = MetaTerminfoDB()); };    UNLOCK;    return tidb;   }      //! Returns the terminal description object for @[term] from the   //! systems termcap database. Returns 0 if not found.   //!   //! @seealso   //! Stdio.Terminfo.getTerm, Stdio.Terminfo.getTerminfo   Termcap getTermcap(string term)