Browse Source

Stylistic fixes

git-svn-id: https://klish.googlecode.com/svn/trunk@384 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
b3b7a58f4b

+ 8 - 13
clish/shell/private.h

@@ -99,25 +99,20 @@ bool_t clish_shell_pop_file(clish_shell_t * instance);
 
 clish_view_t *clish_shell_find_view(clish_shell_t * instance, const char *name);
 void clish_shell_insert_view(clish_shell_t * instance, clish_view_t * view);
-clish_pargv_status_t
-clish_shell_parse(const clish_shell_t * instance,
-		  const char *line,
-		  const clish_command_t ** cmd, clish_pargv_t ** pargv);
+clish_pargv_status_t clish_shell_parse(const clish_shell_t * instance,
+	const char *line, const clish_command_t ** cmd, clish_pargv_t ** pargv);
 char *clish_shell_word_generator(clish_shell_t * instance,
-				 const char *line,
-				 unsigned offset, unsigned state);
+	const char *line, unsigned offset, unsigned state);
 const clish_command_t *clish_shell_resolve_command(const clish_shell_t *
-						   instance, const char *line);
+	instance, const char *line);
 const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t *
-						  instance, const char *line);
+	instance, const char *line);
 const clish_command_t *clish_shell_getfirst_command(clish_shell_t * instance,
-						    const char *line,
-						    clish_nspace_visibility_t
-						    field);
+	const char *line, clish_nspace_visibility_t field);
 const clish_command_t *clish_shell_getnext_command(clish_shell_t * instance,
-						   const char *line);
+	const char *line);
 void clish_shell_insert_ptype(clish_shell_t * instance, clish_ptype_t * ptype);
 void clish_shell_tinyrl_history(clish_shell_t * instance, unsigned int *limit);
 tinyrl_t *clish_shell_tinyrl_new(FILE * instream,
-				 FILE * outstream, unsigned stifle);
+	FILE * outstream, unsigned stifle);
 void clish_shell_tinyrl_delete(tinyrl_t * instance);

+ 11 - 19
clish/shell/shell_command_generator.c

@@ -9,7 +9,7 @@
 /*-------------------------------------------------------- */
 void
 clish_shell_iterator_init(clish_shell_iterator_t * iter,
-			  clish_nspace_visibility_t field)
+	clish_nspace_visibility_t field)
 {
 	iter->last_cmd = NULL;
 	iter->field = field;
@@ -17,9 +17,7 @@ clish_shell_iterator_init(clish_shell_iterator_t * iter,
 
 /*-------------------------------------------------------- */
 const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
-							this, const char *line,
-							clish_shell_iterator_t *
-							iter)
+	this, const char *line, clish_shell_iterator_t * iter)
 {
 	const clish_command_t *result, *cmd;
 
@@ -43,10 +41,8 @@ const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
 
 /*--------------------------------------------------------- */
 static char *clish_shell_param_generator(clish_shell_t * this,
-	const clish_command_t * cmd,
-	const char *line,
-	unsigned offset,
-	unsigned state)
+	const clish_command_t * cmd, const char *line,
+	unsigned offset, unsigned state)
 {
 	char *result = NULL;
 	const char *name = clish_command__get_name(cmd);
@@ -136,24 +132,20 @@ static char *clish_shell_param_generator(clish_shell_t * this,
 
 /*--------------------------------------------------------- */
 static char *clish_shell_command_generator(clish_shell_t * this,
-					   const char *line,
-					   unsigned offset, unsigned state)
+	const char *line, unsigned offset, unsigned state)
 {
 	char *result = NULL;
 	const clish_command_t *cmd = NULL;
-	if (0 == state) {
-		cmd =
-		    clish_shell_getfirst_command(this, line,
-						 CLISH_NSPACE_COMPLETION);
-	} else {
+	if (0 == state)
+		cmd = clish_shell_getfirst_command(this, line,
+			CLISH_NSPACE_COMPLETION);
+	else
 		cmd = clish_shell_getnext_command(this, line);
-	}
-
-	if (NULL != cmd) {
+	if (cmd)
 		result = lub_string_dup(clish_command__get_suffix(cmd));
-	}
 	/* keep the compiler happy */
 	offset = offset;
+
 	return result;
 }
 

+ 5 - 12
clish/shell/shell_delete.c

@@ -19,7 +19,6 @@ static void clish_shell_fini(clish_shell_t * this)
 	while ((view = lub_bintree_findfirst(&this->view_tree))) {
 		/* remove the view from the tree */
 		lub_bintree_remove(&this->view_tree, view);
-
 		/* release the instance */
 		clish_view_delete(view);
 	}
@@ -28,7 +27,6 @@ static void clish_shell_fini(clish_shell_t * this)
 	while ((ptype = lub_bintree_findfirst(&this->ptype_tree))) {
 		/* remove the command from the tree */
 		lub_bintree_remove(&this->ptype_tree, ptype);
-
 		/* release the instance */
 		clish_ptype_delete(ptype);
 	}
@@ -36,14 +34,11 @@ static void clish_shell_fini(clish_shell_t * this)
 	lub_string_free(this->overview);
 	lub_string_free(this->viewid);
 
-	if (NULL != this->startup) {
-		/* remove the startup command */
+	/* remove the startup command */
+	if (this->startup)
 		clish_command_delete(this->startup);
-	}
 	/* clean up the file stack */
-	while (BOOL_TRUE == clish_shell_pop_file(this)) {
-		/* not alot do do here */
-	}
+	while (BOOL_TRUE == clish_shell_pop_file(this));
 	/* delete the tinyrl object */
 	clish_shell_tinyrl_delete(this->tinyrl);
 
@@ -81,11 +76,9 @@ static void clish_shell_fini(clish_shell_t * this)
 /*--------------------------------------------------------- */
 void clish_shell_delete(clish_shell_t * this)
 {
-	if (this->client_hooks->fini_fn) {
-		/* now call the client finalisation */
+	/* now call the client finalisation */
+	if (this->client_hooks->fini_fn)
 		this->client_hooks->fini_fn(this);
-	}
-
 	clish_shell_fini(this);
 
 	free(this);

+ 2 - 2
clish/shell/shell_dump.c

@@ -19,14 +19,14 @@ void clish_shell_dump(clish_shell_t * this)
 
 	/* iterate the tree of views */
 	for (lub_bintree_iterator_init(&iter, &this->view_tree, v);
-	     v; v = lub_bintree_iterator_next(&iter)) {
+		v; v = lub_bintree_iterator_next(&iter)) {
 		clish_view_dump(v);
 	}
 
 	/* iterate the tree of types */
 	t = lub_bintree_findfirst(&this->ptype_tree);
 	for (lub_bintree_iterator_init(&iter, &this->ptype_tree, t);
-	     t; t = lub_bintree_iterator_next(&iter)) {
+		t; t = lub_bintree_iterator_next(&iter)) {
 		clish_ptype_dump(t);
 	}
 	lub_dump_undent();

+ 13 - 15
clish/shell/shell_execute.c

@@ -79,6 +79,7 @@ clish_source_internal(const clish_shell_t * shell,
 		result = clish_shell_push_file(this, filename,
 			stop_on_error);
 	}
+
 	return result;
 }
 
@@ -128,7 +129,7 @@ static bool_t clish_history(const clish_shell_t * this, const lub_argv_t * argv)
 	unsigned limit = 0;
 	const char *arg = lub_argv__get_arg(argv, 0);
 
-	if ((NULL != arg) && ('\0' != *arg)) {
+	if (arg && ('\0' != *arg)) {
 		limit = (unsigned)atoi(arg);
 		if (0 == limit) {
 			/* unlimit the history list */
@@ -186,7 +187,7 @@ clish_shell_execute(clish_shell_t * this,
 	sigset_t old_sigs;
 	struct sigaction old_sigint, old_sigquit;
 
-	assert(NULL != cmd);
+	assert(cmd);
 
 	/* Pre-change view if the command is from another depth/view */
         {
@@ -206,7 +207,7 @@ clish_shell_execute(clish_shell_t * this,
 				clish_command__get_depth(cmd));
 		}
 
-		if (NULL != view) {
+		if (view) {
 			this->view = view;
 			/* cleanup */
 			lub_string_free(this->viewid);
@@ -266,7 +267,7 @@ clish_shell_execute(clish_shell_t * this,
 	/* account for thread cancellation whilst running a script */
 	pthread_cleanup_push((void (*)(void *))clish_shell_cleanup_script,
 		script);
-	if (NULL != builtin) {
+	if (builtin) {
 		clish_shell_builtin_fn_t *callback;
 		lub_argv_t *argv = script ? lub_argv_new(script, 0) : NULL;
 
@@ -275,20 +276,17 @@ clish_shell_execute(clish_shell_t * this,
 		/* search for an internal command */
 		callback = find_builtin_callback(clish_cmd_list, builtin);
 
-		if (NULL == callback) {
+		if (!callback) {
 			/* search for a client command */
-			callback =
-			    find_builtin_callback(this->client_hooks->cmd_list,
-						  builtin);
+			callback = find_builtin_callback(
+				this->client_hooks->cmd_list, builtin);
 		}
-		if (NULL != callback) {
-			/* invoke the builtin callback */
+		/* invoke the builtin callback */
+		if (callback)
 			result = callback(this, argv);
-		}
-		if (NULL != argv) {
+		if (argv)
 			lub_argv_delete(argv);
-		}
-	} else if (NULL != script) {
+	} else if (script) {
 		/* now get the client to interpret the resulting script */
 		result = this->client_hooks->script_fn(this, cmd, script, out);
 	}
@@ -324,7 +322,7 @@ clish_shell_execute(clish_shell_t * this,
 		clish_view_t *view = clish_command__get_view(cmd);
 		char *viewid = clish_command__get_viewid(cmd,
 			this->viewid, pargv);
-		if (NULL != view) {
+		if (view) {
 			/* Save the current config PWD */
 			char *line = clish_variable__get_line(cmd, pargv);
 			clish_shell__set_pwd(this,

+ 8 - 12
clish/shell/shell_find_create_ptype.c

@@ -6,19 +6,15 @@
 #include <assert.h>
 /*--------------------------------------------------------- */
 clish_ptype_t *clish_shell_find_create_ptype(clish_shell_t * this,
-					     const char *name,
-					     const char *text,
-					     const char *pattern,
-					     clish_ptype_method_e method,
-					     clish_ptype_preprocess_e
-					     preprocess)
+	const char *name, const char *text, const char *pattern,
+	clish_ptype_method_e method, clish_ptype_preprocess_e preprocess)
 {
 	clish_ptype_t *ptype = lub_bintree_find(&this->ptype_tree, name);
 
-	if (NULL == ptype) {
+	if (!ptype) {
 		/* create a ptype */
-		ptype =
-		    clish_ptype_new(name, text, pattern, method, preprocess);
+		ptype = clish_ptype_new(name, text, pattern,
+			method, preprocess);
 		assert(ptype);
 		clish_shell_insert_ptype(this, ptype);
 	} else {
@@ -28,11 +24,11 @@ clish_ptype_t *clish_shell_find_create_ptype(clish_shell_t * this,
 			/* set the preprocess */
 			clish_ptype__set_preprocess(ptype, preprocess);
 		}
-		if (text) {
-			/* set the help text */
+		/* set the help text */
+		if (text)
 			clish_ptype__set_text(ptype, text);
-		}
 	}
+
 	return ptype;
 }
 

+ 3 - 4
clish/shell/shell_find_create_view.c

@@ -6,7 +6,7 @@
 #include <assert.h>
 /*--------------------------------------------------------- */
 clish_view_t *clish_shell_find_create_view(clish_shell_t * this,
-					   const char *name, const char *prompt)
+	const char *name, const char *prompt)
 {
 	clish_view_t *view = lub_bintree_find(&this->view_tree, name);
 
@@ -16,10 +16,9 @@ clish_view_t *clish_shell_find_create_view(clish_shell_t * this,
 		assert(view);
 		clish_shell_insert_view(this, view);
 	} else {
-		if (prompt) {
-			/* set the prompt */
+		/* set the prompt */
+		if (prompt)
 			clish_view__set_prompt(view, prompt);
-		}
 	}
 	return view;
 }

+ 1 - 3
clish/shell/shell_getfirst_command.c

@@ -5,9 +5,7 @@
 
 /*--------------------------------------------------------- */
 const clish_command_t *clish_shell_getfirst_command(clish_shell_t * this,
-						    const char *line,
-						    clish_nspace_visibility_t
-						    field)
+	const char *line, clish_nspace_visibility_t field)
 {
 	clish_shell_iterator_init(&this->context.iter, field);
 

+ 1 - 1
clish/shell/shell_getnext_command.c

@@ -5,7 +5,7 @@
 
 /*--------------------------------------------------------- */
 const clish_command_t *clish_shell_getnext_command(clish_shell_t * this,
-						   const char *line)
+	const char *line)
 {
 	return clish_shell_find_next_completion(this, line, &this->context.iter);
 }

+ 1 - 1
clish/shell/shell_help.c

@@ -30,7 +30,7 @@ available_commands(clish_shell_t * this, const char *line, bool_t full)
 
 		/* find the best match... */
 		cmd = clish_shell_resolve_prefix(this, line);
-		if (NULL != cmd) {
+		if (cmd) {
 			error_offset +=
 			    strlen(clish_command__get_name(cmd)) + 1;
 			/* take a copy for help purposes */

+ 1 - 0
clish/shell/shell_new.c

@@ -102,6 +102,7 @@ clish_shell_t *clish_shell_new(const clish_shell_hooks_t * hooks,
 				this->state = SHELL_STATE_CLOSING;
 		}
 	}
+
 	return this;
 }
 

+ 1 - 1
clish/shell/shell_parse.c

@@ -16,7 +16,7 @@ clish_pargv_status_t clish_shell_parse(
 
 	*cmd = clish_shell_resolve_command(this, line);
 	/* Now construct the parameters for the command */
-	if (NULL != *cmd)
+	if (*cmd)
 		*pargv = clish_pargv_new(*cmd, this->viewid, line, 0, &result);
 	if (*pargv) {
 		char str[100];

+ 0 - 1
clish/shell/shell_pop_file.c

@@ -9,7 +9,6 @@ bool_t clish_shell_pop_file(clish_shell_t * this)
 	clish_shell_file_t *node = this->current_file;
 
 	if (node) {
-
 		/* remove the current file from the stack... */
 		this->current_file = node->next;
 

+ 1 - 1
clish/shell/shell_resolve_command.c

@@ -5,7 +5,7 @@
 
 /*--------------------------------------------------------- */
 const clish_command_t *clish_shell_resolve_command(const clish_shell_t * this,
-						   const char *line)
+	const char *line)
 {
 	clish_command_t *cmd, *result;
 

+ 1 - 1
clish/shell/shell_resolve_prefix.c

@@ -5,7 +5,7 @@
 
 /*--------------------------------------------------------- */
 const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t * this,
-						  const char *line)
+	const char *line)
 {
 	clish_command_t *cmd, *result;
 

+ 3 - 0
clish/shell/shell_spawn.c

@@ -29,6 +29,7 @@ static char *clish_shell_tilde_expand(const char *path)
 	const char *p = path;
 	const char *segment = path;
 	int count = 0;
+
 	while (*p) {
 		if ('~' == *p) {
 			if (count) {
@@ -43,6 +44,7 @@ static char *clish_shell_tilde_expand(const char *path)
 	}
 	if (count)
 		lub_string_catn(&result, segment, count);
+
 	return result;
 }
 
@@ -219,6 +221,7 @@ int clish_shell_spawn_and_wait(clish_shell_t * this,
 {
 	if (clish_shell_spawn(this, attr) < 0)
 		return -1;
+
 	return clish_shell_wait(this);
 }
 

+ 2 - 4
clish/shell/shell_startup.c

@@ -12,12 +12,10 @@ bool_t clish_shell_startup(clish_shell_t * this)
 	const char *banner;
 
 	assert(this->startup);
-
 	banner = clish_command__get_detail(this->startup);
-
-	if (NULL != banner) {
+	if (banner)
 		tinyrl_printf(this->tinyrl, "%s\n", banner);
-	}
+
 	return clish_shell_execute(this, this->startup, NULL, NULL);
 }
 

+ 4 - 8
clish/shell/shell_tinyrl.c

@@ -133,11 +133,7 @@ static tinyrl_match_e clish_shell_tinyrl_complete(tinyrl_t * this)
 //			tinyrl_reset_line_state(this);
 		}
 		break;
-	case TINYRL_MATCH:
-	case TINYRL_MATCH_WITH_EXTENSIONS:
-	case TINYRL_COMPLETED_MATCH:
-	case TINYRL_AMBIGUOUS:
-	case TINYRL_COMPLETED_AMBIGUOUS:
+	default:
 		/* the default completion function will have prompted for completions as
 		 * necessary
 		 */
@@ -240,8 +236,7 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t * this, int key)
 			 */
 			line = tinyrl__get_line(this);
 			/* get the command to parse? */
-			cmd = clish_shell_resolve_command
-				(context->shell, line);
+			cmd = clish_shell_resolve_command(context->shell, line);
 			/*
 			 * We have had a match but it is not a command
 			 * so add a space so as not to confuse the user
@@ -253,7 +248,8 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t * this, int key)
 			/* failed to get a unique match... */
 			break;
 		}
-	} else {
+	}
+	if (cmd) {
 		clish_pargv_status_t arg_status;
 		tinyrl_crlf(this);
 		/* we've got a command so check the syntax */

+ 8 - 10
clish/shell/shell_tinyxml_read.cpp

@@ -14,7 +14,7 @@ extern "C" {
 #include <string.h>
 #include <assert.h>
 typedef void (PROCESS_FN) (clish_shell_t * instance,
-			   TiXmlElement * element, void *parent);
+	TiXmlElement * element, void *parent);
 
 // Define a control block for handling the decode of an XML file
 typedef struct clish_xml_cb_s clish_xml_cb_t;
@@ -86,10 +86,10 @@ static void process_node(clish_shell_t * shell, TiXmlNode * node, void *parent)
 ///////////////////////////////////////
 static void
 process_children(clish_shell_t * shell,
-		 TiXmlElement * element, void *parent = NULL)
+	TiXmlElement * element, void *parent = NULL)
 {
 	for (TiXmlNode * node = element->FirstChild();
-	     NULL != node; node = element->IterateChildren(node)) {
+		NULL != node; node = element->IterateChildren(node)) {
 		// Now deal with all the contained elements
 		process_node(shell, node, parent);
 	}
@@ -100,10 +100,9 @@ static void
 process_clish_module(clish_shell_t * shell, TiXmlElement * element, void *)
 {
 	// create the global view
-	if (NULL == shell->global) {
+	if (!shell->global)
 		shell->global =
-		    clish_shell_find_create_view(shell, "global", "");
-	}
+			clish_shell_find_create_view(shell, "global", "");
 	process_children(shell, element, shell->global);
 }
 
@@ -142,20 +141,19 @@ static void process_ptype(clish_shell_t * shell, TiXmlElement * element, void *)
 	clish_ptype_method_e method;
 	clish_ptype_preprocess_e preprocess;
 	clish_ptype_t *ptype;
+
 	const char *name = element->Attribute("name");
 	const char *help = element->Attribute("help");
 	const char *pattern = element->Attribute("pattern");
 	const char *method_name = element->Attribute("method");
 	const char *preprocess_name = element->Attribute("preprocess");
+
 	assert(name);
 	assert(pattern);
 	method = clish_ptype_method_resolve(method_name);
 	preprocess = clish_ptype_preprocess_resolve(preprocess_name);
-
 	ptype = clish_shell_find_create_ptype(shell,
-					      name,
-					      help,
-					      pattern, method, preprocess);
+		name, help, pattern, method, preprocess);
 	assert(ptype);
 }