9 * We keep an array sorted by bad atom pointer.
10 * The theory is that since we don't free memory very often,
11 * the array will be mostly sorted already and insertions will
12 * usually be near the end, so we won't spend much time
17 * Binary search a Tx list.
18 * If no entry is found, return a pointer to
19 * where a new such entry would go.
22 txsearch(char *atom, Tx *t, int n)
27 else if(atom > t[n/2].bad) {
37 addtx(char *b, char *g)
43 map = emalloc(sizeof(*map));
47 c->t = erealloc(c->t, (c->nt+32)*sizeof(c->t[0]));
48 t = txsearch(b, c->t, c->nt);
49 if(t < c->t+c->nt && t->bad == b) {
50 fprint(2, "warning: duplicate entry for %s in _conform.map\n", b);
55 memmove(t+1, t, (c->t+c->nt - t)*sizeof(Tx));
62 conform(char *s, int isdir)
71 t = txsearch(s, c->t, c->nt);
72 if(t < c->t+c->nt && t->bad == s)
76 sprint(buf, "%c%.6d", isdir ? 'D' : 'F', c ? c->nt : 0);
94 goodcmp(const void *va, const void *vb)
100 return strcmp(a->good, b->good);
104 badatomcmp(const void *va, const void *vb)
110 if(a->good < b->good)
112 if(a->good > b->good)
118 wrconform(Cdimg *cd, int n, ulong *pblock, ulong *plength)
125 *pblock = cd->nextblock;
126 if(c==nil || n==c->nt){
131 Cwseek(cd, cd->nextblock*Blocksize);
132 qsort(c->t, c->nt, sizeof(c->t[0]), goodcmp);
133 for(i=n; i<c->nt; i++) {
134 snprint(buf, sizeof buf, "%s %s\n", c->t[i].good, c->t[i].bad);
135 Cwrite(cd, buf, strlen(buf));
137 qsort(c->t, c->nt, sizeof(c->t[0]), badatomcmp);
138 *plength = Cwoffset(cd) - *pblock*Blocksize;
139 chat("write _conform.map at %lud+%lud\n", *pblock, *plength);