xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 1cfe5e09fe27a26e57b5936344cb2fea7fce216c

Rename engine/variables.c:let_variable{,s}
Author: xaizek
Author date (UTC): 2014-04-23 20:34
Committer name: xaizek
Committer date (UTC): 2014-04-23 20:34
Parent(s): 8e1049edb14a64e7764209bb1e4d9fa5b234e903
Signing key:
Tree: ecb0549792e26f010f6db9cd866701fc1c4cf488
File Lines added Lines deleted
src/commands.c 1 1
src/engine/variables.c 1 1
src/engine/variables.h 1 1
tests/variables/clear.c 2 2
tests/variables/envvars.c 4 4
tests/variables/format.c 36 36
tests/variables/unlet.c 3 3
File src/commands.c changed (mode: 100644) (index 41eef7a44..8990a7e6c)
... ... static int
2760 2760 let_cmd(const cmd_info_t *cmd_info) let_cmd(const cmd_info_t *cmd_info)
2761 2761 { {
2762 2762 text_buffer_clear(); text_buffer_clear();
2763 if(let_variable(cmd_info->args) != 0)
2763 if(let_variables(cmd_info->args) != 0)
2764 2764 { {
2765 2765 status_bar_error(text_buffer_get()); status_bar_error(text_buffer_get());
2766 2766 return 1; return 1;
File src/engine/variables.c changed (mode: 100644) (index e89dcebe1..0f4d1a1ce)
... ... clear_variables(void)
155 155 } }
156 156
157 157 int int
158 let_variable(const char *cmd)
158 let_variables(const char *cmd)
159 159 { {
160 160 char name[VAR_NAME_MAX + 1]; char name[VAR_NAME_MAX + 1];
161 161 char *p; char *p;
File src/engine/variables.h changed (mode: 100644) (index 220cb39b0..69e51e6b6)
... ... void clear_variables(void);
45 45 /* Processes :let command arguments /* Processes :let command arguments
46 46 * Returns non-zero on error * Returns non-zero on error
47 47 */ */
48 int let_variable(const char *cmd);
48 int let_variables(const char *cmd);
49 49
50 50 /* Processes :unlet command arguments /* Processes :unlet command arguments
51 51 * Returns non-zero on error * Returns non-zero on error
File tests/variables/clear.c changed (mode: 100644) (index 8b8760e8f..8dc845e09)
... ... static void
18 18 test_envvar_remove_on_clear(void) test_envvar_remove_on_clear(void)
19 19 { {
20 20 assert_true(getenv(VAR_NAME) == NULL); assert_true(getenv(VAR_NAME) == NULL);
21 assert_int_equal(0, let_variable("$" VAR_NAME "='VAL'"));
21 assert_int_equal(0, let_variables("$" VAR_NAME "='VAL'"));
22 22 assert_true(getenv(VAR_NAME) != NULL); assert_true(getenv(VAR_NAME) != NULL);
23 23
24 24 clear_variables(); clear_variables();
 
... ... test_envvar_reset_on_clear(void)
35 35 assert_string_equal("VAL_A", getenv("VAR_A")); assert_string_equal("VAL_A", getenv("VAR_A"));
36 36 } }
37 37
38 assert_int_equal(0, let_variable("$VAR_A='VAL_2'"));
38 assert_int_equal(0, let_variables("$VAR_A='VAL_2'"));
39 39 assert_true(getenv("VAR_A") != NULL); assert_true(getenv("VAR_A") != NULL);
40 40 if(getenv("VAR_A") != NULL) if(getenv("VAR_A") != NULL)
41 41 { {
File tests/variables/envvars.c changed (mode: 100644) (index 235fe7c06..86163d6b4)
... ... static void
18 18 test_env_variable_creation_success(void) test_env_variable_creation_success(void)
19 19 { {
20 20 assert_true(getenv(VAR_NAME) == NULL); assert_true(getenv(VAR_NAME) == NULL);
21 assert_int_equal(0, let_variable("$" VAR_NAME "='VAL'"));
21 assert_int_equal(0, let_variables("$" VAR_NAME "='VAL'"));
22 22 assert_true(getenv(VAR_NAME) != NULL); assert_true(getenv(VAR_NAME) != NULL);
23 23 if(getenv(VAR_NAME) != NULL) if(getenv(VAR_NAME) != NULL)
24 24 { {
 
... ... test_env_variable_changing(void)
31 31 { {
32 32 test_env_variable_creation_success(); test_env_variable_creation_success();
33 33
34 assert_int_equal(0, let_variable("$" VAR_NAME "='VAL2'"));
34 assert_int_equal(0, let_variables("$" VAR_NAME "='VAL2'"));
35 35 assert_true(getenv(VAR_NAME) != NULL); assert_true(getenv(VAR_NAME) != NULL);
36 36 if(getenv(VAR_NAME) != NULL) if(getenv(VAR_NAME) != NULL)
37 37 { {
 
... ... static void
43 43 test_env_variable_addition_to_empty(void) test_env_variable_addition_to_empty(void)
44 44 { {
45 45 assert_true(getenv(VAR_NAME) == NULL); assert_true(getenv(VAR_NAME) == NULL);
46 assert_int_equal(0, let_variable("$" VAR_NAME ".='VAL2'"));
46 assert_int_equal(0, let_variables("$" VAR_NAME ".='VAL2'"));
47 47 assert_true(getenv(VAR_NAME) != NULL); assert_true(getenv(VAR_NAME) != NULL);
48 48 if(getenv(VAR_NAME) != NULL) if(getenv(VAR_NAME) != NULL)
49 49 { {
 
... ... test_env_variable_addition(void)
56 56 { {
57 57 test_env_variable_addition_to_empty(); test_env_variable_addition_to_empty();
58 58
59 assert_int_equal(0, let_variable("$" VAR_NAME ".='VAL2'"));
59 assert_int_equal(0, let_variables("$" VAR_NAME ".='VAL2'"));
60 60 if(getenv(VAR_NAME) != NULL) if(getenv(VAR_NAME) != NULL)
61 61 { {
62 62 assert_string_equal("VAL2VAL2", getenv(VAR_NAME)); assert_string_equal("VAL2VAL2", getenv(VAR_NAME));
File tests/variables/format.c changed (mode: 100644) (index 8d6a517d2..f6f70f965)
7 7 static void static void
8 8 test_full_tree_args_ok(void) test_full_tree_args_ok(void)
9 9 { {
10 assert_true(let_variable("$VAR = 'VAL'") == 0);
11 assert_true(let_variable("$VAR .= 'VAL'") == 0);
10 assert_true(let_variables("$VAR = 'VAL'") == 0);
11 assert_true(let_variables("$VAR .= 'VAL'") == 0);
12 12 } }
13 13
14 14 static void static void
15 15 test_full_two_args_ok(void) test_full_two_args_ok(void)
16 16 { {
17 assert_true(let_variable("$VAR ='VAL'") == 0);
18 assert_true(let_variable("$VAR .='VAL'") == 0);
19 assert_true(let_variable("$VAR= 'VAL'") == 0);
20 assert_true(let_variable("$VAR.= 'VAL'") == 0);
17 assert_true(let_variables("$VAR ='VAL'") == 0);
18 assert_true(let_variables("$VAR .='VAL'") == 0);
19 assert_true(let_variables("$VAR= 'VAL'") == 0);
20 assert_true(let_variables("$VAR.= 'VAL'") == 0);
21 21 } }
22 22
23 23 static void static void
24 24 test_full_one_arg_ok(void) test_full_one_arg_ok(void)
25 25 { {
26 assert_true(let_variable("$VAR='VAL'") == 0);
27 assert_true(let_variable("$VAR.='VAL'") == 0);
26 assert_true(let_variables("$VAR='VAL'") == 0);
27 assert_true(let_variables("$VAR.='VAL'") == 0);
28 28 } }
29 29
30 30 static void static void
31 31 test_no_quotes_fail(void) test_no_quotes_fail(void)
32 32 { {
33 assert_false(let_variable("$VAR=VAL") == 0);
34 assert_false(let_variable("$VAR.=VAL") == 0);
33 assert_false(let_variables("$VAR=VAL") == 0);
34 assert_false(let_variables("$VAR.=VAL") == 0);
35 35 } }
36 36
37 37 static void static void
38 38 test_single_quotes_ok(void) test_single_quotes_ok(void)
39 39 { {
40 assert_true(let_variable("$VAR='VAL'") == 0);
41 assert_true(let_variable("$VAR.='VAL'") == 0);
40 assert_true(let_variables("$VAR='VAL'") == 0);
41 assert_true(let_variables("$VAR.='VAL'") == 0);
42 42 } }
43 43
44 44 static void static void
45 45 test_double_quotes_ok(void) test_double_quotes_ok(void)
46 46 { {
47 assert_true(let_variable("$VAR=\"VAL\"") == 0);
48 assert_true(let_variable("$VAR.=\"VAL\"") == 0);
47 assert_true(let_variables("$VAR=\"VAL\"") == 0);
48 assert_true(let_variables("$VAR.=\"VAL\"") == 0);
49 49 } }
50 50
51 51 static void static void
52 52 test_trailing_spaces_ok(void) test_trailing_spaces_ok(void)
53 53 { {
54 assert_true(let_variable("$VAR = \"VAL\" ") == 0);
55 assert_true(let_variable("$VAR .= \"VAL\" ") == 0);
54 assert_true(let_variables("$VAR = \"VAL\" ") == 0);
55 assert_true(let_variables("$VAR .= \"VAL\" ") == 0);
56 56 } }
57 57
58 58 static void static void
59 59 test_too_many_arguments_fail(void) test_too_many_arguments_fail(void)
60 60 { {
61 assert_false(let_variable("$VAR = \"VAL\" bbb") == 0);
62 assert_false(let_variable("$VAR .= \"VAL\" $aaa") == 0);
61 assert_false(let_variables("$VAR = \"VAL\" bbb") == 0);
62 assert_false(let_variables("$VAR .= \"VAL\" $aaa") == 0);
63 63 } }
64 64
65 65 static void static void
66 66 test_incomplete_two_args_fail(void) test_incomplete_two_args_fail(void)
67 67 { {
68 assert_false(let_variable("$VAR =") == 0);
69 assert_false(let_variable("$VAR .=") == 0);
70 assert_false(let_variable("= VAL") == 0);
71 assert_false(let_variable(".= VAL") == 0);
68 assert_false(let_variables("$VAR =") == 0);
69 assert_false(let_variables("$VAR .=") == 0);
70 assert_false(let_variables("= VAL") == 0);
71 assert_false(let_variables(".= VAL") == 0);
72 72 } }
73 73
74 74 static void static void
75 75 test_incomplete_one_arg_fail(void) test_incomplete_one_arg_fail(void)
76 76 { {
77 assert_false(let_variable("$VAR") == 0);
78 assert_false(let_variable("=") == 0);
79 assert_false(let_variable(".=") == 0);
80 assert_false(let_variable("VAL") == 0);
77 assert_false(let_variables("$VAR") == 0);
78 assert_false(let_variables("=") == 0);
79 assert_false(let_variables(".=") == 0);
80 assert_false(let_variables("VAL") == 0);
81 81 } }
82 82
83 83 static void static void
84 84 test_no_dollar_sign_fail(void) test_no_dollar_sign_fail(void)
85 85 { {
86 assert_false(let_variable("VAR='VAL'") == 0);
87 assert_false(let_variable("VAR.='VAL'") == 0);
86 assert_false(let_variables("VAR='VAL'") == 0);
87 assert_false(let_variables("VAR.='VAL'") == 0);
88 88 } }
89 89
90 90 static void static void
91 91 test_env_variable_empty_name_fail(void) test_env_variable_empty_name_fail(void)
92 92 { {
93 assert_false(let_variable("$='VAL'") == 0);
94 assert_false(let_variable("$.='VAL'") == 0);
93 assert_false(let_variables("$='VAL'") == 0);
94 assert_false(let_variables("$.='VAL'") == 0);
95 95 } }
96 96
97 97 static void static void
98 98 test_spaces_in_single_quotes_ok(void) test_spaces_in_single_quotes_ok(void)
99 99 { {
100 assert_true(let_variable("$VAR='a b c'") == 0);
101 assert_true(let_variable("$VAR.='a b c'") == 0);
100 assert_true(let_variables("$VAR='a b c'") == 0);
101 assert_true(let_variables("$VAR.='a b c'") == 0);
102 102 } }
103 103
104 104 static void static void
105 105 test_spaces_in_double_quotes_ok(void) test_spaces_in_double_quotes_ok(void)
106 106 { {
107 assert_true(let_variable("$VAR=\"a b c\"") == 0);
108 assert_true(let_variable("$VAR.=\"a b c\"") == 0);
107 assert_true(let_variables("$VAR=\"a b c\"") == 0);
108 assert_true(let_variables("$VAR.=\"a b c\"") == 0);
109 109 } }
110 110
111 111 static void static void
 
... ... test_unlet_without_dollar_sign_fail(void)
136 136 static void static void
137 137 test_let_alnum_and_underscore_ok(void) test_let_alnum_and_underscore_ok(void)
138 138 { {
139 assert_true(let_variable("$1_aZzA_0 = 'VAL'") == 0);
139 assert_true(let_variables("$1_aZzA_0 = 'VAL'") == 0);
140 140 } }
141 141
142 142 static void static void
143 143 test_let_wrong_symbols_fail(void) test_let_wrong_symbols_fail(void)
144 144 { {
145 assert_true(let_variable("$.|a = 'VAL'") != 0);
145 assert_true(let_variables("$.|a = 'VAL'") != 0);
146 146 } }
147 147
148 148 void void
File tests/variables/unlet.c changed (mode: 100644) (index 398c13356..13b63d93e)
... ... setup(void)
16 16 static void static void
17 17 test_envvar_table_updates_do_not_crash(void) test_envvar_table_updates_do_not_crash(void)
18 18 { {
19 assert_int_equal(0, let_variable("$" VAR_NAME_BASE "1='VAL'"));
19 assert_int_equal(0, let_variables("$" VAR_NAME_BASE "1='VAL'"));
20 20 assert_int_equal(0, unlet_variables("$" VAR_NAME_BASE "1")); assert_int_equal(0, unlet_variables("$" VAR_NAME_BASE "1"));
21 assert_int_equal(0, let_variable("$" VAR_NAME_BASE "2='VAL'"));
22 assert_int_equal(0, let_variable("$" VAR_NAME_BASE "3='VAL'"));
21 assert_int_equal(0, let_variables("$" VAR_NAME_BASE "2='VAL'"));
22 assert_int_equal(0, let_variables("$" VAR_NAME_BASE "3='VAL'"));
23 23 } }
24 24
25 25 void void
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master