2 * The new sysinstall program.
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
7 * $FreeBSD: src/release/sysinstall/msg.c,v 1.52.2.4 2001/09/11 20:42:42 jkh Exp $
8 * $DragonFly: src/release/sysinstall/Attic/msg.c,v 1.2 2003/06/17 04:27:21 dillon Exp $
11 * Jordan Hubbard. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer,
18 * verbatim and that no modifications are made prior to this
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "sysinstall.h"
40 #include <sys/ioctl.h>
41 #include <machine/console.h>
48 return (cp = variable_get(VAR_DEBUG)) && strcmp(cp, "no");
51 /* Whack up an informational message on the status line, in stand-out */
53 msgYap(char *fmt, ...)
59 errstr = (char *)alloca(FILENAME_MAX);
61 vsnprintf(errstr, FILENAME_MAX, fmt, args);
63 attrs = getattrs(stdscr);
65 mvaddstr(StatusLine, 0, errstr);
70 /* Whack up an informational message on the status line */
72 msgInfo(char *fmt, ...)
79 attrs = getattrs(stdscr);
80 /* NULL is a special convention meaning "erase the old stuff" */
86 errstr = (char *)alloca(FILENAME_MAX);
88 vsnprintf(errstr, FILENAME_MAX, fmt, args);
90 memset(line, ' ', 80);
91 for (i = 0; i < 80; i++) {
99 mvaddstr(StatusLine, 0, line);
101 move(StatusLine, 79);
105 /* Whack up a warning on the status line */
107 msgWarn(char *fmt, ...)
113 errstr = (char *)alloca(FILENAME_MAX);
114 strcpy(errstr, "Warning: ");
116 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
118 attrs = getattrs(stdscr);
121 mvaddstr(StatusLine, 0, errstr);
124 if (OnVTY && isDebug())
125 msgDebug("Warning message `%s'\n", errstr);
128 /* Whack up an error on the status line */
130 msgError(char *fmt, ...)
136 errstr = (char *)alloca(FILENAME_MAX);
137 strcpy(errstr, "Error: ");
139 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
142 attrs = getattrs(stdscr);
144 mvaddstr(StatusLine, 0, errstr);
147 if (OnVTY && isDebug())
148 msgDebug("Error message `%s'\n", errstr);
151 /* Whack up a fatal error on the status line */
153 msgFatal(char *fmt, ...)
159 errstr = (char *)alloca(FILENAME_MAX);
160 strcpy(errstr, "Fatal Error: ");
162 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
165 attrs = getattrs(stdscr);
167 mvaddstr(StatusLine, 0, errstr);
169 addstr("PRESS ANY KEY TO ");
177 msgDebug("Fatal error `%s'!\n", errstr);
182 /* Put up a message in a popup confirmation box */
184 msgConfirm(char *fmt, ...)
188 WINDOW *w = savescr();
190 errstr = (char *)alloca(FILENAME_MAX);
192 vsnprintf(errstr, FILENAME_MAX, fmt, args);
197 ioctl(0, VT_ACTIVATE, 1);
200 dialog_notify(errstr);
204 /* Put up a message in a popup information box */
206 msgNotify(char *fmt, ...)
211 errstr = (char *)alloca(FILENAME_MAX);
213 vsnprintf(errstr, FILENAME_MAX, fmt, args);
218 msgDebug("Notify: %s\n", errstr);
219 dialog_msgbox(NULL, errstr, -1, -1, 0);
222 /* Put up a message in a popup yes/no box and return 0 for YES, 1 for NO */
224 msgYesNo(char *fmt, ...)
229 WINDOW *w = savescr();
231 errstr = (char *)alloca(FILENAME_MAX);
233 vsnprintf(errstr, FILENAME_MAX, fmt, args);
238 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
241 if (variable_get(VAR_NONINTERACTIVE))
242 return 0; /* If non-interactive, return YES all the time */
243 ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1);
248 /* Put up a message in a popup no/yes box and return 0 for YES, 1 for NO */
250 msgNoYes(char *fmt, ...)
255 WINDOW *w = savescr();
257 errstr = (char *)alloca(FILENAME_MAX);
259 vsnprintf(errstr, FILENAME_MAX, fmt, args);
264 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
267 if (variable_get(VAR_NONINTERACTIVE))
268 return 1; /* If non-interactive, return NO all the time */
269 ret = dialog_noyes("User Confirmation Requested", errstr, -1, -1);
274 /* Put up a message in an input box and return the value */
276 msgGetInput(char *buf, char *fmt, ...)
280 static char input_buffer[256];
282 WINDOW *w = savescr();
284 errstr = (char *)alloca(FILENAME_MAX);
286 vsnprintf(errstr, FILENAME_MAX, fmt, args);
291 SAFE_STRCPY(input_buffer, buf);
293 input_buffer[0] = '\0';
295 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
298 rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer);
306 /* Write something to the debugging port */
308 msgDebug(char *fmt, ...)
315 dbg = (char *)alloca(FILENAME_MAX);
316 strcpy(dbg, "DEBUG: ");
318 vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args);
320 write(DebugFD, dbg, strlen(dbg));
323 /* Tell the user there's some output to go look at */
325 msgWeHaveOutput(char *fmt, ...)
329 WINDOW *w = savescr();
331 errstr = (char *)alloca(FILENAME_MAX);
333 vsnprintf(errstr, FILENAME_MAX, fmt, args);
337 msgDebug("Notify: %s\n", errstr);
338 dialog_clear_norefresh();
340 dialog_msgbox(NULL, errstr, -1, -1, 0);
344 /* Simple versions of msgConfirm() and msgNotify() for calling from scripts */
346 msgSimpleConfirm(char *str)
348 msgConfirm("%s", str);
349 return DITEM_SUCCESS;
353 msgSimpleNotify(char *str)
355 msgNotify("%s", str);
356 return DITEM_SUCCESS;