historic vi remapped characters in the executed @ buffer
[nvi.git] / vi / v_init.c
blobd37ec32f97c3a6e3850800bbb6c28fbac788dc21
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: v_init.c,v 8.16 1993/12/09 19:43:13 bostic Exp $ (Berkeley) $Date: 1993/12/09 19:43:13 $";
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 "vcmd.h"
20 #include "excmd.h"
23 * v_screen_copy --
24 * Copy vi screen.
26 int
27 v_screen_copy(orig, sp)
28 SCR *orig, *sp;
30 VI_PRIVATE *ovip, *nvip;
32 /* Create the private vi structure. */
33 CALLOC_RET(orig, nvip, VI_PRIVATE *, 1, sizeof(VI_PRIVATE));
34 sp->vi_private = nvip;
36 if (orig == NULL) {
37 nvip->inc_lastch = '+';
38 nvip->inc_lastval = 1;
39 } else {
40 ovip = VIP(orig);
42 /* User can replay the last input, but nothing else. */
43 if (ovip->rep_len != 0) {
44 MALLOC(orig, nvip->rep, char *, ovip->rep_len);
45 if (nvip->rep != NULL) {
46 memmove(nvip->rep, ovip->rep, ovip->rep_len);
47 nvip->rep_len = ovip->rep_len;
51 nvip->inc_lastch = ovip->inc_lastch;
52 nvip->inc_lastval = ovip->inc_lastval;
54 if (ovip->paragraph != NULL &&
55 (nvip->paragraph = strdup(ovip->paragraph)) == NULL) {
56 msgq(sp, M_SYSERR, NULL);
57 return (1);
60 return (0);
64 * v_screen_end --
65 * End a vi screen.
67 int
68 v_screen_end(sp)
69 SCR *sp;
71 VI_PRIVATE *vip;
73 vip = VIP(sp);
75 if (vip->rep != NULL)
76 FREE(vip->rep, vip->rep_len);
78 if (vip->paragraph != NULL)
79 FREE(vip->paragraph, vip->paragraph_len);
81 FREE(vip, sizeof(VI_PRIVATE));
82 return (0);
86 * v_init --
87 * Initialize vi.
89 int
90 v_init(sp, ep)
91 SCR *sp;
92 EXF *ep;
94 size_t len;
97 * The default address is line 1, column 0. If the address set
98 * bit is on for this file, load the address, ensuring that it
99 * exists.
101 if (F_ISSET(sp->frp, FR_CURSORSET)) {
102 sp->lno = sp->frp->lno;
103 sp->cno = sp->frp->cno;
105 if (file_gline(sp, ep, sp->lno, &len) == NULL) {
106 if (sp->lno != 1 || sp->cno != 0) {
107 if (file_lline(sp, ep, &sp->lno))
108 return (1);
109 if (sp->lno == 0)
110 sp->lno = 1;
111 sp->cno = 0;
113 } else if (sp->cno >= len)
114 sp->cno = 0;
116 } else {
117 sp->lno = 1;
118 sp->cno = 0;
120 if (O_ISSET(sp, O_COMMENT) && v_comment(sp, ep))
121 return (1);
124 /* Reset strange attraction. */
125 sp->rcm = 0;
126 sp->rcmflags = 0;
128 /* Make ex display to a special function. */
129 if ((sp->stdfp = fwopen(sp, sp->s_ex_write)) == NULL) {
130 msgq(sp, M_SYSERR, "ex output");
131 return (1);
133 #ifdef MAKE_EX_OUTPUT_LINE_BUFFERED
134 (void)setvbuf(sp->stdfp, NULL, _IOLBF, 0);
135 #endif
137 /* Display the status line. */
138 return (status(sp, ep, sp->lno, 0));
142 * v_end --
143 * End vi session.
146 v_end(sp)
147 SCR *sp;
149 /* Close down ex output file descriptor. */
150 (void)fclose(sp->stdfp);
152 return (0);
156 * v_optchange --
157 * Handle change of options for vi.
160 v_optchange(sp, opt)
161 SCR *sp;
162 int opt;
164 switch (opt) {
165 case O_PARAGRAPHS:
166 case O_SECTIONS:
167 return (v_buildparagraph(sp));
169 return (0);