Browse Source

Fix dump functions

Serj Kalichev 10 years ago
parent
commit
99311a8000

+ 3 - 6
clish/action/action_dump.c

@@ -11,12 +11,9 @@ void clish_action_dump(const clish_action_t *this)
 	lub_dump_printf("action(%p)\n", this);
 	lub_dump_indent();
 
-	lub_dump_printf("script  : %s\n",
-		this->script ? this->script : "(null)");
-	lub_dump_printf("builtin : %s\n",
-		this->builtin ? this->builtin : "(null)");
-	lub_dump_printf("shebang : %s\n",
-		this->shebang ? this->shebang : "(null)");
+	lub_dump_printf("script  : %s\n", LUB_DUMP_STR(this->script));
+	lub_dump_printf("builtin : %s\n", LUB_DUMP_STR(this->builtin));
+	lub_dump_printf("shebang : %s\n", LUB_DUMP_STR(this->shebang));
 
 	lub_dump_undent();
 }

+ 10 - 10
clish/command/command_dump.c

@@ -12,16 +12,16 @@ void clish_command_dump(const clish_command_t * this)
 
 	lub_dump_printf("command(%p)\n", this);
 	lub_dump_indent();
-	lub_dump_printf("name        : %s\n", this->name);
-	lub_dump_printf("text        : %s\n", this->text);
-	lub_dump_printf("link        : %s\n",
-		this->link ? clish_command__get_name(this->link) : "(null)");
-	lub_dump_printf("alias       : %s\n", this->alias);
-	lub_dump_printf("alias_view  : %s\n",
-		this->alias_view ? clish_view__get_name(this->alias_view) : "(null)");
-	lub_dump_printf("paramc      : %d\n", clish_paramv__get_count(this->paramv));
-	lub_dump_printf("detail      : %s\n",
-			this->detail ? this->detail : "(null)");
+	lub_dump_printf("name        : %s\n", LUB_DUMP_STR(this->name));
+	lub_dump_printf("text        : %s\n", LUB_DUMP_STR(this->text));
+	lub_dump_printf("link        : %s\n", this->link ?
+		clish_command__get_name(this->link) : LUB_DUMP_NULL );
+	lub_dump_printf("alias       : %s\n", LUB_DUMP_STR(this->alias));
+	lub_dump_printf("alias_view  : %s\n", this->alias_view ?
+		clish_view__get_name(this->alias_view) : LUB_DUMP_NULL);
+	lub_dump_printf("paramc      : %d\n",
+		clish_paramv__get_count(this->paramv));
+	lub_dump_printf("detail      : %s\n", LUB_DUMP_STR(this->detail));
 	clish_action_dump(this->action);
 	clish_config_dump(this->config);
 

+ 1 - 1
clish/hotkey/hotkey_dump.c

@@ -11,7 +11,7 @@ void clish_hotkey_dump(const clish_hotkey_t *this)
 
 	lub_dump_indent();
 	lub_dump_printf("key : %d\n", this->code);
-	lub_dump_printf("cmd : %s\n", this->cmd);
+	lub_dump_printf("cmd : %s\n", LUB_DUMP_STR(this->cmd));
 	lub_dump_undent();
 }
 

+ 5 - 9
clish/nspace/nspace_dump.c

@@ -12,15 +12,11 @@ void clish_nspace_dump(const clish_nspace_t * this)
 	lub_dump_indent();
 	lub_dump_printf("view         : %s\n",
 			clish_view__get_name(this->view));
-	lub_dump_printf("prefix       : %s\n",
-			this->prefix ? this->prefix : "(null)");
-	lub_dump_printf("help         : %s\n", this->help ? "true" : "false");
-	lub_dump_printf("completion   : %s\n",
-			this->completion ? "true" : "false");
-	lub_dump_printf("context_help : %s\n",
-			this->context_help ? "true" : "false");
-	lub_dump_printf("inherit      : %s\n",
-			this->inherit ? "true" : "false");
+	lub_dump_printf("prefix       : %s\n", LUB_DUMP_STR(this->prefix));
+	lub_dump_printf("help         : %s\n", LUB_DUMP_BOOL(this->help));
+	lub_dump_printf("completion   : %s\n", LUB_DUMP_BOOL(this->completion));
+	lub_dump_printf("context_help : %s\n", LUB_DUMP_BOOL(this->context_help));
+	lub_dump_printf("inherit      : %s\n", LUB_DUMP_BOOL(this->inherit));
 	lub_dump_undent();
 }
 

+ 8 - 11
clish/param/param_dump.c

@@ -12,12 +12,11 @@ void clish_param_dump(const clish_param_t * this)
 	lub_dump_printf("param(%p)\n", this);
 
 	lub_dump_indent();
-	lub_dump_printf("name       : %s\n", this->name);
-	lub_dump_printf("text       : %s\n", this->text);
-	lub_dump_printf("value      : %s\n", this->value);
+	lub_dump_printf("name       : %s\n", LUB_DUMP_STR(this->name));
+	lub_dump_printf("text       : %s\n", LUB_DUMP_STR(this->text));
+	lub_dump_printf("value      : %s\n", LUB_DUMP_STR(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)");
+	lub_dump_printf("default    : %s\n", LUB_DUMP_STR(this->defval));
 	switch (this->mode) {
 	case CLISH_PARAM_COMMON:
 		mode = "COMMON";
@@ -34,12 +33,10 @@ 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");
-	lub_dump_printf("hidden     : %s\n",
-		this->hidden ? "true" : "false");
-	lub_dump_printf("test       : %s\n", this->test);
-	lub_dump_printf("completion : %s\n", this->completion);
+	lub_dump_printf("optional   : %s\n", LUB_DUMP_BOOL(this->optional));
+	lub_dump_printf("hidden     : %s\n", LUB_DUMP_BOOL(this->hidden));
+	lub_dump_printf("test       : %s\n", LUB_DUMP_STR(this->test));
+	lub_dump_printf("completion : %s\n", LUB_DUMP_STR(this->completion));
 
 	/* Get each parameter to dump their details */
 	for (i = 0; i < clish_paramv__get_count(this->paramv); i++) {

+ 2 - 2
clish/ptype/ptype_dump.c

@@ -10,8 +10,8 @@ void clish_ptype_dump(clish_ptype_t * this)
 	lub_dump_printf("ptype(%p)\n", this);
 	lub_dump_indent();
 	lub_dump_printf("name       : %s\n", clish_ptype__get_name(this));
-	lub_dump_printf("text       : %s\n", clish_ptype__get_text(this));
-	lub_dump_printf("pattern    : %s\n", this->pattern);
+	lub_dump_printf("text       : %s\n", LUB_DUMP_STR(clish_ptype__get_text(this)));
+	lub_dump_printf("pattern    : %s\n", LUB_DUMP_STR(this->pattern));
 	lub_dump_printf("method     : %s\n",
 		clish_ptype_method__get_name(this->method));
 	lub_dump_printf("postprocess: %s\n",

+ 1 - 1
clish/shell/shell_dump.c

@@ -13,7 +13,7 @@ void clish_shell_dump(clish_shell_t * this)
 	lub_bintree_iterator_t iter;
 
 	lub_dump_printf("shell(%p)\n", this);
-	lub_dump_printf("OVERVIEW:\n%s", this->overview);
+	lub_dump_printf("OVERVIEW:\n%s", LUB_DUMP_STR(this->overview));
 	lub_dump_indent();
 
 	v = lub_bintree_findfirst(&this->view_tree);

+ 3 - 4
clish/var/var_dump.c

@@ -12,10 +12,9 @@ void clish_var_dump(const clish_var_t *this)
 	lub_dump_printf("var(%p)\n", this);
 	lub_dump_indent();
 
-	lub_dump_printf("name     : %s\n", this->name);
-	lub_dump_printf("dynamic  : %s\n",
-		this->dynamic ? "true" : "false");
-	lub_dump_printf("value    : %s\n", this->value);
+	lub_dump_printf("name     : %s\n", LUB_DUMP_STR(this->name));
+	lub_dump_printf("dynamic  : %s\n", LUB_DUMP_BOOL(this->dynamic));
+	lub_dump_printf("value    : %s\n", LUB_DUMP_STR(this->value));
 	clish_action_dump(this->action);
 
 	lub_dump_undent();

+ 1 - 1
configure.ac

@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 m4_define([MAJOR_VERSION], 1)
 m4_define([MINOR_VERSION], 6)
-m4_define([MICRO_VERSION], 6)
+m4_define([MICRO_VERSION], 7)
 
 AC_PREREQ(2.59)
 AC_INIT([klish],

+ 4 - 0
lub/dump.h

@@ -14,6 +14,10 @@ easy.
 #ifndef _lub_dump_h
 #define _lub_dump_h
 
+#define LUB_DUMP_NULL "(null)"
+#define LUB_DUMP_STR(str) ( str ? str : LUB_DUMP_NULL )
+#define LUB_DUMP_BOOL(val) ( val ? "true" : "false" )
+
 #include <stdarg.h>
 /*=====================================
  * DUMP INTERFACE