diff options
author | Peter Wemm <peter@FreeBSD.org> | 2013-08-11 20:03:12 +0000 |
---|---|---|
committer | Peter Wemm <peter@FreeBSD.org> | 2013-08-11 20:03:12 +0000 |
commit | f0957ccae4f402b93cf27b125542343d28b53109 (patch) | |
tree | 7c1ae67d07b93aea05bfea51c590c1112b65042b /contrib/nvi/ex/ex_txt.c | |
parent | ebe2785690e3a82421eac98f089a934901731af5 (diff) | |
parent | be3e4646eef6a3abcf58590dac24a5dfe54540f6 (diff) |
Update nvi-1.79 to 2.1.1-4334a8297f
This is the gsoc-2011 project to clean up and backport multibyte support
from other nvi forks in a form we can use.
USE_WIDECHAR is on unless building for the rescue crunchgen. This should
allow editing in the native locale encoding.
USE_ICONV depends on make.conf having 'WITH_ICONV=YES' for now. This
adds the ability to do things like edit a KOI8-R file while having $LANG
set to (say) en_US.UTF-8. iconv is used to transcode the characters for
display.
Other points:
* It uses gencat and catopen/etc instead of homegrown msg catalog stuff.
* A lot of stuff has been trimmed out, eg: the perl and tcl bindings which
we could never use in base anyway.
* It uses ncursesw when in widechar mode. This could be interesting.
GSoC info: http://www.google-melange.com/gsoc/proposal/review/google/gsoc2011/zy/1
Repo at: https://github.com/lichray/nvi2
Obtained from: Zhihao Yuan <lichray@gmail.com>
Notes
Notes:
svn path=/head/; revision=254225
Diffstat (limited to 'contrib/nvi/ex/ex_txt.c')
-rw-r--r-- | contrib/nvi/ex/ex_txt.c | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/contrib/nvi/ex/ex_txt.c b/contrib/nvi/ex/ex_txt.c index 30bcf977f3f0..21d9f4412654 100644 --- a/contrib/nvi/ex/ex_txt.c +++ b/contrib/nvi/ex/ex_txt.c @@ -10,11 +10,12 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)ex_txt.c 10.17 (Berkeley) 10/10/96"; +static const char sccsid[] = "$Id: ex_txt.c,v 10.23 2001/06/25 15:19:21 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/time.h> #include <bitstring.h> #include <ctype.h> @@ -24,6 +25,7 @@ static const char sccsid[] = "@(#)ex_txt.c 10.17 (Berkeley) 10/10/96"; #include <string.h> #include "../common/common.h" +#include "../vi/vi.h" /* * !!! @@ -52,11 +54,7 @@ static void txt_prompt __P((SCR *, TEXT *, ARG_CHAR_T, u_int32_t)); * PUBLIC: int ex_txt __P((SCR *, TEXTH *, ARG_CHAR_T, u_int32_t)); */ int -ex_txt(sp, tiqh, prompt, flags) - SCR *sp; - TEXTH *tiqh; - ARG_CHAR_T prompt; - u_int32_t flags; +ex_txt(SCR *sp, TEXTH *tiqh, ARG_CHAR_T prompt, u_int32_t flags) { EVENT ev; GS *gp; @@ -64,6 +62,7 @@ ex_txt(sp, tiqh, prompt, flags) carat_t carat_st; size_t cnt; int rval; + int nochange; rval = 0; @@ -72,9 +71,9 @@ ex_txt(sp, tiqh, prompt, flags) * last one if it's big enough. (All TEXT bookkeeping fields default * to 0 -- text_init() handles this.) */ - if (tiqh->cqh_first != (void *)tiqh) { - tp = tiqh->cqh_first; - if (tp->q.cqe_next != (void *)tiqh || tp->lb_len < 32) { + if (!TAILQ_EMPTY(tiqh)) { + tp = TAILQ_FIRST(tiqh); + if (TAILQ_NEXT(tp, q) != NULL || tp->lb_len < 32) { text_lfree(tiqh); goto newtp; } @@ -82,7 +81,7 @@ ex_txt(sp, tiqh, prompt, flags) } else { newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL) goto err; - CIRCLEQ_INSERT_HEAD(tiqh, tp, q); + TAILQ_INSERT_HEAD(tiqh, tp, q); } /* Set the starting line number. */ @@ -112,7 +111,7 @@ newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL) txt_prompt(sp, tp, prompt, flags); } - for (carat_st = C_NOTSET;;) { + for (carat_st = C_NOTSET, nochange = 0;;) { if (v_event_get(sp, &ev, 0, 0)) goto err; @@ -146,7 +145,7 @@ newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL) * Check to see if the character fits into the input buffer. * (Use tp->len, ignore overwrite and non-printable chars.) */ - BINC_GOTO(sp, tp->lb, tp->lb_len, tp->len + 1); + BINC_GOTOW(sp, tp->lb, tp->lb_len, tp->len + 1); switch (ev.e_value) { case K_CR: @@ -189,7 +188,7 @@ newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL) */ if (LF_ISSET(TXT_DOTTERM) && tp->len == tp->ai + 1 && tp->lb[tp->len - 1] == '.') { -notlast: CIRCLEQ_REMOVE(tiqh, tp, q); +notlast: TAILQ_REMOVE(tiqh, tp, q); text_free(tp); goto done; } @@ -208,7 +207,8 @@ notlast: CIRCLEQ_REMOVE(tiqh, tp, q); * erased. */ if (LF_ISSET(TXT_AUTOINDENT)) { - if (carat_st == C_NOCHANGE) { + if (nochange) { + nochange = 0; if (v_txt_auto(sp, OOBLNO, &ait, ait.ai, ntp)) goto err; @@ -226,7 +226,7 @@ notlast: CIRCLEQ_REMOVE(tiqh, tp, q); * into the queue. */ tp = ntp; - CIRCLEQ_INSERT_TAIL(tiqh, tp, q); + TAILQ_INSERT_TAIL(tiqh, tp, q); break; case K_CARAT: /* Delete autoindent chars. */ if (tp->len <= tp->ai && LF_ISSET(TXT_AUTOINDENT)) @@ -291,11 +291,12 @@ notlast: CIRCLEQ_REMOVE(tiqh, tp, q); /* Save the ai string for later. */ ait.lb = NULL; ait.lb_len = 0; - BINC_GOTO(sp, ait.lb, ait.lb_len, tp->ai); - memcpy(ait.lb, tp->lb, tp->ai); + BINC_GOTOW(sp, ait.lb, ait.lb_len, tp->ai); + MEMCPY(ait.lb, tp->lb, tp->ai); ait.ai = ait.len = tp->ai; - carat_st = C_NOCHANGE; + carat_st = C_NOTSET; + nochange = 1; goto leftmargin; case C_ZEROSET: /* 0^D */ if (tp->len > tp->ai + 1) @@ -328,7 +329,7 @@ leftmargin: (void)gp->scr_ex_adjust(sp, EX_TERM_CE); * not already handled specially, except for <tab> and * <ff>. */ -ins_ch: if (LF_ISSET(TXT_BEAUTIFY) && iscntrl(ev.e_c) && +ins_ch: if (LF_ISSET(TXT_BEAUTIFY) && ISCNTRL(ev.e_c) && ev.e_value != K_FORMFEED && ev.e_value != K_TAB) break; @@ -352,24 +353,20 @@ alloc_err: * not ours. */ static void -txt_prompt(sp, tp, prompt, flags) - SCR *sp; - TEXT *tp; - ARG_CHAR_T prompt; - u_int32_t flags; +txt_prompt(SCR *sp, TEXT *tp, ARG_CHAR_T prompt, u_int32_t flags) { /* Display the prompt. */ if (LF_ISSET(TXT_PROMPT)) - (void)printf("%c", prompt); + (void)ex_printf(sp, "%c", prompt); /* Display the line number. */ if (LF_ISSET(TXT_NUMBER) && O_ISSET(sp, O_NUMBER)) - (void)printf("%6lu ", (u_long)tp->lno); + (void)ex_printf(sp, "%6lu ", (u_long)tp->lno); /* Print out autoindent string. */ if (LF_ISSET(TXT_AUTOINDENT)) - (void)printf("%.*s", (int)tp->ai, tp->lb); - (void)fflush(stdout); + (void)ex_printf(sp, WVS, (int)tp->ai, tp->lb); + (void)ex_fflush(sp); } /* @@ -380,9 +377,7 @@ txt_prompt(sp, tp, prompt, flags) * ranting and raving. This is a fair bit simpler as ^T isn't special. */ static int -txt_dent(sp, tp) - SCR *sp; - TEXT *tp; +txt_dent(SCR *sp, TEXT *tp) { u_long sw, ts; size_t cno, off, scno, spaces, tabs; @@ -416,7 +411,7 @@ txt_dent(sp, tp) spaces = scno - cno; /* Make sure there's enough room. */ - BINC_RET(sp, tp->lb, tp->lb_len, tabs + spaces + 1); + BINC_RETW(sp, tp->lb, tp->lb_len, tabs + spaces + 1); /* Adjust the final ai character count. */ tp->ai = tabs + spaces; |