githelper.git / githelper.pike

version» Context lines:

githelper.git/githelper.pike:103:    };       class MatchAttr(string name, int is_macro, array(AttrState) states) {    static string _sprintf(int type) {    return type=='O' && sprintf("MatchAttr(%O, %d, %O)\n",    name, is_macro, states);    }    };       static array(MatchAttr) attrs = ({}); +  static mapping(string:MatchAttr) macros = ([]);       static int invalid_attr_name(string name)    {    int n;    if(name == "" || name[0] == '-')    return 1;    sscanf(name, "%*[-._0-9a-zA-Z]%n", n);    return n != sizeof(name);    }   
githelper.git/githelper.pike:158:    {    MatchAttr a = parse_attr_line(line, macro_ok);    if(a) attrs += ({ a });    }       static void create(string data)    {    foreach(data/"\n", string line)    handle_attr_line(line, 1);    attrs = reverse(attrs); +  foreach(attrs, MatchAttr a) +  if(a->is_macro) +  macros[a->name] = a; +  attrs = filter(attrs, lambda(MatchAttr a) { return !a->is_macro; });    }       static int path_matches(string path, string pattern)    {    if(search(pattern, "/")<0)    return glob(pattern, (path/"/")[-1]);    if(has_prefix(pattern, "/"))    pattern = pattern[1..];    return glob(pattern, path);    }       static void macroexpand_one(string attrname, array(MatchAttr) attrs,    mapping(string:string|int) all_attr)    { -  MatchAttr ma = 0; +     if(all_attr[attrname] != ATTR_TRUE)    return; -  foreach(attrs, MatchAttr a) -  if(a->is_macro && a->name == attrname) -  ma = a; +  MatchAttr ma = macros[attrname];    if(ma) fill_one(ma, attrs, all_attr);    }       static void fill_one(MatchAttr attr, array(MatchAttr) attrs,    mapping(string:string|int) all_attr)    {    foreach(attr->states, AttrState s) {    if(!all_attr[s->attr]) {    all_attr[s->attr] = s->setto;    macroexpand_one(s->attr, attrs, all_attr);    }    }    }       static void fill(string path, array(MatchAttr) attrs,    mapping(string:string|int) all_attr)    {    foreach(attrs, MatchAttr a) -  if(!a->is_macro && path_matches(path, a->name)) +  if(/*!a->is_macro &&*/ path_matches(path, a->name))    fill_one(a, attrs, all_attr);    }       mapping(string:string|int) checkattr(string path)    {    mapping(string:string|int) all_attr = ([]);    fill(path, attrs, all_attr);    return all_attr;    }       array(string) findattr(string attrname)    {    array(string) r = ({}); -  foreach(attrs, MatchAttr attr) { +  foreach(attrs+values(macros), MatchAttr attr) {    int z=0;    foreach(attr->states, AttrState state)    if(state->attr == attrname && state->setto == ATTR_TRUE) {    z = 1;    break;    }    if (z)    r += ({ attr->name });    }    return r;