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