xref: /minix3/external/bsd/nvi/dist/ex/ex_screen.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: ex_screen.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc  * Copyright (c) 1993, 1994
484d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
584d9c625SLionel Sambuc  * Copyright (c) 1993, 1994, 1995, 1996
684d9c625SLionel Sambuc  *	Keith Bostic.  All rights reserved.
784d9c625SLionel Sambuc  *
884d9c625SLionel Sambuc  * See the LICENSE file for redistribution information.
984d9c625SLionel Sambuc  */
1084d9c625SLionel Sambuc 
1184d9c625SLionel Sambuc #include "config.h"
1284d9c625SLionel Sambuc 
13*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
14*0a6a1f1dSLionel Sambuc #if 0
1584d9c625SLionel Sambuc #ifndef lint
1684d9c625SLionel Sambuc static const char sccsid[] = "Id: ex_screen.c,v 10.12 2001/06/25 15:19:19 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:19 ";
1784d9c625SLionel Sambuc #endif /* not lint */
18*0a6a1f1dSLionel Sambuc #else
19*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: ex_screen.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc 
2284d9c625SLionel Sambuc #include <sys/types.h>
2384d9c625SLionel Sambuc #include <sys/queue.h>
2484d9c625SLionel Sambuc #include <sys/time.h>
2584d9c625SLionel Sambuc 
2684d9c625SLionel Sambuc #include <bitstring.h>
2784d9c625SLionel Sambuc #include <limits.h>
2884d9c625SLionel Sambuc #include <stdio.h>
2984d9c625SLionel Sambuc #include <stdlib.h>
3084d9c625SLionel Sambuc #include <string.h>
3184d9c625SLionel Sambuc 
3284d9c625SLionel Sambuc #include "../common/common.h"
3384d9c625SLionel Sambuc #include "../vi/vi.h"
3484d9c625SLionel Sambuc 
3584d9c625SLionel Sambuc /*
3684d9c625SLionel Sambuc  * ex_bg --	:bg
3784d9c625SLionel Sambuc  *	Hide the screen.
3884d9c625SLionel Sambuc  *
3984d9c625SLionel Sambuc  * PUBLIC: int ex_bg __P((SCR *, EXCMD *));
4084d9c625SLionel Sambuc  */
4184d9c625SLionel Sambuc int
ex_bg(SCR * sp,EXCMD * cmdp)4284d9c625SLionel Sambuc ex_bg(SCR *sp, EXCMD *cmdp)
4384d9c625SLionel Sambuc {
4484d9c625SLionel Sambuc 	return (vs_bg(sp));
4584d9c625SLionel Sambuc }
4684d9c625SLionel Sambuc 
4784d9c625SLionel Sambuc /*
4884d9c625SLionel Sambuc  * ex_fg --	:fg [file]
4984d9c625SLionel Sambuc  *	Show the screen.
5084d9c625SLionel Sambuc  *
5184d9c625SLionel Sambuc  * PUBLIC: int ex_fg __P((SCR *, EXCMD *));
5284d9c625SLionel Sambuc  */
5384d9c625SLionel Sambuc int
ex_fg(SCR * sp,EXCMD * cmdp)5484d9c625SLionel Sambuc ex_fg(SCR *sp, EXCMD *cmdp)
5584d9c625SLionel Sambuc {
5684d9c625SLionel Sambuc 	SCR *nsp;
5784d9c625SLionel Sambuc 	int newscreen;
5884d9c625SLionel Sambuc 
5984d9c625SLionel Sambuc 	newscreen = F_ISSET(cmdp, E_NEWSCREEN);
6084d9c625SLionel Sambuc 	if (vs_fg(sp, &nsp, cmdp->argc ? cmdp->argv[0]->bp : NULL, newscreen))
6184d9c625SLionel Sambuc 		return (1);
6284d9c625SLionel Sambuc 
6384d9c625SLionel Sambuc 	/* Set up the switch. */
6484d9c625SLionel Sambuc 	if (newscreen) {
6584d9c625SLionel Sambuc 		sp->nextdisp = nsp;
6684d9c625SLionel Sambuc 		F_SET(sp, SC_SSWITCH);
6784d9c625SLionel Sambuc 	}
6884d9c625SLionel Sambuc 	return (0);
6984d9c625SLionel Sambuc }
7084d9c625SLionel Sambuc 
7184d9c625SLionel Sambuc /*
7284d9c625SLionel Sambuc  * ex_resize --	:resize [+-]rows
7384d9c625SLionel Sambuc  *	Change the screen size.
7484d9c625SLionel Sambuc  *
7584d9c625SLionel Sambuc  * PUBLIC: int ex_resize __P((SCR *, EXCMD *));
7684d9c625SLionel Sambuc  */
7784d9c625SLionel Sambuc int
ex_resize(SCR * sp,EXCMD * cmdp)7884d9c625SLionel Sambuc ex_resize(SCR *sp, EXCMD *cmdp)
7984d9c625SLionel Sambuc {
8084d9c625SLionel Sambuc 	adj_t adj;
8184d9c625SLionel Sambuc 
8284d9c625SLionel Sambuc 	switch (FL_ISSET(cmdp->iflags,
8384d9c625SLionel Sambuc 	    E_C_COUNT | E_C_COUNT_NEG | E_C_COUNT_POS)) {
8484d9c625SLionel Sambuc 	case E_C_COUNT:
8584d9c625SLionel Sambuc 		adj = A_SET;
8684d9c625SLionel Sambuc 		break;
8784d9c625SLionel Sambuc 	case E_C_COUNT | E_C_COUNT_NEG:
8884d9c625SLionel Sambuc 		adj = A_DECREASE;
8984d9c625SLionel Sambuc 		break;
9084d9c625SLionel Sambuc 	case E_C_COUNT | E_C_COUNT_POS:
9184d9c625SLionel Sambuc 		adj = A_INCREASE;
9284d9c625SLionel Sambuc 		break;
9384d9c625SLionel Sambuc 	default:
9484d9c625SLionel Sambuc 		ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
9584d9c625SLionel Sambuc 		return (1);
9684d9c625SLionel Sambuc 	}
9784d9c625SLionel Sambuc 	return (vs_resize(sp, cmdp->count, adj));
9884d9c625SLionel Sambuc }
9984d9c625SLionel Sambuc 
10084d9c625SLionel Sambuc /*
10184d9c625SLionel Sambuc  * ex_sdisplay --
10284d9c625SLionel Sambuc  *	Display the list of screens.
10384d9c625SLionel Sambuc  *
10484d9c625SLionel Sambuc  * PUBLIC: int ex_sdisplay __P((SCR *));
10584d9c625SLionel Sambuc  */
10684d9c625SLionel Sambuc int
ex_sdisplay(SCR * sp)10784d9c625SLionel Sambuc ex_sdisplay(SCR *sp)
10884d9c625SLionel Sambuc {
10984d9c625SLionel Sambuc 	GS *gp;
11084d9c625SLionel Sambuc 	SCR *tsp;
11184d9c625SLionel Sambuc 	int cnt, sep;
11284d9c625SLionel Sambuc 	size_t col, len;
11384d9c625SLionel Sambuc 
11484d9c625SLionel Sambuc 	gp = sp->gp;
11584d9c625SLionel Sambuc 	if ((tsp = TAILQ_FIRST(&gp->hq)) == NULL) {
11684d9c625SLionel Sambuc 		msgq(sp, M_INFO, "149|No background screens to display");
11784d9c625SLionel Sambuc 		return (0);
11884d9c625SLionel Sambuc 	}
11984d9c625SLionel Sambuc 
12084d9c625SLionel Sambuc 	col = len = sep = 0;
12184d9c625SLionel Sambuc 	for (cnt = 1; tsp != NULL && !INTERRUPTED(sp);
12284d9c625SLionel Sambuc 	    tsp = TAILQ_NEXT(tsp, q)) {
12384d9c625SLionel Sambuc 		col += len = strlen(tsp->frp->name) + sep;
12484d9c625SLionel Sambuc 		if (col >= sp->cols - 1) {
12584d9c625SLionel Sambuc 			col = len;
12684d9c625SLionel Sambuc 			sep = 0;
12784d9c625SLionel Sambuc 			(void)ex_puts(sp, "\n");
12884d9c625SLionel Sambuc 		} else if (cnt != 1) {
12984d9c625SLionel Sambuc 			sep = 1;
13084d9c625SLionel Sambuc 			(void)ex_puts(sp, " ");
13184d9c625SLionel Sambuc 		}
13284d9c625SLionel Sambuc 		(void)ex_puts(sp, tsp->frp->name);
13384d9c625SLionel Sambuc 		++cnt;
13484d9c625SLionel Sambuc 	}
13584d9c625SLionel Sambuc 	if (!INTERRUPTED(sp))
13684d9c625SLionel Sambuc 		(void)ex_puts(sp, "\n");
13784d9c625SLionel Sambuc 	return (0);
13884d9c625SLionel Sambuc }
139