msg.c revision 16366
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.35 1996/06/08 09:08:43 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 * 23 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 */ 36 37#include "sysinstall.h" 38#include <stdarg.h> 39#include <sys/ioctl.h> 40#include <machine/console.h> 41 42#define VTY_STATLINE 24 43#define TTY_STATLINE 23 44 45Boolean 46isDebug(void) 47{ 48 char *cp; 49 50 return (cp = variable_get(VAR_DEBUG)) && strcmp(cp, "no"); 51} 52 53/* Whack up an informational message on the status line, in stand-out */ 54void 55msgYap(char *fmt, ...) 56{ 57 va_list args; 58 char *errstr; 59 int attrs; 60 61 errstr = (char *)alloca(FILENAME_MAX); 62 va_start(args, fmt); 63 vsnprintf(errstr, FILENAME_MAX, fmt, args); 64 va_end(args); 65 attrs = getattrs(stdscr); 66 attrset(A_REVERSE); 67 mvaddstr(OnVTY ? VTY_STATLINE : TTY_STATLINE, 0, errstr); 68 attrset(attrs); 69 refresh(); 70} 71 72/* Whack up an informational message on the status line */ 73void 74msgInfo(char *fmt, ...) 75{ 76 va_list args; 77 char *errstr; 78 int i, attrs; 79 char line[81]; 80 81 attrs = getattrs(stdscr); 82 /* NULL is a special convention meaning "erase the old stuff" */ 83 if (!fmt) { 84 move(OnVTY ? VTY_STATLINE : TTY_STATLINE, 0); 85 attrset(A_NORMAL); 86 clrtoeol(); 87 attrset(attrs); 88 return; 89 } 90 errstr = (char *)alloca(FILENAME_MAX); 91 va_start(args, fmt); 92 vsnprintf(errstr, FILENAME_MAX, fmt, args); 93 va_end(args); 94 memset(line, ' ', 80); 95 for (i = 0; i < 80; i++) { 96 if (errstr[i]) 97 line[i] = errstr[i]; 98 else 99 break; 100 } 101 line[80] = '\0'; 102 attrset(ATTR_TITLE); 103 mvaddstr(OnVTY ? VTY_STATLINE : TTY_STATLINE, 0, line); 104 attrset(attrs); 105 move(OnVTY ? VTY_STATLINE : TTY_STATLINE, 79); 106 refresh(); 107} 108 109/* Whack up a warning on the status line */ 110void 111msgWarn(char *fmt, ...) 112{ 113 va_list args; 114 char *errstr; 115 int attrs; 116 117 errstr = (char *)alloca(FILENAME_MAX); 118 strcpy(errstr, "Warning: "); 119 va_start(args, fmt); 120 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 121 va_end(args); 122 attrs = getattrs(stdscr); 123 beep(); 124 attrset(ATTR_TITLE); 125 mvaddstr(OnVTY ? VTY_STATLINE : TTY_STATLINE, 0, errstr); 126 attrset(attrs); 127 refresh(); 128 if (OnVTY && isDebug()) 129 msgDebug("Warning message `%s'\n", errstr); 130} 131 132/* Whack up an error on the status line */ 133void 134msgError(char *fmt, ...) 135{ 136 va_list args; 137 char *errstr; 138 int attrs; 139 140 errstr = (char *)alloca(FILENAME_MAX); 141 strcpy(errstr, "Error: "); 142 va_start(args, fmt); 143 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 144 va_end(args); 145 beep(); 146 attrs = getattrs(stdscr); 147 attrset(ATTR_TITLE); 148 mvaddstr(OnVTY ? VTY_STATLINE : TTY_STATLINE, 0, errstr); 149 attrset(attrs); 150 refresh(); 151 if (OnVTY && isDebug()) 152 msgDebug("Error message `%s'\n", errstr); 153} 154 155/* Whack up a fatal error on the status line */ 156void 157msgFatal(char *fmt, ...) 158{ 159 va_list args; 160 char *errstr; 161 int attrs; 162 163 errstr = (char *)alloca(FILENAME_MAX); 164 strcpy(errstr, "Fatal Error: "); 165 va_start(args, fmt); 166 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 167 va_end(args); 168 beep(); 169 attrs = getattrs(stdscr); 170 attrset(ATTR_TITLE); 171 mvaddstr(OnVTY ? VTY_STATLINE : TTY_STATLINE, 0, errstr); 172 addstr(" - "); 173 addstr("PRESS ANY KEY TO "); 174 if (getpid() == 1) 175 addstr("REBOOT"); 176 else 177 addstr("QUIT"); 178 attrset(attrs); 179 refresh(); 180 if (OnVTY) 181 msgDebug("Fatal error `%s'!\n", errstr); 182 getch(); 183 systemShutdown(1); 184} 185 186/* Put up a message in a popup confirmation box */ 187void 188msgConfirm(char *fmt, ...) 189{ 190 va_list args; 191 char *errstr; 192 WINDOW *w; 193 194 errstr = (char *)alloca(FILENAME_MAX); 195 va_start(args, fmt); 196 vsnprintf(errstr, FILENAME_MAX, fmt, args); 197 va_end(args); 198 use_helpline(NULL); 199 use_helpfile(NULL); 200 w = savescr(); 201 if (OnVTY) { 202 msgDebug("Switching back to VTY1\n"); 203 ioctl(0, VT_ACTIVATE, 1); 204 msgInfo(NULL); 205 } 206 dialog_notify(errstr); 207 restorescr(w); 208} 209 210/* Put up a message in a popup information box */ 211void 212msgNotify(char *fmt, ...) 213{ 214 va_list args; 215 char *errstr; 216 217 errstr = (char *)alloca(FILENAME_MAX); 218 va_start(args, fmt); 219 vsnprintf(errstr, FILENAME_MAX, fmt, args); 220 va_end(args); 221 use_helpline(NULL); 222 use_helpfile(NULL); 223 if (isDebug()) 224 msgDebug("Notify: %s\n", errstr); 225 dialog_clear(); 226 dialog_msgbox("Information Dialog", errstr, -1, -1, 0); 227} 228 229/* Put up a message in a popup yes/no box and return 1 for YES, 0 for NO */ 230int 231msgYesNo(char *fmt, ...) 232{ 233 va_list args; 234 char *errstr; 235 int ret; 236 WINDOW *w; 237 238 errstr = (char *)alloca(FILENAME_MAX); 239 va_start(args, fmt); 240 vsnprintf(errstr, FILENAME_MAX, fmt, args); 241 va_end(args); 242 use_helpline(NULL); 243 use_helpfile(NULL); 244 w = savescr(); 245 if (OnVTY) { 246 msgDebug("Switching back to VTY1\n"); 247 ioctl(0, VT_ACTIVATE, 1); /* Switch back */ 248 msgInfo(NULL); 249 } 250 ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1); 251 restorescr(w); 252 return ret; 253} 254 255/* Put up a message in an input box and return the value */ 256char * 257msgGetInput(char *buf, char *fmt, ...) 258{ 259 va_list args; 260 char *errstr; 261 static char input_buffer[256]; 262 int rval; 263 WINDOW *w; 264 265 errstr = (char *)alloca(FILENAME_MAX); 266 va_start(args, fmt); 267 vsnprintf(errstr, FILENAME_MAX, fmt, args); 268 va_end(args); 269 use_helpline(NULL); 270 use_helpfile(NULL); 271 if (buf) 272 strcpy(input_buffer, buf); 273 else 274 input_buffer[0] = '\0'; 275 w = savescr(); 276 if (OnVTY) { 277 msgDebug("Switching back to VTY1\n"); 278 ioctl(0, VT_ACTIVATE, 1); /* Switch back */ 279 msgInfo(NULL); 280 } 281 rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer); 282 restorescr(w); 283 if (!rval) 284 return input_buffer; 285 else 286 return NULL; 287} 288 289/* Write something to the debugging port */ 290void 291msgDebug(char *fmt, ...) 292{ 293 va_list args; 294 char *dbg; 295 296 if (DebugFD == -1) 297 return; 298 dbg = (char *)alloca(FILENAME_MAX); 299 strcpy(dbg, "DEBUG: "); 300 va_start(args, fmt); 301 vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args); 302 va_end(args); 303 write(DebugFD, dbg, strlen(dbg)); 304} 305 306/* Tell the user there's some output to go look at */ 307void 308msgWeHaveOutput(char *fmt, ...) 309{ 310 va_list args; 311 char *errstr; 312 313 errstr = (char *)alloca(FILENAME_MAX); 314 va_start(args, fmt); 315 vsnprintf(errstr, FILENAME_MAX, fmt, args); 316 va_end(args); 317 use_helpline(NULL); 318 use_helpfile(NULL); 319 msgDebug("Notify: %s\n", errstr); 320 dialog_clear(); 321 dialog_msgbox("Information Dialog", errstr, -1, -1, 0); 322 if (OnVTY) 323 msgInfo("Command output is on VTY2 - type ALT-F2 to see it"); 324} 325 326/* Simple versions of msgConfirm() and msgNotify() for calling from scripts */ 327int 328msgSimpleConfirm(char *str) 329{ 330 msgConfirm(str); 331 return DITEM_SUCCESS; 332} 333 334int 335msgSimpleNotify(char *str) 336{ 337 msgNotify(str); 338 return DITEM_SUCCESS; 339} 340