3 * Sven Verdoolaege. All rights reserved.
5 * See the LICENSE file for redistribution information.
10 #include <sys/types.h>
11 #include <sys/queue.h>
13 #include <bitstring.h>
21 #include "../common/common.h"
23 static void perr
__P((char *, char *));
27 * Create and partially initialize the GS structure.
28 * PUBLIC: GS * gs_init __P((char*));
37 /* Figure out what our name is. */
38 if ((p
= strrchr(name
, '/')) != NULL
)
41 /* Allocate the global structure. */
42 CALLOC_NOMSG(NULL
, gp
, GS
*, 1, sizeof(GS
));
48 /* Common global structure initialization. */
49 /* others will need to be copied from main.c */
50 CIRCLEQ_INIT(&gp
->dq
);
60 * PUBLIC: WIN * gs_new_win __P((GS *gp));
68 CALLOC_NOMSG(NULL
, wp
, WIN
*, 1, sizeof(*wp
));
72 /* Common global structure initialization. */
74 LIST_INSERT_HEAD(&wp
->ecq
, &wp
->excmd
, q
);
76 CIRCLEQ_INSERT_TAIL(&gp
->dq
, wp
, q
);
77 CIRCLEQ_INIT(&wp
->scrq
);
86 * End the program, discarding screens and most of the global area.
88 * PUBLIC: void gs_end __P((GS *));
98 /* If there are any remaining screens, kill them off. */
99 if (gp
->ccl_sp
!= NULL
) {
100 (void)file_end(gp
->ccl_sp
, NULL
, 1);
101 (void)screen_end(gp
->ccl_sp
);
103 for (wp
= gp
->dq
.cqh_first
; wp
!= (void *)&gp
->dq
;
105 while ((sp
= wp
->scrq
.cqh_first
) != (void *)&wp
->scrq
)
106 (void)screen_end(sp
);
107 while ((sp
= gp
->hq
.cqh_first
) != (void *)&gp
->hq
)
108 (void)screen_end(sp
);
110 #ifdef HAVE_PERL_INTERP
114 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
117 while ((frp
= gp
->frefq
.cqh_first
) != (FREF
*)&gp
->frefq
) {
118 CIRCLEQ_REMOVE(&gp
->frefq
, frp
, q
);
119 if (frp
->name
!= NULL
)
121 if (frp
->tname
!= NULL
)
127 /* Free key input queue. */
128 if (gp
->i_event
!= NULL
)
131 /* Free cut buffers. */
134 /* Free map sequences. */
137 /* Free default buffer storage. */
138 (void)text_lfree(&gp
->dcb_store
.textq
);
140 /* Close message catalogs. */
144 /* Ring the bell if scheduled. */
145 if (F_ISSET(gp
, G_BELLSCHED
))
146 (void)fprintf(stderr
, "\07"); /* \a */
149 * Flush any remaining messages. If a message is here, it's almost
150 * certainly the message about the event that killed us (although
151 * it's possible that the user is sourcing a file that exits from the
154 while ((mp
= gp
->msgq
.lh_first
) != NULL
) {
155 (void)fprintf(stderr
, "%s%.*s",
156 mp
->mtype
== M_ERR
? "ex/vi: " : "", (int)mp
->len
, mp
->buf
);
158 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
164 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
165 /* Free any temporary space. */
166 if (gp
->tmp_bp
!= NULL
)
170 /* Close tracing file descriptor. */
179 * Print system error.
185 (void)fprintf(stderr
, "%s:", name
);
187 (void)fprintf(stderr
, "%s:", msg
);
188 (void)fprintf(stderr
, "%s\n", strerror(errno
));