comparison src/ex_cmds.c @ 15595:1ec942f1b648 v8.1.0805

patch 8.1.0805: too many #ifdefs commit https://github.com/vim/vim/commit/135059724f140ceac889c9f8136bd1bf5c41d49d Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 15:04:48 2019 +0100 patch 8.1.0805: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 1.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 15:15:06 +0100
parents dd725a8ab112
children 6f1c7e9a6393
comparison
equal deleted inserted replaced
15594:7a8983fe4f97 15595:1ec942f1b648
48 char buf2[20]; 48 char buf2[20];
49 char_u buf3[7]; 49 char_u buf3[7];
50 #ifdef FEAT_DIGRAPHS 50 #ifdef FEAT_DIGRAPHS
51 char_u *dig; 51 char_u *dig;
52 #endif 52 #endif
53 #ifdef FEAT_MBYTE
54 int cc[MAX_MCO]; 53 int cc[MAX_MCO];
55 int ci = 0; 54 int ci = 0;
56 int len; 55 int len;
57 56
58 if (enc_utf8) 57 if (enc_utf8)
59 c = utfc_ptr2char(ml_get_cursor(), cc); 58 c = utfc_ptr2char(ml_get_cursor(), cc);
60 else 59 else
61 #endif
62 c = gchar_cursor(); 60 c = gchar_cursor();
63 if (c == NUL) 61 if (c == NUL)
64 { 62 {
65 msg("NUL"); 63 msg("NUL");
66 return; 64 return;
67 } 65 }
68 66
69 #ifdef FEAT_MBYTE
70 IObuff[0] = NUL; 67 IObuff[0] = NUL;
71 if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80) 68 if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80)
72 #endif
73 { 69 {
74 if (c == NL) /* NUL is stored as NL */ 70 if (c == NL) /* NUL is stored as NL */
75 c = NUL; 71 c = NUL;
76 if (c == CAR && get_fileformat(curbuf) == EOL_MAC) 72 if (c == CAR && get_fileformat(curbuf) == EOL_MAC)
77 cval = NL; /* NL is stored as CR */ 73 cval = NL; /* NL is stored as CR */
104 else 100 else
105 #endif 101 #endif
106 vim_snprintf((char *)IObuff, IOSIZE, 102 vim_snprintf((char *)IObuff, IOSIZE,
107 _("<%s>%s%s %d, Hex %02x, Octal %03o"), 103 _("<%s>%s%s %d, Hex %02x, Octal %03o"),
108 transchar(c), buf1, buf2, cval, cval, cval); 104 transchar(c), buf1, buf2, cval, cval, cval);
109 #ifdef FEAT_MBYTE
110 if (enc_utf8) 105 if (enc_utf8)
111 c = cc[ci++]; 106 c = cc[ci++];
112 else 107 else
113 c = 0; 108 c = 0;
114 #endif 109 }
115 } 110
116
117 #ifdef FEAT_MBYTE
118 /* Repeat for combining characters. */ 111 /* Repeat for combining characters. */
119 while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80))) 112 while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80)))
120 { 113 {
121 len = (int)STRLEN(IObuff); 114 len = (int)STRLEN(IObuff);
122 /* This assumes every multi-byte char is printable... */ 115 /* This assumes every multi-byte char is printable... */
148 if (enc_utf8) 141 if (enc_utf8)
149 c = cc[ci++]; 142 c = cc[ci++];
150 else 143 else
151 c = 0; 144 c = 0;
152 } 145 }
153 #endif
154 146
155 msg((char *)IObuff); 147 msg((char *)IObuff);
156 } 148 }
157 149
158 /* 150 /*
821 num_spaces = 0; 813 num_spaces = 0;
822 } 814 }
823 if (ptr[col] == NUL) 815 if (ptr[col] == NUL)
824 break; 816 break;
825 vcol += chartabsize(ptr + col, (colnr_T)vcol); 817 vcol += chartabsize(ptr + col, (colnr_T)vcol);
826 #ifdef FEAT_MBYTE
827 if (has_mbyte) 818 if (has_mbyte)
828 col += (*mb_ptr2len)(ptr + col); 819 col += (*mb_ptr2len)(ptr + col);
829 else 820 else
830 #endif
831 ++col; 821 ++col;
832 } 822 }
833 if (new_line == NULL) /* out of memory */ 823 if (new_line == NULL) /* out of memory */
834 break; 824 break;
835 line_breakcheck(); 825 line_breakcheck();
2280 garray_T buflist; 2270 garray_T buflist;
2281 2271
2282 if ((vir.vir_line = alloc(LSIZE)) == NULL) 2272 if ((vir.vir_line = alloc(LSIZE)) == NULL)
2283 return; 2273 return;
2284 vir.vir_fd = fp_in; 2274 vir.vir_fd = fp_in;
2285 #ifdef FEAT_MBYTE
2286 vir.vir_conv.vc_type = CONV_NONE; 2275 vir.vir_conv.vc_type = CONV_NONE;
2287 #endif
2288 ga_init2(&vir.vir_barlines, (int)sizeof(char_u *), 100); 2276 ga_init2(&vir.vir_barlines, (int)sizeof(char_u *), 100);
2289 vir.vir_version = -1; 2277 vir.vir_version = -1;
2290 2278
2291 if (fp_in != NULL) 2279 if (fp_in != NULL)
2292 { 2280 {
2319 /* Write the info: */ 2307 /* Write the info: */
2320 fprintf(fp_out, _("# This viminfo file was generated by Vim %s.\n"), 2308 fprintf(fp_out, _("# This viminfo file was generated by Vim %s.\n"),
2321 VIM_VERSION_MEDIUM); 2309 VIM_VERSION_MEDIUM);
2322 fputs(_("# You may edit it if you're careful!\n\n"), fp_out); 2310 fputs(_("# You may edit it if you're careful!\n\n"), fp_out);
2323 write_viminfo_version(fp_out); 2311 write_viminfo_version(fp_out);
2324 #ifdef FEAT_MBYTE
2325 fputs(_("# Value of 'encoding' when this file was written\n"), fp_out); 2312 fputs(_("# Value of 'encoding' when this file was written\n"), fp_out);
2326 fprintf(fp_out, "*encoding=%s\n\n", p_enc); 2313 fprintf(fp_out, "*encoding=%s\n\n", p_enc);
2327 #endif
2328 write_viminfo_search_pattern(fp_out); 2314 write_viminfo_search_pattern(fp_out);
2329 write_viminfo_sub_string(fp_out); 2315 write_viminfo_sub_string(fp_out);
2330 #ifdef FEAT_CMDHIST 2316 #ifdef FEAT_CMDHIST
2331 write_viminfo_history(fp_out, merge); 2317 write_viminfo_history(fp_out, merge);
2332 #endif 2318 #endif
2351 if (fp_out != NULL) 2337 if (fp_out != NULL)
2352 ga_clear(&buflist); 2338 ga_clear(&buflist);
2353 } 2339 }
2354 2340
2355 vim_free(vir.vir_line); 2341 vim_free(vir.vir_line);
2356 #ifdef FEAT_MBYTE
2357 if (vir.vir_conv.vc_type != CONV_NONE) 2342 if (vir.vir_conv.vc_type != CONV_NONE)
2358 convert_setup(&vir.vir_conv, NULL, NULL); 2343 convert_setup(&vir.vir_conv, NULL, NULL);
2359 #endif
2360 ga_clear_strings(&vir.vir_barlines); 2344 ga_clear_strings(&vir.vir_barlines);
2361 } 2345 }
2362 2346
2363 /* 2347 /*
2364 * read_viminfo_up_to_marks() -- Only called from do_viminfo(). Reads in the 2348 * read_viminfo_up_to_marks() -- Only called from do_viminfo(). Reads in the
2482 * conversion of text with iconv() in viminfo_readstring(). 2466 * conversion of text with iconv() in viminfo_readstring().
2483 */ 2467 */
2484 static int 2468 static int
2485 viminfo_encoding(vir_T *virp) 2469 viminfo_encoding(vir_T *virp)
2486 { 2470 {
2487 #ifdef FEAT_MBYTE
2488 char_u *p; 2471 char_u *p;
2489 int i; 2472 int i;
2490 2473
2491 if (get_viminfo_parameter('c') != 0) 2474 if (get_viminfo_parameter('c') != 0)
2492 { 2475 {
2500 p[i] = NUL; 2483 p[i] = NUL;
2501 2484
2502 convert_setup(&virp->vir_conv, p, p_enc); 2485 convert_setup(&virp->vir_conv, p, p_enc);
2503 } 2486 }
2504 } 2487 }
2505 #endif
2506 return viminfo_readline(virp); 2488 return viminfo_readline(virp);
2507 } 2489 }
2508 2490
2509 /* 2491 /*
2510 * Read a line from the viminfo file. 2492 * Read a line from the viminfo file.
2572 else 2554 else
2573 *d++ = *s++; 2555 *d++ = *s++;
2574 } 2556 }
2575 *d = NUL; 2557 *d = NUL;
2576 2558
2577 #ifdef FEAT_MBYTE
2578 if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) 2559 if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL)
2579 { 2560 {
2580 d = string_convert(&virp->vir_conv, retval, NULL); 2561 d = string_convert(&virp->vir_conv, retval, NULL);
2581 if (d != NULL) 2562 if (d != NULL)
2582 { 2563 {
2583 vim_free(retval); 2564 vim_free(retval);
2584 retval = d; 2565 retval = d;
2585 } 2566 }
2586 } 2567 }
2587 #endif
2588 2568
2589 return retval; 2569 return retval;
2590 } 2570 }
2591 2571
2592 /* 2572 /*
2706 char_u *buf = NULL; 2686 char_u *buf = NULL;
2707 bval_T *value; 2687 bval_T *value;
2708 int i; 2688 int i;
2709 int allocated = FALSE; 2689 int allocated = FALSE;
2710 int eof; 2690 int eof;
2711 #ifdef FEAT_MBYTE
2712 char_u *sconv; 2691 char_u *sconv;
2713 int converted; 2692 int converted;
2714 #endif
2715 2693
2716 while (*p == ',') 2694 while (*p == ',')
2717 { 2695 {
2718 ++p; 2696 ++p;
2719 if (ga_grow(values, 1) == FAIL) 2697 if (ga_grow(values, 1) == FAIL)
2833 s[len++] = *p++; 2811 s[len++] = *p++;
2834 } 2812 }
2835 ++p; 2813 ++p;
2836 s[len] = NUL; 2814 s[len] = NUL;
2837 2815
2838 #ifdef FEAT_MBYTE
2839 converted = FALSE; 2816 converted = FALSE;
2840 if (virp->vir_conv.vc_type != CONV_NONE && *s != NUL) 2817 if (virp->vir_conv.vc_type != CONV_NONE && *s != NUL)
2841 { 2818 {
2842 sconv = string_convert(&virp->vir_conv, s, NULL); 2819 sconv = string_convert(&virp->vir_conv, s, NULL);
2843 if (sconv != NULL) 2820 if (sconv != NULL)
2847 s = sconv; 2824 s = sconv;
2848 buf = s; 2825 buf = s;
2849 converted = TRUE; 2826 converted = TRUE;
2850 } 2827 }
2851 } 2828 }
2852 #endif 2829
2853 /* Need to copy in allocated memory if the string wasn't allocated 2830 /* Need to copy in allocated memory if the string wasn't allocated
2854 * above and we did allocate before, thus vir_line may change. */ 2831 * above and we did allocate before, thus vir_line may change. */
2855 if (s != buf && allocated) 2832 if (s != buf && allocated)
2856 s = vim_strsave(s); 2833 s = vim_strsave(s);
2857 value->bv_string = s; 2834 value->bv_string = s;
2858 value->bv_type = BVAL_STRING; 2835 value->bv_type = BVAL_STRING;
2859 value->bv_len = len; 2836 value->bv_len = len;
2860 value->bv_allocated = allocated 2837 value->bv_allocated = allocated || converted;
2861 #ifdef FEAT_MBYTE
2862 || converted
2863 #endif
2864 ;
2865 ++values->ga_len; 2838 ++values->ga_len;
2866 if (nextp != NULL) 2839 if (nextp != NULL)
2867 { 2840 {
2868 /* values following a long string */ 2841 /* values following a long string */
2869 p = nextp; 2842 p = nextp;
4092 4065
4093 /* Set 'fileformat', 'binary' and 'fenc' when forced. */ 4066 /* Set 'fileformat', 'binary' and 'fenc' when forced. */
4094 if (!oldbuf && eap != NULL) 4067 if (!oldbuf && eap != NULL)
4095 { 4068 {
4096 set_file_options(TRUE, eap); 4069 set_file_options(TRUE, eap);
4097 #ifdef FEAT_MBYTE
4098 set_forced_fenc(eap); 4070 set_forced_fenc(eap);
4099 #endif
4100 } 4071 }
4101 } 4072 }
4102 4073
4103 /* May get the window options from the last time this buffer 4074 /* May get the window options from the last time this buffer
4104 * was in this window (or another window). If not used 4075 * was in this window (or another window). If not used
5315 * for a match in this line again. */ 5286 * for a match in this line again. */
5316 skip_match = TRUE; 5287 skip_match = TRUE;
5317 else 5288 else
5318 { 5289 {
5319 /* search for a match at next column */ 5290 /* search for a match at next column */
5320 #ifdef FEAT_MBYTE
5321 if (has_mbyte) 5291 if (has_mbyte)
5322 matchcol += mb_ptr2len(sub_firstline + matchcol); 5292 matchcol += mb_ptr2len(sub_firstline + matchcol);
5323 else 5293 else
5324 #endif
5325 ++matchcol; 5294 ++matchcol;
5326 } 5295 }
5327 goto skip; 5296 goto skip;
5328 } 5297 }
5329 5298
5757 // copy the rest 5726 // copy the rest
5758 STRMOVE(new_start, p1 + 1); 5727 STRMOVE(new_start, p1 + 1);
5759 p1 = new_start - 1; 5728 p1 = new_start - 1;
5760 } 5729 }
5761 } 5730 }
5762 #ifdef FEAT_MBYTE
5763 else if (has_mbyte) 5731 else if (has_mbyte)
5764 p1 += (*mb_ptr2len)(p1) - 1; 5732 p1 += (*mb_ptr2len)(p1) - 1;
5765 #endif
5766 } 5733 }
5767 5734
5768 /* 5735 /*
5769 * 4. If do_all is set, find next match. 5736 * 4. If do_all is set, find next match.
5770 * Prevent endless loop with patterns that match empty 5737 * Prevent endless loop with patterns that match empty
7015 int fcount; 6982 int fcount;
7016 char_u **fnames; 6983 char_u **fnames;
7017 FILE *fd; 6984 FILE *fd;
7018 char_u *s; 6985 char_u *s;
7019 int fi; 6986 int fi;
7020 #ifdef FEAT_MBYTE
7021 vimconv_T vc; 6987 vimconv_T vc;
7022 char_u *cp; 6988 char_u *cp;
7023 #endif
7024 6989
7025 /* Find all "doc/ *.txt" files in this directory. */ 6990 /* Find all "doc/ *.txt" files in this directory. */
7026 add_pathsep(NameBuff); 6991 add_pathsep(NameBuff);
7027 #ifdef FEAT_MULTI_LANG 6992 #ifdef FEAT_MULTI_LANG
7028 STRCAT(NameBuff, "doc/*.??[tx]"); 6993 STRCAT(NameBuff, "doc/*.??[tx]");
7084 vim_fgets(IObuff, IOSIZE, fd); 7049 vim_fgets(IObuff, IOSIZE, fd);
7085 if (IObuff[0] == '*' 7050 if (IObuff[0] == '*'
7086 && (s = vim_strchr(IObuff + 1, '*')) 7051 && (s = vim_strchr(IObuff + 1, '*'))
7087 != NULL) 7052 != NULL)
7088 { 7053 {
7089 #ifdef FEAT_MBYTE
7090 int this_utf = MAYBE; 7054 int this_utf = MAYBE;
7091 #endif 7055
7092 /* Change tag definition to a 7056 /* Change tag definition to a
7093 * reference and remove <CR>/<NL>. */ 7057 * reference and remove <CR>/<NL>. */
7094 IObuff[0] = '|'; 7058 IObuff[0] = '|';
7095 *s = '|'; 7059 *s = '|';
7096 while (*s != NUL) 7060 while (*s != NUL)
7097 { 7061 {
7098 if (*s == '\r' || *s == '\n') 7062 if (*s == '\r' || *s == '\n')
7099 *s = NUL; 7063 *s = NUL;
7100 #ifdef FEAT_MBYTE
7101 /* The text is utf-8 when a byte 7064 /* The text is utf-8 when a byte
7102 * above 127 is found and no 7065 * above 127 is found and no
7103 * illegal byte sequence is found. 7066 * illegal byte sequence is found.
7104 */ 7067 */
7105 if (*s >= 0x80 && this_utf != FALSE) 7068 if (*s >= 0x80 && this_utf != FALSE)
7110 l = utf_ptr2len(s); 7073 l = utf_ptr2len(s);
7111 if (l == 1) 7074 if (l == 1)
7112 this_utf = FALSE; 7075 this_utf = FALSE;
7113 s += l - 1; 7076 s += l - 1;
7114 } 7077 }
7115 #endif
7116 ++s; 7078 ++s;
7117 } 7079 }
7118 #ifdef FEAT_MBYTE 7080
7119 /* The help file is latin1 or utf-8; 7081 /* The help file is latin1 or utf-8;
7120 * conversion to the current 7082 * conversion to the current
7121 * 'encoding' may be required. */ 7083 * 'encoding' may be required. */
7122 vc.vc_type = CONV_NONE; 7084 vc.vc_type = CONV_NONE;
7123 convert_setup(&vc, (char_u *)( 7085 convert_setup(&vc, (char_u *)(
7138 convert_setup(&vc, NULL, NULL); 7100 convert_setup(&vc, NULL, NULL);
7139 7101
7140 ml_append(lnum, cp, (colnr_T)0, FALSE); 7102 ml_append(lnum, cp, (colnr_T)0, FALSE);
7141 if (cp != IObuff) 7103 if (cp != IObuff)
7142 vim_free(cp); 7104 vim_free(cp);
7143 #else
7144 ml_append(lnum, IObuff, (colnr_T)0,
7145 FALSE);
7146 #endif
7147 ++lnum; 7105 ++lnum;
7148 } 7106 }
7149 fclose(fd); 7107 fclose(fd);
7150 } 7108 }
7151 } 7109 }
7197 int fi; 7155 int fi;
7198 char_u *s; 7156 char_u *s;
7199 int i; 7157 int i;
7200 char_u *fname; 7158 char_u *fname;
7201 int dirlen; 7159 int dirlen;
7202 # ifdef FEAT_MBYTE
7203 int utf8 = MAYBE; 7160 int utf8 = MAYBE;
7204 int this_utf8; 7161 int this_utf8;
7205 int firstline; 7162 int firstline;
7206 int mix = FALSE; /* detected mixed encodings */ 7163 int mix = FALSE; /* detected mixed encodings */
7207 # endif
7208 7164
7209 /* 7165 /*
7210 * Find all *.txt files. 7166 * Find all *.txt files.
7211 */ 7167 */
7212 dirlen = (int)STRLEN(dir); 7168 dirlen = (int)STRLEN(dir);
7272 semsg(_("E153: Unable to open %s for reading"), files[fi]); 7228 semsg(_("E153: Unable to open %s for reading"), files[fi]);
7273 continue; 7229 continue;
7274 } 7230 }
7275 fname = files[fi] + dirlen + 1; 7231 fname = files[fi] + dirlen + 1;
7276 7232
7277 # ifdef FEAT_MBYTE
7278 firstline = TRUE; 7233 firstline = TRUE;
7279 # endif
7280 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) 7234 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
7281 { 7235 {
7282 # ifdef FEAT_MBYTE
7283 if (firstline) 7236 if (firstline)
7284 { 7237 {
7285 /* Detect utf-8 file by a non-ASCII char in the first line. */ 7238 /* Detect utf-8 file by a non-ASCII char in the first line. */
7286 this_utf8 = MAYBE; 7239 this_utf8 = MAYBE;
7287 for (s = IObuff; *s != NUL; ++s) 7240 for (s = IObuff; *s != NUL; ++s)
7309 mix = !got_int; 7262 mix = !got_int;
7310 got_int = TRUE; 7263 got_int = TRUE;
7311 } 7264 }
7312 firstline = FALSE; 7265 firstline = FALSE;
7313 } 7266 }
7314 # endif
7315 p1 = vim_strchr(IObuff, '*'); /* find first '*' */ 7267 p1 = vim_strchr(IObuff, '*'); /* find first '*' */
7316 while (p1 != NULL) 7268 while (p1 != NULL)
7317 { 7269 {
7318 /* Use vim_strbyte() instead of vim_strchr() so that when 7270 /* Use vim_strbyte() instead of vim_strchr() so that when
7319 * 'encoding' is dbcs it still works, don't find '*' in the 7271 * 'encoding' is dbcs it still works, don't find '*' in the
7396 ++p1; 7348 ++p1;
7397 ++p2; 7349 ++p2;
7398 } 7350 }
7399 } 7351 }
7400 7352
7401 # ifdef FEAT_MBYTE
7402 if (utf8 == TRUE) 7353 if (utf8 == TRUE)
7403 fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n"); 7354 fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n");
7404 # endif
7405 7355
7406 /* 7356 /*
7407 * Write the tags into the file. 7357 * Write the tags into the file.
7408 */ 7358 */
7409 for (i = 0; i < ga.ga_len; ++i) 7359 for (i = 0; i < ga.ga_len; ++i)
7424 } 7374 }
7425 fprintf(fd_tags, "*\n"); 7375 fprintf(fd_tags, "*\n");
7426 } 7376 }
7427 } 7377 }
7428 } 7378 }
7429 #ifdef FEAT_MBYTE
7430 if (mix) 7379 if (mix)
7431 got_int = FALSE; /* continue with other languages */ 7380 got_int = FALSE; /* continue with other languages */
7432 #endif
7433 7381
7434 for (i = 0; i < ga.ga_len; ++i) 7382 for (i = 0; i < ga.ga_len; ++i)
7435 vim_free(((char_u **)ga.ga_data)[i]); 7383 vim_free(((char_u **)ga.ga_data)[i]);
7436 ga_clear(&ga); 7384 ga_clear(&ga);
7437 fclose(fd_tags); /* there is no check for an error... */ 7385 fclose(fd_tags); /* there is no check for an error... */