Forráskód Böngészése

Fix issue #76. Test tag inside switch. TODO: optimize

git-svn-id: https://klish.googlecode.com/svn/trunk@509 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 éve
szülő
commit
1b63ef2bbe
1 módosított fájl, 29 hozzáadás és 12 törlés
  1. 29 12
      clish/shell/shell_parse.c

+ 29 - 12
clish/shell/shell_parse.c

@@ -113,9 +113,21 @@ clish_pargv_status_t clish_shell_parse_pargv(clish_pargv_t *pargv,
 			if (is_switch) {
 				unsigned rec_paramc = clish_param__get_param_count(param);
 				for (i = 0; i < rec_paramc; i++) {
+					char *str = NULL;
+					char *tmptest = NULL;
 					cparam = clish_param__get_param(param, i);
 					if (!cparam)
 						break;
+					/* Check test condition */
+					tmptest = clish_param__get_test(cparam);
+					if (tmptest)
+						str = clish_shell_expand(tmptest, SHELL_VAR_ACTION, context);
+					if (str && !lub_system_line_test(str)) {
+						lub_string_free(str);
+						continue;
+					}
+					if (str)
+						lub_string_free(str);
 					if (CLISH_PARAM_SUBCOMMAND ==
 						clish_param__get_mode(cparam)) {
 						const char *pname =
@@ -167,20 +179,25 @@ clish_pargv_status_t clish_shell_parse_pargv(clish_pargv_t *pargv,
 				validated = NULL;
 			} else if (is_switch) {
 				for (i = 0; i < rec_paramc; i++) {
-					cparam =
-					    clish_param__get_param(param, i);
+					char *str  = NULL;
+					char *tmptest = NULL;
+					cparam = clish_param__get_param(param, i);
 					if (!cparam)
 						break;
-					if ((validated =
-					    arg ? clish_param_validate(cparam,
-								       arg) :
-					    NULL)) {
-						rec_paramv =
-						    clish_param__get_paramv
-						    (cparam);
-						rec_paramc =
-						    clish_param__get_param_count
-						    (cparam);
+					/* Check test condition */
+					tmptest = clish_param__get_test(cparam);
+					if (tmptest)
+						str = clish_shell_expand(tmptest, SHELL_VAR_ACTION, context);
+					if (str && !lub_system_line_test(str)) {
+						lub_string_free(str);
+						continue;
+					}
+					if (str)
+						lub_string_free(str);
+					if ((validated = arg ?
+						clish_param_validate(cparam, arg) : NULL)) {
+						rec_paramv = clish_param__get_paramv(cparam);
+						rec_paramc = clish_param__get_param_count(cparam);
 						break;
 					}
 				}