/* * Apply pattern matching to a table: all table entries that match a pattern * are added to wp. */ static void glob_table(const char *pat, XPtrV *wp, struct table *tp) { struct tstate ts; struct tbl *te; for (ktwalk(&ts, tp); (te = ktnext(&ts)); ) { if (gmatch(te->name, pat, false)) XPput(*wp, str_save(te->name, ATEMP)); } }
/* * flush executable commands with relative paths * (just relative or all?) */ void flushcom(bool all) { struct tbl *tp; struct tstate ts; for (ktwalk(&ts, &taliases); (tp = ktnext(&ts)) != NULL; ) if ((tp->flag&ISSET) && (all || tp->val.s[0] != '/')) { if (tp->flag&ALLOC) { tp->flag &= ~(ALLOC|ISSET); afree(tp->val.s, APERM); } tp->flag &= ~ISSET; } }
void tprintinfo(struct table *tp) { struct tbl *te; char *n; unsigned int h; int ncmp; int totncmp = 0, maxncmp = 0; int nentries = 0; struct tstate ts; shellf("table size %d, nfree %d\n", tp->size, tp->nfree); shellf(" Ncmp name\n"); ktwalk(&ts, tp); while ((te = ktnext(&ts))) { struct tbl **pp, *p; h = hash(n = te->name); ncmp = 0; /* taken from ktsearch() and added counter */ for (pp = &tp->tbls[h & (tp->size-1)]; (p = *pp); pp--) { ncmp++; if (*p->name == *n && strcmp(p->name, n) == 0 && (p->flag&DEFINED)) break; /* return p; */ if (pp == tp->tbls) /* wrap */ pp += tp->size; } shellf(" %4d %s\n", ncmp, n); totncmp += ncmp; nentries++; if (ncmp > maxncmp) maxncmp = ncmp; } if (nentries) shellf(" %d entries, worst ncmp %d, avg ncmp %d.%02d\n", nentries, maxncmp, totncmp / nentries, (totncmp % nentries) * 100 / nentries); }