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"
22 #include "../perl_api/extern.h"
24 static void perr
__P((char *, char *));
28 * Create and partially initialize the GS structure.
29 * 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
);
52 CIRCLEQ_INIT(&gp
->hq
);
53 gp
->noprint
= DEFAULT_NOPRINT
;
55 /* Structures shared by screens so stored in the GS structure. */
56 CIRCLEQ_INIT(&gp
->frefq
);
57 CIRCLEQ_INIT(&gp
->exfq
);
68 * PUBLIC: WIN * gs_new_win __P((GS *gp));
76 CALLOC_NOMSG(NULL
, wp
, WIN
*, 1, sizeof(*wp
));
80 /* Common global structure initialization. */
82 LIST_INSERT_HEAD(&wp
->ecq
, &wp
->excmd
, q
);
84 CIRCLEQ_INSERT_TAIL(&gp
->dq
, wp
, q
);
85 CIRCLEQ_INIT(&wp
->scrq
);
87 CIRCLEQ_INIT(&wp
->dcb_store
.textq
);
99 * PUBLIC: int win_end __P((WIN *wp));
106 CIRCLEQ_REMOVE(&wp
->gp
->dq
, wp
, q
);
108 if (wp
->ccl_sp
!= NULL
) {
109 (void)file_end(wp
->ccl_sp
, NULL
, 1);
110 (void)screen_end(wp
->ccl_sp
);
112 while ((sp
= wp
->scrq
.cqh_first
) != (void *)&wp
->scrq
)
113 (void)screen_end(sp
);
115 /* Free key input queue. */
116 if (wp
->i_event
!= NULL
)
119 /* Free cut buffers. */
122 /* Free default buffer storage. */
123 (void)text_lfree(&wp
->dcb_store
.textq
);
125 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
126 /* Free any temporary space. */
127 if (wp
->tmp_bp
!= NULL
)
136 * End the program, discarding screens and most of the global area.
138 * PUBLIC: void gs_end __P((GS *));
147 /* If there are any remaining screens, kill them off. */
148 while ((wp
= gp
->dq
.cqh_first
) != (void *)&gp
->dq
)
150 while ((sp
= gp
->hq
.cqh_first
) != (void *)&gp
->hq
)
151 (void)screen_end(sp
);
153 #ifdef HAVE_PERL_INTERP
157 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
160 while ((frp
= gp
->frefq
.cqh_first
) != (FREF
*)&gp
->frefq
) {
161 CIRCLEQ_REMOVE(&gp
->frefq
, frp
, q
);
162 if (frp
->name
!= NULL
)
164 if (frp
->tname
!= NULL
)
170 /* Free map sequences. */
173 /* Close message catalogs. */
177 /* Ring the bell if scheduled. */
178 if (F_ISSET(gp
, G_BELLSCHED
))
179 (void)fprintf(stderr
, "\07"); /* \a */
182 * Flush any remaining messages. If a message is here, it's almost
183 * certainly the message about the event that killed us (although
184 * it's possible that the user is sourcing a file that exits from the
187 while ((mp
= gp
->msgq
.lh_first
) != NULL
) {
188 (void)fprintf(stderr
, "%s%.*s",
189 mp
->mtype
== M_ERR
? "ex/vi: " : "", (int)mp
->len
, mp
->buf
);
191 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
198 /* Close tracing file descriptor. */
206 * Print system error.
209 perr(char *name
, char *msg
)
211 (void)fprintf(stderr
, "%s:", name
);
213 (void)fprintf(stderr
, "%s:", msg
);
214 (void)fprintf(stderr
, "%s\n", strerror(errno
));