1*0a6a1f1dSLionel Sambuc /* $NetBSD: v_init.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc * Copyright (c) 1992, 1993, 1994
484d9c625SLionel Sambuc * The Regents of the University of California. All rights reserved.
584d9c625SLionel Sambuc * Copyright (c) 1992, 1993, 1994, 1995, 1996
684d9c625SLionel Sambuc * Keith Bostic. All rights reserved.
784d9c625SLionel Sambuc *
884d9c625SLionel Sambuc * See the LICENSE file for redistribution information.
984d9c625SLionel Sambuc */
1084d9c625SLionel Sambuc
1184d9c625SLionel Sambuc #include "config.h"
1284d9c625SLionel Sambuc
13*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
14*0a6a1f1dSLionel Sambuc #if 0
1584d9c625SLionel Sambuc #ifndef lint
1684d9c625SLionel Sambuc 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 ";
1784d9c625SLionel Sambuc #endif /* not lint */
18*0a6a1f1dSLionel Sambuc #else
19*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: v_init.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc
2284d9c625SLionel Sambuc #include <sys/types.h>
2384d9c625SLionel Sambuc #include <sys/queue.h>
2484d9c625SLionel Sambuc #include <sys/time.h>
2584d9c625SLionel Sambuc
2684d9c625SLionel Sambuc #include <bitstring.h>
2784d9c625SLionel Sambuc #include <errno.h>
2884d9c625SLionel Sambuc #include <limits.h>
2984d9c625SLionel Sambuc #include <stdio.h>
3084d9c625SLionel Sambuc #include <stdlib.h>
3184d9c625SLionel Sambuc #include <string.h>
3284d9c625SLionel Sambuc
3384d9c625SLionel Sambuc #include "../common/common.h"
3484d9c625SLionel Sambuc #include "vi.h"
3584d9c625SLionel Sambuc
3684d9c625SLionel Sambuc /*
3784d9c625SLionel Sambuc * v_screen_copy --
3884d9c625SLionel Sambuc * Copy vi screen.
3984d9c625SLionel Sambuc *
4084d9c625SLionel Sambuc * PUBLIC: int v_screen_copy __P((SCR *, SCR *));
4184d9c625SLionel Sambuc */
4284d9c625SLionel Sambuc int
v_screen_copy(SCR * orig,SCR * sp)4384d9c625SLionel Sambuc v_screen_copy(SCR *orig, SCR *sp)
4484d9c625SLionel Sambuc {
4584d9c625SLionel Sambuc VI_PRIVATE *ovip, *nvip;
4684d9c625SLionel Sambuc
4784d9c625SLionel Sambuc /* Create the private vi structure. */
4884d9c625SLionel Sambuc CALLOC_RET(orig, nvip, VI_PRIVATE *, 1, sizeof(VI_PRIVATE));
4984d9c625SLionel Sambuc sp->vi_private = nvip;
5084d9c625SLionel Sambuc
5184d9c625SLionel Sambuc /* Invalidate the line size cache. */
5284d9c625SLionel Sambuc VI_SCR_CFLUSH(nvip);
5384d9c625SLionel Sambuc
5484d9c625SLionel Sambuc if (orig == NULL) {
5584d9c625SLionel Sambuc nvip->csearchdir = CNOTSET;
5684d9c625SLionel Sambuc } else {
5784d9c625SLionel Sambuc ovip = VIP(orig);
5884d9c625SLionel Sambuc
5984d9c625SLionel Sambuc /* User can replay the last input, but nothing else. */
6084d9c625SLionel Sambuc if (ovip->rep_len != 0) {
6184d9c625SLionel Sambuc MALLOC_RET(orig, nvip->rep, EVENT *, ovip->rep_len);
6284d9c625SLionel Sambuc memmove(nvip->rep, ovip->rep, ovip->rep_len);
6384d9c625SLionel Sambuc nvip->rep_len = ovip->rep_len;
6484d9c625SLionel Sambuc }
6584d9c625SLionel Sambuc
6684d9c625SLionel Sambuc /* Copy the paragraph/section information. */
6784d9c625SLionel Sambuc if (ovip->ps != NULL && (nvip->ps =
6884d9c625SLionel Sambuc v_strdup(sp, ovip->ps, strlen(ovip->ps))) == NULL)
6984d9c625SLionel Sambuc return (1);
7084d9c625SLionel Sambuc
7184d9c625SLionel Sambuc nvip->lastckey = ovip->lastckey;
7284d9c625SLionel Sambuc nvip->csearchdir = ovip->csearchdir;
7384d9c625SLionel Sambuc
7484d9c625SLionel Sambuc nvip->srows = ovip->srows;
7584d9c625SLionel Sambuc }
7684d9c625SLionel Sambuc return (0);
7784d9c625SLionel Sambuc }
7884d9c625SLionel Sambuc
7984d9c625SLionel Sambuc /*
8084d9c625SLionel Sambuc * v_screen_end --
8184d9c625SLionel Sambuc * End a vi screen.
8284d9c625SLionel Sambuc *
8384d9c625SLionel Sambuc * PUBLIC: int v_screen_end __P((SCR *));
8484d9c625SLionel Sambuc */
8584d9c625SLionel Sambuc int
v_screen_end(SCR * sp)8684d9c625SLionel Sambuc v_screen_end(SCR *sp)
8784d9c625SLionel Sambuc {
8884d9c625SLionel Sambuc VI_PRIVATE *vip;
8984d9c625SLionel Sambuc
9084d9c625SLionel Sambuc if ((vip = VIP(sp)) == NULL)
9184d9c625SLionel Sambuc return (0);
9284d9c625SLionel Sambuc if (vip->keyw != NULL)
9384d9c625SLionel Sambuc free(vip->keyw);
9484d9c625SLionel Sambuc if (vip->rep != NULL)
9584d9c625SLionel Sambuc free(vip->rep);
9684d9c625SLionel Sambuc if (vip->ps != NULL)
9784d9c625SLionel Sambuc free(vip->ps);
9884d9c625SLionel Sambuc
9984d9c625SLionel Sambuc if (HMAP != NULL)
10084d9c625SLionel Sambuc free(HMAP);
10184d9c625SLionel Sambuc
10284d9c625SLionel Sambuc free(vip);
10384d9c625SLionel Sambuc sp->vi_private = NULL;
10484d9c625SLionel Sambuc
10584d9c625SLionel Sambuc return (0);
10684d9c625SLionel Sambuc }
10784d9c625SLionel Sambuc
10884d9c625SLionel Sambuc /*
10984d9c625SLionel Sambuc * v_optchange --
11084d9c625SLionel Sambuc * Handle change of options for vi.
11184d9c625SLionel Sambuc *
11284d9c625SLionel Sambuc * PUBLIC: int v_optchange __P((SCR *, int, const char *, u_long *));
11384d9c625SLionel Sambuc */
11484d9c625SLionel Sambuc int
v_optchange(SCR * sp,int offset,const char * str,u_long * valp)11584d9c625SLionel Sambuc v_optchange(SCR *sp, int offset, const char *str, u_long *valp)
11684d9c625SLionel Sambuc {
11784d9c625SLionel Sambuc switch (offset) {
11884d9c625SLionel Sambuc case O_PARAGRAPHS:
11984d9c625SLionel Sambuc return (v_buildps(sp, str, O_STR(sp, O_SECTIONS)));
12084d9c625SLionel Sambuc case O_SECTIONS:
12184d9c625SLionel Sambuc return (v_buildps(sp, O_STR(sp, O_PARAGRAPHS), str));
12284d9c625SLionel Sambuc case O_WINDOW:
12384d9c625SLionel Sambuc return (vs_crel(sp, *valp));
12484d9c625SLionel Sambuc }
12584d9c625SLionel Sambuc return (0);
12684d9c625SLionel Sambuc }
127