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