Skip to content

Commit 80adaa8

Browse files
committed
patch 9.0.1673: cannot produce a status 418 or 503 message
Problem: Cannot produce a status 418 or 503 message. Solution: Add err_teapot().
1 parent d392a74 commit 80adaa8

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

runtime/doc/builtin.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ digraph_getlist([{listall}]) List get all |digraph|s
154154
digraph_set({chars}, {digraph}) Boolean register |digraph|
155155
digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
156156
echoraw({expr}) none output {expr} as-is
157+
err_teapot() Number produce error 418
157158
empty({expr}) Number |TRUE| if {expr} is empty
158159
environ() Dict return environment variables
159160
escape({string}, {chars}) String escape {chars} in {string} with '\'
@@ -2176,6 +2177,14 @@ echoraw({string}) *echoraw()*
21762177
< Use with care, you can mess up the terminal this way.
21772178

21782179

2180+
err_teapot([{expr}]) *err_teapot()*
2181+
Produce an error with number 418, needed for implementation of
2182+
RFC 2325.
2183+
If {expr} is present and it is TRUE error 503 is given,
2184+
indicating that coffee is temporarily not available.
2185+
If {expr} is present it must be a String.
2186+
2187+
21792188
empty({expr}) *empty()*
21802189
Return the Number 1 if {expr} is empty, zero otherwise.
21812190
- A |List| or |Dictionary| is empty when it does not have any

src/errors.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,8 @@ EXTERN char e_missing_argument_str[]
10371037
INIT(= N_("E417: Missing argument: %s"));
10381038
EXTERN char e_illegal_value_str[]
10391039
INIT(= N_("E418: Illegal value: %s"));
1040+
EXTERN char e_im_a_teapot[]
1041+
INIT(= N_("E418: I'm a teapot"));
10401042
EXTERN char e_fg_color_unknown[]
10411043
INIT(= N_("E419: FG color unknown"));
10421044
EXTERN char e_bg_color_unknown[]
@@ -1270,6 +1272,8 @@ EXTERN char e_is_not_file_or_writable_device[]
12701272
INIT(= N_("is not a file or writable device"));
12711273
EXTERN char e_str_is_not_file_or_writable_device[]
12721274
INIT(= N_("E503: \"%s\" is not a file or writable device"));
1275+
EXTERN char e_coffee_currently_not_available[]
1276+
INIT(= N_("E503: Coffee is currently not available"));
12731277
// E504
12741278
EXTERN char e_is_read_only_cannot_override_W_in_cpoptions[]
12751279
INIT(= N_("is read-only (cannot override: \"W\" in 'cpoptions')"));

src/evalfunc.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static void f_did_filetype(typval_T *argvars, typval_T *rettv);
4545
static void f_echoraw(typval_T *argvars, typval_T *rettv);
4646
static void f_empty(typval_T *argvars, typval_T *rettv);
4747
static void f_environ(typval_T *argvars, typval_T *rettv);
48+
static void f_err_teapot(typval_T *argvars, typval_T *rettv);
4849
static void f_escape(typval_T *argvars, typval_T *rettv);
4950
static void f_eval(typval_T *argvars, typval_T *rettv);
5051
static void f_eventhandler(typval_T *argvars, typval_T *rettv);
@@ -1881,6 +1882,8 @@ static funcentry_T global_functions[] =
18811882
ret_number_bool, f_empty},
18821883
{"environ", 0, 0, 0, NULL,
18831884
ret_dict_string, f_environ},
1885+
{"err_teapot", 0, 1, 0, NULL,
1886+
ret_number_bool, f_err_teapot},
18841887
{"escape", 2, 2, FEARG_1, arg2_string,
18851888
ret_string, f_escape},
18861889
{"eval", 1, 1, FEARG_1, arg1_string,
@@ -3922,6 +3925,33 @@ f_environ(typval_T *argvars UNUSED, typval_T *rettv)
39223925
#endif
39233926
}
39243927

3928+
/*
3929+
* "err_teapot()" function
3930+
*/
3931+
static void
3932+
f_err_teapot(typval_T *argvars, typval_T *rettv UNUSED)
3933+
{
3934+
if (argvars[0].v_type != VAR_UNKNOWN)
3935+
{
3936+
if (argvars[0].v_type == VAR_STRING)
3937+
{
3938+
char_u *s = tv_get_string_strict(&argvars[0]);
3939+
if (s == NULL || *skipwhite(s) == NUL)
3940+
return;
3941+
}
3942+
3943+
int err = FALSE;
3944+
int do_503 = eval_expr_to_bool(&argvars[0], &err);
3945+
if (!err && do_503)
3946+
{
3947+
emsg(_(e_coffee_currently_not_available));
3948+
return;
3949+
}
3950+
}
3951+
3952+
emsg(_(e_im_a_teapot));
3953+
}
3954+
39253955
/*
39263956
* "escape({string}, {chars})" function
39273957
*/
@@ -6456,6 +6486,14 @@ f_has(typval_T *argvars, typval_T *rettv)
64566486
1
64576487
#else
64586488
0
6489+
#endif
6490+
},
6491+
{":tearoff",
6492+
// same #ifdef as used for ex_tearoff().
6493+
#if defined(FEAT_GUI_MSWIN) && defined(FEAT_MENU) && defined(FEAT_TEAROFF)
6494+
1
6495+
#else
6496+
0
64596497
#endif
64606498
},
64616499
{NULL, 0}

src/testdir/test_functions.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ func Test_has()
3030
call assert_equal(1, or(has('ttyin'), 1))
3131
call assert_equal(0, and(has('ttyout'), 0))
3232
call assert_equal(1, has('multi_byte_encoding'))
33+
call assert_equal(0, has(':tearoff'))
3334
endif
3435
call assert_equal(1, has('vcon', 1))
3536
call assert_equal(1, has('mouse_gpm_enabled', 1))
3637

38+
call assert_equal(has('gui_win32') && has('menu'), has(':tearoff'))
39+
3740
call assert_equal(0, has('nonexistent'))
3841
call assert_equal(0, has('nonexistent', 1))
3942

@@ -86,6 +89,17 @@ func Test_empty()
8689
call assert_fails("call empty(test_unknown())", ['E340:', 'E685:'])
8790
endfunc
8891

92+
func Test_err_teapot()
93+
call assert_fails('call err_teapot()', "E418: I'm a teapot")
94+
call assert_fails('call err_teapot(0)', "E418: I'm a teapot")
95+
call assert_fails('call err_teapot(v:false)', "E418: I'm a teapot")
96+
97+
call assert_fails('call err_teapot("1")', "E503: Coffee is currently not available")
98+
call assert_fails('call err_teapot(v:true)', "E503: Coffee is currently not available")
99+
let expr = 1
100+
call assert_fails('call err_teapot(expr)', "E503: Coffee is currently not available")
101+
endfunc
102+
89103
func Test_test_void()
90104
call assert_fails('echo 1 == test_void()', 'E1031:')
91105
call assert_fails('echo 1.0 == test_void()', 'E1031:')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1673,
698700
/**/
699701
1672,
700702
/**/

0 commit comments

Comments
 (0)