1/* $NetBSD: msg_sys.def,v 1.1.1.1 1997/09/26 21:16:38 phil Exp $ */ 2 3/* 4 * Copyright 1997 Piermont Information Systems Inc. 5 * All rights reserved. 6 * 7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software develooped for the NetBSD Project by 20 * Piermont Information Systems Inc. 21 * 4. The name of Piermont Information Systems Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 35 * THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 */ 38 39static WINDOW *msg_win = NULL; 40static char cbuffer [ MAXSTR ]; 41static int do_echo = 1; 42 43/* Routines */ 44 45void beep (void) 46{ 47 fprintf (stderr, "\a"); 48} 49 50void msg_window(WINDOW *window) 51{ 52 msg_win = window; 53} 54 55char *msg_string (int msg_no) 56{ 57 return msg_list[msg_no]; 58} 59 60void msg_clear(void) 61{ 62 wclear (msg_win); 63 wrefresh (msg_win); 64} 65 66void msg_standout(void) 67{ 68 wstandout(msg_win); 69} 70 71void msg_standend(void) 72{ 73 wstandend(msg_win); 74} 75 76int msg_vprintf (char *fmt, va_list ap) 77{ 78 int ret; 79 80 ret = vsnprintf (cbuffer, MAXSTR, fmt, ap); 81 waddstr (msg_win, cbuffer); 82 wrefresh (msg_win); 83 return ret; 84} 85 86void msg_display(int msg_no, ...) 87{ 88 va_list ap; 89 90 va_start(ap, msg_no); 91 wclear (msg_win); 92 wmove (msg_win, 0, 0); 93 (void)msg_vprintf (msg_list[msg_no], ap); 94 va_end(ap); 95} 96 97void msg_display_add(int msg_no, ...) 98{ 99 va_list ap; 100 101 va_start (ap, msg_no); 102 (void)msg_vprintf (msg_list[msg_no], ap); 103 va_end (ap); 104} 105 106int msg_printf (char *fmt, ...) 107{ 108 va_list ap; 109 int res; 110 111 va_start (ap, fmt); 112 wclear (msg_win); 113 wmove (msg_win, 0, 0); 114 res = msg_vprintf (fmt, ap); 115 va_end (ap); 116 return res; 117} 118 119int msg_printf_add (char *fmt, ...) 120{ 121 va_list ap; 122 int res; 123 124 va_start (ap, fmt); 125 res = msg_vprintf (fmt, ap); 126 va_end (ap); 127 return res; 128} 129 130 131static void msg_vprompt (char *msg, char *def, char *val, int max_chars, 132 va_list ap) 133{ 134 int ch; 135 int count = 0; 136 int y,x; 137 138 msg_vprintf (msg, ap); 139 if (def != NULL && *def) { 140 waddstr (msg_win, " ["); 141 waddstr (msg_win, def); 142 waddstr (msg_win, "]"); 143 } 144 waddstr (msg_win, ": "); 145 wrefresh (msg_win); 146 147 while ((ch = wgetch(msg_win)) != '\n') { 148 if (ch == 0x08 || ch == 0x7f) { /* bs or del */ 149 if (count > 0) { 150 count--; 151 if (do_echo) { 152 getyx(msg_win, y, x); 153 x--; 154 wmove(msg_win, y, x); 155 wdelch(msg_win); 156 } 157 } else 158 beep (); 159 } 160 else if (count < max_chars && isprint(ch)) { 161 if (do_echo) 162 waddch (msg_win, ch); 163 val[count++] = ch; 164 } else 165 beep (); 166 if (do_echo) 167 wrefresh(msg_win); 168 } 169 if (do_echo) 170 waddch(msg_win, '\n'); 171 172 if (count != 0) 173 val[count] = '\0'; 174 175 /* Do a string copy if needed to get default */ 176 if (count == 0 && def != NULL && val != def) 177 strncpy (val, def, max_chars); 178 179} 180 181void msg_prompt_addstr (char *fmt, char *def, char *val, int max_chars, ...) 182{ 183 va_list ap; 184 185 va_start (ap, max_chars); 186 msg_vprompt (fmt, def, val, max_chars, ap); 187 va_end(ap); 188} 189 190void msg_prompt_add (int msg_no, char *def, char *val, int max_chars, ...) 191{ 192 va_list ap; 193 194 va_start (ap, max_chars); 195 msg_vprompt (msg_list[msg_no], def, val, max_chars, ap); 196 va_end(ap); 197} 198 199void msg_prompt_str (char *msg, char *def, char *val, int max_chars, ...) 200{ 201 va_list ap; 202 203 va_start (ap, max_chars); 204 wclear (msg_win); 205 wmove (msg_win, 0, 0); 206 msg_vprompt (msg, def, val, max_chars, ap); 207 va_end (ap); 208} 209 210void msg_prompt (int msg_no, char *def, char *val, int max_chars, ...) 211{ 212 va_list ap; 213 214 va_start (ap, max_chars); 215 wclear (msg_win); 216 wmove (msg_win, 0, 0); 217 msg_vprompt (msg_list[msg_no], def, val, max_chars, ap); 218 va_end (ap); 219} 220 221void msg_noecho() 222{ 223 do_echo = 0; 224} 225 226void msg_echo() 227{ 228 do_echo = 1; 229} 230