/* * ======== putMod ======== */ Int Text_putMod(Types_ModuleId mid, Char **bufp, Int len) { Text_PrintVisState state; /* If this is an unnamed module... */ if (mid <= Text_unnamedModsLastId) { return (Text_xprintf(bufp, "{module#%d}", mid)); } /* If this is a dynamically registered module... */ if (mid <= Text_registryModsLastId) { return (Text_xprintf(bufp, Registry_findById(mid)->modName)); } /* If this is a static, named module, but the strings are not loaded... */ if (!Text_isLoaded) { return (Text_xprintf(bufp, "{module-rope:%x}", mid)); } /* Otherwise, this is a static, named module. */ state.bufp = bufp; state.len = len < 0 ? 0x7fff : len; /* 0x7fff == infinite, almost */; state.res = 0; Text_visitRopeFxn(mid, (Fxn)Text_printVisFxn, &state); return (state.res); }
/* * ======== putLab ======== * len == -1 => infinite output */ Int Text_putLab(Types_Label *lab, Char **bufp, Int len) { Int res; res = Text_putMod(lab->modId, bufp, len); if (len < 0 || (len - res) > 8) { /* need at most 9 characters for "%p" */ res += Text_xprintf(bufp, "%p", lab->handle); } if (lab->named && (len < 0 || (len - res) >= (4 + (Int)strlen(lab->iname))) ) { res += Text_xprintf(bufp, "('%s')", lab->iname); } return (res); }
/* * ======== putSite ======== * len == -1 => infinite output * * If site->mod == 0, the module is unspecified and will be omitted from the output. */ Int Text_putSite(Types_Site *site, Char **bufp, Int len) { Int res; Int max = len < 0 ? 0x7fff : len; /* 0x7fff == infinite, well almost */ res = 0; if (!site) { return (0); } /* The 'mod' field is optional; 0 if it's unspecified. */ if (site->mod != 0) { res = Text_putMod(site->mod, bufp, max); max -= (res + 2); /* +2 for the ": " string below */ } if (max > 0) { /* Don't output this if there's no mod */ if (site->mod != 0) { res += Text_xprintf(bufp, ": "); } if (site->line == 0) { return (res); } if (site->file && (max >= ((Int)strlen(site->file) + 4))) { Int oc = Text_xprintf(bufp, "\"%s\", ", site->file); res += oc; max -= oc; } /* 7 = length of "line : ", 10 = max decimal digits in 32-bit number */ if (max >= (7 + 10)) { res += Text_xprintf(bufp, "line %d: ", site->line); } } return (res); }
/* * ======== putMod ======== */ Int Text_putMod(Types_ModuleId mid, Char **bufp, Int len) { /* If this is an unnamed module... */ if (mid <= Text_unnamedModsLastId) { return (Text_xprintf(bufp, "{module#%d}", mid)); } /* If this is a dynamically registered module... */ if (mid <= Text_registryModsLastId) { return (Text_xprintf(bufp, Registry_findById(mid)->modName)); } /* If this is a static, named module, but the strings are not loaded... */ if (!Text_isLoaded) { return (Text_xprintf(bufp, "{module-rope:%x}", mid)); } /* Otherwise, this is a static, named module. */ return(Text_xprintf(bufp, "%s", Diags_dictElems[mid-0x8000].modName)); }
/* * ======== printVisFxn ======== */ Bool Text_printVisFxn(Ptr obj, String src) { Text_PrintVisState *state = obj; if (state->len == 0) { return (TRUE); } else { Int oc = Text_xprintf(state->bufp, "%.*s", state->len, src); state->res += oc; if (state->len > 0) { state->len -= oc; } return (FALSE); } }