Mercurial > vim
comparison src/ops.c @ 9389:32e34e574716 v7.4.1976
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jul 1 18:17:26 2016 +0200
patch 7.4.1976
Problem: Number variables are not 64 bits while they could be.
Solution: Add the num64 feature. (Ken Takata)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 01 Jul 2016 18:30:07 +0200 |
parents | a9b8f5613601 |
children | 80ace3687eec |
comparison
equal
deleted
inserted
replaced
9388:404ac7af0e7e | 9389:32e34e574716 |
---|---|
1177 } | 1177 } |
1178 | 1178 |
1179 static int execreg_lastc = NUL; | 1179 static int execreg_lastc = NUL; |
1180 | 1180 |
1181 /* | 1181 /* |
1182 * execute a yank register: copy it into the stuff buffer | 1182 * Execute a yank register: copy it into the stuff buffer. |
1183 * | 1183 * |
1184 * return FAIL for failure, OK otherwise | 1184 * Return FAIL for failure, OK otherwise. |
1185 */ | 1185 */ |
1186 int | 1186 int |
1187 do_execreg( | 1187 do_execreg( |
1188 int regname, | 1188 int regname, |
1189 int colon, /* insert ':' before each line */ | 1189 int colon, /* insert ':' before each line */ |
4753 /* | 4753 /* |
4754 * Evaluate the function. | 4754 * Evaluate the function. |
4755 */ | 4755 */ |
4756 if (use_sandbox) | 4756 if (use_sandbox) |
4757 ++sandbox; | 4757 ++sandbox; |
4758 r = eval_to_number(curbuf->b_p_fex); | 4758 r = (int)eval_to_number(curbuf->b_p_fex); |
4759 if (use_sandbox) | 4759 if (use_sandbox) |
4760 --sandbox; | 4760 --sandbox; |
4761 | 4761 |
4762 set_vim_var_string(VV_CHAR, NULL, -1); | 4762 set_vim_var_string(VV_CHAR, NULL, -1); |
4763 | 4763 |
5447 int col; | 5447 int col; |
5448 char_u *buf1; | 5448 char_u *buf1; |
5449 char_u buf2[NUMBUFLEN]; | 5449 char_u buf2[NUMBUFLEN]; |
5450 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ | 5450 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
5451 static int hexupper = FALSE; /* 0xABC */ | 5451 static int hexupper = FALSE; /* 0xABC */ |
5452 unsigned long n; | 5452 uvarnumber_T n; |
5453 long_u oldn; | 5453 uvarnumber_T oldn; |
5454 char_u *ptr; | 5454 char_u *ptr; |
5455 int c; | 5455 int c; |
5456 int todel; | 5456 int todel; |
5457 int dohex; | 5457 int dohex; |
5458 int dooct; | 5458 int dooct; |
5706 if (negative) | 5706 if (negative) |
5707 subtract ^= TRUE; | 5707 subtract ^= TRUE; |
5708 | 5708 |
5709 oldn = n; | 5709 oldn = n; |
5710 if (subtract) | 5710 if (subtract) |
5711 n -= (unsigned long)Prenum1; | 5711 n -= (uvarnumber_T)Prenum1; |
5712 else | 5712 else |
5713 n += (unsigned long)Prenum1; | 5713 n += (uvarnumber_T)Prenum1; |
5714 /* handle wraparound for decimal numbers */ | 5714 /* handle wraparound for decimal numbers */ |
5715 if (!pre) | 5715 if (!pre) |
5716 { | 5716 { |
5717 if (subtract) | 5717 if (subtract) |
5718 { | 5718 { |
5719 if (n > oldn) | 5719 if (n > oldn) |
5720 { | 5720 { |
5721 n = 1 + (n ^ (unsigned long)-1); | 5721 n = 1 + (n ^ (uvarnumber_T)-1); |
5722 negative ^= TRUE; | 5722 negative ^= TRUE; |
5723 } | 5723 } |
5724 } | 5724 } |
5725 else | 5725 else |
5726 { | 5726 { |
5727 /* add */ | 5727 /* add */ |
5728 if (n < oldn) | 5728 if (n < oldn) |
5729 { | 5729 { |
5730 n = (n ^ (unsigned long)-1); | 5730 n = (n ^ (uvarnumber_T)-1); |
5731 negative ^= TRUE; | 5731 negative ^= TRUE; |
5732 } | 5732 } |
5733 } | 5733 } |
5734 if (n == 0) | 5734 if (n == 0) |
5735 negative = FALSE; | 5735 negative = FALSE; |
5801 */ | 5801 */ |
5802 if (pre == 'b' || pre == 'B') | 5802 if (pre == 'b' || pre == 'B') |
5803 { | 5803 { |
5804 int i; | 5804 int i; |
5805 int bit = 0; | 5805 int bit = 0; |
5806 int bits = sizeof(unsigned long) * 8; | 5806 int bits = sizeof(uvarnumber_T) * 8; |
5807 | 5807 |
5808 /* leading zeros */ | 5808 /* leading zeros */ |
5809 for (bit = bits; bit > 0; bit--) | 5809 for (bit = bits; bit > 0; bit--) |
5810 if ((n >> (bit - 1)) & 0x1) break; | 5810 if ((n >> (bit - 1)) & 0x1) break; |
5811 | 5811 |
5813 buf2[i++] = ((n >> (bit - 1)) & 0x1) ? '1' : '0'; | 5813 buf2[i++] = ((n >> (bit - 1)) & 0x1) ? '1' : '0'; |
5814 | 5814 |
5815 buf2[i] = '\0'; | 5815 buf2[i] = '\0'; |
5816 } | 5816 } |
5817 else if (pre == 0) | 5817 else if (pre == 0) |
5818 sprintf((char *)buf2, "%lu", n); | 5818 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", n); |
5819 else if (pre == '0') | 5819 else if (pre == '0') |
5820 sprintf((char *)buf2, "%lo", n); | 5820 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", n); |
5821 else if (pre && hexupper) | 5821 else if (pre && hexupper) |
5822 sprintf((char *)buf2, "%lX", n); | 5822 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", n); |
5823 else | 5823 else |
5824 sprintf((char *)buf2, "%lx", n); | 5824 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", n); |
5825 length -= (int)STRLEN(buf2); | 5825 length -= (int)STRLEN(buf2); |
5826 | 5826 |
5827 /* | 5827 /* |
5828 * Adjust number of zeros to the new number of digits, so the | 5828 * Adjust number of zeros to the new number of digits, so the |
5829 * total length of the number remains the same. | 5829 * total length of the number remains the same. |
7084 clear_oparg(oparg_T *oap) | 7084 clear_oparg(oparg_T *oap) |
7085 { | 7085 { |
7086 vim_memset(oap, 0, sizeof(oparg_T)); | 7086 vim_memset(oap, 0, sizeof(oparg_T)); |
7087 } | 7087 } |
7088 | 7088 |
7089 static long line_count_info(char_u *line, long *wc, long *cc, long limit, int eol_size); | 7089 static varnumber_T line_count_info(char_u *line, varnumber_T *wc, varnumber_T *cc, varnumber_T limit, int eol_size); |
7090 | 7090 |
7091 /* | 7091 /* |
7092 * Count the number of bytes, characters and "words" in a line. | 7092 * Count the number of bytes, characters and "words" in a line. |
7093 * | 7093 * |
7094 * "Words" are counted by looking for boundaries between non-space and | 7094 * "Words" are counted by looking for boundaries between non-space and |
7100 * The function will only examine the first "limit" characters in the | 7100 * The function will only examine the first "limit" characters in the |
7101 * line, stopping if it encounters an end-of-line (NUL byte). In that | 7101 * line, stopping if it encounters an end-of-line (NUL byte). In that |
7102 * case, eol_size will be added to the character count to account for | 7102 * case, eol_size will be added to the character count to account for |
7103 * the size of the EOL character. | 7103 * the size of the EOL character. |
7104 */ | 7104 */ |
7105 static long | 7105 static varnumber_T |
7106 line_count_info( | 7106 line_count_info( |
7107 char_u *line, | 7107 char_u *line, |
7108 long *wc, | 7108 varnumber_T *wc, |
7109 long *cc, | 7109 varnumber_T *cc, |
7110 long limit, | 7110 varnumber_T limit, |
7111 int eol_size) | 7111 int eol_size) |
7112 { | 7112 { |
7113 long i; | 7113 varnumber_T i; |
7114 long words = 0; | 7114 varnumber_T words = 0; |
7115 long chars = 0; | 7115 varnumber_T chars = 0; |
7116 int is_word = 0; | 7116 int is_word = 0; |
7117 | 7117 |
7118 for (i = 0; i < limit && line[i] != NUL; ) | 7118 for (i = 0; i < limit && line[i] != NUL; ) |
7119 { | 7119 { |
7120 if (is_word) | 7120 if (is_word) |
7160 { | 7160 { |
7161 char_u *p; | 7161 char_u *p; |
7162 char_u buf1[50]; | 7162 char_u buf1[50]; |
7163 char_u buf2[40]; | 7163 char_u buf2[40]; |
7164 linenr_T lnum; | 7164 linenr_T lnum; |
7165 long byte_count = 0; | 7165 varnumber_T byte_count = 0; |
7166 #ifdef FEAT_MBYTE | 7166 #ifdef FEAT_MBYTE |
7167 long bom_count = 0; | 7167 varnumber_T bom_count = 0; |
7168 #endif | 7168 #endif |
7169 long byte_count_cursor = 0; | 7169 varnumber_T byte_count_cursor = 0; |
7170 long char_count = 0; | 7170 varnumber_T char_count = 0; |
7171 long char_count_cursor = 0; | 7171 varnumber_T char_count_cursor = 0; |
7172 long word_count = 0; | 7172 varnumber_T word_count = 0; |
7173 long word_count_cursor = 0; | 7173 varnumber_T word_count_cursor = 0; |
7174 int eol_size; | 7174 int eol_size; |
7175 long last_check = 100000L; | 7175 varnumber_T last_check = 100000L; |
7176 long line_count_selected = 0; | 7176 long line_count_selected = 0; |
7177 pos_T min_pos, max_pos; | 7177 pos_T min_pos, max_pos; |
7178 oparg_T oparg; | 7178 oparg_T oparg; |
7179 struct block_def bd; | 7179 struct block_def bd; |
7180 | 7180 |
7306 word_count_cursor += word_count; | 7306 word_count_cursor += word_count; |
7307 char_count_cursor += char_count; | 7307 char_count_cursor += char_count; |
7308 byte_count_cursor = byte_count + | 7308 byte_count_cursor = byte_count + |
7309 line_count_info(ml_get(lnum), | 7309 line_count_info(ml_get(lnum), |
7310 &word_count_cursor, &char_count_cursor, | 7310 &word_count_cursor, &char_count_cursor, |
7311 (long)(curwin->w_cursor.col + 1), eol_size); | 7311 (varnumber_T)(curwin->w_cursor.col + 1), |
7312 eol_size); | |
7312 } | 7313 } |
7313 } | 7314 } |
7314 /* Add to the running totals */ | 7315 /* Add to the running totals */ |
7315 byte_count += line_count_info(ml_get(lnum), &word_count, | 7316 byte_count += line_count_info(ml_get(lnum), &word_count, |
7316 &char_count, (long)MAXCOL, eol_size); | 7317 &char_count, (varnumber_T)MAXCOL, |
7318 eol_size); | |
7317 } | 7319 } |
7318 | 7320 |
7319 /* Correction for when last line doesn't have an EOL. */ | 7321 /* Correction for when last line doesn't have an EOL. */ |
7320 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) | 7322 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
7321 byte_count -= eol_size; | 7323 byte_count -= eol_size; |
7335 buf1[0] = NUL; | 7337 buf1[0] = NUL; |
7336 | 7338 |
7337 if (char_count_cursor == byte_count_cursor | 7339 if (char_count_cursor == byte_count_cursor |
7338 && char_count == byte_count) | 7340 && char_count == byte_count) |
7339 vim_snprintf((char *)IObuff, IOSIZE, | 7341 vim_snprintf((char *)IObuff, IOSIZE, |
7340 _("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Bytes"), | 7342 _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Bytes"), |
7341 buf1, line_count_selected, | 7343 buf1, line_count_selected, |
7342 (long)curbuf->b_ml.ml_line_count, | 7344 (long)curbuf->b_ml.ml_line_count, |
7343 word_count_cursor, word_count, | 7345 word_count_cursor, word_count, |
7344 byte_count_cursor, byte_count); | 7346 byte_count_cursor, byte_count); |
7345 else | 7347 else |
7346 vim_snprintf((char *)IObuff, IOSIZE, | 7348 vim_snprintf((char *)IObuff, IOSIZE, |
7347 _("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Chars; %ld of %ld Bytes"), | 7349 _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Chars; %lld of %lld Bytes"), |
7348 buf1, line_count_selected, | 7350 buf1, line_count_selected, |
7349 (long)curbuf->b_ml.ml_line_count, | 7351 (long)curbuf->b_ml.ml_line_count, |
7350 word_count_cursor, word_count, | 7352 word_count_cursor, word_count, |
7351 char_count_cursor, char_count, | 7353 char_count_cursor, char_count, |
7352 byte_count_cursor, byte_count); | 7354 byte_count_cursor, byte_count); |
7361 linetabsize(p)); | 7363 linetabsize(p)); |
7362 | 7364 |
7363 if (char_count_cursor == byte_count_cursor | 7365 if (char_count_cursor == byte_count_cursor |
7364 && char_count == byte_count) | 7366 && char_count == byte_count) |
7365 vim_snprintf((char *)IObuff, IOSIZE, | 7367 vim_snprintf((char *)IObuff, IOSIZE, |
7366 _("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Byte %ld of %ld"), | 7368 _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Byte %lld of %lld"), |
7367 (char *)buf1, (char *)buf2, | 7369 (char *)buf1, (char *)buf2, |
7368 (long)curwin->w_cursor.lnum, | 7370 (long)curwin->w_cursor.lnum, |
7369 (long)curbuf->b_ml.ml_line_count, | 7371 (long)curbuf->b_ml.ml_line_count, |
7370 word_count_cursor, word_count, | 7372 word_count_cursor, word_count, |
7371 byte_count_cursor, byte_count); | 7373 byte_count_cursor, byte_count); |
7372 else | 7374 else |
7373 vim_snprintf((char *)IObuff, IOSIZE, | 7375 vim_snprintf((char *)IObuff, IOSIZE, |
7374 _("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Char %ld of %ld; Byte %ld of %ld"), | 7376 _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Char %lld of %lld; Byte %lld of %lld"), |
7375 (char *)buf1, (char *)buf2, | 7377 (char *)buf1, (char *)buf2, |
7376 (long)curwin->w_cursor.lnum, | 7378 (long)curwin->w_cursor.lnum, |
7377 (long)curbuf->b_ml.ml_line_count, | 7379 (long)curbuf->b_ml.ml_line_count, |
7378 word_count_cursor, word_count, | 7380 word_count_cursor, word_count, |
7379 char_count_cursor, char_count, | 7381 char_count_cursor, char_count, |
7397 } | 7399 } |
7398 } | 7400 } |
7399 #if defined(FEAT_EVAL) | 7401 #if defined(FEAT_EVAL) |
7400 if (dict != NULL) | 7402 if (dict != NULL) |
7401 { | 7403 { |
7402 dict_add_nr_str(dict, "words", (long)word_count, NULL); | 7404 dict_add_nr_str(dict, "words", word_count, NULL); |
7403 dict_add_nr_str(dict, "chars", (long)char_count, NULL); | 7405 dict_add_nr_str(dict, "chars", char_count, NULL); |
7404 dict_add_nr_str(dict, "bytes", (long)byte_count | 7406 dict_add_nr_str(dict, "bytes", byte_count |
7405 # ifdef FEAT_MBYTE | 7407 # ifdef FEAT_MBYTE |
7406 + bom_count | 7408 + bom_count |
7407 # endif | 7409 # endif |
7408 , NULL); | 7410 , NULL); |
7409 dict_add_nr_str(dict, VIsual_active ? "visual_bytes" : "cursor_bytes", | 7411 dict_add_nr_str(dict, VIsual_active ? "visual_bytes" : "cursor_bytes", |
7410 (long)byte_count_cursor, NULL); | 7412 byte_count_cursor, NULL); |
7411 dict_add_nr_str(dict, VIsual_active ? "visual_chars" : "cursor_chars", | 7413 dict_add_nr_str(dict, VIsual_active ? "visual_chars" : "cursor_chars", |
7412 (long)char_count_cursor, NULL); | 7414 char_count_cursor, NULL); |
7413 dict_add_nr_str(dict, VIsual_active ? "visual_words" : "cursor_words", | 7415 dict_add_nr_str(dict, VIsual_active ? "visual_words" : "cursor_words", |
7414 (long)word_count_cursor, NULL); | 7416 word_count_cursor, NULL); |
7415 } | 7417 } |
7416 #endif | 7418 #endif |
7417 } | 7419 } |