xref: /minix/external/bsd/nvi/dist/ex/ex_screen.c (revision 84d9c625)
1 /*	$NetBSD: ex_screen.c,v 1.3 2013/11/25 22:43:46 christos Exp $ */
2 /*-
3  * Copyright (c) 1993, 1994
4  *	The Regents of the University of California.  All rights reserved.
5  * Copyright (c) 1993, 1994, 1995, 1996
6  *	Keith Bostic.  All rights reserved.
7  *
8  * See the LICENSE file for redistribution information.
9  */
10 
11 #include "config.h"
12 
13 #ifndef lint
14 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 ";
15 #endif /* not lint */
16 
17 #include <sys/types.h>
18 #include <sys/queue.h>
19 #include <sys/time.h>
20 
21 #include <bitstring.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "../common/common.h"
28 #include "../vi/vi.h"
29 
30 /*
31  * ex_bg --	:bg
32  *	Hide the screen.
33  *
34  * PUBLIC: int ex_bg __P((SCR *, EXCMD *));
35  */
36 int
37 ex_bg(SCR *sp, EXCMD *cmdp)
38 {
39 	return (vs_bg(sp));
40 }
41 
42 /*
43  * ex_fg --	:fg [file]
44  *	Show the screen.
45  *
46  * PUBLIC: int ex_fg __P((SCR *, EXCMD *));
47  */
48 int
49 ex_fg(SCR *sp, EXCMD *cmdp)
50 {
51 	SCR *nsp;
52 	int newscreen;
53 
54 	newscreen = F_ISSET(cmdp, E_NEWSCREEN);
55 	if (vs_fg(sp, &nsp, cmdp->argc ? cmdp->argv[0]->bp : NULL, newscreen))
56 		return (1);
57 
58 	/* Set up the switch. */
59 	if (newscreen) {
60 		sp->nextdisp = nsp;
61 		F_SET(sp, SC_SSWITCH);
62 	}
63 	return (0);
64 }
65 
66 /*
67  * ex_resize --	:resize [+-]rows
68  *	Change the screen size.
69  *
70  * PUBLIC: int ex_resize __P((SCR *, EXCMD *));
71  */
72 int
73 ex_resize(SCR *sp, EXCMD *cmdp)
74 {
75 	adj_t adj;
76 
77 	switch (FL_ISSET(cmdp->iflags,
78 	    E_C_COUNT | E_C_COUNT_NEG | E_C_COUNT_POS)) {
79 	case E_C_COUNT:
80 		adj = A_SET;
81 		break;
82 	case E_C_COUNT | E_C_COUNT_NEG:
83 		adj = A_DECREASE;
84 		break;
85 	case E_C_COUNT | E_C_COUNT_POS:
86 		adj = A_INCREASE;
87 		break;
88 	default:
89 		ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
90 		return (1);
91 	}
92 	return (vs_resize(sp, cmdp->count, adj));
93 }
94 
95 /*
96  * ex_sdisplay --
97  *	Display the list of screens.
98  *
99  * PUBLIC: int ex_sdisplay __P((SCR *));
100  */
101 int
102 ex_sdisplay(SCR *sp)
103 {
104 	GS *gp;
105 	SCR *tsp;
106 	int cnt, sep;
107 	size_t col, len;
108 
109 	gp = sp->gp;
110 	if ((tsp = TAILQ_FIRST(&gp->hq)) == NULL) {
111 		msgq(sp, M_INFO, "149|No background screens to display");
112 		return (0);
113 	}
114 
115 	col = len = sep = 0;
116 	for (cnt = 1; tsp != NULL && !INTERRUPTED(sp);
117 	    tsp = TAILQ_NEXT(tsp, q)) {
118 		col += len = strlen(tsp->frp->name) + sep;
119 		if (col >= sp->cols - 1) {
120 			col = len;
121 			sep = 0;
122 			(void)ex_puts(sp, "\n");
123 		} else if (cnt != 1) {
124 			sep = 1;
125 			(void)ex_puts(sp, " ");
126 		}
127 		(void)ex_puts(sp, tsp->frp->name);
128 		++cnt;
129 	}
130 	if (!INTERRUPTED(sp))
131 		(void)ex_puts(sp, "\n");
132 	return (0);
133 }
134