summaryrefslogtreecommitdiff
path: root/usr.bin/msgc/msg_sys.def
blob: f257f956f4572ecdee660fa8f4dcdbdda2e12787 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*	$NetBSD: msg_sys.def,v 1.1.1.1 1997/09/26 21:16:38 phil Exp $	*/

/*
 * Copyright 1997 Piermont Information Systems Inc.
 * All rights reserved.
 *
 * Written by Philip A. Nelson for Piermont Information Systems Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software develooped for the NetBSD Project by
 *      Piermont Information Systems Inc.
 * 4. The name of Piermont Information Systems Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 * THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

static WINDOW *msg_win = NULL;
static char cbuffer [ MAXSTR ];
static int do_echo = 1;

/* Routines */

void beep (void)
{
	fprintf (stderr, "\a");
}

void msg_window(WINDOW *window)
{
	msg_win = window;
}

char *msg_string (int msg_no)
{
	return msg_list[msg_no];
}

void msg_clear(void)
{
	wclear (msg_win);
	wrefresh (msg_win);
}

void msg_standout(void)
{
	wstandout(msg_win);
}

void msg_standend(void)
{
	wstandend(msg_win);
}

int msg_vprintf (char *fmt, va_list ap)
{
	int ret;

	ret = vsnprintf (cbuffer, MAXSTR, fmt, ap);
	waddstr (msg_win, cbuffer);
	wrefresh (msg_win);
	return ret;
}

void msg_display(int msg_no, ...)
{
	va_list ap;

	va_start(ap, msg_no);
	wclear (msg_win);
	wmove (msg_win, 0, 0);
	(void)msg_vprintf (msg_list[msg_no], ap);
	va_end(ap);
}

void msg_display_add(int msg_no, ...)
{
	va_list ap;

	va_start (ap, msg_no);
	(void)msg_vprintf (msg_list[msg_no], ap);
	va_end (ap);
}

int msg_printf (char *fmt, ...)
{
	va_list ap;
	int  res;

	va_start (ap, fmt);
	wclear (msg_win);
	wmove (msg_win, 0, 0);
	res = msg_vprintf (fmt, ap);
	va_end (ap);
	return res;
}

int msg_printf_add (char *fmt, ...)
{
	va_list ap;
	int  res;

	va_start (ap, fmt);
	res = msg_vprintf (fmt, ap);
	va_end (ap);
	return res;
}


static void msg_vprompt (char *msg, char *def, char *val, int max_chars,
			 va_list ap)
{
	int ch;
	int count = 0;
	int y,x;

	msg_vprintf (msg, ap);
	if (def != NULL && *def) {
		waddstr (msg_win, " [");
		waddstr (msg_win, def);
		waddstr (msg_win, "]");
	}
	waddstr (msg_win, ": ");
	wrefresh (msg_win);

	while ((ch = wgetch(msg_win)) != '\n') {
		if (ch == 0x08 || ch == 0x7f) {  /* bs or del */
			if (count > 0) {
				count--;
				if (do_echo) {
					getyx(msg_win, y, x);
					x--;
					wmove(msg_win, y, x);
					wdelch(msg_win);
				}
			} else
				beep ();
		}
		else if (count < max_chars && isprint(ch)) {
			if (do_echo)
				waddch (msg_win, ch);
			val[count++] = ch;
		} else
			beep ();
		if (do_echo)
			wrefresh(msg_win);
	}
	if (do_echo)
		waddch(msg_win, '\n');

	if (count != 0)
		val[count] = '\0';

	/* Do a string copy if needed to get default */
	if (count == 0 && def != NULL && val != def)
		strncpy (val, def, max_chars);

}

void msg_prompt_addstr (char *fmt, char *def, char *val, int max_chars, ...)
{
	va_list ap;

	va_start (ap, max_chars);
	msg_vprompt (fmt, def, val, max_chars, ap);
	va_end(ap);
}

void msg_prompt_add (int msg_no, char *def, char *val, int max_chars, ...)
{
	va_list ap;

	va_start (ap, max_chars);
	msg_vprompt (msg_list[msg_no], def, val, max_chars, ap);
	va_end(ap);
}

void msg_prompt_str (char *msg, char *def, char *val, int max_chars, ...)
{
	va_list ap;

	va_start (ap, max_chars);
	wclear (msg_win);
	wmove (msg_win, 0, 0);
	msg_vprompt (msg, def, val, max_chars, ap);
	va_end (ap);
}

void msg_prompt (int msg_no, char *def, char *val, int max_chars, ...)
{
	va_list ap;

	va_start (ap, max_chars);
	wclear (msg_win);
	wmove (msg_win, 0, 0);
	msg_vprompt (msg_list[msg_no], def, val, max_chars, ap);
	va_end (ap);
}

void msg_noecho()
{
	do_echo = 0;
}

void msg_echo()
{
	do_echo = 1;
}