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