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