1 /*
2     wmget - A background download manager as a Window Maker dock app
3     Copyright (c) 2001-2003 Aaron Trickey <aaron@amtrickey.net>
4 
5     Permission is hereby granted, free of charge, to any person
6     obtaining a copy of this software and associated documentation files
7     (the "Software"), to deal in the Software without restriction,
8     including without limitation the rights to use, copy, modify, merge,
9     publish, distribute, sublicense, and/or sell copies of the Software,
10     and to permit persons to whom the Software is furnished to do so,
11     subject to the following conditions:
12 
13     The above copyright notice and this permission notice shall be
14     included in all copies or substantial portions of the Software.
15 
16     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19     NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20     CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21     TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22     SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24     ********************************************************************
25     messages.c - functions for writing error, status, & debug messages
26 */
27 
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <errno.h>
31 
32 #include "wmget.h"
33 
34 static OutputLevel output_level_;
35 
36 
set_output_level(OutputLevel lev)37 void set_output_level (OutputLevel lev)
38 {
39     output_level_ = lev;
40 }
41 
42 
output_level(void)43 OutputLevel output_level (void)
44 {
45     return output_level_;
46 }
47 
48 
error(const char * fmt,...)49 void error (const char *fmt, ...)
50 {
51     va_list ap;
52     va_start (ap, fmt);
53     vfprintf (stderr, fmt, ap);
54     va_end (ap);
55     fputs ("\n", stderr);
56 }
57 
error_sys(const char * fmt,...)58 void error_sys (const char *fmt, ...)
59 {
60     va_list ap;
61     va_start (ap, fmt);
62     vfprintf (stderr, fmt, ap);
63     va_end (ap);
64     perror (" ");
65 }
66 
info(const char * fmt,...)67 void info (const char *fmt, ...)
68 {
69     va_list ap;
70 
71     if (output_level_ < OL_NORMAL)
72         return;
73 
74     va_start (ap, fmt);
75     vfprintf (stderr, fmt, ap);
76     va_end (ap);
77     fputs ("\n", stderr);
78 }
79 
debug(const char * fmt,...)80 void debug (const char *fmt, ...)
81 {
82     va_list ap;
83 
84     if (output_level_ < OL_DEBUG)
85         return;
86 
87     va_start (ap, fmt);
88     vfprintf (stderr, fmt, ap);
89     va_end (ap);
90     fputs ("\n", stderr);
91 }
92 
debug_sys(const char * fmt,...)93 void debug_sys (const char *fmt, ...)
94 {
95     va_list ap;
96 
97     if (output_level_ < OL_DEBUG)
98         return;
99 
100     va_start (ap, fmt);
101     vfprintf (stderr, fmt, ap);
102     va_end (ap);
103     perror (" ");
104 }
105 
106 
107