msg.c revision 17375
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.38 1996/07/31 06:20:58 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 42Boolean 43isDebug(void) 44{ 45 char *cp; 46 47 return (cp = variable_get(VAR_DEBUG)) && strcmp(cp, "no"); 48} 49 50/* Whack up an informational message on the status line, in stand-out */ 51void 52msgYap(char *fmt, ...) 53{ 54 va_list args; 55 char *errstr; 56 int attrs; 57 58 errstr = (char *)alloca(FILENAME_MAX); 59 va_start(args, fmt); 60 vsnprintf(errstr, FILENAME_MAX, fmt, args); 61 va_end(args); 62 attrs = getattrs(stdscr); 63 attrset(A_REVERSE); 64 mvaddstr(StatusLine, 0, errstr); 65 attrset(attrs); 66 refresh(); 67} 68 69/* Whack up an informational message on the status line */ 70void 71msgInfo(char *fmt, ...) 72{ 73 va_list args; 74 char *errstr; 75 int i, attrs; 76 char line[81]; 77 78 attrs = getattrs(stdscr); 79 /* NULL is a special convention meaning "erase the old stuff" */ 80 if (!fmt) { 81 move(StatusLine, 0); 82 clrtoeol(); 83 return; 84 } 85 errstr = (char *)alloca(FILENAME_MAX); 86 va_start(args, fmt); 87 vsnprintf(errstr, FILENAME_MAX, fmt, args); 88 va_end(args); 89 memset(line, ' ', 80); 90 for (i = 0; i < 80; i++) { 91 if (errstr[i]) 92 line[i] = errstr[i]; 93 else 94 break; 95 } 96 line[80] = '\0'; 97 attrset(ATTR_TITLE); 98 mvaddstr(StatusLine, 0, line); 99 attrset(attrs); 100 move(StatusLine, 79); 101 refresh(); 102} 103 104/* Whack up a warning on the status line */ 105void 106msgWarn(char *fmt, ...) 107{ 108 va_list args; 109 char *errstr; 110 int attrs; 111 112 errstr = (char *)alloca(FILENAME_MAX); 113 strcpy(errstr, "Warning: "); 114 va_start(args, fmt); 115 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 116 va_end(args); 117 attrs = getattrs(stdscr); 118 beep(); 119 attrset(ATTR_TITLE); 120 mvaddstr(StatusLine, 0, errstr); 121 attrset(attrs); 122 refresh(); 123 if (OnVTY && isDebug()) 124 msgDebug("Warning message `%s'\n", errstr); 125} 126 127/* Whack up an error on the status line */ 128void 129msgError(char *fmt, ...) 130{ 131 va_list args; 132 char *errstr; 133 int attrs; 134 135 errstr = (char *)alloca(FILENAME_MAX); 136 strcpy(errstr, "Error: "); 137 va_start(args, fmt); 138 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 139 va_end(args); 140 beep(); 141 attrs = getattrs(stdscr); 142 attrset(ATTR_TITLE); 143 mvaddstr(StatusLine, 0, errstr); 144 attrset(attrs); 145 refresh(); 146 if (OnVTY && isDebug()) 147 msgDebug("Error message `%s'\n", errstr); 148} 149 150/* Whack up a fatal error on the status line */ 151void 152msgFatal(char *fmt, ...) 153{ 154 va_list args; 155 char *errstr; 156 int attrs; 157 158 errstr = (char *)alloca(FILENAME_MAX); 159 strcpy(errstr, "Fatal Error: "); 160 va_start(args, fmt); 161 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 162 va_end(args); 163 beep(); 164 attrs = getattrs(stdscr); 165 attrset(ATTR_TITLE); 166 mvaddstr(StatusLine, 0, errstr); 167 addstr(" - "); 168 addstr("PRESS ANY KEY TO "); 169 if (getpid() == 1) 170 addstr("REBOOT"); 171 else 172 addstr("QUIT"); 173 attrset(attrs); 174 refresh(); 175 if (OnVTY) 176 msgDebug("Fatal error `%s'!\n", errstr); 177 getch(); 178 systemShutdown(1); 179} 180 181/* Put up a message in a popup confirmation box */ 182void 183msgConfirm(char *fmt, ...) 184{ 185 va_list args; 186 char *errstr; 187 WINDOW *w; 188 189 errstr = (char *)alloca(FILENAME_MAX); 190 va_start(args, fmt); 191 vsnprintf(errstr, FILENAME_MAX, fmt, args); 192 va_end(args); 193 use_helpline(NULL); 194 use_helpfile(NULL); 195 w = savescr(); 196 if (OnVTY) { 197 msgDebug("Switching back to VTY1\n"); 198 ioctl(0, VT_ACTIVATE, 1); 199 msgInfo(NULL); 200 } 201 dialog_notify(errstr); 202 restorescr(w); 203} 204 205/* Put up a message in a popup information box */ 206void 207msgNotify(char *fmt, ...) 208{ 209 va_list args; 210 char *errstr; 211 212 errstr = (char *)alloca(FILENAME_MAX); 213 va_start(args, fmt); 214 vsnprintf(errstr, FILENAME_MAX, fmt, args); 215 va_end(args); 216 use_helpline(NULL); 217 use_helpfile(NULL); 218 if (isDebug()) 219 msgDebug("Notify: %s\n", errstr); 220 dialog_clear(); 221 dialog_msgbox("Information Dialog", errstr, -1, -1, 0); 222} 223 224/* Put up a message in a popup yes/no box and return 1 for YES, 0 for NO */ 225int 226msgYesNo(char *fmt, ...) 227{ 228 va_list args; 229 char *errstr; 230 int ret; 231 WINDOW *w; 232 233 errstr = (char *)alloca(FILENAME_MAX); 234 va_start(args, fmt); 235 vsnprintf(errstr, FILENAME_MAX, fmt, args); 236 va_end(args); 237 use_helpline(NULL); 238 use_helpfile(NULL); 239 w = savescr(); 240 if (OnVTY) { 241 msgDebug("Switching back to VTY1\n"); 242 ioctl(0, VT_ACTIVATE, 1); /* Switch back */ 243 msgInfo(NULL); 244 } 245 ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1); 246 restorescr(w); 247 return ret; 248} 249 250/* Put up a message in an input box and return the value */ 251char * 252msgGetInput(char *buf, char *fmt, ...) 253{ 254 va_list args; 255 char *errstr; 256 static char input_buffer[256]; 257 int rval; 258 WINDOW *w; 259 260 errstr = (char *)alloca(FILENAME_MAX); 261 va_start(args, fmt); 262 vsnprintf(errstr, FILENAME_MAX, fmt, args); 263 va_end(args); 264 use_helpline(NULL); 265 use_helpfile(NULL); 266 if (buf) 267 strcpy(input_buffer, buf); 268 else 269 input_buffer[0] = '\0'; 270 w = savescr(); 271 if (OnVTY) { 272 msgDebug("Switching back to VTY1\n"); 273 ioctl(0, VT_ACTIVATE, 1); /* Switch back */ 274 msgInfo(NULL); 275 } 276 rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer); 277 restorescr(w); 278 if (!rval) 279 return input_buffer; 280 else 281 return NULL; 282} 283 284/* Write something to the debugging port */ 285void 286msgDebug(char *fmt, ...) 287{ 288 va_list args; 289 char *dbg; 290 291 if (DebugFD == -1) 292 return; 293 dbg = (char *)alloca(FILENAME_MAX); 294 strcpy(dbg, "DEBUG: "); 295 va_start(args, fmt); 296 vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args); 297 va_end(args); 298 write(DebugFD, dbg, strlen(dbg)); 299} 300 301/* Tell the user there's some output to go look at */ 302void 303msgWeHaveOutput(char *fmt, ...) 304{ 305 va_list args; 306 char *errstr; 307 308 errstr = (char *)alloca(FILENAME_MAX); 309 va_start(args, fmt); 310 vsnprintf(errstr, FILENAME_MAX, fmt, args); 311 va_end(args); 312 use_helpline(NULL); 313 use_helpfile(NULL); 314 msgDebug("Notify: %s\n", errstr); 315 dialog_clear(); 316 dialog_msgbox("Information Dialog", errstr, -1, -1, 0); 317} 318 319/* Simple versions of msgConfirm() and msgNotify() for calling from scripts */ 320int 321msgSimpleConfirm(char *str) 322{ 323 msgConfirm(str); 324 return DITEM_SUCCESS; 325} 326 327int 328msgSimpleNotify(char *str) 329{ 330 msgNotify(str); 331 return DITEM_SUCCESS; 332} 333