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.20 2000/07/22 10:20:31 skimo Exp $ (Berkeley) $Date: 2000/07/22 10:20:31 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
31 CHAR_T RE_WSTART
[] = {'[','[',':','<',':',']',']',0};
32 CHAR_T RE_WSTOP
[] = {'[','[',':','>',':',']',']',0};
36 * Do the default initialization of an SCR structure.
38 * PUBLIC: int screen_init __P((GS *, SCR *, SCR **));
41 screen_init(gp
, orig
, spp
)
49 CALLOC_RET(orig
, sp
, SCR
*, 1, sizeof(SCR
));
52 /* INITIALIZED AT SCREEN CREATE. */
56 sp
->gp
= gp
; /* All ref the GS structure. */
58 sp
->ccnt
= 2; /* Anything > 1 */
62 * sp->defscroll is initialized by the opts_init() code because
63 * we don't have the option information yet.
66 CIRCLEQ_INIT(&sp
->tiq
);
68 /* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
70 sp
->searchdir
= NOTSET
;
74 /* Alternate file name. */
75 if (orig
->alt_name
!= NULL
&&
76 (sp
->alt_name
= strdup(orig
->alt_name
)) == NULL
)
79 /* Last executed at buffer. */
80 if (F_ISSET(orig
, SC_AT_SET
)) {
82 sp
->at_lbuf
= orig
->at_lbuf
;
85 /* Retain searching/substitution information. */
86 sp
->searchdir
= orig
->searchdir
== NOTSET
? NOTSET
: FORWARD
;
87 if (orig
->re
!= NULL
&& (sp
->re
=
88 v_wstrdup(sp
, orig
->re
, orig
->re_len
)) == NULL
)
90 sp
->re_len
= orig
->re_len
;
91 if (orig
->subre
!= NULL
&& (sp
->subre
=
92 v_wstrdup(sp
, orig
->subre
, orig
->subre_len
)) == NULL
)
94 sp
->subre_len
= orig
->subre_len
;
95 if (orig
->repl
!= NULL
&& (sp
->repl
=
96 v_wstrdup(sp
, orig
->repl
, orig
->repl_len
)) == NULL
)
98 sp
->repl_len
= orig
->repl_len
;
100 len
= orig
->newl_len
* sizeof(size_t);
101 MALLOC(sp
, sp
->newl
, size_t *, len
);
102 if (sp
->newl
== NULL
) {
103 mem
: msgq(orig
, M_SYSERR
, NULL
);
106 sp
->newl_len
= orig
->newl_len
;
107 sp
->newl_cnt
= orig
->newl_cnt
;
108 memcpy(sp
->newl
, orig
->newl
, len
);
111 if (opts_copy(orig
, sp
))
114 F_SET(sp
, F_ISSET(orig
, SC_EX
| SC_VI
));
117 if (ex_screen_copy(orig
, sp
)) /* Ex. */
119 if (v_screen_copy(orig
, sp
)) /* Vi. */
121 sp
->cl_private
= 0; /* XXX */
122 conv_init(orig
, sp
); /* XXX */
133 * Release a screen, no matter what had (and had not) been
136 * PUBLIC: int screen_end __P((SCR *));
144 /* If multiply referenced, just decrement the count and return. */
145 if (--sp
->refcnt
!= 0)
149 * Remove the screen from the displayed queue.
151 * If a created screen failed during initialization, it may not
152 * be linked into the chain.
154 if (sp
->q
.cqe_next
!= NULL
)
155 CIRCLEQ_REMOVE(&sp
->wp
->scrq
, sp
, q
);
157 /* The screen is no longer real. */
158 F_CLR(sp
, SC_SCR_EX
| SC_SCR_VI
);
161 #ifdef HAVE_PERL_INTERP
162 if (perl_screen_end(sp
)) /* End perl. */
165 if (v_screen_end(sp
)) /* End vi. */
167 if (ex_screen_end(sp
)) /* End ex. */
170 /* Free file names. */
172 if (!F_ISSET(sp
, SC_ARGNOFREE
) && sp
->argv
!= NULL
) {
173 for (ap
= sp
->argv
; *ap
!= NULL
; ++ap
)
179 /* Free any text input. */
180 if (sp
->tiq
.cqh_first
!= NULL
)
181 text_lfree(&sp
->tiq
);
183 /* Free alternate file name. */
184 if (sp
->alt_name
!= NULL
)
187 /* Free up search information. */
190 if (F_ISSET(sp
, SC_RE_SEARCH
))
192 if (sp
->subre
!= NULL
)
194 if (F_ISSET(sp
, SC_RE_SUBST
))
195 regfree(&sp
->subre_c
);
196 if (sp
->repl
!= NULL
)
198 if (sp
->newl
!= NULL
)
201 /* Free all the options */
204 /* Free the screen itself. */
212 * Return the next screen in the queue.
214 * PUBLIC: SCR *screen_next __P((SCR *));
224 /* Try the display queue, without returning the current screen. */
227 for (next
= wp
->scrq
.cqh_first
;
228 next
!= (void *)&wp
->scrq
; next
= next
->q
.cqe_next
)
231 if (next
!= (void *)&wp
->scrq
)
234 /* Try the hidden queue; if found, move screen to the display queue. */
235 if (gp
->hq
.cqh_first
!= (void *)&gp
->hq
) {
236 next
= gp
->hq
.cqh_first
;
237 CIRCLEQ_REMOVE(&gp
->hq
, next
, q
);
238 CIRCLEQ_INSERT_HEAD(&wp
->scrq
, next
, q
);