rework initial error handling -- since we check for any screens on
[nvi.git] / ex / ex_visual.c
blobc406ac118c50954762e09f53146f8abf30ba9382
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_visual.c,v 8.7 1993/11/29 20:01:54 bostic Exp $ (Berkeley) $Date: 1993/11/29 20:01:54 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <stdlib.h>
15 #include <string.h>
17 #include "vi.h"
18 #include "excmd.h"
21 * ex_visual -- :[line] vi[sual] [^-.+] [window_size] [flags]
23 * Switch to visual mode.
25 int
26 ex_visual(sp, ep, cmdp)
27 SCR *sp;
28 EXF *ep;
29 EXCMDARG *cmdp;
31 size_t len;
32 int pos;
33 char buf[256];
35 /* If open option off, disallow visual command. */
36 if (!O_ISSET(sp, O_OPEN)) {
37 msgq(sp, M_ERR,
38 "The visual command requires that the open option be set.");
39 return (1);
42 /* If a line specified, move to that line. */
43 if (cmdp->addrcnt)
44 sp->lno = cmdp->addr1.lno;
47 * Push a command based on the line position flags. If no
48 * flag specified, the line goes at the top of the screen.
50 switch (F_ISSET(cmdp, E_F_CARAT | E_F_DASH | E_F_DOT | E_F_PLUS)) {
51 case E_F_CARAT:
52 pos = '^';
53 break;
54 case E_F_DASH:
55 pos = '-';
56 break;
57 case E_F_DOT:
58 pos = '.';
59 break;
60 case E_F_PLUS:
61 default:
62 pos = '+';
63 break;
66 if (F_ISSET(cmdp, E_COUNT))
67 len = snprintf(buf, sizeof(buf),
68 "%luz%c%lu", sp->lno, pos, cmdp->count);
69 else
70 len = snprintf(buf, sizeof(buf), "%luz%c", sp->lno, pos);
71 (void)term_push(sp, buf, len, 0, CH_NOMAP | CH_QUOTED);
74 * !!!
75 * Historically, if no line address was specified, the [p#l] flags
76 * caused the cursor to be moved to the last line of the file, which
77 * was then positioned as described above. This seems useless, so
78 * I haven't implemented it.
80 switch (F_ISSET(cmdp, E_F_HASH | E_F_LIST | E_F_PRINT)) {
81 case E_F_HASH:
82 O_SET(sp, O_NUMBER);
83 break;
84 case E_F_LIST:
85 O_SET(sp, O_LIST);
86 break;
87 case E_F_PRINT:
88 break;
91 /* Switch modes. */
92 F_CLR(sp, S_SCREENS);
93 F_SET(sp, sp->saved_vi_mode);
95 return (0);