if no messages waiting, always display the file status line on
[nvi.git] / vi / v_init.c
blob73e6ceb2fa9284bd9a4635eab6e9e1ac4f5024e2
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.15 1993/11/13 18:01:36 bostic Exp $ (Berkeley) $Date: 1993/11/13 18:01:36 $";
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 if ((sp->vi_private = nvip = malloc(sizeof(VI_PRIVATE))) == NULL)
34 goto mem;
35 memset(nvip, 0, sizeof(VI_PRIVATE));
37 if (orig == NULL) {
38 nvip->inc_lastch = '+';
39 nvip->inc_lastval = 1;
40 } else {
41 ovip = VIP(orig);
43 /* User can replay the last input, but nothing else. */
44 if (ovip->rep_len != 0)
45 if ((nvip->rep = malloc(ovip->rep_len)) == NULL)
46 goto mem;
47 else {
48 memmove(nvip->rep, ovip->rep, ovip->rep_len);
49 nvip->rep_len = ovip->rep_len;
52 nvip->inc_lastch = ovip->inc_lastch;
53 nvip->inc_lastval = ovip->inc_lastval;
55 if (ovip->paragraph != NULL &&
56 (nvip->paragraph = strdup(ovip->paragraph)) == NULL) {
57 mem: msgq(sp, M_SYSERR, NULL);
58 return (1);
61 return (0);
65 * v_screen_end --
66 * End a vi screen.
68 int
69 v_screen_end(sp)
70 SCR *sp;
72 VI_PRIVATE *vip;
74 vip = VIP(sp);
76 if (vip->rep != NULL)
77 FREE(vip->rep, vip->rep_len);
79 if (vip->paragraph != NULL)
80 FREE(vip->paragraph, vip->paragraph_len);
82 FREE(vip, sizeof(VI_PRIVATE));
83 return (0);
87 * v_init --
88 * Initialize vi.
90 int
91 v_init(sp, ep)
92 SCR *sp;
93 EXF *ep;
95 size_t len;
98 * The default address is line 1, column 0. If the address set
99 * bit is on for this file, load the address, ensuring that it
100 * exists.
102 if (F_ISSET(sp->frp, FR_CURSORSET)) {
103 sp->lno = sp->frp->lno;
104 sp->cno = sp->frp->cno;
106 if (file_gline(sp, ep, sp->lno, &len) == NULL) {
107 if (sp->lno != 1 || sp->cno != 0) {
108 if (file_lline(sp, ep, &sp->lno))
109 return (1);
110 if (sp->lno == 0)
111 sp->lno = 1;
112 sp->cno = 0;
114 } else if (sp->cno >= len)
115 sp->cno = 0;
117 } else {
118 sp->lno = 1;
119 sp->cno = 0;
121 if (O_ISSET(sp, O_COMMENT) && v_comment(sp, ep))
122 return (1);
125 /* Reset strange attraction. */
126 sp->rcm = 0;
127 sp->rcmflags = 0;
129 /* Make ex display to a special function. */
130 if ((sp->stdfp = fwopen(sp, sp->s_ex_write)) == NULL) {
131 msgq(sp, M_SYSERR, "ex output");
132 return (1);
134 #ifdef MAKE_EX_OUTPUT_LINE_BUFFERED
135 (void)setvbuf(sp->stdfp, NULL, _IOLBF, 0);
136 #endif
138 /* Display the status line. */
139 return (status(sp, ep, sp->lno, 0));
143 * v_end --
144 * End vi session.
147 v_end(sp)
148 SCR *sp;
150 /* Close down ex output file descriptor. */
151 (void)fclose(sp->stdfp);
153 return (0);
157 * v_optchange --
158 * Handle change of options for vi.
161 v_optchange(sp, opt)
162 SCR *sp;
163 int opt;
165 switch (opt) {
166 case O_PARAGRAPHS:
167 case O_SECTIONS:
168 return (v_buildparagraph(sp));
170 return (0);