3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: screen.c,v 8.51 1994/01/11 22:36:23 bostic Exp $ (Berkeley) $Date: 1994/01/11 22:36:23 $";
12 #include <sys/types.h>
26 * Do the default initialization of an SCR structure.
29 screen_init(orig
, spp
, flags
)
37 CALLOC_RET(orig
, sp
, SCR
*, 1, sizeof(SCR
));
40 /* INITIALIZED AT SCREEN CREATE. */
41 sp
->gp
= __global_list
; /* All ref the GS structure. */
44 CIRCLEQ_INIT(&sp
->frefq
);
46 sp
->ccnt
= 2; /* Anything > 1 */
50 CIRCLEQ_INIT(&sp
->tiq
);
52 /* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
54 sp
->searchdir
= NOTSET
;
55 sp
->csearchdir
= CNOTSET
;
57 switch (flags
& S_SCREENS
) {
59 if (sex_screen_init(sp
))
63 if (svi_screen_init(sp
))
67 if (xaw_screen_init(sp
))
76 if (orig
->alt_name
!= NULL
&&
77 (sp
->alt_name
= strdup(orig
->alt_name
)) == NULL
)
80 /* Retain all searching/substitution information. */
81 if (F_ISSET(orig
, S_SRE_SET
)) {
85 if (F_ISSET(orig
, S_SUBRE_SET
)) {
86 F_SET(sp
, S_SUBRE_SET
);
87 sp
->subre
= orig
->subre
;
89 sp
->searchdir
= orig
->searchdir
== NOTSET
? NOTSET
: FORWARD
;
90 sp
->csearchdir
= CNOTSET
;
91 sp
->lastckey
= orig
->lastckey
;
93 if (orig
->matchsize
) {
94 len
= orig
->matchsize
* sizeof(regmatch_t
);
95 MALLOC(sp
, sp
->match
, regmatch_t
*, len
);
96 if (sp
->match
== NULL
)
98 sp
->matchsize
= orig
->matchsize
;
99 memmove(sp
->match
, orig
->match
, len
);
101 if (orig
->repl_len
) {
102 MALLOC(sp
, sp
->repl
, char *, orig
->repl_len
);
103 if (sp
->repl
== NULL
)
105 sp
->repl_len
= orig
->repl_len
;
106 memmove(sp
->repl
, orig
->repl
, orig
->repl_len
);
108 if (orig
->newl_len
) {
109 len
= orig
->newl_len
* sizeof(size_t);
110 MALLOC(sp
, sp
->newl
, size_t *, len
);
111 if (sp
->newl
== NULL
)
113 sp
->newl_len
= orig
->newl_len
;
114 sp
->newl_cnt
= orig
->newl_cnt
;
115 memmove(sp
->newl
, orig
->newl
, len
);
118 sp
->saved_vi_mode
= orig
->saved_vi_mode
;
120 if (opts_copy(orig
, sp
)) {
121 mem
: msgq(orig
, M_SYSERR
, "new screen attributes");
122 (void)screen_end(sp
);
126 sp
->s_bell
= orig
->s_bell
;
127 sp
->s_bg
= orig
->s_bg
;
128 sp
->s_busy
= orig
->s_busy
;
129 sp
->s_change
= orig
->s_change
;
130 sp
->s_chposition
= orig
->s_chposition
;
131 sp
->s_clear
= orig
->s_clear
;
132 sp
->s_column
= orig
->s_column
;
133 sp
->s_confirm
= orig
->s_confirm
;
134 sp
->s_down
= orig
->s_down
;
135 sp
->s_edit
= orig
->s_edit
;
136 sp
->s_end
= orig
->s_end
;
137 sp
->s_ex_cmd
= orig
->s_ex_cmd
;
138 sp
->s_ex_run
= orig
->s_ex_run
;
139 sp
->s_ex_write
= orig
->s_ex_write
;
140 sp
->s_fg
= orig
->s_fg
;
141 sp
->s_fill
= orig
->s_fill
;
142 sp
->s_get
= orig
->s_get
;
143 sp
->s_key_read
= orig
->s_key_read
;
144 sp
->s_optchange
= orig
->s_optchange
;
145 sp
->s_position
= orig
->s_position
;
146 sp
->s_rabs
= orig
->s_rabs
;
147 sp
->s_refresh
= orig
->s_refresh
;
148 sp
->s_relative
= orig
->s_relative
;
149 sp
->s_rrel
= orig
->s_rrel
;
150 sp
->s_split
= orig
->s_split
;
151 sp
->s_suspend
= orig
->s_suspend
;
152 sp
->s_up
= orig
->s_up
;
154 F_SET(sp
, F_ISSET(orig
, S_SCREENS
));
157 if (xaw_screen_copy(orig
, sp
)) /* Init S_VI_XAW screen. */
159 if (svi_screen_copy(orig
, sp
)) /* Init S_VI_CURSES screen. */
161 if (sex_screen_copy(orig
, sp
)) /* Init S_EX screen. */
163 if (v_screen_copy(orig
, sp
)) /* Init vi. */
165 if (ex_screen_copy(orig
, sp
)) /* Init ex. */
183 if (xaw_screen_end(sp
)) /* End S_VI_XAW screen. */
185 if (svi_screen_end(sp
)) /* End S_VI_CURSES screen. */
187 if (sex_screen_end(sp
)) /* End S_EX screen. */
189 if (v_screen_end(sp
)) /* End vi. */
191 if (ex_screen_end(sp
)) /* End ex. */
196 while ((frp
= sp
->frefq
.cqh_first
) != (FREF
*)&sp
->frefq
) {
197 CIRCLEQ_REMOVE(&sp
->frefq
, frp
, q
);
198 if (frp
->cname
!= NULL
)
200 if (frp
->name
!= NULL
)
202 if (frp
->tname
!= NULL
)
204 FREE(frp
, sizeof(FREF
));
208 /* Free any text input. */
209 text_lfree(&sp
->tiq
);
211 /* Free any script information. */
212 if (F_ISSET(sp
, S_SCRIPT
))
215 /* Free alternate file name. */
216 if (sp
->alt_name
!= NULL
)
217 FREE(sp
->alt_name
, strlen(sp
->alt_name
) + 1);
219 /* Free up search information. */
220 if (sp
->match
!= NULL
)
221 FREE(sp
->match
, sizeof(regmatch_t
));
222 if (sp
->repl
!= NULL
)
223 FREE(sp
->repl
, sp
->repl_len
);
224 if (sp
->newl
!= NULL
)
225 FREE(sp
->newl
, sp
->newl_len
);
227 /* Free all the options */
231 * Free the message chain last, so previous failures have a place
232 * to put messages. Copy messages to (in order) a related screen,
233 * any screen, the global area.
235 { SCR
*c_sp
; MSG
*mp
, *next
;
236 if ((c_sp
= sp
->q
.cqe_prev
) != (void *)&sp
->gp
->dq
) {
237 if (F_ISSET(sp
, S_BELLSCHED
))
238 F_SET(c_sp
, S_BELLSCHED
);
239 } else if ((c_sp
= sp
->q
.cqe_next
) != (void *)&sp
->gp
->dq
) {
240 if (F_ISSET(sp
, S_BELLSCHED
))
241 F_SET(c_sp
, S_BELLSCHED
);
243 sp
->gp
->hq
.cqh_first
) != (void *)&sp
->gp
->hq
) {
244 if (F_ISSET(sp
, S_BELLSCHED
))
245 F_SET(c_sp
, S_BELLSCHED
);
248 if (F_ISSET(sp
, S_BELLSCHED
))
249 F_SET(sp
->gp
, G_BELLSCHED
);
252 for (mp
= sp
->msgq
.lh_first
; mp
!= NULL
; mp
= next
) {
253 if (!F_ISSET(mp
, M_EMPTY
))
254 msg_app(sp
->gp
, c_sp
,
255 mp
->flags
& M_INV_VIDEO
, mp
->mbuf
, mp
->len
);
256 next
= mp
->q
.le_next
;
257 if (mp
->mbuf
!= NULL
)
258 FREE(mp
->mbuf
, mp
->blen
);
259 FREE(mp
, sizeof(MSG
));
263 /* Remove the screen from the displayed queue. */
264 CIRCLEQ_REMOVE(&sp
->gp
->dq
, sp
, q
);
266 /* Free the screen itself. */
267 FREE(sp
, sizeof(SCR
));