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