const char *_sh_translate(const char *message) { #if ERROR_VERSION >= 20000317L return(ERROR_translate(0,0,e_dict,message)); #else #if ERROR_VERSION >= 20000101L return(ERROR_translate(e_dict,message)); #else return(ERROR_translate(message,1)); #endif #endif }
static void context(register Sfio_t* sp, register Error_context_t* cp) { if (cp->context) context(sp, CONTEXT(cp->flags, cp->context)); if (!(cp->flags & ERROR_SILENT)) { if (cp->id) print(sp, cp->id, NiL); if (cp->line > ((cp->flags & ERROR_INTERACTIVE) != 0)) { if (cp->file) sfprintf(sp, ": \"%s\", %s %d", cp->file, ERROR_translate(NiL, NiL, ast.id, "line"), cp->line); else sfprintf(sp, "[%d]", cp->line); } sfputr(sp, ": ", -1); } }
void errorv(const char* id, int level, va_list ap) { register int n; int fd; int flags; char* s; char* t; char* format; char* library; const char* catalog; int line; char* file; #if !_PACKAGE_astsa unsigned long d; struct tms us; #endif if (!error_info.init) { error_info.init = 1; stropt(getenv("ERROR_OPTIONS"), options, sizeof(*options), setopt, NiL); } if (level > 0) { flags = level & ~ERROR_LEVEL; level &= ERROR_LEVEL; } else flags = 0; if ((flags & (ERROR_USAGE|ERROR_NOID)) == ERROR_NOID) { format = (char*)id; id = 0; } else format = 0; if (id) { catalog = (char*)id; if (!*catalog || *catalog == ':') { catalog = 0; library = 0; } else if ((library = strchr(catalog, ':')) && !*++library) library = 0; } else { catalog = 0; library = 0; } if (catalog) id = 0; else { id = (const char*)error_info.id; catalog = error_info.catalog; } if (level < error_info.trace || (flags & ERROR_LIBRARY) && !(((error_info.set | error_info.flags) ^ error_info.clear) & ERROR_LIBRARY) || level < 0 && error_info.mask && !(error_info.mask & (1<<(-level - 1)))) { if (level >= ERROR_FATAL) (*error_info.exit)(level - 1); return; } if (error_info.trace < 0) flags |= ERROR_LIBRARY|ERROR_SYSTEM; flags |= error_info.set | error_info.flags; flags &= ~error_info.clear; if (!library) flags &= ~ERROR_LIBRARY; fd = (flags & ERROR_OUTPUT) ? va_arg(ap, int) : error_info.fd; if (error_info.write) { long off; char* bas; bas = stkptr(stkstd, 0); if (off = stktell(stkstd)) stkfreeze(stkstd, 0); file = error_info.id; if (error_state.prefix) sfprintf(stkstd, "%s: ", error_state.prefix); if (flags & ERROR_USAGE) { if (flags & ERROR_NOID) sfprintf(stkstd, " "); else sfprintf(stkstd, "%s: ", ERROR_translate(NiL, NiL, ast.id, "Usage")); if (file || opt_info.argv && (file = opt_info.argv[0])) print(stkstd, file, " "); } else { if (level && !(flags & ERROR_NOID)) { if (error_info.context && level > 0) context(stkstd, CONTEXT(error_info.flags, error_info.context)); if (file) print(stkstd, file, (flags & ERROR_LIBRARY) ? " " : ": "); if (flags & (ERROR_CATALOG|ERROR_LIBRARY)) { sfprintf(stkstd, "["); if (flags & ERROR_CATALOG) sfprintf(stkstd, "%s %s%s", catalog ? catalog : ERROR_translate(NiL, NiL, ast.id, "DEFAULT"), ERROR_translate(NiL, NiL, ast.id, "catalog"), (flags & ERROR_LIBRARY) ? ", " : ""); if (flags & ERROR_LIBRARY) sfprintf(stkstd, "%s %s", library, ERROR_translate(NiL, NiL, ast.id, "library")); sfprintf(stkstd, "]: "); } } if (level > 0 && error_info.line > ((flags & ERROR_INTERACTIVE) != 0)) { if (error_info.file && *error_info.file) sfprintf(stkstd, "\"%s\", ", error_info.file); sfprintf(stkstd, "%s %d: ", ERROR_translate(NiL, NiL, ast.id, "line"), error_info.line); } } #if !_PACKAGE_astsa if (error_info.time) { if ((d = times(&us)) < error_info.time || error_info.time == 1) error_info.time = d; sfprintf(stkstd, " %05lu.%05lu.%05lu ", d - error_info.time, (unsigned long)us.tms_utime, (unsigned long)us.tms_stime); } #endif switch (level) { case 0: flags &= ~ERROR_SYSTEM; break; case ERROR_WARNING: sfprintf(stkstd, "%s: ", ERROR_translate(NiL, NiL, ast.id, "warning")); break; case ERROR_PANIC: sfprintf(stkstd, "%s: ", ERROR_translate(NiL, NiL, ast.id, "panic")); break; default: if (level < 0) { s = ERROR_translate(NiL, NiL, ast.id, "debug"); if (error_info.trace < -1) sfprintf(stkstd, "%s%d:%s", s, level, level > -10 ? " " : ""); else sfprintf(stkstd, "%s: ", s); for (n = 0; n < error_info.indent; n++) { sfputc(stkstd, ' '); sfputc(stkstd, ' '); } } break; } if (flags & ERROR_SOURCE) { /* * source ([version], file, line) message */ file = va_arg(ap, char*); line = va_arg(ap, int); s = ERROR_translate(NiL, NiL, ast.id, "line"); if (error_info.version) sfprintf(stkstd, "(%s: \"%s\", %s %d) ", error_info.version, file, s, line); else sfprintf(stkstd, "(\"%s\", %s %d) ", file, s, line); }
char* _ast_strerror(int err) { char* msg; int z; #if _lib_strerror z = errno; msg = strerror(err); errno = z; #else if (err > 0 && err <= sys_nerr) msg = (char*)sys_errlist[err]; else msg = 0; #endif if (msg) { #if !_PACKAGE_astsa if (ERROR_translating()) { #if _lib_strerror static int sys; if (!sys) { char* s; char* t; char* p; #if _lib_strerror /* * stash the pending strerror() msg */ msg = strcpy(fmtbuf(strlen(msg) + 1), msg); #endif /* * make sure that strerror() translates */ if (!(s = strerror(1))) sys = -1; else { t = fmtbuf(z = strlen(s) + 1); strcpy(t, s); ast.locale.set |= AST_LC_internal; p = setlocale(LC_MESSAGES, NiL); setlocale(LC_MESSAGES, "C"); sys = (s = strerror(1)) && strcmp(s, t) ? 1 : -1; setlocale(LC_MESSAGES, p); ast.locale.set &= ~AST_LC_internal; } } if (sys > 0) return msg; #endif return ERROR_translate(NiL, NiL, "errlist", msg); } #endif return msg; } msg = fmtbuf(z = 32); sfsprintf(msg, z, ERROR_translate(NiL, NiL, "errlist", "Error %d"), err); return msg; }
int block(int check) { register Cojob_t* cojob; register Joblist_t* job; Rule_t* r; int n; int clear = 0; int resume = 0; if (!state.coshell || !copending(state.coshell)) { if (jobs.intermediate) { /* * mark the jobs that must be generated */ n = 0; for (job = jobs.firstjob; job; job = job->next) if (job->target->must > ((unsigned int)(job->target->dynamic & D_intermediate) != 0)) { n = 1; break; } if (n) { /* * some intermediates must be generated */ error(2, "some intermediates must be generated"); } else { /* * accept missing intermediates */ while (job = jobs.firstjob) { if (error_info.trace || state.explain) error(state.explain ? 0 : -1, "cancelling %s action -- %s", job->target->name, job->status == INTERMEDIATE ? "intermediate not needed" : "missing intermediates accepted"); job->target->status = EXISTS; discard(job); } jobs.intermediate = 0; return 1; } } return 0; } for (;;) { state.waiting = 1; if ((cojob = cowait(state.coshell, check ? (Cojob_t*)state.coshell : (Cojob_t*)0, -1)) && (job = (Joblist_t*)cojob->local)) job->cojob = 0; if (trap()) { if (state.interpreter) clear = resume = 1; if (!cojob) continue; } state.waiting = 0; if (!cojob) { if (check) return 0; break; } if (r = getrule(external.jobdone)) { if (!jobs.tmp) jobs.tmp = sfstropen(); sfprintf(jobs.tmp, "%s %d %s %s", job->target->name, cojob->status, fmtelapsed(cojob->user, CO_QUANT), fmtelapsed(cojob->sys, CO_QUANT)); call(r, sfstruse(jobs.tmp)); } if (cojob->status) { if (n = !EXITED_TERM(cojob->status) || EXIT_CODE(cojob->status)) { if ((job->target->dynamic & D_hasafter) && hasafter(job->target, P_failure)) n = 0; error(n ? 2 : state.explain ? 0 : -1, "%s%s code %d making %s%s", n ? "*** " : null, ERROR_translate(NiL, NiL, NiL, EXITED_TERM(cojob->status) ? "termination" : "exit"), EXIT_CODE(cojob->status), job->target->name, (job->flags & CO_IGNORE) ? ERROR_translate(NiL, NiL, NiL, " ignored") : null); } if (!(job->flags & CO_IGNORE)) { job->flags |= CO_ERRORS; if (state.keepgoing || !n) { if (n) state.errors++; job->flags |= CO_KEEPGOING; } } if (state.interrupt || !(job->flags & (CO_IGNORE|CO_KEEPGOING))) clear = 1; } message((-3, "job: %s: interrupt=%d clear=%d status=%d flags=%08x", job->target->name, state.interrupt, clear, cojob->status, job->flags)); /* * job is done */ if (done(job, clear, cojob)) return 1; } if (resume) longjmp(state.resume.label, 1); if (!state.finish) { if (!copending(state.coshell)) { if (clear) finish(1); } else if (!state.interrupt) error(3, "lost contact with coshell"); } return 0; }