output.c

Wed, 20 Dec 2000 20:34:02 +0100

author
tuomov
date
Wed, 20 Dec 2000 20:34:02 +0100
changeset 29
a2715cff4288
parent 27
228f64ffb422
child 31
e9cad8bd8ec8
permissions
-rw-r--r--

trunk: changeset 32
Use 'ranlib' instead of 'ar s'.

0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
1 /*
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
2 * libtu/output.c
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
3 *
9
55e7f2ff6021 trunk: changeset 12
tuomov
parents: 5
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2000.
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
5 * See the included file LICENSE for details.
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
6 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
7
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
8 #include <stdio.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
9 #include <stdlib.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
10 #include <errno.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
11 #include <strings.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
12 #include <string.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
13
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents: 0
diff changeset
14 #include <libtu/misc.h>
f878a9ffa3e0 trunk: changeset 8
tuomov
parents: 0
diff changeset
15 #include <libtu/output.h>
f878a9ffa3e0 trunk: changeset 8
tuomov
parents: 0
diff changeset
16 #include <libtu/util.h>
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
17
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
18 #if !defined(LIBTU_NO_ERRMSG) && !defined(HAS_SYSTEM_ASPRINTF)
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
19 #include "../snprintf_2.2/snprintf.h"
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
20 #endif
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
21
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
22
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
23 /* verbose
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
24 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
25
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
26 static bool verbose_mode=FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
27 static int verbose_indent_lvl=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
28 static bool progname_enable=TRUE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
29
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
30 #define INDENTATOR_LENGTH 4
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
31
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
32 static char indentator[]={' ', ' ', ' ', ' '};
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
33
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
34
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
35 void verbose(const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
36 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
37 va_list args;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
38
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
39 va_start(args, p);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
40
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
41 verbose_v(p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
42
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
43 va_end(args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
44 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
45
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
46
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
47 void verbose_v(const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
48 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
49 int i;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
50
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
51 if(verbose_mode){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
52 for(i=0; i<verbose_indent_lvl; i++)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
53 writef(stdout, indentator, INDENTATOR_LENGTH);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
54
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
55 vprintf(p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
56 fflush(stdout);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
57 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
58 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
59
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
60
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
61 void verbose_enable(bool enable)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
62 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
63 verbose_mode=enable;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
64 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
65
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
66
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
67 int verbose_indent(int depth)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
68 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
69 int old=verbose_indent_lvl;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
70
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
71 if(depth>=0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
72 verbose_indent_lvl=depth;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
73
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
74 return old;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
75 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
76
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
77
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
78 void warn_progname_enable(bool enable)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
79 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
80 progname_enable=enable;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
81 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
82
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
83
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
84 static void put_prog_name()
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
85 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
86 const char*progname;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
87
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
88 if(!progname_enable)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
89 return;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
90
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
91 progname=prog_execname();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
92
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
93 if(progname==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
94 return;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
95
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
96 fprintf(stderr, "%s: ", (char*)progname);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
97 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
98
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
99 /* warn
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
100 */
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
101
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
102 #define CALL_V(NAME, ARGS) \
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
103 va_list args; va_start(args, p); NAME ARGS; va_end(args);
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
104
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
105
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
106 void warn(const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
107 {
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
108 CALL_V(warn_v, (p, args));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
109 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
110
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
111
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
112 void warn_obj(const char *obj, const char *p, ...)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
113 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
114 CALL_V(warn_obj_v, (obj, p, args));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
115 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
116
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
117
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
118 void warn_obj_line(const char *obj, int line, const char *p, ...)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
119 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
120 CALL_V(warn_obj_line_v, (obj, line, p, args));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
121 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
122
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
123
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
124 void warn_obj_v(const char *obj, const char *p, va_list args)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
125 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
126 warn_obj_line_v(obj, -1, p, args);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
127 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
128
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
129
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
130 void warn_v(const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
131 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
132 put_prog_name();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
133 vfprintf(stderr, p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
134 putc('\n', stderr);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
135 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
136
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
137
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
138 void warn_obj_line_v(const char *obj, int line, const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
139 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
140 put_prog_name();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
141 if(obj!=NULL){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
142 if(line>0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
143 fprintf(stderr, TR("%s:%d: "), obj, line);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
144 else
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
145 fprintf(stderr, "%s: ", obj);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
146 }else{
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
147 if(line>0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
148 fprintf(stderr, TR("%d: "), line);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
149 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
150 vfprintf(stderr, p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
151 putc('\n', stderr);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
152 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
153
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
154
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
155 void warn_err()
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
156 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
157 put_prog_name();
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
158 fprintf(stderr, "%s\n", strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
159 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
160
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
161
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
162 void warn_err_obj(const char *obj)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
163 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
164 put_prog_name();
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
165 if(obj!=NULL)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
166 fprintf(stderr, "%s: %s\n", obj, strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
167 else
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
168 fprintf(stderr, "%s\n", strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
169 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
170
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
171 void warn_err_obj_line(const char *obj, int line)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
172 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
173 put_prog_name();
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
174 if(obj!=NULL){
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
175 if(line>0)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
176 fprintf(stderr, TR("%s:%d: %s\n"), obj, line, strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
177 else
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
178 fprintf(stderr, "%s: %s\n", obj, strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
179 }else{
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
180 if(line>0)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
181 fprintf(stderr, TR("%d: %s\n"), line, strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
182 else
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
183 fprintf(stderr, TR("%s\n"), strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
184 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
185
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
186 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
187
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
188
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
189 /* errmsg
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
190 */
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
191 #ifndef LIBTU_NO_ERRMSG
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
192
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
193 #define CALL_V_RET(NAME, ARGS) \
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
194 char *ret; va_list args; va_start(args, p); ret=NAME ARGS; va_end(args); return ret;
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
195
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
196
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
197 char* errmsg(const char *p, ...)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
198 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
199 CALL_V_RET(errmsg_v, (p, args));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
200 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
201
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
202
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
203 char *errmsg_obj(const char *obj, const char *p, ...)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
204 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
205 CALL_V_RET(errmsg_obj_v, (obj, p, args));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
206 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
207
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
208
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
209 char *errmsg_obj_line(const char *obj, int line, const char *p, ...)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
210 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
211 CALL_V_RET(errmsg_obj_line_v, (obj, line, p, args));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
212 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
213
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
214
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
215 char* errmsg_obj_v(const char *obj, const char *p, va_list args)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
216 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
217 return errmsg_obj_line_v(obj, -1, p, args);
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
218 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
219
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
220
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
221 char *errmsg_v(const char *p, va_list args)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
222 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
223 char *res;
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
224 vasprintf(&res, p, args);
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
225 return res;
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
226 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
227
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
228
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
229 char *errmsg_obj_line_v(const char *obj, int line, const char *p, va_list args)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
230 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
231 char *res1=NULL, *res2, *res3;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
232 if(obj!=NULL){
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
233 if(line>0)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
234 asprintf(&res1, TR("%s:%d: "), obj, line);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
235 else
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
236 asprintf(&res1, "%s: ", obj);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
237 }else{
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
238 if(line>0)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
239 asprintf(&res1, TR("%d: "), line);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
240 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
241 asprintf(&res2, p, args);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
242 if(res1!=NULL){
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
243 if(res2==NULL)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
244 return NULL;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
245 res3=scat(res1, res2);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
246 free(res1);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
247 free(res2);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
248 return res3;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
249 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
250 return res2;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
251 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
252
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
253
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
254 char *errmsg_err()
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
255 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
256 char *res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
257 asprintf(&res, "%s\n", strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
258 return res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
259 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
260
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
261
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
262 char *errmsg_err_obj(const char *obj)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
263 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
264 char *res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
265 if(obj!=NULL)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
266 asprintf(&res, "%s: %s\n", obj, strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
267 else
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
268 asprintf(&res, "%s\n", strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
269 return res;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
270 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
271
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
272
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
273 char *errmsg_err_obj_line(const char *obj, int line)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
274 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
275 char *res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
276 if(obj!=NULL){
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
277 if(line>0)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
278 asprintf(&res, TR("%s:%d: %s\n"), obj, line, strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
279 else
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
280 asprintf(&res, "%s: %s\n", obj, strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
281 }else{
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
282 if(line>0)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
283 asprintf(&res, TR("%d: %s\n"), line, strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
284 else
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
285 asprintf(&res, TR("%s\n"), strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
286 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
287 return res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
288 }
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
289 #endif /* LIBTU_NO_ERRMSG */
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
290
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
291
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
292 /* die
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
293 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
294
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
295 void die(const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
296 {
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
297 CALL_V(die_v, (p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
298 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
299
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
300
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
301 void die_v(const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
302 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
303 warn_v(p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
304 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
305 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
306
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
307
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
308 void die_obj(const char *obj, const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
309 {
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
310 CALL_V(die_obj_v, (obj, p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
311 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
312
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
313
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
314 void die_obj_line(const char *obj, int line, const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
315 {
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
316 CALL_V(die_obj_line_v, (obj, line, p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
317 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
318
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
319
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
320 void die_obj_v(const char *obj, const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
321 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
322 warn_obj_v(obj, p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
323 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
324 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
325
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
326
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
327 void die_obj_line_v(const char *obj, int line, const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
328 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
329 warn_obj_line_v(obj, line, p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
330 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
331 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
332
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
333
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
334 void die_err()
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
335 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
336 warn_err();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
337 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
338 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
339
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
340
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
341 void die_err_obj(const char *obj)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
342 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
343 warn_err_obj(obj);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
344 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
345 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
346
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
347
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
348 void die_err_obj_line(const char *obj, int line)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
349 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
350 warn_err_obj_line(obj, line);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
351 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
352 }

mercurial