msg.c revision 8278
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.3 1995/05/04 03:51:21 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_BOLD);
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_BOLD);
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_BOLD);
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_BOLD);
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 Confirmation Request", errstr, -1, -1);
177    free(errstr);
178}
179
180/* Put up a message in a popup yes/no box and return 1 for YES, 0 for NO */
181int
182msgYesNo(char *fmt, ...)
183{
184    va_list args;
185    char *errstr;
186    int ret;
187
188    errstr = (char *)malloc(FILENAME_MAX);
189    va_start(args, fmt);
190    vsnprintf(errstr, FILENAME_MAX, fmt, args);
191    va_end(args);
192    use_helpline(NULL);
193    use_helpfile(NULL);
194    ret = dialog_yesno("Decision Required", errstr, -1, -1);
195    free(errstr);
196    return ret;
197}
198
199/* Put up a message in an input box and return the value */
200char *
201msgGetInput(char *buf, char *fmt, ...)
202{
203    va_list args;
204    char *errstr;
205    static char input_buffer[256];
206    int rval;
207
208    errstr = (char *)malloc(FILENAME_MAX);
209    va_start(args, fmt);
210    vsnprintf(errstr, FILENAME_MAX, fmt, args);
211    va_end(args);
212    use_helpline(NULL);
213    use_helpfile(NULL);
214    strcpy(input_buffer, buf);
215    rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer);
216    free(errstr);
217    if (!rval)
218	return input_buffer;
219    else
220	return NULL;
221}
222
223