align CHAR_T string in log
[nvi.git] / vi / v_init.c
blob9029440c94a6c479cdfd420d3e638ffd631c73b7
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.8 1996/03/30 13:47:10 bostic Exp $ (Berkeley) $Date: 1996/03/30 13:47:10 $";
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(orig, sp)
38 SCR *orig, *sp;
40 VI_PRIVATE *ovip, *nvip;
42 /* Create the private vi structure. */
43 CALLOC_RET(orig, nvip, VI_PRIVATE *, 1, sizeof(VI_PRIVATE));
44 sp->vi_private = nvip;
46 /* Invalidate the line size cache. */
47 VI_SCR_CFLUSH(nvip);
49 if (orig == NULL) {
50 nvip->csearchdir = CNOTSET;
51 } else {
52 ovip = VIP(orig);
54 /* User can replay the last input, but nothing else. */
55 if (ovip->rep_len != 0) {
56 MALLOC_RET(orig, nvip->rep, EVENT *, ovip->rep_len);
57 memmove(nvip->rep, ovip->rep, ovip->rep_len);
58 nvip->rep_len = ovip->rep_len;
61 /* Copy the paragraph/section information. */
62 if (ovip->ps != NULL && (nvip->ps =
63 v_strdup(sp, ovip->ps, strlen(ovip->ps))) == NULL)
64 return (1);
66 nvip->lastckey = ovip->lastckey;
67 nvip->csearchdir = ovip->csearchdir;
69 nvip->srows = ovip->srows;
71 return (0);
75 * v_screen_end --
76 * End a vi screen.
78 * PUBLIC: int v_screen_end __P((SCR *));
80 int
81 v_screen_end(sp)
82 SCR *sp;
84 VI_PRIVATE *vip;
86 if ((vip = VIP(sp)) == NULL)
87 return (0);
88 if (vip->keyw != NULL)
89 free(vip->keyw);
90 if (vip->rep != NULL)
91 free(vip->rep);
92 if (vip->ps != NULL)
93 free(vip->ps);
95 if (HMAP != NULL)
96 free(HMAP);
98 free(vip);
99 sp->vi_private = NULL;
101 return (0);
105 * v_optchange --
106 * Handle change of options for vi.
108 * PUBLIC: int v_optchange __P((SCR *, int, char *, u_long *));
111 v_optchange(sp, offset, str, valp)
112 SCR *sp;
113 int offset;
114 char *str;
115 u_long *valp;
117 switch (offset) {
118 case O_PARAGRAPHS:
119 return (v_buildps(sp, str, O_STR(sp, O_SECTIONS)));
120 case O_SECTIONS:
121 return (v_buildps(sp, O_STR(sp, O_PARAGRAPHS), str));
122 case O_WINDOW:
123 return (vs_crel(sp, *valp));
125 return (0);