* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)screen.c 8.51 (Berkeley) 1/11/94";
* Do the default initialization of an SCR structure.
screen_init(orig
, spp
, flags
)
CALLOC_RET(orig
, sp
, SCR
*, 1, sizeof(SCR
));
/* INITIALIZED AT SCREEN CREATE. */
sp
->gp
= __global_list
; /* All ref the GS structure. */
CIRCLEQ_INIT(&sp
->frefq
);
sp
->ccnt
= 2; /* Anything > 1 */
/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
sp
->csearchdir
= CNOTSET
;
switch (flags
& S_SCREENS
) {
if (orig
->alt_name
!= NULL
&&
(sp
->alt_name
= strdup(orig
->alt_name
)) == NULL
)
/* Retain all searching/substitution information. */
if (F_ISSET(orig
, S_SRE_SET
)) {
if (F_ISSET(orig
, S_SUBRE_SET
)) {
sp
->searchdir
= orig
->searchdir
== NOTSET
? NOTSET
: FORWARD
;
sp
->csearchdir
= CNOTSET
;
sp
->lastckey
= orig
->lastckey
;
len
= orig
->matchsize
* sizeof(regmatch_t
);
MALLOC(sp
, sp
->match
, regmatch_t
*, len
);
sp
->matchsize
= orig
->matchsize
;
memmove(sp
->match
, orig
->match
, len
);
MALLOC(sp
, sp
->repl
, char *, orig
->repl_len
);
sp
->repl_len
= orig
->repl_len
;
memmove(sp
->repl
, orig
->repl
, orig
->repl_len
);
len
= orig
->newl_len
* sizeof(size_t);
MALLOC(sp
, sp
->newl
, size_t *, len
);
sp
->newl_len
= orig
->newl_len
;
sp
->newl_cnt
= orig
->newl_cnt
;
memmove(sp
->newl
, orig
->newl
, len
);
sp
->saved_vi_mode
= orig
->saved_vi_mode
;
if (opts_copy(orig
, sp
)) {
mem
: msgq(orig
, M_SYSERR
, "new screen attributes");
sp
->s_bell
= orig
->s_bell
;
sp
->s_busy
= orig
->s_busy
;
sp
->s_change
= orig
->s_change
;
sp
->s_chposition
= orig
->s_chposition
;
sp
->s_clear
= orig
->s_clear
;
sp
->s_column
= orig
->s_column
;
sp
->s_confirm
= orig
->s_confirm
;
sp
->s_down
= orig
->s_down
;
sp
->s_edit
= orig
->s_edit
;
sp
->s_ex_cmd
= orig
->s_ex_cmd
;
sp
->s_ex_run
= orig
->s_ex_run
;
sp
->s_ex_write
= orig
->s_ex_write
;
sp
->s_fill
= orig
->s_fill
;
sp
->s_key_read
= orig
->s_key_read
;
sp
->s_optchange
= orig
->s_optchange
;
sp
->s_position
= orig
->s_position
;
sp
->s_rabs
= orig
->s_rabs
;
sp
->s_refresh
= orig
->s_refresh
;
sp
->s_relative
= orig
->s_relative
;
sp
->s_rrel
= orig
->s_rrel
;
sp
->s_split
= orig
->s_split
;
sp
->s_suspend
= orig
->s_suspend
;
F_SET(sp
, F_ISSET(orig
, S_SCREENS
));
if (xaw_screen_copy(orig
, sp
)) /* Init S_VI_XAW screen. */
if (svi_screen_copy(orig
, sp
)) /* Init S_VI_CURSES screen. */
if (sex_screen_copy(orig
, sp
)) /* Init S_EX screen. */
if (v_screen_copy(orig
, sp
)) /* Init vi. */
if (ex_screen_copy(orig
, sp
)) /* Init ex. */
if (xaw_screen_end(sp
)) /* End S_VI_XAW screen. */
if (svi_screen_end(sp
)) /* End S_VI_CURSES screen. */
if (sex_screen_end(sp
)) /* End S_EX screen. */
if (v_screen_end(sp
)) /* End vi. */
if (ex_screen_end(sp
)) /* End ex. */
while ((frp
= sp
->frefq
.cqh_first
) != (FREF
*)&sp
->frefq
) {
CIRCLEQ_REMOVE(&sp
->frefq
, frp
, q
);
/* Free any text input. */
/* Free any script information. */
if (F_ISSET(sp
, S_SCRIPT
))
/* Free alternate file name. */
if (sp
->alt_name
!= NULL
)
FREE(sp
->alt_name
, strlen(sp
->alt_name
) + 1);
/* Free up search information. */
FREE(sp
->match
, sizeof(regmatch_t
));
FREE(sp
->repl
, sp
->repl_len
);
FREE(sp
->newl
, sp
->newl_len
);
/* Free all the options */
* Free the message chain last, so previous failures have a place
* to put messages. Copy messages to (in order) a related screen,
* any screen, the global area.
{ SCR
*c_sp
; MSG
*mp
, *next
;
if ((c_sp
= sp
->q
.cqe_prev
) != (void *)&sp
->gp
->dq
) {
if (F_ISSET(sp
, S_BELLSCHED
))
F_SET(c_sp
, S_BELLSCHED
);
} else if ((c_sp
= sp
->q
.cqe_next
) != (void *)&sp
->gp
->dq
) {
if (F_ISSET(sp
, S_BELLSCHED
))
F_SET(c_sp
, S_BELLSCHED
);
sp
->gp
->hq
.cqh_first
) != (void *)&sp
->gp
->hq
) {
if (F_ISSET(sp
, S_BELLSCHED
))
F_SET(c_sp
, S_BELLSCHED
);
if (F_ISSET(sp
, S_BELLSCHED
))
F_SET(sp
->gp
, G_BELLSCHED
);
for (mp
= sp
->msgq
.lh_first
; mp
!= NULL
; mp
= next
) {
if (!F_ISSET(mp
, M_EMPTY
))
mp
->flags
& M_INV_VIDEO
, mp
->mbuf
, mp
->len
);
FREE(mp
->mbuf
, mp
->blen
);
/* Remove the screen from the displayed queue. */
CIRCLEQ_REMOVE(&sp
->gp
->dq
, sp
, q
);
/* Free the screen itself. */