From fc3abf47fbe1e426f2b676c316c81ee9ff607075 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 24 Jan 2019 15:54:21 +0100 Subject: patch 8.1.0806: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 2. --- src/misc1.c | 106 +++++------------------------------------------------------- 1 file changed, 8 insertions(+), 98 deletions(-) (limited to 'src/misc1.c') diff --git a/src/misc1.c b/src/misc1.c index f75ea81d75..0c38c8af53 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -843,11 +843,9 @@ open_line( p = saved_line + curwin->w_cursor.col; while (*p != NUL) { -#ifdef FEAT_MBYTE if (has_mbyte) p += replace_push_mb(p); else -#endif replace_push(*p++); } saved_line[curwin->w_cursor.col] = NUL; @@ -1296,7 +1294,6 @@ open_line( ; ++p; -#ifdef FEAT_MBYTE /* Compute the length of the replaced characters in * screen characters, not bytes. */ { @@ -1317,12 +1314,6 @@ open_line( (size_t)((leader + lead_len) - endp)); lead_len += l; } -#else - if (p < leader + lead_repl_len) - p = leader; - else - p -= lead_repl_len; -#endif mch_memmove(p, lead_repl, (size_t)lead_repl_len); if (p + lead_repl_len > leader + lead_len) p[lead_repl_len] = NUL; @@ -1330,7 +1321,6 @@ open_line( /* blank-out any other chars from the old leader. */ while (--p >= leader) { -#ifdef FEAT_MBYTE int l = mb_head_off(leader, p); if (l > 1) @@ -1346,16 +1336,14 @@ open_line( lead_len -= l; *p = ' '; } - else -#endif - if (!VIM_ISWHITE(*p)) + else if (!VIM_ISWHITE(*p)) *p = ' '; } } else /* left adjusted leader */ { p = skipwhite(leader); -#ifdef FEAT_MBYTE + /* Compute the length of the replaced characters in * screen characters, not bytes. Move the part that is * not to be overwritten. */ @@ -1378,7 +1366,6 @@ open_line( lead_len += lead_repl_len - i; } } -#endif mch_memmove(p, lead_repl, (size_t)lead_repl_len); /* Replace any remaining non-white chars in the old @@ -1396,7 +1383,6 @@ open_line( } else { -#ifdef FEAT_MBYTE int l = (*mb_ptr2len)(p); if (l > 1) @@ -1412,7 +1398,6 @@ open_line( (leader + lead_len) - p); lead_len -= l - 1; } -#endif *p = ' '; } } @@ -1537,11 +1522,8 @@ open_line( if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) { while ((*p_extra == ' ' || *p_extra == '\t') -#ifdef FEAT_MBYTE && (!enc_utf8 - || !utf_iscomposing(utf_ptr2char(p_extra + 1))) -#endif - ) + || !utf_iscomposing(utf_ptr2char(p_extra + 1)))) { if (REPLACE_NORMAL(State)) replace_push(*p_extra); @@ -2320,7 +2302,6 @@ ins_bytes(char_u *p) ins_bytes_len(char_u *p, int len) { int i; -#ifdef FEAT_MBYTE int n; if (has_mbyte) @@ -2334,7 +2315,6 @@ ins_bytes_len(char_u *p, int len) ins_char_bytes(p + i, n); } else -#endif for (i = 0; i < len; ++i) ins_char(p[i]); } @@ -2350,18 +2330,12 @@ ins_bytes_len(char_u *p, int len) ins_char(int c) { char_u buf[MB_MAXBYTES + 1]; - int n = 1; - -#ifdef FEAT_MBYTE - n = (*mb_char2bytes)(c, buf); + int n = (*mb_char2bytes)(c, buf); /* When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte. * Happens for CTRL-Vu9900. */ if (buf[0] == 0) buf[0] = '\n'; -#else - buf[0] = c; -#endif ins_char_bytes(buf, n); } @@ -2401,9 +2375,6 @@ ins_char_bytes(char_u *buf, int charlen) colnr_T new_vcol = 0; /* init for GCC */ colnr_T vcol; int old_list; -#ifndef FEAT_MBYTE - char_u cbuf[2]; -#endif /* * Disable 'list' temporarily, unless 'cpo' contains the 'L' flag. @@ -2421,13 +2392,7 @@ ins_char_bytes(char_u *buf, int charlen) * cells. May result in adding spaces to fill a gap. */ getvcol(curwin, &curwin->w_cursor, NULL, &vcol, NULL); -#ifndef FEAT_MBYTE - cbuf[0] = c; - cbuf[1] = NUL; - new_vcol = vcol + chartabsize(cbuf, vcol); -#else new_vcol = vcol + chartabsize(buf, vcol); -#endif while (oldp[col + oldlen] != NUL && vcol < new_vcol) { vcol += chartabsize(oldp + col + oldlen, vcol); @@ -2435,11 +2400,7 @@ ins_char_bytes(char_u *buf, int charlen) * position. */ if (vcol > new_vcol && oldp[col + oldlen] == TAB) break; -#ifdef FEAT_MBYTE oldlen += (*mb_ptr2len)(oldp + col + oldlen); -#else - ++oldlen; -#endif /* Deleted a bit too much, insert spaces. */ if (vcol > new_vcol) newlen += vcol - new_vcol; @@ -2449,11 +2410,7 @@ ins_char_bytes(char_u *buf, int charlen) else if (oldp[col] != NUL) { /* normal replace */ -#ifdef FEAT_MBYTE oldlen = (*mb_ptr2len)(oldp + col); -#else - oldlen = 1; -#endif } @@ -2464,11 +2421,9 @@ ins_char_bytes(char_u *buf, int charlen) replace_push(NUL); for (i = 0; i < oldlen; ++i) { -#ifdef FEAT_MBYTE if (has_mbyte) i += replace_push_mb(oldp + col + i) - 1; else -#endif replace_push(oldp[col + i]); } } @@ -2488,13 +2443,8 @@ ins_char_bytes(char_u *buf, int charlen) (size_t)(linelen - col - oldlen)); /* Insert or overwrite the new character. */ -#ifdef FEAT_MBYTE mch_memmove(p, buf, charlen); i = charlen; -#else - *p = c; - i = 1; -#endif /* Fill with spaces when necessary. */ while (i < newlen) @@ -2517,11 +2467,9 @@ ins_char_bytes(char_u *buf, int charlen) #endif ) { -#ifdef FEAT_MBYTE if (has_mbyte) showmatch(mb_ptr2char(buf)); else -#endif showmatch(c); } @@ -2530,11 +2478,7 @@ ins_char_bytes(char_u *buf, int charlen) #endif { /* Normal insert: move cursor right */ -#ifdef FEAT_MBYTE curwin->w_cursor.col += charlen; -#else - ++curwin->w_cursor.col; -#endif } /* * TODO: should try to update w_row here, to avoid recomputing it later. @@ -2586,7 +2530,6 @@ ins_str(char_u *s) int del_char(int fixpos) { -#ifdef FEAT_MBYTE if (has_mbyte) { /* Make sure the cursor is at the start of a character. */ @@ -2595,11 +2538,9 @@ del_char(int fixpos) return FAIL; return del_chars(1L, fixpos); } -#endif return del_bytes(1L, fixpos, TRUE); } -#if defined(FEAT_MBYTE) || defined(PROTO) /* * Like del_bytes(), but delete characters instead of bytes. */ @@ -2620,7 +2561,6 @@ del_chars(long count, int fixpos) } return del_bytes(bytes, fixpos, TRUE); } -#endif /* * Delete "count" bytes under the cursor. @@ -2662,7 +2602,6 @@ del_bytes( return FAIL; } -#ifdef FEAT_MBYTE /* If 'delcombine' is set and deleting (less than) one character, only * delete the last combining character. */ if (p_deco && use_delcombine && enc_utf8 @@ -2685,7 +2624,6 @@ del_bytes( fixpos = 0; } } -#endif /* * When count is too big, reduce it. @@ -2708,11 +2646,9 @@ del_bytes( #ifdef FEAT_VIRTUALEDIT curwin->w_cursor.coladd = 0; #endif -#ifdef FEAT_MBYTE if (has_mbyte) curwin->w_cursor.col -= (*mb_head_off)(oldp, oldp + curwin->w_cursor.col); -#endif } count = oldlen - col; movelen = 1; @@ -2847,20 +2783,16 @@ gchar_pos(pos_T *pos) if (pos->col == MAXCOL) return NUL; ptr = ml_get_pos(pos); -#ifdef FEAT_MBYTE if (has_mbyte) return (*mb_ptr2char)(ptr); -#endif return (int)*ptr; } int gchar_cursor(void) { -#ifdef FEAT_MBYTE if (has_mbyte) return (*mb_ptr2char)(ml_get_cursor()); -#endif return (int)*ml_get_cursor(); } @@ -3681,7 +3613,6 @@ get_keystroke(void) } break; } -#ifdef FEAT_MBYTE if (has_mbyte) { if (MB_BYTE2LEN(n) > len) @@ -3689,7 +3620,6 @@ get_keystroke(void) buf[len >= buflen ? buflen - 1 : len] = NUL; n = (*mb_ptr2char)(buf); } -#endif #ifdef UNIX if (n == intr_char) n = ESC; @@ -4023,7 +3953,6 @@ init_homedir(void) if (var != NULL && *var == NUL) /* empty is same as not set */ var = NULL; -# ifdef FEAT_MBYTE if (enc_utf8 && var != NULL) { int len; @@ -4038,7 +3967,6 @@ init_homedir(void) return; } } -# endif /* * Default home dir is C:/ @@ -4437,7 +4365,7 @@ vim_getenv(char_u *name, int *mustfree) if (p != NULL) { -#if defined(FEAT_MBYTE) && defined(WIN3264) +#if defined(WIN3264) if (enc_utf8) { int len; @@ -4481,7 +4409,7 @@ vim_getenv(char_u *name, int *mustfree) else p = mch_getenv((char_u *)"VIM"); -#if defined(FEAT_MBYTE) && defined(WIN3264) +#if defined(WIN3264) if (enc_utf8) { int len; @@ -5332,7 +5260,6 @@ shorten_dir(char_u *str) *d++ = *s; /* copy next char */ if (*s != '~' && *s != '.') /* and leading "~" and "." */ skip = TRUE; -# ifdef FEAT_MBYTE if (has_mbyte) { int l = mb_ptr2len(s); @@ -5340,7 +5267,6 @@ shorten_dir(char_u *str) while (--l > 0) *d++ = *++s; } -# endif } } } @@ -10155,10 +10081,8 @@ dos_expandpath( static int stardepth = 0; /* depth for "**" expansion */ WIN32_FIND_DATA fb; HANDLE hFind = (HANDLE)0; -# ifdef FEAT_MBYTE WIN32_FIND_DATAW wfb; WCHAR *wn = NULL; /* UCS-2 name, NULL when not used. */ -# endif char_u *matchname; int ok; @@ -10170,8 +10094,8 @@ dos_expandpath( return 0; } - /* Make room for file name. When doing encoding conversion the actual - * length may be quite a bit longer, thus use the maximum possible length. */ + // Make room for file name. When doing encoding conversion the actual + // length may be quite a bit longer, thus use the maximum possible length. buf = alloc((int)MAXPATHL); if (buf == NULL) return 0; @@ -10199,7 +10123,6 @@ dos_expandpath( else if (path_end >= path + wildoff && vim_strchr((char_u *)"*?[~", *path_end) != NULL) e = p; -# ifdef FEAT_MBYTE if (has_mbyte) { len = (*mb_ptr2len)(path_end); @@ -10208,7 +10131,6 @@ dos_expandpath( path_end += len; } else -# endif *p++ = *path_end++; } e = p; @@ -10269,7 +10191,6 @@ dos_expandpath( /* Scan all files in the directory with "dir/ *.*" */ STRCPY(s, "*.*"); -# ifdef FEAT_MBYTE if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) { /* The active codepage differs from 'encoding'. Attempt using the @@ -10286,17 +10207,14 @@ dos_expandpath( } if (wn == NULL) -# endif hFind = FindFirstFile((LPCSTR)buf, &fb); ok = (hFind != INVALID_HANDLE_VALUE); while (ok) { -# ifdef FEAT_MBYTE if (wn != NULL) p = utf16_to_enc(wfb.cFileName, NULL); /* p is allocated here */ else -# endif p = (char_u *)fb.cFileName; /* Ignore entries starting with a dot, unless when asked for. Accept * all entries found with "matchname". */ @@ -10341,14 +10259,12 @@ dos_expandpath( } } -# ifdef FEAT_MBYTE if (wn != NULL) { vim_free(p); ok = FindNextFileW(hFind, &wfb); } else -# endif ok = FindNextFile(hFind, &fb); /* If no more matches and no match was used, try expanding the name @@ -10357,7 +10273,6 @@ dos_expandpath( { STRCPY(s, matchname); FindClose(hFind); -# ifdef FEAT_MBYTE if (wn != NULL) { vim_free(wn); @@ -10366,7 +10281,6 @@ dos_expandpath( hFind = FindFirstFileW(wn, &wfb); } if (wn == NULL) -# endif hFind = FindFirstFile((LPCSTR)buf, &fb); ok = (hFind != INVALID_HANDLE_VALUE); VIM_CLEAR(matchname); @@ -10374,9 +10288,7 @@ dos_expandpath( } FindClose(hFind); -# ifdef FEAT_MBYTE vim_free(wn); -# endif vim_free(buf); vim_regfree(regmatch.regprog); vim_free(matchname); @@ -10480,7 +10392,6 @@ unix_expandpath( || (!p_fic && (flags & EW_ICASE) && isalpha(PTR2CHAR(path_end))))) e = p; -#ifdef FEAT_MBYTE if (has_mbyte) { len = (*mb_ptr2len)(path_end); @@ -10489,7 +10400,6 @@ unix_expandpath( path_end += len; } else -#endif *p++ = *path_end++; } e = p; -- cgit v1.2.3