struct rnndecaddrinfo *rnndec_decodeaddr(struct rnndeccontext *ctx, struct rnndomain *domain, uint64_t addr, int write) { struct rnndecaddrinfo *res = trymatch(ctx, domain->subelems, domain->subelemsnum, addr, write, domain->width, 0, 0); if (res) return res; res = calloc (sizeof *res, 1); asprintf (&res->name, "%s%#"PRIx64"%s", ctx->colors->err, addr, ctx->colors->reset); return res; }
static int expandline(void) { register int c = 0; char * tp; register int e, r; char const *tlim; enum markers matchresult; int orig_size; if (Gkvlen < KEYLENGTH+3) { Gkvlen = KEYLENGTH + 3; Gkeyval = xrealloc(Gkeyval, Gkvlen); } e = 0; r = -1; for (;;) { c = in_buffer_getc(); for (;;) { switch (c) { case EOF: goto uncache_exit; default: out_putc(c); r = 0; break; case '\n': out_putc(c); r = 2; goto uncache_exit; case KDELIM: r = 0; /* check for keyword */ /* first, copy a long enough string into keystring */ tp = Gkeyval; *tp++ = KDELIM; for (;;) { c = in_buffer_getc(); if (tp <= &Gkeyval[KEYLENGTH] && latin1_alpha(c)) *tp++ = c; else break; } *tp++ = c; *tp = '\0'; matchresult = trymatch(Gkeyval+1); if (matchresult==Nomatch) { tp[-1] = 0; out_fputs(Gkeyval); continue; /* last c handled properly */ } /* Now we have a keyword terminated with a K/VDELIM */ if (c==VDELIM) { /* try to find closing KDELIM, and replace value */ tlim = Gkeyval + Gkvlen; for (;;) { c = in_buffer_getc(); if (c=='\n' || c==KDELIM) break; *tp++ =c; if (tlim <= tp) { orig_size = Gkvlen; Gkvlen *= 2; Gkeyval = xrealloc(Gkeyval, Gkvlen); tlim = Gkeyval + Gkvlen; tp = Gkeyval + orig_size; } if (c==EOF) goto keystring_eof; } if (c!=KDELIM) { /* couldn't find closing KDELIM -- give up */ *tp = 0; out_fputs(Gkeyval); continue; /* last c handled properly */ } } /* * CVS will expand keywords that have * overlapping delimiters, eg "$Name$Id$". To * support that (mis)feature, push the closing * delimiter back on the input so that the * loop will resume processing starting with * it. */ if (c == KDELIM) in_buffer_ungetc(); /* now put out the new keyword value */ keyreplace(matchresult); e = 1; break; } break; } } keystring_eof: *tp = 0; out_fputs(Gkeyval); uncache_exit: return r + e; }
static struct rnndecaddrinfo *trymatch (struct rnndeccontext *ctx, struct rnndelem **elems, int elemsnum, uint64_t addr, int write, int dwidth, uint64_t *indices, int indicesnum) { struct rnndecaddrinfo *res; int i, j; for (i = 0; i < elemsnum; i++) { if (!rnndec_varmatch(ctx, &elems[i]->varinfo)) continue; uint64_t offset, idx; char *tmp, *name; switch (elems[i]->type) { case RNN_ETYPE_REG: if (addr < elems[i]->offset) break; if (elems[i]->stride) { idx = (addr-elems[i]->offset)/elems[i]->stride; offset = (addr-elems[i]->offset)%elems[i]->stride; } else { idx = 0; offset = addr-elems[i]->offset; } if (offset >= elems[i]->width/dwidth) break; if (elems[i]->length && idx >= elems[i]->length) break; res = calloc (sizeof *res, 1); res->typeinfo = &elems[i]->typeinfo; res->width = elems[i]->width; asprintf (&res->name, "%s%s%s", ctx->colors->rname, elems[i]->name, ctx->colors->reset); for (j = 0; j < indicesnum; j++) res->name = appendidx(ctx, res->name, indices[j]); if (elems[i]->length != 1) res->name = appendidx(ctx, res->name, idx); if (offset) { asprintf (&tmp, "%s+%s%#"PRIx64"%s", res->name, ctx->colors->err, offset, ctx->colors->reset); free(res->name); res->name = tmp; } return res; case RNN_ETYPE_STRIPE: for (idx = 0; idx < elems[i]->length || !elems[i]->length; idx++) { if (addr < elems[i]->offset + elems[i]->stride * idx) break; offset = addr - (elems[i]->offset + elems[i]->stride * idx); int extraidx = (elems[i]->length != 1); int nindnum = (elems[i]->name ? 0 : indicesnum + extraidx); uint64_t nind[nindnum]; if (!elems[i]->name) { for (j = 0; j < indicesnum; j++) nind[j] = indices[j]; if (extraidx) nind[indicesnum] = idx; } res = trymatch (ctx, elems[i]->subelems, elems[i]->subelemsnum, offset, write, dwidth, nind, nindnum); if (!res) continue; if (!elems[i]->name) return res; asprintf (&name, "%s%s%s", ctx->colors->rname, elems[i]->name, ctx->colors->reset); for (j = 0; j < indicesnum; j++) name = appendidx(ctx, name, indices[j]); if (elems[i]->length != 1) name = appendidx(ctx, name, idx); asprintf (&tmp, "%s.%s", name, res->name); free(name); free(res->name); res->name = tmp; return res; } break; case RNN_ETYPE_ARRAY: if (addr < elems[i]->offset) break; idx = (addr-elems[i]->offset)/elems[i]->stride; offset = (addr-elems[i]->offset)%elems[i]->stride; if (elems[i]->length && idx >= elems[i]->length) break; asprintf (&name, "%s%s%s", ctx->colors->rname, elems[i]->name, ctx->colors->reset); for (j = 0; j < indicesnum; j++) name = appendidx(ctx, name, indices[j]); if (elems[i]->length != 1) name = appendidx(ctx, name, idx); if ((res = trymatch (ctx, elems[i]->subelems, elems[i]->subelemsnum, offset, write, dwidth, 0, 0))) { asprintf (&tmp, "%s.%s", name, res->name); free(name); free(res->name); res->name = tmp; return res; } res = calloc (sizeof *res, 1); asprintf (&tmp, "%s+%s%#"PRIx64"%s", name, ctx->colors->err, offset, ctx->colors->reset); free(name); res->name = tmp; return res; default: break; } } return 0; }