lint
[nvi.git] / ex / ex_init.c
blob40b07426a608998168fecb26e6008930915ef0be
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_init.c,v 8.9 1993/12/09 19:42:41 bostic Exp $ (Berkeley) $Date: 1993/12/09 19:42:41 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #include "vi.h"
19 #include "excmd.h"
20 #include "tag.h"
23 * ex_screen_copy --
24 * Copy ex screen.
26 int
27 ex_screen_copy(orig, sp)
28 SCR *orig, *sp;
30 EX_PRIVATE *oexp, *nexp;
32 /* Create the private ex structure. */
33 CALLOC_RET(orig, nexp, EX_PRIVATE *, 1, sizeof(EX_PRIVATE));
34 sp->ex_private = nexp;
36 /* Initialize queues. */
37 TAILQ_INIT(&nexp->tagq);
38 TAILQ_INIT(&nexp->tagfq);
40 if (orig == NULL) {
41 nexp->at_lbuf_set = 0;
42 } else {
43 oexp = EXP(orig);
45 nexp->at_lbuf = oexp->at_lbuf;
46 nexp->at_lbuf_set = oexp->at_lbuf_set;
48 if (oexp->lastbcomm != NULL &&
49 (nexp->lastbcomm = strdup(oexp->lastbcomm)) == NULL) {
50 msgq(sp, M_SYSERR, NULL);
51 return(1);
54 if (ex_tagcopy(orig, sp))
55 return (1);
58 nexp->lastcmd = &cmds[C_PRINT];
59 return (0);
63 * ex_screen_end --
64 * End a vi screen.
66 int
67 ex_screen_end(sp)
68 SCR *sp;
70 EX_PRIVATE *exp;
71 int rval;
73 rval = 0;
74 exp = EXP(sp);
76 if (argv_free(sp))
77 rval = 1;
79 if (exp->ibp != NULL)
80 FREE(exp->ibp, exp->ibp_len);
82 if (exp->lastbcomm != NULL)
83 FREE(exp->lastbcomm, strlen(exp->lastbcomm) + 1);
85 FREE(exp, sizeof(EX_PRIVATE));
86 return (rval);
90 * ex_init --
91 * Initialize ex.
93 int
94 ex_init(sp, ep)
95 SCR *sp;
96 EXF *ep;
98 size_t len;
101 * The default address is the last line of the file. If the address
102 * set bit is on for this file, load the address, ensuring that it
103 * exists.
105 if (F_ISSET(sp->frp, FR_CURSORSET)) {
106 sp->lno = sp->frp->lno;
107 sp->cno = sp->frp->cno;
109 if (file_gline(sp, ep, sp->lno, &len) == NULL) {
110 if (file_lline(sp, ep, &sp->lno))
111 return (1);
112 if (sp->lno == 0)
113 sp->lno = 1;
114 sp->cno = 0;
115 } else if (sp->cno >= len)
116 sp->cno = 0;
117 } else {
118 if (file_lline(sp, ep, &sp->lno))
119 return (1);
120 if (sp->lno == 0)
121 sp->lno = 1;
122 sp->cno = 0;
125 /* Display the status line. */
126 return (status(sp, ep, sp->lno, 0));
130 * ex_end --
131 * End ex session.
134 ex_end(sp)
135 SCR *sp;
137 /* Save the cursor location. */
138 sp->frp->lno = sp->lno;
139 sp->frp->cno = sp->cno;
140 F_SET(sp->frp, FR_CURSORSET);
142 return (0);
146 * ex_optchange --
147 * Handle change of options for vi.
150 ex_optchange(sp, opt)
151 SCR *sp;
152 int opt;
154 switch (opt) {
155 case O_TAGS:
156 return (ex_tagalloc(sp, O_STR(sp, O_TAGS)));
158 return (0);