home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / EDITOR / NVI179B / NVI179B.ZIP / ex / ex_visual.c < prev    next >
C/C++ Source or Header  |  1996-06-28  |  4KB  |  162 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[] = "@(#)ex_visual.c    10.13 (Berkeley) 6/28/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 <limits.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <unistd.h>
  26.  
  27. #include "../common/common.h"
  28. #include "../vi/vi.h"
  29.  
  30. /*
  31.  * ex_visual -- :[line] vi[sual] [^-.+] [window_size] [flags]
  32.  *    Switch to visual mode.
  33.  *
  34.  * PUBLIC: int ex_visual __P((SCR *, EXCMD *));
  35.  */
  36. int
  37. ex_visual(sp, cmdp)
  38.     SCR *sp;
  39.     EXCMD *cmdp;
  40. {
  41.     SCR *tsp;
  42.     size_t len;
  43.     int pos;
  44.     char buf[256];
  45.  
  46.     /* If open option off, disallow visual command. */
  47.     if (!O_ISSET(sp, O_OPEN)) {
  48.         msgq(sp, M_ERR,
  49.         "175|The visual command requires that the open option be set");
  50.         return (1);
  51.     }
  52.  
  53.     /* Move to the address. */
  54.     sp->lno = cmdp->addr1.lno == 0 ? 1 : cmdp->addr1.lno;
  55.  
  56.     /*
  57.      * Push a command based on the line position flags.  If no
  58.      * flag specified, the line goes at the top of the screen.
  59.      */
  60.     switch (FL_ISSET(cmdp->iflags,
  61.         E_C_CARAT | E_C_DASH | E_C_DOT | E_C_PLUS)) {
  62.     case E_C_CARAT:
  63.         pos = '^';
  64.         break;
  65.     case E_C_DASH:
  66.         pos = '-';
  67.         break;
  68.     case E_C_DOT:
  69.         pos = '.';
  70.         break;
  71.     case E_C_PLUS:
  72.         pos = '+';
  73.         break;
  74.     default:
  75.         sp->frp->lno = sp->lno;
  76.         sp->frp->cno = 0;
  77.         (void)nonblank(sp, sp->lno, &sp->cno);
  78.         F_SET(sp->frp, FR_CURSORSET);
  79.         goto nopush;
  80.     }
  81.  
  82.     if (FL_ISSET(cmdp->iflags, E_C_COUNT))
  83.         len = snprintf(buf, sizeof(buf),
  84.              "%luz%c%lu", sp->lno, pos, cmdp->count);
  85.     else
  86.         len = snprintf(buf, sizeof(buf), "%luz%c", sp->lno, pos);
  87.     (void)v_event_push(sp, NULL, buf, len, CH_NOMAP | CH_QUOTED);
  88.  
  89.     /*
  90.      * !!!
  91.      * Historically, if no line address was specified, the [p#l] flags
  92.      * caused the cursor to be moved to the last line of the file, which
  93.      * was then positioned as described above.  This seems useless, so
  94.      * I haven't implemented it.
  95.      */
  96.     switch (FL_ISSET(cmdp->iflags, E_C_HASH | E_C_LIST | E_C_PRINT)) {
  97.     case E_C_HASH:
  98.         O_SET(sp, O_NUMBER);
  99.         break;
  100.     case E_C_LIST:
  101.         O_SET(sp, O_LIST);
  102.         break;
  103.     case E_C_PRINT:
  104.         break;
  105.     }
  106.  
  107. nopush:    /*
  108.      * !!!
  109.      * You can call the visual part of the editor from within an ex
  110.      * global command.
  111.      *
  112.      * XXX
  113.      * Historically, undoing a visual session was a single undo command,
  114.      * i.e. you could undo all of the changes you made in visual mode.
  115.      * We don't get this right; I'm waiting for the new logging code to
  116.      * be available.
  117.      *
  118.      * It's explicit, don't have to wait for the user, unless there's
  119.      * already a reason to wait.
  120.      */
  121.     if (!F_ISSET(sp, SC_SCR_EXWROTE))
  122.         F_SET(sp, SC_EX_WAIT_NO);
  123.  
  124.     if (F_ISSET(sp, SC_EX_GLOBAL)) {
  125.         /*
  126.          * When the vi screen(s) exit, we don't want to lose our hold
  127.          * on this screen or this file, otherwise we're going to fail
  128.          * fairly spectacularly.
  129.          */
  130.         ++sp->refcnt;
  131.         ++sp->ep->refcnt;
  132.  
  133.         /*
  134.          * Fake up a screen pointer -- vi doesn't get to change our
  135.          * underlying file, regardless.
  136.          */
  137.         tsp = sp;
  138.         if (vi(&tsp))
  139.             return (1);
  140.  
  141.         /*
  142.          * !!!
  143.          * Historically, if the user exited the vi screen(s) using an
  144.          * ex quit command (e.g. :wq, :q) ex/vi exited, it was only if
  145.          * they exited vi using the Q command that ex continued.  Some
  146.          * early versions of nvi continued in ex regardless, but users
  147.          * didn't like the semantic.
  148.          *
  149.          * Reset the screen.
  150.          */
  151.         if (ex_init(sp))
  152.             return (1);
  153.  
  154.         /* Move out of the vi screen. */
  155.         (void)ex_puts(sp, "\n");
  156.     } else {
  157.         F_CLR(sp, SC_EX | SC_SCR_EX);
  158.         F_SET(sp, SC_VI);
  159.     }
  160.     return (0);
  161. }
  162.