all callers passed in O_SHELL value, change ex_exec_proc to just use it
[nvi.git] / ex / ex_init.c
blob68ae570c4dfe06e2e86f7ade70a58fdf3b66b0a7
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.8 1993/11/18 08:17:43 bostic Exp $ (Berkeley) $Date: 1993/11/18 08:17:43 $";
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 if ((sp->ex_private = nexp = malloc(sizeof(EX_PRIVATE))) == NULL)
34 goto mem;
35 memset(nexp, 0, sizeof(EX_PRIVATE));
37 /* Initialize queues. */
38 TAILQ_INIT(&nexp->tagq);
39 TAILQ_INIT(&nexp->tagfq);
41 if (orig == NULL) {
42 nexp->at_lbuf_set = 0;
43 } else {
44 oexp = EXP(orig);
46 nexp->at_lbuf = oexp->at_lbuf;
47 nexp->at_lbuf_set = oexp->at_lbuf_set;
49 if (oexp->lastbcomm != NULL &&
50 (nexp->lastbcomm = strdup(oexp->lastbcomm)) == NULL) {
51 mem: msgq(sp, M_SYSERR, NULL);
52 return(1);
55 if (ex_tagcopy(orig, sp))
56 return (1);
59 nexp->lastcmd = &cmds[C_PRINT];
60 return (0);
64 * ex_screen_end --
65 * End a vi screen.
67 int
68 ex_screen_end(sp)
69 SCR *sp;
71 EX_PRIVATE *exp;
72 int rval;
74 rval = 0;
75 exp = EXP(sp);
77 if (argv_free(sp))
78 rval = 1;
80 if (exp->ibp != NULL)
81 FREE(exp->ibp, exp->ibp_len);
83 if (exp->lastbcomm != NULL)
84 FREE(exp->lastbcomm, strlen(exp->lastbcomm) + 1);
86 FREE(exp, sizeof(EX_PRIVATE));
87 return (rval);
91 * ex_init --
92 * Initialize ex.
94 int
95 ex_init(sp, ep)
96 SCR *sp;
97 EXF *ep;
99 size_t len;
102 * The default address is the last line of the file. If the address
103 * set bit is on for this file, load the address, ensuring that it
104 * exists.
106 if (F_ISSET(sp->frp, FR_CURSORSET)) {
107 sp->lno = sp->frp->lno;
108 sp->cno = sp->frp->cno;
110 if (file_gline(sp, ep, sp->lno, &len) == NULL) {
111 if (file_lline(sp, ep, &sp->lno))
112 return (1);
113 if (sp->lno == 0)
114 sp->lno = 1;
115 sp->cno = 0;
116 } else if (sp->cno >= len)
117 sp->cno = 0;
118 } else {
119 if (file_lline(sp, ep, &sp->lno))
120 return (1);
121 if (sp->lno == 0)
122 sp->lno = 1;
123 sp->cno = 0;
126 /* Display the status line. */
127 return (status(sp, ep, sp->lno, 0));
131 * ex_end --
132 * End ex session.
135 ex_end(sp)
136 SCR *sp;
138 /* Save the cursor location. */
139 sp->frp->lno = sp->lno;
140 sp->frp->cno = sp->cno;
141 F_SET(sp->frp, FR_CURSORSET);
143 return (0);
147 * ex_optchange --
148 * Handle change of options for vi.
151 ex_optchange(sp, opt)
152 SCR *sp;
153 int opt;
155 switch (opt) {
156 case O_TAGS:
157 return (ex_tagalloc(sp, O_STR(sp, O_TAGS)));
159 return (0);