11573Srgrimes/*-
21573Srgrimes * Copyright (c) 1992, 1993
31573Srgrimes *	The Regents of the University of California.  All rights reserved.
41573Srgrimes *
51573Srgrimes * This code is derived from software contributed to Berkeley by
61573Srgrimes * Christos Zoulas of Cornell University.
71573Srgrimes *
81573Srgrimes * Redistribution and use in source and binary forms, with or without
91573Srgrimes * modification, are permitted provided that the following conditions
101573Srgrimes * are met:
111573Srgrimes * 1. Redistributions of source code must retain the above copyright
121573Srgrimes *    notice, this list of conditions and the following disclaimer.
131573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141573Srgrimes *    notice, this list of conditions and the following disclaimer in the
151573Srgrimes *    documentation and/or other materials provided with the distribution.
16148834Sstefanf * 3. Neither the name of the University nor the names of its contributors
171573Srgrimes *    may be used to endorse or promote products derived from this software
181573Srgrimes *    without specific prior written permission.
191573Srgrimes *
201573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301573Srgrimes * SUCH DAMAGE.
3184260Sobrien *
32237448Spfg *	$NetBSD: el.c,v 1.55 2009/07/25 21:19:23 christos Exp $
331573Srgrimes */
341573Srgrimes
3560773Simp#if !defined(lint) && !defined(SCCSID)
361573Srgrimesstatic char sccsid[] = "@(#)el.c	8.2 (Berkeley) 1/3/94";
3760773Simp#endif /* not lint && not SCCSID */
3884260Sobrien#include <sys/cdefs.h>
3984260Sobrien__FBSDID("$FreeBSD$");
401573Srgrimes
411573Srgrimes/*
421573Srgrimes * el.c: EditLine interface functions
431573Srgrimes */
441573Srgrimes#include "sys.h"
451573Srgrimes
461573Srgrimes#include <sys/types.h>
471573Srgrimes#include <sys/param.h>
481573Srgrimes#include <string.h>
491573Srgrimes#include <stdlib.h>
5084260Sobrien#include <stdarg.h>
51237448Spfg#include <ctype.h>
521573Srgrimes#include "el.h"
531573Srgrimes
54148834Sstefanf#define	HAVE_ISSETUGID
55148834Sstefanf
561573Srgrimes/* el_init():
571573Srgrimes *	Initialize editline and set default parameters.
581573Srgrimes */
591573Srgrimespublic EditLine *
6084260Sobrienel_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
611573Srgrimes{
6284260Sobrien
6384260Sobrien	EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
641573Srgrimes
6584260Sobrien	if (el == NULL)
6684260Sobrien		return (NULL);
671573Srgrimes
6884260Sobrien	memset(el, 0, sizeof(EditLine));
691573Srgrimes
70170511Sstefanf	el->el_infile = fin;
7184260Sobrien	el->el_outfile = fout;
7284260Sobrien	el->el_errfile = ferr;
73170511Sstefanf
74170511Sstefanf	el->el_infd = fileno(fin);
75170511Sstefanf
76148834Sstefanf	if ((el->el_prog = el_strdup(prog)) == NULL) {
77148834Sstefanf		el_free(el);
78148834Sstefanf		return NULL;
79148834Sstefanf	}
801573Srgrimes
8184260Sobrien	/*
8284260Sobrien         * Initialize all the modules. Order is important!!!
8384260Sobrien         */
8484260Sobrien	el->el_flags = 0;
851573Srgrimes
86148834Sstefanf	if (term_init(el) == -1) {
87148834Sstefanf		el_free(el->el_prog);
88148834Sstefanf		el_free(el);
89148834Sstefanf		return NULL;
90148834Sstefanf	}
9184260Sobrien	(void) key_init(el);
9284260Sobrien	(void) map_init(el);
9384260Sobrien	if (tty_init(el) == -1)
9484260Sobrien		el->el_flags |= NO_TTY;
9584260Sobrien	(void) ch_init(el);
9684260Sobrien	(void) search_init(el);
9784260Sobrien	(void) hist_init(el);
9884260Sobrien	(void) prompt_init(el);
9984260Sobrien	(void) sig_init(el);
100148834Sstefanf	(void) read_init(el);
1011573Srgrimes
10284260Sobrien	return (el);
10384260Sobrien}
1041573Srgrimes
1051573Srgrimes
1061573Srgrimes/* el_end():
1071573Srgrimes *	Clean up.
1081573Srgrimes */
1091573Srgrimespublic void
11084260Sobrienel_end(EditLine *el)
1111573Srgrimes{
1121573Srgrimes
11384260Sobrien	if (el == NULL)
11484260Sobrien		return;
1151573Srgrimes
11684260Sobrien	el_reset(el);
1171573Srgrimes
11884260Sobrien	term_end(el);
11984260Sobrien	key_end(el);
12084260Sobrien	map_end(el);
12184260Sobrien	tty_end(el);
12284260Sobrien	ch_end(el);
12384260Sobrien	search_end(el);
12484260Sobrien	hist_end(el);
12584260Sobrien	prompt_end(el);
12684260Sobrien	sig_end(el);
1271573Srgrimes
12884260Sobrien	el_free((ptr_t) el->el_prog);
12984260Sobrien	el_free((ptr_t) el);
13084260Sobrien}
1311573Srgrimes
13284260Sobrien
1331573Srgrimes/* el_reset():
1341573Srgrimes *	Reset the tty and the parser
1351573Srgrimes */
1361573Srgrimespublic void
13784260Sobrienel_reset(EditLine *el)
1381573Srgrimes{
13984260Sobrien
14084260Sobrien	tty_cookedmode(el);
141148834Sstefanf	ch_reset(el, 0);		/* XXX: Do we want that? */
1421573Srgrimes}
1431573Srgrimes
1441573Srgrimes
1451573Srgrimes/* el_set():
1461573Srgrimes *	set the editline parameters
1471573Srgrimes */
1481573Srgrimespublic int
1491573Srgrimesel_set(EditLine *el, int op, ...)
1501573Srgrimes{
151170511Sstefanf	va_list ap;
152148834Sstefanf	int rv = 0;
1531573Srgrimes
15484260Sobrien	if (el == NULL)
15584260Sobrien		return (-1);
156170511Sstefanf	va_start(ap, op);
157148834Sstefanf
15884260Sobrien	switch (op) {
15984260Sobrien	case EL_PROMPT:
160237448Spfg	case EL_RPROMPT: {
161237448Spfg		el_pfunc_t p = va_arg(ap, el_pfunc_t);
162237448Spfg
163237448Spfg		rv = prompt_set(el, p, 0, op);
16484260Sobrien		break;
165237448Spfg	}
1668870Srgrimes
167237448Spfg	case EL_PROMPT_ESC:
168237448Spfg	case EL_RPROMPT_ESC: {
169237448Spfg		el_pfunc_t p = va_arg(ap, el_pfunc_t);
170237448Spfg		char c = va_arg(ap, int);
171237448Spfg
172237448Spfg		rv = prompt_set(el, p, c, op);
173237448Spfg		break;
174237448Spfg	}
175237448Spfg
17684260Sobrien	case EL_TERMINAL:
177170511Sstefanf		rv = term_set(el, va_arg(ap, char *));
17884260Sobrien		break;
1791573Srgrimes
18084260Sobrien	case EL_EDITOR:
181170511Sstefanf		rv = map_set_editor(el, va_arg(ap, char *));
18284260Sobrien		break;
1831573Srgrimes
18484260Sobrien	case EL_SIGNAL:
185170511Sstefanf		if (va_arg(ap, int))
18684260Sobrien			el->el_flags |= HANDLE_SIGNALS;
18784260Sobrien		else
18884260Sobrien			el->el_flags &= ~HANDLE_SIGNALS;
18984260Sobrien		break;
1901573Srgrimes
19184260Sobrien	case EL_BIND:
19284260Sobrien	case EL_TELLTC:
19384260Sobrien	case EL_SETTC:
194170511Sstefanf	case EL_GETTC:
19584260Sobrien	case EL_ECHOTC:
19684260Sobrien	case EL_SETTY:
19784260Sobrien	{
198148834Sstefanf		const char *argv[20];
19984260Sobrien		int i;
2001573Srgrimes
20184260Sobrien		for (i = 1; i < 20; i++)
202170511Sstefanf			if ((argv[i] = va_arg(ap, char *)) == NULL)
20384260Sobrien				break;
20484260Sobrien
20584260Sobrien		switch (op) {
20684260Sobrien		case EL_BIND:
20784260Sobrien			argv[0] = "bind";
20884260Sobrien			rv = map_bind(el, i, argv);
20984260Sobrien			break;
21084260Sobrien
21184260Sobrien		case EL_TELLTC:
21284260Sobrien			argv[0] = "telltc";
21384260Sobrien			rv = term_telltc(el, i, argv);
21484260Sobrien			break;
21584260Sobrien
21684260Sobrien		case EL_SETTC:
21784260Sobrien			argv[0] = "settc";
21884260Sobrien			rv = term_settc(el, i, argv);
21984260Sobrien			break;
22084260Sobrien
22184260Sobrien		case EL_ECHOTC:
22284260Sobrien			argv[0] = "echotc";
22384260Sobrien			rv = term_echotc(el, i, argv);
22484260Sobrien			break;
22584260Sobrien
22684260Sobrien		case EL_SETTY:
22784260Sobrien			argv[0] = "setty";
22884260Sobrien			rv = tty_stty(el, i, argv);
22984260Sobrien			break;
23084260Sobrien
23184260Sobrien		default:
23284260Sobrien			rv = -1;
23384260Sobrien			EL_ABORT((el->el_errfile, "Bad op %d\n", op));
23484260Sobrien			break;
23584260Sobrien		}
23684260Sobrien		break;
23784260Sobrien	}
23884260Sobrien
23984260Sobrien	case EL_ADDFN:
2401573Srgrimes	{
241170511Sstefanf		char *name = va_arg(ap, char *);
242170511Sstefanf		char *help = va_arg(ap, char *);
243170511Sstefanf		el_func_t func = va_arg(ap, el_func_t);
2441573Srgrimes
24584260Sobrien		rv = map_addfunc(el, name, help, func);
2461573Srgrimes		break;
24784260Sobrien	}
2481573Srgrimes
24984260Sobrien	case EL_HIST:
25084260Sobrien	{
251170511Sstefanf		hist_fun_t func = va_arg(ap, hist_fun_t);
252170511Sstefanf		ptr_t ptr = va_arg(ap, char *);
25384260Sobrien
25484260Sobrien		rv = hist_set(el, func, ptr);
2551573Srgrimes		break;
25684260Sobrien	}
2571573Srgrimes
25884260Sobrien	case EL_EDITMODE:
259170511Sstefanf		if (va_arg(ap, int))
26084260Sobrien			el->el_flags &= ~EDIT_DISABLED;
26184260Sobrien		else
26284260Sobrien			el->el_flags |= EDIT_DISABLED;
26384260Sobrien		rv = 0;
2641573Srgrimes		break;
2651573Srgrimes
266148834Sstefanf	case EL_GETCFN:
267148834Sstefanf	{
268170511Sstefanf		el_rfunc_t rc = va_arg(ap, el_rfunc_t);
269148834Sstefanf		rv = el_read_setfn(el, rc);
270148834Sstefanf		break;
271148834Sstefanf	}
272148834Sstefanf
273148834Sstefanf	case EL_CLIENTDATA:
274170511Sstefanf		el->el_data = va_arg(ap, void *);
275148834Sstefanf		break;
276148834Sstefanf
277148834Sstefanf	case EL_UNBUFFERED:
278170511Sstefanf		rv = va_arg(ap, int);
279148834Sstefanf		if (rv && !(el->el_flags & UNBUFFERED)) {
280148834Sstefanf			el->el_flags |= UNBUFFERED;
281148834Sstefanf			read_prepare(el);
282148834Sstefanf		} else if (!rv && (el->el_flags & UNBUFFERED)) {
283148834Sstefanf			el->el_flags &= ~UNBUFFERED;
284148834Sstefanf			read_finish(el);
285148834Sstefanf		}
286148834Sstefanf		rv = 0;
287148834Sstefanf		break;
288148834Sstefanf
289148834Sstefanf	case EL_PREP_TERM:
290170511Sstefanf		rv = va_arg(ap, int);
291148834Sstefanf		if (rv)
292148834Sstefanf			(void) tty_rawmode(el);
293148834Sstefanf		else
294148834Sstefanf			(void) tty_cookedmode(el);
295148834Sstefanf		rv = 0;
296148834Sstefanf		break;
297148834Sstefanf
298170511Sstefanf	case EL_SETFP:
299170511Sstefanf	{
300170511Sstefanf		FILE *fp;
301170511Sstefanf		int what;
302170511Sstefanf
303170511Sstefanf		what = va_arg(ap, int);
304170511Sstefanf		fp = va_arg(ap, FILE *);
305170511Sstefanf
306170511Sstefanf		rv = 0;
307170511Sstefanf		switch (what) {
308170511Sstefanf		case 0:
309170511Sstefanf			el->el_infile = fp;
310170511Sstefanf			el->el_infd = fileno(fp);
311170511Sstefanf			break;
312170511Sstefanf		case 1:
313170511Sstefanf			el->el_outfile = fp;
314170511Sstefanf			break;
315170511Sstefanf		case 2:
316170511Sstefanf			el->el_errfile = fp;
317170511Sstefanf			break;
318170511Sstefanf		default:
319170511Sstefanf			rv = -1;
320170511Sstefanf			break;
321170511Sstefanf		}
322170511Sstefanf		break;
323170511Sstefanf	}
324170511Sstefanf
325237448Spfg	case EL_REFRESH:
326237448Spfg		re_clear_display(el);
327237448Spfg		re_refresh(el);
328237448Spfg		term__flush(el);
329237448Spfg		break;
330237448Spfg
33184260Sobrien	default:
33284260Sobrien		rv = -1;
333148834Sstefanf		break;
33484260Sobrien	}
33584260Sobrien
336170511Sstefanf	va_end(ap);
33784260Sobrien	return (rv);
33884260Sobrien}
33984260Sobrien
34084260Sobrien
34184260Sobrien/* el_get():
34284260Sobrien *	retrieve the editline parameters
34384260Sobrien */
34484260Sobrienpublic int
345170511Sstefanfel_get(EditLine *el, int op, ...)
34684260Sobrien{
347170511Sstefanf	va_list ap;
34884260Sobrien	int rv;
34984260Sobrien
350170511Sstefanf	if (el == NULL)
351170511Sstefanf		return -1;
352170511Sstefanf
353170511Sstefanf	va_start(ap, op);
354170511Sstefanf
35584260Sobrien	switch (op) {
35684260Sobrien	case EL_PROMPT:
357237448Spfg	case EL_RPROMPT: {
358237448Spfg		el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
359237448Spfg		char *c = va_arg(ap, char *);
360237448Spfg
361237448Spfg		rv = prompt_get(el, p, c, op);
3621573Srgrimes		break;
363237448Spfg	}
3641573Srgrimes
36584260Sobrien	case EL_EDITOR:
366170511Sstefanf		rv = map_get_editor(el, va_arg(ap, const char **));
3671573Srgrimes		break;
3681573Srgrimes
36984260Sobrien	case EL_SIGNAL:
370170511Sstefanf		*va_arg(ap, int *) = (el->el_flags & HANDLE_SIGNALS);
37184260Sobrien		rv = 0;
3721573Srgrimes		break;
3738870Srgrimes
37484260Sobrien	case EL_EDITMODE:
375170511Sstefanf		*va_arg(ap, int *) = !(el->el_flags & EDIT_DISABLED);
37684260Sobrien		rv = 0;
37784260Sobrien		break;
37884260Sobrien
37984260Sobrien	case EL_TERMINAL:
380170511Sstefanf		term_get(el, va_arg(ap, const char **));
381148834Sstefanf		rv = 0;
38284260Sobrien		break;
38384260Sobrien
384170511Sstefanf	case EL_GETTC:
3851573Srgrimes	{
386170511Sstefanf		static char name[] = "gettc";
387170511Sstefanf		char *argv[20];
38884260Sobrien		int i;
38984260Sobrien
390237448Spfg 		for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++)
391170511Sstefanf			if ((argv[i] = va_arg(ap, char *)) == NULL)
39284260Sobrien				break;
39384260Sobrien
39484260Sobrien		switch (op) {
395170511Sstefanf		case EL_GETTC:
396170511Sstefanf			argv[0] = name;
397170511Sstefanf			rv = term_gettc(el, i, argv);
39884260Sobrien			break;
39984260Sobrien
40084260Sobrien		default:
40184260Sobrien			rv = -1;
402170511Sstefanf			EL_ABORT((el->el_errfile, "Bad op %d\n", op));
40384260Sobrien			break;
40484260Sobrien		}
40584260Sobrien		break;
4061573Srgrimes	}
4071573Srgrimes
408170511Sstefanf#if 0 /* XXX */
40984260Sobrien	case EL_ADDFN:
4101573Srgrimes	{
411170511Sstefanf		char *name = va_arg(ap, char *);
412170511Sstefanf		char *help = va_arg(ap, char *);
413170511Sstefanf		el_func_t func = va_arg(ap, el_func_t);
41484260Sobrien
41584260Sobrien		rv = map_addfunc(el, name, help, func);
41684260Sobrien		break;
4171573Srgrimes	}
4181573Srgrimes
41984260Sobrien	case EL_HIST:
42084260Sobrien		{
421170511Sstefanf			hist_fun_t func = va_arg(ap, hist_fun_t);
422170511Sstefanf			ptr_t ptr = va_arg(ap, char *);
42384260Sobrien			rv = hist_set(el, func, ptr);
42484260Sobrien		}
42584260Sobrien		break;
42684260Sobrien#endif /* XXX */
4271573Srgrimes
428148834Sstefanf	case EL_GETCFN:
429170511Sstefanf		*va_arg(ap, el_rfunc_t *) = el_read_getfn(el);
430148834Sstefanf		rv = 0;
431148834Sstefanf		break;
432148834Sstefanf
433148834Sstefanf	case EL_CLIENTDATA:
434170511Sstefanf		*va_arg(ap, void **) = el->el_data;
435148834Sstefanf		rv = 0;
436148834Sstefanf		break;
437148834Sstefanf
438148834Sstefanf	case EL_UNBUFFERED:
439170511Sstefanf		*va_arg(ap, int *) = (!(el->el_flags & UNBUFFERED));
440148834Sstefanf		rv = 0;
441148834Sstefanf		break;
442148834Sstefanf
443170511Sstefanf	case EL_GETFP:
444170511Sstefanf	{
445170511Sstefanf		int what;
446170511Sstefanf		FILE **fpp;
447170511Sstefanf
448170511Sstefanf		what = va_arg(ap, int);
449170511Sstefanf		fpp = va_arg(ap, FILE **);
450170511Sstefanf		rv = 0;
451170511Sstefanf		switch (what) {
452170511Sstefanf		case 0:
453170511Sstefanf			*fpp = el->el_infile;
454170511Sstefanf			break;
455170511Sstefanf		case 1:
456170511Sstefanf			*fpp = el->el_outfile;
457170511Sstefanf			break;
458170511Sstefanf		case 2:
459170511Sstefanf			*fpp = el->el_errfile;
460170511Sstefanf			break;
461170511Sstefanf		default:
462170511Sstefanf			rv = -1;
463170511Sstefanf			break;
464170511Sstefanf		}
465170511Sstefanf		break;
466170511Sstefanf	}
46784260Sobrien	default:
46884260Sobrien		rv = -1;
469170511Sstefanf		break;
47084260Sobrien	}
471170511Sstefanf	va_end(ap);
4721573Srgrimes
47384260Sobrien	return (rv);
47484260Sobrien}
4751573Srgrimes
47684260Sobrien
4771573Srgrimes/* el_line():
4781573Srgrimes *	Return editing info
4791573Srgrimes */
4801573Srgrimespublic const LineInfo *
48184260Sobrienel_line(EditLine *el)
4821573Srgrimes{
48384260Sobrien
48484260Sobrien	return (const LineInfo *) (void *) &el->el_line;
4851573Srgrimes}
4861573Srgrimes
4871573Srgrimes
4881573Srgrimes/* el_source():
4891573Srgrimes *	Source a file
4901573Srgrimes */
4911573Srgrimespublic int
49284260Sobrienel_source(EditLine *el, const char *fname)
4931573Srgrimes{
49484260Sobrien	FILE *fp;
49584260Sobrien	size_t len;
496148834Sstefanf	char *ptr;
497237448Spfg#ifdef HAVE_ISSETUGID
498237448Spfg	char path[MAXPATHLEN];
499237448Spfg#endif
5001573Srgrimes
50184260Sobrien	fp = NULL;
50284260Sobrien	if (fname == NULL) {
503148834Sstefanf#ifdef HAVE_ISSETUGID
504148834Sstefanf		static const char elpath[] = "/.editrc";
505148834Sstefanf
50684260Sobrien		if (issetugid())
50784260Sobrien			return (-1);
50884260Sobrien		if ((ptr = getenv("HOME")) == NULL)
50984260Sobrien			return (-1);
51084260Sobrien		if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
51184260Sobrien			return (-1);
51284260Sobrien		if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
51384260Sobrien			return (-1);
51484260Sobrien		fname = path;
515148834Sstefanf#else
516148834Sstefanf		/*
517148834Sstefanf		 * If issetugid() is missing, always return an error, in order
518148834Sstefanf		 * to keep from inadvertently opening up the user to a security
519148834Sstefanf		 * hole.
520148834Sstefanf		 */
521148834Sstefanf		return (-1);
522148834Sstefanf#endif
52384260Sobrien	}
52484260Sobrien	if (fp == NULL)
52584260Sobrien		fp = fopen(fname, "r");
52684260Sobrien	if (fp == NULL)
52784260Sobrien		return (-1);
5281573Srgrimes
52984260Sobrien	while ((ptr = fgetln(fp, &len)) != NULL) {
53084260Sobrien		if (len > 0 && ptr[len - 1] == '\n')
53184260Sobrien			--len;
53284260Sobrien		ptr[len] = '\0';
533237448Spfg
534237448Spfg		/* loop until first non-space char or EOL */
535237448Spfg		while (*ptr != '\0' && isspace((unsigned char)*ptr))
536237448Spfg			ptr++;
537237448Spfg		if (*ptr == '#')
538237448Spfg			continue;   /* ignore, this is a comment line */
539237448Spfg
54084260Sobrien		if (parse_line(el, ptr) == -1) {
54184260Sobrien			(void) fclose(fp);
54284260Sobrien			return (-1);
54384260Sobrien		}
5441573Srgrimes	}
5451573Srgrimes
54684260Sobrien	(void) fclose(fp);
54784260Sobrien	return (0);
5481573Srgrimes}
5491573Srgrimes
5501573Srgrimes
5511573Srgrimes/* el_resize():
5521573Srgrimes *	Called from program when terminal is resized
5531573Srgrimes */
5541573Srgrimespublic void
55584260Sobrienel_resize(EditLine *el)
5561573Srgrimes{
55784260Sobrien	int lins, cols;
55884260Sobrien	sigset_t oset, nset;
5591573Srgrimes
56084260Sobrien	(void) sigemptyset(&nset);
56184260Sobrien	(void) sigaddset(&nset, SIGWINCH);
56284260Sobrien	(void) sigprocmask(SIG_BLOCK, &nset, &oset);
5631573Srgrimes
56484260Sobrien	/* get the correct window size */
56584260Sobrien	if (term_get_size(el, &lins, &cols))
56684260Sobrien		term_change_size(el, lins, cols);
56784260Sobrien
56884260Sobrien	(void) sigprocmask(SIG_SETMASK, &oset, NULL);
5691573Srgrimes}
57050070Smdodd
57184260Sobrien
57284260Sobrien/* el_beep():
57384260Sobrien *	Called from the program to beep
57484260Sobrien */
57550070Smdoddpublic void
57684260Sobrienel_beep(EditLine *el)
57750070Smdodd{
57850070Smdodd
57984260Sobrien	term_beep(el);
58050070Smdodd}
58150070Smdodd
58284260Sobrien
58384260Sobrien/* el_editmode()
58484260Sobrien *	Set the state of EDIT_DISABLED from the `edit' command.
58584260Sobrien */
58684260Sobrienprotected int
58784260Sobrien/*ARGSUSED*/
588148834Sstefanfel_editmode(EditLine *el, int argc, const char **argv)
58950070Smdodd{
59084260Sobrien	const char *how;
59184260Sobrien
59284260Sobrien	if (argv == NULL || argc != 2 || argv[1] == NULL)
59384260Sobrien		return (-1);
59484260Sobrien
59584260Sobrien	how = argv[1];
596148834Sstefanf	if (strcmp(how, "on") == 0) {
59784260Sobrien		el->el_flags &= ~EDIT_DISABLED;
598148834Sstefanf		tty_rawmode(el);
599148834Sstefanf	} else if (strcmp(how, "off") == 0) {
600148834Sstefanf		tty_cookedmode(el);
60184260Sobrien		el->el_flags |= EDIT_DISABLED;
602148834Sstefanf	}
60384260Sobrien	else {
60484260Sobrien		(void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
60584260Sobrien		return (-1);
60684260Sobrien	}
60784260Sobrien	return (0);
60850070Smdodd}
609