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