To: vim_dev@googlegroups.com Subject: Patch 8.0.1807 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1807 Problem: Function to set terminal name is too long. Solution: Refactor the function. Fix typo in test. Files: src/term.c, src/testdir/test_options.vim *** ../vim-8.0.1806/src/term.c 2018-05-05 14:29:02.421738251 +0200 --- src/term.c 2018-05-10 14:04:24.041744391 +0200 *************** *** 1544,1549 **** --- 1544,1693 ---- }; #endif + static void + get_term_entries(int *height, int *width) + { + static struct { + enum SpecialKey dest; /* index in term_strings[] */ + char *name; /* termcap name for string */ + } string_names[] = + { {KS_CE, "ce"}, {KS_AL, "al"}, {KS_CAL,"AL"}, + {KS_DL, "dl"}, {KS_CDL,"DL"}, {KS_CS, "cs"}, + {KS_CL, "cl"}, {KS_CD, "cd"}, + {KS_VI, "vi"}, {KS_VE, "ve"}, {KS_MB, "mb"}, + {KS_ME, "me"}, {KS_MR, "mr"}, + {KS_MD, "md"}, {KS_SE, "se"}, {KS_SO, "so"}, + {KS_CZH,"ZH"}, {KS_CZR,"ZR"}, {KS_UE, "ue"}, + {KS_US, "us"}, {KS_UCE, "Ce"}, {KS_UCS, "Cs"}, + {KS_STE,"Te"}, {KS_STS,"Ts"}, + {KS_CM, "cm"}, {KS_SR, "sr"}, + {KS_CRI,"RI"}, {KS_VB, "vb"}, {KS_KS, "ks"}, + {KS_KE, "ke"}, {KS_TI, "ti"}, {KS_TE, "te"}, + {KS_BC, "bc"}, {KS_CSB,"Sb"}, {KS_CSF,"Sf"}, + {KS_CAB,"AB"}, {KS_CAF,"AF"}, {KS_LE, "le"}, + {KS_ND, "nd"}, {KS_OP, "op"}, {KS_CRV, "RV"}, + {KS_VS, "vs"}, {KS_CVS, "VS"}, + {KS_CIS, "IS"}, {KS_CIE, "IE"}, + {KS_CSC, "SC"}, {KS_CEC, "EC"}, + {KS_TS, "ts"}, {KS_FS, "fs"}, + {KS_CWP, "WP"}, {KS_CWS, "WS"}, + {KS_CSI, "SI"}, {KS_CEI, "EI"}, + {KS_U7, "u7"}, {KS_RFG, "RF"}, {KS_RBG, "RB"}, + {KS_8F, "8f"}, {KS_8B, "8b"}, + {KS_CBE, "BE"}, {KS_CBD, "BD"}, + {KS_CPS, "PS"}, {KS_CPE, "PE"}, + {(enum SpecialKey)0, NULL} + }; + int i; + char_u *p; + static char_u tstrbuf[TBUFSZ]; + char_u *tp = tstrbuf; + + /* + * get output strings + */ + for (i = 0; string_names[i].name != NULL; ++i) + { + if (TERM_STR(string_names[i].dest) == NULL + || TERM_STR(string_names[i].dest) == empty_option) + TERM_STR(string_names[i].dest) = TGETSTR(string_names[i].name, &tp); + } + + /* tgetflag() returns 1 if the flag is present, 0 if not and + * possibly -1 if the flag doesn't exist. */ + if ((T_MS == NULL || T_MS == empty_option) && tgetflag("ms") > 0) + T_MS = (char_u *)"y"; + if ((T_XS == NULL || T_XS == empty_option) && tgetflag("xs") > 0) + T_XS = (char_u *)"y"; + if ((T_XN == NULL || T_XN == empty_option) && tgetflag("xn") > 0) + T_XN = (char_u *)"y"; + if ((T_DB == NULL || T_DB == empty_option) && tgetflag("db") > 0) + T_DB = (char_u *)"y"; + if ((T_DA == NULL || T_DA == empty_option) && tgetflag("da") > 0) + T_DA = (char_u *)"y"; + if ((T_UT == NULL || T_UT == empty_option) && tgetflag("ut") > 0) + T_UT = (char_u *)"y"; + + /* + * get key codes + */ + for (i = 0; key_names[i] != NULL; ++i) + if (find_termcode((char_u *)key_names[i]) == NULL) + { + p = TGETSTR(key_names[i], &tp); + /* if cursor-left == backspace, ignore it (televideo 925) */ + if (p != NULL + && (*p != Ctrl_H + || key_names[i][0] != 'k' + || key_names[i][1] != 'l')) + add_termcode((char_u *)key_names[i], p, FALSE); + } + + if (*height == 0) + *height = tgetnum("li"); + if (*width == 0) + *width = tgetnum("co"); + + /* + * Get number of colors (if not done already). + */ + if (TERM_STR(KS_CCO) == NULL || TERM_STR(KS_CCO) == empty_option) + set_color_count(tgetnum("Co")); + + # ifndef hpux + BC = (char *)TGETSTR("bc", &tp); + UP = (char *)TGETSTR("up", &tp); + p = TGETSTR("pc", &tp); + if (p) + PC = *p; + # endif + } + + static void + report_term_error(char_u *error_msg, char_u *term) + { + struct builtin_term *termp; + + mch_errmsg("\r\n"); + if (error_msg != NULL) + { + mch_errmsg((char *)error_msg); + mch_errmsg("\r\n"); + } + mch_errmsg("'"); + mch_errmsg((char *)term); + mch_errmsg(_("' not known. Available builtin terminals are:")); + mch_errmsg("\r\n"); + for (termp = &(builtin_termcaps[0]); termp->bt_string != NULL; ++termp) + { + if (termp->bt_entry == (int)KS_NAME) + { + #ifdef HAVE_TGETENT + mch_errmsg(" builtin_"); + #else + mch_errmsg(" "); + #endif + mch_errmsg(termp->bt_string); + mch_errmsg("\r\n"); + } + } + } + + static void + report_default_term(char_u *term) + { + mch_errmsg(_("defaulting to '")); + mch_errmsg((char *)term); + mch_errmsg("'\r\n"); + if (emsg_silent == 0) + { + screen_start(); /* don't know where cursor is now */ + out_flush(); + if (!is_not_a_term()) + ui_delay(2000L, TRUE); + } + } + /* * Set terminal options for terminal "term". * Return OK if terminal 'term' was found in a termcap, FAIL otherwise. *************** *** 1595,1636 **** */ if (try == 1) { - char_u *p; - static char_u tstrbuf[TBUFSZ]; - int i; char_u tbuf[TBUFSZ]; - char_u *tp; - static struct { - enum SpecialKey dest; /* index in term_strings[] */ - char *name; /* termcap name for string */ - } string_names[] = - { {KS_CE, "ce"}, {KS_AL, "al"}, {KS_CAL,"AL"}, - {KS_DL, "dl"}, {KS_CDL,"DL"}, {KS_CS, "cs"}, - {KS_CL, "cl"}, {KS_CD, "cd"}, - {KS_VI, "vi"}, {KS_VE, "ve"}, {KS_MB, "mb"}, - {KS_ME, "me"}, {KS_MR, "mr"}, - {KS_MD, "md"}, {KS_SE, "se"}, {KS_SO, "so"}, - {KS_CZH,"ZH"}, {KS_CZR,"ZR"}, {KS_UE, "ue"}, - {KS_US, "us"}, {KS_UCE, "Ce"}, {KS_UCS, "Cs"}, - {KS_STE,"Te"}, {KS_STS,"Ts"}, - {KS_CM, "cm"}, {KS_SR, "sr"}, - {KS_CRI,"RI"}, {KS_VB, "vb"}, {KS_KS, "ks"}, - {KS_KE, "ke"}, {KS_TI, "ti"}, {KS_TE, "te"}, - {KS_BC, "bc"}, {KS_CSB,"Sb"}, {KS_CSF,"Sf"}, - {KS_CAB,"AB"}, {KS_CAF,"AF"}, {KS_LE, "le"}, - {KS_ND, "nd"}, {KS_OP, "op"}, {KS_CRV, "RV"}, - {KS_VS, "vs"}, {KS_CVS, "VS"}, - {KS_CIS, "IS"}, {KS_CIE, "IE"}, - {KS_CSC, "SC"}, {KS_CEC, "EC"}, - {KS_TS, "ts"}, {KS_FS, "fs"}, - {KS_CWP, "WP"}, {KS_CWS, "WS"}, - {KS_CSI, "SI"}, {KS_CEI, "EI"}, - {KS_U7, "u7"}, {KS_RFG, "RF"}, {KS_RBG, "RB"}, - {KS_8F, "8f"}, {KS_8B, "8b"}, - {KS_CBE, "BE"}, {KS_CBD, "BD"}, - {KS_CPS, "PS"}, {KS_CPE, "PE"}, - {(enum SpecialKey)0, NULL} - }; /* * If the external termcap does not have a matching entry, try the --- 1739,1745 ---- *************** *** 1638,1718 **** */ if ((error_msg = tgetent_error(tbuf, term)) == NULL) { - tp = tstrbuf; if (!termcap_cleared) { clear_termoptions(); /* clear old options */ termcap_cleared = TRUE; } ! /* get output strings */ ! for (i = 0; string_names[i].name != NULL; ++i) ! { ! if (TERM_STR(string_names[i].dest) == NULL ! || TERM_STR(string_names[i].dest) == empty_option) ! TERM_STR(string_names[i].dest) = ! TGETSTR(string_names[i].name, &tp); ! } ! ! /* tgetflag() returns 1 if the flag is present, 0 if not and ! * possibly -1 if the flag doesn't exist. */ ! if ((T_MS == NULL || T_MS == empty_option) ! && tgetflag("ms") > 0) ! T_MS = (char_u *)"y"; ! if ((T_XS == NULL || T_XS == empty_option) ! && tgetflag("xs") > 0) ! T_XS = (char_u *)"y"; ! if ((T_XN == NULL || T_XN == empty_option) ! && tgetflag("xn") > 0) ! T_XN = (char_u *)"y"; ! if ((T_DB == NULL || T_DB == empty_option) ! && tgetflag("db") > 0) ! T_DB = (char_u *)"y"; ! if ((T_DA == NULL || T_DA == empty_option) ! && tgetflag("da") > 0) ! T_DA = (char_u *)"y"; ! if ((T_UT == NULL || T_UT == empty_option) ! && tgetflag("ut") > 0) ! T_UT = (char_u *)"y"; ! ! ! /* ! * get key codes ! */ ! for (i = 0; key_names[i] != NULL; ++i) ! { ! if (find_termcode((char_u *)key_names[i]) == NULL) ! { ! p = TGETSTR(key_names[i], &tp); ! /* if cursor-left == backspace, ignore it (televideo ! * 925) */ ! if (p != NULL ! && (*p != Ctrl_H ! || key_names[i][0] != 'k' ! || key_names[i][1] != 'l')) ! add_termcode((char_u *)key_names[i], p, FALSE); ! } ! } ! ! if (height == 0) ! height = tgetnum("li"); ! if (width == 0) ! width = tgetnum("co"); ! ! /* ! * Get number of colors (if not done already). ! */ ! if (TERM_STR(KS_CCO) == NULL ! || TERM_STR(KS_CCO) == empty_option) ! set_color_count(tgetnum("Co")); ! ! # ifndef hpux ! BC = (char *)TGETSTR("bc", &tp); ! UP = (char *)TGETSTR("up", &tp); ! p = TGETSTR("pc", &tp); ! if (p) ! PC = *p; ! # endif /* hpux */ } } else /* try == 0 || try == 2 */ --- 1747,1759 ---- */ if ((error_msg = tgetent_error(tbuf, term)) == NULL) { if (!termcap_cleared) { clear_termoptions(); /* clear old options */ termcap_cleared = TRUE; } ! get_term_entries(&height, &width); } } else /* try == 0 || try == 2 */ *************** *** 1748,1778 **** if (termcap_cleared) /* found in external termcap */ break; #endif - mch_errmsg("\r\n"); - if (error_msg != NULL) - { - mch_errmsg((char *)error_msg); - mch_errmsg("\r\n"); - } - mch_errmsg("'"); - mch_errmsg((char *)term); - mch_errmsg(_("' not known. Available builtin terminals are:")); - mch_errmsg("\r\n"); - for (termp = &(builtin_termcaps[0]); termp->bt_string != NULL; - ++termp) - { - if (termp->bt_entry == (int)KS_NAME) - { - #ifdef HAVE_TGETENT - mch_errmsg(" builtin_"); - #else - mch_errmsg(" "); - #endif - mch_errmsg(termp->bt_string); - mch_errmsg("\r\n"); - } - } /* when user typed :set term=xxx, quit here */ if (starting != NO_SCREEN) { --- 1789,1796 ---- if (termcap_cleared) /* found in external termcap */ break; #endif + report_term_error(error_msg, term); /* when user typed :set term=xxx, quit here */ if (starting != NO_SCREEN) { *************** *** 1781,1796 **** return FAIL; } term = DEFAULT_TERM; ! mch_errmsg(_("defaulting to '")); ! mch_errmsg((char *)term); ! mch_errmsg("'\r\n"); ! if (emsg_silent == 0) ! { ! screen_start(); /* don't know where cursor is now */ ! out_flush(); ! if (!is_not_a_term()) ! ui_delay(2000L, TRUE); ! } set_string_option_direct((char_u *)"term", -1, term, OPT_FREE, 0); display_errors(); --- 1799,1805 ---- return FAIL; } term = DEFAULT_TERM; ! report_default_term(term); set_string_option_direct((char_u *)"term", -1, term, OPT_FREE, 0); display_errors(); *** ../vim-8.0.1806/src/testdir/test_options.vim 2018-04-12 21:37:28.618561305 +0200 --- src/testdir/test_options.vim 2018-05-10 14:10:24.759966060 +0200 *************** *** 284,290 **** " in travis on some builds. Why? Catch both for now try set ttytype= ! call assert_report('set ttype= did not fail') catch /E529\|E522/ endtry --- 284,290 ---- " in travis on some builds. Why? Catch both for now try set ttytype= ! call assert_report('set ttytype= did not fail') catch /E529\|E522/ endtry *************** *** 292,298 **** " check for failure of finding the entry and for missing 'cm' entry. try set ttytype=xxx ! call assert_report('set ttype=xxx did not fail') catch /E522\|E437/ endtry --- 292,298 ---- " check for failure of finding the entry and for missing 'cm' entry. try set ttytype=xxx ! call assert_report('set ttytype=xxx did not fail') catch /E522\|E437/ endtry *** ../vim-8.0.1806/src/version.c 2018-05-08 22:47:56.646469545 +0200 --- src/version.c 2018-05-10 14:10:51.807998420 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1807, /**/ -- There are 10 kinds of people: Those who understand binary and those who don't. /// 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 ///