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