typo
[nvi.git] / vi / v_init.c
blob2e18dce530923f6681727e6d084cef8a2280f3f5
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: v_init.c,v 10.9 2001/06/25 15:19:31 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:31 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <errno.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "../common/common.h"
28 #include "vi.h"
31 * v_screen_copy --
32 * Copy vi screen.
34 * PUBLIC: int v_screen_copy __P((SCR *, SCR *));
36 int
37 v_screen_copy(SCR *orig, SCR *sp)
39 VI_PRIVATE *ovip, *nvip;
41 /* Create the private vi structure. */
42 CALLOC_RET(orig, nvip, VI_PRIVATE *, 1, sizeof(VI_PRIVATE));
43 sp->vi_private = nvip;
45 /* Invalidate the line size cache. */
46 VI_SCR_CFLUSH(nvip);
48 if (orig == NULL) {
49 nvip->csearchdir = CNOTSET;
50 } else {
51 ovip = VIP(orig);
53 /* User can replay the last input, but nothing else. */
54 if (ovip->rep_len != 0) {
55 MALLOC_RET(orig, nvip->rep, EVENT *, ovip->rep_len);
56 memmove(nvip->rep, ovip->rep, ovip->rep_len);
57 nvip->rep_len = ovip->rep_len;
60 /* Copy the paragraph/section information. */
61 if (ovip->ps != NULL && (nvip->ps =
62 v_strdup(sp, ovip->ps, strlen(ovip->ps))) == NULL)
63 return (1);
65 nvip->lastckey = ovip->lastckey;
66 nvip->csearchdir = ovip->csearchdir;
68 nvip->srows = ovip->srows;
70 return (0);
74 * v_screen_end --
75 * End a vi screen.
77 * PUBLIC: int v_screen_end __P((SCR *));
79 int
80 v_screen_end(SCR *sp)
82 VI_PRIVATE *vip;
84 if ((vip = VIP(sp)) == NULL)
85 return (0);
86 if (vip->keyw != NULL)
87 free(vip->keyw);
88 if (vip->rep != NULL)
89 free(vip->rep);
90 if (vip->ps != NULL)
91 free(vip->ps);
93 if (HMAP != NULL)
94 free(HMAP);
96 free(vip);
97 sp->vi_private = NULL;
99 return (0);
103 * v_optchange --
104 * Handle change of options for vi.
106 * PUBLIC: int v_optchange __P((SCR *, int, char *, u_long *));
109 v_optchange(SCR *sp, int offset, char *str, u_long *valp)
111 switch (offset) {
112 case O_PARAGRAPHS:
113 return (v_buildps(sp, str, O_STR(sp, O_SECTIONS)));
114 case O_SECTIONS:
115 return (v_buildps(sp, O_STR(sp, O_PARAGRAPHS), str));
116 case O_WINDOW:
117 return (vs_crel(sp, *valp));
119 return (0);