msg.c revision 8314
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.6 1995/05/05 23:47:44 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 *)malloc(FILENAME_MAX);
56    errstr[0] = '\0';
57    va_start(args, fmt);
58    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
59    va_end(args);
60    attrs = getattrs(stdscr);
61    attrset(A_REVERSE);
62    mvaddstr(23, 0, errstr);
63    attrset(attrs);
64    refresh();
65    free(errstr);
66}
67
68/* Whack up an informational message on the status line */
69void
70msgInfo(char *fmt, ...)
71{
72    va_list args;
73    char *errstr;
74    int attrs;
75
76    errstr = (char *)malloc(FILENAME_MAX);
77    errstr[0] = '\0';
78    va_start(args, fmt);
79    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
80    va_end(args);
81    attrs = getattrs(stdscr);
82    attrset(A_NORMAL);
83    mvaddstr(23, 0, errstr);
84    attrset(attrs);
85    refresh();
86    free(errstr);
87}
88
89/* Whack up a warning on the status line */
90void
91msgWarn(char *fmt, ...)
92{
93    va_list args;
94    char *errstr;
95    int attrs;
96
97    errstr = (char *)malloc(FILENAME_MAX);
98    strcpy(errstr, "Warning: ");
99    va_start(args, fmt);
100    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
101    va_end(args);
102    attrs = getattrs(stdscr);
103    beep();
104    attrset(A_REVERSE);
105    mvaddstr(23, 0, errstr);
106    attrset(attrs);
107    refresh();
108    free(errstr);
109}
110
111/* Whack up an error on the status line */
112void
113msgError(char *fmt, ...)
114{
115    va_list args;
116    char *errstr;
117    int attrs;
118
119    errstr = (char *)malloc(FILENAME_MAX);
120    strcpy(errstr, "Error: ");
121    va_start(args, fmt);
122    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
123    va_end(args);
124    beep();
125    attrs = getattrs(stdscr);
126    attrset(A_REVERSE);
127    mvaddstr(23, 0, errstr);
128    attrset(attrs);
129    refresh();
130    free(errstr);
131}
132
133/* Whack up a fatal error on the status line */
134void
135msgFatal(char *fmt, ...)
136{
137    va_list args;
138    char *errstr;
139    int attrs;
140
141    errstr = (char *)malloc(FILENAME_MAX);
142    strcpy(errstr, "Fatal Error: ");
143    va_start(args, fmt);
144    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
145    va_end(args);
146    beep();
147    attrs = getattrs(stdscr);
148    attrset(A_REVERSE);
149    mvaddstr(23, 0, errstr);
150    addstr(" - ");
151    addstr("PRESS ANY KEY TO ");
152    if (getpid() == 1)
153	addstr("REBOOT");
154    else
155	addstr("QUIT");
156    attrset(attrs);
157    refresh();
158    free(errstr);
159    getch();
160    systemShutdown();
161}
162
163/* Put up a message in a popup confirmation box */
164void
165msgConfirm(char *fmt, ...)
166{
167    va_list args;
168    char *errstr;
169
170    errstr = (char *)malloc(FILENAME_MAX);
171    va_start(args, fmt);
172    vsnprintf(errstr, FILENAME_MAX, fmt, args);
173    va_end(args);
174    use_helpline(NULL);
175    use_helpfile(NULL);
176    dialog_mesgbox("User Attention Requested", errstr, -1, -1);
177    free(errstr);
178}
179
180/* Put up a message in a popup information box */
181void
182msgNotify(char *fmt, ...)
183{
184    va_list args;
185    char *errstr;
186
187    errstr = (char *)malloc(FILENAME_MAX);
188    va_start(args, fmt);
189    vsnprintf(errstr, FILENAME_MAX, fmt, args);
190    va_end(args);
191    use_helpline(NULL);
192    use_helpfile(NULL);
193    dialog_notify(errstr);
194    free(errstr);
195}
196
197/* Put up a message in a popup yes/no box and return 1 for YES, 0 for NO */
198int
199msgYesNo(char *fmt, ...)
200{
201    va_list args;
202    char *errstr;
203    int ret;
204
205    errstr = (char *)malloc(FILENAME_MAX);
206    va_start(args, fmt);
207    vsnprintf(errstr, FILENAME_MAX, fmt, args);
208    va_end(args);
209    use_helpline(NULL);
210    use_helpfile(NULL);
211    ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1);
212    free(errstr);
213    return ret;
214}
215
216/* Put up a message in an input box and return the value */
217char *
218msgGetInput(char *buf, char *fmt, ...)
219{
220    va_list args;
221    char *errstr;
222    static char input_buffer[256];
223    int rval;
224
225    errstr = (char *)malloc(FILENAME_MAX);
226    va_start(args, fmt);
227    vsnprintf(errstr, FILENAME_MAX, fmt, args);
228    va_end(args);
229    use_helpline(NULL);
230    use_helpfile(NULL);
231    if (buf)
232	strcpy(input_buffer, buf);
233    else
234	input_buffer[0] = '\0';
235    rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer);
236    free(errstr);
237    if (!rval)
238	return input_buffer;
239    else
240	return NULL;
241}
242
243