align CHAR_T string in log
[nvi.git] / ex / ex_visual.c
blob541c153fcbd3bf48abf16f03cc35fdadc158513c
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.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: ex_visual.c,v 10.14 2000/07/14 14:29:22 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:22 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
27 #include "../common/common.h"
28 #include "../vi/vi.h"
31 * ex_visual -- :[line] vi[sual] [^-.+] [window_size] [flags]
32 * Switch to visual mode.
34 * PUBLIC: int ex_visual __P((SCR *, EXCMD *));
36 int
37 ex_visual(sp, cmdp)
38 SCR *sp;
39 EXCMD *cmdp;
41 SCR *tsp;
42 size_t len;
43 int pos;
44 char buf[256];
45 size_t wlen;
46 CHAR_T *wp;
48 /* If open option off, disallow visual command. */
49 if (!O_ISSET(sp, O_OPEN)) {
50 msgq(sp, M_ERR,
51 "175|The visual command requires that the open option be set");
52 return (1);
55 /* Move to the address. */
56 sp->lno = cmdp->addr1.lno == 0 ? 1 : cmdp->addr1.lno;
59 * Push a command based on the line position flags. If no
60 * flag specified, the line goes at the top of the screen.
62 switch (FL_ISSET(cmdp->iflags,
63 E_C_CARAT | E_C_DASH | E_C_DOT | E_C_PLUS)) {
64 case E_C_CARAT:
65 pos = '^';
66 break;
67 case E_C_DASH:
68 pos = '-';
69 break;
70 case E_C_DOT:
71 pos = '.';
72 break;
73 case E_C_PLUS:
74 pos = '+';
75 break;
76 default:
77 sp->frp->lno = sp->lno;
78 sp->frp->cno = 0;
79 (void)nonblank(sp, sp->lno, &sp->cno);
80 F_SET(sp->frp, FR_CURSORSET);
81 goto nopush;
84 if (FL_ISSET(cmdp->iflags, E_C_COUNT))
85 len = snprintf(buf, sizeof(buf),
86 "%luz%c%lu", sp->lno, pos, cmdp->count);
87 else
88 len = snprintf(buf, sizeof(buf), "%luz%c", sp->lno, pos);
89 CHAR2INT(sp, buf, len, wp, wlen);
90 (void)v_event_push(sp, NULL, wp, wlen, CH_NOMAP | CH_QUOTED);
93 * !!!
94 * Historically, if no line address was specified, the [p#l] flags
95 * caused the cursor to be moved to the last line of the file, which
96 * was then positioned as described above. This seems useless, so
97 * I haven't implemented it.
99 switch (FL_ISSET(cmdp->iflags, E_C_HASH | E_C_LIST | E_C_PRINT)) {
100 case E_C_HASH:
101 O_SET(sp, O_NUMBER);
102 break;
103 case E_C_LIST:
104 O_SET(sp, O_LIST);
105 break;
106 case E_C_PRINT:
107 break;
110 nopush: /*
111 * !!!
112 * You can call the visual part of the editor from within an ex
113 * global command.
115 * XXX
116 * Historically, undoing a visual session was a single undo command,
117 * i.e. you could undo all of the changes you made in visual mode.
118 * We don't get this right; I'm waiting for the new logging code to
119 * be available.
121 * It's explicit, don't have to wait for the user, unless there's
122 * already a reason to wait.
124 if (!F_ISSET(sp, SC_SCR_EXWROTE))
125 F_SET(sp, SC_EX_WAIT_NO);
127 if (F_ISSET(sp, SC_EX_GLOBAL)) {
129 * When the vi screen(s) exit, we don't want to lose our hold
130 * on this screen or this file, otherwise we're going to fail
131 * fairly spectacularly.
133 ++sp->refcnt;
134 ++sp->ep->refcnt;
137 * Fake up a screen pointer -- vi doesn't get to change our
138 * underlying file, regardless.
140 tsp = sp;
141 if (vi(&tsp))
142 return (1);
145 * !!!
146 * Historically, if the user exited the vi screen(s) using an
147 * ex quit command (e.g. :wq, :q) ex/vi exited, it was only if
148 * they exited vi using the Q command that ex continued. Some
149 * early versions of nvi continued in ex regardless, but users
150 * didn't like the semantic.
152 * Reset the screen.
154 if (ex_init(sp))
155 return (1);
157 /* Move out of the vi screen. */
158 (void)ex_puts(sp, "\n");
159 } else {
160 F_CLR(sp, SC_EX | SC_SCR_EX);
161 F_SET(sp, SC_VI);
163 return (0);