5 * Sven Verdoolaege. All rights reserved.
7 * See the LICENSE file for redistribution information.
12 #include <sys/types.h>
13 #include <sys/queue.h>
15 #include <bitstring.h>
23 #include "../common/common.h"
24 #include "../perl_api/extern.h"
26 static void perr
__P((char *, char *));
30 * Create and partially initialize the GS structure.
31 * PUBLIC: GS * gs_init __P((char*));
39 /* Figure out what our name is. */
40 if ((p
= strrchr(name
, '/')) != NULL
)
43 /* Allocate the global structure. */
44 CALLOC_NOMSG(NULL
, gp
, GS
*, 1, sizeof(GS
));
50 /* Common global structure initialization. */
51 /* others will need to be copied from main.c */
52 CIRCLEQ_INIT(&gp
->dq
);
54 CIRCLEQ_INIT(&gp
->hq
);
55 gp
->noprint
= DEFAULT_NOPRINT
;
57 /* Structures shared by screens so stored in the GS structure. */
58 CIRCLEQ_INIT(&gp
->frefq
);
59 CIRCLEQ_INIT(&gp
->exfq
);
70 * PUBLIC: WIN * gs_new_win __P((GS *gp));
78 CALLOC_NOMSG(NULL
, wp
, WIN
*, 1, sizeof(*wp
));
82 /* Common global structure initialization. */
84 LIST_INSERT_HEAD(&wp
->ecq
, &wp
->excmd
, q
);
86 CIRCLEQ_INSERT_TAIL(&gp
->dq
, wp
, q
);
87 CIRCLEQ_INIT(&wp
->scrq
);
89 CIRCLEQ_INIT(&wp
->dcb_store
.textq
);
101 * PUBLIC: int win_end __P((WIN *wp));
108 CIRCLEQ_REMOVE(&wp
->gp
->dq
, wp
, q
);
110 if (wp
->ccl_sp
!= NULL
) {
111 (void)file_end(wp
->ccl_sp
, NULL
, 1);
112 (void)screen_end(wp
->ccl_sp
);
114 while ((sp
= wp
->scrq
.cqh_first
) != (void *)&wp
->scrq
)
115 (void)screen_end(sp
);
117 /* Free key input queue. */
118 if (wp
->i_event
!= NULL
)
121 /* Free cut buffers. */
124 /* Free default buffer storage. */
125 (void)text_lfree(&wp
->dcb_store
.textq
);
127 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
128 /* Free any temporary space. */
129 if (wp
->tmp_bp
!= NULL
)
138 * End the program, discarding screens and most of the global area.
140 * PUBLIC: void gs_end __P((GS *));
149 /* If there are any remaining screens, kill them off. */
150 while ((wp
= gp
->dq
.cqh_first
) != (void *)&gp
->dq
)
152 while ((sp
= gp
->hq
.cqh_first
) != (void *)&gp
->hq
)
153 (void)screen_end(sp
);
155 #ifdef HAVE_PERL_INTERP
159 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
162 while ((frp
= gp
->frefq
.cqh_first
) != (FREF
*)&gp
->frefq
) {
163 CIRCLEQ_REMOVE(&gp
->frefq
, frp
, q
);
164 if (frp
->name
!= NULL
)
166 if (frp
->tname
!= NULL
)
172 /* Free map sequences. */
175 /* Close message catalogs. */
179 /* Ring the bell if scheduled. */
180 if (F_ISSET(gp
, G_BELLSCHED
))
181 (void)fprintf(stderr
, "\07"); /* \a */
184 * Flush any remaining messages. If a message is here, it's almost
185 * certainly the message about the event that killed us (although
186 * it's possible that the user is sourcing a file that exits from the
189 while ((mp
= gp
->msgq
.lh_first
) != NULL
) {
190 (void)fprintf(stderr
, "%s%.*s",
191 mp
->mtype
== M_ERR
? "ex/vi: " : "", (int)mp
->len
, mp
->buf
);
193 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
200 /* Close tracing file descriptor. */
208 * Print system error.
211 perr(char *name
, char *msg
)
213 (void)fprintf(stderr
, "%s:", name
);
215 (void)fprintf(stderr
, "%s:", msg
);
216 (void)fprintf(stderr
, "%s\n", strerror(errno
));