Browse Source

Stylistic fixes

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

+ 21 - 22
clish/command/command.c

@@ -87,7 +87,7 @@ static void clish_command_fini(clish_command_t * this)
 	lub_string_free(this->escape_chars);
 	this->escape_chars = NULL;
 
-	if (NULL != this->args) {
+	if (this->args) {
 		clish_param_delete(this->args);
 		this->args = NULL;
 	}
@@ -134,9 +134,9 @@ clish_command_t *clish_command_new(const char *name, const char *help)
 {
 	clish_command_t *this = malloc(sizeof(clish_command_t));
 
-	if (this) {
+	if (this)
 		clish_command_init(this, name, help);
-	}
+
 	return this;
 }
 
@@ -263,7 +263,7 @@ void clish_command_help(const clish_command_t * this, const char * viewid,
 
 /*--------------------------------------------------------- */
 clish_command_t *clish_command_choose_longest(clish_command_t * cmd1,
-					      clish_command_t * cmd2)
+	clish_command_t * cmd2)
 {
 	unsigned len1 = (cmd1 ? strlen(clish_command__get_name(cmd1)) : 0);
 	unsigned len2 = (cmd2 ? strlen(clish_command__get_name(cmd2)) : 0);
@@ -283,17 +283,16 @@ int
 clish_command_diff(const clish_command_t * cmd1, const clish_command_t * cmd2)
 {
 	if (NULL == cmd1) {
-		if (NULL != cmd2) {
+		if (NULL != cmd2)
 			return 1;
-		} else {
+		else
 			return 0;
-		}
 	}
-	if (NULL == cmd2) {
+	if (NULL == cmd2)
 		return -1;
-	}
+
 	return lub_string_nocasecmp(clish_command__get_name(cmd1),
-				    clish_command__get_name(cmd2));
+		clish_command__get_name(cmd2));
 }
 
 /*---------------------------------------------------------
@@ -334,7 +333,7 @@ void clish_command__set_detail(clish_command_t * this, const char *detail)
 
 /*--------------------------------------------------------- */
 char *clish_command__get_action(const clish_command_t * this,
-				const char *viewid, clish_pargv_t * pargv)
+	const char *viewid, clish_pargv_t * pargv)
 {
 	return clish_variable_expand(this->action, viewid, this, pargv);
 }
@@ -373,14 +372,14 @@ void clish_command__force_viewid(clish_command_t * this, const char *viewid)
 
 /*--------------------------------------------------------- */
 char *clish_command__get_viewid(const clish_command_t * this,
-				const char *viewid, clish_pargv_t * pargv)
+	const char *viewid, clish_pargv_t * pargv)
 {
 	return clish_variable_expand(this->viewid, viewid, this, pargv);
 }
 
 /*--------------------------------------------------------- */
 const clish_param_t *clish_command__get_param(const clish_command_t * this,
-					      unsigned index)
+	unsigned index)
 {
 	return clish_paramv__get_param(this->paramv, index);
 }
@@ -407,7 +406,7 @@ const char *clish_command__get_builtin(const clish_command_t * this)
 /*--------------------------------------------------------- */
 void
 clish_command__set_escape_chars(clish_command_t * this,
-				const char *escape_chars)
+	const char *escape_chars)
 {
 	assert(NULL == this->escape_chars);
 	this->escape_chars = lub_string_dup(escape_chars);
@@ -467,7 +466,7 @@ unsigned clish_command__get_depth(const clish_command_t * this)
 /*--------------------------------------------------------- */
 void
 clish_command__set_cfg_op(clish_command_t * this,
-			  clish_config_operation_t operation)
+	clish_config_operation_t operation)
 {
 	this->cfg_op = operation;
 }
@@ -507,7 +506,7 @@ char *clish_command__get_pattern(const clish_command_t * this,
 /*--------------------------------------------------------- */
 void clish_command__set_file(clish_command_t * this, const char *file)
 {
-	assert(NULL == this->file);
+	assert(!this->file);
 	this->file = lub_string_dup(file);
 }
 
@@ -533,7 +532,7 @@ void clish_command__set_splitter(clish_command_t * this, bool_t splitter)
 /*--------------------------------------------------------- */
 void clish_command__set_seq(clish_command_t * this, const char * seq)
 {
-	assert(NULL == this->seq);
+	assert(!this->seq);
 	this->seq = lub_string_dup(seq);
 }
 
@@ -548,7 +547,7 @@ unsigned short clish_command__get_seq(const clish_command_t * this,
 		return 0;
 
 	str = clish_variable_expand(this->seq, viewid, this, pargv);
-	if ((str != NULL) && (*str != '\0')) {
+	if (str && (*str != '\0')) {
 		long val = 0;
 		char *endptr;
 
@@ -604,7 +603,7 @@ const clish_command_t * clish_command__get_orig(const clish_command_t * this)
 /*--------------------------------------------------------- */
 void clish_command__set_cfg_depth(clish_command_t * this, const char * cfg_depth)
 {
-	assert(NULL == this->cfg_depth);
+	assert(!this->cfg_depth);
 	this->cfg_depth = lub_string_dup(cfg_depth);
 }
 
@@ -619,7 +618,7 @@ unsigned clish_command__get_cfg_depth(const clish_command_t * this,
 		return clish_command__get_depth(this);
 
 	str = clish_variable_expand(this->cfg_depth, viewid, this, pargv);
-	if ((str != NULL) && (*str != '\0')) {
+	if (str && (*str != '\0')) {
 		long val = 0;
 		char *endptr;
 
@@ -662,7 +661,7 @@ void clish_command__set_shebang(clish_command_t * this, const char * shebang)
 	const char *prog = shebang;
 	const char *prefix = "#!";
 
-	assert(NULL == this->shebang);
+	assert(!this->shebang);
 	if (lub_string_nocasestr(shebang, prefix) == shebang)
 		prog += strlen(prefix);
 	this->shebang = lub_string_dup(prog);
@@ -671,7 +670,7 @@ void clish_command__set_shebang(clish_command_t * this, const char * shebang)
 /*--------------------------------------------------------- */
 void clish_command__set_alias(clish_command_t * this, const char * alias)
 {
-	assert(NULL == this->alias);
+	assert(!this->alias);
 	this->alias = lub_string_dup(alias);
 }
 

+ 4 - 6
clish/nspace/nspace.c

@@ -130,9 +130,8 @@ clish_nspace_t *clish_nspace_new(clish_view_t * view)
 {
 	clish_nspace_t *this = malloc(sizeof(clish_nspace_t));
 
-	if (this) {
+	if (this)
 		clish_nspace_init(this, view);
-	}
 	return this;
 }
 
@@ -280,7 +279,7 @@ clish_view_t *clish_nspace__get_view(const clish_nspace_t * this)
 /*--------------------------------------------------------- */
 void clish_nspace__set_prefix(clish_nspace_t * this, const char *prefix)
 {
-	assert(NULL == this->prefix);
+	assert(!this->prefix);
 	this->prefix = lub_string_dup(prefix);
 }
 
@@ -339,9 +338,8 @@ bool_t clish_nspace__get_inherit(const clish_nspace_t * this)
 }
 
 /*--------------------------------------------------------- */
-bool_t
-clish_nspace__get_visibility(const clish_nspace_t * instance,
-			     clish_nspace_visibility_t field)
+bool_t clish_nspace__get_visibility(const clish_nspace_t * instance,
+	clish_nspace_visibility_t field)
 {
 	bool_t result = BOOL_FALSE;
 

+ 11 - 15
clish/param/param.c

@@ -57,13 +57,12 @@ static void clish_param_fini(clish_param_t * this)
  * PUBLIC META FUNCTIONS
  *--------------------------------------------------------- */
 clish_param_t *clish_param_new(const char *name,
-			       const char *text, clish_ptype_t * ptype)
+	const char *text, clish_ptype_t * ptype)
 {
 	clish_param_t *this = malloc(sizeof(clish_param_t));
 
-	if (this) {
+	if (this)
 		clish_param_init(this, name, text, ptype);
-	}
 	return this;
 }
 
@@ -113,7 +112,7 @@ clish_ptype_t *clish_param__get_ptype(const clish_param_t * this)
 /*--------------------------------------------------------- */
 void clish_param__set_default(clish_param_t * this, const char *defval)
 {
-	assert(NULL == this->defval);
+	assert(!this->defval);
 	this->defval = lub_string_dup(defval);
 }
 
@@ -175,9 +174,8 @@ void clish_param_help(const clish_param_t * this, size_t offset)
 
 	fprintf(stderr, "  %s %*c%s",
 		name, (int)(offset - strlen(name)), ' ', this->text);
-	if (NULL != range) {
+	if (NULL != range)
 		fprintf(stderr, " (%s)", range);
-	}
 	fprintf(stderr, "\n");
 }
 
@@ -189,7 +187,7 @@ void clish_param_help_arrow(const clish_param_t * this, size_t offset)
 
 /*--------------------------------------------------------- */
 clish_param_t *clish_param__get_param(const clish_param_t * this,
-				      unsigned index)
+	unsigned index)
 {
 	return clish_paramv__get_param(this->paramv, index);
 }
@@ -248,9 +246,8 @@ clish_paramv_t *clish_paramv_new(void)
 {
 	clish_paramv_t *this = malloc(sizeof(clish_paramv_t));
 
-	if (this) {
+	if (this)
 		clish_paramv_init(this);
-	}
 	return this;
 }
 
@@ -269,7 +266,7 @@ void clish_paramv_insert(clish_paramv_t * this, clish_param_t * param)
 
 	/* resize the parameter vector */
 	tmp = realloc(this->paramv, new_size);
-	if (NULL != tmp) {
+	if (tmp) {
 		this->paramv = tmp;
 		/* insert reference to the parameter */
 		this->paramv[this->paramc++] = param;
@@ -278,13 +275,12 @@ void clish_paramv_insert(clish_paramv_t * this, clish_param_t * param)
 
 /*--------------------------------------------------------- */
 clish_param_t *clish_paramv__get_param(const clish_paramv_t * this,
-				      unsigned index)
+	unsigned index)
 {
 	clish_param_t *result = NULL;
 
-	if (index < this->paramc) {
+	if (index < this->paramc)
 		result = this->paramv[index];
-	}
 	return result;
 }
 
@@ -297,7 +293,7 @@ const unsigned clish_paramv__get_count(const clish_paramv_t * this)
 /*--------------------------------------------------------- */
 void clish_param__set_value(clish_param_t * this, const char * value)
 {
-	assert(NULL == this->value);
+	assert(!this->value);
 	this->value = lub_string_dup(value);
 }
 
@@ -324,7 +320,7 @@ bool_t clish_param__get_hidden(const clish_param_t * this)
 /*--------------------------------------------------------- */
 void clish_param__set_test(clish_param_t * this, const char *test)
 {
-	assert(NULL == this->test);
+	assert(!this->test);
 	this->test = lub_string_dup(test);
 }
 

+ 3 - 3
clish/param/param_dump.c

@@ -17,7 +17,7 @@ void clish_param_dump(const clish_param_t * this)
 	lub_dump_printf("value    : %s\n", this->value);
 	lub_dump_printf("ptype    : %s\n", clish_ptype__get_name(this->ptype));
 	lub_dump_printf("default  : %s\n",
-			this->defval ? this->defval : "(null)");
+		this->defval ? this->defval : "(null)");
 	switch (this->mode) {
 	case CLISH_PARAM_COMMON:
 		mode = "COMMON";
@@ -35,9 +35,9 @@ void clish_param_dump(const clish_param_t * this)
 	lub_dump_printf("mode     : %s\n", mode);
 	lub_dump_printf("paramc   : %d\n", clish_paramv__get_count(this->paramv));
 	lub_dump_printf("optional : %s\n",
-			this->optional ? "true" : "false");
+		this->optional ? "true" : "false");
 	lub_dump_printf("hidden   : %s\n",
-			this->hidden ? "true" : "false");
+		this->hidden ? "true" : "false");
 	lub_dump_printf("test     : %s\n", this->test);
 
 	/* Get each parameter to dump their details */

+ 4 - 7
clish/pargv/pargv.c

@@ -45,7 +45,7 @@ int clish_pargv_insert(clish_pargv_t * this,
 
 	clish_parg_t *parg = find_parg(this, clish_param__get_name(param));
 
-	if (NULL != parg) {
+	if (parg) {
 		/* release the current value */
 		lub_string_free(parg->value);
 	} else {
@@ -96,8 +96,7 @@ static void set_defaults(clish_pargv_t * this, const clish_command_t * cmd)
 #endif
 
 /*--------------------------------------------------------- */
-clish_pargv_status_t
-clish_pargv_parse(clish_pargv_t * this,
+clish_pargv_status_t clish_pargv_parse(clish_pargv_t * this,
 	const clish_command_t * cmd,
 	const char *viewid,
 	clish_paramv_t * paramv,
@@ -348,10 +347,8 @@ clish_pargv_parse(clish_pargv_t * this,
 }
 
 /*--------------------------------------------------------- */
-static clish_pargv_status_t
-clish_pargv_init(clish_pargv_t * this,
-	const clish_command_t * cmd,
-	const char *viewid,
+static clish_pargv_status_t clish_pargv_init(clish_pargv_t * this,
+	const clish_command_t * cmd, const char *viewid,
 	const lub_argv_t * argv)
 {
 	unsigned idx = lub_argv_wordcount(clish_command__get_name(cmd));

+ 1 - 1
clish/pargv/pargv_dump.c

@@ -11,7 +11,7 @@ void clish_parg_dump(const clish_parg_t * this)
 	lub_dump_indent();
 	lub_dump_printf("name : %s\n", clish_parg__get_name(this));
 	lub_dump_printf("ptype: %s\n",
-			clish_ptype__get_name(clish_parg__get_ptype(this)));
+		clish_ptype__get_name(clish_parg__get_ptype(this)));
 	lub_dump_printf("value: %s\n", clish_parg__get_value(this));
 	lub_dump_undent();
 }

+ 204 - 258
clish/ptype/ptype.c

@@ -15,16 +15,15 @@
  * PRIVATE METHODS
  *--------------------------------------------------------- */
 static char *clish_ptype_select__get_name(const clish_ptype_t * this,
-					  unsigned index)
+	unsigned index)
 {
 	char *result = NULL;
 	const char *arg = lub_argv__get_arg(this->u.select.items, index);
-	if (NULL != arg) {
+	if (arg) {
 		size_t name_len = 0;
 		const char *lbrk = strchr(arg, '(');
-		if (NULL != lbrk) {
+		if (lbrk)
 			name_len = (size_t) (lbrk - arg);
-		}
 		assert(name_len < strlen(arg));	/* check for syntax error */
 		result = lub_string_dupn(arg, name_len);
 	}
@@ -33,20 +32,19 @@ static char *clish_ptype_select__get_name(const clish_ptype_t * this,
 
 /*--------------------------------------------------------- */
 static char *clish_ptype_select__get_value(const clish_ptype_t * this,
-					   unsigned index)
+	unsigned index)
 {
 	char *result = NULL;
 	const char *arg = lub_argv__get_arg(this->u.select.items, index);
-	if (NULL != arg) {
+	if (arg) {
 		const char *lbrk = strchr(arg, '(');
 		const char *rbrk = strchr(arg, ')');
 		const char *value = NULL;
 		size_t value_len = 0;
 		if (lbrk) {
 			value = lbrk + 1;
-			if (rbrk) {
+			if (rbrk)
 				value_len = (size_t) (rbrk - value);
-			}
 		}
 		assert(value_len < strlen(arg));	/* check for syntax error */
 		result = lub_string_dupn(value, value_len);
@@ -63,61 +61,53 @@ static void clish_ptype__set_range(clish_ptype_t * this)
 	switch (this->method) {
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_REGEXP:
-		{
-			/* 
-			 * nothing more to do 
-			 */
-			break;
-		}
+		/*
+		 * nothing more to do 
+		 */
+		break;
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_INTEGER:
-		{
-			/*
-			 * Setup the integer range
-			 */
-			sprintf(tmp,
-				"%d..%d",
-				this->u.integer.min, this->u.integer.max);
-			this->range = lub_string_dup(tmp);
-			break;
-		}
+		/*
+		 * Setup the integer range
+		 */
+		sprintf(tmp,
+			"%d..%d",
+			this->u.integer.min, this->u.integer.max);
+		this->range = lub_string_dup(tmp);
+		break;
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_UNSIGNEDINTEGER:
-		{
-			/*
-			 * Setup the unsigned integer range
-			 */
-			sprintf(tmp,
-				"%u..%u",
-				(unsigned int)this->u.integer.min,
-				(unsigned int)this->u.integer.max);
-			this->range = lub_string_dup(tmp);
-			break;
-		}
+		/*
+		 * Setup the unsigned integer range
+		 */
+		sprintf(tmp,
+			"%u..%u",
+			(unsigned int)this->u.integer.min,
+			(unsigned int)this->u.integer.max);
+		this->range = lub_string_dup(tmp);
+		break;
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_SELECT:
-		{
-			/*
-			 * Setup the selection values to the help text
-			 */
-			unsigned i;
-
-			for (i = 0;
-			     i < lub_argv__get_count(this->u.select.items);
-			     i++) {
-				char *p = tmp;
-				char *name =
-				    clish_ptype_select__get_name(this, i);
-
-				if (i > 0) {
-					p += sprintf(p, "/");
-				}
-				p += sprintf(p, "%s", name);
-				lub_string_cat(&this->range, tmp);
-				lub_string_free(name);
-			}
-			break;
+	{
+		/*
+		 * Setup the selection values to the help text
+		 */
+		unsigned i;
+
+		for (i = 0;
+			i < lub_argv__get_count(this->u.select.items);
+			i++) {
+			char *p = tmp;
+			char *name = clish_ptype_select__get_name(this, i);
+
+			if (i > 0)
+				p += sprintf(p, "/");
+			p += sprintf(p, "%s", name);
+			lub_string_cat(&this->range, tmp);
+			lub_string_free(name);
 		}
+		break;
+	}
 	/*------------------------------------------------- */
 	}
 }
@@ -192,8 +182,8 @@ static const char *preprocess_names[] = {
 };
 
 /*--------------------------------------------------------- */
-const char *clish_ptype_preprocess__get_name(clish_ptype_preprocess_e
-					     preprocess)
+const char *clish_ptype_preprocess__get_name(
+	clish_ptype_preprocess_e preprocess)
 {
 	return preprocess_names[preprocess];
 }
@@ -202,7 +192,7 @@ const char *clish_ptype_preprocess__get_name(clish_ptype_preprocess_e
 clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char *name)
 {
 	clish_ptype_preprocess_e result = CLISH_PTYPE_NONE;
-	if (NULL != name) {
+	if (name) {
 		unsigned i;
 		for (i = 0; i < CLISH_PTYPE_TOLOWER + 1; i++) {
 			if (0 == strcmp(name, preprocess_names[i])) {
@@ -228,33 +218,23 @@ char *clish_ptype_word_generator(clish_ptype_t * this,
 
 	if (this->method != CLISH_PTYPE_SELECT)
 		return NULL;
-	if (0 == state) {
-		/* first of all simply try to validate the result */
+	/* first of all simply try to validate the result */
+	if (0 == state)
 		result = clish_ptype_validate(this, text);
-	}
-	if (NULL == result) {
+	if (!result) {
 		switch (this->method) {
 		case CLISH_PTYPE_SELECT:
-			{
-				if (0 == state) {
-					this->last_name = 0;
-				}
-				while ((result =
-					clish_ptype_select__get_name(this,
-								     this->
-								     last_name++)))
-				{
-					/* get the next item and check if it is a completion */
-					if (result ==
-					    lub_string_nocasestr(result,
-								 text)) {
-						/* found the next completion */
+			if (0 == state)
+				this->last_name = 0;
+			while ((result = clish_ptype_select__get_name(this,
+					this->last_name++))) {
+				/* get the next item and check if it is a completion */
+				/* found the next completion */
+				if (result == lub_string_nocasestr(result, text))
 						break;
-					}
-					lub_string_free(result);
-				}
-				break;
+				lub_string_free(result);
 			}
+			break;
 		default:
 			break;
 		}
@@ -264,8 +244,7 @@ char *clish_ptype_word_generator(clish_ptype_t * this,
 
 /*--------------------------------------------------------- */
 static char *clish_ptype_validate_or_translate(const clish_ptype_t * this,
-					       const char *text,
-					       bool_t translate)
+	const char *text, bool_t translate)
 {
 	char *result = lub_string_dup(text);
 	assert(this->pattern);
@@ -273,160 +252,144 @@ static char *clish_ptype_validate_or_translate(const clish_ptype_t * this,
 	switch (this->preprocess) {
 	/*----------------------------------------- */
 	case CLISH_PTYPE_NONE:
-		{
-			break;
-		}
+		break;
 	/*----------------------------------------- */
 	case CLISH_PTYPE_TOUPPER:
-		{
-			char *p = result;
-			while (*p) {
-				/*lint -e155 Ignoring { }'ed sequence within an expression, 0 assumed 
-				 * MACRO implementation uses braces to prevent multiple increments
-				 * when called.
-				 */
-				*p = lub_ctype_toupper(*p);
-				p++;
-			}
-			break;
+	{
+		char *p = result;
+		while (*p) {
+			/*lint -e155 Ignoring { }'ed sequence within an expression, 0 assumed 
+			 * MACRO implementation uses braces to prevent multiple increments
+			 * when called.
+			 */
+			*p = lub_ctype_toupper(*p);
+			p++;
 		}
+		break;
+	}
 	/*----------------------------------------- */
 	case CLISH_PTYPE_TOLOWER:
-		{
-			char *p = result;
-			while (*p) {
-				*p = lub_ctype_tolower(*p);
-				p++;
-			}
-			break;
+	{
+		char *p = result;
+		while (*p) {
+			*p = lub_ctype_tolower(*p);
+			p++;
 		}
+		break;
+	}
 	/*----------------------------------------- */
 	}
-	/* 
+	/*
 	 * now validate according the specified method 
 	 */
 	switch (this->method) {
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_REGEXP:
-		{
-			/* test the regular expression against the string */
-			/*lint -e64 Type mismatch (arg. no. 4) */
-			/*
-			 * lint seems to equate regmatch_t[] as being of type regmatch_t !!!
-			 */
-			if (0 != regexec(&this->u.regexp, result, 0, NULL, 0)) {
-				lub_string_free(result);
-				result = NULL;
-			}
-			/*lint +e64 */
-			break;
+		/* test the regular expression against the string */
+		/*lint -e64 Type mismatch (arg. no. 4) */
+		/*
+		 * lint seems to equate regmatch_t[] as being of type regmatch_t !!!
+		 */
+		if (0 != regexec(&this->u.regexp, result, 0, NULL, 0)) {
+			lub_string_free(result);
+			result = NULL;
 		}
+		/*lint +e64 */
+		break;
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_INTEGER:
-		{
-			/* first of all check that this is a number */
-
-			bool_t ok = BOOL_TRUE;
-			const char *p = result;
-
-			if (*p == '-') {
-				p++;
-			}
-			while (*p) {
-				if (!lub_ctype_isdigit(*p++)) {
-					ok = BOOL_FALSE;
-					break;
-				}
+	{
+		/* first of all check that this is a number */
+		bool_t ok = BOOL_TRUE;
+		const char *p = result;
+
+		if (*p == '-')
+			p++;
+		while (*p) {
+			if (!lub_ctype_isdigit(*p++)) {
+				ok = BOOL_FALSE;
+				break;
 			}
-			if (BOOL_TRUE == ok) {
-				/* convert and check the range */
-				int value = atoi(result);
-				if ((value < this->u.integer.min)
-				    || (value > this->u.integer.max)) {
-					lub_string_free(result);
-					result = NULL;
-				}
-			} else {
+		}
+		if (BOOL_TRUE == ok) {
+			/* convert and check the range */
+			int value = atoi(result);
+			if ((value < this->u.integer.min)
+				|| (value > this->u.integer.max)) {
 				lub_string_free(result);
 				result = NULL;
 			}
-			break;
+		} else {
+			lub_string_free(result);
+			result = NULL;
 		}
+		break;
+	}
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_UNSIGNEDINTEGER:
-		{
-			/* first of all check that this is a number */
-			bool_t ok = BOOL_TRUE;
-			const char *p = result;
-			if (*p == '-') {
-				p++;
-			}
-			while (*p) {
-				if (!lub_ctype_isdigit(*p++)) {
-					ok = BOOL_FALSE;
-					break;
-				}
+	{
+		/* first of all check that this is a number */
+		bool_t ok = BOOL_TRUE;
+		const char *p = result;
+		if (*p == '-')
+			p++;
+		while (*p) {
+			if (!lub_ctype_isdigit(*p++)) {
+				ok = BOOL_FALSE;
+				break;
 			}
-			if (BOOL_TRUE == ok) {
-				/* convert and check the range */
-				unsigned int value = (unsigned int)atoi(result);
-				if ((value < (unsigned)this->u.integer.min)
-				    || (value > (unsigned)this->u.integer.max)) {
-					lub_string_free(result);
-					result = NULL;
-				}
-			} else {
+		}
+		if (BOOL_TRUE == ok) {
+			/* convert and check the range */
+			unsigned int value = (unsigned int)atoi(result);
+			if ((value < (unsigned)this->u.integer.min)
+				|| (value > (unsigned)this->u.integer.max)) {
 				lub_string_free(result);
 				result = NULL;
 			}
-			break;
+		} else {
+			lub_string_free(result);
+			result = NULL;
 		}
+		break;
+	}
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_SELECT:
-		{
-			unsigned i;
-			for (i = 0;
-			     i < lub_argv__get_count(this->u.select.items);
-			     i++) {
-				char *name =
-				    clish_ptype_select__get_name(this, i);
-				char *value =
-				    clish_ptype_select__get_value(this, i);
-				int tmp = lub_string_nocasecmp(result, name);
-				lub_string_free((BOOL_TRUE ==
-						 translate) ? name : value);
-				if (0 == tmp) {
-					lub_string_free(result);
-					result =
-					    ((BOOL_TRUE ==
-					      translate) ? value : name);
-					break;
-				} else {
-					lub_string_free((BOOL_TRUE ==
-							 translate) ? value :
-							name);
-				}
-			}
-			if (i == lub_argv__get_count(this->u.select.items)) {
-				/* failed to find a match */
+	{
+		unsigned i;
+		for (i = 0; i < lub_argv__get_count(this->u.select.items);
+			i++) {
+			char *name = clish_ptype_select__get_name(this, i);
+			char *value = clish_ptype_select__get_value(this, i);
+			int tmp = lub_string_nocasecmp(result, name);
+			lub_string_free((BOOL_TRUE ==
+				translate) ? name : value);
+			if (0 == tmp) {
 				lub_string_free(result);
-				result = NULL;
+				result = ((BOOL_TRUE ==
+					translate) ? value : name);
+				break;
+			} else {
+				lub_string_free((BOOL_TRUE ==
+					translate) ? value : name);
 			}
-			break;
 		}
+		if (i == lub_argv__get_count(this->u.select.items)) {
+			/* failed to find a match */
+			lub_string_free(result);
+			result = NULL;
+		}
+		break;
+	}
 	/*------------------------------------------------- */
 	}
 	return (char *)result;
 }
 
 /*--------------------------------------------------------- */
-static void
-clish_ptype_init(clish_ptype_t * this,
-		 const char *name,
-		 const char *text,
-		 const char *pattern,
-		 clish_ptype_method_e method,
-		 clish_ptype_preprocess_e preprocess)
+static void clish_ptype_init(clish_ptype_t * this,
+	const char *name, const char *text, const char *pattern,
+	clish_ptype_method_e method, clish_ptype_preprocess_e preprocess)
 {
 	assert(name);
 	this->name = lub_string_dup(name);
@@ -438,7 +401,7 @@ clish_ptype_init(clish_ptype_t * this,
 	/* Be a good binary tree citizen */
 	lub_bintree_node_init(&this->bt_node);
 
-	if (NULL != pattern) {
+	if (pattern) {
 		/* set the pattern for this type */
 		clish_ptype__set_pattern(this, pattern, method);
 	} else {
@@ -446,10 +409,9 @@ clish_ptype_init(clish_ptype_t * this,
 		this->method = CLISH_PTYPE_REGEXP;
 	}
 	
-	if (NULL != text) {
-		/* set the help text for this type */
+	/* set the help text for this type */
+	if (text)
 		clish_ptype__set_text(this, text);
-	}
 }
 
 /*--------------------------------------------------------- */
@@ -466,16 +428,13 @@ char *clish_ptype_translate(const clish_ptype_t * this, const char *text)
 
 /*--------------------------------------------------------- */
 clish_ptype_t *clish_ptype_new(const char *name,
-			       const char *help,
-			       const char *pattern,
-			       clish_ptype_method_e method,
-			       clish_ptype_preprocess_e preprocess)
+	const char *help, const char *pattern,
+	clish_ptype_method_e method, clish_ptype_preprocess_e preprocess)
 {
 	clish_ptype_t *this = malloc(sizeof(clish_ptype_t));
 
-	if (NULL != this) {
+	if (this)
 		clish_ptype_init(this, name, help, pattern, method, preprocess);
-	}
 	return this;
 }
 
@@ -484,19 +443,15 @@ static void clish_ptype_fini(clish_ptype_t * this)
 {
 	if (this->pattern) {
 		switch (this->method) {
-		/*------------------------------------------------- */
 		case CLISH_PTYPE_REGEXP:
 			regfree(&this->u.regexp);
 			break;
-		/*------------------------------------------------- */
 		case CLISH_PTYPE_INTEGER:
 		case CLISH_PTYPE_UNSIGNEDINTEGER:
 			break;
-		/*------------------------------------------------- */
 		case CLISH_PTYPE_SELECT:
 			lub_argv_delete(this->u.select.items);
 			break;
-		/*------------------------------------------------- */
 		}
 	}
 
@@ -540,56 +495,47 @@ clish_ptype__set_pattern(clish_ptype_t * this,
 	switch (this->method) {
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_REGEXP:
-		{
-			int result;
-
-			/* only the expression is allowed */
-			lub_string_cat(&this->pattern, "^");
-			lub_string_cat(&this->pattern, pattern);
-			lub_string_cat(&this->pattern, "$");
-
-			/* compile the regular expression for later use */
-			result =
-			    regcomp(&this->u.regexp, this->pattern,
-				    REG_NOSUB | REG_EXTENDED);
-			assert(0 == result);
-			break;
-		}
+	{
+		int result;
+
+		/* only the expression is allowed */
+		lub_string_cat(&this->pattern, "^");
+		lub_string_cat(&this->pattern, pattern);
+		lub_string_cat(&this->pattern, "$");
+
+		/* compile the regular expression for later use */
+		result = regcomp(&this->u.regexp, this->pattern,
+			REG_NOSUB | REG_EXTENDED);
+		assert(0 == result);
+		break;
+	}
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_INTEGER:
-		{
-			/* default the range to that of an integer */
-			this->u.integer.min = INT_MIN;
-			this->u.integer.max = INT_MAX;
-			this->pattern = lub_string_dup(pattern);
-			/* now try and read the specified range */
-			sscanf(this->pattern,
-			       "%d..%d",
-			       &this->u.integer.min, &this->u.integer.max);
-			break;
-		}
+		/* default the range to that of an integer */
+		this->u.integer.min = INT_MIN;
+		this->u.integer.max = INT_MAX;
+		this->pattern = lub_string_dup(pattern);
+		/* now try and read the specified range */
+		sscanf(this->pattern, "%d..%d",
+			&this->u.integer.min, &this->u.integer.max);
+		break;
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_UNSIGNEDINTEGER:
-		{
-			/* default the range to that of an unsigned integer */
-			this->u.integer.min = 0;
-			this->u.integer.max = (int)UINT_MAX;
-			this->pattern = lub_string_dup(pattern);
-			/* now try and read the specified range */
-			sscanf(this->pattern,
-			       "%u..%u",
-			       (unsigned int *)&this->u.integer.min,
-			       (unsigned int *)&this->u.integer.max);
-			break;
-		}
+		/* default the range to that of an unsigned integer */
+		this->u.integer.min = 0;
+		this->u.integer.max = (int)UINT_MAX;
+		this->pattern = lub_string_dup(pattern);
+		/* now try and read the specified range */
+		sscanf(this->pattern, "%u..%u",
+			(unsigned int *)&this->u.integer.min,
+			(unsigned int *)&this->u.integer.max);
+		break;
 	/*------------------------------------------------- */
 	case CLISH_PTYPE_SELECT:
-		{
-			this->pattern = lub_string_dup(pattern);
-			/* store a vector of item descriptors */
-			this->u.select.items = lub_argv_new(this->pattern, 0);
-			break;
-		}
+		this->pattern = lub_string_dup(pattern);
+		/* store a vector of item descriptors */
+		this->u.select.items = lub_argv_new(this->pattern, 0);
+		break;
 	/*------------------------------------------------- */
 	}
 	/* now set up the range details */
@@ -599,7 +545,7 @@ clish_ptype__set_pattern(clish_ptype_t * this,
 /*--------------------------------------------------------- */
 void clish_ptype__set_text(clish_ptype_t * this, const char *text)
 {
-	assert(NULL == this->text);
+	assert(!this->text);
 	this->text = lub_string_dup(text);
 
 }
@@ -607,7 +553,7 @@ void clish_ptype__set_text(clish_ptype_t * this, const char *text)
 /*--------------------------------------------------------- */
 void
 clish_ptype__set_preprocess(clish_ptype_t * this,
-			    clish_ptype_preprocess_e preprocess)
+	clish_ptype_preprocess_e preprocess)
 {
 	this->preprocess = preprocess;
 }

+ 2 - 2
clish/ptype/ptype_dump.c

@@ -13,9 +13,9 @@ void clish_ptype_dump(clish_ptype_t * this)
 	lub_dump_printf("text       : %s\n", clish_ptype__get_text(this));
 	lub_dump_printf("pattern    : %s\n", this->pattern);
 	lub_dump_printf("method     : %s\n",
-			clish_ptype_method__get_name(this->method));
+		clish_ptype_method__get_name(this->method));
 	lub_dump_printf("postprocess: %s\n",
-			clish_ptype_preprocess__get_name(this->preprocess));
+		clish_ptype_preprocess__get_name(this->preprocess));
 	lub_dump_undent();
 }
 

+ 22 - 27
clish/view/view.c

@@ -53,8 +53,8 @@ clish_view_init(clish_view_t * this, const char *name, const char *prompt)
 
 	/* initialise the tree of commands for this view */
 	lub_bintree_init(&this->tree,
-			 clish_command_bt_offset(),
-			 clish_command_bt_compare, clish_command_bt_getkey);
+		clish_command_bt_offset(),
+		clish_command_bt_compare, clish_command_bt_getkey);
 
 	/* set up the defaults */
 	clish_view__set_prompt(this, prompt);
@@ -70,7 +70,6 @@ static void clish_view_fini(clish_view_t * this)
 	while ((cmd = lub_bintree_findfirst(&this->tree))) {
 		/* remove the command from the tree */
 		lub_bintree_remove(&this->tree, cmd);
-
 		/* release the instance */
 		clish_command_delete(cmd);
 	}
@@ -104,9 +103,8 @@ clish_view_t *clish_view_new(const char *name, const char *prompt)
 {
 	clish_view_t *this = malloc(sizeof(clish_view_t));
 
-	if (this) {
+	if (this)
 		clish_view_init(this, name, prompt);
-	}
 	return this;
 }
 
@@ -121,7 +119,7 @@ void clish_view_delete(clish_view_t * this)
 
 /*--------------------------------------------------------- */
 clish_command_t *clish_view_new_command(clish_view_t * this,
-					const char *name, const char *help)
+	const char *name, const char *help)
 {
 	/* allocate the memory for a new parameter definition */
 	clish_command_t *cmd = clish_command_new(name, help);
@@ -149,7 +147,7 @@ clish_command_t *clish_view_new_command(clish_view_t * this,
  * line - the command line to analyse 
  */
 clish_command_t *clish_view_resolve_prefix(clish_view_t * this,
-					   const char *line, bool_t inherit)
+	const char *line, bool_t inherit)
 {
 	clish_command_t *result = NULL, *cmd;
 	char *buffer = NULL;
@@ -166,10 +164,9 @@ clish_command_t *clish_view_resolve_prefix(clish_view_t * this,
 		/* set the result to the longest match */
 		cmd = clish_view_find_command(this, buffer, inherit);
 
-		if (NULL == cmd) {
-			/* job done */
+		/* job done */
+		if (!cmd)
 			break;
-		}
 		result = cmd;
 
 		/* ready for the next word */
@@ -185,16 +182,15 @@ clish_command_t *clish_view_resolve_prefix(clish_view_t * this,
 
 /*--------------------------------------------------------- */
 clish_command_t *clish_view_resolve_command(clish_view_t * this,
-					    const char *line, bool_t inherit)
+	const char *line, bool_t inherit)
 {
 	clish_command_t *result = clish_view_resolve_prefix(this, line, inherit);
 
-	if (NULL != result) {
+	if (result) {
 		char *action = clish_command__get_action(result, NULL, NULL);
-		if ((NULL == action) &&
-		    (NULL == clish_command__get_builtin(result)) &&
-		    (CLISH_CONFIG_NONE == clish_command__get_cfg_op(result)) &&
-		    (NULL == clish_command__get_view(result))) {
+		if (!action && (NULL == clish_command__get_builtin(result)) &&
+			(CLISH_CONFIG_NONE == clish_command__get_cfg_op(result)) &&
+			(NULL == clish_command__get_view(result))) {
 			/* if this doesn't do anything we've
 			 * not resolved a command 
 			 */
@@ -207,7 +203,8 @@ clish_command_t *clish_view_resolve_command(clish_view_t * this,
 }
 
 /*--------------------------------------------------------- */
-clish_command_t *clish_view_find_command(clish_view_t * this, const char *name, bool_t inherit)
+clish_command_t *clish_view_find_command(clish_view_t * this,
+	const char *name, bool_t inherit)
 {
 	clish_command_t *cmd, *result = NULL;
 	clish_nspace_t *nspace;
@@ -244,24 +241,21 @@ static const clish_command_t *find_next_completion(clish_view_t * this,
 	largv = lub_argv_new(line, 0);
 	words = lub_argv__get_count(largv);
 
-	if (!*line || lub_ctype_isspace(line[strlen(line) - 1])) {
-		/* account for trailing space */
+	/* account for trailing space */
+	if (!*line || lub_ctype_isspace(line[strlen(line) - 1]))
 		words++;
-	}
 
-	if (NULL != iter_cmd) {
+	if (iter_cmd)
 		name = iter_cmd;
-	}
 	while ((cmd = lub_bintree_findnext(&this->tree, name))) {
 		/* Make command link from command alias */
 		cmd = clish_command_alias_to_link(cmd);
 		name = clish_command__get_name(cmd);
 		if (words == lub_argv_wordcount(name)) {
 			/* only bother with commands of which this line is a prefix */
-			if (lub_string_nocasestr(name, line) == name) {
-				/* this is a completion */
+			/* this is a completion */
+			if (lub_string_nocasestr(name, line) == name)
 				break;
-			}
 		}
 	}
 	/* clean up the dynamic memory */
@@ -272,7 +266,8 @@ static const clish_command_t *find_next_completion(clish_view_t * this,
 
 /*--------------------------------------------------------- */
 const clish_command_t *clish_view_find_next_completion(clish_view_t * this,
-		const char *iter_cmd, const char *line, clish_nspace_visibility_t field, bool_t inherit)
+	const char *iter_cmd, const char *line,
+	clish_nspace_visibility_t field, bool_t inherit)
 {
 	const clish_command_t *result, *cmd;
 	clish_nspace_t *nspace;
@@ -335,7 +330,7 @@ const char *clish_view__get_name(const clish_view_t * this)
 /*--------------------------------------------------------- */
 void clish_view__set_prompt(clish_view_t * this, const char *prompt)
 {
-	assert(NULL == this->prompt);
+	assert(!this->prompt);
 	this->prompt = lub_string_dup(prompt);
 }
 

+ 1 - 1
clish/view/view_dump.c

@@ -25,7 +25,7 @@ void clish_view_dump(clish_view_t * this)
 	/* iterate the tree of commands */
 	c = lub_bintree_findfirst(&this->tree);
 	for (lub_bintree_iterator_init(&iter, &this->tree, c);
-	     c; c = lub_bintree_iterator_next(&iter)) {
+		c; c = lub_bintree_iterator_next(&iter)) {
 		clish_command_dump(c);
 	}