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.
7 * See the LICENSE file for redistribution information.
13 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 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
33 * Do the default initialization of an SCR structure.
35 * PUBLIC: int screen_init __P((GS *, SCR *, SCR **));
38 screen_init(GS
*gp
, SCR
*orig
, SCR
**spp
)
44 CALLOC_RET(orig
, sp
, SCR
*, 1, sizeof(SCR
));
47 /* INITIALIZED AT SCREEN CREATE. */
51 sp
->gp
= gp
; /* All ref the GS structure. */
53 sp
->ccnt
= 2; /* Anything > 1 */
57 * sp->defscroll is initialized by the opts_init() code because
58 * we don't have the option information yet.
61 CIRCLEQ_INIT(&sp
->tiq
);
63 /* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
65 sp
->searchdir
= NOTSET
;
69 /* Alternate file name. */
70 if (orig
->alt_name
!= NULL
&&
71 (sp
->alt_name
= strdup(orig
->alt_name
)) == NULL
)
74 /* Last executed at buffer. */
75 if (F_ISSET(orig
, SC_AT_SET
)) {
77 sp
->at_lbuf
= orig
->at_lbuf
;
80 /* Retain searching/substitution information. */
81 sp
->searchdir
= orig
->searchdir
== NOTSET
? NOTSET
: FORWARD
;
82 if (orig
->re
!= NULL
&& (sp
->re
=
83 v_wstrdup(sp
, orig
->re
, orig
->re_len
)) == NULL
)
85 sp
->re_len
= orig
->re_len
;
86 if (orig
->subre
!= NULL
&& (sp
->subre
=
87 v_wstrdup(sp
, orig
->subre
, orig
->subre_len
)) == NULL
)
89 sp
->subre_len
= orig
->subre_len
;
90 if (orig
->repl
!= NULL
&& (sp
->repl
=
91 v_wstrdup(sp
, orig
->repl
, orig
->repl_len
)) == NULL
)
93 sp
->repl_len
= orig
->repl_len
;
95 len
= orig
->newl_len
* sizeof(size_t);
96 MALLOC(sp
, sp
->newl
, size_t *, len
);
97 if (sp
->newl
== NULL
) {
98 mem
: msgq(orig
, M_SYSERR
, NULL
);
101 sp
->newl_len
= orig
->newl_len
;
102 sp
->newl_cnt
= orig
->newl_cnt
;
103 memcpy(sp
->newl
, orig
->newl
, len
);
106 if (opts_copy(orig
, sp
))
109 F_SET(sp
, F_ISSET(orig
, SC_EX
| SC_VI
));
112 if (ex_screen_copy(orig
, sp
)) /* Ex. */
114 if (v_screen_copy(orig
, sp
)) /* Vi. */
116 sp
->cl_private
= 0; /* XXX */
117 conv_init(orig
, sp
); /* XXX */
128 * Release a screen, no matter what had (and had not) been
131 * PUBLIC: int screen_end __P((SCR *));
138 /* If multiply referenced, just decrement the count and return. */
139 if (--sp
->refcnt
!= 0)
143 * Remove the screen from the displayed queue.
145 * If a created screen failed during initialization, it may not
146 * be linked into the chain.
148 if (sp
->q
.cqe_next
!= NULL
)
149 CIRCLEQ_REMOVE(&sp
->wp
->scrq
, sp
, q
);
151 /* The screen is no longer real. */
152 F_CLR(sp
, SC_SCR_EX
| SC_SCR_VI
);
155 #ifdef HAVE_PERL_INTERP
156 if (perl_screen_end(sp
)) /* End perl. */
159 if (v_screen_end(sp
)) /* End vi. */
161 if (ex_screen_end(sp
)) /* End ex. */
164 /* Free file names. */
166 if (!F_ISSET(sp
, SC_ARGNOFREE
) && sp
->argv
!= NULL
) {
167 for (ap
= sp
->argv
; *ap
!= NULL
; ++ap
)
173 /* Free any text input. */
174 if (sp
->tiq
.cqh_first
!= NULL
)
175 text_lfree(&sp
->tiq
);
177 /* Free alternate file name. */
178 if (sp
->alt_name
!= NULL
)
181 /* Free up search information. */
184 if (F_ISSET(sp
, SC_RE_SEARCH
))
186 if (sp
->subre
!= NULL
)
188 if (F_ISSET(sp
, SC_RE_SUBST
))
189 regfree(&sp
->subre_c
);
190 if (sp
->repl
!= NULL
)
192 if (sp
->newl
!= NULL
)
195 /* Free all the options */
198 /* Free the screen itself. */
206 * Return the next screen in the queue.
208 * PUBLIC: SCR *screen_next __P((SCR *));
217 /* Try the display queue, without returning the current screen. */
220 for (next
= wp
->scrq
.cqh_first
;
221 next
!= (void *)&wp
->scrq
; next
= next
->q
.cqe_next
)
224 if (next
!= (void *)&wp
->scrq
)
227 /* Try the hidden queue; if found, move screen to the display queue. */
228 if (gp
->hq
.cqh_first
!= (void *)&gp
->hq
) {
229 next
= gp
->hq
.cqh_first
;
230 CIRCLEQ_REMOVE(&gp
->hq
, next
, q
);
231 CIRCLEQ_INSERT_HEAD(&wp
->scrq
, next
, q
);