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.
9 * See the LICENSE file for redistribution information.
15 static const char sccsid
[] = "Id: screen.c,v 10.22 2001/06/25 15:19:12 skimo Exp (Berkeley) Date: 2001/06/25 15:19:12";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
35 * Do the default initialization of an SCR structure.
37 * PUBLIC: int screen_init __P((GS *, SCR *, SCR **));
40 screen_init(GS
*gp
, SCR
*orig
, SCR
**spp
)
46 CALLOC_RET(orig
, sp
, SCR
*, 1, sizeof(SCR
));
49 /* INITIALIZED AT SCREEN CREATE. */
53 sp
->gp
= gp
; /* All ref the GS structure. */
55 sp
->ccnt
= 2; /* Anything > 1 */
59 * sp->defscroll is initialized by the opts_init() code because
60 * we don't have the option information yet.
63 CIRCLEQ_INIT(&sp
->tiq
);
65 /* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
67 sp
->searchdir
= NOTSET
;
71 /* Alternate file name. */
72 if (orig
->alt_name
!= NULL
&&
73 (sp
->alt_name
= strdup(orig
->alt_name
)) == NULL
)
76 /* Last executed at buffer. */
77 if (F_ISSET(orig
, SC_AT_SET
)) {
79 sp
->at_lbuf
= orig
->at_lbuf
;
82 /* Retain searching/substitution information. */
83 sp
->searchdir
= orig
->searchdir
== NOTSET
? NOTSET
: FORWARD
;
84 if (orig
->re
!= NULL
&& (sp
->re
=
85 v_wstrdup(sp
, orig
->re
, orig
->re_len
)) == NULL
)
87 sp
->re_len
= orig
->re_len
;
88 if (orig
->subre
!= NULL
&& (sp
->subre
=
89 v_wstrdup(sp
, orig
->subre
, orig
->subre_len
)) == NULL
)
91 sp
->subre_len
= orig
->subre_len
;
92 if (orig
->repl
!= NULL
&& (sp
->repl
=
93 v_wstrdup(sp
, orig
->repl
, orig
->repl_len
)) == NULL
)
95 sp
->repl_len
= orig
->repl_len
;
97 len
= orig
->newl_len
* sizeof(size_t);
98 MALLOC(sp
, sp
->newl
, size_t *, len
);
99 if (sp
->newl
== NULL
) {
100 mem
: msgq(orig
, M_SYSERR
, NULL
);
103 sp
->newl_len
= orig
->newl_len
;
104 sp
->newl_cnt
= orig
->newl_cnt
;
105 memcpy(sp
->newl
, orig
->newl
, len
);
108 if (opts_copy(orig
, sp
))
111 F_SET(sp
, F_ISSET(orig
, SC_EX
| SC_VI
));
114 if (ex_screen_copy(orig
, sp
)) /* Ex. */
116 if (v_screen_copy(orig
, sp
)) /* Vi. */
118 sp
->cl_private
= 0; /* XXX */
119 conv_init(orig
, sp
); /* XXX */
130 * Release a screen, no matter what had (and had not) been
133 * PUBLIC: int screen_end __P((SCR *));
140 /* If multiply referenced, just decrement the count and return. */
141 if (--sp
->refcnt
!= 0)
145 * Remove the screen from the displayed queue.
147 * If a created screen failed during initialization, it may not
148 * be linked into the chain.
150 if (sp
->q
.cqe_next
!= NULL
)
151 CIRCLEQ_REMOVE(&sp
->wp
->scrq
, sp
, q
);
153 /* The screen is no longer real. */
154 F_CLR(sp
, SC_SCR_EX
| SC_SCR_VI
);
157 #ifdef HAVE_PERL_INTERP
158 if (perl_screen_end(sp
)) /* End perl. */
161 if (v_screen_end(sp
)) /* End vi. */
163 if (ex_screen_end(sp
)) /* End ex. */
166 /* Free file names. */
168 if (!F_ISSET(sp
, SC_ARGNOFREE
) && sp
->argv
!= NULL
) {
169 for (ap
= sp
->argv
; *ap
!= NULL
; ++ap
)
175 /* Free any text input. */
176 if (sp
->tiq
.cqh_first
!= NULL
)
177 text_lfree(&sp
->tiq
);
179 /* Free alternate file name. */
180 if (sp
->alt_name
!= NULL
)
183 /* Free up search information. */
186 if (F_ISSET(sp
, SC_RE_SEARCH
))
188 if (sp
->subre
!= NULL
)
190 if (F_ISSET(sp
, SC_RE_SUBST
))
191 regfree(&sp
->subre_c
);
192 if (sp
->repl
!= NULL
)
194 if (sp
->newl
!= NULL
)
197 /* Free all the options */
200 /* Free the screen itself. */
208 * Return the next screen in the queue.
210 * PUBLIC: SCR *screen_next __P((SCR *));
219 /* Try the display queue, without returning the current screen. */
222 for (next
= wp
->scrq
.cqh_first
;
223 next
!= (void *)&wp
->scrq
; next
= next
->q
.cqe_next
)
226 if (next
!= (void *)&wp
->scrq
)
229 /* Try the hidden queue; if found, move screen to the display queue. */
230 if (gp
->hq
.cqh_first
!= (void *)&gp
->hq
) {
231 next
= gp
->hq
.cqh_first
;
232 CIRCLEQ_REMOVE(&gp
->hq
, next
, q
);
233 CIRCLEQ_INSERT_HEAD(&wp
->scrq
, next
, q
);