1e0b8e63eSJohn Marino /*-
2e0b8e63eSJohn Marino * Copyright (c) 1992, 1993, 1994
3e0b8e63eSJohn Marino * The Regents of the University of California. All rights reserved.
4e0b8e63eSJohn Marino * Copyright (c) 1992, 1993, 1994, 1995, 1996
5e0b8e63eSJohn Marino * Keith Bostic. All rights reserved.
6e0b8e63eSJohn Marino *
7e0b8e63eSJohn Marino * See the LICENSE file for redistribution information.
8e0b8e63eSJohn Marino */
9e0b8e63eSJohn Marino
10e0b8e63eSJohn Marino #include "config.h"
11e0b8e63eSJohn Marino
12e0b8e63eSJohn Marino #include <sys/types.h>
13e0b8e63eSJohn Marino #include <sys/queue.h>
14e0b8e63eSJohn Marino #include <sys/time.h>
15e0b8e63eSJohn Marino
16e0b8e63eSJohn Marino #include <bitstring.h>
17e0b8e63eSJohn Marino #include <errno.h>
18e0b8e63eSJohn Marino #include <limits.h>
19e0b8e63eSJohn Marino #include <stdio.h>
20e0b8e63eSJohn Marino #include <stdlib.h>
21e0b8e63eSJohn Marino #include <string.h>
22e0b8e63eSJohn Marino
23e0b8e63eSJohn Marino #include "../common/common.h"
24e0b8e63eSJohn Marino #include "vi.h"
25e0b8e63eSJohn Marino
26e0b8e63eSJohn Marino /*
27e0b8e63eSJohn Marino * v_screen_copy --
28e0b8e63eSJohn Marino * Copy vi screen.
29e0b8e63eSJohn Marino *
30e0b8e63eSJohn Marino * PUBLIC: int v_screen_copy(SCR *, SCR *);
31e0b8e63eSJohn Marino */
32e0b8e63eSJohn Marino int
v_screen_copy(SCR * orig,SCR * sp)33e0b8e63eSJohn Marino v_screen_copy(SCR *orig, SCR *sp)
34e0b8e63eSJohn Marino {
35e0b8e63eSJohn Marino VI_PRIVATE *ovip, *nvip;
36e0b8e63eSJohn Marino
37e0b8e63eSJohn Marino /* Create the private vi structure. */
38*b1ac2ebbSDaniel Fojt CALLOC_RET(orig, nvip, 1, sizeof(VI_PRIVATE));
39e0b8e63eSJohn Marino sp->vi_private = nvip;
40e0b8e63eSJohn Marino
41e0b8e63eSJohn Marino /* Invalidate the line size cache. */
42e0b8e63eSJohn Marino VI_SCR_CFLUSH(nvip);
43e0b8e63eSJohn Marino
44e0b8e63eSJohn Marino if (orig == NULL) {
45e0b8e63eSJohn Marino nvip->csearchdir = CNOTSET;
46e0b8e63eSJohn Marino } else {
47e0b8e63eSJohn Marino ovip = VIP(orig);
48e0b8e63eSJohn Marino
49e0b8e63eSJohn Marino /* User can replay the last input, but nothing else. */
50e0b8e63eSJohn Marino if (ovip->rep_len != 0) {
51*b1ac2ebbSDaniel Fojt MALLOC_RET(orig, nvip->rep, ovip->rep_len);
52e0b8e63eSJohn Marino memmove(nvip->rep, ovip->rep, ovip->rep_len);
53e0b8e63eSJohn Marino nvip->rep_len = ovip->rep_len;
54e0b8e63eSJohn Marino }
55e0b8e63eSJohn Marino
56e0b8e63eSJohn Marino /* Copy the match characters information. */
57e0b8e63eSJohn Marino if (ovip->mcs != NULL && (nvip->mcs =
58e0b8e63eSJohn Marino v_wstrdup(sp, ovip->mcs, STRLEN(ovip->mcs))) == NULL)
59e0b8e63eSJohn Marino return (1);
60e0b8e63eSJohn Marino
61e0b8e63eSJohn Marino /* Copy the paragraph/section information. */
62e0b8e63eSJohn Marino if (ovip->ps != NULL && (nvip->ps =
63e0b8e63eSJohn Marino v_strdup(sp, ovip->ps, strlen(ovip->ps))) == NULL)
64e0b8e63eSJohn Marino return (1);
65e0b8e63eSJohn Marino
66e0b8e63eSJohn Marino nvip->lastckey = ovip->lastckey;
67e0b8e63eSJohn Marino nvip->csearchdir = ovip->csearchdir;
68e0b8e63eSJohn Marino
69e0b8e63eSJohn Marino nvip->srows = ovip->srows;
70e0b8e63eSJohn Marino }
71e0b8e63eSJohn Marino return (0);
72e0b8e63eSJohn Marino }
73e0b8e63eSJohn Marino
74e0b8e63eSJohn Marino /*
75e0b8e63eSJohn Marino * v_screen_end --
76e0b8e63eSJohn Marino * End a vi screen.
77e0b8e63eSJohn Marino *
78e0b8e63eSJohn Marino * PUBLIC: int v_screen_end(SCR *);
79e0b8e63eSJohn Marino */
80e0b8e63eSJohn Marino int
v_screen_end(SCR * sp)81e0b8e63eSJohn Marino v_screen_end(SCR *sp)
82e0b8e63eSJohn Marino {
83e0b8e63eSJohn Marino VI_PRIVATE *vip;
84e0b8e63eSJohn Marino
85e0b8e63eSJohn Marino if ((vip = VIP(sp)) == NULL)
86e0b8e63eSJohn Marino return (0);
87e0b8e63eSJohn Marino free(vip->keyw);
88e0b8e63eSJohn Marino free(vip->rep);
89e0b8e63eSJohn Marino free(vip->mcs);
90e0b8e63eSJohn Marino free(vip->ps);
91e0b8e63eSJohn Marino
92e0b8e63eSJohn Marino free(HMAP);
93e0b8e63eSJohn Marino
94e0b8e63eSJohn Marino free(vip);
95e0b8e63eSJohn Marino sp->vi_private = NULL;
96e0b8e63eSJohn Marino
97e0b8e63eSJohn Marino return (0);
98e0b8e63eSJohn Marino }
99e0b8e63eSJohn Marino
100e0b8e63eSJohn Marino /*
101e0b8e63eSJohn Marino * v_optchange --
102e0b8e63eSJohn Marino * Handle change of options for vi.
103e0b8e63eSJohn Marino *
104e0b8e63eSJohn Marino * PUBLIC: int v_optchange(SCR *, int, char *, u_long *);
105e0b8e63eSJohn Marino */
106e0b8e63eSJohn Marino int
v_optchange(SCR * sp,int offset,char * str,u_long * valp)107e0b8e63eSJohn Marino v_optchange(SCR *sp, int offset, char *str, u_long *valp)
108e0b8e63eSJohn Marino {
109e0b8e63eSJohn Marino switch (offset) {
110e0b8e63eSJohn Marino case O_MATCHCHARS:
111e0b8e63eSJohn Marino return (v_buildmcs(sp, str));
112e0b8e63eSJohn Marino case O_PARAGRAPHS:
113e0b8e63eSJohn Marino return (v_buildps(sp, str, O_STR(sp, O_SECTIONS)));
114e0b8e63eSJohn Marino case O_SECTIONS:
115e0b8e63eSJohn Marino return (v_buildps(sp, O_STR(sp, O_PARAGRAPHS), str));
116e0b8e63eSJohn Marino case O_WINDOW:
117e0b8e63eSJohn Marino return (vs_crel(sp, *valp));
118e0b8e63eSJohn Marino }
119e0b8e63eSJohn Marino return (0);
120e0b8e63eSJohn Marino }
121