From 95a1465f8d5c7045d825c6e713d4e9e8f1404dd1 Mon Sep 17 00:00:00 2001 From: skimo Date: Thu, 10 May 2001 19:28:42 +0000 Subject: [PATCH] Croak on first time a conversion error occurs in a screen. --- catalog/english.base | 1 + common/conv.c | 63 ++++++++++++++++++++++++++-------------------------- common/conv.h | 10 ++++----- common/db.c | 10 +++++++-- common/key.h | 27 +++++++++------------- common/screen.c | 5 +---- common/screen.h | 11 ++++----- vi/v_ex.c | 4 ++-- 8 files changed, 64 insertions(+), 67 deletions(-) diff --git a/catalog/english.base b/catalog/english.base index 8f6d7e73..c0de63b5 100644 --- a/catalog/english.base +++ b/catalog/english.base @@ -310,3 +310,4 @@ 319 "%d screens backgrounded; use :display to list them" 320 "Unknown cursor position." 321 "File encoding conversion not supported" +321 "Conversion error on line %d" diff --git a/common/conv.c b/common/conv.c index 54f1d81d..ed1b1607 100644 --- a/common/conv.c +++ b/common/conv.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: conv.c,v 1.11 2001/05/06 21:10:27 skimo Exp $ (Berkeley) $Date: 2001/05/06 21:10:27 $"; +static const char sccsid[] = "$Id: conv.c,v 1.12 2001/05/10 19:28:42 skimo Exp $ (Berkeley) $Date: 2001/05/10 19:28:42 $"; #endif /* not lint */ #include @@ -35,7 +35,8 @@ static const char sccsid[] = "$Id: conv.c,v 1.11 2001/05/06 21:10:27 skimo Exp $ #include int -raw2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, size_t *tolen) +raw2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, size_t *tolen, + CHAR_T **dst) { int i; CHAR_T **tostr = (CHAR_T **)&cw->bp1; @@ -47,6 +48,8 @@ raw2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, size_t *tolen) for (i = 0; i < len; ++i) (*tostr)[i] = (u_char) str[i]; + *dst = cw->bp1; + return 0; } @@ -69,7 +72,8 @@ raw2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, size_t *tolen) } while (0) int -default_char2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, size_t *tolen) +default_char2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, + size_t *tolen, CHAR_T **dst) { int i = 0, j; CHAR_T **tostr = (CHAR_T **)&cw->bp1; @@ -113,16 +117,21 @@ default_char2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, size_t *to if (id != (iconv_t)-1) iconv_close(id); + *dst = cw->bp1; + return 0; err: *tolen = i; if (id != (iconv_t)-1) iconv_close(id); + *dst = cw->bp1; + return 1; } int -int2raw(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t *tolen) +int2raw(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t *tolen, + char **dst) { int i; char **tostr = (char **)&cw->bp1; @@ -134,11 +143,14 @@ int2raw(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t *tolen) for (i = 0; i < len; ++i) (*tostr)[i] = str[i]; + *dst = cw->bp1; + return 0; } int -default_int2char(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t *tolen) +default_int2char(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, + size_t *tolen, char **pdst) { int i, j, offset = 0; char **tostr = (char **)&cw->bp1; @@ -211,16 +223,22 @@ default_int2char(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t * *tolen = offset; } + *pdst = cw->bp1; + return 0; err: *tolen = j; + + *pdst = cw->bp1; + return 1; } //#ifdef HAVE_NCURSESW #ifdef HAVE_ADDNWSTR int -default_int2disp (SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t *tolen) +default_int2disp (SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, + size_t *tolen, char **dst) { int i, j; chtype *dest; @@ -238,13 +256,16 @@ default_int2disp (SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t dest[j++] = str[i]; *tolen = j; + *dst = cw.bp1; + return 0; } #else int -default_int2disp (SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t *tolen) +default_int2disp (SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, + size_t *tolen, char **dst) { int i, j; char **tostr = (char **)&cw->bp1; @@ -260,34 +281,12 @@ default_int2disp (SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t (*tostr)[j++] = str[i]; *tolen = j; + *dst = cw->bp1; + return 0; } #endif -int -gb2int (SCR *sp, const char * str, ssize_t len, CONVWIN *cw, size_t *tolen) -{ - int i, j; - CHAR_T **tostr = (CHAR_T **)&cw->bp1; - size_t *blen = &cw->blen1; - - BINC_RETW(NULL, *tostr, *blen, len); - - for (i = 0, j = 0; i < len; ++i) { - if (str[i] & 0x80) { - if (i+1 < len && str[i+1] & 0x80) { - (*tostr)[j++] = INT9494(F_GB,str[i]&0x7F,str[i+1]&0x7F); - ++i; - } else { - (*tostr)[j++] = INTILL(str[i]); - } - } else - (*tostr)[j++] = str[i]; - } - *tolen = j; - - return 0; -} CONV raw_conv = { raw2int, int2raw, raw2int, int2raw, default_int2disp }; @@ -324,6 +323,8 @@ conv_enc (SCR *sp, char *enc) goto err; iconv_close(id); + F_CLR(sp, SC_CONV_ERROR); + return 0; err: msgq(sp, M_ERR, diff --git a/common/conv.h b/common/conv.h index edfe3b53..8cdd310e 100644 --- a/common/conv.h +++ b/common/conv.h @@ -20,9 +20,9 @@ struct _conv_win { }; struct _conv { - int (*char2int) (SCR *, const char *, ssize_t, struct _conv_win *, size_t *); - int (*int2char) (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *); - int (*file2int) (SCR *, const char *, ssize_t, struct _conv_win *, size_t *); - int (*int2file) (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *); - int (*int2disp) (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *); + int (*char2int) (SCR *, const char *, ssize_t, struct _conv_win *, size_t *, CHAR_T **); + int (*int2char) (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *, char **); + int (*file2int) (SCR *, const char *, ssize_t, struct _conv_win *, size_t *, CHAR_T **); + int (*int2file) (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *, char **); + int (*int2disp) (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *, char **); }; diff --git a/common/db.c b/common/db.c index 3a792a85..0b03fd1f 100644 --- a/common/db.c +++ b/common/db.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: db.c,v 10.35 2001/05/07 21:15:55 skimo Exp $ (Berkeley) $Date: 2001/05/07 21:15:55 $"; +static const char sccsid[] = "$Id: db.c,v 10.36 2001/05/10 19:28:42 skimo Exp $ (Berkeley) $Date: 2001/05/10 19:28:42 $"; #endif /* not lint */ #include @@ -186,7 +186,13 @@ err3: if (lenp != NULL) ; } - FILE2INT(sp, data.data, data.size, wp, wlen); + if (FILE2INT(sp, data.data, data.size, wp, wlen)) { + if (!F_ISSET(sp, SC_CONV_ERROR)) { + F_SET(sp, SC_CONV_ERROR); + msgq(sp, M_ERR, "321|Conversion error on line %d", lno); + } + goto err3; + } /* Reset the cache. */ if (wp != data.data) { diff --git a/common/key.h b/common/key.h index e69ecc7c..40d1f029 100644 --- a/common/key.h +++ b/common/key.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: key.h,v 10.39 2001/04/27 19:57:32 skimo Exp $ (Berkeley) $Date: 2001/04/27 19:57:32 $ + * $Id: key.h,v 10.40 2001/05/10 19:28:43 skimo Exp $ (Berkeley) $Date: 2001/05/10 19:28:43 $ */ #include "multibyte.h" @@ -27,20 +27,15 @@ 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 = sp->wp->cw.bp1 + sp->conv->file2int(sp, n, nlen, &sp->wp->cw, &wlen, &w) #define INT2FILE(sp,w,wlen,n,nlen) \ - sp->conv->int2file(sp, w, wlen, &sp->wp->cw, &nlen), \ - n = sp->wp->cw.bp1 + sp->conv->int2file(sp, w, wlen, &sp->wp->cw, &nlen, &n) #define CHAR2INTB(sp,n,nlen,w,wlen,buf) \ - sp->conv->char2int(sp, n, nlen, &buf, &wlen), \ - w = buf.bp1 + sp->conv->char2int(sp, n, nlen, &buf, &wlen, &w) #define INT2CHAR(sp,w,wlen,n,nlen) \ - sp->conv->int2char(sp, w, wlen, &sp->wp->cw, &nlen), \ - n = sp->wp->cw.bp1 + sp->conv->int2char(sp, w, wlen, &sp->wp->cw, &nlen, &n) #define INT2DISP(sp,w,wlen,n,nlen) \ - sp->conv->int2disp(sp, w, wlen, &sp->wp->cw, &nlen), \ - n = sp->wp->cw.bp1 + sp->conv->int2disp(sp, w, wlen, &sp->wp->cw, &nlen, &n) #define CONST #define ISCNTRL(ch) \ iswcntrl((ch)) @@ -53,15 +48,15 @@ typedef u_int ARG_CHAR_T; #define L(ch) L ## ch #else #define FILE2INT(sp,n,nlen,w,wlen) \ - w = n, wlen = nlen + w = n, wlen = nlen, 0 #define INT2FILE(sp,w,wlen,n,nlen) \ - n = w, nlen = wlen + n = w, nlen = wlen, 0 #define CHAR2INTB(sp,n,nlen,w,wlen,buf) \ - w = n, wlen = nlen + w = n, wlen = nlen, 0 #define INT2CHAR(sp,w,wlen,n,nlen) \ - n = w, nlen = wlen + n = w, nlen = wlen, 0 #define INT2DISP(sp,w,wlen,n,nlen) \ - n = w, nlen = wlen + n = w, nlen = wlen, 0 #define CONST const #define ISCNTRL(ch) \ iscntrl((ch)) diff --git a/common/screen.c b/common/screen.c index dfa78566..5a12f471 100644 --- a/common/screen.c +++ b/common/screen.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: screen.c,v 10.20 2000/07/22 10:20:31 skimo Exp $ (Berkeley) $Date: 2000/07/22 10:20:31 $"; +static const char sccsid[] = "$Id: screen.c,v 10.21 2001/05/10 19:28:43 skimo Exp $ (Berkeley) $Date: 2001/05/10 19:28:43 $"; #endif /* not lint */ #include @@ -28,9 +28,6 @@ static const char sccsid[] = "$Id: screen.c,v 10.20 2000/07/22 10:20:31 skimo Ex #include "common.h" #include "../vi/vi.h" -CHAR_T RE_WSTART[] = {'[','[',':','<',':',']',']',0}; -CHAR_T RE_WSTOP[] = {'[','[',':','>',':',']',']',0}; - /* * screen_init -- * Do the default initialization of an SCR structure. diff --git a/common/screen.h b/common/screen.h index 22d74d46..9a896e10 100644 --- a/common/screen.h +++ b/common/screen.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: screen.h,v 10.41 2001/04/23 22:46:56 skimo Exp $ (Berkeley) $Date: 2001/04/23 22:46:56 $ + * $Id: screen.h,v 10.42 2001/05/10 19:28:43 skimo Exp $ (Berkeley) $Date: 2001/05/10 19:28:43 $ */ /* @@ -74,8 +74,6 @@ struct _win { u_int32_t flags; }; -extern CHAR_T RE_WSTART[8]; -extern CHAR_T RE_WSTOP[8]; /* * SCR -- * The screen structure. To the extent possible, all screen information @@ -154,10 +152,8 @@ struct _scr { CHAR_T at_lbuf; /* Ex/vi: Last executed at buffer. */ /* Ex/vi: re_compile flags. */ -#if 0 -#define RE_WSTART "[[:<:]]" /* Ex/vi: not-in-word search pattern. */ -#define RE_WSTOP "[[:>:]]" -#endif +#define RE_WSTART L("[[:<:]]") /* Ex/vi: not-in-word search pattern. */ +#define RE_WSTOP L("[[:>:]]") #define RE_WSTART_LEN (sizeof(RE_WSTART)/sizeof(CHAR_T)) #define RE_WSTOP_LEN (sizeof(RE_WSTOP)/sizeof(CHAR_T)) /* Ex/vi: flags to search routines. */ @@ -262,6 +258,7 @@ struct _scr { #define SC_STATUS_CNT 0x04000000 /* Welcome message plus file count. */ #define SC_TINPUT 0x08000000 /* Doing text input. */ #define SC_TINPUT_INFO 0x10000000 /* Doing text input on info line. */ +#define SC_CONV_ERROR 0x20000000 /* Met with a conversion error. */ u_int32_t flags; int db_error; /* Return code from db function. */ diff --git a/vi/v_ex.c b/vi/v_ex.c index 098515ff..3c21704a 100644 --- a/vi/v_ex.c +++ b/vi/v_ex.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: v_ex.c,v 10.50 2000/09/01 16:15:42 skimo Exp $ (Berkeley) $Date: 2000/09/01 16:15:42 $"; +static const char sccsid[] = "$Id: v_ex.c,v 10.51 2001/05/10 19:28:43 skimo Exp $ (Berkeley) $Date: 2001/05/10 19:28:43 $"; #endif /* not lint */ #include @@ -634,7 +634,7 @@ v_ecl_log(sp, tp) sp->ep = save_ep; return (1); } - /* Don't look line that is identical to previous one */ + /* Don't log line that is identical to previous one */ if (lno > 0 && !db_get(sp, lno, 0, &p, &len) && len == tp->len && -- 2.11.4.GIT