home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / EDITOR / NVI179B / NVI179B.ZIP / vi / v_init.c < prev    next >
C/C++ Source or Header  |  1996-05-16  |  2KB  |  127 lines

  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. #ifndef lint
  13. static const char sccsid[] = "@(#)v_init.c    10.8 (Berkeley) 3/30/96";
  14. #endif /* not lint */
  15.  
  16. #include <sys/types.h>
  17. #include <sys/queue.h>
  18. #include <sys/time.h>
  19.  
  20. #include <bitstring.h>
  21. #include <errno.h>
  22. #include <limits.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26.  
  27. #include "../common/common.h"
  28. #include "vi.h"
  29.  
  30. /*
  31.  * v_screen_copy --
  32.  *    Copy vi screen.
  33.  *
  34.  * PUBLIC: int v_screen_copy __P((SCR *, SCR *));
  35.  */
  36. int
  37. v_screen_copy(orig, sp)
  38.     SCR *orig, *sp;
  39. {
  40.     VI_PRIVATE *ovip, *nvip;
  41.  
  42.     /* Create the private vi structure. */
  43.     CALLOC_RET(orig, nvip, VI_PRIVATE *, 1, sizeof(VI_PRIVATE));
  44.     sp->vi_private = nvip;
  45.  
  46.     /* Invalidate the line size cache. */
  47.     VI_SCR_CFLUSH(nvip);
  48.  
  49.     if (orig == NULL) {
  50.         nvip->csearchdir = CNOTSET;
  51.     } else {
  52.         ovip = VIP(orig);
  53.  
  54.         /* User can replay the last input, but nothing else. */
  55.         if (ovip->rep_len != 0) {
  56.             MALLOC_RET(orig, nvip->rep, EVENT *, ovip->rep_len);
  57.             memmove(nvip->rep, ovip->rep, ovip->rep_len);
  58.             nvip->rep_len = ovip->rep_len;
  59.         }
  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 __P((SCR *));
  79.  */
  80. int
  81. v_screen_end(sp)
  82.     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, char *, u_long *));
  109.  */
  110. int
  111. v_optchange(sp, offset, str, valp)
  112.     SCR *sp;
  113.     int offset;
  114.     char *str;
  115.     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.