Introduce old redir program
[lcapit-junk-code.git] / pet-projects / DLW-1e / das / error.c
blob608aee838ee29c8e6f61c5e3c22e0234109bcbc9
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdarg.h>
4 #include <stdlib.h>
6 #include "error.h"
8 const char *program_name;
10 /* report(): Write 'mesg' with specified 'prefix' to stderr */
11 static void report(const char *prefix, const char *msg, va_list params)
13 fputs(prefix, stderr);
14 vfprintf(stderr, msg, params);
15 fputs("\n", stderr);
18 void error(int line_nr, const char *err, ...)
20 va_list params;
22 fprintf(stderr, "%s:%d: error: ", program_name, line_nr);
24 va_start(params, err);
25 vfprintf(stderr, err, params);
26 va_end(params);
28 fputs("\n", stderr);
31 void fatal(const char *err, ...)
33 va_list params;
35 va_start(params, err);
36 report("fatal: ", err, params);
37 va_end(params);
39 exit(1);
42 void error_setup(const char *name)
44 char *p;
46 p = strrchr(name, '/');
47 program_name = (p == NULL ? name : ++p);