Bring in an errno.9 manual page (based on NetBSD's).
[dragonfly.git] / contrib / nvi2 / vi / v_init.c
bloba9966323f4a0465b569fad5784ee7ac4f8bbd3b7
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.10 2012/02/11 00:33:46 zy Exp $";
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(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 match characters information. */
61 if (ovip->mcs != NULL && (nvip->mcs =
62 v_wstrdup(sp, ovip->mcs, STRLEN(ovip->mcs))) == NULL)
63 return (1);
65 /* Copy the paragraph/section information. */
66 if (ovip->ps != NULL && (nvip->ps =
67 v_strdup(sp, ovip->ps, strlen(ovip->ps))) == NULL)
68 return (1);
70 nvip->lastckey = ovip->lastckey;
71 nvip->csearchdir = ovip->csearchdir;
73 nvip->srows = ovip->srows;
75 return (0);
79 * v_screen_end --
80 * End a vi screen.
82 * PUBLIC: int v_screen_end(SCR *);
84 int
85 v_screen_end(SCR *sp)
87 VI_PRIVATE *vip;
89 if ((vip = VIP(sp)) == NULL)
90 return (0);
91 if (vip->keyw != NULL)
92 free(vip->keyw);
93 if (vip->rep != NULL)
94 free(vip->rep);
95 if (vip->mcs != NULL)
96 free(vip->mcs);
97 if (vip->ps != NULL)
98 free(vip->ps);
100 if (HMAP != NULL)
101 free(HMAP);
103 free(vip);
104 sp->vi_private = NULL;
106 return (0);
110 * v_optchange --
111 * Handle change of options for vi.
113 * PUBLIC: int v_optchange(SCR *, int, char *, u_long *);
116 v_optchange(SCR *sp, int offset, char *str, u_long *valp)
118 switch (offset) {
119 case O_MATCHCHARS:
120 return (v_buildmcs(sp, str));
121 case O_PARAGRAPHS:
122 return (v_buildps(sp, str, O_STR(sp, O_SECTIONS)));
123 case O_SECTIONS:
124 return (v_buildps(sp, O_STR(sp, O_PARAGRAPHS), str));
125 case O_WINDOW:
126 return (vs_crel(sp, *valp));
128 return (0);