4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 /* Copyright (c) 1981 Regents of the University of California */
33 #pragma ident "%Z%%M% %I% %E% SMI"
41 * Entry points to open and visual from command mode processor.
42 * The open/visual code breaks down roughly as follows:
44 * ex_v.c entry points, checking of terminal characteristics
46 * ex_vadj.c logical screen control, use of intelligent operations
47 * insert/delete line and coordination with screen image;
48 * updating of screen after changes.
50 * ex_vget.c input of single keys and reading of input lines
51 * from the echo area, handling of \ escapes on input for
52 * uppercase only terminals, handling of memory for repeated
53 * commands and small saved texts from inserts and partline
54 * deletes, notification of multi line changes in the echo
57 * ex_vmain.c main command decoding, some command processing.
59 * ex_voperate.c decoding of operator/operand sequences and
60 * contextual scans, implementation of word motions.
62 * ex_vops.c major operator interfaces, undos, motions, deletes,
63 * changes, opening new lines, shifts, replacements and yanks
64 * coordinating logical and physical changes.
66 * ex_vops2.c subroutines for operator interfaces in ex_vops.c,
67 * insert mode, read input line processing at lowest level.
69 * ex_vops3.c structured motion definitions of ( ) { } and [ ] operators,
70 * indent for lisp routines, () and {} balancing.
72 * ex_vput.c output routines, clearing, physical mapping of logical cursor
73 * positioning, cursor motions, handling of insert character
74 * and delete character functions of intelligent and unintelligent
75 * terminals, visual mode tracing routines (for debugging),
76 * control of screen image and its updating.
78 * ex_vwind.c window level control of display, forward and backward rolls,
79 * absolute motions, contextual displays, line depth determination
87 wchar_t atube
[TUBESIZE
];
92 /* reinitialize window size after SIGWINCH */
97 if(value(vi_WINDOW
) >= lines
|| options
[vi_WINDOW
].odefault
== value(vi_WINDOW
))
98 value(vi_WINDOW
) = lines
-1;
99 options
[vi_WINDOW
].odefault
= lines
- 1;
100 if(options
[vi_SCROLL
].odefault
== value(vi_SCROLL
))
101 value(vi_SCROLL
) = value(vi_WINDOW
)/2;
102 options
[vi_SCROLL
].odefault
= (lines
- 1)/2;
103 vsetsiz(value(vi_WINDOW
));
114 if(state
!= VISUAL
) {
116 vmoveto(dot
, cursor
, 0);
136 if(ioctl(0, TIOCGWINSZ
, &jwin
) != -1) {
138 oldlines
= jwin
.ws_row
;
139 oldcolumns
= jwin
.ws_col
;
142 if (columns
!= jwin
.ws_col
|| lines
!= jwin
.ws_row
)
148 (void)signal(SIGWINCH
, winch
);
157 if(ioctl(0, TIOCGWINSZ
, &jwin
) != -1) {
159 columns
= jwin
.ws_col
;
165 if (envlines
!= -1) {
169 if (envcolumns
!= -1) {
170 columns
= envcolumns
;
173 if (envlines
!= -1 || envcolumns
!= -1) {
175 jwin
.ws_col
= columns
;
177 if (ioctl(0, TIOCSWINSZ
, &jwin
) == -1) {
178 jwin
.ws_row
= oldlines
;
179 jwin
.ws_col
= oldcolumns
;
181 ioctl(0, TIOCSWINSZ
, &jwin
);
191 value(vi_WINDOW
) = options
[vi_WINDOW
].odefault
= l
- 1;
201 ttymode f
; /* was register */
205 (void)signal(SIGWINCH
, winch
);
207 if (peekchar() == '/') {
208 (void)vi_compile(getchar(), 1);
210 if (execute(0, dot
) == 0)
211 error(value(vi_TERSE
) ? gettext("Fail") :
212 gettext("Pattern not found on addressed line"));
213 ic
= (unsigned char *)loc1
;
214 if (ic
> linebuf
&& *ic
== 0)
218 ic
= vskipwh(linebuf
);
223 * If overstrike then have to HARDOPEN
224 * else if can move cursor up off current line can use CRTOPEN (~~vi1)
225 * otherwise have to use ONEOPEN (like adm3)
227 if (over_strike
&& !erase_overstrike
)
229 else if (cursor_address
|| cursor_up
)
236 * To avoid bombing on glass-crt's when the line is too long
237 * pretend that such terminals are 160 columns wide.
238 * If a line is too wide for display, we will dynamically
239 * switch to hardcopy open mode.
241 if (state
!= CRTOPEN
)
246 if (state
!= CRTOPEN
)
250 if (state
== CRTOPEN
) {
255 outline
= destline
= WBOT
;
259 if (state
!= CRTOPEN
)
261 Command
= (unsigned char *)"open";
263 (void)signal(SIGWINCH
, SIG_DFL
);
271 error(gettext("Recursive open/visual not allowed"));
305 ttymode f
; /* was register */
306 extern unsigned char termtype
[];
308 if (!cursor_address
&& !cursor_up
) {
312 merror(gettext("I don't know what kind of terminal you are on - all I have is '%s'."), termtype
);
314 merror(gettext("[Using open mode]"));
319 error(gettext("Visual needs addressable cursor or upline capability"));
321 if (over_strike
&& !erase_overstrike
) {
324 error(gettext("Can't use visual on a terminal which overstrikes"));
329 error(gettext("Visual requires clear screen capability"));
331 if (!scroll_forward
) {
334 error(gettext("Visual requires scrolling"));
337 (void)signal(SIGWINCH
, winch
);
341 if (any(peekchar(), "+-^."))
344 vsetsiz(isdigit(peekchar()) ? getnum() : value(vi_WINDOW
));
355 vnline((unsigned char *)NOSTR
);
358 Command
= (unsigned char *)"visual";
360 (void)signal(SIGWINCH
, SIG_DFL
);
364 * Hack to allow entry to visual with
365 * empty buffer since routines internally
366 * demand at least one line.
375 vdoappend((unsigned char *)"");
379 } else if (addr2
== zero
)
384 * Save lines before visual between unddol and truedol.
385 * Accomplish this by throwing away current [unddol,truedol]
386 * and then saving all the lines in the buffer and moving
387 * unddol back to dol. Don't do this if in a global.
393 * at some point, and then quit from the visual and undo
394 * you get the old file back. Somewhat weird.
409 * Restore a sensible state after a visual/open, moving the saved
410 * stuff back to [unddol,dol], and killing the partial line kill indicators.
417 signal(SIGINT
, onintr
);
419 pkill
[0] = pkill
[1] = 0;
425 if (undadot
<= zero
|| undadot
> dol
)
430 * Set the window parameters based on the base state bastate
431 * and the available buffer space.
441 if (auto_right_margin
)
446 basWTOP
= WTOP
= WBOT
= WECHO
= 0;
456 ZERO
= lines
- TUBESIZE
/ WCOLS
;
460 error(gettext("Screen too large for internal buffer"));
461 WTOP
= basWTOP
; WBOT
= lines
- 2; WECHO
= lines
- 1;
465 basWLINES
= WLINES
= WBOT
- WTOP
+ 1;
469 * Can we hack an open/visual on this terminal?
470 * If so, then divide the screen buffer up into lines,
471 * and initialize a bunch of state variables before we start.
473 static unsigned char vlinebuf
[LBSIZE
];
476 vok(wchar_t *atube
, int undo
)
482 serror((unsigned char *)
483 gettext("Don't know enough about your terminal to use %s"),
485 if (WCOLS
> TUBECOLS
)
486 error(gettext("Terminal too wide"));
487 if (WLINES
>= TUBELINES
|| WCOLS
* (WECHO
- ZERO
+ 1) > TUBESIZE
)
488 error(gettext("Screen too large"));
492 vclrbyte(atube
, WCOLS
* (WECHO
- ZERO
+ 1));
493 for (i
= 0; i
< ZERO
; i
++)
494 vtube
[i
] = (wchar_t *) 0;
495 for (; i
<= WECHO
; i
++)
496 vtube
[i
] = atube
, atube
+= WCOLS
;
498 for (; i
< TUBELINES
; i
++)
499 vtube
[i
] = (wchar_t *) 0;
509 signal(SIGINT
, vintr
);
519 vSCROLL
= value(vi_SCROLL
);
533 signal(SIGINT
, vintr
);
542 * Set the size of the screen to size lines, to take effect the
543 * next time the screen is redrawn.
550 if (bastate
!= VISUAL
)
552 b
= lines
- 1 - size
;
558 basWLINES
= WBOT
- b
+ 1;