msg.c revision 8438
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
7 * $Id: msg.c,v 1.9 1995/05/08 06:06:26 jkh Exp $
8 *
9 * Copyright (c) 1995
10 *	Jordan Hubbard.  All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer,
17 *    verbatim and that no modifications are made prior to this
18 *    point in the file.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 *    must display the following acknowledgement:
24 *	This product includes software developed by Jordan Hubbard
25 *	for the FreeBSD Project.
26 * 4. The name of Jordan Hubbard or the FreeBSD project may not be used to
27 *    endorse or promote products derived from this software without specific
28 *    prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 */
43
44#include "sysinstall.h"
45#include <stdarg.h>
46
47/* Whack up an informational message on the status line, in stand-out */
48void
49msgYap(char *fmt, ...)
50{
51    va_list args;
52    char *errstr;
53    int attrs;
54
55    errstr = (char *)safe_malloc(FILENAME_MAX);
56    va_start(args, fmt);
57    vsnprintf(errstr, FILENAME_MAX, fmt, args);
58    va_end(args);
59    attrs = getattrs(stdscr);
60    attrset(A_REVERSE);
61    mvaddstr(23, 0, errstr);
62    attrset(attrs);
63    refresh();
64    free(errstr);
65}
66
67/* Whack up an informational message on the status line */
68void
69msgInfo(char *fmt, ...)
70{
71    va_list args;
72    char *errstr;
73    int attrs;
74
75    errstr = (char *)safe_malloc(FILENAME_MAX);
76    va_start(args, fmt);
77    vsnprintf(errstr, FILENAME_MAX, fmt, args);
78    va_end(args);
79    attrs = getattrs(stdscr);
80    attrset(A_NORMAL);
81    mvaddstr(23, 0, errstr);
82    attrset(attrs);
83    refresh();
84    free(errstr);
85}
86
87/* Whack up a warning on the status line */
88void
89msgWarn(char *fmt, ...)
90{
91    va_list args;
92    char *errstr;
93    int attrs;
94
95    errstr = (char *)safe_malloc(FILENAME_MAX);
96    strcpy(errstr, "Warning: ");
97    va_start(args, fmt);
98    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
99    va_end(args);
100    attrs = getattrs(stdscr);
101    beep();
102    attrset(A_REVERSE);
103    mvaddstr(23, 0, errstr);
104    attrset(attrs);
105    refresh();
106    free(errstr);
107}
108
109/* Whack up an error on the status line */
110void
111msgError(char *fmt, ...)
112{
113    va_list args;
114    char *errstr;
115    int attrs;
116
117    errstr = (char *)safe_malloc(FILENAME_MAX);
118    strcpy(errstr, "Error: ");
119    va_start(args, fmt);
120    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
121    va_end(args);
122    beep();
123    attrs = getattrs(stdscr);
124    attrset(A_REVERSE);
125    mvaddstr(23, 0, errstr);
126    attrset(attrs);
127    refresh();
128    free(errstr);
129}
130
131/* Whack up a fatal error on the status line */
132void
133msgFatal(char *fmt, ...)
134{
135    va_list args;
136    char *errstr;
137    int attrs;
138
139    errstr = (char *)safe_malloc(FILENAME_MAX);
140    strcpy(errstr, "Fatal Error: ");
141    va_start(args, fmt);
142    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
143    va_end(args);
144    beep();
145    attrs = getattrs(stdscr);
146    attrset(A_REVERSE);
147    mvaddstr(23, 0, errstr);
148    addstr(" - ");
149    addstr("PRESS ANY KEY TO ");
150    if (getpid() == 1)
151	addstr("REBOOT");
152    else
153	addstr("QUIT");
154    attrset(attrs);
155    refresh();
156    free(errstr);
157    getch();
158    systemShutdown();
159}
160
161/* Put up a message in a popup confirmation box */
162void
163msgConfirm(char *fmt, ...)
164{
165    va_list args;
166    char *errstr;
167
168    errstr = (char *)safe_malloc(FILENAME_MAX);
169    va_start(args, fmt);
170    vsnprintf(errstr, FILENAME_MAX, fmt, args);
171    va_end(args);
172    use_helpline(NULL);
173    use_helpfile(NULL);
174    dialog_mesgbox("User Attention Requested", errstr, -1, -1);
175    free(errstr);
176}
177
178/* Put up a message in a popup information box */
179void
180msgNotify(char *fmt, ...)
181{
182    va_list args;
183    char *errstr;
184
185    errstr = (char *)safe_malloc(FILENAME_MAX);
186    va_start(args, fmt);
187    vsnprintf(errstr, FILENAME_MAX, fmt, args);
188    va_end(args);
189    use_helpline(NULL);
190    use_helpfile(NULL);
191    dialog_msgbox("Information Dialog", errstr, -1, -1, 0);
192    free(errstr);
193}
194
195/* Put up a message in a popup yes/no box and return 1 for YES, 0 for NO */
196int
197msgYesNo(char *fmt, ...)
198{
199    va_list args;
200    char *errstr;
201    int ret;
202
203    errstr = (char *)safe_malloc(FILENAME_MAX);
204    va_start(args, fmt);
205    vsnprintf(errstr, FILENAME_MAX, fmt, args);
206    va_end(args);
207    use_helpline(NULL);
208    use_helpfile(NULL);
209    ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1);
210    free(errstr);
211    return ret;
212}
213
214/* Put up a message in an input box and return the value */
215char *
216msgGetInput(char *buf, char *fmt, ...)
217{
218    va_list args;
219    char *errstr;
220    static char input_buffer[256];
221    int rval;
222
223    errstr = (char *)safe_malloc(FILENAME_MAX);
224    va_start(args, fmt);
225    vsnprintf(errstr, FILENAME_MAX, fmt, args);
226    va_end(args);
227    use_helpline(NULL);
228    use_helpfile(NULL);
229    if (buf)
230	strcpy(input_buffer, buf);
231    else
232	input_buffer[0] = '\0';
233    rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer);
234    free(errstr);
235    if (!rval)
236	return input_buffer;
237    else
238	return NULL;
239}
240
241/* Write something to the debugging port */
242void
243msgDebug(char *fmt, ...)
244{
245    va_list args;
246    char *dbg;
247
248    dbg = (char *)safe_malloc(FILENAME_MAX);
249    strcpy(dbg, "DEBUG: ");
250    va_start(args, fmt);
251    vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args);
252    va_end(args);
253    write(DebugFD, dbg, strlen(dbg));
254    free(dbg);
255}
256