static void outputtree(nick *np, unsigned int marker, trustgroup *originalgroup, trusthost *th, int depth, int showchildren) { const char *cidrstr; char *prespacebuf, *postspacebuf, parentbuf[512]; if(th->marker != marker) return; cidrstr = CIDRtostr(th->ip, th->bits); calculatespaces(depth + 2, 30 + 1, cidrstr, &prespacebuf, &postspacebuf); if(th->group == originalgroup) { if(!showchildren && th->group == originalgroup && th->children) prespacebuf[0] = '*'; else prespacebuf[0] = ' '; prespacebuf[1] = '>'; parentbuf[0] = '\0'; } else { /* show the ids of other groups */ snprintf(parentbuf, sizeof(parentbuf), "%-10d %s", th->group->id, th->group->name->content); } controlreply(np, "%s%s%s %-10d %-10d %-21s %-15d /%-14d%s", prespacebuf, cidrstr, postspacebuf, th->count, th->maxusage, (th->count>0)?"(now)":((th->lastseen>0)?trusts_timetostr(th->lastseen):"(never)"), th->maxpernode, (irc_in_addr_is_ipv4(&th->ip))?(th->nodebits - 96):th->nodebits, parentbuf); /* Make sure we're not seeing this subtree again. */ th->marker = -1; for(th=th->children;th;th=th->nextbychild) outputtree(np, marker, originalgroup, th, depth + 1, showchildren); }
int main(int argc, char *argv[]) { suf_t *sa,*isa, *H; i64 n, last; i64 i; uchar *T; FILE *in; if (argc < 3) { printf("mkcst file file.bw file.lst\n"); return 0; } bw_to_psi(&n, &last, &sa, argv[2], argv[3]); psi_to_sa(n, last, sa, sa); #if 1 for (i=0; i<=n; i++) { printf("sa[%ld] = %ld\n",i,sa[i]); } #endif isa = (suf_t *)mymalloc((n+2)*sizeof(suf_t)); T = (uchar *)mymalloc((n+1)*sizeof(uchar)); H = (suf_t *)mymalloc((n+1)*sizeof(suf_t)); in = fopen(argv[1],"r"); if (in == NULL) {printf("cannot open %s\n",argv[1]); exit(1);} for (i=0; i<n; i++) T[i] = fgetc(in); fclose(in); fast_hgt(isa, sa, T, H, n); #if 1 for (i=0; i<=n; i++) { printf("H[%ld] = %d\n",i,H[i]); } #endif char file[20]; strcpy(file, "output.bp" ); outputtree(file, H, n); fast_hgt2(isa, sa, T, H, n); #if 1 for (i=0; i<=n; i++) { printf("H[%ld] = %d\n",i,H[i]); } #endif strcpy(file, "output.bp2" ); outputtree2(file, H, n); }
static void displaygroup(nick *sender, trustgroup *tg, int showchildren) { trusthost *th, **p2; unsigned int marker; array parents; int i; time_t t = getnettime(); /* abusing the ternary operator a bit :( */ controlreply(sender, "Name : %s", tg->name->content); controlreply(sender, "Trusted for : %s", formatlimit(tg->trustedfor)); controlreply(sender, "Currently using : %d", tg->count); controlreply(sender, "Clients per user : %s", formatlimit(tg->maxperident)); controlreply(sender, "Flags : %s", formatflags(tg->flags)); controlreply(sender, "Contact : %s", tg->contact->content); controlreply(sender, "Expires in : %s", (tg->expires)?((tg->expires>t)?longtoduration(tg->expires - t, 2):"the past (will be removed during next cleanup)"):"never"); controlreply(sender, "Created by : %s", tg->createdby->content); controlreply(sender, "Comment : %s", tg->comment->content); controlreply(sender, "ID : %u", tg->id); controlreply(sender, "Last used : %s", (tg->count>0)?"(now)":((tg->lastseen>0)?trusts_timetostr(tg->lastseen):"(never)")); controlreply(sender, "Max usage : %d", tg->maxusage); controlreply(sender, "Last max reset : %s", tg->lastmaxusereset?trusts_timetostr(tg->lastmaxusereset):"(never)"); controlreply(sender, "---"); controlreply(sender, "Attributes: * (has hidden children, show with -v), > (belongs to this trust group)"); controlreply(sender, "Host Current Max Last seen Max per Node Node Mask Group ID Group name"); marker = nextthmarker(); array_init(&parents, sizeof(trusthost *)); for(th=tg->hosts;th;th=th->next) marktree(&parents, marker, th, showchildren); p2 = (trusthost **)(parents.content); for(i=0;i<parents.cursi;i++) outputtree(sender, marker, tg, p2[i], 0, showchildren); array_free(&parents); }