summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-05-10 14:11:52 +0200
committerBram Moolenaar <Bram@vim.org>2018-05-10 14:11:52 +0200
commit69e056915c4145b7b64c60963797692a5b293561 (patch)
treebcbc5410e82d04c07301b621946199c673f037c6
parent39de95257714b76ccd845d081cff57830a79b488 (diff)
patch 8.0.1807: function to set terminal name is too longv8.0.1807
Problem: Function to set terminal name is too long. Solution: Refactor the function. Fix typo in test.
-rw-r--r--src/term.c285
-rw-r--r--src/testdir/test_options.vim4
-rw-r--r--src/version.c2
3 files changed, 151 insertions, 140 deletions
diff --git a/src/term.c b/src/term.c
index 49dee03013..37caf2b26c 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1544,6 +1544,150 @@ static char *(key_names[]) =
};
#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,42 +1739,7 @@ set_termname(char_u *term)
*/
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
@@ -1638,81 +1747,13 @@ set_termname(char_u *term)
*/
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 */
+ get_term_entries(&height, &width);
}
}
else /* try == 0 || try == 2 */
@@ -1748,31 +1789,8 @@ set_termname(char_u *term)
if (termcap_cleared) /* found in external termcap */
break;
#endif
+ report_term_error(error_msg, term);
- 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)
{
@@ -1781,16 +1799,7 @@ set_termname(char_u *term)
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);
- }
+ report_default_term(term);
set_string_option_direct((char_u *)"term", -1, term,
OPT_FREE, 0);
display_errors();
diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim
index 0f2908fcb3..8fa5f8b7bf 100644
--- a/src/testdir/test_options.vim
+++ b/src/testdir/test_options.vim
@@ -284,7 +284,7 @@ func Test_set_ttytype()
" in travis on some builds. Why? Catch both for now
try
set ttytype=
- call assert_report('set ttype= did not fail')
+ call assert_report('set ttytype= did not fail')
catch /E529\|E522/
endtry
@@ -292,7 +292,7 @@ func Test_set_ttytype()
" 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')
+ call assert_report('set ttytype=xxx did not fail')
catch /E522\|E437/
endtry
diff --git a/src/version.c b/src/version.c
index 5ebf701848..147f4ed077 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1807,
+/**/
1806,
/**/
1805,