pike.git / lib / modules / ADT.pmod / Table.pmod

version» Context lines:

pike.git/lib/modules/ADT.pmod/Table.pmod:1:   // Table.pmod by Fredrik Noring, 1998 - // $Id: Table.pmod,v 1.10 1999/11/25 00:55:54 hubbe Exp $ + // $Id: Table.pmod,v 1.11 1999/12/21 12:06:47 noring Exp $      #define TABLE_ERR(msg) throw(({ "(Table) "+msg+"\n", backtrace() }))      class table {    static private mapping fieldmap;    static private array table, fields, types;       static private array|int remap(array|string|int cs, int|void forgive)    {    array v = ({});
pike.git/lib/modules/ADT.pmod/Table.pmod:35:    {    mapping m = decode_value(s);    return copy(m->table, m->fields, m->types);    }       mixed cast(string type)    {    switch(type) {    case "array":    return copy_value(table); - #if 0 // This works only in Pike 0.6. +     case "string":    return ASCII->encode(this_object()); - #endif +     }    }       array _indices()    {    return copy_value(fields);    }       array _values()    {
pike.git/lib/modules/ADT.pmod/Table.pmod:321:    string colsep = options->colsep||"\t";    return Array.map(({ indices(t) }) + values(t),    lambda(array r, string colsep)    { return Array.map(r, _string)*colsep; }, colsep)*rowsep;    }   }();      object ASCII = class {    object decode(string s, void|mapping options)    { -  // Yet to be done +  // Yet to be done.    return 0;    }       string encode(object t, void|mapping options)    {    options = options || ([]);    mapping sizes = ([]);    array fields = indices(t);    string indent = String.strmult(" ", options->indent);       t = t->copy(({ fields }) + values(t)); -  foreach(indices(fields), string field) -  t = (t->map(lambda(mixed m, string field, mapping sizes) -  { m = (string)m; +  for(int field = 0; field < sizeof(fields); field++) +  t = (t->map(lambda(mixed m, int field, mapping sizes) +  { +  m = (string)m;    sizes[field] = max(sizeof(m), sizes[field]); -  return m; }, field, field, sizes)-> +  return m; +  }, +  field, field, sizes)->    map(lambda(string s, string size, int num) -  { return sprintf("%"+(num?"":"-")+size+"s", s); }, +  { +  return sprintf("%"+(num?"":"-")+size+"s", s); +  },    field, (string)sizes[field],    (t->type(field)||([]))->type == "num"));       string l = (indent+"-"+    Array.map(values(sizes),    lambda(int n)    { return String.strmult("-", n); })*"---"+"-");    array table = values(t);    return (indent+" "+table[0]*" "+"\n"+l+"\n"+    Array.map(table[1..], lambda(array row, string indent)