summaryrefslogtreecommitdiffstats
path: root/contrib/nvi/vi
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/nvi/vi')
-rw-r--r--contrib/nvi/vi/extern.h145
-rw-r--r--contrib/nvi/vi/getc.c36
-rw-r--r--contrib/nvi/vi/v_at.c24
-rw-r--r--contrib/nvi/vi/v_ch.c43
-rw-r--r--contrib/nvi/vi/v_cmd.c2
-rw-r--r--contrib/nvi/vi/v_delete.c6
-rw-r--r--contrib/nvi/vi/v_ex.c191
-rw-r--r--contrib/nvi/vi/v_increment.c47
-rw-r--r--contrib/nvi/vi/v_init.c23
-rw-r--r--contrib/nvi/vi/v_itxt.c69
-rw-r--r--contrib/nvi/vi/v_left.c22
-rw-r--r--contrib/nvi/vi/v_mark.c70
-rw-r--r--contrib/nvi/vi/v_match.c91
-rw-r--r--contrib/nvi/vi/v_paragraph.c20
-rw-r--r--contrib/nvi/vi/v_put.c14
-rw-r--r--contrib/nvi/vi/v_redraw.c6
-rw-r--r--contrib/nvi/vi/v_replace.c19
-rw-r--r--contrib/nvi/vi/v_right.c10
-rw-r--r--contrib/nvi/vi/v_screen.c14
-rw-r--r--contrib/nvi/vi/v_scroll.c69
-rw-r--r--contrib/nvi/vi/v_search.c121
-rw-r--r--contrib/nvi/vi/v_section.c22
-rw-r--r--contrib/nvi/vi/v_sentence.c12
-rw-r--r--contrib/nvi/vi/v_status.c7
-rw-r--r--contrib/nvi/vi/v_txt.c560
-rw-r--r--contrib/nvi/vi/v_ulcase.c38
-rw-r--r--contrib/nvi/vi/v_undo.c10
-rw-r--r--contrib/nvi/vi/v_util.c31
-rw-r--r--contrib/nvi/vi/v_word.c69
-rw-r--r--contrib/nvi/vi/v_xchar.c10
-rw-r--r--contrib/nvi/vi/v_yank.c6
-rw-r--r--contrib/nvi/vi/v_z.c12
-rw-r--r--contrib/nvi/vi/v_zexit.c6
-rw-r--r--contrib/nvi/vi/vi.c174
-rw-r--r--contrib/nvi/vi/vi.h31
-rw-r--r--contrib/nvi/vi/vs_line.c81
-rw-r--r--contrib/nvi/vi/vs_msg.c113
-rw-r--r--contrib/nvi/vi/vs_refresh.c78
-rw-r--r--contrib/nvi/vi/vs_relative.c43
-rw-r--r--contrib/nvi/vi/vs_smap.c116
-rw-r--r--contrib/nvi/vi/vs_split.c570
41 files changed, 1626 insertions, 1405 deletions
diff --git a/contrib/nvi/vi/extern.h b/contrib/nvi/vi/extern.h
new file mode 100644
index 0000000..600caa6
--- /dev/null
+++ b/contrib/nvi/vi/extern.h
@@ -0,0 +1,145 @@
+int cs_init __P((SCR *, VCS *));
+int cs_next __P((SCR *, VCS *));
+int cs_fspace __P((SCR *, VCS *));
+int cs_fblank __P((SCR *, VCS *));
+int cs_prev __P((SCR *, VCS *));
+int cs_bblank __P((SCR *, VCS *));
+int v_at __P((SCR *, VICMD *));
+int v_chrepeat __P((SCR *, VICMD *));
+int v_chrrepeat __P((SCR *, VICMD *));
+int v_cht __P((SCR *, VICMD *));
+int v_chf __P((SCR *, VICMD *));
+int v_chT __P((SCR *, VICMD *));
+int v_chF __P((SCR *, VICMD *));
+int v_delete __P((SCR *, VICMD *));
+int v_again __P((SCR *, VICMD *));
+int v_exmode __P((SCR *, VICMD *));
+int v_join __P((SCR *, VICMD *));
+int v_shiftl __P((SCR *, VICMD *));
+int v_shiftr __P((SCR *, VICMD *));
+int v_suspend __P((SCR *, VICMD *));
+int v_switch __P((SCR *, VICMD *));
+int v_tagpush __P((SCR *, VICMD *));
+int v_tagpop __P((SCR *, VICMD *));
+int v_filter __P((SCR *, VICMD *));
+int v_ex __P((SCR *, VICMD *));
+int v_ecl_exec __P((SCR *));
+int v_increment __P((SCR *, VICMD *));
+int v_screen_copy __P((SCR *, SCR *));
+int v_screen_end __P((SCR *));
+int v_optchange __P((SCR *, int, char *, u_long *));
+int v_iA __P((SCR *, VICMD *));
+int v_ia __P((SCR *, VICMD *));
+int v_iI __P((SCR *, VICMD *));
+int v_ii __P((SCR *, VICMD *));
+int v_iO __P((SCR *, VICMD *));
+int v_io __P((SCR *, VICMD *));
+int v_change __P((SCR *, VICMD *));
+int v_Replace __P((SCR *, VICMD *));
+int v_subst __P((SCR *, VICMD *));
+int v_left __P((SCR *, VICMD *));
+int v_cfirst __P((SCR *, VICMD *));
+int v_first __P((SCR *, VICMD *));
+int v_ncol __P((SCR *, VICMD *));
+int v_zero __P((SCR *, VICMD *));
+int v_mark __P((SCR *, VICMD *));
+int v_bmark __P((SCR *, VICMD *));
+int v_fmark __P((SCR *, VICMD *));
+int v_emark __P((SCR *, VICMD *));
+int v_match __P((SCR *, VICMD *));
+int v_buildmcs __P((SCR *, char *));
+int v_paragraphf __P((SCR *, VICMD *));
+int v_paragraphb __P((SCR *, VICMD *));
+int v_buildps __P((SCR *, char *, char *));
+int v_Put __P((SCR *, VICMD *));
+int v_put __P((SCR *, VICMD *));
+int v_redraw __P((SCR *, VICMD *));
+int v_replace __P((SCR *, VICMD *));
+int v_right __P((SCR *, VICMD *));
+int v_dollar __P((SCR *, VICMD *));
+int v_screen __P((SCR *, VICMD *));
+int v_lgoto __P((SCR *, VICMD *));
+int v_home __P((SCR *, VICMD *));
+int v_middle __P((SCR *, VICMD *));
+int v_bottom __P((SCR *, VICMD *));
+int v_up __P((SCR *, VICMD *));
+int v_cr __P((SCR *, VICMD *));
+int v_down __P((SCR *, VICMD *));
+int v_hpageup __P((SCR *, VICMD *));
+int v_hpagedown __P((SCR *, VICMD *));
+int v_pagedown __P((SCR *, VICMD *));
+int v_pageup __P((SCR *, VICMD *));
+int v_lineup __P((SCR *, VICMD *));
+int v_linedown __P((SCR *, VICMD *));
+int v_searchb __P((SCR *, VICMD *));
+int v_searchf __P((SCR *, VICMD *));
+int v_searchN __P((SCR *, VICMD *));
+int v_searchn __P((SCR *, VICMD *));
+int v_searchw __P((SCR *, VICMD *));
+int v_correct __P((SCR *, VICMD *, int));
+int v_sectionf __P((SCR *, VICMD *));
+int v_sectionb __P((SCR *, VICMD *));
+int v_sentencef __P((SCR *, VICMD *));
+int v_sentenceb __P((SCR *, VICMD *));
+int v_status __P((SCR *, VICMD *));
+int v_tcmd __P((SCR *, VICMD *, ARG_CHAR_T, u_int));
+int v_txt __P((SCR *, VICMD *, MARK *,
+ const CHAR_T *, size_t, ARG_CHAR_T, recno_t, u_long, u_int32_t));
+int v_txt_auto __P((SCR *, recno_t, TEXT *, size_t, TEXT *));
+int v_ulcase __P((SCR *, VICMD *));
+int v_mulcase __P((SCR *, VICMD *));
+int v_Undo __P((SCR *, VICMD *));
+int v_undo __P((SCR *, VICMD *));
+void v_eof __P((SCR *, MARK *));
+void v_eol __P((SCR *, MARK *));
+void v_nomove __P((SCR *));
+void v_sof __P((SCR *, MARK *));
+void v_sol __P((SCR *));
+int v_isempty __P((CHAR_T *, size_t));
+void v_emsg __P((SCR *, char *, vim_t));
+int v_wordW __P((SCR *, VICMD *));
+int v_wordw __P((SCR *, VICMD *));
+int v_wordE __P((SCR *, VICMD *));
+int v_worde __P((SCR *, VICMD *));
+int v_wordB __P((SCR *, VICMD *));
+int v_wordb __P((SCR *, VICMD *));
+int v_xchar __P((SCR *, VICMD *));
+int v_Xchar __P((SCR *, VICMD *));
+int v_yank __P((SCR *, VICMD *));
+int v_z __P((SCR *, VICMD *));
+int vs_crel __P((SCR *, long));
+int v_zexit __P((SCR *, VICMD *));
+int vi __P((SCR **));
+int v_curword __P((SCR *));
+int vs_line __P((SCR *, SMAP *, size_t *, size_t *));
+int vs_number __P((SCR *));
+void vs_busy __P((SCR *, const char *, busy_t));
+void vs_home __P((SCR *));
+void vs_update __P((SCR *, const char *, const CHAR_T *));
+void vs_msg __P((SCR *, mtype_t, char *, size_t));
+int vs_ex_resolve __P((SCR *, int *));
+int vs_resolve __P((SCR *, SCR *, int));
+int vs_repaint __P((SCR *, EVENT *));
+int vs_refresh __P((SCR *, int));
+int vs_column __P((SCR *, size_t *));
+size_t vs_screens __P((SCR *, recno_t, size_t *));
+size_t vs_columns __P((SCR *, CHAR_T *, recno_t, size_t *, size_t *));
+size_t vs_rcm __P((SCR *, recno_t, int));
+size_t vs_colpos __P((SCR *, recno_t, size_t));
+int vs_change __P((SCR *, recno_t, lnop_t));
+int vs_sm_fill __P((SCR *, recno_t, pos_t));
+int vs_sm_scroll __P((SCR *, MARK *, recno_t, scroll_t));
+int vs_sm_1up __P((SCR *));
+int vs_sm_1down __P((SCR *));
+int vs_sm_next __P((SCR *, SMAP *, SMAP *));
+int vs_sm_prev __P((SCR *, SMAP *, SMAP *));
+int vs_sm_cursor __P((SCR *, SMAP **));
+int vs_sm_position __P((SCR *, MARK *, u_long, pos_t));
+recno_t vs_sm_nlines __P((SCR *, SMAP *, recno_t, size_t));
+int vs_split __P((SCR *, SCR *, int));
+int vs_vsplit __P((SCR *, SCR *));
+int vs_discard __P((SCR *, SCR **));
+int vs_fg __P((SCR *, SCR **, CHAR_T *, int));
+int vs_bg __P((SCR *));
+int vs_swap __P((SCR *, SCR **, char *));
+int vs_resize __P((SCR *, long, adj_t));
diff --git a/contrib/nvi/vi/getc.c b/contrib/nvi/vi/getc.c
index 5e60ade..deb3554 100644
--- a/contrib/nvi/vi/getc.c
+++ b/contrib/nvi/vi/getc.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)getc.c 10.10 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: getc.c,v 10.13 2011/12/27 00:49:31 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -43,9 +43,7 @@ static const char sccsid[] = "@(#)getc.c 10.10 (Berkeley) 3/6/96";
* PUBLIC: int cs_init __P((SCR *, VCS *));
*/
int
-cs_init(sp, csp)
- SCR *sp;
- VCS *csp;
+cs_init(SCR *sp, VCS *csp)
{
int isempty;
@@ -71,11 +69,9 @@ cs_init(sp, csp)
* PUBLIC: int cs_next __P((SCR *, VCS *));
*/
int
-cs_next(sp, csp)
- SCR *sp;
- VCS *csp;
+cs_next(SCR *sp, VCS *csp)
{
- char *p;
+ CHAR_T *p;
switch (csp->cs_flags) {
case CS_EMP: /* EMP; get next line. */
@@ -123,16 +119,14 @@ cs_next(sp, csp)
* PUBLIC: int cs_fspace __P((SCR *, VCS *));
*/
int
-cs_fspace(sp, csp)
- SCR *sp;
- VCS *csp;
+cs_fspace(SCR *sp, VCS *csp)
{
- if (csp->cs_flags != 0 || !isblank(csp->cs_ch))
+ if (csp->cs_flags != 0 || !ISBLANK(csp->cs_ch))
return (0);
for (;;) {
if (cs_next(sp, csp))
return (1);
- if (csp->cs_flags != 0 || !isblank(csp->cs_ch))
+ if (csp->cs_flags != 0 || !ISBLANK(csp->cs_ch))
break;
}
return (0);
@@ -145,15 +139,13 @@ cs_fspace(sp, csp)
* PUBLIC: int cs_fblank __P((SCR *, VCS *));
*/
int
-cs_fblank(sp, csp)
- SCR *sp;
- VCS *csp;
+cs_fblank(SCR *sp, VCS *csp)
{
for (;;) {
if (cs_next(sp, csp))
return (1);
if (csp->cs_flags == CS_EOL || csp->cs_flags == CS_EMP ||
- csp->cs_flags == 0 && isblank(csp->cs_ch))
+ (csp->cs_flags == 0 && ISBLANK(csp->cs_ch)))
continue;
break;
}
@@ -167,9 +159,7 @@ cs_fblank(sp, csp)
* PUBLIC: int cs_prev __P((SCR *, VCS *));
*/
int
-cs_prev(sp, csp)
- SCR *sp;
- VCS *csp;
+cs_prev(SCR *sp, VCS *csp)
{
switch (csp->cs_flags) {
case CS_EMP: /* EMP; get previous line. */
@@ -218,15 +208,13 @@ cs_prev(sp, csp)
* PUBLIC: int cs_bblank __P((SCR *, VCS *));
*/
int
-cs_bblank(sp, csp)
- SCR *sp;
- VCS *csp;
+cs_bblank(SCR *sp, VCS *csp)
{
for (;;) {
if (cs_prev(sp, csp))
return (1);
if (csp->cs_flags == CS_EOL || csp->cs_flags == CS_EMP ||
- csp->cs_flags == 0 && isblank(csp->cs_ch))
+ (csp->cs_flags == 0 && ISBLANK(csp->cs_ch)))
continue;
break;
}
diff --git a/contrib/nvi/vi/v_at.c b/contrib/nvi/vi/v_at.c
index d266f27..45757d4 100644
--- a/contrib/nvi/vi/v_at.c
+++ b/contrib/nvi/vi/v_at.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_at.c 10.8 (Berkeley) 4/27/96";
+static const char sccsid[] = "$Id: v_at.c,v 10.11 2001/06/25 15:19:30 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -21,6 +21,7 @@ static const char sccsid[] = "@(#)v_at.c 10.8 (Berkeley) 4/27/96";
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
+#include <string.h>
#include "../common/common.h"
#include "vi.h"
@@ -32,15 +33,16 @@ static const char sccsid[] = "@(#)v_at.c 10.8 (Berkeley) 4/27/96";
* PUBLIC: int v_at __P((SCR *, VICMD *));
*/
int
-v_at(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_at(SCR *sp, VICMD *vp)
{
CB *cbp;
CHAR_T name;
TEXT *tp;
size_t len;
char nbuf[20];
+ CHAR_T wbuf[20];
+ CHAR_T *wp;
+ size_t wlen;
/*
* !!!
@@ -87,13 +89,13 @@ v_at(sp, vp)
* together. We don't get this right; I'm waiting for the new DB
* logging code to be available.
*/
- for (tp = cbp->textq.cqh_last;
- tp != (void *)&cbp->textq; tp = tp->q.cqe_prev)
- if ((F_ISSET(cbp, CB_LMODE) ||
- tp->q.cqe_next != (void *)&cbp->textq) &&
- v_event_push(sp, NULL, "\n", 1, 0) ||
+ TAILQ_FOREACH_REVERSE(tp, cbp->textq, _texth, q) {
+ if (((F_ISSET(cbp, CB_LMODE) ||
+ TAILQ_NEXT(tp, q) != NULL) &&
+ v_event_push(sp, NULL, L("\n"), 1, 0)) ||
v_event_push(sp, NULL, tp->lb, tp->len, 0))
return (1);
+ }
/*
* !!!
@@ -102,7 +104,9 @@ v_at(sp, vp)
*/
if (F_ISSET(vp, VC_C1SET)) {
len = snprintf(nbuf, sizeof(nbuf), "%lu", vp->count);
- if (v_event_push(sp, NULL, nbuf, len, 0))
+ CHAR2INT(sp, nbuf, len, wp, wlen);
+ MEMCPY(wbuf, wp, wlen);
+ if (v_event_push(sp, NULL, wp, wlen, 0))
return (1);
}
return (0);
diff --git a/contrib/nvi/vi/v_ch.c b/contrib/nvi/vi/v_ch.c
index 6a1b611..04fb6af 100644
--- a/contrib/nvi/vi/v_ch.c
+++ b/contrib/nvi/vi/v_ch.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_ch.c 10.8 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_ch.c,v 10.11 2011/12/02 19:49:50 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -35,9 +35,7 @@ static void noprev __P((SCR *));
* PUBLIC: int v_chrepeat __P((SCR *, VICMD *));
*/
int
-v_chrepeat(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_chrepeat(SCR *sp, VICMD *vp)
{
vp->character = VIP(sp)->lastckey;
@@ -66,9 +64,7 @@ v_chrepeat(sp, vp)
* PUBLIC: int v_chrrepeat __P((SCR *, VICMD *));
*/
int
-v_chrrepeat(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_chrrepeat(SCR *sp, VICMD *vp)
{
cdir_t savedir;
int rval;
@@ -107,9 +103,7 @@ v_chrrepeat(sp, vp)
* PUBLIC: int v_cht __P((SCR *, VICMD *));
*/
int
-v_cht(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_cht(SCR *sp, VICMD *vp)
{
if (v_chf(sp, vp))
return (1);
@@ -140,14 +134,13 @@ v_cht(sp, vp)
* PUBLIC: int v_chf __P((SCR *, VICMD *));
*/
int
-v_chf(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_chf(SCR *sp, VICMD *vp)
{
size_t len;
u_long cnt;
- int isempty, key;
- char *endp, *p, *startp;
+ int isempty;
+ ARG_CHAR_T key;
+ CHAR_T *endp, *p, *startp;
/*
* !!!
@@ -198,9 +191,7 @@ empty: notfound(sp, key);
* PUBLIC: int v_chT __P((SCR *, VICMD *));
*/
int
-v_chT(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_chT(SCR *sp, VICMD *vp)
{
if (v_chF(sp, vp))
return (1);
@@ -225,14 +216,13 @@ v_chT(sp, vp)
* PUBLIC: int v_chF __P((SCR *, VICMD *));
*/
int
-v_chF(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_chF(SCR *sp, VICMD *vp)
{
size_t len;
u_long cnt;
- int isempty, key;
- char *endp, *p;
+ int isempty;
+ ARG_CHAR_T key;
+ CHAR_T *endp, *p;
/*
* !!!
@@ -280,16 +270,13 @@ empty: notfound(sp, key);
}
static void
-noprev(sp)
- SCR *sp;
+noprev(SCR *sp)
{
msgq(sp, M_BERR, "178|No previous F, f, T or t search");
}
static void
-notfound(sp, ch)
- SCR *sp;
- ARG_CHAR_T ch;
+notfound(SCR *sp, ARG_CHAR_T ch)
{
msgq(sp, M_BERR, "179|%s not found", KEY_NAME(sp, ch));
}
diff --git a/contrib/nvi/vi/v_cmd.c b/contrib/nvi/vi/v_cmd.c
index cc9e30f..f77cd27 100644
--- a/contrib/nvi/vi/v_cmd.c
+++ b/contrib/nvi/vi/v_cmd.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_cmd.c 10.9 (Berkeley) 3/28/96";
+static const char sccsid[] = "$Id: v_cmd.c,v 10.9 1996/03/28 15:18:39 bostic Exp $";
#endif /* not lint */
#include <sys/types.h>
diff --git a/contrib/nvi/vi/v_delete.c b/contrib/nvi/vi/v_delete.c
index 70df78b..b3b879e 100644
--- a/contrib/nvi/vi/v_delete.c
+++ b/contrib/nvi/vi/v_delete.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_delete.c 10.9 (Berkeley) 10/23/96";
+static const char sccsid[] = "$Id: v_delete.c,v 10.11 2001/06/25 15:19:31 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -32,9 +32,7 @@ static const char sccsid[] = "@(#)v_delete.c 10.9 (Berkeley) 10/23/96";
* PUBLIC: int v_delete __P((SCR *, VICMD *));
*/
int
-v_delete(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_delete(SCR *sp, VICMD *vp)
{
recno_t nlines;
size_t len;
diff --git a/contrib/nvi/vi/v_ex.c b/contrib/nvi/vi/v_ex.c
index d4d431a..e5ac573 100644
--- a/contrib/nvi/vi/v_ex.c
+++ b/contrib/nvi/vi/v_ex.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_ex.c 10.42 (Berkeley) 6/28/96";
+static const char sccsid[] = "$Id: v_ex.c,v 10.61 2011/12/22 18:41:53 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -40,16 +40,12 @@ static int v_exec_ex __P((SCR *, VICMD *, EXCMD *));
* PUBLIC: int v_again __P((SCR *, VICMD *));
*/
int
-v_again(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_again(SCR *sp, VICMD *vp)
{
- ARGS *ap[2], a;
EXCMD cmd;
- ex_cinit(&cmd, C_SUBAGAIN, 2, vp->m_start.lno, vp->m_start.lno, 1, ap);
- ex_cadd(&cmd, &a, "", 1);
-
+ ex_cinit(sp, &cmd, C_SUBAGAIN, 2, vp->m_start.lno, vp->m_start.lno, 1);
+ argv_exp0(sp, &cmd, L(""), 1);
return (v_exec_ex(sp, vp, &cmd));
}
@@ -60,9 +56,7 @@ v_again(sp, vp)
* PUBLIC: int v_exmode __P((SCR *, VICMD *));
*/
int
-v_exmode(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_exmode(SCR *sp, VICMD *vp)
{
GS *gp;
@@ -98,9 +92,7 @@ v_exmode(sp, vp)
* PUBLIC: int v_join __P((SCR *, VICMD *));
*/
int
-v_join(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_join(SCR *sp, VICMD *vp)
{
EXCMD cmd;
int lno;
@@ -118,7 +110,7 @@ v_join(sp, vp)
if (F_ISSET(vp, VC_C1SET) && vp->count > 2)
lno = vp->m_start.lno + (vp->count - 1);
- ex_cinit(&cmd, C_JOIN, 2, vp->m_start.lno, lno, 0, NULL);
+ ex_cinit(sp, &cmd, C_JOIN, 2, vp->m_start.lno, lno, 0);
return (v_exec_ex(sp, vp, &cmd));
}
@@ -129,15 +121,12 @@ v_join(sp, vp)
* PUBLIC: int v_shiftl __P((SCR *, VICMD *));
*/
int
-v_shiftl(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_shiftl(SCR *sp, VICMD *vp)
{
- ARGS *ap[2], a;
EXCMD cmd;
- ex_cinit(&cmd, C_SHIFTL, 2, vp->m_start.lno, vp->m_stop.lno, 0, ap);
- ex_cadd(&cmd, &a, "<", 1);
+ ex_cinit(sp, &cmd, C_SHIFTL, 2, vp->m_start.lno, vp->m_stop.lno, 0);
+ argv_exp0(sp, &cmd, L("<"), 2);
return (v_exec_ex(sp, vp, &cmd));
}
@@ -148,15 +137,12 @@ v_shiftl(sp, vp)
* PUBLIC: int v_shiftr __P((SCR *, VICMD *));
*/
int
-v_shiftr(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_shiftr(SCR *sp, VICMD *vp)
{
- ARGS *ap[2], a;
EXCMD cmd;
- ex_cinit(&cmd, C_SHIFTR, 2, vp->m_start.lno, vp->m_stop.lno, 0, ap);
- ex_cadd(&cmd, &a, ">", 1);
+ ex_cinit(sp, &cmd, C_SHIFTR, 2, vp->m_start.lno, vp->m_stop.lno, 0);
+ argv_exp0(sp, &cmd, L(">"), 2);
return (v_exec_ex(sp, vp, &cmd));
}
@@ -167,15 +153,12 @@ v_shiftr(sp, vp)
* PUBLIC: int v_suspend __P((SCR *, VICMD *));
*/
int
-v_suspend(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_suspend(SCR *sp, VICMD *vp)
{
- ARGS *ap[2], a;
EXCMD cmd;
- ex_cinit(&cmd, C_STOP, 0, OOBLNO, OOBLNO, 0, ap);
- ex_cadd(&cmd, &a, "suspend", sizeof("suspend") - 1);
+ ex_cinit(sp, &cmd, C_STOP, 0, OOBLNO, OOBLNO, 0);
+ argv_exp0(sp, &cmd, L("suspend"), SIZE(L("suspend")));
return (v_exec_ex(sp, vp, &cmd));
}
@@ -186,13 +169,12 @@ v_suspend(sp, vp)
* PUBLIC: int v_switch __P((SCR *, VICMD *));
*/
int
-v_switch(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_switch(SCR *sp, VICMD *vp)
{
- ARGS *ap[2], a;
EXCMD cmd;
char *name;
+ CHAR_T *wp;
+ size_t wlen;
/*
* Try the alternate file name, then the previous file
@@ -207,8 +189,9 @@ v_switch(sp, vp)
if (file_m1(sp, 0, FS_ALL))
return (1);
- ex_cinit(&cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0, ap);
- ex_cadd(&cmd, &a, name, strlen(name));
+ ex_cinit(sp, &cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0);
+ CHAR2INT(sp, name, strlen(name) + 1, wp, wlen);
+ argv_exp0(sp, &cmd, wp, wlen);
return (v_exec_ex(sp, vp, &cmd));
}
@@ -219,20 +202,12 @@ v_switch(sp, vp)
* PUBLIC: int v_tagpush __P((SCR *, VICMD *));
*/
int
-v_tagpush(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_tagpush(SCR *sp, VICMD *vp)
{
- ARGS *ap[2], a;
EXCMD cmd;
-#ifdef GTAGS
- if (O_ISSET(sp, O_GTAGSMODE) && vp->m_start.cno == 0)
- ex_cinit(&cmd, C_RTAG, 0, OOBLNO, 0, 0, ap);
- else
-#endif
- ex_cinit(&cmd, C_TAG, 0, OOBLNO, 0, 0, ap);
- ex_cadd(&cmd, &a, VIP(sp)->keyw, strlen(VIP(sp)->keyw));
+ ex_cinit(sp, &cmd, C_TAG, 0, OOBLNO, 0, 0);
+ argv_exp0(sp, &cmd, VIP(sp)->keyw, STRLEN(VIP(sp)->keyw) + 1);
return (v_exec_ex(sp, vp, &cmd));
}
@@ -243,13 +218,11 @@ v_tagpush(sp, vp)
* PUBLIC: int v_tagpop __P((SCR *, VICMD *));
*/
int
-v_tagpop(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_tagpop(SCR *sp, VICMD *vp)
{
EXCMD cmd;
- ex_cinit(&cmd, C_TAGPOP, 0, OOBLNO, 0, 0, NULL);
+ ex_cinit(sp, &cmd, C_TAGPOP, 0, OOBLNO, 0, 0);
return (v_exec_ex(sp, vp, &cmd));
}
@@ -260,9 +233,7 @@ v_tagpop(sp, vp)
* PUBLIC: int v_filter __P((SCR *, VICMD *));
*/
int
-v_filter(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_filter(SCR *sp, VICMD *vp)
{
EXCMD cmd;
TEXT *tp;
@@ -288,11 +259,11 @@ v_filter(sp, vp)
*/
if (F_ISSET(vp, VC_ISDOT) ||
ISCMD(vp->rkp, 'N') || ISCMD(vp->rkp, 'n')) {
- ex_cinit(&cmd, C_BANG,
- 2, vp->m_start.lno, vp->m_stop.lno, 0, NULL);
+ ex_cinit(sp,
+ &cmd, C_BANG, 2, vp->m_start.lno, vp->m_stop.lno, 0);
EXP(sp)->argsoff = 0; /* XXX */
- if (argv_exp1(sp, &cmd, "!", 1, 1))
+ if (argv_exp1(sp, &cmd, L("!"), 1, 1))
return (1);
cmd.argc = EXP(sp)->argsoff; /* XXX */
cmd.argv = EXP(sp)->args; /* XXX */
@@ -311,7 +282,7 @@ v_filter(sp, vp)
* Entering <escape> on an empty line was historically an error,
* this implementation doesn't bother.
*/
- tp = sp->tiq.cqh_first;
+ tp = TAILQ_FIRST(sp->tiq);
if (tp->term != TERM_OK) {
vp->m_final.lno = sp->lno;
vp->m_final.cno = sp->cno;
@@ -321,7 +292,7 @@ v_filter(sp, vp)
/* Home the cursor. */
vs_home(sp);
- ex_cinit(&cmd, C_BANG, 2, vp->m_start.lno, vp->m_stop.lno, 0, NULL);
+ ex_cinit(sp, &cmd, C_BANG, 2, vp->m_start.lno, vp->m_stop.lno, 0);
EXP(sp)->argsoff = 0; /* XXX */
if (argv_exp1(sp, &cmd, tp->lb + 1, tp->len - 1, 1))
@@ -332,40 +303,11 @@ v_filter(sp, vp)
}
/*
- * v_event_exec --
- * Execute some command(s) based on an event.
- *
- * PUBLIC: int v_event_exec __P((SCR *, VICMD *));
- */
-int
-v_event_exec(sp, vp)
- SCR *sp;
- VICMD *vp;
-{
- EXCMD cmd;
-
- switch (vp->ev.e_event) {
- case E_QUIT:
- ex_cinit(&cmd, C_QUIT, 0, OOBLNO, OOBLNO, 0, NULL);
- break;
- case E_WRITE:
- ex_cinit(&cmd, C_WRITE, 0, OOBLNO, OOBLNO, 0, NULL);
- break;
- default:
- abort();
- }
- return (v_exec_ex(sp, vp, &cmd));
-}
-
-/*
* v_exec_ex --
* Execute an ex command.
*/
static int
-v_exec_ex(sp, vp, exp)
- SCR *sp;
- VICMD *vp;
- EXCMD *exp;
+v_exec_ex(SCR *sp, VICMD *vp, EXCMD *exp)
{
int rval;
@@ -380,9 +322,7 @@ v_exec_ex(sp, vp, exp)
* PUBLIC: int v_ex __P((SCR *, VICMD *));
*/
int
-v_ex(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_ex(SCR *sp, VICMD *vp)
{
GS *gp;
TEXT *tp;
@@ -410,7 +350,7 @@ v_ex(sp, vp)
if (v_tcmd(sp, vp, ':',
TXT_BS | TXT_CEDIT | TXT_FILEC | TXT_PROMPT))
return (1);
- tp = sp->tiq.cqh_first;
+ tp = TAILQ_FIRST(sp->tiq);
/*
* If the user entered a single <esc>, they want to
@@ -510,9 +450,7 @@ v_ex(sp, vp)
* Cleanup from an ex command.
*/
static int
-v_ex_done(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_ex_done(SCR *sp, VICMD *vp)
{
size_t len;
@@ -554,8 +492,7 @@ v_ex_done(sp, vp)
* Start an edit window on the colon command-line commands.
*/
static int
-v_ecl(sp)
- SCR *sp;
+v_ecl(SCR *sp)
{
GS *gp;
SCR *new;
@@ -591,6 +528,11 @@ v_ecl(sp)
/* It's a special window. */
F_SET(new, SC_COMEDIT);
+#if defined(USE_WIDECHAR) && defined(USE_ICONV)
+ /* Bypass iconv on writing to DB. */
+ o_set(new, O_FILEENCODING, OS_STRDUP, codeset(), 0);
+#endif
+
/* Set up the switch. */
sp->nextdisp = new;
F_SET(sp, SC_SSWITCH);
@@ -604,11 +546,10 @@ v_ecl(sp)
* PUBLIC: int v_ecl_exec __P((SCR *));
*/
int
-v_ecl_exec(sp)
- SCR *sp;
+v_ecl_exec(SCR *sp)
{
size_t len;
- char *p;
+ CHAR_T *p;
if (db_get(sp, sp->lno, 0, &p, &len) && sp->lno == 1) {
v_emsg(sp, NULL, VIM_EMPTY);
@@ -634,39 +575,43 @@ v_ecl_exec(sp)
* Log a command into the colon command-line log file.
*/
static int
-v_ecl_log(sp, tp)
- SCR *sp;
- TEXT *tp;
+v_ecl_log(SCR *sp, TEXT *tp)
{
- EXF *save_ep;
recno_t lno;
int rval;
+ CHAR_T *p;
+ size_t len;
+ SCR *ccl_sp;
/* Initialize the screen, if necessary. */
if (sp->gp->ccl_sp == NULL && v_ecl_init(sp))
return (1);
+ ccl_sp = sp->gp->ccl_sp;
+
/*
* Don't log colon command window commands into the colon command
* window...
*/
- if (sp->ep == sp->gp->ccl_sp->ep)
+ if (sp->ep == ccl_sp->ep)
return (0);
- /*
- * XXX
- * Swap the current EXF with the colon command file EXF. This
- * isn't pretty, but too many routines "know" that sp->ep points
- * to the current EXF.
- */
- save_ep = sp->ep;
- sp->ep = sp->gp->ccl_sp->ep;
- if (db_last(sp, &lno)) {
- sp->ep = save_ep;
+ if (db_last(ccl_sp, &lno)) {
return (1);
}
- rval = db_append(sp, 0, lno, tp->lb, tp->len);
- sp->ep = save_ep;
+ /* Don't log line that is identical to previous one */
+ if (lno > 0 &&
+ !db_get(ccl_sp, lno, 0, &p, &len) &&
+ len == tp->len &&
+ !MEMCMP(tp->lb, p, len))
+ rval = 0;
+ else {
+ rval = db_append(ccl_sp, 0, lno, tp->lb, tp->len);
+ /* XXXX end "transaction" on ccl */
+ /* Is this still necessary now that we no longer hijack sp ? */
+ log_cursor(ccl_sp);
+ }
+
return (rval);
}
@@ -675,8 +620,7 @@ v_ecl_log(sp, tp)
* Initialize the colon command-line log file.
*/
static int
-v_ecl_init(sp)
- SCR *sp;
+v_ecl_init(SCR *sp)
{
FREF *frp;
GS *gp;
@@ -695,6 +639,7 @@ v_ecl_init(sp)
return (1);
if (file_init(gp->ccl_sp, frp, NULL, 0)) {
(void)screen_end(gp->ccl_sp);
+ gp->ccl_sp = NULL;
return (1);
}
diff --git a/contrib/nvi/vi/v_increment.c b/contrib/nvi/vi/v_increment.c
index 45e763f..0a121a9 100644
--- a/contrib/nvi/vi/v_increment.c
+++ b/contrib/nvi/vi/v_increment.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_increment.c 10.12 (Berkeley) 3/19/96";
+static const char sccsid[] = "$Id: v_increment.c,v 10.17 2011/12/02 01:17:53 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -28,17 +28,17 @@ static const char sccsid[] = "@(#)v_increment.c 10.12 (Berkeley) 3/19/96";
#include "../common/common.h"
#include "vi.h"
-static char * const fmt[] = {
+static CHAR_T * const fmt[] = {
#define DEC 0
- "%ld",
+ L("%ld"),
#define SDEC 1
- "%+ld",
+ L("%+ld"),
#define HEXC 2
- "0X%0*lX",
+ L("0X%0*lX"),
#define HEXL 3
- "0x%0*lx",
+ L("0x%0*lx"),
#define OCTAL 4
- "%#0*lo",
+ L("%#0*lo"),
};
static void inc_err __P((SCR *, enum nresult));
@@ -50,16 +50,15 @@ static void inc_err __P((SCR *, enum nresult));
* PUBLIC: int v_increment __P((SCR *, VICMD *));
*/
int
-v_increment(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_increment(SCR *sp, VICMD *vp)
{
enum nresult nret;
u_long ulval;
long change, ltmp, lval;
size_t beg, blen, end, len, nlen, wlen;
int base, isempty, rval;
- char *bp, *ntype, *p, *t, nbuf[100];
+ CHAR_T *ntype, nbuf[100];
+ CHAR_T *bp, *p, *t;
/* Validate the operator. */
if (vp->character == '#')
@@ -91,7 +90,7 @@ v_increment(sp, vp)
* implies moving the cursor to its beginning, if we moved, refresh
* now.
*/
- for (beg = vp->m_start.cno; beg < len && isspace(p[beg]); ++beg);
+ for (beg = vp->m_start.cno; beg < len && ISSPACE(p[beg]); ++beg);
if (beg >= len)
goto nonum;
if (beg != vp->m_start.cno) {
@@ -100,9 +99,9 @@ v_increment(sp, vp)
}
#undef ishex
-#define ishex(c) (isdigit(c) || strchr("abcdefABCDEF", c))
+#define ishex(c) (ISXDIGIT(c))
#undef isoctal
-#define isoctal(c) (isdigit(c) && (c) != '8' && (c) != '9')
+#define isoctal(c) ((c) >= '0' && (c) <= '7')
/*
* Look for 0[Xx], or leading + or - signs, guess at the base.
@@ -175,9 +174,9 @@ nonum: msgq(sp, M_ERR, "181|Cursor not in a number");
* buffer big enough to fit the line changes as well, and only
* allocate once.
*/
- GET_SPACE_RET(sp, bp, blen, len + 50);
+ GET_SPACE_RETW(sp, bp, blen, len + 50);
if (end == len) {
- memmove(bp, &p[beg], wlen);
+ MEMMOVE(bp, &p[beg], wlen);
bp[wlen] = '\0';
t = bp;
} else
@@ -203,7 +202,7 @@ nonum: msgq(sp, M_ERR, "181|Cursor not in a number");
/* If we cross 0, signed numbers lose their sign. */
if (lval == 0 && ntype == fmt[SDEC])
ntype = fmt[DEC];
- nlen = snprintf(nbuf, sizeof(nbuf), ntype, lval);
+ nlen = SPRINTF(nbuf, sizeof(nbuf), ntype, lval);
} else {
if ((nret = nget_uslong(&ulval, t, NULL, base)) != NUM_OK)
goto err;
@@ -225,13 +224,13 @@ nonum: msgq(sp, M_ERR, "181|Cursor not in a number");
if (base == 16)
wlen -= 2;
- nlen = snprintf(nbuf, sizeof(nbuf), ntype, wlen, ulval);
+ nlen = SPRINTF(nbuf, sizeof(nbuf), ntype, wlen, ulval);
}
/* Build the new line. */
- memmove(bp, p, beg);
- memmove(bp + beg, nbuf, nlen);
- memmove(bp + beg + nlen, p + end, len - beg - (end - beg));
+ MEMMOVE(bp, p, beg);
+ MEMMOVE(bp + beg, nbuf, nlen);
+ MEMMOVE(bp + beg + nlen, p + end, len - beg - (end - beg));
len = beg + nlen + (len - beg - (end - beg));
nret = NUM_OK;
@@ -242,14 +241,12 @@ err: rval = 1;
inc_err(sp, nret);
}
if (bp != NULL)
- FREE_SPACE(sp, bp, blen);
+ FREE_SPACEW(sp, bp, blen);
return (rval);
}
static void
-inc_err(sp, nret)
- SCR *sp;
- enum nresult nret;
+inc_err(SCR *sp, enum nresult nret)
{
switch (nret) {
case NUM_ERR:
diff --git a/contrib/nvi/vi/v_init.c b/contrib/nvi/vi/v_init.c
index ee58de3..e47a821 100644
--- a/contrib/nvi/vi/v_init.c
+++ b/contrib/nvi/vi/v_init.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_init.c 10.8 (Berkeley) 3/30/96";
+static const char sccsid[] = "$Id: v_init.c,v 10.10 2012/02/11 00:33:46 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -34,8 +34,7 @@ static const char sccsid[] = "@(#)v_init.c 10.8 (Berkeley) 3/30/96";
* PUBLIC: int v_screen_copy __P((SCR *, SCR *));
*/
int
-v_screen_copy(orig, sp)
- SCR *orig, *sp;
+v_screen_copy(SCR *orig, SCR *sp)
{
VI_PRIVATE *ovip, *nvip;
@@ -58,6 +57,11 @@ v_screen_copy(orig, sp)
nvip->rep_len = ovip->rep_len;
}
+ /* Copy the match characters information. */
+ if (ovip->mcs != NULL && (nvip->mcs =
+ v_wstrdup(sp, ovip->mcs, STRLEN(ovip->mcs))) == NULL)
+ return (1);
+
/* Copy the paragraph/section information. */
if (ovip->ps != NULL && (nvip->ps =
v_strdup(sp, ovip->ps, strlen(ovip->ps))) == NULL)
@@ -78,8 +82,7 @@ v_screen_copy(orig, sp)
* PUBLIC: int v_screen_end __P((SCR *));
*/
int
-v_screen_end(sp)
- SCR *sp;
+v_screen_end(SCR *sp)
{
VI_PRIVATE *vip;
@@ -89,6 +92,8 @@ v_screen_end(sp)
free(vip->keyw);
if (vip->rep != NULL)
free(vip->rep);
+ if (vip->mcs != NULL)
+ free(vip->mcs);
if (vip->ps != NULL)
free(vip->ps);
@@ -108,13 +113,11 @@ v_screen_end(sp)
* PUBLIC: int v_optchange __P((SCR *, int, char *, u_long *));
*/
int
-v_optchange(sp, offset, str, valp)
- SCR *sp;
- int offset;
- char *str;
- u_long *valp;
+v_optchange(SCR *sp, int offset, char *str, u_long *valp)
{
switch (offset) {
+ case O_MATCHCHARS:
+ return (v_buildmcs(sp, str));
case O_PARAGRAPHS:
return (v_buildps(sp, str, O_STR(sp, O_SECTIONS)));
case O_SECTIONS:
diff --git a/contrib/nvi/vi/v_itxt.c b/contrib/nvi/vi/v_itxt.c
index 6cf9377..8b26329 100644
--- a/contrib/nvi/vi/v_itxt.c
+++ b/contrib/nvi/vi/v_itxt.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_itxt.c 10.16 (Berkeley) 10/23/96";
+static const char sccsid[] = "$Id: v_itxt.c,v 10.21 2001/06/25 15:19:32 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -66,9 +66,7 @@ static u_int32_t set_txt_std __P((SCR *, VICMD *, u_int32_t));
* PUBLIC: int v_iA __P((SCR *, VICMD *));
*/
int
-v_iA(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_iA(SCR *sp, VICMD *vp)
{
size_t len;
@@ -88,14 +86,12 @@ v_iA(sp, vp)
* PUBLIC: int v_ia __P((SCR *, VICMD *));
*/
int
-v_ia(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_ia(SCR *sp, VICMD *vp)
{
size_t len;
u_int32_t flags;
int isempty;
- char *p;
+ CHAR_T *p;
flags = set_txt_std(sp, vp, 0);
sp->showmode = SM_APPEND;
@@ -127,9 +123,7 @@ v_ia(sp, vp)
* PUBLIC: int v_iI __P((SCR *, VICMD *));
*/
int
-v_iI(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_iI(SCR *sp, VICMD *vp)
{
sp->cno = 0;
if (nonblank(sp, vp->m_start.lno, &sp->cno))
@@ -148,14 +142,12 @@ v_iI(sp, vp)
* PUBLIC: int v_ii __P((SCR *, VICMD *));
*/
int
-v_ii(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_ii(SCR *sp, VICMD *vp)
{
size_t len;
u_int32_t flags;
int isempty;
- char *p;
+ CHAR_T *p;
flags = set_txt_std(sp, vp, 0);
sp->showmode = SM_INSERT;
@@ -183,9 +175,7 @@ static int io __P((SCR *, VICMD *, enum which));
* PUBLIC: int v_iO __P((SCR *, VICMD *));
*/
int
-v_iO(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_iO(SCR *sp, VICMD *vp)
{
return (io(sp, vp, O_cmd));
}
@@ -197,23 +187,18 @@ v_iO(sp, vp)
* PUBLIC: int v_io __P((SCR *, VICMD *));
*/
int
-v_io(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_io(SCR *sp, VICMD *vp)
{
return (io(sp, vp, o_cmd));
}
static int
-io(sp, vp, cmd)
- SCR *sp;
- VICMD *vp;
- enum which cmd;
+io(SCR *sp, VICMD *vp, enum which cmd)
{
recno_t ai_line, lno;
size_t len;
u_int32_t flags;
- char *p;
+ CHAR_T *p;
flags = set_txt_std(sp, vp, TXT_ADDNEWLINE | TXT_APPENDEOL);
sp->showmode = SM_INSERT;
@@ -227,7 +212,7 @@ io(sp, vp, cmd)
len = 0;
ai_line = OOBLNO;
} else {
-insert: p = "";
+insert: p = L("");
sp->cno = 0;
LOG_CORRECT;
@@ -258,14 +243,13 @@ insert: p = "";
* PUBLIC: int v_change __P((SCR *, VICMD *));
*/
int
-v_change(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_change(SCR *sp, VICMD *vp)
{
size_t blen, len;
u_int32_t flags;
int isempty, lmode, rval;
- char *bp, *p;
+ CHAR_T *bp;
+ CHAR_T *p;
/*
* 'c' can be combined with motion commands that set the resulting
@@ -356,8 +340,8 @@ v_change(sp, vp)
*/
if (db_get(sp, vp->m_start.lno, DBG_FATAL, &p, &len))
return (1);
- GET_SPACE_RET(sp, bp, blen, vp->m_start.cno);
- memmove(bp, p, vp->m_start.cno);
+ GET_SPACE_RETW(sp, bp, blen, vp->m_start.cno);
+ MEMMOVE(bp, p, vp->m_start.cno);
} else
bp = NULL;
@@ -388,7 +372,7 @@ v_change(sp, vp)
0, OOBLNO, F_ISSET(vp, VC_C1SET) ? vp->count : 1, flags);
if (bp != NULL)
- FREE_SPACE(sp, bp, blen);
+ FREE_SPACEW(sp, bp, blen);
return (rval);
}
@@ -399,14 +383,12 @@ v_change(sp, vp)
* PUBLIC: int v_Replace __P((SCR *, VICMD *));
*/
int
-v_Replace(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_Replace(SCR *sp, VICMD *vp)
{
size_t len;
u_int32_t flags;
int isempty;
- char *p;
+ CHAR_T *p;
flags = set_txt_std(sp, vp, 0);
sp->showmode = SM_REPLACE;
@@ -435,14 +417,12 @@ v_Replace(sp, vp)
* PUBLIC: int v_subst __P((SCR *, VICMD *));
*/
int
-v_subst(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_subst(SCR *sp, VICMD *vp)
{
size_t len;
u_int32_t flags;
int isempty;
- char *p;
+ CHAR_T *p;
flags = set_txt_std(sp, vp, 0);
sp->showmode = SM_CHANGE;
@@ -477,10 +457,7 @@ v_subst(sp, vp)
* Initialize text processing flags.
*/
static u_int32_t
-set_txt_std(sp, vp, flags)
- SCR *sp;
- VICMD *vp;
- u_int32_t flags;
+set_txt_std(SCR *sp, VICMD *vp, u_int32_t flags)
{
LF_SET(TXT_CNTRLT |
TXT_ESCAPE | TXT_MAPINPUT | TXT_RECORD | TXT_RESOLVE);
diff --git a/contrib/nvi/vi/v_left.c b/contrib/nvi/vi/v_left.c
index cfed80c..2a8f6e6 100644
--- a/contrib/nvi/vi/v_left.c
+++ b/contrib/nvi/vi/v_left.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_left.c 10.7 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_left.c,v 10.9 2001/06/25 15:19:32 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -31,9 +31,7 @@ static const char sccsid[] = "@(#)v_left.c 10.7 (Berkeley) 3/6/96";
* PUBLIC: int v_left __P((SCR *, VICMD *));
*/
int
-v_left(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_left(SCR *sp, VICMD *vp)
{
recno_t cnt;
@@ -71,9 +69,7 @@ v_left(sp, vp)
* PUBLIC: int v_cfirst __P((SCR *, VICMD *));
*/
int
-v_cfirst(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_cfirst(SCR *sp, VICMD *vp)
{
recno_t cnt, lno;
@@ -140,9 +136,7 @@ v_cfirst(sp, vp)
* PUBLIC: int v_first __P((SCR *, VICMD *));
*/
int
-v_first(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_first(SCR *sp, VICMD *vp)
{
/*
* !!!
@@ -204,9 +198,7 @@ v_first(sp, vp)
* PUBLIC: int v_ncol __P((SCR *, VICMD *));
*/
int
-v_ncol(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_ncol(SCR *sp, VICMD *vp)
{
if (F_ISSET(vp, VC_C1SET) && vp->count > 1) {
--vp->count;
@@ -266,9 +258,7 @@ v_ncol(sp, vp)
* PUBLIC: int v_zero __P((SCR *, VICMD *));
*/
int
-v_zero(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_zero(SCR *sp, VICMD *vp)
{
/*
* !!!
diff --git a/contrib/nvi/vi/v_mark.c b/contrib/nvi/vi/v_mark.c
index 447430e..39ed0aa 100644
--- a/contrib/nvi/vi/v_mark.c
+++ b/contrib/nvi/vi/v_mark.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_mark.c 10.8 (Berkeley) 9/20/96";
+static const char sccsid[] = "$Id: v_mark.c,v 10.12 2001/06/25 15:19:32 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -25,6 +25,9 @@ static const char sccsid[] = "@(#)v_mark.c 10.8 (Berkeley) 9/20/96";
#include "../common/common.h"
#include "vi.h"
+enum which {BQMARK, FQMARK};
+static int mark __P((SCR *, VICMD *, int, enum which));
+
/*
* v_mark -- m[a-z]
* Set a mark.
@@ -32,17 +35,11 @@ static const char sccsid[] = "@(#)v_mark.c 10.8 (Berkeley) 9/20/96";
* PUBLIC: int v_mark __P((SCR *, VICMD *));
*/
int
-v_mark(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_mark(SCR *sp, VICMD *vp)
{
return (mark_set(sp, vp->character, &vp->m_start, 1));
}
-enum which {BQMARK, FQMARK};
-static int mark __P((SCR *, VICMD *, enum which));
-
-
/*
* v_bmark -- `['`a-z]
* Move to a mark.
@@ -59,11 +56,9 @@ static int mark __P((SCR *, VICMD *, enum which));
* PUBLIC: int v_bmark __P((SCR *, VICMD *));
*/
int
-v_bmark(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_bmark(SCR *sp, VICMD *vp)
{
- return (mark(sp, vp, BQMARK));
+ return (mark(sp, vp, 1, BQMARK));
}
/*
@@ -75,11 +70,31 @@ v_bmark(sp, vp)
* PUBLIC: int v_fmark __P((SCR *, VICMD *));
*/
int
-v_fmark(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_fmark(SCR *sp, VICMD *vp)
{
- return (mark(sp, vp, FQMARK));
+ return (mark(sp, vp, 1, FQMARK));
+}
+
+/*
+ * v_emark -- <mouse click>
+ * Mouse mark.
+ *
+ * PUBLIC: int v_emark __P((SCR *, VICMD *));
+ */
+int
+v_emark(SCR *sp, VICMD *vp)
+{
+ SMAP *smp;
+
+ smp = HMAP + vp->ev.e_lno;
+ if (smp > TMAP) {
+ msgq(sp, M_BERR, "320|Unknown cursor position.");
+ return (1);
+ }
+ vp->m_stop.lno = smp->lno;
+ vp->m_stop.cno =
+ vs_colpos(sp, smp->lno, vp->ev.e_cno + (smp->soff - 1) * sp->cols);
+ return (mark(sp, vp, 0, BQMARK));
}
/*
@@ -87,16 +102,13 @@ v_fmark(sp, vp)
* Mark commands.
*/
static int
-mark(sp, vp, cmd)
- SCR *sp;
- VICMD *vp;
- enum which cmd;
+mark(SCR *sp, VICMD *vp, int getmark, enum which cmd)
{
dir_t dir;
MARK m;
size_t len;
- if (mark_get(sp, vp->character, &vp->m_stop, M_BERR))
+ if (getmark && mark_get(sp, vp->character, &vp->m_stop, M_BERR))
return (1);
/*
@@ -111,7 +123,7 @@ mark(sp, vp, cmd)
if (db_get(sp, vp->m_stop.lno, DBG_FATAL, NULL, &len))
return (1);
if (vp->m_stop.cno < len ||
- vp->m_stop.cno == len && len == 0)
+ (vp->m_stop.cno == len && len == 0))
break;
if (ISMOTION(vp))
@@ -152,8 +164,8 @@ mark(sp, vp, cmd)
* and backward motions can happen for any kind of search command.
*/
if (vp->m_start.lno > vp->m_stop.lno ||
- vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno > vp->m_stop.cno) {
+ (vp->m_start.lno == vp->m_stop.lno &&
+ vp->m_start.cno > vp->m_stop.cno)) {
m = vp->m_start;
vp->m_start = vp->m_stop;
vp->m_stop = m;
@@ -187,15 +199,15 @@ mark(sp, vp, cmd)
#ifdef HISTORICAL_PRACTICE
if (ISCMD(vp->rkp, 'y')) {
if ((cmd == BQMARK ||
- cmd == FQMARK && vp->m_start.lno != vp->m_stop.lno) &&
+ (cmd == FQMARK && vp->m_start.lno != vp->m_stop.lno)) &&
(vp->m_start.lno > vp->m_stop.lno ||
- vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno > vp->m_stop.cno))
+ (vp->m_start.lno == vp->m_stop.lno &&
+ vp->m_start.cno > vp->m_stop.cno)))
vp->m_final = vp->m_stop;
} else if (ISCMD(vp->rkp, 'd'))
if (vp->m_start.lno > vp->m_stop.lno ||
- vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno > vp->m_stop.cno)
+ (vp->m_start.lno == vp->m_stop.lno &&
+ vp->m_start.cno > vp->m_stop.cno))
vp->m_final = vp->m_stop;
#else
vp->m_final = vp->m_start;
diff --git a/contrib/nvi/vi/v_match.c b/contrib/nvi/vi/v_match.c
index 3996560..2fae58e 100644
--- a/contrib/nvi/vi/v_match.c
+++ b/contrib/nvi/vi/v_match.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_match.c 10.8 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_match.c,v 10.11 2012/02/11 00:33:46 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -18,8 +18,10 @@ static const char sccsid[] = "@(#)v_match.c 10.8 (Berkeley) 3/6/96";
#include <sys/time.h>
#include <bitstring.h>
+#include <ctype.h>
#include <limits.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "../common/common.h"
@@ -32,15 +34,23 @@ static const char sccsid[] = "@(#)v_match.c 10.8 (Berkeley) 3/6/96";
* PUBLIC: int v_match __P((SCR *, VICMD *));
*/
int
-v_match(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_match(SCR *sp, VICMD *vp)
{
VCS cs;
MARK *mp;
size_t cno, len, off;
int cnt, isempty, matchc, startc, (*gc)__P((SCR *, VCS *));
- char *p;
+ CHAR_T *p;
+ CHAR_T *cp;
+ const CHAR_T *match_chars;
+
+ /*
+ * Historically vi would match (), {} and [] however
+ * an update included <>. This is ok for editing HTML
+ * but a pain in the butt for C source.
+ * Making it an option lets the user decide what is 'right'.
+ */
+ match_chars = VIP(sp)->mcs;
/*
* !!!
@@ -60,43 +70,14 @@ v_match(sp, vp)
nomatch: msgq(sp, M_BERR, "184|No match character on this line");
return (1);
}
- switch (startc = p[off]) {
- case '(':
- matchc = ')';
- gc = cs_next;
- break;
- case ')':
- matchc = '(';
- gc = cs_prev;
- break;
- case '[':
- matchc = ']';
- gc = cs_next;
- break;
- case ']':
- matchc = '[';
- gc = cs_prev;
+ startc = p[off];
+ cp = STRCHR(match_chars, startc);
+ if (cp != NULL) {
+ cnt = cp - match_chars;
+ matchc = match_chars[cnt ^ 1];
+ gc = cnt & 1 ? cs_prev : cs_next;
break;
- case '{':
- matchc = '}';
- gc = cs_next;
- break;
- case '}':
- matchc = '{';
- gc = cs_prev;
- break;
- case '<':
- matchc = '>';
- gc = cs_next;
- break;
- case '>':
- matchc = '<';
- gc = cs_prev;
- break;
- default:
- continue;
}
- break;
}
cs.cs_lno = vp->m_start.lno;
@@ -135,8 +116,8 @@ nomatch: msgq(sp, M_BERR, "184|No match character on this line");
* starting cursor position when deleting to a match.
*/
if (vp->m_start.lno < vp->m_stop.lno ||
- vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno < vp->m_stop.cno)
+ (vp->m_start.lno == vp->m_stop.lno &&
+ vp->m_start.cno < vp->m_stop.cno))
vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
else
vp->m_final = vp->m_stop;
@@ -168,3 +149,29 @@ nomatch: msgq(sp, M_BERR, "184|No match character on this line");
F_SET(vp, VM_LMODE);
return (0);
}
+
+/*
+ * v_buildmcs --
+ * Build the match character list.
+ *
+ * PUBLIC: int v_buildmcs __P((SCR *, char *));
+ */
+int
+v_buildmcs(SCR *sp, char *str)
+{
+ CHAR_T **mp = &VIP(sp)->mcs;
+ size_t len = strlen(str) + 1;
+
+ if (*mp != NULL)
+ free(*mp);
+ MALLOC(sp, *mp, CHAR_T *, len * sizeof(CHAR_T));
+ if (*mp == NULL)
+ return (1);
+#ifdef USE_WIDECHAR
+ if (mbstowcs(*mp, str, len) == (size_t)-1)
+ return (1);
+#else
+ memcpy(*mp, str, len);
+#endif
+ return (0);
+}
diff --git a/contrib/nvi/vi/v_paragraph.c b/contrib/nvi/vi/v_paragraph.c
index 762e38e..4ff4b15 100644
--- a/contrib/nvi/vi/v_paragraph.c
+++ b/contrib/nvi/vi/v_paragraph.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_paragraph.c 10.7 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_paragraph.c,v 10.10 2001/06/25 15:19:32 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -64,15 +64,14 @@ static const char sccsid[] = "@(#)v_paragraph.c 10.7 (Berkeley) 3/6/96";
* PUBLIC: int v_paragraphf __P((SCR *, VICMD *));
*/
int
-v_paragraphf(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_paragraphf(SCR *sp, VICMD *vp)
{
enum { P_INTEXT, P_INBLANK } pstate;
size_t lastlen, len;
recno_t cnt, lastlno, lno;
int isempty;
- char *p, *lp;
+ CHAR_T *p;
+ char *lp;
/*
* !!!
@@ -203,14 +202,13 @@ eof: if (vp->m_start.lno == lno || vp->m_start.lno == lno - 1) {
* PUBLIC: int v_paragraphb __P((SCR *, VICMD *));
*/
int
-v_paragraphb(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_paragraphb(SCR *sp, VICMD *vp)
{
enum { P_INTEXT, P_INBLANK } pstate;
size_t len;
recno_t cnt, lno;
- char *p, *lp;
+ CHAR_T *p;
+ char *lp;
/*
* !!!
@@ -311,9 +309,7 @@ found: vp->m_stop.lno = lno;
* PUBLIC: int v_buildps __P((SCR *, char *, char *));
*/
int
-v_buildps(sp, p_p, s_p)
- SCR *sp;
- char *p_p, *s_p;
+v_buildps(SCR *sp, char *p_p, char *s_p)
{
VI_PRIVATE *vip;
size_t p_len, s_len;
diff --git a/contrib/nvi/vi/v_put.c b/contrib/nvi/vi/v_put.c
index 77220ea..a739bd1 100644
--- a/contrib/nvi/vi/v_put.c
+++ b/contrib/nvi/vi/v_put.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_put.c 10.5 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_put.c,v 10.6 2001/06/25 15:19:34 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -33,9 +33,7 @@ static void inc_buf __P((SCR *, VICMD *));
* PUBLIC: int v_Put __P((SCR *, VICMD *));
*/
int
-v_Put(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_Put(SCR *sp, VICMD *vp)
{
u_long cnt;
@@ -66,9 +64,7 @@ v_Put(sp, vp)
* PUBLIC: int v_put __P((SCR *, VICMD *));
*/
int
-v_put(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_put(SCR *sp, VICMD *vp)
{
u_long cnt;
@@ -108,9 +104,7 @@ v_put(sp, vp)
* the buffer increment gets done regardless of the success of the put.
*/
static void
-inc_buf(sp, vp)
- SCR *sp;
- VICMD *vp;
+inc_buf(SCR *sp, VICMD *vp)
{
CHAR_T v;
diff --git a/contrib/nvi/vi/v_redraw.c b/contrib/nvi/vi/v_redraw.c
index 4c965c7..979f37c 100644
--- a/contrib/nvi/vi/v_redraw.c
+++ b/contrib/nvi/vi/v_redraw.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_redraw.c 10.6 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_redraw.c,v 10.7 2001/06/25 15:19:34 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -31,9 +31,7 @@ static const char sccsid[] = "@(#)v_redraw.c 10.6 (Berkeley) 3/6/96";
* PUBLIC: int v_redraw __P((SCR *, VICMD *));
*/
int
-v_redraw(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_redraw(SCR *sp, VICMD *vp)
{
return (sp->gp->scr_refresh(sp, 1));
}
diff --git a/contrib/nvi/vi/v_replace.c b/contrib/nvi/vi/v_replace.c
index a4712b6..2a7ea97 100644
--- a/contrib/nvi/vi/v_replace.c
+++ b/contrib/nvi/vi/v_replace.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_replace.c 10.17 (Berkeley) 6/30/96";
+static const char sccsid[] = "$Id: v_replace.c,v 10.24 2001/06/25 15:19:34 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -43,9 +43,7 @@ static const char sccsid[] = "@(#)v_replace.c 10.17 (Berkeley) 6/30/96";
* PUBLIC: int v_replace __P((SCR *, VICMD *));
*/
int
-v_replace(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_replace(SCR *sp, VICMD *vp)
{
EVENT ev;
VI_PRIVATE *vip;
@@ -53,7 +51,8 @@ v_replace(sp, vp)
size_t blen, len;
u_long cnt;
int quote, rval;
- char *bp, *p;
+ CHAR_T *bp;
+ CHAR_T *p;
vip = VIP(sp);
@@ -144,8 +143,8 @@ next: if (v_event_get(sp, &ev, 0, 0))
}
/* Copy the line. */
- GET_SPACE_RET(sp, bp, blen, len);
- memmove(bp, p, len);
+ GET_SPACE_RETW(sp, bp, blen, len);
+ MEMMOVE(bp, p, len);
p = bp;
/*
@@ -154,7 +153,7 @@ next: if (v_event_get(sp, &ev, 0, 0))
* is different from the historic vi, which replaced N characters with
* a single new line. Users complained, so we match historic practice.
*/
- if (!quote && vip->rvalue == K_CR || vip->rvalue == K_NL) {
+ if ((!quote && vip->rvalue == K_CR) || vip->rvalue == K_NL) {
/* Set return line. */
vp->m_stop.lno = vp->m_start.lno + 1;
vp->m_stop.cno = 0;
@@ -193,10 +192,10 @@ err_ret: rval = 1;
rval = 0;
}
} else {
- memset(bp + vp->m_start.cno, vip->rlast, cnt);
+ STRSET(bp + vp->m_start.cno, vip->rlast, cnt);
rval = db_set(sp, vp->m_start.lno, bp, len);
}
- FREE_SPACE(sp, bp, blen);
+ FREE_SPACEW(sp, bp, blen);
vp->m_final = vp->m_stop;
return (rval);
diff --git a/contrib/nvi/vi/v_right.c b/contrib/nvi/vi/v_right.c
index c2f349e..566f952 100644
--- a/contrib/nvi/vi/v_right.c
+++ b/contrib/nvi/vi/v_right.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_right.c 10.7 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_right.c,v 10.8 2001/06/25 15:19:34 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -31,9 +31,7 @@ static const char sccsid[] = "@(#)v_right.c 10.7 (Berkeley) 3/6/96";
* PUBLIC: int v_right __P((SCR *, VICMD *));
*/
int
-v_right(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_right(SCR *sp, VICMD *vp)
{
size_t len;
int isempty;
@@ -83,9 +81,7 @@ eol: v_eol(sp, NULL);
* PUBLIC: int v_dollar __P((SCR *, VICMD *));
*/
int
-v_dollar(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_dollar(SCR *sp, VICMD *vp)
{
size_t len;
int isempty;
diff --git a/contrib/nvi/vi/v_screen.c b/contrib/nvi/vi/v_screen.c
index 85cd1e3..d7932a4 100644
--- a/contrib/nvi/vi/v_screen.c
+++ b/contrib/nvi/vi/v_screen.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_screen.c 10.10 (Berkeley) 4/27/96";
+static const char sccsid[] = "$Id: v_screen.c,v 10.12 2001/06/25 15:19:34 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -31,9 +31,7 @@ static const char sccsid[] = "@(#)v_screen.c 10.10 (Berkeley) 4/27/96";
* PUBLIC: int v_screen __P((SCR *, VICMD *));
*/
int
-v_screen(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_screen(SCR *sp, VICMD *vp)
{
/*
* You can't leave a colon command-line edit window -- it's not that
@@ -51,13 +49,13 @@ v_screen(sp, vp)
* Try for the next lower screen, or, go back to the first
* screen on the stack.
*/
- if (sp->q.cqe_next != (void *)&sp->gp->dq)
- sp->nextdisp = sp->q.cqe_next;
- else if (sp->gp->dq.cqh_first == sp) {
+ if (TAILQ_NEXT(sp, q) != NULL)
+ sp->nextdisp = TAILQ_NEXT(sp, q);
+ else if (TAILQ_FIRST(sp->gp->dq) == sp) {
msgq(sp, M_ERR, "187|No other screen to switch to");
return (1);
} else
- sp->nextdisp = sp->gp->dq.cqh_first;
+ sp->nextdisp = TAILQ_FIRST(sp->gp->dq);
F_SET(sp->nextdisp, SC_STATUS);
F_SET(sp, SC_SSWITCH | SC_STATUS);
diff --git a/contrib/nvi/vi/v_scroll.c b/contrib/nvi/vi/v_scroll.c
index 92def4b..71528a0 100644
--- a/contrib/nvi/vi/v_scroll.c
+++ b/contrib/nvi/vi/v_scroll.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_scroll.c 10.9 (Berkeley) 4/27/96";
+static const char sccsid[] = "$Id: v_scroll.c,v 10.12 2001/06/25 15:19:34 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -67,9 +67,7 @@ static void goto_adjust __P((VICMD *));
* PUBLIC: int v_lgoto __P((SCR *, VICMD *));
*/
int
-v_lgoto(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_lgoto(SCR *sp, VICMD *vp)
{
recno_t nlines;
@@ -106,9 +104,7 @@ v_lgoto(sp, vp)
* PUBLIC: int v_home __P((SCR *, VICMD *));
*/
int
-v_home(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_home(SCR *sp, VICMD *vp)
{
if (vs_sm_position(sp, &vp->m_stop,
F_ISSET(vp, VC_C1SET) ? vp->count - 1 : 0, P_TOP))
@@ -125,9 +121,7 @@ v_home(sp, vp)
* PUBLIC: int v_middle __P((SCR *, VICMD *));
*/
int
-v_middle(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_middle(SCR *sp, VICMD *vp)
{
/*
* Yielding to none in our quest for compatibility with every
@@ -148,9 +142,7 @@ v_middle(sp, vp)
* PUBLIC: int v_bottom __P((SCR *, VICMD *));
*/
int
-v_bottom(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_bottom(SCR *sp, VICMD *vp)
{
if (vs_sm_position(sp, &vp->m_stop,
F_ISSET(vp, VC_C1SET) ? vp->count - 1 : 0, P_BOTTOM))
@@ -160,8 +152,7 @@ v_bottom(sp, vp)
}
static void
-goto_adjust(vp)
- VICMD *vp;
+goto_adjust(VICMD *vp)
{
/* Guess that it's the end of the range. */
vp->m_final = vp->m_stop;
@@ -199,8 +190,8 @@ goto_adjust(vp)
* stay at the start of the range. Ignore others.
*/
if (vp->m_stop.lno < vp->m_start.lno ||
- vp->m_stop.lno == vp->m_start.lno &&
- vp->m_stop.cno < vp->m_start.cno) {
+ (vp->m_stop.lno == vp->m_start.lno &&
+ vp->m_stop.cno < vp->m_start.cno)) {
if (ISCMD(vp->rkp, 'y') && vp->m_stop.lno == vp->m_start.lno)
vp->m_final = vp->m_start;
} else
@@ -214,9 +205,7 @@ goto_adjust(vp)
* PUBLIC: int v_up __P((SCR *, VICMD *));
*/
int
-v_up(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_up(SCR *sp, VICMD *vp)
{
recno_t lno;
@@ -238,9 +227,7 @@ v_up(sp, vp)
* PUBLIC: int v_cr __P((SCR *, VICMD *));
*/
int
-v_cr(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_cr(SCR *sp, VICMD *vp)
{
/* If it's a colon command-line edit window, it's an ex command. */
if (F_ISSET(sp, SC_COMEDIT))
@@ -261,9 +248,7 @@ v_cr(sp, vp)
* PUBLIC: int v_down __P((SCR *, VICMD *));
*/
int
-v_down(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_down(SCR *sp, VICMD *vp)
{
recno_t lno;
@@ -284,9 +269,7 @@ v_down(sp, vp)
* PUBLIC: int v_hpageup __P((SCR *, VICMD *));
*/
int
-v_hpageup(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_hpageup(SCR *sp, VICMD *vp)
{
/*
* Half screens always succeed unless already at SOF.
@@ -310,9 +293,7 @@ v_hpageup(sp, vp)
* PUBLIC: int v_hpagedown __P((SCR *, VICMD *));
*/
int
-v_hpagedown(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_hpagedown(SCR *sp, VICMD *vp)
{
/*
* Half screens always succeed unless already at EOF.
@@ -340,9 +321,7 @@ v_hpagedown(sp, vp)
* PUBLIC: int v_pagedown __P((SCR *, VICMD *));
*/
int
-v_pagedown(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_pagedown(SCR *sp, VICMD *vp)
{
recno_t offset;
@@ -361,8 +340,8 @@ v_pagedown(sp, vp)
* any screen but the "next" one anyway. We do it the historical
* way as there's no good reason to change it.
*
- * If the screen has been split, use the smaller of the current
- * window size and the window option value.
+ * If the screen has been split horizontally, use the smaller of
+ * the current window size and the window option value.
*
* It possible for this calculation to be less than 1; move at
* least one line.
@@ -388,9 +367,7 @@ v_pagedown(sp, vp)
* PUBLIC: int v_pageup __P((SCR *, VICMD *));
*/
int
-v_pageup(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_pageup(SCR *sp, VICMD *vp)
{
recno_t offset;
@@ -414,8 +391,8 @@ v_pageup(sp, vp)
* but the first screen. We do it the historical way as there's
* no good reason to change it.
*
- * If the screen has been split, use the smaller of the current
- * window size and the window option value.
+ * If the screen has been split horizontally, use the smaller of
+ * the current window size and the window option value.
*
* It possible for this calculation to be less than 1; move at
* least one line.
@@ -436,9 +413,7 @@ v_pageup(sp, vp)
* PUBLIC: int v_lineup __P((SCR *, VICMD *));
*/
int
-v_lineup(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_lineup(SCR *sp, VICMD *vp)
{
/*
* The cursor moves down, staying with its original line, unless it
@@ -458,9 +433,7 @@ v_lineup(sp, vp)
* PUBLIC: int v_linedown __P((SCR *, VICMD *));
*/
int
-v_linedown(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_linedown(SCR *sp, VICMD *vp)
{
/*
* The cursor moves up, staying with its original line, unless it
diff --git a/contrib/nvi/vi/v_search.c b/contrib/nvi/vi/v_search.c
index 4f7a267..1d6b260 100644
--- a/contrib/nvi/vi/v_search.c
+++ b/contrib/nvi/vi/v_search.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_search.c 10.18 (Berkeley) 9/19/96";
+static const char sccsid[] = "$Id: v_search.c,v 10.31 2012/02/08 07:26:59 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -29,7 +29,7 @@ static const char sccsid[] = "@(#)v_search.c 10.18 (Berkeley) 9/19/96";
#include "vi.h"
static int v_exaddr __P((SCR *, VICMD *, dir_t));
-static int v_search __P((SCR *, VICMD *, char *, size_t, u_int, dir_t));
+static int v_search __P((SCR *, VICMD *, CHAR_T *, size_t, u_int, dir_t));
/*
* v_srch -- [count]?RE[? offset]
@@ -38,9 +38,7 @@ static int v_search __P((SCR *, VICMD *, char *, size_t, u_int, dir_t));
* PUBLIC: int v_searchb __P((SCR *, VICMD *));
*/
int
-v_searchb(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_searchb(SCR *sp, VICMD *vp)
{
return (v_exaddr(sp, vp, BACKWARD));
}
@@ -52,9 +50,7 @@ v_searchb(sp, vp)
* PUBLIC: int v_searchf __P((SCR *, VICMD *));
*/
int
-v_searchf(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_searchf(SCR *sp, VICMD *vp)
{
return (v_exaddr(sp, vp, FORWARD));
}
@@ -64,19 +60,19 @@ v_searchf(sp, vp)
* Do a vi search (which is really an ex address).
*/
static int
-v_exaddr(sp, vp, dir)
- SCR *sp;
- VICMD *vp;
- dir_t dir;
+v_exaddr(SCR *sp, VICMD *vp, dir_t dir)
{
- static EXCMDLIST fake = { "search" };
+ static EXCMDLIST fake = { L("search") };
EXCMD *cmdp;
GS *gp;
TEXT *tp;
recno_t s_lno;
size_t len, s_cno, tlen;
int err, nb, type;
- char *cmd, *t, buf[20];
+ char buf[20];
+ CHAR_T *cmd, *t;
+ CHAR_T *w;
+ size_t wlen;
/*
* !!!
@@ -93,7 +89,7 @@ v_exaddr(sp, vp, dir)
(O_ISSET(sp, O_SEARCHINCR) ? TXT_SEARCHINCR : 0)))
return (1);
- tp = sp->tiq.cqh_first;
+ tp = TAILQ_FIRST(sp->tiq);
/* If the user backspaced over the prompt, do nothing. */
if (tp->term == TERM_BS)
@@ -245,7 +241,7 @@ v_exaddr(sp, vp, dir)
/* Default to z+. */
if (!type &&
- v_event_push(sp, NULL, "+", 1, CH_NOMAP | CH_QUOTED))
+ v_event_push(sp, NULL, L("+"), 1, CH_NOMAP | CH_QUOTED))
return (1);
/* Push the user's command. */
@@ -255,7 +251,8 @@ v_exaddr(sp, vp, dir)
/* Push line number so get correct z display. */
tlen = snprintf(buf,
sizeof(buf), "%lu", (u_long)vp->m_stop.lno);
- if (v_event_push(sp, NULL, buf, tlen, CH_NOMAP | CH_QUOTED))
+ CHAR2INT(sp, buf, tlen, w, wlen);
+ if (v_event_push(sp, NULL, w, wlen, CH_NOMAP | CH_QUOTED))
return (1);
/* Don't refresh until after 'z' happens. */
@@ -284,9 +281,7 @@ err2: vp->m_final.lno = s_lno;
* PUBLIC: int v_searchN __P((SCR *, VICMD *));
*/
int
-v_searchN(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_searchN(SCR *sp, VICMD *vp)
{
dir_t dir;
@@ -311,35 +306,82 @@ v_searchN(sp, vp)
* PUBLIC: int v_searchn __P((SCR *, VICMD *));
*/
int
-v_searchn(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_searchn(SCR *sp, VICMD *vp)
{
return (v_search(sp, vp, NULL, 0, SEARCH_PARSE, sp->searchdir));
}
/*
+ * is_special --
+ * Test if the character is special in a basic RE.
+ */
+static int
+is_special(CHAR_T c)
+{
+ /*
+ * !!!
+ * `*' and `$' are ordinary when appear at the beginning of a RE,
+ * but it's safe to distinguish them from the ordinary characters.
+ * The tilde is vi-specific, of course.
+ */
+ return (STRCHR(L(".[*\\^$~"), c) && c);
+}
+
+/*
+ * Rear delimiter for word search when the keyword ends in
+ * (i.e., consists of) a non-word character. See v_searchw below.
+ */
+#define RE_NWSTOP L("([^[:alnum:]_]|$)")
+#define RE_NWSTOP_LEN (SIZE(RE_NWSTOP) - 1)
+
+/*
* v_searchw -- [count]^A
* Search for the word under the cursor.
*
* PUBLIC: int v_searchw __P((SCR *, VICMD *));
*/
int
-v_searchw(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_searchw(SCR *sp, VICMD *vp)
{
size_t blen, len;
int rval;
- char *bp;
+ CHAR_T *bp, *p;
+
+ /* An upper bound for the SIZE of the RE under construction. */
+ len = VIP(sp)->klen + MAX(RE_WSTART_LEN, 1)
+ + MAX(RE_WSTOP_LEN, RE_NWSTOP_LEN);
+ GET_SPACE_RETW(sp, bp, blen, len);
+ p = bp;
+
+ /* Only the first character can be non-word, see v_curword. */
+ if (inword(VIP(sp)->keyw[0])) {
+ MEMCPY(p, RE_WSTART, RE_WSTART_LEN);
+ p += RE_WSTART_LEN;
+ } else if (is_special(VIP(sp)->keyw[0])) {
+ MEMCPY(p, L("\\"), 1);
+ p += 1;
+ }
- len = VIP(sp)->klen + sizeof(RE_WSTART) + sizeof(RE_WSTOP);
- GET_SPACE_RET(sp, bp, blen, len);
- len = snprintf(bp, blen, "%s%s%s", RE_WSTART, VIP(sp)->keyw, RE_WSTOP);
+ MEMCPY(p, VIP(sp)->keyw, VIP(sp)->klen);
+ p += VIP(sp)->klen;
+
+ if (inword(p[-1])) {
+ MEMCPY(p, RE_WSTOP, RE_WSTOP_LEN);
+ p += RE_WSTOP_LEN;
+ } else {
+ /*
+ * The keyword is a single non-word character.
+ * We want it to stay the same when typing ^A several times
+ * in a row, just the way the other cases behave.
+ */
+ MEMCPY(p, RE_NWSTOP, RE_NWSTOP_LEN);
+ p += RE_NWSTOP_LEN;
+ }
+ len = p - bp;
rval = v_search(sp, vp, bp, len, SEARCH_SET, FORWARD);
- FREE_SPACE(sp, bp, blen);
+ FREE_SPACEW(sp, bp, blen);
return (rval);
}
@@ -348,13 +390,7 @@ v_searchw(sp, vp)
* The search commands.
*/
static int
-v_search(sp, vp, ptrn, plen, flags, dir)
- SCR *sp;
- VICMD *vp;
- u_int flags;
- char *ptrn;
- size_t plen;
- dir_t dir;
+v_search(SCR *sp, VICMD *vp, CHAR_T *ptrn, size_t plen, u_int flags, dir_t dir)
{
/* Display messages. */
LF_SET(SEARCH_MSG);
@@ -417,10 +453,7 @@ v_search(sp, vp, ptrn, plen, flags, dir)
* PUBLIC: int v_correct __P((SCR *, VICMD *, int));
*/
int
-v_correct(sp, vp, isdelta)
- SCR *sp;
- VICMD *vp;
- int isdelta;
+v_correct(SCR *sp, VICMD *vp, int isdelta)
{
dir_t dir;
MARK m;
@@ -462,8 +495,8 @@ v_correct(sp, vp, isdelta)
* because of the wrapscan option.
*/
if (vp->m_start.lno > vp->m_stop.lno ||
- vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno > vp->m_stop.cno) {
+ (vp->m_start.lno == vp->m_stop.lno &&
+ vp->m_start.cno > vp->m_stop.cno)) {
m = vp->m_start;
vp->m_start = vp->m_stop;
vp->m_stop = m;
diff --git a/contrib/nvi/vi/v_section.c b/contrib/nvi/vi/v_section.c
index 20e8ff2..e769cda 100644
--- a/contrib/nvi/vi/v_section.c
+++ b/contrib/nvi/vi/v_section.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_section.c 10.7 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_section.c,v 10.10 2001/06/25 15:19:35 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -62,13 +62,12 @@ static const char sccsid[] = "@(#)v_section.c 10.7 (Berkeley) 3/6/96";
* PUBLIC: int v_sectionf __P((SCR *, VICMD *));
*/
int
-v_sectionf(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_sectionf(SCR *sp, VICMD *vp)
{
recno_t cnt, lno;
size_t len;
- char *p, *list, *lp;
+ CHAR_T *p;
+ char *list, *lp;
/* Get the macro list. */
if ((list = O_STR(sp, O_SECTIONS)) == NULL)
@@ -98,7 +97,7 @@ v_sectionf(sp, vp)
for (lno = vp->m_start.lno; !db_get(sp, ++lno, 0, &p, &len);) {
if (len == 0)
continue;
- if (p[0] == '{' || ISMOTION(vp) && p[0] == '}') {
+ if (p[0] == '{' || (ISMOTION(vp) && p[0] == '}')) {
if (!--cnt) {
if (p[0] == '{')
goto adjust1;
@@ -122,7 +121,7 @@ v_sectionf(sp, vp)
continue;
for (lp = list; *lp != '\0'; lp += 2 * sizeof(*lp))
if (lp[0] == p[1] &&
- (lp[1] == ' ' && len == 2 || lp[1] == p[2]) &&
+ ((lp[1] == ' ' && len == 2) || lp[1] == p[2]) &&
!--cnt) {
/*
* !!!
@@ -170,13 +169,12 @@ ret2: if (ISMOTION(vp)) {
* PUBLIC: int v_sectionb __P((SCR *, VICMD *));
*/
int
-v_sectionb(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_sectionb(SCR *sp, VICMD *vp)
{
size_t len;
recno_t cnt, lno;
- char *p, *list, *lp;
+ CHAR_T *p;
+ char *list, *lp;
/* An empty file or starting from line 1 is always illegal. */
if (vp->m_start.lno <= 1) {
@@ -213,7 +211,7 @@ v_sectionb(sp, vp)
continue;
for (lp = list; *lp != '\0'; lp += 2 * sizeof(*lp))
if (lp[0] == p[1] &&
- (lp[1] == ' ' && len == 2 || lp[1] == p[2]) &&
+ ((lp[1] == ' ' && len == 2) || lp[1] == p[2]) &&
!--cnt) {
adjust1: vp->m_stop.lno = lno;
vp->m_stop.cno = 0;
diff --git a/contrib/nvi/vi/v_sentence.c b/contrib/nvi/vi/v_sentence.c
index a3d9376..ddbc6c7 100644
--- a/contrib/nvi/vi/v_sentence.c
+++ b/contrib/nvi/vi/v_sentence.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_sentence.c 10.7 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_sentence.c,v 10.9 2001/06/25 15:19:35 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -52,9 +52,7 @@ static const char sccsid[] = "@(#)v_sentence.c 10.7 (Berkeley) 3/6/96";
* PUBLIC: int v_sentencef __P((SCR *, VICMD *));
*/
int
-v_sentencef(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_sentencef(SCR *sp, VICMD *vp)
{
enum { BLANK, NONE, PERIOD } state;
VCS cs;
@@ -74,7 +72,7 @@ v_sentencef(sp, vp)
* This may not handle " . " correctly, but it's real unclear
* what correctly means in that case.
*/
- if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && isblank(cs.cs_ch)) {
+ if (cs.cs_flags == CS_EMP || (cs.cs_flags == 0 && isblank(cs.cs_ch))) {
if (cs_fblank(sp, &cs))
return (1);
if (--cnt == 0) {
@@ -193,9 +191,7 @@ okret: vp->m_stop.lno = cs.cs_lno;
* PUBLIC: int v_sentenceb __P((SCR *, VICMD *));
*/
int
-v_sentenceb(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_sentenceb(SCR *sp, VICMD *vp)
{
VCS cs;
recno_t slno;
diff --git a/contrib/nvi/vi/v_status.c b/contrib/nvi/vi/v_status.c
index 7095d78..82fe74b 100644
--- a/contrib/nvi/vi/v_status.c
+++ b/contrib/nvi/vi/v_status.c
@@ -10,13 +10,12 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_status.c 10.9 (Berkeley) 5/15/96";
+static const char sccsid[] = "$Id: v_status.c,v 10.10 2001/06/25 15:19:35 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <bitstring.h>
#include <limits.h>
@@ -32,9 +31,7 @@ static const char sccsid[] = "@(#)v_status.c 10.9 (Berkeley) 5/15/96";
* PUBLIC: int v_status __P((SCR *, VICMD *));
*/
int
-v_status(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_status(SCR *sp, VICMD *vp)
{
(void)msgq_status(sp, vp->m_start.lno, MSTAT_SHOWLAST);
return (0);
diff --git a/contrib/nvi/vi/v_txt.c b/contrib/nvi/vi/v_txt.c
index 0cb1ff5..e81e348 100644
--- a/contrib/nvi/vi/v_txt.c
+++ b/contrib/nvi/vi/v_txt.c
@@ -10,13 +10,12 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_txt.c 10.87 (Berkeley) 10/13/96";
+static const char sccsid[] = "$Id: v_txt.c,v 11.5 2013/05/19 20:37:45 bentley Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <bitstring.h>
#include <ctype.h>
@@ -63,11 +62,7 @@ static void txt_unmap __P((SCR *, TEXT *, u_int32_t *));
* PUBLIC: int v_tcmd __P((SCR *, VICMD *, ARG_CHAR_T, u_int));
*/
int
-v_tcmd(sp, vp, prompt, flags)
- SCR *sp;
- VICMD *vp;
- ARG_CHAR_T prompt;
- u_int flags;
+v_tcmd(SCR *sp, VICMD *vp, ARG_CHAR_T prompt, u_int flags)
{
/* Normally, we end up where we started. */
vp->m_final.lno = sp->lno;
@@ -118,8 +113,7 @@ v_tcmd(sp, vp, prompt, flags)
* Initialize the screen map for colon command-line input.
*/
static int
-txt_map_init(sp)
- SCR *sp;
+txt_map_init(SCR *sp)
{
SMAP *esmp;
VI_PRIVATE *vip;
@@ -171,8 +165,7 @@ txt_map_init(sp)
* Reset the screen map for colon command-line input.
*/
static int
-txt_map_end(sp)
- SCR *sp;
+txt_map_end(SCR *sp)
{
VI_PRIVATE *vip;
size_t cnt;
@@ -242,26 +235,26 @@ txt_map_end(sp)
* Vi text input.
*
* PUBLIC: int v_txt __P((SCR *, VICMD *, MARK *,
- * PUBLIC: const char *, size_t, ARG_CHAR_T, recno_t, u_long, u_int32_t));
+ * PUBLIC: const CHAR_T *, size_t, ARG_CHAR_T, recno_t, u_long, u_int32_t));
*/
int
-v_txt(sp, vp, tm, lp, len, prompt, ai_line, rcount, flags)
- SCR *sp;
- VICMD *vp;
- MARK *tm; /* To MARK. */
- const char *lp; /* Input line. */
- size_t len; /* Input line length. */
- ARG_CHAR_T prompt; /* Prompt to display. */
- recno_t ai_line; /* Line number to use for autoindent count. */
- u_long rcount; /* Replay count. */
- u_int32_t flags; /* TXT_* flags. */
+v_txt(
+ SCR *sp,
+ VICMD *vp,
+ MARK *tm, /* To MARK. */
+ const CHAR_T *lp, /* Input line. */
+ size_t len, /* Input line length. */
+ ARG_CHAR_T prompt, /* Prompt to display. */
+ recno_t ai_line, /* Line number to use for autoindent count. */
+ u_long rcount, /* Replay count. */
+ u_int32_t flags) /* TXT_* flags. */
{
- EVENT ev, *evp; /* Current event. */
+ EVENT ev, *evp = NULL; /* Current event. */
EVENT fc; /* File name completion event. */
GS *gp;
TEXT *ntp, *tp; /* Input text structures. */
TEXT ait; /* Autoindent text structure. */
- TEXT wmt; /* Wrapmargin text structure. */
+ TEXT wmt = {{ 0 }}; /* Wrapmargin text structure. */
TEXTH *tiqh;
VI_PRIVATE *vip;
abb_t abb; /* State of abbreviation checks. */
@@ -281,7 +274,8 @@ v_txt(sp, vp, tm, lp, len, prompt, ai_line, rcount, flags)
int showmatch; /* Showmatch set on this character. */
int wm_set, wm_skip; /* Wrapmargin happened, blank skip flags. */
int max, tmp;
- char *p;
+ int nochange;
+ CHAR_T *p;
gp = sp->gp;
vip = VIP(sp);
@@ -298,23 +292,24 @@ v_txt(sp, vp, tm, lp, len, prompt, ai_line, rcount, flags)
* default to 0 -- text_init() handles this.) If changing a line,
* copy it into the TEXT buffer.
*/
- tiqh = &sp->tiq;
- if (tiqh->cqh_first != (void *)tiqh) {
- tp = tiqh->cqh_first;
- if (tp->q.cqe_next != (void *)tiqh || tp->lb_len < len + 32) {
+ tiqh = sp->tiq;
+ if (!TAILQ_EMPTY(tiqh)) {
+ tp = TAILQ_FIRST(tiqh);
+ if (TAILQ_NEXT(tp, q) != NULL || tp->lb_len < len + 32) {
text_lfree(tiqh);
goto newtp;
}
tp->ai = tp->insert = tp->offset = tp->owrite = 0;
if (lp != NULL) {
tp->len = len;
- memmove(tp->lb, lp, len);
+ BINC_RETW(sp, tp->lb, tp->lb_len, len);
+ MEMMOVE(tp->lb, lp, len);
} else
tp->len = 0;
} else {
newtp: if ((tp = text_init(sp, lp, len, len + 32)) == NULL)
return (1);
- CIRCLEQ_INSERT_HEAD(tiqh, tp, q);
+ TAILQ_INSERT_HEAD(tiqh, tp, q);
}
/* Set default termination condition. */
@@ -463,6 +458,7 @@ newtp: if ((tp = text_init(sp, lp, len, len + 32)) == NULL)
/* Other text input mode setup. */
quote = Q_NOTSET;
carat = C_NOTSET;
+ nochange = 0;
FL_INIT(is_flags,
LF_ISSET(TXT_SEARCHINCR) ? IS_RESTART | IS_RUNNING : 0);
filec_redraw = hexcnt = showmatch = 0;
@@ -510,6 +506,15 @@ next: if (v_event_get(sp, evp, 0, ec_flags))
case E_EOF:
F_SET(sp, SC_EXIT_FORCE);
return (1);
+ case E_INTERRUPT:
+ /*
+ * !!!
+ * Historically, <interrupt> exited the user from text input
+ * mode or cancelled a colon command, and returned to command
+ * mode. It also beeped the terminal, but that seems a bit
+ * excessive.
+ */
+ goto k_escape;
case E_REPAINT:
if (vs_repaint(sp, &ev))
return (1);
@@ -517,37 +522,10 @@ next: if (v_event_get(sp, evp, 0, ec_flags))
case E_WRESIZE:
/* <resize> interrupts the input mode. */
v_emsg(sp, NULL, VIM_WRESIZE);
- /* FALLTHROUGH */
+ goto k_escape;
default:
- if (evp->e_event != E_INTERRUPT && evp->e_event != E_WRESIZE)
- v_event_err(sp, evp);
- /*
- * !!!
- * Historically, <interrupt> exited the user from text input
- * mode or cancelled a colon command, and returned to command
- * mode. It also beeped the terminal, but that seems a bit
- * excessive.
- */
- /*
- * If we are recording, morph into <escape> key so that
- * we can repeat the command safely: there is no way to
- * invalidate the repetition of an instance of a command,
- * which would be the alternative possibility.
- * If we are not recording (most likely on the command line),
- * simply discard the input and return to command mode
- * so that an INTERRUPT doesn't become for example a file
- * completion request. -aymeric
- */
- if (LF_ISSET(TXT_RECORD)) {
- evp->e_event = E_CHARACTER;
- evp->e_c = 033;
- evp->e_flags = 0;
- evp->e_value = K_ESCAPE;
- break;
- } else {
- tp->term = TERM_ESC;
- goto k_escape;
- }
+ v_event_err(sp, evp);
+ goto k_escape;
}
/*
@@ -612,13 +590,16 @@ next: if (v_event_get(sp, evp, 0, ec_flags))
/* Check to see if the character fits into the replay buffers. */
if (LF_ISSET(TXT_RECORD)) {
- BINC_GOTO(sp, vip->rep,
+ BINC_GOTO(sp, EVENT, vip->rep,
vip->rep_len, (rcol + 1) * sizeof(EVENT));
vip->rep[rcol++] = *evp;
}
-replay: if (LF_ISSET(TXT_REPLAY))
+replay: if (LF_ISSET(TXT_REPLAY)) {
+ if (rcol == vip->rep_cnt)
+ goto k_escape;
evp = vip->rep + rcol++;
+ }
/* Wrapmargin check for leading space. */
if (wm_skip) {
@@ -669,7 +650,7 @@ replay: if (LF_ISSET(TXT_REPLAY))
* this test delimits the value by any non-hex character. Offset by
* one, we use 0 to mean that we've found <CH_HEX>.
*/
- if (hexcnt > 1 && !isxdigit(evp->e_c)) {
+ if (hexcnt > 1 && !ISXDIGIT(evp->e_c)) {
hexcnt = 0;
if (txt_hex(sp, tp))
goto err;
@@ -691,7 +672,7 @@ k_cr: if (LF_ISSET(TXT_CR)) {
if (vs_change(sp, tp->lno, LINE_RESET))
goto err;
} else if (F_ISSET(sp, SC_SCRIPT))
- (void)v_event_push(sp, NULL, "\r", 1, CH_NOMAP);
+ (void)v_event_push(sp, NULL, L("\r"), 1, CH_NOMAP);
/* Set term condition: if empty. */
if (tp->cno <= tp->offset)
@@ -789,7 +770,7 @@ k_cr: if (LF_ISSET(TXT_CR)) {
if ((ntp = text_init(sp, p,
insert + owrite, insert + owrite + 32)) == NULL)
goto err;
- CIRCLEQ_INSERT_TAIL(&sp->tiq, ntp, q);
+ TAILQ_INSERT_TAIL(sp->tiq, ntp, q);
/* Set up bookkeeping for the new line. */
ntp->insert = insert;
@@ -804,10 +785,11 @@ k_cr: if (LF_ISSET(TXT_CR)) {
* characters may have been erased.
*/
if (LF_ISSET(TXT_AUTOINDENT)) {
- if (carat == C_NOCHANGE) {
+ if (nochange) {
+ nochange = 0;
if (v_txt_auto(sp, OOBLNO, &ait, ait.ai, ntp))
goto err;
- FREE_SPACE(sp, ait.lb, ait.lb_len);
+ FREE_SPACEW(sp, ait.lb, ait.lb_len);
} else
if (v_txt_auto(sp, OOBLNO, tp, tp->cno, ntp))
goto err;
@@ -826,9 +808,9 @@ k_cr: if (LF_ISSET(TXT_CR)) {
if (wmt.offset != 0 ||
wmt.owrite != 0 || wmt.insert != 0) {
#define WMTSPACE wmt.offset + wmt.owrite + wmt.insert
- BINC_GOTO(sp, ntp->lb,
+ BINC_GOTOW(sp, ntp->lb,
ntp->lb_len, ntp->len + WMTSPACE + 32);
- memmove(ntp->lb + ntp->cno, wmt.lb, WMTSPACE);
+ MEMMOVE(ntp->lb + ntp->cno, wmt.lb, WMTSPACE);
ntp->len += WMTSPACE;
ntp->cno += wmt.offset;
ntp->owrite = wmt.owrite;
@@ -839,7 +821,7 @@ k_cr: if (LF_ISSET(TXT_CR)) {
/* New lines are TXT_APPENDEOL. */
if (ntp->owrite == 0 && ntp->insert == 0) {
- BINC_GOTO(sp, ntp->lb, ntp->lb_len, ntp->len + 1);
+ BINC_GOTOW(sp, ntp->lb, ntp->lb_len, ntp->len + 1);
LF_SET(TXT_APPENDEOL);
ntp->lb[ntp->cno] = CH_CURSOR;
++ntp->insert;
@@ -860,6 +842,7 @@ k_cr: if (LF_ISSET(TXT_CR)) {
if (rcount > 1) {
--rcount;
+ vip->rep_cnt = rcol;
rcol = 0;
abb = AB_NOTSET;
LF_CLR(TXT_RECORD);
@@ -902,7 +885,7 @@ k_escape: LINE_RESOLVE;
* characters, and making them into insert characters.
*/
if (LF_ISSET(TXT_REPLACE))
- txt_Rresolve(sp, &sp->tiq, tp, len);
+ txt_Rresolve(sp, sp->tiq, tp, len);
/*
* If there are any overwrite characters, copy down
@@ -910,7 +893,7 @@ k_escape: LINE_RESOLVE;
*/
if (tp->owrite) {
if (tp->insert)
- memmove(tp->lb + tp->cno,
+ MEMMOVE(tp->lb + tp->cno,
tp->lb + tp->cno + tp->owrite, tp->insert);
tp->len -= tp->owrite;
}
@@ -925,10 +908,10 @@ k_escape: LINE_RESOLVE;
* This is wrong, should pass back a length.
*/
if (LF_ISSET(TXT_RESOLVE)) {
- if (txt_resolve(sp, &sp->tiq, flags))
+ if (txt_resolve(sp, sp->tiq, flags))
goto err;
} else {
- BINC_GOTO(sp, tp->lb, tp->lb_len, tp->len + 1);
+ BINC_GOTOW(sp, tp->lb, tp->lb_len, tp->len + 1);
tp->lb[tp->len] = '\0';
}
@@ -972,11 +955,12 @@ k_escape: LINE_RESOLVE;
/* Save the ai string for later. */
ait.lb = NULL;
ait.lb_len = 0;
- BINC_GOTO(sp, ait.lb, ait.lb_len, tp->ai);
- memmove(ait.lb, tp->lb, tp->ai);
+ BINC_GOTOW(sp, ait.lb, ait.lb_len, tp->ai);
+ MEMMOVE(ait.lb, tp->lb, tp->ai);
ait.ai = ait.len = tp->ai;
- carat = C_NOCHANGE;
+ carat = C_NOTSET;
+ nochange = 1;
goto leftmargin;
case C_ZEROSET: /* 0^D */
if (tp->ai == 0 || tp->cno > tp->ai + tp->offset + 1)
@@ -1011,7 +995,7 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
*/
if (tp->cno == 0) {
if ((ntp =
- txt_backup(sp, &sp->tiq, tp, &flags)) == NULL)
+ txt_backup(sp, sp->tiq, tp, &flags)) == NULL)
goto err;
tp = ntp;
break;
@@ -1063,7 +1047,7 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
*/
if (tp->cno == 0) {
if ((ntp =
- txt_backup(sp, &sp->tiq, tp, &flags)) == NULL)
+ txt_backup(sp, sp->tiq, tp, &flags)) == NULL)
goto err;
tp = ntp;
}
@@ -1093,7 +1077,7 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
}
/* Skip over trailing space characters. */
- while (tp->cno > max && isblank(tp->lb[tp->cno - 1])) {
+ while (tp->cno > max && ISBLANK(tp->lb[tp->cno - 1])) {
--tp->cno;
++tp->owrite;
}
@@ -1122,12 +1106,12 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
*/
if (LF_ISSET(TXT_TTYWERASE))
while (tp->cno > max) {
+ if (ISBLANK(tp->lb[tp->cno - 1]))
+ break;
--tp->cno;
++tp->owrite;
if (FL_ISSET(is_flags, IS_RUNNING))
tp->lb[tp->cno] = ' ';
- if (isblank(tp->lb[tp->cno - 1]))
- break;
}
else {
if (LF_ISSET(TXT_ALTWERASE)) {
@@ -1135,19 +1119,17 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
++tp->owrite;
if (FL_ISSET(is_flags, IS_RUNNING))
tp->lb[tp->cno] = ' ';
- if (isblank(tp->lb[tp->cno - 1]))
- break;
}
if (tp->cno > max)
tmp = inword(tp->lb[tp->cno - 1]);
while (tp->cno > max) {
+ if (tmp != inword(tp->lb[tp->cno - 1])
+ || ISBLANK(tp->lb[tp->cno - 1]))
+ break;
--tp->cno;
++tp->owrite;
if (FL_ISSET(is_flags, IS_RUNNING))
tp->lb[tp->cno] = ' ';
- if (tmp != inword(tp->lb[tp->cno - 1])
- || isblank(tp->lb[tp->cno - 1]))
- break;
}
}
@@ -1164,7 +1146,7 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
*/
if (tp->cno == 0) {
if ((ntp =
- txt_backup(sp, &sp->tiq, tp, &flags)) == NULL)
+ txt_backup(sp, sp->tiq, tp, &flags)) == NULL)
goto err;
tp = ntp;
}
@@ -1213,11 +1195,6 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
if (txt_dent(sp, tp, 1))
goto err;
goto ebuf_chk;
- case K_RIGHTBRACE:
- case K_RIGHTPAREN:
- if (LF_ISSET(TXT_SHOWMATCH))
- showmatch = 1;
- goto ins_ch;
case K_BACKSLASH: /* Quote next erase/kill. */
/*
* !!!
@@ -1265,6 +1242,14 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
hexcnt = 1;
goto insq_ch;
default: /* Insert the character. */
+ if (LF_ISSET(TXT_SHOWMATCH)) {
+ CHAR_T *match_chars, *cp;
+
+ match_chars = VIP(sp)->mcs;
+ cp = STRCHR(match_chars, evp->e_c);
+ if (cp != NULL && (cp - match_chars) & 1)
+ showmatch = 1;
+ }
ins_ch: /*
* Historically, vi eliminated nul's out of hand. If the
* beautify option was set, it also deleted any unknown
@@ -1278,7 +1263,7 @@ ins_ch: /*
* wasn't a replay and wasn't handled specially, except
* <tab> or <ff>.
*/
- if (LF_ISSET(TXT_BEAUTIFY) && iscntrl(evp->e_c) &&
+ if (LF_ISSET(TXT_BEAUTIFY) && ISCNTRL(evp->e_c) &&
evp->e_value != K_FORMFEED && evp->e_value != K_TAB) {
msgq(sp, M_BERR,
"192|Illegal character; quote to enter");
@@ -1331,7 +1316,7 @@ insl_ch: if (txt_insch(sp, tp, &evp->e_c, flags))
* number of hex bytes. Offset by one, we use 0 to mean
* that we've found <CH_HEX>.
*/
- if (hexcnt != 0 && hexcnt++ == sizeof(CHAR_T) * 2 + 1) {
+ if (hexcnt != 0 && hexcnt++ == 3) {
hexcnt = 0;
if (txt_hex(sp, tp))
goto err;
@@ -1370,7 +1355,7 @@ insl_ch: if (txt_insch(sp, tp, &evp->e_c, flags))
* the length of the motion.
*/
ebuf_chk: if (tp->cno >= tp->len) {
- BINC_GOTO(sp, tp->lb, tp->lb_len, tp->len + 1);
+ BINC_GOTOW(sp, tp->lb, tp->lb_len, tp->len + 1);
LF_SET(TXT_APPENDEOL);
tp->lb[tp->cno] = CH_CURSOR;
@@ -1391,7 +1376,7 @@ ebuf_chk: if (tp->cno >= tp->len) {
#ifdef DEBUG
if (tp->cno + tp->insert + tp->owrite != tp->len) {
msgq(sp, M_ERR,
- "len %u != cno: %u ai: %u insert %u overwrite %u",
+ "len %zu != cno: %zu ai: %zu insert %zu overwrite %zu",
tp->len, tp->cno, tp->ai, tp->insert, tp->owrite);
if (LF_ISSET(TXT_REPLAY))
goto done;
@@ -1475,7 +1460,7 @@ done: /* Leave input mode. */
err:
alloc_err:
F_CLR(sp, SC_TINPUT);
- txt_err(sp, &sp->tiq);
+ txt_err(sp, sp->tiq);
return (1);
}
@@ -1484,11 +1469,7 @@ alloc_err:
* Handle abbreviations.
*/
static int
-txt_abbrev(sp, tp, pushcp, isinfoline, didsubp, turnoffp)
- SCR *sp;
- TEXT *tp;
- CHAR_T *pushcp;
- int isinfoline, *didsubp, *turnoffp;
+txt_abbrev(SCR *sp, TEXT *tp, CHAR_T *pushcp, int isinfoline, int *didsubp, int *turnoffp)
{
VI_PRIVATE *vip;
CHAR_T ch, *p;
@@ -1632,7 +1613,7 @@ search: if (isinfoline)
tp->owrite += len;
else {
if (tp->insert)
- memmove(tp->lb + tp->cno + qp->olen,
+ MEMMOVE(tp->lb + tp->cno + qp->olen,
tp->lb + tp->cno + tp->owrite + len, tp->insert);
tp->owrite += qp->olen;
tp->len -= len - qp->olen;
@@ -1654,13 +1635,10 @@ search: if (isinfoline)
* Handle the unmap command.
*/
static void
-txt_unmap(sp, tp, ec_flagsp)
- SCR *sp;
- TEXT *tp;
- u_int32_t *ec_flagsp;
+txt_unmap(SCR *sp, TEXT *tp, u_int32_t *ec_flagsp)
{
size_t len, off;
- char *p;
+ CHAR_T *p;
/* Find the beginning of this "word". */
for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --p, --off) {
@@ -1697,15 +1675,12 @@ txt_unmap(sp, tp, ec_flagsp)
* When a line is resolved by <esc>, review autoindent characters.
*/
static void
-txt_ai_resolve(sp, tp, changedp)
- SCR *sp;
- TEXT *tp;
- int *changedp;
+txt_ai_resolve(SCR *sp, TEXT *tp, int *changedp)
{
u_long ts;
int del;
size_t cno, len, new, old, scno, spaces, tab_after_sp, tabs;
- char *p;
+ CHAR_T *p;
*changedp = 0;
@@ -1748,7 +1723,7 @@ txt_ai_resolve(sp, tp, changedp)
* If there are no spaces, or no tabs after spaces and less than
* ts spaces, it's already minimal.
*/
- if (!spaces || !tab_after_sp && spaces < ts)
+ if (!spaces || (!tab_after_sp && spaces < ts))
return;
/* Count up spaces/tabs needed to get to the target. */
@@ -1767,7 +1742,7 @@ txt_ai_resolve(sp, tp, changedp)
/* Shift the rest of the characters down, adjust the counts. */
del = old - new;
- memmove(p - del, p, tp->len - old);
+ MEMMOVE(p - del, p, tp->len - old);
tp->len -= del;
tp->cno -= del;
@@ -1787,14 +1762,10 @@ txt_ai_resolve(sp, tp, changedp)
* PUBLIC: int v_txt_auto __P((SCR *, recno_t, TEXT *, size_t, TEXT *));
*/
int
-v_txt_auto(sp, lno, aitp, len, tp)
- SCR *sp;
- recno_t lno;
- TEXT *aitp, *tp;
- size_t len;
+v_txt_auto(SCR *sp, recno_t lno, TEXT *aitp, size_t len, TEXT *tp)
{
size_t nlen;
- char *p, *t;
+ CHAR_T *p, *t;
if (aitp == NULL) {
/*
@@ -1821,15 +1792,15 @@ v_txt_auto(sp, lno, aitp, len, tp)
return (0);
/* Make sure the buffer's big enough. */
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + nlen);
+ BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + nlen);
/* Copy the buffer's current contents up. */
if (tp->len != 0)
- memmove(tp->lb + nlen, tp->lb, tp->len);
+ MEMMOVE(tp->lb + nlen, tp->lb, tp->len);
tp->len += nlen;
/* Copy the indentation into the new buffer. */
- memmove(tp->lb, t, nlen);
+ MEMMOVE(tp->lb, t, nlen);
/* Set the autoindent count. */
tp->ai = nlen;
@@ -1841,17 +1812,13 @@ v_txt_auto(sp, lno, aitp, len, tp)
* Back up to the previously edited line.
*/
static TEXT *
-txt_backup(sp, tiqh, tp, flagsp)
- SCR *sp;
- TEXTH *tiqh;
- TEXT *tp;
- u_int32_t *flagsp;
+txt_backup(SCR *sp, TEXTH *tiqh, TEXT *tp, u_int32_t *flagsp)
{
VI_PRIVATE *vip;
TEXT *ntp;
/* Get a handle on the previous TEXT structure. */
- if ((ntp = tp->q.cqe_prev) == (void *)tiqh) {
+ if ((ntp = TAILQ_PREV(tp, _texth, q)) == NULL) {
if (!FL_ISSET(*flagsp, TXT_REPLAY))
msgq(sp, M_BERR,
"193|Already at the beginning of the insert");
@@ -1872,7 +1839,7 @@ txt_backup(sp, tiqh, tp, flagsp)
FL_CLR(*flagsp, TXT_APPENDEOL);
/* Release the current TEXT. */
- CIRCLEQ_REMOVE(tiqh, tp, q);
+ TAILQ_REMOVE(tiqh, tp, q);
text_free(tp);
/* Update the old line on the screen. */
@@ -1910,7 +1877,7 @@ txt_backup(sp, tiqh, tp, flagsp)
* Technically, txt_dent should be part of the screen interface, as it requires
* knowledge of character sizes, including <space>s, on the screen. It's here
* because it's a complicated little beast, and I didn't want to shove it down
- * into the screen. It's probable that KEY_LEN will call into the screen once
+ * into the screen. It's probable that KEY_COL will call into the screen once
* there are screens with different character representations.
*
* txt_dent --
@@ -1920,14 +1887,11 @@ txt_backup(sp, tiqh, tp, flagsp)
* changes.
*/
static int
-txt_dent(sp, tp, isindent)
- SCR *sp;
- TEXT *tp;
- int isindent;
+txt_dent(SCR *sp, TEXT *tp, int isindent)
{
CHAR_T ch;
u_long sw, ts;
- size_t cno, current, spaces, target, tabs, off;
+ size_t cno, current, spaces, target, tabs;
int ai_reset;
ts = O_VAL(sp, O_TABSTOP);
@@ -1951,7 +1915,7 @@ txt_dent(sp, tp, isindent)
*/
for (current = cno = 0; cno < tp->cno; ++cno)
current += tp->lb[cno] == '\t' ?
- COL_OFF(current, ts) : KEY_LEN(sp, tp->lb[cno]);
+ COL_OFF(current, ts) : KEY_COL(sp, tp->lb[cno]);
target = current;
if (isindent)
@@ -1981,7 +1945,7 @@ txt_dent(sp, tp, isindent)
--tp->cno, ++tp->owrite);
for (current = cno = 0; cno < tp->cno; ++cno)
current += tp->lb[cno] == '\t' ?
- COL_OFF(current, ts) : KEY_LEN(sp, tp->lb[cno]);
+ COL_OFF(current, ts) : KEY_COL(sp, tp->lb[cno]);
/*
* If we didn't move up to or past the target, it's because there
@@ -2021,24 +1985,23 @@ txt_dent(sp, tp, isindent)
/*
* txt_fc --
- * File name completion.
+ * File name and ex command completion.
*/
static int
-txt_fc(sp, tp, redrawp)
- SCR *sp;
- TEXT *tp;
- int *redrawp;
+txt_fc(SCR *sp, TEXT *tp, int *redrawp)
{
struct stat sb;
ARGS **argv;
- CHAR_T s_ch;
EXCMD cmd;
size_t indx, len, nlen, off;
- int argc, trydir;
- char *p, *t;
+ int argc;
+ CHAR_T *p, *t, *bp;
+ char *np, *epd = NULL;
+ size_t nplen;
+ int fstwd = 1;
- trydir = 0;
*redrawp = 0;
+ ex_cinit(sp, &cmd, 0, 0, OOBLNO, OOBLNO, 0);
/*
* Find the beginning of this "word" -- if we're at the beginning
@@ -2047,67 +2010,53 @@ txt_fc(sp, tp, redrawp)
if (tp->cno == 1) {
len = 0;
p = tp->lb;
- } else
-retry: for (len = 0,
- off = tp->cno - 1, p = tp->lb + off;; --off, --p) {
- if (isblank(*p)) {
- ++p;
- break;
- }
- ++len;
- if (off == tp->ai || off == tp->offset)
- break;
+ } else {
+ CHAR_T *ap;
+
+ for (len = 0,
+ off = MAX(tp->ai, tp->offset), ap = tp->lb + off, p = ap;
+ off < tp->cno; ++off, ++ap) {
+ if (IS_ESCAPE(sp, &cmd, *ap)) {
+ if (++off == tp->cno)
+ break;
+ ++ap;
+ len += 2;
+ } else if (cmdskip(*ap)) {
+ p = ap + 1;
+ if (len > 0)
+ fstwd = 0;
+ len = 0;
+ } else
+ ++len;
}
+ }
/*
- * Get enough space for a wildcard character.
- *
- * XXX
- * This won't work for "foo\", since the \ will escape the expansion
- * character. I'm not sure if that's a bug or not...
+ * If we are at the first word, do ex command completion instead of
+ * file name completion.
*/
- off = p - tp->lb;
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + 1);
- p = tp->lb + off;
-
- s_ch = p[len];
- p[len] = '*';
-
- /* Build an ex command, and call the ex expansion routines. */
- ex_cinit(&cmd, 0, 0, OOBLNO, OOBLNO, 0, NULL);
- if (argv_init(sp, &cmd))
- return (1);
- if (argv_exp2(sp, &cmd, p, len + 1)) {
- p[len] = s_ch;
- return (0);
+ if (fstwd)
+ (void)argv_flt_ex(sp, &cmd, p, len);
+ else {
+ if ((bp = argv_uesc(sp, &cmd, p, len)) == NULL)
+ return (1);
+ if (argv_flt_path(sp, &cmd, bp, STRLEN(bp))) {
+ FREE_SPACEW(sp, bp, 0);
+ return (0);
+ }
+ FREE_SPACEW(sp, bp, 0);
}
argc = cmd.argc;
argv = cmd.argv;
- p[len] = s_ch;
-
switch (argc) {
case 0: /* No matches. */
- if (!trydir)
- (void)sp->gp->scr_bell(sp);
+ (void)sp->gp->scr_bell(sp);
return (0);
case 1: /* One match. */
- /* If something changed, do the exchange. */
- nlen = strlen(cmd.argv[0]->bp);
- if (len != nlen || memcmp(cmd.argv[0]->bp, p, len))
- break;
-
- /* If haven't done a directory test, do it now. */
- if (!trydir &&
- !stat(cmd.argv[0]->bp, &sb) && S_ISDIR(sb.st_mode)) {
- p += len;
- goto isdir;
- }
-
- /* If nothing changed, period, ring the bell. */
- if (!trydir)
- (void)sp->gp->scr_bell(sp);
- return (0);
+ /* Always overwrite the old text. */
+ nlen = STRLEN(cmd.argv[0]->bp);
+ break;
default: /* Multiple matches. */
*redrawp = 1;
if (txt_fc_col(sp, argc, argv))
@@ -2125,8 +2074,17 @@ retry: for (len = 0,
break;
}
+ /* Escape the matched part of the path. */
+ if (fstwd)
+ bp = cmd.argv[0]->bp;
+ else {
+ if ((bp = argv_esc(sp, &cmd, cmd.argv[0]->bp, nlen)) == NULL)
+ return (1);
+ nlen = STRLEN(bp);
+ }
+
/* Overwrite the expanded text first. */
- for (t = cmd.argv[0]->bp; len > 0 && nlen > 0; --len, --nlen)
+ for (t = bp; len > 0 && nlen > 0; --len, --nlen)
*p++ = *t++;
/* If lost text, make the remaining old text overwrite characters. */
@@ -2142,36 +2100,44 @@ retry: for (len = 0,
/* Shift remaining text up, and move the cursor to the end. */
if (nlen) {
off = p - tp->lb;
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + nlen);
+ BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + nlen);
p = tp->lb + off;
tp->cno += nlen;
tp->len += nlen;
if (tp->insert != 0)
- (void)memmove(p + nlen, p, tp->insert);
+ (void)MEMMOVE(p + nlen, p, tp->insert);
while (nlen--)
*p++ = *t++;
}
- /* If a single match and it's a directory, retry it. */
- if (argc == 1 && !stat(cmd.argv[0]->bp, &sb) && S_ISDIR(sb.st_mode)) {
-isdir: if (tp->owrite == 0) {
+ if (!fstwd)
+ FREE_SPACEW(sp, bp, 0);
+
+ /* If not a single match of path, we've done. */
+ if (argc != 1 || fstwd)
+ return (0);
+
+ /* If a single match and it's a directory, append a '/'. */
+ INT2CHAR(sp, cmd.argv[0]->bp, cmd.argv[0]->len + 1, np, nplen);
+ if ((epd = expanduser(np)) != NULL)
+ np = epd;
+ if (!stat(np, &sb) && S_ISDIR(sb.st_mode)) {
+ if (tp->owrite == 0) {
off = p - tp->lb;
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + 1);
+ BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + 1);
p = tp->lb + off;
if (tp->insert != 0)
- (void)memmove(p + 1, p, tp->insert);
+ (void)MEMMOVE(p + 1, p, tp->insert);
++tp->len;
} else
--tp->owrite;
++tp->cno;
*p++ = '/';
-
- trydir = 1;
- goto retry;
}
+ free(epd);
return (0);
}
@@ -2180,27 +2146,28 @@ isdir: if (tp->owrite == 0) {
* Display file names for file name completion.
*/
static int
-txt_fc_col(sp, argc, argv)
- SCR *sp;
- int argc;
- ARGS **argv;
+txt_fc_col(SCR *sp, int argc, ARGS **argv)
{
ARGS **av;
CHAR_T *p;
GS *gp;
size_t base, cnt, col, colwidth, numrows, numcols, prefix, row;
int ac, nf, reset;
+ char *np, *pp;
+ size_t nlen;
gp = sp->gp;
/* Trim any directory prefix common to all of the files. */
- if ((p = strrchr(argv[0]->bp, '/')) == NULL)
+ INT2CHAR(sp, argv[0]->bp, argv[0]->len + 1, np, nlen);
+ if ((pp = strrchr(np, '/')) == NULL)
prefix = 0;
else {
- prefix = (p - argv[0]->bp) + 1;
+ prefix = (pp - np) + 1;
for (ac = argc - 1, av = argv + 1; ac > 0; --ac, ++av)
if (av[0]->len < prefix ||
- memcmp(av[0]->bp, argv[0]->bp, prefix)) {
+ MEMCMP(av[0]->bp, argv[0]->bp,
+ prefix)) {
prefix = 0;
break;
}
@@ -2215,7 +2182,7 @@ txt_fc_col(sp, argc, argv)
*/
for (ac = argc, av = argv, colwidth = 0; ac > 0; --ac, ++av) {
for (col = 0, p = av[0]->bp + prefix; *p != '\0'; ++p)
- col += KEY_LEN(sp, *p);
+ col += KEY_COL(sp, *p);
if (col > colwidth)
colwidth = col;
}
@@ -2236,15 +2203,17 @@ txt_fc_col(sp, argc, argv)
goto intr;
/* If the largest file name is too large, just print them. */
- if (colwidth > sp->cols) {
+ if (colwidth >= sp->cols) {
for (ac = argc, av = argv; ac > 0; --ac, ++av) {
- p = msg_print(sp, av[0]->bp + prefix, &nf);
- (void)ex_printf(sp, "%s\n", p);
+ INT2CHAR(sp, av[0]->bp+prefix, av[0]->len+1-prefix,
+ np, nlen);
+ pp = msg_print(sp, np, &nf);
+ (void)ex_printf(sp, "%s\n", pp);
+ if (nf)
+ FREE_SPACE(sp, pp, 0);
if (F_ISSET(gp, G_INTERRUPTED))
break;
}
- if (nf)
- FREE_SPACE(sp, p, 0);
CHK_INTR;
} else {
/* Figure out the number of columns. */
@@ -2259,10 +2228,12 @@ txt_fc_col(sp, argc, argv)
/* Display the files in sorted order. */
for (row = 0; row < numrows; ++row) {
for (base = row, col = 0; col < numcols; ++col) {
- p = msg_print(sp, argv[base]->bp + prefix, &nf);
- cnt = ex_printf(sp, "%s", p);
+ INT2CHAR(sp, argv[base]->bp+prefix,
+ argv[base]->len+1-prefix, np, nlen);
+ pp = msg_print(sp, np, &nf);
+ cnt = ex_printf(sp, "%s", pp);
if (nf)
- FREE_SPACE(sp, p, 0);
+ FREE_SPACE(sp, pp, 0);
CHK_INTR;
if ((base += numrows) >= argc)
break;
@@ -2292,14 +2263,12 @@ intr: F_CLR(gp, G_INTERRUPTED);
* Set the end mark on the line.
*/
static int
-txt_emark(sp, tp, cno)
- SCR *sp;
- TEXT *tp;
- size_t cno;
+txt_emark(SCR *sp, TEXT *tp, size_t cno)
{
- CHAR_T ch, *kp;
+ CHAR_T ch;
+ u_char *kp;
size_t chlen, nlen, olen;
- char *p;
+ CHAR_T *p;
ch = CH_ENDMARK;
@@ -2307,11 +2276,11 @@ txt_emark(sp, tp, cno)
* The end mark may not be the same size as the current character.
* Don't let the line shift.
*/
- nlen = KEY_LEN(sp, ch);
+ nlen = KEY_COL(sp, ch);
if (tp->lb[cno] == '\t')
(void)vs_columns(sp, tp->lb, tp->lno, &cno, &olen);
else
- olen = KEY_LEN(sp, tp->lb[cno]);
+ olen = KEY_COL(sp, tp->lb[cno]);
/*
* If the line got longer, well, it's weird, but it's easy. If
@@ -2319,20 +2288,22 @@ txt_emark(sp, tp, cno)
* to fix it up.
*/
if (olen > nlen) {
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + olen);
+ BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + olen);
chlen = olen - nlen;
if (tp->insert != 0)
- memmove(tp->lb + cno + 1 + chlen,
+ MEMMOVE(tp->lb + cno + 1 + chlen,
tp->lb + cno + 1, tp->insert);
tp->len += chlen;
tp->owrite += chlen;
p = tp->lb + cno;
- if (tp->lb[cno] == '\t')
+ if (tp->lb[cno] == '\t' ||
+ KEY_NEEDSWIDE(sp, tp->lb[cno]))
for (cno += chlen; chlen--;)
*p++ = ' ';
else
- for (kp = KEY_NAME(sp, tp->lb[cno]),
+ for (kp = (u_char *)
+ KEY_NAME(sp, tp->lb[cno]),
cno += chlen; chlen--;)
*p++ = *kp++;
}
@@ -2345,9 +2316,7 @@ txt_emark(sp, tp, cno)
* Handle an error during input processing.
*/
static void
-txt_err(sp, tiqh)
- SCR *sp;
- TEXTH *tiqh;
+txt_err(SCR *sp, TEXTH *tiqh)
{
recno_t lno;
@@ -2360,7 +2329,7 @@ txt_err(sp, tiqh)
* We depend on at least one line number being set in the text
* chain.
*/
- for (lno = tiqh->cqh_first->lno;
+ for (lno = TAILQ_FIRST(tiqh)->lno;
!db_exist(sp, lno) && lno > 0; --lno);
sp->lno = lno == 0 ? 1 : lno;
@@ -2380,14 +2349,12 @@ txt_err(sp, tiqh)
* may not be able to enter.
*/
static int
-txt_hex(sp, tp)
- SCR *sp;
- TEXT *tp;
+txt_hex(SCR *sp, TEXT *tp)
{
CHAR_T savec;
size_t len, off;
u_long value;
- char *p, *wp;
+ CHAR_T *p, *wp;
/*
* Null-terminate the string. Since nul isn't a legal hex value,
@@ -2414,8 +2381,8 @@ txt_hex(sp, tp)
/* Get the value. */
errno = 0;
- value = strtol(wp, NULL, 16);
- if (errno || value > MAX_CHAR_T) {
+ value = STRTOL(wp, NULL, 16);
+ if (errno || value > UCHAR_MAX) {
nothex: tp->lb[tp->cno] = savec;
return (0);
}
@@ -2430,12 +2397,14 @@ nothex: tp->lb[tp->cno] = savec;
/* Copy down any overwrite characters. */
if (tp->owrite)
- memmove(tp->lb + tp->cno, tp->lb + tp->cno + len, tp->owrite);
+ MEMMOVE(tp->lb + tp->cno, tp->lb + tp->cno + len,
+ tp->owrite);
/* Copy down any insert characters. */
if (tp->insert)
- memmove(tp->lb + tp->cno + tp->owrite,
- tp->lb + tp->cno + tp->owrite + len, tp->insert);
+ MEMMOVE(tp->lb + tp->cno + tp->owrite,
+ tp->lb + tp->cno + tp->owrite + len,
+ tp->insert);
return (0);
}
@@ -2460,15 +2429,12 @@ nothex: tp->lb[tp->cno] = savec;
* of the screen space they require, but that it not overwrite other characters.
*/
static int
-txt_insch(sp, tp, chp, flags)
- SCR *sp;
- TEXT *tp;
- CHAR_T *chp;
- u_int flags;
+txt_insch(SCR *sp, TEXT *tp, CHAR_T *chp, u_int flags)
{
- CHAR_T *kp, savech;
+ u_char *kp;
+ CHAR_T savech;
size_t chlen, cno, copydown, olen, nlen;
- char *p;
+ CHAR_T *p;
/*
* The 'R' command does one-for-one replacement, because there's
@@ -2494,7 +2460,7 @@ txt_insch(sp, tp, chp, flags)
(void)vs_columns(sp, tp->lb, tp->lno, &cno, &nlen);
tp->lb[cno] = savech;
} else
- nlen = KEY_LEN(sp, *chp);
+ nlen = KEY_COL(sp, *chp);
/*
* Eat overwrite characters until we run out of them or we've
@@ -2509,7 +2475,7 @@ txt_insch(sp, tp, chp, flags)
(void)vs_columns(sp,
tp->lb, tp->lno, &cno, &olen);
else
- olen = KEY_LEN(sp, tp->lb[cno]);
+ olen = KEY_COL(sp, tp->lb[cno]);
if (olen == nlen) {
nlen = 0;
@@ -2519,19 +2485,21 @@ txt_insch(sp, tp, chp, flags)
++copydown;
nlen -= olen;
} else {
- BINC_RET(sp,
+ BINC_RETW(sp,
tp->lb, tp->lb_len, tp->len + olen);
chlen = olen - nlen;
- memmove(tp->lb + cno + 1 + chlen,
- tp->lb + cno + 1, tp->owrite + tp->insert);
+ MEMMOVE(tp->lb + cno + 1 + chlen,
+ tp->lb + cno + 1,
+ tp->owrite + tp->insert);
tp->len += chlen;
tp->owrite += chlen;
- if (tp->lb[cno] == '\t')
+ if (tp->lb[cno] == '\t' ||
+ KEY_NEEDSWIDE(sp, tp->lb[cno]))
for (p = tp->lb + cno + 1; chlen--;)
*p++ = ' ';
else
- for (kp =
+ for (kp = (u_char *)
KEY_NAME(sp, tp->lb[cno]) + nlen,
p = tp->lb + cno + 1; chlen--;)
*p++ = *kp++;
@@ -2546,7 +2514,7 @@ txt_insch(sp, tp, chp, flags)
* into position.
*/
if (copydown != 0 && (tp->len -= copydown) != 0)
- memmove(tp->lb + cno, tp->lb + cno + copydown,
+ MEMMOVE(tp->lb + cno, tp->lb + cno + copydown,
tp->owrite + tp->insert + copydown);
/* If we had enough overwrite characters, we're done. */
@@ -2557,14 +2525,14 @@ txt_insch(sp, tp, chp, flags)
}
/* Check to see if the character fits into the input buffer. */
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + 1);
+ BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + 1);
++tp->len;
if (tp->insert) { /* Insert a character. */
if (tp->insert == 1)
tp->lb[tp->cno + 1] = tp->lb[tp->cno];
else
- memmove(tp->lb + tp->cno + 1,
+ MEMMOVE(tp->lb + tp->cno + 1,
tp->lb + tp->cno, tp->owrite + tp->insert);
}
tp->lb[tp->cno++] = *chp;
@@ -2576,11 +2544,7 @@ txt_insch(sp, tp, chp, flags)
* Do an incremental search.
*/
static int
-txt_isrch(sp, vp, tp, is_flagsp)
- SCR *sp;
- VICMD *vp;
- TEXT *tp;
- u_int8_t *is_flagsp;
+txt_isrch(SCR *sp, VICMD *vp, TEXT *tp, u_int8_t *is_flagsp)
{
MARK start;
recno_t lno;
@@ -2613,7 +2577,7 @@ txt_isrch(sp, vp, tp, is_flagsp)
* If it's a magic shell character, and not quoted, reset the cursor
* to the starting point.
*/
- if (strchr(O_STR(sp, O_SHELLMETA), tp->lb[tp->cno - 1]) != NULL &&
+ if (IS_SHELLMETA(sp, tp->lb[tp->cno - 1]) &&
(tp->cno == 2 || tp->lb[tp->cno - 2] != '\\'))
vp->m_final = vp->m_start;
@@ -2700,10 +2664,7 @@ txt_isrch(sp, vp, tp, is_flagsp)
* Resolve the input text chain into the file.
*/
static int
-txt_resolve(sp, tiqh, flags)
- SCR *sp;
- TEXTH *tiqh;
- u_int32_t flags;
+txt_resolve(SCR *sp, TEXTH *tiqh, u_int32_t flags)
{
VI_PRIVATE *vip;
TEXT *tp;
@@ -2718,23 +2679,23 @@ txt_resolve(sp, tiqh, flags)
* about the line will be wrong.
*/
vip = VIP(sp);
- tp = tiqh->cqh_first;
+ tp = TAILQ_FIRST(tiqh);
if (LF_ISSET(TXT_AUTOINDENT))
txt_ai_resolve(sp, tp, &changed);
else
changed = 0;
if (db_set(sp, tp->lno, tp->lb, tp->len) ||
- changed && vs_change(sp, tp->lno, LINE_RESET))
+ (changed && vs_change(sp, tp->lno, LINE_RESET)))
return (1);
- for (lno = tp->lno; (tp = tp->q.cqe_next) != (void *)&sp->tiq; ++lno) {
+ for (lno = tp->lno; (tp = TAILQ_NEXT(tp, q)) != NULL; ++lno) {
if (LF_ISSET(TXT_AUTOINDENT))
txt_ai_resolve(sp, tp, &changed);
else
changed = 0;
if (db_append(sp, 0, lno, tp->lb, tp->len) ||
- changed && vs_change(sp, tp->lno, LINE_RESET))
+ (changed && vs_change(sp, tp->lno, LINE_RESET)))
return (1);
}
@@ -2757,9 +2718,7 @@ txt_resolve(sp, tiqh, flags)
* I think not.
*/
static int
-txt_showmatch(sp, tp)
- SCR *sp;
- TEXT *tp;
+txt_showmatch(SCR *sp, TEXT *tp)
{
GS *gp;
VCS cs;
@@ -2788,7 +2747,7 @@ txt_showmatch(sp, tp)
cs.cs_cno = tp->cno - 1;
if (cs_init(sp, &cs))
return (1);
- startc = (endc = cs.cs_ch) == ')' ? '(' : '{';
+ startc = STRCHR(VIP(sp)->mcs, endc = cs.cs_ch)[-1];
/* Search for the match. */
for (cnt = 1;;) {
@@ -2809,7 +2768,7 @@ txt_showmatch(sp, tp)
}
/* If the match is on the screen, move to it. */
- if (cs.cs_lno < m.lno || cs.cs_lno == m.lno && cs.cs_cno < m.cno)
+ if (cs.cs_lno < m.lno || (cs.cs_lno == m.lno && cs.cs_cno < m.cno))
return (0);
sp->lno = cs.cs_lno;
sp->cno = cs.cs_cno;
@@ -2826,15 +2785,11 @@ txt_showmatch(sp, tp)
* Handle margin wrap.
*/
static int
-txt_margin(sp, tp, wmtp, didbreak, flags)
- SCR *sp;
- TEXT *tp, *wmtp;
- int *didbreak;
- u_int32_t flags;
+txt_margin(SCR *sp, TEXT *tp, TEXT *wmtp, int *didbreak, u_int32_t flags)
{
VI_PRIVATE *vip;
size_t len, off;
- char *p, *wp;
+ CHAR_T *p, *wp;
/* Find the nearest previous blank. */
for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --off, --p, ++len) {
@@ -2906,15 +2861,11 @@ txt_margin(sp, tp, wmtp, didbreak, flags)
* Resolve the input line for the 'R' command.
*/
static void
-txt_Rresolve(sp, tiqh, tp, orig_len)
- SCR *sp;
- TEXTH *tiqh;
- TEXT *tp;
- const size_t orig_len;
+txt_Rresolve(SCR *sp, TEXTH *tiqh, TEXT *tp, const size_t orig_len)
{
TEXT *ttp;
size_t input_len, retain;
- char *p;
+ CHAR_T *p;
/*
* Check to make sure that the cursor hasn't moved beyond
@@ -2927,9 +2878,9 @@ txt_Rresolve(sp, tiqh, tp, orig_len)
* Calculate how many characters the user has entered,
* plus the blanks erased by <carriage-return>/<newline>s.
*/
- for (ttp = tiqh->cqh_first, input_len = 0;;) {
+ for (ttp = TAILQ_FIRST(tiqh), input_len = 0;;) {
input_len += ttp == tp ? tp->cno : ttp->len + ttp->R_erase;
- if ((ttp = ttp->q.cqe_next) == (void *)&sp->tiq)
+ if ((ttp = TAILQ_NEXT(ttp, q)) == NULL)
break;
}
@@ -2950,9 +2901,9 @@ txt_Rresolve(sp, tiqh, tp, orig_len)
if (input_len < orig_len) {
retain = MIN(tp->owrite, orig_len - input_len);
if (db_get(sp,
- tiqh->cqh_first->lno, DBG_FATAL | DBG_NOCACHE, &p, NULL))
+ TAILQ_FIRST(tiqh)->lno, DBG_FATAL | DBG_NOCACHE, &p, NULL))
return;
- memcpy(tp->lb + tp->cno, p + input_len, retain);
+ MEMCPY(tp->lb + tp->cno, p + input_len, retain);
tp->len -= tp->owrite - retain;
tp->owrite = 0;
tp->insert += retain;
@@ -2964,8 +2915,7 @@ txt_Rresolve(sp, tiqh, tp, orig_len)
* No more characters message.
*/
static void
-txt_nomorech(sp)
- SCR *sp;
+txt_nomorech(SCR *sp)
{
msgq(sp, M_BERR, "194|No more characters to erase");
}
diff --git a/contrib/nvi/vi/v_ulcase.c b/contrib/nvi/vi/v_ulcase.c
index 179beba..10d3d35 100644
--- a/contrib/nvi/vi/v_ulcase.c
+++ b/contrib/nvi/vi/v_ulcase.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_ulcase.c 10.7 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_ulcase.c,v 10.12 2011/12/02 19:58:32 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -47,14 +47,12 @@ static int ulcase __P((SCR *, recno_t, CHAR_T *, size_t, size_t, size_t));
* PUBLIC: int v_ulcase __P((SCR *, VICMD *));
*/
int
-v_ulcase(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_ulcase(SCR *sp, VICMD *vp)
{
recno_t lno;
size_t cno, lcnt, len;
u_long cnt;
- char *p;
+ CHAR_T *p;
lno = vp->m_start.lno;
cno = vp->m_start.cno;
@@ -107,9 +105,7 @@ v_ulcase(sp, vp)
* PUBLIC: int v_mulcase __P((SCR *, VICMD *));
*/
int
-v_mulcase(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_mulcase(SCR *sp, VICMD *vp)
{
CHAR_T *p;
size_t len;
@@ -145,28 +141,24 @@ v_mulcase(sp, vp)
* Change part of a line's case.
*/
static int
-ulcase(sp, lno, lp, len, scno, ecno)
- SCR *sp;
- recno_t lno;
- CHAR_T *lp;
- size_t len, scno, ecno;
+ulcase(SCR *sp, recno_t lno, CHAR_T *lp, size_t len, size_t scno, size_t ecno)
{
size_t blen;
int change, rval;
- CHAR_T ch, *p, *t;
- char *bp;
+ ARG_CHAR_T ch;
+ CHAR_T *p, *t, *bp;
- GET_SPACE_RET(sp, bp, blen, len);
- memmove(bp, lp, len);
+ GET_SPACE_RETW(sp, bp, blen, len);
+ MEMMOVE(bp, lp, len);
change = rval = 0;
for (p = bp + scno, t = bp + ecno + 1; p < t; ++p) {
- ch = *(u_char *)p;
- if (islower(ch)) {
- *p = toupper(ch);
+ ch = (UCHAR_T)*p;
+ if (ISLOWER(ch)) {
+ *p = TOUPPER(ch);
change = 1;
- } else if (isupper(ch)) {
- *p = tolower(ch);
+ } else if (ISUPPER(ch)) {
+ *p = TOLOWER(ch);
change = 1;
}
}
@@ -174,6 +166,6 @@ ulcase(sp, lno, lp, len, scno, ecno)
if (change && db_set(sp, lno, bp, len))
rval = 1;
- FREE_SPACE(sp, bp, blen);
+ FREE_SPACEW(sp, bp, blen);
return (rval);
}
diff --git a/contrib/nvi/vi/v_undo.c b/contrib/nvi/vi/v_undo.c
index d04a8a1..2bbd920 100644
--- a/contrib/nvi/vi/v_undo.c
+++ b/contrib/nvi/vi/v_undo.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_undo.c 10.5 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_undo.c,v 10.6 2001/06/25 15:19:36 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -34,9 +34,7 @@ static const char sccsid[] = "@(#)v_undo.c 10.5 (Berkeley) 3/6/96";
* PUBLIC: int v_Undo __P((SCR *, VICMD *));
*/
int
-v_Undo(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_Undo(SCR *sp, VICMD *vp)
{
/*
* Historically, U reset the cursor to the first column in the line
@@ -70,9 +68,7 @@ v_Undo(sp, vp)
* PUBLIC: int v_undo __P((SCR *, VICMD *));
*/
int
-v_undo(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_undo(SCR *sp, VICMD *vp)
{
EXF *ep;
diff --git a/contrib/nvi/vi/v_util.c b/contrib/nvi/vi/v_util.c
index c4c0daa..6348ca7 100644
--- a/contrib/nvi/vi/v_util.c
+++ b/contrib/nvi/vi/v_util.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_util.c 10.11 (Berkeley) 6/30/96";
+static const char sccsid[] = "$Id: v_util.c,v 10.14 2001/06/25 15:19:36 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -35,9 +35,7 @@ static const char sccsid[] = "@(#)v_util.c 10.11 (Berkeley) 6/30/96";
* PUBLIC: void v_eof __P((SCR *, MARK *));
*/
void
-v_eof(sp, mp)
- SCR *sp;
- MARK *mp;
+v_eof(SCR *sp, MARK *mp)
{
recno_t lno;
@@ -60,9 +58,7 @@ v_eof(sp, mp)
* PUBLIC: void v_eol __P((SCR *, MARK *));
*/
void
-v_eol(sp, mp)
- SCR *sp;
- MARK *mp;
+v_eol(SCR *sp, MARK *mp)
{
size_t len;
@@ -85,8 +81,7 @@ v_eol(sp, mp)
* PUBLIC: void v_nomove __P((SCR *));
*/
void
-v_nomove(sp)
- SCR *sp;
+v_nomove(SCR *sp)
{
msgq(sp, M_BERR, "197|No cursor movement made");
}
@@ -98,9 +93,7 @@ v_nomove(sp)
* PUBLIC: void v_sof __P((SCR *, MARK *));
*/
void
-v_sof(sp, mp)
- SCR *sp;
- MARK *mp;
+v_sof(SCR *sp, MARK *mp)
{
if (mp == NULL || mp->lno == 1)
msgq(sp, M_BERR, "198|Already at the beginning of the file");
@@ -115,8 +108,7 @@ v_sof(sp, mp)
* PUBLIC: void v_sol __P((SCR *));
*/
void
-v_sol(sp)
- SCR *sp;
+v_sol(SCR *sp)
{
msgq(sp, M_BERR, "200|Already in the first column");
}
@@ -125,12 +117,10 @@ v_sol(sp)
* v_isempty --
* Return if the line contains nothing but white-space characters.
*
- * PUBLIC: int v_isempty __P((char *, size_t));
+ * PUBLIC: int v_isempty __P((CHAR_T *, size_t));
*/
int
-v_isempty(p, len)
- char *p;
- size_t len;
+v_isempty(CHAR_T *p, size_t len)
{
for (; len--; ++p)
if (!isblank(*p))
@@ -145,10 +135,7 @@ v_isempty(p, len)
* PUBLIC: void v_emsg __P((SCR *, char *, vim_t));
*/
void
-v_emsg(sp, p, which)
- SCR *sp;
- char *p;
- vim_t which;
+v_emsg(SCR *sp, char *p, vim_t which)
{
switch (which) {
case VIM_COMBUF:
diff --git a/contrib/nvi/vi/v_word.c b/contrib/nvi/vi/v_word.c
index e6e4a63..6336e2d 100644
--- a/contrib/nvi/vi/v_word.c
+++ b/contrib/nvi/vi/v_word.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_word.c 10.5 (Berkeley) 3/6/96";
+static const char sccsid[] = "$Id: v_word.c,v 10.7 2011/12/27 00:49:31 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -77,9 +77,7 @@ static int fword __P((SCR *, VICMD *, enum which));
* PUBLIC: int v_wordW __P((SCR *, VICMD *));
*/
int
-v_wordW(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_wordW(SCR *sp, VICMD *vp)
{
return (fword(sp, vp, BIGWORD));
}
@@ -91,9 +89,7 @@ v_wordW(sp, vp)
* PUBLIC: int v_wordw __P((SCR *, VICMD *));
*/
int
-v_wordw(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_wordw(SCR *sp, VICMD *vp)
{
return (fword(sp, vp, LITTLEWORD));
}
@@ -103,10 +99,7 @@ v_wordw(sp, vp)
* Move forward by words.
*/
static int
-fword(sp, vp, type)
- SCR *sp;
- VICMD *vp;
- enum which type;
+fword(SCR *sp, VICMD *vp, enum which type)
{
enum { INWORD, NOTWORD } state;
VCS cs;
@@ -125,7 +118,7 @@ fword(sp, vp, type)
* counts as a single word move. If it's a motion command,
* don't move off the end of the line.
*/
- if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && isblank(cs.cs_ch)) {
+ if (cs.cs_flags == CS_EMP || (cs.cs_flags == 0 && ISBLANK(cs.cs_ch))) {
if (ISMOTION(vp) && cs.cs_flags != CS_EMP && cnt == 1) {
if (ISCMD(vp->rkp, 'c'))
return (0);
@@ -153,7 +146,7 @@ fword(sp, vp, type)
return (1);
if (cs.cs_flags == CS_EOF)
goto ret;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
break;
}
/*
@@ -185,7 +178,7 @@ fword(sp, vp, type)
return (1);
if (cs.cs_flags == CS_EOF)
goto ret;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
break;
if (state == INWORD) {
if (!inword(cs.cs_ch))
@@ -204,7 +197,7 @@ fword(sp, vp, type)
}
/* Eat whitespace characters. */
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
if (cs_fblank(sp, &cs))
return (1);
if (cs.cs_flags == CS_EOF)
@@ -244,9 +237,7 @@ ret: if (!ISMOTION(vp) &&
* PUBLIC: int v_wordE __P((SCR *, VICMD *));
*/
int
-v_wordE(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_wordE(SCR *sp, VICMD *vp)
{
return (eword(sp, vp, BIGWORD));
}
@@ -258,9 +249,7 @@ v_wordE(sp, vp)
* PUBLIC: int v_worde __P((SCR *, VICMD *));
*/
int
-v_worde(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_worde(SCR *sp, VICMD *vp)
{
return (eword(sp, vp, LITTLEWORD));
}
@@ -270,10 +259,7 @@ v_worde(sp, vp)
* Move forward to the end of the word.
*/
static int
-eword(sp, vp, type)
- SCR *sp;
- VICMD *vp;
- enum which type;
+eword(SCR *sp, VICMD *vp, enum which type)
{
enum { INWORD, NOTWORD } state;
VCS cs;
@@ -291,10 +277,10 @@ eword(sp, vp, type)
* it. (This doesn't count as a word move.) Stay at the character
* past the current one, it sets word "state" for the 'e' command.
*/
- if (cs.cs_flags == 0 && !isblank(cs.cs_ch)) {
+ if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch)) {
if (cs_next(sp, &cs))
return (1);
- if (cs.cs_flags == 0 && !isblank(cs.cs_ch))
+ if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch))
goto start;
}
if (cs_fblank(sp, &cs))
@@ -313,7 +299,7 @@ start: if (type == BIGWORD)
return (1);
if (cs.cs_flags == CS_EOF)
goto ret;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
break;
}
/*
@@ -342,7 +328,7 @@ start: if (type == BIGWORD)
return (1);
if (cs.cs_flags == CS_EOF)
goto ret;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
break;
if (state == INWORD) {
if (!inword(cs.cs_ch))
@@ -359,7 +345,7 @@ start: if (type == BIGWORD)
}
/* Eat whitespace characters. */
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
if (cs_fblank(sp, &cs))
return (1);
if (cs.cs_flags == CS_EOF)
@@ -397,9 +383,7 @@ ret: if (!ISMOTION(vp) &&
* PUBLIC: int v_wordB __P((SCR *, VICMD *));
*/
int
-v_wordB(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_wordB(SCR *sp, VICMD *vp)
{
return (bword(sp, vp, BIGWORD));
}
@@ -411,9 +395,7 @@ v_wordB(sp, vp)
* PUBLIC: int v_wordb __P((SCR *, VICMD *));
*/
int
-v_wordb(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_wordb(SCR *sp, VICMD *vp)
{
return (bword(sp, vp, LITTLEWORD));
}
@@ -423,10 +405,7 @@ v_wordb(sp, vp)
* Move backward by words.
*/
static int
-bword(sp, vp, type)
- SCR *sp;
- VICMD *vp;
- enum which type;
+bword(SCR *sp, VICMD *vp, enum which type)
{
enum { INWORD, NOTWORD } state;
VCS cs;
@@ -445,10 +424,10 @@ bword(sp, vp, type)
* character before the current one, it sets word "state" for the
* 'b' command.
*/
- if (cs.cs_flags == 0 && !isblank(cs.cs_ch)) {
+ if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch)) {
if (cs_prev(sp, &cs))
return (1);
- if (cs.cs_flags == 0 && !isblank(cs.cs_ch))
+ if (cs.cs_flags == 0 && !ISBLANK(cs.cs_ch))
goto start;
}
if (cs_bblank(sp, &cs))
@@ -467,7 +446,7 @@ start: if (type == BIGWORD)
return (1);
if (cs.cs_flags == CS_SOF)
goto ret;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
break;
}
/*
@@ -496,7 +475,7 @@ start: if (type == BIGWORD)
return (1);
if (cs.cs_flags == CS_SOF)
goto ret;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
break;
if (state == INWORD) {
if (!inword(cs.cs_ch))
@@ -513,7 +492,7 @@ start: if (type == BIGWORD)
}
/* Eat whitespace characters. */
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
+ if (cs.cs_flags != 0 || ISBLANK(cs.cs_ch))
if (cs_bblank(sp, &cs))
return (1);
if (cs.cs_flags == CS_SOF)
diff --git a/contrib/nvi/vi/v_xchar.c b/contrib/nvi/vi/v_xchar.c
index 15f155f..a0c1a69 100644
--- a/contrib/nvi/vi/v_xchar.c
+++ b/contrib/nvi/vi/v_xchar.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_xchar.c 10.9 (Berkeley) 10/23/96";
+static const char sccsid[] = "$Id: v_xchar.c,v 10.10 2001/06/25 15:19:36 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -31,9 +31,7 @@ static const char sccsid[] = "@(#)v_xchar.c 10.9 (Berkeley) 10/23/96";
* PUBLIC: int v_xchar __P((SCR *, VICMD *));
*/
int
-v_xchar(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_xchar(SCR *sp, VICMD *vp)
{
size_t len;
int isempty;
@@ -80,9 +78,7 @@ nodel: msgq(sp, M_BERR, "206|No characters to delete");
* PUBLIC: int v_Xchar __P((SCR *, VICMD *));
*/
int
-v_Xchar(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_Xchar(SCR *sp, VICMD *vp)
{
u_long cnt;
diff --git a/contrib/nvi/vi/v_yank.c b/contrib/nvi/vi/v_yank.c
index 4708f19..7b02cce 100644
--- a/contrib/nvi/vi/v_yank.c
+++ b/contrib/nvi/vi/v_yank.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_yank.c 10.9 (Berkeley) 5/19/96";
+static const char sccsid[] = "$Id: v_yank.c,v 10.10 2001/06/25 15:19:36 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -42,9 +42,7 @@ static const char sccsid[] = "@(#)v_yank.c 10.9 (Berkeley) 5/19/96";
* PUBLIC: int v_yank __P((SCR *, VICMD *));
*/
int
-v_yank(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_yank(SCR *sp, VICMD *vp)
{
size_t len;
diff --git a/contrib/nvi/vi/v_z.c b/contrib/nvi/vi/v_z.c
index 5f02ddf..9d4ef64 100644
--- a/contrib/nvi/vi/v_z.c
+++ b/contrib/nvi/vi/v_z.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_z.c 10.10 (Berkeley) 5/16/96";
+static const char sccsid[] = "$Id: v_z.c,v 10.13 2011/12/02 17:26:59 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -31,12 +31,10 @@ static const char sccsid[] = "@(#)v_z.c 10.10 (Berkeley) 5/16/96";
* PUBLIC: int v_z __P((SCR *, VICMD *));
*/
int
-v_z(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_z(SCR *sp, VICMD *vp)
{
recno_t lno;
- u_int value;
+ e_key_t value;
/*
* The first count is the line to use. If the value doesn't
@@ -136,9 +134,7 @@ v_z(sp, vp)
* PUBLIC: int vs_crel __P((SCR *, long));
*/
int
-vs_crel(sp, count)
- SCR *sp;
- long count;
+vs_crel(SCR *sp, long int count)
{
sp->t_minrows = sp->t_rows = count;
if (sp->t_rows > sp->rows - 1)
diff --git a/contrib/nvi/vi/v_zexit.c b/contrib/nvi/vi/v_zexit.c
index 3e454ca..a2decd6 100644
--- a/contrib/nvi/vi/v_zexit.c
+++ b/contrib/nvi/vi/v_zexit.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)v_zexit.c 10.6 (Berkeley) 4/27/96";
+static const char sccsid[] = "$Id: v_zexit.c,v 10.7 2001/06/25 15:19:37 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -32,9 +32,7 @@ static const char sccsid[] = "@(#)v_zexit.c 10.6 (Berkeley) 4/27/96";
* PUBLIC: int v_zexit __P((SCR *, VICMD *));
*/
int
-v_zexit(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_zexit(SCR *sp, VICMD *vp)
{
/* Write back any modifications. */
if (F_ISSET(sp->ep, F_MODIFIED) &&
diff --git a/contrib/nvi/vi/vi.c b/contrib/nvi/vi/vi.c
index d20f7f2..aafdbd1 100644
--- a/contrib/nvi/vi/vi.c
+++ b/contrib/nvi/vi/vi.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)vi.c 10.57 (Berkeley) 10/13/96";
+static const char sccsid[] = "$Id: vi.c,v 10.61 2011/12/21 13:08:30 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -40,7 +40,6 @@ static int v_count __P((SCR *, ARG_CHAR_T, u_long *));
static void v_dtoh __P((SCR *));
static int v_init __P((SCR *));
static gcret_t v_key __P((SCR *, int, EVENT *, u_int32_t));
-static int v_keyword __P((SCR *));
static int v_motion __P((SCR *, VICMD *, VICMD *, int *));
#if defined(DEBUG) && defined(COMLOG)
@@ -62,13 +61,12 @@ static void v_comlog __P((SCR *, VICMD *));
* PUBLIC: int vi __P((SCR **));
*/
int
-vi(spp)
- SCR **spp;
+vi(SCR **spp)
{
GS *gp;
MARK abs;
SCR *next, *sp;
- VICMD cmd, *vp;
+ VICMD cmd = { 0 }, *vp;
VI_PRIVATE *vip;
int comcount, mapped, rval;
@@ -76,9 +74,8 @@ vi(spp)
sp = *spp;
gp = sp->gp;
- /* Initialize the command structure. */
+ /* Point to the command structure. */
vp = &cmd;
- memset(vp, 0, sizeof(VICMD));
/* Reset strange attraction. */
F_SET(vp, VM_RCM_SET);
@@ -158,8 +155,6 @@ vi(spp)
case GC_ERR_NOFLUSH:
goto gc_err_noflush;
case GC_EVENT:
- if (v_event_exec(sp, vp))
- goto err;
goto gc_event;
case GC_FATAL:
goto ret;
@@ -347,9 +342,9 @@ gc_event:
* command, since the tag may be moving to the same file.
*/
if ((F_ISSET(vp, V_ABS) ||
- F_ISSET(vp, V_ABS_L) && sp->lno != abs.lno ||
- F_ISSET(vp, V_ABS_C) &&
- (sp->lno != abs.lno || sp->cno != abs.cno)) &&
+ (F_ISSET(vp, V_ABS_L) && sp->lno != abs.lno) ||
+ (F_ISSET(vp, V_ABS_C) &&
+ (sp->lno != abs.lno || sp->cno != abs.cno))) &&
mark_set(sp, ABSMARK1, &abs, 1))
goto err;
@@ -405,6 +400,7 @@ intr: CLR_INTERRUPT(sp);
if (F_ISSET(gp, G_SRESTART) || F_ISSET(sp, SC_EX)) {
*spp = sp;
v_dtoh(sp);
+ gp->scr_discard(sp, NULL);
break;
}
}
@@ -452,11 +448,13 @@ VIKEYS const tmotion = {
* [count] key [character]
*/
static gcret_t
-v_cmd(sp, dp, vp, ismotion, comcountp, mappedp)
- SCR *sp;
- VICMD *dp, *vp;
- VICMD *ismotion; /* Previous key if getting motion component. */
- int *comcountp, *mappedp;
+v_cmd(
+ SCR *sp,
+ VICMD *dp,
+ VICMD *vp,
+ VICMD *ismotion, /* Previous key if getting motion component. */
+ int *comcountp,
+ int *mappedp)
{
enum { COMMANDMODE, ISPARTIAL, NOTPARTIAL } cpart;
EVENT ev;
@@ -494,7 +492,7 @@ v_cmd(sp, dp, vp, ismotion, comcountp, mappedp)
if (ismotion == NULL)
cpart = NOTPARTIAL;
- /* Pick up optional buffer. */
+ /* Pick up an optional buffer. */
if (key == '"') {
cpart = ISPARTIAL;
if (ismotion != NULL) {
@@ -508,10 +506,10 @@ v_cmd(sp, dp, vp, ismotion, comcountp, mappedp)
}
/*
- * Pick up optional count, where a leading 0 is not a count,
+ * Pick up an optional count, where a leading 0 is not a count,
* it's a command.
*/
- if (isdigit(key) && key != '0') {
+ if (ISDIGIT(key) && key != '0') {
if (v_count(sp, key, &vp->count))
return (GC_ERR);
F_SET(vp, VC_C1SET);
@@ -650,7 +648,7 @@ v_cmd(sp, dp, vp, ismotion, comcountp, mappedp)
* Don't set the EC_MAPCOMMAND flag, apparently ] is a popular
* vi meta-character, and we don't want the user to wait while
* we time out a possible mapping. This *appears* to match
- * historic vi practice, but with mapping characters, you Just
+ * historic vi practice, but with mapping characters, You Just
* Never Know.
*/
KEY(key, 0);
@@ -669,7 +667,7 @@ usage: if (ismotion == NULL)
/* Special case: 'z' command. */
if (vp->key == 'z') {
KEY(vp->character, 0);
- if (isdigit(vp->character)) {
+ if (ISDIGIT(vp->character)) {
if (v_count(sp, vp->character, &vp->count2))
return (GC_ERR);
F_SET(vp, VC_C2SET);
@@ -678,8 +676,8 @@ usage: if (ismotion == NULL)
}
/*
- * Commands that have motion components can be doubled to
- * imply the current line.
+ * Commands that have motion components can be doubled to imply the
+ * current line.
*/
if (ismotion != NULL && ismotion->key != key && !LF_ISSET(V_MOVE)) {
msgq(sp, M_ERR, "210|%s may not be used as a motion command",
@@ -687,12 +685,12 @@ usage: if (ismotion == NULL)
return (GC_ERR);
}
- /* Required character. */
+ /* Pick up required trailing character. */
if (LF_ISSET(V_CHAR))
KEY(vp->character, 0);
/* Get any associated cursor word. */
- if (F_ISSET(kp, V_KEYW) && v_keyword(sp))
+ if (F_ISSET(kp, V_KEYW) && v_curword(sp))
return (GC_ERR);
return (GC_OK);
@@ -716,10 +714,11 @@ esc: switch (cpart) {
* Get resulting motion mark.
*/
static int
-v_motion(sp, dm, vp, mappedp)
- SCR *sp;
- VICMD *dm, *vp;
- int *mappedp;
+v_motion(
+ SCR *sp,
+ VICMD *dm,
+ VICMD *vp,
+ int *mappedp)
{
VICMD motion;
size_t len;
@@ -785,7 +784,7 @@ v_motion(sp, dm, vp, mappedp)
vp->m_stop.lno = sp->lno + motion.count - 1;
if (db_get(sp, vp->m_stop.lno, 0, NULL, &len)) {
if (vp->m_stop.lno != 1 ||
- vp->key != 'c' && vp->key != '!') {
+ (vp->key != 'c' && vp->key != '!')) {
v_emsg(sp, NULL, VIM_EMPTY);
return (1);
}
@@ -857,7 +856,7 @@ v_motion(sp, dm, vp, mappedp)
*/
if (!db_exist(sp, vp->m_stop.lno)) {
if (vp->m_stop.lno != 1 ||
- vp->key != 'c' && vp->key != '!') {
+ (vp->key != 'c' && vp->key != '!')) {
v_emsg(sp, NULL, VIM_EMPTY);
return (1);
}
@@ -901,8 +900,8 @@ v_motion(sp, dm, vp, mappedp)
* Motions are from the from MARK to the to MARK (inclusive).
*/
if (motion.m_start.lno > motion.m_stop.lno ||
- motion.m_start.lno == motion.m_stop.lno &&
- motion.m_start.cno > motion.m_stop.cno) {
+ (motion.m_start.lno == motion.m_stop.lno &&
+ motion.m_start.cno > motion.m_stop.cno)) {
vp->m_start = motion.m_stop;
vp->m_stop = motion.m_start;
} else {
@@ -929,8 +928,7 @@ v_motion(sp, dm, vp, mappedp)
* Initialize the vi screen.
*/
static int
-v_init(sp)
- SCR *sp;
+v_init(SCR *sp)
{
GS *gp;
VI_PRIVATE *vip;
@@ -964,12 +962,12 @@ v_init(sp)
sp->t_minrows = sp->t_rows = sp->rows - 1;
msgq(sp, M_INFO,
"214|Windows option value is too large, max is %u",
- sp->t_rows);
+ (u_int)sp->t_rows);
}
sp->t_maxrows = sp->rows - 1;
} else
sp->t_maxrows = 1;
- sp->woff = 0;
+ sp->roff = sp->coff = 0;
/* Create a screen map. */
CALLOC_RET(sp, HMAP, SMAP *, SIZE_HMAP(sp), sizeof(SMAP));
@@ -1000,8 +998,7 @@ v_init(sp)
* Move all but the current screen to the hidden queue.
*/
static void
-v_dtoh(sp)
- SCR *sp;
+v_dtoh(SCR *sp)
{
GS *gp;
SCR *tsp;
@@ -1009,42 +1006,40 @@ v_dtoh(sp)
/* Move all screens to the hidden queue, tossing screen maps. */
for (hidden = 0, gp = sp->gp;
- (tsp = gp->dq.cqh_first) != (void *)&gp->dq; ++hidden) {
+ (tsp = TAILQ_FIRST(gp->dq)) != NULL; ++hidden) {
if (_HMAP(tsp) != NULL) {
free(_HMAP(tsp));
_HMAP(tsp) = NULL;
}
- CIRCLEQ_REMOVE(&gp->dq, tsp, q);
- CIRCLEQ_INSERT_TAIL(&gp->hq, tsp, q);
+ TAILQ_REMOVE(gp->dq, tsp, q);
+ TAILQ_INSERT_TAIL(gp->hq, tsp, q);
+ /* XXXX Change if hidden screens per window */
+ gp->scr_discard(tsp, NULL);
}
/* Move current screen back to the display queue. */
- CIRCLEQ_REMOVE(&gp->hq, sp, q);
- CIRCLEQ_INSERT_TAIL(&gp->dq, sp, q);
+ TAILQ_REMOVE(gp->hq, sp, q);
+ TAILQ_INSERT_TAIL(gp->dq, sp, q);
- /*
- * XXX
- * Don't bother internationalizing this message, it's going to
- * go away as soon as we have one-line screens. --TK
- */
if (hidden > 1)
msgq(sp, M_INFO,
- "%d screens backgrounded; use :display to list them",
+ "319|%d screens backgrounded; use :display to list them",
hidden - 1);
}
/*
- * v_keyword --
- * Get the word (or non-word) the cursor is on.
+ * v_curword --
+ * Get the word (tagstring, actually) the cursor is on.
+ *
+ * PUBLIC: int v_curword __P((SCR *));
*/
-static int
-v_keyword(sp)
- SCR *sp;
+int
+v_curword(SCR *sp)
{
VI_PRIVATE *vip;
size_t beg, end, len;
- int moved, state;
- char *p;
+ int moved;
+ CHAR_T *p;
if (db_get(sp, sp->lno, DBG_FATAL, &p, &len))
return (1);
@@ -1065,7 +1060,7 @@ v_keyword(sp)
* follow the same rule.
*/
for (moved = 0,
- beg = sp->cno; beg < len && isspace(p[beg]); moved = 1, ++beg);
+ beg = sp->cno; beg < len && ISSPACE(p[beg]); moved = 1, ++beg);
if (beg >= len) {
msgq(sp, M_BERR, "212|Cursor not in a word");
return (1);
@@ -1075,14 +1070,19 @@ v_keyword(sp)
(void)vs_refresh(sp, 0);
}
- /* Find the end of the word. */
- for (state = inword(p[beg]),
- end = beg; ++end < len && state == inword(p[end]););
+ /*
+ * Find the end of the word.
+ *
+ * !!!
+ * Historically, vi accepted any non-blank as initial character
+ * when building up a tagstring. Required by IEEE 1003.1-2001.
+ */
+ for (end = beg; ++end < len && inword(p[end]););
vip = VIP(sp);
- len = (end - beg);
- BINC_RET(sp, vip->keyw, vip->klen, len);
- memmove(vip->keyw, p + beg, len);
+ vip->klen = len = (end - beg);
+ BINC_RETW(sp, vip->keyw, vip->keywlen, len+1);
+ MEMMOVE(vip->keyw, p + beg, len);
vip->keyw[len] = '\0'; /* XXX */
return (0);
}
@@ -1092,10 +1092,10 @@ v_keyword(sp)
* Check for a command alias.
*/
static VIKEYS const *
-v_alias(sp, vp, kp)
- SCR *sp;
- VICMD *vp;
- VIKEYS const *kp;
+v_alias(
+ SCR *sp,
+ VICMD *vp,
+ VIKEYS const *kp)
{
CHAR_T push;
@@ -1128,10 +1128,10 @@ v_alias(sp, vp, kp)
* Return the next count.
*/
static int
-v_count(sp, fkey, countp)
- SCR *sp;
- ARG_CHAR_T fkey;
- u_long *countp;
+v_count(
+ SCR *sp,
+ ARG_CHAR_T fkey,
+ u_long *countp)
{
EVENT ev;
u_long count, tc;
@@ -1150,7 +1150,7 @@ v_count(sp, fkey, countp)
if (v_key(sp, 0, &ev,
EC_MAPCOMMAND | EC_MAPNODIGIT) != GC_OK)
return (1);
- } while (isdigit(ev.e_c));
+ } while (ISDIGIT(ev.e_c));
msgq(sp, M_ERR,
"235|Number larger than %lu", ULONG_MAX);
return (1);
@@ -1158,7 +1158,7 @@ v_count(sp, fkey, countp)
count = tc;
if (v_key(sp, 0, &ev, EC_MAPCOMMAND | EC_MAPNODIGIT) != GC_OK)
return (1);
- } while (isdigit(ev.e_c));
+ } while (ISDIGIT(ev.e_c));
*countp = count;
return (0);
}
@@ -1168,11 +1168,11 @@ v_count(sp, fkey, countp)
* Return the next event.
*/
static gcret_t
-v_key(sp, command_events, evp, ec_flags)
- SCR *sp;
- int command_events;
- EVENT *evp;
- u_int32_t ec_flags;
+v_key(
+ SCR *sp,
+ int command_events,
+ EVENT *evp,
+ u_int32_t ec_flags)
{
u_int32_t quote;
@@ -1216,10 +1216,6 @@ v_key(sp, command_events, evp, ec_flags)
break;
case E_WRESIZE:
return (GC_ERR);
- case E_QUIT:
- case E_WRITE:
- if (command_events)
- return (GC_EVENT);
/* FALLTHROUGH */
default:
v_event_err(sp, evp);
@@ -1235,13 +1231,13 @@ v_key(sp, command_events, evp, ec_flags)
* Log the contents of the command structure.
*/
static void
-v_comlog(sp, vp)
- SCR *sp;
- VICMD *vp;
+v_comlog(
+ SCR *sp,
+ VICMD *vp)
{
- TRACE(sp, "vcmd: %c", vp->key);
+ TRACE(sp, "vcmd: "WC, vp->key);
if (F_ISSET(vp, VC_BUFFER))
- TRACE(sp, " buffer: %c", vp->buffer);
+ TRACE(sp, " buffer: "WC, vp->buffer);
if (F_ISSET(vp, VC_C1SET))
TRACE(sp, " c1: %lu", vp->count);
if (F_ISSET(vp, VC_C2SET))
diff --git a/contrib/nvi/vi/vi.h b/contrib/nvi/vi/vi.h
index bede3a6..2cfbb99 100644
--- a/contrib/nvi/vi/vi.h
+++ b/contrib/nvi/vi/vi.h
@@ -6,11 +6,11 @@
*
* See the LICENSE file for redistribution information.
*
- * @(#)vi.h 10.19 (Berkeley) 6/30/96
+ * $Id: vi.h,v 10.29 2012/02/11 00:33:46 zy Exp $
*/
/* Definition of a vi "word". */
-#define inword(ch) (isalnum(ch) || (ch) == '_')
+#define inword(ch) ((ch) == '_' || (ISGRAPH(ch) && !ISPUNCT(ch)))
typedef struct _vikeys VIKEYS;
@@ -188,23 +188,24 @@ int cs_prev __P((SCR *, VCS *));
* slot for the colon command line, so there is room to add any screen into
* another one at screen exit.
*
- * Lno is the line number. If doing the historic vi long line folding, off
+ * Lno is the line number. If doing the historic vi long line folding, soff
* is the screen offset into the line. For example, the pair 2:1 would be
* the first screen of line 2, and 2:2 would be the second. In the case of
* long lines, the screen map will tend to be staggered, e.g., 1:1, 1:2, 1:3,
- * 2:1, 3:1, etc. If doing left-right scrolling, the off field is the screen
+ * 2:1, 3:1, etc. If doing left-right scrolling, the coff field is the screen
* column offset into the lines, and can take on any value, as it's adjusted
* by the user set value O_SIDESCROLL.
*/
typedef struct _smap {
- recno_t lno; /* 1-N: Physical file line number. */
+ recno_t lno; /* 1-N: Physical file line number. */
size_t coff; /* 0-N: Column offset in the line. */
size_t soff; /* 1-N: Screen offset in the line. */
/* vs_line() cache information. */
- size_t c_sboff; /* 0-N: offset of first character byte. */
- size_t c_eboff; /* 0-N: offset of last character byte. */
+ size_t c_sboff; /* 0-N: offset of first character on screen. */
+ size_t c_eboff; /* 0-N: offset of last character on screen. */
u_int8_t c_scoff; /* 0-N: offset into the first character. */
+ /* 255: no character of line visible. */
u_int8_t c_eclen; /* 1-N: columns from the last character. */
u_int8_t c_ecsize; /* 1-N: size of the last character. */
} SMAP;
@@ -253,8 +254,11 @@ typedef struct _vi_private {
size_t busy_fx; /* Busy character x coordinate. */
size_t busy_oldy; /* Saved y coordinate. */
size_t busy_oldx; /* Saved x coordinate. */
- struct timeval busy_tv; /* Busy timer. */
+ struct timespec busy_ts;/* Busy timer. */
+ MARK sel; /* Select start position. */
+
+ CHAR_T *mcs; /* Match character list. */
char *ps; /* Paragraph plus section list. */
u_long u_ccnt; /* Undo command count. */
@@ -351,10 +355,15 @@ typedef struct _vi_private {
*/
#define TAB_OFF(c) COL_OFF((c), O_VAL(sp, O_TABSTOP))
+/* If more than one horizontal screen being shown. */
+#define IS_HSPLIT(sp) \
+ ((sp)->rows != O_VAL(sp, O_LINES))
+/* If more than one vertical screen being shown. */
+#define IS_VSPLIT(sp) \
+ ((sp)->cols != O_VAL(sp, O_COLUMNS))
/* If more than one screen being shown. */
#define IS_SPLIT(sp) \
- ((sp)->q.cqe_next != (void *)&(sp)->gp->dq || \
- (sp)->q.cqe_prev != (void *)&(sp)->gp->dq)
+ (IS_HSPLIT(sp) || IS_VSPLIT(sp))
/* Screen adjustment operations. */
typedef enum { A_DECREASE, A_INCREASE, A_SET } adj_t;
@@ -374,4 +383,4 @@ typedef enum {
VIM_NOCOM, VIM_NOCOM_B, VIM_USAGE, VIM_WRESIZE
} vim_t;
-#include "vi_extern.h"
+#include "extern.h"
diff --git a/contrib/nvi/vi/vs_line.c b/contrib/nvi/vi/vs_line.c
index 495e75e..dc12a3a 100644
--- a/contrib/nvi/vi/vs_line.c
+++ b/contrib/nvi/vi/vs_line.c
@@ -10,11 +10,7 @@
#include "config.h"
#ifndef lint
-#if 0
-static const char sccsid[] = "@(#)vs_line.c 10.19 (Berkeley) 9/26/96";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
+static const char sccsid[] = "$Id: vs_line.c,v 10.40 2012/02/13 19:22:25 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -42,20 +38,19 @@ static const char rcsid[] =
* PUBLIC: int vs_line __P((SCR *, SMAP *, size_t *, size_t *));
*/
int
-vs_line(sp, smp, yp, xp)
- SCR *sp;
- SMAP *smp;
- size_t *xp, *yp;
+vs_line(SCR *sp, SMAP *smp, size_t *yp, size_t *xp)
{
- CHAR_T *kp;
+ u_char *kp;
GS *gp;
SMAP *tsmp;
- size_t chlen, cno_cnt, cols_per_screen, len, nlen;
+ size_t chlen = 0, cno_cnt, cols_per_screen, len, nlen;
size_t offset_in_char, offset_in_line, oldx, oldy;
size_t scno, skip_cols, skip_screens;
- int ch, dne, is_cached, is_partial, is_tab, no_draw;
+ int dne, is_cached, is_partial, is_tab, no_draw;
int list_tab, list_dollar;
- char *p, *cbp, *ecbp, cbuf[128];
+ CHAR_T *p;
+ CHAR_T *cbp, *ecbp, cbuf[128];
+ ARG_CHAR_T ch = '\0';
#if defined(DEBUG) && 0
TRACE(sp, "vs_line: row %u: line: %u off: %u\n",
@@ -143,9 +138,9 @@ vs_line(sp, smp, yp, xp)
if (O_ISSET(sp, O_NUMBER)) {
cols_per_screen -= O_NUMBER_LENGTH;
if ((!dne || smp->lno == 1) && skip_cols == 0) {
- nlen = snprintf(cbuf, sizeof(cbuf),
- O_NUMBER_FMT, (u_long)smp->lno);
- (void)gp->scr_addstr(sp, cbuf, nlen);
+ nlen = snprintf((char*)cbuf,
+ sizeof(cbuf), O_NUMBER_FMT, (u_long)smp->lno);
+ (void)gp->scr_addstr(sp, (char*)cbuf, nlen);
}
}
}
@@ -197,6 +192,12 @@ empty: (void)gp->scr_addstr(sp,
return (0);
}
+ /* If we shortened this line in another screen, the cursor
+ * position may have fallen off.
+ */
+ if (sp->lno == smp->lno && sp->cno >= len)
+ sp->cno = len - 1;
+
/*
* If we just wrote this or a previous line, we cached the starting
* and ending positions of that line. The way it works is we keep
@@ -262,8 +263,8 @@ empty: (void)gp->scr_addstr(sp,
/* Do it the hard way, for leftright scrolling screens. */
if (O_ISSET(sp, O_LEFTRIGHT)) {
for (; offset_in_line < len; ++offset_in_line) {
- chlen = (ch = *(u_char *)p++) == '\t' && !list_tab ?
- TAB_OFF(scno) : KEY_LEN(sp, ch);
+ chlen = (ch = *p++) == '\t' && !list_tab ?
+ TAB_OFF(scno) : KEY_COL(sp, ch);
if ((scno += chlen) >= skip_cols)
break;
}
@@ -289,8 +290,8 @@ empty: (void)gp->scr_addstr(sp,
/* Do it the hard way, for historic line-folding screens. */
else {
for (; offset_in_line < len; ++offset_in_line) {
- chlen = (ch = *(u_char *)p++) == '\t' && !list_tab ?
- TAB_OFF(scno) : KEY_LEN(sp, ch);
+ chlen = (ch = *p++) == '\t' && !list_tab ?
+ TAB_OFF(scno) : KEY_COL(sp, ch);
if ((scno += chlen) < cols_per_screen)
continue;
scno -= cols_per_screen;
@@ -336,14 +337,14 @@ display:
cno_cnt = (sp->cno - offset_in_line) + 1;
/* This is the loop that actually displays characters. */
- ecbp = (cbp = cbuf) + sizeof(cbuf) - 1;
+ ecbp = (cbp = cbuf) + SIZE(cbuf) - 1;
for (is_partial = 0, scno = 0;
offset_in_line < len; ++offset_in_line, offset_in_char = 0) {
- if ((ch = *(u_char *)p++) == '\t' && !list_tab) {
+ if ((ch = *p++) == '\t' && !list_tab) {
scno += chlen = TAB_OFF(scno) - offset_in_char;
is_tab = 1;
} else {
- scno += chlen = KEY_LEN(sp, ch) - offset_in_char;
+ scno += chlen = KEY_COL(sp, ch) - offset_in_char;
is_tab = 0;
}
@@ -386,7 +387,10 @@ display:
--cno_cnt == 0 && (F_ISSET(sp, SC_TINPUT) || !is_partial)) {
*yp = smp - HMAP;
if (F_ISSET(sp, SC_TINPUT))
- *xp = scno - chlen;
+ if (is_partial)
+ *xp = scno - smp->c_ecsize;
+ else
+ *xp = scno - chlen;
else
*xp = scno - 1;
if (O_ISSET(sp, O_NUMBER) &&
@@ -404,7 +408,7 @@ display:
#define FLUSH { \
*cbp = '\0'; \
- (void)gp->scr_addstr(sp, cbuf, cbp - cbuf); \
+ (void)gp->scr_waddstr(sp, cbuf, cbp - cbuf); \
cbp = cbuf; \
}
/*
@@ -423,14 +427,26 @@ display:
else {
if (cbp + chlen >= ecbp)
FLUSH;
- for (kp = KEY_NAME(sp, ch) + offset_in_char; chlen--;)
- *cbp++ = *kp++;
+
+ /* don't display half a wide character */
+ if (is_partial && CHAR_WIDTH(sp, ch) > 1) {
+ *cbp++ = ' ';
+ break;
+ }
+
+ if (KEY_NEEDSWIDE(sp, ch))
+ *cbp++ = ch;
+ else
+ for (kp = (u_char *)
+ KEY_NAME(sp, ch) + offset_in_char;
+ chlen--;)
+ *cbp++ = *kp++;
}
}
if (scno < cols_per_screen) {
/* If didn't paint the whole line, update the cache. */
- smp->c_ecsize = smp->c_eclen = KEY_LEN(sp, ch);
+ smp->c_ecsize = smp->c_eclen = KEY_COL(sp, ch);
smp->c_eboff = len - 1;
/*
@@ -444,7 +460,8 @@ display:
chlen = KEY_LEN(sp, '$');
if (cbp + chlen >= ecbp)
FLUSH;
- for (kp = KEY_NAME(sp, '$'); chlen--;)
+ for (kp = (u_char *)
+ KEY_NAME(sp, '$'); chlen--;)
*cbp++ = *kp++;
}
@@ -468,8 +485,7 @@ ret1: (void)gp->scr_move(sp, oldy, oldx);
* PUBLIC: int vs_number __P((SCR *));
*/
int
-vs_number(sp)
- SCR *sp;
+vs_number(SCR *sp)
{
GS *gp;
SMAP *smp;
@@ -514,8 +530,7 @@ vs_number(sp)
break;
(void)gp->scr_move(sp, smp - HMAP, 0);
- len = snprintf(nbuf, sizeof(nbuf),
- O_NUMBER_FMT, (u_long)smp->lno);
+ len = snprintf(nbuf, sizeof(nbuf), O_NUMBER_FMT, (u_long)smp->lno);
(void)gp->scr_addstr(sp, nbuf, len);
}
(void)gp->scr_move(sp, oldy, oldx);
diff --git a/contrib/nvi/vi/vs_msg.c b/contrib/nvi/vi/vs_msg.c
index 7ef8f53..32b2755 100644
--- a/contrib/nvi/vi/vs_msg.c
+++ b/contrib/nvi/vi/vs_msg.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)vs_msg.c 10.77 (Berkeley) 10/13/96";
+static const char sccsid[] = "$Id: vs_msg.c,v 10.88 2013/03/19 09:59:03 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -56,15 +56,13 @@ static void vs_wait __P((SCR *, int *, sw_t));
* PUBLIC: void vs_busy __P((SCR *, const char *, busy_t));
*/
void
-vs_busy(sp, msg, btype)
- SCR *sp;
- const char *msg;
- busy_t btype;
+vs_busy(SCR *sp, const char *msg, busy_t btype)
{
GS *gp;
VI_PRIVATE *vip;
static const char flagc[] = "|/-\\";
- struct timeval tv;
+ struct timespec ts, ts_diff;
+ const struct timespec ts_min = { 0, 125000000 };
size_t len, notused;
const char *p;
@@ -89,7 +87,7 @@ vs_busy(sp, msg, btype)
/* Initialize state for updates. */
vip->busy_ch = 0;
- (void)gettimeofday(&vip->busy_tv, NULL);
+ timepoint_steady(&vip->busy_ts);
/* Save the current cursor. */
(void)gp->scr_cursor(sp, &vip->busy_oldy, &vip->busy_oldx);
@@ -122,11 +120,12 @@ vs_busy(sp, msg, btype)
break;
/* Update no more than every 1/8 of a second. */
- (void)gettimeofday(&tv, NULL);
- if (((tv.tv_sec - vip->busy_tv.tv_sec) * 1000000 +
- (tv.tv_usec - vip->busy_tv.tv_usec)) < 125000)
+ timepoint_steady(&ts);
+ ts_diff = ts;
+ timespecsub(&ts_diff, &vip->busy_ts);
+ if (timespeccmp(&ts_diff, &ts_min, <))
return;
- vip->busy_tv = tv;
+ vip->busy_ts = ts;
/* Display the update. */
if (vip->busy_ch == sizeof(flagc) - 1)
@@ -146,8 +145,7 @@ vs_busy(sp, msg, btype)
* PUBLIC: void vs_home __P((SCR *));
*/
void
-vs_home(sp)
- SCR *sp;
+vs_home(SCR *sp)
{
(void)sp->gp->scr_move(sp, LASTLINE(sp), 0);
(void)sp->gp->scr_refresh(sp, 0);
@@ -157,15 +155,15 @@ vs_home(sp)
* vs_update --
* Update a command.
*
- * PUBLIC: void vs_update __P((SCR *, const char *, const char *));
+ * PUBLIC: void vs_update __P((SCR *, const char *, const CHAR_T *));
*/
void
-vs_update(sp, m1, m2)
- SCR *sp;
- const char *m1, *m2;
+vs_update(SCR *sp, const char *m1, const CHAR_T *m2)
{
GS *gp;
size_t len, mlen, oldx, oldy;
+ CONST char *np;
+ size_t nlen;
gp = sp->gp;
@@ -178,8 +176,10 @@ vs_update(sp, m1, m2)
* expanded, and by the ex substitution confirmation prompt.
*/
if (F_ISSET(sp, SC_SCR_EXWROTE)) {
+ if (m2 != NULL)
+ INT2CHAR(sp, m2, STRLEN(m2) + 1, np, nlen);
(void)ex_printf(sp,
- "%s\n", m1 == NULL? "" : m1, m2 == NULL ? "" : m2);
+ "%s\n", m1 == NULL? "" : m1, m2 == NULL ? "" : np);
(void)ex_fflush(sp);
}
@@ -205,10 +205,10 @@ vs_update(sp, m1, m2)
} else
len = 0;
if (m2 != NULL) {
- mlen = strlen(m2);
+ mlen = STRLEN(m2);
if (len + mlen > sp->cols - 2)
mlen = (sp->cols - 2) - len;
- (void)gp->scr_addstr(sp, m2, mlen);
+ (void)gp->scr_waddstr(sp, m2, mlen);
}
(void)gp->scr_move(sp, oldy, oldx);
@@ -228,11 +228,7 @@ vs_update(sp, m1, m2)
* PUBLIC: void vs_msg __P((SCR *, mtype_t, char *, size_t));
*/
void
-vs_msg(sp, mtype, line, len)
- SCR *sp;
- mtype_t mtype;
- char *line;
- size_t len;
+vs_msg(SCR *sp, mtype_t mtype, char *line, size_t len)
{
GS *gp;
VI_PRIVATE *vip;
@@ -394,17 +390,12 @@ ret: (void)gp->scr_move(sp, oldy, oldx);
* Output the text to the screen.
*/
static void
-vs_output(sp, mtype, line, llen)
- SCR *sp;
- mtype_t mtype;
- const char *line;
- int llen;
+vs_output(SCR *sp, mtype_t mtype, const char *line, int llen)
{
- CHAR_T *kp;
GS *gp;
VI_PRIVATE *vip;
- size_t chlen, notused;
- int ch, len, rlen, tlen;
+ size_t notused;
+ int len, rlen, tlen;
const char *p, *t;
char *cbp, *ecbp, cbuf[128];
@@ -472,7 +463,6 @@ vs_output(sp, mtype, line, llen)
}
ecbp = (cbp = cbuf) + sizeof(cbuf) - 1;
for (t = line, tlen = len; tlen--; ++t) {
- ch = *t;
/*
* Replace tabs with spaces, there are places in
* ex that do column calculations without looking
@@ -480,13 +470,9 @@ vs_output(sp, mtype, line, llen)
* <tabs> do their own expansions. This catches
* <tabs> in things like tag search strings.
*/
- if (ch == '\t')
- ch = ' ';
- chlen = KEY_LEN(sp, ch);
- if (cbp + chlen >= ecbp)
+ if (cbp + 1 >= ecbp)
FLUSH;
- for (kp = KEY_NAME(sp, ch); chlen--;)
- *cbp++ = *kp++;
+ *cbp++ = *t == '\t' ? ' ' : *t;
}
if (cbp > cbuf)
FLUSH;
@@ -523,9 +509,7 @@ vs_output(sp, mtype, line, llen)
* PUBLIC: int vs_ex_resolve __P((SCR *, int *));
*/
int
-vs_ex_resolve(sp, continuep)
- SCR *sp;
- int *continuep;
+vs_ex_resolve(SCR *sp, int *continuep)
{
EVENT ev;
GS *gp;
@@ -598,7 +582,7 @@ vs_ex_resolve(sp, continuep)
* If we're not the bottom of the split screen stack, the screen
* image itself is wrong, so redraw everything.
*/
- if (sp->q.cqe_next != (void *)&sp->gp->dq)
+ if (TAILQ_NEXT(sp, q) != NULL)
F_SET(sp, SC_SCR_REDRAW);
/* If ex changed the underlying file, the map itself is wrong. */
@@ -649,9 +633,7 @@ vs_ex_resolve(sp, continuep)
* PUBLIC: int vs_resolve __P((SCR *, SCR *, int));
*/
int
-vs_resolve(sp, csp, forcewait)
- SCR *sp, *csp;
- int forcewait;
+vs_resolve(SCR *sp, SCR *csp, int forcewait)
{
EVENT ev;
GS *gp;
@@ -696,12 +678,12 @@ vs_resolve(sp, csp, forcewait)
* messages.) Once this is done, don't trust the cursor. That
* extra refresh screwed the pooch.
*/
- if (gp->msgq.lh_first != NULL) {
+ if (!SLIST_EMPTY(gp->msgq)) {
if (!F_ISSET(sp, SC_SCR_VI) && vs_refresh(sp, 1))
return (1);
- while ((mp = gp->msgq.lh_first) != NULL) {
+ while ((mp = SLIST_FIRST(gp->msgq)) != NULL) {
gp->scr_msg(sp, mp->mtype, mp->buf, mp->len);
- LIST_REMOVE(mp, q);
+ SLIST_REMOVE_HEAD(gp->msgq, q);
free(mp->buf);
free(mp);
}
@@ -758,10 +740,7 @@ vs_resolve(sp, csp, forcewait)
* Scroll the screen for output.
*/
static void
-vs_scroll(sp, continuep, wtype)
- SCR *sp;
- int *continuep;
- sw_t wtype;
+vs_scroll(SCR *sp, int *continuep, sw_t wtype)
{
GS *gp;
VI_PRIVATE *vip;
@@ -779,7 +758,7 @@ vs_scroll(sp, continuep, wtype)
(void)gp->scr_deleteln(sp);
/* If there are screens below us, push them back into place. */
- if (sp->q.cqe_next != (void *)&sp->gp->dq) {
+ if (TAILQ_NEXT(sp, q) != NULL) {
(void)gp->scr_move(sp, LASTLINE(sp), 0);
(void)gp->scr_insertln(sp);
}
@@ -794,10 +773,7 @@ vs_scroll(sp, continuep, wtype)
* Prompt the user to continue.
*/
static void
-vs_wait(sp, continuep, wtype)
- SCR *sp;
- int *continuep;
- sw_t wtype;
+vs_wait(SCR *sp, int *continuep, sw_t wtype)
{
EVENT ev;
VI_PRIVATE *vip;
@@ -868,8 +844,7 @@ vs_wait(sp, continuep, wtype)
* Draw a dividing line between the screen and the output.
*/
static void
-vs_divider(sp)
- SCR *sp;
+vs_divider(SCR *sp)
{
GS *gp;
size_t len;
@@ -888,11 +863,7 @@ vs_divider(sp)
* Save a message for later display.
*/
static void
-vs_msgsave(sp, mt, p, len)
- SCR *sp;
- mtype_t mt;
- char *p;
- size_t len;
+vs_msgsave(SCR *sp, mtype_t mt, char *p, size_t len)
{
GS *gp;
MSGS *mp_c, *mp_n;
@@ -912,11 +883,13 @@ vs_msgsave(sp, mt, p, len)
mp_n->mtype = mt;
gp = sp->gp;
- if ((mp_c = gp->msgq.lh_first) == NULL) {
- LIST_INSERT_HEAD(&gp->msgq, mp_n, q);
+ if (SLIST_EMPTY(gp->msgq)) {
+ SLIST_INSERT_HEAD(gp->msgq, mp_n, q);
} else {
- for (; mp_c->q.le_next != NULL; mp_c = mp_c->q.le_next);
- LIST_INSERT_AFTER(mp_c, mp_n, q);
+ SLIST_FOREACH(mp_c, gp->msgq, q)
+ if (SLIST_NEXT(mp_c, q) == NULL)
+ break;
+ SLIST_INSERT_AFTER(mp_c, mp_n, q);
}
return;
diff --git a/contrib/nvi/vi/vs_refresh.c b/contrib/nvi/vi/vs_refresh.c
index f69d382..98b66c4 100644
--- a/contrib/nvi/vi/vs_refresh.c
+++ b/contrib/nvi/vi/vs_refresh.c
@@ -10,11 +10,7 @@
#include "config.h"
#ifndef lint
-#if 0
-static const char sccsid[] = "@(#)vs_refresh.c 10.44 (Berkeley) 10/13/96";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
+static const char sccsid[] = "$Id: vs_refresh.c,v 10.52 2011/12/16 11:06:25 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -44,9 +40,9 @@ static int vs_paint __P((SCR *, u_int));
* PUBLIC: int vs_repaint __P((SCR *, EVENT *));
*/
int
-vs_repaint(sp, evp)
- SCR *sp;
- EVENT *evp;
+vs_repaint(
+ SCR *sp,
+ EVENT *evp)
{
SMAP *smp;
@@ -66,13 +62,13 @@ vs_repaint(sp, evp)
* PUBLIC: int vs_refresh __P((SCR *, int));
*/
int
-vs_refresh(sp, forcepaint)
- SCR *sp;
- int forcepaint;
+vs_refresh(
+ SCR *sp,
+ int forcepaint)
{
GS *gp;
SCR *tsp;
- int need_refresh;
+ int need_refresh = 0;
u_int priv_paint, pub_paint;
gp = sp->gp;
@@ -84,8 +80,7 @@ vs_refresh(sp, forcepaint)
* that we can find, including status lines.
*/
if (F_ISSET(sp, SC_SCR_REDRAW))
- for (tsp = gp->dq.cqh_first;
- tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next)
+ TAILQ_FOREACH(tsp, gp->dq, q)
if (tsp != sp)
F_SET(tsp, SC_SCR_REDRAW | SC_STATUS);
@@ -102,8 +97,7 @@ vs_refresh(sp, forcepaint)
priv_paint = VIP_CUR_INVALID | VIP_N_REFRESH;
if (O_ISSET(sp, O_NUMBER))
priv_paint |= VIP_N_RENUMBER;
- for (tsp = gp->dq.cqh_first;
- tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next)
+ TAILQ_FOREACH(tsp, gp->dq, q)
if (tsp != sp && !F_ISSET(tsp, SC_EXIT | SC_EXIT_FORCE) &&
(F_ISSET(tsp, pub_paint) ||
F_ISSET(VIP(tsp), priv_paint))) {
@@ -138,8 +132,7 @@ vs_refresh(sp, forcepaint)
* And, finally, if we updated any status lines, make sure the cursor
* gets back to where it belongs.
*/
- for (need_refresh = 0, tsp = gp->dq.cqh_first;
- tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next)
+ TAILQ_FOREACH(tsp, gp->dq, q)
if (F_ISSET(tsp, SC_STATUS)) {
need_refresh = 1;
vs_resolve(tsp, sp, 0);
@@ -166,17 +159,17 @@ vs_refresh(sp, forcepaint)
* what you're doing. It's subtle and quick to anger.
*/
static int
-vs_paint(sp, flags)
- SCR *sp;
- u_int flags;
+vs_paint(
+ SCR *sp,
+ u_int flags)
{
GS *gp;
SMAP *smp, tmp;
VI_PRIVATE *vip;
recno_t lastline, lcnt;
size_t cwtotal, cnt, len, notused, off, y;
- int ch, didpaint, isempty, leftright_warp;
- char *p;
+ int ch = 0, didpaint, isempty, leftright_warp;
+ CHAR_T *p;
#define LNO sp->lno /* Current file line. */
#define OLNO vip->olno /* Remembered file line. */
@@ -474,7 +467,7 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) &&
#ifdef DEBUG
/* Sanity checking. */
if (CNO >= len && len != 0) {
- msgq(sp, M_ERR, "Error: %s/%d: cno (%u) >= len (%u)",
+ msgq(sp, M_ERR, "Error: %s/%d: cno (%zu) >= len (%zu)",
tail(__FILE__), __LINE__, CNO, len);
return (1);
}
@@ -511,8 +504,8 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) &&
* Count up the widths of the characters. If it's a tab
* character, go do it the the slow way.
*/
- for (cwtotal = 0; cnt--; cwtotal += KEY_LEN(sp, ch))
- if ((ch = *(u_char *)p--) == '\t')
+ for (cwtotal = 0; cnt--; cwtotal += KEY_COL(sp, ch))
+ if ((ch = *(UCHAR_T *)p--) == '\t')
goto slow;
/*
@@ -525,8 +518,8 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) &&
* If we're moving left, and there's a wide character in the
* current position, go to the end of the character.
*/
- if (KEY_LEN(sp, ch) > 1)
- cwtotal -= KEY_LEN(sp, ch) - 1;
+ if (KEY_COL(sp, ch) > 1)
+ cwtotal -= KEY_COL(sp, ch) - 1;
/*
* If the new column moved us off of the current logical line,
@@ -551,9 +544,9 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) &&
* screen boundary, we can quit.
*/
for (cwtotal = SCNO; cnt--;) {
- if ((ch = *(u_char *)p++) == '\t')
+ if ((ch = *(UCHAR_T *)p++) == '\t')
goto slow;
- if ((cwtotal += KEY_LEN(sp, ch)) >= SCREEN_COLS(sp))
+ if ((cwtotal += KEY_COL(sp, ch)) >= SCREEN_COLS(sp))
break;
}
@@ -617,8 +610,8 @@ slow: for (smp = HMAP; smp->lno != LNO; ++smp);
}
/* Adjust the window towards the end of the line. */
- if (off == 0 && off + SCREEN_COLS(sp) < cnt ||
- off != 0 && off + sp->cols < cnt) {
+ if ((off == 0 && off + SCREEN_COLS(sp) < cnt) ||
+ (off != 0 && off + sp->cols < cnt)) {
do {
off += O_VAL(sp, O_SIDESCROLL);
} while (off + sp->cols < cnt);
@@ -767,8 +760,7 @@ number: if (O_ISSET(sp, O_NUMBER) &&
* Update the mode line.
*/
static void
-vs_modeline(sp)
- SCR *sp;
+vs_modeline(SCR *sp)
{
static char * const modes[] = {
"215|Append", /* SM_APPEND */
@@ -779,9 +771,9 @@ vs_modeline(sp)
};
GS *gp;
size_t cols, curcol, curlen, endpoint, len, midpoint;
- const char *t;
+ const char *t = NULL;
int ellipsis;
- char *p, buf[20];
+ char buf[20];
gp = sp->gp;
@@ -803,19 +795,23 @@ vs_modeline(sp)
/* If more than one screen in the display, show the file name. */
curlen = 0;
if (IS_SPLIT(sp)) {
- for (p = sp->frp->name; *p != '\0'; ++p);
- for (ellipsis = 0, cols = sp->cols / 2; --p > sp->frp->name;) {
+ CHAR_T *wp, *p;
+ size_t l;
+
+ CHAR2INT(sp, sp->frp->name, strlen(sp->frp->name) + 1, wp, l);
+ p = wp + l;
+ for (ellipsis = 0, cols = sp->cols / 2; --p > wp;) {
if (*p == '/') {
++p;
break;
}
- if ((curlen += KEY_LEN(sp, *p)) > cols) {
+ if ((curlen += KEY_COL(sp, *p)) > cols) {
ellipsis = 3;
curlen +=
KEY_LEN(sp, '.') * 3 + KEY_LEN(sp, ' ');
while (curlen > cols) {
++p;
- curlen -= KEY_LEN(sp, *p);
+ curlen -= KEY_COL(sp, *p);
}
break;
}
@@ -829,7 +825,7 @@ vs_modeline(sp)
}
for (; *p != '\0'; ++p)
(void)gp->scr_addstr(sp,
- KEY_NAME(sp, *p), KEY_LEN(sp, *p));
+ KEY_NAME(sp, *p), KEY_COL(sp, *p));
}
/* Clear the rest of the line. */
diff --git a/contrib/nvi/vi/vs_relative.c b/contrib/nvi/vi/vs_relative.c
index 878fc4f..5f25b51 100644
--- a/contrib/nvi/vi/vs_relative.c
+++ b/contrib/nvi/vi/vs_relative.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)vs_relative.c 10.11 (Berkeley) 5/13/96";
+static const char sccsid[] = "$Id: vs_relative.c,v 10.19 2011/12/01 15:22:59 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -32,9 +32,7 @@ static const char sccsid[] = "@(#)vs_relative.c 10.11 (Berkeley) 5/13/96";
* PUBLIC: int vs_column __P((SCR *, size_t *));
*/
int
-vs_column(sp, colp)
- SCR *sp;
- size_t *colp;
+vs_column(SCR *sp, size_t *colp)
{
VI_PRIVATE *vip;
@@ -55,10 +53,7 @@ vs_column(sp, colp)
* PUBLIC: size_t vs_screens __P((SCR *, recno_t, size_t *));
*/
size_t
-vs_screens(sp, lno, cnop)
- SCR *sp;
- recno_t lno;
- size_t *cnop;
+vs_screens(SCR *sp, recno_t lno, size_t *cnop)
{
size_t cols, screens;
@@ -98,18 +93,14 @@ vs_screens(sp, lno, cnop)
* Return the screen columns necessary to display the line, or,
* if specified, the physical character column within the line.
*
- * PUBLIC: size_t vs_columns __P((SCR *, char *, recno_t, size_t *, size_t *));
+ * PUBLIC: size_t vs_columns __P((SCR *, CHAR_T *, recno_t, size_t *, size_t *));
*/
size_t
-vs_columns(sp, lp, lno, cnop, diffp)
- SCR *sp;
- char *lp;
- recno_t lno;
- size_t *cnop, *diffp;
+vs_columns(SCR *sp, CHAR_T *lp, recno_t lno, size_t *cnop, size_t *diffp)
{
- size_t chlen, cno, curoff, last, len, scno;
+ size_t chlen, cno, curoff, last = 0, len, scno;
int ch, leftright, listset;
- char *p;
+ CHAR_T *p;
/*
* Initialize the screen offset.
@@ -142,11 +133,11 @@ done: if (diffp != NULL) /* XXX */
* Initialize the pointer into the buffer and current offset.
*/
p = lp;
- curoff = 0;
+ curoff = scno;
/* Macro to return the display length of any signal character. */
-#define CHLEN(val) (ch = *(u_char *)p++) == '\t' && \
- !listset ? TAB_OFF(val) : KEY_LEN(sp, ch);
+#define CHLEN(val) (ch = *(UCHAR_T *)p++) == '\t' && \
+ !listset ? TAB_OFF(val) : KEY_COL(sp, ch);
/*
* If folding screens (the historic vi screen format), past the end
@@ -204,10 +195,7 @@ done: if (diffp != NULL) /* XXX */
* PUBLIC: size_t vs_rcm __P((SCR *, recno_t, int));
*/
size_t
-vs_rcm(sp, lno, islast)
- SCR *sp;
- recno_t lno;
- int islast;
+vs_rcm(SCR *sp, recno_t lno, int islast)
{
size_t len;
@@ -233,14 +221,11 @@ vs_rcm(sp, lno, islast)
* PUBLIC: size_t vs_colpos __P((SCR *, recno_t, size_t));
*/
size_t
-vs_colpos(sp, lno, cno)
- SCR *sp;
- recno_t lno;
- size_t cno;
+vs_colpos(SCR *sp, recno_t lno, size_t cno)
{
size_t chlen, curoff, len, llen, off, scno;
- int ch, leftright, listset;
- char *lp, *p;
+ int ch = 0, leftright, listset;
+ CHAR_T *lp, *p;
/* Need the line to go any further. */
(void)db_get(sp, lno, 0, &lp, &llen);
diff --git a/contrib/nvi/vi/vs_smap.c b/contrib/nvi/vi/vs_smap.c
index 18d7942..0ab2df9 100644
--- a/contrib/nvi/vi/vs_smap.c
+++ b/contrib/nvi/vi/vs_smap.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)vs_smap.c 10.25 (Berkeley) 7/12/96";
+static const char sccsid[] = "$Id: vs_smap.c,v 10.31 2011/02/26 13:56:21 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -42,10 +42,7 @@ static int vs_sm_up __P((SCR *, MARK *, recno_t, scroll_t, SMAP *));
* PUBLIC: int vs_change __P((SCR *, recno_t, lnop_t));
*/
int
-vs_change(sp, lno, op)
- SCR *sp;
- recno_t lno;
- lnop_t op;
+vs_change(SCR *sp, recno_t lno, lnop_t op)
{
VI_PRIVATE *vip;
SMAP *p;
@@ -64,7 +61,8 @@ vs_change(sp, lno, op)
*
* Check for line #2 before going to the end of the file.
*/
- if ((op == LINE_APPEND && lno == 0 || op == LINE_INSERT && lno == 1) &&
+ if (((op == LINE_APPEND && lno == 0) ||
+ (op == LINE_INSERT && lno == 1)) &&
!db_exist(sp, 2)) {
lno = 1;
op = LINE_RESET;
@@ -138,11 +136,15 @@ vs_change(sp, lno, op)
case LINE_DELETE:
if (vs_sm_delete(sp, lno))
return (1);
+ if (sp->lno > lno)
+ --sp->lno;
F_SET(vip, VIP_N_RENUMBER);
break;
case LINE_INSERT:
if (vs_sm_insert(sp, lno))
return (1);
+ if (sp->lno > lno)
+ ++sp->lno;
F_SET(vip, VIP_N_RENUMBER);
break;
case LINE_RESET:
@@ -172,10 +174,7 @@ vs_change(sp, lno, op)
* PUBLIC: int vs_sm_fill __P((SCR *, recno_t, pos_t));
*/
int
-vs_sm_fill(sp, lno, pos)
- SCR *sp;
- recno_t lno;
- pos_t pos;
+vs_sm_fill(SCR *sp, recno_t lno, pos_t pos)
{
SMAP *p, tmp;
size_t cnt;
@@ -225,6 +224,16 @@ vs_sm_fill(sp, lno, pos)
top: HMAP->lno = lno;
HMAP->coff = 0;
HMAP->soff = 1;
+ } else {
+ /*
+ * If number of lines HMAP->lno (top line) spans
+ * changed due to, say reformatting, and now is
+ * fewer than HMAP->soff, reset so the line is
+ * redrawn at the top of the screen.
+ */
+ cnt = vs_screens(sp, HMAP->lno, NULL);
+ if (cnt < HMAP->soff)
+ HMAP->soff = 1;
}
/* If we fail, just punt. */
for (p = HMAP, cnt = sp->t_rows; --cnt; ++p)
@@ -299,9 +308,7 @@ err: HMAP->lno = 1;
* Delete a line out of the SMAP.
*/
static int
-vs_sm_delete(sp, lno)
- SCR *sp;
- recno_t lno;
+vs_sm_delete(SCR *sp, recno_t lno)
{
SMAP *p, *t;
size_t cnt_orig;
@@ -349,9 +356,7 @@ vs_sm_delete(sp, lno)
* Insert a line into the SMAP.
*/
static int
-vs_sm_insert(sp, lno)
- SCR *sp;
- recno_t lno;
+vs_sm_insert(SCR *sp, recno_t lno)
{
SMAP *p, *t;
size_t cnt_orig, cnt, coff;
@@ -405,9 +410,7 @@ vs_sm_insert(sp, lno)
* Reset a line in the SMAP.
*/
static int
-vs_sm_reset(sp, lno)
- SCR *sp;
- recno_t lno;
+vs_sm_reset(SCR *sp, recno_t lno)
{
SMAP *p, *t;
size_t cnt_orig, cnt_new, cnt, diff;
@@ -512,11 +515,7 @@ vs_sm_reset(sp, lno)
* PUBLIC: int vs_sm_scroll __P((SCR *, MARK *, recno_t, scroll_t));
*/
int
-vs_sm_scroll(sp, rp, count, scmd)
- SCR *sp;
- MARK *rp;
- recno_t count;
- scroll_t scmd;
+vs_sm_scroll(SCR *sp, MARK *rp, recno_t count, scroll_t scmd)
{
SMAP *smp;
@@ -573,12 +572,7 @@ vs_sm_scroll(sp, rp, count, scmd)
* Scroll the SMAP up count logical lines.
*/
static int
-vs_sm_up(sp, rp, count, scmd, smp)
- SCR *sp;
- MARK *rp;
- scroll_t scmd;
- recno_t count;
- SMAP *smp;
+vs_sm_up(SCR *sp, MARK *rp, recno_t count, scroll_t scmd, SMAP *smp)
{
int cursor_set, echanged, zset;
SMAP *ssmp, s1, s2;
@@ -754,8 +748,7 @@ vs_sm_up(sp, rp, count, scmd, smp)
* PUBLIC: int vs_sm_1up __P((SCR *));
*/
int
-vs_sm_1up(sp)
- SCR *sp;
+vs_sm_1up(SCR *sp)
{
/*
* Delete the top line of the screen. Shift the screen map
@@ -784,14 +777,19 @@ vs_sm_1up(sp)
* line and other screens back.
*/
static int
-vs_deleteln(sp, cnt)
- SCR *sp;
- int cnt;
+vs_deleteln(SCR *sp, int cnt)
{
GS *gp;
size_t oldy, oldx;
gp = sp->gp;
+
+ /* If the screen is vertically split, we can't scroll it. */
+ if (IS_VSPLIT(sp)) {
+ F_SET(sp, SC_SCR_REDRAW);
+ return (0);
+ }
+
if (IS_ONELINE(sp))
(void)gp->scr_clrtoeol(sp);
else {
@@ -811,12 +809,7 @@ vs_deleteln(sp, cnt)
* Scroll the SMAP down count logical lines.
*/
static int
-vs_sm_down(sp, rp, count, scmd, smp)
- SCR *sp;
- MARK *rp;
- recno_t count;
- SMAP *smp;
- scroll_t scmd;
+vs_sm_down(SCR *sp, MARK *rp, recno_t count, scroll_t scmd, SMAP *smp)
{
SMAP *ssmp, s1, s2;
int cursor_set, ychanged, zset;
@@ -967,8 +960,7 @@ vs_sm_down(sp, rp, count, scmd, smp)
* Erase the small screen area for the scrolling functions.
*/
static int
-vs_sm_erase(sp)
- SCR *sp;
+vs_sm_erase(SCR *sp)
{
GS *gp;
@@ -989,8 +981,7 @@ vs_sm_erase(sp)
* PUBLIC: int vs_sm_1down __P((SCR *));
*/
int
-vs_sm_1down(sp)
- SCR *sp;
+vs_sm_1down(SCR *sp)
{
/*
* Insert a line at the top of the screen. Shift the screen map
@@ -1019,14 +1010,19 @@ vs_sm_1down(sp)
* line and other screens back.
*/
static int
-vs_insertln(sp, cnt)
- SCR *sp;
- int cnt;
+vs_insertln(SCR *sp, int cnt)
{
GS *gp;
size_t oldy, oldx;
gp = sp->gp;
+
+ /* If the screen is vertically split, we can't scroll it. */
+ if (IS_VSPLIT(sp)) {
+ F_SET(sp, SC_SCR_REDRAW);
+ return (0);
+ }
+
if (IS_ONELINE(sp)) {
(void)gp->scr_move(sp, LASTLINE(sp), 0);
(void)gp->scr_clrtoeol(sp);
@@ -1049,9 +1045,7 @@ vs_insertln(sp, cnt)
* PUBLIC: int vs_sm_next __P((SCR *, SMAP *, SMAP *));
*/
int
-vs_sm_next(sp, p, t)
- SCR *sp;
- SMAP *p, *t;
+vs_sm_next(SCR *sp, SMAP *p, SMAP *t)
{
size_t lcnt;
@@ -1079,9 +1073,7 @@ vs_sm_next(sp, p, t)
* PUBLIC: int vs_sm_prev __P((SCR *, SMAP *, SMAP *));
*/
int
-vs_sm_prev(sp, p, t)
- SCR *sp;
- SMAP *p, *t;
+vs_sm_prev(SCR *sp, SMAP *p, SMAP *t)
{
SMAP_FLUSH(t);
if (O_ISSET(sp, O_LEFTRIGHT)) {
@@ -1106,9 +1098,7 @@ vs_sm_prev(sp, p, t)
* PUBLIC: int vs_sm_cursor __P((SCR *, SMAP **));
*/
int
-vs_sm_cursor(sp, smpp)
- SCR *sp;
- SMAP **smpp;
+vs_sm_cursor(SCR *sp, SMAP **smpp)
{
SMAP *p;
@@ -1147,11 +1137,7 @@ vs_sm_cursor(sp, smpp)
* PUBLIC: int vs_sm_position __P((SCR *, MARK *, u_long, pos_t));
*/
int
-vs_sm_position(sp, rp, cnt, pos)
- SCR *sp;
- MARK *rp;
- u_long cnt;
- pos_t pos;
+vs_sm_position(SCR *sp, MARK *rp, u_long cnt, pos_t pos)
{
SMAP *smp;
recno_t last;
@@ -1231,11 +1217,7 @@ eof: msgq(sp, M_BERR,
* PUBLIC: recno_t vs_sm_nlines __P((SCR *, SMAP *, recno_t, size_t));
*/
recno_t
-vs_sm_nlines(sp, from_sp, to_lno, max)
- SCR *sp;
- SMAP *from_sp;
- recno_t to_lno;
- size_t max;
+vs_sm_nlines(SCR *sp, SMAP *from_sp, recno_t to_lno, size_t max)
{
recno_t lno, lcnt;
diff --git a/contrib/nvi/vi/vs_split.c b/contrib/nvi/vi/vs_split.c
index d017354..07bc8e5 100644
--- a/contrib/nvi/vi/vs_split.c
+++ b/contrib/nvi/vi/vs_split.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "@(#)vs_split.c 10.31 (Berkeley) 10/13/96";
+static const char sccsid[] = "$Id: vs_split.c,v 10.42 2001/06/25 15:19:38 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -27,18 +27,23 @@ static const char sccsid[] = "@(#)vs_split.c 10.31 (Berkeley) 10/13/96";
#include "../common/common.h"
#include "vi.h"
-static SCR *vs_getbg __P((SCR *, char *));
+typedef enum { HORIZ_FOLLOW, HORIZ_PRECEDE, VERT_FOLLOW, VERT_PRECEDE } jdir_t;
+
+static SCR *vs_getbg __P((SCR *, char *));
+static void vs_insert __P((SCR *sp, GS *gp));
+static int vs_join __P((SCR *, SCR **, jdir_t *));
/*
* vs_split --
- * Create a new screen.
+ * Create a new screen, horizontally.
*
* PUBLIC: int vs_split __P((SCR *, SCR *, int));
*/
int
-vs_split(sp, new, ccl)
- SCR *sp, *new;
- int ccl; /* Colon-command line split. */
+vs_split(
+ SCR *sp,
+ SCR *new,
+ int ccl) /* Colon-command line split. */
{
GS *gp;
SMAP *smp;
@@ -58,10 +63,6 @@ vs_split(sp, new, ccl)
/* Wait for any messages in the screen. */
vs_resolve(sp, NULL, 1);
- half = sp->rows / 2;
- if (ccl && half > 6)
- half = 6;
-
/* Get a new screen map. */
CALLOC(sp, _HMAP(new), SMAP *, SIZE_HMAP(sp), sizeof(SMAP));
if (_HMAP(new) == NULL)
@@ -70,6 +71,11 @@ vs_split(sp, new, ccl)
_HMAP(new)->coff = 0;
_HMAP(new)->soff = 1;
+ /* Split the screen in half. */
+ half = sp->rows / 2;
+ if (ccl && half > 6)
+ half = 6;
+
/*
* Small screens: see vs_refresh.c section 6a. Set a flag so
* we know to fix the screen up later.
@@ -77,6 +83,7 @@ vs_split(sp, new, ccl)
issmallscreen = IS_SMALL(sp);
/* The columns in the screen don't change. */
+ new->coff = sp->coff;
new->cols = sp->cols;
/*
@@ -93,24 +100,20 @@ vs_split(sp, new, ccl)
!ccl && (vs_sm_cursor(sp, &smp) ? 0 : (smp - HMAP) + 1) >= half;
if (splitup) { /* Old is bottom half. */
new->rows = sp->rows - half; /* New. */
- new->woff = sp->woff;
+ new->roff = sp->roff;
sp->rows = half; /* Old. */
- sp->woff += new->rows;
- /* Link in before old. */
- CIRCLEQ_INSERT_BEFORE(&gp->dq, sp, new, q);
+ sp->roff += new->rows;
/*
* If the parent is the bottom half of the screen, shift
* the map down to match on-screen text.
*/
- memmove(_HMAP(sp), _HMAP(sp) + new->rows,
+ memcpy(_HMAP(sp), _HMAP(sp) + new->rows,
(sp->t_maxrows - new->rows) * sizeof(SMAP));
} else { /* Old is top half. */
new->rows = half; /* New. */
sp->rows -= half; /* Old. */
- new->woff = sp->woff + sp->rows;
- /* Link in after old. */
- CIRCLEQ_INSERT_AFTER(&gp->dq, sp, new, q);
+ new->roff = sp->roff + sp->rows;
}
/* Adjust maximum text count. */
@@ -168,6 +171,103 @@ vs_split(sp, new, ccl)
if ((new->defscroll = new->t_maxrows / 2) == 0)
new->defscroll = 1;
+ /* Fit the screen into the logical chain. */
+ vs_insert(new, sp->gp);
+
+ /* Tell the display that we're splitting. */
+ (void)gp->scr_split(sp, new);
+
+ /*
+ * Initialize the screen flags:
+ *
+ * If we're in vi mode in one screen, we don't have to reinitialize.
+ * This isn't just a cosmetic fix. The path goes like this:
+ *
+ * return into vi(), SC_SSWITCH set
+ * call vs_refresh() with SC_STATUS set
+ * call vs_resolve to display the status message
+ * call vs_refresh() because the SC_SCR_VI bit isn't set
+ *
+ * Things go downhill at this point.
+ *
+ * Draw the new screen from scratch, and add a status line.
+ */
+ F_SET(new,
+ SC_SCR_REFORMAT | SC_STATUS |
+ F_ISSET(sp, SC_EX | SC_VI | SC_SCR_VI | SC_SCR_EX));
+ return (0);
+}
+
+/*
+ * vs_vsplit --
+ * Create a new screen, vertically.
+ *
+ * PUBLIC: int vs_vsplit __P((SCR *, SCR *));
+ */
+int
+vs_vsplit(SCR *sp, SCR *new)
+{
+ GS *gp;
+ size_t cols;
+
+ gp = sp->gp;
+
+ /* Check to see if it's possible. */
+ if (sp->cols / 2 <= MINIMUM_SCREEN_COLS) {
+ msgq(sp, M_ERR,
+ "288|Screen must be larger than %d columns to split",
+ MINIMUM_SCREEN_COLS * 2);
+ return (1);
+ }
+
+ /* Wait for any messages in the screen. */
+ vs_resolve(sp, NULL, 1);
+
+ /* Get a new screen map. */
+ CALLOC(sp, _HMAP(new), SMAP *, SIZE_HMAP(sp), sizeof(SMAP));
+ if (_HMAP(new) == NULL)
+ return (1);
+ _HMAP(new)->lno = sp->lno;
+ _HMAP(new)->coff = 0;
+ _HMAP(new)->soff = 1;
+
+ /*
+ * Split the screen in half; we have to sacrifice a column to delimit
+ * the screens.
+ *
+ * XXX
+ * We always split to the right... that makes more sense to me, and
+ * I don't want to play the stupid games that I play when splitting
+ * horizontally.
+ *
+ * XXX
+ * We reserve a column for the screen, "knowing" that curses needs
+ * one. This should be worked out with the display interface.
+ */
+ cols = sp->cols / 2;
+ new->cols = sp->cols - cols - 1;
+ sp->cols = cols;
+ new->coff = sp->coff + cols + 1;
+ sp->cno = 0;
+
+ /* Nothing else changes. */
+ new->rows = sp->rows;
+ new->t_rows = sp->t_rows;
+ new->t_maxrows = sp->t_maxrows;
+ new->t_minrows = sp->t_minrows;
+ new->roff = sp->roff;
+ new->defscroll = sp->defscroll;
+ _TMAP(new) = _HMAP(new) + (new->t_rows - 1);
+
+ /* Fit the screen into the logical chain. */
+ vs_insert(new, sp->gp);
+
+ /* Tell the display that we're splitting. */
+ (void)gp->scr_split(sp, new);
+
+ /* Redraw the old screen from scratch. */
+ F_SET(sp, SC_SCR_REFORMAT | SC_STATUS);
+
/*
* Initialize the screen flags:
*
@@ -190,6 +290,43 @@ vs_split(sp, new, ccl)
}
/*
+ * vs_insert --
+ * Insert the new screen into the correct place in the logical
+ * chain.
+ */
+static void
+vs_insert(SCR *sp, GS *gp)
+{
+ SCR *tsp;
+
+ gp = sp->gp;
+
+ /* Move past all screens with lower row numbers. */
+ TAILQ_FOREACH(tsp, gp->dq, q)
+ if (tsp->roff >= sp->roff)
+ break;
+ /*
+ * Move past all screens with the same row number and lower
+ * column numbers.
+ */
+ for (; tsp != NULL; tsp = TAILQ_NEXT(tsp, q))
+ if (tsp->roff != sp->roff || tsp->coff > sp->coff)
+ break;
+
+ /*
+ * If we reached the end, this screen goes there. Otherwise,
+ * put it before or after the screen where we stopped.
+ */
+ if (tsp == NULL) {
+ TAILQ_INSERT_TAIL(gp->dq, sp, q);
+ } else if (tsp->roff < sp->roff ||
+ (tsp->roff == sp->roff && tsp->coff < sp->coff)) {
+ TAILQ_INSERT_AFTER(gp->dq, tsp, sp, q);
+ } else
+ TAILQ_INSERT_BEFORE(tsp, sp, q);
+}
+
+/*
* vs_discard --
* Discard the screen, folding the real-estate into a related screen,
* if one exists, and return that screen.
@@ -197,11 +334,13 @@ vs_split(sp, new, ccl)
* PUBLIC: int vs_discard __P((SCR *, SCR **));
*/
int
-vs_discard(sp, spp)
- SCR *sp, **spp;
+vs_discard(SCR *sp, SCR **spp)
{
- SCR *nsp;
- dir_t dir;
+ GS *gp;
+ SCR *tsp, **lp, *list[100];
+ jdir_t jdir;
+
+ gp = sp->gp;
/*
* Save the old screen's cursor information.
@@ -216,94 +355,285 @@ vs_discard(sp, spp)
F_SET(sp->frp, FR_CURSORSET);
}
- /*
- * Add into a previous screen and then into a subsequent screen, as
- * they're the closest to the current screen. If that doesn't work,
- * there was no screen to join.
- */
- if ((nsp = sp->q.cqe_prev) != (void *)&sp->gp->dq) {
- nsp->rows += sp->rows;
- sp = nsp;
- dir = FORWARD;
- } else if ((nsp = sp->q.cqe_next) != (void *)&sp->gp->dq) {
- nsp->woff = sp->woff;
- nsp->rows += sp->rows;
- sp = nsp;
- dir = BACKWARD;
- } else
- sp = NULL;
+ /* If no other screens to join, we're done. */
+ if (!IS_SPLIT(sp)) {
+ (void)gp->scr_discard(sp, NULL);
- if (spp != NULL)
- *spp = sp;
- if (sp == NULL)
+ if (spp != NULL)
+ *spp = NULL;
return (0);
-
+ }
+
/*
- * Make no effort to clean up the discarded screen's information. If
- * it's not exiting, we'll do the work when the user redisplays it.
- *
- * Small screens: see vs_refresh.c section 6a. Adjust text line info,
- * unless it's a small screen.
+ * Find a set of screens that cover one of the screen's borders.
+ * Check the vertical axis first, for no particular reason.
*
- * Reset the length of the default scroll.
+ * XXX
+ * It's possible (I think?), to create a screen that shares no full
+ * border with any other set of screens, so we can't discard it. We
+ * just complain at the user until they clean it up.
*/
- if (!IS_SMALL(sp))
- sp->t_rows = sp->t_minrows = sp->rows - 1;
- sp->t_maxrows = sp->rows - 1;
- sp->defscroll = sp->t_maxrows / 2;
- *(HMAP + (sp->t_rows - 1)) = *TMAP;
- TMAP = HMAP + (sp->t_rows - 1);
+ if (vs_join(sp, list, &jdir))
+ return (1);
/*
- * Draw the new screen from scratch, and add a status line.
+ * Modify the affected screens. Redraw the modified screen(s) from
+ * scratch, setting a status line. If this is ever a performance
+ * problem we could play games with the map, but I wrote that code
+ * before and it was never clean or easy.
*
- * XXX
- * We could play games with the map, if this were ever to be a
- * performance problem, but I wrote the code a few times and it
- * was never clean or easy.
+ * Don't clean up the discarded screen's information. If the screen
+ * isn't exiting, we'll do the work when the user redisplays it.
*/
- switch (dir) {
- case FORWARD:
- vs_sm_fill(sp, OOBLNO, P_TOP);
+ switch (jdir) {
+ case HORIZ_FOLLOW:
+ case HORIZ_PRECEDE:
+ for (lp = &list[0]; (tsp = *lp) != NULL; ++lp) {
+ /*
+ * Small screens: see vs_refresh.c section 6a. Adjust
+ * text line info, unless it's a small screen.
+ *
+ * Reset the length of the default scroll.
+ *
+ * Reset the map references.
+ */
+ tsp->rows += sp->rows;
+ if (!IS_SMALL(tsp))
+ tsp->t_rows = tsp->t_minrows = tsp->rows - 1;
+ tsp->t_maxrows = tsp->rows - 1;
+
+ tsp->defscroll = tsp->t_maxrows / 2;
+
+ *(_HMAP(tsp) + (tsp->t_rows - 1)) = *_TMAP(tsp);
+ _TMAP(tsp) = _HMAP(tsp) + (tsp->t_rows - 1);
+
+ switch (jdir) {
+ case HORIZ_FOLLOW:
+ tsp->roff = sp->roff;
+ vs_sm_fill(tsp, OOBLNO, P_TOP);
+ break;
+ case HORIZ_PRECEDE:
+ vs_sm_fill(tsp, OOBLNO, P_BOTTOM);
+ break;
+ default:
+ abort();
+ }
+ F_SET(tsp, SC_STATUS);
+ }
break;
- case BACKWARD:
- vs_sm_fill(sp, OOBLNO, P_BOTTOM);
+ case VERT_FOLLOW:
+ case VERT_PRECEDE:
+ for (lp = &list[0]; (tsp = *lp) != NULL; ++lp) {
+ if (jdir == VERT_FOLLOW)
+ tsp->coff = sp->coff;
+ tsp->cols += sp->cols + 1; /* XXX: DIVIDER */
+ vs_sm_fill(tsp, OOBLNO, P_TOP);
+ F_SET(tsp, SC_STATUS);
+ }
break;
default:
abort();
}
- F_SET(sp, SC_STATUS);
+ /* Find the closest screen that changed and move to it. */
+ tsp = list[0];
+ if (spp != NULL)
+ *spp = tsp;
+
+ /* Tell the display that we're discarding a screen. */
+ (void)gp->scr_discard(sp, list);
+
return (0);
}
/*
+ * vs_join --
+ * Find a set of screens that covers a screen's border.
+ */
+static int
+vs_join(SCR *sp, SCR **listp, jdir_t *jdirp)
+{
+ GS *gp;
+ SCR **lp, *tsp;
+ int first;
+ size_t tlen;
+
+ gp = sp->gp;
+
+ /* Check preceding vertical. */
+ for (lp = listp, tlen = sp->rows,
+ tsp = TAILQ_FIRST(gp->dq);
+ tsp != NULL; tsp = TAILQ_NEXT(tsp, q)) {
+ if (sp == tsp)
+ continue;
+ /* Test if precedes the screen vertically. */
+ if (tsp->coff + tsp->cols + 1 != sp->coff)
+ continue;
+ /*
+ * Test if a subset on the vertical axis. If overlaps the
+ * beginning or end, we can't join on this axis at all.
+ */
+ if (tsp->roff > sp->roff + sp->rows)
+ continue;
+ if (tsp->roff < sp->roff) {
+ if (tsp->roff + tsp->rows >= sp->roff)
+ break;
+ continue;
+ }
+ if (tsp->roff + tsp->rows > sp->roff + sp->rows)
+ break;
+#ifdef DEBUG
+ if (tlen < tsp->rows)
+ abort();
+#endif
+ tlen -= tsp->rows;
+ *lp++ = tsp;
+ }
+ if (tlen == 0) {
+ *lp = NULL;
+ *jdirp = VERT_PRECEDE;
+ return (0);
+ }
+
+ /* Check following vertical. */
+ for (lp = listp, tlen = sp->rows,
+ tsp = TAILQ_FIRST(gp->dq);
+ tsp != NULL; tsp = TAILQ_NEXT(tsp, q)) {
+ if (sp == tsp)
+ continue;
+ /* Test if follows the screen vertically. */
+ if (tsp->coff != sp->coff + sp->cols + 1)
+ continue;
+ /*
+ * Test if a subset on the vertical axis. If overlaps the
+ * beginning or end, we can't join on this axis at all.
+ */
+ if (tsp->roff > sp->roff + sp->rows)
+ continue;
+ if (tsp->roff < sp->roff) {
+ if (tsp->roff + tsp->rows >= sp->roff)
+ break;
+ continue;
+ }
+ if (tsp->roff + tsp->rows > sp->roff + sp->rows)
+ break;
+#ifdef DEBUG
+ if (tlen < tsp->rows)
+ abort();
+#endif
+ tlen -= tsp->rows;
+ *lp++ = tsp;
+ }
+ if (tlen == 0) {
+ *lp = NULL;
+ *jdirp = VERT_FOLLOW;
+ return (0);
+ }
+
+ /* Check preceding horizontal. */
+ for (first = 0, lp = listp, tlen = sp->cols,
+ tsp = TAILQ_FIRST(gp->dq);
+ tsp != NULL; tsp = TAILQ_NEXT(tsp, q)) {
+ if (sp == tsp)
+ continue;
+ /* Test if precedes the screen horizontally. */
+ if (tsp->roff + tsp->rows != sp->roff)
+ continue;
+ /*
+ * Test if a subset on the horizontal axis. If overlaps the
+ * beginning or end, we can't join on this axis at all.
+ */
+ if (tsp->coff > sp->coff + sp->cols)
+ continue;
+ if (tsp->coff < sp->coff) {
+ if (tsp->coff + tsp->cols >= sp->coff)
+ break;
+ continue;
+ }
+ if (tsp->coff + tsp->cols > sp->coff + sp->cols)
+ break;
+#ifdef DEBUG
+ if (tlen < tsp->cols)
+ abort();
+#endif
+ tlen -= tsp->cols + first;
+ first = 1;
+ *lp++ = tsp;
+ }
+ if (tlen == 0) {
+ *lp = NULL;
+ *jdirp = HORIZ_PRECEDE;
+ return (0);
+ }
+
+ /* Check following horizontal. */
+ for (first = 0, lp = listp, tlen = sp->cols,
+ tsp = TAILQ_FIRST(gp->dq);
+ tsp != NULL; tsp = TAILQ_NEXT(tsp, q)) {
+ if (sp == tsp)
+ continue;
+ /* Test if precedes the screen horizontally. */
+ if (tsp->roff != sp->roff + sp->rows)
+ continue;
+ /*
+ * Test if a subset on the horizontal axis. If overlaps the
+ * beginning or end, we can't join on this axis at all.
+ */
+ if (tsp->coff > sp->coff + sp->cols)
+ continue;
+ if (tsp->coff < sp->coff) {
+ if (tsp->coff + tsp->cols >= sp->coff)
+ break;
+ continue;
+ }
+ if (tsp->coff + tsp->cols > sp->coff + sp->cols)
+ break;
+#ifdef DEBUG
+ if (tlen < tsp->cols)
+ abort();
+#endif
+ tlen -= tsp->cols + first;
+ first = 1;
+ *lp++ = tsp;
+ }
+ if (tlen == 0) {
+ *lp = NULL;
+ *jdirp = HORIZ_FOLLOW;
+ return (0);
+ }
+ return (1);
+}
+
+/*
* vs_fg --
* Background the current screen, and foreground a new one.
*
* PUBLIC: int vs_fg __P((SCR *, SCR **, CHAR_T *, int));
*/
int
-vs_fg(sp, nspp, name, newscreen)
- SCR *sp, **nspp;
- CHAR_T *name;
- int newscreen;
+vs_fg(SCR *sp, SCR **nspp, CHAR_T *name, int newscreen)
{
GS *gp;
SCR *nsp;
+ char *np;
+ size_t nlen;
gp = sp->gp;
+ if (name)
+ INT2CHAR(sp, name, STRLEN(name) + 1, np, nlen);
+ else
+ np = NULL;
if (newscreen)
/* Get the specified background screen. */
- nsp = vs_getbg(sp, name);
+ nsp = vs_getbg(sp, np);
else
/* Swap screens. */
- if (vs_swap(sp, &nsp, name))
+ if (vs_swap(sp, &nsp, np))
return (1);
if ((*nspp = nsp) == NULL) {
- msgq_str(sp, M_ERR, name,
+ msgq_wstr(sp, M_ERR, name,
name == NULL ?
"223|There are no background screens" :
"224|There's no background screen editing a file named %s");
@@ -312,17 +642,17 @@ vs_fg(sp, nspp, name, newscreen)
if (newscreen) {
/* Remove the new screen from the background queue. */
- CIRCLEQ_REMOVE(&gp->hq, nsp, q);
+ TAILQ_REMOVE(gp->hq, nsp, q);
/* Split the screen; if we fail, hook the screen back in. */
if (vs_split(sp, nsp, 0)) {
- CIRCLEQ_INSERT_TAIL(&gp->hq, nsp, q);
+ TAILQ_INSERT_TAIL(gp->hq, nsp, q);
return (1);
}
} else {
/* Move the old screen to the background queue. */
- CIRCLEQ_REMOVE(&gp->dq, sp, q);
- CIRCLEQ_INSERT_TAIL(&gp->hq, sp, q);
+ TAILQ_REMOVE(gp->dq, sp, q);
+ TAILQ_INSERT_TAIL(gp->hq, sp, q);
}
return (0);
}
@@ -334,8 +664,7 @@ vs_fg(sp, nspp, name, newscreen)
* PUBLIC: int vs_bg __P((SCR *));
*/
int
-vs_bg(sp)
- SCR *sp;
+vs_bg(SCR *sp)
{
GS *gp;
SCR *nsp;
@@ -352,8 +681,8 @@ vs_bg(sp)
}
/* Move the old screen to the background queue. */
- CIRCLEQ_REMOVE(&gp->dq, sp, q);
- CIRCLEQ_INSERT_TAIL(&gp->hq, sp, q);
+ TAILQ_REMOVE(gp->dq, sp, q);
+ TAILQ_INSERT_TAIL(gp->hq, sp, q);
/* Toss the screen map. */
free(_HMAP(sp));
@@ -373,12 +702,10 @@ vs_bg(sp)
* PUBLIC: int vs_swap __P((SCR *, SCR **, char *));
*/
int
-vs_swap(sp, nspp, name)
- SCR *sp, **nspp;
- char *name;
+vs_swap(SCR *sp, SCR **nspp, char *name)
{
GS *gp;
- SCR *nsp;
+ SCR *nsp, *list[2];
gp = sp->gp;
@@ -409,7 +736,7 @@ vs_swap(sp, nspp, name)
/* Initialize screen information. */
nsp->cols = sp->cols;
nsp->rows = sp->rows; /* XXX: Only place in vi that sets rows. */
- nsp->woff = sp->woff;
+ nsp->roff = sp->roff;
/*
* Small screens: see vs_refresh.c, section 6a.
@@ -435,6 +762,7 @@ vs_swap(sp, nspp, name)
_TMAP(nsp) = _HMAP(nsp) + (nsp->t_rows - 1);
/* Fill the map. */
+ nsp->gp = sp->gp;
if (vs_sm_fill(nsp, nsp->lno, P_FILL))
return (1);
@@ -444,8 +772,8 @@ vs_swap(sp, nspp, name)
* the exit will delete the old one, if we're foregrounding, the fg
* code will move the old one to the background queue.
*/
- CIRCLEQ_REMOVE(&gp->hq, nsp, q);
- CIRCLEQ_INSERT_AFTER(&gp->dq, sp, nsp, q);
+ TAILQ_REMOVE(gp->hq, nsp, q);
+ TAILQ_INSERT_AFTER(gp->dq, sp, nsp, q);
/*
* Don't change the screen's cursor information other than to
@@ -455,6 +783,10 @@ vs_swap(sp, nspp, name)
/* Draw the new screen from scratch, and add a status line. */
F_SET(nsp, SC_SCR_REDRAW | SC_STATUS);
+
+ list[0] = nsp; list[1] = NULL;
+ (void)gp->scr_discard(sp, list);
+
return (0);
}
@@ -465,13 +797,10 @@ vs_swap(sp, nspp, name)
* PUBLIC: int vs_resize __P((SCR *, long, adj_t));
*/
int
-vs_resize(sp, count, adj)
- SCR *sp;
- long count;
- adj_t adj;
+vs_resize(SCR *sp, long int count, adj_t adj)
{
GS *gp;
- SCR *g, *s;
+ SCR *g, *s, *prev, *next, *list[3] = {NULL, NULL, NULL};
size_t g_off, s_off;
gp = sp->gp;
@@ -494,6 +823,23 @@ vs_resize(sp, count, adj)
}
}
+ /* Find first overlapping screen */
+ for (next = TAILQ_NEXT(sp, q); next != NULL &&
+ (next->coff >= sp->coff + sp->cols ||
+ next->coff + next->cols <= sp->coff);
+ next = TAILQ_NEXT(next, q));
+ /* See if we can use it */
+ if (next != NULL &&
+ (sp->coff != next->coff || sp->cols != next->cols))
+ next = NULL;
+ for (prev = TAILQ_PREV(sp, _dqh, q); prev != NULL &&
+ (prev->coff >= sp->coff + sp->cols ||
+ prev->coff + prev->cols <= sp->coff);
+ prev = TAILQ_PREV(prev, _dqh, q));
+ if (prev != NULL &&
+ (sp->coff != prev->coff || sp->cols != prev->cols))
+ prev = NULL;
+
g_off = s_off = 0;
if (adj == A_DECREASE) {
if (count < 0)
@@ -501,23 +847,21 @@ vs_resize(sp, count, adj)
s = sp;
if (s->t_maxrows < MINIMUM_SCREEN_ROWS + count)
goto toosmall;
- if ((g = sp->q.cqe_prev) == (void *)&gp->dq) {
- if ((g = sp->q.cqe_next) == (void *)&gp->dq)
+ if ((g = prev) == NULL) {
+ if ((g = next) == NULL)
goto toobig;
g_off = -count;
} else
s_off = count;
} else {
g = sp;
- if ((s = sp->q.cqe_next) != (void *)&gp->dq)
- if (s->t_maxrows < MINIMUM_SCREEN_ROWS + count)
- s = NULL;
- else
+ if ((s = next) != NULL &&
+ s->t_maxrows >= MINIMUM_SCREEN_ROWS + count)
s_off = count;
else
s = NULL;
if (s == NULL) {
- if ((s = sp->q.cqe_prev) == (void *)&gp->dq) {
+ if ((s = prev) == NULL) {
toobig: msgq(sp, M_BERR, adj == A_DECREASE ?
"227|The screen cannot shrink" :
"228|The screen cannot grow");
@@ -539,9 +883,9 @@ toosmall: msgq(sp, M_BERR,
* to make it worthwhile.
*/
s->rows += -count;
- s->woff += s_off;
+ s->roff += s_off;
g->rows += count;
- g->woff += g_off;
+ g->roff += g_off;
g->t_rows += count;
if (g->t_minrows == g->t_maxrows)
@@ -557,6 +901,10 @@ toosmall: msgq(sp, M_BERR,
_TMAP(s) -= count;
F_SET(s, SC_SCR_REFORMAT | SC_STATUS);
+ /* XXXX */
+ list[0] = g; list[1] = s;
+ gp->scr_discard(0, list);
+
return (0);
}
@@ -566,9 +914,7 @@ toosmall: msgq(sp, M_BERR,
* background screen.
*/
static SCR *
-vs_getbg(sp, name)
- SCR *sp;
- char *name;
+vs_getbg(SCR *sp, char *name)
{
GS *gp;
SCR *nsp;
@@ -577,22 +923,18 @@ vs_getbg(sp, name)
gp = sp->gp;
/* If name is NULL, return the first background screen on the list. */
- if (name == NULL) {
- nsp = gp->hq.cqh_first;
- return (nsp == (void *)&gp->hq ? NULL : nsp);
- }
+ if (name == NULL)
+ return (TAILQ_FIRST(gp->hq));
/* Search for a full match. */
- for (nsp = gp->hq.cqh_first;
- nsp != (void *)&gp->hq; nsp = nsp->q.cqe_next)
+ TAILQ_FOREACH(nsp, gp->hq, q)
if (!strcmp(nsp->frp->name, name))
break;
- if (nsp != (void *)&gp->hq)
+ if (nsp != NULL)
return (nsp);
/* Search for a last-component match. */
- for (nsp = gp->hq.cqh_first;
- nsp != (void *)&gp->hq; nsp = nsp->q.cqe_next) {
+ TAILQ_FOREACH(nsp, gp->hq, q) {
if ((p = strrchr(nsp->frp->name, '/')) == NULL)
p = nsp->frp->name;
else
@@ -600,7 +942,7 @@ vs_getbg(sp, name)
if (!strcmp(p, name))
break;
}
- if (nsp != (void *)&gp->hq)
+ if (nsp != NULL)
return (nsp);
return (NULL);
OpenPOWER on IntegriCloud