diff options
| author | Simon Tatham <anakin@pobox.com> | 1999-01-30 21:35:36 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 1999-01-30 21:35:36 +0000 |
| commit | f91811f57de0561cc7c8efb5897a6b62f5c0e0b2 (patch) | |
| tree | 0f942e70bd4936e5806874193d17ba90693cd313 /error.c | |
| download | halibut-f91811f57de0561cc7c8efb5897a6b62f5c0e0b2.zip halibut-f91811f57de0561cc7c8efb5897a6b62f5c0e0b2.tar.gz halibut-f91811f57de0561cc7c8efb5897a6b62f5c0e0b2.tar.bz2 halibut-f91811f57de0561cc7c8efb5897a6b62f5c0e0b2.tar.xz | |
Initial checkin of skeleton application. About to start reading files
[originally from svn r22]
Diffstat (limited to 'error.c')
| -rw-r--r-- | error.c | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -0,0 +1,60 @@ +/* + * error.c: buttress error handling + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include "buttress.h" + +/* + * Error flags + */ +#define PREFIX 0x0001 /* give `buttress:' prefix */ + +static void do_error(int code, va_list ap) { + char error[1024]; + char *sp; + int flags; + + switch(code) { + case err_nomemory: /* no arguments */ + sprintf(error, "out of memory"); + flags = PREFIX; + break; + case err_optnoarg: + sp = va_arg(ap, char *); + sprintf(error, "option `-%.200s' requires an argument", sp); + flags = PREFIX; + break; + case err_nosuchopt: + sp = va_arg(ap, char *); + sprintf(error, "unrecognised option `-%.200s'", sp); + flags = PREFIX; + break; + case err_noinput: /* no arguments */ + sprintf(error, "no input files"); + flags = PREFIX; + break; + } + + if (flags & PREFIX) + fputs("buttress: ", stderr); + fputs(error, stderr); + fputc('\n', stderr); +} + +void fatal(int code, ...) { + va_list ap; + va_start(ap, code); + do_error(code, ap); + va_end(ap); + exit(EXIT_FAILURE); +} + +void error(int code, ...) { + va_list ap; + va_start(ap, code); + do_error(code, ap); + va_end(ap); +} |