output.c

Fri, 05 Jan 2001 17:31:37 +0100

author
tuomov
date
Fri, 05 Jan 2001 17:31:37 +0100
changeset 32
7e74a8d61b76
parent 31
e9cad8bd8ec8
child 33
3a0064eb9421
permissions
-rw-r--r--

trunk: changeset 35
Added 'stripws'.

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
31
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
106 void libtu_asprintf(char **ret, const char *p, ...)
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
107 {
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
108 CALL_V(vasprintf, (ret, p, args));
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
109 }
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
110
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
111
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
112 void libtu_vasprintf(char **ret, const char *p, va_list args)
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
113 {
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
114 vasprintf(ret, p, args);
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
115 }
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
116
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
117
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
118 void warn(const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
119 {
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
120 CALL_V(warn_v, (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(const char *obj, const char *p, ...)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
125 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
126 CALL_V(warn_obj_v, (obj, 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
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
130 void warn_obj_line(const char *obj, int line, const char *p, ...)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
131 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
132 CALL_V(warn_obj_line_v, (obj, line, p, args));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
133 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
134
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
135
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
136 void warn_obj_v(const char *obj, const char *p, va_list args)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
137 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
138 warn_obj_line_v(obj, -1, p, args);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
139 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
140
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
141
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
142 void warn_v(const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
143 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
144 put_prog_name();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
145 vfprintf(stderr, p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
146 putc('\n', stderr);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
147 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
148
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 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
151 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
152 put_prog_name();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
153 if(obj!=NULL){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
154 if(line>0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
155 fprintf(stderr, TR("%s:%d: "), obj, line);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
156 else
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
157 fprintf(stderr, "%s: ", obj);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
158 }else{
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
159 if(line>0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
160 fprintf(stderr, TR("%d: "), line);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
161 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
162 vfprintf(stderr, p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
163 putc('\n', stderr);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
164 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
165
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
166
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
167 void warn_err()
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
168 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
169 put_prog_name();
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
170 fprintf(stderr, "%s\n", strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
171 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
172
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
173
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
174 void warn_err_obj(const char *obj)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
175 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
176 put_prog_name();
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
177 if(obj!=NULL)
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 fprintf(stderr, "%s\n", strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
181 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
182
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
183 void warn_err_obj_line(const char *obj, int line)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
184 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
185 put_prog_name();
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
186 if(obj!=NULL){
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
187 if(line>0)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
188 fprintf(stderr, TR("%s:%d: %s\n"), obj, line, strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
189 else
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
190 fprintf(stderr, "%s: %s\n", obj, strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
191 }else{
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
192 if(line>0)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
193 fprintf(stderr, TR("%d: %s\n"), line, strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
194 else
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
195 fprintf(stderr, TR("%s\n"), strerror(errno));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
196 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
197
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
198 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
199
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
200
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
201 /* errmsg
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
202 */
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
203 #ifndef LIBTU_NO_ERRMSG
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
204
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
205 #define CALL_V_RET(NAME, ARGS) \
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
206 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
207
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
208
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
209 char* errmsg(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_v, (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(const char *obj, const char *p, ...)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
216 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
217 CALL_V_RET(errmsg_obj_v, (obj, 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_obj_line(const char *obj, int line, const char *p, ...)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
222 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
223 CALL_V_RET(errmsg_obj_line_v, (obj, line, p, args));
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
224 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
225
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
226
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
227 char* errmsg_obj_v(const char *obj, const char *p, va_list args)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
228 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
229 return errmsg_obj_line_v(obj, -1, p, args);
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
230 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
231
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
232
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
233 char *errmsg_v(const char *p, va_list args)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
234 {
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
235 char *res;
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
236 vasprintf(&res, p, args);
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
237 return res;
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
238 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
239
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
240
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
241 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
242 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
243 char *res1=NULL, *res2, *res3;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
244 if(obj!=NULL){
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
245 if(line>0)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
246 asprintf(&res1, TR("%s:%d: "), obj, line);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
247 else
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
248 asprintf(&res1, "%s: ", obj);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
249 }else{
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
250 if(line>0)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
251 asprintf(&res1, TR("%d: "), line);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
252 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
253 asprintf(&res2, p, args);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
254 if(res1!=NULL){
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
255 if(res2==NULL)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
256 return NULL;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
257 res3=scat(res1, res2);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
258 free(res1);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
259 free(res2);
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
260 return res3;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
261 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
262 return res2;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
263 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
264
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
265
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
266 char *errmsg_err()
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
267 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
268 char *res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
269 asprintf(&res, "%s\n", strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
270 return res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
271 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
272
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
273
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
274 char *errmsg_err_obj(const char *obj)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
275 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
276 char *res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
277 if(obj!=NULL)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
278 asprintf(&res, "%s: %s\n", obj, 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\n", strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
281 return res;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
282 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
283
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
284
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
285 char *errmsg_err_obj_line(const char *obj, int line)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
286 {
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
287 char *res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
288 if(obj!=NULL){
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
289 if(line>0)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
290 asprintf(&res, TR("%s:%d: %s\n"), obj, line, strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
291 else
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
292 asprintf(&res, "%s: %s\n", obj, strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
293 }else{
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
294 if(line>0)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
295 asprintf(&res, TR("%d: %s\n"), line, strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
296 else
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
297 asprintf(&res, TR("%s\n"), strerror(errno));
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
298 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
299 return res;
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
300 }
31
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
301
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
302 #endif /* LIBTU_NO_ERRMSG */
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
303
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
304
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
305 /* die
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(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_v, (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_v(const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
315 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
316 warn_v(p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
317 exit(EXIT_FAILURE);
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
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
321 void die_obj(const char *obj, const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
322 {
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
323 CALL_V(die_obj_v, (obj, p, args));
0
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(const char *obj, int line, const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
328 {
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
329 CALL_V(die_obj_line_v, (obj, line, p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
330 }
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 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
334 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
335 warn_obj_v(obj, p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
336 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
337 }
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 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
341 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
342 warn_obj_line_v(obj, line, p, args);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
343 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
344 }
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 void die_err()
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
348 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
349 warn_err();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
350 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
351 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
352
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
353
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
354 void die_err_obj(const char *obj)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
355 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
356 warn_err_obj(obj);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
357 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
358 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
359
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
360
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
361 void die_err_obj_line(const char *obj, int line)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
362 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
363 warn_err_obj_line(obj, line);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
364 exit(EXIT_FAILURE);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
365 }

mercurial