Sync with FreeBSD. This adds read-only support for zip and ISO9660.
[dragonfly.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 #ifndef lint
13 static const char sccsid[] = "@(#)ex_screen.c   10.11 (Berkeley) 6/29/96";
14 #endif /* not lint */
15
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
19
20 #include <bitstring.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "../common/common.h"
27 #include "../vi/vi.h"
28
29 /*
30  * ex_bg --     :bg
31  *      Hide the screen.
32  *
33  * PUBLIC: int ex_bg __P((SCR *, EXCMD *));
34  */
35 int
36 ex_bg(sp, cmdp)
37         SCR *sp;
38         EXCMD *cmdp;
39 {
40         return (vs_bg(sp));
41 }
42
43 /*
44  * ex_fg --     :fg [file]
45  *      Show the screen.
46  *
47  * PUBLIC: int ex_fg __P((SCR *, EXCMD *));
48  */
49 int
50 ex_fg(sp, cmdp)
51         SCR *sp;
52         EXCMD *cmdp;
53 {
54         SCR *nsp;
55         int newscreen;
56
57         newscreen = F_ISSET(cmdp, E_NEWSCREEN);
58         if (vs_fg(sp, &nsp, cmdp->argc ? cmdp->argv[0]->bp : NULL, newscreen))
59                 return (1);
60
61         /* Set up the switch. */
62         if (newscreen) {
63                 sp->nextdisp = nsp;
64                 F_SET(sp, SC_SSWITCH);
65         }
66         return (0);
67 }
68
69 /*
70  * ex_resize -- :resize [+-]rows
71  *      Change the screen size.
72  *
73  * PUBLIC: int ex_resize __P((SCR *, EXCMD *));
74  */
75 int
76 ex_resize(sp, cmdp)
77         SCR *sp;
78         EXCMD *cmdp;
79 {
80         adj_t adj;
81
82         switch (FL_ISSET(cmdp->iflags,
83             E_C_COUNT | E_C_COUNT_NEG | E_C_COUNT_POS)) {
84         case E_C_COUNT:
85                 adj = A_SET;
86                 break;
87         case E_C_COUNT | E_C_COUNT_NEG:
88                 adj = A_DECREASE;
89                 break;
90         case E_C_COUNT | E_C_COUNT_POS:
91                 adj = A_INCREASE;
92                 break;
93         default:
94                 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
95                 return (1);
96         }
97         return (vs_resize(sp, cmdp->count, adj));
98 }
99
100 /*
101  * ex_sdisplay --
102  *      Display the list of screens.
103  *
104  * PUBLIC: int ex_sdisplay __P((SCR *));
105  */
106 int
107 ex_sdisplay(sp)
108         SCR *sp;
109 {
110         GS *gp;
111         SCR *tsp;
112         int cnt, col, len, sep;
113
114         gp = sp->gp;
115         if ((tsp = gp->hq.cqh_first) == (void *)&gp->hq) {
116                 msgq(sp, M_INFO, "149|No background screens to display");
117                 return (0);
118         }
119
120         col = len = sep = 0;
121         for (cnt = 1; tsp != (void *)&gp->hq && !INTERRUPTED(sp);
122             tsp = tsp->q.cqe_next) {
123                 col += len = strlen(tsp->frp->name) + sep;
124                 if (col >= sp->cols - 1) {
125                         col = len;
126                         sep = 0;
127                         (void)ex_puts(sp, "\n");
128                 } else if (cnt != 1) {
129                         sep = 1;
130                         (void)ex_puts(sp, " ");
131                 }
132                 (void)ex_puts(sp, tsp->frp->name);
133                 ++cnt;
134         }
135         if (!INTERRUPTED(sp))
136                 (void)ex_puts(sp, "\n");
137         return (0);
138 }