5 * Jordan Hubbard. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * verbatim and that no modifications are made prior to this
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/ioctl.h>
35 #include <sys/consio.h>
42 return (cp = variable_get(VAR_DEBUG)) && strcmp(cp, "no");
45 /* Whack up an informational message on the status line, in stand-out */
47 msgYap(const char *fmt, ...)
53 errstr = (char *)alloca(FILENAME_MAX);
55 vsnprintf(errstr, FILENAME_MAX, fmt, args);
57 attrs = getattrs(stdscr);
59 mvaddstr(StatusLine, 0, errstr);
64 /* Whack up an informational message on the status line */
66 msgInfo(const char *fmt, ...)
73 attrs = getattrs(stdscr);
74 /* NULL is a special convention meaning "erase the old stuff" */
80 errstr = (char *)alloca(FILENAME_MAX);
82 vsnprintf(errstr, FILENAME_MAX, fmt, args);
84 memset(line, ' ', 80);
85 for (i = 0; i < 80; i++) {
93 mvaddstr(StatusLine, 0, line);
99 /* Whack up a warning on the status line */
101 msgWarn(const char *fmt, ...)
107 errstr = (char *)alloca(FILENAME_MAX);
108 strcpy(errstr, "Warning: ");
110 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
112 attrs = getattrs(stdscr);
115 mvaddstr(StatusLine, 0, errstr);
118 if (OnVTY && isDebug())
119 msgDebug("Warning message `%s'\n", errstr);
122 /* Whack up an error on the status line */
124 msgError(const char *fmt, ...)
130 errstr = (char *)alloca(FILENAME_MAX);
131 strcpy(errstr, "Error: ");
133 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
136 attrs = getattrs(stdscr);
138 mvaddstr(StatusLine, 0, errstr);
141 if (OnVTY && isDebug())
142 msgDebug("Error message `%s'\n", errstr);
145 /* Whack up a fatal error on the status line */
147 msgFatal(const char *fmt, ...)
153 errstr = (char *)alloca(FILENAME_MAX);
154 strcpy(errstr, "Fatal Error: ");
156 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
159 attrs = getattrs(stdscr);
161 mvaddstr(StatusLine, 0, errstr);
163 addstr("PRESS ANY KEY TO ");
171 msgDebug("Fatal error `%s'!\n", errstr);
175 /* Put up a message in a popup confirmation box */
177 msgConfirm(const char *fmt, ...)
181 WINDOW *w = savescr();
183 errstr = (char *)alloca(FILENAME_MAX);
185 vsnprintf(errstr, FILENAME_MAX, fmt, args);
190 ioctl(0, VT_ACTIVATE, 1);
193 dialog_notify(errstr);
197 /* Put up a message in a popup information box */
199 msgNotify(const char *fmt, ...)
204 errstr = (char *)alloca(FILENAME_MAX);
206 vsnprintf(errstr, FILENAME_MAX, fmt, args);
211 msgDebug("Notify: %s\n", errstr);
212 dialog_msgbox(NULL, errstr, -1, -1, 0);
215 /* Put up a message in a popup yes/no box and return 0 for YES, 1 for NO */
217 msgYesNo(const char *fmt, ...)
222 WINDOW *w = savescr();
224 errstr = (char *)alloca(FILENAME_MAX);
226 vsnprintf(errstr, FILENAME_MAX, fmt, args);
231 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
234 if (variable_get(VAR_NONINTERACTIVE))
235 return 0; /* If non-interactive, return YES all the time */
236 ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1);
241 /* Put up a message in a popup no/yes box and return 0 for YES, 1 for NO */
243 msgNoYes(const char *fmt, ...)
248 WINDOW *w = savescr();
250 errstr = (char *)alloca(FILENAME_MAX);
252 vsnprintf(errstr, FILENAME_MAX, fmt, args);
257 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
260 if (variable_get(VAR_NONINTERACTIVE))
261 return 1; /* If non-interactive, return NO all the time */
262 ret = dialog_noyes("User Confirmation Requested", errstr, -1, -1);
267 /* Put up a message in an input box and return the value */
269 msgGetInput(char *buf, const char *fmt, ...)
273 static char input_buffer[256];
275 WINDOW *w = savescr();
277 errstr = (char *)alloca(FILENAME_MAX);
279 vsnprintf(errstr, FILENAME_MAX, fmt, args);
284 SAFE_STRCPY(input_buffer, buf);
286 input_buffer[0] = '\0';
288 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
291 rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer);
299 /* Write something to the debugging port */
301 msgDebug(const char *fmt, ...)
308 dbg = (char *)alloca(FILENAME_MAX);
309 strcpy(dbg, "DEBUG: ");
311 vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args);
313 write(DebugFD, dbg, strlen(dbg));
316 /* Tell the user there's some output to go look at */
318 msgWeHaveOutput(const char *fmt, ...)
322 WINDOW *w = savescr();
324 errstr = (char *)alloca(FILENAME_MAX);
326 vsnprintf(errstr, FILENAME_MAX, fmt, args);
330 msgDebug("Notify: %s\n", errstr);
331 dialog_clear_norefresh();
333 dialog_msgbox(NULL, errstr, -1, -1, 0);
337 /* Simple versions of msgConfirm() and msgNotify() for calling from scripts */
339 msgSimpleConfirm(const char *str)
341 msgConfirm("%s", str);
342 return DITEM_SUCCESS;
346 msgSimpleNotify(const char *str)
348 msgNotify("%s", str);
349 return DITEM_SUCCESS;