10 |
|
#include "config.h" |
11 |
|
|
12 |
|
#ifndef lint |
13 |
< |
static const char sccsid[] = "@(#)screen.c 10.15 (Berkeley) 9/15/96"; |
13 |
> |
static const char sccsid[] = "$Id: screen.c,v 10.25 2011/12/04 04:06:45 zy Exp $"; |
14 |
|
#endif /* not lint */ |
15 |
|
|
16 |
|
#include <sys/types.h> |
35 |
|
* PUBLIC: int screen_init __P((GS *, SCR *, SCR **)); |
36 |
|
*/ |
37 |
|
int |
38 |
< |
screen_init(gp, orig, spp) |
39 |
< |
GS *gp; |
40 |
< |
SCR *orig, **spp; |
38 |
> |
screen_init( |
39 |
> |
GS *gp, |
40 |
> |
SCR *orig, |
41 |
> |
SCR **spp) |
42 |
|
{ |
43 |
|
SCR *sp; |
44 |
|
size_t len; |
51 |
|
sp->id = ++gp->id; |
52 |
|
sp->refcnt = 1; |
53 |
|
|
54 |
< |
sp->gp = gp; /* All ref the GS structure. */ |
54 |
> |
sp->gp = gp; /* All ref the GS structure. */ |
55 |
|
|
56 |
< |
sp->ccnt = 2; /* Anything > 1 */ |
56 |
> |
sp->ccnt = 2; /* Anything > 1 */ |
57 |
|
|
58 |
|
/* |
59 |
|
* XXX |
61 |
|
* we don't have the option information yet. |
62 |
|
*/ |
63 |
|
|
64 |
< |
CIRCLEQ_INIT(&sp->tiq); |
64 |
> |
TAILQ_INIT(sp->tiq); |
65 |
|
|
66 |
|
/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */ |
67 |
|
if (orig == NULL) { |
81 |
|
/* Retain searching/substitution information. */ |
82 |
|
sp->searchdir = orig->searchdir == NOTSET ? NOTSET : FORWARD; |
83 |
|
if (orig->re != NULL && (sp->re = |
84 |
< |
v_strdup(sp, orig->re, orig->re_len)) == NULL) |
84 |
> |
v_wstrdup(sp, orig->re, orig->re_len)) == NULL) |
85 |
|
goto mem; |
86 |
|
sp->re_len = orig->re_len; |
87 |
|
if (orig->subre != NULL && (sp->subre = |
88 |
< |
v_strdup(sp, orig->subre, orig->subre_len)) == NULL) |
88 |
> |
v_wstrdup(sp, orig->subre, orig->subre_len)) == NULL) |
89 |
|
goto mem; |
90 |
|
sp->subre_len = orig->subre_len; |
91 |
|
if (orig->repl != NULL && (sp->repl = |
92 |
< |
v_strdup(sp, orig->repl, orig->repl_len)) == NULL) |
92 |
> |
v_wstrdup(sp, orig->repl, orig->repl_len)) == NULL) |
93 |
|
goto mem; |
94 |
|
sp->repl_len = orig->repl_len; |
95 |
|
if (orig->newl_len) { |
114 |
|
goto err; |
115 |
|
if (v_screen_copy(orig, sp)) /* Vi. */ |
116 |
|
goto err; |
117 |
+ |
sp->cl_private = 0; /* XXX */ |
118 |
+ |
conv_init(orig, sp); /* XXX */ |
119 |
|
|
120 |
|
*spp = sp; |
121 |
|
return (0); |
132 |
|
* PUBLIC: int screen_end __P((SCR *)); |
133 |
|
*/ |
134 |
|
int |
135 |
< |
screen_end(sp) |
133 |
< |
SCR *sp; |
135 |
> |
screen_end(SCR *sp) |
136 |
|
{ |
137 |
|
int rval; |
138 |
|
|
146 |
|
* If a created screen failed during initialization, it may not |
147 |
|
* be linked into the chain. |
148 |
|
*/ |
149 |
< |
if (sp->q.cqe_next != NULL) |
150 |
< |
CIRCLEQ_REMOVE(&sp->gp->dq, sp, q); |
149 |
> |
if (TAILQ_ENTRY_ISVALID(sp, q)) |
150 |
> |
TAILQ_REMOVE(sp->gp->dq, sp, q); |
151 |
|
|
152 |
|
/* The screen is no longer real. */ |
153 |
|
F_CLR(sp, SC_SCR_EX | SC_SCR_VI); |
154 |
|
|
155 |
|
rval = 0; |
154 |
– |
#ifdef HAVE_PERL_INTERP |
155 |
– |
if (perl_screen_end(sp)) /* End perl. */ |
156 |
– |
rval = 1; |
157 |
– |
#endif |
156 |
|
if (v_screen_end(sp)) /* End vi. */ |
157 |
|
rval = 1; |
158 |
|
if (ex_screen_end(sp)) /* End ex. */ |
168 |
|
} |
169 |
|
|
170 |
|
/* Free any text input. */ |
171 |
< |
if (sp->tiq.cqh_first != NULL) |
172 |
< |
text_lfree(&sp->tiq); |
171 |
> |
if (!TAILQ_EMPTY(sp->tiq)) |
172 |
> |
text_lfree(sp->tiq); |
173 |
|
|
174 |
|
/* Free alternate file name. */ |
175 |
|
if (sp->alt_name != NULL) |
189 |
|
if (sp->newl != NULL) |
190 |
|
free(sp->newl); |
191 |
|
|
192 |
+ |
/* Free the iconv environment */ |
193 |
+ |
conv_end(sp); |
194 |
+ |
|
195 |
|
/* Free all the options */ |
196 |
|
opts_free(sp); |
197 |
|
|
208 |
|
* PUBLIC: SCR *screen_next __P((SCR *)); |
209 |
|
*/ |
210 |
|
SCR * |
211 |
< |
screen_next(sp) |
211 |
< |
SCR *sp; |
211 |
> |
screen_next(SCR *sp) |
212 |
|
{ |
213 |
|
GS *gp; |
214 |
|
SCR *next; |
215 |
|
|
216 |
|
/* Try the display queue, without returning the current screen. */ |
217 |
|
gp = sp->gp; |
218 |
< |
for (next = gp->dq.cqh_first; |
219 |
< |
next != (void *)&gp->dq; next = next->q.cqe_next) |
218 |
> |
TAILQ_FOREACH(next, gp->dq, q) |
219 |
|
if (next != sp) |
220 |
|
break; |
221 |
< |
if (next != (void *)&gp->dq) |
221 |
> |
if (next != NULL) |
222 |
|
return (next); |
223 |
|
|
224 |
|
/* Try the hidden queue; if found, move screen to the display queue. */ |
225 |
< |
if (gp->hq.cqh_first != (void *)&gp->hq) { |
226 |
< |
next = gp->hq.cqh_first; |
227 |
< |
CIRCLEQ_REMOVE(&gp->hq, next, q); |
228 |
< |
CIRCLEQ_INSERT_HEAD(&gp->dq, next, q); |
225 |
> |
if (!TAILQ_EMPTY(gp->hq)) { |
226 |
> |
next = TAILQ_FIRST(gp->hq); |
227 |
> |
TAILQ_REMOVE(gp->hq, next, q); |
228 |
> |
TAILQ_INSERT_HEAD(gp->dq, next, q); |
229 |
|
return (next); |
230 |
|
} |
231 |
|
return (NULL); |