msg.c revision 8641
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.17 1995/05/20 08:31:42 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 *)safe_malloc(FILENAME_MAX); 56 va_start(args, fmt); 57 vsnprintf(errstr, FILENAME_MAX, fmt, args); 58 va_end(args); 59 attrs = getattrs(stdscr); 60 attrset(A_REVERSE); 61 mvaddstr(23, 0, errstr); 62 attrset(attrs); 63 refresh(); 64 free(errstr); 65} 66 67/* Whack up an informational message on the status line */ 68void 69msgInfo(char *fmt, ...) 70{ 71 va_list args; 72 char *errstr; 73 int attrs; 74 75 /* NULL is a special convention meaning "erase the old stuff" */ 76 if (!fmt) { 77 move(23, 0); 78 clrtoeol(); 79 return; 80 } 81 errstr = (char *)safe_malloc(FILENAME_MAX); 82 va_start(args, fmt); 83 vsnprintf(errstr, FILENAME_MAX, fmt, args); 84 va_end(args); 85 attrs = getattrs(stdscr); 86 attrset(A_NORMAL); 87 mvaddstr(23, 0, errstr); 88 attrset(attrs); 89 refresh(); 90 if (OnVTY) { 91 msgDebug("Informational message `%s'\n", errstr); 92 msgInfo(NULL); 93 } 94 free(errstr); 95} 96 97/* Whack up a warning on the status line */ 98void 99msgWarn(char *fmt, ...) 100{ 101 va_list args; 102 char *errstr; 103 int attrs; 104 105 errstr = (char *)safe_malloc(FILENAME_MAX); 106 strcpy(errstr, "Warning: "); 107 va_start(args, fmt); 108 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 109 va_end(args); 110 attrs = getattrs(stdscr); 111 beep(); 112 attrset(A_REVERSE); 113 mvaddstr(23, 0, errstr); 114 attrset(attrs); 115 refresh(); 116 if (OnVTY) 117 msgDebug("Warning message `%s'\n", errstr); 118 free(errstr); 119} 120 121/* Whack up an error on the status line */ 122void 123msgError(char *fmt, ...) 124{ 125 va_list args; 126 char *errstr; 127 int attrs; 128 129 errstr = (char *)safe_malloc(FILENAME_MAX); 130 strcpy(errstr, "Error: "); 131 va_start(args, fmt); 132 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 133 va_end(args); 134 beep(); 135 attrs = getattrs(stdscr); 136 attrset(A_REVERSE); 137 mvaddstr(23, 0, errstr); 138 attrset(attrs); 139 refresh(); 140 if (OnVTY) 141 msgDebug("Error message `%s'\n", errstr); 142 free(errstr); 143} 144 145/* Whack up a fatal error on the status line */ 146void 147msgFatal(char *fmt, ...) 148{ 149 va_list args; 150 char *errstr; 151 int attrs; 152 153 errstr = (char *)safe_malloc(FILENAME_MAX); 154 strcpy(errstr, "Fatal Error: "); 155 va_start(args, fmt); 156 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args); 157 va_end(args); 158 beep(); 159 attrs = getattrs(stdscr); 160 attrset(A_REVERSE); 161 mvaddstr(23, 0, errstr); 162 addstr(" - "); 163 addstr("PRESS ANY KEY TO "); 164 if (getpid() == 1) 165 addstr("REBOOT"); 166 else 167 addstr("QUIT"); 168 attrset(attrs); 169 refresh(); 170 if (OnVTY) 171 msgDebug("Fatal error `%s'!\n", errstr); 172 free(errstr); 173 getch(); 174 systemShutdown(); 175} 176 177/* Put up a message in a popup confirmation box */ 178void 179msgConfirm(char *fmt, ...) 180{ 181 va_list args; 182 char *errstr; 183 184 errstr = (char *)safe_malloc(FILENAME_MAX); 185 va_start(args, fmt); 186 vsnprintf(errstr, FILENAME_MAX, fmt, args); 187 va_end(args); 188 use_helpline(NULL); 189 use_helpfile(NULL); 190 if (OnVTY) { 191 msgDebug("User confirmation requested (type ALT-F1)\n"); 192 msgInfo(NULL); 193 } 194 dialog_notify(errstr); 195 free(errstr); 196} 197 198/* Put up a message in a popup information box */ 199void 200msgNotify(char *fmt, ...) 201{ 202 va_list args; 203 char *errstr; 204 205 errstr = (char *)safe_malloc(FILENAME_MAX); 206 va_start(args, fmt); 207 vsnprintf(errstr, FILENAME_MAX, fmt, args); 208 va_end(args); 209 use_helpline(NULL); 210 use_helpfile(NULL); 211 msgDebug("Notify: %s\n", errstr); 212 dialog_msgbox("Information Dialog", errstr, -1, -1, 0); 213 free(errstr); 214} 215 216/* Put up a message in a popup yes/no box and return 1 for YES, 0 for NO */ 217int 218msgYesNo(char *fmt, ...) 219{ 220 va_list args; 221 char *errstr; 222 int ret; 223 WINDOW *w; 224 225 errstr = (char *)safe_malloc(FILENAME_MAX); 226 va_start(args, fmt); 227 vsnprintf(errstr, FILENAME_MAX, fmt, args); 228 va_end(args); 229 use_helpline(NULL); 230 use_helpfile(NULL); 231 w = dupwin(newscr); 232 if (OnVTY) { 233 msgDebug("User decision requested (type ALT-F1)\n"); 234 msgInfo(NULL); 235 } 236 ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1); 237 touchwin(w); 238 wrefresh(w); 239 delwin(w); 240 free(errstr); 241 return ret; 242} 243 244/* Put up a message in an input box and return the value */ 245char * 246msgGetInput(char *buf, char *fmt, ...) 247{ 248 va_list args; 249 char *errstr; 250 static char input_buffer[256]; 251 int rval; 252 WINDOW *w; 253 254 errstr = (char *)safe_malloc(FILENAME_MAX); 255 va_start(args, fmt); 256 vsnprintf(errstr, FILENAME_MAX, fmt, args); 257 va_end(args); 258 use_helpline(NULL); 259 use_helpfile(NULL); 260 if (buf) 261 strcpy(input_buffer, buf); 262 else 263 input_buffer[0] = '\0'; 264 w = dupwin(newscr); 265 if (OnVTY) { 266 msgDebug("User input requested (type ALT-F1)\n"); 267 msgInfo(NULL); 268 } 269 rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer); 270 touchwin(w); 271 wrefresh(w); 272 delwin(w); 273 free(errstr); 274 if (!rval) 275 return input_buffer; 276 else 277 return NULL; 278} 279 280/* Write something to the debugging port */ 281void 282msgDebug(char *fmt, ...) 283{ 284 va_list args; 285 char *dbg; 286 287 if (DebugFD == -1) 288 return; 289 dbg = (char *)safe_malloc(FILENAME_MAX); 290 strcpy(dbg, "DEBUG: "); 291 va_start(args, fmt); 292 vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args); 293 va_end(args); 294 write(DebugFD, dbg, strlen(dbg)); 295 free(dbg); 296} 297