]>
Commit | Line | Data |
---|---|---|
d1b2a10e | 1 | /* |
2 | * Copyright 1987, 1988 by MIT Student Information Processing Board. | |
3 | * | |
4 | * For copyright info, see mit-sipb-copyright.h. | |
5 | */ | |
6 | ||
d1b2a10e | 7 | #include "mit-sipb-copyright.h" |
8 | ||
a91a6d50 | 9 | #include <stdio.h> |
10 | #include <stdarg.h> | |
d1b2a10e | 11 | #include "error_table.h" |
d1b2a10e | 12 | #include "com_err.h" |
d1b2a10e | 13 | |
a91a6d50 | 14 | static const char rcsid[] = "$Id$"; |
15 | ||
16 | static void default_com_err_proc(const char *progname, long code, | |
17 | const char *fmt, va_list args); | |
d1b2a10e | 18 | |
a91a6d50 | 19 | com_err_handler_t com_err_hook = default_com_err_proc; |
d1b2a10e | 20 | |
a91a6d50 | 21 | static void default_com_err_proc(const char *progname, long code, |
22 | const char *fmt, va_list args) | |
d1b2a10e | 23 | { |
a91a6d50 | 24 | if (progname) { |
25 | fputs(progname, stderr); | |
d1b2a10e | 26 | fputs(": ", stderr); |
27 | } | |
a91a6d50 | 28 | |
d1b2a10e | 29 | if (code) { |
30 | fputs(error_message(code), stderr); | |
31 | fputs(" ", stderr); | |
32 | } | |
a91a6d50 | 33 | if (fmt) |
34 | vfprintf(stderr, fmt, args); | |
35 | ||
36 | /* possibly should do the \r only on a tty in raw mode */ | |
d1b2a10e | 37 | putc('\r', stderr); |
a91a6d50 | 38 | putc('\n', stderr); |
d1b2a10e | 39 | fflush(stderr); |
40 | } | |
41 | ||
a91a6d50 | 42 | void com_err_va(const char *progname, long code, const char *fmt, va_list args) |
d1b2a10e | 43 | { |
a91a6d50 | 44 | (*com_err_hook)(progname, code, fmt, args); |
d1b2a10e | 45 | } |
46 | ||
a91a6d50 | 47 | void com_err(const char *progname, long code, const char *fmt, ...) |
d1b2a10e | 48 | { |
d1b2a10e | 49 | va_list pvar; |
50 | ||
d1b2a10e | 51 | va_start(pvar, fmt); |
a91a6d50 | 52 | com_err_va(progname, code, fmt, pvar); |
d1b2a10e | 53 | va_end(pvar); |
54 | } | |
55 | ||
a91a6d50 | 56 | com_err_handler_t set_com_err_hook(com_err_handler_t new_proc) |
d1b2a10e | 57 | { |
a91a6d50 | 58 | com_err_handler_t x = com_err_hook; |
59 | ||
60 | com_err_hook = (new_proc) ? new_proc : default_com_err_proc; | |
d1b2a10e | 61 | return x; |
62 | } | |
63 | ||
a91a6d50 | 64 | com_err_handler_t reset_com_err_hook() |
65 | { | |
66 | return set_com_err_hook(NULL); | |
d1b2a10e | 67 | } |