1 /*
2 * Copyright (c) 1993-2016, 2018-2019 Paul Mattes.
3 * Copyright (c) 1990, Jeff Sparkes.
4 * Copyright (c) 1989, Georgia Tech Research Corporation (GTRC), Atlanta, GA
5 * 30332.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the names of Paul Mattes, Jeff Sparkes, GTRC nor the names of
16 * their contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY PAUL MATTES, JEFF SPARKES AND GTRC "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL PAUL MATTES, JEFF SPARKES OR GTRC BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * popups_glue.c
34 * Pop-up messages.
35 */
36
37 #include "globals.h"
38
39 #include "glue.h"
40 #include "glue_gui.h"
41 #include "popups.h" /* must come before child_popups.h */
42 #include "child_popups.h"
43 #include "screen.h"
44 #include "task.h"
45 #include "trace.h"
46 #include "utils.h"
47
48 /* Pop up an error dialog. */
49 void
popup_an_error(const char * fmt,...)50 popup_an_error(const char *fmt, ...)
51 {
52 va_list args;
53 char *s;
54
55 va_start(args, fmt);
56 s = xs_vbuffer(fmt, args);
57 va_end(args);
58
59 /* Log to the trace file. */
60 vtrace("error: %s\n", s);
61
62 if (task_redirect()) {
63 task_error(s);
64 } else if (!glue_gui_error(s)) {
65 fprintf(stderr, "%s\n", s);
66 fflush(stderr);
67 }
68 Free(s);
69 }
70
71 /* Pop up an error dialog, based on an error number. */
72 void
popup_an_errno(int errn,const char * fmt,...)73 popup_an_errno(int errn, const char *fmt, ...)
74 {
75 va_list args;
76 char *s;
77
78 va_start(args, fmt);
79 s = xs_vbuffer(fmt, args);
80 va_end(args);
81
82 if (errn > 0) {
83 popup_an_error("%s: %s", s, strerror(errn));
84 } else {
85 popup_an_error("%s", s);
86 }
87 Free(s);
88 }
89
90 void
action_output(const char * fmt,...)91 action_output(const char *fmt, ...)
92 {
93 va_list args;
94 char *s;
95
96 va_start(args, fmt);
97 s = xs_vbuffer(fmt, args);
98 va_end(args);
99 if (task_redirect()) {
100 task_info("%s", s);
101 } else {
102 if (!glue_gui_output(s)) {
103 fprintf(stderr, "%s\n", s);
104 fflush(stderr);
105 }
106 }
107 Free(s);
108 }
109
110 void
popup_printer_output(bool is_err _is_unused,abort_callback_t * a _is_unused,const char * fmt,...)111 popup_printer_output(bool is_err _is_unused, abort_callback_t *a _is_unused,
112 const char *fmt, ...)
113 {
114 va_list args;
115 char *m;
116
117 va_start(args, fmt);
118 m = xs_vbuffer(fmt, args);
119 va_end(args);
120 popup_an_error("Printer session: %s", m);
121 Free(m);
122 }
123
124 void
popup_child_output(bool is_err _is_unused,abort_callback_t * a _is_unused,const char * fmt,...)125 popup_child_output(bool is_err _is_unused, abort_callback_t *a _is_unused,
126 const char *fmt, ...)
127 {
128 va_list args;
129 char *m;
130
131 va_start(args, fmt);
132 m = xs_vbuffer(fmt, args);
133 va_end(args);
134 action_output("%s", m);
135 Free(m);
136 }
137
138 void
child_popup_init(void)139 child_popup_init(void)
140 {
141 }
142