To: vim_dev@googlegroups.com Subject: Patch 8.1.2388 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2388 Problem: Using old C style comments. Solution: Use // comments where appropriate. Files: src/json.c, src/json_test.c, src/kword_test.c, src/list.c, src/main.c, src/mark.c, src/mbyte.c, src/memfile.c, src/memfile_test.c, src/memline.c, src/menu.c *** ../vim-8.1.2387/src/json.c 2019-08-20 20:13:40.326821952 +0200 --- src/json.c 2019-12-04 21:56:55.920591425 +0100 *************** *** 48,54 **** { garray_T ga; ! /* Store bytes in the growarray. */ ga_init2(&ga, 1, 4000); json_encode_gap(&ga, val, options); ga_append(&ga, NUL); --- 48,54 ---- { garray_T ga; ! // Store bytes in the growarray. ga_init2(&ga, 1, 4000); json_encode_gap(&ga, val, options); ga_append(&ga, NUL); *************** *** 104,111 **** if (!enc_utf8) { ! /* Convert the text from 'encoding' to utf-8, the JSON string is ! * always utf-8. */ conv.vc_type = CONV_NONE; convert_setup(&conv, p_enc, (char_u*)"utf-8"); if (conv.vc_type != CONV_NONE) --- 104,111 ---- if (!enc_utf8) { ! // Convert the text from 'encoding' to utf-8, the JSON string is ! // always utf-8. conv.vc_type = CONV_NONE; convert_setup(&conv, p_enc, (char_u*)"utf-8"); if (conv.vc_type != CONV_NONE) *************** *** 117,123 **** while (*res != NUL) { int c; ! /* always use utf-8 encoding, ignore 'encoding' */ c = utf_ptr2char(res); switch (c) --- 117,123 ---- while (*res != NUL) { int c; ! // always use utf-8 encoding, ignore 'encoding' c = utf_ptr2char(res); switch (c) *************** *** 132,139 **** ga_append(gap, '\\'); ga_append(gap, 'f'); break; case 0x0d: ga_append(gap, '\\'); ga_append(gap, 'r'); break; ! case 0x22: /* " */ ! case 0x5c: /* \ */ ga_append(gap, '\\'); ga_append(gap, c); break; --- 132,139 ---- ga_append(gap, '\\'); ga_append(gap, 'f'); break; case 0x0d: ga_append(gap, '\\'); ga_append(gap, 'r'); break; ! case 0x22: // " ! case 0x5c: // backslash ga_append(gap, '\\'); ga_append(gap, c); break; *************** *** 200,208 **** case VVAL_TRUE: ga_concat(gap, (char_u *)"true"); break; case VVAL_NONE: if ((options & JSON_JS) != 0 && (options & JSON_NO_NONE) == 0) ! /* empty item */ break; ! /* FALLTHROUGH */ case VVAL_NULL: ga_concat(gap, (char_u *)"null"); break; } break; --- 200,208 ---- case VVAL_TRUE: ga_concat(gap, (char_u *)"true"); break; case VVAL_NONE: if ((options & JSON_JS) != 0 && (options & JSON_NO_NONE) == 0) ! // empty item break; ! // FALLTHROUGH case VVAL_NULL: ga_concat(gap, (char_u *)"null"); break; } break; *************** *** 222,228 **** case VAR_PARTIAL: case VAR_JOB: case VAR_CHANNEL: ! /* no JSON equivalent TODO: better error */ emsg(_(e_invarg)); return FAIL; --- 222,228 ---- case VAR_PARTIAL: case VAR_JOB: case VAR_CHANNEL: ! // no JSON equivalent TODO: better error emsg(_(e_invarg)); return FAIL; *************** *** 268,274 **** && li->li_next == NULL && li->li_tv.v_type == VAR_SPECIAL && li->li_tv.vval.v_number == VVAL_NONE) ! /* add an extra comma if the last item is v:none */ ga_append(gap, ','); li = li->li_next; if (li != NULL) --- 268,274 ---- && li->li_next == NULL && li->li_tv.v_type == VAR_SPECIAL && li->li_tv.vval.v_number == VVAL_NONE) ! // add an extra comma if the last item is v:none ga_append(gap, ','); li = li->li_next; if (li != NULL) *************** *** 405,425 **** if (res != NULL) ga_init2(&ga, 1, 200); ! p = reader->js_buf + reader->js_used + 1; /* skip over " or ' */ while (*p != quote) { ! /* The JSON is always expected to be utf-8, thus use utf functions ! * here. The string is converted below if needed. */ if (*p == NUL || p[1] == NUL || utf_ptr2len(p) < utf_byte2len(*p)) { ! /* Not enough bytes to make a character or end of the string. Get ! * more if possible. */ if (reader->js_fill == NULL) break; len = (int)(reader->js_end - p); reader->js_used = (int)(p - reader->js_buf); if (!reader->js_fill(reader)) ! break; /* didn't get more */ p = reader->js_buf + reader->js_used; reader->js_end = reader->js_buf + STRLEN(reader->js_buf); continue; --- 405,425 ---- if (res != NULL) ga_init2(&ga, 1, 200); ! p = reader->js_buf + reader->js_used + 1; // skip over " or ' while (*p != quote) { ! // The JSON is always expected to be utf-8, thus use utf functions ! // here. The string is converted below if needed. if (*p == NUL || p[1] == NUL || utf_ptr2len(p) < utf_byte2len(*p)) { ! // Not enough bytes to make a character or end of the string. Get ! // more if possible. if (reader->js_fill == NULL) break; len = (int)(reader->js_end - p); reader->js_used = (int)(p - reader->js_buf); if (!reader->js_fill(reader)) ! break; // didn't get more p = reader->js_buf + reader->js_used; reader->js_end = reader->js_buf + STRLEN(reader->js_buf); continue; *************** *** 466,472 **** { varnumber_T nr2 = 0; ! /* decode surrogate pair: \ud812\u3456 */ len = 0; vim_str2nr(p + 2, NULL, &len, STR2NR_HEX + STR2NR_FORCE, &nr2, NULL, 4, TRUE); --- 466,472 ---- { varnumber_T nr2 = 0; ! // decode surrogate pair: \ud812\u3456 len = 0; vim_str2nr(p + 2, NULL, &len, STR2NR_HEX + STR2NR_FORCE, &nr2, NULL, 4, TRUE); *************** *** 492,498 **** } break; default: ! /* not a special char, skip over \ */ ++p; continue; } --- 492,498 ---- } break; default: ! // not a special char, skip over backslash ++p; continue; } *************** *** 533,539 **** { vimconv_T conv; ! /* Convert the utf-8 string to 'encoding'. */ conv.vc_type = CONV_NONE; convert_setup(&conv, (char_u*)"utf-8", p_enc); if (conv.vc_type != CONV_NONE) --- 533,539 ---- { vimconv_T conv; ! // Convert the utf-8 string to 'encoding'. conv.vc_type = CONV_NONE; convert_setup(&conv, (char_u*)"utf-8", p_enc); if (conv.vc_type != CONV_NONE) *************** *** 560,573 **** } typedef enum { ! JSON_ARRAY, /* parsing items in an array */ ! JSON_OBJECT_KEY, /* parsing key of an object */ ! JSON_OBJECT /* parsing item in an object, after the key */ } json_decode_T; typedef struct { json_decode_T jd_type; ! typval_T jd_tv; /* the list or dict */ typval_T jd_key_tv; char_u *jd_key; } json_dec_item_T; --- 560,573 ---- } typedef enum { ! JSON_ARRAY, // parsing items in an array ! JSON_OBJECT_KEY, // parsing key of an object ! JSON_OBJECT // parsing item in an object, after the key } json_decode_T; typedef struct { json_decode_T jd_type; ! typval_T jd_tv; // the list or dict typval_T jd_key_tv; char_u *jd_key; } json_dec_item_T; *************** *** 611,627 **** { retval = MAYBE; if (top_item->jd_type == JSON_OBJECT) ! /* did get the key, clear it */ clear_tv(&top_item->jd_key_tv); goto theend; } if (top_item->jd_type == JSON_OBJECT_KEY || top_item->jd_type == JSON_ARRAY) { ! /* Check for end of object or array. */ if (*p == (top_item->jd_type == JSON_ARRAY ? ']' : '}')) { ! ++reader->js_used; /* consume the ']' or '}' */ --stack.ga_len; if (stack.ga_len == 0) { --- 611,627 ---- { retval = MAYBE; if (top_item->jd_type == JSON_OBJECT) ! // did get the key, clear it clear_tv(&top_item->jd_key_tv); goto theend; } if (top_item->jd_type == JSON_OBJECT_KEY || top_item->jd_type == JSON_ARRAY) { ! // Check for end of object or array. if (*p == (top_item->jd_type == JSON_ARRAY ? ']' : '}')) { ! ++reader->js_used; // consume the ']' or '}' --stack.ga_len; if (stack.ga_len == 0) { *************** *** 644,650 **** { char_u *key; ! /* accept an object key that is not in quotes */ key = p = reader->js_buf + reader->js_used; while (*p != NUL && *p != ':' && *p > ' ') ++p; --- 644,650 ---- { char_u *key; ! // accept an object key that is not in quotes key = p = reader->js_buf + reader->js_used; while (*p != NUL && *p != ':' && *p > ' ') ++p; *************** *** 660,666 **** { switch (*p) { ! case '[': /* start of array */ if (top_item && top_item->jd_type == JSON_OBJECT_KEY) { retval = FAIL; --- 660,666 ---- { switch (*p) { ! case '[': // start of array if (top_item && top_item->jd_type == JSON_OBJECT_KEY) { retval = FAIL; *************** *** 679,685 **** break; } ! ++reader->js_used; /* consume the '[' */ top_item = ((json_dec_item_T *)stack.ga_data) + stack.ga_len; top_item->jd_type = JSON_ARRAY; --- 679,685 ---- break; } ! ++reader->js_used; // consume the '[' top_item = ((json_dec_item_T *)stack.ga_data) + stack.ga_len; top_item->jd_type = JSON_ARRAY; *************** *** 691,697 **** } continue; ! case '{': /* start of object */ if (top_item && top_item->jd_type == JSON_OBJECT_KEY) { retval = FAIL; --- 691,697 ---- } continue; ! case '{': // start of object if (top_item && top_item->jd_type == JSON_OBJECT_KEY) { retval = FAIL; *************** *** 710,716 **** break; } ! ++reader->js_used; /* consume the '{' */ top_item = ((json_dec_item_T *)stack.ga_data) + stack.ga_len; top_item->jd_type = JSON_OBJECT_KEY; --- 710,716 ---- break; } ! ++reader->js_used; // consume the '{' top_item = ((json_dec_item_T *)stack.ga_data) + stack.ga_len; top_item->jd_type = JSON_OBJECT_KEY; *************** *** 722,728 **** } continue; ! case '"': /* string */ retval = json_decode_string(reader, cur_item, *p); break; --- 722,728 ---- } continue; ! case '"': // string retval = json_decode_string(reader, cur_item, *p); break; *************** *** 736,750 **** } break; ! case ',': /* comma: empty item */ if ((options & JSON_JS) == 0) { emsg(_(e_invarg)); retval = FAIL; break; } ! /* FALLTHROUGH */ ! case NUL: /* empty */ if (cur_item != NULL) { cur_item->v_type = VAR_SPECIAL; --- 736,750 ---- } break; ! case ',': // comma: empty item if ((options & JSON_JS) == 0) { emsg(_(e_invarg)); retval = FAIL; break; } ! // FALLTHROUGH ! case NUL: // empty if (cur_item != NULL) { cur_item->v_type = VAR_SPECIAL; *************** *** 795,801 **** varnumber_T nr; vim_str2nr(reader->js_buf + reader->js_used, ! NULL, &len, 0, /* what */ &nr, NULL, 0, TRUE); if (len == 0) { --- 795,801 ---- varnumber_T nr; vim_str2nr(reader->js_buf + reader->js_used, ! NULL, &len, 0, // what &nr, NULL, 0, TRUE); if (len == 0) { *************** *** 881,887 **** break; } #endif ! /* check for truncated name */ len = (int)(reader->js_end - (reader->js_buf + reader->js_used)); if ( (len < 5 && STRNICMP((char *)p, "false", len) == 0) --- 881,887 ---- break; } #endif ! // check for truncated name len = (int)(reader->js_end - (reader->js_buf + reader->js_used)); if ( (len < 5 && STRNICMP((char *)p, "false", len) == 0) *************** *** 899,906 **** break; } ! /* We are finished when retval is FAIL or MAYBE and when at the ! * toplevel. */ if (retval == FAIL) break; if (retval == MAYBE || stack.ga_len == 0) --- 899,906 ---- break; } ! // We are finished when retval is FAIL or MAYBE and when at the ! // toplevel. if (retval == FAIL) break; if (retval == MAYBE || stack.ga_len == 0) *************** *** 1037,1043 **** } } ! /* Get here when parsing failed. */ if (res != NULL) { clear_tv(res); --- 1037,1043 ---- } } ! // Get here when parsing failed. if (res != NULL) { clear_tv(res); *************** *** 1061,1067 **** { int ret; ! /* We find the end once, to avoid calling strlen() many times. */ reader->js_end = reader->js_buf + STRLEN(reader->js_buf); json_skip_white(reader); ret = json_decode_item(reader, res, options); --- 1061,1067 ---- { int ret; ! // We find the end once, to avoid calling strlen() many times. reader->js_end = reader->js_buf + STRLEN(reader->js_buf); json_skip_white(reader); ret = json_decode_item(reader, res, options); *************** *** 1093,1099 **** { int ret; ! /* We find the end once, to avoid calling strlen() many times. */ reader->js_end = reader->js_buf + STRLEN(reader->js_buf); json_skip_white(reader); ret = json_decode_item(reader, res, options); --- 1093,1099 ---- { int ret; ! // We find the end once, to avoid calling strlen() many times. reader->js_end = reader->js_buf + STRLEN(reader->js_buf); json_skip_white(reader); ret = json_decode_item(reader, res, options); *************** *** 1119,1125 **** int used_save = reader->js_used; int ret; ! /* We find the end once, to avoid calling strlen() many times. */ reader->js_end = reader->js_buf + STRLEN(reader->js_buf); json_skip_white(reader); ret = json_decode_item(reader, NULL, options); --- 1119,1125 ---- int used_save = reader->js_used; int ret; ! // We find the end once, to avoid calling strlen() many times. reader->js_end = reader->js_buf + STRLEN(reader->js_buf); json_skip_white(reader); ret = json_decode_item(reader, NULL, options); *** ../vim-8.1.2387/src/json_test.c 2018-02-04 14:37:00.000000000 +0100 --- src/json_test.c 2019-12-04 21:41:23.951956804 +0100 *************** *** 14,29 **** #undef NDEBUG #include ! /* Must include main.c because it contains much more than just main() */ #define NO_VIM_MAIN #include "main.c" ! /* This file has to be included because the tested functions are static */ #include "json.c" #if defined(FEAT_EVAL) /* ! * Test json_find_end() with imcomplete items. */ static void test_decode_find_end(void) --- 14,29 ---- #undef NDEBUG #include ! // Must include main.c because it contains much more than just main() #define NO_VIM_MAIN #include "main.c" ! // This file has to be included because the tested functions are static #include "json.c" #if defined(FEAT_EVAL) /* ! * Test json_find_end() with incomplete items. */ static void test_decode_find_end(void) *************** *** 33,39 **** reader.js_fill = NULL; reader.js_used = 0; ! /* string and incomplete string */ reader.js_buf = (char_u *)"\"hello\""; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)" \"hello\" "; --- 33,39 ---- reader.js_fill = NULL; reader.js_used = 0; ! // string and incomplete string reader.js_buf = (char_u *)"\"hello\""; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)" \"hello\" "; *************** *** 41,53 **** reader.js_buf = (char_u *)"\"hello"; assert(json_find_end(&reader, 0) == MAYBE); ! /* number and dash (incomplete number) */ reader.js_buf = (char_u *)"123"; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)"-"; assert(json_find_end(&reader, 0) == MAYBE); ! /* false, true and null, also incomplete */ reader.js_buf = (char_u *)"false"; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)"f"; --- 41,53 ---- reader.js_buf = (char_u *)"\"hello"; assert(json_find_end(&reader, 0) == MAYBE); ! // number and dash (incomplete number) reader.js_buf = (char_u *)"123"; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)"-"; assert(json_find_end(&reader, 0) == MAYBE); ! // false, true and null, also incomplete reader.js_buf = (char_u *)"false"; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)"f"; *************** *** 77,83 **** reader.js_buf = (char_u *)"nul"; assert(json_find_end(&reader, 0) == MAYBE); ! /* object without white space */ reader.js_buf = (char_u *)"{\"a\":123}"; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)"{\"a\":123"; --- 77,83 ---- reader.js_buf = (char_u *)"nul"; assert(json_find_end(&reader, 0) == MAYBE); ! // object without white space reader.js_buf = (char_u *)"{\"a\":123}"; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)"{\"a\":123"; *************** *** 93,99 **** reader.js_buf = (char_u *)"{"; assert(json_find_end(&reader, 0) == MAYBE); ! /* object with white space */ reader.js_buf = (char_u *)" { \"a\" : 123 } "; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)" { \"a\" : 123 "; --- 93,99 ---- reader.js_buf = (char_u *)"{"; assert(json_find_end(&reader, 0) == MAYBE); ! // object with white space reader.js_buf = (char_u *)" { \"a\" : 123 } "; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)" { \"a\" : 123 "; *************** *** 107,119 **** reader.js_buf = (char_u *)" { "; assert(json_find_end(&reader, 0) == MAYBE); ! /* JS object with white space */ reader.js_buf = (char_u *)" { a : 123 } "; assert(json_find_end(&reader, JSON_JS) == OK); reader.js_buf = (char_u *)" { a : "; assert(json_find_end(&reader, JSON_JS) == MAYBE); ! /* array without white space */ reader.js_buf = (char_u *)"[\"a\",123]"; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)"[\"a\",123"; --- 107,119 ---- reader.js_buf = (char_u *)" { "; assert(json_find_end(&reader, 0) == MAYBE); ! // JS object with white space reader.js_buf = (char_u *)" { a : 123 } "; assert(json_find_end(&reader, JSON_JS) == OK); reader.js_buf = (char_u *)" { a : "; assert(json_find_end(&reader, JSON_JS) == MAYBE); ! // array without white space reader.js_buf = (char_u *)"[\"a\",123]"; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)"[\"a\",123"; *************** *** 129,135 **** reader.js_buf = (char_u *)"["; assert(json_find_end(&reader, 0) == MAYBE); ! /* array with white space */ reader.js_buf = (char_u *)" [ \"a\" , 123 ] "; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)" [ \"a\" , 123 "; --- 129,135 ---- reader.js_buf = (char_u *)"["; assert(json_find_end(&reader, 0) == MAYBE); ! // array with white space reader.js_buf = (char_u *)" [ \"a\" , 123 ] "; assert(json_find_end(&reader, 0) == OK); reader.js_buf = (char_u *)" [ \"a\" , 123 "; *** ../vim-8.1.2387/src/kword_test.c 2019-01-24 15:54:17.786847003 +0100 --- src/kword_test.c 2019-12-04 21:41:40.751904257 +0100 *************** *** 14,24 **** #undef NDEBUG #include ! /* Must include main.c because it contains much more than just main() */ #define NO_VIM_MAIN #include "main.c" ! /* This file has to be included because the tested functions are static */ #include "charset.c" /* --- 14,24 ---- #undef NDEBUG #include ! // Must include main.c because it contains much more than just main() #define NO_VIM_MAIN #include "main.c" ! // This file has to be included because the tested functions are static #include "charset.c" /* *************** *** 38,44 **** buf.b_p_isk = (char_u *)"@,48-57,_,128-167,224-235"; curbuf = &buf; ! mb_init(); /* calls init_chartab() */ for (c = 0; c < 0x10000; ++c) { --- 38,44 ---- buf.b_p_isk = (char_u *)"@,48-57,_,128-167,224-235"; curbuf = &buf; ! mb_init(); // calls init_chartab() for (c = 0; c < 0x10000; ++c) { *** ../vim-8.1.2387/src/list.c 2019-09-04 17:48:11.712877356 +0200 --- src/list.c 2019-12-04 21:42:30.355748468 +0100 *************** *** 17,24 **** static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob"); ! /* List heads for garbage collection. */ ! static list_T *first_list = NULL; /* list of all lists */ /* * Add a watcher to a list. --- 17,24 ---- static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob"); ! // List heads for garbage collection. ! static list_T *first_list = NULL; // list of all lists /* * Add a watcher to a list. *************** *** 77,83 **** l = ALLOC_CLEAR_ONE(list_T); if (l != NULL) { ! /* Prepend the list to the list of lists for garbage collection. */ if (first_list != NULL) first_list->lv_used_prev = l; l->lv_used_prev = NULL; --- 77,83 ---- l = ALLOC_CLEAR_ONE(list_T); if (l != NULL) { ! // Prepend the list to the list of lists for garbage collection. if (first_list != NULL) first_list->lv_used_prev = l; l->lv_used_prev = NULL; *************** *** 165,171 **** for (item = l->lv_first; item != NULL; item = l->lv_first) { ! /* Remove the item before deleting it. */ l->lv_first = item->li_next; clear_tv(&item->li_tv); vim_free(item); --- 165,171 ---- for (item = l->lv_first; item != NULL; item = l->lv_first) { ! // Remove the item before deleting it. l->lv_first = item->li_next; clear_tv(&item->li_tv); vim_free(item); *************** *** 187,195 **** if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK) && ll->lv_watch == NULL) { ! /* Free the List and ordinary items it contains, but don't recurse ! * into Lists and Dictionaries, they will be in the list of dicts ! * or list of lists. */ list_free_contents(ll); did_free = TRUE; } --- 187,195 ---- if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK) && ll->lv_watch == NULL) { ! // Free the List and ordinary items it contains, but don't recurse ! // into Lists and Dictionaries, they will be in the list of dicts ! // or list of lists. list_free_contents(ll); did_free = TRUE; } *************** *** 199,205 **** static void list_free_list(list_T *l) { ! /* Remove the list from the list of lists for garbage collection. */ if (l->lv_used_prev == NULL) first_list = l->lv_used_next; else --- 199,205 ---- static void list_free_list(list_T *l) { ! // Remove the list from the list of lists for garbage collection. if (l->lv_used_prev == NULL) first_list = l->lv_used_next; else *************** *** 221,229 **** if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK) && ll->lv_watch == NULL) { ! /* Free the List and ordinary items it contains, but don't recurse ! * into Lists and Dictionaries, they will be in the list of dicts ! * or list of lists. */ list_free_list(ll); } } --- 221,229 ---- if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK) && ll->lv_watch == NULL) { ! // Free the List and ordinary items it contains, but don't recurse ! // into Lists and Dictionaries, they will be in the list of dicts ! // or list of lists. list_free_list(ll); } } *************** *** 287,294 **** list_equal( list_T *l1, list_T *l2, ! int ic, /* ignore case for strings */ ! int recursive) /* TRUE when used recursively */ { listitem_T *item1, *item2; --- 287,294 ---- list_equal( list_T *l1, list_T *l2, ! int ic, // ignore case for strings ! int recursive) // TRUE when used recursively { listitem_T *item1, *item2; *************** *** 321,352 **** if (l == NULL) return NULL; ! /* Negative index is relative to the end. */ if (n < 0) n = l->lv_len + n; ! /* Check for index out of range. */ if (n < 0 || n >= l->lv_len) return NULL; ! /* When there is a cached index may start search from there. */ if (l->lv_idx_item != NULL) { if (n < l->lv_idx / 2) { ! /* closest to the start of the list */ item = l->lv_first; idx = 0; } else if (n > (l->lv_idx + l->lv_len) / 2) { ! /* closest to the end of the list */ item = l->lv_last; idx = l->lv_len - 1; } else { ! /* closest to the cached index */ item = l->lv_idx_item; idx = l->lv_idx; } --- 321,352 ---- if (l == NULL) return NULL; ! // Negative index is relative to the end. if (n < 0) n = l->lv_len + n; ! // Check for index out of range. if (n < 0 || n >= l->lv_len) return NULL; ! // When there is a cached index may start search from there. if (l->lv_idx_item != NULL) { if (n < l->lv_idx / 2) { ! // closest to the start of the list item = l->lv_first; idx = 0; } else if (n > (l->lv_idx + l->lv_len) / 2) { ! // closest to the end of the list item = l->lv_last; idx = l->lv_len - 1; } else { ! // closest to the cached index item = l->lv_idx_item; idx = l->lv_idx; } *************** *** 355,367 **** { if (n < l->lv_len / 2) { ! /* closest to the start of the list */ item = l->lv_first; idx = 0; } else { ! /* closest to the end of the list */ item = l->lv_last; idx = l->lv_len - 1; } --- 355,367 ---- { if (n < l->lv_len / 2) { ! // closest to the start of the list item = l->lv_first; idx = 0; } else { ! // closest to the end of the list item = l->lv_last; idx = l->lv_len - 1; } *************** *** 369,386 **** while (n > idx) { ! /* search forward */ item = item->li_next; ++idx; } while (n < idx) { ! /* search backward */ item = item->li_prev; --idx; } ! /* cache the used index */ l->lv_idx = idx; l->lv_idx_item = item; --- 369,386 ---- while (n > idx) { ! // search forward item = item->li_next; ++idx; } while (n < idx) { ! // search backward item = item->li_prev; --idx; } ! // cache the used index l->lv_idx = idx; l->lv_idx_item = item; *************** *** 394,400 **** list_find_nr( list_T *l, long idx, ! int *errorp) /* set to TRUE when something wrong */ { listitem_T *li; --- 394,400 ---- list_find_nr( list_T *l, long idx, ! int *errorp) // set to TRUE when something wrong { listitem_T *li; *************** *** 453,459 **** { if (l->lv_last == NULL) { ! /* empty list */ l->lv_first = item; l->lv_last = item; item->li_prev = NULL; --- 453,459 ---- { if (l->lv_last == NULL) { ! // empty list l->lv_first = item; l->lv_last = item; item->li_prev = NULL; *************** *** 585,595 **** list_insert(list_T *l, listitem_T *ni, listitem_T *item) { if (item == NULL) ! /* Append new item at end of list. */ list_append(l, ni); else { ! /* Insert new item before existing item. */ ni->li_prev = item->li_prev; ni->li_next = item; if (item->li_prev == NULL) --- 585,595 ---- list_insert(list_T *l, listitem_T *ni, listitem_T *item) { if (item == NULL) ! // Append new item at end of list. list_append(l, ni); else { ! // Insert new item before existing item. ni->li_prev = item->li_prev; ni->li_next = item; if (item->li_prev == NULL) *************** *** 618,625 **** listitem_T *item; int todo = l2->lv_len; ! /* We also quit the loop when we have inserted the original item count of ! * the list, avoid a hang when we extend a list with itself. */ for (item = l2->lv_first; item != NULL && --todo >= 0; item = item->li_next) if (list_insert_tv(l1, &item->li_tv, bef) == FAIL) return FAIL; --- 618,625 ---- listitem_T *item; int todo = l2->lv_len; ! // We also quit the loop when we have inserted the original item count of ! // the list, avoid a hang when we extend a list with itself. for (item = l2->lv_first; item != NULL && --todo >= 0; item = item->li_next) if (list_insert_tv(l1, &item->li_tv, bef) == FAIL) return FAIL; *************** *** 638,651 **** if (l1 == NULL || l2 == NULL) return FAIL; ! /* make a copy of the first list. */ l = list_copy(l1, FALSE, 0); if (l == NULL) return FAIL; tv->v_type = VAR_LIST; tv->vval.v_list = l; ! /* append all items from the second list */ return list_extend(l, l2, NULL); } --- 638,651 ---- if (l1 == NULL || l2 == NULL) return FAIL; ! // make a copy of the first list. l = list_copy(l1, FALSE, 0); if (l == NULL) return FAIL; tv->v_type = VAR_LIST; tv->vval.v_list = l; ! // append all items from the second list return list_extend(l, l2, NULL); } *************** *** 670,677 **** { if (copyID != 0) { ! /* Do this before adding the items, because one of the items may ! * refer back to this list. */ orig->lv_copyID = copyID; orig->lv_copylist = copy; } --- 670,677 ---- { if (copyID != 0) { ! // Do this before adding the items, because one of the items may ! // refer back to this list. orig->lv_copyID = copyID; orig->lv_copylist = copy; } *************** *** 715,721 **** { listitem_T *ip; ! /* notify watchers */ for (ip = item; ip != NULL; ip = ip->li_next) { --l->lv_len; --- 715,721 ---- { listitem_T *ip; ! // notify watchers for (ip = item; ip != NULL; ip = ip->li_next) { --l->lv_len; *************** *** 766,778 **** static int list_join_inner( ! garray_T *gap, /* to store the result in */ list_T *l, char_u *sep, int echo_style, int restore_copyID, int copyID, ! garray_T *join_gap) /* to keep each list item string */ { int i; join_T *p; --- 766,778 ---- static int list_join_inner( ! garray_T *gap, // to store the result in list_T *l, char_u *sep, int echo_style, int restore_copyID, int copyID, ! garray_T *join_gap) // to keep each list item string { int i; join_T *p; *************** *** 784,790 **** listitem_T *item; char_u *s; ! /* Stringify each item in the list. */ for (item = l->lv_first; item != NULL && !got_int; item = item->li_next) { s = echo_string_core(&item->li_tv, &tofree, numbuf, copyID, --- 784,790 ---- listitem_T *item; char_u *s; ! // Stringify each item in the list. for (item = l->lv_first; item != NULL && !got_int; item = item->li_next) { s = echo_string_core(&item->li_tv, &tofree, numbuf, copyID, *************** *** 809,820 **** } line_breakcheck(); ! if (did_echo_string_emsg) /* recursion error, bail out */ break; } ! /* Allocate result buffer with its total size, avoid re-allocation and ! * multiple copy operations. Add 2 for a tailing ']' and NUL. */ if (join_gap->ga_len >= 2) sumlen += (int)STRLEN(sep) * (join_gap->ga_len - 1); if (ga_grow(gap, sumlen + 2) == FAIL) --- 809,820 ---- } line_breakcheck(); ! if (did_echo_string_emsg) // recursion error, bail out break; } ! // Allocate result buffer with its total size, avoid re-allocation and ! // multiple copy operations. Add 2 for a tailing ']' and NUL. if (join_gap->ga_len >= 2) sumlen += (int)STRLEN(sep) * (join_gap->ga_len - 1); if (ga_grow(gap, sumlen + 2) == FAIL) *************** *** 856,867 **** int i; if (l->lv_len < 1) ! return OK; /* nothing to do */ ga_init2(&join_ga, (int)sizeof(join_T), l->lv_len); retval = list_join_inner(gap, l, sep, echo_style, restore_copyID, copyID, &join_ga); ! /* Dispose each item in join_ga. */ if (join_ga.ga_data != NULL) { p = (join_T *)join_ga.ga_data; --- 856,867 ---- int i; if (l->lv_len < 1) ! return OK; // nothing to do ga_init2(&join_ga, (int)sizeof(join_T), l->lv_len); retval = list_join_inner(gap, l, sep, echo_style, restore_copyID, copyID, &join_ga); ! // Dispose each item in join_ga. if (join_ga.ga_data != NULL) { p = (join_T *)join_ga.ga_data; *************** *** 931,937 **** *arg = skipwhite(*arg + 1); while (**arg != ']' && **arg != NUL) { ! if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */ goto failret; if (evaluate) { --- 931,937 ---- *arg = skipwhite(*arg + 1); while (**arg != ']' && **arg != NUL) { ! if (eval1(arg, &tv, evaluate) == FAIL) // recursive! goto failret; if (evaluate) { *************** *** 1120,1126 **** { if (argvars[2].v_type == VAR_UNKNOWN) { ! /* Remove one item, return its value. */ vimlist_remove(l, item, item); *rettv = item->li_tv; vim_free(item); --- 1120,1126 ---- { if (argvars[2].v_type == VAR_UNKNOWN) { ! // Remove one item, return its value. vimlist_remove(l, item, item); *rettv = item->li_tv; vim_free(item); *************** *** 1144,1150 **** if (li == item2) break; } ! if (li == NULL) /* didn't find "item2" after "item" */ emsg(_(e_invrange)); else { --- 1144,1150 ---- if (li == item2) break; } ! if (li == NULL) // didn't find "item2" after "item" emsg(_(e_invrange)); else { *************** *** 1167,1180 **** static int item_compare(const void *s1, const void *s2); static int item_compare2(const void *s1, const void *s2); ! /* struct used in the array that's given to qsort() */ typedef struct { listitem_T *item; int idx; } sortItem_T; ! /* struct storing information about current sort */ typedef struct { int item_compare_ic; --- 1167,1180 ---- static int item_compare(const void *s1, const void *s2); static int item_compare2(const void *s1, const void *s2); ! // struct used in the array that's given to qsort() typedef struct { listitem_T *item; int idx; } sortItem_T; ! // struct storing information about current sort typedef struct { int item_compare_ic; *************** *** 1229,1237 **** } #endif ! /* tv2string() puts quotes around a string and allocates memory. Don't do ! * that for string variables. Use a single quote when comparing with a ! * non-string to do what the docs promise. */ if (tv1->v_type == VAR_STRING) { if (tv2->v_type != VAR_STRING || sortinfo->item_compare_numeric) --- 1229,1237 ---- } #endif ! // tv2string() puts quotes around a string and allocates memory. Don't do ! // that for string variables. Use a single quote when comparing with a ! // non-string to do what the docs promise. if (tv1->v_type == VAR_STRING) { if (tv2->v_type != VAR_STRING || sortinfo->item_compare_numeric) *************** *** 1269,1276 **** res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1; } ! /* When the result would be zero, compare the item indexes. Makes the ! * sort stable. */ if (res == 0 && !sortinfo->item_compare_keep_zero) res = si1->idx > si2->idx ? 1 : -1; --- 1269,1276 ---- res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1; } ! // When the result would be zero, compare the item indexes. Makes the ! // sort stable. if (res == 0 && !sortinfo->item_compare_keep_zero) res = si1->idx > si2->idx ? 1 : -1; *************** *** 1290,1296 **** partial_T *partial = sortinfo->item_compare_partial; funcexe_T funcexe; ! /* shortcut after failure in previous call; compare all items equal */ if (sortinfo->item_compare_func_err) return 0; --- 1290,1296 ---- partial_T *partial = sortinfo->item_compare_partial; funcexe_T funcexe; ! // shortcut after failure in previous call; compare all items equal if (sortinfo->item_compare_func_err) return 0; *************** *** 1302,1313 **** else func_name = partial_name(partial); ! /* Copy the values. This is needed to be able to set v_lock to VAR_FIXED ! * in the copy without changing the original list items. */ copy_tv(&si1->item->li_tv, &argv[0]); copy_tv(&si2->item->li_tv, &argv[1]); ! rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */ vim_memset(&funcexe, 0, sizeof(funcexe)); funcexe.evaluate = TRUE; funcexe.partial = partial; --- 1302,1313 ---- else func_name = partial_name(partial); ! // Copy the values. This is needed to be able to set v_lock to VAR_FIXED ! // in the copy without changing the original list items. copy_tv(&si1->item->li_tv, &argv[0]); copy_tv(&si2->item->li_tv, &argv[1]); ! rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this vim_memset(&funcexe, 0, sizeof(funcexe)); funcexe.evaluate = TRUE; funcexe.partial = partial; *************** *** 1321,1331 **** else res = (int)tv_get_number_chk(&rettv, &sortinfo->item_compare_func_err); if (sortinfo->item_compare_func_err) ! res = ITEM_COMPARE_FAIL; /* return value has wrong type */ clear_tv(&rettv); ! /* When the result would be zero, compare the pointers themselves. Makes ! * the sort stable. */ if (res == 0 && !sortinfo->item_compare_keep_zero) res = si1->idx > si2->idx ? 1 : -1; --- 1321,1331 ---- else res = (int)tv_get_number_chk(&rettv, &sortinfo->item_compare_func_err); if (sortinfo->item_compare_func_err) ! res = ITEM_COMPARE_FAIL; // return value has wrong type clear_tv(&rettv); ! // When the result would be zero, compare the pointers themselves. Makes ! // the sort stable. if (res == 0 && !sortinfo->item_compare_keep_zero) res = si1->idx > si2->idx ? 1 : -1; *************** *** 1346,1353 **** long len; long i; ! /* Pointer to current info struct used in compare function. Save and ! * restore the current one for nested calls. */ old_sortinfo = sortinfo; sortinfo = &info; --- 1346,1353 ---- long len; long i; ! // Pointer to current info struct used in compare function. Save and ! // restore the current one for nested calls. old_sortinfo = sortinfo; sortinfo = &info; *************** *** 1364,1370 **** len = list_len(l); if (len <= 1) ! goto theend; /* short list sorts pretty quickly */ info.item_compare_ic = FALSE; info.item_compare_numeric = FALSE; --- 1364,1370 ---- len = list_len(l); if (len <= 1) ! goto theend; // short list sorts pretty quickly info.item_compare_ic = FALSE; info.item_compare_numeric = FALSE; *************** *** 1377,1383 **** info.item_compare_selfdict = NULL; if (argvars[1].v_type != VAR_UNKNOWN) { ! /* optional second argument: {func} */ if (argvars[1].v_type == VAR_FUNC) info.item_compare_func = argvars[1].vval.v_string; else if (argvars[1].v_type == VAR_PARTIAL) --- 1377,1383 ---- info.item_compare_selfdict = NULL; if (argvars[1].v_type != VAR_UNKNOWN) { ! // optional second argument: {func} if (argvars[1].v_type == VAR_FUNC) info.item_compare_func = argvars[1].vval.v_string; else if (argvars[1].v_type == VAR_PARTIAL) *************** *** 1388,1394 **** i = (long)tv_get_number_chk(&argvars[1], &error); if (error) ! goto theend; /* type error; errmsg already given */ if (i == 1) info.item_compare_ic = TRUE; else if (argvars[1].v_type != VAR_NUMBER) --- 1388,1394 ---- i = (long)tv_get_number_chk(&argvars[1], &error); if (error) ! goto theend; // type error; errmsg already given if (i == 1) info.item_compare_ic = TRUE; else if (argvars[1].v_type != VAR_NUMBER) *************** *** 1402,1408 **** { if (*info.item_compare_func == NUL) { ! /* empty string means default sort */ info.item_compare_func = NULL; } else if (STRCMP(info.item_compare_func, "n") == 0) --- 1402,1408 ---- { if (*info.item_compare_func == NUL) { ! // empty string means default sort info.item_compare_func = NULL; } else if (STRCMP(info.item_compare_func, "n") == 0) *************** *** 1432,1438 **** if (argvars[2].v_type != VAR_UNKNOWN) { ! /* optional third argument: {dict} */ if (argvars[2].v_type != VAR_DICT) { emsg(_(e_dictreq)); --- 1432,1438 ---- if (argvars[2].v_type != VAR_UNKNOWN) { ! // optional third argument: {dict} if (argvars[2].v_type != VAR_DICT) { emsg(_(e_dictreq)); *************** *** 1442,1448 **** } } ! /* Make an array with each entry pointing to an item in the List. */ ptrs = ALLOC_MULT(sortItem_T, len); if (ptrs == NULL) goto theend; --- 1442,1448 ---- } } ! // Make an array with each entry pointing to an item in the List. ptrs = ALLOC_MULT(sortItem_T, len); if (ptrs == NULL) goto theend; *************** *** 1450,1456 **** i = 0; if (sort) { ! /* sort(): ptrs will be the list to sort */ for (li = l->lv_first; li != NULL; li = li->li_next) { ptrs[i].item = li; --- 1450,1456 ---- i = 0; if (sort) { ! // sort(): ptrs will be the list to sort for (li = l->lv_first; li != NULL; li = li->li_next) { ptrs[i].item = li; *************** *** 1460,1466 **** info.item_compare_func_err = FALSE; info.item_compare_keep_zero = FALSE; ! /* test the compare function */ if ((info.item_compare_func != NULL || info.item_compare_partial != NULL) && item_compare2((void *)&ptrs[0], (void *)&ptrs[1]) --- 1460,1466 ---- info.item_compare_func_err = FALSE; info.item_compare_keep_zero = FALSE; ! // test the compare function if ((info.item_compare_func != NULL || info.item_compare_partial != NULL) && item_compare2((void *)&ptrs[0], (void *)&ptrs[1]) *************** *** 1468,1474 **** emsg(_("E702: Sort compare function failed")); else { ! /* Sort the array with item pointers. */ qsort((void *)ptrs, (size_t)len, sizeof(sortItem_T), info.item_compare_func == NULL && info.item_compare_partial == NULL --- 1468,1474 ---- emsg(_("E702: Sort compare function failed")); else { ! // Sort the array with item pointers. qsort((void *)ptrs, (size_t)len, sizeof(sortItem_T), info.item_compare_func == NULL && info.item_compare_partial == NULL *************** *** 1476,1482 **** if (!info.item_compare_func_err) { ! /* Clear the List and append the items in sorted order. */ l->lv_first = l->lv_last = l->lv_idx_item = NULL; l->lv_len = 0; for (i = 0; i < len; ++i) --- 1476,1482 ---- if (!info.item_compare_func_err) { ! // Clear the List and append the items in sorted order. l->lv_first = l->lv_last = l->lv_idx_item = NULL; l->lv_len = 0; for (i = 0; i < len; ++i) *************** *** 1488,1494 **** { int (*item_compare_func_ptr)(const void *, const void *); ! /* f_uniq(): ptrs will be a stack of items to remove */ info.item_compare_func_err = FALSE; info.item_compare_keep_zero = TRUE; item_compare_func_ptr = info.item_compare_func != NULL --- 1488,1494 ---- { int (*item_compare_func_ptr)(const void *, const void *); ! // f_uniq(): ptrs will be a stack of items to remove info.item_compare_func_err = FALSE; info.item_compare_keep_zero = TRUE; item_compare_func_ptr = info.item_compare_func != NULL *************** *** 1774,1780 **** list_T *l; blob_T *b; ! rettv->vval.v_number = 1; /* Default: Failed */ if (argvars[0].v_type == VAR_LIST) { if ((l = argvars[0].vval.v_list) != NULL --- 1774,1780 ---- list_T *l; blob_T *b; ! rettv->vval.v_number = 1; // Default: Failed if (argvars[0].v_type == VAR_LIST) { if ((l = argvars[0].vval.v_list) != NULL *************** *** 1935,1941 **** { before = (long)tv_get_number_chk(&argvars[2], &error); if (error) ! return; /* type error; errmsg already given */ if (before == l1->lv_len) item = NULL; --- 1935,1941 ---- { before = (long)tv_get_number_chk(&argvars[2], &error); if (error) ! return; // type error; errmsg already given if (before == l1->lv_len) item = NULL; *************** *** 1967,1980 **** if (d1 != NULL && !var_check_lock(d1->dv_lock, arg_errmsg, TRUE) && d2 != NULL) { ! /* Check the third argument. */ if (argvars[2].v_type != VAR_UNKNOWN) { static char *(av[]) = {"keep", "force", "error"}; action = tv_get_string_chk(&argvars[2]); if (action == NULL) ! return; /* type error; errmsg already given */ for (i = 0; i < 3; ++i) if (STRCMP(action, av[i]) == 0) break; --- 1967,1980 ---- if (d1 != NULL && !var_check_lock(d1->dv_lock, arg_errmsg, TRUE) && d2 != NULL) { ! // Check the third argument. if (argvars[2].v_type != VAR_UNKNOWN) { static char *(av[]) = {"keep", "force", "error"}; action = tv_get_string_chk(&argvars[2]); if (action == NULL) ! return; // type error; errmsg already given for (i = 0; i < 3; ++i) if (STRCMP(action, av[i]) == 0) break; *************** *** 2051,2057 **** if (argvars[2].v_type != VAR_UNKNOWN) before = (long)tv_get_number_chk(&argvars[2], &error); if (error) ! return; /* type error; errmsg already given */ if (before == l->lv_len) item = NULL; --- 2051,2057 ---- if (argvars[2].v_type != VAR_UNKNOWN) before = (long)tv_get_number_chk(&argvars[2], &error); if (error) ! return; // type error; errmsg already given if (before == l->lv_len) item = NULL; *** ../vim-8.1.2387/src/main.c 2019-11-30 22:47:42.651331201 +0100 --- src/main.c 2019-12-04 21:46:01.995074777 +0100 *************** *** 13,20 **** #ifdef __CYGWIN__ # ifndef MSWIN # include ! # include /* for cygwin_conv_to_posix_path() and/or ! * cygwin_conv_path() */ # endif # include #endif --- 13,20 ---- #ifdef __CYGWIN__ # ifndef MSWIN # include ! # include // for cygwin_conv_to_posix_path() and/or ! // cygwin_conv_path() # endif # include #endif *************** *** 23,34 **** # include "iscygpty.h" #endif ! /* Values for edit_type. */ ! #define EDIT_NONE 0 /* no edit type yet */ ! #define EDIT_FILE 1 /* file name argument[s] given, use argument list */ ! #define EDIT_STDIN 2 /* read file from stdin */ ! #define EDIT_TAG 3 /* tag name argument given, use tagname */ ! #define EDIT_QF 4 /* start in quickfix mode */ #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN) static int file_owned(char *fname); --- 23,34 ---- # include "iscygpty.h" #endif ! // Values for edit_type. ! #define EDIT_NONE 0 // no edit type yet ! #define EDIT_FILE 1 // file name argument[s] given, use argument list ! #define EDIT_STDIN 2 // read file from stdin ! #define EDIT_TAG 3 // tag name argument given, use tagname ! #define EDIT_QF 4 // start in quickfix mode #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN) static int file_owned(char *fname); *************** *** 82,95 **** #define ME_INVALID_ARG 5 }; ! #ifndef PROTO /* don't want a prototype for main() */ ! /* Various parameters passed between main() and other functions. */ static mparm_T params; ! #ifndef NO_VIM_MAIN /* skip this for unittests */ ! static char_u *start_dir = NULL; /* current working dir on startup */ static int has_dash_c_arg = FALSE; --- 82,95 ---- #define ME_INVALID_ARG 5 }; ! #ifndef PROTO // don't want a prototype for main() ! // Various parameters passed between main() and other functions. static mparm_T params; ! #ifndef NO_VIM_MAIN // skip this for unittests ! static char_u *start_dir = NULL; // current working dir on startup static int has_dash_c_arg = FALSE; *************** *** 122,130 **** argc = get_cmd_argsW(&argv); #endif ! /* Many variables are in "params" so that we can pass them to invoked ! * functions without a lot of arguments. "argc" and "argv" are also ! * copied, so that they can be changed. */ vim_memset(¶ms, 0, sizeof(params)); params.argc = argc; params.argv = argv; --- 122,130 ---- argc = get_cmd_argsW(&argv); #endif ! // Many variables are in "params" so that we can pass them to invoked ! // functions without a lot of arguments. "argc" and "argv" are also ! // copied, so that they can be changed. vim_memset(¶ms, 0, sizeof(params)); params.argc = argc; params.argv = argv; *************** *** 150,156 **** #endif #ifdef STARTUPTIME ! /* Need to find "--startuptime" before actually parsing arguments. */ for (i = 1; i < argc - 1; ++i) if (STRICMP(argv[i], "--startuptime") == 0) { --- 150,156 ---- #endif #ifdef STARTUPTIME ! // Need to find "--startuptime" before actually parsing arguments. for (i = 1; i < argc - 1; ++i) if (STRICMP(argv[i], "--startuptime") == 0) { *************** *** 162,168 **** starttime = time(NULL); #ifdef CLEAN_RUNTIMEPATH ! /* Need to find "--clean" before actually parsing arguments. */ for (i = 1; i < argc; ++i) if (STRICMP(argv[i], "--clean") == 0) { --- 162,168 ---- starttime = time(NULL); #ifdef CLEAN_RUNTIMEPATH ! // Need to find "--clean" before actually parsing arguments. for (i = 1; i < argc; ++i) if (STRICMP(argv[i], "--clean") == 0) { *************** *** 219,226 **** { gui.starting = FALSE; ! /* When running "evim" or "gvim -y" we need the menus, exit if we ! * don't have them. */ if (params.evim_mode) mch_exit(1); } --- 219,226 ---- { gui.starting = FALSE; ! // When running "evim" or "gvim -y" we need the menus, exit if we ! // don't have them. if (params.evim_mode) mch_exit(1); } *************** *** 239,247 **** start_dir = alloc(MAXPATHL); if (start_dir != NULL) mch_dirname(start_dir, MAXPATHL); ! /* Temporarily add '(' and ')' to 'isfname'. These are valid ! * filename characters but are excluded from 'isfname' to make ! * "gf" work on a file name in parenthesis (e.g.: see vim.h). */ do_cmdline_cmd((char_u *)":set isf+=(,)"); alist_expand(NULL, 0); do_cmdline_cmd((char_u *)":set isf&"); --- 239,247 ---- start_dir = alloc(MAXPATHL); if (start_dir != NULL) mch_dirname(start_dir, MAXPATHL); ! // Temporarily add '(' and ')' to 'isfname'. These are valid ! // filename characters but are excluded from 'isfname' to make ! // "gf" work on a file name in parenthesis (e.g.: see vim.h). do_cmdline_cmd((char_u *)":set isf+=(,)"); alist_expand(NULL, 0); do_cmdline_cmd((char_u *)":set isf&"); *************** *** 256,263 **** { extern void set_alist_count(void); ! /* Remember the number of entries in the argument list. If it changes ! * we don't react on setting 'encoding'. */ set_alist_count(); } #endif --- 256,263 ---- { extern void set_alist_count(void); ! // Remember the number of entries in the argument list. If it changes ! // we don't react on setting 'encoding'. set_alist_count(); } #endif *************** *** 280,289 **** #ifdef FEAT_DIFF if (params.diff_mode && params.window_count == -1) ! params.window_count = 0; /* open up to 3 windows */ #endif ! /* Don't redraw until much later. */ ++RedrawingDisabled; /* --- 280,289 ---- #ifdef FEAT_DIFF if (params.diff_mode && params.window_count == -1) ! params.window_count = 0; // open up to 3 windows #endif ! // Don't redraw until much later. ++RedrawingDisabled; /* *************** *** 308,323 **** #endif #if defined(FEAT_GUI_MAC) && defined(MACOS_X_DARWIN) ! /* When the GUI is started from Finder, need to display messages in a ! * message box. isatty(2) returns TRUE anyway, thus we need to check the ! * name to know we're not started from a terminal. */ if (gui.starting && (!isatty(2) || strcmp("/dev/console", ttyname(2)) == 0)) { params.want_full_screen = FALSE; ! /* Avoid always using "/" as the current directory. Note that when ! * started from Finder the arglist will be filled later in ! * HandleODocAE() and "fname" will be NULL. */ if (getcwd((char *)NameBuff, MAXPATHL) != NULL && STRCMP(NameBuff, "/") == 0) { --- 308,323 ---- #endif #if defined(FEAT_GUI_MAC) && defined(MACOS_X_DARWIN) ! // When the GUI is started from Finder, need to display messages in a ! // message box. isatty(2) returns TRUE anyway, thus we need to check the ! // name to know we're not started from a terminal. if (gui.starting && (!isatty(2) || strcmp("/dev/console", ttyname(2)) == 0)) { params.want_full_screen = FALSE; ! // Avoid always using "/" as the current directory. Note that when ! // started from Finder the arglist will be filled later in ! // HandleODocAE() and "fname" will be NULL. if (getcwd((char *)NameBuff, MAXPATHL) != NULL && STRCMP(NameBuff, "/") == 0) { *************** *** 368,375 **** check_tty(¶ms); #ifdef _IOLBF ! /* Ensure output works usefully without a tty: buffer lines instead of ! * fully buffered. */ if (silent_mode) setvbuf(stdout, NULL, _IOLBF, 0); #endif --- 368,375 ---- check_tty(¶ms); #ifdef _IOLBF ! // Ensure output works usefully without a tty: buffer lines instead of ! // fully buffered. if (silent_mode) setvbuf(stdout, NULL, _IOLBF, 0); #endif *************** *** 381,434 **** if (params.want_full_screen && !silent_mode) { ! termcapinit(params.term); /* set terminal name and get terminal ! capabilities (will set full_screen) */ ! screen_start(); /* don't know where cursor is now */ TIME_MSG("Termcap init"); } /* * Set the default values for the options that use Rows and Columns. */ ! ui_get_shellsize(); /* inits Rows and Columns */ win_init_size(); #ifdef FEAT_DIFF ! /* Set the 'diff' option now, so that it can be checked for in a .vimrc ! * file. There is no buffer yet though. */ if (params.diff_mode) diff_win_options(firstwin, FALSE); #endif cmdline_row = Rows - p_ch; msg_row = cmdline_row; ! screenalloc(FALSE); /* allocate screen buffers */ set_init_2(); TIME_MSG("inits 2"); msg_scroll = TRUE; no_wait_return = TRUE; ! init_mappings(); /* set up initial mappings */ ! init_highlight(TRUE, FALSE); /* set the default highlight groups */ TIME_MSG("init highlight"); #ifdef FEAT_EVAL ! /* Set the break level after the terminal is initialized. */ debug_break_level = params.use_debug_break_level; #endif ! /* Reset 'loadplugins' for "-u NONE" before "--cmd" arguments. ! * Allows for setting 'loadplugins' there. */ if (params.use_vimrc != NULL && (STRCMP(params.use_vimrc, "NONE") == 0 || STRCMP(params.use_vimrc, "DEFAULTS") == 0)) p_lpl = FALSE; ! /* Execute --cmd arguments. */ exe_pre_commands(¶ms); ! /* Source startup scripts. */ source_startup_scripts(¶ms); #ifdef FEAT_MZSCHEME --- 381,434 ---- if (params.want_full_screen && !silent_mode) { ! termcapinit(params.term); // set terminal name and get terminal ! // capabilities (will set full_screen) ! screen_start(); // don't know where cursor is now TIME_MSG("Termcap init"); } /* * Set the default values for the options that use Rows and Columns. */ ! ui_get_shellsize(); // inits Rows and Columns win_init_size(); #ifdef FEAT_DIFF ! // Set the 'diff' option now, so that it can be checked for in a .vimrc ! // file. There is no buffer yet though. if (params.diff_mode) diff_win_options(firstwin, FALSE); #endif cmdline_row = Rows - p_ch; msg_row = cmdline_row; ! screenalloc(FALSE); // allocate screen buffers set_init_2(); TIME_MSG("inits 2"); msg_scroll = TRUE; no_wait_return = TRUE; ! init_mappings(); // set up initial mappings ! init_highlight(TRUE, FALSE); // set the default highlight groups TIME_MSG("init highlight"); #ifdef FEAT_EVAL ! // Set the break level after the terminal is initialized. debug_break_level = params.use_debug_break_level; #endif ! // Reset 'loadplugins' for "-u NONE" before "--cmd" arguments. ! // Allows for setting 'loadplugins' there. if (params.use_vimrc != NULL && (STRCMP(params.use_vimrc, "NONE") == 0 || STRCMP(params.use_vimrc, "DEFAULTS") == 0)) p_lpl = FALSE; ! // Execute --cmd arguments. exe_pre_commands(¶ms); ! // Source startup scripts. source_startup_scripts(¶ms); #ifdef FEAT_MZSCHEME *************** *** 444,451 **** return vim_main2(); #endif } ! #endif /* NO_VIM_MAIN */ ! #endif /* PROTO */ /* * vim_main2() is needed for FEAT_MZSCHEME, but we define it always to keep --- 444,451 ---- return vim_main2(); #endif } ! #endif // NO_VIM_MAIN ! #endif // PROTO /* * vim_main2() is needed for FEAT_MZSCHEME, but we define it always to keep *************** *** 465,475 **** { char_u *rtp_copy = NULL; ! /* First add all package directories to 'runtimepath', so that their ! * autoload directories can be found. Only if not done already with a ! * :packloadall command. ! * Make a copy of 'runtimepath', so that source_runtime does not use ! * the pack directories. */ if (!did_source_packages) { rtp_copy = vim_strsave(p_rtp); --- 465,475 ---- { char_u *rtp_copy = NULL; ! // First add all package directories to 'runtimepath', so that their ! // autoload directories can be found. Only if not done already with a ! // :packloadall command. ! // Make a copy of 'runtimepath', so that source_runtime does not use ! // the pack directories. if (!did_source_packages) { rtp_copy = vim_strsave(p_rtp); *************** *** 477,483 **** } source_in_path(rtp_copy == NULL ? p_rtp : rtp_copy, ! # ifdef VMS /* Somehow VMS doesn't handle the "**". */ (char_u *)"plugin/*.vim", # else (char_u *)"plugin/**/*.vim", --- 477,483 ---- } source_in_path(rtp_copy == NULL ? p_rtp : rtp_copy, ! # ifdef VMS // Somehow VMS doesn't handle the "**". (char_u *)"plugin/*.vim", # else (char_u *)"plugin/**/*.vim", *************** *** 486,498 **** TIME_MSG("loading plugins"); vim_free(rtp_copy); ! /* Only source "start" packages if not done already with a :packloadall ! * command. */ if (!did_source_packages) load_start_packages(); TIME_MSG("loading packages"); ! # ifdef VMS /* Somehow VMS doesn't handle the "**". */ source_runtime((char_u *)"plugin/*.vim", DIP_ALL | DIP_AFTER); # else source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_AFTER); --- 486,498 ---- TIME_MSG("loading plugins"); vim_free(rtp_copy); ! // Only source "start" packages if not done already with a :packloadall ! // command. if (!did_source_packages) load_start_packages(); TIME_MSG("loading packages"); ! # ifdef VMS // Somehow VMS doesn't handle the "**". source_runtime((char_u *)"plugin/*.vim", DIP_ALL | DIP_AFTER); # else source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_AFTER); *************** *** 503,515 **** #endif #ifdef FEAT_DIFF ! /* Decide about window layout for diff mode after reading vimrc. */ if (params.diff_mode && params.window_layout == 0) { if (diffopt_horizontal()) ! params.window_layout = WIN_HOR; /* use horizontal split */ else ! params.window_layout = WIN_VER; /* use vertical split */ } #endif --- 503,515 ---- #endif #ifdef FEAT_DIFF ! // Decide about window layout for diff mode after reading vimrc. if (params.diff_mode && params.window_layout == 0) { if (diffopt_horizontal()) ! params.window_layout = WIN_HOR; // use horizontal split else ! params.window_layout = WIN_VER; // use vertical split } #endif *************** *** 542,558 **** if (gui.starting) { # if defined(UNIX) || defined(VMS) ! /* When something caused a message from a vimrc script, need to output ! * an extra newline before the shell prompt. */ if (did_emsg || msg_didout) putchar('\n'); # endif ! gui_start(NULL); /* will set full_screen to TRUE */ TIME_MSG("starting GUI"); ! /* When running "evim" or "gvim -y" we need the menus, exit if we ! * don't have them. */ if (!gui.in_use && params.evim_mode) mch_exit(1); } --- 542,558 ---- if (gui.starting) { # if defined(UNIX) || defined(VMS) ! // When something caused a message from a vimrc script, need to output ! // an extra newline before the shell prompt. if (did_emsg || msg_didout) putchar('\n'); # endif ! gui_start(NULL); // will set full_screen to TRUE TIME_MSG("starting GUI"); ! // When running "evim" or "gvim -y" we need the menus, exit if we ! // don't have them. if (!gui.in_use && params.evim_mode) mch_exit(1); } *************** *** 570,576 **** } #endif #ifdef FEAT_EVAL ! /* It's better to make v:oldfiles an empty list than NULL. */ if (get_vim_var_list(VV_OLDFILES) == NULL) set_vim_var_list(VV_OLDFILES, list_alloc()); #endif --- 570,576 ---- } #endif #ifdef FEAT_EVAL ! // It's better to make v:oldfiles an empty list than NULL. if (get_vim_var_list(VV_OLDFILES) == NULL) set_vim_var_list(VV_OLDFILES, list_alloc()); #endif *************** *** 632,638 **** #endif #ifdef FEAT_XCLIPBOARD ! /* Start using the X clipboard, unless the GUI was started. */ # ifdef FEAT_GUI if (!gui.in_use) # endif --- 632,638 ---- #endif #ifdef FEAT_XCLIPBOARD ! // Start using the X clipboard, unless the GUI was started. # ifdef FEAT_GUI if (!gui.in_use) # endif *************** *** 643,649 **** #endif #ifdef FEAT_CLIENTSERVER ! /* Prepare for being a Vim server. */ prepare_server(¶ms); #endif --- 643,649 ---- #endif #ifdef FEAT_CLIENTSERVER ! // Prepare for being a Vim server. prepare_server(¶ms); #endif *************** *** 658,665 **** read_stdin(); #if defined(UNIX) || defined(VMS) ! /* When switching screens and something caused a message from a vimrc ! * script, need to output an extra newline on exit. */ if ((did_emsg || msg_didout) && *T_TI != NUL) newline_on_exit = TRUE; #endif --- 658,665 ---- read_stdin(); #if defined(UNIX) || defined(VMS) ! // When switching screens and something caused a message from a vimrc ! // script, need to output an extra newline on exit. if ((did_emsg || msg_didout) && *T_TI != NUL) newline_on_exit = TRUE; #endif *************** *** 681,693 **** TIME_MSG("waiting for return"); } ! starttermcap(); /* start termcap if not done by wait_return() */ TIME_MSG("start termcap"); setmouse(); // may start using the mouse if (scroll_region) ! scroll_region_reset(); /* In case Rows changed */ ! scroll_start(); /* may scroll the screen to the right position */ #if defined(FEAT_TITLE) && (defined(UNIX) || defined(VMS) || defined(MACOS_X)) term_push_title(SAVE_RESTORE_BOTH); --- 681,693 ---- TIME_MSG("waiting for return"); } ! starttermcap(); // start termcap if not done by wait_return() TIME_MSG("start termcap"); setmouse(); // may start using the mouse if (scroll_region) ! scroll_region_reset(); // In case Rows changed ! scroll_start(); // may scroll the screen to the right position #if defined(FEAT_TITLE) && (defined(UNIX) || defined(VMS) || defined(MACOS_X)) term_push_title(SAVE_RESTORE_BOTH); *************** *** 704,710 **** must_redraw = CLEAR; else { ! screenclear(); /* clear screen */ TIME_MSG("clearing screen"); } --- 704,710 ---- must_redraw = CLEAR; else { ! screenclear(); // clear screen TIME_MSG("clearing screen"); } *************** *** 727,737 **** TIME_MSG("opening buffers"); #ifdef FEAT_EVAL ! /* clear v:swapcommand */ set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); #endif ! /* Ex starts at last line of the file */ if (exmode_active) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; --- 727,737 ---- TIME_MSG("opening buffers"); #ifdef FEAT_EVAL ! // clear v:swapcommand set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); #endif ! // Ex starts at last line of the file if (exmode_active) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; *************** *** 762,768 **** { win_T *wp; ! /* set options in each window for "vimdiff". */ FOR_ALL_WINDOWS(wp) diff_win_options(wp, TRUE); } --- 762,768 ---- { win_T *wp; ! // set options in each window for "vimdiff". FOR_ALL_WINDOWS(wp) diff_win_options(wp, TRUE); } *************** *** 785,804 **** do_cmdline_cmd(IObuff); TIME_MSG("jumping to tag"); ! /* If the user doesn't want to edit the file then we quit here. */ if (swap_exists_did_quit) getout(1); } ! /* Execute any "+", "-c" and "-S" arguments. */ if (params.n_commands > 0) exe_commands(¶ms); ! /* Must come before the may_req_ calls. */ starting = 0; #if defined(FEAT_TERMRESPONSE) ! /* Must be done before redrawing, puts a few characters on the screen. */ may_req_ambiguous_char_width(); #endif --- 785,804 ---- do_cmdline_cmd(IObuff); TIME_MSG("jumping to tag"); ! // If the user doesn't want to edit the file then we quit here. if (swap_exists_did_quit) getout(1); } ! // Execute any "+", "-c" and "-S" arguments. if (params.n_commands > 0) exe_commands(¶ms); ! // Must come before the may_req_ calls. starting = 0; #if defined(FEAT_TERMRESPONSE) ! // Must be done before redrawing, puts a few characters on the screen. may_req_ambiguous_char_width(); #endif *************** *** 806,823 **** redraw_all_later(NOT_VALID); no_wait_return = FALSE; ! /* 'autochdir' has been postponed */ DO_AUTOCHDIR; #ifdef FEAT_TERMRESPONSE ! /* Requesting the termresponse is postponed until here, so that a "-c q" ! * argument doesn't make it appear in the shell Vim was started from. */ may_req_termresponse(); may_req_bg_color(); #endif ! /* start in insert mode */ if (p_im) need_start_insertmode = TRUE; --- 806,823 ---- redraw_all_later(NOT_VALID); no_wait_return = FALSE; ! // 'autochdir' has been postponed DO_AUTOCHDIR; #ifdef FEAT_TERMRESPONSE ! // Requesting the termresponse is postponed until here, so that a "-c q" ! // argument doesn't make it appear in the shell Vim was started from. may_req_termresponse(); may_req_bg_color(); #endif ! // start in insert mode if (p_im) need_start_insertmode = TRUE; *************** *** 828,837 **** TIME_MSG("VimEnter autocommands"); #if defined(FEAT_EVAL) && defined(FEAT_CLIPBOARD) ! /* Adjust default register name for "unnamed" in 'clipboard'. Can only be ! * done after the clipboard is available and all initial commands that may ! * modify the 'clipboard' setting have run; i.e. just before entering the ! * main loop. */ { int default_regname = 0; --- 828,837 ---- TIME_MSG("VimEnter autocommands"); #if defined(FEAT_EVAL) && defined(FEAT_CLIPBOARD) ! // Adjust default register name for "unnamed" in 'clipboard'. Can only be ! // done after the clipboard is available and all initial commands that may ! // modify the 'clipboard' setting have run; i.e. just before entering the ! // main loop. { int default_regname = 0; *************** *** 841,848 **** #endif #if defined(FEAT_DIFF) ! /* When a startup script or session file setup for diff'ing and ! * scrollbind, sync the scrollbind now. */ if (curwin->w_p_diff && curwin->w_p_scb) { update_topline(); --- 841,848 ---- #endif #if defined(FEAT_DIFF) ! // When a startup script or session file setup for diff'ing and ! // scrollbind, sync the scrollbind now. if (curwin->w_p_diff && curwin->w_p_scb) { update_topline(); *************** *** 855,866 **** # ifdef VIMDLL if (!gui.in_use) # endif ! mch_set_winsize_now(); /* Allow winsize changes from now on */ #endif #if defined(FEAT_GUI) ! /* When tab pages were created, may need to update the tab pages line and ! * scrollbars. This is skipped while creating them. */ if (first_tabpage->tp_next != NULL) { out_flush(); --- 855,866 ---- # ifdef VIMDLL if (!gui.in_use) # endif ! mch_set_winsize_now(); // Allow winsize changes from now on #endif #if defined(FEAT_GUI) ! // When tab pages were created, may need to update the tab pages line and ! // scrollbars. This is skipped while creating them. if (first_tabpage->tp_next != NULL) { out_flush(); *************** *** 870,877 **** need_mouse_correct = TRUE; #endif ! /* If ":startinsert" command used, stuff a dummy command to be able to ! * call normal_cmd(), which will then start Insert mode. */ if (restart_edit != 0) stuffcharReadbuff(K_NOP); --- 870,877 ---- need_mouse_correct = TRUE; #endif ! // If ":startinsert" command used, stuff a dummy command to be able to ! // call normal_cmd(), which will then start Insert mode. if (restart_edit != 0) stuffcharReadbuff(K_NOP); *************** *** 888,894 **** } # endif # endif ! /* Tell the client that it can start sending commands. */ netbeans_open(netbeansArg + 3, TRUE); } #endif --- 888,894 ---- } # endif # endif ! // Tell the client that it can start sending commands. netbeans_open(netbeansArg + 3, TRUE); } #endif *************** *** 900,906 **** */ main_loop(FALSE, FALSE); ! #endif /* NO_VIM_MAIN */ return 0; } --- 900,906 ---- */ main_loop(FALSE, FALSE); ! #endif // NO_VIM_MAIN return 0; } *************** *** 913,928 **** { cmdline_init(); ! (void)mb_init(); /* init mb_bytelen_tab[] to ones */ #ifdef FEAT_EVAL ! eval_init(); /* init global variables */ #endif #ifdef __QNXNTO__ ! qnx_init(); /* PhAttach() for clipboard, (and gui) */ #endif ! /* Init the table of Normal mode commands. */ init_normal_cmds(); /* --- 913,928 ---- { cmdline_init(); ! (void)mb_init(); // init mb_bytelen_tab[] to ones #ifdef FEAT_EVAL ! eval_init(); // init global variables #endif #ifdef __QNXNTO__ ! qnx_init(); // PhAttach() for clipboard, (and gui) #endif ! // Init the table of Normal mode commands. init_normal_cmds(); /* *************** *** 935,942 **** TIME_MSG("Allocated generic buffers"); #ifdef NBDEBUG ! /* Wait a moment for debugging NetBeans. Must be after allocating ! * NameBuff. */ nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); TIME_MSG("NetBeans debug wait"); --- 935,942 ---- TIME_MSG("Allocated generic buffers"); #ifdef NBDEBUG ! // Wait a moment for debugging NetBeans. Must be after allocating ! // NameBuff. nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); TIME_MSG("NetBeans debug wait"); *************** *** 953,959 **** #endif #ifdef FEAT_GUI ! gui.dofork = TRUE; /* default is to use fork() */ #endif /* --- 953,959 ---- #endif #ifdef FEAT_GUI ! gui.dofork = TRUE; // default is to use fork() #endif /* *************** *** 966,978 **** early_arg_scan(paramp); #if defined(FEAT_GUI) ! /* Prepare for possibly starting GUI sometime */ gui_prepare(¶mp->argc, paramp->argv); TIME_MSG("GUI prepared"); #endif #ifdef FEAT_CLIPBOARD ! clip_init(FALSE); /* Initialise clipboard stuff */ TIME_MSG("clipboard setup"); #endif --- 966,978 ---- early_arg_scan(paramp); #if defined(FEAT_GUI) ! // Prepare for possibly starting GUI sometime gui_prepare(¶mp->argc, paramp->argv); TIME_MSG("GUI prepared"); #endif #ifdef FEAT_CLIPBOARD ! clip_init(FALSE); // Initialise clipboard stuff TIME_MSG("clipboard setup"); #endif *************** *** 992,1000 **** if (win_alloc_first() == FAIL) mch_exit(0); ! init_yank(); /* init yank buffers */ ! alist_init(&global_alist); /* Init the argument list to empty. */ global_alist.id = 0; /* --- 992,1000 ---- if (win_alloc_first() == FAIL) mch_exit(0); ! init_yank(); // init yank buffers ! alist_init(&global_alist); // Init the argument list to empty. global_alist.id = 0; /* *************** *** 1004,1010 **** * msg_outtrans_len_attr(). * First find out the home directory, needed to expand "~" in options. */ ! init_homedir(); /* find real value of $HOME */ set_init_1(paramp->clean); TIME_MSG("inits 1"); --- 1004,1010 ---- * msg_outtrans_len_attr(). * First find out the home directory, needed to expand "~" in options. */ ! init_homedir(); // find real value of $HOME set_init_1(paramp->clean); TIME_MSG("inits 1"); *************** *** 1156,1163 **** */ void main_loop( ! int cmdwin, /* TRUE when working in the command-line window */ ! int noexmode) /* TRUE when return on entering Ex mode */ { oparg_T oa; // operator arguments oparg_T *prev_oap; // operator arguments --- 1156,1163 ---- */ void main_loop( ! int cmdwin, // TRUE when working in the command-line window ! int noexmode) // TRUE when return on entering Ex mode { oparg_T oa; // operator arguments oparg_T *prev_oap; // operator arguments *************** *** 1173,1182 **** current_oap = &oa; #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) ! /* Setup to catch a terminating error from the X server. Just ignore ! * it, restore the state and continue. This might not always work ! * properly, but at least we don't exit unexpectedly when the X server ! * exits while Vim is running in a console. */ if (!cmdwin && !noexmode && SETJMP(x_jump_env)) { State = NORMAL; --- 1173,1182 ---- current_oap = &oa; #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) ! // Setup to catch a terminating error from the X server. Just ignore ! // it, restore the state and continue. This might not always work ! // properly, but at least we don't exit unexpectedly when the X server ! // exits while Vim is running in a console. if (!cmdwin && !noexmode && SETJMP(x_jump_env)) { State = NORMAL; *************** *** 1213,1248 **** did_check_timestamps = FALSE; if (need_check_timestamps) check_timestamps(FALSE); ! if (need_wait_return) /* if wait_return still needed ... */ ! wait_return(FALSE); /* ... call it now */ if (need_start_insertmode && goto_im() && !VIsual_active) { need_start_insertmode = FALSE; ! stuffReadbuff((char_u *)"i"); /* start insert mode next */ ! /* skip the fileinfo message now, because it would be shown ! * after insert mode finishes! */ need_fileinfo = FALSE; } } ! /* Reset "got_int" now that we got back to the main loop. Except when ! * inside a ":g/pat/cmd" command, then the "got_int" needs to abort ! * the ":g" command. ! * For ":g/pat/vi" we reset "got_int" when used once. When used ! * a second time we go back to Ex mode and abort the ":g" command. */ if (got_int) { if (noexmode && global_busy && !exmode_active && previous_got_int) { ! /* Typed two CTRL-C in a row: go back to ex mode as if "Q" was ! * used and keep "got_int" set, so that it aborts ":g". */ exmode_active = EXMODE_NORMAL; State = NORMAL; } else if (!global_busy || !exmode_active) { if (!quit_more) ! (void)vgetc(); /* flush all buffers */ got_int = FALSE; } previous_got_int = TRUE; --- 1213,1248 ---- did_check_timestamps = FALSE; if (need_check_timestamps) check_timestamps(FALSE); ! if (need_wait_return) // if wait_return still needed ... ! wait_return(FALSE); // ... call it now if (need_start_insertmode && goto_im() && !VIsual_active) { need_start_insertmode = FALSE; ! stuffReadbuff((char_u *)"i"); // start insert mode next ! // skip the fileinfo message now, because it would be shown ! // after insert mode finishes! need_fileinfo = FALSE; } } ! // Reset "got_int" now that we got back to the main loop. Except when ! // inside a ":g/pat/cmd" command, then the "got_int" needs to abort ! // the ":g" command. ! // For ":g/pat/vi" we reset "got_int" when used once. When used ! // a second time we go back to Ex mode and abort the ":g" command. if (got_int) { if (noexmode && global_busy && !exmode_active && previous_got_int) { ! // Typed two CTRL-C in a row: go back to ex mode as if "Q" was ! // used and keep "got_int" set, so that it aborts ":g". exmode_active = EXMODE_NORMAL; State = NORMAL; } else if (!global_busy || !exmode_active) { if (!quit_more) ! (void)vgetc(); // flush all buffers got_int = FALSE; } previous_got_int = TRUE; *************** *** 1280,1286 **** conceal_update_lines = FALSE; #endif ! /* Trigger CursorMoved if the cursor moved. */ if (!finish_op && ( has_cursormoved() #ifdef FEAT_PROP_POPUP --- 1280,1286 ---- conceal_update_lines = FALSE; #endif ! // Trigger CursorMoved if the cursor moved. if (!finish_op && ( has_cursormoved() #ifdef FEAT_PROP_POPUP *************** *** 1327,1333 **** } #endif ! /* Trigger TextChanged if b:changedtick differs. */ if (!finish_op && has_textchanged() && curbuf->b_last_changedtick != CHANGEDTICK(curbuf)) { --- 1327,1333 ---- } #endif ! // Trigger TextChanged if b:changedtick differs. if (!finish_op && has_textchanged() && curbuf->b_last_changedtick != CHANGEDTICK(curbuf)) { *************** *** 1349,1356 **** curtab->tp_diff_update = FALSE; } ! /* Scroll-binding for diff mode may have been postponed until ! * here. Avoids doing it for every change. */ if (diff_need_scrollbind) { check_scrollbind((linenr_T)0, 0L); --- 1349,1356 ---- curtab->tp_diff_update = FALSE; } ! // Scroll-binding for diff mode may have been postponed until ! // here. Avoids doing it for every change. if (diff_need_scrollbind) { check_scrollbind((linenr_T)0, 0L); *************** *** 1358,1364 **** } #endif #if defined(FEAT_FOLDING) ! /* Include a closed fold completely in the Visual area. */ foldAdjustVisual(); #endif #ifdef FEAT_FOLDING --- 1358,1364 ---- } #endif #if defined(FEAT_FOLDING) ! // Include a closed fold completely in the Visual area. foldAdjustVisual(); #endif #ifdef FEAT_FOLDING *************** *** 1410,1416 **** #ifdef FEAT_VIMINFO curbuf->b_last_used = vim_time(); #endif ! /* display message after redraw */ if (keep_msg != NULL) { char_u *p = vim_strsave(keep_msg); --- 1410,1416 ---- #ifdef FEAT_VIMINFO curbuf->b_last_used = vim_time(); #endif ! // display message after redraw if (keep_msg != NULL) { char_u *p = vim_strsave(keep_msg); *************** *** 1427,1442 **** vim_free(p); } } ! if (need_fileinfo) /* show file info after redraw */ { fileinfo(FALSE, TRUE, FALSE); need_fileinfo = FALSE; } ! emsg_on_display = FALSE; /* can delete error message now */ did_emsg = FALSE; ! msg_didany = FALSE; /* reset lines_left in msg_start() */ ! may_clear_sb_text(); /* clear scroll-back text on next msg */ showruler(FALSE); setcursor(); --- 1427,1442 ---- vim_free(p); } } ! if (need_fileinfo) // show file info after redraw { fileinfo(FALSE, TRUE, FALSE); need_fileinfo = FALSE; } ! emsg_on_display = FALSE; // can delete error message now did_emsg = FALSE; ! msg_didany = FALSE; // reset lines_left in msg_start() ! may_clear_sb_text(); // clear scroll-back text on next msg showruler(FALSE); setcursor(); *************** *** 1445,1452 **** do_redraw = FALSE; #ifdef STARTUPTIME ! /* Now that we have drawn the first screen all the startup stuff ! * has been done, close any file for startup messages. */ if (time_fd != NULL) { TIME_MSG("first screen update"); --- 1445,1452 ---- do_redraw = FALSE; #ifdef STARTUPTIME ! // Now that we have drawn the first screen all the startup stuff ! // has been done, close any file for startup messages. if (time_fd != NULL) { TIME_MSG("first screen update"); *************** *** 1483,1489 **** */ if (exmode_active) { ! if (noexmode) /* End of ":global/path/visual" commands */ goto theend; do_exmode(exmode_active == EXMODE_VIM); } --- 1483,1489 ---- */ if (exmode_active) { ! if (noexmode) // End of ":global/path/visual" commands goto theend; do_exmode(exmode_active == EXMODE_VIM); } *************** *** 1495,1503 **** && !VIsual_active && !skip_term_loop) { ! /* If terminal_loop() returns OK we got a key that is handled ! * in Normal model. With FAIL we first need to position the ! * cursor and the screen needs to be redrawn. */ if (terminal_loop(TRUE) == OK) normal_cmd(&oa, TRUE); } --- 1495,1503 ---- && !VIsual_active && !skip_term_loop) { ! // If terminal_loop() returns OK we got a key that is handled ! // in Normal model. With FAIL we first need to position the ! // cursor and the screen needs to be redrawn. if (terminal_loop(TRUE) == OK) normal_cmd(&oa, TRUE); } *************** *** 1525,1540 **** getout_preserve_modified(int exitval) { # if defined(SIGHUP) && defined(SIG_IGN) ! /* Ignore SIGHUP, because a dropped connection causes a read error, which ! * makes Vim exit and then handling SIGHUP causes various reentrance ! * problems. */ signal(SIGHUP, SIG_IGN); # endif ! ml_close_notmod(); /* close all not-modified buffers */ ! ml_sync_all(FALSE, FALSE); /* preserve all swap files */ ! ml_close_all(FALSE); /* close all memfiles, without deleting */ ! getout(exitval); /* exit Vim properly */ } #endif --- 1525,1540 ---- getout_preserve_modified(int exitval) { # if defined(SIGHUP) && defined(SIG_IGN) ! // Ignore SIGHUP, because a dropped connection causes a read error, which ! // makes Vim exit and then handling SIGHUP causes various reentrance ! // problems. signal(SIGHUP, SIG_IGN); # endif ! ml_close_notmod(); // close all not-modified buffers ! ml_sync_all(FALSE, FALSE); // preserve all swap files ! ml_close_all(FALSE); // close all memfiles, without deleting ! getout(exitval); // exit Vim properly } #endif *************** *** 1550,1569 **** ch_log(NULL, "Exiting..."); #endif ! /* When running in Ex mode an error causes us to exit with a non-zero exit ! * code. POSIX requires this, although it's not 100% clear from the ! * standard. */ if (exmode_active) exitval += ex_exitval; ! /* Position the cursor on the last screen line, below all the text */ #ifdef FEAT_GUI if (!gui.in_use) #endif windgoto((int)Rows - 1, 0); #if defined(FEAT_EVAL) || defined(FEAT_SYN_HL) ! /* Optionally print hashtable efficiency. */ hash_debug_results(); #endif --- 1550,1569 ---- ch_log(NULL, "Exiting..."); #endif ! // When running in Ex mode an error causes us to exit with a non-zero exit ! // code. POSIX requires this, although it's not 100% clear from the ! // standard. if (exmode_active) exitval += ex_exitval; ! // Position the cursor on the last screen line, below all the text #ifdef FEAT_GUI if (!gui.in_use) #endif windgoto((int)Rows - 1, 0); #if defined(FEAT_EVAL) || defined(FEAT_SYN_HL) ! // Optionally print hashtable efficiency. hash_debug_results(); #endif *************** *** 1578,1591 **** buf_T *buf; win_T *wp; ! /* Trigger BufWinLeave for all windows, but only once per buffer. */ for (tp = first_tabpage; tp != NULL; tp = next_tp) { next_tp = tp->tp_next; FOR_ALL_WINDOWS_IN_TAB(tp, wp) { if (wp->w_buffer == NULL) ! /* Autocmd must have close the buffer already, skip. */ continue; buf = wp->w_buffer; if (CHANGEDTICK(buf) != -1) --- 1578,1591 ---- buf_T *buf; win_T *wp; ! // Trigger BufWinLeave for all windows, but only once per buffer. for (tp = first_tabpage; tp != NULL; tp = next_tp) { next_tp = tp->tp_next; FOR_ALL_WINDOWS_IN_TAB(tp, wp) { if (wp->w_buffer == NULL) ! // Autocmd must have close the buffer already, skip. continue; buf = wp->w_buffer; if (CHANGEDTICK(buf) != -1) *************** *** 1596,1611 **** apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, FALSE, buf); if (bufref_valid(&bufref)) ! CHANGEDTICK(buf) = -1; /* note we did it already */ ! /* start all over, autocommands may mess up the lists */ next_tp = first_tabpage; break; } } } ! /* Trigger BufUnload for buffers that are loaded */ FOR_ALL_BUFFERS(buf) if (buf->b_ml.ml_mfp != NULL) { --- 1596,1611 ---- apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, FALSE, buf); if (bufref_valid(&bufref)) ! CHANGEDTICK(buf) = -1; // note we did it already ! // start all over, autocommands may mess up the lists next_tp = first_tabpage; break; } } } ! // Trigger BufUnload for buffers that are loaded FOR_ALL_BUFFERS(buf) if (buf->b_ml.ml_mfp != NULL) { *************** *** 1615,1621 **** apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, FALSE, buf); if (!bufref_valid(&bufref)) ! /* autocmd deleted the buffer */ break; } apply_autocmds(EVENT_VIMLEAVEPRE, NULL, NULL, FALSE, curbuf); --- 1615,1621 ---- apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, FALSE, buf); if (!bufref_valid(&bufref)) ! // autocmd deleted the buffer break; } apply_autocmds(EVENT_VIMLEAVEPRE, NULL, NULL, FALSE, curbuf); *************** *** 1623,1629 **** #ifdef FEAT_VIMINFO if (*p_viminfo != NUL) ! /* Write out the registers, history, marks etc, to the viminfo file */ write_viminfo(NULL, FALSE); #endif --- 1623,1629 ---- #ifdef FEAT_VIMINFO if (*p_viminfo != NUL) ! // Write out the registers, history, marks etc, to the viminfo file write_viminfo(NULL, FALSE); #endif *************** *** 1652,1663 **** #endif ) { ! /* give the user a chance to read the (error) message */ no_wait_return = FALSE; wait_return(FALSE); } ! /* Position the cursor again, the autocommands may have moved it */ #ifdef FEAT_GUI if (!gui.in_use) #endif --- 1652,1663 ---- #endif ) { ! // give the user a chance to read the (error) message no_wait_return = FALSE; wait_return(FALSE); } ! // Position the cursor again, the autocommands may have moved it #ifdef FEAT_GUI if (!gui.in_use) #endif *************** *** 1717,1734 **** setlocale(LC_ALL, ""); # ifdef FEAT_GUI_GTK ! /* Tell Gtk not to change our locale settings. */ gtk_disable_setlocale(); # endif # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) ! /* Make sure strtod() uses a decimal point, not a comma. */ setlocale(LC_NUMERIC, "C"); # endif # ifdef MSWIN ! /* Apparently MS-Windows printf() may cause a crash when we give it 8-bit ! * text while it's expecting text in the current locale. This call avoids ! * that. */ setlocale(LC_CTYPE, "C"); # endif --- 1717,1734 ---- setlocale(LC_ALL, ""); # ifdef FEAT_GUI_GTK ! // Tell Gtk not to change our locale settings. gtk_disable_setlocale(); # endif # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) ! // Make sure strtod() uses a decimal point, not a comma. setlocale(LC_NUMERIC, "C"); # endif # ifdef MSWIN ! // Apparently MS-Windows printf() may cause a crash when we give it 8-bit ! // text while it's expecting text in the current locale. This call avoids ! // that. setlocale(LC_CTYPE, "C"); # endif *************** *** 1738,1748 **** char_u *p; # ifdef DYNAMIC_GETTEXT ! /* Initialize the gettext library */ dyn_libintl_init(); # endif ! /* expand_env() doesn't work yet, because g_chartab[] is not ! * initialized yet, call vim_getenv() directly */ p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); if (p != NULL && *p != NUL) { --- 1738,1748 ---- char_u *p; # ifdef DYNAMIC_GETTEXT ! // Initialize the gettext library dyn_libintl_init(); # endif ! // expand_env() doesn't work yet, because g_chartab[] is not ! // initialized yet, call vim_getenv() directly p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); if (p != NULL && *p != NUL) { *************** *** 1802,1808 **** parmp->serverArg = TRUE; # ifdef FEAT_GUI if (strstr(argv[i], "-wait") != 0) ! /* don't fork() when starting the GUI to edit files ourself */ gui.dofork = FALSE; # endif } --- 1802,1808 ---- parmp->serverArg = TRUE; # ifdef FEAT_GUI if (strstr(argv[i], "-wait") != 0) ! // don't fork() when starting the GUI to edit files ourself gui.dofork = FALSE; # endif } *************** *** 1857,1865 **** */ static int get_number_arg( ! char_u *p, /* pointer to argument */ ! int *idx, /* index in argument, is incremented */ ! int def) /* default value */ { if (vim_isdigit(p[*idx])) { --- 1857,1865 ---- */ static int get_number_arg( ! char_u *p, // pointer to argument ! int *idx, // index in argument, is incremented ! int def) // default value { if (vim_isdigit(p[*idx])) { *************** *** 1888,1903 **** initstr = gettail((char_u *)parmp->argv[0]); #ifdef FEAT_GUI_MAC ! /* An issue has been seen when launching Vim in such a way that ! * $PWD/$ARGV[0] or $ARGV[0] is not the absolute path to the ! * executable or a symbolic link of it. Until this issue is resolved ! * we prohibit the GUI from being used. ! */ if (STRCMP(initstr, parmp->argv[0]) == 0) disallow_gui = TRUE; ! /* TODO: On MacOS X default to gui if argv[0] ends in: ! * /Vim.app/Contents/MacOS/Vim */ #endif #ifdef FEAT_EVAL --- 1888,1902 ---- initstr = gettail((char_u *)parmp->argv[0]); #ifdef FEAT_GUI_MAC ! // An issue has been seen when launching Vim in such a way that ! // $PWD/$ARGV[0] or $ARGV[0] is not the absolute path to the ! // executable or a symbolic link of it. Until this issue is resolved ! // we prohibit the GUI from being used. if (STRCMP(initstr, parmp->argv[0]) == 0) disallow_gui = TRUE; ! // TODO: On MacOS X default to gui if argv[0] ends in: ! // /Vim.app/Contents/MacOS/Vim #endif #ifdef FEAT_EVAL *************** *** 1911,1917 **** ++initstr; } ! /* Use evim mode for "evim" and "egvim", not for "editor". */ if (TOLOWER_ASC(initstr[0]) == 'e' && (TOLOWER_ASC(initstr[1]) == 'v' || TOLOWER_ASC(initstr[1]) == 'g')) --- 1910,1916 ---- ++initstr; } ! // Use evim mode for "evim" and "egvim", not for "editor". if (TOLOWER_ASC(initstr[0]) == 'e' && (TOLOWER_ASC(initstr[1]) == 'v' || TOLOWER_ASC(initstr[1]) == 'g')) *************** *** 1923,1929 **** ++initstr; } ! /* "gvim" starts the GUI. Also accept "Gvim" for MS-Windows. */ if (TOLOWER_ASC(initstr[0]) == 'g') { main_start_gui(); --- 1922,1928 ---- ++initstr; } ! // "gvim" starts the GUI. Also accept "Gvim" for MS-Windows. if (TOLOWER_ASC(initstr[0]) == 'g') { main_start_gui(); *************** *** 1944,1950 **** { readonlymode = TRUE; curbuf->b_p_ro = TRUE; ! p_uc = 10000; /* don't update very often */ initstr += 4; } else if (STRNICMP(initstr, "vim", 3) == 0) --- 1943,1949 ---- { readonlymode = TRUE; curbuf->b_p_ro = TRUE; ! p_uc = 10000; // don't update very often initstr += 4; } else if (STRNICMP(initstr, "vim", 3) == 0) *************** *** 1982,1997 **** { int argc = parmp->argc; char **argv = parmp->argv; ! int argv_idx; /* index in argv[n][] */ ! int had_minmin = FALSE; /* found "--" argument */ ! int want_argument; /* option argument with argument */ int c; char_u *p = NULL; long n; --argc; ++argv; ! argv_idx = 1; /* active option letter is argv[0][argv_idx] */ while (argc > 0) { /* --- 1981,1996 ---- { int argc = parmp->argc; char **argv = parmp->argv; ! int argv_idx; // index in argv[n][] ! int had_minmin = FALSE; // found "--" argument ! int want_argument; // option argument with argument int c; char_u *p = NULL; long n; --argc; ++argv; ! argv_idx = 1; // active option letter is argv[0][argv_idx] while (argc > 0) { /* *************** *** 2001,2007 **** { if (parmp->n_commands >= MAX_ARG_CMDS) mainerr(ME_EXTRA_CMD, NULL); ! argv_idx = -1; /* skip to next argument */ if (argv[0][1] == NUL) parmp->commands[parmp->n_commands++] = (char_u *)"$"; else --- 2000,2006 ---- { if (parmp->n_commands >= MAX_ARG_CMDS) mainerr(ME_EXTRA_CMD, NULL); ! argv_idx = -1; // skip to next argument if (argv[0][1] == NUL) parmp->commands[parmp->n_commands++] = (char_u *)"$"; else *************** *** 2030,2037 **** #endif switch (c) { ! case NUL: /* "vim -" read from stdin */ ! /* "ex -" silent mode */ if (exmode_active) silent_mode = TRUE; else --- 2029,2036 ---- #endif switch (c) { ! case NUL: // "vim -" read from stdin ! // "ex -" silent mode if (exmode_active) silent_mode = TRUE; else *************** *** 2039,2065 **** if (parmp->edit_type != EDIT_NONE) mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); parmp->edit_type = EDIT_STDIN; ! read_cmd_fd = 2; /* read from stderr instead of stdin */ } ! argv_idx = -1; /* skip to next argument */ break; ! case '-': /* "--" don't take any more option arguments */ ! /* "--help" give help message */ ! /* "--version" give version message */ ! /* "--clean" clean context */ ! /* "--literal" take files literally */ ! /* "--nofork" don't fork */ ! /* "--not-a-term" don't warn for not a term */ ! /* "--ttyfail" exit if not a term */ ! /* "--noplugin[s]" skip plugins */ ! /* "--cmd " execute cmd before vimrc */ if (STRICMP(argv[0] + argv_idx, "help") == 0) usage(); else if (STRICMP(argv[0] + argv_idx, "version") == 0) { ! Columns = 80; /* need to init Columns */ ! info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ list_version(); msg_putchar('\n'); msg_didout = FALSE; --- 2038,2064 ---- if (parmp->edit_type != EDIT_NONE) mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); parmp->edit_type = EDIT_STDIN; ! read_cmd_fd = 2; // read from stderr instead of stdin } ! argv_idx = -1; // skip to next argument break; ! case '-': // "--" don't take any more option arguments ! // "--help" give help message ! // "--version" give version message ! // "--clean" clean context ! // "--literal" take files literally ! // "--nofork" don't fork ! // "--not-a-term" don't warn for not a term ! // "--ttyfail" exit if not a term ! // "--noplugin[s]" skip plugins ! // "--cmd " execute cmd before vimrc if (STRICMP(argv[0] + argv_idx, "help") == 0) usage(); else if (STRICMP(argv[0] + argv_idx, "version") == 0) { ! Columns = 80; // need to init Columns ! info_message = TRUE; // use mch_msg(), not mch_errmsg() list_version(); msg_putchar('\n'); msg_didout = FALSE; *************** *** 2083,2089 **** else if (STRNICMP(argv[0] + argv_idx, "nofork", 6) == 0) { #ifdef FEAT_GUI ! gui.dofork = FALSE; /* don't fork() when starting GUI */ #endif } else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) --- 2082,2088 ---- else if (STRNICMP(argv[0] + argv_idx, "nofork", 6) == 0) { #ifdef FEAT_GUI ! gui.dofork = FALSE; // don't fork() when starting GUI #endif } else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) *************** *** 2104,2114 **** } #ifdef FEAT_CLIENTSERVER else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0) ! ; /* already processed -- no arg */ else if (STRNICMP(argv[0] + argv_idx, "servername", 10) == 0 || STRNICMP(argv[0] + argv_idx, "serversend", 10) == 0) { ! /* already processed -- snatch the following arg */ if (argc > 1) { --argc; --- 2103,2113 ---- } #ifdef FEAT_CLIENTSERVER else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0) ! ; // already processed -- no arg else if (STRNICMP(argv[0] + argv_idx, "servername", 10) == 0 || STRNICMP(argv[0] + argv_idx, "serversend", 10) == 0) { ! // already processed -- snatch the following arg if (argc > 1) { --argc; *************** *** 2123,2129 **** else if (STRNICMP(argv[0] + argv_idx, "windowid", 8) == 0) # endif { ! /* already processed -- snatch the following arg */ if (argc > 1) { --argc; --- 2122,2128 ---- else if (STRNICMP(argv[0] + argv_idx, "windowid", 8) == 0) # endif { ! // already processed -- snatch the following arg if (argc > 1) { --argc; *************** *** 2134,2140 **** #ifdef FEAT_GUI_GTK else if (STRNICMP(argv[0] + argv_idx, "echo-wid", 8) == 0) { ! /* already processed, skip */ } #endif else --- 2133,2139 ---- #ifdef FEAT_GUI_GTK else if (STRNICMP(argv[0] + argv_idx, "echo-wid", 8) == 0) { ! // already processed, skip } #endif else *************** *** 2144,2153 **** had_minmin = TRUE; } if (!want_argument) ! argv_idx = -1; /* skip to next argument */ break; ! case 'A': /* "-A" start in Arabic mode */ #ifdef FEAT_ARABIC set_option_value((char_u *)"arabic", 1L, NULL, 0); #else --- 2143,2152 ---- had_minmin = TRUE; } if (!want_argument) ! argv_idx = -1; // skip to next argument break; ! case 'A': // "-A" start in Arabic mode #ifdef FEAT_ARABIC set_option_value((char_u *)"arabic", 1L, NULL, 0); #else *************** *** 2156,2208 **** #endif break; ! case 'b': /* "-b" binary mode */ ! /* Needs to be effective before expanding file names, because ! * for Win32 this makes us edit a shortcut file itself, ! * instead of the file it links to. */ set_options_bin(curbuf->b_p_bin, 1, 0); ! curbuf->b_p_bin = 1; /* binary file I/O */ break; ! case 'C': /* "-C" Compatible */ change_compatible(TRUE); has_dash_c_arg = TRUE; break; ! case 'e': /* "-e" Ex mode */ exmode_active = EXMODE_NORMAL; break; ! case 'E': /* "-E" Improved Ex mode */ exmode_active = EXMODE_VIM; break; ! case 'f': /* "-f" GUI: run in foreground. Amiga: open ! window directly, not with newcli */ #ifdef FEAT_GUI ! gui.dofork = FALSE; /* don't fork() when starting GUI */ #endif break; ! case 'g': /* "-g" start GUI */ main_start_gui(); break; ! case 'F': /* "-F" was for Farsi mode */ mch_errmsg(_(e_nofarsi)); mch_exit(2); break; ! case '?': /* "-?" give help message (for MS-Windows) */ ! case 'h': /* "-h" give help message */ #ifdef FEAT_GUI_GNOME ! /* Tell usage() to exit for "gvim". */ gui.starting = FALSE; #endif usage(); break; ! case 'H': /* "-H" start in Hebrew mode: rl + hkmap set */ #ifdef FEAT_RIGHTLEFT p_hkmap = TRUE; set_option_value((char_u *)"rl", 1L, NULL, 0); --- 2155,2207 ---- #endif break; ! case 'b': // "-b" binary mode ! // Needs to be effective before expanding file names, because ! // for Win32 this makes us edit a shortcut file itself, ! // instead of the file it links to. set_options_bin(curbuf->b_p_bin, 1, 0); ! curbuf->b_p_bin = 1; // binary file I/O break; ! case 'C': // "-C" Compatible change_compatible(TRUE); has_dash_c_arg = TRUE; break; ! case 'e': // "-e" Ex mode exmode_active = EXMODE_NORMAL; break; ! case 'E': // "-E" Improved Ex mode exmode_active = EXMODE_VIM; break; ! case 'f': // "-f" GUI: run in foreground. Amiga: open ! // window directly, not with newcli #ifdef FEAT_GUI ! gui.dofork = FALSE; // don't fork() when starting GUI #endif break; ! case 'g': // "-g" start GUI main_start_gui(); break; ! case 'F': // "-F" was for Farsi mode mch_errmsg(_(e_nofarsi)); mch_exit(2); break; ! case '?': // "-?" give help message (for MS-Windows) ! case 'h': // "-h" give help message #ifdef FEAT_GUI_GNOME ! // Tell usage() to exit for "gvim". gui.starting = FALSE; #endif usage(); break; ! case 'H': // "-H" start in Hebrew mode: rl + hkmap set #ifdef FEAT_RIGHTLEFT p_hkmap = TRUE; set_option_value((char_u *)"rl", 1L, NULL, 0); *************** *** 2212,2343 **** #endif break; ! case 'l': /* "-l" lisp mode, 'lisp' and 'showmatch' on */ #ifdef FEAT_LISP set_option_value((char_u *)"lisp", 1L, NULL, 0); p_sm = TRUE; #endif break; ! case 'M': /* "-M" no changes or writing of files */ reset_modifiable(); ! /* FALLTHROUGH */ ! case 'm': /* "-m" no writing of files */ p_write = FALSE; break; ! case 'y': /* "-y" easy mode */ #ifdef FEAT_GUI ! gui.starting = TRUE; /* start GUI a bit later */ #endif parmp->evim_mode = TRUE; break; ! case 'N': /* "-N" Nocompatible */ change_compatible(FALSE); break; ! case 'n': /* "-n" no swap file */ #ifdef FEAT_NETBEANS_INTG ! /* checking for "-nb", netbeans parameters */ if (argv[0][argv_idx] == 'b') { netbeansArg = argv[0]; ! argv_idx = -1; /* skip to next argument */ } else #endif parmp->no_swap_file = TRUE; break; ! case 'p': /* "-p[N]" open N tab pages */ #ifdef TARGET_API_MAC_OSX ! /* For some reason on MacOS X, an argument like: ! -psn_0_10223617 is passed in when invoke from Finder ! or with the 'open' command */ if (argv[0][argv_idx] == 's') { ! argv_idx = -1; /* bypass full -psn */ main_start_gui(); break; } #endif ! /* default is 0: open window for each file */ parmp->window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0); parmp->window_layout = WIN_TABS; break; ! case 'o': /* "-o[N]" open N horizontal split windows */ ! /* default is 0: open window for each file */ parmp->window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0); parmp->window_layout = WIN_HOR; break; ! case 'O': /* "-O[N]" open N vertical split windows */ ! /* default is 0: open window for each file */ parmp->window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0); parmp->window_layout = WIN_VER; break; #ifdef FEAT_QUICKFIX ! case 'q': /* "-q" QuickFix mode */ if (parmp->edit_type != EDIT_NONE) mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); parmp->edit_type = EDIT_QF; ! if (argv[0][argv_idx]) /* "-q{errorfile}" */ { parmp->use_ef = (char_u *)argv[0] + argv_idx; argv_idx = -1; } ! else if (argc > 1) /* "-q {errorfile}" */ want_argument = TRUE; break; #endif ! case 'R': /* "-R" readonly mode */ readonlymode = TRUE; curbuf->b_p_ro = TRUE; ! p_uc = 10000; /* don't update very often */ break; ! case 'r': /* "-r" recovery mode */ ! case 'L': /* "-L" recovery mode */ recoverymode = 1; break; case 's': ! if (exmode_active) /* "-s" silent (batch) mode */ silent_mode = TRUE; ! else /* "-s {scriptin}" read from script file */ want_argument = TRUE; break; ! case 't': /* "-t {tag}" or "-t{tag}" jump to tag */ if (parmp->edit_type != EDIT_NONE) mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); parmp->edit_type = EDIT_TAG; ! if (argv[0][argv_idx]) /* "-t{tag}" */ { parmp->tagname = (char_u *)argv[0] + argv_idx; argv_idx = -1; } ! else /* "-t {tag}" */ want_argument = TRUE; break; #ifdef FEAT_EVAL ! case 'D': /* "-D" Debugging */ parmp->use_debug_break_level = 9999; break; #endif #ifdef FEAT_DIFF ! case 'd': /* "-d" 'diff' */ # ifdef AMIGA ! /* check for "-dev {device}" */ if (argv[0][argv_idx] == 'e' && argv[0][argv_idx + 1] == 'v') want_argument = TRUE; else --- 2211,2342 ---- #endif break; ! case 'l': // "-l" lisp mode, 'lisp' and 'showmatch' on #ifdef FEAT_LISP set_option_value((char_u *)"lisp", 1L, NULL, 0); p_sm = TRUE; #endif break; ! case 'M': // "-M" no changes or writing of files reset_modifiable(); ! // FALLTHROUGH ! case 'm': // "-m" no writing of files p_write = FALSE; break; ! case 'y': // "-y" easy mode #ifdef FEAT_GUI ! gui.starting = TRUE; // start GUI a bit later #endif parmp->evim_mode = TRUE; break; ! case 'N': // "-N" Nocompatible change_compatible(FALSE); break; ! case 'n': // "-n" no swap file #ifdef FEAT_NETBEANS_INTG ! // checking for "-nb", netbeans parameters if (argv[0][argv_idx] == 'b') { netbeansArg = argv[0]; ! argv_idx = -1; // skip to next argument } else #endif parmp->no_swap_file = TRUE; break; ! case 'p': // "-p[N]" open N tab pages #ifdef TARGET_API_MAC_OSX ! // For some reason on MacOS X, an argument like: ! // -psn_0_10223617 is passed in when invoke from Finder ! // or with the 'open' command if (argv[0][argv_idx] == 's') { ! argv_idx = -1; // bypass full -psn main_start_gui(); break; } #endif ! // default is 0: open window for each file parmp->window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0); parmp->window_layout = WIN_TABS; break; ! case 'o': // "-o[N]" open N horizontal split windows ! // default is 0: open window for each file parmp->window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0); parmp->window_layout = WIN_HOR; break; ! case 'O': // "-O[N]" open N vertical split windows ! // default is 0: open window for each file parmp->window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0); parmp->window_layout = WIN_VER; break; #ifdef FEAT_QUICKFIX ! case 'q': // "-q" QuickFix mode if (parmp->edit_type != EDIT_NONE) mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); parmp->edit_type = EDIT_QF; ! if (argv[0][argv_idx]) // "-q{errorfile}" { parmp->use_ef = (char_u *)argv[0] + argv_idx; argv_idx = -1; } ! else if (argc > 1) // "-q {errorfile}" want_argument = TRUE; break; #endif ! case 'R': // "-R" readonly mode readonlymode = TRUE; curbuf->b_p_ro = TRUE; ! p_uc = 10000; // don't update very often break; ! case 'r': // "-r" recovery mode ! case 'L': // "-L" recovery mode recoverymode = 1; break; case 's': ! if (exmode_active) // "-s" silent (batch) mode silent_mode = TRUE; ! else // "-s {scriptin}" read from script file want_argument = TRUE; break; ! case 't': // "-t {tag}" or "-t{tag}" jump to tag if (parmp->edit_type != EDIT_NONE) mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); parmp->edit_type = EDIT_TAG; ! if (argv[0][argv_idx]) // "-t{tag}" { parmp->tagname = (char_u *)argv[0] + argv_idx; argv_idx = -1; } ! else // "-t {tag}" want_argument = TRUE; break; #ifdef FEAT_EVAL ! case 'D': // "-D" Debugging parmp->use_debug_break_level = 9999; break; #endif #ifdef FEAT_DIFF ! case 'd': // "-d" 'diff' # ifdef AMIGA ! // check for "-dev {device}" if (argv[0][argv_idx] == 'e' && argv[0][argv_idx + 1] == 'v') want_argument = TRUE; else *************** *** 2345,2352 **** parmp->diff_mode = TRUE; break; #endif ! case 'V': /* "-V{N}" Verbose level */ ! /* default is 10: a little bit verbose */ p_verbose = get_number_arg((char_u *)argv[0], &argv_idx, 10); if (argv[0][argv_idx] != NUL) { --- 2344,2351 ---- parmp->diff_mode = TRUE; break; #endif ! case 'V': // "-V{N}" Verbose level ! // default is 10: a little bit verbose p_verbose = get_number_arg((char_u *)argv[0], &argv_idx, 10); if (argv[0][argv_idx] != NUL) { *************** *** 2356,2370 **** } break; ! case 'v': /* "-v" Vi-mode (as if called "vi") */ exmode_active = 0; #if defined(FEAT_GUI) && !defined(VIMDLL) ! gui.starting = FALSE; /* don't start GUI */ #endif break; ! case 'w': /* "-w{number}" set window height */ ! /* "-w {scriptout}" write to script */ if (vim_isdigit(((char_u *)argv[0])[argv_idx])) { n = get_number_arg((char_u *)argv[0], &argv_idx, 10); --- 2355,2369 ---- } break; ! case 'v': // "-v" Vi-mode (as if called "vi") exmode_active = 0; #if defined(FEAT_GUI) && !defined(VIMDLL) ! gui.starting = FALSE; // don't start GUI #endif break; ! case 'w': // "-w{number}" set window height ! // "-w {scriptout}" write to script if (vim_isdigit(((char_u *)argv[0])[argv_idx])) { n = get_number_arg((char_u *)argv[0], &argv_idx, 10); *************** *** 2375,2397 **** break; #ifdef FEAT_CRYPT ! case 'x': /* "-x" encrypted reading/writing of files */ parmp->ask_for_key = TRUE; break; #endif ! case 'X': /* "-X" don't connect to X server */ #if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11) x_no_connect = TRUE; #endif break; ! case 'Z': /* "-Z" restricted mode */ restricted = TRUE; break; ! case 'c': /* "-c{command}" or "-c {command}" execute ! command */ if (argv[0][argv_idx] != NUL) { if (parmp->n_commands >= MAX_ARG_CMDS) --- 2374,2396 ---- break; #ifdef FEAT_CRYPT ! case 'x': // "-x" encrypted reading/writing of files parmp->ask_for_key = TRUE; break; #endif ! case 'X': // "-X" don't connect to X server #if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11) x_no_connect = TRUE; #endif break; ! case 'Z': // "-Z" restricted mode restricted = TRUE; break; ! case 'c': // "-c{command}" or "-c {command}" execute ! // command if (argv[0][argv_idx] != NUL) { if (parmp->n_commands >= MAX_ARG_CMDS) *************** *** 2401,2418 **** argv_idx = -1; break; } ! /* FALLTHROUGH */ ! case 'S': /* "-S {file}" execute Vim script */ ! case 'i': /* "-i {viminfo}" use for viminfo */ #ifndef FEAT_DIFF ! case 'd': /* "-d {device}" device (for Amiga) */ #endif ! case 'T': /* "-T {terminal}" terminal name */ ! case 'u': /* "-u {vimrc}" vim inits file */ ! case 'U': /* "-U {gvimrc}" gvim inits file */ ! case 'W': /* "-W {scriptout}" overwrite */ #ifdef FEAT_GUI_MSWIN ! case 'P': /* "-P {parent title}" MDI parent */ #endif want_argument = TRUE; break; --- 2400,2417 ---- argv_idx = -1; break; } ! // FALLTHROUGH ! case 'S': // "-S {file}" execute Vim script ! case 'i': // "-i {viminfo}" use for viminfo #ifndef FEAT_DIFF ! case 'd': // "-d {device}" device (for Amiga) #endif ! case 'T': // "-T {terminal}" terminal name ! case 'u': // "-u {vimrc}" vim inits file ! case 'U': // "-U {gvimrc}" gvim inits file ! case 'W': // "-W {scriptout}" overwrite #ifdef FEAT_GUI_MSWIN ! case 'P': // "-P {parent title}" MDI parent #endif want_argument = TRUE; break; *************** *** 2433,2447 **** mainerr(ME_GARBAGE, (char_u *)argv[0]); --argc; ! if (argc < 1 && c != 'S') /* -S has an optional argument */ mainerr_arg_missing((char_u *)argv[0]); ++argv; argv_idx = -1; switch (c) { ! case 'c': /* "-c {command}" execute command */ ! case 'S': /* "-S {file}" execute Vim script */ if (parmp->n_commands >= MAX_ARG_CMDS) mainerr(ME_EXTRA_CMD, NULL); if (c == 'S') --- 2432,2446 ---- mainerr(ME_GARBAGE, (char_u *)argv[0]); --argc; ! if (argc < 1 && c != 'S') // -S has an optional argument mainerr_arg_missing((char_u *)argv[0]); ++argv; argv_idx = -1; switch (c) { ! case 'c': // "-c {command}" execute command ! case 'S': // "-S {file}" execute Vim script if (parmp->n_commands >= MAX_ARG_CMDS) mainerr(ME_EXTRA_CMD, NULL); if (c == 'S') *************** *** 2449,2461 **** char *a; if (argc < 1) ! /* "-S" without argument: use default session file ! * name. */ a = SESSION_FILE; else if (argv[0][0] == '-') { ! /* "-S" followed by another option: use default ! * session file name. */ a = SESSION_FILE; ++argc; --argv; --- 2448,2460 ---- char *a; if (argc < 1) ! // "-S" without argument: use default session file ! // name. a = SESSION_FILE; else if (argv[0][0] == '-') { ! // "-S" followed by another option: use default ! // session file name. a = SESSION_FILE; ++argc; --argv; *************** *** 2477,2505 **** case '-': if (argv[-1][2] == 'c') { ! /* "--cmd {command}" execute command */ if (parmp->n_pre_commands >= MAX_ARG_CMDS) mainerr(ME_EXTRA_CMD, NULL); parmp->pre_commands[parmp->n_pre_commands++] = (char_u *)argv[0]; } ! /* "--startuptime " already handled */ break; ! /* case 'd': -d {device} is handled in mch_check_win() for the ! * Amiga */ #ifdef FEAT_QUICKFIX ! case 'q': /* "-q {errorfile}" QuickFix mode */ parmp->use_ef = (char_u *)argv[0]; break; #endif ! case 'i': /* "-i {viminfo}" use for viminfo */ set_option_value((char_u *)"vif", 0L, (char_u *)argv[0], 0); break; ! case 's': /* "-s {scriptin}" read from script file */ if (scriptin[0] != NULL) { scripterror: --- 2476,2504 ---- case '-': if (argv[-1][2] == 'c') { ! // "--cmd {command}" execute command if (parmp->n_pre_commands >= MAX_ARG_CMDS) mainerr(ME_EXTRA_CMD, NULL); parmp->pre_commands[parmp->n_pre_commands++] = (char_u *)argv[0]; } ! // "--startuptime " already handled break; ! // case 'd': -d {device} is handled in mch_check_win() for the ! // Amiga #ifdef FEAT_QUICKFIX ! case 'q': // "-q {errorfile}" QuickFix mode parmp->use_ef = (char_u *)argv[0]; break; #endif ! case 'i': // "-i {viminfo}" use for viminfo set_option_value((char_u *)"vif", 0L, (char_u *)argv[0], 0); break; ! case 's': // "-s {scriptin}" read from script file if (scriptin[0] != NULL) { scripterror: *************** *** 2518,2531 **** mch_exit(2); } if (save_typebuf() == FAIL) ! mch_exit(2); /* out of memory */ break; ! case 't': /* "-t {tag}" */ parmp->tagname = (char_u *)argv[0]; break; ! case 'T': /* "-T {terminal}" terminal name */ /* * The -T term argument is always available and when * HAVE_TERMLIB is supported it overrides the environment --- 2517,2530 ---- mch_exit(2); } if (save_typebuf() == FAIL) ! mch_exit(2); // out of memory break; ! case 't': // "-t {tag}" parmp->tagname = (char_u *)argv[0]; break; ! case 'T': // "-T {terminal}" terminal name /* * The -T term argument is always available and when * HAVE_TERMLIB is supported it overrides the environment *************** *** 2533,2556 **** */ #ifdef FEAT_GUI if (term_is_gui((char_u *)argv[0])) ! gui.starting = TRUE; /* start GUI a bit later */ else #endif parmp->term = (char_u *)argv[0]; break; ! case 'u': /* "-u {vimrc}" vim inits file */ parmp->use_vimrc = (char_u *)argv[0]; break; ! case 'U': /* "-U {gvimrc}" gvim inits file */ #ifdef FEAT_GUI use_gvimrc = (char_u *)argv[0]; #endif break; ! case 'w': /* "-w {nr}" 'window' value */ ! /* "-w {scriptout}" append to script file */ if (vim_isdigit(*((char_u *)argv[0]))) { argv_idx = 0; --- 2532,2555 ---- */ #ifdef FEAT_GUI if (term_is_gui((char_u *)argv[0])) ! gui.starting = TRUE; // start GUI a bit later else #endif parmp->term = (char_u *)argv[0]; break; ! case 'u': // "-u {vimrc}" vim inits file parmp->use_vimrc = (char_u *)argv[0]; break; ! case 'U': // "-U {gvimrc}" gvim inits file #ifdef FEAT_GUI use_gvimrc = (char_u *)argv[0]; #endif break; ! case 'w': // "-w {nr}" 'window' value ! // "-w {scriptout}" append to script file if (vim_isdigit(*((char_u *)argv[0]))) { argv_idx = 0; *************** *** 2559,2566 **** argv_idx = -1; break; } ! /* FALLTHROUGH */ ! case 'W': /* "-W {scriptout}" overwrite script file */ if (scriptout != NULL) goto scripterror; if ((scriptout = mch_fopen(argv[0], --- 2558,2565 ---- argv_idx = -1; break; } ! // FALLTHROUGH ! case 'W': // "-W {scriptout}" overwrite script file if (scriptout != NULL) goto scripterror; if ((scriptout = mch_fopen(argv[0], *************** *** 2574,2580 **** break; #ifdef FEAT_GUI_MSWIN ! case 'P': /* "-P {parent title}" MDI parent */ gui_mch_set_parent(argv[0]); break; #endif --- 2573,2579 ---- break; #ifdef FEAT_GUI_MSWIN ! case 'P': // "-P {parent title}" MDI parent gui_mch_set_parent(argv[0]); break; #endif *************** *** 2587,2607 **** */ else { ! argv_idx = -1; /* skip to next argument */ ! /* Check for only one type of editing. */ if (parmp->edit_type != EDIT_NONE && parmp->edit_type != EDIT_FILE) mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); parmp->edit_type = EDIT_FILE; #ifdef MSWIN ! /* Remember if the argument was a full path before changing ! * slashes to backslashes. */ if (argv[0][0] != NUL && argv[0][1] == ':' && argv[0][2] == '\\') parmp->full_path = TRUE; #endif ! /* Add the file to the global argument list. */ if (ga_grow(&global_alist.al_ga, 1) == FAIL || (p = vim_strsave((char_u *)argv[0])) == NULL) mch_exit(2); --- 2586,2606 ---- */ else { ! argv_idx = -1; // skip to next argument ! // Check for only one type of editing. if (parmp->edit_type != EDIT_NONE && parmp->edit_type != EDIT_FILE) mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); parmp->edit_type = EDIT_FILE; #ifdef MSWIN ! // Remember if the argument was a full path before changing ! // slashes to backslashes. if (argv[0][0] != NUL && argv[0][1] == ':' && argv[0][2] == '\\') parmp->full_path = TRUE; #endif ! // Add the file to the global argument list. if (ga_grow(&global_alist.al_ga, 1) == FAIL || (p = vim_strsave((char_u *)argv[0])) == NULL) mch_exit(2); *************** *** 2643,2664 **** #endif #ifdef USE_FNAME_CASE ! /* Make the case of the file name match the actual file. */ fname_case(p, 0); #endif alist_add(&global_alist, p, #ifdef EXPAND_FILENAMES ! parmp->literal ? 2 : 0 /* add buffer nr after exp. */ #else ! 2 /* add buffer number now and use curbuf */ #endif ); #ifdef MSWIN { ! /* Remember this argument has been added to the argument list. ! * Needed when 'encoding' is changed. */ used_file_arg(argv[0], parmp->literal, parmp->full_path, # ifdef FEAT_DIFF parmp->diff_mode --- 2642,2663 ---- #endif #ifdef USE_FNAME_CASE ! // Make the case of the file name match the actual file. fname_case(p, 0); #endif alist_add(&global_alist, p, #ifdef EXPAND_FILENAMES ! parmp->literal ? 2 : 0 // add buffer nr after exp. #else ! 2 // add buffer number now and use curbuf #endif ); #ifdef MSWIN { ! // Remember this argument has been added to the argument list. ! // Needed when 'encoding' is changed. used_file_arg(argv[0], parmp->literal, parmp->full_path, # ifdef FEAT_DIFF parmp->diff_mode *************** *** 2684,2691 **** } #ifdef FEAT_EVAL ! /* If there is a "+123" or "-c" command, set v:swapcommand to the first ! * one. */ if (parmp->n_commands > 0) { p = alloc(STRLEN(parmp->commands[0]) + 3); --- 2683,2690 ---- } #ifdef FEAT_EVAL ! // If there is a "+123" or "-c" command, set v:swapcommand to the first ! // one. if (parmp->n_commands > 0) { p = alloc(STRLEN(parmp->commands[0]) + 3); *************** *** 2706,2712 **** static void check_tty(mparm_T *parmp) { ! int input_isatty; /* is active input a terminal? */ input_isatty = mch_input_isatty(); if (exmode_active) --- 2705,2711 ---- static void check_tty(mparm_T *parmp) { ! int input_isatty; // is active input a terminal? input_isatty = mch_input_isatty(); if (exmode_active) *************** *** 2716,2722 **** } else if (parmp->want_full_screen && (!stdout_isatty || !input_isatty) #ifdef FEAT_GUI ! /* don't want the delay when started from the desktop */ && !gui.starting #endif && !parmp->not_a_term) --- 2715,2721 ---- } else if (parmp->want_full_screen && (!stdout_isatty || !input_isatty) #ifdef FEAT_GUI ! // don't want the delay when started from the desktop && !gui.starting #endif && !parmp->not_a_term) *************** *** 2746,2759 **** && defined(FEAT_GETTEXT) char *s, *tofree = NULL; ! /* Set the encoding of the error message based on $LC_ALL or ! * other environment variables instead of 'encoding'. ! * Note that the message is shown on a Cygwin terminal (e.g. ! * mintty) which encoding is based on $LC_ALL or etc., not the ! * current codepage used by normal Win32 console programs. */ tofree = s = (char *)enc_locale_env(NULL); if (s == NULL) ! s = "utf-8"; /* Use "utf-8" by default. */ (void)bind_textdomain_codeset(VIMPACKAGE, s); vim_free(tofree); # endif --- 2745,2758 ---- && defined(FEAT_GETTEXT) char *s, *tofree = NULL; ! // Set the encoding of the error message based on $LC_ALL or ! // other environment variables instead of 'encoding'. ! // Note that the message is shown on a Cygwin terminal (e.g. ! // mintty) which encoding is based on $LC_ALL or etc., not the ! // current codepage used by normal Win32 console programs. tofree = s = (char *)enc_locale_env(NULL); if (s == NULL) ! s = "utf-8"; // Use "utf-8" by default. (void)bind_textdomain_codeset(VIMPACKAGE, s); vim_free(tofree); # endif *************** *** 2818,2831 **** /* * Create the number of windows that was requested. */ ! if (parmp->window_count == -1) /* was not set */ parmp->window_count = 1; if (parmp->window_count == 0) parmp->window_count = GARGCOUNT; if (parmp->window_count > 1) { ! /* Don't change the windows if there was a command in .vimrc that ! * already split some windows */ if (parmp->window_layout == 0) parmp->window_layout = WIN_HOR; if (parmp->window_layout == WIN_TABS) --- 2817,2830 ---- /* * Create the number of windows that was requested. */ ! if (parmp->window_count == -1) // was not set parmp->window_count = 1; if (parmp->window_count == 0) parmp->window_count = GARGCOUNT; if (parmp->window_count > 1) { ! // Don't change the windows if there was a command in .vimrc that ! // already split some windows if (parmp->window_layout == 0) parmp->window_layout = WIN_HOR; if (parmp->window_layout == WIN_TABS) *************** *** 2845,2857 **** else parmp->window_count = 1; ! if (recoverymode) /* do recover */ { ! msg_scroll = TRUE; /* scroll message up */ ml_recover(TRUE); ! if (curbuf->b_ml.ml_mfp == NULL) /* failed */ getout(1); ! do_modelines(0); /* do modelines */ } else { --- 2844,2856 ---- else parmp->window_count = 1; ! if (recoverymode) // do recover { ! msg_scroll = TRUE; // scroll message up ml_recover(TRUE); ! if (curbuf->b_ml.ml_mfp == NULL) // failed getout(1); ! do_modelines(0); // do modelines } else { *************** *** 2892,2898 **** if (curbuf->b_ml.ml_mfp == NULL) { #ifdef FEAT_FOLDING ! /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */ if (p_fdls >= 0) curwin->w_p_fdl = p_fdls; #endif --- 2891,2897 ---- if (curbuf->b_ml.ml_mfp == NULL) { #ifdef FEAT_FOLDING ! // Set 'foldlevel' to 'foldlevelstart' if it's not negative. if (p_fdls >= 0) curwin->w_p_fdl = p_fdls; #endif *************** *** 2901,2932 **** set_buflisted(TRUE); ! /* create memfile, read file */ (void)open_buffer(FALSE, NULL, 0); if (swap_exists_action == SEA_QUIT) { if (got_int || only_one_window()) { ! /* abort selected or quit and only one window */ ! did_emsg = FALSE; /* avoid hit-enter prompt */ getout(1); } ! /* We can't close the window, it would disturb what ! * happens next. Clear the file name and set the arg ! * index to -1 to delete it later. */ setfname(curbuf, NULL, NULL, FALSE); curwin->w_arg_idx = -1; swap_exists_action = SEA_NONE; } else handle_swap_exists(NULL); ! dorewind = TRUE; /* start again */ } ui_breakcheck(); if (got_int) { ! (void)vgetc(); /* only break the file loading, not the rest */ break; } } --- 2900,2931 ---- set_buflisted(TRUE); ! // create memfile, read file (void)open_buffer(FALSE, NULL, 0); if (swap_exists_action == SEA_QUIT) { if (got_int || only_one_window()) { ! // abort selected or quit and only one window ! did_emsg = FALSE; // avoid hit-enter prompt getout(1); } ! // We can't close the window, it would disturb what ! // happens next. Clear the file name and set the arg ! // index to -1 to delete it later. setfname(curbuf, NULL, NULL, FALSE); curwin->w_arg_idx = -1; swap_exists_action = SEA_NONE; } else handle_swap_exists(NULL); ! dorewind = TRUE; // start again } ui_breakcheck(); if (got_int) { ! (void)vgetc(); // only break the file loading, not the rest break; } } *************** *** 2947,2955 **** static void edit_buffers( mparm_T *parmp, ! char_u *cwd) /* current working dir */ { ! int arg_idx; /* index in argument list */ int i; int advance = TRUE; win_T *win; --- 2946,2954 ---- static void edit_buffers( mparm_T *parmp, ! char_u *cwd) // current working dir { ! int arg_idx; // index in argument list int i; int advance = TRUE; win_T *win; *************** *** 2961,2967 **** ++autocmd_no_enter; ++autocmd_no_leave; ! /* When w_arg_idx is -1 remove the window (see create_windows()). */ if (curwin->w_arg_idx == -1) { win_close(curwin, TRUE); --- 2960,2966 ---- ++autocmd_no_enter; ++autocmd_no_leave; ! // When w_arg_idx is -1 remove the window (see create_windows()). if (curwin->w_arg_idx == -1) { win_close(curwin, TRUE); *************** *** 2973,2979 **** { if (cwd != NULL) mch_chdir((char *)cwd); ! /* When w_arg_idx is -1 remove the window (see create_windows()). */ if (curwin->w_arg_idx == -1) { ++arg_idx; --- 2972,2978 ---- { if (cwd != NULL) mch_chdir((char *)cwd); ! // When w_arg_idx is -1 remove the window (see create_windows()). if (curwin->w_arg_idx == -1) { ++arg_idx; *************** *** 2986,2992 **** { if (parmp->window_layout == WIN_TABS) { ! if (curtab->tp_next == NULL) /* just checking */ break; goto_tabpage(0); // Temporarily reset 'shm' option to not print fileinfo when --- 2985,2991 ---- { if (parmp->window_layout == WIN_TABS) { ! if (curtab->tp_next == NULL) // just checking break; goto_tabpage(0); // Temporarily reset 'shm' option to not print fileinfo when *************** *** 3003,3033 **** } else { ! if (curwin->w_next == NULL) /* just checking */ break; win_enter(curwin->w_next, FALSE); } } advance = TRUE; ! /* Only open the file if there is no file in this window yet (that can ! * happen when .vimrc contains ":sall"). */ if (curbuf == firstwin->w_buffer || curbuf->b_ffname == NULL) { curwin->w_arg_idx = arg_idx; ! /* Edit file from arg list, if there is one. When "Quit" selected ! * at the ATTENTION prompt close the window. */ swap_exists_did_quit = FALSE; (void)do_ecmd(0, arg_idx < GARGCOUNT ? alist_name(&GARGLIST[arg_idx]) : NULL, NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin); if (swap_exists_did_quit) { ! /* abort or quit selected */ if (got_int || only_one_window()) { ! /* abort selected and only one window */ ! did_emsg = FALSE; /* avoid hit-enter prompt */ getout(1); } win_close(curwin, TRUE); --- 3002,3032 ---- } else { ! if (curwin->w_next == NULL) // just checking break; win_enter(curwin->w_next, FALSE); } } advance = TRUE; ! // Only open the file if there is no file in this window yet (that can ! // happen when .vimrc contains ":sall"). if (curbuf == firstwin->w_buffer || curbuf->b_ffname == NULL) { curwin->w_arg_idx = arg_idx; ! // Edit file from arg list, if there is one. When "Quit" selected ! // at the ATTENTION prompt close the window. swap_exists_did_quit = FALSE; (void)do_ecmd(0, arg_idx < GARGCOUNT ? alist_name(&GARGLIST[arg_idx]) : NULL, NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin); if (swap_exists_did_quit) { ! // abort or quit selected if (got_int || only_one_window()) { ! // abort selected and only one window ! did_emsg = FALSE; // avoid hit-enter prompt getout(1); } win_close(curwin, TRUE); *************** *** 3040,3046 **** ui_breakcheck(); if (got_int) { ! (void)vgetc(); /* only break the file loading, not the rest */ break; } } --- 3039,3045 ---- ui_breakcheck(); if (got_int) { ! (void)vgetc(); // only break the file loading, not the rest break; } } *************** *** 3055,3064 **** goto_tabpage(1); --autocmd_no_enter; ! /* make the first window the current window */ win = firstwin; #if defined(FEAT_QUICKFIX) ! /* Avoid making a preview window the current window. */ while (win->w_p_pvw) { win = win->w_next; --- 3054,3063 ---- goto_tabpage(1); --autocmd_no_enter; ! // make the first window the current window win = firstwin; #if defined(FEAT_QUICKFIX) ! // Avoid making a preview window the current window. while (win->w_p_pvw) { win = win->w_next; *************** *** 3074,3080 **** --autocmd_no_leave; TIME_MSG("editing files in windows"); if (parmp->window_count > 1 && parmp->window_layout != WIN_TABS) ! win_equal(curwin, FALSE, 'b'); /* adjust heights */ } /* --- 3073,3079 ---- --autocmd_no_leave; TIME_MSG("editing files in windows"); if (parmp->window_count > 1 && parmp->window_layout != WIN_TABS) ! win_equal(curwin, FALSE, 'b'); // adjust heights } /* *************** *** 3089,3095 **** if (cnt > 0) { ! curwin->w_cursor.lnum = 0; /* just in case.. */ sourcing_name = (char_u *)_("pre-vimrc command line"); # ifdef FEAT_EVAL current_sctx.sc_sid = SID_CMDARG; --- 3088,3094 ---- if (cnt > 0) { ! curwin->w_cursor.lnum = 0; // just in case.. sourcing_name = (char_u *)_("pre-vimrc command line"); # ifdef FEAT_EVAL current_sctx.sc_sid = SID_CMDARG; *************** *** 3142,3148 **** msg_scroll = FALSE; #ifdef FEAT_QUICKFIX ! /* When started with "-q errorfile" jump to first error again. */ if (parmp->edit_type == EDIT_QF) qf_jump(NULL, 0, 0, FALSE); #endif --- 3141,3147 ---- msg_scroll = FALSE; #ifdef FEAT_QUICKFIX ! // When started with "-q errorfile" jump to first error again. if (parmp->edit_type == EDIT_QF) qf_jump(NULL, 0, 0, FALSE); #endif *************** *** 3179,3185 **** || STRCMP(parmp->use_vimrc, "NORC") == 0) { #ifdef FEAT_GUI ! if (use_gvimrc == NULL) /* don't load gvimrc either */ use_gvimrc = parmp->use_vimrc; #endif } --- 3178,3184 ---- || STRCMP(parmp->use_vimrc, "NORC") == 0) { #ifdef FEAT_GUI ! if (use_gvimrc == NULL) // don't load gvimrc either use_gvimrc = parmp->use_vimrc; #endif } *************** *** 3195,3201 **** struct Process *proc = (struct Process *)FindTask(0L); APTR save_winptr = proc->pr_WindowPtr; ! /* Avoid a requester here for a volume that doesn't exist. */ proc->pr_WindowPtr = (APTR)-1L; #endif --- 3194,3200 ---- struct Process *proc = (struct Process *)FindTask(0L); APTR save_winptr = proc->pr_WindowPtr; ! // Avoid a requester here for a volume that doesn't exist. proc->pr_WindowPtr = (APTR)-1L; #endif *************** *** 3241,3247 **** #endif && !has_dash_c_arg) { ! /* When no .vimrc file was found: source defaults.vim. */ do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE); } } --- 3240,3246 ---- #endif && !has_dash_c_arg) { ! // When no .vimrc file was found: source defaults.vim. do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE); } } *************** *** 3258,3264 **** if (p_exrc) { #if defined(UNIX) || defined(VMS) ! /* If ".vimrc" file is not owned by user, set 'secure' mode. */ if (!file_owned(VIMRC_FILE)) #endif secure = p_secure; --- 3257,3263 ---- if (p_exrc) { #if defined(UNIX) || defined(VMS) ! // If ".vimrc" file is not owned by user, set 'secure' mode. if (!file_owned(VIMRC_FILE)) #endif secure = p_secure; *************** *** 3284,3290 **** if (i == FAIL) { #if defined(UNIX) || defined(VMS) ! /* if ".exrc" is not owned by user set 'secure' mode */ if (!file_owned(EXRC_FILE)) secure = p_secure; else --- 3283,3289 ---- if (i == FAIL) { #if defined(UNIX) || defined(VMS) ! // if ".exrc" is not owned by user set 'secure' mode if (!file_owned(EXRC_FILE)) secure = p_secure; else *************** *** 3317,3323 **** main_start_gui(void) { #ifdef FEAT_GUI ! gui.starting = TRUE; /* start GUI a bit later */ #else mch_errmsg(_(e_nogvim)); mch_errmsg("\n"); --- 3316,3322 ---- main_start_gui(void) { #ifdef FEAT_GUI ! gui.starting = TRUE; // start GUI a bit later #else mch_errmsg(_(e_nogvim)); mch_errmsg("\n"); *************** *** 3325,3331 **** #endif } ! #endif /* NO_VIM_MAIN */ /* * Get an environment variable, and execute it as Ex commands. --- 3324,3330 ---- #endif } ! #endif // NO_VIM_MAIN /* * Get an environment variable, and execute it as Ex commands. *************** *** 3334,3340 **** int process_env( char_u *env, ! int is_viminit) /* when TRUE, called for VIMINIT */ { char_u *initstr; char_u *save_sourcing_name; --- 3333,3339 ---- int process_env( char_u *env, ! int is_viminit) // when TRUE, called for VIMINIT { char_u *initstr; char_u *save_sourcing_name; *************** *** 3381,3387 **** stat_T s; # ifdef UNIX uid_t uid = getuid(); ! # else /* VMS */ uid_t uid = ((getgid() << 16) | getuid()); # endif --- 3380,3386 ---- stat_T s; # ifdef UNIX uid_t uid = getuid(); ! # else // VMS uid_t uid = ((getgid() << 16) | getuid()); # endif *************** *** 3398,3408 **** */ static void mainerr( ! int n, /* one of the ME_ defines */ ! char_u *str) /* extra argument or NULL */ { #if defined(UNIX) || defined(VMS) ! reset_signals(); /* kill us with CTRL-C here, if you like */ #endif // If this is a Windows GUI executable, show an error dialog box. --- 3397,3407 ---- */ static void mainerr( ! int n, // one of the ME_ defines ! char_u *str) // extra argument or NULL { #if defined(UNIX) || defined(VMS) ! reset_signals(); // kill us with CTRL-C here, if you like #endif // If this is a Windows GUI executable, show an error dialog box. *************** *** 3464,3470 **** }; #if defined(UNIX) || defined(VMS) ! reset_signals(); /* kill us with CTRL-C here, if you like */ #endif init_longVersion(); --- 3463,3469 ---- }; #if defined(UNIX) || defined(VMS) ! reset_signals(); // kill us with CTRL-C here, if you like #endif init_longVersion(); *************** *** 3608,3614 **** main_msg(_("-reverse\t\tUse reverse video (also: -rv)")); main_msg(_("+reverse\t\tDon't use reverse video (also: +rv)")); main_msg(_("-xrm \tSet the specified resource")); ! #endif /* FEAT_GUI_X11 */ #ifdef FEAT_GUI_GTK mch_msg(_("\nArguments recognised by gvim (GTK+ version):\n")); main_msg(_("-font \t\tUse for normal text (also: -fn)")); --- 3607,3613 ---- main_msg(_("-reverse\t\tUse reverse video (also: -rv)")); main_msg(_("+reverse\t\tDon't use reverse video (also: +rv)")); main_msg(_("-xrm \tSet the specified resource")); ! #endif // FEAT_GUI_X11 #ifdef FEAT_GUI_GTK mch_msg(_("\nArguments recognised by gvim (GTK+ version):\n")); main_msg(_("-font \t\tUse for normal text (also: -fn)")); *************** *** 3630,3636 **** #endif #ifdef FEAT_GUI_GNOME ! /* Gnome gives extra messages for --help if we continue, but not for -h. */ if (gui.starting) { mch_msg("\n"); --- 3629,3635 ---- #endif #ifdef FEAT_GUI_GNOME ! // Gnome gives extra messages for --help if we continue, but not for -h. if (gui.starting) { mch_msg("\n"); *************** *** 3654,3660 **** handle_swap_exists(NULL); } ! #endif /* NO_VIM_MAIN */ #if defined(STARTUPTIME) || defined(PROTO) static struct timeval prev_timeval; --- 3653,3659 ---- handle_swap_exists(NULL); } ! #endif // NO_VIM_MAIN #if defined(STARTUPTIME) || defined(PROTO) static struct timeval prev_timeval; *************** *** 3702,3708 **** */ void time_pop( ! void *tp) /* actually (struct timeval *) */ { prev_timeval.tv_usec -= ((struct timeval *)tp)->tv_usec; prev_timeval.tv_sec -= ((struct timeval *)tp)->tv_sec; --- 3701,3707 ---- */ void time_pop( ! void *tp) // actually (struct timeval *) { prev_timeval.tv_usec -= ((struct timeval *)tp)->tv_usec; prev_timeval.tv_sec -= ((struct timeval *)tp)->tv_sec; *************** *** 3728,3735 **** void time_msg( char *mesg, ! void *tv_start) /* only for do_source: start time; actually ! (struct timeval *) */ { static struct timeval start; struct timeval now; --- 3727,3734 ---- void time_msg( char *mesg, ! void *tv_start) // only for do_source: start time; actually ! // (struct timeval *) { static struct timeval start; struct timeval now; *************** *** 3767,3776 **** char_u *val = argv0; # ifdef MSWIN ! /* A relative path containing a "/" will become invalid when using ":cd", ! * turn it into a full path. ! * On MS-Windows "vim" should be expanded to "vim.exe", thus always do ! * this. */ char_u *path = NULL; if (mch_can_exe(argv0, &path, FALSE) && path != NULL) --- 3766,3775 ---- char_u *val = argv0; # ifdef MSWIN ! // A relative path containing a "/" will become invalid when using ":cd", ! // turn it into a full path. ! // On MS-Windows "vim" should be expanded to "vim.exe", thus always do ! // this. char_u *path = NULL; if (mch_can_exe(argv0, &path, FALSE) && path != NULL) *************** *** 3804,3810 **** # endif } ! #endif /* NO_VIM_MAIN */ #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO) --- 3803,3809 ---- # endif } ! #endif // NO_VIM_MAIN #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO) *************** *** 3823,3829 **** if (parmp->serverName_arg == NULL || *parmp->serverName_arg != NUL) { # ifdef MSWIN ! /* Initialise the client/server messaging infrastructure. */ serverInitMessaging(); # endif --- 3822,3828 ---- if (parmp->serverName_arg == NULL || *parmp->serverName_arg != NUL) { # ifdef MSWIN ! // Initialise the client/server messaging infrastructure. serverInitMessaging(); # endif *************** *** 3839,3847 **** parmp->serverStrEnc = vim_strsave(p_enc); } ! /* If we're still running, get the name to register ourselves. ! * On Win32 can register right now, for X11 need to setup the ! * clipboard first, it's further down. */ parmp->servername = serverMakeName(parmp->serverName_arg, parmp->argv[0]); # ifdef MSWIN --- 3838,3846 ---- parmp->serverStrEnc = vim_strsave(p_enc); } ! // If we're still running, get the name to register ourselves. ! // On Win32 can register right now, for X11 need to setup the ! // clipboard first, it's further down. parmp->servername = serverMakeName(parmp->serverName_arg, parmp->argv[0]); # ifdef MSWIN *************** *** 3947,3953 **** for (i = 1; i < Argc; i++) { res = NULL; ! if (STRCMP(argv[i], "--") == 0) /* end of option arguments */ { for (; i < *argc; i++) { --- 3946,3952 ---- for (i = 1; i < Argc; i++) { res = NULL; ! if (STRCMP(argv[i], "--") == 0) // end of option arguments { for (; i < *argc; i++) { *************** *** 4006,4012 **** tabs, argtype == ARGTYPE_EDIT_WAIT); if (*serverStr == NULL) { ! /* Probably out of memory, exit. */ didone = TRUE; exiterr = 1; break; --- 4005,4011 ---- tabs, argtype == ARGTYPE_EDIT_WAIT); if (*serverStr == NULL) { ! // Probably out of memory, exit. didone = TRUE; exiterr = 1; break; *************** *** 4023,4050 **** ret = serverSendToVim(xterm_dpy, sname, *serverStr, NULL, &srv, 0, 0, 0, silent); # else ! /* Win32 always works? */ ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, 0, silent); # endif if (ret < 0) { if (argtype == ARGTYPE_SEND) { ! /* Failed to send, abort. */ mch_errmsg(_(": Send failed.\n")); didone = TRUE; exiterr = 1; } else if (!silent) ! /* Let vim start normally. */ mch_errmsg(_(": Send failed. Trying to execute locally\n")); break; } # ifdef FEAT_GUI_MSWIN ! /* Guess that when the server name starts with "g" it's a GUI ! * server, which we can bring to the foreground here. ! * Foreground() in the server doesn't work very well. */ if (argtype != ARGTYPE_SEND && TOUPPER_ASC(*sname) == 'G') SetForegroundWindow(srv); # endif --- 4022,4049 ---- ret = serverSendToVim(xterm_dpy, sname, *serverStr, NULL, &srv, 0, 0, 0, silent); # else ! // Win32 always works? ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, 0, silent); # endif if (ret < 0) { if (argtype == ARGTYPE_SEND) { ! // Failed to send, abort. mch_errmsg(_(": Send failed.\n")); didone = TRUE; exiterr = 1; } else if (!silent) ! // Let vim start normally. mch_errmsg(_(": Send failed. Trying to execute locally\n")); break; } # ifdef FEAT_GUI_MSWIN ! // Guess that when the server name starts with "g" it's a GUI ! // server, which we can bring to the foreground here. ! // Foreground() in the server doesn't work very well. if (argtype != ARGTYPE_SEND && TOUPPER_ASC(*sname) == 'G') SetForegroundWindow(srv); # endif *************** *** 4066,4072 **** # endif if (numFiles > 0 && argv[i + 1][0] == '+') ! /* Skip "+cmd" argument, don't wait for it to be edited. */ --numFiles; # ifdef FEAT_GUI_MSWIN --- 4065,4071 ---- # endif if (numFiles > 0 && argv[i + 1][0] == '+') ! // Skip "+cmd" argument, don't wait for it to be edited. --numFiles; # ifdef FEAT_GUI_MSWIN *************** *** 4079,4085 **** Shell_NotifyIcon(NIM_ADD, &ni); # endif ! /* Wait for all files to unload in remote */ vim_memset(done, 0, numFiles); while (memchr(done, 0, numFiles) != NULL) { --- 4078,4084 ---- Shell_NotifyIcon(NIM_ADD, &ni); # endif ! // Wait for all files to unload in remote vim_memset(done, 0, numFiles); while (memchr(done, 0, numFiles) != NULL) { *************** *** 4113,4119 **** if (i == *argc - 1) mainerr_arg_missing((char_u *)argv[i]); # ifdef MSWIN ! /* Win32 always works? */ if (serverSendToVim(sname, (char_u *)argv[i + 1], &res, NULL, 1, 0, FALSE) < 0) # else --- 4112,4118 ---- if (i == *argc - 1) mainerr_arg_missing((char_u *)argv[i]); # ifdef MSWIN ! // Win32 always works? if (serverSendToVim(sname, (char_u *)argv[i + 1], &res, NULL, 1, 0, FALSE) < 0) # else *************** *** 4125,4131 **** { if (res != NULL && *res != NUL) { ! /* Output error from remote */ mch_errmsg((char *)res); VIM_CLEAR(res); } --- 4124,4130 ---- { if (res != NULL && *res != NUL) { ! // Output error from remote mch_errmsg((char *)res); VIM_CLEAR(res); } *************** *** 4135,4141 **** else if (STRICMP(argv[i], "--serverlist") == 0) { # ifdef MSWIN ! /* Win32 always works? */ res = serverGetVimNames(); # else if (xterm_dpy != NULL) --- 4134,4140 ---- else if (STRICMP(argv[i], "--serverlist") == 0) { # ifdef MSWIN ! // Win32 always works? res = serverGetVimNames(); # else if (xterm_dpy != NULL) *************** *** 4146,4152 **** } else if (STRICMP(argv[i], "--servername") == 0) { ! /* Already processed. Take it out of the command line */ i++; continue; } --- 4145,4151 ---- } else if (STRICMP(argv[i], "--servername") == 0) { ! // Already processed. Take it out of the command line i++; continue; } *************** *** 4168,4178 **** if (didone) { ! display_errors(); /* display any collected messages */ ! exit(exiterr); /* Mission accomplished - get out */ } ! /* Return back into main() */ *argc = newArgC; vim_free(sname); } --- 4167,4177 ---- if (didone) { ! display_errors(); // display any collected messages ! exit(exiterr); // Mission accomplished - get out } ! // Return back into main() *argc = newArgC; vim_free(sname); } *************** *** 4184,4190 **** build_drop_cmd( int filec, char **filev, ! int tabs, /* Use ":tab drop" instead of ":drop". */ int sendReply) { garray_T ga; --- 4183,4189 ---- build_drop_cmd( int filec, char **filev, ! int tabs, // Use ":tab drop" instead of ":drop". int sendReply) { garray_T ga; *************** *** 4200,4210 **** filev++; filec--; } ! /* Check if we have at least one argument. */ if (filec <= 0) mainerr_arg_missing((char_u *)filev[-1]); ! /* Temporarily cd to the current directory to handle relative file names. */ cwd = alloc(MAXPATHL); if (cwd == NULL) return NULL; --- 4199,4209 ---- filev++; filec--; } ! // Check if we have at least one argument. if (filec <= 0) mainerr_arg_missing((char_u *)filev[-1]); ! // Temporarily cd to the current directory to handle relative file names. cwd = alloc(MAXPATHL); if (cwd == NULL) return NULL; *************** *** 4215,4225 **** } cdp = vim_strsave_escaped_ext(cwd, #ifdef BACKSLASH_IN_FILENAME ! (char_u *)"", /* rem_backslash() will tell what chars to escape */ #else ! PATH_ESC_CHARS, #endif ! '\\', TRUE); vim_free(cwd); if (cdp == NULL) return NULL; --- 4214,4224 ---- } cdp = vim_strsave_escaped_ext(cwd, #ifdef BACKSLASH_IN_FILENAME ! (char_u *)"", // rem_backslash() will tell what chars to escape #else ! PATH_ESC_CHARS, #endif ! '\\', TRUE); vim_free(cwd); if (cdp == NULL) return NULL; *************** *** 4227,4242 **** ga_concat(&ga, (char_u *)":cd "); ga_concat(&ga, cdp); ! /* Call inputsave() so that a prompt for an encryption key works. */ ga_concat(&ga, (char_u *)":if exists('*inputsave')|call inputsave()|endif|"); if (tabs) ga_concat(&ga, (char_u *)"tab "); ga_concat(&ga, (char_u *)"drop"); for (i = 0; i < filec; i++) { ! /* On Unix the shell has already expanded the wildcards, don't want to ! * do it again in the Vim server. On MS-Windows only escape ! * non-wildcard characters. */ p = vim_strsave_escaped((char_u *)filev[i], #ifdef UNIX PATH_ESC_CHARS --- 4226,4241 ---- ga_concat(&ga, (char_u *)":cd "); ga_concat(&ga, cdp); ! // Call inputsave() so that a prompt for an encryption key works. ga_concat(&ga, (char_u *)":if exists('*inputsave')|call inputsave()|endif|"); if (tabs) ga_concat(&ga, (char_u *)"tab "); ga_concat(&ga, (char_u *)"drop"); for (i = 0; i < filec; i++) { ! // On Unix the shell has already expanded the wildcards, don't want to ! // do it again in the Vim server. On MS-Windows only escape ! // non-wildcard characters. p = vim_strsave_escaped((char_u *)filev[i], #ifdef UNIX PATH_ESC_CHARS *************** *** 4255,4276 **** } ga_concat(&ga, (char_u *)"|if exists('*inputrestore')|call inputrestore()|endif"); ! /* The :drop commands goes to Insert mode when 'insertmode' is set, use ! * CTRL-\ CTRL-N again. */ ga_concat(&ga, (char_u *)""); ! /* Switch back to the correct current directory (prior to temporary path ! * switch) unless 'autochdir' is set, in which case it will already be ! * correct after the :drop command. With line breaks and spaces: ! * if !exists('+acd') || !&acd ! * if haslocaldir() ! * cd - ! * lcd - ! * elseif getcwd() ==# 'current path' ! * cd - ! * endif ! * endif ! */ ga_concat(&ga, (char_u *)":if !exists('+acd')||!&acd|if haslocaldir()|"); ga_concat(&ga, (char_u *)"cd -|lcd -|elseif getcwd() ==# '"); ga_concat(&ga, cdp); --- 4254,4274 ---- } ga_concat(&ga, (char_u *)"|if exists('*inputrestore')|call inputrestore()|endif"); ! // The :drop commands goes to Insert mode when 'insertmode' is set, use ! // CTRL-\ CTRL-N again. ga_concat(&ga, (char_u *)""); ! // Switch back to the correct current directory (prior to temporary path ! // switch) unless 'autochdir' is set, in which case it will already be ! // correct after the :drop command. With line breaks and spaces: ! // if !exists('+acd') || !&acd ! // if haslocaldir() ! // cd - ! // lcd - ! // elseif getcwd() ==# 'current path' ! // cd - ! // endif ! // endif ga_concat(&ga, (char_u *)":if !exists('+acd')||!&acd|if haslocaldir()|"); ga_concat(&ga, (char_u *)"cd -|lcd -|elseif getcwd() ==# '"); ga_concat(&ga, cdp); *************** *** 4282,4295 **** ga_concat(&ga, (char_u *)":"); if (inicmd != NULL) { ! /* Can't use after "inicmd", because an "startinsert" would cause ! * the following commands to be inserted as text. Use a "|", ! * hopefully "inicmd" does allow this... */ ga_concat(&ga, inicmd); ga_concat(&ga, (char_u *)"|"); } ! /* Bring the window to the foreground, goto Insert mode when 'im' set and ! * clear command line. */ ga_concat(&ga, (char_u *)"cal foreground()|if &im|star|en|redr|f"); ga_append(&ga, NUL); return ga.ga_data; --- 4280,4293 ---- ga_concat(&ga, (char_u *)":"); if (inicmd != NULL) { ! // Can't use after "inicmd", because an "startinsert" would cause ! // the following commands to be inserted as text. Use a "|", ! // hopefully "inicmd" does allow this... ga_concat(&ga, inicmd); ga_concat(&ga, (char_u *)"|"); } ! // Bring the window to the foreground, goto Insert mode when 'im' set and ! // clear command line. ga_concat(&ga, (char_u *)"cal foreground()|if &im|star|en|redr|f"); ga_append(&ga, NUL); return ga.ga_data; *************** *** 4310,4322 **** else { p = vim_strsave_up(gettail((char_u *)cmd)); ! /* Remove .exe or .bat from the name. */ if (p != NULL && vim_strchr(p, '.') != NULL) *vim_strchr(p, '.') = NUL; } return p; } ! #endif /* FEAT_CLIENTSERVER */ #if defined(FEAT_CLIENTSERVER) || defined(PROTO) /* --- 4308,4320 ---- else { p = vim_strsave_up(gettail((char_u *)cmd)); ! // Remove .exe or .bat from the name. if (p != NULL && vim_strchr(p, '.') != NULL) *vim_strchr(p, '.') = NUL; } return p; } ! #endif // FEAT_CLIENTSERVER #if defined(FEAT_CLIENTSERVER) || defined(PROTO) /* *************** *** 4328,4345 **** char_u *ptr = NULL; char_u *cpo_save = p_cpo; ! /* Set 'cpoptions' the way we want it. ! * B set - backslashes are *not* treated specially ! * k set - keycodes are *not* reverse-engineered ! * < unset - sequences *are* interpreted ! * The last but one parameter of replace_termcodes() is TRUE so that the ! * sequence is recognised - needed for a real backslash. ! */ p_cpo = (char_u *)"Bk"; str = replace_termcodes((char_u *)str, &ptr, REPTERM_DO_LT, NULL); p_cpo = cpo_save; ! if (*ptr != NUL) /* trailing CTRL-V results in nothing */ { /* * Add the string to the input stream. --- 4326,4342 ---- char_u *ptr = NULL; char_u *cpo_save = p_cpo; ! // Set 'cpoptions' the way we want it. ! // B set - backslashes are *not* treated specially ! // k set - keycodes are *not* reverse-engineered ! // < unset - sequences *are* interpreted ! // The last but one parameter of replace_termcodes() is TRUE so that the ! // sequence is recognised - needed for a real backslash. p_cpo = (char_u *)"Bk"; str = replace_termcodes((char_u *)str, &ptr, REPTERM_DO_LT, NULL); p_cpo = cpo_save; ! if (*ptr != NUL) // trailing CTRL-V results in nothing { /* * Add the string to the input stream. *************** *** 4353,4360 **** del_typebuf(typebuf.tb_len - typebuf.tb_maplen, typebuf.tb_maplen); (void)ins_typebuf(str, REMAP_NONE, typebuf.tb_len, TRUE, FALSE); ! /* Let input_available() know we inserted text in the typeahead ! * buffer. */ typebuf_was_filled = TRUE; } vim_free((char_u *)ptr); --- 4350,4357 ---- del_typebuf(typebuf.tb_len - typebuf.tb_maplen, typebuf.tb_maplen); (void)ins_typebuf(str, REMAP_NONE, typebuf.tb_len, TRUE, FALSE); ! // Let input_available() know we inserted text in the typeahead ! // buffer. typebuf_was_filled = TRUE; } vim_free((char_u *)ptr); *************** *** 4372,4391 **** funccal_entry_T funccal_entry; int did_save_funccal = FALSE; ! /* Evaluate the expression at the toplevel, don't use variables local to ! * the calling function. Except when in debug mode. */ if (!debug_mode) { save_funccal(&funccal_entry); did_save_funccal = TRUE; } ! /* Disable debugging, otherwise Vim hangs, waiting for "cont" to be ! * typed. */ debug_break_level = -1; redir_off = 0; ! /* Do not display error message, otherwise Vim hangs, waiting for "cont" ! * to be typed. Do generate errors so that try/catch works. */ ++emsg_silent; res = eval_to_string(expr, NULL, TRUE); --- 4369,4388 ---- funccal_entry_T funccal_entry; int did_save_funccal = FALSE; ! // Evaluate the expression at the toplevel, don't use variables local to ! // the calling function. Except when in debug mode. if (!debug_mode) { save_funccal(&funccal_entry); did_save_funccal = TRUE; } ! // Disable debugging, otherwise Vim hangs, waiting for "cont" to be ! // typed. debug_break_level = -1; redir_off = 0; ! // Do not display error message, otherwise Vim hangs, waiting for "cont" ! // to be typed. Do generate errors so that try/catch works. ++emsg_silent; res = eval_to_string(expr, NULL, TRUE); *************** *** 4398,4405 **** if (did_save_funccal) restore_funccal(); ! /* A client can tell us to redraw, but not to display the cursor, so do ! * that here. */ setcursor(); out_flush_cursor(FALSE, FALSE); --- 4395,4402 ---- if (did_save_funccal) restore_funccal(); ! // A client can tell us to redraw, but not to display the cursor, so do ! // that here. setcursor(); out_flush_cursor(FALSE, FALSE); *** ../vim-8.1.2387/src/mark.c 2019-09-19 23:21:48.233926270 +0200 --- src/mark.c 2019-12-04 21:47:10.294854814 +0100 *************** *** 24,30 **** * There are marks 'A - 'Z (set by user) and '0 to '9 (set when writing * viminfo). */ ! static xfmark_T namedfm[NMARKS + EXTRA_MARKS]; /* marks with file nr */ static void fname2fnum(xfmark_T *fm); static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf); --- 24,30 ---- * There are marks 'A - 'Z (set by user) and '0 to '9 (set when writing * viminfo). */ ! static xfmark_T namedfm[NMARKS + EXTRA_MARKS]; // marks with file nr static void fname2fnum(xfmark_T *fm); static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf); *************** *** 54,60 **** int i; buf_T *buf; ! /* Check for a special key (may cause islower() to crash). */ if (c < 0) return FAIL; --- 54,60 ---- int i; buf_T *buf; ! // Check for a special key (may cause islower() to crash). if (c < 0) return FAIL; *************** *** 63,69 **** if (pos == &curwin->w_cursor) { setpcmark(); ! /* keep it even when the cursor doesn't move */ curwin->w_prev_pcmark = curwin->w_pcmark; } else --- 63,69 ---- if (pos == &curwin->w_cursor) { setpcmark(); ! // keep it even when the cursor doesn't move curwin->w_prev_pcmark = curwin->w_pcmark; } else *************** *** 81,88 **** return OK; } ! /* Allow setting '[ and '] for an autocommand that simulates reading a ! * file. */ if (c == '[') { buf->b_op_start = *pos; --- 81,88 ---- return OK; } ! // Allow setting '[ and '] for an autocommand that simulates reading a ! // file. if (c == '[') { buf->b_op_start = *pos; *************** *** 101,107 **** else buf->b_visual.vi_end = *pos; if (buf->b_visual.vi_mode == NUL) ! /* Visual_mode has not yet been set, use a sane default. */ buf->b_visual.vi_mode = 'v'; return OK; } --- 101,107 ---- else buf->b_visual.vi_end = *pos; if (buf->b_visual.vi_mode == NUL) ! // Visual_mode has not yet been set, use a sane default. buf->b_visual.vi_mode = 'v'; return OK; } *************** *** 144,150 **** xfmark_T tempmark; #endif ! /* for :global the mark is set only once */ if (global_busy || listcmd_busy || cmdmod.keepjumps) return; --- 144,150 ---- xfmark_T tempmark; #endif ! // for :global the mark is set only once if (global_busy || listcmd_busy || cmdmod.keepjumps) return; *************** *** 170,176 **** } # endif ! /* If jumplist is full: remove oldest entry */ if (++curwin->w_jumplistlen > JUMPLISTSIZE) { curwin->w_jumplistlen = JUMPLISTSIZE; --- 170,176 ---- } # endif ! // If jumplist is full: remove oldest entry if (++curwin->w_jumplistlen > JUMPLISTSIZE) { curwin->w_jumplistlen = JUMPLISTSIZE; *************** *** 204,210 **** || curwin->w_pcmark.lnum == 0)) { curwin->w_pcmark = curwin->w_prev_pcmark; ! curwin->w_prev_pcmark.lnum = 0; /* Show it has been checked */ } } --- 204,210 ---- || curwin->w_pcmark.lnum == 0)) { curwin->w_pcmark = curwin->w_prev_pcmark; ! curwin->w_prev_pcmark.lnum = 0; // Show it has been checked } } *************** *** 220,226 **** cleanup_jumplist(curwin, TRUE); ! if (curwin->w_jumplistlen == 0) /* nothing to jump to */ return (pos_T *)NULL; for (;;) --- 220,226 ---- cleanup_jumplist(curwin, TRUE); ! if (curwin->w_jumplistlen == 0) // nothing to jump to return (pos_T *)NULL; for (;;) *************** *** 237,243 **** if (curwin->w_jumplistidx == curwin->w_jumplistlen) { setpcmark(); ! --curwin->w_jumplistidx; /* skip the new entry */ if (curwin->w_jumplistidx + count < 0) return (pos_T *)NULL; } --- 237,243 ---- if (curwin->w_jumplistidx == curwin->w_jumplistlen) { setpcmark(); ! --curwin->w_jumplistidx; // skip the new entry if (curwin->w_jumplistidx + count < 0) return (pos_T *)NULL; } *************** *** 249,264 **** fname2fnum(jmp); if (jmp->fmark.fnum != curbuf->b_fnum) { ! /* jump to other file */ if (buflist_findnr(jmp->fmark.fnum) == NULL) ! { /* Skip this one .. */ count += count < 0 ? -1 : 1; continue; } if (buflist_getfile(jmp->fmark.fnum, jmp->fmark.mark.lnum, 0, FALSE) == FAIL) return (pos_T *)NULL; ! /* Set lnum again, autocommands my have changed it */ curwin->w_cursor = jmp->fmark.mark; pos = (pos_T *)-1; } --- 249,264 ---- fname2fnum(jmp); if (jmp->fmark.fnum != curbuf->b_fnum) { ! // jump to other file if (buflist_findnr(jmp->fmark.fnum) == NULL) ! { // Skip this one .. count += count < 0 ? -1 : 1; continue; } if (buflist_getfile(jmp->fmark.fnum, jmp->fmark.mark.lnum, 0, FALSE) == FAIL) return (pos_T *)NULL; ! // Set lnum again, autocommands my have changed it curwin->w_cursor = jmp->fmark.mark; pos = (pos_T *)-1; } *************** *** 276,282 **** { int n; ! if (curbuf->b_changelistlen == 0) /* nothing to jump to */ return (pos_T *)NULL; n = curwin->w_changelistidx; --- 276,282 ---- { int n; ! if (curbuf->b_changelistlen == 0) // nothing to jump to return (pos_T *)NULL; n = curwin->w_changelistidx; *************** *** 335,372 **** posp = NULL; ! /* Check for special key, can't be a mark name and might cause islower() ! * to crash. */ if (c < 0) return posp; #ifndef EBCDIC ! if (c > '~') /* check for islower()/isupper() */ ; else #endif ! if (c == '\'' || c == '`') /* previous context mark */ { ! pos_copy = curwin->w_pcmark; /* need to make a copy because */ ! posp = &pos_copy; /* w_pcmark may be changed soon */ } ! else if (c == '"') /* to pos when leaving buffer */ posp = &(buf->b_last_cursor); ! else if (c == '^') /* to where Insert mode stopped */ posp = &(buf->b_last_insert); ! else if (c == '.') /* to where last change was made */ posp = &(buf->b_last_change); ! else if (c == '[') /* to start of previous operator */ posp = &(buf->b_op_start); ! else if (c == ']') /* to end of previous operator */ posp = &(buf->b_op_end); ! else if (c == '{' || c == '}') /* to previous/next paragraph */ { pos_T pos; oparg_T oa; int slcb = listcmd_busy; pos = curwin->w_cursor; ! listcmd_busy = TRUE; /* avoid that '' is changed */ if (findpar(&oa.inclusive, c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE)) { --- 335,372 ---- posp = NULL; ! // Check for special key, can't be a mark name and might cause islower() ! // to crash. if (c < 0) return posp; #ifndef EBCDIC ! if (c > '~') // check for islower()/isupper() ; else #endif ! if (c == '\'' || c == '`') // previous context mark { ! pos_copy = curwin->w_pcmark; // need to make a copy because ! posp = &pos_copy; // w_pcmark may be changed soon } ! else if (c == '"') // to pos when leaving buffer posp = &(buf->b_last_cursor); ! else if (c == '^') // to where Insert mode stopped posp = &(buf->b_last_insert); ! else if (c == '.') // to where last change was made posp = &(buf->b_last_change); ! else if (c == '[') // to start of previous operator posp = &(buf->b_op_start); ! else if (c == ']') // to end of previous operator posp = &(buf->b_op_end); ! else if (c == '{' || c == '}') // to previous/next paragraph { pos_T pos; oparg_T oa; int slcb = listcmd_busy; pos = curwin->w_cursor; ! listcmd_busy = TRUE; // avoid that '' is changed if (findpar(&oa.inclusive, c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE)) { *************** *** 376,388 **** curwin->w_cursor = pos; listcmd_busy = slcb; } ! else if (c == '(' || c == ')') /* to previous/next sentence */ { pos_T pos; int slcb = listcmd_busy; pos = curwin->w_cursor; ! listcmd_busy = TRUE; /* avoid that '' is changed */ if (findsent(c == ')' ? FORWARD : BACKWARD, 1L)) { pos_copy = curwin->w_cursor; --- 376,388 ---- curwin->w_cursor = pos; listcmd_busy = slcb; } ! else if (c == '(' || c == ')') // to previous/next sentence { pos_T pos; int slcb = listcmd_busy; pos = curwin->w_cursor; ! listcmd_busy = TRUE; // avoid that '' is changed if (findsent(c == ')' ? FORWARD : BACKWARD, 1L)) { pos_copy = curwin->w_cursor; *************** *** 391,397 **** curwin->w_cursor = pos; listcmd_busy = slcb; } ! else if (c == '<' || c == '>') /* start/end of visual area */ { startp = &buf->b_visual.vi_start; endp = &buf->b_visual.vi_end; --- 391,397 ---- curwin->w_cursor = pos; listcmd_busy = slcb; } ! else if (c == '<' || c == '>') // start/end of visual area { startp = &buf->b_visual.vi_start; endp = &buf->b_visual.vi_end; *************** *** 414,424 **** pos_copy.coladd = 0; } } ! else if (ASCII_ISLOWER(c)) /* normal named mark */ { posp = &(buf->b_namedm[c - 'a']); } ! else if (ASCII_ISUPPER(c) || VIM_ISDIGIT(c)) /* named file mark */ { if (VIM_ISDIGIT(c)) c = c - '0' + NMARKS; --- 414,424 ---- pos_copy.coladd = 0; } } ! else if (ASCII_ISLOWER(c)) // normal named mark { posp = &(buf->b_namedm[c - 'a']); } ! else if (ASCII_ISUPPER(c) || VIM_ISDIGIT(c)) // named file mark { if (VIM_ISDIGIT(c)) c = c - '0' + NMARKS; *************** *** 433,439 **** *fnum = namedfm[c].fmark.fnum; else if (namedfm[c].fmark.fnum != buf->b_fnum) { ! /* mark is in another file */ posp = &pos_copy; if (namedfm[c].fmark.mark.lnum != 0 --- 433,439 ---- *fnum = namedfm[c].fmark.fnum; else if (namedfm[c].fmark.fnum != buf->b_fnum) { ! // mark is in another file posp = &pos_copy; if (namedfm[c].fmark.mark.lnum != 0 *************** *** 442,456 **** if (buflist_getfile(namedfm[c].fmark.fnum, (linenr_T)1, GETF_SETMARK, FALSE) == OK) { ! /* Set the lnum now, autocommands could have changed it */ curwin->w_cursor = namedfm[c].fmark.mark; return (pos_T *)-1; } ! pos_copy.lnum = -1; /* can't get file */ } else ! pos_copy.lnum = 0; /* mark exists, but is not valid in ! current buffer */ } } --- 442,456 ---- if (buflist_getfile(namedfm[c].fmark.fnum, (linenr_T)1, GETF_SETMARK, FALSE) == OK) { ! // Set the lnum now, autocommands could have changed it curwin->w_cursor = namedfm[c].fmark.mark; return (pos_T *)-1; } ! pos_copy.lnum = -1; // can't get file } else ! pos_copy.lnum = 0; // mark exists, but is not valid in ! // current buffer } } *************** *** 464,471 **** */ pos_T * getnextmark( ! pos_T *startpos, /* where to start */ ! int dir, /* direction for search */ int begin_line) { int i; --- 464,471 ---- */ pos_T * getnextmark( ! pos_T *startpos, // where to start ! int dir, // direction for search int begin_line) { int i; *************** *** 474,483 **** pos = *startpos; ! /* When searching backward and leaving the cursor on the first non-blank, ! * position must be in a previous line. ! * When searching forward and leaving the cursor on the first non-blank, ! * position must be in a next line. */ if (dir == BACKWARD && begin_line) pos.col = 0; else if (dir == FORWARD && begin_line) --- 474,483 ---- pos = *startpos; ! // When searching backward and leaving the cursor on the first non-blank, ! // position must be in a previous line. ! // When searching forward and leaving the cursor on the first non-blank, ! // position must be in a next line. if (dir == BACKWARD && begin_line) pos.col = 0; else if (dir == FORWARD && begin_line) *************** *** 536,546 **** else vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1); ! /* Try to shorten the file name. */ mch_dirname(IObuff, IOSIZE); p = shorten_fname(NameBuff, IObuff); ! /* buflist_new() will call fmarks_check_names() */ (void)buflist_new(NameBuff, p, (linenr_T)1, 0); } } --- 536,546 ---- else vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1); ! // Try to shorten the file name. mch_dirname(IObuff, IOSIZE); p = shorten_fname(NameBuff, IObuff); ! // buflist_new() will call fmarks_check_names() (void)buflist_new(NameBuff, p, (linenr_T)1, 0); } } *************** *** 606,613 **** } if (pos->lnum <= 0) { ! /* lnum is negative if mark is in another file can can't get that ! * file, error message already give then. */ if (pos->lnum == 0) emsg(_(e_marknotset)); return FAIL; --- 606,613 ---- } if (pos->lnum <= 0) { ! // lnum is negative if mark is in another file can can't get that ! // file, error message already give then. if (pos->lnum == 0) emsg(_(e_marknotset)); return FAIL; *************** *** 630,636 **** { static int i = -1; ! if (i == -1) /* first call ever: initialize */ for (i = 0; i < NMARKS + 1; i++) { namedfm[i].fmark.mark.lnum = 0; --- 630,636 ---- { static int i = -1; ! if (i == -1) // first call ever: initialize for (i = 0; i < NMARKS + 1; i++) { namedfm[i].fmark.mark.lnum = 0; *************** *** 642,654 **** for (i = 0; i < NMARKS; i++) buf->b_namedm[i].lnum = 0; ! buf->b_op_start.lnum = 0; /* start/end op mark cleared */ buf->b_op_end.lnum = 0; ! buf->b_last_cursor.lnum = 1; /* '" mark cleared */ buf->b_last_cursor.col = 0; buf->b_last_cursor.coladd = 0; ! buf->b_last_insert.lnum = 0; /* '^ mark cleared */ ! buf->b_last_change.lnum = 0; /* '. mark cleared */ #ifdef FEAT_JUMPLIST buf->b_changelistlen = 0; #endif --- 642,654 ---- for (i = 0; i < NMARKS; i++) buf->b_namedm[i].lnum = 0; ! buf->b_op_start.lnum = 0; // start/end op mark cleared buf->b_op_end.lnum = 0; ! buf->b_last_cursor.lnum = 1; // '" mark cleared buf->b_last_cursor.col = 0; buf->b_last_cursor.coladd = 0; ! buf->b_last_insert.lnum = 0; // '^ mark cleared ! buf->b_last_change.lnum = 0; // '. mark cleared #ifdef FEAT_JUMPLIST buf->b_changelistlen = 0; #endif *************** *** 662,668 **** char_u * fm_getname(fmark_T *fmark, int lead_len) { ! if (fmark->fnum == curbuf->b_fnum) /* current buffer */ return mark_line(&(fmark->mark), lead_len); return buflist_nr2name(fmark->fnum, FALSE, TRUE); } --- 662,668 ---- char_u * fm_getname(fmark_T *fmark, int lead_len) { ! if (fmark->fnum == curbuf->b_fnum) // current buffer return mark_line(&(fmark->mark), lead_len); return buflist_nr2name(fmark->fnum, FALSE, TRUE); } *************** *** 742,754 **** char_u *arg, pos_T *p, char_u *name_arg, ! int current) /* in current file */ { static int did_title = FALSE; int mustfree = FALSE; char_u *name = name_arg; ! if (c == -1) /* finish up */ { if (did_title) did_title = FALSE; --- 742,754 ---- char_u *arg, pos_T *p, char_u *name_arg, ! int current) // in current file { static int did_title = FALSE; int mustfree = FALSE; char_u *name = name_arg; ! if (c == -1) // finish up { if (did_title) did_title = FALSE; *************** *** 809,815 **** int n; if (*eap->arg == NUL && eap->forceit) ! /* clear all marks */ clrallmarks(curbuf); else if (eap->forceit) emsg(_(e_invarg)); --- 809,815 ---- int n; if (*eap->arg == NUL && eap->forceit) ! // clear all marks clrallmarks(curbuf); else if (eap->forceit) emsg(_(e_invarg)); *************** *** 817,823 **** emsg(_(e_argreq)); else { ! /* clear specified marks only */ for (p = eap->arg; *p != NUL; ++p) { lower = ASCII_ISLOWER(*p); --- 817,823 ---- emsg(_(e_argreq)); else { ! // clear specified marks only for (p = eap->arg; *p != NUL; ++p) { lower = ASCII_ISLOWER(*p); *************** *** 826,832 **** { if (p[1] == '-') { ! /* clear range of marks */ from = *p; to = p[2]; if (!(lower ? ASCII_ISLOWER(p[2]) --- 826,832 ---- { if (p[1] == '-') { ! // clear range of marks from = *p; to = p[2]; if (!(lower ? ASCII_ISLOWER(p[2]) *************** *** 840,846 **** p += 2; } else ! /* clear one lower case mark */ from = to = *p; for (i = from; i <= to; ++i) --- 840,846 ---- p += 2; } else ! // clear one lower case mark from = to = *p; for (i = from; i <= to; ++i) *************** *** 891,897 **** cleanup_jumplist(curwin, TRUE); ! /* Highlight title */ msg_puts_title(_("\n jump line col file/text")); for (i = 0; i < curwin->w_jumplistlen && !got_int; ++i) { --- 891,897 ---- cleanup_jumplist(curwin, TRUE); ! // Highlight title msg_puts_title(_("\n jump line col file/text")); for (i = 0; i < curwin->w_jumplistlen && !got_int; ++i) { *************** *** 948,954 **** int i; char_u *name; ! /* Highlight title */ msg_puts_title(_("\nchange line col text")); for (i = 0; i < curbuf->b_changelistlen && !got_int; ++i) --- 948,954 ---- int i; char_u *name; ! // Highlight title msg_puts_title(_("\nchange line col text")); for (i = 0; i < curbuf->b_changelistlen && !got_int; ++i) *************** *** 993,999 **** *lp += amount_after; \ } ! /* don't delete the line, just put at first deleted line */ #define one_adjust_nodel(add) \ { \ lp = add; \ --- 993,999 ---- *lp += amount_after; \ } ! // don't delete the line, just put at first deleted line #define one_adjust_nodel(add) \ { \ lp = add; \ *************** *** 1054,1065 **** tabpage_T *tab; static pos_T initpos = {1, 0, 0}; ! if (line2 < line1 && amount_after == 0L) /* nothing to do */ return; if (!cmdmod.lockmarks) { ! /* named marks, lower case and upper case */ for (i = 0; i < NMARKS; i++) { one_adjust(&(curbuf->b_namedm[i].lnum)); --- 1054,1065 ---- tabpage_T *tab; static pos_T initpos = {1, 0, 0}; ! if (line2 < line1 && amount_after == 0L) // nothing to do return; if (!cmdmod.lockmarks) { ! // named marks, lower case and upper case for (i = 0; i < NMARKS; i++) { one_adjust(&(curbuf->b_namedm[i].lnum)); *************** *** 1072,1102 **** one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); } ! /* last Insert position */ one_adjust(&(curbuf->b_last_insert.lnum)); ! /* last change position */ one_adjust(&(curbuf->b_last_change.lnum)); ! /* last cursor position, if it was set */ if (!EQUAL_POS(curbuf->b_last_cursor, initpos)) one_adjust(&(curbuf->b_last_cursor.lnum)); #ifdef FEAT_JUMPLIST ! /* list of change positions */ for (i = 0; i < curbuf->b_changelistlen; ++i) one_adjust_nodel(&(curbuf->b_changelist[i].lnum)); #endif ! /* Visual area */ one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum)); one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum)); #ifdef FEAT_QUICKFIX ! /* quickfix marks */ qf_mark_adjust(NULL, line1, line2, amount, amount_after); ! /* location lists */ FOR_ALL_TAB_WINDOWS(tab, win) qf_mark_adjust(win, line1, line2, amount, amount_after); #endif --- 1072,1102 ---- one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); } ! // last Insert position one_adjust(&(curbuf->b_last_insert.lnum)); ! // last change position one_adjust(&(curbuf->b_last_change.lnum)); ! // last cursor position, if it was set if (!EQUAL_POS(curbuf->b_last_cursor, initpos)) one_adjust(&(curbuf->b_last_cursor.lnum)); #ifdef FEAT_JUMPLIST ! // list of change positions for (i = 0; i < curbuf->b_changelistlen; ++i) one_adjust_nodel(&(curbuf->b_changelist[i].lnum)); #endif ! // Visual area one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum)); one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum)); #ifdef FEAT_QUICKFIX ! // quickfix marks qf_mark_adjust(NULL, line1, line2, amount, amount_after); ! // location lists FOR_ALL_TAB_WINDOWS(tab, win) qf_mark_adjust(win, line1, line2, amount, amount_after); #endif *************** *** 1106,1118 **** #endif } ! /* previous context mark */ one_adjust(&(curwin->w_pcmark.lnum)); ! /* previous pcmark */ one_adjust(&(curwin->w_prev_pcmark.lnum)); ! /* saved cursor for formatting */ if (saved_cursor.lnum != 0) one_adjust_nodel(&(saved_cursor.lnum)); --- 1106,1118 ---- #endif } ! // previous context mark one_adjust(&(curwin->w_pcmark.lnum)); ! // previous pcmark one_adjust(&(curwin->w_prev_pcmark.lnum)); ! // saved cursor for formatting if (saved_cursor.lnum != 0) one_adjust_nodel(&(saved_cursor.lnum)); *************** *** 1123,1130 **** { #ifdef FEAT_JUMPLIST if (!cmdmod.lockmarks) ! /* Marks in the jumplist. When deleting lines, this may create ! * duplicate marks in the jumplist, they will be removed later. */ for (i = 0; i < win->w_jumplistlen; ++i) if (win->w_jumplist[i].fmark.fnum == fnum) one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum)); --- 1123,1130 ---- { #ifdef FEAT_JUMPLIST if (!cmdmod.lockmarks) ! // Marks in the jumplist. When deleting lines, this may create ! // duplicate marks in the jumplist, they will be removed later. for (i = 0; i < win->w_jumplistlen; ++i) if (win->w_jumplist[i].fmark.fnum == fnum) one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum)); *************** *** 1133,1164 **** if (win->w_buffer == curbuf) { if (!cmdmod.lockmarks) ! /* marks in the tag stack */ for (i = 0; i < win->w_tagstacklen; i++) if (win->w_tagstack[i].fmark.fnum == fnum) one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum)); ! /* the displayed Visual area */ if (win->w_old_cursor_lnum != 0) { one_adjust_nodel(&(win->w_old_cursor_lnum)); one_adjust_nodel(&(win->w_old_visual_lnum)); } ! /* topline and cursor position for windows with the same buffer ! * other than the current window */ if (win != curwin) { if (win->w_topline >= line1 && win->w_topline <= line2) { ! if (amount == MAXLNUM) /* topline is deleted */ { if (line1 <= 1) win->w_topline = 1; else win->w_topline = line1 - 1; } ! else /* keep topline on the same line */ win->w_topline += amount; #ifdef FEAT_DIFF win->w_topfill = 0; --- 1133,1164 ---- if (win->w_buffer == curbuf) { if (!cmdmod.lockmarks) ! // marks in the tag stack for (i = 0; i < win->w_tagstacklen; i++) if (win->w_tagstack[i].fmark.fnum == fnum) one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum)); ! // the displayed Visual area if (win->w_old_cursor_lnum != 0) { one_adjust_nodel(&(win->w_old_cursor_lnum)); one_adjust_nodel(&(win->w_old_visual_lnum)); } ! // topline and cursor position for windows with the same buffer ! // other than the current window if (win != curwin) { if (win->w_topline >= line1 && win->w_topline <= line2) { ! if (amount == MAXLNUM) // topline is deleted { if (line1 <= 1) win->w_topline = 1; else win->w_topline = line1 - 1; } ! else // keep topline on the same line win->w_topline += amount; #ifdef FEAT_DIFF win->w_topfill = 0; *************** *** 1173,1179 **** } if (win->w_cursor.lnum >= line1 && win->w_cursor.lnum <= line2) { ! if (amount == MAXLNUM) /* line with cursor is deleted */ { if (line1 <= 1) win->w_cursor.lnum = 1; --- 1173,1179 ---- } if (win->w_cursor.lnum >= line1 && win->w_cursor.lnum <= line2) { ! if (amount == MAXLNUM) // line with cursor is deleted { if (line1 <= 1) win->w_cursor.lnum = 1; *************** *** 1181,1187 **** win->w_cursor.lnum = line1 - 1; win->w_cursor.col = 0; } ! else /* keep cursor on the same line */ win->w_cursor.lnum += amount; } else if (amount_after && win->w_cursor.lnum > line2) --- 1181,1187 ---- win->w_cursor.lnum = line1 - 1; win->w_cursor.col = 0; } ! else // keep cursor on the same line win->w_cursor.lnum += amount; } else if (amount_after && win->w_cursor.lnum > line2) *************** *** 1189,1195 **** } #ifdef FEAT_FOLDING ! /* adjust folds */ if (adjust_folds) foldMarkAdjust(win, line1, line2, amount, amount_after); #endif --- 1189,1195 ---- } #ifdef FEAT_FOLDING ! // adjust folds if (adjust_folds) foldMarkAdjust(win, line1, line2, amount, amount_after); #endif *************** *** 1197,1208 **** } #ifdef FEAT_DIFF ! /* adjust diffs */ diff_mark_adjust(line1, line2, amount, amount_after); #endif } ! /* This code is used often, needs to be fast. */ #define col_adjust(pp) \ { \ posp = pp; \ --- 1197,1208 ---- } #ifdef FEAT_DIFF ! // adjust diffs diff_mark_adjust(line1, line2, amount, amount_after); #endif } ! // This code is used often, needs to be fast. #define col_adjust(pp) \ { \ posp = pp; \ *************** *** 1239,1247 **** pos_T *posp; if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks) ! return; /* nothing to do */ ! /* named marks, lower case and upper case */ for (i = 0; i < NMARKS; i++) { col_adjust(&(curbuf->b_namedm[i])); --- 1239,1247 ---- pos_T *posp; if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks) ! return; // nothing to do ! // named marks, lower case and upper case for (i = 0; i < NMARKS; i++) { col_adjust(&(curbuf->b_namedm[i])); *************** *** 1254,1282 **** col_adjust(&(namedfm[i].fmark.mark)); } ! /* last Insert position */ col_adjust(&(curbuf->b_last_insert)); ! /* last change position */ col_adjust(&(curbuf->b_last_change)); #ifdef FEAT_JUMPLIST ! /* list of change positions */ for (i = 0; i < curbuf->b_changelistlen; ++i) col_adjust(&(curbuf->b_changelist[i])); #endif ! /* Visual area */ col_adjust(&(curbuf->b_visual.vi_start)); col_adjust(&(curbuf->b_visual.vi_end)); ! /* previous context mark */ col_adjust(&(curwin->w_pcmark)); ! /* previous pcmark */ col_adjust(&(curwin->w_prev_pcmark)); ! /* saved cursor for formatting */ col_adjust(&saved_cursor); /* --- 1254,1282 ---- col_adjust(&(namedfm[i].fmark.mark)); } ! // last Insert position col_adjust(&(curbuf->b_last_insert)); ! // last change position col_adjust(&(curbuf->b_last_change)); #ifdef FEAT_JUMPLIST ! // list of change positions for (i = 0; i < curbuf->b_changelistlen; ++i) col_adjust(&(curbuf->b_changelist[i])); #endif ! // Visual area col_adjust(&(curbuf->b_visual.vi_start)); col_adjust(&(curbuf->b_visual.vi_end)); ! // previous context mark col_adjust(&(curwin->w_pcmark)); ! // previous pcmark col_adjust(&(curwin->w_prev_pcmark)); ! // saved cursor for formatting col_adjust(&saved_cursor); /* *************** *** 1285,1291 **** FOR_ALL_WINDOWS(win) { #ifdef FEAT_JUMPLIST ! /* marks in the jumplist */ for (i = 0; i < win->w_jumplistlen; ++i) if (win->w_jumplist[i].fmark.fnum == fnum) col_adjust(&(win->w_jumplist[i].fmark.mark)); --- 1285,1291 ---- FOR_ALL_WINDOWS(win) { #ifdef FEAT_JUMPLIST ! // marks in the jumplist for (i = 0; i < win->w_jumplistlen; ++i) if (win->w_jumplist[i].fmark.fnum == fnum) col_adjust(&(win->w_jumplist[i].fmark.mark)); *************** *** 1293,1304 **** if (win->w_buffer == curbuf) { ! /* marks in the tag stack */ for (i = 0; i < win->w_tagstacklen; i++) if (win->w_tagstack[i].fmark.fnum == fnum) col_adjust(&(win->w_tagstack[i].fmark.mark)); ! /* cursor position for other windows with the same buffer */ if (win != curwin) col_adjust(&win->w_cursor); } --- 1293,1304 ---- if (win->w_buffer == curbuf) { ! // marks in the tag stack for (i = 0; i < win->w_tagstacklen; i++) if (win->w_tagstack[i].fmark.fnum == fnum) col_adjust(&(win->w_tagstack[i].fmark.mark)); ! // cursor position for other windows with the same buffer if (win != curwin) col_adjust(&win->w_cursor); } *************** *** 1320,1328 **** if (loadfiles) { ! /* If specified, load all the files from the jump list. This is ! * needed to properly clean up duplicate entries, but will take some ! * time. */ for (i = 0; i < wp->w_jumplistlen; ++i) { if ((wp->w_jumplist[i].fmark.fnum == 0) && --- 1320,1328 ---- if (loadfiles) { ! // If specified, load all the files from the jump list. This is ! // needed to properly clean up duplicate entries, but will take some ! // time. for (i = 0; i < wp->w_jumplistlen; ++i) { if ((wp->w_jumplist[i].fmark.fnum == 0) && *************** *** 1343,1349 **** && wp->w_jumplist[i].fmark.mark.lnum == wp->w_jumplist[from].fmark.mark.lnum) break; ! if (i >= wp->w_jumplistlen) /* no duplicate */ wp->w_jumplist[to++] = wp->w_jumplist[from]; else vim_free(wp->w_jumplist[from].fname); --- 1343,1349 ---- && wp->w_jumplist[i].fmark.mark.lnum == wp->w_jumplist[from].fmark.mark.lnum) break; ! if (i >= wp->w_jumplistlen) // no duplicate wp->w_jumplist[to++] = wp->w_jumplist[from]; else vim_free(wp->w_jumplist[from].fname); *************** *** 1382,1388 **** for (i = 0; i < wp->w_jumplistlen; ++i) vim_free(wp->w_jumplist[i].fname); } ! #endif /* FEAT_JUMPLIST */ void set_last_cursor(win_T *win) --- 1382,1388 ---- for (i = 0; i < wp->w_jumplistlen; ++i) vim_free(wp->w_jumplist[i].fname); } ! #endif // FEAT_JUMPLIST void set_last_cursor(win_T *win) *** ../vim-8.1.2387/src/mbyte.c 2019-11-29 23:15:22.116220569 +0100 --- src/mbyte.c 2019-12-04 21:50:22.758230227 +0100 *************** *** 91,97 **** # define WINBYTE BYTE # endif # ifdef WIN32 ! # undef WIN32 /* Some windows.h define WIN32, we don't want that here. */ # endif #else # define WINBYTE BYTE --- 91,97 ---- # define WINBYTE BYTE # endif # ifdef WIN32 ! # undef WIN32 // Some windows.h define WIN32, we don't want that here. # endif #else # define WINBYTE BYTE *************** *** 129,136 **** #endif #if 0 ! /* This has been disabled, because several people reported problems with the ! * wcwidth() and iswprint() library functions, esp. for Hebrew. */ # ifdef __STDC_ISO_10646__ # define USE_WCHAR_FUNCTIONS # endif --- 129,136 ---- #endif #if 0 ! // This has been disabled, because several people reported problems with the ! // wcwidth() and iswprint() library functions, esp. for Hebrew. # ifdef __STDC_ISO_10646__ # define USE_WCHAR_FUNCTIONS # endif *************** *** 183,189 **** * XIM often causes trouble. Define XIM_DEBUG to get a log of XIM callbacks * in the "xim.log" file. */ ! /* #define XIM_DEBUG */ #ifdef XIM_DEBUG static void xim_log(char *s, ...) --- 183,189 ---- * XIM often causes trouble. Define XIM_DEBUG to get a log of XIM callbacks * in the "xim.log" file. */ ! // #define XIM_DEBUG #ifdef XIM_DEBUG static void xim_log(char *s, ...) *************** *** 266,272 **** #define IDX_UCS4LE 22 {"ucs-4le", ENC_UNICODE + ENC_ENDIAN_L + ENC_4BYTE, 0}, ! /* For debugging DBCS encoding on Unix. */ #define IDX_DEBUG 23 {"debug", ENC_DBCS, DBCS_DEBUG}, #define IDX_EUC_JP 24 --- 266,272 ---- #define IDX_UCS4LE 22 {"ucs-4le", ENC_UNICODE + ENC_ENDIAN_L + ENC_4BYTE, 0}, ! // For debugging DBCS encoding on Unix. #define IDX_DEBUG 23 {"debug", ENC_DBCS, DBCS_DEBUG}, #define IDX_EUC_JP 24 *************** *** 282,320 **** #define IDX_BIG5 29 {"big5", ENC_DBCS, DBCS_CHT}, ! /* MS-DOS and MS-Windows codepages are included here, so that they can be ! * used on Unix too. Most of them are similar to ISO-8859 encodings, but ! * not exactly the same. */ #define IDX_CP437 30 ! {"cp437", ENC_8BIT, 437}, /* like iso-8859-1 */ #define IDX_CP737 31 ! {"cp737", ENC_8BIT, 737}, /* like iso-8859-7 */ #define IDX_CP775 32 ! {"cp775", ENC_8BIT, 775}, /* Baltic */ #define IDX_CP850 33 ! {"cp850", ENC_8BIT, 850}, /* like iso-8859-4 */ #define IDX_CP852 34 ! {"cp852", ENC_8BIT, 852}, /* like iso-8859-1 */ #define IDX_CP855 35 ! {"cp855", ENC_8BIT, 855}, /* like iso-8859-2 */ #define IDX_CP857 36 ! {"cp857", ENC_8BIT, 857}, /* like iso-8859-5 */ #define IDX_CP860 37 ! {"cp860", ENC_8BIT, 860}, /* like iso-8859-9 */ #define IDX_CP861 38 ! {"cp861", ENC_8BIT, 861}, /* like iso-8859-1 */ #define IDX_CP862 39 ! {"cp862", ENC_8BIT, 862}, /* like iso-8859-1 */ #define IDX_CP863 40 ! {"cp863", ENC_8BIT, 863}, /* like iso-8859-8 */ #define IDX_CP865 41 ! {"cp865", ENC_8BIT, 865}, /* like iso-8859-1 */ #define IDX_CP866 42 ! {"cp866", ENC_8BIT, 866}, /* like iso-8859-5 */ #define IDX_CP869 43 ! {"cp869", ENC_8BIT, 869}, /* like iso-8859-7 */ #define IDX_CP874 44 ! {"cp874", ENC_8BIT, 874}, /* Thai */ #define IDX_CP932 45 {"cp932", ENC_DBCS, DBCS_JPN}, #define IDX_CP936 46 --- 282,320 ---- #define IDX_BIG5 29 {"big5", ENC_DBCS, DBCS_CHT}, ! // MS-DOS and MS-Windows codepages are included here, so that they can be ! // used on Unix too. Most of them are similar to ISO-8859 encodings, but ! // not exactly the same. #define IDX_CP437 30 ! {"cp437", ENC_8BIT, 437}, // like iso-8859-1 #define IDX_CP737 31 ! {"cp737", ENC_8BIT, 737}, // like iso-8859-7 #define IDX_CP775 32 ! {"cp775", ENC_8BIT, 775}, // Baltic #define IDX_CP850 33 ! {"cp850", ENC_8BIT, 850}, // like iso-8859-4 #define IDX_CP852 34 ! {"cp852", ENC_8BIT, 852}, // like iso-8859-1 #define IDX_CP855 35 ! {"cp855", ENC_8BIT, 855}, // like iso-8859-2 #define IDX_CP857 36 ! {"cp857", ENC_8BIT, 857}, // like iso-8859-5 #define IDX_CP860 37 ! {"cp860", ENC_8BIT, 860}, // like iso-8859-9 #define IDX_CP861 38 ! {"cp861", ENC_8BIT, 861}, // like iso-8859-1 #define IDX_CP862 39 ! {"cp862", ENC_8BIT, 862}, // like iso-8859-1 #define IDX_CP863 40 ! {"cp863", ENC_8BIT, 863}, // like iso-8859-8 #define IDX_CP865 41 ! {"cp865", ENC_8BIT, 865}, // like iso-8859-1 #define IDX_CP866 42 ! {"cp866", ENC_8BIT, 866}, // like iso-8859-5 #define IDX_CP869 43 ! {"cp869", ENC_8BIT, 869}, // like iso-8859-7 #define IDX_CP874 44 ! {"cp874", ENC_8BIT, 874}, // Thai #define IDX_CP932 45 {"cp932", ENC_DBCS, DBCS_JPN}, #define IDX_CP936 46 *************** *** 324,352 **** #define IDX_CP950 48 {"cp950", ENC_DBCS, DBCS_CHT}, #define IDX_CP1250 49 ! {"cp1250", ENC_8BIT, 1250}, /* Czech, Polish, etc. */ #define IDX_CP1251 50 ! {"cp1251", ENC_8BIT, 1251}, /* Cyrillic */ ! /* cp1252 is considered to be equal to latin1 */ #define IDX_CP1253 51 ! {"cp1253", ENC_8BIT, 1253}, /* Greek */ #define IDX_CP1254 52 ! {"cp1254", ENC_8BIT, 1254}, /* Turkish */ #define IDX_CP1255 53 ! {"cp1255", ENC_8BIT, 1255}, /* Hebrew */ #define IDX_CP1256 54 ! {"cp1256", ENC_8BIT, 1256}, /* Arabic */ #define IDX_CP1257 55 ! {"cp1257", ENC_8BIT, 1257}, /* Baltic */ #define IDX_CP1258 56 ! {"cp1258", ENC_8BIT, 1258}, /* Vietnamese */ #define IDX_MACROMAN 57 ! {"macroman", ENC_8BIT + ENC_MACROMAN, 0}, /* Mac OS */ #define IDX_DECMCS 58 ! {"dec-mcs", ENC_8BIT, 0}, /* DEC MCS */ #define IDX_HPROMAN8 59 ! {"hp-roman8", ENC_8BIT, 0}, /* HP Roman8 */ #define IDX_COUNT 60 }; --- 324,352 ---- #define IDX_CP950 48 {"cp950", ENC_DBCS, DBCS_CHT}, #define IDX_CP1250 49 ! {"cp1250", ENC_8BIT, 1250}, // Czech, Polish, etc. #define IDX_CP1251 50 ! {"cp1251", ENC_8BIT, 1251}, // Cyrillic ! // cp1252 is considered to be equal to latin1 #define IDX_CP1253 51 ! {"cp1253", ENC_8BIT, 1253}, // Greek #define IDX_CP1254 52 ! {"cp1254", ENC_8BIT, 1254}, // Turkish #define IDX_CP1255 53 ! {"cp1255", ENC_8BIT, 1255}, // Hebrew #define IDX_CP1256 54 ! {"cp1256", ENC_8BIT, 1256}, // Arabic #define IDX_CP1257 55 ! {"cp1257", ENC_8BIT, 1257}, // Baltic #define IDX_CP1258 56 ! {"cp1258", ENC_8BIT, 1258}, // Vietnamese #define IDX_MACROMAN 57 ! {"macroman", ENC_8BIT + ENC_MACROMAN, 0}, // Mac OS #define IDX_DECMCS 58 ! {"dec-mcs", ENC_8BIT, 0}, // DEC MCS #define IDX_HPROMAN8 59 ! {"hp-roman8", ENC_8BIT, 0}, // HP Roman8 #define IDX_COUNT 60 }; *************** *** 371,380 **** {"hebrew", IDX_ISO_8}, #endif {"latin5", IDX_ISO_9}, ! {"turkish", IDX_ISO_9}, /* ? */ {"latin6", IDX_ISO_10}, ! {"nordic", IDX_ISO_10}, /* ? */ ! {"thai", IDX_ISO_11}, /* ? */ {"latin7", IDX_ISO_13}, {"latin8", IDX_ISO_14}, {"latin9", IDX_ISO_15}, --- 371,380 ---- {"hebrew", IDX_ISO_8}, #endif {"latin5", IDX_ISO_9}, ! {"turkish", IDX_ISO_9}, // ? {"latin6", IDX_ISO_10}, ! {"nordic", IDX_ISO_10}, // ? ! {"thai", IDX_ISO_11}, // ? {"latin7", IDX_ISO_13}, {"latin8", IDX_ISO_14}, {"latin9", IDX_ISO_15}, *************** *** 407,415 **** {"unix-jis", IDX_EUC_JP}, {"ujis", IDX_EUC_JP}, {"shift-jis", IDX_SJIS}, ! {"pck", IDX_SJIS}, /* Sun: PCK */ {"euckr", IDX_EUC_KR}, ! {"5601", IDX_EUC_KR}, /* Sun: KS C 5601 */ {"euccn", IDX_EUC_CN}, {"gb2312", IDX_EUC_CN}, {"euctw", IDX_EUC_TW}, --- 407,415 ---- {"unix-jis", IDX_EUC_JP}, {"ujis", IDX_EUC_JP}, {"shift-jis", IDX_SJIS}, ! {"pck", IDX_SJIS}, // Sun: PCK {"euckr", IDX_EUC_KR}, ! {"5601", IDX_EUC_KR}, // Sun: KS C 5601 {"euccn", IDX_EUC_CN}, {"gb2312", IDX_EUC_CN}, {"euctw", IDX_EUC_TW}, *************** *** 435,441 **** }; #ifndef CP_UTF8 ! # define CP_UTF8 65001 /* magic number from winnls.h */ #endif /* --- 435,441 ---- }; #ifndef CP_UTF8 ! # define CP_UTF8 65001 // magic number from winnls.h #endif /* *************** *** 471,484 **** { CPINFO cpinfo; ! /* Get info on this codepage to find out what it is. */ if (GetCPInfo(atoi((char *)name + 2), &cpinfo) != 0) { ! if (cpinfo.MaxCharSize == 1) /* some single-byte encoding */ return ENC_8BIT; if (cpinfo.MaxCharSize == 2 && (cpinfo.LeadByte[0] != 0 || cpinfo.LeadByte[1] != 0)) ! /* must be a DBCS encoding */ return ENC_DBCS; } return 0; --- 471,484 ---- { CPINFO cpinfo; ! // Get info on this codepage to find out what it is. if (GetCPInfo(atoi((char *)name + 2), &cpinfo) != 0) { ! if (cpinfo.MaxCharSize == 1) // some single-byte encoding return ENC_8BIT; if (cpinfo.MaxCharSize == 2 && (cpinfo.LeadByte[0] != 0 || cpinfo.LeadByte[1] != 0)) ! // must be a DBCS encoding return ENC_DBCS; } return 0; *************** *** 519,525 **** if (p_enc == NULL) { ! /* Just starting up: set the whole table to one's. */ for (i = 0; i < 256; ++i) mb_bytelen_tab[i] = 1; input_conv.vc_type = CONV_NONE; --- 519,525 ---- if (p_enc == NULL) { ! // Just starting up: set the whole table to one's. for (i = 0; i < 256; ++i) mb_bytelen_tab[i] = 1; input_conv.vc_type = CONV_NONE; *************** *** 533,551 **** { CPINFO cpinfo; ! /* Get info on this codepage to find out what it is. */ if (GetCPInfo(atoi((char *)p_enc + 2), &cpinfo) != 0) { if (cpinfo.MaxCharSize == 1) { ! /* some single-byte encoding */ enc_unicode = 0; enc_utf8 = FALSE; } else if (cpinfo.MaxCharSize == 2 && (cpinfo.LeadByte[0] != 0 || cpinfo.LeadByte[1] != 0)) { ! /* must be a DBCS encoding, check below */ enc_dbcs_new = atoi((char *)p_enc + 2); } else --- 533,551 ---- { CPINFO cpinfo; ! // Get info on this codepage to find out what it is. if (GetCPInfo(atoi((char *)p_enc + 2), &cpinfo) != 0) { if (cpinfo.MaxCharSize == 1) { ! // some single-byte encoding enc_unicode = 0; enc_utf8 = FALSE; } else if (cpinfo.MaxCharSize == 2 && (cpinfo.LeadByte[0] != 0 || cpinfo.LeadByte[1] != 0)) { ! // must be a DBCS encoding, check below enc_dbcs_new = atoi((char *)p_enc + 2); } else *************** *** 561,579 **** else if (STRNCMP(p_enc, "8bit-", 5) == 0 || STRNCMP(p_enc, "iso-8859-", 9) == 0) { ! /* Accept any "8bit-" or "iso-8859-" name. */ enc_unicode = 0; enc_utf8 = FALSE; } else if (STRNCMP(p_enc, "2byte-", 6) == 0) { #ifdef MSWIN ! /* Windows: accept only valid codepage numbers, check below. */ if (p_enc[6] != 'c' || p_enc[7] != 'p' || (enc_dbcs_new = atoi((char *)p_enc + 8)) == 0) return e_invarg; #else ! /* Unix: accept any "2byte-" name, assume current locale. */ enc_dbcs_new = DBCS_2BYTE; #endif } --- 561,579 ---- else if (STRNCMP(p_enc, "8bit-", 5) == 0 || STRNCMP(p_enc, "iso-8859-", 9) == 0) { ! // Accept any "8bit-" or "iso-8859-" name. enc_unicode = 0; enc_utf8 = FALSE; } else if (STRNCMP(p_enc, "2byte-", 6) == 0) { #ifdef MSWIN ! // Windows: accept only valid codepage numbers, check below. if (p_enc[6] != 'c' || p_enc[7] != 'p' || (enc_dbcs_new = atoi((char *)p_enc + 8)) == 0) return e_invarg; #else ! // Unix: accept any "2byte-" name, assume current locale. enc_dbcs_new = DBCS_2BYTE; #endif } *************** *** 582,588 **** i = enc_canon_table[idx].prop; if (i & ENC_UNICODE) { ! /* Unicode */ enc_utf8 = TRUE; if (i & (ENC_2BYTE | ENC_2WORD)) enc_unicode = 2; --- 582,588 ---- i = enc_canon_table[idx].prop; if (i & ENC_UNICODE) { ! // Unicode enc_utf8 = TRUE; if (i & (ENC_2BYTE | ENC_2WORD)) enc_unicode = 2; *************** *** 593,615 **** } else if (i & ENC_DBCS) { ! /* 2byte, handle below */ enc_dbcs_new = enc_canon_table[idx].codepage; } else { ! /* Must be 8-bit. */ enc_unicode = 0; enc_utf8 = FALSE; } } ! else /* Don't know what encoding this is, reject it. */ return e_invarg; if (enc_dbcs_new != 0) { #ifdef MSWIN ! /* Check if the DBCS code page is OK. */ if (!IsValidCodePage(enc_dbcs_new)) goto codepage_invalid; #endif --- 593,615 ---- } else if (i & ENC_DBCS) { ! // 2byte, handle below enc_dbcs_new = enc_canon_table[idx].codepage; } else { ! // Must be 8-bit. enc_unicode = 0; enc_utf8 = FALSE; } } ! else // Don't know what encoding this is, reject it. return e_invarg; if (enc_dbcs_new != 0) { #ifdef MSWIN ! // Check if the DBCS code page is OK. if (!IsValidCodePage(enc_dbcs_new)) goto codepage_invalid; #endif *************** *** 624,630 **** enc_latin9 = (STRCMP(p_enc, "iso-8859-15") == 0); #endif ! /* Detect an encoding that uses latin1 characters. */ enc_latin1like = (enc_utf8 || STRCMP(p_enc, "latin1") == 0 || STRCMP(p_enc, "iso-8859-15") == 0); --- 624,630 ---- enc_latin9 = (STRCMP(p_enc, "iso-8859-15") == 0); #endif ! // Detect an encoding that uses latin1 characters. enc_latin1like = (enc_utf8 || STRCMP(p_enc, "latin1") == 0 || STRCMP(p_enc, "iso-8859-15") == 0); *************** *** 675,682 **** * Fill the mb_bytelen_tab[] for MB_BYTE2LEN(). */ #ifdef LEN_FROM_CONV ! /* When 'encoding' is different from the current locale mblen() won't ! * work. Use conversion to "utf-8" instead. */ vimconv.vc_type = CONV_NONE; if (enc_dbcs) { --- 675,682 ---- * Fill the mb_bytelen_tab[] for MB_BYTE2LEN(). */ #ifdef LEN_FROM_CONV ! // When 'encoding' is different from the current locale mblen() won't ! // work. Use conversion to "utf-8" instead. vimconv.vc_type = CONV_NONE; if (enc_dbcs) { *************** *** 692,699 **** for (i = 0; i < 256; ++i) { ! /* Our own function to reliably check the length of UTF-8 characters, ! * independent of mblen(). */ if (enc_utf8) n = utf8len_tab[i]; else if (enc_dbcs == 0) --- 692,699 ---- for (i = 0; i < 256; ++i) { ! // Our own function to reliably check the length of UTF-8 characters, ! // independent of mblen(). if (enc_utf8) n = utf8len_tab[i]; else if (enc_dbcs == 0) *************** *** 701,709 **** else { #if defined(MSWIN) || defined(WIN32UNIX) ! /* enc_dbcs is set by setting 'fileencoding'. It becomes a Windows ! * CodePage identifier, which we can pass directly in to Windows ! * API */ n = IsDBCSLeadByteEx(enc_dbcs, (WINBYTE)i) ? 2 : 1; #else # if defined(__amigaos4__) || defined(__ANDROID__) || \ --- 701,709 ---- else { #if defined(MSWIN) || defined(WIN32UNIX) ! // enc_dbcs is set by setting 'fileencoding'. It becomes a Windows ! // CodePage identifier, which we can pass directly in to Windows ! // API n = IsDBCSLeadByteEx(enc_dbcs, (WINBYTE)i) ? 2 : 1; #else # if defined(__amigaos4__) || defined(__ANDROID__) || \ *************** *** 717,723 **** # else char buf[MB_MAXBYTES + 1]; ! if (i == NUL) /* just in case mblen() can't handle "" */ n = 1; else { --- 717,723 ---- # else char buf[MB_MAXBYTES + 1]; ! if (i == NUL) // just in case mblen() can't handle "" n = 1; else { *************** *** 766,802 **** convert_setup(&vimconv, NULL, NULL); #endif ! /* The cell width depends on the type of multi-byte characters. */ (void)init_chartab(); ! /* When enc_utf8 is set or reset, (de)allocate ScreenLinesUC[] */ screenalloc(FALSE); ! /* When using Unicode, set default for 'fileencodings'. */ if (enc_utf8 && !option_was_set((char_u *)"fencs")) set_string_option_direct((char_u *)"fencs", -1, (char_u *)"ucs-bom,utf-8,default,latin1", OPT_FREE, 0); #if defined(HAVE_BIND_TEXTDOMAIN_CODESET) && defined(FEAT_GETTEXT) ! /* GNU gettext 0.10.37 supports this feature: set the codeset used for ! * translated messages independently from the current locale. */ (void)bind_textdomain_codeset(VIMPACKAGE, enc_utf8 ? "utf-8" : (char *)p_enc); #endif #ifdef MSWIN ! /* When changing 'encoding' while starting up, then convert the command ! * line arguments from the active codepage to 'encoding'. */ if (starting != 0) fix_arg_enc(); #endif ! /* Fire an autocommand to let people do custom font setup. This must be ! * after Vim has been setup for the new encoding. */ apply_autocmds(EVENT_ENCODINGCHANGED, NULL, (char_u *)"", FALSE, curbuf); #ifdef FEAT_SPELL ! /* Need to reload spell dictionaries */ spell_reload(); #endif --- 766,802 ---- convert_setup(&vimconv, NULL, NULL); #endif ! // The cell width depends on the type of multi-byte characters. (void)init_chartab(); ! // When enc_utf8 is set or reset, (de)allocate ScreenLinesUC[] screenalloc(FALSE); ! // When using Unicode, set default for 'fileencodings'. if (enc_utf8 && !option_was_set((char_u *)"fencs")) set_string_option_direct((char_u *)"fencs", -1, (char_u *)"ucs-bom,utf-8,default,latin1", OPT_FREE, 0); #if defined(HAVE_BIND_TEXTDOMAIN_CODESET) && defined(FEAT_GETTEXT) ! // GNU gettext 0.10.37 supports this feature: set the codeset used for ! // translated messages independently from the current locale. (void)bind_textdomain_codeset(VIMPACKAGE, enc_utf8 ? "utf-8" : (char *)p_enc); #endif #ifdef MSWIN ! // When changing 'encoding' while starting up, then convert the command ! // line arguments from the active codepage to 'encoding'. if (starting != 0) fix_arg_enc(); #endif ! // Fire an autocommand to let people do custom font setup. This must be ! // after Vim has been setup for the new encoding. apply_autocmds(EVENT_ENCODINGCHANGED, NULL, (char_u *)"", FALSE, curbuf); #ifdef FEAT_SPELL ! // Need to reload spell dictionaries spell_reload(); #endif *************** *** 900,917 **** { switch (enc_dbcs) { ! /* please add classify routine for your language in here */ ! case DBCS_JPNU: /* ? */ case DBCS_JPN: { ! /* JIS code classification */ unsigned char lb = lead; unsigned char tb = trail; ! /* convert process code to JIS */ # if defined(MSWIN) || defined(WIN32UNIX) || defined(MACOS_X) ! /* process code is SJIS */ if (lb <= 0x9f) lb = (lb - 0x81) * 2 + 0x21; else --- 900,917 ---- { switch (enc_dbcs) { ! // please add classify routine for your language in here ! case DBCS_JPNU: // ? case DBCS_JPN: { ! // JIS code classification unsigned char lb = lead; unsigned char tb = trail; ! // convert process code to JIS # if defined(MSWIN) || defined(WIN32UNIX) || defined(MACOS_X) ! // process code is SJIS if (lb <= 0x9f) lb = (lb - 0x81) * 2 + 0x21; else *************** *** 935,992 **** * process code in most system because it uses * escape sequences(JIS is context depend encoding). */ ! /* assume process code is JAPANESE-EUC */ lb &= 0x7f; tb &= 0x7f; # endif ! /* exceptions */ switch (lb << 8 | tb) { ! case 0x2121: /* ZENKAKU space */ return 0; ! case 0x2122: /* TOU-TEN (Japanese comma) */ ! case 0x2123: /* KU-TEN (Japanese period) */ ! case 0x2124: /* ZENKAKU comma */ ! case 0x2125: /* ZENKAKU period */ return 1; ! case 0x213c: /* prolongedsound handled as KATAKANA */ return 13; } ! /* sieved by KU code */ switch (lb) { case 0x21: case 0x22: ! /* special symbols */ return 10; case 0x23: ! /* alpha-numeric */ return 11; case 0x24: ! /* hiragana */ return 12; case 0x25: ! /* katakana */ return 13; case 0x26: ! /* greek */ return 14; case 0x27: ! /* russian */ return 15; case 0x28: ! /* lines */ return 16; default: ! /* kanji */ return 17; } } ! case DBCS_KORU: /* ? */ case DBCS_KOR: { ! /* KS code classification */ unsigned char c1 = lead; unsigned char c2 = trail; --- 935,992 ---- * process code in most system because it uses * escape sequences(JIS is context depend encoding). */ ! // assume process code is JAPANESE-EUC lb &= 0x7f; tb &= 0x7f; # endif ! // exceptions switch (lb << 8 | tb) { ! case 0x2121: // ZENKAKU space return 0; ! case 0x2122: // TOU-TEN (Japanese comma) ! case 0x2123: // KU-TEN (Japanese period) ! case 0x2124: // ZENKAKU comma ! case 0x2125: // ZENKAKU period return 1; ! case 0x213c: // prolongedsound handled as KATAKANA return 13; } ! // sieved by KU code switch (lb) { case 0x21: case 0x22: ! // special symbols return 10; case 0x23: ! // alpha-numeric return 11; case 0x24: ! // hiragana return 12; case 0x25: ! // katakana return 13; case 0x26: ! // greek return 14; case 0x27: ! // russian return 15; case 0x28: ! // lines return 16; default: ! // kanji return 17; } } ! case DBCS_KORU: // ? case DBCS_KOR: { ! // KS code classification unsigned char c1 = lead; unsigned char c2 = trail; *************** *** 1005,1060 **** */ if (c1 >= 0xB0 && c1 <= 0xC8) ! /* Hangul */ return 20; #if defined(MSWIN) || defined(WIN32UNIX) else if (c1 <= 0xA0 || c2 <= 0xA0) ! /* Extended Hangul Region : MS UHC(Unified Hangul Code) */ ! /* c1: 0x81-0xA0 with c2: 0x41-0x5A, 0x61-0x7A, 0x81-0xFE ! * c1: 0xA1-0xC6 with c2: 0x41-0x5A, 0x61-0x7A, 0x81-0xA0 ! */ return 20; #endif else if (c1 >= 0xCA && c1 <= 0xFD) ! /* Hanja */ return 21; else switch (c1) { case 0xA1: case 0xA2: ! /* Symbols */ return 22; case 0xA3: ! /* Alpha-numeric */ return 23; case 0xA4: ! /* Hangul Letter(Alphabet) */ return 24; case 0xA5: ! /* Roman Numeral/Greek Letter */ return 25; case 0xA6: ! /* Box Drawings */ return 26; case 0xA7: ! /* Unit Symbols */ return 27; case 0xA8: case 0xA9: if (c2 <= 0xAF) ! return 25; /* Roman Letter */ else if (c2 >= 0xF6) ! return 22; /* Symbols */ else ! /* Circled/Parenthesized Letter */ return 28; case 0xAA: case 0xAB: ! /* Hiragana/Katakana */ return 29; case 0xAC: ! /* Cyrillic Letter */ return 30; } } --- 1005,1059 ---- */ if (c1 >= 0xB0 && c1 <= 0xC8) ! // Hangul return 20; #if defined(MSWIN) || defined(WIN32UNIX) else if (c1 <= 0xA0 || c2 <= 0xA0) ! // Extended Hangul Region : MS UHC(Unified Hangul Code) ! // c1: 0x81-0xA0 with c2: 0x41-0x5A, 0x61-0x7A, 0x81-0xFE ! // c1: 0xA1-0xC6 with c2: 0x41-0x5A, 0x61-0x7A, 0x81-0xA0 return 20; #endif else if (c1 >= 0xCA && c1 <= 0xFD) ! // Hanja return 21; else switch (c1) { case 0xA1: case 0xA2: ! // Symbols return 22; case 0xA3: ! // Alpha-numeric return 23; case 0xA4: ! // Hangul Letter(Alphabet) return 24; case 0xA5: ! // Roman Numeral/Greek Letter return 25; case 0xA6: ! // Box Drawings return 26; case 0xA7: ! // Unit Symbols return 27; case 0xA8: case 0xA9: if (c2 <= 0xAF) ! return 25; // Roman Letter else if (c2 >= 0xF6) ! return 22; // Symbols else ! // Circled/Parenthesized Letter return 28; case 0xAA: case 0xAB: ! // Hiragana/Katakana return 29; case 0xAC: ! // Cyrillic Letter return 30; } } *************** *** 1103,1110 **** { buf[0] = (unsigned)c >> 8; buf[1] = c; ! /* Never use a NUL byte, it causes lots of trouble. It's an invalid ! * character anyway. */ if (buf[1] == NUL) buf[1] = '\n'; return 2; --- 1102,1109 ---- { buf[0] = (unsigned)c >> 8; buf[1] = c; ! // Never use a NUL byte, it causes lots of trouble. It's an invalid ! // character anyway. if (buf[1] == NUL) buf[1] = '\n'; return 2; *************** *** 1131,1137 **** { int len; ! /* Check if second byte is not missing. */ len = MB_BYTE2LEN(*p); if (len == 2 && p[1] == NUL) len = 1; --- 1130,1136 ---- { int len; ! // Check if second byte is not missing. len = MB_BYTE2LEN(*p); if (len == 2 && p[1] == NUL) len = 1; *************** *** 1161,1167 **** return 0; if (size == 1) return 1; ! /* Check that second byte is not missing. */ len = MB_BYTE2LEN(*p); if (len == 2 && p[1] == NUL) len = 1; --- 1160,1166 ---- return 0; if (size == 1) return 1; ! // Check that second byte is not missing. len = MB_BYTE2LEN(*p); if (len == 2 && p[1] == NUL) len = 1; *************** *** 1182,1192 **** { int mid, bot, top; ! /* first quick check for Latin1 etc. characters */ if (c < table[0].first) return FALSE; ! /* binary search in table */ bot = 0; top = (int)(size / sizeof(struct interval) - 1); while (top >= bot) --- 1181,1191 ---- { int mid, bot, top; ! // first quick check for Latin1 etc. characters if (c < table[0].first) return FALSE; ! // binary search in table bot = 0; top = (int)(size / sizeof(struct interval) - 1); while (top >= bot) *************** *** 1202,1209 **** return FALSE; } ! /* Sorted list of non-overlapping intervals of East Asian Ambiguous ! * characters, generated with ../runtime/tools/unicode.vim. */ static struct interval ambiguous[] = { {0x00a1, 0x00a1}, --- 1201,1208 ---- return FALSE; } ! // Sorted list of non-overlapping intervals of East Asian Ambiguous ! // characters, generated with ../runtime/tools/unicode.vim. static struct interval ambiguous[] = { {0x00a1, 0x00a1}, *************** *** 1410,1417 **** int utf_char2cells(int c) { ! /* Sorted list of non-overlapping intervals of East Asian double width ! * characters, generated with ../runtime/tools/unicode.vim. */ static struct interval doublewidth[] = { {0x1100, 0x115f}, --- 1409,1416 ---- int utf_char2cells(int c) { ! // Sorted list of non-overlapping intervals of East Asian double width ! // characters, generated with ../runtime/tools/unicode.vim. static struct interval doublewidth[] = { {0x1100, 0x115f}, *************** *** 1529,1537 **** {0x30000, 0x3fffd} }; ! /* Sorted list of non-overlapping intervals of Emoji characters that don't ! * have ambiguous or double width, ! * based on http://unicode.org/emoji/charts/emoji-list.html */ static struct interval emoji_width[] = { {0x1f1e6, 0x1f1ff}, --- 1528,1536 ---- {0x30000, 0x3fffd} }; ! // Sorted list of non-overlapping intervals of Emoji characters that don't ! // have ambiguous or double width, ! // based on http://unicode.org/emoji/charts/emoji-list.html static struct interval emoji_width[] = { {0x1f1e6, 0x1f1ff}, *************** *** 1585,1596 **** int n = wcwidth(c); if (n < 0) ! return 6; /* unprintable, displays */ if (n > 1) return n; #else if (!utf_printable(c)) ! return 6; /* unprintable, displays */ if (intable(doublewidth, sizeof(doublewidth), c)) return 2; #endif --- 1584,1595 ---- int n = wcwidth(c); if (n < 0) ! return 6; // unprintable, displays if (n > 1) return n; #else if (!utf_printable(c)) ! return 6; // unprintable, displays if (intable(doublewidth, sizeof(doublewidth), c)) return 2; #endif *************** *** 1598,1606 **** return 2; } ! /* Characters below 0x100 are influenced by 'isprint' option */ else if (c >= 0x80 && !vim_isprintc(c)) ! return 4; /* unprintable, displays */ if (c >= 0x80 && *p_ambw == 'd' && intable(ambiguous, sizeof(ambiguous), c)) return 2; --- 1597,1605 ---- return 2; } ! // Characters below 0x100 are influenced by 'isprint' option else if (c >= 0x80 && !vim_isprintc(c)) ! return 4; // unprintable, displays if (c >= 0x80 && *p_ambw == 'd' && intable(ambiguous, sizeof(ambiguous), c)) return 2; *************** *** 1625,1638 **** { int c; ! /* Need to convert to a wide character. */ if (*p >= 0x80) { c = utf_ptr2char(p); ! /* An illegal byte is displayed as . */ if (utf_ptr2len(p) == 1 || c == NUL) return 4; ! /* If the char is ASCII it must be an overlong sequence. */ if (c < 0x80) return char2cells(c); return utf_char2cells(c); --- 1624,1637 ---- { int c; ! // Need to convert to a wide character. if (*p >= 0x80) { c = utf_ptr2char(p); ! // An illegal byte is displayed as . if (utf_ptr2len(p) == 1 || c == NUL) return 4; ! // If the char is ASCII it must be an overlong sequence. if (c < 0x80) return char2cells(c); return utf_char2cells(c); *************** *** 1643,1650 **** int dbcs_ptr2cells(char_u *p) { ! /* Number of cells is equal to number of bytes, except for euc-jp when ! * the first byte is 0x8e. */ if (enc_dbcs == DBCS_JPNU && *p == 0x8e) return 1; return MB_BYTE2LEN(*p); --- 1642,1649 ---- int dbcs_ptr2cells(char_u *p) { ! // Number of cells is equal to number of bytes, except for euc-jp when ! // the first byte is 0x8e. if (enc_dbcs == DBCS_JPNU && *p == 0x8e) return 1; return MB_BYTE2LEN(*p); *************** *** 1666,1681 **** { int c; ! /* Need to convert to a wide character. */ if (size > 0 && *p >= 0x80) { if (utf_ptr2len_len(p, size) < utf8len_tab[*p]) ! return 1; /* truncated */ c = utf_ptr2char(p); ! /* An illegal byte is displayed as . */ if (utf_ptr2len(p) == 1 || c == NUL) return 4; ! /* If the char is ASCII it must be an overlong sequence. */ if (c < 0x80) return char2cells(c); return utf_char2cells(c); --- 1665,1680 ---- { int c; ! // Need to convert to a wide character. if (size > 0 && *p >= 0x80) { if (utf_ptr2len_len(p, size) < utf8len_tab[*p]) ! return 1; // truncated c = utf_ptr2char(p); ! // An illegal byte is displayed as . if (utf_ptr2len(p) == 1 || c == NUL) return 4; ! // If the char is ASCII it must be an overlong sequence. if (c < 0x80) return char2cells(c); return utf_char2cells(c); *************** *** 1686,1693 **** static int dbcs_ptr2cells_len(char_u *p, int size) { ! /* Number of cells is equal to number of bytes, except for euc-jp when ! * the first byte is 0x8e. */ if (size <= 1 || (enc_dbcs == DBCS_JPNU && *p == 0x8e)) return 1; return MB_BYTE2LEN(*p); --- 1685,1692 ---- static int dbcs_ptr2cells_len(char_u *p, int size) { ! // Number of cells is equal to number of bytes, except for euc-jp when ! // the first byte is 0x8e. if (size <= 1 || (enc_dbcs == DBCS_JPNU && *p == 0x8e)) return 1; return MB_BYTE2LEN(*p); *************** *** 1707,1717 **** static int dbcs_char2cells(int c) { ! /* Number of cells is equal to number of bytes, except for euc-jp when ! * the first byte is 0x8e. */ if (enc_dbcs == DBCS_JPNU && ((unsigned)c >> 8) == 0x8e) return 1; ! /* use the first byte */ return MB_BYTE2LEN((unsigned)c >> 8); } --- 1706,1716 ---- static int dbcs_char2cells(int c) { ! // Number of cells is equal to number of bytes, except for euc-jp when ! // the first byte is 0x8e. if (enc_dbcs == DBCS_JPNU && ((unsigned)c >> 8) == 0x8e) return 1; ! // use the first byte return MB_BYTE2LEN((unsigned)c >> 8); } *************** *** 1744,1755 **** int dbcs_off2cells(unsigned off, unsigned max_off) { ! /* never check beyond end of the line */ if (off >= max_off) return 1; ! /* Number of cells is equal to number of bytes, except for euc-jp when ! * the first byte is 0x8e. */ if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) return 1; return MB_BYTE2LEN(ScreenLines[off]); --- 1743,1754 ---- int dbcs_off2cells(unsigned off, unsigned max_off) { ! // never check beyond end of the line if (off >= max_off) return 1; ! // Number of cells is equal to number of bytes, except for euc-jp when ! // the first byte is 0x8e. if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) return 1; return MB_BYTE2LEN(ScreenLines[off]); *************** *** 1791,1797 **** { int len; ! if (p[0] < 0x80) /* be quick for ASCII */ return p[0]; len = utf8len_tab_zero[p[0]]; --- 1790,1796 ---- { int len; ! if (p[0] < 0x80) // be quick for ASCII return p[0]; len = utf8len_tab_zero[p[0]]; *************** *** 1823,1829 **** } } } ! /* Illegal value, just return the first byte */ return p[0]; } --- 1822,1828 ---- } } } ! // Illegal value, just return the first byte return p[0]; } *************** *** 1848,1887 **** { int c, k; ! if (*n == 0) /* end of buffer */ return 0; k = utf8len_tab_zero[**s]; if (k == 1) { ! /* ASCII character or NUL */ (*n)--; return *(*s)++; } if ((size_t)k <= *n) { ! /* We have a multibyte sequence and it isn't truncated by buffer ! * limits so utf_ptr2char() is safe to use. Or the first byte is ! * illegal (k=0), and it's also safe to use utf_ptr2char(). */ c = utf_ptr2char(*s); ! /* On failure, utf_ptr2char() returns the first byte, so here we ! * check equality with the first byte. The only non-ASCII character ! * which equals the first byte of its own UTF-8 representation is ! * U+00C3 (UTF-8: 0xC3 0x83), so need to check that special case too. ! * It's safe even if n=1, else we would have k=2 > n. */ if (c != (int)(**s) || (c == 0xC3 && (*s)[1] == 0x83)) { ! /* byte sequence was successfully decoded */ *s += k; *n -= k; return c; } } ! /* byte sequence is incomplete or illegal */ return -1; } --- 1847,1886 ---- { int c, k; ! if (*n == 0) // end of buffer return 0; k = utf8len_tab_zero[**s]; if (k == 1) { ! // ASCII character or NUL (*n)--; return *(*s)++; } if ((size_t)k <= *n) { ! // We have a multibyte sequence and it isn't truncated by buffer ! // limits so utf_ptr2char() is safe to use. Or the first byte is ! // illegal (k=0), and it's also safe to use utf_ptr2char(). c = utf_ptr2char(*s); ! // On failure, utf_ptr2char() returns the first byte, so here we ! // check equality with the first byte. The only non-ASCII character ! // which equals the first byte of its own UTF-8 representation is ! // U+00C3 (UTF-8: 0xC3 0x83), so need to check that special case too. ! // It's safe even if n=1, else we would have k=2 > n. if (c != (int)(**s) || (c == 0xC3 && (*s)[1] == 0x83)) { ! // byte sequence was successfully decoded *s += k; *n -= k; return c; } } ! // byte sequence is incomplete or illegal return -1; } *************** *** 1943,1949 **** int utfc_ptr2char( char_u *p, ! int *pcc) /* return: composing chars, last one is 0 */ { int len; int c; --- 1942,1948 ---- int utfc_ptr2char( char_u *p, ! int *pcc) // return: composing chars, last one is 0 { int len; int c; *************** *** 1953,1959 **** c = utf_ptr2char(p); len = utf_ptr2len(p); ! /* Only accept a composing char when the first char isn't illegal. */ if ((len > 1 || *p < 0x80) && p[len] >= 0x80 && UTF_COMPOSINGLIKE(p, p + len)) --- 1952,1958 ---- c = utf_ptr2char(p); len = utf_ptr2len(p); ! // Only accept a composing char when the first char isn't illegal. if ((len > 1 || *p < 0x80) && p[len] >= 0x80 && UTF_COMPOSINGLIKE(p, p + len)) *************** *** 1970,1976 **** } } ! if (i < MAX_MCO) /* last composing char must be 0 */ pcc[i] = 0; return c; --- 1969,1975 ---- } } ! if (i < MAX_MCO) // last composing char must be 0 pcc[i] = 0; return c; *************** *** 1983,1989 **** int utfc_ptr2char_len( char_u *p, ! int *pcc, /* return: composing chars, last one is 0 */ int maxlen) { int len; --- 1982,1988 ---- int utfc_ptr2char_len( char_u *p, ! int *pcc, // return: composing chars, last one is 0 int maxlen) { int len; *************** *** 1993,1999 **** c = utf_ptr2char(p); len = utf_ptr2len_len(p, maxlen); ! /* Only accept a composing char when the first char isn't illegal. */ if ((len > 1 || *p < 0x80) && len < maxlen && p[len] >= 0x80 --- 1992,1998 ---- c = utf_ptr2char(p); len = utf_ptr2len_len(p, maxlen); ! // Only accept a composing char when the first char isn't illegal. if ((len > 1 || *p < 0x80) && len < maxlen && p[len] >= 0x80 *************** *** 2013,2019 **** } } ! if (i < MAX_MCO) /* last composing char must be 0 */ pcc[i] = 0; return c; --- 2012,2018 ---- } } ! if (i < MAX_MCO) // last composing char must be 0 pcc[i] = 0; return c; *************** *** 2091,2099 **** len = utf8len_tab[*p]; if (len == 1) ! return 1; /* NUL, ascii or illegal lead byte */ if (len > size) ! m = size; /* incomplete byte sequence. */ else m = len; for (i = 1; i < m; ++i) --- 2090,2098 ---- len = utf8len_tab[*p]; if (len == 1) ! return 1; // NUL, ascii or illegal lead byte if (len > size) ! m = size; // incomplete byte sequence. else m = len; for (i = 1; i < m; ++i) *************** *** 2117,2129 **** if (b0 == NUL) return 0; ! if (b0 < 0x80 && p[1] < 0x80) /* be quick for ASCII */ return 1; ! /* Skip over first UTF-8 char, stopping at a NUL byte. */ len = utf_ptr2len(p); ! /* Check for illegal byte. */ if (len == 1 && b0 >= 0x80) return 1; --- 2116,2128 ---- if (b0 == NUL) return 0; ! if (b0 < 0x80 && p[1] < 0x80) // be quick for ASCII return 1; ! // Skip over first UTF-8 char, stopping at a NUL byte. len = utf_ptr2len(p); ! // Check for illegal byte. if (len == 1 && b0 >= 0x80) return 1; *************** *** 2139,2145 **** if (p[len] < 0x80 || !UTF_COMPOSINGLIKE(p + prevlen, p + len)) return len; ! /* Skip over composing char */ #ifdef FEAT_ARABIC prevlen = len; #endif --- 2138,2144 ---- if (p[len] < 0x80 || !UTF_COMPOSINGLIKE(p + prevlen, p + len)) return len; ! // Skip over composing char #ifdef FEAT_ARABIC prevlen = len; #endif *************** *** 2163,2175 **** if (size < 1 || *p == NUL) return 0; ! if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) /* be quick for ASCII */ return 1; ! /* Skip over first UTF-8 char, stopping at a NUL byte. */ len = utf_ptr2len_len(p, size); ! /* Check for illegal byte and incomplete byte sequence. */ if ((len == 1 && p[0] >= 0x80) || len > size) return 1; --- 2162,2174 ---- if (size < 1 || *p == NUL) return 0; ! if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) // be quick for ASCII return 1; ! // Skip over first UTF-8 char, stopping at a NUL byte. len = utf_ptr2len_len(p, size); ! // Check for illegal byte and incomplete byte sequence. if ((len == 1 && p[0] >= 0x80) || len > size) return 1; *************** *** 2198,2204 **** if (!UTF_COMPOSINGLIKE(p + prevlen, p + len)) break; ! /* Skip over composing char */ #ifdef FEAT_ARABIC prevlen = len; #endif --- 2197,2203 ---- if (!UTF_COMPOSINGLIKE(p + prevlen, p + len)) break; ! // Skip over composing char #ifdef FEAT_ARABIC prevlen = len; #endif *************** *** 2234,2258 **** int utf_char2bytes(int c, char_u *buf) { ! if (c < 0x80) /* 7 bits */ { buf[0] = c; return 1; } ! if (c < 0x800) /* 11 bits */ { buf[0] = 0xc0 + ((unsigned)c >> 6); buf[1] = 0x80 + (c & 0x3f); return 2; } ! if (c < 0x10000) /* 16 bits */ { buf[0] = 0xe0 + ((unsigned)c >> 12); buf[1] = 0x80 + (((unsigned)c >> 6) & 0x3f); buf[2] = 0x80 + (c & 0x3f); return 3; } ! if (c < 0x200000) /* 21 bits */ { buf[0] = 0xf0 + ((unsigned)c >> 18); buf[1] = 0x80 + (((unsigned)c >> 12) & 0x3f); --- 2233,2257 ---- int utf_char2bytes(int c, char_u *buf) { ! if (c < 0x80) // 7 bits { buf[0] = c; return 1; } ! if (c < 0x800) // 11 bits { buf[0] = 0xc0 + ((unsigned)c >> 6); buf[1] = 0x80 + (c & 0x3f); return 2; } ! if (c < 0x10000) // 16 bits { buf[0] = 0xe0 + ((unsigned)c >> 12); buf[1] = 0x80 + (((unsigned)c >> 6) & 0x3f); buf[2] = 0x80 + (c & 0x3f); return 3; } ! if (c < 0x200000) // 21 bits { buf[0] = 0xf0 + ((unsigned)c >> 18); buf[1] = 0x80 + (((unsigned)c >> 12) & 0x3f); *************** *** 2260,2266 **** buf[3] = 0x80 + (c & 0x3f); return 4; } ! if (c < 0x4000000) /* 26 bits */ { buf[0] = 0xf8 + ((unsigned)c >> 24); buf[1] = 0x80 + (((unsigned)c >> 18) & 0x3f); --- 2259,2265 ---- buf[3] = 0x80 + (c & 0x3f); return 4; } ! if (c < 0x4000000) // 26 bits { buf[0] = 0xf8 + ((unsigned)c >> 24); buf[1] = 0x80 + (((unsigned)c >> 18) & 0x3f); *************** *** 2269,2275 **** buf[4] = 0x80 + (c & 0x3f); return 5; } ! /* 31 bits */ buf[0] = 0xfc + ((unsigned)c >> 30); buf[1] = 0x80 + (((unsigned)c >> 24) & 0x3f); buf[2] = 0x80 + (((unsigned)c >> 18) & 0x3f); --- 2268,2274 ---- buf[4] = 0x80 + (c & 0x3f); return 5; } ! // 31 bits buf[0] = 0xfc + ((unsigned)c >> 30); buf[1] = 0x80 + (((unsigned)c >> 24) & 0x3f); buf[2] = 0x80 + (((unsigned)c >> 18) & 0x3f); *************** *** 2298,2305 **** int utf_iscomposing(int c) { ! /* Sorted list of non-overlapping intervals. ! * Generated by ../runtime/tools/unicode.vim. */ static struct interval combining[] = { {0x0300, 0x036f}, --- 2297,2304 ---- int utf_iscomposing(int c) { ! // Sorted list of non-overlapping intervals. ! // Generated by ../runtime/tools/unicode.vim. static struct interval combining[] = { {0x0300, 0x036f}, *************** *** 2600,2607 **** */ return iswprint(c); #else ! /* Sorted list of non-overlapping intervals. ! * 0xd800-0xdfff is reserved for UTF-16, actually illegal. */ static struct interval nonprint[] = { {0x070f, 0x070f}, {0x180b, 0x180e}, {0x200b, 0x200f}, {0x202a, 0x202e}, --- 2599,2606 ---- */ return iswprint(c); #else ! // Sorted list of non-overlapping intervals. ! // 0xd800-0xdfff is reserved for UTF-16, actually illegal. static struct interval nonprint[] = { {0x070f, 0x070f}, {0x180b, 0x180e}, {0x200b, 0x200f}, {0x202a, 0x202e}, *************** *** 2613,2620 **** #endif } ! /* Sorted list of non-overlapping intervals of all Emoji characters, ! * based on http://unicode.org/emoji/charts/emoji-list.html */ static struct interval emoji_all[] = { {0x203c, 0x203c}, --- 2612,2619 ---- #endif } ! // Sorted list of non-overlapping intervals of all Emoji characters, ! // based on http://unicode.org/emoji/charts/emoji-list.html static struct interval emoji_all[] = { {0x203c, 0x203c}, *************** *** 2776,2782 **** int utf_class_buf(int c, buf_T *buf) { ! /* sorted list of non-overlapping intervals */ static struct clinterval { unsigned int first; --- 2775,2781 ---- int utf_class_buf(int c, buf_T *buf) { ! // sorted list of non-overlapping intervals static struct clinterval { unsigned int first; *************** *** 2784,2793 **** unsigned int class; } classes[] = { ! {0x037e, 0x037e, 1}, /* Greek question mark */ ! {0x0387, 0x0387, 1}, /* Greek ano teleia */ ! {0x055a, 0x055f, 1}, /* Armenian punctuation */ ! {0x0589, 0x0589, 1}, /* Armenian full stop */ {0x05be, 0x05be, 1}, {0x05c0, 0x05c0, 1}, {0x05c3, 0x05c3, 1}, --- 2783,2792 ---- unsigned int class; } classes[] = { ! {0x037e, 0x037e, 1}, // Greek question mark ! {0x0387, 0x0387, 1}, // Greek ano teleia ! {0x055a, 0x055f, 1}, // Armenian punctuation ! {0x0589, 0x0589, 1}, // Armenian full stop {0x05be, 0x05be, 1}, {0x05c0, 0x05c0, 1}, {0x05c3, 0x05c3, 1}, *************** *** 2797,2803 **** {0x061f, 0x061f, 1}, {0x066a, 0x066d, 1}, {0x06d4, 0x06d4, 1}, ! {0x0700, 0x070d, 1}, /* Syriac punctuation */ {0x0964, 0x0965, 1}, {0x0970, 0x0970, 1}, {0x0df4, 0x0df4, 1}, --- 2796,2802 ---- {0x061f, 0x061f, 1}, {0x066a, 0x066d, 1}, {0x06d4, 0x06d4, 1}, ! {0x0700, 0x070d, 1}, // Syriac punctuation {0x0964, 0x0965, 1}, {0x0970, 0x0970, 1}, {0x0df4, 0x0df4, 1}, *************** *** 2806,2877 **** {0x0f04, 0x0f12, 1}, {0x0f3a, 0x0f3d, 1}, {0x0f85, 0x0f85, 1}, ! {0x104a, 0x104f, 1}, /* Myanmar punctuation */ ! {0x10fb, 0x10fb, 1}, /* Georgian punctuation */ ! {0x1361, 0x1368, 1}, /* Ethiopic punctuation */ ! {0x166d, 0x166e, 1}, /* Canadian Syl. punctuation */ {0x1680, 0x1680, 0}, {0x169b, 0x169c, 1}, {0x16eb, 0x16ed, 1}, {0x1735, 0x1736, 1}, ! {0x17d4, 0x17dc, 1}, /* Khmer punctuation */ ! {0x1800, 0x180a, 1}, /* Mongolian punctuation */ ! {0x2000, 0x200b, 0}, /* spaces */ ! {0x200c, 0x2027, 1}, /* punctuation and symbols */ {0x2028, 0x2029, 0}, ! {0x202a, 0x202e, 1}, /* punctuation and symbols */ {0x202f, 0x202f, 0}, ! {0x2030, 0x205e, 1}, /* punctuation and symbols */ {0x205f, 0x205f, 0}, ! {0x2060, 0x27ff, 1}, /* punctuation and symbols */ ! {0x2070, 0x207f, 0x2070}, /* superscript */ ! {0x2080, 0x2094, 0x2080}, /* subscript */ ! {0x20a0, 0x27ff, 1}, /* all kinds of symbols */ ! {0x2800, 0x28ff, 0x2800}, /* braille */ ! {0x2900, 0x2998, 1}, /* arrows, brackets, etc. */ {0x29d8, 0x29db, 1}, {0x29fc, 0x29fd, 1}, ! {0x2e00, 0x2e7f, 1}, /* supplemental punctuation */ ! {0x3000, 0x3000, 0}, /* ideographic space */ ! {0x3001, 0x3020, 1}, /* ideographic punctuation */ {0x3030, 0x3030, 1}, {0x303d, 0x303d, 1}, ! {0x3040, 0x309f, 0x3040}, /* Hiragana */ ! {0x30a0, 0x30ff, 0x30a0}, /* Katakana */ ! {0x3300, 0x9fff, 0x4e00}, /* CJK Ideographs */ ! {0xac00, 0xd7a3, 0xac00}, /* Hangul Syllables */ ! {0xf900, 0xfaff, 0x4e00}, /* CJK Ideographs */ {0xfd3e, 0xfd3f, 1}, ! {0xfe30, 0xfe6b, 1}, /* punctuation forms */ ! {0xff00, 0xff0f, 1}, /* half/fullwidth ASCII */ ! {0xff1a, 0xff20, 1}, /* half/fullwidth ASCII */ ! {0xff3b, 0xff40, 1}, /* half/fullwidth ASCII */ ! {0xff5b, 0xff65, 1}, /* half/fullwidth ASCII */ ! {0x1d000, 0x1d24f, 1}, /* Musical notation */ ! {0x1d400, 0x1d7ff, 1}, /* Mathematical Alphanumeric Symbols */ ! {0x1f000, 0x1f2ff, 1}, /* Game pieces; enclosed characters */ ! {0x1f300, 0x1f9ff, 1}, /* Many symbol blocks */ ! {0x20000, 0x2a6df, 0x4e00}, /* CJK Ideographs */ ! {0x2a700, 0x2b73f, 0x4e00}, /* CJK Ideographs */ ! {0x2b740, 0x2b81f, 0x4e00}, /* CJK Ideographs */ ! {0x2f800, 0x2fa1f, 0x4e00}, /* CJK Ideographs */ }; int bot = 0; int top = sizeof(classes) / sizeof(struct clinterval) - 1; int mid; ! /* First quick check for Latin1 characters, use 'iskeyword'. */ if (c < 0x100) { if (c == ' ' || c == '\t' || c == NUL || c == 0xa0) ! return 0; /* blank */ if (vim_iswordc_buf(c, buf)) ! return 2; /* word character */ ! return 1; /* punctuation */ } ! /* binary search in table */ while (top >= bot) { mid = (bot + top) / 2; --- 2805,2876 ---- {0x0f04, 0x0f12, 1}, {0x0f3a, 0x0f3d, 1}, {0x0f85, 0x0f85, 1}, ! {0x104a, 0x104f, 1}, // Myanmar punctuation ! {0x10fb, 0x10fb, 1}, // Georgian punctuation ! {0x1361, 0x1368, 1}, // Ethiopic punctuation ! {0x166d, 0x166e, 1}, // Canadian Syl. punctuation {0x1680, 0x1680, 0}, {0x169b, 0x169c, 1}, {0x16eb, 0x16ed, 1}, {0x1735, 0x1736, 1}, ! {0x17d4, 0x17dc, 1}, // Khmer punctuation ! {0x1800, 0x180a, 1}, // Mongolian punctuation ! {0x2000, 0x200b, 0}, // spaces ! {0x200c, 0x2027, 1}, // punctuation and symbols {0x2028, 0x2029, 0}, ! {0x202a, 0x202e, 1}, // punctuation and symbols {0x202f, 0x202f, 0}, ! {0x2030, 0x205e, 1}, // punctuation and symbols {0x205f, 0x205f, 0}, ! {0x2060, 0x27ff, 1}, // punctuation and symbols ! {0x2070, 0x207f, 0x2070}, // superscript ! {0x2080, 0x2094, 0x2080}, // subscript ! {0x20a0, 0x27ff, 1}, // all kinds of symbols ! {0x2800, 0x28ff, 0x2800}, // braille ! {0x2900, 0x2998, 1}, // arrows, brackets, etc. {0x29d8, 0x29db, 1}, {0x29fc, 0x29fd, 1}, ! {0x2e00, 0x2e7f, 1}, // supplemental punctuation ! {0x3000, 0x3000, 0}, // ideographic space ! {0x3001, 0x3020, 1}, // ideographic punctuation {0x3030, 0x3030, 1}, {0x303d, 0x303d, 1}, ! {0x3040, 0x309f, 0x3040}, // Hiragana ! {0x30a0, 0x30ff, 0x30a0}, // Katakana ! {0x3300, 0x9fff, 0x4e00}, // CJK Ideographs ! {0xac00, 0xd7a3, 0xac00}, // Hangul Syllables ! {0xf900, 0xfaff, 0x4e00}, // CJK Ideographs {0xfd3e, 0xfd3f, 1}, ! {0xfe30, 0xfe6b, 1}, // punctuation forms ! {0xff00, 0xff0f, 1}, // half/fullwidth ASCII ! {0xff1a, 0xff20, 1}, // half/fullwidth ASCII ! {0xff3b, 0xff40, 1}, // half/fullwidth ASCII ! {0xff5b, 0xff65, 1}, // half/fullwidth ASCII ! {0x1d000, 0x1d24f, 1}, // Musical notation ! {0x1d400, 0x1d7ff, 1}, // Mathematical Alphanumeric Symbols ! {0x1f000, 0x1f2ff, 1}, // Game pieces; enclosed characters ! {0x1f300, 0x1f9ff, 1}, // Many symbol blocks ! {0x20000, 0x2a6df, 0x4e00}, // CJK Ideographs ! {0x2a700, 0x2b73f, 0x4e00}, // CJK Ideographs ! {0x2b740, 0x2b81f, 0x4e00}, // CJK Ideographs ! {0x2f800, 0x2fa1f, 0x4e00}, // CJK Ideographs }; int bot = 0; int top = sizeof(classes) / sizeof(struct clinterval) - 1; int mid; ! // First quick check for Latin1 characters, use 'iskeyword'. if (c < 0x100) { if (c == ' ' || c == '\t' || c == NUL || c == 0xa0) ! return 0; // blank if (vim_iswordc_buf(c, buf)) ! return 2; // word character ! return 1; // punctuation } ! // binary search in table while (top >= bot) { mid = (bot + top) / 2; *************** *** 2883,2893 **** return (int)classes[mid].class; } ! /* emoji */ if (intable(emoji_all, sizeof(emoji_all), c)) return 3; ! /* most other characters are "word" characters */ return 2; } --- 2882,2892 ---- return (int)classes[mid].class; } ! // emoji if (intable(emoji_all, sizeof(emoji_all), c)) return 3; ! // most other characters are "word" characters return 2; } *************** *** 3127,3140 **** convertStruct table[], int tableSize) { ! int start, mid, end; /* indices into table */ int entries = tableSize / sizeof(convertStruct); start = 0; end = entries; while (start < end) { ! /* need to search further */ mid = (end + start) / 2; if (table[mid].rangeEnd < a) start = mid + 1; --- 3126,3139 ---- convertStruct table[], int tableSize) { ! int start, mid, end; // indices into table int entries = tableSize / sizeof(convertStruct); start = 0; end = entries; while (start < end) { ! // need to search further mid = (end + start) / 2; if (table[mid].rangeEnd < a) start = mid + 1; *************** *** 3158,3164 **** utf_fold(int a) { if (a < 0x80) ! /* be fast for ASCII */ return a >= 0x41 && a <= 0x5a ? a + 32 : a; return utf_convert(a, foldCase, (int)sizeof(foldCase)); } --- 3157,3163 ---- utf_fold(int a) { if (a < 0x80) ! // be fast for ASCII return a >= 0x41 && a <= 0x5a ? a + 32 : a; return utf_convert(a, foldCase, (int)sizeof(foldCase)); } *************** *** 3537,3564 **** int utf_toupper(int a) { ! /* If 'casemap' contains "keepascii" use ASCII style toupper(). */ if (a < 128 && (cmp_flags & CMP_KEEPASCII)) return TOUPPER_ASC(a); #if defined(HAVE_TOWUPPER) && defined(__STDC_ISO_10646__) ! /* If towupper() is available and handles Unicode, use it. */ if (!(cmp_flags & CMP_INTERNAL)) return towupper(a); #endif ! /* For characters below 128 use locale sensitive toupper(). */ if (a < 128) return TOUPPER_LOC(a); ! /* For any other characters use the above mapping table. */ return utf_convert(a, toUpper, (int)sizeof(toUpper)); } int utf_islower(int a) { ! /* German sharp s is lower case but has no upper case equivalent. */ return (utf_toupper(a) != a) || a == 0xdf; } --- 3536,3563 ---- int utf_toupper(int a) { ! // If 'casemap' contains "keepascii" use ASCII style toupper(). if (a < 128 && (cmp_flags & CMP_KEEPASCII)) return TOUPPER_ASC(a); #if defined(HAVE_TOWUPPER) && defined(__STDC_ISO_10646__) ! // If towupper() is available and handles Unicode, use it. if (!(cmp_flags & CMP_INTERNAL)) return towupper(a); #endif ! // For characters below 128 use locale sensitive toupper(). if (a < 128) return TOUPPER_LOC(a); ! // For any other characters use the above mapping table. return utf_convert(a, toUpper, (int)sizeof(toUpper)); } int utf_islower(int a) { ! // German sharp s is lower case but has no upper case equivalent. return (utf_toupper(a) != a) || a == 0xdf; } *************** *** 3569,3589 **** int utf_tolower(int a) { ! /* If 'casemap' contains "keepascii" use ASCII style tolower(). */ if (a < 128 && (cmp_flags & CMP_KEEPASCII)) return TOLOWER_ASC(a); #if defined(HAVE_TOWLOWER) && defined(__STDC_ISO_10646__) ! /* If towlower() is available and handles Unicode, use it. */ if (!(cmp_flags & CMP_INTERNAL)) return towlower(a); #endif ! /* For characters below 128 use locale sensitive tolower(). */ if (a < 128) return TOLOWER_LOC(a); ! /* For any other characters use the above mapping table. */ return utf_convert(a, toLower, (int)sizeof(toLower)); } --- 3568,3588 ---- int utf_tolower(int a) { ! // If 'casemap' contains "keepascii" use ASCII style tolower(). if (a < 128 && (cmp_flags & CMP_KEEPASCII)) return TOLOWER_ASC(a); #if defined(HAVE_TOWLOWER) && defined(__STDC_ISO_10646__) ! // If towlower() is available and handles Unicode, use it. if (!(cmp_flags & CMP_INTERNAL)) return towlower(a); #endif ! // For characters below 128 use locale sensitive tolower(). if (a < 128) return TOLOWER_LOC(a); ! // For any other characters use the above mapping table. return utf_convert(a, toLower, (int)sizeof(toLower)); } *************** *** 3619,3640 **** return cdiff; } ! /* some string ended or has an incomplete/illegal character sequence */ if (c1 == 0 || c2 == 0) { ! /* some string ended. shorter string is smaller */ if (c1 == 0 && c2 == 0) return 0; return c1 == 0 ? -1 : 1; } ! /* Continue with bytewise comparison to produce some result that ! * would make comparison operations involving this function transitive. ! * ! * If only one string had an error, comparison should be made with ! * folded version of the other string. In this case it is enough ! * to fold just one character to determine the result of comparison. */ if (c1 != -1 && c2 == -1) { --- 3618,3639 ---- return cdiff; } ! // some string ended or has an incomplete/illegal character sequence if (c1 == 0 || c2 == 0) { ! // some string ended. shorter string is smaller if (c1 == 0 && c2 == 0) return 0; return c1 == 0 ? -1 : 1; } ! // Continue with bytewise comparison to produce some result that ! // would make comparison operations involving this function transitive. ! // ! // If only one string had an error, comparison should be made with ! // folded version of the other string. In this case it is enough ! // to fold just one character to determine the result of comparison. if (c1 != -1 && c2 == -1) { *************** *** 3692,3704 **** { for (i = 0; i < n; i += l) { ! if (s1[i] == NUL && s2[i] == NUL) /* both strings end */ return 0; l = (*mb_ptr2len)(s1 + i); if (l <= 1) { ! /* Single byte: first check normally, then with ignore case. */ if (s1[i] != s2[i]) { cdiff = MB_TOLOWER(s1[i]) - MB_TOLOWER(s2[i]); --- 3691,3703 ---- { for (i = 0; i < n; i += l) { ! if (s1[i] == NUL && s2[i] == NUL) // both strings end return 0; l = (*mb_ptr2len)(s1 + i); if (l <= 1) { ! // Single byte: first check normally, then with ignore case. if (s1[i] != s2[i]) { cdiff = MB_TOLOWER(s1[i]) - MB_TOLOWER(s2[i]); *************** *** 3708,3714 **** } else { ! /* For non-Unicode multi-byte don't ignore case. */ if (l > n - i) l = n - i; cdiff = STRNCMP(s1 + i, s2 + i, l); --- 3707,3713 ---- } else { ! // For non-Unicode multi-byte don't ignore case. if (l > n - i) l = n - i; cdiff = STRNCMP(s1 + i, s2 + i, l); *************** *** 3733,3740 **** int clen; int i; ! /* Get the byte length of the char under the cursor, including composing ! * characters. */ line = ml_get_cursor(); len = utfc_ptr2len(line); if (len == 0) --- 3732,3739 ---- int clen; int i; ! // Get the byte length of the char under the cursor, including composing ! // characters. line = ml_get_cursor(); len = utfc_ptr2len(line); if (len == 0) *************** *** 3748,3754 **** { if (clen == 0) { ! /* start of (composing) character, get its length */ if (i > 0) { STRCPY(IObuff + rlen, "+ "); --- 3747,3753 ---- { if (clen == 0) { ! // start of (composing) character, get its length if (i > 0) { STRCPY(IObuff + rlen, "+ "); *************** *** 3757,3763 **** clen = utf_ptr2len(line + i); } sprintf((char *)IObuff + rlen, "%02x ", ! (line[i] == NL) ? NUL : line[i]); /* NUL is stored as NL */ --clen; rlen += (int)STRLEN(IObuff + rlen); if (rlen > IOSIZE - 20) --- 3756,3762 ---- clen = utf_ptr2len(line + i); } sprintf((char *)IObuff + rlen, "%02x ", ! (line[i] == NL) ? NUL : line[i]); // NUL is stored as NL --clen; rlen += (int)STRLEN(IObuff + rlen); if (rlen > IOSIZE - 20) *************** *** 3784,3796 **** { char_u *q; ! /* It can't be a trailing byte when not using DBCS, at the start of the ! * string or the previous byte can't start a double-byte. */ if (p <= base || MB_BYTE2LEN(p[-1]) == 1 || *p == NUL) return 0; ! /* This is slow: need to start at the base and go forward until the ! * byte we are looking for. Return 1 when we went past it, 0 otherwise. */ q = base; while (q < p) q += dbcs_ptr2len(q); --- 3783,3795 ---- { char_u *q; ! // It can't be a trailing byte when not using DBCS, at the start of the ! // string or the previous byte can't start a double-byte. if (p <= base || MB_BYTE2LEN(p[-1]) == 1 || *p == NUL) return 0; ! // This is slow: need to start at the base and go forward until the ! // byte we are looking for. Return 1 when we went past it, 0 otherwise. q = base; while (q < p) q += dbcs_ptr2len(q); *************** *** 3806,3825 **** { char_u *q; ! /* It can't be a trailing byte when not using DBCS, at the start of the ! * string or the previous byte can't start a double-byte. ! * For euc-jp an 0x8e byte in the previous cell always means we have a ! * lead byte in the current cell. */ if (p <= base || (enc_dbcs == DBCS_JPNU && p[-1] == 0x8e) || MB_BYTE2LEN(p[-1]) == 1 || *p == NUL) return 0; ! /* This is slow: need to start at the base and go forward until the ! * byte we are looking for. Return 1 when we went past it, 0 otherwise. ! * For DBCS_JPNU look out for 0x8e, which means the second byte is not ! * stored as the next byte. */ q = base; while (q < p) { --- 3805,3824 ---- { char_u *q; ! // It can't be a trailing byte when not using DBCS, at the start of the ! // string or the previous byte can't start a double-byte. ! // For euc-jp an 0x8e byte in the previous cell always means we have a ! // lead byte in the current cell. if (p <= base || (enc_dbcs == DBCS_JPNU && p[-1] == 0x8e) || MB_BYTE2LEN(p[-1]) == 1 || *p == NUL) return 0; ! // This is slow: need to start at the base and go forward until the ! // byte we are looking for. Return 1 when we went past it, 0 otherwise. ! // For DBCS_JPNU look out for 0x8e, which means the second byte is not ! // stored as the next byte. q = base; while (q < p) { *************** *** 3842,3862 **** char_u *j; #endif ! if (*p < 0x80) /* be quick for ASCII */ return 0; ! /* Skip backwards over trailing bytes: 10xx.xxxx ! * Skip backwards again if on a composing char. */ for (q = p; ; --q) { ! /* Move s to the last byte of this char. */ for (s = q; (s[1] & 0xc0) == 0x80; ++s) ; ! /* Move q to the first byte of this char. */ while (q > base && (*q & 0xc0) == 0x80) --q; ! /* Check for illegal sequence. Do allow an illegal byte after where we ! * started. */ len = utf8len_tab[*q]; if (len != (int)(s - q + 1) && len != (int)(p - q + 1)) return 0; --- 3841,3861 ---- char_u *j; #endif ! if (*p < 0x80) // be quick for ASCII return 0; ! // Skip backwards over trailing bytes: 10xx.xxxx ! // Skip backwards again if on a composing char. for (q = p; ; --q) { ! // Move s to the last byte of this char. for (s = q; (s[1] & 0xc0) == 0x80; ++s) ; ! // Move q to the first byte of this char. while (q > base && (*q & 0xc0) == 0x80) --q; ! // Check for illegal sequence. Do allow an illegal byte after where we ! // started. len = utf8len_tab[*q]; if (len != (int)(s - q + 1) && len != (int)(p - q + 1)) return 0; *************** *** 3871,3880 **** #ifdef FEAT_ARABIC if (arabic_maycombine(c)) { ! /* Advance to get a sneak-peak at the next char */ j = q; --j; ! /* Move j to the first byte of this char. */ while (j > base && (*j & 0xc0) == 0x80) --j; if (arabic_combine(utf_ptr2char(j), c)) --- 3870,3879 ---- #ifdef FEAT_ARABIC if (arabic_maycombine(c)) { ! // Advance to get a sneak-peak at the next char j = q; --j; ! // Move j to the first byte of this char. while (j > base && (*j & 0xc0) == 0x80) --j; if (arabic_combine(utf_ptr2char(j), c)) *************** *** 3913,3927 **** if (enc_utf8) { ! if (*p < 0x80) /* be quick for ASCII */ return 0; ! /* Find the next character that isn't 10xx.xxxx */ for (i = 0; (p[i] & 0xc0) == 0x80; ++i) ; if (i > 0) { ! /* Check for illegal sequence. */ for (j = 0; p - j > base; ++j) if ((p[-j] & 0xc0) != 0x80) break; --- 3912,3926 ---- if (enc_utf8) { ! if (*p < 0x80) // be quick for ASCII return 0; ! // Find the next character that isn't 10xx.xxxx for (i = 0; (p[i] & 0xc0) == 0x80; ++i) ; if (i > 0) { ! // Check for illegal sequence. for (j = 0; p - j > base; ++j) if ((p[-j] & 0xc0) != 0x80) break; *************** *** 3931,3938 **** return i; } ! /* Only need to check if we're on a trail byte, it doesn't matter if we ! * want the offset to the next or current character. */ return (*mb_head_off)(base, p); } --- 3930,3937 ---- return i; } ! // Only need to check if we're on a trail byte, it doesn't matter if we ! // want the offset to the next or current character. return (*mb_head_off)(base, p); } *************** *** 3951,3960 **** if (enc_utf8) { ! /* Find the last character that is 10xx.xxxx */ for (i = 0; (p[i + 1] & 0xc0) == 0x80; ++i) ; ! /* Check for illegal sequence. */ for (j = 0; p - j > base; ++j) if ((p[-j] & 0xc0) != 0x80) break; --- 3950,3959 ---- if (enc_utf8) { ! // Find the last character that is 10xx.xxxx for (i = 0; (p[i + 1] & 0xc0) == 0x80; ++i) ; ! // Check for illegal sequence. for (j = 0; p - j > base; ++j) if ((p[-j] & 0xc0) != 0x80) break; *************** *** 3963,3974 **** return i; } ! /* It can't be the first byte if a double-byte when not using DBCS, at the ! * end of the string or the byte can't start a double-byte. */ if (enc_dbcs == 0 || p[1] == NUL || MB_BYTE2LEN(*p) == 1) return 0; ! /* Return 1 when on the lead byte, 0 when on the tail byte. */ return 1 - dbcs_head_off(base, p); } --- 3962,3973 ---- return i; } ! // It can't be the first byte if a double-byte when not using DBCS, at the ! // end of the string or the byte can't start a double-byte. if (enc_dbcs == 0 || p[1] == NUL || MB_BYTE2LEN(*p) == 1) return 0; ! // Return 1 when on the lead byte, 0 when on the tail byte. return 1 - dbcs_head_off(base, p); } *************** *** 3987,3995 **** vimconv.vc_type = CONV_NONE; if (enc_utf8 && (enc_canon_props(curbuf->b_p_fenc) & ENC_8BIT)) { ! /* 'encoding' is "utf-8" but we are editing a 8-bit encoded file, ! * possibly a utf-8 file with illegal bytes. Setup for conversion ! * from utf-8 to 'fileencoding'. */ convert_setup(&vimconv, p_enc, curbuf->b_p_fenc); } --- 3986,3994 ---- vimconv.vc_type = CONV_NONE; if (enc_utf8 && (enc_canon_props(curbuf->b_p_fenc) & ENC_8BIT)) { ! // 'encoding' is "utf-8" but we are editing a 8-bit encoded file, ! // possibly a utf-8 file with illegal bytes. Setup for conversion ! // from utf-8 to 'fileencoding'. convert_setup(&vimconv, p_enc, curbuf->b_p_fenc); } *************** *** 4008,4015 **** while (*p != NUL) { ! /* Illegal means that there are not enough trail bytes (checked by ! * utf_ptr2len()) or too many of them (overlong sequence). */ len = utf_ptr2len(p); if (*p >= 0x80 && (len == 1 || utf_char2len(utf_ptr2char(p)) != len)) --- 4007,4014 ---- while (*p != NUL) { ! // Illegal means that there are not enough trail bytes (checked by ! // utf_ptr2len()) or too many of them (overlong sequence). len = utf_ptr2len(p); if (*p >= 0x80 && (len == 1 || utf_char2len(utf_ptr2char(p)) != len)) *************** *** 4037,4043 **** curwin->w_cursor.col = 0; } ! /* didn't find it: don't move and beep */ curwin->w_cursor = pos; beep_flush(); --- 4036,4042 ---- curwin->w_cursor.col = 0; } ! // didn't find it: don't move and beep curwin->w_cursor = pos; beep_flush(); *************** *** 4062,4074 **** { l = utf8len_tab_zero[*p]; if (l == 0) ! return FALSE; /* invalid lead byte */ if (end != NULL && p + l > end) ! return FALSE; /* incomplete byte sequence */ ++p; while (--l > 0) if ((*p++ & 0xc0) != 0x80) ! return FALSE; /* invalid trail byte */ } return TRUE; } --- 4061,4073 ---- { l = utf8len_tab_zero[*p]; if (l == 0) ! return FALSE; // invalid lead byte if (end != NULL && p + l > end) ! return FALSE; // incomplete byte sequence ++p; while (--l > 0) if ((*p++ & 0xc0) != 0x80) ! return FALSE; // invalid trail byte } return TRUE; } *************** *** 4081,4096 **** int dbcs_screen_tail_off(char_u *base, char_u *p) { ! /* It can't be the first byte if a double-byte when not using DBCS, at the ! * end of the string or the byte can't start a double-byte. ! * For euc-jp an 0x8e byte always means we have a lead byte in the current ! * cell. */ if (*p == NUL || p[1] == NUL || (enc_dbcs == DBCS_JPNU && *p == 0x8e) || MB_BYTE2LEN(*p) == 1) return 0; ! /* Return 1 when on the lead byte, 0 when on the tail byte. */ return 1 - dbcs_screen_head_off(base, p); } #endif --- 4080,4095 ---- int dbcs_screen_tail_off(char_u *base, char_u *p) { ! // It can't be the first byte if a double-byte when not using DBCS, at the ! // end of the string or the byte can't start a double-byte. ! // For euc-jp an 0x8e byte always means we have a lead byte in the current ! // cell. if (*p == NUL || p[1] == NUL || (enc_dbcs == DBCS_JPNU && *p == 0x8e) || MB_BYTE2LEN(*p) == 1) return 0; ! // Return 1 when on the lead byte, 0 when on the tail byte. return 1 - dbcs_screen_head_off(base, p); } #endif *************** *** 4122,4129 **** lp->col = 0; else lp->col -= (*mb_head_off)(p, p + lp->col); ! /* Reset "coladd" when the cursor would be on the right half of a ! * double-wide character. */ if (lp->coladd == 1 && p[lp->col] != TAB && vim_isprintc((*mb_ptr2char)(p + lp->col)) --- 4121,4128 ---- lp->col = 0; else lp->col -= (*mb_head_off)(p, p + lp->col); ! // Reset "coladd" when the cursor would be on the right half of a ! // double-wide character. if (lp->coladd == 1 && p[lp->col] != TAB && vim_isprintc((*mb_ptr2char)(p + lp->col)) *************** *** 4137,4143 **** */ char_u * mb_prevptr( ! char_u *line, /* start of the string */ char_u *p) { if (p > line) --- 4136,4142 ---- */ char_u * mb_prevptr( ! char_u *line, // start of the string char_u *p) { if (p > line) *************** *** 4196,4204 **** int m = 0; char_u *str = *pp; ! /* Must translate K_SPECIAL KS_SPECIAL KE_FILLER to K_SPECIAL and CSI ! * KS_EXTRA KE_CSI to CSI. ! * Maximum length of a utf-8 character is 4 bytes. */ for (n = 0; str[n] != NUL && m < 4; ++n) { if (str[n] == K_SPECIAL --- 4195,4203 ---- int m = 0; char_u *str = *pp; ! // Must translate K_SPECIAL KS_SPECIAL KE_FILLER to K_SPECIAL and CSI ! // KS_EXTRA KE_CSI to CSI. ! // Maximum length of a utf-8 character is 4 bytes. for (n = 0; str[n] != NUL && m < 4; ++n) { if (str[n] == K_SPECIAL *************** *** 4224,4243 **** || str[n] == CSI # endif ) ! break; /* a special key can't be a multibyte char */ else buf[m++] = str[n]; buf[m] = NUL; ! /* Return a multi-byte character if it's found. An illegal sequence ! * will result in a 1 here. */ if ((*mb_ptr2len)(buf) > 1) { *pp = str + n + 1; return buf; } ! /* Bail out quickly for ASCII. */ if (buf[0] < 128) break; } --- 4223,4242 ---- || str[n] == CSI # endif ) ! break; // a special key can't be a multibyte char else buf[m++] = str[n]; buf[m] = NUL; ! // Return a multi-byte character if it's found. An illegal sequence ! // will result in a 1 here. if ((*mb_ptr2len)(buf) > 1) { *pp = str + n + 1; return buf; } ! // Bail out quickly for ASCII. if (buf[0] < 128) break; } *************** *** 4309,4326 **** if (STRCMP(enc, "default") == 0) { ! /* Use the default encoding as it's found by set_init_1(). */ r = get_encoding_default(); if (r == NULL) r = (char_u *)"latin1"; return vim_strsave(r); } ! /* copy "enc" to allocated memory, with room for two '-' */ r = alloc(STRLEN(enc) + 3); if (r != NULL) { ! /* Make it all lower case and replace '_' with '-'. */ p = r; for (s = enc; *s != NUL; ++s) { --- 4308,4325 ---- if (STRCMP(enc, "default") == 0) { ! // Use the default encoding as it's found by set_init_1(). r = get_encoding_default(); if (r == NULL) r = (char_u *)"latin1"; return vim_strsave(r); } ! // copy "enc" to allocated memory, with room for two '-' r = alloc(STRLEN(enc) + 3); if (r != NULL) { ! // Make it all lower case and replace '_' with '-'. p = r; for (s = enc; *s != NUL; ++s) { *************** *** 4331,4370 **** } *p = NUL; ! /* Skip "2byte-" and "8bit-". */ p = enc_skip(r); ! /* Change "microsoft-cp" to "cp". Used in some spell files. */ if (STRNCMP(p, "microsoft-cp", 12) == 0) STRMOVE(p, p + 10); ! /* "iso8859" -> "iso-8859" */ if (STRNCMP(p, "iso8859", 7) == 0) { STRMOVE(p + 4, p + 3); p[3] = '-'; } ! /* "iso-8859n" -> "iso-8859-n" */ if (STRNCMP(p, "iso-8859", 8) == 0 && p[8] != '-') { STRMOVE(p + 9, p + 8); p[8] = '-'; } ! /* "latin-N" -> "latinN" */ if (STRNCMP(p, "latin-", 6) == 0) STRMOVE(p + 5, p + 6); if (enc_canon_search(p) >= 0) { ! /* canonical name can be used unmodified */ if (p != r) STRMOVE(r, p); } else if ((i = enc_alias_search(p)) >= 0) { ! /* alias recognized, get canonical name */ vim_free(r); r = vim_strsave((char_u *)enc_canon_table[i].name); } --- 4330,4369 ---- } *p = NUL; ! // Skip "2byte-" and "8bit-". p = enc_skip(r); ! // Change "microsoft-cp" to "cp". Used in some spell files. if (STRNCMP(p, "microsoft-cp", 12) == 0) STRMOVE(p, p + 10); ! // "iso8859" -> "iso-8859" if (STRNCMP(p, "iso8859", 7) == 0) { STRMOVE(p + 4, p + 3); p[3] = '-'; } ! // "iso-8859n" -> "iso-8859-n" if (STRNCMP(p, "iso-8859", 8) == 0 && p[8] != '-') { STRMOVE(p + 9, p + 8); p[8] = '-'; } ! // "latin-N" -> "latinN" if (STRNCMP(p, "latin-", 6) == 0) STRMOVE(p + 5, p + 6); if (enc_canon_search(p) >= 0) { ! // canonical name can be used unmodified if (p != r) STRMOVE(r, p); } else if ((i = enc_alias_search(p)) >= 0) { ! // alias recognized, get canonical name vim_free(r); r = vim_strsave((char_u *)enc_canon_table[i].name); } *************** *** 4414,4433 **** if (s == NULL || *s == NUL) return NULL; ! /* The most generic locale format is: ! * language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]] ! * If there is a '.' remove the part before it. ! * if there is something after the codeset, remove it. ! * Make the name lowercase and replace '_' with '-'. ! * Exception: "ja_JP.EUC" == "euc-jp", "zh_CN.EUC" = "euc-cn", ! * "ko_KR.EUC" == "euc-kr" ! */ if ((p = (char *)vim_strchr((char_u *)s, '.')) != NULL) { if (p > s + 2 && STRNICMP(p + 1, "EUC", 3) == 0 && !isalnum((int)p[4]) && p[4] != '-' && p[-3] == '_') { ! /* copy "XY.EUC" to "euc-XY" to buf[10] */ STRCPY(buf + 10, "euc-"); buf[14] = p[-2]; buf[15] = p[-1]; --- 4413,4431 ---- if (s == NULL || *s == NUL) return NULL; ! // The most generic locale format is: ! // language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]] ! // If there is a '.' remove the part before it. ! // if there is something after the codeset, remove it. ! // Make the name lowercase and replace '_' with '-'. ! // Exception: "ja_JP.EUC" == "euc-jp", "zh_CN.EUC" = "euc-cn", ! // "ko_KR.EUC" == "euc-kr" if ((p = (char *)vim_strchr((char_u *)s, '.')) != NULL) { if (p > s + 2 && STRNICMP(p + 1, "EUC", 3) == 0 && !isalnum((int)p[4]) && p[4] != '-' && p[-3] == '_') { ! // copy "XY.EUC" to "euc-XY" to buf[10] STRCPY(buf + 10, "euc-"); buf[14] = p[-2]; buf[15] = p[-1]; *************** *** 4536,4545 **** static int iconv_ok = -1; if (iconv_ok == FALSE) ! return (void *)-1; /* detected a broken iconv() previously */ #ifdef DYNAMIC_ICONV ! /* Check if the iconv.dll can be found. */ if (!iconv_enabled(TRUE)) return (void *)-1; #endif --- 4534,4543 ---- static int iconv_ok = -1; if (iconv_ok == FALSE) ! return (void *)-1; // detected a broken iconv() previously #ifdef DYNAMIC_ICONV ! // Check if the iconv.dll can be found. if (!iconv_enabled(TRUE)) return (void *)-1; #endif *************** *** 4602,4651 **** { if (len == 0 || ICONV_ERRNO == ICONV_E2BIG) { ! /* Allocate enough room for most conversions. When re-allocating ! * increase the buffer size. */ len = len + fromlen * 2 + 40; p = alloc(len); if (p != NULL && done > 0) mch_memmove(p, result, done); vim_free(result); result = p; ! if (result == NULL) /* out of memory */ break; } to = (char *)result + done; tolen = len - done - 2; ! /* Avoid a warning for systems with a wrong iconv() prototype by ! * casting the second argument to void *. */ if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen) != (size_t)-1) { ! /* Finished, append a NUL. */ *to = NUL; break; } ! /* Check both ICONV_EINVAL and EINVAL, because the dynamically loaded ! * iconv library may use one of them. */ if (!vcp->vc_fail && unconvlenp != NULL && (ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) { ! /* Handle an incomplete sequence at the end. */ *to = NUL; *unconvlenp = (int)fromlen; break; } ! /* Check both ICONV_EILSEQ and EILSEQ, because the dynamically loaded ! * iconv library may use one of them. */ else if (!vcp->vc_fail && (ICONV_ERRNO == ICONV_EILSEQ || ICONV_ERRNO == EILSEQ || ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) { ! /* Can't convert: insert a '?' and skip a character. This assumes ! * conversion from 'encoding' to something else. In other ! * situations we don't know what to skip anyway. */ *to++ = '?'; if ((*mb_ptr2cells)((char_u *)from) > 1) *to++ = '?'; --- 4600,4649 ---- { if (len == 0 || ICONV_ERRNO == ICONV_E2BIG) { ! // Allocate enough room for most conversions. When re-allocating ! // increase the buffer size. len = len + fromlen * 2 + 40; p = alloc(len); if (p != NULL && done > 0) mch_memmove(p, result, done); vim_free(result); result = p; ! if (result == NULL) // out of memory break; } to = (char *)result + done; tolen = len - done - 2; ! // Avoid a warning for systems with a wrong iconv() prototype by ! // casting the second argument to void *. if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen) != (size_t)-1) { ! // Finished, append a NUL. *to = NUL; break; } ! // Check both ICONV_EINVAL and EINVAL, because the dynamically loaded ! // iconv library may use one of them. if (!vcp->vc_fail && unconvlenp != NULL && (ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) { ! // Handle an incomplete sequence at the end. *to = NUL; *unconvlenp = (int)fromlen; break; } ! // Check both ICONV_EILSEQ and EILSEQ, because the dynamically loaded ! // iconv library may use one of them. else if (!vcp->vc_fail && (ICONV_ERRNO == ICONV_EILSEQ || ICONV_ERRNO == EILSEQ || ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) { ! // Can't convert: insert a '?' and skip a character. This assumes ! // conversion from 'encoding' to something else. In other ! // situations we don't know what to skip anyway. *to++ = '?'; if ((*mb_ptr2cells)((char_u *)from) > 1) *to++ = '?'; *************** *** 4662,4672 **** } else if (ICONV_ERRNO != ICONV_E2BIG) { ! /* conversion failed */ VIM_CLEAR(result); break; } ! /* Not enough room or skipping illegal sequence. */ done = to - (char *)result; } --- 4660,4670 ---- } else if (ICONV_ERRNO != ICONV_E2BIG) { ! // conversion failed VIM_CLEAR(result); break; } ! // Not enough room or skipping illegal sequence. done = to - (char *)result; } *************** *** 4680,4686 **** * Dynamically load the "iconv.dll" on Win32. */ ! # ifndef DYNAMIC_ICONV /* must be generating prototypes */ # define HINSTANCE int # endif static HINSTANCE hIconvDLL = 0; --- 4678,4684 ---- * Dynamically load the "iconv.dll" on Win32. */ ! # ifndef DYNAMIC_ICONV // must be generating prototypes # define HINSTANCE int # endif static HINSTANCE hIconvDLL = 0; *************** *** 4705,4712 **** if (hIconvDLL != 0 && hMsvcrtDLL != 0) return TRUE; ! /* The iconv DLL file goes under different names, try them all. ! * Do the "2" version first, it's newer. */ #ifdef DYNAMIC_ICONV_DLL_ALT2 if (hIconvDLL == 0) hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT2); --- 4703,4710 ---- if (hIconvDLL != 0 && hMsvcrtDLL != 0) return TRUE; ! // The iconv DLL file goes under different names, try them all. ! // Do the "2" version first, it's newer. #ifdef DYNAMIC_ICONV_DLL_ALT2 if (hIconvDLL == 0) hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT2); *************** *** 4726,4733 **** hMsvcrtDLL = vimLoadLib(DYNAMIC_MSVCRT_DLL); if (hIconvDLL == 0 || hMsvcrtDLL == 0) { ! /* Only give the message when 'verbose' is set, otherwise it might be ! * done whenever a conversion is attempted. */ if (verbose && p_verbose > 0) { verbose_enter(); --- 4724,4731 ---- hMsvcrtDLL = vimLoadLib(DYNAMIC_MSVCRT_DLL); if (hIconvDLL == 0 || hMsvcrtDLL == 0) { ! // Only give the message when 'verbose' is set, otherwise it might be ! // done whenever a conversion is attempted. if (verbose && p_verbose > 0) { verbose_enter(); *************** *** 4764,4770 **** void iconv_end(void) { ! /* Don't use iconv() when inputting or outputting characters. */ if (input_conv.vc_type == CONV_ICONV) convert_setup(&input_conv, NULL, NULL); if (output_conv.vc_type == CONV_ICONV) --- 4762,4768 ---- void iconv_end(void) { ! // Don't use iconv() when inputting or outputting characters. if (input_conv.vc_type == CONV_ICONV) convert_setup(&input_conv, NULL, NULL); if (output_conv.vc_type == CONV_ICONV) *************** *** 4777,4784 **** hIconvDLL = 0; hMsvcrtDLL = 0; } ! # endif /* DYNAMIC_ICONV */ ! # endif /* USE_ICONV */ #ifdef FEAT_GUI --- 4775,4782 ---- hIconvDLL = 0; hMsvcrtDLL = 0; } ! # endif // DYNAMIC_ICONV ! # endif // USE_ICONV #ifdef FEAT_GUI *************** *** 4807,4817 **** { int is_active; ! /* FIXME: Don't execute user function in unsafe situation. */ if (exiting || is_autocmd_blocked()) return FALSE; ! /* FIXME: :py print 'xxx' is shown duplicate result. ! * Use silent to avoid it. */ ++msg_silent; is_active = call_func_retnr(p_imsf, 0, NULL); --msg_silent; --- 4805,4815 ---- { int is_active; ! // FIXME: Don't execute user function in unsafe situation. if (exiting || is_autocmd_blocked()) return FALSE; ! // FIXME: :py print 'xxx' is shown duplicate result. ! // Use silent to avoid it. ++msg_silent; is_active = call_func_retnr(p_imsf, 0, NULL); --msg_silent; *************** *** 4822,4828 **** #if defined(FEAT_XIM) || defined(PROTO) # if defined(FEAT_GUI_GTK) || defined(PROTO) ! static int xim_has_preediting INIT(= FALSE); /* IM current status */ /* * Set preedit_start_col to the current cursor position. --- 4820,4826 ---- #if defined(FEAT_XIM) || defined(PROTO) # if defined(FEAT_GUI_GTK) || defined(PROTO) ! static int xim_has_preediting INIT(= FALSE); // IM current status /* * Set preedit_start_col to the current cursor position. *************** *** 4834,4847 **** preedit_start_col = cmdline_getvcol_cursor(); else if (curwin != NULL && curwin->w_buffer != NULL) getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); ! /* Prevent that preediting marks the buffer as changed. */ xim_changed_while_preediting = curbuf->b_changed; } ! static int im_is_active = FALSE; /* IM is enabled for current mode */ static int preedit_is_active = FALSE; ! static int im_preedit_cursor = 0; /* cursor offset in characters */ ! static int im_preedit_trailing = 0; /* number of characters after cursor */ static unsigned long im_commit_handler_id = 0; static unsigned int im_activatekey_keyval = GDK_VoidSymbol; --- 4832,4845 ---- preedit_start_col = cmdline_getvcol_cursor(); else if (curwin != NULL && curwin->w_buffer != NULL) getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); ! // Prevent that preediting marks the buffer as changed. xim_changed_while_preediting = curbuf->b_changed; } ! static int im_is_active = FALSE; // IM is enabled for current mode static int preedit_is_active = FALSE; ! static int im_preedit_cursor = 0; // cursor offset in characters ! static int im_preedit_trailing = 0; // number of characters after cursor static unsigned long im_commit_handler_id = 0; static unsigned int im_activatekey_keyval = GDK_VoidSymbol; *************** *** 4895,4901 **** } } ! # if 0 || defined(PROTO) /* apparently only used in gui_x11.c */ void xim_set_preedit(void) { --- 4893,4899 ---- } } ! # if 0 || defined(PROTO) // apparently only used in gui_x11.c void xim_set_preedit(void) { *************** *** 4906,4912 **** static void im_add_to_input(char_u *str, int len) { ! /* Convert from 'termencoding' (always "utf-8") to 'encoding' */ if (input_conv.vc_type != CONV_NONE) { str = string_convert(&input_conv, str, &len); --- 4904,4910 ---- static void im_add_to_input(char_u *str, int len) { ! // Convert from 'termencoding' (always "utf-8") to 'encoding' if (input_conv.vc_type != CONV_NONE) { str = string_convert(&input_conv, str, &len); *************** *** 4918,4924 **** if (input_conv.vc_type != CONV_NONE) vim_free(str); ! if (p_mh) /* blank out the pointer if necessary */ gui_mch_mousehide(TRUE); } --- 4916,4922 ---- if (input_conv.vc_type != CONV_NONE) vim_free(str); ! if (p_mh) // blank out the pointer if necessary gui_mch_mousehide(TRUE); } *************** *** 4986,4993 **** if (!pango_font_description_get_size_is_absolute(gui.norm_font)) { ! /* fontsize was given in points. Convert it into that in pixels ! * to use with CSS. */ GdkScreen * const screen = gdk_window_get_screen(gtk_widget_get_window(gui.mainwin)); const gdouble dpi = gdk_screen_get_resolution(screen); --- 4984,4991 ---- if (!pango_font_description_get_size_is_absolute(gui.norm_font)) { ! // fontsize was given in points. Convert it into that in pixels ! // to use with CSS. GdkScreen * const screen = gdk_window_get_screen(gtk_widget_get_window(gui.mainwin)); const gdouble dpi = gdk_screen_get_resolution(screen); *************** *** 5078,5084 **** { im_preedit_window_open(); ! if (p_mh) /* blank out the pointer if necessary */ gui_mch_mousehide(TRUE); } --- 5076,5082 ---- { im_preedit_window_open(); ! if (p_mh) // blank out the pointer if necessary gui_mch_mousehide(TRUE); } *************** *** 5172,5197 **** if (p_imst == IM_ON_THE_SPOT) { ! /* The imhangul module doesn't reset the preedit string before ! * committing. Call im_delete_preedit() to work around that. */ im_delete_preedit(); ! /* Indicate that preediting has finished. */ if (preedit_start_col == MAXCOL) { init_preedit_start_col(); commit_with_preedit = FALSE; } ! /* The thing which setting "preedit_start_col" to MAXCOL means that ! * "preedit_start_col" will be set forcedly when calling ! * preedit_changed_cb() next time. ! * "preedit_start_col" should not reset with MAXCOL on this part. Vim ! * is simulating the preediting by using add_to_input_str(). when ! * preedit begin immediately before committed, the typebuf is not ! * flushed to screen, then it can't get correct "preedit_start_col". ! * Thus, it should calculate the cells by adding cells of the committed ! * string. */ if (input_conv.vc_type != CONV_NONE) { im_str = string_convert(&input_conv, (char_u *)str, &len); --- 5170,5195 ---- if (p_imst == IM_ON_THE_SPOT) { ! // The imhangul module doesn't reset the preedit string before ! // committing. Call im_delete_preedit() to work around that. im_delete_preedit(); ! // Indicate that preediting has finished. if (preedit_start_col == MAXCOL) { init_preedit_start_col(); commit_with_preedit = FALSE; } ! // The thing which setting "preedit_start_col" to MAXCOL means that ! // "preedit_start_col" will be set forcedly when calling ! // preedit_changed_cb() next time. ! // "preedit_start_col" should not reset with MAXCOL on this part. Vim ! // is simulating the preediting by using add_to_input_str(). when ! // preedit begin immediately before committed, the typebuf is not ! // flushed to screen, then it can't get correct "preedit_start_col". ! // Thus, it should calculate the cells by adding cells of the committed ! // string. if (input_conv.vc_type != CONV_NONE) { im_str = string_convert(&input_conv, (char_u *)str, &len); *************** *** 5207,5228 **** preedit_start_col += clen; } ! /* Is this a single character that matches a keypad key that's just ! * been pressed? If so, we don't want it to be entered as such - let ! * us carry on processing the raw keycode so that it may be used in ! * mappings as . */ if (xim_expected_char != NUL) { ! /* We're currently processing a keypad or other special key */ if (slen == 1 && str[0] == xim_expected_char) { ! /* It's a match - don't do it here */ xim_ignored_char = TRUE; add_to_input = FALSE; } else { ! /* Not a match */ xim_ignored_char = FALSE; } } --- 5205,5226 ---- preedit_start_col += clen; } ! // Is this a single character that matches a keypad key that's just ! // been pressed? If so, we don't want it to be entered as such - let ! // us carry on processing the raw keycode so that it may be used in ! // mappings as . if (xim_expected_char != NUL) { ! // We're currently processing a keypad or other special key if (slen == 1 && str[0] == xim_expected_char) { ! // It's a match - don't do it here xim_ignored_char = TRUE; add_to_input = FALSE; } else { ! // Not a match xim_ignored_char = FALSE; } } *************** *** 5232,5244 **** if (p_imst == IM_ON_THE_SPOT) { ! /* Inserting chars while "im_is_active" is set does not cause a ! * change of buffer. When the chars are committed the buffer must be ! * marked as changed. */ if (!commit_with_preedit) preedit_start_col = MAXCOL; ! /* This flag is used in changed() at next call. */ xim_changed_while_preediting = TRUE; } --- 5230,5242 ---- if (p_imst == IM_ON_THE_SPOT) { ! // Inserting chars while "im_is_active" is set does not cause a ! // change of buffer. When the chars are committed the buffer must be ! // marked as changed. if (!commit_with_preedit) preedit_start_col = MAXCOL; ! // This flag is used in changed() at next call. xim_changed_while_preediting = TRUE; } *************** *** 5273,5287 **** #endif im_delete_preedit(); ! /* Indicate that preediting has finished */ if (p_imst == IM_ON_THE_SPOT) preedit_start_col = MAXCOL; xim_has_preediting = FALSE; #if 0 ! /* Removal of this line suggested by Takuhiro Nishioka. Fixes that IM was ! * switched off unintentionally. We now use preedit_is_active (added by ! * SungHyun Nam). */ im_is_active = FALSE; #endif preedit_is_active = FALSE; --- 5271,5285 ---- #endif im_delete_preedit(); ! // Indicate that preediting has finished if (p_imst == IM_ON_THE_SPOT) preedit_start_col = MAXCOL; xim_has_preediting = FALSE; #if 0 ! // Removal of this line suggested by Takuhiro Nishioka. Fixes that IM was ! // switched off unintentionally. We now use preedit_is_active (added by ! // SungHyun Nam). im_is_active = FALSE; #endif preedit_is_active = FALSE; *************** *** 5349,5355 **** xim_log("im_preedit_changed_cb(): %s\n", preedit_string); #endif ! g_return_if_fail(preedit_string != NULL); /* just in case */ if (p_imst == IM_OVER_THE_SPOT) { --- 5347,5353 ---- xim_log("im_preedit_changed_cb(): %s\n", preedit_string); #endif ! g_return_if_fail(preedit_string != NULL); // just in case if (p_imst == IM_OVER_THE_SPOT) { *************** *** 5366,5385 **** } else { ! /* If preedit_start_col is MAXCOL set it to the current cursor position. */ if (preedit_start_col == MAXCOL && preedit_string[0] != '\0') { xim_has_preediting = TRUE; ! /* Urgh, this breaks if the input buffer isn't empty now */ init_preedit_start_col(); } else if (cursor_index == 0 && preedit_string[0] == '\0') { xim_has_preediting = FALSE; ! /* If at the start position (after typing backspace) ! * preedit_start_col must be reset. */ preedit_start_col = MAXCOL; } --- 5364,5383 ---- } else { ! // If preedit_start_col is MAXCOL set it to the current cursor position. if (preedit_start_col == MAXCOL && preedit_string[0] != '\0') { xim_has_preediting = TRUE; ! // Urgh, this breaks if the input buffer isn't empty now init_preedit_start_col(); } else if (cursor_index == 0 && preedit_string[0] == '\0') { xim_has_preediting = FALSE; ! // If at the start position (after typing backspace) ! // preedit_start_col must be reset. preedit_start_col = MAXCOL; } *************** *** 5414,5421 **** } if (!is_composing && i >= cursor_index) { ! /* This is essentially the same as im_preedit_trailing, except ! * composing characters are not counted even if p_deco is set. */ ++num_move_back; } if (preedit_start_col != MAXCOL) --- 5412,5419 ---- } if (!is_composing && i >= cursor_index) { ! // This is essentially the same as im_preedit_trailing, except ! // composing characters are not counted even if p_deco is set. ++num_move_back; } if (preedit_start_col != MAXCOL) *************** *** 5466,5472 **** { const PangoColor *color = &((PangoAttrColor *)attr)->color; ! /* Assume inverse if black background is requested */ if ((color->red | color->green | color->blue) == 0) char_attr |= HL_INVERSE; } --- 5464,5470 ---- { const PangoColor *color = &((PangoAttrColor *)attr)->color; ! // Assume inverse if black background is requested if ((color->red | color->green | color->blue) == 0) char_attr |= HL_INVERSE; } *************** *** 5494,5500 **** { int idx; ! /* Get the byte index as used by PangoAttrIterator */ for (idx = 0; col > 0 && preedit_string[idx] != '\0'; --col) idx += utfc_ptr2len((char_u *)preedit_string + idx); --- 5492,5498 ---- { int idx; ! // Get the byte index as used by PangoAttrIterator for (idx = 0; col > 0 && preedit_string[idx] != '\0'; --col) idx += utfc_ptr2len((char_u *)preedit_string + idx); *************** *** 5506,5512 **** char_attr = HL_NORMAL; iter = pango_attr_list_get_iterator(attr_list); ! /* Extract all relevant attributes from the list. */ do { pango_attr_iterator_range(iter, &start, &end); --- 5504,5510 ---- char_attr = HL_NORMAL; iter = pango_attr_list_get_iterator(attr_list); ! // Extract all relevant attributes from the list. do { pango_attr_iterator_range(iter, &start, &end); *************** *** 5588,5594 **** mods_end = strrchr(str, '-'); mods_end = (mods_end != NULL) ? mods_end + 1 : str; ! /* Parse modifier keys */ while (str < mods_end) switch (*str++) { --- 5586,5592 ---- mods_end = strrchr(str, '-'); mods_end = (mods_end != NULL) ? mods_end + 1 : str; ! // Parse modifier keys while (str < mods_end) switch (*str++) { *************** *** 5649,5668 **** event = (GdkEventKey *)gdk_event_new(GDK_KEY_PRESS); g_object_ref(gtk_widget_get_window(gui.drawarea)); ! /* unreffed by gdk_event_free() */ event->window = gtk_widget_get_window(gui.drawarea); event->send_event = TRUE; event->time = GDK_CURRENT_TIME; event->state = state; event->keyval = keyval; ! event->hardware_keycode = /* needed for XIM */ XKeysymToKeycode(GDK_WINDOW_XDISPLAY(event->window), (KeySym)keyval); event->length = 0; event->string = NULL; gtk_im_context_filter_keypress(xic, event); ! /* For consistency, also send the corresponding release event. */ event->type = GDK_KEY_RELEASE; event->send_event = FALSE; gtk_im_context_filter_keypress(xic, event); --- 5647,5666 ---- event = (GdkEventKey *)gdk_event_new(GDK_KEY_PRESS); g_object_ref(gtk_widget_get_window(gui.drawarea)); ! // unreffed by gdk_event_free() event->window = gtk_widget_get_window(gui.drawarea); event->send_event = TRUE; event->time = GDK_CURRENT_TIME; event->state = state; event->keyval = keyval; ! event->hardware_keycode = // needed for XIM XKeysymToKeycode(GDK_WINDOW_XDISPLAY(event->window), (KeySym)keyval); event->length = 0; event->string = NULL; gtk_im_context_filter_keypress(xic, event); ! // For consistency, also send the corresponding release event. event->type = GDK_KEY_RELEASE; event->send_event = FALSE; gtk_im_context_filter_keypress(xic, event); *************** *** 5770,5778 **** { unsigned int state_mask; ! /* Require the state of the 3 most used modifiers to match exactly. ! * Otherwise e.g. would be unusable for other purposes ! * if the IM activate key is . */ state_mask = im_activatekey_state; state_mask |= ((int)GDK_SHIFT_MASK | (int)GDK_CONTROL_MASK | (int)GDK_MOD1_MASK); --- 5768,5776 ---- { unsigned int state_mask; ! // Require the state of the 3 most used modifiers to match exactly. ! // Otherwise e.g. would be unusable for other purposes ! // if the IM activate key is . state_mask = im_activatekey_state; state_mask |= ((int)GDK_SHIFT_MASK | (int)GDK_CONTROL_MASK | (int)GDK_MOD1_MASK); *************** *** 5780,5786 **** if ((event->state & state_mask) != im_activatekey_state) return FALSE; ! /* Don't send it a second time on GDK_KEY_RELEASE. */ if (event->type != GDK_KEY_PRESS) return TRUE; --- 5778,5784 ---- if ((event->state & state_mask) != im_activatekey_state) return FALSE; ! // Don't send it a second time on GDK_KEY_RELEASE. if (event->type != GDK_KEY_PRESS) return TRUE; *************** *** 5788,5794 **** { im_set_active(FALSE); ! /* ":lmap" mappings exists, toggle use of mappings. */ State ^= LANGMAP; if (State & LANGMAP) { --- 5786,5792 ---- { im_set_active(FALSE); ! // ":lmap" mappings exists, toggle use of mappings. State ^= LANGMAP; if (State & LANGMAP) { *************** *** 5806,5828 **** return gtk_im_context_filter_keypress(xic, event); } ! /* Don't filter events through the IM context if IM isn't active ! * right now. Unlike with GTK+ 1.2 we cannot rely on the IM module ! * not doing anything before the activation key was sent. */ if (im_activatekey_keyval == GDK_VoidSymbol || im_is_active) { int imresult = gtk_im_context_filter_keypress(xic, event); if (p_imst == IM_ON_THE_SPOT) { ! /* Some XIM send following sequence: ! * 1. preedited string. ! * 2. committed string. ! * 3. line changed key. ! * 4. preedited string. ! * 5. remove preedited string. ! * if 3, Vim can't move back the above line for 5. ! * thus, this part should not parse the key. */ if (!imresult && preedit_start_col != MAXCOL && event->keyval == GDK_Return) { --- 5804,5826 ---- return gtk_im_context_filter_keypress(xic, event); } ! // Don't filter events through the IM context if IM isn't active ! // right now. Unlike with GTK+ 1.2 we cannot rely on the IM module ! // not doing anything before the activation key was sent. if (im_activatekey_keyval == GDK_VoidSymbol || im_is_active) { int imresult = gtk_im_context_filter_keypress(xic, event); if (p_imst == IM_ON_THE_SPOT) { ! // Some XIM send following sequence: ! // 1. preedited string. ! // 2. committed string. ! // 3. line changed key. ! // 4. preedited string. ! // 5. remove preedited string. ! // if 3, Vim can't move back the above line for 5. ! // thus, this part should not parse the key. if (!imresult && preedit_start_col != MAXCOL && event->keyval == GDK_Return) { *************** *** 5831,5847 **** } } ! /* If XIM tried to commit a keypad key as a single char., ! * ignore it so we can use the keypad key 'raw', for mappings. */ if (xim_expected_char != NUL && xim_ignored_char) ! /* We had a keypad key, and XIM tried to thieve it */ return FALSE; ! /* This is supposed to fix a problem with iBus, that space ! * characters don't work in input mode. */ xim_expected_char = NUL; ! /* Normal processing */ return imresult; } } --- 5829,5845 ---- } } ! // If XIM tried to commit a keypad key as a single char., ! // ignore it so we can use the keypad key 'raw', for mappings. if (xim_expected_char != NUL && xim_ignored_char) ! // We had a keypad key, and XIM tried to thieve it return FALSE; ! // This is supposed to fix a problem with iBus, that space ! // characters don't work in input mode. xim_expected_char = NUL; ! // Normal processing return imresult; } } *************** *** 5871,5881 **** return xim_has_preediting; } ! # else /* !FEAT_GUI_GTK */ ! static int xim_is_active = FALSE; /* XIM should be active in the current ! mode */ ! static int xim_has_focus = FALSE; /* XIM is really being used for Vim */ # ifdef FEAT_GUI_X11 static XIMStyle input_style; static int status_area_enabled = TRUE; --- 5869,5879 ---- return xim_has_preediting; } ! # else // !FEAT_GUI_GTK ! static int xim_is_active = FALSE; // XIM should be active in the current ! // mode ! static int xim_has_focus = FALSE; // XIM is really being used for Vim # ifdef FEAT_GUI_X11 static XIMStyle input_style; static int status_area_enabled = TRUE; *************** *** 5890,5902 **** { int active = active_arg; ! /* If 'imdisable' is set, XIM is never active. */ if (p_imdisable) active = FALSE; else if (input_style & XIMPreeditPosition) ! /* There is a problem in switching XIM off when preediting is used, ! * and it is not clear how this can be solved. For now, keep XIM on ! * all the time, like it was done in Vim 5.8. */ active = TRUE; # if defined(FEAT_EVAL) --- 5888,5900 ---- { int active = active_arg; ! // If 'imdisable' is set, XIM is never active. if (p_imdisable) active = FALSE; else if (input_style & XIMPreeditPosition) ! // There is a problem in switching XIM off when preediting is used, ! // and it is not clear how this can be solved. For now, keep XIM on ! // all the time, like it was done in Vim 5.8. active = TRUE; # if defined(FEAT_EVAL) *************** *** 5914,5920 **** if (xic == NULL) return; ! /* Remember the active state, it is needed when Vim gets keyboard focus. */ xim_is_active = active; xim_set_preedit(); } --- 5912,5918 ---- if (xic == NULL) return; ! // Remember the active state, it is needed when Vim gets keyboard focus. xim_is_active = active; xim_set_preedit(); } *************** *** 5975,5983 **** if (!xim_has_focus) { ! /* hide XIM cursor */ over_spot.x = 0; ! over_spot.y = -100; /* arbitrary invisible position */ attr_list = (XVaNestedList) XVaCreateNestedList(0, XNSpotLocation, &over_spot, --- 5973,5981 ---- if (!xim_has_focus) { ! // hide XIM cursor over_spot.x = 0; ! over_spot.y = -100; // arbitrary invisible position attr_list = (XVaNestedList) XVaCreateNestedList(0, XNSpotLocation, &over_spot, *************** *** 6155,6170 **** if (xim == NULL && (p = XSetLocaleModifiers("")) != NULL && *p != NUL) xim = XOpenIM(x11_display, NULL, NULL, NULL); ! /* This is supposed to be useful to obtain characters through ! * XmbLookupString() without really using a XIM. */ if (xim == NULL && (p = XSetLocaleModifiers("@im=none")) != NULL && *p != NUL) xim = XOpenIM(x11_display, NULL, NULL, NULL); if (xim == NULL) { ! /* Only give this message when verbose is set, because too many people ! * got this message when they didn't want to use a XIM. */ if (p_verbose > 0) { verbose_enter(); --- 6153,6168 ---- if (xim == NULL && (p = XSetLocaleModifiers("")) != NULL && *p != NUL) xim = XOpenIM(x11_display, NULL, NULL, NULL); ! // This is supposed to be useful to obtain characters through ! // XmbLookupString() without really using a XIM. if (xim == NULL && (p = XSetLocaleModifiers("@im=none")) != NULL && *p != NUL) xim = XOpenIM(x11_display, NULL, NULL, NULL); if (xim == NULL) { ! // Only give this message when verbose is set, because too many people ! // got this message when they didn't want to use a XIM. if (p_verbose > 0) { verbose_enter(); *************** *** 6241,6248 **** if (!found) { ! /* Only give this message when verbose is set, because too many people ! * got this message when they didn't want to use a XIM. */ if (p_verbose > 0) { verbose_enter(); --- 6239,6246 ---- if (!found) { ! // Only give this message when verbose is set, because too many people ! // got this message when they didn't want to use a XIM. if (p_verbose > 0) { verbose_enter(); *************** *** 6257,6264 **** over_spot.y = TEXT_Y(gui.row); input_style = this_input_style; ! /* A crash was reported when trying to pass gui.norm_font as XNFontSet, ! * thus that has been removed. Hopefully the default works... */ # ifdef FEAT_XFONTSET if (gui.fontset != NOFONTSET) { --- 6255,6262 ---- over_spot.y = TEXT_Y(gui.row); input_style = this_input_style; ! // A crash was reported when trying to pass gui.norm_font as XNFontSet, ! // thus that has been removed. Hopefully the default works... # ifdef FEAT_XFONTSET if (gui.fontset != NOFONTSET) { *************** *** 6318,6324 **** return TRUE; } ! # endif /* FEAT_GUI_X11 */ /* * Get IM status. When IM is on, return TRUE. Else return FALSE. --- 6316,6322 ---- return TRUE; } ! # endif // FEAT_GUI_X11 /* * Get IM status. When IM is on, return TRUE. Else return FALSE. *************** *** 6336,6342 **** return xim_has_focus; } ! # endif /* !FEAT_GUI_GTK */ # if !defined(FEAT_GUI_GTK) || defined(PROTO) /* --- 6334,6340 ---- return xim_has_focus; } ! # endif // !FEAT_GUI_GTK # if !defined(FEAT_GUI_GTK) || defined(PROTO) /* *************** *** 6362,6368 **** { XRectangle *needed_rect; ! /* to get status_area width */ status_list = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); XGetICValues(xic, XNStatusAttributes, status_list, NULL); --- 6360,6366 ---- { XRectangle *needed_rect; ! // to get status_area width status_list = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); XGetICValues(xic, XNStatusAttributes, status_list, NULL); *************** *** 6398,6404 **** status_area.height = gui.char_height; } ! if (input_style & XIMPreeditArea) /* off-the-spot */ { pre_area.x = status_area.x + status_area.width; pre_area.y = gui.char_height * Rows + gui.border_offset; --- 6396,6402 ---- status_area.height = gui.char_height; } ! if (input_style & XIMPreeditArea) // off-the-spot { pre_area.x = status_area.x + status_area.width; pre_area.y = gui.char_height * Rows + gui.border_offset; *************** *** 6412,6418 **** pre_area.height = gui.char_height; preedit_list = XVaCreateNestedList(0, XNArea, &pre_area, NULL); } ! else if (input_style & XIMPreeditPosition) /* over-the-spot */ { pre_area.x = 0; pre_area.y = 0; --- 6410,6416 ---- pre_area.height = gui.char_height; preedit_list = XVaCreateNestedList(0, XNArea, &pre_area, NULL); } ! else if (input_style & XIMPreeditPosition) // over-the-spot { pre_area.x = 0; pre_area.y = 0; *************** *** 6453,6459 **** } # endif ! #else /* !defined(FEAT_XIM) */ # if defined(IME_WITHOUT_XIM) || defined(VIMDLL) static int im_was_set_active = FALSE; --- 6451,6457 ---- } # endif ! #else // !defined(FEAT_XIM) # if defined(IME_WITHOUT_XIM) || defined(VIMDLL) static int im_was_set_active = FALSE; *************** *** 6498,6504 **** # endif # endif ! #endif /* FEAT_XIM */ #if defined(FEAT_EVAL) || defined(PROTO) /* --- 6496,6502 ---- # endif # endif ! #endif // FEAT_XIM #if defined(FEAT_EVAL) || defined(PROTO) /* *************** *** 6545,6551 **** int from_is_utf8; int to_is_utf8; ! /* Reset to no conversion. */ #ifdef USE_ICONV if (vcp->vc_type == CONV_ICONV && vcp->vc_fd != (iconv_t)-1) iconv_close(vcp->vc_fd); --- 6543,6549 ---- int from_is_utf8; int to_is_utf8; ! // Reset to no conversion. #ifdef USE_ICONV if (vcp->vc_type == CONV_ICONV && vcp->vc_fd != (iconv_t)-1) iconv_close(vcp->vc_fd); *************** *** 6554,6560 **** vcp->vc_factor = 1; vcp->vc_fail = FALSE; ! /* No conversion when one of the names is empty or they are equal. */ if (from == NULL || *from == NUL || to == NULL || *to == NUL || STRCMP(from, to) == 0) return OK; --- 6552,6558 ---- vcp->vc_factor = 1; vcp->vc_fail = FALSE; ! // No conversion when one of the names is empty or they are equal. if (from == NULL || *from == NUL || to == NULL || *to == NUL || STRCMP(from, to) == 0) return OK; *************** *** 6572,6604 **** if ((from_prop & ENC_LATIN1) && to_is_utf8) { ! /* Internal latin1 -> utf-8 conversion. */ vcp->vc_type = CONV_TO_UTF8; ! vcp->vc_factor = 2; /* up to twice as long */ } else if ((from_prop & ENC_LATIN9) && to_is_utf8) { ! /* Internal latin9 -> utf-8 conversion. */ vcp->vc_type = CONV_9_TO_UTF8; ! vcp->vc_factor = 3; /* up to three as long (euro sign) */ } else if (from_is_utf8 && (to_prop & ENC_LATIN1)) { ! /* Internal utf-8 -> latin1 conversion. */ vcp->vc_type = CONV_TO_LATIN1; } else if (from_is_utf8 && (to_prop & ENC_LATIN9)) { ! /* Internal utf-8 -> latin9 conversion. */ vcp->vc_type = CONV_TO_LATIN9; } #ifdef MSWIN ! /* Win32-specific codepage <-> codepage conversion without iconv. */ else if ((from_is_utf8 || encname2codepage(from) > 0) && (to_is_utf8 || encname2codepage(to) > 0)) { vcp->vc_type = CONV_CODEPAGE; ! vcp->vc_factor = 2; /* up to twice as long */ vcp->vc_cpfrom = from_is_utf8 ? 0 : encname2codepage(from); vcp->vc_cpto = to_is_utf8 ? 0 : encname2codepage(to); } --- 6570,6602 ---- if ((from_prop & ENC_LATIN1) && to_is_utf8) { ! // Internal latin1 -> utf-8 conversion. vcp->vc_type = CONV_TO_UTF8; ! vcp->vc_factor = 2; // up to twice as long } else if ((from_prop & ENC_LATIN9) && to_is_utf8) { ! // Internal latin9 -> utf-8 conversion. vcp->vc_type = CONV_9_TO_UTF8; ! vcp->vc_factor = 3; // up to three as long (euro sign) } else if (from_is_utf8 && (to_prop & ENC_LATIN1)) { ! // Internal utf-8 -> latin1 conversion. vcp->vc_type = CONV_TO_LATIN1; } else if (from_is_utf8 && (to_prop & ENC_LATIN9)) { ! // Internal utf-8 -> latin9 conversion. vcp->vc_type = CONV_TO_LATIN9; } #ifdef MSWIN ! // Win32-specific codepage <-> codepage conversion without iconv. else if ((from_is_utf8 || encname2codepage(from) > 0) && (to_is_utf8 || encname2codepage(to) > 0)) { vcp->vc_type = CONV_CODEPAGE; ! vcp->vc_factor = 2; // up to twice as long vcp->vc_cpfrom = from_is_utf8 ? 0 : encname2codepage(from); vcp->vc_cpto = to_is_utf8 ? 0 : encname2codepage(to); } *************** *** 6611,6617 **** else if ((from_prop & ENC_MACROMAN) && to_is_utf8) { vcp->vc_type = CONV_MAC_UTF8; ! vcp->vc_factor = 2; /* up to twice as long */ } else if ((from_prop & ENC_LATIN1) && (to_prop & ENC_MACROMAN)) { --- 6609,6615 ---- else if ((from_prop & ENC_MACROMAN) && to_is_utf8) { vcp->vc_type = CONV_MAC_UTF8; ! vcp->vc_factor = 2; // up to twice as long } else if ((from_prop & ENC_LATIN1) && (to_prop & ENC_MACROMAN)) { *************** *** 6625,6638 **** #ifdef USE_ICONV else { ! /* Use iconv() for conversion. */ vcp->vc_fd = (iconv_t)my_iconv_open( to_is_utf8 ? (char_u *)"utf-8" : to, from_is_utf8 ? (char_u *)"utf-8" : from); if (vcp->vc_fd != (iconv_t)-1) { vcp->vc_type = CONV_ICONV; ! vcp->vc_factor = 4; /* could be longer too... */ } } #endif --- 6623,6636 ---- #ifdef USE_ICONV else { ! // Use iconv() for conversion. vcp->vc_fd = (iconv_t)my_iconv_open( to_is_utf8 ? (char_u *)"utf-8" : to, from_is_utf8 ? (char_u *)"utf-8" : from); if (vcp->vc_fd != (iconv_t)-1) { vcp->vc_type = CONV_ICONV; ! vcp->vc_factor = 4; // could be longer too... } } #endif *************** *** 6681,6687 **** { if (unconvertlen > 0) { ! /* Move the unconverted characters to allocated memory. */ *restp = alloc(unconvertlen); if (*restp != NULL) mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); --- 6679,6685 ---- { if (unconvertlen > 0) { ! // Move the unconverted characters to allocated memory. *restp = alloc(unconvertlen); if (*restp != NULL) mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); *************** *** 6690,6697 **** mch_memmove(ptr, d, dlen); } else ! /* result is too long, keep the unconverted text (the caller must ! * have done something wrong!) */ dlen = len; vim_free(d); } --- 6688,6695 ---- mch_memmove(ptr, d, dlen); } else ! // result is too long, keep the unconverted text (the caller must ! // have done something wrong!) dlen = len; vim_free(d); } *************** *** 6742,6748 **** switch (vcp->vc_type) { ! case CONV_TO_UTF8: /* latin1 to utf-8 conversion */ retval = alloc(len * 2 + 1); if (retval == NULL) break; --- 6740,6746 ---- switch (vcp->vc_type) { ! case CONV_TO_UTF8: // latin1 to utf-8 conversion retval = alloc(len * 2 + 1); if (retval == NULL) break; *************** *** 6763,6769 **** *lenp = (int)(d - retval); break; ! case CONV_9_TO_UTF8: /* latin9 to utf-8 conversion */ retval = alloc(len * 3 + 1); if (retval == NULL) break; --- 6761,6767 ---- *lenp = (int)(d - retval); break; ! case CONV_9_TO_UTF8: // latin9 to utf-8 conversion retval = alloc(len * 3 + 1); if (retval == NULL) break; *************** *** 6773,6786 **** c = ptr[i]; switch (c) { ! case 0xa4: c = 0x20ac; break; /* euro */ ! case 0xa6: c = 0x0160; break; /* S hat */ ! case 0xa8: c = 0x0161; break; /* S -hat */ ! case 0xb4: c = 0x017d; break; /* Z hat */ ! case 0xb8: c = 0x017e; break; /* Z -hat */ ! case 0xbc: c = 0x0152; break; /* OE */ ! case 0xbd: c = 0x0153; break; /* oe */ ! case 0xbe: c = 0x0178; break; /* Y */ } d += utf_char2bytes(c, d); } --- 6771,6784 ---- c = ptr[i]; switch (c) { ! case 0xa4: c = 0x20ac; break; // euro ! case 0xa6: c = 0x0160; break; // S hat ! case 0xa8: c = 0x0161; break; // S -hat ! case 0xb4: c = 0x017d; break; // Z hat ! case 0xb8: c = 0x017e; break; // Z -hat ! case 0xbc: c = 0x0152; break; // OE ! case 0xbd: c = 0x0153; break; // oe ! case 0xbe: c = 0x0178; break; // Y } d += utf_char2bytes(c, d); } *************** *** 6789,6796 **** *lenp = (int)(d - retval); break; ! case CONV_TO_LATIN1: /* utf-8 to latin1 conversion */ ! case CONV_TO_LATIN9: /* utf-8 to latin9 conversion */ retval = alloc(len + 1); if (retval == NULL) break; --- 6787,6794 ---- *lenp = (int)(d - retval); break; ! case CONV_TO_LATIN1: // utf-8 to latin1 conversion ! case CONV_TO_LATIN9: // utf-8 to latin9 conversion retval = alloc(len + 1); if (retval == NULL) break; *************** *** 6806,6818 **** if (l_w == 0) { ! /* Illegal utf-8 byte cannot be converted */ vim_free(retval); return NULL; } if (unconvlenp != NULL && l_w > len - i) { ! /* Incomplete sequence at the end. */ *unconvlenp = len - i; break; } --- 6804,6816 ---- if (l_w == 0) { ! // Illegal utf-8 byte cannot be converted vim_free(retval); return NULL; } if (unconvlenp != NULL && l_w > len - i) { ! // Incomplete sequence at the end. *unconvlenp = len - i; break; } *************** *** 6824,6837 **** if (vcp->vc_type == CONV_TO_LATIN9) switch (c) { ! case 0x20ac: c = 0xa4; break; /* euro */ ! case 0x0160: c = 0xa6; break; /* S hat */ ! case 0x0161: c = 0xa8; break; /* S -hat */ ! case 0x017d: c = 0xb4; break; /* Z hat */ ! case 0x017e: c = 0xb8; break; /* Z -hat */ ! case 0x0152: c = 0xbc; break; /* OE */ ! case 0x0153: c = 0xbd; break; /* oe */ ! case 0x0178: c = 0xbe; break; /* Y */ case 0xa4: case 0xa6: case 0xa8: --- 6822,6835 ---- if (vcp->vc_type == CONV_TO_LATIN9) switch (c) { ! case 0x20ac: c = 0xa4; break; // euro ! case 0x0160: c = 0xa6; break; // S hat ! case 0x0161: c = 0xa8; break; // S -hat ! case 0x017d: c = 0xb4; break; // Z hat ! case 0x017e: c = 0xb8; break; // Z -hat ! case 0x0152: c = 0xbc; break; // OE ! case 0x0153: c = 0xbd; break; // oe ! case 0x0178: c = 0xbe; break; // Y case 0xa4: case 0xa6: case 0xa8: *************** *** 6839,6847 **** case 0xb8: case 0xbc: case 0xbd: ! case 0xbe: c = 0x100; break; /* not in latin9 */ } ! if (!utf_iscomposing(c)) /* skip composing chars */ { if (c < 0x100) *d++ = c; --- 6837,6845 ---- case 0xb8: case 0xbc: case 0xbd: ! case 0xbe: c = 0x100; break; // not in latin9 } ! if (!utf_iscomposing(c)) // skip composing chars { if (c < 0x100) *d++ = c; *************** *** 6888,6905 **** # endif # ifdef USE_ICONV ! case CONV_ICONV: /* conversion with output_conv.vc_fd */ retval = iconv_string(vcp, ptr, len, unconvlenp, lenp); break; # endif # ifdef MSWIN ! case CONV_CODEPAGE: /* codepage -> codepage */ { int retlen; int tmp_len; short_u *tmp; ! /* 1. codepage/UTF-8 -> ucs-2. */ if (vcp->vc_cpfrom == 0) tmp_len = utf8_to_utf16(ptr, len, NULL, NULL); else --- 6886,6903 ---- # endif # ifdef USE_ICONV ! case CONV_ICONV: // conversion with output_conv.vc_fd retval = iconv_string(vcp, ptr, len, unconvlenp, lenp); break; # endif # ifdef MSWIN ! case CONV_CODEPAGE: // codepage -> codepage { int retlen; int tmp_len; short_u *tmp; ! // 1. codepage/UTF-8 -> ucs-2. if (vcp->vc_cpfrom == 0) tmp_len = utf8_to_utf16(ptr, len, NULL, NULL); else *************** *** 6929,6935 **** MultiByteToWideChar(vcp->vc_cpfrom, 0, (char *)ptr, len, tmp, tmp_len); ! /* 2. ucs-2 -> codepage/UTF-8. */ if (vcp->vc_cpto == 0) retlen = utf16_to_utf8(tmp, tmp_len, NULL); else --- 6927,6933 ---- MultiByteToWideChar(vcp->vc_cpfrom, 0, (char *)ptr, len, tmp, tmp_len); ! // 2. ucs-2 -> codepage/UTF-8. if (vcp->vc_cpto == 0) retlen = utf16_to_utf8(tmp, tmp_len, NULL); else *** ../vim-8.1.2387/src/memfile.c 2019-05-28 23:08:12.068648696 +0200 --- src/memfile.c 2019-12-04 21:51:25.702024693 +0100 *************** *** 46,52 **** # include # define STATFS statfs # define F_BSIZE f_bsize ! # ifdef __MINT__ /* do we still need this? */ # define fstatfs(fd, buf, len, nul) mch_fstat((fd), (buf)) # endif # endif --- 46,52 ---- # include # define STATFS statfs # define F_BSIZE f_bsize ! # ifdef __MINT__ // do we still need this? # define fstatfs(fd, buf, len, nul) mch_fstat((fd), (buf)) # endif # endif *************** *** 57,73 **** */ #ifdef AMIGA # ifdef FEAT_ARP ! extern int dos2; /* this is in os_amiga.c */ # endif # ifdef SASC # include ! # include /* for chkufb() */ # endif #endif ! #define MEMFILE_PAGE_SIZE 4096 /* default page size */ ! static long_u total_mem_used = 0; /* total memory used for memfiles */ static void mf_ins_hash(memfile_T *, bhdr_T *); static void mf_rem_hash(memfile_T *, bhdr_T *); --- 57,73 ---- */ #ifdef AMIGA # ifdef FEAT_ARP ! extern int dos2; // this is in os_amiga.c # endif # ifdef SASC # include ! # include // for chkufb() # endif #endif ! #define MEMFILE_PAGE_SIZE 4096 // default page size ! static long_u total_mem_used = 0; // total memory used for memfiles static void mf_ins_hash(memfile_T *, bhdr_T *); static void mf_rem_hash(memfile_T *, bhdr_T *); *************** *** 133,139 **** if ((mfp = ALLOC_ONE(memfile_T)) == NULL) return NULL; ! if (fname == NULL) /* no file for this memfile, use memory only */ { mfp->mf_fname = NULL; mfp->mf_ffname = NULL; --- 133,139 ---- if ((mfp = ALLOC_ONE(memfile_T)) == NULL) return NULL; ! if (fname == NULL) // no file for this memfile, use memory only { mfp->mf_fname = NULL; mfp->mf_ffname = NULL; *************** *** 141,149 **** } else { ! mf_do_open(mfp, fname, flags); /* try to open the file */ ! /* if the file cannot be opened, return here */ if (mfp->mf_fd < 0) { vim_free(mfp); --- 141,149 ---- } else { ! mf_do_open(mfp, fname, flags); // try to open the file ! // if the file cannot be opened, return here if (mfp->mf_fd < 0) { vim_free(mfp); *************** *** 151,158 **** } } ! mfp->mf_free_first = NULL; /* free list is empty */ ! mfp->mf_used_first = NULL; /* used list is empty */ mfp->mf_used_last = NULL; mfp->mf_dirty = FALSE; mfp->mf_used_count = 0; --- 151,158 ---- } } ! mfp->mf_free_first = NULL; // free list is empty ! mfp->mf_used_first = NULL; // used list is empty mfp->mf_used_last = NULL; mfp->mf_dirty = FALSE; mfp->mf_used_count = 0; *************** *** 180,186 **** if (mfp->mf_fd < 0 || (flags & (O_TRUNC|O_EXCL)) || (size = vim_lseek(mfp->mf_fd, (off_T)0L, SEEK_END)) <= 0) ! mfp->mf_blocknr_max = 0; /* no file or empty file */ else mfp->mf_blocknr_max = (blocknr_T)((size + mfp->mf_page_size - 1) / mfp->mf_page_size); --- 180,186 ---- if (mfp->mf_fd < 0 || (flags & (O_TRUNC|O_EXCL)) || (size = vim_lseek(mfp->mf_fd, (off_T)0L, SEEK_END)) <= 0) ! mfp->mf_blocknr_max = 0; // no file or empty file else mfp->mf_blocknr_max = (blocknr_T)((size + mfp->mf_page_size - 1) / mfp->mf_page_size); *************** *** 223,229 **** int mf_open_file(memfile_T *mfp, char_u *fname) { ! mf_do_open(mfp, fname, O_RDWR|O_CREAT|O_EXCL); /* try to open the file */ if (mfp->mf_fd < 0) return FAIL; --- 223,229 ---- int mf_open_file(memfile_T *mfp, char_u *fname) { ! mf_do_open(mfp, fname, O_RDWR|O_CREAT|O_EXCL); // try to open the file if (mfp->mf_fd < 0) return FAIL; *************** *** 240,246 **** { bhdr_T *hp, *nextp; ! if (mfp == NULL) /* safety check */ return; if (mfp->mf_fd >= 0) { --- 240,246 ---- { bhdr_T *hp, *nextp; ! if (mfp == NULL) // safety check return; if (mfp->mf_fd >= 0) { *************** *** 249,265 **** } if (del_file && mfp->mf_fname != NULL) mch_remove(mfp->mf_fname); ! /* free entries in used list */ for (hp = mfp->mf_used_first; hp != NULL; hp = nextp) { total_mem_used -= hp->bh_page_count * mfp->mf_page_size; nextp = hp->bh_next; mf_free_bhdr(hp); } ! while (mfp->mf_free_first != NULL) /* free entries in free list */ vim_free(mf_rem_free(mfp)); mf_hash_free(&mfp->mf_hash); ! mf_hash_free_all(&mfp->mf_trans); /* free hashtable and its items */ vim_free(mfp->mf_fname); vim_free(mfp->mf_ffname); vim_free(mfp); --- 249,265 ---- } if (del_file && mfp->mf_fname != NULL) mch_remove(mfp->mf_fname); ! // free entries in used list for (hp = mfp->mf_used_first; hp != NULL; hp = nextp) { total_mem_used -= hp->bh_page_count * mfp->mf_page_size; nextp = hp->bh_next; mf_free_bhdr(hp); } ! while (mfp->mf_free_first != NULL) // free entries in free list vim_free(mf_rem_free(mfp)); mf_hash_free(&mfp->mf_hash); ! mf_hash_free_all(&mfp->mf_trans); // free hashtable and its items vim_free(mfp->mf_fname); vim_free(mfp->mf_ffname); vim_free(mfp); *************** *** 271,302 **** void mf_close_file( buf_T *buf, ! int getlines) /* get all lines into memory? */ { memfile_T *mfp; linenr_T lnum; mfp = buf->b_ml.ml_mfp; ! if (mfp == NULL || mfp->mf_fd < 0) /* nothing to close */ return; if (getlines) { ! /* get all blocks in memory by accessing all lines (clumsy!) */ mf_dont_release = TRUE; for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) (void)ml_get_buf(buf, lnum, FALSE); mf_dont_release = FALSE; ! /* TODO: should check if all blocks are really in core */ } ! if (close(mfp->mf_fd) < 0) /* close the file */ emsg(_(e_swapclose)); mfp->mf_fd = -1; if (mfp->mf_fname != NULL) { ! mch_remove(mfp->mf_fname); /* delete the swap file */ VIM_CLEAR(mfp->mf_fname); VIM_CLEAR(mfp->mf_ffname); } --- 271,302 ---- void mf_close_file( buf_T *buf, ! int getlines) // get all lines into memory? { memfile_T *mfp; linenr_T lnum; mfp = buf->b_ml.ml_mfp; ! if (mfp == NULL || mfp->mf_fd < 0) // nothing to close return; if (getlines) { ! // get all blocks in memory by accessing all lines (clumsy!) mf_dont_release = TRUE; for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) (void)ml_get_buf(buf, lnum, FALSE); mf_dont_release = FALSE; ! // TODO: should check if all blocks are really in core } ! if (close(mfp->mf_fd) < 0) // close the file emsg(_(e_swapclose)); mfp->mf_fd = -1; if (mfp->mf_fname != NULL) { ! mch_remove(mfp->mf_fname); // delete the swap file VIM_CLEAR(mfp->mf_fname); VIM_CLEAR(mfp->mf_ffname); } *************** *** 309,316 **** void mf_new_page_size(memfile_T *mfp, unsigned new_size) { ! /* Correct the memory used for block 0 to the new size, because it will be ! * freed with that size later on. */ total_mem_used += new_size - mfp->mf_page_size; mfp->mf_page_size = new_size; } --- 309,316 ---- void mf_new_page_size(memfile_T *mfp, unsigned new_size) { ! // Correct the memory used for block 0 to the new size, because it will be ! // freed with that size later on. total_mem_used += new_size - mfp->mf_page_size; mfp->mf_page_size = new_size; } *************** *** 323,330 **** bhdr_T * mf_new(memfile_T *mfp, int negative, int page_count) { ! bhdr_T *hp; /* new bhdr_T */ ! bhdr_T *freep; /* first block in free list */ char_u *p; /* --- 323,330 ---- bhdr_T * mf_new(memfile_T *mfp, int negative, int page_count) { ! bhdr_T *hp; // new bhdr_T ! bhdr_T *freep; // first block in free list char_u *p; /* *************** *** 360,380 **** freep->bh_bnum += page_count; freep->bh_page_count -= page_count; } ! else if (hp == NULL) /* need to allocate memory for this block */ { if ((p = alloc(mfp->mf_page_size * page_count)) == NULL) return NULL; hp = mf_rem_free(mfp); hp->bh_data = p; } ! else /* use the number, remove entry from free list */ { freep = mf_rem_free(mfp); hp->bh_bnum = freep->bh_bnum; vim_free(freep); } } ! else /* get a new number */ { if (hp == NULL && (hp = mf_alloc_bhdr(mfp, page_count)) == NULL) return NULL; --- 360,380 ---- freep->bh_bnum += page_count; freep->bh_page_count -= page_count; } ! else if (hp == NULL) // need to allocate memory for this block { if ((p = alloc(mfp->mf_page_size * page_count)) == NULL) return NULL; hp = mf_rem_free(mfp); hp->bh_data = p; } ! else // use the number, remove entry from free list { freep = mf_rem_free(mfp); hp->bh_bnum = freep->bh_bnum; vim_free(freep); } } ! else // get a new number { if (hp == NULL && (hp = mf_alloc_bhdr(mfp, page_count)) == NULL) return NULL; *************** *** 389,395 **** mfp->mf_blocknr_max += page_count; } } ! hp->bh_flags = BH_LOCKED | BH_DIRTY; /* new block is always dirty */ mfp->mf_dirty = TRUE; hp->bh_page_count = page_count; mf_ins_used(mfp, hp); --- 389,395 ---- mfp->mf_blocknr_max += page_count; } } ! hp->bh_flags = BH_LOCKED | BH_DIRTY; // new block is always dirty mfp->mf_dirty = TRUE; hp->bh_page_count = page_count; mf_ins_used(mfp, hp); *************** *** 414,420 **** mf_get(memfile_T *mfp, blocknr_T nr, int page_count) { bhdr_T *hp; ! /* doesn't exist */ if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min) return NULL; --- 414,420 ---- mf_get(memfile_T *mfp, blocknr_T nr, int page_count) { bhdr_T *hp; ! // doesn't exist if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min) return NULL; *************** *** 422,433 **** * see if it is in the cache */ hp = mf_find_hash(mfp, nr); ! if (hp == NULL) /* not in the hash list */ { ! if (nr < 0 || nr >= mfp->mf_infile_count) /* can't be in the file */ return NULL; ! /* could check here if the block is in the free list */ /* * Check if we need to flush an existing block. --- 422,433 ---- * see if it is in the cache */ hp = mf_find_hash(mfp, nr); ! if (hp == NULL) // not in the hash list { ! if (nr < 0 || nr >= mfp->mf_infile_count) // can't be in the file return NULL; ! // could check here if the block is in the free list /* * Check if we need to flush an existing block. *************** *** 441,447 **** hp->bh_bnum = nr; hp->bh_flags = 0; hp->bh_page_count = page_count; ! if (mf_read(mfp, hp) == FAIL) /* cannot read the block! */ { mf_free_bhdr(hp); return NULL; --- 441,447 ---- hp->bh_bnum = nr; hp->bh_flags = 0; hp->bh_page_count = page_count; ! if (mf_read(mfp, hp) == FAIL) // cannot read the block! { mf_free_bhdr(hp); return NULL; *************** *** 449,461 **** } else { ! mf_rem_used(mfp, hp); /* remove from list, insert in front below */ mf_rem_hash(mfp, hp); } hp->bh_flags |= BH_LOCKED; ! mf_ins_used(mfp, hp); /* put in front of used list */ ! mf_ins_hash(mfp, hp); /* put in front of hash list */ return hp; } --- 449,461 ---- } else { ! mf_rem_used(mfp, hp); // remove from list, insert in front below mf_rem_hash(mfp, hp); } hp->bh_flags |= BH_LOCKED; ! mf_ins_used(mfp, hp); // put in front of used list ! mf_ins_hash(mfp, hp); // put in front of hash list return hp; } *************** *** 489,495 **** } hp->bh_flags = flags; if (infile) ! mf_trans_add(mfp, hp); /* may translate negative in positive nr */ } /* --- 489,495 ---- } hp->bh_flags = flags; if (infile) ! mf_trans_add(mfp, hp); // may translate negative in positive nr } /* *************** *** 498,517 **** void mf_free(memfile_T *mfp, bhdr_T *hp) { ! vim_free(hp->bh_data); /* free the memory */ ! mf_rem_hash(mfp, hp); /* get *hp out of the hash list */ ! mf_rem_used(mfp, hp); /* get *hp out of the used list */ if (hp->bh_bnum < 0) { ! vim_free(hp); /* don't want negative numbers in free list */ mfp->mf_neg_count--; } else ! mf_ins_free(mfp, hp); /* put *hp in the free list */ } #if defined(__MORPHOS__) && defined(__libnix__) ! /* function is missing in MorphOS libnix version */ extern unsigned long *__stdfiledes; static unsigned long --- 498,517 ---- void mf_free(memfile_T *mfp, bhdr_T *hp) { ! vim_free(hp->bh_data); // free the memory ! mf_rem_hash(mfp, hp); // get *hp out of the hash list ! mf_rem_used(mfp, hp); // get *hp out of the used list if (hp->bh_bnum < 0) { ! vim_free(hp); // don't want negative numbers in free list mfp->mf_neg_count--; } else ! mf_ins_free(mfp, hp); // put *hp in the free list } #if defined(__MORPHOS__) && defined(__libnix__) ! // function is missing in MorphOS libnix version extern unsigned long *__stdfiledes; static unsigned long *************** *** 541,554 **** bhdr_T *hp; int got_int_save = got_int; ! if (mfp->mf_fd < 0) /* there is no file, nothing to do */ { mfp->mf_dirty = FALSE; return FAIL; } ! /* Only a CTRL-C while writing will break us here, not one typed ! * previously. */ got_int = FALSE; /* --- 541,554 ---- bhdr_T *hp; int got_int_save = got_int; ! if (mfp->mf_fd < 0) // there is no file, nothing to do { mfp->mf_dirty = FALSE; return FAIL; } ! // Only a CTRL-C while writing will break us here, not one typed ! // previously. got_int = FALSE; /* *************** *** 568,580 **** continue; if (mf_write(mfp, hp) == FAIL) { ! if (status == FAIL) /* double error: quit syncing */ break; status = FAIL; } if (flags & MFS_STOP) { ! /* Stop when char available now. */ if (ui_char_avail()) break; } --- 568,580 ---- continue; if (mf_write(mfp, hp) == FAIL) { ! if (status == FAIL) // double error: quit syncing break; status = FAIL; } if (flags & MFS_STOP) { ! // Stop when char available now. if (ui_char_avail()) break; } *************** *** 605,613 **** } else # endif ! /* OpenNT is strictly POSIX (Benzinger) */ ! /* Tandem/Himalaya NSK-OSS doesn't have sync() */ ! /* No sync() on Stratus VOS */ # if defined(__OPENNT) || defined(__TANDEM) || defined(__VOS__) fflush(NULL); # else --- 605,613 ---- } else # endif ! // OpenNT is strictly POSIX (Benzinger) ! // Tandem/Himalaya NSK-OSS doesn't have sync() ! // No sync() on Stratus VOS # if defined(__OPENNT) || defined(__TANDEM) || defined(__VOS__) fflush(NULL); # else *************** *** 649,656 **** # if defined(_DCC) || defined(__GNUC__) || defined(__MORPHOS__) { # if defined(__GNUC__) && !defined(__MORPHOS__) && defined(__libnix__) ! /* Have function (in libnix at least), ! * but ain't got no prototype anywhere. */ extern unsigned long fdtofh(int filedescriptor); # endif # if !defined(__libnix__) --- 649,656 ---- # if defined(_DCC) || defined(__GNUC__) || defined(__MORPHOS__) { # if defined(__GNUC__) && !defined(__MORPHOS__) && defined(__libnix__) ! // Have function (in libnix at least), ! // but ain't got no prototype anywhere. extern unsigned long fdtofh(int filedescriptor); # endif # if !defined(__libnix__) *************** *** 662,673 **** Flush(fh); # endif } ! # else /* assume Manx */ Flush(_devtab[mfp->mf_fd].fd); # endif # endif # endif ! #endif /* AMIGA */ } got_int |= got_int_save; --- 662,673 ---- Flush(fh); # endif } ! # else // assume Manx Flush(_devtab[mfp->mf_fd].fd); # endif # endif # endif ! #endif // AMIGA } got_int |= got_int_save; *************** *** 727,733 **** hp->bh_next = mfp->mf_used_first; mfp->mf_used_first = hp; hp->bh_prev = NULL; ! if (hp->bh_next == NULL) /* list was empty, adjust last pointer */ mfp->mf_used_last = hp; else hp->bh_next->bh_prev = hp; --- 727,733 ---- hp->bh_next = mfp->mf_used_first; mfp->mf_used_first = hp; hp->bh_prev = NULL; ! if (hp->bh_next == NULL) // list was empty, adjust last pointer mfp->mf_used_last = hp; else hp->bh_next->bh_prev = hp; *************** *** 741,751 **** static void mf_rem_used(memfile_T *mfp, bhdr_T *hp) { ! if (hp->bh_next == NULL) /* last block in used list */ mfp->mf_used_last = hp->bh_prev; else hp->bh_next->bh_prev = hp->bh_prev; ! if (hp->bh_prev == NULL) /* first block in used list */ mfp->mf_used_first = hp->bh_next; else hp->bh_prev->bh_next = hp->bh_next; --- 741,751 ---- static void mf_rem_used(memfile_T *mfp, bhdr_T *hp) { ! if (hp->bh_next == NULL) // last block in used list mfp->mf_used_last = hp->bh_prev; else hp->bh_next->bh_prev = hp->bh_prev; ! if (hp->bh_prev == NULL) // first block in used list mfp->mf_used_first = hp->bh_next; else hp->bh_prev->bh_next = hp->bh_next; *************** *** 769,775 **** int need_release; buf_T *buf; ! /* don't release while in mf_close_file() */ if (mf_dont_release) return NULL; --- 769,775 ---- int need_release; buf_T *buf; ! // don't release while in mf_close_file() if (mf_dont_release) return NULL; *************** *** 786,792 **** */ if (mfp->mf_fd < 0 && need_release && p_uc) { ! /* find for which buffer this memfile is */ FOR_ALL_BUFFERS(buf) if (buf->b_ml.ml_mfp == mfp) break; --- 786,792 ---- */ if (mfp->mf_fd < 0 && need_release && p_uc) { ! // find for which buffer this memfile is FOR_ALL_BUFFERS(buf) if (buf->b_ml.ml_mfp == mfp) break; *************** *** 808,814 **** for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) if (!(hp->bh_flags & BH_LOCKED)) break; ! if (hp == NULL) /* not a single one that can be released */ return NULL; /* --- 808,814 ---- for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) if (!(hp->bh_flags & BH_LOCKED)) break; ! if (hp == NULL) // not a single one that can be released return NULL; /* *************** *** 857,867 **** mfp = buf->b_ml.ml_mfp; if (mfp != NULL) { ! /* If no swap file yet, may open one */ if (mfp->mf_fd < 0 && buf->b_may_swap) ml_open_file(buf); ! /* only if there is a swapfile */ if (mfp->mf_fd >= 0) { for (hp = mfp->mf_used_last; hp != NULL; ) --- 857,867 ---- mfp = buf->b_ml.ml_mfp; if (mfp != NULL) { ! // If no swap file yet, may open one if (mfp->mf_fd < 0 && buf->b_may_swap) ml_open_file(buf); ! // only if there is a swapfile if (mfp->mf_fd >= 0) { for (hp = mfp->mf_used_last; hp != NULL; ) *************** *** 873,879 **** mf_rem_used(mfp, hp); mf_rem_hash(mfp, hp); mf_free_bhdr(hp); ! hp = mfp->mf_used_last; /* re-start, list was changed */ retval = TRUE; } else --- 873,879 ---- mf_rem_used(mfp, hp); mf_rem_hash(mfp, hp); mf_free_bhdr(hp); ! hp = mfp->mf_used_last; // re-start, list was changed retval = TRUE; } else *************** *** 897,903 **** { if ((hp->bh_data = alloc(mfp->mf_page_size * page_count)) == NULL) { ! vim_free(hp); /* not enough memory */ return NULL; } hp->bh_page_count = page_count; --- 897,903 ---- { if ((hp->bh_data = alloc(mfp->mf_page_size * page_count)) == NULL) { ! vim_free(hp); // not enough memory return NULL; } hp->bh_page_count = page_count; *************** *** 951,957 **** unsigned page_size; unsigned size; ! if (mfp->mf_fd < 0) /* there is no file, can't read */ return FAIL; page_size = mfp->mf_page_size; --- 951,957 ---- unsigned page_size; unsigned size; ! if (mfp->mf_fd < 0) // there is no file, can't read return FAIL; page_size = mfp->mf_page_size; *************** *** 969,976 **** } #ifdef FEAT_CRYPT ! /* Decrypt if 'key' is set and this is a data block. And when changing the ! * key. */ if (*mfp->mf_buffer->b_p_key != NUL || mfp->mf_old_key != NULL) ml_decrypt_data(mfp, hp->bh_data, offset, size); #endif --- 969,976 ---- } #ifdef FEAT_CRYPT ! // Decrypt if 'key' is set and this is a data block. And when changing the ! // key. if (*mfp->mf_buffer->b_p_key != NUL || mfp->mf_old_key != NULL) ml_decrypt_data(mfp, hp->bh_data, offset, size); #endif *************** *** 986,1003 **** static int mf_write(memfile_T *mfp, bhdr_T *hp) { ! off_T offset; /* offset in the file */ ! blocknr_T nr; /* block nr which is being written */ bhdr_T *hp2; ! unsigned page_size; /* number of bytes in a page */ ! unsigned page_count; /* number of pages written */ ! unsigned size; /* number of bytes written */ if (mfp->mf_fd < 0 && !mfp->mf_reopen) // there is no file and there was no file, can't write return FAIL; ! if (hp->bh_bnum < 0) /* must assign file block number */ if (mf_trans_add(mfp, hp) == FAIL) return FAIL; --- 986,1003 ---- static int mf_write(memfile_T *mfp, bhdr_T *hp) { ! off_T offset; // offset in the file ! blocknr_T nr; // block nr which is being written bhdr_T *hp2; ! unsigned page_size; // number of bytes in a page ! unsigned page_count; // number of pages written ! unsigned size; // number of bytes written if (mfp->mf_fd < 0 && !mfp->mf_reopen) // there is no file and there was no file, can't write return FAIL; ! if (hp->bh_bnum < 0) // must assign file block number if (mf_trans_add(mfp, hp) == FAIL) return FAIL; *************** *** 1014,1029 **** int attempt; nr = hp->bh_bnum; ! if (nr > mfp->mf_infile_count) /* beyond end of file */ { nr = mfp->mf_infile_count; ! hp2 = mf_find_hash(mfp, nr); /* NULL caught below */ } else hp2 = hp; offset = (off_T)page_size * nr; ! if (hp2 == NULL) /* freed block, fill with dummy data */ page_count = 1; else page_count = hp2->bh_page_count; --- 1014,1029 ---- int attempt; nr = hp->bh_bnum; ! if (nr > mfp->mf_infile_count) // beyond end of file { nr = mfp->mf_infile_count; ! hp2 = mf_find_hash(mfp, nr); // NULL caught below } else hp2 = hp; offset = (off_T)page_size * nr; ! if (hp2 == NULL) // freed block, fill with dummy data page_count = 1; else page_count = hp2->bh_page_count; *************** *** 1067,1078 **** } did_swapwrite_msg = FALSE; ! if (hp2 != NULL) /* written a non-dummy block */ hp2->bh_flags &= ~BH_DIRTY; ! /* appended to the file */ if (nr + (blocknr_T)page_count > mfp->mf_infile_count) mfp->mf_infile_count = nr + page_count; ! if (nr == hp->bh_bnum) /* written the desired block */ break; } return OK; --- 1067,1078 ---- } did_swapwrite_msg = FALSE; ! if (hp2 != NULL) // written a non-dummy block hp2->bh_flags &= ~BH_DIRTY; ! // appended to the file if (nr + (blocknr_T)page_count > mfp->mf_infile_count) mfp->mf_infile_count = nr + page_count; ! if (nr == hp->bh_bnum) // written the desired block break; } return OK; *************** *** 1094,1100 **** int result = OK; #ifdef FEAT_CRYPT ! /* Encrypt if 'key' is set and this is a data block. */ if (*mfp->mf_buffer->b_p_key != NUL) { data = ml_encrypt_data(mfp, data, offset, size); --- 1094,1100 ---- int result = OK; #ifdef FEAT_CRYPT ! // Encrypt if 'key' is set and this is a data block. if (*mfp->mf_buffer->b_p_key != NUL) { data = ml_encrypt_data(mfp, data, offset, size); *************** *** 1127,1133 **** NR_TRANS *np; int page_count; ! if (hp->bh_bnum >= 0) /* it's already positive */ return OK; if ((np = ALLOC_ONE(NR_TRANS)) == NULL) --- 1127,1133 ---- NR_TRANS *np; int page_count; ! if (hp->bh_bnum >= 0) // it's already positive return OK; if ((np = ALLOC_ONE(NR_TRANS)) == NULL) *************** *** 1164,1177 **** mfp->mf_blocknr_max += page_count; } ! np->nt_old_bnum = hp->bh_bnum; /* adjust number */ np->nt_new_bnum = new_bnum; ! mf_rem_hash(mfp, hp); /* remove from old hash list */ hp->bh_bnum = new_bnum; ! mf_ins_hash(mfp, hp); /* insert in new hash list */ ! /* Insert "np" into "mf_trans" hashtable with key "np->nt_old_bnum" */ mf_hash_add_item(&mfp->mf_trans, (mf_hashitem_T *)np); return OK; --- 1164,1177 ---- mfp->mf_blocknr_max += page_count; } ! np->nt_old_bnum = hp->bh_bnum; // adjust number np->nt_new_bnum = new_bnum; ! mf_rem_hash(mfp, hp); // remove from old hash list hp->bh_bnum = new_bnum; ! mf_ins_hash(mfp, hp); // insert in new hash list ! // Insert "np" into "mf_trans" hashtable with key "np->nt_old_bnum" mf_hash_add_item(&mfp->mf_trans, (mf_hashitem_T *)np); return OK; *************** *** 1190,1202 **** np = (NR_TRANS *)mf_hash_find(&mfp->mf_trans, old_nr); ! if (np == NULL) /* not found */ return old_nr; mfp->mf_neg_count--; new_bnum = np->nt_new_bnum; ! /* remove entry from the trans list */ mf_hash_rem_item(&mfp->mf_trans, (mf_hashitem_T *)np); vim_free(np); --- 1190,1202 ---- np = (NR_TRANS *)mf_hash_find(&mfp->mf_trans, old_nr); ! if (np == NULL) // not found return old_nr; mfp->mf_neg_count--; new_bnum = np->nt_new_bnum; ! // remove entry from the trans list mf_hash_rem_item(&mfp->mf_trans, (mf_hashitem_T *)np); vim_free(np); *************** *** 1248,1254 **** mf_do_open( memfile_T *mfp, char_u *fname, ! int flags) /* flags for open() */ { #ifdef HAVE_LSTAT stat_T sb; --- 1248,1254 ---- mf_do_open( memfile_T *mfp, char_u *fname, ! int flags) // flags for open() { #ifdef HAVE_LSTAT stat_T sb; *************** *** 1288,1296 **** */ flags |= O_EXTRA | O_NOFOLLOW; #ifdef MSWIN ! /* Prevent handle inheritance that cause problems with Cscope ! * (swap file may not be deleted if cscope connection was open after ! * the file) */ flags |= O_NOINHERIT; #endif mfp->mf_flags = flags; --- 1288,1296 ---- */ flags |= O_EXTRA | O_NOFOLLOW; #ifdef MSWIN ! // Prevent handle inheritance that cause problems with Cscope ! // (swap file may not be deleted if cscope connection was open after ! // the file) flags |= O_NOINHERIT; #endif mfp->mf_flags = flags; *************** *** 1315,1321 **** #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) mch_copy_sec(fname, mfp->mf_fname); #endif ! mch_hide(mfp->mf_fname); /* try setting the 'hidden' flag */ } } --- 1315,1321 ---- #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) mch_copy_sec(fname, mfp->mf_fname); #endif ! mch_hide(mfp->mf_fname); // try setting the 'hidden' flag } } *************** *** 1329,1335 **** * exceeds 2 ^ MHT_LOG_LOAD_FACTOR. */ #define MHT_LOG_LOAD_FACTOR 6 ! #define MHT_GROWTH_FACTOR 2 /* must be a power of two */ /* * Initialize an empty hash table. --- 1329,1335 ---- * exceeds 2 ^ MHT_LOG_LOAD_FACTOR. */ #define MHT_LOG_LOAD_FACTOR 6 ! #define MHT_GROWTH_FACTOR 2 // must be a power of two /* * Initialize an empty hash table. *************** *** 1416,1422 **** { if (mf_hash_grow(mht) == FAIL) { ! /* stop trying to grow after first failure to allocate memory */ mht->mht_fixed = 1; } } --- 1416,1422 ---- { if (mf_hash_grow(mht) == FAIL) { ! // stop trying to grow after first failure to allocate memory mht->mht_fixed = 1; } } *************** *** 1439,1446 **** mht->mht_count--; ! /* We could shrink the table here, but it typically takes little memory, ! * so why bother? */ } /* --- 1439,1446 ---- mht->mht_count--; ! // We could shrink the table here, but it typically takes little memory, ! // so why bother? } /* *** ../vim-8.1.2387/src/memfile_test.c 2019-06-04 22:29:06.931288432 +0200 --- src/memfile_test.c 2019-12-04 21:51:41.053974497 +0100 *************** *** 15,25 **** #undef NDEBUG #include ! /* Must include main.c because it contains much more than just main() */ #define NO_VIM_MAIN #include "main.c" ! /* This file has to be included because the tested functions are static */ #include "memfile.c" #define index_to_key(i) ((i) ^ 15167) --- 15,25 ---- #undef NDEBUG #include ! // Must include main.c because it contains much more than just main() #define NO_VIM_MAIN #include "main.c" ! // This file has to be included because the tested functions are static #include "memfile.c" #define index_to_key(i) ((i) ^ 15167) *************** *** 39,59 **** mf_hash_init(&ht); ! /* insert some items and check invariants */ for (i = 0; i < TEST_COUNT; i++) { assert(ht.mht_count == i); ! /* check that number of buckets is a power of 2 */ num_buckets = ht.mht_mask + 1; assert(num_buckets > 0 && (num_buckets & (num_buckets - 1)) == 0); ! /* check load factor */ assert(ht.mht_count <= (num_buckets << MHT_LOG_LOAD_FACTOR)); if (i < (MHT_INIT_SIZE << MHT_LOG_LOAD_FACTOR)) { ! /* first expansion shouldn't have occurred yet */ assert(num_buckets == MHT_INIT_SIZE); assert(ht.mht_buckets == ht.mht_small_buckets); } --- 39,59 ---- mf_hash_init(&ht); ! // insert some items and check invariants for (i = 0; i < TEST_COUNT; i++) { assert(ht.mht_count == i); ! // check that number of buckets is a power of 2 num_buckets = ht.mht_mask + 1; assert(num_buckets > 0 && (num_buckets & (num_buckets - 1)) == 0); ! // check load factor assert(ht.mht_count <= (num_buckets << MHT_LOG_LOAD_FACTOR)); if (i < (MHT_INIT_SIZE << MHT_LOG_LOAD_FACTOR)) { ! // first expansion shouldn't have occurred yet assert(num_buckets == MHT_INIT_SIZE); assert(ht.mht_buckets == ht.mht_small_buckets); } *************** *** 66,72 **** key = index_to_key(i); assert(mf_hash_find(&ht, key) == NULL); ! /* allocate and add new item */ item = LALLOC_CLEAR_ONE(mf_hashitem_T); assert(item != NULL); item->mhi_key = key; --- 66,72 ---- key = index_to_key(i); assert(mf_hash_find(&ht, key) == NULL); ! // allocate and add new item item = LALLOC_CLEAR_ONE(mf_hashitem_T); assert(item != NULL); item->mhi_key = key; *************** *** 76,88 **** if (ht.mht_mask + 1 != num_buckets) { ! /* hash table was expanded */ assert(ht.mht_mask + 1 == num_buckets * MHT_GROWTH_FACTOR); assert(i + 1 == (num_buckets << MHT_LOG_LOAD_FACTOR)); } } ! /* check presence of inserted items */ for (i = 0; i < TEST_COUNT; i++) { key = index_to_key(i); --- 76,88 ---- if (ht.mht_mask + 1 != num_buckets) { ! // hash table was expanded assert(ht.mht_mask + 1 == num_buckets * MHT_GROWTH_FACTOR); assert(i + 1 == (num_buckets << MHT_LOG_LOAD_FACTOR)); } } ! // check presence of inserted items for (i = 0; i < TEST_COUNT; i++) { key = index_to_key(i); *************** *** 91,97 **** assert(item->mhi_key == key); } ! /* delete some items */ for (i = 0; i < TEST_COUNT; i++) { if (i % 100 < 70) --- 91,97 ---- assert(item->mhi_key == key); } ! // delete some items for (i = 0; i < TEST_COUNT; i++) { if (i % 100 < 70) *************** *** 114,120 **** } } ! /* check again */ for (i = 0; i < TEST_COUNT; i++) { key = index_to_key(i); --- 114,120 ---- } } ! // check again for (i = 0; i < TEST_COUNT; i++) { key = index_to_key(i); *************** *** 131,137 **** } } ! /* free hash table and all remaining items */ mf_hash_free_all(&ht); } --- 131,137 ---- } } ! // free hash table and all remaining items mf_hash_free_all(&ht); } *** ../vim-8.1.2387/src/memline.c 2019-11-30 22:47:42.651331201 +0100 --- src/memline.c 2019-12-04 21:54:42.353161823 +0100 *************** *** 7,14 **** * See README.txt for an overview of the Vim source code. */ ! /* for debugging */ ! /* #define CHECK(c, s) do { if (c) emsg((s)); } while (0) */ #define CHECK(c, s) do { /**/ } while (0) /* --- 7,14 ---- * See README.txt for an overview of the Vim source code. */ ! // for debugging ! // #define CHECK(c, s) do { if (c) emsg((s)); } while (0) #define CHECK(c, s) do { /**/ } while (0) /* *************** *** 44,75 **** #include "vim.h" ! #ifndef UNIX /* it's in os_unix.h for Unix */ # include #endif #if defined(SASC) || defined(__amigaos4__) ! # include /* for Open() and Close() */ #endif ! typedef struct block0 ZERO_BL; /* contents of the first block */ ! typedef struct pointer_block PTR_BL; /* contents of a pointer block */ ! typedef struct data_block DATA_BL; /* contents of a data block */ ! typedef struct pointer_entry PTR_EN; /* block/line-count pair */ ! ! #define DATA_ID (('d' << 8) + 'a') /* data block id */ ! #define PTR_ID (('p' << 8) + 't') /* pointer block id */ ! #define BLOCK0_ID0 'b' /* block 0 id 0 */ ! #define BLOCK0_ID1 '0' /* block 0 id 1 */ ! #define BLOCK0_ID1_C0 'c' /* block 0 id 1 'cm' 0 */ ! #define BLOCK0_ID1_C1 'C' /* block 0 id 1 'cm' 1 */ ! #define BLOCK0_ID1_C2 'd' /* block 0 id 1 'cm' 2 */ #if defined(FEAT_CRYPT) static int id1_codes[] = { ! BLOCK0_ID1_C0, /* CRYPT_M_ZIP */ ! BLOCK0_ID1_C1, /* CRYPT_M_BF */ ! BLOCK0_ID1_C2, /* CRYPT_M_BF2 */ }; #endif --- 44,75 ---- #include "vim.h" ! #ifndef UNIX // it's in os_unix.h for Unix # include #endif #if defined(SASC) || defined(__amigaos4__) ! # include // for Open() and Close() #endif ! typedef struct block0 ZERO_BL; // contents of the first block ! typedef struct pointer_block PTR_BL; // contents of a pointer block ! typedef struct data_block DATA_BL; // contents of a data block ! typedef struct pointer_entry PTR_EN; // block/line-count pair ! ! #define DATA_ID (('d' << 8) + 'a') // data block id ! #define PTR_ID (('p' << 8) + 't') // pointer block id ! #define BLOCK0_ID0 'b' // block 0 id 0 ! #define BLOCK0_ID1 '0' // block 0 id 1 ! #define BLOCK0_ID1_C0 'c' // block 0 id 1 'cm' 0 ! #define BLOCK0_ID1_C1 'C' // block 0 id 1 'cm' 1 ! #define BLOCK0_ID1_C2 'd' // block 0 id 1 'cm' 2 #if defined(FEAT_CRYPT) static int id1_codes[] = { ! BLOCK0_ID1_C0, // CRYPT_M_ZIP ! BLOCK0_ID1_C1, // CRYPT_M_BF ! BLOCK0_ID1_C2, // CRYPT_M_BF2 }; #endif *************** *** 78,87 **** */ struct pointer_entry { ! blocknr_T pe_bnum; /* block number */ ! linenr_T pe_line_count; /* number of lines in this branch */ ! linenr_T pe_old_lnum; /* lnum for this block (for recovery) */ ! int pe_page_count; /* number of pages in block pe_bnum */ }; /* --- 78,87 ---- */ struct pointer_entry { ! blocknr_T pe_bnum; // block number ! linenr_T pe_line_count; // number of lines in this branch ! linenr_T pe_old_lnum; // lnum for this block (for recovery) ! int pe_page_count; // number of pages in block pe_bnum }; /* *************** *** 89,99 **** */ struct pointer_block { ! short_u pb_id; /* ID for pointer block: PTR_ID */ ! short_u pb_count; /* number of pointers in this block */ ! short_u pb_count_max; /* maximum value for pb_count */ ! PTR_EN pb_pointer[1]; /* list of pointers to blocks (actually longer) ! * followed by empty space until end of page */ }; /* --- 89,99 ---- */ struct pointer_block { ! short_u pb_id; // ID for pointer block: PTR_ID ! short_u pb_count; // number of pointers in this block ! short_u pb_count_max; // maximum value for pb_count ! PTR_EN pb_pointer[1]; // list of pointers to blocks (actually longer) ! // followed by empty space until end of page }; /* *************** *** 105,119 **** */ struct data_block { ! short_u db_id; /* ID for data block: DATA_ID */ ! unsigned db_free; /* free space available */ ! unsigned db_txt_start; /* byte where text starts */ ! unsigned db_txt_end; /* byte just after data block */ ! linenr_T db_line_count; /* number of lines in this block */ ! unsigned db_index[1]; /* index for start of line (actually bigger) ! * followed by empty space upto db_txt_start ! * followed by the text in the lines until ! * end of page */ }; /* --- 105,119 ---- */ struct data_block { ! short_u db_id; // ID for data block: DATA_ID ! unsigned db_free; // free space available ! unsigned db_txt_start; // byte where text starts ! unsigned db_txt_end; // byte just after data block ! linenr_T db_line_count; // number of lines in this block ! unsigned db_index[1]; // index for start of line (actually bigger) ! // followed by empty space upto db_txt_start ! // followed by the text in the lines until ! // end of page }; /* *************** *** 127,138 **** #define DB_MARKED ((unsigned)1 << ((sizeof(unsigned) * 8) - 1)) #define DB_INDEX_MASK (~DB_MARKED) ! #define INDEX_SIZE (sizeof(unsigned)) /* size of one db_index entry */ ! #define HEADER_SIZE (sizeof(DATA_BL) - INDEX_SIZE) /* size of data block header */ ! #define B0_FNAME_SIZE_ORG 900 /* what it was in older versions */ ! #define B0_FNAME_SIZE_NOCRYPT 898 /* 2 bytes used for other things */ ! #define B0_FNAME_SIZE_CRYPT 890 /* 10 bytes used for other things */ #define B0_UNAME_SIZE 40 #define B0_HNAME_SIZE 40 /* --- 127,138 ---- #define DB_MARKED ((unsigned)1 << ((sizeof(unsigned) * 8) - 1)) #define DB_INDEX_MASK (~DB_MARKED) ! #define INDEX_SIZE (sizeof(unsigned)) // size of one db_index entry ! #define HEADER_SIZE (sizeof(DATA_BL) - INDEX_SIZE) // size of data block header ! #define B0_FNAME_SIZE_ORG 900 // what it was in older versions ! #define B0_FNAME_SIZE_NOCRYPT 898 // 2 bytes used for other things ! #define B0_FNAME_SIZE_CRYPT 890 // 10 bytes used for other things #define B0_UNAME_SIZE 40 #define B0_HNAME_SIZE 40 /* *************** *** 159,178 **** */ struct block0 { ! char_u b0_id[2]; /* id for block 0: BLOCK0_ID0 and BLOCK0_ID1, ! * BLOCK0_ID1_C0, BLOCK0_ID1_C1, etc. */ ! char_u b0_version[10]; /* Vim version string */ ! char_u b0_page_size[4];/* number of bytes per page */ ! char_u b0_mtime[4]; /* last modification time of file */ ! char_u b0_ino[4]; /* inode of b0_fname */ ! char_u b0_pid[4]; /* process id of creator (or 0) */ ! char_u b0_uname[B0_UNAME_SIZE]; /* name of user (uid if no name) */ ! char_u b0_hname[B0_HNAME_SIZE]; /* host name (if it has a name) */ ! char_u b0_fname[B0_FNAME_SIZE_ORG]; /* name of file being edited */ ! long b0_magic_long; /* check for byte order of long */ ! int b0_magic_int; /* check for byte order of int */ ! short b0_magic_short; /* check for byte order of short */ ! char_u b0_magic_char; /* check for last char */ }; /* --- 159,178 ---- */ struct block0 { ! char_u b0_id[2]; // id for block 0: BLOCK0_ID0 and BLOCK0_ID1, ! // BLOCK0_ID1_C0, BLOCK0_ID1_C1, etc. ! char_u b0_version[10]; // Vim version string ! char_u b0_page_size[4];// number of bytes per page ! char_u b0_mtime[4]; // last modification time of file ! char_u b0_ino[4]; // inode of b0_fname ! char_u b0_pid[4]; // process id of creator (or 0) ! char_u b0_uname[B0_UNAME_SIZE]; // name of user (uid if no name) ! char_u b0_hname[B0_HNAME_SIZE]; // host name (if it has a name) ! char_u b0_fname[B0_FNAME_SIZE_ORG]; // name of file being edited ! long b0_magic_long; // check for byte order of long ! int b0_magic_int; // check for byte order of int ! short b0_magic_short; // check for byte order of short ! char_u b0_magic_char; // check for last char }; /* *************** *** 195,214 **** */ #define b0_seed b0_fname[B0_FNAME_SIZE_ORG - 2 - MF_SEED_LEN] ! /* The lowest two bits contain the fileformat. Zero means it's not set ! * (compatible with Vim 6.x), otherwise it's EOL_UNIX + 1, EOL_DOS + 1 or ! * EOL_MAC + 1. */ #define B0_FF_MASK 3 ! /* Swap file is in directory of edited file. Used to find the file from ! * different mount points. */ #define B0_SAME_DIR 4 ! /* The 'fileencoding' is at the end of b0_fname[], with a NUL in front of it. ! * When empty there is only the NUL. */ #define B0_HAS_FENC 8 ! #define STACK_INCR 5 /* nr of entries added to ml_stack at a time */ /* * The line number where the first mark may be is remembered. --- 195,214 ---- */ #define b0_seed b0_fname[B0_FNAME_SIZE_ORG - 2 - MF_SEED_LEN] ! // The lowest two bits contain the fileformat. Zero means it's not set ! // (compatible with Vim 6.x), otherwise it's EOL_UNIX + 1, EOL_DOS + 1 or ! // EOL_MAC + 1. #define B0_FF_MASK 3 ! // Swap file is in directory of edited file. Used to find the file from ! // different mount points. #define B0_SAME_DIR 4 ! // The 'fileencoding' is at the end of b0_fname[], with a NUL in front of it. ! // When empty there is only the NUL. #define B0_HAS_FENC 8 ! #define STACK_INCR 5 // nr of entries added to ml_stack at a time /* * The line number where the first mark may be is remembered. *************** *** 221,237 **** /* * arguments for ml_find_line() */ ! #define ML_DELETE 0x11 /* delete line */ ! #define ML_INSERT 0x12 /* insert line */ ! #define ML_FIND 0x13 /* just find the line */ ! #define ML_FLUSH 0x02 /* flush locked block */ ! #define ML_SIMPLE(x) (x & 0x10) /* DEL, INS or FIND */ ! /* argument for ml_upd_block0() */ typedef enum { ! UB_FNAME = 0 /* update timestamp and filename */ ! , UB_SAME_DIR /* update the B0_SAME_DIR flag */ ! , UB_CRYPT /* update crypt key */ } upd_block0_T; #ifdef FEAT_CRYPT --- 221,237 ---- /* * arguments for ml_find_line() */ ! #define ML_DELETE 0x11 // delete line ! #define ML_INSERT 0x12 // insert line ! #define ML_FIND 0x13 // just find the line ! #define ML_FLUSH 0x02 // flush locked block ! #define ML_SIMPLE(x) (x & 0x10) // DEL, INS or FIND ! // argument for ml_upd_block0() typedef enum { ! UB_FNAME = 0 // update timestamp and filename ! , UB_SAME_DIR // update the B0_SAME_DIR flag ! , UB_CRYPT // update crypt key } upd_block0_T; #ifdef FEAT_CRYPT *************** *** 281,291 **** /* * init fields in memline struct */ ! buf->b_ml.ml_stack_size = 0; /* no stack yet */ ! buf->b_ml.ml_stack = NULL; /* no stack yet */ ! buf->b_ml.ml_stack_top = 0; /* nothing in the stack */ ! buf->b_ml.ml_locked = NULL; /* no cached block */ ! buf->b_ml.ml_line_lnum = 0; /* no cached line */ #ifdef FEAT_BYTEOFF buf->b_ml.ml_chunksize = NULL; #endif --- 281,291 ---- /* * init fields in memline struct */ ! buf->b_ml.ml_stack_size = 0; // no stack yet ! buf->b_ml.ml_stack = NULL; // no stack yet ! buf->b_ml.ml_stack_top = 0; // nothing in the stack ! buf->b_ml.ml_locked = NULL; // no cached block ! buf->b_ml.ml_line_lnum = 0; // no cached line #ifdef FEAT_BYTEOFF buf->b_ml.ml_chunksize = NULL; #endif *************** *** 383,389 **** pp->pb_pointer[0].pe_bnum = 2; pp->pb_pointer[0].pe_page_count = 1; pp->pb_pointer[0].pe_old_lnum = 1; ! pp->pb_pointer[0].pe_line_count = 1; /* line count after insertion */ mf_put(mfp, hp, TRUE, FALSE); /* --- 383,389 ---- pp->pb_pointer[0].pe_bnum = 2; pp->pb_pointer[0].pe_page_count = 1; pp->pb_pointer[0].pe_old_lnum = 1; ! pp->pb_pointer[0].pe_line_count = 1; // line count after insertion mf_put(mfp, hp, TRUE, FALSE); /* *************** *** 398,407 **** } dp = (DATA_BL *)(hp->bh_data); ! dp->db_index[0] = --dp->db_txt_start; /* at end of block */ dp->db_free -= 1 + INDEX_SIZE; dp->db_line_count = 1; ! *((char_u *)dp + dp->db_txt_start) = NUL; /* empty line */ return OK; --- 398,407 ---- } dp = (DATA_BL *)(hp->bh_data); ! dp->db_index[0] = --dp->db_txt_start; // at end of block dp->db_free -= 1 + INDEX_SIZE; dp->db_line_count = 1; ! *((char_u *)dp + dp->db_txt_start) = NUL; // empty line return OK; *************** *** 410,416 **** { if (hp) mf_put(mfp, hp, FALSE, FALSE); ! mf_close(mfp, TRUE); /* will also free(mfp->mf_fname) */ } buf->b_ml.ml_mfp = NULL; return FAIL; --- 410,416 ---- { if (hp) mf_put(mfp, hp, FALSE, FALSE); ! mf_close(mfp, TRUE); // will also free(mfp->mf_fname) } buf->b_ml.ml_mfp = NULL; return FAIL; *************** *** 429,435 **** if (method_nr > CRYPT_M_ZIP) { ! /* Generate a seed and store it in the memfile. */ sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0); } } --- 429,435 ---- if (method_nr > CRYPT_M_ZIP) { ! // Generate a seed and store it in the memfile. sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0); } } *************** *** 450,456 **** b0p->b0_id[1] = id1_codes[method_nr]; if (method_nr > CRYPT_M_ZIP) { ! /* Generate a seed and store it in block 0 and in the memfile. */ sha2_seed(&b0p->b0_seed, MF_SEED_LEN, NULL, 0); mch_memmove(buf->b_ml.ml_mfp->mf_seed, &b0p->b0_seed, MF_SEED_LEN); } --- 450,456 ---- b0p->b0_id[1] = id1_codes[method_nr]; if (method_nr > CRYPT_M_ZIP) { ! // Generate a seed and store it in block 0 and in the memfile. sha2_seed(&b0p->b0_seed, MF_SEED_LEN, NULL, 0); mch_memmove(buf->b_ml.ml_mfp->mf_seed, &b0p->b0_seed, MF_SEED_LEN); } *************** *** 484,494 **** int old_method; if (mfp == NULL) ! return; /* no memfile yet, nothing to do */ old_method = crypt_method_nr_from_name(old_cm); ! /* First make sure the swapfile is in a consistent state, using the old ! * key and method. */ { char_u *new_key = buf->b_p_key; char_u *new_buf_cm = buf->b_p_cm; --- 484,494 ---- int old_method; if (mfp == NULL) ! return; // no memfile yet, nothing to do old_method = crypt_method_nr_from_name(old_cm); ! // First make sure the swapfile is in a consistent state, using the old ! // key and method. { char_u *new_key = buf->b_p_key; char_u *new_buf_cm = buf->b_p_cm; *************** *** 500,513 **** buf->b_p_cm = new_buf_cm; } ! /* Set the key, method and seed to be used for reading, these must be the ! * old values. */ mfp->mf_old_key = old_key; mfp->mf_old_cm = old_method; if (old_method > 0 && *old_key != NUL) mch_memmove(mfp->mf_old_seed, mfp->mf_seed, MF_SEED_LEN); ! /* Update block 0 with the crypt flag and may set a new seed. */ ml_upd_block0(buf, UB_CRYPT); if (mfp->mf_infile_count > 2) --- 500,513 ---- buf->b_p_cm = new_buf_cm; } ! // Set the key, method and seed to be used for reading, these must be the ! // old values. mfp->mf_old_key = old_key; mfp->mf_old_cm = old_method; if (old_method > 0 && *old_key != NUL) mch_memmove(mfp->mf_old_seed, mfp->mf_seed, MF_SEED_LEN); ! // Update block 0 with the crypt flag and may set a new seed. ml_upd_block0(buf, UB_CRYPT); if (mfp->mf_infile_count > 2) *************** *** 518,541 **** * similar to what happens in ml_recover(), but we skip negative block * numbers. */ ! ml_flush_line(buf); /* flush buffered line */ ! (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */ hp = NULL; ! bnum = 1; /* start with block 1 */ ! page_count = 1; /* which is 1 page */ ! idx = 0; /* start with first index in block 1 */ error = 0; buf->b_ml.ml_stack_top = 0; VIM_CLEAR(buf->b_ml.ml_stack); ! buf->b_ml.ml_stack_size = 0; /* no stack yet */ for ( ; !got_int; line_breakcheck()) { if (hp != NULL) ! mf_put(mfp, hp, FALSE, FALSE); /* release previous block */ ! /* get the block (pointer or data) */ if ((hp = mf_get(mfp, (blocknr_T)bnum, page_count)) == NULL) { if (bnum == 1) --- 518,541 ---- * similar to what happens in ml_recover(), but we skip negative block * numbers. */ ! ml_flush_line(buf); // flush buffered line ! (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush locked block hp = NULL; ! bnum = 1; // start with block 1 ! page_count = 1; // which is 1 page ! idx = 0; // start with first index in block 1 error = 0; buf->b_ml.ml_stack_top = 0; VIM_CLEAR(buf->b_ml.ml_stack); ! buf->b_ml.ml_stack_size = 0; // no stack yet for ( ; !got_int; line_breakcheck()) { if (hp != NULL) ! mf_put(mfp, hp, FALSE, FALSE); // release previous block ! // get the block (pointer or data) if ((hp = mf_get(mfp, (blocknr_T)bnum, page_count)) == NULL) { if (bnum == 1) *************** *** 545,574 **** else { pp = (PTR_BL *)(hp->bh_data); ! if (pp->pb_id == PTR_ID) /* it is a pointer block */ { if (pp->pb_count == 0) { ! /* empty block? */ ++error; } ! else if (idx < (int)pp->pb_count) /* go a block deeper */ { if (pp->pb_pointer[idx].pe_bnum < 0) { ! /* Skip data block with negative block number. ! * Should not happen, because of the ml_preserve() ! * above. Get same block again for next index. */ ++idx; continue; } ! /* going one block deeper in the tree, new entry in ! * stack */ if ((top = ml_add_stack(buf)) < 0) { ++error; ! break; /* out of memory */ } ip = &(buf->b_ml.ml_stack[top]); ip->ip_bnum = bnum; --- 545,574 ---- else { pp = (PTR_BL *)(hp->bh_data); ! if (pp->pb_id == PTR_ID) // it is a pointer block { if (pp->pb_count == 0) { ! // empty block? ++error; } ! else if (idx < (int)pp->pb_count) // go a block deeper { if (pp->pb_pointer[idx].pe_bnum < 0) { ! // Skip data block with negative block number. ! // Should not happen, because of the ml_preserve() ! // above. Get same block again for next index. ++idx; continue; } ! // going one block deeper in the tree, new entry in ! // stack if ((top = ml_add_stack(buf)) < 0) { ++error; ! break; // out of memory } ip = &(buf->b_ml.ml_stack[top]); ip->ip_bnum = bnum; *************** *** 580,610 **** continue; } } ! else /* not a pointer block */ { dp = (DATA_BL *)(hp->bh_data); ! if (dp->db_id != DATA_ID) /* block id wrong */ ++error; else { ! /* It is a data block, need to write it back to disk. */ mf_put(mfp, hp, TRUE, FALSE); hp = NULL; } } } ! if (buf->b_ml.ml_stack_top == 0) /* finished */ break; ! /* go one block up in the tree */ ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]); bnum = ip->ip_bnum; ! idx = ip->ip_index + 1; /* go to next index */ page_count = 1; } if (hp != NULL) ! mf_put(mfp, hp, FALSE, FALSE); /* release previous block */ if (error > 0) emsg(_("E843: Error while updating swap file crypt")); --- 580,610 ---- continue; } } ! else // not a pointer block { dp = (DATA_BL *)(hp->bh_data); ! if (dp->db_id != DATA_ID) // block id wrong ++error; else { ! // It is a data block, need to write it back to disk. mf_put(mfp, hp, TRUE, FALSE); hp = NULL; } } } ! if (buf->b_ml.ml_stack_top == 0) // finished break; ! // go one block up in the tree ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]); bnum = ip->ip_bnum; ! idx = ip->ip_index + 1; // go to next index page_count = 1; } if (hp != NULL) ! mf_put(mfp, hp, FALSE, FALSE); // release previous block if (error > 0) emsg(_("E843: Error while updating swap file crypt")); *************** *** 630,643 **** #endif mfp = buf->b_ml.ml_mfp; ! if (mfp->mf_fd < 0) /* there is no swap file yet */ { /* * When 'updatecount' is 0 and 'noswapfile' there is no swap file. * For help files we will make a swap file now. */ if (p_uc != 0 && !cmdmod.noswapfile) ! ml_open_file(buf); /* create a swap file */ return; } --- 630,643 ---- #endif mfp = buf->b_ml.ml_mfp; ! if (mfp->mf_fd < 0) // there is no swap file yet { /* * When 'updatecount' is 0 and 'noswapfile' there is no swap file. * For help files we will make a swap file now. */ if (p_uc != 0 && !cmdmod.noswapfile) ! ml_open_file(buf); // create a swap file return; } *************** *** 647,659 **** dirp = p_dir; for (;;) { ! if (*dirp == NUL) /* tried all directories, fail */ break; fname = findswapname(buf, &dirp, mfp->mf_fname); ! /* alloc's fname */ ! if (dirp == NULL) /* out of memory */ break; ! if (fname == NULL) /* no file name found for this dir */ continue; #if defined(MSWIN) --- 647,659 ---- dirp = p_dir; for (;;) { ! if (*dirp == NUL) // tried all directories, fail break; fname = findswapname(buf, &dirp, mfp->mf_fname); ! // alloc's fname ! if (dirp == NULL) // out of memory break; ! if (fname == NULL) // no file name found for this dir continue; #if defined(MSWIN) *************** *** 667,687 **** if (fname == NULL) continue; #endif ! /* if the file name is the same we don't have to do anything */ if (fnamecmp(fname, mfp->mf_fname) == 0) { vim_free(fname); success = TRUE; break; } ! /* need to close the swap file before renaming */ if (mfp->mf_fd >= 0) { close(mfp->mf_fd); mfp->mf_fd = -1; } ! /* try to rename the swap file */ if (vim_rename(mfp->mf_fname, fname) == 0) { success = TRUE; --- 667,687 ---- if (fname == NULL) continue; #endif ! // if the file name is the same we don't have to do anything if (fnamecmp(fname, mfp->mf_fname) == 0) { vim_free(fname); success = TRUE; break; } ! // need to close the swap file before renaming if (mfp->mf_fd >= 0) { close(mfp->mf_fd); mfp->mf_fd = -1; } ! // try to rename the swap file if (vim_rename(mfp->mf_fname, fname) == 0) { success = TRUE; *************** *** 689,710 **** mfp->mf_fname = fname; vim_free(mfp->mf_ffname); #if defined(MSWIN) ! mfp->mf_ffname = NULL; /* mf_fname is full pathname already */ #else mf_set_ffname(mfp); #endif ml_upd_block0(buf, UB_SAME_DIR); break; } ! vim_free(fname); /* this fname didn't work, try another */ } ! if (mfp->mf_fd == -1) /* need to (re)open the swap file */ { mfp->mf_fd = mch_open((char *)mfp->mf_fname, O_RDWR | O_EXTRA, 0); if (mfp->mf_fd < 0) { ! /* could not (re)open the swap file, what can we do???? */ emsg(_("E301: Oops, lost the swap file!!!")); return; } --- 689,710 ---- mfp->mf_fname = fname; vim_free(mfp->mf_ffname); #if defined(MSWIN) ! mfp->mf_ffname = NULL; // mf_fname is full pathname already #else mf_set_ffname(mfp); #endif ml_upd_block0(buf, UB_SAME_DIR); break; } ! vim_free(fname); // this fname didn't work, try another } ! if (mfp->mf_fd == -1) // need to (re)open the swap file { mfp->mf_fd = mch_open((char *)mfp->mf_fname, O_RDWR | O_EXTRA, 0); if (mfp->mf_fd < 0) { ! // could not (re)open the swap file, what can we do???? emsg(_("E301: Oops, lost the swap file!!!")); return; } *************** *** 749,763 **** mfp = buf->b_ml.ml_mfp; if (mfp == NULL || mfp->mf_fd >= 0 || !buf->b_p_swf || cmdmod.noswapfile) ! return; /* nothing to do */ #ifdef FEAT_SPELL ! /* For a spell buffer use a temp file name. */ if (buf->b_spell) { fname = vim_tempname('s', FALSE); if (fname != NULL) ! (void)mf_open_file(mfp, fname); /* consumes fname! */ buf->b_may_swap = FALSE; return; } --- 749,763 ---- mfp = buf->b_ml.ml_mfp; if (mfp == NULL || mfp->mf_fd >= 0 || !buf->b_p_swf || cmdmod.noswapfile) ! return; // nothing to do #ifdef FEAT_SPELL ! // For a spell buffer use a temp file name. if (buf->b_spell) { fname = vim_tempname('s', FALSE); if (fname != NULL) ! (void)mf_open_file(mfp, fname); // consumes fname! buf->b_may_swap = FALSE; return; } *************** *** 771,785 **** { if (*dirp == NUL) break; ! /* There is a small chance that between choosing the swap file name ! * and creating it, another Vim creates the file. In that case the ! * creation will fail and we will use another directory. */ ! fname = findswapname(buf, &dirp, NULL); /* allocates fname */ if (dirp == NULL) ! break; /* out of memory */ if (fname == NULL) continue; ! if (mf_open_file(mfp, fname) == OK) /* consumes fname! */ { #if defined(MSWIN) /* --- 771,785 ---- { if (*dirp == NUL) break; ! // There is a small chance that between choosing the swap file name ! // and creating it, another Vim creates the file. In that case the ! // creation will fail and we will use another directory. ! fname = findswapname(buf, &dirp, NULL); // allocates fname if (dirp == NULL) ! break; // out of memory if (fname == NULL) continue; ! if (mf_open_file(mfp, fname) == OK) // consumes fname! { #if defined(MSWIN) /* *************** *** 790,805 **** #endif ml_upd_block0(buf, UB_SAME_DIR); ! /* Flush block zero, so others can read it */ if (mf_sync(mfp, MFS_ZERO) == OK) { ! /* Mark all blocks that should be in the swapfile as dirty. ! * Needed for when the 'swapfile' option was reset, so that ! * the swap file was deleted, and then on again. */ mf_set_dirty(mfp); break; } ! /* Writing block 0 failed: close the file and try another dir */ mf_close_file(buf, FALSE); } } --- 790,805 ---- #endif ml_upd_block0(buf, UB_SAME_DIR); ! // Flush block zero, so others can read it if (mf_sync(mfp, MFS_ZERO) == OK) { ! // Mark all blocks that should be in the swapfile as dirty. ! // Needed for when the 'swapfile' option was reset, so that ! // the swap file was deleted, and then on again. mf_set_dirty(mfp); break; } ! // Writing block 0 failed: close the file and try another dir mf_close_file(buf, FALSE); } } *************** *** 813,819 **** --no_wait_return; } ! /* don't try to open a swap file again */ buf->b_may_swap = FALSE; } --- 813,819 ---- --no_wait_return; } ! // don't try to open a swap file again buf->b_may_swap = FALSE; } *************** *** 839,847 **** void ml_close(buf_T *buf, int del_file) { ! if (buf->b_ml.ml_mfp == NULL) /* not open */ return; ! mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */ if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY)) vim_free(buf->b_ml.ml_line_ptr); vim_free(buf->b_ml.ml_stack); --- 839,847 ---- void ml_close(buf_T *buf, int del_file) { ! if (buf->b_ml.ml_mfp == NULL) // not open return; ! mf_close(buf->b_ml.ml_mfp, del_file); // close the .swp file if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY)) vim_free(buf->b_ml.ml_line_ptr); vim_free(buf->b_ml.ml_stack); *************** *** 850,857 **** #endif buf->b_ml.ml_mfp = NULL; ! /* Reset the "recovered" flag, give the ATTENTION prompt the next time ! * this buffer is loaded. */ buf->b_flags &= ~BF_RECOVERED; } --- 850,857 ---- #endif buf->b_ml.ml_mfp = NULL; ! // Reset the "recovered" flag, give the ATTENTION prompt the next time ! // this buffer is loaded. buf->b_flags &= ~BF_RECOVERED; } *************** *** 870,879 **** ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0 || vim_strchr(p_cpo, CPO_PRESERVE) == NULL)); #ifdef FEAT_SPELL ! spell_delete_wordlist(); /* delete the internal wordlist */ #endif #ifdef TEMPDIRNAMES ! vim_deltempdir(); /* delete created temp directory */ #endif } --- 870,879 ---- ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0 || vim_strchr(p_cpo, CPO_PRESERVE) == NULL)); #ifdef FEAT_SPELL ! spell_delete_wordlist(); // delete the internal wordlist #endif #ifdef TEMPDIRNAMES ! vim_deltempdir(); // delete created temp directory #endif } *************** *** 888,894 **** FOR_ALL_BUFFERS(buf) if (!bufIsChanged(buf)) ! ml_close(buf, TRUE); /* close all not-modified buffers */ } /* --- 888,894 ---- FOR_ALL_BUFFERS(buf) if (!bufIsChanged(buf)) ! ml_close(buf, TRUE); // close all not-modified buffers } /* *************** *** 934,940 **** if (hp == NULL) { #ifdef FEAT_CRYPT ! /* Possibly update the seed in the memfile before there is a block0. */ if (what == UB_CRYPT) ml_set_mfp_crypt(buf); #endif --- 934,940 ---- if (hp == NULL) { #ifdef FEAT_CRYPT ! // Possibly update the seed in the memfile before there is a block0. if (what == UB_CRYPT) ml_set_mfp_crypt(buf); #endif *************** *** 952,958 **** else if (what == UB_CRYPT) ml_set_b0_crypt(buf, b0p); #endif ! else /* what == UB_SAME_DIR */ set_b0_dir_flag(b0p, buf); } mf_put(mfp, hp, TRUE, FALSE); --- 952,958 ---- else if (what == UB_CRYPT) ml_set_b0_crypt(buf, b0p); #endif ! else // what == UB_SAME_DIR set_b0_dir_flag(b0p, buf); } mf_put(mfp, hp, TRUE, FALSE); *************** *** 973,981 **** else { #if defined(MSWIN) || defined(AMIGA) ! /* Systems that cannot translate "~user" back into a path: copy the ! * file name unmodified. Do use slashes instead of backslashes for ! * portability. */ vim_strncpy(b0p->b0_fname, buf->b_ffname, B0_FNAME_SIZE_CRYPT - 1); # ifdef BACKSLASH_IN_FILENAME forward_slash(b0p->b0_fname); --- 973,981 ---- else { #if defined(MSWIN) || defined(AMIGA) ! // Systems that cannot translate "~user" back into a path: copy the ! // file name unmodified. Do use slashes instead of backslashes for ! // portability. vim_strncpy(b0p->b0_fname, buf->b_ffname, B0_FNAME_SIZE_CRYPT - 1); # ifdef BACKSLASH_IN_FILENAME forward_slash(b0p->b0_fname); *************** *** 996,1002 **** if (b0p->b0_fname[0] == '~') { flen = STRLEN(b0p->b0_fname); ! /* If there is no user name or it is too long, don't use "~/" */ if (get_user_name(uname, B0_UNAME_SIZE) == FAIL || (ulen = STRLEN(uname)) + flen > B0_FNAME_SIZE_CRYPT - 1) vim_strncpy(b0p->b0_fname, buf->b_ffname, --- 996,1002 ---- if (b0p->b0_fname[0] == '~') { flen = STRLEN(b0p->b0_fname); ! // If there is no user name or it is too long, don't use "~/" if (get_user_name(uname, B0_UNAME_SIZE) == FAIL || (ulen = STRLEN(uname)) + flen > B0_FNAME_SIZE_CRYPT - 1) vim_strncpy(b0p->b0_fname, buf->b_ffname, *************** *** 1030,1036 **** } } ! /* Also add the 'fileencoding' if there is room. */ add_b0_fenc(b0p, curbuf); } --- 1030,1036 ---- } } ! // Also add the 'fileencoding' if there is room. add_b0_fenc(b0p, curbuf); } *************** *** 1061,1069 **** int size = B0_FNAME_SIZE_NOCRYPT; #ifdef FEAT_CRYPT ! /* Without encryption use the same offset as in Vim 7.2 to be compatible. ! * With encryption it's OK to move elsewhere, the swap file is not ! * compatible anyway. */ if (*buf->b_p_key != NUL) size = B0_FNAME_SIZE_CRYPT; #endif --- 1061,1069 ---- int size = B0_FNAME_SIZE_NOCRYPT; #ifdef FEAT_CRYPT ! // Without encryption use the same offset as in Vim 7.2 to be compatible. ! // With encryption it's OK to move elsewhere, the swap file is not ! // compatible anyway. if (*buf->b_p_key != NUL) size = B0_FNAME_SIZE_CRYPT; #endif *************** *** 1134,1140 **** * Otherwise a search is done to find the swap file(s). */ fname = curbuf->b_fname; ! if (fname == NULL) /* When there is no file name */ fname = (char_u *)""; len = (int)STRLEN(fname); if (checkext && len >= 4 && --- 1134,1140 ---- * Otherwise a search is done to find the swap file(s). */ fname = curbuf->b_fname; ! if (fname == NULL) // When there is no file name fname = (char_u *)""; len = (int)STRLEN(fname); if (checkext && len >= 4 && *************** *** 1149,1172 **** && ASCII_ISALPHA(fname[len - 1])) { directly = TRUE; ! fname_used = vim_strsave(fname); /* make a copy for mf_open() */ } else { directly = FALSE; ! /* count the number of matching swap files */ len = recover_names(fname, FALSE, 0, NULL); ! if (len == 0) /* no swap files found */ { semsg(_("E305: No swap file found for %s"), fname); goto theend; } ! if (len == 1) /* one swap file found, use it */ i = 1; ! else /* several swap files found, choose */ { ! /* list the names of the swap files */ (void)recover_names(fname, TRUE, 0, NULL); msg_putchar('\n'); msg_puts(_("Enter number of swap file to use (0 to quit): ")); --- 1149,1172 ---- && ASCII_ISALPHA(fname[len - 1])) { directly = TRUE; ! fname_used = vim_strsave(fname); // make a copy for mf_open() } else { directly = FALSE; ! // count the number of matching swap files len = recover_names(fname, FALSE, 0, NULL); ! if (len == 0) // no swap files found { semsg(_("E305: No swap file found for %s"), fname); goto theend; } ! if (len == 1) // one swap file found, use it i = 1; ! else // several swap files found, choose { ! // list the names of the swap files (void)recover_names(fname, TRUE, 0, NULL); msg_putchar('\n'); msg_puts(_("Enter number of swap file to use (0 to quit): ")); *************** *** 1174,1186 **** if (i < 1 || i > len) goto theend; } ! /* get the swap file name that will be used */ (void)recover_names(fname, FALSE, i, &fname_used); } if (fname_used == NULL) ! goto theend; /* out of memory */ ! /* When called from main() still need to initialize storage structure */ if (called_from_main && ml_open(curbuf) == FAIL) getout(1); --- 1174,1186 ---- if (i < 1 || i > len) goto theend; } ! // get the swap file name that will be used (void)recover_names(fname, FALSE, i, &fname_used); } if (fname_used == NULL) ! goto theend; // out of memory ! // When called from main() still need to initialize storage structure if (called_from_main && ml_open(curbuf) == FAIL) getout(1); *************** *** 1195,1205 **** /* * init fields in memline struct */ ! buf->b_ml.ml_stack_size = 0; /* no stack yet */ ! buf->b_ml.ml_stack = NULL; /* no stack yet */ ! buf->b_ml.ml_stack_top = 0; /* nothing in the stack */ ! buf->b_ml.ml_line_lnum = 0; /* no cached line */ ! buf->b_ml.ml_locked = NULL; /* no locked block */ buf->b_ml.ml_flags = 0; #ifdef FEAT_CRYPT buf->b_p_key = empty_option; --- 1195,1205 ---- /* * init fields in memline struct */ ! buf->b_ml.ml_stack_size = 0; // no stack yet ! buf->b_ml.ml_stack = NULL; // no stack yet ! buf->b_ml.ml_stack_top = 0; // nothing in the stack ! buf->b_ml.ml_line_lnum = 0; // no cached line ! buf->b_ml.ml_locked = NULL; // no locked block buf->b_ml.ml_flags = 0; #ifdef FEAT_CRYPT buf->b_p_key = empty_option; *************** *** 1209,1216 **** /* * open the memfile from the old swap file */ ! p = vim_strsave(fname_used); /* save "fname_used" for the message: ! mf_open() will consume "fname_used"! */ mfp = mf_open(fname_used, O_RDONLY); fname_used = p; if (mfp == NULL || mfp->mf_fd < 0) --- 1209,1216 ---- /* * open the memfile from the old swap file */ ! p = vim_strsave(fname_used); // save "fname_used" for the message: ! // mf_open() will consume "fname_used"! mfp = mf_open(fname_used, O_RDONLY); fname_used = p; if (mfp == NULL || mfp->mf_fd < 0) *************** *** 1274,1280 **** msg_puts_attr(_(" cannot be used on this computer.\n"), attr | MSG_HIST); msg_puts_attr(_("The file was created on "), attr | MSG_HIST); ! /* avoid going past the end of a corrupted hostname */ b0p->b0_fname[0] = NUL; msg_puts_attr((char *)b0p->b0_hname, attr | MSG_HIST); msg_puts_attr(_(",\nor the file has been damaged."), attr | MSG_HIST); --- 1274,1280 ---- msg_puts_attr(_(" cannot be used on this computer.\n"), attr | MSG_HIST); msg_puts_attr(_("The file was created on "), attr | MSG_HIST); ! // avoid going past the end of a corrupted hostname b0p->b0_fname[0] = NUL; msg_puts_attr((char *)b0p->b0_hname, attr | MSG_HIST); msg_puts_attr(_(",\nor the file has been damaged."), attr | MSG_HIST); *************** *** 1316,1327 **** goto theend; } if ((size = vim_lseek(mfp->mf_fd, (off_T)0L, SEEK_END)) <= 0) ! mfp->mf_blocknr_max = 0; /* no file or empty file */ else mfp->mf_blocknr_max = (blocknr_T)(size / mfp->mf_page_size); mfp->mf_infile_count = mfp->mf_blocknr_max; ! /* need to reallocate the memory used to store the data */ p = alloc(mfp->mf_page_size); if (p == NULL) goto theend; --- 1316,1327 ---- goto theend; } if ((size = vim_lseek(mfp->mf_fd, (off_T)0L, SEEK_END)) <= 0) ! mfp->mf_blocknr_max = 0; // no file or empty file else mfp->mf_blocknr_max = (blocknr_T)(size / mfp->mf_page_size); mfp->mf_infile_count = mfp->mf_blocknr_max; ! // need to reallocate the memory used to store the data p = alloc(mfp->mf_page_size); if (p == NULL) goto theend; *************** *** 1363,1376 **** emsg(_("E308: Warning: Original file may have been changed")); out_flush(); ! /* Get the 'fileformat' and 'fileencoding' from block zero. */ b0_ff = (b0p->b0_flags & B0_FF_MASK); if (b0p->b0_flags & B0_HAS_FENC) { int fnsize = B0_FNAME_SIZE_NOCRYPT; #ifdef FEAT_CRYPT ! /* Use the same size as in add_b0_fenc(). */ if (b0p->b0_id[1] != BLOCK0_ID1) fnsize = B0_FNAME_SIZE_CRYPT; #endif --- 1363,1376 ---- emsg(_("E308: Warning: Original file may have been changed")); out_flush(); ! // Get the 'fileformat' and 'fileencoding' from block zero. b0_ff = (b0p->b0_flags & B0_FF_MASK); if (b0p->b0_flags & B0_HAS_FENC) { int fnsize = B0_FNAME_SIZE_NOCRYPT; #ifdef FEAT_CRYPT ! // Use the same size as in add_b0_fenc(). if (b0p->b0_id[1] != BLOCK0_ID1) fnsize = B0_FNAME_SIZE_CRYPT; #endif *************** *** 1379,1385 **** b0_fenc = vim_strnsave(p, (int)(b0p->b0_fname + fnsize - p)); } ! mf_put(mfp, hp, FALSE, FALSE); /* release block 0 */ hp = NULL; /* --- 1379,1385 ---- b0_fenc = vim_strnsave(p, (int)(b0p->b0_fname + fnsize - p)); } ! mf_put(mfp, hp, FALSE, FALSE); // release block 0 hp = NULL; /* *************** *** 1401,1408 **** #ifdef FEAT_CRYPT if (b0_cm >= 0) { ! /* Need to ask the user for the crypt key. If this fails we continue ! * without a key, will probably get garbage text. */ if (*curbuf->b_p_key != NUL) { smsg(_("Swap file is encrypted: \"%s\""), fname_used); --- 1401,1408 ---- #ifdef FEAT_CRYPT if (b0_cm >= 0) { ! // Need to ask the user for the crypt key. If this fails we continue ! // without a key, will probably get garbage text. if (*curbuf->b_p_key != NUL) { smsg(_("Swap file is encrypted: \"%s\""), fname_used); *************** *** 1426,1432 **** } #endif ! /* Use the 'fileformat' and 'fileencoding' as stored in the swap file. */ if (b0_ff != 0) set_fileformat(b0_ff - 1, OPT_LOCAL); if (b0_fenc != NULL) --- 1426,1432 ---- } #endif ! // Use the 'fileformat' and 'fileencoding' as stored in the swap file. if (b0_ff != 0) set_fileformat(b0_ff - 1, OPT_LOCAL); if (b0_fenc != NULL) *************** *** 1436,1450 **** } unchanged(curbuf, TRUE, TRUE); ! bnum = 1; /* start with block 1 */ ! page_count = 1; /* which is 1 page */ ! lnum = 0; /* append after line 0 in curbuf */ line_count = 0; ! idx = 0; /* start with first index in block 1 */ error = 0; buf->b_ml.ml_stack_top = 0; buf->b_ml.ml_stack = NULL; ! buf->b_ml.ml_stack_size = 0; /* no stack yet */ if (curbuf->b_ffname == NULL) cannot_open = TRUE; --- 1436,1450 ---- } unchanged(curbuf, TRUE, TRUE); ! bnum = 1; // start with block 1 ! page_count = 1; // which is 1 page ! lnum = 0; // append after line 0 in curbuf line_count = 0; ! idx = 0; // start with first index in block 1 error = 0; buf->b_ml.ml_stack_top = 0; buf->b_ml.ml_stack = NULL; ! buf->b_ml.ml_stack_size = 0; // no stack yet if (curbuf->b_ffname == NULL) cannot_open = TRUE; *************** *** 1455,1461 **** for ( ; !got_int; line_breakcheck()) { if (hp != NULL) ! mf_put(mfp, hp, FALSE, FALSE); /* release previous block */ /* * get block --- 1455,1461 ---- for ( ; !got_int; line_breakcheck()) { if (hp != NULL) ! mf_put(mfp, hp, FALSE, FALSE); // release previous block /* * get block *************** *** 1471,1482 **** ml_append(lnum++, (char_u *)_("???MANY LINES MISSING"), (colnr_T)0, TRUE); } ! else /* there is a block */ { pp = (PTR_BL *)(hp->bh_data); ! if (pp->pb_id == PTR_ID) /* it is a pointer block */ { ! /* check line count when using pointer block first time */ if (idx == 0 && line_count != 0) { for (i = 0; i < (int)pp->pb_count; ++i) --- 1471,1482 ---- ml_append(lnum++, (char_u *)_("???MANY LINES MISSING"), (colnr_T)0, TRUE); } ! else // there is a block { pp = (PTR_BL *)(hp->bh_data); ! if (pp->pb_id == PTR_ID) // it is a pointer block { ! // check line count when using pointer block first time if (idx == 0 && line_count != 0) { for (i = 0; i < (int)pp->pb_count; ++i) *************** *** 1495,1501 **** (colnr_T)0, TRUE); ++error; } ! else if (idx < (int)pp->pb_count) /* go a block deeper */ { if (pp->pb_pointer[idx].pe_bnum < 0) { --- 1495,1501 ---- (colnr_T)0, TRUE); ++error; } ! else if (idx < (int)pp->pb_count) // go a block deeper { if (pp->pb_pointer[idx].pe_bnum < 0) { *************** *** 1520,1536 **** ml_append(lnum++, (char_u *)_("???LINES MISSING"), (colnr_T)0, TRUE); } ! ++idx; /* get same block again for next index */ continue; } /* * going one block deeper in the tree */ ! if ((top = ml_add_stack(buf)) < 0) /* new entry in stack */ { ++error; ! break; /* out of memory */ } ip = &(buf->b_ml.ml_stack[top]); ip->ip_bnum = bnum; --- 1520,1536 ---- ml_append(lnum++, (char_u *)_("???LINES MISSING"), (colnr_T)0, TRUE); } ! ++idx; // get same block again for next index continue; } /* * going one block deeper in the tree */ ! if ((top = ml_add_stack(buf)) < 0) // new entry in stack { ++error; ! break; // out of memory } ip = &(buf->b_ml.ml_stack[top]); ip->ip_bnum = bnum; *************** *** 1543,1552 **** continue; } } ! else /* not a pointer block */ { dp = (DATA_BL *)(hp->bh_data); ! if (dp->db_id != DATA_ID) /* block id wrong */ { if (bnum == 1) { --- 1543,1552 ---- continue; } } ! else // not a pointer block { dp = (DATA_BL *)(hp->bh_data); ! if (dp->db_id != DATA_ID) // block id wrong { if (bnum == 1) { *************** *** 1578,1584 **** dp->db_txt_end = page_count * mfp->mf_page_size; } ! /* make sure there is a NUL at the end of the block */ *((char_u *)dp + dp->db_txt_end - 1) = NUL; /* --- 1578,1584 ---- dp->db_txt_end = page_count * mfp->mf_page_size; } ! // make sure there is a NUL at the end of the block *((char_u *)dp + dp->db_txt_end - 1) = NUL; /* *************** *** 1613,1619 **** } } ! if (buf->b_ml.ml_stack_top == 0) /* finished */ break; /* --- 1613,1619 ---- } } ! if (buf->b_ml.ml_stack_top == 0) // finished break; /* *************** *** 1621,1627 **** */ ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]); bnum = ip->ip_bnum; ! idx = ip->ip_index + 1; /* go to next index */ page_count = 1; } --- 1621,1627 ---- */ ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]); bnum = ip->ip_bnum; ! idx = ip->ip_index + 1; // go to next index page_count = 1; } *************** *** 1634,1641 **** */ if (orig_file_status != OK || curbuf->b_ml.ml_line_count != lnum * 2 + 1) { ! /* Recovering an empty file results in two lines and the first line is ! * empty. Don't set the modified flag then. */ if (!(curbuf->b_ml.ml_line_count == 2 && *ml_get(1) == NUL)) { changed_internal(); --- 1634,1641 ---- */ if (orig_file_status != OK || curbuf->b_ml.ml_line_count != lnum * 2 + 1) { ! // Recovering an empty file results in two lines and the first line is ! // empty. Don't set the modified flag then. if (!(curbuf->b_ml.ml_line_count == 2 && *ml_get(1) == NUL)) { changed_internal(); *************** *** 1646,1652 **** { for (idx = 1; idx <= lnum; ++idx) { ! /* Need to copy one line, fetching the other one may flush it. */ p = vim_strsave(ml_get(idx)); i = STRCMP(p, ml_get(idx + lnum)); vim_free(p); --- 1646,1652 ---- { for (idx = 1; idx <= lnum; ++idx) { ! // Need to copy one line, fetching the other one may flush it. p = vim_strsave(ml_get(idx)); i = STRCMP(p, ml_get(idx + lnum)); vim_free(p); *************** *** 1709,1715 **** { if (hp != NULL) mf_put(mfp, hp, FALSE, FALSE); ! mf_close(mfp, FALSE); /* will also vim_free(mfp->mf_fname) */ } if (buf != NULL) { --- 1709,1715 ---- { if (hp != NULL) mf_put(mfp, hp, FALSE, FALSE); ! mf_close(mfp, FALSE); // will also vim_free(mfp->mf_fname) } if (buf != NULL) { *************** *** 1743,1752 **** */ int recover_names( ! char_u *fname, /* base for swap file name */ ! int list, /* when TRUE, list the swap file names */ ! int nr, /* when non-zero, return nr'th swap file name */ ! char_u **fname_out) /* result when "nr" > 0 */ { int num_names; char_u *(names[6]); --- 1743,1752 ---- */ int recover_names( ! char_u *fname, // base for swap file name ! int list, // when TRUE, list the swap file names ! int nr, // when non-zero, return nr'th swap file name ! char_u **fname_out) // result when "nr" > 0 { int num_names; char_u *(names[6]); *************** *** 1766,1773 **** if (fname != NULL) { #ifdef HAVE_READLINK ! /* Expand symlink in the file name, because the swap file is created ! * with the actual file instead of with the symlink. */ if (resolve_symlink(fname, fname_buf) == OK) fname_res = fname_buf; else --- 1766,1773 ---- if (fname != NULL) { #ifdef HAVE_READLINK ! // Expand symlink in the file name, because the swap file is created ! // with the actual file instead of with the symlink. if (resolve_symlink(fname, fname_buf) == OK) fname_res = fname_buf; else *************** *** 1777,1783 **** if (list) { ! /* use msg() to start the scrolling properly */ msg(_("Swap files found:")); msg_putchar('\n'); } --- 1777,1783 ---- if (list) { ! // use msg() to start the scrolling properly msg(_("Swap files found:")); msg_putchar('\n'); } *************** *** 1797,1803 **** */ (void)copy_option_part(&dirp, dir_name, 31000, ","); ! if (dir_name[0] == '.' && dir_name[1] == NUL) /* check current dir */ { if (fname == NULL) { --- 1797,1803 ---- */ (void)copy_option_part(&dirp, dir_name, 31000, ","); ! if (dir_name[0] == '.' && dir_name[1] == NUL) // check current dir { if (fname == NULL) { *************** *** 1807,1814 **** names[0] = vim_strsave((char_u *)"*.sw?"); #endif #if defined(UNIX) || defined(MSWIN) ! /* For Unix names starting with a dot are special. MS-Windows ! * supports this too, on some file systems. */ names[1] = vim_strsave((char_u *)".*.sw?"); names[2] = vim_strsave((char_u *)".sw?"); num_names = 3; --- 1807,1814 ---- names[0] = vim_strsave((char_u *)"*.sw?"); #endif #if defined(UNIX) || defined(MSWIN) ! // For Unix names starting with a dot are special. MS-Windows ! // supports this too, on some file systems. names[1] = vim_strsave((char_u *)".*.sw?"); names[2] = vim_strsave((char_u *)".sw?"); num_names = 3; *************** *** 1824,1830 **** else num_names = recov_file_names(names, fname_res, TRUE); } ! else /* check directory dir_name */ { if (fname == NULL) { --- 1824,1830 ---- else num_names = recov_file_names(names, fname_res, TRUE); } ! else // check directory dir_name { if (fname == NULL) { *************** *** 1834,1841 **** names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE); #endif #if defined(UNIX) || defined(MSWIN) ! /* For Unix names starting with a dot are special. MS-Windows ! * supports this too, on some file systems. */ names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE); names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE); num_names = 3; --- 1834,1841 ---- names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE); #endif #if defined(UNIX) || defined(MSWIN) ! // For Unix names starting with a dot are special. MS-Windows ! // supports this too, on some file systems. names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE); names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE); num_names = 3; *************** *** 1856,1862 **** p = dir_name + len; if (after_pathsep(dir_name, p) && len > 1 && p[-1] == p[-2]) { ! /* Ends with '//', Use Full path for swap name */ tail = make_percent_swname(dir_name, fname_res); } else --- 1856,1862 ---- p = dir_name + len; if (after_pathsep(dir_name, p) && len > 1 && p[-1] == p[-2]) { ! // Ends with '//', Use Full path for swap name tail = make_percent_swname(dir_name, fname_res); } else *************** *** 1953,1959 **** { *fname_out = vim_strsave( files[nr - 1 + num_files - file_count]); ! dirp = (char_u *)""; /* stop searching */ } } else if (list) --- 1953,1959 ---- { *fname_out = vim_strsave( files[nr - 1 + num_files - file_count]); ! dirp = (char_u *)""; // stop searching } } else if (list) *************** *** 1976,1982 **** { for (i = 0; i < num_files; ++i) { ! /* print the swap file name */ msg_outnum((long)++file_count); msg_puts(". "); msg_puts((char *)gettail(files[i])); --- 1976,1982 ---- { for (i = 0; i < num_files; ++i) { ! // print the swap file name msg_outnum((long)++file_count); msg_puts(". "); msg_puts((char *)gettail(files[i])); *************** *** 2057,2063 **** dict_add_string(d, "error", (char_u *)"Magic number mismatch"); else { ! /* we have swap information */ dict_add_string_len(d, "version", b0.b0_version, 10); dict_add_string_len(d, "user", b0.b0_uname, B0_UNAME_SIZE); dict_add_string_len(d, "host", b0.b0_hname, B0_HNAME_SIZE); --- 2057,2063 ---- dict_add_string(d, "error", (char_u *)"Magic number mismatch"); else { ! // we have swap information dict_add_string_len(d, "version", b0.b0_version, 10); dict_add_string_len(d, "user", b0.b0_uname, B0_UNAME_SIZE); dict_add_string_len(d, "host", b0.b0_hname, B0_HNAME_SIZE); *************** *** 2138,2144 **** struct tm *curtime; curtime = vim_localtime(&thetime, &tmval); ! /* MSVC returns NULL for an invalid value of seconds. */ if (curtime == NULL) vim_strncpy((char_u *)buf, (char_u *)_("(Invalid)"), sizeof(buf) - 1); else --- 2138,2144 ---- struct tm *curtime; curtime = vim_localtime(&thetime, &tmval); ! // MSVC returns NULL for an invalid value of seconds. if (curtime == NULL) vim_strncpy((char_u *)buf, (char_u *)_("(Invalid)"), sizeof(buf) - 1); else *************** *** 2373,2384 **** #endif if (names[num_names] == NULL) goto end; ! if (num_names >= 1) /* check if we have the same name twice */ { p = names[num_names - 1]; i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); if (i > 0) ! p += i; /* file name has been expanded to full path */ if (STRCMP(p, names[num_names]) != 0) ++num_names; --- 2373,2384 ---- #endif if (names[num_names] == NULL) goto end; ! if (num_names >= 1) // check if we have the same name twice { p = names[num_names - 1]; i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); if (i > 0) ! p += i; // file name has been expanded to full path if (STRCMP(p, names[num_names]) != 0) ++num_names; *************** *** 2407,2413 **** p = names[num_names]; i = STRLEN(names[num_names]) - STRLEN(names[num_names - 1]); if (i > 0) ! p += i; /* file name has been expanded to full path */ if (STRCMP(names[num_names - 1], p) == 0) vim_free(names[num_names]); else --- 2407,2413 ---- p = names[num_names]; i = STRLEN(names[num_names]) - STRLEN(names[num_names - 1]); if (i > 0) ! p += i; // file name has been expanded to full path if (STRCMP(names[num_names - 1], p) == 0) vim_free(names[num_names]); else *************** *** 2438,2447 **** FOR_ALL_BUFFERS(buf) { if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL) ! continue; /* no file */ ! ml_flush_line(buf); /* flush buffered line */ ! /* flush locked block */ (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); if (bufIsChanged(buf) && check_file && mf_need_trans(buf->b_ml.ml_mfp) && buf->b_ffname != NULL) --- 2438,2447 ---- FOR_ALL_BUFFERS(buf) { if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL) ! continue; // no file ! ml_flush_line(buf); // flush buffered line ! // flush locked block (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); if (bufIsChanged(buf) && check_file && mf_need_trans(buf->b_ml.ml_mfp) && buf->b_ffname != NULL) *************** *** 2456,2469 **** { ml_preserve(buf, FALSE); did_check_timestamps = FALSE; ! need_check_timestamps = TRUE; /* give message later */ } } if (buf->b_ml.ml_mfp->mf_dirty) { (void)mf_sync(buf->b_ml.ml_mfp, (check_char ? MFS_STOP : 0) | (bufIsChanged(buf) ? MFS_FLUSH : 0)); ! if (check_char && ui_char_avail()) /* character available now */ break; } } --- 2456,2469 ---- { ml_preserve(buf, FALSE); did_check_timestamps = FALSE; ! need_check_timestamps = TRUE; // give message later } } if (buf->b_ml.ml_mfp->mf_dirty) { (void)mf_sync(buf->b_ml.ml_mfp, (check_char ? MFS_STOP : 0) | (bufIsChanged(buf) ? MFS_FLUSH : 0)); ! if (check_char && ui_char_avail()) // character available now break; } } *************** *** 2495,2509 **** return; } ! /* We only want to stop when interrupted here, not when interrupted ! * before. */ got_int = FALSE; ! ml_flush_line(buf); /* flush buffered line */ ! (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */ status = mf_sync(mfp, MFS_ALL | MFS_FLUSH); ! /* stack is invalid after mf_sync(.., MFS_ALL) */ buf->b_ml.ml_stack_top = 0; /* --- 2495,2509 ---- return; } ! // We only want to stop when interrupted here, not when interrupted ! // before. got_int = FALSE; ! ml_flush_line(buf); // flush buffered line ! (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush locked block status = mf_sync(mfp, MFS_ALL | MFS_FLUSH); ! // stack is invalid after mf_sync(.., MFS_ALL) buf->b_ml.ml_stack_top = 0; /* *************** *** 2532,2542 **** CHECK(buf->b_ml.ml_locked_low != lnum, "low != lnum"); lnum = buf->b_ml.ml_locked_high + 1; } ! (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */ ! /* sync the updated pointer blocks */ if (mf_sync(mfp, MFS_ALL | MFS_FLUSH) == FAIL) status = FAIL; ! buf->b_ml.ml_stack_top = 0; /* stack is invalid now */ } theend: got_int |= got_int_save; --- 2532,2542 ---- CHECK(buf->b_ml.ml_locked_low != lnum, "low != lnum"); lnum = buf->b_ml.ml_locked_high + 1; } ! (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush locked block ! // sync the updated pointer blocks if (mf_sync(mfp, MFS_ALL | MFS_FLUSH) == FAIL) status = FAIL; ! buf->b_ml.ml_stack_top = 0; // stack is invalid now } theend: got_int |= got_int_save; *************** *** 2607,2624 **** ml_get_buf( buf_T *buf, linenr_T lnum, ! int will_change) /* line will be changed */ { bhdr_T *hp; DATA_BL *dp; static int recursive = 0; ! if (lnum > buf->b_ml.ml_line_count) /* invalid line number */ { if (recursive == 0) { ! /* Avoid giving this message for a recursive call, may happen when ! * the GUI redraws part of the text. */ ++recursive; siemsg(_("E315: ml_get: invalid lnum: %ld"), lnum); --recursive; --- 2607,2624 ---- ml_get_buf( buf_T *buf, linenr_T lnum, ! int will_change) // line will be changed { bhdr_T *hp; DATA_BL *dp; static int recursive = 0; ! if (lnum > buf->b_ml.ml_line_count) // invalid line number { if (recursive == 0) { ! // Avoid giving this message for a recursive call, may happen when ! // the GUI redraws part of the text. ++recursive; siemsg(_("E315: ml_get: invalid lnum: %ld"), lnum); --recursive; *************** *** 2660,2667 **** { if (recursive == 0) { ! /* Avoid giving this message for a recursive call, may happen ! * when the GUI redraws part of the text. */ ++recursive; get_trans_bufname(buf); shorten_dir(NameBuff); --- 2660,2667 ---- { if (recursive == 0) { ! // Avoid giving this message for a recursive call, may happen ! // when the GUI redraws part of the text. ++recursive; get_trans_bufname(buf); shorten_dir(NameBuff); *************** *** 2825,2835 **** buf->b_ml.ml_flags &= ~ML_EMPTY; ! if (lnum == 0) /* got line one instead, correct db_idx */ ! db_idx = -1; /* careful, it is negative! */ else db_idx = lnum - buf->b_ml.ml_locked_low; ! /* get line count before the insertion */ line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low; dp = (DATA_BL *)(hp->bh_data); --- 2825,2835 ---- buf->b_ml.ml_flags &= ~ML_EMPTY; ! if (lnum == 0) // got line one instead, correct db_idx ! db_idx = -1; // careful, it is negative! else db_idx = lnum - buf->b_ml.ml_locked_low; ! // get line count before the insertion line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low; dp = (DATA_BL *)(hp->bh_data); *************** *** 2854,2861 **** if ((hp = ml_find_line(buf, lnum + 1, ML_INSERT)) == NULL) goto theend; ! db_idx = -1; /* careful, it is negative! */ ! /* get line count before the insertion */ line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low; CHECK(buf->b_ml.ml_locked_low != lnum + 1, "locked_low != lnum + 1"); --- 2854,2861 ---- if ((hp = ml_find_line(buf, lnum + 1, ML_INSERT)) == NULL) goto theend; ! db_idx = -1; // careful, it is negative! ! // get line count before the insertion line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low; CHECK(buf->b_ml.ml_locked_low != lnum + 1, "locked_low != lnum + 1"); *************** *** 2864,2870 **** ++buf->b_ml.ml_line_count; ! if ((int)dp->db_free >= space_needed) /* enough room in data block */ { /* * Insert the new line in an existing data block, or in the data block --- 2864,2870 ---- ++buf->b_ml.ml_line_count; ! if ((int)dp->db_free >= space_needed) // enough room in data block { /* * Insert the new line in an existing data block, or in the data block *************** *** 2878,2884 **** * move the text of the lines that follow to the front * adjust the indexes of the lines that follow */ ! if (line_count > db_idx + 1) /* if there are following lines */ { /* * Offset is the start of the previous line. --- 2878,2884 ---- * move the text of the lines that follow to the front * adjust the indexes of the lines that follow */ ! if (line_count > db_idx + 1) // if there are following lines { /* * Offset is the start of the previous line. *************** *** 2913,2919 **** if (!newfile) buf->b_ml.ml_flags |= ML_LOCKED_POS; } ! else /* not enough space in data block */ { long line_count_left, line_count_right; int page_count_left, page_count_right; --- 2913,2919 ---- if (!newfile) buf->b_ml.ml_flags |= ML_LOCKED_POS; } ! else // not enough space in data block { long line_count_left, line_count_right; int page_count_left, page_count_right; *************** *** 2921,2928 **** bhdr_T *hp_right; bhdr_T *hp_new; int lines_moved; ! int data_moved = 0; /* init to shut up gcc */ ! int total_moved = 0; /* init to shut up gcc */ DATA_BL *dp_right, *dp_left; int stack_idx; int in_left; --- 2921,2928 ---- bhdr_T *hp_right; bhdr_T *hp_new; int lines_moved; ! int data_moved = 0; // init to shut up gcc ! int total_moved = 0; // init to shut up gcc DATA_BL *dp_right, *dp_left; int stack_idx; int in_left; *************** *** 2948,2965 **** * also put in the right block. This method is more efficient when * inserting a lot of lines at one place. */ ! if (db_idx < 0) /* left block is new, right block is existing */ { lines_moved = 0; in_left = TRUE; ! /* space_needed does not change */ } ! else /* left block is existing, right block is new */ { lines_moved = line_count - db_idx - 1; if (lines_moved == 0) ! in_left = FALSE; /* put new line in right block */ ! /* space_needed does not change */ else { data_moved = ((dp->db_index[db_idx]) & DB_INDEX_MASK) - --- 2948,2965 ---- * also put in the right block. This method is more efficient when * inserting a lot of lines at one place. */ ! if (db_idx < 0) // left block is new, right block is existing { lines_moved = 0; in_left = TRUE; ! // space_needed does not change } ! else // left block is existing, right block is new { lines_moved = line_count - db_idx - 1; if (lines_moved == 0) ! in_left = FALSE; // put new line in right block ! // space_needed does not change else { data_moved = ((dp->db_index[db_idx]) & DB_INDEX_MASK) - *************** *** 2967,2978 **** total_moved = data_moved + lines_moved * INDEX_SIZE; if ((int)dp->db_free + total_moved >= space_needed) { ! in_left = TRUE; /* put new line in left block */ space_needed = total_moved; } else { ! in_left = FALSE; /* put new line in right block */ space_needed += total_moved; } } --- 2967,2978 ---- total_moved = data_moved + lines_moved * INDEX_SIZE; if ((int)dp->db_free + total_moved >= space_needed) { ! in_left = TRUE; // put new line in left block space_needed = total_moved; } else { ! in_left = FALSE; // put new line in right block space_needed += total_moved; } } *************** *** 2981,2999 **** page_count = ((space_needed + HEADER_SIZE) + page_size - 1) / page_size; if ((hp_new = ml_new_data(mfp, newfile, page_count)) == NULL) { ! /* correct line counts in pointer blocks */ --(buf->b_ml.ml_locked_lineadd); --(buf->b_ml.ml_locked_high); goto theend; } ! if (db_idx < 0) /* left block is new */ { hp_left = hp_new; hp_right = hp; line_count_left = 0; line_count_right = line_count; } ! else /* right block is new */ { hp_left = hp; hp_right = hp_new; --- 2981,2999 ---- page_count = ((space_needed + HEADER_SIZE) + page_size - 1) / page_size; if ((hp_new = ml_new_data(mfp, newfile, page_count)) == NULL) { ! // correct line counts in pointer blocks --(buf->b_ml.ml_locked_lineadd); --(buf->b_ml.ml_locked_high); goto theend; } ! if (db_idx < 0) // left block is new { hp_left = hp_new; hp_right = hp; line_count_left = 0; line_count_right = line_count; } ! else // right block is new { hp_left = hp; hp_right = hp_new; *************** *** 3063,3074 **** ++line_count_left; } ! if (db_idx < 0) /* left block is new */ { lnum_left = lnum + 1; lnum_right = 0; } ! else /* right block is new */ { lnum_left = 0; if (in_left) --- 3063,3074 ---- ++line_count_left; } ! if (db_idx < 0) // left block is new { lnum_left = lnum + 1; lnum_right = 0; } ! else // right block is new { lnum_left = 0; if (in_left) *************** *** 3098,3104 **** */ lineadd = buf->b_ml.ml_locked_lineadd; buf->b_ml.ml_locked_lineadd = 0; ! ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush data block */ /* * update pointer blocks for the new data block --- 3098,3104 ---- */ lineadd = buf->b_ml.ml_locked_lineadd; buf->b_ml.ml_locked_lineadd = 0; ! ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush data block /* * update pointer blocks for the new data block *************** *** 3110,3116 **** pb_idx = ip->ip_index; if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) goto theend; ! pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */ if (pp->pb_id != PTR_ID) { iemsg(_("E317: pointer block id wrong 3")); --- 3110,3116 ---- pb_idx = ip->ip_index; if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) goto theend; ! pp = (PTR_BL *)(hp->bh_data); // must be pointer block if (pp->pb_id != PTR_ID) { iemsg(_("E317: pointer block id wrong 3")); *************** *** 3121,3127 **** * TODO: If the pointer block is full and we are adding at the end * try to insert in front of the next block */ ! /* block not full, add one entry */ if (pp->pb_count < pp->pb_count_max) { if (pb_idx + 1 < (int)pp->pb_count) --- 3121,3127 ---- * TODO: If the pointer block is full and we are adding at the end * try to insert in front of the next block */ ! // block not full, add one entry if (pp->pb_count < pp->pb_count_max) { if (pb_idx + 1 < (int)pp->pb_count) *************** *** 3142,3155 **** pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right; mf_put(mfp, hp, TRUE, FALSE); ! buf->b_ml.ml_stack_top = stack_idx + 1; /* truncate stack */ if (lineadd) { --(buf->b_ml.ml_stack_top); ! /* fix line count for rest of blocks in the stack */ ml_lineadd(buf, lineadd); ! /* fix stack itself */ buf->b_ml.ml_stack[buf->b_ml.ml_stack_top].ip_high += lineadd; ++(buf->b_ml.ml_stack_top); --- 3142,3155 ---- pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right; mf_put(mfp, hp, TRUE, FALSE); ! buf->b_ml.ml_stack_top = stack_idx + 1; // truncate stack if (lineadd) { --(buf->b_ml.ml_stack_top); ! // fix line count for rest of blocks in the stack ml_lineadd(buf, lineadd); ! // fix stack itself buf->b_ml.ml_stack[buf->b_ml.ml_stack_top].ip_high += lineadd; ++(buf->b_ml.ml_stack_top); *************** *** 3160,3166 **** */ break; } ! else /* pointer block full */ { /* * split the pointer block --- 3160,3166 ---- */ break; } ! else // pointer block full { /* * split the pointer block *************** *** 3168,3177 **** * move some of the pointer into the new block * prepare for updating the parent block */ ! for (;;) /* do this twice when splitting block 1 */ { hp_new = ml_new_ptr(mfp); ! if (hp_new == NULL) /* TODO: try to fix tree */ goto theend; pp_new = (PTR_BL *)(hp_new->bh_data); --- 3168,3177 ---- * move some of the pointer into the new block * prepare for updating the parent block */ ! for (;;) // do this twice when splitting block 1 { hp_new = ml_new_ptr(mfp); ! if (hp_new == NULL) // TODO: try to fix tree goto theend; pp_new = (PTR_BL *)(hp_new->bh_data); *************** *** 3190,3201 **** pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count; pp->pb_pointer[0].pe_old_lnum = 1; pp->pb_pointer[0].pe_page_count = 1; ! mf_put(mfp, hp, TRUE, FALSE); /* release block 1 */ ! hp = hp_new; /* new block is to be split */ pp = pp_new; CHECK(stack_idx != 0, _("stack_idx should be 0")); ip->ip_index = 0; ! ++stack_idx; /* do block 1 again later */ } /* * move the pointers after the current one to the new block --- 3190,3201 ---- pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count; pp->pb_pointer[0].pe_old_lnum = 1; pp->pb_pointer[0].pe_page_count = 1; ! mf_put(mfp, hp, TRUE, FALSE); // release block 1 ! hp = hp_new; // new block is to be split pp = pp_new; CHECK(stack_idx != 0, _("stack_idx should be 0")); ip->ip_index = 0; ! ++stack_idx; // do block 1 again later } /* * move the pointers after the current one to the new block *************** *** 3256,3267 **** if (stack_idx < 0) { iemsg(_("E318: Updated too many blocks?")); ! buf->b_ml.ml_stack_top = 0; /* invalidate stack */ } } #ifdef FEAT_BYTEOFF ! /* The line was inserted below 'lnum' */ ml_updatechunk(buf, lnum + 1, (long)len, ML_CHNK_ADDLINE); #endif #ifdef FEAT_NETBEANS_INTG --- 3256,3267 ---- if (stack_idx < 0) { iemsg(_("E318: Updated too many blocks?")); ! buf->b_ml.ml_stack_top = 0; // invalidate stack } } #ifdef FEAT_BYTEOFF ! // The line was inserted below 'lnum' ml_updatechunk(buf, lnum + 1, (long)len, ML_CHNK_ADDLINE); #endif #ifdef FEAT_NETBEANS_INTG *************** *** 3329,3340 **** */ int ml_append( ! linenr_T lnum, /* append after this line (can be 0) */ ! char_u *line, /* text of the new line */ ! colnr_T len, /* length of new line, including NUL, or 0 */ ! int newfile) /* flag, see above */ { ! /* When starting up, we might still need to create the memfile */ if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) return FAIL; return ml_append_flush(curbuf, lnum, line, len, newfile); --- 3329,3340 ---- */ int ml_append( ! linenr_T lnum, // append after this line (can be 0) ! char_u *line, // text of the new line ! colnr_T len, // length of new line, including NUL, or 0 ! int newfile) // flag, see above { ! // When starting up, we might still need to create the memfile if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) return FAIL; return ml_append_flush(curbuf, lnum, line, len, newfile); *************** *** 3348,3357 **** int ml_append_buf( buf_T *buf, ! linenr_T lnum, /* append after this line (can be 0) */ ! char_u *line, /* text of the new line */ ! colnr_T len, /* length of new line, including NUL, or 0 */ ! int newfile) /* flag, see above */ { if (buf->b_ml.ml_mfp == NULL) return FAIL; --- 3348,3357 ---- int ml_append_buf( buf_T *buf, ! linenr_T lnum, // append after this line (can be 0) ! char_u *line, // text of the new line ! colnr_T len, // length of new line, including NUL, or 0 ! int newfile) // flag, see above { if (buf->b_ml.ml_mfp == NULL) return FAIL; *************** *** 3397,3406 **** char_u *line = line_arg; colnr_T len = len_arg; ! if (line == NULL) /* just checking... */ return FAIL; ! /* When starting up, we might still need to create the memfile */ if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) return FAIL; --- 3397,3406 ---- char_u *line = line_arg; colnr_T len = len_arg; ! if (line == NULL) // just checking... return FAIL; ! // When starting up, we might still need to create the memfile if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) return FAIL; *************** *** 3606,3612 **** DATA_BL *dp; PTR_BL *pp; infoptr_T *ip; ! int count; /* number of entries in block */ int idx; int stack_idx; int text_start; --- 3606,3612 ---- DATA_BL *dp; PTR_BL *pp; infoptr_T *ip; ! int count; // number of entries in block int idx; int stack_idx; int text_start; *************** *** 3625,3631 **** /* * If the file becomes empty the last line is replaced by an empty line. */ ! if (buf->b_ml.ml_line_count == 1) /* file becomes empty */ { if (message #ifdef FEAT_NETBEANS_INTG --- 3625,3631 ---- /* * If the file becomes empty the last line is replaced by an empty line. */ ! if (buf->b_ml.ml_line_count == 1) // file becomes empty { if (message #ifdef FEAT_NETBEANS_INTG *************** *** 3634,3640 **** ) set_keep_msg((char_u *)_(no_lines_msg), 0); ! /* FEAT_BYTEOFF already handled in there, don't worry 'bout it below */ i = ml_replace((linenr_T)1, (char_u *)"", TRUE); buf->b_ml.ml_flags |= ML_EMPTY; --- 3634,3640 ---- ) set_keep_msg((char_u *)_(no_lines_msg), 0); ! // FEAT_BYTEOFF already handled in there, don't worry 'bout it below i = ml_replace((linenr_T)1, (char_u *)"", TRUE); buf->b_ml.ml_flags |= ML_EMPTY; *************** *** 3654,3660 **** return FAIL; dp = (DATA_BL *)(hp->bh_data); ! /* compute line count before the delete */ count = (long)(buf->b_ml.ml_locked_high) - (long)(buf->b_ml.ml_locked_low) + 2; idx = lnum - buf->b_ml.ml_locked_low; --- 3654,3660 ---- return FAIL; dp = (DATA_BL *)(hp->bh_data); ! // compute line count before the delete count = (long)(buf->b_ml.ml_locked_high) - (long)(buf->b_ml.ml_locked_low) + 2; idx = lnum - buf->b_ml.ml_locked_low; *************** *** 3662,3668 **** --buf->b_ml.ml_line_count; line_start = ((dp->db_index[idx]) & DB_INDEX_MASK); ! if (idx == 0) /* first line in block, text at the end */ line_size = dp->db_txt_end - line_start; else line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - line_start; --- 3662,3668 ---- --buf->b_ml.ml_line_count; line_start = ((dp->db_index[idx]) & DB_INDEX_MASK); ! if (idx == 0) // first line in block, text at the end line_size = dp->db_txt_end - line_start; else line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - line_start; *************** *** 3697,3714 **** */ if (count == 1) { ! mf_free(mfp, hp); /* free the data block */ buf->b_ml.ml_locked = NULL; for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0; --stack_idx) { ! buf->b_ml.ml_stack_top = 0; /* stack is invalid when failing */ ip = &(buf->b_ml.ml_stack[stack_idx]); idx = ip->ip_index; if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) goto theend; ! pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */ if (pp->pb_id != PTR_ID) { iemsg(_("E317: pointer block id wrong 4")); --- 3697,3714 ---- */ if (count == 1) { ! mf_free(mfp, hp); // free the data block buf->b_ml.ml_locked = NULL; for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0; --stack_idx) { ! buf->b_ml.ml_stack_top = 0; // stack is invalid when failing ip = &(buf->b_ml.ml_stack[stack_idx]); idx = ip->ip_index; if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) goto theend; ! pp = (PTR_BL *)(hp->bh_data); // must be pointer block if (pp->pb_id != PTR_ID) { iemsg(_("E317: pointer block id wrong 4")); *************** *** 3716,3732 **** goto theend; } count = --(pp->pb_count); ! if (count == 0) /* the pointer block becomes empty! */ mf_free(mfp, hp); else { ! if (count != idx) /* move entries after the deleted one */ mch_memmove(&pp->pb_pointer[idx], &pp->pb_pointer[idx + 1], (size_t)(count - idx) * sizeof(PTR_EN)); mf_put(mfp, hp, TRUE, FALSE); ! buf->b_ml.ml_stack_top = stack_idx; /* truncate stack */ ! /* fix line count for rest of blocks in the stack */ if (buf->b_ml.ml_locked_lineadd != 0) { ml_lineadd(buf, buf->b_ml.ml_locked_lineadd); --- 3716,3732 ---- goto theend; } count = --(pp->pb_count); ! if (count == 0) // the pointer block becomes empty! mf_free(mfp, hp); else { ! if (count != idx) // move entries after the deleted one mch_memmove(&pp->pb_pointer[idx], &pp->pb_pointer[idx + 1], (size_t)(count - idx) * sizeof(PTR_EN)); mf_put(mfp, hp, TRUE, FALSE); ! buf->b_ml.ml_stack_top = stack_idx; // truncate stack ! // fix line count for rest of blocks in the stack if (buf->b_ml.ml_locked_lineadd != 0) { ml_lineadd(buf, buf->b_ml.ml_locked_lineadd); *************** *** 3794,3803 **** { bhdr_T *hp; DATA_BL *dp; ! /* invalid line number */ if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count || curbuf->b_ml.ml_mfp == NULL) ! return; /* give error message? */ if (lowest_marked == 0 || lowest_marked > lnum) lowest_marked = lnum; --- 3794,3803 ---- { bhdr_T *hp; DATA_BL *dp; ! // invalid line number if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count || curbuf->b_ml.ml_mfp == NULL) ! return; // give error message? if (lowest_marked == 0 || lowest_marked > lnum) lowest_marked = lnum; *************** *** 3808,3814 **** * This also releases any locked block. */ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) ! return; /* give error message? */ dp = (DATA_BL *)(hp->bh_data); dp->db_index[lnum - curbuf->b_ml.ml_locked_low] |= DB_MARKED; --- 3808,3814 ---- * This also releases any locked block. */ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) ! return; // give error message? dp = (DATA_BL *)(hp->bh_data); dp->db_index[lnum - curbuf->b_ml.ml_locked_low] |= DB_MARKED; *************** *** 3841,3847 **** * block This also releases any locked block. */ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) ! return (linenr_T)0; /* give error message? */ dp = (DATA_BL *)(hp->bh_data); --- 3841,3847 ---- * block This also releases any locked block. */ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) ! return (linenr_T)0; // give error message? dp = (DATA_BL *)(hp->bh_data); *************** *** 3870,3876 **** linenr_T lnum; int i; ! if (curbuf->b_ml.ml_mfp == NULL) /* nothing to do */ return; /* --- 3870,3876 ---- linenr_T lnum; int i; ! if (curbuf->b_ml.ml_mfp == NULL) // nothing to do return; /* *************** *** 3884,3890 **** * block and releases any locked block. */ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) ! return; /* give error message? */ dp = (DATA_BL *)(hp->bh_data); --- 3884,3890 ---- * block and releases any locked block. */ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) ! return; // give error message? dp = (DATA_BL *)(hp->bh_data); *************** *** 3922,3933 **** static int entered = FALSE; if (buf->b_ml.ml_line_lnum == 0 || buf->b_ml.ml_mfp == NULL) ! return; /* nothing to do */ if (buf->b_ml.ml_flags & ML_LINE_DIRTY) { ! /* This code doesn't work recursively, but Netbeans may call back here ! * when obtaining the cursor position. */ if (entered) return; entered = TRUE; --- 3922,3933 ---- static int entered = FALSE; if (buf->b_ml.ml_line_lnum == 0 || buf->b_ml.ml_mfp == NULL) ! return; // nothing to do if (buf->b_ml.ml_flags & ML_LINE_DIRTY) { ! // This code doesn't work recursively, but Netbeans may call back here ! // when obtaining the cursor position. if (entered) return; entered = TRUE; *************** *** 3944,3985 **** idx = lnum - buf->b_ml.ml_locked_low; start = ((dp->db_index[idx]) & DB_INDEX_MASK); old_line = (char_u *)dp + start; ! if (idx == 0) /* line is last in block */ old_len = dp->db_txt_end - start; ! else /* text of previous line follows */ old_len = (dp->db_index[idx - 1] & DB_INDEX_MASK) - start; new_len = buf->b_ml.ml_line_len; ! extra = new_len - old_len; /* negative if lines gets smaller */ /* * if new line fits in data block, replace directly */ if ((int)dp->db_free >= extra) { ! /* if the length changes and there are following lines */ count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; if (extra != 0 && idx < count - 1) { ! /* move text of following lines */ mch_memmove((char *)dp + dp->db_txt_start - extra, (char *)dp + dp->db_txt_start, (size_t)(start - dp->db_txt_start)); ! /* adjust pointers of this and following lines */ for (i = idx + 1; i < count; ++i) dp->db_index[i] -= extra; } dp->db_index[idx] -= extra; ! /* adjust free space */ dp->db_free -= extra; dp->db_txt_start -= extra; ! /* copy new line into the data block */ mch_memmove(old_line - extra, new_line, (size_t)new_len); buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS); #ifdef FEAT_BYTEOFF ! /* The else case is already covered by the insert and delete */ ml_updatechunk(buf, lnum, (long)extra, ML_CHNK_UPDLINE); #endif } --- 3944,3985 ---- idx = lnum - buf->b_ml.ml_locked_low; start = ((dp->db_index[idx]) & DB_INDEX_MASK); old_line = (char_u *)dp + start; ! if (idx == 0) // line is last in block old_len = dp->db_txt_end - start; ! else // text of previous line follows old_len = (dp->db_index[idx - 1] & DB_INDEX_MASK) - start; new_len = buf->b_ml.ml_line_len; ! extra = new_len - old_len; // negative if lines gets smaller /* * if new line fits in data block, replace directly */ if ((int)dp->db_free >= extra) { ! // if the length changes and there are following lines count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; if (extra != 0 && idx < count - 1) { ! // move text of following lines mch_memmove((char *)dp + dp->db_txt_start - extra, (char *)dp + dp->db_txt_start, (size_t)(start - dp->db_txt_start)); ! // adjust pointers of this and following lines for (i = idx + 1; i < count; ++i) dp->db_index[i] -= extra; } dp->db_index[idx] -= extra; ! // adjust free space dp->db_free -= extra; dp->db_txt_start -= extra; ! // copy new line into the data block mch_memmove(old_line - extra, new_line, (size_t)new_len); buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS); #ifdef FEAT_BYTEOFF ! // The else case is already covered by the insert and delete ml_updatechunk(buf, lnum, (long)extra, ML_CHNK_UPDLINE); #endif } *************** *** 3992,3998 **** * that has only one line. * Don't forget to copy the mark! */ ! /* How about handling errors??? */ (void)ml_append_int(buf, lnum, new_line, new_len, FALSE, (dp->db_index[idx] & DB_MARKED)); (void)ml_delete_int(buf, lnum, FALSE); --- 3992,3998 ---- * that has only one line. * Don't forget to copy the mark! */ ! // How about handling errors??? (void)ml_append_int(buf, lnum, new_line, new_len, FALSE, (dp->db_index[idx] & DB_MARKED)); (void)ml_delete_int(buf, lnum, FALSE); *************** *** 4095,4101 **** && buf->b_ml.ml_locked_high >= lnum && !mf_dont_release) { ! /* remember to update pointer blocks and stack later */ if (action == ML_INSERT) { ++(buf->b_ml.ml_locked_lineadd); --- 4095,4101 ---- && buf->b_ml.ml_locked_high >= lnum && !mf_dont_release) { ! // remember to update pointer blocks and stack later if (action == ML_INSERT) { ++(buf->b_ml.ml_locked_lineadd); *************** *** 4121,4135 **** ml_lineadd(buf, buf->b_ml.ml_locked_lineadd); } ! if (action == ML_FLUSH) /* nothing else to do */ return NULL; ! bnum = 1; /* start at the root of the tree */ page_count = 1; low = 1; high = buf->b_ml.ml_line_count; ! if (action == ML_FIND) /* first try stack entries */ { for (top = buf->b_ml.ml_stack_top - 1; top >= 0; --top) { --- 4121,4135 ---- ml_lineadd(buf, buf->b_ml.ml_locked_lineadd); } ! if (action == ML_FLUSH) // nothing else to do return NULL; ! bnum = 1; // start at the root of the tree page_count = 1; low = 1; high = buf->b_ml.ml_line_count; ! if (action == ML_FIND) // first try stack entries { for (top = buf->b_ml.ml_stack_top - 1; top >= 0; --top) { *************** *** 4139,4153 **** bnum = ip->ip_bnum; low = ip->ip_low; high = ip->ip_high; ! buf->b_ml.ml_stack_top = top; /* truncate stack at prev entry */ break; } } if (top < 0) ! buf->b_ml.ml_stack_top = 0; /* not found, start at the root */ } ! else /* ML_DELETE or ML_INSERT */ ! buf->b_ml.ml_stack_top = 0; /* start at the root */ /* * search downwards in the tree until a data block is found --- 4139,4153 ---- bnum = ip->ip_bnum; low = ip->ip_low; high = ip->ip_high; ! buf->b_ml.ml_stack_top = top; // truncate stack at prev entry break; } } if (top < 0) ! buf->b_ml.ml_stack_top = 0; // not found, start at the root } ! else // ML_DELETE or ML_INSERT ! buf->b_ml.ml_stack_top = 0; // start at the root /* * search downwards in the tree until a data block is found *************** *** 4166,4172 **** --high; dp = (DATA_BL *)(hp->bh_data); ! if (dp->db_id == DATA_ID) /* data block */ { buf->b_ml.ml_locked = hp; buf->b_ml.ml_locked_low = low; --- 4166,4172 ---- --high; dp = (DATA_BL *)(hp->bh_data); ! if (dp->db_id == DATA_ID) // data block { buf->b_ml.ml_locked = hp; buf->b_ml.ml_locked_low = low; *************** *** 4176,4195 **** return hp; } ! pp = (PTR_BL *)(dp); /* must be pointer block */ if (pp->pb_id != PTR_ID) { iemsg(_("E317: pointer block id wrong")); goto error_block; } ! if ((top = ml_add_stack(buf)) < 0) /* add new entry to stack */ goto error_block; ip = &(buf->b_ml.ml_stack[top]); ip->ip_bnum = bnum; ip->ip_low = low; ip->ip_high = high; ! ip->ip_index = -1; /* index not known yet */ dirty = FALSE; for (idx = 0; idx < (int)pp->pb_count; ++idx) --- 4176,4195 ---- return hp; } ! pp = (PTR_BL *)(dp); // must be pointer block if (pp->pb_id != PTR_ID) { iemsg(_("E317: pointer block id wrong")); goto error_block; } ! if ((top = ml_add_stack(buf)) < 0) // add new entry to stack goto error_block; ip = &(buf->b_ml.ml_stack[top]); ip->ip_bnum = bnum; ip->ip_low = low; ip->ip_high = high; ! ip->ip_index = -1; // index not known yet dirty = FALSE; for (idx = 0; idx < (int)pp->pb_count; ++idx) *************** *** 4221,4227 **** break; } } ! if (idx >= (int)pp->pb_count) /* past the end: something wrong! */ { if (lnum > buf->b_ml.ml_line_count) siemsg(_("E322: line number out of range: %ld past the end"), --- 4221,4227 ---- break; } } ! if (idx >= (int)pp->pb_count) // past the end: something wrong! { if (lnum > buf->b_ml.ml_line_count) siemsg(_("E322: line number out of range: %ld past the end"), *************** *** 4273,4282 **** top = buf->b_ml.ml_stack_top; ! /* may have to increase the stack size */ if (top == buf->b_ml.ml_stack_size) { ! CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */ newstack = ALLOC_MULT(infoptr_T, buf->b_ml.ml_stack_size + STACK_INCR); if (newstack == NULL) --- 4273,4282 ---- top = buf->b_ml.ml_stack_top; ! // may have to increase the stack size if (top == buf->b_ml.ml_stack_size) { ! CHECK(top > 0, _("Stack size increases")); // more than 5 levels??? newstack = ALLOC_MULT(infoptr_T, buf->b_ml.ml_stack_size + STACK_INCR); if (newstack == NULL) *************** *** 4317,4323 **** ip = &(buf->b_ml.ml_stack[idx]); if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) break; ! pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */ if (pp->pb_id != PTR_ID) { mf_put(mfp, hp, FALSE, FALSE); --- 4317,4323 ---- ip = &(buf->b_ml.ml_stack[idx]); if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) break; ! pp = (PTR_BL *)(hp->bh_data); // must be pointer block if (pp->pb_id != PTR_ID) { mf_put(mfp, hp, FALSE, FALSE); *************** *** 4348,4359 **** if (fname == NULL) return FAIL; ! /* Put the result so far in tmp[], starting with the original name. */ vim_strncpy(tmp, fname, MAXPATHL - 1); for (;;) { ! /* Limit symlink depth to 100, catch recursive loops. */ if (++depth == 100) { semsg(_("E773: Symlink loop for \"%s\""), fname); --- 4348,4359 ---- if (fname == NULL) return FAIL; ! // Put the result so far in tmp[], starting with the original name. vim_strncpy(tmp, fname, MAXPATHL - 1); for (;;) { ! // Limit symlink depth to 100, catch recursive loops. if (++depth == 100) { semsg(_("E773: Symlink loop for \"%s\""), fname); *************** *** 4365,4381 **** { if (errno == EINVAL || errno == ENOENT) { ! /* Found non-symlink or not existing file, stop here. ! * When at the first level use the unmodified name, skip the ! * call to vim_FullName(). */ if (depth == 1) return FAIL; ! /* Use the resolved name in tmp[]. */ break; } ! /* There must be some error reading links, use original name. */ return FAIL; } buf[ret] = NUL; --- 4365,4381 ---- { if (errno == EINVAL || errno == ENOENT) { ! // Found non-symlink or not existing file, stop here. ! // When at the first level use the unmodified name, skip the ! // call to vim_FullName(). if (depth == 1) return FAIL; ! // Use the resolved name in tmp[]. break; } ! // There must be some error reading links, use original name. return FAIL; } buf[ret] = NUL; *************** *** 4430,4436 **** s = dir_name + len; if (after_pathsep(dir_name, s) && len > 1 && s[-1] == s[-2]) ! { /* Ends with '//', Use Full path */ r = NULL; if ((s = make_percent_swname(dir_name, fname)) != NULL) { --- 4430,4436 ---- s = dir_name + len; if (after_pathsep(dir_name, s) && len > 1 && s[-1] == s[-2]) ! { // Ends with '//', Use Full path r = NULL; if ((s = make_percent_swname(dir_name, fname)) != NULL) { *************** *** 4442,4449 **** #endif #ifdef HAVE_READLINK ! /* Expand symlink in the file name, so that we put the swap file with the ! * actual file instead of with the symlink. */ if (resolve_symlink(fname, fname_buf) == OK) fname_res = fname_buf; #endif --- 4442,4449 ---- #endif #ifdef HAVE_READLINK ! // Expand symlink in the file name, so that we put the swap file with the ! // actual file instead of with the symlink. if (resolve_symlink(fname, fname_buf) == OK) fname_res = fname_buf; #endif *************** *** 4457,4465 **** #else ".swp", #endif ! /* Prepend a '.' to the swap file name for the current directory. */ dir_name[0] == '.' && dir_name[1] == NUL); ! if (r == NULL) /* out of memory */ return NULL; s = get_file_in_dir(r, dir_name); --- 4457,4465 ---- #else ".swp", #endif ! // Prepend a '.' to the swap file name for the current directory. dir_name[0] == '.' && dir_name[1] == NUL); ! if (r == NULL) // out of memory return NULL; s = get_file_in_dir(r, dir_name); *************** *** 4482,4488 **** char_u * get_file_in_dir( char_u *fname, ! char_u *dname) /* don't use "dirname", it is a global for Alpha */ { char_u *t; char_u *tail; --- 4482,4488 ---- char_u * get_file_in_dir( char_u *fname, ! char_u *dname) // don't use "dirname", it is a global for Alpha { char_u *t; char_u *tail; *************** *** 4495,4501 **** retval = vim_strsave(fname); else if (dname[0] == '.' && vim_ispathsep(dname[1])) { ! if (tail == fname) /* no path before file name */ retval = concat_fnames(dname + 2, tail, TRUE); else { --- 4495,4501 ---- retval = vim_strsave(fname); else if (dname[0] == '.' && vim_ispathsep(dname[1])) { ! if (tail == fname) // no path before file name retval = concat_fnames(dname + 2, tail, TRUE); else { *************** *** 4503,4509 **** *tail = NUL; t = concat_fnames(fname, dname + 2, TRUE); *tail = save_char; ! if (t == NULL) /* out of memory */ retval = NULL; else { --- 4503,4509 ---- *tail = NUL; t = concat_fnames(fname, dname + 2, TRUE); *tail = save_char; ! if (t == NULL) // out of memory retval = NULL; else { *************** *** 4530,4537 **** */ static void attention_message( ! buf_T *buf, /* buffer being edited */ ! char_u *fname) /* swap file name */ { stat_T st; time_t swap_mtime; --- 4530,4537 ---- */ static void attention_message( ! buf_T *buf, // buffer being edited ! char_u *fname) // swap file name { stat_T st; time_t swap_mtime; *************** *** 4556,4563 **** if (swap_mtime != 0 && st.st_mtime > swap_mtime) msg_puts(_(" NEWER than swap file!\n")); } ! /* Some of these messages are long to allow translation to ! * other languages. */ msg_puts(_("\n(1) Another program may be editing the same file. If this is the case,\n be careful not to end up with two different instances of the same\n file when making changes. Quit, or continue with caution.\n")); msg_puts(_("(2) An edit session for this file crashed.\n")); msg_puts(_(" If this is the case, use \":recover\" or \"vim -r ")); --- 4556,4563 ---- if (swap_mtime != 0 && st.st_mtime > swap_mtime) msg_puts(_(" NEWER than swap file!\n")); } ! // Some of these messages are long to allow translation to ! // other languages. msg_puts(_("\n(1) Another program may be editing the same file. If this is the case,\n be careful not to end up with two different instances of the same\n file when making changes. Quit, or continue with caution.\n")); msg_puts(_("(2) An edit session for this file crashed.\n")); msg_puts(_(" If this is the case, use \":recover\" or \"vim -r ")); *************** *** 4588,4595 **** set_vim_var_string(VV_SWAPNAME, fname, -1); set_vim_var_string(VV_SWAPCHOICE, NULL, -1); ! /* Trigger SwapExists autocommands with set to the file being ! * edited. Disallow changing directory here. */ ++allbuf_lock; apply_autocmds(EVENT_SWAPEXISTS, buf->b_fname, NULL, FALSE, NULL); --allbuf_lock; --- 4588,4595 ---- set_vim_var_string(VV_SWAPNAME, fname, -1); set_vim_var_string(VV_SWAPCHOICE, NULL, -1); ! // Trigger SwapExists autocommands with set to the file being ! // edited. Disallow changing directory here. ++allbuf_lock; apply_autocmds(EVENT_SWAPEXISTS, buf->b_fname, NULL, FALSE, NULL); --allbuf_lock; *************** *** 4624,4631 **** static char_u * findswapname( buf_T *buf, ! char_u **dirp, /* pointer to list of directories */ ! char_u *old_fname) /* don't give warning for this file name */ { char_u *fname; int n; --- 4624,4631 ---- static char_u * findswapname( buf_T *buf, ! char_u **dirp, // pointer to list of directories ! char_u *old_fname) // don't give warning for this file name { char_u *fname; int n; *************** *** 4681,4696 **** /* * we try different names until we find one that does not exist yet */ ! if (dir_name == NULL) /* out of memory */ fname = NULL; else fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name); for (;;) { ! if (fname == NULL) /* must be out of memory */ break; ! if ((n = (int)STRLEN(fname)) == 0) /* safety check */ { VIM_CLEAR(fname); break; --- 4681,4696 ---- /* * we try different names until we find one that does not exist yet */ ! if (dir_name == NULL) // out of memory fname = NULL; else fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name); for (;;) { ! if (fname == NULL) // must be out of memory break; ! if ((n = (int)STRLEN(fname)) == 0) // safety check { VIM_CLEAR(fname); break; *************** *** 4725,4734 **** if (fname2 != NULL) { STRCPY(fname2, fname); ! /* if fname == "xx.xx.swp", fname2 = "xx.xx.swx" ! * if fname == ".xx.swp", fname2 = ".xx.swpx" ! * if fname == "123456789.swp", fname2 = "12345678x.swp" ! */ if (vim_strchr(tail, '.') != NULL) fname2[n - 1] = 'x'; else if (*gettail(fname) == '.') --- 4725,4733 ---- if (fname2 != NULL) { STRCPY(fname2, fname); ! // if fname == "xx.xx.swp", fname2 = "xx.xx.swx" ! // if fname == ".xx.swp", fname2 = ".xx.swpx" ! // if fname == "123456789.swp", fname2 = "12345678x.swp" if (vim_strchr(tail, '.') != NULL) fname2[n - 1] = 'x'; else if (*gettail(fname) == '.') *************** *** 4783,4789 **** vim_free(fname); fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name); ! continue; /* try again with b_shortname set */ } } } --- 4782,4788 ---- vim_free(fname); fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name); ! continue; // try again with b_shortname set } } } *************** *** 4792,4798 **** /* * check if the swapfile already exists */ ! if (mch_getperm(fname) < 0) /* it does not exist */ { #ifdef HAVE_LSTAT stat_T sb; --- 4791,4797 ---- /* * check if the swapfile already exists */ ! if (mch_getperm(fname) < 0) // it does not exist { #ifdef HAVE_LSTAT stat_T sb; *************** *** 4810,4816 **** * but is being used by another program. This happens if you edit * a file twice. */ ! if (fh != (BPTR)NULL) /* can open file, OK */ { Close(fh); mch_remove(fname); --- 4809,4815 ---- * but is being used by another program. This happens if you edit * a file twice. */ ! if (fh != (BPTR)NULL) // can open file, OK { Close(fh); mch_remove(fname); *************** *** 4832,4838 **** /* * get here when file already exists */ ! if (fname[n - 2] == 'w' && fname[n - 1] == 'p') /* first try */ { /* * on MS-DOS compatible filesystems (e.g. messydos) file.doc.swp --- 4831,4837 ---- /* * get here when file already exists */ ! if (fname[n - 2] == 'w' && fname[n - 1] == 'p') // first try { /* * on MS-DOS compatible filesystems (e.g. messydos) file.doc.swp *************** *** 4842,4859 **** * underscores for this file), and try again. If it doesn't we * assume that "file.doc.swp" already exists. */ ! if (!(buf->b_p_sn || buf->b_shortname)) /* not tried yet */ { fname[n - 1] = 'x'; ! r = mch_getperm(fname); /* try "file.swx" */ fname[n - 1] = 'p'; ! if (r >= 0) /* "file.swx" seems to exist */ { buf->b_shortname = TRUE; vim_free(fname); fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name); ! continue; /* try again with '.' replaced with '_' */ } } /* --- 4841,4858 ---- * underscores for this file), and try again. If it doesn't we * assume that "file.doc.swp" already exists. */ ! if (!(buf->b_p_sn || buf->b_shortname)) // not tried yet { fname[n - 1] = 'x'; ! r = mch_getperm(fname); // try "file.swx" fname[n - 1] = 'p'; ! if (r >= 0) // "file.swx" seems to exist { buf->b_shortname = TRUE; vim_free(fname); fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name); ! continue; // try again with '.' replaced with '_' } } /* *************** *** 4891,4899 **** || !same_directory(fname, buf->b_ffname)) { #ifdef CHECK_INODE ! /* Symlinks may point to the same file even ! * when the name differs, need to check the ! * inode too. */ expand_env(b0.b0_fname, NameBuff, MAXPATHL); if (fnamecmp_ino(buf->b_ffname, NameBuff, char_to_long(b0.b0_ino))) --- 4890,4898 ---- || !same_directory(fname, buf->b_ffname)) { #ifdef CHECK_INODE ! // Symlinks may point to the same file even ! // when the name differs, need to check the ! // inode too. expand_env(b0.b0_fname, NameBuff, MAXPATHL); if (fnamecmp_ino(buf->b_ffname, NameBuff, char_to_long(b0.b0_ino))) *************** *** 4921,4928 **** close(fd); } ! /* give the ATTENTION message when there is an old swap file ! * for the current file, and the buffer was not recovered. */ if (differ == FALSE && !(curbuf->b_flags & BF_RECOVERED) && vim_strchr(p_shm, SHM_ATTENTION) == NULL) { --- 4920,4927 ---- close(fd); } ! // give the ATTENTION message when there is an old swap file ! // for the current file, and the buffer was not recovered. if (differ == FALSE && !(curbuf->b_flags & BF_RECOVERED) && vim_strchr(p_shm, SHM_ATTENTION) == NULL) { *************** *** 4931,4940 **** #ifdef CREATE_DUMMY_FILE int did_use_dummy = FALSE; ! /* Avoid getting a warning for the file being created ! * outside of Vim, it was created at the start of this ! * function. Delete the file now, because Vim might exit ! * here if the window is closed. */ if (dummyfd != NULL) { fclose(dummyfd); --- 4930,4939 ---- #ifdef CREATE_DUMMY_FILE int did_use_dummy = FALSE; ! // Avoid getting a warning for the file being created ! // outside of Vim, it was created at the start of this ! // function. Delete the file now, because Vim might exit ! // here if the window is closed. if (dummyfd != NULL) { fclose(dummyfd); *************** *** 5020,5030 **** # ifdef HAVE_PROCESS_STILL_RUNNING if (process_still_running && choice >= 4) ! choice++; /* Skip missing "Delete it" button */ # endif vim_free(name); ! /* pretend screen didn't scroll, need redraw anyway */ msg_scrolled = 0; redraw_all_later(NOT_VALID); } --- 5019,5029 ---- # ifdef HAVE_PROCESS_STILL_RUNNING if (process_still_running && choice >= 4) ! choice++; // Skip missing "Delete it" button # endif vim_free(name); ! // pretend screen didn't scroll, need redraw anyway msg_scrolled = 0; redraw_all_later(NOT_VALID); } *************** *** 5054,5060 **** break; } ! /* If the file was deleted this fname can be used. */ if (mch_getperm(fname) < 0) break; } --- 5053,5059 ---- break; } ! // If the file was deleted this fname can be used. if (mch_getperm(fname) < 0) break; } *************** *** 5062,5073 **** { msg_puts("\n"); if (msg_silent == 0) ! /* call wait_return() later */ need_wait_return = TRUE; } #ifdef CREATE_DUMMY_FILE ! /* Going to try another name, need the dummy file again. */ if (did_use_dummy) dummyfd = mch_fopen((char *)buf_fname, "w"); #endif --- 5061,5072 ---- { msg_puts("\n"); if (msg_silent == 0) ! // call wait_return() later need_wait_return = TRUE; } #ifdef CREATE_DUMMY_FILE ! // Going to try another name, need the dummy file again. if (did_use_dummy) dummyfd = mch_fopen((char *)buf_fname, "w"); #endif *************** *** 5081,5103 **** * If that still isn't enough decrement the last but one char: ".svz" * Can happen when editing many "No Name" buffers. */ ! if (fname[n - 1] == 'a') /* ".s?a" */ { ! if (fname[n - 2] == 'a') /* ".saa": tried enough, give up */ { emsg(_("E326: Too many swap files found")); VIM_CLEAR(fname); break; } ! --fname[n - 2]; /* ".svz", ".suz", etc. */ fname[n - 1] = 'z' + 1; } ! --fname[n - 1]; /* ".swo", ".swn", etc. */ } vim_free(dir_name); #ifdef CREATE_DUMMY_FILE ! if (dummyfd != NULL) /* file has been created temporarily */ { fclose(dummyfd); mch_remove(buf_fname); --- 5080,5102 ---- * If that still isn't enough decrement the last but one char: ".svz" * Can happen when editing many "No Name" buffers. */ ! if (fname[n - 1] == 'a') // ".s?a" { ! if (fname[n - 2] == 'a') // ".saa": tried enough, give up { emsg(_("E326: Too many swap files found")); VIM_CLEAR(fname); break; } ! --fname[n - 2]; // ".svz", ".suz", etc. fname[n - 1] = 'z' + 1; } ! --fname[n - 1]; // ".swo", ".swn", etc. } vim_free(dir_name); #ifdef CREATE_DUMMY_FILE ! if (dummyfd != NULL) // file has been created temporarily { fclose(dummyfd); mch_remove(buf_fname); *************** *** 5171,5187 **** static int fnamecmp_ino( ! char_u *fname_c, /* current file name */ ! char_u *fname_s, /* file name from swap file */ long ino_block0) { stat_T st; ! ino_t ino_c = 0; /* ino of current file */ ! ino_t ino_s; /* ino of file from swap file */ ! char_u buf_c[MAXPATHL]; /* full path of fname_c */ ! char_u buf_s[MAXPATHL]; /* full path of fname_s */ ! int retval_c; /* flag: buf_c valid */ ! int retval_s; /* flag: buf_s valid */ if (mch_stat((char *)fname_c, &st) == 0) ino_c = (ino_t)st.st_ino; --- 5170,5186 ---- static int fnamecmp_ino( ! char_u *fname_c, // current file name ! char_u *fname_s, // file name from swap file long ino_block0) { stat_T st; ! ino_t ino_c = 0; // ino of current file ! ino_t ino_s; // ino of file from swap file ! char_u buf_c[MAXPATHL]; // full path of fname_c ! char_u buf_s[MAXPATHL]; // full path of fname_s ! int retval_c; // flag: buf_c valid ! int retval_s; // flag: buf_s valid if (mch_stat((char *)fname_c, &st) == 0) ino_c = (ino_t)st.st_ino; *************** *** 5217,5223 **** return STRCMP(fname_c, fname_s) != 0; return TRUE; } ! #endif /* CHECK_INODE */ /* * Move a long integer into a four byte character array. --- 5216,5222 ---- return STRCMP(fname_c, fname_s) != 0; return TRUE; } ! #endif // CHECK_INODE /* * Move a long integer into a four byte character array. *************** *** 5315,5328 **** text_start = (char_u *)dp + dp->db_txt_start; text_len = size - dp->db_txt_start; ! /* Copy the header and the text. */ mch_memmove(new_data, dp, head_end - (char_u *)dp); ! /* Encrypt the text. */ crypt_encode(state, text_start, text_len, new_data + dp->db_txt_start); crypt_free_state(state); ! /* Clear the gap. */ if (head_end < text_start) vim_memset(new_data + (head_end - data), 0, text_start - head_end); --- 5314,5327 ---- text_start = (char_u *)dp + dp->db_txt_start; text_len = size - dp->db_txt_start; ! // Copy the header and the text. mch_memmove(new_data, dp, head_end - (char_u *)dp); ! // Encrypt the text. crypt_encode(state, text_start, text_len, new_data + dp->db_txt_start); crypt_free_state(state); ! // Clear the gap. if (head_end < text_start) vim_memset(new_data + (head_end - data), 0, text_start - head_end); *************** *** 5353,5364 **** if (head_end > text_start || dp->db_txt_start > size || dp->db_txt_end > size) ! return; /* data was messed up */ state = ml_crypt_prepare(mfp, offset, TRUE); if (state != NULL) { ! /* Decrypt the text in place. */ crypt_decode_inplace(state, text_start, text_len); crypt_free_state(state); } --- 5352,5363 ---- if (head_end > text_start || dp->db_txt_start > size || dp->db_txt_end > size) ! return; // data was messed up state = ml_crypt_prepare(mfp, offset, TRUE); if (state != NULL) { ! // Decrypt the text in place. crypt_decode_inplace(state, text_start, text_len); crypt_free_state(state); } *************** *** 5380,5386 **** if (reading && mfp->mf_old_key != NULL) { ! /* Reading back blocks with the previous key/method/seed. */ method_nr = mfp->mf_old_cm; key = mfp->mf_old_key; seed = mfp->mf_old_seed; --- 5379,5385 ---- if (reading && mfp->mf_old_key != NULL) { ! // Reading back blocks with the previous key/method/seed. method_nr = mfp->mf_old_cm; key = mfp->mf_old_key; seed = mfp->mf_old_seed; *************** *** 5396,5409 **** if (method_nr == CRYPT_M_ZIP) { ! /* For PKzip: Append the offset to the key, so that we use a different ! * key for every block. */ vim_snprintf((char *)salt, sizeof(salt), "%s%ld", key, (long)offset); return crypt_create(method_nr, salt, NULL, 0, NULL, 0); } ! /* Using blowfish or better: add salt and seed. We use the byte offset ! * of the block for the salt. */ vim_snprintf((char *)salt, sizeof(salt), "%ld", (long)offset); return crypt_create(method_nr, key, salt, (int)STRLEN(salt), seed, MF_SEED_LEN); --- 5395,5408 ---- if (method_nr == CRYPT_M_ZIP) { ! // For PKzip: Append the offset to the key, so that we use a different ! // key for every block. vim_snprintf((char *)salt, sizeof(salt), "%s%ld", key, (long)offset); return crypt_create(method_nr, salt, NULL, 0, NULL, 0); } ! // Using blowfish or better: add salt and seed. We use the byte offset ! // of the block for the salt. vim_snprintf((char *)salt, sizeof(salt), "%ld", (long)offset); return crypt_create(method_nr, key, salt, (int)STRLEN(salt), seed, MF_SEED_LEN); *************** *** 5414,5421 **** #if defined(FEAT_BYTEOFF) || defined(PROTO) ! #define MLCS_MAXL 800 /* max no of lines in chunk */ ! #define MLCS_MINL 400 /* should be half of MLCS_MAXL */ /* * Keep information for finding byte offset of a line, updtype may be one of: --- 5413,5420 ---- #if defined(FEAT_BYTEOFF) || defined(PROTO) ! #define MLCS_MAXL 800 // max no of lines in chunk ! #define MLCS_MINL 400 // should be half of MLCS_MAXL /* * Keep information for finding byte offset of a line, updtype may be one of: *************** *** 5487,5493 **** else if (curix < buf->b_ml.ml_usedchunks - 1 && line >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines) { ! /* Adjust cached curix & curline */ curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines; curix++; } --- 5486,5492 ---- else if (curix < buf->b_ml.ml_usedchunks - 1 && line >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines) { ! // Adjust cached curix & curline curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines; curix++; } *************** *** 5500,5506 **** { curchnk->mlcs_numlines++; ! /* May resize here so we don't have to do it in both cases below */ if (buf->b_ml.ml_usedchunks + 1 >= buf->b_ml.ml_numchunks) { chunksize_T *t_chunksize = buf->b_ml.ml_chunksize; --- 5499,5505 ---- { curchnk->mlcs_numlines++; ! // May resize here so we don't have to do it in both cases below if (buf->b_ml.ml_usedchunks + 1 >= buf->b_ml.ml_numchunks) { chunksize_T *t_chunksize = buf->b_ml.ml_chunksize; *************** *** 5511,5517 **** sizeof(chunksize_T) * buf->b_ml.ml_numchunks); if (buf->b_ml.ml_chunksize == NULL) { ! /* Hmmmm, Give up on offset for this buffer */ vim_free(t_chunksize); buf->b_ml.ml_usedchunks = -1; return; --- 5510,5516 ---- sizeof(chunksize_T) * buf->b_ml.ml_numchunks); if (buf->b_ml.ml_chunksize == NULL) { ! // Hmmmm, Give up on offset for this buffer vim_free(t_chunksize); buf->b_ml.ml_usedchunks = -1; return; *************** *** 5520,5526 **** if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL) { ! int count; /* number of entries in block */ int idx; int end_idx; int text_end; --- 5519,5525 ---- if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL) { ! int count; // number of entries in block int idx; int end_idx; int text_end; *************** *** 5530,5536 **** buf->b_ml.ml_chunksize + curix, (buf->b_ml.ml_usedchunks - curix) * sizeof(chunksize_T)); ! /* Compute length of first half of lines in the split chunk */ size = 0; linecnt = 0; while (curline < buf->b_ml.ml_line_count --- 5529,5535 ---- buf->b_ml.ml_chunksize + curix, (buf->b_ml.ml_usedchunks - curix) * sizeof(chunksize_T)); ! // Compute length of first half of lines in the split chunk size = 0; linecnt = 0; while (curline < buf->b_ml.ml_line_count *************** *** 5573,5579 **** else #endif { ! if (idx == 0)/* first line in block, text at the end */ text_end = dp->db_txt_end; else text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); --- 5572,5578 ---- else #endif { ! if (idx == 0)// first line in block, text at the end text_end = dp->db_txt_end; else text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); *************** *** 5585,5591 **** buf->b_ml.ml_chunksize[curix].mlcs_totalsize = size; buf->b_ml.ml_chunksize[curix + 1].mlcs_totalsize -= size; buf->b_ml.ml_usedchunks++; ! ml_upd_lastbuf = NULL; /* Force recalc of curix & curline */ return; } else if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MINL --- 5584,5590 ---- buf->b_ml.ml_chunksize[curix].mlcs_totalsize = size; buf->b_ml.ml_chunksize[curix + 1].mlcs_totalsize -= size; buf->b_ml.ml_usedchunks++; ! ml_upd_lastbuf = NULL; // Force recalc of curix & curline return; } else if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MINL *************** *** 5632,5638 **** else if (updtype == ML_CHNK_DELLINE) { curchnk->mlcs_numlines--; ! ml_upd_lastbuf = NULL; /* Force recalc of curix & curline */ if (curix < (buf->b_ml.ml_usedchunks - 1) && (curchnk->mlcs_numlines + curchnk[1].mlcs_numlines) <= MLCS_MINL) --- 5631,5637 ---- else if (updtype == ML_CHNK_DELLINE) { curchnk->mlcs_numlines--; ! ml_upd_lastbuf = NULL; // Force recalc of curix & curline if (curix < (buf->b_ml.ml_usedchunks - 1) && (curchnk->mlcs_numlines + curchnk[1].mlcs_numlines) <= MLCS_MINL) *************** *** 5654,5660 **** return; } ! /* Collapse chunks */ curchnk[-1].mlcs_numlines += curchnk->mlcs_numlines; curchnk[-1].mlcs_totalsize += curchnk->mlcs_totalsize; buf->b_ml.ml_usedchunks--; --- 5653,5659 ---- return; } ! // Collapse chunks curchnk[-1].mlcs_numlines += curchnk->mlcs_numlines; curchnk[-1].mlcs_totalsize += curchnk->mlcs_totalsize; buf->b_ml.ml_usedchunks--; *************** *** 5687,5693 **** long size; bhdr_T *hp; DATA_BL *dp; ! int count; /* number of entries in block */ int idx; int start_idx; int text_end; --- 5686,5692 ---- long size; bhdr_T *hp; DATA_BL *dp; ! int count; // number of entries in block int idx; int start_idx; int text_end; *************** *** 5696,5702 **** int ffdos = (get_fileformat(buf) == EOL_DOS); int extra = 0; ! /* take care of cached line first */ ml_flush_line(curbuf); if (buf->b_ml.ml_usedchunks == -1 --- 5695,5701 ---- int ffdos = (get_fileformat(buf) == EOL_DOS); int extra = 0; ! // take care of cached line first ml_flush_line(curbuf); if (buf->b_ml.ml_usedchunks == -1 *************** *** 5709,5715 **** else offset = *offp; if (lnum == 0 && offset <= 0) ! return 1; /* Not a "find offset" and offset 0 _must_ be in line 1 */ /* * Find the last chunk before the one containing our line. Last chunk is * special because it will never qualify --- 5708,5714 ---- else offset = *offp; if (lnum == 0 && offset <= 0) ! return 1; // Not a "find offset" and offset 0 _must_ be in line 1 /* * Find the last chunk before the one containing our line. Last chunk is * special because it will never qualify *************** *** 5739,5749 **** count = (long)(buf->b_ml.ml_locked_high) - (long)(buf->b_ml.ml_locked_low) + 1; start_idx = idx = curline - buf->b_ml.ml_locked_low; ! if (idx == 0)/* first line in block, text at the end */ text_end = dp->db_txt_end; else text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); ! /* Compute index of last line to use in this MEMLINE */ if (lnum != 0) { if (curline + (count - idx) >= lnum) --- 5738,5748 ---- count = (long)(buf->b_ml.ml_locked_high) - (long)(buf->b_ml.ml_locked_low) + 1; start_idx = idx = curline - buf->b_ml.ml_locked_low; ! if (idx == 0)// first line in block, text at the end text_end = dp->db_txt_end; else text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); ! // Compute index of last line to use in this MEMLINE if (lnum != 0) { if (curline + (count - idx) >= lnum) *************** *** 5794,5800 **** - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); curline += idx - start_idx + extra; if (curline > buf->b_ml.ml_line_count) ! return -1; /* exactly one byte beyond the end */ return curline; } curline = buf->b_ml.ml_locked_high + 1; --- 5793,5799 ---- - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); curline += idx - start_idx + extra; if (curline > buf->b_ml.ml_line_count) ! return -1; // exactly one byte beyond the end return curline; } curline = buf->b_ml.ml_locked_high + 1; *************** *** 5802,5813 **** if (lnum != 0) { ! /* Count extra CR characters. */ if (ffdos) size += lnum - 1; ! /* Don't count the last line break if 'noeol' and ('bin' or ! * 'nofixeol'). */ if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol && lnum > buf->b_ml.ml_line_count) size -= ffdos + 1; --- 5801,5812 ---- if (lnum != 0) { ! // Count extra CR characters. if (ffdos) size += lnum - 1; ! // Don't count the last line break if 'noeol' and ('bin' or ! // 'nofixeol'). if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol && lnum > buf->b_ml.ml_line_count) size -= ffdos + 1; *************** *** 5825,5836 **** long boff = cnt; linenr_T lnum; ! ml_flush_line(curbuf); /* cached line may be dirty */ setpcmark(); if (boff) --boff; lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff); ! if (lnum < 1) /* past the end */ { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_curswant = MAXCOL; --- 5824,5835 ---- long boff = cnt; linenr_T lnum; ! ml_flush_line(curbuf); // cached line may be dirty setpcmark(); if (boff) --boff; lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff); ! if (lnum < 1) // past the end { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_curswant = MAXCOL; *************** *** 5845,5851 **** } check_cursor(); ! /* Make sure the cursor is on the first byte of a multi-byte char. */ if (has_mbyte) mb_adjust_cursor(); } --- 5844,5850 ---- } check_cursor(); ! // Make sure the cursor is on the first byte of a multi-byte char. if (has_mbyte) mb_adjust_cursor(); } *** ../vim-8.1.2387/src/menu.c 2019-11-29 23:15:22.116220569 +0100 --- src/menu.c 2019-12-04 21:56:33.864683789 +0100 *************** *** 16,22 **** #if defined(FEAT_MENU) || defined(PROTO) ! #define MENUDEPTH 10 /* maximum depth of menus */ #ifdef FEAT_GUI_MSWIN static int add_menu_path(char_u *, vimmenu_T *, int *, char_u *, int); --- 16,22 ---- #if defined(FEAT_MENU) || defined(PROTO) ! #define MENUDEPTH 10 // maximum depth of menus #ifdef FEAT_GUI_MSWIN static int add_menu_path(char_u *, vimmenu_T *, int *, char_u *, int); *************** *** 56,62 **** static char_u *menu_translate_tab_and_shift(char_u *arg_start); ! /* The character for each menu mode */ static char *menu_mode_chars[] = {"n", "v", "s", "o", "i", "c", "tl", "t"}; static char_u e_notsubmenu[] = N_("E327: Part of menu-item path is not sub-menu"); --- 56,62 ---- static char_u *menu_translate_tab_and_shift(char_u *arg_start); ! // The character for each menu mode static char *menu_mode_chars[] = {"n", "v", "s", "o", "i", "c", "tl", "t"}; static char_u e_notsubmenu[] = N_("E327: Part of menu-item path is not sub-menu"); *************** *** 106,112 **** */ void ex_menu( ! exarg_T *eap) /* Ex command arguments */ { char_u *menu_path; int modes; --- 106,112 ---- */ void ex_menu( ! exarg_T *eap) // Ex command arguments { char_u *menu_path; int modes; *************** *** 126,133 **** # endif #endif int pri_tab[MENUDEPTH + 1]; ! int enable = MAYBE; /* TRUE for "menu enable", FALSE for "menu ! * disable */ #ifdef FEAT_TOOLBAR char_u *icon = NULL; #endif --- 126,133 ---- # endif #endif int pri_tab[MENUDEPTH + 1]; ! int enable = MAYBE; // TRUE for "menu enable", FALSE for "menu ! // disable #ifdef FEAT_TOOLBAR char_u *icon = NULL; #endif *************** *** 161,167 **** } ! /* Locate an optional "icon=filename" argument. */ if (STRNCMP(arg, "icon=", 5) == 0) { arg += 5; --- 161,167 ---- } ! // Locate an optional "icon=filename" argument. if (STRNCMP(arg, "icon=", 5) == 0) { arg += 5; *************** *** 208,214 **** i = 0; while (i < MENUDEPTH) pri_tab[i++] = 500; ! pri_tab[MENUDEPTH] = -1; /* mark end of the table */ /* * Check for "disable" or "enable" argument. --- 208,214 ---- i = 0; while (i < MENUDEPTH) pri_tab[i++] = 500; ! pri_tab[MENUDEPTH] = -1; // mark end of the table /* * Check for "disable" or "enable" argument. *************** *** 301,307 **** root_menu_ptr = get_root_menu(menu_path); if (root_menu_ptr == &curwin->w_winbar) ! /* Assume the window toolbar menu will change. */ redraw_later(NOT_VALID); if (enable != MAYBE) --- 301,307 ---- root_menu_ptr = get_root_menu(menu_path); if (root_menu_ptr == &curwin->w_winbar) ! // Assume the window toolbar menu will change. redraw_later(NOT_VALID); if (enable != MAYBE) *************** *** 311,317 **** * For the PopUp menu, remove a menu for each mode separately. * Careful: menu_nable_recurse() changes menu_path. */ ! if (STRCMP(menu_path, "*") == 0) /* meaning: do all menus */ menu_path = (char_u *)""; if (menu_is_popup(menu_path)) --- 311,317 ---- * For the PopUp menu, remove a menu for each mode separately. * Careful: menu_nable_recurse() changes menu_path. */ ! if (STRCMP(menu_path, "*") == 0) // meaning: do all menus menu_path = (char_u *)""; if (menu_is_popup(menu_path)) *************** *** 335,341 **** /* * Delete menu(s). */ ! if (STRCMP(menu_path, "*") == 0) /* meaning: remove all menus */ menu_path = (char_u *)""; /* --- 335,341 ---- /* * Delete menu(s). */ ! if (STRCMP(menu_path, "*") == 0) // meaning: remove all menus menu_path = (char_u *)""; /* *************** *** 355,361 **** } } ! /* Careful: remove_menu() changes menu_path */ remove_menu(root_menu_ptr, menu_path, modes, FALSE); } else --- 355,361 ---- } } ! // Careful: remove_menu() changes menu_path remove_menu(root_menu_ptr, menu_path, modes, FALSE); } else *************** *** 364,376 **** * Add menu(s). * Replace special key codes. */ ! if (STRICMP(map_to, "") == 0) /* "" means nothing */ { map_to = (char_u *)""; map_buf = NULL; } else if (modes & MENU_TIP_MODE) ! map_buf = NULL; /* Menu tips are plain text. */ else map_to = replace_termcodes(map_to, &map_buf, REPTERM_DO_LT | (special ? REPTERM_SPECIAL : 0), NULL); --- 364,376 ---- * Add menu(s). * Replace special key codes. */ ! if (STRICMP(map_to, "") == 0) // "" means nothing { map_to = (char_u *)""; map_buf = NULL; } else if (modes & MENU_TIP_MODE) ! map_buf = NULL; // Menu tips are plain text. else map_to = replace_termcodes(map_to, &map_buf, REPTERM_DO_LT | (special ? REPTERM_SPECIAL : 0), NULL); *************** *** 397,403 **** p = popup_mode_name(menu_path, i); if (p != NULL) { ! /* Include all modes, to make ":amenu" work */ menuarg.modes = modes; #ifdef FEAT_TOOLBAR menuarg.iconfile = NULL; --- 397,403 ---- p = popup_mode_name(menu_path, i); if (p != NULL) { ! // Include all modes, to make ":amenu" work menuarg.modes = modes; #ifdef FEAT_TOOLBAR menuarg.iconfile = NULL; *************** *** 418,424 **** } #if defined(FEAT_GUI) && !(defined(FEAT_GUI_GTK)) ! /* If the menubar height changed, resize the window */ if (gui.in_use && (gui.menu_height != old_menu_height # if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) --- 418,424 ---- } #if defined(FEAT_GUI) && !(defined(FEAT_GUI_GTK)) ! // If the menubar height changed, resize the window if (gui.in_use && (gui.menu_height != old_menu_height # if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) *************** *** 451,462 **** static int add_menu_path( char_u *menu_path, ! vimmenu_T *menuarg, /* passes modes, iconfile, iconidx, ! icon_builtin, silent[0], noremap[0] */ int *pri_tab, char_u *call_data #ifdef FEAT_GUI_MSWIN ! , int addtearoff /* may add tearoff item */ #endif ) { --- 451,462 ---- static int add_menu_path( char_u *menu_path, ! vimmenu_T *menuarg, // passes modes, iconfile, iconidx, ! // icon_builtin, silent[0], noremap[0] int *pri_tab, char_u *call_data #ifdef FEAT_GUI_MSWIN ! , int addtearoff // may add tearoff item #endif ) { *************** *** 486,492 **** #endif vimmenu_T **root_menu_ptr; ! /* Make a copy so we can stuff around with it, since it could be const */ path_name = vim_strsave(menu_path); if (path_name == NULL) return FAIL; --- 486,492 ---- #endif vimmenu_T **root_menu_ptr; ! // Make a copy so we can stuff around with it, since it could be const path_name = vim_strsave(menu_path); if (path_name == NULL) return FAIL; *************** *** 496,503 **** name = path_name; while (*name) { ! /* Get name of this element in the menu hierarchy, and the simplified ! * name (without mnemonic and accelerator text). */ next_name = menu_name_skip(name); #ifdef FEAT_MULTI_LANG map_to = menutrans_lookup(name, (int)STRLEN(name)); --- 496,503 ---- name = path_name; while (*name) { ! // Get name of this element in the menu hierarchy, and the simplified ! // name (without mnemonic and accelerator text). next_name = menu_name_skip(name); #ifdef FEAT_MULTI_LANG map_to = menutrans_lookup(name, (int)STRLEN(name)); *************** *** 514,525 **** goto erret; if (*dname == NUL) { ! /* Only a mnemonic or accelerator is not valid. */ emsg(_("E792: Empty menu name")); goto erret; } ! /* See if it's already there */ lower_pri = menup; #ifdef FEAT_GUI idx = 0; --- 514,525 ---- goto erret; if (*dname == NUL) { ! // Only a mnemonic or accelerator is not valid. emsg(_("E792: Empty menu name")); goto erret; } ! // See if it's already there lower_pri = menup; #ifdef FEAT_GUI idx = 0; *************** *** 550,557 **** } menup = &menu->next; ! /* Count menus, to find where this one needs to be inserted. ! * Ignore menus that are not in the menubar (PopUp and Toolbar) */ if (parent != NULL || menu_is_menubar(menu->name)) { #ifdef FEAT_GUI --- 550,557 ---- } menup = &menu->next; ! // Count menus, to find where this one needs to be inserted. ! // Ignore menus that are not in the menubar (PopUp and Toolbar) if (parent != NULL || menu_is_menubar(menu->name)) { #ifdef FEAT_GUI *************** *** 582,588 **** goto erret; } ! /* Not already there, so lets add it */ menu = ALLOC_CLEAR_ONE(vimmenu_T); if (menu == NULL) goto erret; --- 582,588 ---- goto erret; } ! // Not already there, so lets add it menu = ALLOC_CLEAR_ONE(vimmenu_T); if (menu == NULL) goto erret; *************** *** 590,596 **** menu->modes = modes; menu->enabled = MENU_ALL_MODES; menu->name = vim_strsave(name); ! /* separate mnemonic and accelerator text from actual menu name */ menu->dname = menu_text(name, &menu->mnemonic, &menu->actext); #ifdef FEAT_MULTI_LANG if (en_name != NULL) --- 590,596 ---- menu->modes = modes; menu->enabled = MENU_ALL_MODES; menu->name = vim_strsave(name); ! // separate mnemonic and accelerator text from actual menu name menu->dname = menu_text(name, &menu->mnemonic, &menu->actext); #ifdef FEAT_MULTI_LANG if (en_name != NULL) *************** *** 607,619 **** menu->priority = pri_tab[pri_idx]; menu->parent = parent; #ifdef FEAT_GUI_MOTIF ! menu->sensitive = TRUE; /* the default */ #endif #ifdef FEAT_BEVAL_TIP menu->tip = NULL; #endif #ifdef FEAT_GUI_ATHENA ! menu->image = None; /* X-Windows definition for NULL*/ #endif /* --- 607,619 ---- menu->priority = pri_tab[pri_idx]; menu->parent = parent; #ifdef FEAT_GUI_MOTIF ! menu->sensitive = TRUE; // the default #endif #ifdef FEAT_BEVAL_TIP menu->tip = NULL; #endif #ifdef FEAT_GUI_ATHENA ! menu->image = None; // X-Windows definition for NULL #endif /* *************** *** 631,637 **** menu->iconfile = vim_strsave(menuarg->iconfile); #endif #if defined(FEAT_GUI_MSWIN) && defined(FEAT_TEAROFF) ! /* the tearoff item must be present in the modes of each item. */ if (parent != NULL && menu_is_tearoff(parent->children->dname)) parent->children->modes |= modes; #endif --- 631,637 ---- menu->iconfile = vim_strsave(menuarg->iconfile); #endif #if defined(FEAT_GUI_MSWIN) && defined(FEAT_TEAROFF) ! // the tearoff item must be present in the modes of each item. if (parent != NULL && menu_is_tearoff(parent->children->dname)) parent->children->modes |= modes; #endif *************** *** 646,652 **** * Also enable a menu when it's created or changed. */ #ifdef FEAT_GUI_MSWIN ! /* If adding a tearbar (addtearoff == FALSE) don't update modes */ if (addtearoff) #endif { --- 646,652 ---- * Also enable a menu when it's created or changed. */ #ifdef FEAT_GUI_MSWIN ! // If adding a tearbar (addtearoff == FALSE) don't update modes if (addtearoff) #endif { *************** *** 663,687 **** if ((old_modes & MENU_ALL_MODES) == 0 && (menu->modes & MENU_ALL_MODES) != 0) { ! if (gui.in_use) /* Otherwise it will be added when GUI starts */ { if (*next_name == NUL) { ! /* Real menu item, not sub-menu */ gui_mch_add_menu_item(menu, new_idx); ! /* Want to update menus now even if mode not changed */ force_menu_update = TRUE; } else { ! /* Sub-menu (not at end of path yet) */ gui_mch_add_menu(menu, new_idx); } } # if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) ! /* When adding a new submenu, may add a tearoff item */ if ( addtearoff && *next_name && vim_strchr(p_go, GO_TEAROFF) != NULL --- 663,687 ---- if ((old_modes & MENU_ALL_MODES) == 0 && (menu->modes & MENU_ALL_MODES) != 0) { ! if (gui.in_use) // Otherwise it will be added when GUI starts { if (*next_name == NUL) { ! // Real menu item, not sub-menu gui_mch_add_menu_item(menu, new_idx); ! // Want to update menus now even if mode not changed force_menu_update = TRUE; } else { ! // Sub-menu (not at end of path yet) gui_mch_add_menu(menu, new_idx); } } # if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) ! // When adding a new submenu, may add a tearoff item if ( addtearoff && *next_name && vim_strchr(p_go, GO_TEAROFF) != NULL *************** *** 721,727 **** } # endif } ! #endif /* FEAT_GUI */ menup = &menu->children; parent = menu; --- 721,727 ---- } # endif } ! #endif // FEAT_GUI menup = &menu->children; parent = menu; *************** *** 748,764 **** #endif p = (call_data == NULL) ? NULL : vim_strsave(call_data); ! /* loop over all modes, may add more than one */ for (i = 0; i < MENU_MODES; ++i) { if (modes & (1 << i)) { ! /* free any old menu */ free_menu_string(menu, i); ! /* For "amenu", may insert an extra character. ! * Don't do this if adding a tearbar (addtearoff == FALSE). ! * Don't do this for "". */ c = 0; d = 0; if (amenu && call_data != NULL && *call_data != NUL --- 748,764 ---- #endif p = (call_data == NULL) ? NULL : vim_strsave(call_data); ! // loop over all modes, may add more than one for (i = 0; i < MENU_MODES; ++i) { if (modes & (1 << i)) { ! // free any old menu free_menu_string(menu, i); ! // For "amenu", may insert an extra character. ! // Don't do this if adding a tearbar (addtearoff == FALSE). ! // Don't do this for "". c = 0; d = 0; if (amenu && call_data != NULL && *call_data != NUL *************** *** 799,805 **** { int len = (int)STRLEN(menu->strings[i]); ! /* Append CTRL-\ CTRL-G to obey 'insertmode'. */ menu->strings[i][len] = Ctrl_BSL; menu->strings[i][len + 1] = Ctrl_G; menu->strings[i][len + 2] = NUL; --- 799,805 ---- { int len = (int)STRLEN(menu->strings[i]); ! // Append CTRL-\ CTRL-G to obey 'insertmode'. menu->strings[i][len] = Ctrl_BSL; menu->strings[i][len + 1] = Ctrl_G; menu->strings[i][len + 2] = NUL; *************** *** 814,820 **** } #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) \ && (defined(FEAT_BEVAL_GUI) || defined(FEAT_GUI_GTK)) ! /* Need to update the menu tip. */ if (modes & MENU_TIP_MODE) gui_mch_menu_set_tip(menu); #endif --- 814,820 ---- } #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) \ && (defined(FEAT_BEVAL_GUI) || defined(FEAT_GUI_GTK)) ! // Need to update the menu tip. if (modes & MENU_TIP_MODE) gui_mch_menu_set_tip(menu); #endif *************** *** 825,832 **** vim_free(path_name); vim_free(dname); ! /* Delete any empty submenu we added before discovering the error. Repeat ! * for higher levels. */ while (parent != NULL && parent->children == NULL) { if (parent->parent == NULL) --- 825,832 ---- vim_free(path_name); vim_free(dname); ! // Delete any empty submenu we added before discovering the error. Repeat ! // for higher levels. while (parent != NULL && parent->children == NULL) { if (parent->parent == NULL) *************** *** 835,841 **** menup = &parent->parent->children; for ( ; *menup != NULL && *menup != parent; menup = &((*menup)->next)) ; ! if (*menup == NULL) /* safety check */ break; parent = parent->parent; free_menu(menup); --- 835,841 ---- menup = &parent->parent->children; for ( ; *menup != NULL && *menup != parent; menup = &((*menup)->next)) ; ! if (*menup == NULL) // safety check break; parent = parent->parent; free_menu(menup); *************** *** 857,868 **** char_u *p; if (menu == NULL) ! return OK; /* Got to bottom of hierarchy */ ! /* Get name of this element in the menu hierarchy */ p = menu_name_skip(name); ! /* Find the menu */ while (menu != NULL) { if (*name == NUL || *name == '*' || menu_name_equal(name, menu)) --- 857,868 ---- char_u *p; if (menu == NULL) ! return OK; // Got to bottom of hierarchy ! // Get name of this element in the menu hierarchy p = menu_name_skip(name); ! // Find the menu while (menu != NULL) { if (*name == NUL || *name == '*' || menu_name_equal(name, menu)) *************** *** 901,907 **** } #ifdef FEAT_GUI ! /* Want to update menus now even if mode not changed */ force_menu_update = TRUE; #endif --- 901,907 ---- } #ifdef FEAT_GUI ! // Want to update menus now even if mode not changed force_menu_update = TRUE; #endif *************** *** 917,935 **** vimmenu_T **menup, char_u *name, int modes, ! int silent) /* don't give error messages */ { vimmenu_T *menu; vimmenu_T *child; char_u *p; if (*menup == NULL) ! return OK; /* Got to bottom of hierarchy */ ! /* Get name of this element in the menu hierarchy */ p = menu_name_skip(name); ! /* Find the menu */ while ((menu = *menup) != NULL) { if (*name == NUL || menu_name_equal(name, menu)) --- 917,935 ---- vimmenu_T **menup, char_u *name, int modes, ! int silent) // don't give error messages { vimmenu_T *menu; vimmenu_T *child; char_u *p; if (*menup == NULL) ! return OK; // Got to bottom of hierarchy ! // Get name of this element in the menu hierarchy p = menu_name_skip(name); ! // Find the menu while ((menu = *menup) != NULL) { if (*name == NUL || menu_name_equal(name, menu)) *************** *** 971,978 **** if (*name != NUL) break; ! /* Remove the menu item for the given mode[s]. If the menu item ! * is no longer valid in ANY mode, delete it */ menu->modes &= ~modes; if (modes & MENU_TIP_MODE) free_menu_string(menu, MENU_INDEX_TIP); --- 971,978 ---- if (*name != NUL) break; ! // Remove the menu item for the given mode[s]. If the menu item ! // is no longer valid in ANY mode, delete it menu->modes &= ~modes; if (modes & MENU_TIP_MODE) free_menu_string(menu, MENU_INDEX_TIP); *************** *** 994,1004 **** } ! /* Recalculate modes for menu based on the new updated children */ menu->modes &= ~modes; #if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) ! if ((s_tearoffs) && (menu->children != NULL)) /* there's a tear bar.. */ ! child = menu->children->next; /* don't count tearoff bar */ else #endif child = menu->children; --- 994,1004 ---- } ! // Recalculate modes for menu based on the new updated children menu->modes &= ~modes; #if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) ! if ((s_tearoffs) && (menu->children != NULL)) // there's a tear bar.. ! child = menu->children->next; // don't count tearoff bar else #endif child = menu->children; *************** *** 1009,1024 **** free_menu_string(menu, MENU_INDEX_TIP); #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) \ && (defined(FEAT_BEVAL_GUI) || defined(FEAT_GUI_GTK)) ! /* Need to update the menu tip. */ if (gui.in_use) gui_mch_menu_set_tip(menu); #endif } if ((menu->modes & MENU_ALL_MODES) == 0) { ! /* The menu item is no longer valid in ANY mode, so delete it */ #if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) ! if (s_tearoffs && menu->children != NULL) /* there's a tear bar.. */ free_menu(&menu->children); #endif *menup = menu; --- 1009,1024 ---- free_menu_string(menu, MENU_INDEX_TIP); #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) \ && (defined(FEAT_BEVAL_GUI) || defined(FEAT_GUI_GTK)) ! // Need to update the menu tip. if (gui.in_use) gui_mch_menu_set_tip(menu); #endif } if ((menu->modes & MENU_ALL_MODES) == 0) { ! // The menu item is no longer valid in ANY mode, so delete it #if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) ! if (s_tearoffs && menu->children != NULL) // there's a tear bar.. free_menu(&menu->children); #endif *menup = menu; *************** *** 1051,1064 **** menu = *menup; #ifdef FEAT_GUI ! /* Free machine specific menu structures (only when already created) */ ! /* Also may rebuild a tearoff'ed menu */ if (gui.in_use) gui_mch_destroy_menu(menu); #endif ! /* Don't change *menup until after calling gui_mch_destroy_menu(). The ! * MacOS code needs the original structure to properly delete the menu. */ *menup = menu->next; vim_free(menu->name); vim_free(menu->dname); --- 1051,1064 ---- menu = *menup; #ifdef FEAT_GUI ! // Free machine specific menu structures (only when already created) ! // Also may rebuild a tearoff'ed menu if (gui.in_use) gui_mch_destroy_menu(menu); #endif ! // Don't change *menup until after calling gui_mch_destroy_menu(). The ! // MacOS code needs the original structure to properly delete the menu. *menup = menu->next; vim_free(menu->name); vim_free(menu->dname); *************** *** 1078,1084 **** vim_free(menu); #ifdef FEAT_GUI ! /* Want to update menus now even if mode not changed */ force_menu_update = TRUE; #endif } --- 1078,1084 ---- vim_free(menu); #ifdef FEAT_GUI ! // Want to update menus now even if mode not changed force_menu_update = TRUE; #endif } *************** *** 1116,1122 **** return FAIL; menu = *get_root_menu(path_name); ! /* First, find the (sub)menu with the given name */ while (*name) { p = menu_name_skip(name); --- 1116,1122 ---- return FAIL; menu = *get_root_menu(path_name); ! // First, find the (sub)menu with the given name while (*name) { p = menu_name_skip(name); *************** *** 1124,1130 **** { if (menu_name_equal(name, menu)) { ! /* Found menu */ if (*p != NUL && menu->children == NULL) { emsg(_(e_notsubmenu)); --- 1124,1130 ---- { if (menu_name_equal(name, menu)) { ! // Found menu if (*p != NUL && menu->children == NULL) { emsg(_(e_notsubmenu)); *************** *** 1153,1160 **** } vim_free(path_name); ! /* Now we have found the matching menu, and we list the mappings */ ! /* Highlight title */ msg_puts_title(_("\n--- Menus ---")); show_menus_recursive(parent, modes, 0); --- 1153,1160 ---- } vim_free(path_name); ! // Now we have found the matching menu, and we list the mappings ! // Highlight title msg_puts_title(_("\n--- Menus ---")); show_menus_recursive(parent, modes, 0); *************** *** 1176,1182 **** if (menu != NULL) { msg_putchar('\n'); ! if (got_int) /* "q" hit for "--more--" */ return; for (i = 0; i < depth; i++) msg_puts(" "); --- 1176,1182 ---- if (menu != NULL) { msg_putchar('\n'); ! if (got_int) // "q" hit for "--more--" return; for (i = 0; i < depth; i++) msg_puts(" "); *************** *** 1185,1191 **** msg_outnum((long)menu->priority); msg_puts(" "); } ! /* Same highlighting as for directories!? */ msg_outtrans_attr(menu->name, HL_ATTR(HLF_D)); } --- 1185,1191 ---- msg_outnum((long)menu->priority); msg_puts(" "); } ! // Same highlighting as for directories!? msg_outtrans_attr(menu->name, HL_ATTR(HLF_D)); } *************** *** 1195,1201 **** if ((menu->modes & modes & (1 << bit)) != 0) { msg_putchar('\n'); ! if (got_int) /* "q" hit for "--more--" */ return; for (i = 0; i < depth + 2; i++) msg_puts(" "); --- 1195,1201 ---- if ((menu->modes & modes & (1 << bit)) != 0) { msg_putchar('\n'); ! if (got_int) // "q" hit for "--more--" return; for (i = 0; i < depth + 2; i++) msg_puts(" "); *************** *** 1231,1237 **** else menu = menu->children; ! /* recursively show all children. Skip PopUp[nvoci]. */ for (; menu != NULL && !got_int; menu = menu->next) if (!menu_is_hidden(menu->dname)) show_menus_recursive(menu, modes, depth + 1); --- 1231,1237 ---- else menu = menu->children; ! // recursively show all children. Skip PopUp[nvoci]. for (; menu != NULL && !got_int; menu = menu->next) if (!menu_is_hidden(menu->dname)) show_menus_recursive(menu, modes, depth + 1); *************** *** 1244,1250 **** static vimmenu_T *expand_menu = NULL; static vimmenu_T *expand_menu_alt = NULL; static int expand_modes = 0x0; ! static int expand_emenu; /* TRUE for ":emenu" command */ /* * Work out what to complete when doing command line completion of menu names. --- 1244,1250 ---- static vimmenu_T *expand_menu = NULL; static vimmenu_T *expand_menu_alt = NULL; static int expand_modes = 0x0; ! static int expand_emenu; // TRUE for ":emenu" command /* * Work out what to complete when doing command line completion of menu names. *************** *** 1267,1273 **** xp->xp_context = EXPAND_UNSUCCESSFUL; ! /* Check for priority numbers, enable and disable */ for (p = arg; *p; ++p) if (!VIM_ISDIGIT(*p) && *p != '.') break; --- 1267,1273 ---- xp->xp_context = EXPAND_UNSUCCESSFUL; ! // Check for priority numbers, enable and disable for (p = arg; *p; ++p) if (!VIM_ISDIGIT(*p) && *p != '.') break; *************** *** 1297,1308 **** after_dot = p + 1; } ! /* ":tearoff" and ":popup" only use menus, not entries */ expand_menus = !((*cmd == 't' && cmd[1] == 'e') || *cmd == 'p'); expand_emenu = (*cmd == 'e'); if (expand_menus && VIM_ISWHITE(*p)) ! return NULL; /* TODO: check for next command? */ ! if (*p == NUL) /* Complete the menu name */ { int try_alt_menu = TRUE; --- 1297,1308 ---- after_dot = p + 1; } ! // ":tearoff" and ":popup" only use menus, not entries expand_menus = !((*cmd == 't' && cmd[1] == 'e') || *cmd == 'p'); expand_emenu = (*cmd == 'e'); if (expand_menus && VIM_ISWHITE(*p)) ! return NULL; // TODO: check for next command? ! if (*p == NUL) // Complete the menu name { int try_alt_menu = TRUE; *************** *** 1331,1337 **** { if (menu_name_equal(name, menu)) { ! /* Found menu */ if ((*p != NUL && menu->children == NULL) || ((menu->modes & expand_modes) == 0x0)) { --- 1331,1337 ---- { if (menu_name_equal(name, menu)) { ! // Found menu if ((*p != NUL && menu->children == NULL) || ((menu->modes & expand_modes) == 0x0)) { *************** *** 1353,1359 **** } if (menu == NULL) { ! /* No menu found with the name we were looking for */ vim_free(path_name); return NULL; } --- 1353,1359 ---- } if (menu == NULL) { ! // No menu found with the name we were looking for vim_free(path_name); return NULL; } *************** *** 1371,1377 **** else expand_menu_alt = NULL; } ! else /* We're in the mapping part */ xp->xp_context = EXPAND_NOTHING; return NULL; } --- 1371,1377 ---- else expand_menu_alt = NULL; } ! else // We're in the mapping part xp->xp_context = EXPAND_NOTHING; return NULL; } *************** *** 1390,1396 **** static int should_advance = FALSE; #endif ! if (idx == 0) /* first call: start at first item */ { menu = expand_menu; did_alt_menu = FALSE; --- 1390,1396 ---- static int should_advance = FALSE; #endif ! if (idx == 0) // first call: start at first item { menu = expand_menu; did_alt_menu = FALSE; *************** *** 1399,1405 **** #endif } ! /* Skip PopUp[nvoci]. */ while (menu != NULL && (menu_is_hidden(menu->dname) || menu_is_separator(menu->dname) || menu_is_tearoff(menu->dname) --- 1399,1405 ---- #endif } ! // Skip PopUp[nvoci]. while (menu != NULL && (menu_is_hidden(menu->dname) || menu_is_separator(menu->dname) || menu_is_tearoff(menu->dname) *************** *** 1413,1419 **** } } ! if (menu == NULL) /* at end of linked list */ return NULL; if (menu->modes & expand_modes) --- 1413,1419 ---- } } ! if (menu == NULL) // at end of linked list return NULL; if (menu->modes & expand_modes) *************** *** 1436,1442 **** if (should_advance) #endif { ! /* Advance to next menu entry. */ menu = menu->next; if (menu == NULL && !did_alt_menu) { --- 1436,1442 ---- if (should_advance) #endif { ! // Advance to next menu entry. menu = menu->next; if (menu == NULL && !did_alt_menu) { *************** *** 1462,1474 **** static vimmenu_T *menu = NULL; static int did_alt_menu = FALSE; #define TBUFFER_LEN 256 ! static char_u tbuffer[TBUFFER_LEN]; /*hack*/ char_u *str; #ifdef FEAT_MULTI_LANG static int should_advance = FALSE; #endif ! if (idx == 0) /* first call: start at first item */ { menu = expand_menu; did_alt_menu = FALSE; --- 1462,1474 ---- static vimmenu_T *menu = NULL; static int did_alt_menu = FALSE; #define TBUFFER_LEN 256 ! static char_u tbuffer[TBUFFER_LEN]; //hack char_u *str; #ifdef FEAT_MULTI_LANG static int should_advance = FALSE; #endif ! if (idx == 0) // first call: start at first item { menu = expand_menu; did_alt_menu = FALSE; *************** *** 1477,1483 **** #endif } ! /* Skip Browse-style entries, popup menus and separators. */ while (menu != NULL && ( menu_is_hidden(menu->dname) || (expand_emenu && menu_is_separator(menu->dname)) --- 1477,1483 ---- #endif } ! // Skip Browse-style entries, popup menus and separators. while (menu != NULL && ( menu_is_hidden(menu->dname) || (expand_emenu && menu_is_separator(menu->dname)) *************** *** 1495,1501 **** } } ! if (menu == NULL) /* at end of linked list */ return NULL; if (menu->modes & expand_modes) --- 1495,1501 ---- } } ! if (menu == NULL) // at end of linked list return NULL; if (menu->modes & expand_modes) *************** *** 1514,1521 **** should_advance = TRUE; } #endif ! /* hack on menu separators: use a 'magic' char for the separator ! * so that '.' in names gets escaped properly */ STRCAT(tbuffer, "\001"); str = tbuffer; } --- 1514,1521 ---- should_advance = TRUE; } #endif ! // hack on menu separators: use a 'magic' char for the separator ! // so that '.' in names gets escaped properly STRCAT(tbuffer, "\001"); str = tbuffer; } *************** *** 1542,1548 **** if (should_advance) #endif { ! /* Advance to next menu entry. */ menu = menu->next; if (menu == NULL && !did_alt_menu) { --- 1542,1548 ---- if (should_advance) #endif { ! // Advance to next menu entry. menu = menu->next; if (menu == NULL && !did_alt_menu) { *************** *** 1621,1627 **** static int get_menu_cmd_modes( char_u *cmd, ! int forceit, /* Was there a "!" after the command? */ int *noremap, int *unmenu) { --- 1621,1627 ---- static int get_menu_cmd_modes( char_u *cmd, ! int forceit, // Was there a "!" after the command? int *noremap, int *unmenu) { *************** *** 1629,1678 **** switch (*cmd++) { ! case 'v': /* vmenu, vunmenu, vnoremenu */ modes = MENU_VISUAL_MODE | MENU_SELECT_MODE; break; ! case 'x': /* xmenu, xunmenu, xnoremenu */ modes = MENU_VISUAL_MODE; break; ! case 's': /* smenu, sunmenu, snoremenu */ modes = MENU_SELECT_MODE; break; ! case 'o': /* omenu */ modes = MENU_OP_PENDING_MODE; break; ! case 'i': /* imenu */ modes = MENU_INSERT_MODE; break; case 't': ! if (*cmd == 'l') /* tlmenu, tlunmenu, tlnoremenu */ { modes = MENU_TERMINAL_MODE; ++cmd; break; } ! modes = MENU_TIP_MODE; /* tmenu */ break; ! case 'c': /* cmenu */ modes = MENU_CMDLINE_MODE; break; ! case 'a': /* amenu */ modes = MENU_INSERT_MODE | MENU_CMDLINE_MODE | MENU_NORMAL_MODE | MENU_VISUAL_MODE | MENU_SELECT_MODE | MENU_OP_PENDING_MODE; break; case 'n': ! if (*cmd != 'o') /* nmenu, not noremenu */ { modes = MENU_NORMAL_MODE; break; } ! /* FALLTHROUGH */ default: --cmd; ! if (forceit) /* menu!! */ modes = MENU_INSERT_MODE | MENU_CMDLINE_MODE; ! else /* menu */ modes = MENU_NORMAL_MODE | MENU_VISUAL_MODE | MENU_SELECT_MODE | MENU_OP_PENDING_MODE; } --- 1629,1678 ---- switch (*cmd++) { ! case 'v': // vmenu, vunmenu, vnoremenu modes = MENU_VISUAL_MODE | MENU_SELECT_MODE; break; ! case 'x': // xmenu, xunmenu, xnoremenu modes = MENU_VISUAL_MODE; break; ! case 's': // smenu, sunmenu, snoremenu modes = MENU_SELECT_MODE; break; ! case 'o': // omenu modes = MENU_OP_PENDING_MODE; break; ! case 'i': // imenu modes = MENU_INSERT_MODE; break; case 't': ! if (*cmd == 'l') // tlmenu, tlunmenu, tlnoremenu { modes = MENU_TERMINAL_MODE; ++cmd; break; } ! modes = MENU_TIP_MODE; // tmenu break; ! case 'c': // cmenu modes = MENU_CMDLINE_MODE; break; ! case 'a': // amenu modes = MENU_INSERT_MODE | MENU_CMDLINE_MODE | MENU_NORMAL_MODE | MENU_VISUAL_MODE | MENU_SELECT_MODE | MENU_OP_PENDING_MODE; break; case 'n': ! if (*cmd != 'o') // nmenu, not noremenu { modes = MENU_NORMAL_MODE; break; } ! // FALLTHROUGH default: --cmd; ! if (forceit) // menu!! modes = MENU_INSERT_MODE | MENU_CMDLINE_MODE; ! else // menu modes = MENU_NORMAL_MODE | MENU_VISUAL_MODE | MENU_SELECT_MODE | MENU_OP_PENDING_MODE; } *************** *** 1761,1767 **** char_u *p; char_u *text; ! /* Locate accelerator text, after the first TAB */ p = vim_strchr(str, TAB); if (p != NULL) { --- 1761,1767 ---- char_u *p; char_u *text; ! // Locate accelerator text, after the first TAB p = vim_strchr(str, TAB); if (p != NULL) { *************** *** 1772,1784 **** else text = vim_strsave(str); ! /* Find mnemonic characters "&a" and reduce "&&" to "&". */ for (p = text; p != NULL; ) { p = vim_strchr(p, '&'); if (p != NULL) { ! if (p[1] == NUL) /* trailing "&" */ break; if (mnemonic != NULL && p[1] != '&') #if !defined(__MVS__) || defined(MOTIF390_MNEMONIC_FIXED) --- 1772,1784 ---- else text = vim_strsave(str); ! // Find mnemonic characters "&a" and reduce "&&" to "&". for (p = text; p != NULL; ) { p = vim_strchr(p, '&'); if (p != NULL) { ! if (p[1] == NUL) // trailing "&" break; if (mnemonic != NULL && p[1] != '&') #if !defined(__MVS__) || defined(MOTIF390_MNEMONIC_FIXED) *************** *** 1901,1907 **** return MENU_INDEX_OP_PENDING; if (State & NORMAL) return MENU_INDEX_NORMAL; ! if (State & LANGMAP) /* must be a "r" command, like Insert mode */ return MENU_INDEX_INSERT; return MENU_INDEX_INVALID; } --- 1901,1907 ---- return MENU_INDEX_OP_PENDING; if (State & NORMAL) return MENU_INDEX_NORMAL; ! if (State & LANGMAP) // must be a "r" command, like Insert mode return MENU_INDEX_INSERT; return MENU_INDEX_INVALID; } *************** *** 1941,1954 **** if (STRNCMP("PopUp", menu->name, 5) == 0 && STRNCMP(menu->name + 5, mode, mode_len) == 0) break; ! /* Only show a popup when it is defined and has entries */ if (menu != NULL && menu->children != NULL) { # if defined(FEAT_GUI) if (gui.in_use) { ! /* Update the menus now, in case the MenuPopup autocommand did ! * anything. */ gui_update_menus(0); gui_mch_show_popupmenu(menu); } --- 1941,1954 ---- if (STRNCMP("PopUp", menu->name, 5) == 0 && STRNCMP(menu->name + 5, mode, mode_len) == 0) break; ! // Only show a popup when it is defined and has entries if (menu != NULL && menu->children != NULL) { # if defined(FEAT_GUI) if (gui.in_use) { ! // Update the menus now, in case the MenuPopup autocommand did ! // anything. gui_update_menus(0); gui_mch_show_popupmenu(menu); } *************** *** 1998,2004 **** while (menu != NULL) { ! /* Don't add a menu when only a tip was defined. */ if (menu->modes & MENU_ALL_MODES) { if (menu->children != NULL) --- 1998,2004 ---- while (menu != NULL) { ! // Don't add a menu when only a tip was defined. if (menu->modes & MENU_ALL_MODES) { if (menu->children != NULL) *************** *** 2033,2043 **** else grey = TRUE; # ifdef FEAT_GUI_ATHENA ! /* Hiding menus doesn't work for Athena, it can cause a crash. */ gui_mch_menu_grey(menu, grey); # else ! /* Never hide a toplevel menu, it may make the menubar resize or ! * disappear. Same problem for ToolBar items. */ if (vim_strchr(p_go, GO_GREY) != NULL || menu->parent == NULL # ifdef FEAT_TOOLBAR || menu_is_toolbar(menu->parent->name) --- 2033,2043 ---- else grey = TRUE; # ifdef FEAT_GUI_ATHENA ! // Hiding menus doesn't work for Athena, it can cause a crash. gui_mch_menu_grey(menu, grey); # else ! // Never hide a toplevel menu, it may make the menubar resize or ! // disappear. Same problem for ToolBar items. if (vim_strchr(p_go, GO_GREY) != NULL || menu->parent == NULL # ifdef FEAT_TOOLBAR || menu_is_toolbar(menu->parent->name) *************** *** 2097,2103 **** return FALSE; } # endif ! #endif /* FEAT_GUI */ #if (defined(FEAT_GUI_MSWIN) && defined(FEAT_TEAROFF)) || defined(PROTO) --- 2097,2103 ---- return FALSE; } # endif ! #endif // FEAT_GUI #if (defined(FEAT_GUI_MSWIN) && defined(FEAT_TEAROFF)) || defined(PROTO) *************** *** 2145,2152 **** { if (menu->children != NULL && menu_is_menubar(menu->name)) { ! /* Add the menu name to the menu path. Insert a backslash before ! * dots (it's used to separate menu names). */ len = (int)STRLEN(pname) + (int)STRLEN(menu->name); for (s = menu->name; *s; ++s) if (*s == '.' || *s == '\\') --- 2145,2152 ---- { if (menu->children != NULL && menu_is_menubar(menu->name)) { ! // Add the menu name to the menu path. Insert a backslash before ! // dots (it's used to separate menu names). len = (int)STRLEN(pname) + (int)STRLEN(menu->name); for (s = menu->name; *s; ++s) if (*s == '.' || *s == '\\') *************** *** 2164,2174 **** } *d = NUL; ! /* check if tearoff already exists */ if (STRCMP(menu->children->name, TEAR_STRING) != 0) { gui_add_tearoff(newpname, pri_tab, pri_idx - 1); ! *d = NUL; /* remove TEAR_STRING */ } STRCAT(newpname, "."); --- 2164,2174 ---- } *d = NUL; ! // check if tearoff already exists if (STRCMP(menu->children->name, TEAR_STRING) != 0) { gui_add_tearoff(newpname, pri_tab, pri_idx - 1); ! *d = NUL; // remove TEAR_STRING } STRCAT(newpname, "."); *************** *** 2204,2210 **** STRCAT(tearpath, "."); STRCAT(tearpath, TEAR_STRING); ! /* Priority of tear-off is always 1 */ t = pri_tab[pri_idx + 1]; pri_tab[pri_idx + 1] = 1; --- 2204,2210 ---- STRCAT(tearpath, "."); STRCAT(tearpath, TEAR_STRING); ! // Priority of tear-off is always 1 t = pri_tab[pri_idx + 1]; pri_tab[pri_idx + 1] = 1; *************** *** 2238,2257 **** { if (menu->children) { ! /* check if tearoff exists */ if (STRCMP(menu->children->name, TEAR_STRING) == 0) { ! /* Disconnect the item and free the memory */ free_menu(&menu->children); } ! if (menu->children != NULL) /* if not the last one */ gui_destroy_tearoffs_recurse(menu->children); } menu = menu->next; } } ! #endif /* FEAT_GUI_MSWIN && FEAT_TEAROFF */ /* * Execute "menu". Use by ":emenu" and the window toolbar. --- 2238,2257 ---- { if (menu->children) { ! // check if tearoff exists if (STRCMP(menu->children->name, TEAR_STRING) == 0) { ! // Disconnect the item and free the memory free_menu(&menu->children); } ! if (menu->children != NULL) // if not the last one gui_destroy_tearoffs_recurse(menu->children); } menu = menu->next; } } ! #endif // FEAT_GUI_MSWIN && FEAT_TEAROFF /* * Execute "menu". Use by ":emenu" and the window toolbar. *************** *** 2266,2272 **** if (idx < 0) { ! /* Use the Insert mode entry when returning to Insert mode. */ if (restart_edit #ifdef FEAT_EVAL && !current_sctx.sc_sid --- 2266,2272 ---- if (idx < 0) { ! // Use the Insert mode entry when returning to Insert mode. if (restart_edit #ifdef FEAT_EVAL && !current_sctx.sc_sid *************** *** 2291,2304 **** idx = MENU_INDEX_VISUAL; ! /* GEDDES: This is not perfect - but it is a ! * quick way of detecting whether we are doing this from a ! * selection - see if the range matches up with the visual ! * select start and end. */ if ((curbuf->b_visual.vi_start.lnum == eap->line1) && (curbuf->b_visual.vi_end.lnum) == eap->line2) { ! /* Set it up for visual mode - equivalent to gv. */ VIsual_mode = curbuf->b_visual.vi_mode; tpos = curbuf->b_visual.vi_end; curwin->w_cursor = curbuf->b_visual.vi_start; --- 2291,2304 ---- idx = MENU_INDEX_VISUAL; ! // GEDDES: This is not perfect - but it is a ! // quick way of detecting whether we are doing this from a ! // selection - see if the range matches up with the visual ! // select start and end. if ((curbuf->b_visual.vi_start.lnum == eap->line1) && (curbuf->b_visual.vi_end.lnum) == eap->line2) { ! // Set it up for visual mode - equivalent to gv. VIsual_mode = curbuf->b_visual.vi_mode; tpos = curbuf->b_visual.vi_end; curwin->w_cursor = curbuf->b_visual.vi_start; *************** *** 2306,2312 **** } else { ! /* Set it up for line-wise visual mode */ VIsual_mode = 'V'; curwin->w_cursor.lnum = eap->line1; curwin->w_cursor.col = 1; --- 2306,2312 ---- } else { ! // Set it up for line-wise visual mode VIsual_mode = 'V'; curwin->w_cursor.lnum = eap->line1; curwin->w_cursor.col = 1; *************** *** 2315,2321 **** tpos.coladd = 0; } ! /* Activate visual mode */ VIsual_active = TRUE; VIsual_reselect = TRUE; check_cursor(); --- 2315,2321 ---- tpos.coladd = 0; } ! // Activate visual mode VIsual_active = TRUE; VIsual_reselect = TRUE; check_cursor(); *************** *** 2324,2346 **** check_cursor(); ! /* Adjust the cursor to make sure it is in the correct pos ! * for exclusive mode */ if (*p_sel == 'e' && gchar_cursor() != NUL) ++curwin->w_cursor.col; } } ! /* For the WinBar menu always use the Normal mode menu. */ if (idx == -1 || eap == NULL) idx = MENU_INDEX_NORMAL; if (idx != MENU_INDEX_INVALID && menu->strings[idx] != NULL && (menu->modes & (1 << idx))) { ! /* When executing a script or function execute the commands right now. ! * Also for the window toolbar. ! * Otherwise put them in the typeahead buffer. */ if (eap == NULL #ifdef FEAT_EVAL || current_sctx.sc_sid != 0 --- 2324,2346 ---- check_cursor(); ! // Adjust the cursor to make sure it is in the correct pos ! // for exclusive mode if (*p_sel == 'e' && gchar_cursor() != NUL) ++curwin->w_cursor.col; } } ! // For the WinBar menu always use the Normal mode menu. if (idx == -1 || eap == NULL) idx = MENU_INDEX_NORMAL; if (idx != MENU_INDEX_INVALID && menu->strings[idx] != NULL && (menu->modes & (1 << idx))) { ! // When executing a script or function execute the commands right now. ! // Also for the window toolbar. ! // Otherwise put them in the typeahead buffer. if (eap == NULL #ifdef FEAT_EVAL || current_sctx.sc_sid != 0 *************** *** 2432,2438 **** name = saved_name; while (*name) { ! /* Find in the menu hierarchy */ p = menu_name_skip(name); while (menu != NULL) --- 2432,2438 ---- name = saved_name; while (*name) { ! // Find in the menu hierarchy p = menu_name_skip(name); while (menu != NULL) *************** *** 2496,2503 **** if (wp != curwin) { ! /* Clicking in the window toolbar of a not-current window. ! * Make that window the current one and save Visual mode. */ save_curwin = curwin; VIsual_active = FALSE; curwin = wp; --- 2496,2503 ---- if (wp != curwin) { ! // Clicking in the window toolbar of a not-current window. ! // Make that window the current one and save Visual mode. save_curwin = curwin; VIsual_active = FALSE; curwin = wp; *************** *** 2547,2553 **** name = saved_name; while (*name) { ! /* find the end of one dot-separated name and put a NUL at the dot */ p = menu_name_skip(name); while (menu != NULL) --- 2547,2553 ---- name = saved_name; while (*name) { ! // find the end of one dot-separated name and put a NUL at the dot p = menu_name_skip(name); while (menu != NULL) *************** *** 2556,2562 **** { if (menu->children == NULL) { ! /* found a menu item instead of a sub-menu */ if (*p == NUL) emsg(_("E336: Menu path must lead to a sub-menu")); else --- 2556,2562 ---- { if (menu->children == NULL) { ! // found a menu item instead of a sub-menu if (*p == NUL) emsg(_("E336: Menu path must lead to a sub-menu")); else *************** *** 2564,2579 **** menu = NULL; goto theend; } ! if (*p == NUL) /* found a full match */ goto theend; break; } menu = menu->next; } ! if (menu == NULL) /* didn't find it */ break; ! /* Found a match, search the sub-menu. */ menu = menu->children; name = p; } --- 2564,2579 ---- menu = NULL; goto theend; } ! if (*p == NUL) // found a full match goto theend; break; } menu = menu->next; } ! if (menu == NULL) // didn't find it break; ! // Found a match, search the sub-menu. menu = menu->children; name = p; } *************** *** 2593,2601 **** typedef struct { ! char_u *from; /* English name */ ! char_u *from_noamp; /* same, without '&' */ ! char_u *to; /* translated name */ } menutrans_T; static garray_T menutrans_ga = {0, 0, 0, 0, NULL}; --- 2593,2601 ---- typedef struct { ! char_u *from; // English name ! char_u *from_noamp; // same, without '&' ! char_u *to; // translated name } menutrans_T; static garray_T menutrans_ga = {0, 0, 0, 0, NULL}; *************** *** 2632,2644 **** } ga_clear(&menutrans_ga); # ifdef FEAT_EVAL ! /* Delete all "menutrans_" global variables. */ del_menutrans_vars(); # endif } else { ! /* ":menutrans from to": add translation */ from = arg; arg = menu_skip_part(arg); to = skipwhite(arg); --- 2632,2644 ---- } ga_clear(&menutrans_ga); # ifdef FEAT_EVAL ! // Delete all "menutrans_" global variables. del_menutrans_vars(); # endif } else { ! // ":menutrans from to": add translation from = arg; arg = menu_skip_part(arg); to = skipwhite(arg); *************** *** 2713,2719 **** if (STRNICMP(name, tp[i].from, len) == 0 && tp[i].from[len] == NUL) return tp[i].to; ! /* Now try again while ignoring '&' characters. */ i = name[len]; name[len] = NUL; dname = menu_text(name, NULL, NULL); --- 2713,2719 ---- if (STRNICMP(name, tp[i].from, len) == 0 && tp[i].from[len] == NUL) return tp[i].to; ! // Now try again while ignoring '&' characters. i = name[len]; name[len] = NUL; dname = menu_text(name, NULL, NULL); *************** *** 2744,2750 **** if (*p == '\\') STRMOVE(p, p + 1); } ! #endif /* FEAT_MULTI_LANG */ /* * Isolate the menu name. --- 2744,2750 ---- if (*p == '\\') STRMOVE(p, p + 1); } ! #endif // FEAT_MULTI_LANG /* * Isolate the menu name. *************** *** 2773,2776 **** return arg; } ! #endif /* FEAT_MENU */ --- 2773,2776 ---- return arg; } ! #endif // FEAT_MENU *** ../vim-8.1.2387/src/version.c 2019-12-04 21:24:49.430632805 +0100 --- src/version.c 2019-12-04 21:57:16.044507689 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 2388, /**/ -- hundred-and-one symptoms of being an internet addict: 185. You order fast food over the Internet /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///