po: Update German man pages translation
[dpkg.git] / lib / dpkg / report.c
blobf7763b3629c468d594db2662c8be9ffa7a6f6dd6
1 /*
2 * libdpkg - Debian packaging suite library routines
3 * report.c - message reporting
5 * Copyright © 2004-2005 Scott James Remnant <scott@netsplit.com>
6 * Copyright © 2008-2013 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
22 #include <config.h>
23 #include <compat.h>
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <unistd.h>
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>
37 static int piped_mode = _IOLBF;
39 void
40 dpkg_set_report_piped_mode(int mode)
42 piped_mode = mode;
45 void
46 dpkg_set_report_buffer(FILE *fp)
48 if (isatty(fileno(fp)))
49 setvbuf(fp, NULL, _IONBF, 0);
50 else
51 setvbuf(fp, NULL, piped_mode, 0);
54 void
55 dpkg_warning_printer(const char *msg, void *data)
57 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);
62 static dpkg_warning_printer_func *warning_printer_func = dpkg_warning_printer;
63 static void *warning_printer_data;
65 void
66 dpkg_set_warning_printer(dpkg_warning_printer_func *printer, void *data)
68 warning_printer_func = printer;
69 warning_printer_data = data;
72 static int warn_count = 0;
74 int
75 warning_get_count(void)
77 return warn_count;
80 void
81 warningv(const char *fmt, va_list args)
83 char *buf = NULL;
85 warn_count++;
87 m_vasprintf(&buf, fmt, args);
88 warning_printer_func(buf, warning_printer_data);
89 free(buf);
92 void
93 warning(const char *fmt, ...)
95 va_list args;
97 va_start(args, fmt);
98 warningv(fmt, args);
99 va_end(args);
102 void
103 notice(const char *fmt, ...)
105 char *buf = NULL;
106 va_list args;
108 va_start(args, fmt);
109 m_vasprintf(&buf, fmt, args);
110 va_end(args);
112 fprintf(stderr, "%s%s:%s %s\n",
113 color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), buf);
115 free(buf);
118 void
119 info(const char *fmt, ...)
121 char *buf;
122 va_list args;
124 va_start(args, fmt);
125 m_vasprintf(&buf, fmt, args);
126 va_end(args);
128 printf("%s%s:%s %s\n",
129 color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), buf);
131 free(buf);