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