Browse Source

Move lock and interrupts fields to ACTION tag

Serj Kalichev 6 years ago
parent
commit
2053171f13

+ 2 - 2
clish.xsd

@@ -220,9 +220,9 @@
 		<xs:attribute name="viewid" type="xs:string" use="optional"/>
 		<xs:attribute name="default_shebang" type="xs:string" use="optional"/>
 		<xs:attribute name="timeout" type="xs:string" use="optional"/>
-		<xs:attribute name="lock" type="bool_t" use="optional" default="true"/>
-		<xs:attribute name="interrupt" type="bool_t" use="optional" default="false"/>
 		<xs:attribute name="default_plugin" type="bool_t" use="optional" default="true"/>
+<!-- legacy -->	<xs:attribute name="lock" type="bool_t" use="optional" default="true"/>
+<!-- legacy -->	<xs:attribute name="interrupt" type="bool_t" use="optional" default="false"/>
 	</xs:complexType>
 
 <!--

+ 2 - 0
clish/action/action.c

@@ -19,6 +19,8 @@ static void clish_action_init(clish_action_t *this)
 	this->script = NULL;
 	this->builtin = NULL;
 	this->shebang = NULL;
+	this->lock = BOOL_TRUE;
+	this->interrupt = BOOL_FALSE;
 }
 
 /*--------------------------------------------------------- */

+ 0 - 6
clish/command.h

@@ -65,12 +65,6 @@ _CLISH_SET(command, bool_t, internal);
 _CLISH_GET(command, bool_t, internal);
 _CLISH_SET(command, bool_t, dynamic);
 _CLISH_GET(command, bool_t, dynamic);
-#ifdef LEGACY
-_CLISH_SET(command, bool_t, lock);
-_CLISH_GET(command, bool_t, lock);
-_CLISH_SET(command, bool_t, interrupt);
-_CLISH_GET(command, bool_t, interrupt);
-#endif
 
 const char *clish_command__get_suffix(const clish_command_t * instance);
 unsigned int clish_command__get_param_count(const clish_command_t * instance);

+ 0 - 8
clish/command/command.c

@@ -38,8 +38,6 @@ clish_command_init(clish_command_t *this, const char *name, const char *text)
 	this->regex_chars = NULL;
 	this->args = NULL;
 	this->pview = NULL;
-	this->lock = BOOL_TRUE;
-	this->interrupt = BOOL_FALSE;
 	this->dynamic = BOOL_FALSE;
 	this->internal = BOOL_FALSE;
 	this->access = NULL;
@@ -236,12 +234,6 @@ CLISH_SET(command, bool_t, internal);
 CLISH_GET(command, bool_t, internal);
 CLISH_SET(command, bool_t, dynamic);
 CLISH_GET(command, bool_t, dynamic);
-#ifdef LEGACY
-CLISH_SET(command, bool_t, lock);
-CLISH_GET(command, bool_t, lock);
-CLISH_SET(command, bool_t, interrupt);
-CLISH_GET(command, bool_t, interrupt);
-#endif
 
 /*--------------------------------------------------------- */
 void clish_command__force_viewname(clish_command_t * this, const char *viewname)

+ 0 - 4
clish/command/private.h

@@ -22,10 +22,6 @@ struct clish_command_s {
 	char *alias_view;
 	char *alias;
 	clish_view_t *pview;
-#ifdef LEGACY
-	bool_t lock;
-	bool_t interrupt;
-#endif
 	bool_t dynamic; /* Is command dynamically created */
 	bool_t internal; /* Is command internal? Like the "startup" */
 };

+ 1 - 1
clish/shell.h

@@ -114,7 +114,7 @@ clish_ptype_t *clish_shell_find_create_ptype(clish_shell_t * instance,
 clish_ptype_t *clish_shell_find_ptype(clish_shell_t *instance,
 	const char *name);
 void clish_shell_help(clish_shell_t * instance, const char *line);
-int clish_shell_exec_action(clish_context_t *context, char **out, bool_t intr);
+int clish_shell_exec_action(clish_context_t *context, char **out);
 int clish_shell_execute(clish_context_t *context, char **out);
 int clish_shell_forceline(clish_shell_t *instance, const char *line, char ** out);
 int clish_shell_readline(clish_shell_t *instance, char ** out);

+ 4 - 4
clish/shell/shell_execute.c

@@ -113,7 +113,7 @@ int clish_shell_execute(clish_context_t *context, char **out)
 	}
 
 	/* Lock the lockfile */
-	if (lock_path && clish_command__get_lock(cmd)) {
+	if (lock_path && clish_action__get_lock(clish_command__get_action(cmd))) {
 		lock_fd = clish_shell_lock(lock_path);
 		if (-1 == lock_fd) {
 			result = -1;
@@ -123,8 +123,7 @@ int clish_shell_execute(clish_context_t *context, char **out)
 
 	/* Execute ACTION */
 	clish_context__set_action(context, clish_command__get_action(cmd));
-	result = clish_shell_exec_action(context, out,
-		clish_command__get_interrupt(cmd));
+	result = clish_shell_exec_action(context, out);
 
 	/* Call config callback */
 	if (!result)
@@ -299,7 +298,7 @@ stdout_error:
 }
 
 /*----------------------------------------------------------- */
-int clish_shell_exec_action(clish_context_t *context, char **out, bool_t intr)
+int clish_shell_exec_action(clish_context_t *context, char **out)
 {
 	int result = -1;
 	const clish_sym_t *sym;
@@ -307,6 +306,7 @@ int clish_shell_exec_action(clish_context_t *context, char **out, bool_t intr)
 	const void *func = NULL; /* We don't know the func API at this time */
 	const clish_action_t *action = clish_context__get_action(context);
 	clish_shell_t *shell = clish_context__get_shell(context);
+	bool_t intr = clish_action__get_interrupt(action);
 	/* Signal vars */
 	struct sigaction old_sigint, old_sigquit, old_sighup;
 	struct sigaction sa;

+ 1 - 1
clish/shell/shell_var.c

@@ -177,7 +177,7 @@ static char *find_var(const char *name, lub_bintree_t *tree, clish_context_t *co
 		clish_context_t ctx;
 		clish_context_dup(&ctx, context);
 		clish_context__set_action(&ctx, clish_var__get_action(var));
-		if (clish_shell_exec_action(&ctx, &out, BOOL_FALSE)) {
+		if (clish_shell_exec_action(&ctx, &out)) {
 			lub_string_free(out);
 			return NULL;
 		}

+ 71 - 26
clish/shell/shell_xml.c

@@ -468,9 +468,12 @@ static int process_command(clish_shell_t *shell, clish_xmlnode_t *element,
 	char *escape_chars = clish_xmlnode_fetch_attr(element, "escape_chars");
 	char *args_name = clish_xmlnode_fetch_attr(element, "args");
 	char *args_help = clish_xmlnode_fetch_attr(element, "args_help");
+	char *ref = clish_xmlnode_fetch_attr(element, "ref");
+#ifdef LEGACY
 	char *lock = clish_xmlnode_fetch_attr(element, "lock");
 	char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
-	char *ref = clish_xmlnode_fetch_attr(element, "ref");
+	clish_action_t *action;
+#endif
 
 	/* Check syntax */
 	if (!name) {
@@ -540,17 +543,25 @@ static int process_command(clish_shell_t *shell, clish_xmlnode_t *element,
 	if (viewid)
 		clish_command__set_viewid(cmd, viewid);
 
-	/* lock field */
-	if (lock && lub_string_nocasecmp(lock, "false") == 0)
-		clish_command__set_lock(cmd, BOOL_FALSE);
-	else
-		clish_command__set_lock(cmd, BOOL_TRUE);
+#ifdef LEGACY
+	action = clish_command__get_action(cmd);
 
-	/* interrupt field */
-	if (interrupt && lub_string_nocasecmp(interrupt, "true") == 0)
-		clish_command__set_interrupt(cmd, BOOL_TRUE);
-	else
-		clish_command__set_interrupt(cmd, BOOL_FALSE);
+	/* lock */
+	if (lock) { // Don't change anything if lock is not specified
+		if (lub_string_nocasecmp(lock, "false") == 0)
+			clish_action__set_lock(action, BOOL_FALSE);
+		else
+			clish_action__set_lock(action, BOOL_TRUE);
+	}
+
+	/* interrupt */
+	if (interrupt) { // Don't change anything if lock is not specified
+		if (lub_string_nocasecmp(interrupt, "true") == 0)
+			clish_action__set_interrupt(action, BOOL_TRUE);
+		else
+			clish_action__set_interrupt(action, BOOL_FALSE);
+	}
+#endif
 
 	if (access)
 		clish_command__set_access(cmd, access);
@@ -566,9 +577,11 @@ error:
 	clish_xml_release(escape_chars);
 	clish_xml_release(args_name);
 	clish_xml_release(args_help);
+	clish_xml_release(ref);
+#ifdef LEGACY
 	clish_xml_release(lock);
 	clish_xml_release(interrupt);
-	clish_xml_release(ref);
+#endif
 
 	return res;
 }
@@ -586,10 +599,14 @@ static int process_startup(clish_shell_t *shell, clish_xmlnode_t *element,
 	char *default_shebang =
 		clish_xmlnode_fetch_attr(element, "default_shebang");
 	char *timeout = clish_xmlnode_fetch_attr(element, "timeout");
-	char *lock = clish_xmlnode_fetch_attr(element, "lock");
-	char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
 	char *default_plugin = clish_xmlnode_fetch_attr(element,
 		"default_plugin");
+#ifdef LEGACY
+	char *lock = clish_xmlnode_fetch_attr(element, "lock");
+	char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
+	clish_action_t *action;
+#endif
+
 
 	/* Check syntax */
 	if (!view) {
@@ -603,7 +620,6 @@ static int process_startup(clish_shell_t *shell, clish_xmlnode_t *element,
 
 	/* create a command with NULL help */
 	cmd = clish_view_new_command(v, "startup", NULL);
-	clish_command__set_lock(cmd, BOOL_FALSE);
 	clish_command__set_internal(cmd, BOOL_TRUE);
 
 	/* reference the next view */
@@ -622,17 +638,25 @@ static int process_startup(clish_shell_t *shell, clish_xmlnode_t *element,
 		clish_shell__set_idle_timeout(shell, to);
 	}
 
-	/* lock field */
-	if (lock && lub_string_nocasecmp(lock, "false") == 0)
-		clish_command__set_lock(cmd, BOOL_FALSE);
-	else
-		clish_command__set_lock(cmd, BOOL_TRUE);
+#ifdef LEGACY
+	action = clish_command__get_action(cmd);
 
-	/* interrupt field */
-	if (interrupt && lub_string_nocasecmp(interrupt, "true") == 0)
-		clish_command__set_interrupt(cmd, BOOL_TRUE);
-	else
-		clish_command__set_interrupt(cmd, BOOL_FALSE);
+	/* lock */
+	if (lock) { // Don't change anything if lock is not specified
+		if (lub_string_nocasecmp(lock, "false") == 0)
+			clish_action__set_lock(action, BOOL_FALSE);
+		else
+			clish_action__set_lock(action, BOOL_TRUE);
+	}
+
+	/* interrupt */
+	if (interrupt) { // Don't change anything if lock is not specified
+		if (lub_string_nocasecmp(interrupt, "true") == 0)
+			clish_action__set_interrupt(action, BOOL_TRUE);
+		else
+			clish_action__set_interrupt(action, BOOL_FALSE);
+	}
+#endif
 
 	/* If we need the default plugin */
 	if (default_plugin && (0 == strcmp(default_plugin, "false")))
@@ -647,8 +671,10 @@ error:
 	clish_xml_release(viewid);
 	clish_xml_release(default_shebang);
 	clish_xml_release(timeout);
+#ifdef LEGACY
 	clish_xml_release(lock);
 	clish_xml_release(interrupt);
+#endif
 
 	return res;
 }
@@ -836,8 +862,13 @@ static int process_action(clish_shell_t *shell, clish_xmlnode_t *element,
 	void *parent)
 {
 	clish_action_t *action = NULL;
+
 	char *builtin = clish_xmlnode_fetch_attr(element, "builtin");
 	char *shebang = clish_xmlnode_fetch_attr(element, "shebang");
+	char *lock = clish_xmlnode_fetch_attr(element, "lock");
+	char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
+	char *interactive = clish_xmlnode_fetch_attr(element, "interactive");
+
 	clish_xmlnode_t *pelement = clish_xmlnode_parent(element);
 	char *pname = clish_xmlnode_get_all_name(pelement);
 	char *text;
@@ -870,8 +901,19 @@ static int process_action(clish_shell_t *shell, clish_xmlnode_t *element,
 	if (shebang)
 		clish_action__set_shebang(action, shebang);
 
+	/* lock */
+	if (lock && lub_string_nocasecmp(lock, "false") == 0)
+		clish_action__set_lock(action, BOOL_FALSE);
+
+	/* interrupt */
+	if (interrupt && lub_string_nocasecmp(interrupt, "true") == 0)
+		clish_action__set_interrupt(action, BOOL_TRUE);
+
 	clish_xml_release(builtin);
 	clish_xml_release(shebang);
+	clish_xml_release(lock);
+	clish_xml_release(interrupt);
+	clish_xml_release(interactive);
 
 	return 0;
 }
@@ -1120,7 +1162,10 @@ static int process_wdog(clish_shell_t *shell,
 
 	/* Create a command with NULL help */
 	cmd = clish_view_new_command(v, "watchdog", NULL);
-	clish_command__set_lock(cmd, BOOL_FALSE);
+#ifdef LEGACY
+	// Legacy watchdog has lockless ACTION
+	clish_action__set_lock(clish_command__get_action(cmd), BOOL_FALSE);
+#endif
 
 	/* Remember this command */
 	shell->wdog = cmd;