From 66118c7cdf4045951e96a67000bb4ce52343d7fc Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 1 Jul 2006 18:39:37 +0200 Subject: [PATCH] ex: convert line input buffer from file encoding to internal encoding The input buffer was typed as having internal encoding, but the data stored in it actually had file encoding. The commit makes the type match the content. --- common/common.h | 2 +- common/key.h | 8 +++++--- ex/ex.h | 3 ++- ex/ex_filter.c | 5 ++++- ex/ex_read.c | 5 ++++- ex/ex_util.c | 6 +++--- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/common/common.h b/common/common.h index 87cf553b..5d59dbd8 100644 --- a/common/common.h +++ b/common/common.h @@ -95,9 +95,9 @@ typedef enum { SEQ_ABBREV, SEQ_COMMAND, SEQ_INPUT } seq_t; #include "seq.h" /* Required by screen.h. */ #include "util.h" /* Required by ex.h. */ #include "mark.h" /* Required by gs.h. */ +#include "conv.h" /* Required by ex.h and screen.h */ #include "../ex/ex.h" /* Required by gs.h. */ #include "gs.h" /* Required by screen.h. */ -#include "conv.h" #include "log.h" /* Required by screen.h */ #include "screen.h" /* Required by exf.h. */ #include "exf.h" diff --git a/common/key.h b/common/key.h index f788fdef..b35d80f2 100644 --- a/common/key.h +++ b/common/key.h @@ -26,8 +26,8 @@ typedef u_int ARG_CHAR_T; #ifdef USE_WIDECHAR -#define FILE2INT(sp,n,nlen,w,wlen) \ - sp->conv.file2int(sp, n, nlen, &sp->wp->cw, &wlen, &w) +#define FILE2INT5(sp,buf,n,nlen,w,wlen) \ + sp->conv.file2int(sp, n, nlen, &buf, &wlen, &w) #define INT2FILE(sp,w,wlen,n,nlen) \ sp->conv.int2file(sp, w, wlen, &sp->wp->cw, &nlen, &n) #define CHAR2INT5(sp,buf,n,nlen,w,wlen) \ @@ -57,7 +57,7 @@ typedef u_int ARG_CHAR_T; #define WVS "%*ls" #define WC "%lc" #else -#define FILE2INT(sp,n,nlen,w,wlen) \ +#define FILE2INT(sp,buf,n,nlen,w,wlen) \ (w = n, wlen = nlen, 0) #define INT2FILE(sp,w,wlen,n,nlen) \ (n = w, nlen = wlen, 0) @@ -88,6 +88,8 @@ typedef u_int ARG_CHAR_T; #define WVS "%*s" #define WC "%c" #endif +#define FILE2INT(sp,n,nlen,w,wlen) \ + FILE2INT5(sp,sp->wp->cw,n,nlen,w,wlen) #define CHAR2INT(sp,n,nlen,w,wlen) \ CHAR2INT5(sp,sp->wp->cw,n,nlen,w,wlen) diff --git a/ex/ex.h b/ex/ex.h index d12ae92a..673d650e 100644 --- a/ex/ex.h +++ b/ex/ex.h @@ -170,8 +170,9 @@ typedef struct _ex_private { u_int32_t fdef; /* Saved E_C_* default command flags. */ - CHAR_T *ibp; /* File line input buffer. */ + char *ibp; /* File line input buffer. */ size_t ibp_len; /* File line input buffer length. */ + CONVWIN ibcw; /* File line input conversion buffer. */ /* * Buffers for the ex output. The screen/vi support doesn't do any diff --git a/ex/ex_filter.c b/ex/ex_filter.c index 75a45f9d..49f6bfd3 100644 --- a/ex/ex_filter.c +++ b/ex/ex_filter.c @@ -300,11 +300,14 @@ static int filter_ldisplay(SCR *sp, FILE *fp) { size_t len; + size_t wlen; + CHAR_T *wp; EX_PRIVATE *exp; for (exp = EXP(sp); !ex_getline(sp, fp, &len) && !INTERRUPTED(sp);) { - if (ex_ldisplay(sp, exp->ibp, len, 0, 0)) + FILE2INT5(sp, exp->ibcw, exp->ibp, len, wp, wlen); + if (ex_ldisplay(sp, wp, wlen, 0, 0)) break; } if (ferror(fp)) diff --git a/ex/ex_read.c b/ex/ex_read.c index 84397fee..e55eee0c 100644 --- a/ex/ex_read.c +++ b/ex/ex_read.c @@ -305,6 +305,8 @@ ex_readfp(SCR *sp, char *name, FILE *fp, MARK *fm, db_recno_t *nlinesp, int sile u_long ccnt; /* XXX: can't print off_t portably. */ int nf, rval; char *p; + size_t wlen; + CHAR_T *wp; gp = sp->gp; exp = EXP(sp); @@ -326,7 +328,8 @@ ex_readfp(SCR *sp, char *name, FILE *fp, MARK *fm, db_recno_t *nlinesp, int sile p = NULL; } } - if (db_append(sp, 1, lno, exp->ibp, len)) + FILE2INT5(sp, exp->ibcw, exp->ibp, len, wp, wlen); + if (db_append(sp, 1, lno, wp, wlen)) goto err; ccnt += len; } diff --git a/ex/ex_util.c b/ex/ex_util.c index 3410a3e8..8a5783c5 100644 --- a/ex/ex_util.c +++ b/ex/ex_util.c @@ -59,12 +59,12 @@ ex_getline(SCR *sp, FILE *fp, size_t *lenp) EX_PRIVATE *exp; size_t off; int ch; - CHAR_T *p; + char *p; exp = EXP(sp); for (errno = 0, off = 0, p = exp->ibp;;) { - if (off * sizeof(CHAR_T) >= exp->ibp_len) { - BINC_RETW(sp, exp->ibp, exp->ibp_len, off + 1); + if (off >= exp->ibp_len) { + BINC_RET(sp, exp->ibp, exp->ibp_len, off + 1); p = exp->ibp + off; } if ((ch = getc(fp)) == EOF && !feof(fp)) { -- 2.11.4.GIT