Branch data Line data Source code
1 : : /*
2 : : * libdpkg - Debian packaging suite library routines
3 : : * report.c - message reporting
4 : : *
5 : : * Copyright © 2004-2005 Scott James Remnant <scott@netsplit.com>
6 : : * Copyright © 2008-2013 Guillem Jover <guillem@debian.org>
7 : : *
8 : : * This is free software; you can redistribute it and/or modify
9 : : * it under the terms of the GNU General Public License as published by
10 : : * the Free Software Foundation; either version 2 of the License, or
11 : : * (at your option) any later version.
12 : : *
13 : : * This is distributed in the hope that it will be useful,
14 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : : * GNU General Public License for more details.
17 : : *
18 : : * You should have received a copy of the GNU General Public License
19 : : * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 : : */
21 : :
22 : : #include <config.h>
23 : : #include <compat.h>
24 : :
25 : : #include <stdarg.h>
26 : : #include <stdlib.h>
27 : : #include <stdio.h>
28 : : #include <unistd.h>
29 : :
30 : : #include <dpkg/dpkg.h>
31 : : #include <dpkg/macros.h>
32 : : #include <dpkg/i18n.h>
33 : : #include <dpkg/progname.h>
34 : : #include <dpkg/color.h>
35 : : #include <dpkg/report.h>
36 : :
37 : : static int piped_mode = _IOLBF;
38 : :
39 : : void
40 : 19 : dpkg_set_report_piped_mode(int mode)
41 : : {
42 : 19 : piped_mode = mode;
43 : 19 : }
44 : :
45 : : void
46 : 417 : dpkg_set_report_buffer(FILE *fp)
47 : : {
48 [ - + ]: 417 : if (isatty(fileno(fp)))
49 : 0 : setvbuf(fp, NULL, _IONBF, 0);
50 : : else
51 : 417 : setvbuf(fp, NULL, piped_mode, 0);
52 : 417 : }
53 : :
54 : : void
55 : 31 : dpkg_warning_printer(const char *msg, void *data)
56 : : {
57 : 31 : fprintf(stderr, "%s%s:%s %s%s:%s %s\n",
58 : : color_get(COLOR_PROG), dpkg_get_progname(), color_reset(),
59 : : color_get(COLOR_WARN), _("warning"), color_reset(), msg);
60 : 31 : }
61 : :
62 : : static dpkg_warning_printer_func *warning_printer_func = dpkg_warning_printer;
63 : : static void *warning_printer_data;
64 : :
65 : : void
66 : 0 : dpkg_set_warning_printer(dpkg_warning_printer_func *printer, void *data)
67 : : {
68 : 0 : warning_printer_func = printer;
69 : 0 : warning_printer_data = data;
70 : 0 : }
71 : :
72 : : static int warn_count = 0;
73 : :
74 : : int
75 : 18 : warning_get_count(void)
76 : : {
77 : 18 : return warn_count;
78 : : }
79 : :
80 : : void
81 : 31 : warningv(const char *fmt, va_list args)
82 : : {
83 : 31 : char *buf = NULL;
84 : :
85 : 31 : warn_count++;
86 : :
87 : 31 : m_vasprintf(&buf, fmt, args);
88 : 31 : warning_printer_func(buf, warning_printer_data);
89 : 31 : free(buf);
90 : 31 : }
91 : :
92 : : void
93 : 31 : warning(const char *fmt, ...)
94 : : {
95 : : va_list args;
96 : :
97 : 31 : va_start(args, fmt);
98 : 31 : warningv(fmt, args);
99 : 31 : va_end(args);
100 : 31 : }
101 : :
102 : : void
103 : 0 : notice(const char *fmt, ...)
104 : : {
105 : 0 : char *buf = NULL;
106 : : va_list args;
107 : :
108 : 0 : va_start(args, fmt);
109 : 0 : m_vasprintf(&buf, fmt, args);
110 : 0 : va_end(args);
111 : :
112 : 0 : fprintf(stderr, "%s%s:%s %s\n",
113 : : color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), buf);
114 : :
115 : 0 : free(buf);
116 : 0 : }
117 : :
118 : : void
119 : 18 : info(const char *fmt, ...)
120 : : {
121 : : char *buf;
122 : : va_list args;
123 : :
124 : 18 : va_start(args, fmt);
125 : 18 : m_vasprintf(&buf, fmt, args);
126 : 18 : va_end(args);
127 : :
128 : 18 : printf("%s%s:%s %s\n",
129 : : color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), buf);
130 : :
131 : 18 : free(buf);
132 : 18 : }
|