Bladeren bron

New klish. Remove legacy code. Start refactoring

Serj Kalichev 4 jaren geleden
bovenliggende
commit
0e8fd0078c
100 gewijzigde bestanden met toevoegingen van 0 en 11548 verwijderingen
  1. 0 13
      clish/README
  2. 0 30
      clish/action.h
  3. 0 72
      clish/action/action.c
  4. 0 26
      clish/action/action_dump.c
  5. 0 4
      clish/action/module.am
  6. 0 14
      clish/action/private.h
  7. 0 80
      clish/command.h
  8. 0 305
      clish/command/command.c
  9. 0 41
      clish/command/command_dump.c
  10. 0 4
      clish/command/module.am
  11. 0 27
      clish/command/private.h
  12. 0 42
      clish/config.h
  13. 0 71
      clish/config/config.c
  14. 0 42
      clish/config/config_dump.c
  15. 0 4
      clish/config/module.am
  16. 0 19
      clish/config/private.h
  17. 0 16
      clish/hotkey.h
  18. 0 159
      clish/hotkey/hotkey.c
  19. 0 34
      clish/hotkey/hotkey_dump.c
  20. 0 4
      clish/hotkey/module.am
  21. 0 19
      clish/hotkey/private.h
  22. 0 54
      clish/macros.h
  23. 0 63
      clish/module.am
  24. 0 57
      clish/nspace.h
  25. 0 4
      clish/nspace/module.am
  26. 0 336
      clish/nspace/nspace.c
  27. 0 29
      clish/nspace/nspace_dump.c
  28. 0 23
      clish/nspace/private.h
  29. 0 85
      clish/param.h
  30. 0 5
      clish/param/module.am
  31. 0 189
      clish/param/param.c
  32. 0 53
      clish/param/param_dump.c
  33. 0 147
      clish/param/paramv.c
  34. 0 30
      clish/param/private.h
  35. 0 49
      clish/pargv.h
  36. 0 5
      clish/pargv/module.am
  37. 0 30
      clish/pargv/parg.c
  38. 0 163
      clish/pargv/pargv.c
  39. 0 37
      clish/pargv/pargv_dump.c
  40. 0 16
      clish/pargv/private.h
  41. 0 131
      clish/plugin.h
  42. 0 5
      clish/plugin/module.am
  43. 0 272
      clish/plugin/plugin.c
  44. 0 75
      clish/plugin/plugin_dump.c
  45. 0 33
      clish/plugin/private.h
  46. 0 80
      clish/plugin/sym.c
  47. 0 17
      clish/plugin_builtin.c.in
  48. 0 10
      clish/private.h
  49. 0 97
      clish/ptype.h
  50. 0 4
      clish/ptype/module.am
  51. 0 41
      clish/ptype/private.h
  52. 0 506
      clish/ptype/ptype.c
  53. 0 26
      clish/ptype/ptype_dump.c
  54. 0 235
      clish/shell.h
  55. 0 106
      clish/shell/context.c
  56. 0 28
      clish/shell/module.am
  57. 0 147
      clish/shell/private.h
  58. 0 150
      clish/shell/shell_command.c
  59. 0 48
      clish/shell/shell_dump.c
  60. 0 445
      clish/shell/shell_execute.c
  61. 0 539
      clish/shell/shell_expat.c
  62. 0 94
      clish/shell/shell_file.c
  63. 0 168
      clish/shell/shell_help.c
  64. 0 376
      clish/shell/shell_libxml2.c
  65. 0 56
      clish/shell/shell_loop.c
  66. 0 10
      clish/shell/shell_misc.c
  67. 0 182
      clish/shell/shell_new.c
  68. 0 324
      clish/shell/shell_parse.c
  69. 0 237
      clish/shell/shell_plugin.c
  70. 0 50
      clish/shell/shell_ptype.c
  71. 0 183
      clish/shell/shell_pwd.c
  72. 0 358
      clish/shell/shell_roxml.c
  73. 0 341
      clish/shell/shell_startup.c
  74. 0 602
      clish/shell/shell_tinyrl.c
  75. 0 95
      clish/shell/shell_udata.c
  76. 0 539
      clish/shell/shell_var.c
  77. 0 59
      clish/shell/shell_view.c
  78. 0 66
      clish/shell/shell_wdog.c
  79. 0 1317
      clish/shell/shell_xml.c
  80. 0 242
      clish/shell/xmlapi.h
  81. 0 18
      clish/types.h
  82. 0 28
      clish/udata.h
  83. 0 3
      clish/udata/module.am
  84. 0 10
      clish/udata/private.h
  85. 0 64
      clish/udata/udata.c
  86. 0 26
      clish/var.h
  87. 0 4
      clish/var/module.am
  88. 0 17
      clish/var/private.h
  89. 0 83
      clish/var/var.c
  90. 0 27
      clish/var/var_dump.c
  91. 0 66
      clish/view.h
  92. 0 4
      clish/view/module.am
  93. 0 18
      clish/view/private.h
  94. 0 324
      clish/view/view.c
  95. 0 44
      clish/view/view_dump.c
  96. 0 43
      contrib/README
  97. 0 16
      contrib/buildroot-2010.11/Config.in
  98. 0 21
      contrib/buildroot-2010.11/klish.mk
  99. 0 8
      contrib/buildroot-2014.08/Config.in
  100. 0 29
      contrib/buildroot-2014.08/klish.mk

+ 0 - 13
clish/README

@@ -1,13 +0,0 @@
-/**
-\defgroup clish "CLI Shell" Library
-@{
-
-This library provides the core functionality for a shell to implement a 
-CISCO-like user interface. The look and feel is fully defined by a set of XML
-files which are loaded when the shell starts up.
-
-The schema for these XML files can be found in 
-http://clish.sourceforge.net/XMLSchema/clish.xsd
-
-@}
-*/

+ 0 - 30
clish/action.h

@@ -1,30 +0,0 @@
-/*
- * action.h
- */
-
-#ifndef _clish_action_h
-#define _clish_action_h
-
-typedef struct clish_action_s clish_action_t;
-
-#include "clish/macros.h"
-#include "clish/plugin.h"
-
-clish_action_t *clish_action_new(void);
-void clish_action_delete(clish_action_t *instance);
-void clish_action_dump(const clish_action_t *instance);
-
-_CLISH_SET_STR(action, script);
-_CLISH_GET_STR(action, script);
-_CLISH_SET(action, const clish_sym_t *, builtin);
-_CLISH_GET(action, const clish_sym_t *, builtin);
-_CLISH_SET_STR(action, shebang);
-_CLISH_GET_STR(action, shebang);
-_CLISH_SET(action, bool_t, lock);
-_CLISH_GET(action, bool_t, lock);
-_CLISH_SET(action, bool_t, interrupt);
-_CLISH_GET(action, bool_t, interrupt);
-_CLISH_SET(action, bool_t, interactive);
-_CLISH_GET(action, bool_t, interactive);
-
-#endif // _clish_action_h

+ 0 - 72
clish/action/action.c

@@ -1,72 +0,0 @@
-/*
- * action.c
- *
- * This file provides the implementation of a action definition
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include "private.h"
-#include "lub/string.h"
-
-/*--------------------------------------------------------- */
-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;
-}
-
-/*--------------------------------------------------------- */
-static void clish_action_fini(clish_action_t *this)
-{
-	lub_string_free(this->script);
-	lub_string_free(this->shebang);
-}
-
-/*--------------------------------------------------------- */
-clish_action_t *clish_action_new(void)
-{
-	clish_action_t *this = malloc(sizeof(clish_action_t));
-
-	if (this)
-		clish_action_init(this);
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_action_delete(clish_action_t *this)
-{
-	clish_action_fini(this);
-	free(this);
-}
-
-CLISH_SET_STR(action, script);
-CLISH_GET_STR(action, script);
-CLISH_SET(action, const clish_sym_t *, builtin);
-CLISH_GET(action, const clish_sym_t *, builtin);
-CLISH_SET(action, bool_t, lock);
-CLISH_GET(action, bool_t, lock);
-CLISH_SET(action, bool_t, interrupt);
-CLISH_GET(action, bool_t, interrupt);
-CLISH_SET(action, bool_t, interactive);
-CLISH_GET(action, bool_t, interactive);
-
-_CLISH_SET_STR(action, shebang)
-{
-	const char *prog = val;
-	const char *prefix = "#!";
-
-	lub_string_free(inst->shebang);
-	if (lub_string_nocasestr(val, prefix) == val)
-		prog += strlen(prefix);
-	inst->shebang = lub_string_dup(prog);
-}
-
-CLISH_GET_STR(action, shebang);

+ 0 - 26
clish/action/action_dump.c

@@ -1,26 +0,0 @@
-#ifdef DEBUG
-
-/*
- * action_dump.c
- */
-
-#include "lub/dump.h"
-#include "private.h"
-
-/*--------------------------------------------------------- */
-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", LUB_DUMP_STR(this->script));
-	lub_dump_printf("builtin : %s\n",
-		this->builtin ? clish_sym__get_name(this->builtin) : LUB_DUMP_NULL );
-	lub_dump_printf("shebang : %s\n", LUB_DUMP_STR(this->shebang));
-
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 4
clish/action/module.am

@@ -1,4 +0,0 @@
-libclish_la_SOURCES += \
-	clish/action/action.c \
-	clish/action/action_dump.c \
-	clish/action/private.h

+ 0 - 14
clish/action/private.h

@@ -1,14 +0,0 @@
-/*
- * action.h
- */
-
-#include "clish/action.h"
-
-struct clish_action_s {
-	char *script;
-	const clish_sym_t *builtin;
-	char *shebang;
-	bool_t lock;
-	bool_t interrupt;
-	bool_t interactive;
-};

+ 0 - 80
clish/command.h

@@ -1,80 +0,0 @@
-/*
- * command.h
- */
-
-#ifndef _clish_command_h
-#define _clish_command_h
-
-typedef struct clish_command_s clish_command_t;
-
-#include "lub/bintree.h"
-#include "lub/argv.h"
-#include "clish/types.h"
-#include "clish/macros.h"
-#include "clish/pargv.h"
-#include "clish/view.h"
-#include "clish/param.h"
-#include "clish/action.h"
-#include "clish/config.h"
-
-clish_command_t *clish_command_new(const char *name, const char *help);
-clish_command_t *clish_command_new_link(const char *name,
-	const char *help, const clish_command_t * ref);
-clish_command_t * clish_command_alias_to_link(clish_command_t *instance, clish_command_t *ref);
-
-int clish_command_bt_compare(const void *clientnode, const void *clientkey);
-void clish_command_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
-size_t clish_command_bt_offset(void);
-clish_command_t *clish_command_choose_longest(clish_command_t * cmd1,
-	clish_command_t * cmd2);
-int
-clish_command_diff(const clish_command_t * cmd1, const clish_command_t * cmd2);
-
-void clish_command_delete(clish_command_t *instance);
-void clish_command_insert_param(clish_command_t *instance,
-	clish_param_t *param);
-int clish_command_help(const clish_command_t *instance);
-void clish_command_dump(const clish_command_t *instance);
-
-_CLISH_GET_STR(command, name);
-_CLISH_GET_STR(command, text);
-_CLISH_SET_STR_ONCE(command, detail);
-_CLISH_GET_STR(command, detail);
-_CLISH_GET(command, clish_action_t *, action);
-_CLISH_GET(command, clish_config_t *, config);
-_CLISH_SET_STR_ONCE(command, regex_chars);
-_CLISH_GET_STR(command, regex_chars);
-_CLISH_SET_STR_ONCE(command, escape_chars);
-_CLISH_GET_STR(command, escape_chars);
-_CLISH_SET_STR_ONCE(command, viewname);
-_CLISH_GET_STR(command, viewname);
-_CLISH_SET_STR_ONCE(command, viewid);
-_CLISH_GET_STR(command, viewid);
-_CLISH_SET_ONCE(command, clish_param_t *, args);
-_CLISH_GET(command, clish_param_t *, args);
-_CLISH_GET(command, clish_paramv_t *, paramv);
-_CLISH_SET(command, clish_view_t *, pview);
-_CLISH_GET(command, clish_view_t *, pview);
-_CLISH_SET_STR(command, access);
-_CLISH_GET_STR(command, access);
-_CLISH_SET_STR(command, alias);
-_CLISH_GET_STR(command, alias);
-_CLISH_SET_STR(command, alias_view);
-_CLISH_GET_STR(command, alias_view);
-_CLISH_SET(command, bool_t, internal);
-_CLISH_GET(command, bool_t, internal);
-_CLISH_SET(command, bool_t, dynamic);
-_CLISH_GET(command, bool_t, dynamic);
-
-const char *clish_command__get_suffix(const clish_command_t * instance);
-unsigned int clish_command__get_param_count(const clish_command_t * instance);
-const clish_param_t *clish_command__get_param(const clish_command_t * instance,
-	unsigned index);
-void clish_command__force_viewname(clish_command_t * instance, const char *viewname);
-void clish_command__force_viewid(clish_command_t * instance, const char *viewid);
-int clish_command__get_depth(const clish_command_t * instance);
-clish_view_restore_e clish_command__get_restore(const clish_command_t * instance);
-const clish_command_t * clish_command__get_orig(const clish_command_t * instance);
-const clish_command_t * clish_command__get_cmd(const clish_command_t * instance);
-
-#endif				/* _clish_command_h */

+ 0 - 305
clish/command/command.c

@@ -1,305 +0,0 @@
-/*
-  * command.c
-  *
-  * This file provides the implementation of a command definition  
-  */
-
-#include "private.h"
-#include "clish/types.h"
-#include "lub/bintree.h"
-#include "lub/string.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-static void
-clish_command_init(clish_command_t *this, const char *name, const char *text)
-{
-	/* initialise the node part */
-	this->name = lub_string_dup(name);
-	this->text = lub_string_dup(text);
-
-	/* Be a good binary tree citizen */
-	lub_bintree_node_init(&this->bt_node);
-
-	/* set up defaults */
-	this->link = NULL;
-	this->alias = NULL;
-	this->alias_view = NULL;
-	this->paramv = clish_paramv_new();
-	this->viewid = NULL;
-	this->viewname = NULL;
-	this->action = clish_action_new();
-	this->config = clish_config_new();
-	this->detail = NULL;
-	this->escape_chars = NULL;
-	this->regex_chars = NULL;
-	this->args = NULL;
-	this->pview = NULL;
-	this->dynamic = BOOL_FALSE;
-	this->internal = BOOL_FALSE;
-	this->access = NULL;
-}
-
-/*--------------------------------------------------------- */
-static void clish_command_fini(clish_command_t * this)
-{
-	lub_string_free(this->name);
-	lub_string_free(this->text);
-
-	/* Link need not full cleanup */
-	if (this->link)
-		return;
-
-	/* finalize each of the parameter instances */
-	clish_paramv_delete(this->paramv);
-
-	clish_action_delete(this->action);
-	clish_config_delete(this->config);
-	lub_string_free(this->alias);
-	lub_string_free(this->alias_view);
-	lub_string_free(this->viewname);
-	lub_string_free(this->viewid);
-	lub_string_free(this->detail);
-	lub_string_free(this->escape_chars);
-	lub_string_free(this->regex_chars);
-	lub_string_free(this->access);
-	if (this->args)
-		clish_param_delete(this->args);
-}
-
-/*--------------------------------------------------------- */
-size_t clish_command_bt_offset(void)
-{
-	return offsetof(clish_command_t, bt_node);
-}
-
-/*--------------------------------------------------------- */
-int clish_command_bt_compare(const void *clientnode, const void *clientkey)
-{
-	const clish_command_t *this = clientnode;
-	const char *key = clientkey;
-
-	return lub_string_nocasecmp(this->name, key);
-}
-
-/*--------------------------------------------------------- */
-void clish_command_bt_getkey(const void *clientnode, lub_bintree_key_t * key)
-{
-	const clish_command_t *this = clientnode;
-
-	/* fill out the opaque key */
-	strcpy((char *)key, this->name);
-}
-
-/*--------------------------------------------------------- */
-clish_command_t *clish_command_new(const char *name, const char *help)
-{
-	clish_command_t *this = malloc(sizeof(clish_command_t));
-
-	if (this)
-		clish_command_init(this, name, help);
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-clish_command_t *clish_command_new_link(const char *name,
-	const char *help, const clish_command_t * ref)
-{
-	if (!ref)
-		return NULL;
-
-	clish_command_t *this = malloc(sizeof(clish_command_t));
-	assert(this);
-
-	/* Copy all fields to the new command-link */
-	*this = *ref;
-	/* Initialise the name (other than original name) */
-	this->name = lub_string_dup(name);
-	/* Initialise the help (other than original help) */
-	this->text = lub_string_dup(help);
-	/* Be a good binary tree citizen */
-	lub_bintree_node_init(&this->bt_node);
-	/* It a link to command so set the link flag */
-	this->link = ref;
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-clish_command_t * clish_command_alias_to_link(clish_command_t *this, clish_command_t *ref)
-{
-	clish_command_t tmp;
-
-	if (!this || !ref)
-		return NULL;
-	if (ref->alias) /* The reference is a link too */
-		return NULL;
-	memcpy(&tmp, this, sizeof(tmp));
-	*this = *ref;
-	memcpy(&this->bt_node, &tmp.bt_node, sizeof(tmp.bt_node));
-	this->name = lub_string_dup(tmp.name); /* Save an original name */
-	this->text = lub_string_dup(tmp.text); /* Save an original help */
-	this->link = ref;
-	this->pview = tmp.pview; /* Save an original parent view */
-	clish_command_fini(&tmp);
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_command_delete(clish_command_t * this)
-{
-	clish_command_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-void clish_command_insert_param(clish_command_t * this, clish_param_t * param)
-{
-	clish_paramv_insert(this->paramv, param);
-}
-
-/*--------------------------------------------------------- */
-int clish_command_help(const clish_command_t *this)
-{
-	this = this; /* Happy compiler */
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-clish_command_t *clish_command_choose_longest(clish_command_t * cmd1,
-	clish_command_t * cmd2)
-{
-	unsigned len1 = (cmd1 ? strlen(clish_command__get_name(cmd1)) : 0);
-	unsigned len2 = (cmd2 ? strlen(clish_command__get_name(cmd2)) : 0);
-
-	if (len2 < len1) {
-		return cmd1;
-	} else if (len1 < len2) {
-		return cmd2;
-	} else {
-		/* let local view override */
-		return cmd1;
-	}
-}
-
-/*--------------------------------------------------------- */
-int clish_command_diff(const clish_command_t * cmd1,
-	const clish_command_t * cmd2)
-{
-	if (NULL == cmd1) {
-		if (NULL != cmd2)
-			return 1;
-		else
-			return 0;
-	}
-	if (NULL == cmd2)
-		return -1;
-
-	return lub_string_nocasecmp(clish_command__get_name(cmd1),
-		clish_command__get_name(cmd2));
-}
-
-CLISH_GET_STR(command, name);
-CLISH_GET_STR(command, text);
-CLISH_SET_STR_ONCE(command, detail);
-CLISH_GET_STR(command, detail);
-CLISH_GET(command, clish_action_t *, action);
-CLISH_GET(command, clish_config_t *, config);
-CLISH_SET_STR_ONCE(command, regex_chars);
-CLISH_GET_STR(command, regex_chars);
-CLISH_SET_STR_ONCE(command, escape_chars);
-CLISH_GET_STR(command, escape_chars);
-CLISH_SET_STR_ONCE(command, viewname);
-CLISH_GET_STR(command, viewname);
-CLISH_SET_STR_ONCE(command, viewid);
-CLISH_GET_STR(command, viewid);
-CLISH_SET_ONCE(command, clish_param_t *, args);
-CLISH_GET(command, clish_param_t *, args);
-CLISH_GET(command, clish_paramv_t *, paramv);
-CLISH_SET(command, clish_view_t *, pview);
-CLISH_GET(command, clish_view_t *, pview);
-CLISH_SET_STR(command, access);
-CLISH_GET_STR(command, access);
-CLISH_SET_STR(command, alias);
-CLISH_GET_STR(command, alias);
-CLISH_SET_STR(command, alias_view);
-CLISH_GET_STR(command, alias_view);
-CLISH_SET(command, bool_t, internal);
-CLISH_GET(command, bool_t, internal);
-CLISH_SET(command, bool_t, dynamic);
-CLISH_GET(command, bool_t, dynamic);
-
-/*--------------------------------------------------------- */
-void clish_command__force_viewname(clish_command_t * this, const char *viewname)
-{
-	if (this->viewname)
-		lub_string_free(this->viewname);
-	this->viewname = lub_string_dup(viewname);
-}
-
-/*--------------------------------------------------------- */
-void clish_command__force_viewid(clish_command_t * this, const char *viewid)
-{
-	if (this->viewid)
-		lub_string_free(this->viewid);
-	this->viewid = lub_string_dup(viewid);
-}
-
-/*--------------------------------------------------------- */
-const clish_param_t *clish_command__get_param(const clish_command_t * this,
-	unsigned index)
-{
-	return clish_paramv__get_param(this->paramv, index);
-}
-
-/*--------------------------------------------------------- */
-const char *clish_command__get_suffix(const clish_command_t * this)
-{
-	return lub_string_suffix(this->name);
-}
-
-/*--------------------------------------------------------- */
-unsigned int clish_command__get_param_count(const clish_command_t * this)
-{
-	return clish_paramv__get_count(this->paramv);
-}
-
-/*--------------------------------------------------------- */
-int clish_command__get_depth(const clish_command_t * this)
-{
-	if (!this->pview)
-		return 0;
-	return clish_view__get_depth(this->pview);
-}
-
-/*--------------------------------------------------------- */
-clish_view_restore_e clish_command__get_restore(const clish_command_t * this)
-{
-	if (!this->pview)
-		return CLISH_RESTORE_NONE;
-	return clish_view__get_restore(this->pview);
-}
-
-/*--------------------------------------------------------- */
-const clish_command_t * clish_command__get_orig(const clish_command_t * this)
-{
-	if (this->link)
-		return clish_command__get_orig(this->link);
-	return this;
-}
-
-/*--------------------------------------------------------- */
-const clish_command_t * clish_command__get_cmd(const clish_command_t * this)
-{
-	if (!this->dynamic)
-		return this;
-	if (this->link)
-		return clish_command__get_cmd(this->link);
-	return NULL;
-}

+ 0 - 41
clish/command/command_dump.c

@@ -1,41 +0,0 @@
-#ifdef DEBUG
-
-/*
- * command_dump.c
- */
-
-#include "lub/dump.h"
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void clish_command_dump(const clish_command_t * this)
-{
-	unsigned i;
-
-	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) : LUB_DUMP_NULL);
-	lub_dump_printf("alias      : %s\n", LUB_DUMP_STR(this->alias));
-	lub_dump_printf("alias_view : %s\n", LUB_DUMP_STR(this->alias_view));
-	lub_dump_printf("paramc     : %d\n",
-		clish_paramv__get_count(this->paramv));
-	lub_dump_printf("detail     : %s\n", LUB_DUMP_STR(this->detail));
-	lub_dump_printf("access     : %s\n", LUB_DUMP_STR(this->access));
-	clish_action_dump(this->action);
-	clish_config_dump(this->config);
-
-	/* Get each parameter to dump their details */
-	for (i = 0; i < clish_paramv__get_count(this->paramv); i++) {
-		clish_param_dump(clish_command__get_param(this, i));
-	}
-
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 4
clish/command/module.am

@@ -1,4 +0,0 @@
-libclish_la_SOURCES += \
-	clish/command/command.c \
-	clish/command/command_dump.c \
-	clish/command/private.h

+ 0 - 27
clish/command/private.h

@@ -1,27 +0,0 @@
-/*
- * command.h
- */
-
-#include "clish/command.h"
-
-struct clish_command_s {
-	lub_bintree_node_t bt_node;
-	char *name;
-	char *text;
-	clish_paramv_t *paramv;
-	clish_action_t *action;
-	clish_config_t *config;
-	char *viewname;
-	char *viewid;
-	char *detail;
-	char *escape_chars;
-	char *regex_chars;
-	char *access;
-	clish_param_t *args;
-	const struct clish_command_s *link;
-	char *alias_view;
-	char *alias;
-	clish_view_t *pview;
-	bool_t dynamic; /* Is command dynamically created */
-	bool_t internal; /* Is command internal? Like the "startup" */
-};

+ 0 - 42
clish/config.h

@@ -1,42 +0,0 @@
-/*
- * config.h
- */
-#ifndef _clish_config_h
-#define _clish_config_h
-
-#include "clish/macros.h"
-#include "lub/types.h"
-
-typedef struct clish_config_s clish_config_t;
-
-/* Possible CONFIG operations */
-typedef enum {
-	CLISH_CONFIG_NONE,
-	CLISH_CONFIG_SET,
-	CLISH_CONFIG_UNSET,
-	CLISH_CONFIG_DUMP
-} clish_config_op_e;
-
-clish_config_t *clish_config_new(void);
-
-void clish_config_delete(clish_config_t *instance);
-void clish_config_dump(const clish_config_t *instance);
-
-_CLISH_SET(config, clish_config_op_e, op);
-_CLISH_GET(config, clish_config_op_e, op);
-_CLISH_SET(config, unsigned short, priority);
-_CLISH_GET(config, unsigned short, priority);
-_CLISH_SET(config, bool_t, splitter);
-_CLISH_GET(config, bool_t, splitter);
-_CLISH_SET(config, bool_t, unique);
-_CLISH_GET(config, bool_t, unique);
-_CLISH_SET_STR_ONCE(config, pattern);
-_CLISH_GET_STR(config, pattern);
-_CLISH_SET_STR_ONCE(config, file);
-_CLISH_GET_STR(config, file);
-_CLISH_SET_STR_ONCE(config, seq);
-_CLISH_GET_STR(config, seq);
-_CLISH_SET_STR_ONCE(config, depth);
-_CLISH_GET_STR(config, depth);
-
-#endif				/* _clish_config_h */

+ 0 - 71
clish/config/config.c

@@ -1,71 +0,0 @@
-/*
-  * config.c
-  *
-  * This file provides the implementation of a config definition
-  */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-#include "lub/types.h"
-#include "lub/string.h"
-#include "private.h"
-
-/*--------------------------------------------------------- */
-static void clish_config_init(clish_config_t *this)
-{
-	this->op = CLISH_CONFIG_NONE;
-	this->priority = 0;
-	this->pattern = NULL;
-	this->file = NULL;
-	this->splitter = BOOL_TRUE;
-	this->seq = NULL;
-	this->unique = BOOL_TRUE;
-	this->depth = NULL;
-}
-
-/*--------------------------------------------------------- */
-static void clish_config_fini(clish_config_t *this)
-{
-	lub_string_free(this->pattern);
-	lub_string_free(this->file);
-	lub_string_free(this->seq);
-	lub_string_free(this->depth);
-}
-
-/*--------------------------------------------------------- */
-clish_config_t *clish_config_new(void)
-{
-	clish_config_t *this = malloc(sizeof(clish_config_t));
-
-	if (this)
-		clish_config_init(this);
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_config_delete(clish_config_t *this)
-{
-	clish_config_fini(this);
-	free(this);
-}
-
-CLISH_SET(config, clish_config_op_e, op);
-CLISH_GET(config, clish_config_op_e, op);
-CLISH_SET(config, unsigned short, priority);
-CLISH_GET(config, unsigned short, priority);
-CLISH_SET(config, bool_t, splitter);
-CLISH_GET(config, bool_t, splitter);
-CLISH_SET(config, bool_t, unique);
-CLISH_GET(config, bool_t, unique);
-CLISH_SET_STR_ONCE(config, pattern);
-CLISH_GET_STR(config, pattern);
-CLISH_SET_STR_ONCE(config, file);
-CLISH_GET_STR(config, file);
-CLISH_SET_STR_ONCE(config, seq);
-CLISH_GET_STR(config, seq);
-CLISH_SET_STR_ONCE(config, depth);
-CLISH_GET_STR(config, depth);

+ 0 - 42
clish/config/config_dump.c

@@ -1,42 +0,0 @@
-#ifdef DEBUG
-
-/*
- * config_dump.c
- */
-
-#include "lub/dump.h"
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void clish_config_dump(const clish_config_t *this)
-{
-	char *op;
-
-	lub_dump_printf("config(%p)\n", this);
-	lub_dump_indent();
-
-	switch (this->op) {
-	case CLISH_CONFIG_NONE:
-		op = "NONE";
-		break;
-	case CLISH_CONFIG_SET:
-		op = "SET";
-		break;
-	case CLISH_CONFIG_UNSET:
-		op = "UNSET";
-		break;
-	case CLISH_CONFIG_DUMP:
-		op = "DUMP";
-		break;
-	default:
-		op = "Unknown";
-		break;
-	}
-	lub_dump_printf("op      : %s\n", op);
-
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 4
clish/config/module.am

@@ -1,4 +0,0 @@
-libclish_la_SOURCES += \
-	clish/config/config.c \
-	clish/config/config_dump.c \
-	clish/config/private.h

+ 0 - 19
clish/config/private.h

@@ -1,19 +0,0 @@
-/*
- * clish/config/private.h
- */
-
-#include "clish/config.h"
-
-/*---------------------------------------------------------
- * PRIVATE TYPES
- *--------------------------------------------------------- */
-struct clish_config_s {
-	clish_config_op_e op; /* CONFIG operation */
-	unsigned short priority;
-	char *pattern;
-	char *file;
-	bool_t splitter;
-	char *seq;
-	bool_t unique;
-	char *depth;
-};

+ 0 - 16
clish/hotkey.h

@@ -1,16 +0,0 @@
-/*
- * hotkey.h
- */
-#ifndef _clish_hotkey_h
-#define _clish_hotkey_h
-
-typedef struct clish_hotkey_s clish_hotkey_t;
-typedef struct clish_hotkeyv_s clish_hotkeyv_t;
-
-const char *clish_hotkeyv_cmd_by_code(clish_hotkeyv_t *instance, int code);
-int clish_hotkeyv_insert(clish_hotkeyv_t *instance,
-	const char *key, const char *cmd);
-clish_hotkeyv_t *clish_hotkeyv_new(void);
-void clish_hotkeyv_delete(clish_hotkeyv_t *instance);
-
-#endif				/* _clish_hotkey_h */

+ 0 - 159
clish/hotkey/hotkey.c

@@ -1,159 +0,0 @@
-/*
- * hotkey.c
- */
-#include "private.h"
-#include "lub/string.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-
-/* Symbolic key codes */
-const char *clish_hotkey_list[] = {
-	"^@", /* 0 Null character */
-	"^A", /* 1 Start of heading, = console interrupt */
-	"^B", /* 2 Start of text, maintenance mode on HP console */
-	"^C", /* 3 End of text */
-	"^D", /* 4 End of transmission, not the same as ETB */
-	"^E", /* 5 Enquiry, goes with ACK; old HP flow control */
-	"^F", /* 6 Acknowledge, clears ENQ logon hand */
-	"^G", /* 7 Bell, rings the bell... */
-	"^H", /* 8 Backspace, works on HP terminals/computers */
-	"^I", /* 9 Horizontal tab, move to next tab stop */
-	"^J", /* 10 Line Feed */
-	"^K", /* 11 Vertical tab */
-	"^L", /* 12 Form Feed, page eject */
-	"^M", /* 13 Carriage Return*/
-	"^N", /* 14 Shift Out, alternate character set */
-	"^O", /* 15 Shift In, resume defaultn character set */
-	"^P", /* 16 Data link escape */
-	"^Q", /* 17 XON, with XOFF to pause listings; "okay to send". */
-	"^R", /* 18 Device control 2, block-mode flow control */
-	"^S", /* 19 XOFF, with XON is TERM=18 flow control */
-	"^T", /* 20 Device control 4 */
-	"^U", /* 21 Negative acknowledge */
-	"^V", /* 22 Synchronous idle */
-	"^W", /* 23 End transmission block, not the same as EOT */
-	"^X", /* 24 Cancel line, MPE echoes !!! */
-	"^Y", /* 25 End of medium, Control-Y interrupt */
-	"^Z", /* 26 Substitute */
-	"^[", /* 27 Escape, next character is not echoed */
-	"^\\", /* 28 File separator */
-	"^]", /* 29 Group separator */
-	"^^", /* 30 Record separator, block-mode terminator */
-	"^_",  /* 31 Unit separator */
-	NULL
-	};
-
-/*--------------------------------------------------------- */
-/* Search for the specified hotkey and return its hotkey structure */
-static clish_hotkey_t *find_hotkey(clish_hotkeyv_t *this, int code)
-{
-	unsigned int i;
-	clish_hotkey_t *result = NULL;
-
-	if (!this)
-		return NULL;
-
-	/* Scan the hotkey entries in this instance */
-	for (i = 0; i < this->num; i++) {
-		clish_hotkey_t *hk = this->hotkeyv[i];
-		if (code == hk->code) {
-			result = hk;
-			break;
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */
-const char *clish_hotkeyv_cmd_by_code(clish_hotkeyv_t *this, int code)
-{
-	clish_hotkey_t *hk;
-	if (!this)
-		return NULL;
-	hk = find_hotkey(this, code);
-	if (!hk)
-		return NULL;
-	return hk->cmd;
-}
-
-/*--------------------------------------------------------- */
-int clish_hotkeyv_insert(clish_hotkeyv_t *this,
-	const char *key, const char *cmd)
-{
-	int code = -1;
-	int i;
-	if (!this)
-		return -1;
-
-	/* Find out key code */
-	i = 0;
-	while (clish_hotkey_list[i]) {
-		if (!strcmp(clish_hotkey_list[i], key))
-			code = i;
-		i++;
-	}
-	if (code < 0)
-		return -1;
-
-	/* Search for existance of such hotkey */
-	clish_hotkey_t *hk = find_hotkey(this, code);
-	if (hk) {
-		/* release the current value */
-		lub_string_free(hk->cmd);
-	} else {
-		size_t new_size = ((this->num + 1) * sizeof(clish_hotkey_t *));
-		clish_hotkey_t **tmp;
-		/* resize the hotkeys vector */
-		tmp = realloc(this->hotkeyv, new_size);
-	
-		this->hotkeyv = tmp;
-		/* insert reference to the parameter */
-		hk = malloc(sizeof(*hk));
-		this->hotkeyv[this->num++] = hk;
-		hk->code = code;
-	}
-	hk->cmd = NULL;
-	if (cmd)
-		hk->cmd = lub_string_dup(cmd);
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-clish_hotkeyv_t *clish_hotkeyv_new(void)
-{
-	clish_hotkeyv_t *this;
-
-	this = malloc(sizeof(clish_hotkeyv_t));
-	this->num = 0;
-	this->hotkeyv = NULL;
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-static void clish_hotkeyv_fini(clish_hotkeyv_t *this)
-{
-	unsigned int i;
-
-	for (i = 0; i < this->num; i++) {
-		lub_string_free(this->hotkeyv[i]->cmd);
-		free(this->hotkeyv[i]);
-	}
-	free(this->hotkeyv);
-}
-
-/*--------------------------------------------------------- */
-void clish_hotkeyv_delete(clish_hotkeyv_t *this)
-{
-	if (!this)
-		return;
-
-	clish_hotkeyv_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 34
clish/hotkey/hotkey_dump.c

@@ -1,34 +0,0 @@
-#ifdef DEBUG
-
-/*
- * hotkey_dump.c
- */
-#include "private.h"
-#include "lub/dump.h"
-
-/*--------------------------------------------------------- */
-void clish_hotkey_dump(const clish_hotkey_t *this)
-{
-	lub_dump_printf("hotkey(%p)\n", this);
-
-	lub_dump_indent();
-	lub_dump_printf("key : %d\n", this->code);
-	lub_dump_printf("cmd : %s\n", LUB_DUMP_STR(this->cmd));
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-void clish_hotkeyv_dump(const clish_hotkeyv_t *this)
-{
-	unsigned int i;
-
-	lub_dump_printf("hotkeyv(%p)\n", this);
-	lub_dump_indent();
-	for (i = 0; i < this->num; i++)
-		clish_hotkey_dump(this->hotkeyv[i]);
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 4
clish/hotkey/module.am

@@ -1,4 +0,0 @@
-libclish_la_SOURCES += \
-	clish/hotkey/hotkey.c \
-	clish/hotkey/hotkey_dump.c \
-	clish/hotkey/private.h

+ 0 - 19
clish/hotkey/private.h

@@ -1,19 +0,0 @@
-/*
- * hotkey private.h
- */
-
-#include "clish/hotkey.h"
-
-/*---------------------------------------------------------
- * PRIVATE TYPES
- *--------------------------------------------------------- */
-
-struct clish_hotkey_s {
-	int code; /* Hotkey code */
-	char *cmd; /* Command to execute on this hotkey */
-};
-
-struct clish_hotkeyv_s {
-	unsigned int num;
-	clish_hotkey_t **hotkeyv;
-};

+ 0 - 54
clish/macros.h

@@ -1,54 +0,0 @@
-/* Macros for simplifying to write subsystem's service functions */
-
-#ifndef _clish_macros_h
-#define _clish_macros_h
-
-#include <assert.h>
-
-/* Function to get value from structure by name */
-#define _CLISH_GET(obj, type, name) \
-	type clish_##obj##__get_##name(const clish_##obj##_t *inst)
-#define CLISH_GET(obj, type, name) \
-	_CLISH_GET(obj, type, name) { \
-		assert(inst); \
-		return inst->name; \
-	}
-#define _CLISH_GET_STR(obj, name) \
-	_CLISH_GET(obj, const char *, name)
-#define CLISH_GET_STR(obj, name) \
-	CLISH_GET(obj, const char *, name)
-
-/* Function to set value to structure by name */
-#define _CLISH_SET(obj, type, name) \
-	void clish_##obj##__set_##name(clish_##obj##_t *inst, type val)
-#define CLISH_SET(obj, type, name) \
-	_CLISH_SET(obj, type, name) { \
-		assert(inst); \
-		inst->name = val; \
-	}
-#define _CLISH_SET_ONCE(obj, type, name) \
-	_CLISH_SET(obj, type, name)
-#define CLISH_SET_ONCE(obj, type, name) \
-	_CLISH_SET_ONCE(obj, type, name) { \
-		assert(inst); \
-		assert(!inst->name); \
-		inst->name = val; \
-	}
-#define _CLISH_SET_STR(obj, name) \
-	_CLISH_SET(obj, const char *, name)
-#define CLISH_SET_STR(obj, name) \
-	_CLISH_SET_STR(obj, name) { \
-		assert(inst); \
-		lub_string_free(inst->name); \
-		inst->name = lub_string_dup(val); \
-	}
-#define _CLISH_SET_STR_ONCE(obj, name) \
-	_CLISH_SET_STR(obj, name)
-#define CLISH_SET_STR_ONCE(obj, name) \
-	_CLISH_SET_STR_ONCE(obj, name) { \
-		assert(inst); \
-		assert(!inst->name); \
-		inst->name = lub_string_dup(val); \
-	}
-
-#endif // _clish_macros_h

+ 0 - 63
clish/module.am

@@ -1,63 +0,0 @@
-## Process this file with automake to produce Makefile.in
-lib_LTLIBRARIES += libclish.la
-
-libclish_la_SOURCES = \
-	clish/plugin_builtin.c \
-	clish/private.h
-
-libclish_la_LDFLAGS = $(VERSION_INFO) @XML_LDFLAGS@
-libclish_la_CFLAGS = @XML_CFLAGS@ $(DEBUG_CFLAGS) $(LEGACY_CFLAGS)
-libclish_la_DEPENDENCIES = \
-	liblub.la \
-	libtinyrl.la \
-	libkonf.la
-libclish_la_LIBADD = \
-	$(libclish_la_DEPENDENCIES) \
-	@XML_LIBS@
-
-nobase_include_HEADERS += \
-	clish/types.h \
-	clish/macros.h \
-	clish/command.h \
-	clish/param.h \
-	clish/pargv.h \
-	clish/ptype.h \
-	clish/shell.h \
-	clish/view.h \
-	clish/nspace.h \
-	clish/var.h \
-	clish/action.h \
-	clish/config.h \
-	clish/hotkey.h \
-	clish/plugin.h \
-	clish/udata.h
-
-EXTRA_DIST += \
-	clish/command/module.am \
-	clish/param/module.am \
-	clish/pargv/module.am \
-	clish/ptype/module.am \
-	clish/shell/module.am \
-	clish/view/module.am \
-	clish/nspace/module.am \
-	clish/var/module.am \
-	clish/action/module.am \
-	clish/config/module.am \
-	clish/hotkey/module.am \
-	clish/plugin/module.am \
-	clish/udata/module.am \
-	clish/README
-
-include $(top_srcdir)/clish/command/module.am
-include $(top_srcdir)/clish/param/module.am
-include $(top_srcdir)/clish/pargv/module.am
-include $(top_srcdir)/clish/ptype/module.am
-include $(top_srcdir)/clish/shell/module.am
-include $(top_srcdir)/clish/view/module.am
-include $(top_srcdir)/clish/nspace/module.am
-include $(top_srcdir)/clish/var/module.am
-include $(top_srcdir)/clish/action/module.am
-include $(top_srcdir)/clish/config/module.am
-include $(top_srcdir)/clish/hotkey/module.am
-include $(top_srcdir)/clish/plugin/module.am
-include $(top_srcdir)/clish/udata/module.am

+ 0 - 57
clish/nspace.h

@@ -1,57 +0,0 @@
-/*
- * nspace.h
- * Namespace instances are assocated with a view to make view's commands available
- * within current view.
- */
-
-#ifndef _clish_nspace_h
-#define _clish_nspace_h
-
-typedef struct clish_nspace_s clish_nspace_t;
-
-typedef enum {
-	CLISH_NSPACE_NONE,
-	CLISH_NSPACE_HELP,
-	CLISH_NSPACE_COMPLETION,
-	CLISH_NSPACE_CHELP
-} clish_nspace_visibility_e;
-
-#include <regex.h>
-
-#include "clish/macros.h"
-#include "clish/view.h"
-
-clish_nspace_t *clish_nspace_new(const char *view_name);
-
-void clish_nspace_delete(void *instance);
-const clish_command_t *clish_nspace_find_next_completion(clish_nspace_t *
-	instance, const char *iter_cmd, const char *line,
-	clish_nspace_visibility_e field);
-clish_command_t *clish_nspace_find_command(clish_nspace_t * instance, const char *name);
-void clish_nspace_dump(const clish_nspace_t * instance);
-clish_command_t * clish_nspace_create_prefix_cmd(clish_nspace_t * instance,
-	const char * name, const char * help);
-void clish_nspace_clean_proxy(clish_nspace_t * instance);
-
-_CLISH_SET(nspace, bool_t, help);
-_CLISH_GET(nspace, bool_t, help);
-_CLISH_SET(nspace, bool_t, completion);
-_CLISH_GET(nspace, bool_t, completion);
-_CLISH_SET(nspace, bool_t, context_help);
-_CLISH_GET(nspace, bool_t, context_help);
-_CLISH_SET(nspace, bool_t, inherit);
-_CLISH_GET(nspace, bool_t, inherit);
-_CLISH_SET(nspace, clish_view_t *, view);
-_CLISH_GET(nspace, clish_view_t *, view);
-_CLISH_SET_STR(nspace, view_name);
-_CLISH_GET_STR(nspace, view_name);
-_CLISH_SET_STR(nspace, access);
-_CLISH_GET_STR(nspace, access);
-_CLISH_SET_STR_ONCE(nspace, prefix);
-_CLISH_GET_STR(nspace, prefix);
-_CLISH_GET(nspace, const regex_t *, prefix_regex);
-
-bool_t clish_nspace__get_visibility(const clish_nspace_t * instance,
-	clish_nspace_visibility_e field);
-
-#endif				/* _clish_nspace_h */

+ 0 - 4
clish/nspace/module.am

@@ -1,4 +0,0 @@
-libclish_la_SOURCES += \
-	clish/nspace/nspace.c \
-	clish/nspace/nspace_dump.c \
-	clish/nspace/private.h

+ 0 - 336
clish/nspace/nspace.c

@@ -1,336 +0,0 @@
-/*
- * nspace.c
- *
- * This file provides the implementation of the "nspace" class
- */
-#include "private.h"
-#include "lub/string.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <regex.h>
-#include <ctype.h>
-
-/*--------------------------------------------------------- */
-static void clish_nspace_init(clish_nspace_t *this,  const char *view_name)
-{
-	this->view_name = NULL;
-	clish_nspace__set_view_name(this, view_name);
-
-	/* Set up defaults */
-	this->view = NULL;
-	this->prefix = NULL;
-	this->help = BOOL_FALSE;
-	this->completion = BOOL_TRUE;
-	this->context_help = BOOL_FALSE;
-	this->inherit = BOOL_TRUE;
-	this->prefix_cmd = NULL;
-	this->access = NULL;
-
-	/* initialise the tree of commands links for this nspace */
-	lub_bintree_init(&this->tree,
-		clish_command_bt_offset(),
-		clish_command_bt_compare, clish_command_bt_getkey);
-}
-
-/*--------------------------------------------------------- */
-static void clish_nspace_fini(clish_nspace_t *this)
-{
-	clish_command_t *cmd;
-
-	/* deallocate the memory for this instance */
-	if (this->prefix) {
-		free(this->prefix);
-		regfree(&this->prefix_regex);
-	}
-	/* delete each command link held by this nspace */
-	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);
-	}
-	/* Delete prefix pseudo-command */
-	if (this->prefix_cmd) {
-		clish_command_delete(this->prefix_cmd);
-		this->prefix_cmd = NULL;
-	}
-	lub_string_free(this->access);
-	lub_string_free(this->view_name);
-}
-
-/*--------------------------------------------------------- */
-clish_command_t * clish_nspace_create_prefix_cmd(clish_nspace_t * this,
-	const char * name, const char * help)
-{
-	if (this->prefix_cmd) {
-		clish_command_delete(this->prefix_cmd);
-		this->prefix_cmd = NULL;
-	}
-
-	return (this->prefix_cmd = clish_command_new(name, help));
-}
-
-/*--------------------------------------------------------- */
-static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
-	const char *prefix, const clish_command_t * ref)
-{
-	clish_command_t *cmd;
-	char *name = NULL;
-	const char *help = NULL;
-	clish_command_t *tmp = NULL;
-	const char *str = NULL;
-
-	assert(prefix);
-	if (!ref) {
-		assert(this->prefix_cmd);
-		name = lub_string_dup(prefix);
-		ref = this->prefix_cmd;
-		help = clish_command__get_text(this->prefix_cmd);
-	} else {
-		lub_string_catn(&name, prefix, strlen(prefix));
-		lub_string_catn(&name, " ", 1);
-		lub_string_catn(&name, clish_command__get_name(ref),
-				strlen(clish_command__get_name(ref)));
-		help = clish_command__get_text(ref);
-	}
-
-	/* The command is cached already */
-	if ((cmd = lub_bintree_find(&this->tree, name))) {
-		free(name);
-		return cmd;
-	}
-	cmd = clish_command_new_link(name, help, ref);
-	free(name);
-	assert(cmd);
-	/* The command was created dynamically */
-	clish_command__set_dynamic(cmd, BOOL_TRUE);
-
-	/* Delete proxy commands with another prefixes */
-	tmp = lub_bintree_findfirst(&this->tree);
-	if (tmp)
-		str = clish_command__get_name(tmp);
-	if (str && (lub_string_nocasestr(str, prefix) != str)) {
-		do {
-			lub_bintree_remove(&this->tree, tmp);
-			clish_command_delete(tmp);
-		} while ((tmp = lub_bintree_findfirst(&this->tree)));
-	}
-
-	/* Insert command link into the tree */
-	if (-1 == lub_bintree_insert(&this->tree, cmd)) {
-		clish_command_delete(cmd);
-		cmd = NULL;
-	}
-
-	return cmd;
-}
-
-/*--------------------------------------------------------- */
-clish_nspace_t *clish_nspace_new(const char *view_name)
-{
-	clish_nspace_t *this = malloc(sizeof(clish_nspace_t));
-
-	if (this)
-		clish_nspace_init(this, view_name);
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_nspace_delete(void *data)
-{
-	clish_nspace_t *this = (clish_nspace_t *)data;
-	clish_nspace_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-static const char *clish_nspace_after_prefix(const regex_t *prefix_regex,
-	const char *line, char **real_prefix)
-{
-	const char *in_line = NULL;
-	regmatch_t pmatch[1] = {};
-	int res;
-
-	if (!line)
-		return NULL;
-
-	/* Compile regular expression */
-	res = regexec(prefix_regex, line, 1, pmatch, 0);
-	if (res || (0 != pmatch[0].rm_so))
-		return NULL;
-	/* Empty match */
-	if (0 == pmatch[0].rm_eo)
-		return NULL;
-	in_line = line + pmatch[0].rm_eo;
-
-	lub_string_catn(real_prefix, line, pmatch[0].rm_eo);
-
-	return in_line;
-}
-
-/*--------------------------------------------------------- */
-clish_command_t *clish_nspace_find_command(clish_nspace_t * this, const char *name)
-{
-	clish_command_t *cmd = NULL, *retval = NULL;
-	clish_view_t *view = clish_nspace__get_view(this);
-	const char *in_line;
-	char *real_prefix = NULL;
-
-	if (!clish_nspace__get_prefix(this))
-		return clish_view_find_command(view, name, this->inherit);
-
-	if (!(in_line = clish_nspace_after_prefix(
-		clish_nspace__get_prefix_regex(this), name, &real_prefix)))
-		return NULL;
-
-	/* If prefix is followed by space */
-	if (in_line[0] == ' ')
-		in_line++;
-
-	if (in_line[0] != '\0') {
-		cmd = clish_view_find_command(view, in_line, this->inherit);
-		if (!cmd) {
-			lub_string_free(real_prefix);
-			return NULL;
-		}
-	}
-
-	retval = clish_nspace_find_create_command(this, real_prefix, cmd);
-	lub_string_free(real_prefix);
-
-	return retval;
-}
-
-/*--------------------------------------------------------- */
-const clish_command_t *clish_nspace_find_next_completion(clish_nspace_t * this,
-	const char *iter_cmd, const char *line,
-	clish_nspace_visibility_e field)
-{
-	const clish_command_t *cmd = NULL, *retval = NULL;
-	clish_view_t *view = clish_nspace__get_view(this);
-	const char *in_iter = "";
-	const char *in_line;
-	char *real_prefix = NULL;
-
-	if (!clish_nspace__get_prefix(this))
-		return clish_view_find_next_completion(view, iter_cmd,
-			line, field, this->inherit);
-
-	if (!(in_line = clish_nspace_after_prefix(
-		clish_nspace__get_prefix_regex(this), line, &real_prefix)))
-		return NULL;
-
-	if (in_line[0] != '\0') {
-		/* If prefix is followed by space */
-		if (!isspace(in_line[0])) {
-			lub_string_free(real_prefix);
-			return NULL;
-		}
-		in_line++;
-		if (iter_cmd &&
-			(lub_string_nocasestr(iter_cmd, real_prefix) == iter_cmd) &&
-			(lub_string_nocasecmp(iter_cmd, real_prefix)))
-			in_iter = iter_cmd + strlen(real_prefix) + 1;
-		cmd = clish_view_find_next_completion(view,
-			in_iter, in_line, field, this->inherit);
-		if (!cmd) {
-			lub_string_free(real_prefix);
-			return NULL;
-		}
-	}
-
-	/* If prefix was already returned. */
-	if (!cmd && iter_cmd && !lub_string_nocasecmp(iter_cmd, real_prefix)) {
-		lub_string_free(real_prefix);
-		return NULL;
-	}
-
-	retval = clish_nspace_find_create_command(this, real_prefix, cmd);
-	lub_string_free(real_prefix);
-
-	if (retval && iter_cmd &&
-		lub_string_nocasecmp(iter_cmd, clish_command__get_name(retval)) > 0)
-		return NULL;
-
-	return retval;
-}
-
-/*--------------------------------------------------------- */
-void clish_nspace_clean_proxy(clish_nspace_t * this)
-{
-	clish_command_t *cmd = NULL;
-
-	/* Recursive proxy clean */
-	clish_view_clean_proxy(this->view);
-	/* Delete each command proxy held by this nspace */
-	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);
-	}
-}
-
-CLISH_SET(nspace, bool_t, help);
-CLISH_GET(nspace, bool_t, help);
-CLISH_SET(nspace, bool_t, completion);
-CLISH_GET(nspace, bool_t, completion);
-CLISH_SET(nspace, bool_t, context_help);
-CLISH_GET(nspace, bool_t, context_help);
-CLISH_SET(nspace, bool_t, inherit);
-CLISH_GET(nspace, bool_t, inherit);
-CLISH_SET(nspace, clish_view_t *, view);
-CLISH_GET(nspace, clish_view_t *, view);
-CLISH_SET_STR(nspace, view_name);
-CLISH_GET_STR(nspace, view_name);
-CLISH_SET_STR(nspace, access);
-CLISH_GET_STR(nspace, access);
-CLISH_GET_STR(nspace, prefix);
-
-/*--------------------------------------------------------- */
-_CLISH_SET_STR_ONCE(nspace, prefix)
-{
-	int res = 0;
-
-	assert(inst);
-	assert(!inst->prefix);
-	res = regcomp(&inst->prefix_regex, val, REG_EXTENDED | REG_ICASE);
-	assert(!res);
-	inst->prefix = lub_string_dup(val);
-}
-
-/*--------------------------------------------------------- */
-_CLISH_GET(nspace, const regex_t *, prefix_regex)
-{
-	assert(inst);
-	if (!inst->prefix)
-		return NULL;
-	return &inst->prefix_regex;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_nspace__get_visibility(const clish_nspace_t * instance,
-	clish_nspace_visibility_e field)
-{
-	bool_t result = BOOL_FALSE;
-
-	switch (field) {
-	case CLISH_NSPACE_HELP:
-		result = clish_nspace__get_help(instance);
-		break;
-	case CLISH_NSPACE_COMPLETION:
-		result = clish_nspace__get_completion(instance);
-		break;
-	case CLISH_NSPACE_CHELP:
-		result = clish_nspace__get_context_help(instance);
-		break;
-	default:
-		break;
-	}
-
-	return result;
-}

+ 0 - 29
clish/nspace/nspace_dump.c

@@ -1,29 +0,0 @@
-#ifdef DEBUG
-
-/*
- * nspace_dump.c
- */
-#include "private.h"
-#include "lub/dump.h"
-
-/*--------------------------------------------------------- */
-void clish_nspace_dump(const clish_nspace_t * this)
-{
-	lub_dump_printf("nspace(%p)\n", this);
-
-	lub_dump_indent();
-	lub_dump_printf("view         : %s\n",
-		clish_view__get_name(this->view));
-	lub_dump_printf("view_name    : %s\n", LUB_DUMP_STR(this->view_name));
-	lub_dump_printf("prefix       : %s\n", LUB_DUMP_STR(this->prefix));
-	lub_dump_printf("access       : %s\n", LUB_DUMP_STR(this->access));
-	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();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 23
clish/nspace/private.h

@@ -1,23 +0,0 @@
-/*
- * nspace.h
- */
-#include <regex.h>
-
-#include "clish/nspace.h"
-
-/*---------------------------------------------------------
- * PRIVATE TYPES
- *--------------------------------------------------------- */
-struct clish_nspace_s {
-	lub_bintree_t tree;	/* Tree of command links */
-	clish_view_t *view;	/* The view to import commands from */
-	char *view_name;	/* The text name of view to import command from */
-	char *prefix;		/* if non NULL the prefix for imported commands */
-	char *access;
-	regex_t prefix_regex;
-	bool_t help;
-	bool_t completion;
-	bool_t context_help;
-	bool_t inherit;
-	clish_command_t * prefix_cmd;
-};

+ 0 - 85
clish/param.h

@@ -1,85 +0,0 @@
-/*
- * param.h
- * Parameter instances are assocated with a command line and used to validate the
- * the arguments which a user is inputing for a command.
- */
-
-#ifndef _clish_param_h
-#define _clish_param_h
-
-typedef struct clish_paramv_s clish_paramv_t;
-typedef struct clish_param_s clish_param_t;
-
-#include "clish/types.h"
-#include "clish/ptype.h"
-#include "clish/pargv.h"
-#include "clish/var.h"
-
-/* The means by which the param is interpreted */
-typedef enum {
-	/* A common parameter */
-	CLISH_PARAM_COMMON,
-	/* A swich parameter. Choose the only one of nested parameters. */
-	CLISH_PARAM_SWITCH,
-	/* A subcomand. Identified by it's name. */
-	CLISH_PARAM_SUBCOMMAND
-} clish_param_mode_e;
-
-/* Class param */
-
-clish_param_t *clish_param_new(const char *name,
-	const char *text, const char *ptype_name);
-
-void clish_param_delete(clish_param_t * instance);
-void clish_param_help(const clish_param_t * instance, clish_help_t *help);
-void clish_param_help_arrow(const clish_param_t * instance, size_t offset);
-char *clish_param_validate(const clish_param_t * instance, const char *text);
-void clish_param_dump(const clish_param_t * instance);
-void clish_param_insert_param(clish_param_t * instance, clish_param_t * param);
-
-_CLISH_SET_STR(param, ptype_name);
-_CLISH_GET_STR(param, ptype_name);
-_CLISH_SET_STR(param, access);
-_CLISH_GET_STR(param, access);
-_CLISH_GET_STR(param, name);
-_CLISH_GET_STR(param, text);
-_CLISH_GET_STR(param, range);
-_CLISH_SET_STR_ONCE(param, value);
-_CLISH_GET_STR(param, value);
-_CLISH_SET(param, clish_ptype_t *, ptype);
-_CLISH_GET(param, clish_ptype_t *, ptype);
-_CLISH_SET_STR_ONCE(param, defval);
-_CLISH_GET_STR(param, defval);
-_CLISH_SET_STR_ONCE(param, test);
-_CLISH_GET_STR(param, test);
-_CLISH_SET_STR_ONCE(param, completion);
-_CLISH_GET_STR(param, completion);
-_CLISH_SET(param, clish_param_mode_e, mode);
-_CLISH_GET(param, clish_param_mode_e, mode);
-_CLISH_GET(param, clish_paramv_t *, paramv);
-_CLISH_SET(param, bool_t, optional);
-_CLISH_GET(param, bool_t, optional);
-_CLISH_SET(param, bool_t, order);
-_CLISH_GET(param, bool_t, order);
-_CLISH_SET(param, bool_t, hidden);
-_CLISH_GET(param, bool_t, hidden);
-_CLISH_GET(param, unsigned int, param_count);
-
-clish_param_t *clish_param__get_param(const clish_param_t * instance,
-	unsigned int index);
-
-/* Class paramv */
-
-clish_paramv_t *clish_paramv_new(void);
-void clish_paramv_delete(clish_paramv_t * instance);
-void clish_paramv_insert(clish_paramv_t * instance, clish_param_t * param);
-int clish_paramv_remove(clish_paramv_t *instance, unsigned int index); /* Remove param from vector */
-clish_param_t *clish_paramv__get_param(const clish_paramv_t * instance,
-				unsigned index);
-unsigned int clish_paramv__get_count(const clish_paramv_t * instance);
-clish_param_t *clish_paramv_find_param(const clish_paramv_t * instance,
-	const char *name);
-const char *clish_paramv_find_default(const clish_paramv_t * instance,
-	const char *name);
-
-#endif				/* _clish_param_h */

+ 0 - 5
clish/param/module.am

@@ -1,5 +0,0 @@
-libclish_la_SOURCES += \
-	clish/param/param.c \
-	clish/param/paramv.c \
-	clish/param/param_dump.c \
-	clish/param/private.h

+ 0 - 189
clish/param/param.c

@@ -1,189 +0,0 @@
-/*
- * param.c
- *
- * This file provides the implementation of the "param" class
- */
-#include "private.h"
-#include "lub/string.h"
-#include "clish/types.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-/*--------------------------------------------------------- */
-static void clish_param_init(clish_param_t *this, const char *name,
-	const char *text, const char *ptype_name)
-{
-	this->name = lub_string_dup(name);
-	this->text = lub_string_dup(text);
-	this->ptype_name = lub_string_dup(ptype_name);
-
-	/* Set up defaults */
-	this->ptype = NULL;
-	this->defval = NULL;
-	this->mode = CLISH_PARAM_COMMON;
-	this->optional = BOOL_FALSE;
-	this->order = BOOL_FALSE;
-	this->value = NULL;
-	this->hidden = BOOL_FALSE;
-	this->test = NULL;
-	this->completion = NULL;
-	this->access = NULL;
-
-	this->paramv = clish_paramv_new();
-}
-
-/*--------------------------------------------------------- */
-static void clish_param_fini(clish_param_t * this)
-{
-	/* deallocate the memory for this instance */
-	lub_string_free(this->defval);
-	lub_string_free(this->name);
-	lub_string_free(this->text);
-	lub_string_free(this->ptype_name);
-	lub_string_free(this->value);
-	lub_string_free(this->test);
-	lub_string_free(this->completion);
-	lub_string_free(this->access);
-
-	clish_paramv_delete(this->paramv);
-}
-
-/*--------------------------------------------------------- */
-clish_param_t *clish_param_new(const char *name, const char *text,
-	const char *ptype_name)
-{
-	clish_param_t *this = malloc(sizeof(clish_param_t));
-
-	if (this)
-		clish_param_init(this, name, text, ptype_name);
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_param_delete(clish_param_t * this)
-{
-	clish_param_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-void clish_param_insert_param(clish_param_t * this, clish_param_t * param)
-{
-	return clish_paramv_insert(this->paramv, param);
-}
-
-/*--------------------------------------------------------- */
-char *clish_param_validate(const clish_param_t * this, const char *text)
-{
-	if (CLISH_PARAM_SUBCOMMAND == clish_param__get_mode(this)) {
-		if (lub_string_nocasecmp(clish_param__get_value(this), text))
-			return NULL;
-	}
-	return clish_ptype_translate(this->ptype, text);
-}
-
-/*--------------------------------------------------------- */
-void clish_param_help(const clish_param_t * this, clish_help_t *help)
-{
-	const char *range = clish_ptype__get_range(this->ptype);
-	const char *name;
-	char *str = NULL;
-
-	if (CLISH_PARAM_SWITCH == clish_param__get_mode(this)) {
-		unsigned rec_paramc = clish_param__get_param_count(this);
-		clish_param_t *cparam;
-		unsigned i;
-
-		for (i = 0; i < rec_paramc; i++) {
-			cparam = clish_param__get_param(this, i);
-			if (!cparam)
-				break;
-			clish_param_help(cparam, help);
-		}
-		return;
-	}
-
-	if (CLISH_PARAM_SUBCOMMAND == clish_param__get_mode(this))
-		name = clish_param__get_value(this);
-	else
-		if (!(name = clish_ptype__get_text(this->ptype)))
-			name = clish_ptype__get_name(this->ptype);
-
-	lub_string_cat(&str, this->text);
-	if (range) {
-		lub_string_cat(&str, " (");
-		lub_string_cat(&str, range);
-		lub_string_cat(&str, ")");
-	}
-	lub_argv_add(help->name, name);
-	lub_argv_add(help->help, str);
-	lub_string_free(str);
-	lub_argv_add(help->detail, NULL);
-}
-
-/*--------------------------------------------------------- */
-void clish_param_help_arrow(const clish_param_t * this, size_t offset)
-{
-	fprintf(stderr, "%*c\n", (int)offset, '^');
-
-	this = this; /* Happy compiler */
-}
-
-CLISH_SET_STR(param, ptype_name);
-CLISH_GET_STR(param, ptype_name);
-CLISH_SET_STR(param, access);
-CLISH_GET_STR(param, access);
-CLISH_GET_STR(param, name);
-CLISH_GET_STR(param, text);
-CLISH_SET_STR_ONCE(param, value);
-CLISH_SET(param, clish_ptype_t *, ptype);
-CLISH_GET(param, clish_ptype_t *, ptype);
-CLISH_SET_STR_ONCE(param, defval);
-CLISH_GET_STR(param, defval);
-CLISH_SET_STR_ONCE(param, test);
-CLISH_GET_STR(param, test);
-CLISH_SET_STR_ONCE(param, completion);
-CLISH_GET_STR(param, completion);
-CLISH_SET(param, clish_param_mode_e, mode);
-CLISH_GET(param, clish_param_mode_e, mode);
-CLISH_GET(param, clish_paramv_t *, paramv);
-CLISH_SET(param, bool_t, optional);
-CLISH_GET(param, bool_t, optional);
-CLISH_SET(param, bool_t, order);
-CLISH_GET(param, bool_t, order);
-CLISH_SET(param, bool_t, hidden);
-CLISH_GET(param, bool_t, hidden);
-
-/*--------------------------------------------------------- */
-_CLISH_GET_STR(param, value)
-{
-	assert(inst);
-	if (inst->value)
-		return inst->value;
-	return inst->name;
-}
-
-/*--------------------------------------------------------- */
-_CLISH_GET_STR(param, range)
-{
-	assert(inst);
-	return clish_ptype__get_range(inst->ptype);
-}
-
-/*--------------------------------------------------------- */
-clish_param_t *clish_param__get_param(const clish_param_t * this,
-	unsigned int index)
-{
-	assert(this);
-	return clish_paramv__get_param(this->paramv, index);
-}
-
-/*--------------------------------------------------------- */
-_CLISH_GET(param, unsigned int, param_count)
-{
-	assert(inst);
-	return clish_paramv__get_count(inst->paramv);
-}

+ 0 - 53
clish/param/param_dump.c

@@ -1,53 +0,0 @@
-#ifdef DEBUG
-
-/*
- * param_dump.c
- */
-#include "private.h"
-#include "lub/dump.h"
-/*--------------------------------------------------------- */
-void clish_param_dump(const clish_param_t * this)
-{
-	unsigned i;
-	char *mode;
-
-	lub_dump_printf("param(%p)\n", this);
-
-	lub_dump_indent();
-	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", LUB_DUMP_STR(this->defval));
-	switch (this->mode) {
-	case CLISH_PARAM_COMMON:
-		mode = "COMMON";
-		break;
-	case CLISH_PARAM_SWITCH:
-		mode = "SWITCH";
-		break;
-	case CLISH_PARAM_SUBCOMMAND:
-		mode = "SUBCOMMAND";
-		break;
-	default:
-		mode = "Unknown";
-		break;
-	}
-	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", 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++) {
-		clish_param_dump(clish_param__get_param(this, i));
-	}
-
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 147
clish/param/paramv.c

@@ -1,147 +0,0 @@
-/*
- * paramv.c
- *
- */
-#include "private.h"
-#include "lub/string.h"
-#include "clish/types.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-/*--------------------------------------------------------- */
-static void clish_paramv_init(clish_paramv_t * this)
-{
-	this->paramc = 0;
-	this->paramv = NULL;
-}
-
-/*--------------------------------------------------------- */
-static void clish_paramv_fini(clish_paramv_t * this)
-{
-	unsigned i;
-
-	/* finalize each of the parameter instances */
-	for (i = 0; i < this->paramc; i++) {
-		clish_param_delete(this->paramv[i]);
-	}
-	/* free the parameter vector */
-	free(this->paramv);
-	this->paramc = 0;
-}
-
-/*--------------------------------------------------------- */
-clish_paramv_t *clish_paramv_new(void)
-{
-	clish_paramv_t *this = malloc(sizeof(clish_paramv_t));
-
-	if (this)
-		clish_paramv_init(this);
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_paramv_delete(clish_paramv_t * this)
-{
-	clish_paramv_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-void clish_paramv_insert(clish_paramv_t * this, clish_param_t * param)
-{
-	size_t new_size = ((this->paramc + 1) * sizeof(clish_param_t *));
-	clish_param_t **tmp;
-
-	/* resize the parameter vector */
-	tmp = realloc(this->paramv, new_size);
-	if (tmp) {
-		this->paramv = tmp;
-		/* insert reference to the parameter */
-		this->paramv[this->paramc++] = param;
-	}
-}
-
-/*--------------------------------------------------------- */
-int clish_paramv_remove(clish_paramv_t *this, unsigned int index)
-{
-	size_t new_size;
-	clish_param_t **tmp;
-	clish_param_t **dst, **src;
-	size_t n;
-
-	if (this->paramc < 1)
-		return -1;
-	if (index >= this->paramc)
-		return -1;
-
-	new_size = ((this->paramc - 1) * sizeof(clish_param_t *));
-	dst = this->paramv + index;
-	src = dst + 1;
-	n = this->paramc - index - 1;
-	if (n)
-		memmove(dst, src, n * sizeof(clish_param_t *));
-	/* Resize the parameter vector */
-	if (new_size) {
-		tmp = realloc(this->paramv, new_size);
-		if (!tmp)
-			return -1;
-		this->paramv = tmp;
-	} else {
-		free(this->paramv);
-		this->paramv = NULL;
-	}
-	this->paramc--;
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-clish_param_t *clish_paramv__get_param(const clish_paramv_t * this,
-	unsigned int index)
-{
-	clish_param_t *result = NULL;
-
-	if (index < this->paramc)
-		result = this->paramv[index];
-	return result;
-}
-
-/*--------------------------------------------------------- */
-clish_param_t *clish_paramv_find_param(const clish_paramv_t * this,
-	const char *name)
-{
-	clish_param_t *res = NULL;
-	unsigned int i;
-
-	for (i = 0; i < this->paramc; i++) {
-		if (!strcmp(clish_param__get_name(this->paramv[i]), name))
-			return this->paramv[i];
-		if ((res = clish_paramv_find_param(
-			clish_param__get_paramv(this->paramv[i]), name)))
-			return res;
-	}
-
-	return res;
-}
-
-/*--------------------------------------------------------- */
-const char *clish_paramv_find_default(const clish_paramv_t * this,
-	const char *name)
-{
-	clish_param_t *res = clish_paramv_find_param(this, name);
-
-	if (res)
-		return clish_param__get_defval(res);
-
-	return NULL;
-}
-
-/*--------------------------------------------------------- */
-unsigned int clish_paramv__get_count(const clish_paramv_t * this)
-{
-	return this->paramc;
-}
-

+ 0 - 30
clish/param/private.h

@@ -1,30 +0,0 @@
-/*
- * param.h
- */
-#include "clish/param.h"
-
-/*---------------------------------------------------------
- * PRIVATE TYPES
- *--------------------------------------------------------- */
-
-struct clish_paramv_s {
-	unsigned paramc;
-	clish_param_t **paramv;
-};
-
-struct clish_param_s {
-	char *name;
-	char *text;
-	char *value;
-	char *ptype_name;	/* Name of PTYPE */
-	clish_ptype_t *ptype;	/* The type of this parameter */
-	char *defval;		/* default value to use for this parameter */
-	clish_paramv_t *paramv;
-	clish_param_mode_e mode;
-	bool_t optional;
-	bool_t order;
-	bool_t hidden;
-	char *test; /* The condition to enable param */
-	char *completion; /* Possible completions */
-	char *access;
-};

+ 0 - 49
clish/pargv.h

@@ -1,49 +0,0 @@
-/*
- * pargv.h
- * This class represents a vector of command line arguments.
- */
-
-#ifndef _clish_pargv_h
-#define _clish_pargv_h
-
-typedef enum {
-	CLISH_LINE_OK,
-	CLISH_LINE_PARTIAL,
-	CLISH_BAD_CMD,
-	CLISH_BAD_PARAM,
-	CLISH_BAD_HISTORY
-} clish_pargv_status_e;
-
-typedef struct clish_pargv_s clish_pargv_t;
-typedef struct clish_parg_s clish_parg_t;
-
-#include "clish/ptype.h"
-#include "clish/command.h"
-#include "clish/param.h"
-
-/* Class pargv */
-
-clish_pargv_t *clish_pargv_new(void);
-
-void clish_pargv_delete(clish_pargv_t * instance);
-const clish_parg_t *clish_pargv_find_arg(clish_pargv_t * instance,
-	const char *name);
-int clish_pargv_insert(clish_pargv_t * instance,
-	const clish_param_t * param, const char *value);
-clish_pargv_t *clish_pargv_clone(const clish_pargv_t *src);
-void clish_pargv_dump(const clish_pargv_t * instance);
-
-unsigned clish_pargv__get_count(clish_pargv_t * instance);
-clish_parg_t *clish_pargv__get_parg(clish_pargv_t * instance, unsigned index);
-const clish_param_t *clish_pargv__get_param(clish_pargv_t * instance,
-	unsigned index);
-
-/* Class parg */
-
-void clish_parg_dump(const clish_parg_t * instance);
-
-_CLISH_GET_STR(parg, value);
-_CLISH_GET_STR(parg, name);
-_CLISH_GET(parg, clish_ptype_t *, ptype);
-
-#endif				/* _clish_pargv_h */

+ 0 - 5
clish/pargv/module.am

@@ -1,5 +0,0 @@
-libclish_la_SOURCES += \
-	clish/pargv/pargv.c \
-	clish/pargv/parg.c \
-	clish/pargv/pargv_dump.c \
-	clish/pargv/private.h

+ 0 - 30
clish/pargv/parg.c

@@ -1,30 +0,0 @@
-/*
- * parg.c
- */
-#include "private.h"
-#include "lub/string.h"
-#include "lub/argv.h"
-#include "lub/system.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-
-CLISH_GET_STR(parg, value);
-
-/*--------------------------------------------------------- */
-_CLISH_GET_STR(parg, name)
-{
-	if (!inst)
-		return NULL;
-	return clish_param__get_name(inst->param);
-}
-
-/*--------------------------------------------------------- */
-_CLISH_GET(parg, clish_ptype_t *, ptype)
-{
-	if (!inst)
-		return NULL;
-	return clish_param__get_ptype(inst->param);
-}

+ 0 - 163
clish/pargv/pargv.c

@@ -1,163 +0,0 @@
-/*
- * pargv.c
- */
-#include "private.h"
-#include "lub/string.h"
-#include "lub/argv.h"
-#include "lub/system.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-
-/*--------------------------------------------------------- */
-/*
- * Search for the specified parameter and return its value
- */
-static clish_parg_t *find_parg(clish_pargv_t * this, const char *name)
-{
-	unsigned i;
-	clish_parg_t *result = NULL;
-
-	if (!this || !name)
-		return NULL;
-
-	/* scan the parameters in this instance */
-	for (i = 0; i < this->pargc; i++) {
-		clish_parg_t *parg = this->pargv[i];
-		const char *pname = clish_param__get_name(parg->param);
-
-		if (0 == strcmp(pname, name)) {
-			result = parg;
-			break;
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */
-int clish_pargv_insert(clish_pargv_t * this,
-	const clish_param_t * param, const char *value)
-{
-	if (!this || !param)
-		return -1;
-
-	clish_parg_t *parg = find_parg(this, clish_param__get_name(param));
-
-	if (parg) {
-		/* release the current value */
-		lub_string_free(parg->value);
-	} else {
-		size_t new_size = ((this->pargc + 1) * sizeof(clish_parg_t *));
-		clish_parg_t **tmp;
-
-		/* resize the parameter vector */
-		tmp = realloc(this->pargv, new_size);
-		this->pargv = tmp;
-		/* insert reference to the parameter */
-		parg = malloc(sizeof(*parg));
-		this->pargv[this->pargc++] = parg;
-		parg->param = param;
-	}
-	parg->value = NULL;
-	if (value)
-		parg->value = lub_string_dup(value);
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-clish_pargv_t *clish_pargv_new(void)
-{
-	clish_pargv_t *this;
-
-	this = malloc(sizeof(clish_pargv_t));
-	this->pargc = 0;
-	this->pargv = NULL;
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-clish_pargv_t *clish_pargv_clone(const clish_pargv_t *src)
-{
-	clish_pargv_t *dst;
-	unsigned int i;
-
-	if (!src)
-		return NULL;
-
-	dst = clish_pargv_new();
-	for (i = 0; i < src->pargc; i++) {
-		clish_pargv_insert(dst, src->pargv[i]->param, src->pargv[i]->value);
-	}
-
-	return dst;
-}
-
-/*--------------------------------------------------------- */
-static void clish_pargv_fini(clish_pargv_t * this)
-{
-	unsigned int i;
-
-	/* cleanup time */
-	for (i = 0; i < this->pargc; i++) {
-		lub_string_free(this->pargv[i]->value);
-		this->pargv[i]->value = NULL;
-		free(this->pargv[i]);
-	}
-	free(this->pargv);
-}
-
-/*--------------------------------------------------------- */
-void clish_pargv_delete(clish_pargv_t * this)
-{
-	if (!this)
-		return;
-
-	clish_pargv_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-unsigned clish_pargv__get_count(clish_pargv_t * this)
-{
-	if (!this)
-		return 0;
-	return this->pargc;
-}
-
-/*--------------------------------------------------------- */
-clish_parg_t *clish_pargv__get_parg(clish_pargv_t * this, unsigned int index)
-{
-	if (!this)
-		return NULL;
-	if (index >= this->pargc)
-		return NULL;
-	return this->pargv[index];
-}
-
-/*--------------------------------------------------------- */
-const clish_param_t *clish_pargv__get_param(clish_pargv_t * this,
-	unsigned index)
-{
-	clish_parg_t *tmp;
-
-	if (!this)
-		return NULL;
-	if (index >= this->pargc)
-		return NULL;
-	tmp = this->pargv[index];
-	return tmp->param;
-}
-
-/*--------------------------------------------------------- */
-const clish_parg_t *clish_pargv_find_arg(clish_pargv_t * this, const char *name)
-{
-	if (!this)
-		return NULL;
-	return find_parg(this, name);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 37
clish/pargv/pargv_dump.c

@@ -1,37 +0,0 @@
-#ifdef DEBUG
-
-/*
- * pargv_dump.c
- */
-#include "private.h"
-#include "lub/dump.h"
-
-/*--------------------------------------------------------- */
-void clish_parg_dump(const clish_parg_t * this)
-{
-	lub_dump_printf("parg(%p)\n", 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)));
-	lub_dump_printf("value: %s\n", clish_parg__get_value(this));
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-void clish_pargv_dump(const clish_pargv_t * this)
-{
-	unsigned i;
-
-	lub_dump_printf("pargv(%p)\n", this);
-	lub_dump_indent();
-	for (i = 0; i < this->pargc; i++) {
-		/* get the appropriate parameter definition */
-		clish_parg_dump(this->pargv[i]);
-	}
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 16
clish/pargv/private.h

@@ -1,16 +0,0 @@
-/*
- * pargv.h
- */
-#include "clish/pargv.h"
-#include "clish/param.h"
-
-/*--------------------------------------------------------- */
-struct clish_parg_s {
-	const clish_param_t *param;
-	char *value;
-};
-struct clish_pargv_s {
-	unsigned pargc;
-	clish_parg_t **pargv;
-};
-/*--------------------------------------------------------- */

+ 0 - 131
clish/plugin.h

@@ -1,131 +0,0 @@
-/*
- * plugin.h
- */
-#ifndef _clish_plugin_h
-#define _clish_plugin_h
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include "clish/macros.h"
-#include "lub/types.h"
-
-/* Symbol */
-
-/* Symbol types. Functions with different purposes. */
-typedef enum {
-	CLISH_SYM_TYPE_NONE = 0, /* None */
-	CLISH_SYM_TYPE_ACTION, /* Common builtin symbol for ACTION tag */
-	CLISH_SYM_TYPE_ACCESS, /* Callback for "access" field */
-	CLISH_SYM_TYPE_CONFIG, /* Callback for CONFIG tag */
-	CLISH_SYM_TYPE_LOG, /* Callback for logging */
-	CLISH_SYM_TYPE_MAX /* Number of elements */
-} clish_sym_type_e;
-
-/* External functions APIs. */
-typedef enum {
-	CLISH_SYM_API_SIMPLE = 0, /* Simple (may be single) API */
-	CLISH_SYM_API_STDOUT /* Symbol for ACTION tag without "out" argument */
-} clish_sym_api_e;
-
-typedef struct clish_sym_s clish_sym_t;
-typedef struct clish_plugin_s clish_plugin_t;
-
-/* Plugin types */
-
-/* Name of init function within plugin */
-#define CLISH_PLUGIN_INIT_FNAME(name) clish_plugin_##name##_init
-#define CLISH_PLUGIN_INIT_NAME_PREFIX "clish_plugin_"
-#define CLISH_PLUGIN_INIT_NAME_SUFFIX "_init"
-#define CLISH_PLUGIN_INIT_FUNC(name) int name(void *clish_shell, clish_plugin_t *plugin)
-#define CLISH_PLUGIN_INIT(name) CLISH_PLUGIN_INIT_FUNC(CLISH_PLUGIN_INIT_FNAME(name))
-
-#define CLISH_PLUGIN_FINI(name) int name(void *clish_shell, clish_plugin_t *plugin)
-#define CLISH_PLUGIN_SYM(name) int name(void *clish_context, const char *script, char **out)
-#define CLISH_PLUGIN_OSYM(name) int name(void *clish_context, const char *script)
-#define CLISH_HOOK_ACCESS(name) int name(void *clish_shell, const char *access)
-#define CLISH_HOOK_CONFIG(name) int name(void *clish_context)
-#define CLISH_HOOK_LOG(name) int name(void *clish_context, const char *line, int retcode)
-
-typedef CLISH_PLUGIN_INIT_FUNC(clish_plugin_init_t);
-typedef CLISH_PLUGIN_FINI(clish_plugin_fini_t);
-typedef CLISH_PLUGIN_SYM(clish_hook_action_fn_t);
-typedef CLISH_PLUGIN_OSYM(clish_hook_oaction_fn_t);
-typedef CLISH_HOOK_ACCESS(clish_hook_access_fn_t);
-typedef CLISH_HOOK_CONFIG(clish_hook_config_fn_t);
-typedef CLISH_HOOK_LOG(clish_hook_log_fn_t);
-
-/* Helpers */
-#define SYM_FN(TYPE,SYM) (*((clish_hook_##TYPE##_fn_t *)(clish_sym__get_func(SYM))))
-
-/* Create an array of builtin plugin's init functions */
-struct clish_plugin_builtin_list_s {
-	const char *name; /* Plugin name */
-	clish_plugin_init_t *init; /* Plugin init function */
-};
-typedef struct clish_plugin_builtin_list_s clish_plugin_builtin_list_t;
-extern clish_plugin_builtin_list_t clish_plugin_builtin_list[];
-
-/* Symbol */
-
-int clish_sym_compare(const void *first, const void *second);
-clish_sym_t *clish_sym_new(const char *name, void *func, int type);
-void clish_sym_free(void *instance);
-int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src);
-
-_CLISH_SET(sym, const void *, func);
-_CLISH_GET(sym, const void *, func);
-_CLISH_SET(sym, bool_t, permanent);
-_CLISH_GET(sym, bool_t, permanent);
-_CLISH_SET_STR(sym, name);
-_CLISH_GET_STR(sym, name);
-_CLISH_SET(sym, clish_plugin_t *, plugin);
-_CLISH_GET(sym, clish_plugin_t *, plugin);
-_CLISH_SET(sym, int, type);
-_CLISH_GET(sym, int, type);
-_CLISH_SET(sym, clish_sym_api_e, api);
-_CLISH_GET(sym, clish_sym_api_e, api);
-
-/* Plugin */
-
-clish_plugin_t *clish_plugin_new(const char *name, void *userdata);
-void clish_plugin_free(void *instance);
-int clish_plugin_load(clish_plugin_t *instance);
-clish_sym_t *clish_plugin_get_sym(clish_plugin_t *instance,
-	const char *name, int type);
-clish_sym_t *clish_plugin_add_generic(clish_plugin_t *instance,
-	void *func, const char *name, int type, bool_t permanent);
-clish_sym_t *clish_plugin_add_sym(clish_plugin_t *instance,
-	clish_hook_action_fn_t *func, const char *name);
-clish_sym_t *clish_plugin_add_psym(clish_plugin_t *instance,
-	clish_hook_action_fn_t *func, const char *name);
-clish_sym_t *clish_plugin_add_osym(clish_plugin_t *instance,
-	clish_hook_oaction_fn_t *func, const char *name);
-clish_sym_t *clish_plugin_add_posym(clish_plugin_t *instance,
-	clish_hook_oaction_fn_t *func, const char *name);
-clish_sym_t *clish_plugin_add_hook(clish_plugin_t *instance,
-	void *func, const char *name, int type);
-clish_sym_t *clish_plugin_add_phook(clish_plugin_t *instance,
-	void *func, const char *name, int type);
-void clish_plugin_dump(const clish_plugin_t *instance);
-
-_CLISH_SET(plugin, clish_plugin_fini_t *, fini);
-_CLISH_GET(plugin, clish_plugin_fini_t *, fini);
-_CLISH_SET(plugin, clish_plugin_init_t *, init);
-_CLISH_GET(plugin, clish_plugin_init_t *, init);
-_CLISH_GET_STR(plugin, name);
-_CLISH_SET_STR(plugin, alias);
-_CLISH_GET_STR(plugin, alias);
-_CLISH_SET_STR(plugin, file);
-_CLISH_GET_STR(plugin, file);
-_CLISH_SET_STR(plugin, conf);
-_CLISH_GET_STR(plugin, conf);
-_CLISH_SET(plugin, bool_t, builtin_flag);
-_CLISH_GET(plugin, bool_t, builtin_flag);
-_CLISH_SET(plugin, bool_t, rtld_global);
-_CLISH_GET(plugin, bool_t, rtld_global);
-_CLISH_GET_STR(plugin, pubname);
-
-#endif				/* _clish_plugin_h */
-/** @} clish_plugin */

+ 0 - 5
clish/plugin/module.am

@@ -1,5 +0,0 @@
-libclish_la_SOURCES += \
-	clish/plugin/plugin.c \
-	clish/plugin/sym.c \
-	clish/plugin/plugin_dump.c \
-	clish/plugin/private.h

+ 0 - 272
clish/plugin/plugin.c

@@ -1,272 +0,0 @@
-/*
- * plugin.c
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include "private.h"
-#include "lub/string.h"
-#include "lub/list.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-#ifdef HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
-
-/*--------------------------------------------------------- */
-clish_plugin_t *clish_plugin_new(const char *name, void *userdata)
-{
-	clish_plugin_t *this;
-
-	this = malloc(sizeof(*this));
-
-	this->name = lub_string_dup(name);
-	this->conf = NULL;
-	this->alias = NULL;
-	this->file = NULL;
-	this->builtin_flag = BOOL_FALSE; /* The plugin is shared object by default */
-	this->dlhan = NULL;
-	/* Initialise the list of symbols */
-	this->syms = lub_list_new(clish_sym_compare, clish_sym_free);
-	/* Constructor and destructor */
-	this->init = NULL;
-	this->fini = NULL;
-	/* Flags */
-	this->rtld_global = BOOL_FALSE; /* The dlopen() use RTLD_LOCAL by default */
-	/* Userdata */
-	this->userdata = userdata;
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_plugin_free(void *plugin)
-{
-	clish_plugin_t *this = (clish_plugin_t *)plugin;
-
-	if (!this)
-		return;
-
-	/* Execute destructor */
-	if (this->fini)
-		this->fini(this->userdata, this);
-
-	lub_string_free(this->name);
-	lub_string_free(this->alias);
-	lub_string_free(this->file);
-	lub_string_free(this->conf);
-
-	/* Free symbol list */
-	lub_list_free_all(this->syms);
-#ifdef HAVE_DLFCN_H
-	if (this->dlhan)
-		dlclose(this->dlhan);
-#endif
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-clish_sym_t *clish_plugin_add_generic(clish_plugin_t *this,
-	void *func, const char *name, int type, bool_t permanent)
-{
-	clish_sym_t *sym;
-
-	if (!name || !func)
-		return NULL;
-
-	if (!(sym = clish_sym_new(name, func, type)))
-		return NULL;
-	clish_sym__set_plugin(sym, this);
-	clish_sym__set_permanent(sym, permanent);
-	lub_list_add(this->syms, sym);
-
-	return sym;
-}
-
-/*--------------------------------------------------------- */
-clish_sym_t *clish_plugin_add_sym(clish_plugin_t *this,
-	clish_hook_action_fn_t *func, const char *name)
-{
-	return clish_plugin_add_generic(this, func,
-		name, CLISH_SYM_TYPE_ACTION, BOOL_FALSE);
-}
-
-/*--------------------------------------------------------- */
-/* Add permanent symbol (can't be turned off by dry-run) */
-clish_sym_t *clish_plugin_add_psym(clish_plugin_t *this,
-	clish_hook_action_fn_t *func, const char *name)
-{
-	return clish_plugin_add_generic(this, func,
-		name, CLISH_SYM_TYPE_ACTION, BOOL_TRUE);
-}
-
-/*--------------------------------------------------------- */
-clish_sym_t *clish_plugin_add_osym(clish_plugin_t *this,
-	clish_hook_oaction_fn_t *func, const char *name)
-{
-	clish_sym_t *s;
-
-	if (!(s = clish_plugin_add_generic(this, func,
-		name, CLISH_SYM_TYPE_ACTION, BOOL_FALSE)))
-		return s;
-	clish_sym__set_api(s, CLISH_SYM_API_STDOUT);
-
-	return s;
-}
-
-/*--------------------------------------------------------- */
-/* Add permanent symbol (can't be turned off by dry-run) */
-clish_sym_t *clish_plugin_add_posym(clish_plugin_t *this,
-	clish_hook_oaction_fn_t *func, const char *name)
-{
-	clish_sym_t *s;
-
-	if (!(s = clish_plugin_add_generic(this, func,
-		name, CLISH_SYM_TYPE_ACTION, BOOL_TRUE)))
-		return s;
-	clish_sym__set_api(s, CLISH_SYM_API_STDOUT);
-
-	return s;
-}
-
-/*--------------------------------------------------------- */
-clish_sym_t *clish_plugin_add_hook(clish_plugin_t *this,
-	void *func, const char *name, int type)
-{
-	return clish_plugin_add_generic(this, func,
-		name, type, BOOL_FALSE);
-}
-
-/*--------------------------------------------------------- */
-clish_sym_t *clish_plugin_add_phook(clish_plugin_t *this,
-	void *func, const char *name, int type)
-{
-	return clish_plugin_add_generic(this, func,
-		name, type, BOOL_TRUE);
-}
-
-/*--------------------------------------------------------- */
-clish_sym_t *clish_plugin_get_sym(clish_plugin_t *this, const char *name, int type)
-{
-	lub_list_node_t *iter;
-	clish_sym_t *sym;
-
-	/* Iterate elements */
-	for(iter = lub_list__get_head(this->syms);
-		iter; iter = lub_list_node__get_next(iter)) {
-		int res;
-		sym = (clish_sym_t *)lub_list_node__get_data(iter);
-		res = strcmp(clish_sym__get_name(sym), name);
-		if (!res && ((CLISH_SYM_TYPE_NONE == type) || (clish_sym__get_type(sym) == type)))
-			return sym;
-		if (res > 0) /* No chances to find name */
-			break;
-	}
-
-	return NULL;
-}
-
-/*--------------------------------------------------------- */
-static int clish_plugin_load_shared(clish_plugin_t *this)
-{
-#ifdef HAVE_DLFCN_H
-	char *file = NULL; /* Plugin so file name */
-	char *init_name = NULL; /* Init function name */
-	int flag = RTLD_NOW;
-
-	if (this->file) {
-		file = lub_string_dup(this->file);
-	} else {
-		lub_string_cat(&file, "clish_plugin_");
-		lub_string_cat(&file, this->name);
-		lub_string_cat(&file, ".so");
-	}
-
-	/* Open dynamic library */
-	if (clish_plugin__get_rtld_global(this))
-		flag |= RTLD_GLOBAL;
-	else
-		flag |= RTLD_LOCAL;
-	this->dlhan = dlopen(file, flag);
-	lub_string_free(file);
-	if (!this->dlhan) {
-		fprintf(stderr, "Error: Can't open plugin \"%s\": %s\n",
-			this->name, dlerror());
-		return -1;
-	}
-
-	/* Get plugin init function */
-	lub_string_cat(&init_name, CLISH_PLUGIN_INIT_NAME_PREFIX);
-	lub_string_cat(&init_name, this->name);
-	lub_string_cat(&init_name, CLISH_PLUGIN_INIT_NAME_SUFFIX);
-	this->init = (clish_plugin_init_t *)dlsym(this->dlhan, init_name);
-	lub_string_free(init_name);
-	if (!this->init) {
-		fprintf(stderr, "Error: Can't get plugin \"%s\" init function: %s\n",
-			this->name, dlerror());
-		return -1;
-	}
-
-	return 0;
-#else /* HAVE_DLFCN_H */
-	/* We have no any dl functions. */
-	fprintf(stderr, "Error: Can't get plugin \"%s\" init function.\n",
-		this->name);
-	return -1;
-#endif /* HAVE_DLFCN_H */
-}
-
-/*--------------------------------------------------------- */
-int clish_plugin_load(clish_plugin_t *this)
-{
-	int res;
-
-	if (!this)
-		return -1;
-	assert(this->name);
-
-	/* Builtin plugins already have init function. */
-	if (!this->builtin_flag) {
-		if (clish_plugin_load_shared(this) < 0)
-			return -1;
-	}
-	if (!this->init) {
-		fprintf(stderr, "Error: PLUGIN %s has no init function\n",
-			this->name);
-		return -1;
-	}
-	/* Execute init function */
-	if ((res = this->init(this->userdata, this)))
-		fprintf(stderr, "Error: Plugin %s init retcode: %d\n",
-			this->name, res);
-
-	return res;
-}
-
-CLISH_SET(plugin, clish_plugin_fini_t *, fini);
-CLISH_GET(plugin, clish_plugin_fini_t *, fini);
-CLISH_SET(plugin, clish_plugin_init_t *, init);
-CLISH_GET(plugin, clish_plugin_init_t *, init);
-CLISH_GET_STR(plugin, name);
-CLISH_SET_STR(plugin, alias);
-CLISH_GET_STR(plugin, alias);
-CLISH_SET_STR(plugin, file);
-CLISH_GET_STR(plugin, file);
-CLISH_SET_STR(plugin, conf);
-CLISH_GET_STR(plugin, conf);
-CLISH_SET(plugin, bool_t, builtin_flag);
-CLISH_GET(plugin, bool_t, builtin_flag);
-CLISH_SET(plugin, bool_t, rtld_global);
-CLISH_GET(plugin, bool_t, rtld_global);
-
-/*--------------------------------------------------------- */
-_CLISH_GET_STR(plugin, pubname)
-{
-	assert(inst);
-	return (inst->alias ? inst->alias : inst->name);
-}

+ 0 - 75
clish/plugin/plugin_dump.c

@@ -1,75 +0,0 @@
-#ifdef DEBUG
-
-/*
- * plugin_dump.c
- */
-#include "private.h"
-#include "lub/dump.h"
-#include "lub/list.h"
-#include "clish/plugin.h"
-
-/*--------------------------------------------------------- */
-void clish_sym_dump(const clish_sym_t *this)
-{
-	char *type = NULL;
-
-	lub_dump_printf("sym(%p)\n", this);
-
-	lub_dump_indent();
-	lub_dump_printf("name      : %s\n", LUB_DUMP_STR(this->name));
-	lub_dump_printf("func      : %p\n", LUB_DUMP_STR(this->func));
-	switch (this->type) {
-	case CLISH_SYM_TYPE_NONE:
-		type = "none";
-		break;
-	case CLISH_SYM_TYPE_ACTION:
-		type = "action";
-		break;
-	case CLISH_SYM_TYPE_ACCESS:
-		type = "access";
-		break;
-	case CLISH_SYM_TYPE_CONFIG:
-		type = "config";
-		break;
-	case CLISH_SYM_TYPE_LOG:
-		type = "log";
-		break;
-	default:
-		type = "unknown";
-		break;
-	}
-	lub_dump_printf("type      : %s\n", type);
-	lub_dump_printf("permanent : %s\n", LUB_DUMP_BOOL(this->permanent));
-	lub_dump_printf("plugin    : %p\n", this->plugin);
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-void clish_plugin_dump(const clish_plugin_t *this)
-{
-	lub_list_node_t *iter;
-	clish_sym_t *sym;
-
-	lub_dump_printf("plugin(%p)\n", this);
-	lub_dump_indent();
-	lub_dump_printf("name        : %s\n", LUB_DUMP_STR(this->name));
-	lub_dump_printf("alias       : %s\n", LUB_DUMP_STR(this->alias));
-	lub_dump_printf("conf        : %s\n", LUB_DUMP_STR(this->conf));
-	lub_dump_printf("dlhan       : %p\n", this->dlhan);
-	lub_dump_printf("init        : %p\n", this->init);
-	lub_dump_printf("fini        : %p\n", this->fini);
-	lub_dump_printf("rtld_global : %s\n", LUB_DUMP_BOOL(this->rtld_global));
-	lub_dump_indent();
-	/* Iterate child elements */
-	for(iter = lub_list__get_head(this->syms);
-		iter; iter = lub_list_node__get_next(iter)) {
-		sym = (clish_sym_t *)lub_list_node__get_data(iter);
-		clish_sym_dump(sym);
-	}
-	lub_dump_undent();
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 33
clish/plugin/private.h

@@ -1,33 +0,0 @@
-/*
- * plugin private.h
- */
-
-#include "lub/list.h"
-#include "clish/plugin.h"
-
-/*---------------------------------------------------------
- * PRIVATE TYPES
- *--------------------------------------------------------- */
-
-struct clish_sym_s {
-	char *name; /* Symbol name */
-	const void *func; /* Function address */
-	int type; /* Function type */
-	clish_sym_api_e api; /* Function API */
-	bool_t permanent; /* If permanent the dry-run can't switch it off */
-	clish_plugin_t *plugin; /* Parent plugin */
-};
-
-struct clish_plugin_s {
-	char *name; /* Plugin name. */
-	char *alias; /* User defined plugin name. Can be used in builtin ref. */
-	char *file; /* Shared object file name. */
-	bool_t builtin_flag; /* If plugin is built into binary */
-	char *conf; /* The content of <PLUGIN>...</PLUGIN> */
-	lub_list_t *syms; /* List of plugin symbols */
-	void *dlhan; /* Handler of dlopen() */
-	clish_plugin_init_t *init; /* Init function (constructor) != NULL */
-	clish_plugin_fini_t *fini; /* Fini function (destructor) */
-	bool_t rtld_global; /* RTLD_GLOBAL flag for dlopen() */
-	void *userdata; /* Arbitrary userdata to pass to ini and fini functions */
-};

+ 0 - 80
clish/plugin/sym.c

@@ -1,80 +0,0 @@
-/*
- * plugin.c
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include "private.h"
-#include "lub/string.h"
-#include "lub/list.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-#ifdef HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
-
-/*--------------------------------------------------------- */
-int clish_sym_compare(const void *first, const void *second)
-{
-	const clish_sym_t *f = (const clish_sym_t *)first;
-	const clish_sym_t *s = (const clish_sym_t *)second;
-
-	return strcmp(f->name, s->name);
-}
-
-/*--------------------------------------------------------- */
-clish_sym_t *clish_sym_new(const char *name, void *func, int type)
-{
-	clish_sym_t *this;
-
-	this = malloc(sizeof(*this));
-	this->name = lub_string_dup(name);
-	this->func = func;
-	this->type = type;
-	this->api = CLISH_SYM_API_SIMPLE;
-	this->permanent = BOOL_FALSE;
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_sym_free(void *data)
-{
-	clish_sym_t *this = (clish_sym_t *)data;
-	if (!data)
-		return;
-	lub_string_free(this->name);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src)
-{
-	char *name;
-
-	if (!dst || !src)
-		return -1;
-	name = dst->name;
-	*dst = *src;
-	dst->name = name;
-
-	return 0;
-}
-
-CLISH_SET(sym, const void *, func);
-CLISH_GET(sym, const void *, func);
-CLISH_SET(sym, bool_t, permanent);
-CLISH_GET(sym, bool_t, permanent);
-CLISH_SET_STR(sym, name);
-CLISH_GET_STR(sym, name);
-CLISH_SET(sym, clish_plugin_t *, plugin);
-CLISH_GET(sym, clish_plugin_t *, plugin);
-CLISH_SET(sym, int, type);
-CLISH_GET(sym, int, type);
-CLISH_SET(sym, clish_sym_api_e, api);
-CLISH_GET(sym, clish_sym_api_e, api);

+ 0 - 17
clish/plugin_builtin.c.in

@@ -1,17 +0,0 @@
-/*
- * plugin_builtin.c.in
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include "clish/plugin.h"
-
-/* Declare builtin plugin's init functions */
-@CLISH_PLUGIN_BUILTIN_DEFS@
-
-/* The array of builtin plugin's filled by configure script. */
-clish_plugin_builtin_list_t clish_plugin_builtin_list[] = {@CLISH_PLUGIN_BUILTIN_LIST@ { NULL, NULL } };
-

+ 0 - 10
clish/private.h

@@ -1,10 +0,0 @@
-/*
- * private.h
- */
-
-#ifndef _clish_private_h
-#define _clish_private_h
-
-#include "lub/c_decl.h"
-
-#endif /* _clish_private_h */

+ 0 - 97
clish/ptype.h

@@ -1,97 +0,0 @@
-/*
- * ptype.h
- * Types are a syntatical template which parameters reference.
- */
-
-#ifndef _clish_ptype_h
-#define _clish_ptype_h
-
-typedef struct clish_ptype_s clish_ptype_t;
-
-#include "lub/types.h"
-#include "clish/macros.h"
-#include "lub/argv.h"
-#include "clish/action.h"
-
-#include <stddef.h>
-
-/* The means by which the pattern is interpreted and validated. */
-typedef enum {
-	/* [default] - A POSIX regular expression. */
-	CLISH_PTYPE_METHOD_REGEXP,
-	/* A numeric definition "min..max" signed and unsigned versions */
-	CLISH_PTYPE_METHOD_INTEGER,
-	CLISH_PTYPE_METHOD_UNSIGNEDINTEGER,
-	/* A list of possible values. The syntax of the string is of the form:
-	* "valueOne(ONE) valueTwo(TWO) valueThree(THREE)" where the text before
-	* the parethesis defines the syntax that the user must use, and the
-	* value within the parenthesis is the result expanded as a parameter value.
-	*/
-	CLISH_PTYPE_METHOD_SELECT,
-	/* User-defined code in ACTION */
-	CLISH_PTYPE_METHOD_CODE,
-	/* Used to detect errors */
-	CLISH_PTYPE_METHOD_MAX
-
-} clish_ptype_method_e;
-
-/* This defines the pre processing which is to be performed before a string is validated. */
-typedef enum {
-	/* [default] - do nothing */
-	CLISH_PTYPE_PRE_NONE,
-	/* before validation convert to uppercase. */
-	CLISH_PTYPE_PRE_TOUPPER,
-	/* before validation convert to lowercase. */
-	CLISH_PTYPE_PRE_TOLOWER,
-	/* Used to detect errors */
-	CLISH_PTYPE_PRE_MAX
-} clish_ptype_preprocess_e;
-
-int clish_ptype_compare(const void *first, const void *second);
-const char *clish_ptype__get_method_name(clish_ptype_method_e method);
-clish_ptype_method_e clish_ptype_method_resolve(const char *method_name);
-const char *clish_ptype__get_preprocess_name(clish_ptype_preprocess_e preprocess);
-clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char *preprocess_name);
-clish_ptype_t *clish_ptype_new(const char *name, const char *text,
-	const char *pattern, clish_ptype_method_e method,
-	clish_ptype_preprocess_e preprocess);
-
-void clish_ptype_free(void *instance);
-/**
- * This is the validation method for the specified type.
- * \return
- * - NULL if the validation is negative.
- * - A pointer to a string containing the validated text. NB. this
- *   may not be identical to that passed in. e.g. it may have been
- *   a case-modified "select" or a preprocessed value.
- */
-char *clish_ptype_validate(clish_ptype_t * instance, const char *text);
-/**
- * This is the translation method for the specified type. The text is
- * first validated then translated into the form which should be used
- * for variable substitutions in ACTION or VIEW_ID fields.
- * \return
- * - NULL if the validation is negative.
- * - A pointer to a string containing the translated text. NB. this
- *   may not be identical to that passed in. e.g. it may have been
- *   a translated "select" value.
- */
-char *clish_ptype_translate(clish_ptype_t * instance, const char *text);
-/**
- * This is used to perform parameter auto-completion
- */
-void clish_ptype_word_generator(clish_ptype_t * instance,
-	lub_argv_t *matches, const char *text);
-void clish_ptype_dump(clish_ptype_t * instance);
-
-_CLISH_GET_STR(ptype, name);
-_CLISH_SET_STR_ONCE(ptype, text);
-_CLISH_GET_STR(ptype, text);
-_CLISH_SET_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
-_CLISH_GET_STR(ptype, range);
-_CLISH_GET(ptype, clish_action_t *, action);
-
-void clish_ptype__set_pattern(clish_ptype_t * instance,
-	const char *pattern, clish_ptype_method_e method);
-
-#endif	/* _clish_ptype_h */

+ 0 - 4
clish/ptype/module.am

@@ -1,4 +0,0 @@
-libclish_la_SOURCES += \
-	clish/ptype/ptype.c \
-	clish/ptype/ptype_dump.c \
-	clish/ptype/private.h

+ 0 - 41
clish/ptype/private.h

@@ -1,41 +0,0 @@
-/*
- * ptype.h
- */
-#include "clish/pargv.h"
-#include "lub/argv.h"
-
-#include <sys/types.h>
-#include <regex.h>
-
-typedef struct clish_ptype_integer_s clish_ptype_integer_t;
-struct clish_ptype_integer_s {
-	int min;
-	int max;
-};
-
-typedef struct clish_ptype_select_s clish_ptype_select_t;
-struct clish_ptype_select_s {
-	lub_argv_t *items;
-};
-
-typedef struct clish_ptype_regex_s clish_ptype_regex_t;
-struct clish_ptype_regex_s {
-	bool_t is_compiled;
-	regex_t re;
-};
-
-struct clish_ptype_s {
-	char *name;
-	char *text;
-	char *pattern;
-	char *range;
-	clish_ptype_method_e method;
-	clish_ptype_preprocess_e preprocess;
-	unsigned int last_name; /* Index used for auto-completion */
-	union {
-		clish_ptype_regex_t regex;
-		clish_ptype_integer_t integer;
-		clish_ptype_select_t select;
-	} u;
-	clish_action_t *action;
-};

+ 0 - 506
clish/ptype/ptype.c

@@ -1,506 +0,0 @@
-/*
- * ptype.c
- */
-#include "private.h"
-#include "lub/string.h"
-#include "lub/ctype.h"
-#include "lub/argv.h"
-#include "lub/conv.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <limits.h>
-#include <stdio.h>
-
-/*--------------------------------------------------------- */
-int clish_ptype_compare(const void *first, const void *second)
-{
-	const clish_ptype_t *f = (const clish_ptype_t *)first;
-	const clish_ptype_t *s = (const clish_ptype_t *)second;
-
-	return strcmp(f->name, s->name);
-}
-
-/*--------------------------------------------------------- */
-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(this);
-	assert(name);
-	this->name = lub_string_dup(name);
-	this->text = NULL;
-	this->pattern = NULL;
-	this->preprocess = preprocess;
-	this->range = NULL;
-	this->action = clish_action_new();
-
-	if (pattern) {
-		/* set the pattern for this type */
-		clish_ptype__set_pattern(this, pattern, method);
-	} else {
-		/* The method is regexp by default */
-		this->method = CLISH_PTYPE_METHOD_REGEXP;
-	}
-	
-	/* set the help text for this type */
-	if (text)
-		clish_ptype__set_text(this, text);
-}
-
-/*--------------------------------------------------------- */
-static void clish_ptype_fini(clish_ptype_t * this)
-{
-	if (this->pattern) {
-		switch (this->method) {
-		case CLISH_PTYPE_METHOD_REGEXP:
-			if (this->u.regex.is_compiled)
-				regfree(&this->u.regex.re);
-			break;
-		case CLISH_PTYPE_METHOD_INTEGER:
-		case CLISH_PTYPE_METHOD_UNSIGNEDINTEGER:
-			break;
-		case CLISH_PTYPE_METHOD_SELECT:
-			lub_argv_delete(this->u.select.items);
-			break;
-		default:
-			break;
-		}
-	}
-
-	lub_string_free(this->name);
-	lub_string_free(this->text);
-	lub_string_free(this->pattern);
-	lub_string_free(this->range);
-	clish_action_delete(this->action);
-}
-
-/*--------------------------------------------------------- */
-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)
-{
-	clish_ptype_t *this = malloc(sizeof(clish_ptype_t));
-
-	if (this)
-		clish_ptype_init(this, name, help, pattern, method, preprocess);
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_ptype_free(void *data)
-{
-	clish_ptype_t *this = (clish_ptype_t *)data;
-	clish_ptype_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-static char *clish_ptype_select__get_name(const clish_ptype_t *this,
-	unsigned int index)
-{
-	char *res = NULL;
-	size_t name_len;
-	const char *arg = lub_argv__get_arg(this->u.select.items, index);
-
-	if (!arg)
-		return NULL;
-	name_len = strlen(arg);
-	const char *lbrk = strchr(arg, '(');
-	if (lbrk)
-		name_len = (size_t) (lbrk - arg);
-	res = lub_string_dupn(arg, name_len);
-
-	return res;
-}
-
-/*--------------------------------------------------------- */
-static char *clish_ptype_select__get_value(const clish_ptype_t *this,
-	unsigned int index)
-{
-	char *res = NULL;
-	const char *lbrk, *rbrk, *value;
-	size_t value_len;
-	const char *arg = lub_argv__get_arg(this->u.select.items, index);
-
-	if (!arg)
-		return NULL;
-
-	lbrk = strchr(arg, '(');
-	rbrk = strchr(arg, ')');
-	value = arg;
-	value_len = strlen(arg);
-	if (lbrk) {
-		value = lbrk + 1;
-		if (rbrk)
-			value_len = (size_t) (rbrk - value);
-	}
-	res = lub_string_dupn(value, value_len);
-
-	return res;
-}
-
-/*--------------------------------------------------------- */
-static void clish_ptype__set_range(clish_ptype_t * this)
-{
-	char tmp[80];
-
-	/* Now set up the range values */
-	switch (this->method) {
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_REGEXP:
-		/* Nothing more to do */
-		break;
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_INTEGER:
-		/* Setup the integer range */
-		snprintf(tmp, sizeof(tmp), "%d..%d",
-			this->u.integer.min, this->u.integer.max);
-		tmp[sizeof(tmp) - 1] = '\0';
-		this->range = lub_string_dup(tmp);
-		break;
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_UNSIGNEDINTEGER:
-		/* Setup the unsigned integer range */
-		snprintf(tmp, sizeof(tmp), "%u..%u",
-			(unsigned int)this->u.integer.min,
-			(unsigned int)this->u.integer.max);
-		tmp[sizeof(tmp) - 1] = '\0';
-		this->range = lub_string_dup(tmp);
-		break;
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_SELECT:
-	{
-		/* Setup the selection values to the help text */
-		unsigned int i;
-
-		for (i = 0; i < lub_argv__get_count(this->u.select.items); i++) {
-			char *name = clish_ptype_select__get_name(this, i);
-
-			if (i > 0)
-				lub_string_cat(&this->range, "/");
-			snprintf(tmp, sizeof(tmp), "%s", name);
-			tmp[sizeof(tmp) - 1] = '\0';
-			lub_string_cat(&this->range, tmp);
-			lub_string_free(name);
-		}
-		break;
-	}
-	/*------------------------------------------------- */
-	default:
-		break;
-	/*------------------------------------------------- */
-	}
-}
-
-/*--------------------------------------------------------- */
-static const char *method_names[] = {
-	"regexp",
-	"integer",
-	"unsignedInteger",
-	"select",
-	"code"
-};
-
-/*--------------------------------------------------------- */
-const char *clish_ptype__get_method_name(clish_ptype_method_e method)
-{
-	if (method >= CLISH_PTYPE_METHOD_MAX)
-		return NULL;
-	return method_names[method];
-}
-
-/*--------------------------------------------------------- */
-/* Return value of CLISH_PTYPE_METHOD_MAX indicates an illegal method */
-clish_ptype_method_e clish_ptype_method_resolve(const char *name)
-{
-	unsigned int i;
-
-	if (NULL == name)
-		return CLISH_PTYPE_METHOD_REGEXP;
-	for (i = 0; i < CLISH_PTYPE_METHOD_MAX; i++) {
-		if (!strcmp(name, method_names[i]))
-			break;
-	}
-
-	return (clish_ptype_method_e)i;
-}
-
-/*--------------------------------------------------------- */
-static const char *preprocess_names[] = {
-	"none",
-	"toupper",
-	"tolower"
-};
-
-/*--------------------------------------------------------- */
-const char *clish_ptype__get_preprocess_name(clish_ptype_preprocess_e preprocess)
-{
-	if (preprocess >= CLISH_PTYPE_PRE_MAX)
-		return NULL;
-
-	return preprocess_names[preprocess];
-}
-
-/*--------------------------------------------------------- */
-/* Return value of CLISH_PTYPE_PRE_MAX indicates an illegal method */
-clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char *name)
-{
-	unsigned int i;
-
-	if (NULL == name)
-		return CLISH_PTYPE_PRE_NONE;
-	for (i = 0; i < CLISH_PTYPE_PRE_MAX; i++) {
-		if (!strcmp(name, preprocess_names[i]))
-			break;
-	}
-
-	return (clish_ptype_preprocess_e)i;
-}
-
-/*--------------------------------------------------------- */
-void clish_ptype_word_generator(clish_ptype_t * this,
-	lub_argv_t *matches, const char *text)
-{
-	char *result = NULL;
-	unsigned int i = 0;
-
-	/* Only METHOD_SELECT has completions */
-	if (this->method != CLISH_PTYPE_METHOD_SELECT)
-		return;
-
-	/* First of all simply try to validate the result */
-	result = clish_ptype_validate(this, text);
-	if (result) {
-		lub_argv_add(matches, result);
-		lub_string_free(result);
-		return;
-	}
-
-	/* Iterate possible completion */
-	while ((result = clish_ptype_select__get_name(this, i++))) {
-		/* get the next item and check if it is a completion */
-		if (result == lub_string_nocasestr(result, text))
-			lub_argv_add(matches, result);
-		lub_string_free(result);
-	}
-}
-
-/*--------------------------------------------------------- */
-static char *clish_ptype_validate_or_translate(clish_ptype_t * this,
-	const char *text, bool_t translate)
-{
-	char *result = lub_string_dup(text);
-	assert(this->pattern);
-
-	switch (this->preprocess) {
-	/*----------------------------------------- */
-	case CLISH_PTYPE_PRE_NONE:
-		break;
-	/*----------------------------------------- */
-	case CLISH_PTYPE_PRE_TOUPPER:
-	{
-		char *p = result;
-		while (*p) {
-			*p = lub_ctype_toupper(*p);
-			p++;
-		}
-		break;
-	}
-	/*----------------------------------------- */
-	case CLISH_PTYPE_PRE_TOLOWER:
-	{
-		char *p = result;
-		while (*p) {
-			*p = lub_ctype_tolower(*p);
-			p++;
-		}
-		break;
-	}
-	/*----------------------------------------- */
-	default:
-		break;
-	}
-
-	/* Validate according the specified method */
-	switch (this->method) {
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_REGEXP:
-		/* Lazy compilation of the regular expression */
-		if (!this->u.regex.is_compiled) {
-			if (regcomp(&this->u.regex.re, this->pattern,
-				REG_NOSUB | REG_EXTENDED)) {
-				lub_string_free(result);
-				result = NULL;
-				break;
-			}
-			this->u.regex.is_compiled = BOOL_TRUE;
-		}
-
-		if (regexec(&this->u.regex.re, result, 0, NULL, 0)) {
-			lub_string_free(result);
-			result = NULL;
-		}
-		break;
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_INTEGER:
-	{
-		/* first of all check that this is a number */
-		bool_t ok = BOOL_TRUE;
-		const char *p = result;
-		int value = 0;
-
-		if (*p == '-')
-			p++;
-		while (*p) {
-			if (!lub_ctype_isdigit(*p++)) {
-				ok = BOOL_FALSE;
-				break;
-			}
-		}
-		if (BOOL_FALSE == ok) {
-			lub_string_free(result);
-			result = NULL;
-			break;
-		}
-		/* Convert to number and check the range */
-		if ((lub_conv_atoi(result, &value, 0) < 0) ||
-			(value < this->u.integer.min) ||
-			(value > this->u.integer.max)) {
-			lub_string_free(result);
-			result = NULL;
-			break;
-		}
-		break;
-	}
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_UNSIGNEDINTEGER:
-	{
-		/* first of all check that this is a number */
-		bool_t ok = BOOL_TRUE;
-		const char *p = result;
-		unsigned int value = 0;
-		while (p && *p) {
-			if (!lub_ctype_isdigit(*p++)) {
-				ok = BOOL_FALSE;
-				break;
-			}
-		}
-		if (BOOL_FALSE == ok) {
-			lub_string_free(result);
-			result = NULL;
-			break;
-		}
-		/* Convert to number and check the range */
-		if ((lub_conv_atoui(result, &value, 0) < 0) ||
-			(value < (unsigned)this->u.integer.min) ||
-			(value > (unsigned)this->u.integer.max)) {
-			lub_string_free(result);
-			result = NULL;
-			break;
-		}
-		break;
-	}
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_SELECT:
-	{
-		unsigned int 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;
-			}
-			lub_string_free((BOOL_TRUE == translate) ? value : name);
-		}
-		if (i == lub_argv__get_count(this->u.select.items)) {
-			/* failed to find a match */
-			lub_string_free(result);
-			result = NULL;
-			break;
-		}
-		break;
-	}
-	/*------------------------------------------------- */
-	default:
-		break;
-	}
-	return (char *)result;
-}
-
-/*--------------------------------------------------------- */
-char *clish_ptype_validate(clish_ptype_t * this, const char *text)
-{
-	return clish_ptype_validate_or_translate(this, text, BOOL_FALSE);
-}
-
-/*--------------------------------------------------------- */
-char *clish_ptype_translate(clish_ptype_t * this, const char *text)
-{
-	return clish_ptype_validate_or_translate(this, text, BOOL_TRUE);
-}
-
-CLISH_GET_STR(ptype, name);
-CLISH_SET_STR_ONCE(ptype, text);
-CLISH_GET_STR(ptype, text);
-CLISH_SET_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
-CLISH_GET_STR(ptype, range);
-CLISH_GET(ptype, clish_action_t *, action);
-
-/*--------------------------------------------------------- */
-void clish_ptype__set_pattern(clish_ptype_t * this,
-	const char *pattern, clish_ptype_method_e method)
-{
-	assert(NULL == this->pattern);
-	this->method = method;
-
-	switch (this->method) {
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_REGEXP:
-	{
-		lub_string_cat(&this->pattern, "^");
-		lub_string_cat(&this->pattern, pattern);
-		lub_string_cat(&this->pattern, "$");
-		/* Use lazy mechanism to compile regular expressions */
-		this->u.regex.is_compiled = BOOL_FALSE;
-		break;
-	}
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_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;
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_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;
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_METHOD_SELECT:
-		this->pattern = lub_string_dup(pattern);
-		/* store a vector of item descriptors */
-		this->u.select.items = lub_argv_new(this->pattern, 0);
-		break;
-	/*------------------------------------------------- */
-	default:
-		break;
-	}
-	/* now set up the range details */
-	clish_ptype__set_range(this);
-}

+ 0 - 26
clish/ptype/ptype_dump.c

@@ -1,26 +0,0 @@
-#ifdef DEBUG
-
-/*
- * ptype_dump.c
- */
-#include "private.h"
-#include "lub/dump.h"
-
-/*--------------------------------------------------------- */
-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", 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__get_method_name(this->method));
-	lub_dump_printf("postprocess: %s\n",
-		clish_ptype_preprocess__get_name(this->preprocess));
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 235
clish/shell.h

@@ -1,235 +0,0 @@
-/*
- * shell.h
- */
- /**
-\ingroup clish
-\defgroup clish_shell shell
-@{
-
-\brief This class represents the top level container for a CLI session.
-
-*/
-#ifndef _clish_shell_h
-#define _clish_shell_h
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <pwd.h>
-
-#include "lub/c_decl.h"
-#include "lub/types.h"
-#include "lub/argv.h"
-#include "tinyrl/tinyrl.h"
-#include "clish/macros.h"
-#include "clish/view.h"
-#include "clish/ptype.h"
-#include "clish/var.h"
-#include "clish/plugin.h"
-#include "konf/net.h"
-
-#define CLISH_LOCK_PATH "/tmp/clish.lock"
-#define CLISH_LOCK_WAIT 20
-
-#define CLISH_STDOUT_CHUNK 1024
-#define CLISH_STDOUT_MAXBUF (CLISH_STDOUT_CHUNK * 1024)
-
-#define CLISH_XML_ERROR_STR "Error parsing XML: "
-#define CLISH_XML_ERROR_ATTR(attr) CLISH_XML_ERROR_STR"The \""attr"\" attribute is required.\n"
-
-typedef struct clish_shell_s clish_shell_t;
-typedef struct clish_context_s clish_context_t;
-
-/* Context functions */
-
-_BEGIN_C_DECL
-clish_context_t *clish_context_new(clish_shell_t *shell);
-int clish_context_init(clish_context_t *instance, clish_shell_t *shell);
-void clish_context_free(clish_context_t *instance);
-int clish_context_dup(clish_context_t *dst, const clish_context_t *src);
-
-clish_shell_t *clish_context__get_shell(const void *instance);
-void clish_context__set_cmd(void *instance, const clish_command_t *cmd);
-const clish_command_t *clish_context__get_cmd(const void *instance);
-void clish_context__set_pargv(void *instance, clish_pargv_t *pargv);
-clish_pargv_t *clish_context__get_pargv(const void *instance);
-void clish_context__set_action(void *instance, const clish_action_t *action);
-const clish_action_t *clish_context__get_action(const void *instance);
-_END_C_DECL
-
-/* Shell */
-
-typedef enum {
-	SHELL_STATE_OK = 0,
-	SHELL_STATE_UNKNOWN = 1,
-	SHELL_STATE_IO_ERROR = 2,
-	SHELL_STATE_SCRIPT_ERROR = 3,/* Script execution error */
-	SHELL_STATE_SYNTAX_ERROR = 4, /* Illegal line entered */
-	SHELL_STATE_SYSTEM_ERROR = 5, /* Some internal system error */
-	SHELL_STATE_INITIALISING = 6,
-	SHELL_STATE_HELPING = 7,
-	SHELL_STATE_EOF = 8, /* EOF of input stream */
-	SHELL_STATE_CLOSING = 9
-} clish_shell_state_e;
-
-typedef enum {
-	SHELL_VAR_NONE, /* Nothing to escape */
-	SHELL_VAR_ACTION, /* Variable expanding for ACTION script */
-	SHELL_VAR_REGEX /* Variable expanding for regex usage */
-} clish_shell_var_e;
-
-typedef enum {
-	SHELL_EXPAND_PARAM = 1,
-	SHELL_EXPAND_VIEW = 2,
-	SHELL_EXPAND_CONTEXT = 4,
-	SHELL_EXPAND_VAR = 8,
-	SHELL_EXPAND_ENV = 16,
-	SHELL_EXPAND_ALL = 255
-} clish_shell_expand_e;
-
-_BEGIN_C_DECL
-
-clish_shell_t *clish_shell_new(FILE *istream, FILE *ostream, bool_t stop_on_error);
-int clish_shell_startup(clish_shell_t *instance);
-void clish_shell_delete(clish_shell_t *instance);
-clish_view_t *clish_shell_find_create_view(clish_shell_t *instance, const char *name);
-clish_ptype_t *clish_shell_find_create_ptype(clish_shell_t *instance,
-	const char *name,
-	const char *text,
-	const char *pattern,
-	clish_ptype_method_e method,
-	clish_ptype_preprocess_e preprocess);
-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);
-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);
-void clish_shell_dump(clish_shell_t * instance);
-/**
- * Push the specified file handle on to the stack of file handles
- * for this shell. The specified file will become the source of 
- * commands, until it is exhausted.
- *
- * \return
- * BOOL_TRUE - the file was successfully associated with the shell.
- * BOOL_FALSE - there was insufficient resource to associate this file.
- */
-int clish_shell_push_file(clish_shell_t * instance, const char * fname,
-	bool_t stop_on_error);
-int clish_shell_push_fd(clish_shell_t * instance, FILE * file,
-	bool_t stop_on_error);
-void clish_shell_insert_var(clish_shell_t *instance, clish_var_t *var);
-clish_var_t *clish_shell_find_var(clish_shell_t *instance, const char *name);
-char *clish_shell_expand_var(const char *name, clish_context_t *context);
-char *clish_shell_expand_var_ex(const char *name, clish_context_t *context, clish_shell_expand_e flags);
-char *clish_shell_expand(const char *str, clish_shell_var_e vtype, clish_context_t *context);
-char * clish_shell_mkfifo(clish_shell_t * instance, char *name, size_t n);
-int clish_shell_rmfifo(clish_shell_t * instance, const char *name);
-
-/*-----------------
- * attributes
- *----------------- */
-_CLISH_GET_STR(shell, overview);
-_CLISH_SET_STR(shell, lockfile);
-_CLISH_GET_STR(shell, lockfile);
-_CLISH_SET_STR(shell, default_shebang);
-_CLISH_GET_STR(shell, default_shebang);
-_CLISH_SET(shell, unsigned int, idle_timeout);
-_CLISH_SET(shell, unsigned int, wdog_timeout);
-_CLISH_GET(shell, unsigned int, wdog_timeout);
-_CLISH_GET(shell, unsigned int, depth);
-_CLISH_SET(shell, int, log_facility);
-_CLISH_GET(shell, int, log_facility);
-_CLISH_GET(shell, konf_client_t *, client);
-_CLISH_GET(shell, struct passwd *, user);
-_CLISH_SET(shell, clish_shell_state_e, state);
-_CLISH_GET(shell, clish_shell_state_e, state);
-_CLISH_SET(shell, bool_t, interactive);
-_CLISH_GET(shell, bool_t, interactive);
-_CLISH_SET(shell, bool_t, log);
-_CLISH_GET(shell, bool_t, log);
-_CLISH_SET(shell, bool_t, dryrun);
-_CLISH_GET(shell, bool_t, dryrun);
-_CLISH_SET(shell, bool_t, canon_out);
-_CLISH_GET(shell, bool_t, canon_out);
-
-clish_view_t *clish_shell__get_view(const clish_shell_t * instance);
-clish_view_t *clish_shell__set_depth(clish_shell_t *instance, unsigned int depth);
-const char *clish_shell__get_viewid(const clish_shell_t * instance);
-tinyrl_t *clish_shell__get_tinyrl(const clish_shell_t * instance);
-void clish_shell__set_pwd(clish_shell_t *instance, const char * line,
-	clish_view_t * view, const char * viewid, clish_context_t *context);
-char *clish_shell__get_pwd_line(const clish_shell_t * instance,
-	 unsigned int index);
-clish_pargv_t *clish_shell__get_pwd_pargv(const clish_shell_t *instance,
-	unsigned int index);
-char *clish_shell__get_pwd_cmd(const clish_shell_t *instance,
-	unsigned int index);
-char *clish_shell__get_pwd_prefix(const clish_shell_t *instance,
-	unsigned int index);
-char *clish_shell__get_pwd_full(const clish_shell_t * instance,
-	unsigned int depth);
-clish_view_t *clish_shell__get_pwd_view(const clish_shell_t * instance,
-	unsigned int index);
-FILE *clish_shell__get_istream(const clish_shell_t * instance);
-FILE *clish_shell__get_ostream(const clish_shell_t * instance);
-int clish_shell__set_socket(clish_shell_t * instance, const char * path);
-int clish_shell_load_scheme(clish_shell_t * instance, const char * xml_path, const char *xslt_path);
-int clish_shell_loop(clish_shell_t * instance);
-void clish_shell__set_startup_view(clish_shell_t * instance, const char * viewname);
-void clish_shell__set_startup_viewid(clish_shell_t * instance, const char * viewid);
-bool_t clish_shell__get_utf8(const clish_shell_t * instance);
-void clish_shell__set_utf8(clish_shell_t * instance, bool_t utf8);
-char *clish_shell__get_line(clish_context_t *context);
-char *clish_shell__get_full_line(clish_context_t *context);
-char *clish_shell__get_params(clish_context_t *context);
-int clish_shell_wdog(clish_shell_t *instance);
-int clish_shell__save_history(const clish_shell_t *instance, const char *fname);
-int clish_shell__restore_history(clish_shell_t *instance, const char *fname);
-void clish_shell__stifle_history(clish_shell_t *instance, unsigned int stifle);
-
-/* Plugin functions */
-clish_plugin_t * clish_shell_create_plugin(clish_shell_t *instance,
-	const char *name);
-clish_plugin_t * clish_shell_find_plugin(clish_shell_t *instance,
-	const char *name);
-clish_plugin_t * clish_shell_find_create_plugin(clish_shell_t *instance,
-	const char *name);
-int clish_shell_load_plugins(clish_shell_t *instance);
-int clish_shell_link_plugins(clish_shell_t *instance);
-
-/* Unresolved symbols functions */
-clish_sym_t *clish_shell_find_sym(clish_shell_t *instance,
-	const char *name, int type);
-clish_sym_t *clish_shell_add_sym(clish_shell_t *instance,
-	void *func, const char *name, int type);
-clish_sym_t *clish_shell_add_unresolved_sym(clish_shell_t *instance,
-	const char *name, int type);
-clish_sym_t *clish_shell_get_hook(const clish_shell_t *instance, int type);
-
-/* Hook wrappers */
-const void *clish_shell_check_hook(const clish_context_t *clish_context, int type);
-CLISH_HOOK_CONFIG(clish_shell_exec_config);
-CLISH_HOOK_LOG(clish_shell_exec_log);
-
-/* User data functions */
-void *clish_shell__get_udata(const clish_shell_t *instance, const char *name);
-void *clish_shell__del_udata(clish_shell_t *instance, const char *name);
-int clish_shell__set_udata(clish_shell_t *instance,
-	const char *name, void *data);
-
-/* Access functions */
-int clish_shell_prepare(clish_shell_t *instance);
-
-/*
- * Non shell specific functions.
- * Start and Stop XML parser engine.
- */
-int clish_xmldoc_start(void);
-int clish_xmldoc_stop(void);
-
-_END_C_DECL
-
-#endif				/* _clish_shell_h */
-/** @} clish_shell */

+ 0 - 106
clish/shell/context.c

@@ -1,106 +0,0 @@
-/*
- * context.c
- */
-
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-int clish_context_init(clish_context_t *this, clish_shell_t *shell)
-{
-	if (!this)
-		return -1;
-	memset(this, 0, sizeof(*this));
-	this->shell = shell;
-
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-clish_context_t *clish_context_new(clish_shell_t *shell)
-{
-	clish_context_t *this;
-
-	if (!shell)
-		return NULL;
-	if (!(this = malloc(sizeof(*this))))
-		return NULL;
-	clish_context_init(this, shell);
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-/* Note it will not free all content because it's a
- * container only.
- */
-void clish_context_free(clish_context_t *this)
-{
-	if (!this)
-		return;
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-int clish_context_dup(clish_context_t *dst, const clish_context_t *src)
-{
-	*dst = *src;
-	return 0;
-}
-
-/*--------------------------------------------------------- */
-clish_shell_t *clish_context__get_shell(const void *this)
-{
-	const clish_context_t *context = (const clish_context_t *)this;
-	return context->shell;
-}
-
-/*--------------------------------------------------------- */
-void clish_context__set_cmd(void *this, const clish_command_t *cmd)
-{
-	clish_context_t *context = (clish_context_t *)this;
-	assert(context);
-	context->cmd = cmd;
-}
-
-/*--------------------------------------------------------- */
-const clish_command_t *clish_context__get_cmd(const void *this)
-{
-	const clish_context_t *context = (const clish_context_t *)this;
-	return context->cmd;
-}
-
-/*--------------------------------------------------------- */
-void clish_context__set_pargv(void *this, clish_pargv_t *pargv)
-{
-	clish_context_t *context = (clish_context_t *)this;
-	assert(context);
-	context->pargv = pargv;
-}
-
-/*--------------------------------------------------------- */
-clish_pargv_t *clish_context__get_pargv(const void *this)
-{
-	const clish_context_t *context = (const clish_context_t *)this;
-	return context->pargv;
-}
-
-/*--------------------------------------------------------- */
-void clish_context__set_action(void *this, const clish_action_t *action)
-{
-	clish_context_t *context = (clish_context_t *)this;
-	assert(context);
-	context->action = action;
-}
-
-/*--------------------------------------------------------- */
-const clish_action_t *clish_context__get_action(const void *this)
-{
-	const clish_context_t *context = (const clish_context_t *)this;
-	return context->action;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 28
clish/shell/module.am

@@ -1,28 +0,0 @@
-libclish_la_SOURCES += \
-	clish/shell/shell_view.c \
-	clish/shell/shell_ptype.c \
-	clish/shell/shell_var.c \
-	clish/shell/shell_command.c \
-	clish/shell/shell_dump.c \
-	clish/shell/shell_execute.c \
-	clish/shell/shell_help.c \
-	clish/shell/shell_new.c \
-	clish/shell/shell_parse.c \
-	clish/shell/shell_file.c \
-	clish/shell/shell_loop.c \
-	clish/shell/shell_startup.c \
-	clish/shell/shell_wdog.c \
-	clish/shell/shell_pwd.c \
-	clish/shell/shell_tinyrl.c \
-	clish/shell/shell_plugin.c \
-	clish/shell/shell_xml.c \
-	clish/shell/private.h \
-	clish/shell/xmlapi.h \
-	clish/shell/shell_roxml.c \
-	clish/shell/shell_libxml2.c \
-	clish/shell/shell_expat.c \
-	clish/shell/shell_udata.c \
-	clish/shell/shell_misc.c \
-	clish/shell/context.c
-
-

+ 0 - 147
clish/shell/private.h

@@ -1,147 +0,0 @@
-/*
- * shell/private.h - private interface to the shell class
- */
-#include "lub/bintree.h"
-#include "lub/list.h"
-#include "tinyrl/tinyrl.h"
-#include "clish/shell.h"
-#include "clish/pargv.h"
-#include "clish/var.h"
-#include "clish/action.h"
-#include "clish/plugin.h"
-#include "clish/udata.h"
-
-/* iterate around commands */
-typedef struct {
-	const char *last_cmd;
-	clish_nspace_visibility_e field;
-} clish_shell_iterator_t;
-
-/* this is used to maintain a stack of file handles */
-typedef struct clish_shell_file_s clish_shell_file_t;
-struct clish_shell_file_s {
-	clish_shell_file_t *next;
-	FILE *file;
-	char *fname;
-	unsigned int line;
-	bool_t stop_on_error; /* stop on error for file input  */
-};
-
-typedef struct {
-	char *line;
-	clish_view_t *view;
-	lub_bintree_t viewid;
-	clish_pargv_t *pargv; /* Saved pargv structure */
-	char *cmd; /* Command name without prefix */
-	char *prefix; /* Prefix string if exists */
-} clish_shell_pwd_t;
-
-/* Context structure */
-struct clish_context_s {
-	clish_shell_t *shell;
-	const clish_command_t *cmd;
-	clish_pargv_t *pargv;
-	const clish_action_t *action;
-};
-
-/* Shell structure */
-struct clish_shell_s {
-	lub_list_t *view_tree; /* VIEW list */
-	lub_list_t *ptype_tree; /* PTYPE list */
-	lub_bintree_t var_tree; /* Tree of global variables */
-
-	/* Hooks */
-	clish_sym_t *hooks[CLISH_SYM_TYPE_MAX]; /* Callback hooks */
-	bool_t hooks_use[CLISH_SYM_TYPE_MAX]; /* Is hook defined */
-
-	clish_view_t *global; /* Reference to the global view. */
-	clish_command_t *startup; /* This is the startup command */
-	unsigned int idle_timeout; /* This is the idle timeout */
-
-	/* Watchdog */
-	clish_command_t *wdog; /* Watchdog command */
-	unsigned int wdog_timeout; /* Watchdog timeout */
-	bool_t wdog_active; /* If watchdog is active now */
-
-	clish_shell_state_e state; /* The current state */
-	char *overview; /* Overview text for this shell */
-	tinyrl_t *tinyrl; /* Tiny readline instance */
-	clish_shell_file_t *current_file; /* file currently in use for input */
-	clish_shell_pwd_t **pwdv; /* Levels for the config file structure */
-	unsigned int pwdc;
-	int depth;
-	konf_client_t *client;
-	char *lockfile;
-	char *default_shebang;
-	char *fifo_temp; /* The template of temporary FIFO file name */
-	struct passwd *user; /* Current user information */
-
-	/* Boolean flags */
-	bool_t interactive; /* Is shell interactive. */
-	bool_t log; /* If command logging is enabled */
-	int log_facility; /* Syslog facility */
-	bool_t dryrun; /* Is this a dry-running */
-	bool_t default_plugin; /* Use or not default plugin */
-	bool_t canon_out; /* Output every command in canonical form (with pre-spaces) */
-
-	/* Plugins and symbols */
-	lub_list_t *plugins; /* List of plugins */
-	lub_list_t *syms; /* List of all used symbols. Must be resolved. */
-
-	/* Userdata list holder */
-	lub_list_t *udata;
-};
-
-/**
- * Initialise a command iterator structure
- */
-void
-clish_shell_iterator_init(clish_shell_iterator_t * iter,
-	clish_nspace_visibility_e field);
-
-/**
- * get the next command which is an extension of the specified line 
- */
-const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
-	instance, const char *line, clish_shell_iterator_t * iter);
-/**
- * Pop the current file handle from the stack of file handles, shutting
- * the file down and freeing any associated memory. The next file handle
- * in the stack becomes associated with the input stream for this shell.
- *
- * \return
- * BOOL_TRUE - the current file handle has been replaced.
- * BOOL_FALSE - there is only one handle on the stack which cannot be replaced.
- */
-int 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_e clish_shell_parse(clish_shell_t * instance,
-	const char *line, const clish_command_t ** cmd, clish_pargv_t ** pargv);
-clish_pargv_status_e clish_shell_parse_pargv(clish_pargv_t *pargv,
-	const clish_command_t *cmd,
-	void *context,
-	clish_paramv_t *paramv,
-	const lub_argv_t *argv,
-	unsigned *idx, clish_pargv_t *last, unsigned need_index);
-char *clish_shell_word_generator(clish_shell_t * instance,
-	const char *line, unsigned offset, unsigned state);
-const clish_command_t *clish_shell_resolve_command(const clish_shell_t *
-	instance, const char *line);
-const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t *
-	instance, const char *line);
-void clish_shell_tinyrl_history(clish_shell_t * instance, unsigned int *limit);
-tinyrl_t *clish_shell_tinyrl_new(FILE * instream,
-	FILE * outstream, unsigned stifle);
-void clish_shell_tinyrl_delete(tinyrl_t * instance);
-void clish_shell_param_generator(clish_shell_t * instance, lub_argv_t *matches,
-	const clish_command_t * cmd, const char *line, unsigned offset);
-char **clish_shell_tinyrl_completion(tinyrl_t * tinyrl,
-	const char *line, unsigned start, unsigned end);
-void clish_shell__expand_viewid(const char *viewid, lub_bintree_t *tree,
-	clish_context_t *context);
-void clish_shell__init_pwd(clish_shell_pwd_t *pwd);
-void clish_shell__fini_pwd(clish_shell_pwd_t *pwd);
-int clish_shell_timeout_fn(tinyrl_t *tinyrl);
-int clish_shell_keypress_fn(tinyrl_t *tinyrl, int key);

+ 0 - 150
clish/shell/shell_command.c

@@ -1,150 +0,0 @@
-/*
- * shell_word_generator.c
- */
-#include <string.h>
-
-#include "private.h"
-#include "lub/string.h"
-#include "lub/argv.h"
-
-/*-------------------------------------------------------- */
-void clish_shell_iterator_init(clish_shell_iterator_t * iter,
-	clish_nspace_visibility_e field)
-{
-	iter->last_cmd = NULL;
-	iter->field = field;
-}
-
-/*--------------------------------------------------------- */
-const clish_command_t *clish_shell_resolve_command(const clish_shell_t * this,
-	const char *line)
-{
-	clish_command_t *cmd, *result;
-
-	/* Search the current view */
-	result = clish_view_resolve_command(clish_shell__get_view(this), line, BOOL_TRUE);
-	/* Search the global view */
-	cmd = clish_view_resolve_command(this->global, line, BOOL_TRUE);
-
-	result = clish_command_choose_longest(result, cmd);
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t * this,
-	const char *line)
-{
-	clish_command_t *cmd, *result;
-
-	/* Search the current view */
-	result = clish_view_resolve_prefix(clish_shell__get_view(this), line, BOOL_TRUE);
-	/* Search the global view */
-	cmd = clish_view_resolve_prefix(this->global, line, BOOL_TRUE);
-
-	result = clish_command_choose_longest(result, cmd);
-
-	return result;
-}
-
-/*-------------------------------------------------------- */
-const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
-	this, const char *line, clish_shell_iterator_t * iter)
-{
-	const clish_command_t *result, *cmd;
-
-	/* ask the local view for next command */
-	result = clish_view_find_next_completion(clish_shell__get_view(this),
-		iter->last_cmd, line, iter->field, BOOL_TRUE);
-	/* ask the global view for next command */
-	cmd = clish_view_find_next_completion(this->global,
-		iter->last_cmd, line, iter->field, BOOL_TRUE);
-
-	if (clish_command_diff(result, cmd) > 0)
-		result = cmd;
-
-	if (!result)
-		iter->last_cmd = NULL;
-	else
-		iter->last_cmd = clish_command__get_name(result);
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-void clish_shell_param_generator(clish_shell_t *this, lub_argv_t *matches,
-	const clish_command_t *cmd, const char *line, unsigned offset)
-{
-	const char *name = clish_command__get_name(cmd);
-	char *text = lub_string_dup(&line[offset]);
-	clish_ptype_t *ptype;
-	unsigned idx = lub_string_wordcount(name);
-	/* get the index of the current parameter */
-	unsigned index = lub_string_wordcount(line) - idx;
-	clish_context_t context;
-
-	if ((0 != index) || (offset && line[offset - 1] == ' ')) {
-		lub_argv_t *argv = lub_argv_new(line, 0);
-		clish_pargv_t *pargv = clish_pargv_new();
-		clish_pargv_t *completion = clish_pargv_new();
-		unsigned completion_index = 0;
-		const clish_param_t *param = NULL;
-
-		/* if there is some text for the parameter then adjust the index */
-		if ((0 != index) && (text[0] != '\0'))
-			index--;
-
-		/* Parse command line to get completion pargv's */
-		/* Prepare context */
-		clish_context_init(&context, this);
-		clish_context__set_cmd(&context, cmd);
-		clish_context__set_pargv(&context, pargv);
-
-		clish_shell_parse_pargv(pargv, cmd, &context,
-			clish_command__get_paramv(cmd),
-			argv, &idx, completion, index + idx);
-		lub_argv_delete(argv);
-
-		while ((param = clish_pargv__get_param(completion,
-			completion_index++))) {
-			const char *result;
-			/* The param is args so it has no completion */
-			if (param == clish_command__get_args(cmd))
-				continue;
-			/* The switch has no completion string */
-			if (CLISH_PARAM_SWITCH == clish_param__get_mode(param))
-				continue;
-			/* The subcommand is identified by it's value */
-			if (CLISH_PARAM_SUBCOMMAND ==
-				clish_param__get_mode(param)) {
-				result = clish_param__get_value(param);
-				if (result)
-					lub_argv_add(matches, result);
-			}
-			/* The 'completion' field of PARAM */
-			if (clish_param__get_completion(param)) {
-				char *str, *q;
-				char *saveptr = NULL;
-				str = clish_shell_expand(
-					clish_param__get_completion(param), SHELL_VAR_ACTION, &context);
-				if (str) {
-					for (q = strtok_r(str, " \n", &saveptr);
-						q; q = strtok_r(NULL, " \n", &saveptr)) {
-						if (q == strstr(q, text))
-							lub_argv_add(matches, q);
-					}
-					lub_string_free(str);
-				}
-			}
-			/* The common PARAM. Let ptype do the work */
-			if ((ptype = clish_param__get_ptype(param)))
-				clish_ptype_word_generator(ptype, matches, text);
-		}
-		clish_pargv_delete(completion);
-		clish_pargv_delete(pargv);
-	}
-
-	lub_string_free(text);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 48
clish/shell/shell_dump.c

@@ -1,48 +0,0 @@
-#ifdef DEBUG
-
-/*
- * shell_dump.c
- */
-#include "private.h"
-#include "lub/dump.h"
-
-/*--------------------------------------------------------- */
-void clish_shell_dump(clish_shell_t * this)
-{
-	clish_view_t *v;
-	clish_ptype_t *t;
-	clish_var_t *var;
-	lub_bintree_iterator_t iter;
-
-	lub_dump_printf("shell(%p)\n", this);
-	lub_dump_printf("OVERVIEW:\n%s\n", LUB_DUMP_STR(this->overview));
-	lub_dump_indent();
-
-	v = lub_bintree_findfirst(&this->view_tree);
-
-	/* iterate the tree of views */
-	for (lub_bintree_iterator_init(&iter, &this->view_tree, v);
-		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)) {
-		clish_ptype_dump(t);
-	}
-
-	/* iterate the tree of vars */
-	var = lub_bintree_findfirst(&this->var_tree);
-	for (lub_bintree_iterator_init(&iter, &this->var_tree, var);
-		var; var = lub_bintree_iterator_next(&iter)) {
-		clish_var_dump(var);
-	}
-
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 445
clish/shell/shell_execute.c

@@ -1,445 +0,0 @@
-/*
- * shell_execute.c
- */
-#include "private.h"
-#include "lub/string.h"
-#include "lub/argv.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-#include <sys/wait.h>
-#include <sys/uio.h>
-#include <signal.h>
-#include <fcntl.h>
-
-/* Empty signal handler to ignore signal but don't use SIG_IGN. */
-static void sigignore(int signo)
-{
-	signo = signo; /* Happy compiler */
-	return;
-}
-
-/*-------------------------------------------------------- */
-static int clish_shell_lock(const char *lock_path)
-{
-	int i;
-	int res = -1;
-	int lock_fd = -1;
-	struct flock lock;
-
-	if (!lock_path)
-		return -1;
-	lock_fd = open(lock_path, O_WRONLY | O_CREAT, 00644);
-	if (-1 == lock_fd) {
-		fprintf(stderr, "Warning: Can't open lockfile %s.\n", lock_path);
-		return -1;
-	}
-#ifdef FD_CLOEXEC
-	fcntl(lock_fd, F_SETFD, fcntl(lock_fd, F_GETFD) | FD_CLOEXEC);
-#endif
-	memset(&lock, 0, sizeof(lock));
-	lock.l_type = F_WRLCK;
-	lock.l_whence = SEEK_SET;
-	for (i = 0; i < CLISH_LOCK_WAIT; i++) {
-		res = fcntl(lock_fd, F_SETLK, &lock);
-		if (res != -1)
-			break;
-		if (EINTR == errno)
-			continue;
-		if ((EAGAIN == errno) || (EACCES == errno)) {
-			if (0 == i)
-				fprintf(stderr,
-					"Warning: Try to get lock. Please wait...\n");
-			sleep(1);
-			continue;
-		}
-		if (EINVAL == errno)
-			fprintf(stderr, "Error: Locking isn't supported by OS, consider \"--lockless\".\n");
-		break;
-	}
-	if (res == -1) {
-		fprintf(stderr, "Error: Can't get lock.\n");
-		close(lock_fd);
-		return -1;
-	}
-	return lock_fd;
-}
-
-/*-------------------------------------------------------- */
-static void clish_shell_unlock(int lock_fd)
-{
-	struct flock lock;
-
-	if (lock_fd == -1)
-		return;
-	memset(&lock, 0, sizeof(lock));
-	lock.l_type = F_UNLCK;
-	lock.l_whence = SEEK_SET;
-	fcntl(lock_fd, F_SETLK, &lock);
-	close(lock_fd);
-}
-
-/*----------------------------------------------------------- */
-int clish_shell_execute(clish_context_t *context, char **out)
-{
-	clish_shell_t *this = clish_context__get_shell(context);
-	const clish_command_t *cmd = clish_context__get_cmd(context);
-	int result = 0;
-	const char *lock_path = clish_shell__get_lockfile(this);
-	int lock_fd = -1;
-	clish_view_t *cur_view = clish_shell__get_view(this);
-	unsigned int saved_wdog_timeout = this->wdog_timeout;
-
-	assert(cmd);
-
-	/* Pre-change view if the command is from another depth/view */
-	{
-		clish_view_restore_e restore = clish_command__get_restore(cmd);
-		if ((CLISH_RESTORE_VIEW == restore) &&
-			(clish_command__get_pview(cmd) != cur_view)) {
-			clish_view_t *view = clish_command__get_pview(cmd);
-			clish_shell__set_pwd(this, NULL, view, NULL, context);
-		} else if ((CLISH_RESTORE_DEPTH == restore) &&
-			(clish_command__get_depth(cmd) < this->depth)) {
-			this->depth = clish_command__get_depth(cmd);
-		}
-	}
-
-	/* Lock the lockfile */
-	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;
-			goto error; /* Can't set lock */
-		}
-	}
-
-	/* Execute ACTION */
-	clish_context__set_action(context, clish_command__get_action(cmd));
-	result = clish_shell_exec_action(context, out);
-
-	/* Call config callback */
-	if (!result)
-		clish_shell_exec_config(context);
-
-	/* Call logging callback */
-	if (clish_shell__get_log(this) &&
-		clish_shell_check_hook(context, CLISH_SYM_TYPE_LOG)) {
-		char *full_line = clish_shell__get_full_line(context);
-		clish_shell_exec_log(context, full_line, result);
-		lub_string_free(full_line);
-	}
-
-	if (clish_shell__get_canon_out(this) &&
-		!clish_command__get_internal(cmd)) {
-		char *space = NULL;
-		char *full_line = clish_shell__get_full_line(context);
-		if (this->depth > 0) {
-			space = malloc(this->depth + 1);
-			memset(space, ' ', this->depth);
-			space[this->depth] = '\0';
-		}
-		printf("%s%s\n", space ? space : "", full_line);
-		lub_string_free(full_line);
-		if (space)
-			free(space);
-	}
-
-	/* Unlock the lockfile */
-	if (lock_fd != -1)
-		clish_shell_unlock(lock_fd);
-
-	/* Move into the new view */
-	if (!result) {
-		char *viewname = clish_shell_expand(clish_command__get_viewname(cmd), SHELL_VAR_NONE, context);
-		if (viewname) {
-			/* Search for the view */
-			clish_view_t *view = clish_shell_find_view(this, viewname);
-			if (!view)
-				fprintf(stderr, "System error: Can't "
-					"change view to %s\n", viewname);
-			lub_string_free(viewname);
-			/* Save the PWD */
-			if (view) {
-				char *line = clish_shell__get_line(context);
-				clish_shell__set_pwd(this, line, view,
-					clish_command__get_viewid(cmd), context);
-				lub_string_free(line);
-			}
-		}
-	}
-
-	/* Set appropriate timeout. Workaround: Don't turn on  watchdog
-	on the "set watchdog <timeout>" command itself. */
-	if (this->wdog_timeout && saved_wdog_timeout) {
-		tinyrl__set_timeout(this->tinyrl, this->wdog_timeout);
-		this->wdog_active = BOOL_TRUE;
-		fprintf(stderr, "Warning: The watchdog is active. Timeout is %u "
-			"seconds.\nWarning: Press any key to stop watchdog.\n",
-			this->wdog_timeout);
-	} else
-		tinyrl__set_timeout(this->tinyrl, this->idle_timeout);
-
-error:
-	return result;
-}
-
-/*----------------------------------------------------------- */
-/* Execute oaction. It suppose the forked process to get
- * script's stdout. Then forked process write the output back
- * to klish.
- */
-static int clish_shell_exec_oaction(clish_hook_oaction_fn_t func,
-	void *context, const char *script, char **out)
-{
-	int result = -1;
-	int real_stdout; /* Saved stdout handler */
-	int pipe1[2], pipe2[2];
-	pid_t cpid = -1;
-	konf_buf_t *buf;
-
-	if (pipe(pipe1))
-		return -1;
-	if (pipe(pipe2))
-		goto stdout_error;
-
-	/* Create process to read script's stdout */
-	cpid = fork();
-	if (cpid == -1) {
-		fprintf(stderr, "Error: Can't fork the stdout-grabber process.\n"
-			"Error: The ACTION will be not executed.\n");
-		goto stdout_error;
-	}
-
-	/* Child: read action's stdout */
-	if (cpid == 0) {
-		lub_list_t *l;
-		lub_list_node_t *node;
-		struct iovec *iov;
-		const int rsize = CLISH_STDOUT_CHUNK; /* Read chunk size */
-		size_t cur_size = 0;
-		ssize_t r = 0;
-
-		close(pipe1[1]);
-		close(pipe2[0]);
-		l = lub_list_new(NULL, NULL);
-
-		/* Read the result of script execution */
-		while (1) {
-			ssize_t ret;
-			iov = malloc(sizeof(*iov));
-			iov->iov_len = rsize;
-			iov->iov_base = malloc(iov->iov_len);
-			do {
-				ret = readv(pipe1[0], iov, 1);
-			} while ((ret < 0) && (errno == EINTR));
-			if (ret <= 0) { /* Error or EOF */
-				free(iov->iov_base);
-				free(iov);
-				break;
-			}
-			iov->iov_len = ret;
-			lub_list_add(l, iov);
-			/* Check the max size of buffer */
-			cur_size += ret;
-			if (cur_size >= CLISH_STDOUT_MAXBUF)
-				break;
-		}
-		close(pipe1[0]);
-
-		/* Write the result of script back to klish */
-		while ((node = lub_list__get_head(l))) {
-			iov = lub_list_node__get_data(node);
-			lub_list_del(l, node);
-			lub_list_node_free(node);
-			r = write(pipe2[1], iov->iov_base, iov->iov_len);
-			free(iov->iov_base);
-			free(iov);
-		}
-		close(pipe2[1]);
-
-		lub_list_free(l);
-		_exit(r < 0 ? 1 : 0);
-	}
-
-	real_stdout = dup(STDOUT_FILENO);
-	dup2(pipe1[1], STDOUT_FILENO);
-	close(pipe1[0]);
-	close(pipe1[1]);
-	close(pipe2[1]);
-
-	result = func(context, script);
-
-	/* Restore real stdout */
-	dup2(real_stdout, STDOUT_FILENO);
-	close(real_stdout);
-	/* Read the result of script execution */
-	buf = konf_buf_new(pipe2[0]);
-	while (konf_buf_read(buf) > 0);
-	*out = konf_buf__dup_line(buf);
-	konf_buf_delete(buf);
-	close(pipe2[0]);
-	/* Wait for the stdout-grabber process */
-	while (waitpid(cpid, NULL, 0) != cpid);
-
-	return result;
-
-stdout_error:
-	close(pipe1[0]);
-	close(pipe1[1]);
-	return -1;
-}
-
-/*----------------------------------------------------------- */
-int clish_shell_exec_action(clish_context_t *context, char **out)
-{
-	int result = -1;
-	const clish_sym_t *sym;
-	char *script;
-	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;
-	sigset_t old_sigs;
-
-	if (!(sym = clish_action__get_builtin(action)))
-		return 0;
-	if (shell->dryrun && !clish_sym__get_permanent(sym))
-		return 0;
-	if (!(func = clish_sym__get_func(sym))) {
-		fprintf(stderr, "Error: Default ACTION symbol is not specified.\n");
-		return -1;
-	}
-	script = clish_shell_expand(clish_action__get_script(action), SHELL_VAR_ACTION, context);
-
-	/* Ignore and block SIGINT, SIGQUIT, SIGHUP.
-	 * The SIG_IGN is not a case because it will be inherited
-	 * while a fork(). It's necessary to ignore signals because
-	 * the klish itself and ACTION script share the same terminal.
-	 */
-	sa.sa_flags = 0;
-	sigemptyset(&sa.sa_mask);
-	sa.sa_handler = sigignore; /* Empty signal handler */
-	sigaction(SIGINT, &sa, &old_sigint);
-	sigaction(SIGQUIT, &sa, &old_sigquit);
-	sigaction(SIGHUP, &sa, &old_sighup);
-	/* Block signals for children processes. The block state is inherited. */
-	if (!intr) {
-		sigset_t sigs;
-		sigemptyset(&sigs);
-		sigaddset(&sigs, SIGINT);
-		sigaddset(&sigs, SIGQUIT);
-		sigaddset(&sigs, SIGHUP);
-		sigprocmask(SIG_BLOCK, &sigs, &old_sigs);
-	}
-
-	/* Find out the function API */
-	/* CLISH_SYM_API_SIMPLE */
-	if (clish_sym__get_api(sym) == CLISH_SYM_API_SIMPLE) {
-		result = ((clish_hook_action_fn_t *)func)(context, script, out);
-
-	/* CLISH_SYM_API_STDOUT and output is not needed */
-	} else if ((clish_sym__get_api(sym) == CLISH_SYM_API_STDOUT) && (!out)) {
-		result = ((clish_hook_oaction_fn_t *)func)(context, script);
-
-	/* CLISH_SYM_API_STDOUT and outpus is needed */
-	} else if (clish_sym__get_api(sym) == CLISH_SYM_API_STDOUT) {
-		result = clish_shell_exec_oaction((clish_hook_oaction_fn_t *)func,
-			context, script, out);
-	}
-
-	/* Restore SIGINT, SIGQUIT, SIGHUP */
-	if (!intr) {
-		sigprocmask(SIG_SETMASK, &old_sigs, NULL);
-		/* Is the signals delivery guaranteed here (before
-		   sigaction restore) for previously blocked and
-		   pending signals? The simple test is working well.
-		   I don't want to use sigtimedwait() function because
-		   it needs a realtime extensions. The sigpending() with
-		   the sleep() is not nice too. Report bug if clish will
-		   get the SIGINT after non-interruptable action.
-		*/
-	}
-	sigaction(SIGINT, &old_sigint, NULL);
-	sigaction(SIGQUIT, &old_sigquit, NULL);
-	sigaction(SIGHUP, &old_sighup, NULL);
-
-	lub_string_free(script);
-
-	return result;
-}
-
-/*----------------------------------------------------------- */
-const void *clish_shell_check_hook(const clish_context_t *clish_context, int type)
-{
-	clish_sym_t *sym;
-	clish_shell_t *shell = clish_context__get_shell(clish_context);
-	const void *func;
-
-	if (!(sym = shell->hooks[type]))
-		return NULL;
-	if (shell->dryrun && !clish_sym__get_permanent(sym))
-		return NULL;
-	if (!(func = clish_sym__get_func(sym)))
-		return NULL;
-
-	return func;
-}
-
-/*----------------------------------------------------------- */
-CLISH_HOOK_CONFIG(clish_shell_exec_config)
-{
-	clish_hook_config_fn_t *func = NULL;
-	func = clish_shell_check_hook(clish_context, CLISH_SYM_TYPE_CONFIG);
-	return func ? func(clish_context) : 0;
-}
-
-/*----------------------------------------------------------- */
-CLISH_HOOK_LOG(clish_shell_exec_log)
-{
-	clish_hook_log_fn_t *func = NULL;
-	func = clish_shell_check_hook(clish_context, CLISH_SYM_TYPE_LOG);
-	return func ? func(clish_context, line, retcode) : 0;
-}
-
-/*----------------------------------------------------------- */
-char *clish_shell_mkfifo(clish_shell_t * this, char *name, size_t n)
-{
-	int res;
-
-	if (n < 1) /* Buffer too small */
-		return NULL;
-	do {
-		strncpy(name, this->fifo_temp, n);
-		name[n - 1] = '\0';
-		mktemp(name);
-		if (name[0] == '\0')
-			return NULL;
-		res = mkfifo(name, 0600);
-	} while ((res < 0) && (EEXIST == errno));
-
-	return name;
-}
-
-/*----------------------------------------------------------- */
-int clish_shell_rmfifo(clish_shell_t * this, const char *name)
-{
-	return unlink(name);
-}
-
-CLISH_SET(shell, bool_t, log);
-CLISH_GET(shell, bool_t, log);
-CLISH_SET(shell, bool_t, dryrun);
-CLISH_GET(shell, bool_t, dryrun);
-CLISH_SET(shell, bool_t, canon_out);
-CLISH_GET(shell, bool_t, canon_out);

+ 0 - 539
clish/shell/shell_expat.c

@@ -1,539 +0,0 @@
-/*
- * ------------------------------------------------------
- * shell_expat.c
- *
- * This file implements the means to read an XML encoded file
- * and populate the CLI tree based on the contents. It implements
- * the clish_xml API using the expat XML parser
- *
- * expat is not your typicall XML parser. It does not work
- * by creating a full in-memory XML tree, but by calling specific
- * callbacks (element handlers) regularly while parsing. It's up
- * to the user to create the corresponding XML tree if needed
- * (obviously, this is what we're doing, as we really need the XML
- * tree in klish).
- *
- * The code below do that. It transforms the output of expat
- * to a DOM representation of the underlying XML file. This is
- * a bit overkill, and maybe a later implementation will help to
- * cut the work to something simpler, but the current klish
- * implementation requires this.
- * ------------------------------------------------------
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#if defined(HAVE_LIB_EXPAT)
-#include <string.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
-
-/* FreeBSD have verbatim version of expat named bsdxml */
-#ifdef HAVE_LIB_BSDXML
-#include <bsdxml.h>
-#else
-#include <expat.h>
-#endif
-
-#include "xmlapi.h"
-
-/** DOM_like XML node
- *
- * @struct clish_xmlnode_s
- */
-struct clish_xmlnode_s {
-	char *name;
-	clish_xmlnode_t *parent; /**< parent node */
-	clish_xmlnode_t *children; /**< list of children */
-	clish_xmlnode_t *next; /**< next sibling */
-	clish_xmlnode_t *attributes; /**< attributes are nodes too */
-	char *content; /**< !NULL for text and attributes nodes */
-	clish_xmlnodetype_e type; /**< node type */
-	int depth; /**< node depth */
-	clish_xmldoc_t *doc;
-};
-
-/** DOM-like XML document
- *
- * @struct clish_xmldoc_s
- */
-struct clish_xmldoc_s {
-	clish_xmlnode_t *root; /**< list of root elements */
-	clish_xmlnode_t *current; /**< current element */
-	char *filename; /**< current filename */
-};
-
-/*
- * Expat need these functions to be able to build a DOM-like tree that
- * will be usable by klish.
- */
-/** Put a element at the and of an element list
- *
- * @param first first element of the list
- * @param node element to add
- * @return new first element of the list
- */
-static clish_xmlnode_t *clish_expat_list_push_back(clish_xmlnode_t *first, clish_xmlnode_t *node)
-{
-	clish_xmlnode_t *cur = first;
-	clish_xmlnode_t *prev = NULL;
-
-	while (cur) {
-		prev = cur;
-		cur = cur->next;
-	}
-	if (prev) {
-		prev->next = node;
-		return first;
-	}
-	return node;
-}
-
-/** Generic add_attr() function
- *
- * @param first first attribute in the attribute list
- * @param n attribute name
- * @param v attribute value
- * @return the new first attribute in the attribute list
- */
-static clish_xmlnode_t *clish_expat_add_attr(clish_xmlnode_t *first, const char *n, const char *v)
-{
-	clish_xmlnode_t *node;
-
-	node = malloc(sizeof(clish_xmlnode_t));
-	if (!node)
-		return first;
-
-	node->name = strdup(n);
-	node->content = strdup(v);
-	node->children = NULL;
-	node->attributes = NULL;
-	node->next = NULL;
-	node->type = CLISH_XMLNODE_ATTR;
-	node->depth = 0;
-
-	return clish_expat_list_push_back(first, node);
-}
-
-/** Run through an expat attribute list, and create a DOM-like attribute list
- *
- * @param node parent node
- * @param attr NULL-terminated attribute liste
- *
- * Each attribute uses two slots in the expat attribute list. The first one is
- * used to store the name, the second one is used to store the value.
- */
-static void clish_expat_add_attrlist(clish_xmlnode_t *node, const char **attr)
-{
-	int i;
-
-	for (i = 0; attr[i]; i += 2) {
-		node->attributes = clish_expat_add_attr(node->attributes,
-			attr[i], attr[i+1]);
-	}
-}
-
-/** Generic make_node() function
- *
- * @param parent XML parent node
- * @param type XML node type
- * @param n node name (can be NULL, strdup'ed)
- * @param v node content (can be NULL, strdup'ed)
- * @param attr attribute list
- * @return a new node or NULL on error
- */
-static clish_xmlnode_t *clish_expat_make_node(clish_xmlnode_t *parent,
-					      clish_xmlnodetype_e type,
-					      const char *n,
-					      const char *v,
-					      const char **attr)
-{
-	clish_xmlnode_t *node;
-
-	node = malloc(sizeof(clish_xmlnode_t));
-	if (!node)
-		return NULL;
-	node->name = n ? strdup(n) : NULL;
-	node->content = v ? strdup(v) : NULL;
-	node->children = NULL;
-	node->attributes = NULL;
-	node->next = NULL;
-	node->parent = parent;
-	node->doc = parent ? parent->doc : NULL;
-	node->depth = parent ? parent->depth + 1 : 0;
-	node->type = type;
-
-	if (attr)
-		clish_expat_add_attrlist(node, attr);
-
-	if (parent)
-		parent->children = clish_expat_list_push_back(parent->children, node);
-
-	return node;
-}
-
-/** Add a new XML root
- *
- * @param doc XML document
- * @param el root node name
- * @param attr expat attribute list
- * @return a new root element
- */
-static clish_xmlnode_t *clish_expat_add_root(clish_xmldoc_t *doc, const char *el, const char **attr)
-{
-	clish_xmlnode_t *node;
-
-	node = clish_expat_make_node(NULL, CLISH_XMLNODE_ELM, el, NULL, attr);
-	if (!node)
-		return doc->root;
-
-	doc->root = clish_expat_list_push_back(doc->root, node);
-
-	return node;
-}
-
-/** Add a new XML element as a child
- *
- * @param cur parent XML element
- * @param el element name
- * @param attr expat attribute list
- * @return a new XMl element
- */
-static clish_xmlnode_t *clish_expat_add_child(clish_xmlnode_t *cur, const char *el, const char **attr)
-{
-	clish_xmlnode_t *node;
-
-	node = clish_expat_make_node(cur, CLISH_XMLNODE_ELM, el, NULL, attr);
-	if (!node)
-		return cur;
-
-	return node;
-}
-
-/** Expat handler: element content
- *
- * @param data user data
- * @param s content (not nul-termainated)
- * @param len content length
- */
-static void clish_expat_chardata_handler(void *data, const char *s, int len)
-{
-	clish_xmldoc_t *doc = data;
-
-	if (doc->current) {
-		char *content = malloc(len + 1);
-		strncpy(content, s, len);
-		content[len] = '\0';
-
-		clish_expat_make_node(doc->current, CLISH_XMLNODE_TEXT, NULL, content, NULL);
-		/*
-		 * the previous call is a bit too generic, and strdup() content
-		 * so we need to free out own version of content.
-		 */
-		free(content);
-	}
-}
-
-/** Expat handler: start XML element
- *
- * @param data user data
- * @param el element name (nul-terminated)
- * @param attr expat attribute list
- */
-static void clish_expat_element_start(void *data, const char *el, const char **attr)
-{
-	clish_xmldoc_t *doc = data;
-
-	if (!doc->current) {
-		doc->current = clish_expat_add_root(doc, el, attr);
-	} else {
-		doc->current = clish_expat_add_child(doc->current, el, attr);
-	}
-}
-
-/** Expat handler: end XML element
- *
- * @param data user data
- * @param el element name
- */
-static void clish_expat_element_end(void *data, const char *el)
-{
-	clish_xmldoc_t *doc = data;
-
-	if (doc->current) {
-		doc->current = doc->current->parent;
-	}
-
-	el = el; /* Happy compiler */
-}
-
-/** Free a node, its children and its attributes
- *
- * @param node node to free
- */
-static void clish_expat_free_node(clish_xmlnode_t *cur)
-{
-	clish_xmlnode_t *node;
-	clish_xmlnode_t *first;
-
-	if (cur->attributes) {
-		first = cur->attributes;
-		while (first) {
-			node = first;
-			first = first->next;
-			clish_expat_free_node(node);
-		}
-	}
-	if (cur->children) {
-		first = cur->children;
-		while (first) {
-			node = first;
-			first = first->next;
-			clish_expat_free_node(node);
-		}
-	}
-	if (cur->name)
-		free(cur->name);
-	if (cur->content)
-		free(cur->content);
-	free(cur);
-}
-
-/*
- * Public interface
- */
-
-int clish_xmldoc_start(void)
-{
-	return 0;
-}
-
-int clish_xmldoc_stop(void)
-{
-	return 0;
-}
-
-clish_xmldoc_t *clish_xmldoc_read(const char *filename)
-{
-	clish_xmldoc_t *doc;
-	struct stat sb;
-	int fd;
-	char *buffer;
-	XML_Parser parser;
-	int rb;
-
-	doc = malloc(sizeof(clish_xmldoc_t));
-	if (!doc)
-		return NULL;
-	memset(doc, 0, sizeof(clish_xmldoc_t));
-	doc->filename = strdup(filename);
-	parser = XML_ParserCreate(NULL);
-	if (!parser)
-		goto error_parser_create;
-	XML_SetUserData(parser, doc);
-	XML_SetCharacterDataHandler(parser, clish_expat_chardata_handler);
-	XML_SetElementHandler(parser,
-		clish_expat_element_start,
-		clish_expat_element_end);
-
-	fd = open(filename, O_RDONLY);
-	if (fd < 0)
-		goto error_open;
-	fstat(fd, &sb);
-	buffer = malloc(sb.st_size+1);
-	rb = read(fd, buffer, sb.st_size);
-	if (rb < 0) {
-		close(fd);
-		goto error_parse;
-	}
-	buffer[sb.st_size] = 0;
-	close(fd);
-
-	if (!XML_Parse(parser, buffer, sb.st_size, 1))
-		goto error_parse;
-
-	XML_ParserFree(parser);
-	free(buffer);
-
-	return doc;
-
-error_parse:
-	free(buffer);
-
-error_open:
-	XML_ParserFree(parser);
-
-error_parser_create:
-	clish_xmldoc_release(doc);
-
-	return NULL;
-}
-
-void clish_xmldoc_release(clish_xmldoc_t *doc)
-{
-	if (doc) {
-		clish_xmlnode_t *node;
-		while (doc->root) {
-			node = doc->root;
-			doc->root = node->next;
-			clish_expat_free_node(node);
-		}
-		if (doc->filename)
-			free(doc->filename);
-		free(doc);
-	}
-}
-
-int clish_xmldoc_is_valid(clish_xmldoc_t *doc)
-{
-	return doc && doc->root;
-}
-
-int clish_xmldoc_error_caps(clish_xmldoc_t *doc)
-{
-	doc = doc; /* Happy compiler */
-
-	return CLISH_XMLERR_NOCAPS;
-}
-
-int clish_xmldoc_get_err_line(clish_xmldoc_t *doc)
-{
-	doc = doc; /* Happy compiler */
-
-	return -1;
-}
-
-int clish_xmldoc_get_err_col(clish_xmldoc_t *doc)
-{
-	doc = doc; /* Happy compiler */
-
-	return -1;
-}
-
-const char *clish_xmldoc_get_err_msg(clish_xmldoc_t *doc)
-{
-	doc = doc; /* Happy compiler */
-
-	return "";
-}
-
-int clish_xmlnode_get_type(clish_xmlnode_t *node)
-{
-	if (node)
-		return node->type;
-	return CLISH_XMLNODE_UNKNOWN;
-}
-
-clish_xmlnode_t *clish_xmldoc_get_root(clish_xmldoc_t *doc)
-{
-	if (doc)
-		return doc->root;
-	return NULL;
-}
-
-clish_xmlnode_t *clish_xmlnode_parent(clish_xmlnode_t *node)
-{
-	if (node)
-		return node->parent;
-	return NULL;
-}
-
-clish_xmlnode_t *clish_xmlnode_next_child(clish_xmlnode_t *parent,
-					  clish_xmlnode_t *curchild)
-{
-	if (curchild)
-		return curchild->next;
-	if (parent)
-		return parent->children;
-	return NULL;
-}
-
-char *clish_xmlnode_fetch_attr(clish_xmlnode_t *node,
-			       const char *attrname)
-{
-	if (node) {
-		clish_xmlnode_t *n = node->attributes;
-		while (n) {
-			if (strcmp(n->name, attrname) == 0)
-				return n->content;
-			n = n->next;
-		}
-	}
-	return NULL;
-}
-
-int clish_xmlnode_get_content(clish_xmlnode_t *node, char *content,
-			      unsigned int *contentlen)
-{
-	unsigned int minlen = 1;
-
-	if (node && content && contentlen) {
-		clish_xmlnode_t *children = node->children;
-		while (children) {
-			if (children->type == CLISH_XMLNODE_TEXT && children->content)
-				minlen += strlen(children->content);
-			children = children->next;
-		}
-		if (minlen >= *contentlen) {
-			*contentlen = minlen + 1;
-			return -E2BIG;
-		}
-		children = node->children;
-		*content = 0;
-		while (children) {
-			if (children->type == CLISH_XMLNODE_TEXT && children->content)
-				strcat(content, children->content);
-			children = children->next;
-		}
-		return 0;
-	}
-
-	return -EINVAL;
-}
-
-int clish_xmlnode_get_name(clish_xmlnode_t *node, char *name,
-	unsigned int *namelen)
-{
-	if (node && name && namelen) {
-		if (strlen(node->name) >= *namelen) {
-			*namelen = strlen(node->name) + 1;
-			return -E2BIG;
-		}
-		snprintf(name, *namelen, "%s", node->name);
-		name[*namelen - 1] = '\0';
-		return 0;
-	}
-	return -EINVAL;
-}
-
-void clish_xmlnode_print(clish_xmlnode_t *node, FILE *out)
-{
-	if (node) {
-		int i;
-		clish_xmlnode_t *a;
-		for (i=0; i<node->depth; ++i) {
-			fprintf(out, "  ");
-		}
-		fprintf(out, "<%s", node->name);
-		a = node->attributes;
-		while (a) {
-			fprintf(out, " %s='%s'", a->name, a->content);
-			a = a->next;
-		}
-		fprintf(out, ">...");
-	}
-}
-
-void clish_xml_release(void *p)
-{
-	p = p; /* Happy compiler */
-	/* nothing to release */
-}
-
-#endif /* HAVE_LIB_EXPAT */
-

+ 0 - 94
clish/shell/shell_file.c

@@ -1,94 +0,0 @@
-#include <stdlib.h>
-#include <assert.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "lub/string.h"
-#include "private.h"
-
-/*----------------------------------------------------------- */
-static int clish_shell_push(clish_shell_t * this, FILE * file,
-	const char *fname, bool_t stop_on_error)
-{
-	/* Allocate a control node */
-	clish_shell_file_t *node = malloc(sizeof(clish_shell_file_t));
-
-	assert(this);
-	assert(node);
-
-	/* intialise the node */
-	node->file = file;
-	if (fname)
-		node->fname = lub_string_dup(fname);
-	else
-		node->fname = NULL;
-	node->line = 0;
-	node->stop_on_error = stop_on_error;
-	node->next = this->current_file;
-
-	/* put the node at the top of the file stack */
-	this->current_file = node;
-
-	/* now switch the terminal's input stream */
-	tinyrl__set_istream(this->tinyrl, file);
-
-	return 0;
-}
-
-/*----------------------------------------------------------- */
-int clish_shell_push_file(clish_shell_t * this, const char * fname,
-	bool_t stop_on_error)
-{
-	FILE *file;
-	int res;
-
-	assert(this);
-	if (!fname)
-		return -1;
-	file = fopen(fname, "r");
-	if (!file)
-		return -1;
-#ifdef FD_CLOEXEC
-       fcntl(fileno(file), F_SETFD, fcntl(fileno(file), F_GETFD) | FD_CLOEXEC);
-#endif
-	res = clish_shell_push(this, file, fname, stop_on_error);
-	if (res)
-		fclose(file);
-
-	return res;
-}
-
-/*----------------------------------------------------------- */
-int clish_shell_push_fd(clish_shell_t *this, FILE *file,
-	bool_t stop_on_error)
-{
-	return clish_shell_push(this, file, NULL, stop_on_error);
-}
-
-/*----------------------------------------------------------- */
-int clish_shell_pop_file(clish_shell_t *this)
-{
-	int result = -1;
-	clish_shell_file_t *node = this->current_file;
-
-	if (!node)
-		return -1;
-
-	/* remove the current file from the stack... */
-	this->current_file = node->next;
-	/* and close the current file... */
-	fclose(node->file);
-	if (node->next) {
-		/* now switch the terminal's input stream */
-		tinyrl__set_istream(this->tinyrl, node->next->file);
-		result = 0;
-	}
-	/* and free up the memory */
-	if (node->fname)
-		lub_string_free(node->fname);
-	free(node);
-
-	return result;
-}
-
-/*----------------------------------------------------------- */

+ 0 - 168
clish/shell/shell_help.c

@@ -1,168 +0,0 @@
-/*
- * shell_help.c
- */
-#include "private.h"
-#include "clish/types.h"
-#include "lub/string.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-
-/*--------------------------------------------------------- */
-/*
- * Provide a detailed list of the possible command completions
- */
-static void available_commands(clish_shell_t *this,
-	clish_help_t *help, const char *line, size_t *max_width)
-{
-	const clish_command_t *cmd;
-	clish_shell_iterator_t iter;
-
-	if (max_width)
-		*max_width = 0;
-	/* Search for COMMAND completions */
-	clish_shell_iterator_init(&iter, CLISH_NSPACE_HELP);
-	while ((cmd = clish_shell_find_next_completion(this, line, &iter))) {
-		size_t width;
-		const char *name = clish_command__get_suffix(cmd);
-		if (max_width) {
-			width = strlen(name);
-			if (width > *max_width)
-				*max_width = width;
-		}
-		lub_argv_add(help->name, name);
-		lub_argv_add(help->help, clish_command__get_text(cmd));
-		lub_argv_add(help->detail, clish_command__get_detail(cmd));
-	}
-}
-
-/*--------------------------------------------------------- */
-static int available_params(clish_shell_t *this,
-	clish_help_t *help, const clish_command_t *cmd,
-	const char *line, size_t *max_width)
-{
-	unsigned index = lub_string_wordcount(line);
-	unsigned idx = lub_string_wordcount(clish_command__get_name(cmd));
-	lub_argv_t *argv;
-	clish_pargv_t *completion, *pargv;
-	unsigned i;
-	unsigned cnt = 0;
-	clish_pargv_status_e status = CLISH_LINE_OK;
-	clish_context_t context;
-
-	/* Empty line */
-	if (0 == index)
-		return -1;
-
-	if (line[strlen(line) - 1] != ' ')
-		index--;
-
-	argv = lub_argv_new(line, 0);
-
-	/* get the parameter definition */
-	completion = clish_pargv_new();
-	pargv = clish_pargv_new();
-
-	/* Prepare context */
-	clish_context_init(&context, this);
-	clish_context__set_cmd(&context, cmd);
-	clish_context__set_pargv(&context, pargv);
-
-	status = clish_shell_parse_pargv(pargv, cmd, &context,
-		clish_command__get_paramv(cmd),
-		argv, &idx, completion, index);
-	clish_pargv_delete(pargv);
-	cnt = clish_pargv__get_count(completion);
-
-	/* Calculate the longest name */
-	for (i = 0; i < cnt; i++) {
-		const clish_param_t *param;
-		const char *name;
-		unsigned clen = 0;
-
-		param = clish_pargv__get_param(completion, i);
-		if (CLISH_PARAM_SUBCOMMAND == clish_param__get_mode(param))
-			name = clish_param__get_value(param);
-		else
-			name = clish_ptype__get_text(clish_param__get_ptype(param));
-		if (name)
-			clen = strlen(name);
-		if (max_width && (clen > *max_width))
-			*max_width = clen;
-		clish_param_help(param, help);
-	}
-	clish_pargv_delete(completion);
-	lub_argv_delete(argv);
-
-	/* It's a completed command */
-	if (CLISH_LINE_OK == status)
-		return 0;
-
-	/* Incompleted command */
-	return -1;
-}
-
-/*--------------------------------------------------------- */
-void clish_shell_help(clish_shell_t *this, const char *line)
-{
-	clish_help_t help;
-	size_t max_width = 0;
-	const clish_command_t *cmd;
-	unsigned int i;
-
-	help.name = lub_argv_new(NULL, 0);
-	help.help = lub_argv_new(NULL, 0);
-	help.detail = lub_argv_new(NULL, 0);
-
-	/* Get COMMAND completions */
-	available_commands(this, &help, line, &max_width);
-
-	/* Resolve a command */
-	cmd = clish_shell_resolve_command(this, line);
-	/* Search for PARAM completion */
-	if (cmd) {
-		size_t width = 0;
-		int status;
-		status = available_params(this, &help, cmd, line, &width);
-		if (width > max_width)
-			max_width = width;
-		/* Add <cr> if command is completed */
-		if (!status) {
-			lub_argv_add(help.name, "<cr>");
-			lub_argv_add(help.help, NULL);
-			lub_argv_add(help.detail, NULL);
-		}
-	}
-	if (lub_argv__get_count(help.name) == 0)
-		goto end;
-
-	/* Print help messages */
-	for (i = 0; i < lub_argv__get_count(help.name); i++) {
-		fprintf(stderr, "  %-*s  %s\n", (int)max_width,
-			lub_argv__get_arg(help.name, i),
-			lub_argv__get_arg(help.help, i) ?
-			lub_argv__get_arg(help.help, i) : "");
-	}
-
-	/* Print details */
-	if ((lub_argv__get_count(help.name) == 1) &&
-		(SHELL_STATE_HELPING == this->state)) {
-		const char *detail = lub_argv__get_arg(help.detail, 0);
-		if (detail)
-			fprintf(stderr, "%s\n", detail);
-	}
-
-	/* update the state */
-	if (this->state == SHELL_STATE_HELPING)
-		this->state = SHELL_STATE_OK;
-	else
-		this->state = SHELL_STATE_HELPING;
-
-end:
-	lub_argv_delete(help.name);
-	lub_argv_delete(help.help);
-	lub_argv_delete(help.detail);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 376
clish/shell/shell_libxml2.c

@@ -1,376 +0,0 @@
-/*
- * ------------------------------------------------------
- * shell_roxml.c
- *
- * This file implements the means to read an XML encoded file 
- * and populate the CLI tree based on the contents. It implements
- * the clish_xml API using roxml
- * ------------------------------------------------------
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#if defined(HAVE_LIB_LIBXML2)
-#include <errno.h>
-#include <string.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include "xmlapi.h"
-
-#ifdef HAVE_LIB_LIBXSLT
-#include <libxslt/xslt.h>
-#include <libxslt/xsltInternals.h>
-#include <libxslt/transform.h>
-#include <libxslt/xsltutils.h>
-extern int xmlLoadExtDtdDefaultValue;
-
-/* dummy stuff ; really a xsltStylesheet */
-struct clish_xslt_s {
-	int dummy;
-};
-#endif
-
-/* dummy stuff ; really a xmlDoc */
-struct clish_xmldoc_s {
-	int dummy;
-};
-
-/* dummy stuff ; really a xmlNode */
-struct clish_xmlnode_s {
-	int dummy;
-};
-
-static inline xmlDoc *xmldoc_to_doc(clish_xmldoc_t *doc)
-{
-	return (xmlDoc*)doc;
-}
-
-static inline xmlNode *xmlnode_to_node(clish_xmlnode_t *node)
-{
-	return (xmlNode*)node;
-}
-
-static inline clish_xmldoc_t *doc_to_xmldoc(xmlDoc *node)
-{
-	return (clish_xmldoc_t*)node;
-}
-
-static inline clish_xmlnode_t *node_to_xmlnode(xmlNode *node)
-{
-	return (clish_xmlnode_t*)node;
-}
-
-/*
- * public interface
- */
-
-int clish_xmldoc_start(void)
-{
-#ifdef HAVE_LIB_LIBXSLT
-	/* The XSLT example contain these settings but I doubt 
-	 * it's really necessary.
-	 */
-/*	xmlSubstituteEntitiesDefault(1);
-	xmlLoadExtDtdDefaultValue = 1;
-*/
-#endif
-	return 0;
-}
-
-int clish_xmldoc_stop(void)
-{
-#ifdef HAVE_LIB_LIBXSLT
-	xsltCleanupGlobals();
-#endif
-	xmlCleanupParser();
-	return 0;
-}
-
-clish_xmldoc_t *clish_xmldoc_read(const char *filename)
-{
-	xmlDoc *doc;
-	doc = xmlReadFile(filename, NULL, 0);
-	return doc_to_xmldoc(doc);
-}
-
-void clish_xmldoc_release(clish_xmldoc_t *doc)
-{
-	if (doc)
-		xmlFreeDoc(xmldoc_to_doc(doc));
-}
-
-int clish_xmldoc_is_valid(clish_xmldoc_t *doc)
-{
-	return doc != NULL;
-}
-
-int clish_xmldoc_error_caps(clish_xmldoc_t *doc)
-{
-	return CLISH_XMLERR_NOCAPS;
-}
-
-int clish_xmldoc_get_err_line(clish_xmldoc_t *doc)
-{
-	return -1;
-}
-
-int clish_xmldoc_get_err_col(clish_xmldoc_t *doc)
-{
-	return -1;
-}
-
-const char *clish_xmldoc_get_err_msg(clish_xmldoc_t *doc)
-{
-	return "";
-}
-
-int clish_xmlnode_get_type(clish_xmlnode_t *node)
-{
-	if (node) {
-		xmlNode *n = xmlnode_to_node(node);
-		switch (n->type) {
-		case XML_ELEMENT_NODE: 
-			return CLISH_XMLNODE_ELM;
-		case XML_TEXT_NODE: 
-			return CLISH_XMLNODE_TEXT;
-		case XML_COMMENT_NODE: 
-			return CLISH_XMLNODE_COMMENT;
-		case XML_PI_NODE: 
-			return CLISH_XMLNODE_PI;
-		case XML_ATTRIBUTE_NODE: 
-			return CLISH_XMLNODE_ATTR;
-		default:
-			break;
-		}
-	}
-
-	return CLISH_XMLNODE_UNKNOWN;
-}
-
-clish_xmlnode_t *clish_xmldoc_get_root(clish_xmldoc_t *doc)
-{
-	if (doc) {
-		xmlNode *root = xmlDocGetRootElement(xmldoc_to_doc(doc));
-		return node_to_xmlnode(root);
-	}
-	return NULL;
-}
-
-clish_xmlnode_t *clish_xmlnode_parent(clish_xmlnode_t *node)
-{
-	if (node) {
-		xmlNode *n = xmlnode_to_node(node);
-		xmlNode *root = xmlDocGetRootElement(n->doc);
-		if (n != root)
-			return node_to_xmlnode(n->parent);
-	}
-	return NULL;
-}
-
-clish_xmlnode_t *clish_xmlnode_next_child(clish_xmlnode_t *parent, 
-					  clish_xmlnode_t *curchild)
-{
-	xmlNode *child;
-
-	if (!parent)
-		return NULL;
-
-	if (curchild) {
-		child = xmlnode_to_node(curchild)->next;
-	} else {
-		child = xmlnode_to_node(parent)->children;
-	}
-
-	return node_to_xmlnode(child);
-}
-
-char *clish_xmlnode_fetch_attr(clish_xmlnode_t *node,
-					  const char *attrname)
-{
-	xmlNode *n;
-
-	if (!node || !attrname)
-		return NULL;
-
-	n = xmlnode_to_node(node);
-
-	if (n->type == XML_ELEMENT_NODE) {
-		xmlAttr *a = n->properties;
-		while (a) {
-			if (strcmp((char*)a->name, attrname) == 0) {
-				if (a->children && a->children->content)
-					return (char *)a->children->content;
-				else
-					return NULL;
-			}
-			a = a->next;
-		}
-	}
-		
-	return NULL;
-}
-
-int clish_xmlnode_get_content(clish_xmlnode_t *node, char *content, 
-			      unsigned int *contentlen)
-{
-	xmlNode *n;
-	xmlNode *c;
-	int rlen = 0;
-
-	if (content && contentlen && *contentlen)
-		*content = 0;
-
-	if (!node || !content || !contentlen)
-		return -EINVAL;
-
-	if (*contentlen <= 1)
-		return -EINVAL;
-
-	*content = 0;
-	n = xmlnode_to_node(node);
-
-	/* first, get the content length */
-	c = n->children;
-	while (c) {
-		if ((c->type == XML_TEXT_NODE || c->type == XML_CDATA_SECTION_NODE)
-			&& !xmlIsBlankNode(c)) {
-			rlen += strlen((char*)c->content);
-		}
-		c = c->next;
-	}
-	++rlen;
-
-	if (rlen <= *contentlen) {
-		c = n->children;
-		while (c) {
-			if ((c->type == XML_TEXT_NODE || c->type == XML_CDATA_SECTION_NODE)
-				 && !xmlIsBlankNode(c)) {
-				strcat(content, (char*)c->content);
-			}
-			c = c->next;
-		}
-		return 0;
-	} else {
-		*contentlen = rlen;
-		return -E2BIG;
-	}
-}
-
-int clish_xmlnode_get_name(clish_xmlnode_t *node, char *name, 
-			    unsigned int *namelen)
-{
-	int rlen;
-	xmlNode *n;
-
-	if (name && namelen && *namelen)
-		*name = 0;
-
-	if (!node || !name || !namelen)
-		return -EINVAL;
-
-	if (*namelen <= 1)
-		return -EINVAL;
-
-	*name = 0;
-	n = xmlnode_to_node(node);
-	rlen = strlen((char*)n->name) + 1;
-	
-	if (rlen <= *namelen) {
-		snprintf(name, *namelen, "%s", (char*)n->name);
-		name[*namelen - 1] = '\0';
-		return 0;
-	} else {
-		*namelen = rlen;
-		return -E2BIG;
-	}
-}
-
-void clish_xmlnode_print(clish_xmlnode_t *node, FILE *out)
-{
-	xmlNode *n;
-	xmlAttr *a;
-
-	n = xmlnode_to_node(node);
-	if (n && n->name) {
-		fprintf(out, "<%s", (char*)n->name);
-		a = n->properties;
-		while (a) {
-			char *av = "";
-			if (a->children && a->children->content)
-				av = (char*)a->children->content;
-			fprintf(out, " %s='%s'", (char*)a->name, av);
-			a = a->next;
-		}
-		fprintf(out, ">");
-	}
-}
-
-void clish_xml_release(void *p)
-{
-	/* do we allocate memory? not yet. */
-}
-
-#ifdef HAVE_LIB_LIBXSLT
-
-static inline xsltStylesheet *xslt_to_xsltStylesheet(clish_xslt_t *xslt)
-{
-	return (xsltStylesheet*)xslt;
-}
-
-static inline clish_xslt_t *xsltStylesheet_to_xslt(xsltStylesheet *xslt)
-{
-	return (clish_xslt_t*)xslt;
-}
-
-int clish_xslt_is_valid(clish_xslt_t *stylesheet)
-{
-	return stylesheet != NULL;
-}
-
-clish_xmldoc_t *clish_xslt_apply(clish_xmldoc_t *xmldoc, clish_xslt_t *stylesheet)
-{
-	xmlDoc *doc = xmldoc_to_doc(xmldoc);
-	xsltStylesheetPtr cur = xslt_to_xsltStylesheet(stylesheet);
-	xmlDoc *res;
-
-	if (!doc || !cur)
-		return doc_to_xmldoc(NULL);
-	res = xsltApplyStylesheet(cur, doc, NULL);
-
-	return doc_to_xmldoc(res);
-}
-
-clish_xslt_t *clish_xslt_read(const char *filename)
-{
-	xsltStylesheet* cur = NULL;
-
-	cur = xsltParseStylesheetFile((const xmlChar *)filename);
-
-	return xsltStylesheet_to_xslt(cur);
-}
-
-clish_xslt_t *clish_xslt_read_embedded(clish_xmldoc_t *xmldoc)
-{
-	xsltStylesheet* cur = NULL;
-	xmlDoc *doc = xmldoc_to_doc(xmldoc);
-
-	cur = xsltLoadStylesheetPI(doc);
-
-	return xsltStylesheet_to_xslt(cur);
-}
-
-void clish_xslt_release(clish_xslt_t *stylesheet)
-{
-	xsltStylesheet* cur = xslt_to_xsltStylesheet(stylesheet);
-
-	if (!cur)
-		return;
-	xsltFreeStylesheet(cur);
-}
-
-#endif /* HAVE_LIB_LIBXSLT */
-
-#endif /* HAVE_LIB_LIBXML2 */
-

+ 0 - 56
clish/shell/shell_loop.c

@@ -1,56 +0,0 @@
-/*
- * shell_loop.c
- */
-#include "private.h"
-#include "lub/string.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <unistd.h>
-
-/*-------------------------------------------------------- */
-/* The main CLI loop while interactive execution.
- */
-int clish_shell_loop(clish_shell_t *this)
-{
-	int running = 0;
-	int retval = SHELL_STATE_OK;
-
-	assert(this);
-	if (!tinyrl__get_istream(this->tinyrl))
-		return SHELL_STATE_IO_ERROR;
-	/* Check the shell isn't closing down */
-	if (this && (SHELL_STATE_CLOSING == this->state))
-		return retval;
-
-	/* Loop reading and executing lines until the user quits */
-	while (!running) {
-		retval = SHELL_STATE_OK;
-		/* Get input from the stream */
-		running = clish_shell_readline(this, NULL);
-		if (running) {
-			switch (this->state) {
-			case SHELL_STATE_SCRIPT_ERROR:
-			case SHELL_STATE_SYNTAX_ERROR:
-				/* Interactive session doesn't exit on error */
-				if (tinyrl__get_isatty(this->tinyrl) ||
-					(this->current_file &&
-					!this->current_file->stop_on_error))
-					running = 0;
-				retval = this->state;
-			default:
-				break;
-			}
-		}
-		if (SHELL_STATE_CLOSING == this->state)
-			running = -1;
-		if (running)
-			running = clish_shell_pop_file(this);
-	}
-
-	return retval;
-}
-
-/*-------------------------------------------------------- */

+ 0 - 10
clish/shell/shell_misc.c

@@ -1,10 +0,0 @@
-/*
- * shell_misc.c
- */
-
-#include <stdlib.h>
-#include <assert.h>
-
-#include "private.h"
-
-CLISH_GET_STR(shell, overview);

+ 0 - 182
clish/shell/shell_new.c

@@ -1,182 +0,0 @@
-/*
- * shell_new.c
- */
-#include "private.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <limits.h>
-
-#include "lub/string.h"
-#include "lub/db.h"
-#include "lub/list.h"
-#include "clish/plugin.h"
-
-/*-------------------------------------------------------- */
-static void clish_shell_init(clish_shell_t * this,
-	FILE * istream, FILE * ostream, bool_t stop_on_error)
-{
-	clish_ptype_t *tmp_ptype = NULL;
-	int i;
-	char template[PATH_MAX];
-
-	/* Initialise VIEW list */
-	this->view_tree = lub_list_new(clish_view_compare, clish_view_delete);
-
-	/* Init PTYPE list */
-	this->ptype_tree = lub_list_new(clish_ptype_compare, clish_ptype_free);
-
-	/* initialise the tree of vars */
-	lub_bintree_init(&this->var_tree,
-		clish_var_bt_offset(),
-		clish_var_bt_compare, clish_var_bt_getkey);
-
-	/* Initialize plugin list */
-	this->plugins = lub_list_new(NULL, clish_plugin_free);
-
-	/* Initialise the list of unresolved (yet) symbols */
-	this->syms = lub_list_new(clish_sym_compare, clish_sym_free);
-
-	/* Create userdata storage */
-	this->udata = lub_list_new(clish_udata_compare, clish_udata_delete);
-
-	/* Hooks */
-	for (i = 0; i < CLISH_SYM_TYPE_MAX; i++) {
-		this->hooks[i] = clish_sym_new(NULL, NULL, i);
-		this->hooks_use[i] = BOOL_FALSE;
-	}
-
-	/* Set up defaults */
-	this->global = NULL;
-	this->startup = NULL;
-	this->idle_timeout = 0; /* No idle timeout by default */
-	this->wdog = NULL;
-	this->wdog_timeout = 0; /* No watchdog timeout by default */
-	this->wdog_active = BOOL_FALSE;
-	this->state = SHELL_STATE_INITIALISING;
-	this->overview = NULL;
-	this->tinyrl = clish_shell_tinyrl_new(istream, ostream, 0);
-	this->current_file = NULL;
-	this->pwdv = NULL;
-	this->pwdc = 0;
-	this->depth = -1; /* Current depth is undefined */
-	this->client = NULL;
-	this->lockfile = lub_string_dup(CLISH_LOCK_PATH);
-	this->default_shebang = lub_string_dup("/bin/sh");
-	this->interactive = BOOL_TRUE; /* The interactive shell by default. */
-	this->log = BOOL_FALSE; /* Disable logging by default */
-	this->log_facility = LOG_LOCAL0; /* LOCAL0 for compatibility */
-	this->dryrun = BOOL_FALSE; /* Disable dry-run by default */
-	this->user = lub_db_getpwuid(getuid()); /* Get user information */
-	this->default_plugin = BOOL_TRUE; /* Load default plugin by default */
-	this->canon_out = BOOL_FALSE; /* A canonical output is needed in special cases only */
-
-	/* Create template (string) for FIFO name generation */
-	snprintf(template, sizeof(template),
-		"%s/klish.fifo.%u.XXXXXX", "/tmp", getpid());
-	template[sizeof(template) - 1] = '\0';
-	this->fifo_temp = lub_string_dup(template);
-
-	/* Create internal ptypes and params */
-	/* Args */
-	tmp_ptype = clish_shell_find_create_ptype(this,
-		"__ptype_ARGS",
-		"Arguments", "[^\\\\]+",
-		CLISH_PTYPE_METHOD_REGEXP,
-		CLISH_PTYPE_PRE_NONE);
-	assert(tmp_ptype);
-
-	/* Push non-NULL istream */
-	if (istream)
-		clish_shell_push_fd(this, istream, stop_on_error);
-}
-
-/*--------------------------------------------------------- */
-static void clish_shell_fini(clish_shell_t *this)
-{
-	clish_var_t *var;
-	unsigned int i;
-
-	/* Free all loaded plugins */
-	lub_list_free_all(this->plugins);
-
-	/* Delete each VIEW  */
-	lub_list_free_all(this->view_tree);
-
-	/* Delete each PTYPE  */
-	lub_list_free_all(this->ptype_tree);
-
-	/* delete each VAR held  */
-	while ((var = lub_bintree_findfirst(&this->var_tree))) {
-		lub_bintree_remove(&this->var_tree, var);
-		clish_var_delete(var);
-	}
-
-	/* Free empty hooks */
-	for (i = 0; i < CLISH_SYM_TYPE_MAX; i++) {
-		if (clish_sym__get_name(this->hooks[i]))
-			continue;
-		clish_sym_free(this->hooks[i]);
-	}
-
-	/* Free symbol list */
-	lub_list_free_all(this->syms);
-
-	/* Free user data storage */
-	lub_list_free_all(this->udata);
-
-	/* free the textual details */
-	lub_string_free(this->overview);
-
-	/* Remove the startup command */
-	if (this->startup)
-		clish_command_delete(this->startup);
-	/* Remove the watchdog command */
-	if (this->wdog)
-		clish_command_delete(this->wdog);
-	/* clean up the file stack */
-	while (!clish_shell_pop_file(this));
-	/* delete the tinyrl object */
-	clish_shell_tinyrl_delete(this->tinyrl);
-
-	/* finalize each of the pwd strings */
-	for (i = 0; i < this->pwdc; i++) {
-		clish_shell__fini_pwd(this->pwdv[i]);
-		free(this->pwdv[i]);
-	}
-	/* free the pwd vector */
-	free(this->pwdv);
-	konf_client_free(this->client);
-
-	lub_string_free(this->lockfile);
-	lub_string_free(this->default_shebang);
-	free(this->user);
-	if (this->fifo_temp)
-		lub_string_free(this->fifo_temp);
-}
-
-/*-------------------------------------------------------- */
-clish_shell_t *clish_shell_new(
-	FILE * istream,
-	FILE * ostream,
-	bool_t stop_on_error)
-{
-	clish_shell_t *this = malloc(sizeof(clish_shell_t));
-
-	if (this)
-		clish_shell_init(this, istream, ostream, stop_on_error);
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_shell_delete(clish_shell_t *this)
-{
-	clish_shell_fini(this);
-	free(this);
-}
-
-CLISH_GET(shell, struct passwd *, user);

+ 0 - 324
clish/shell/shell_parse.c

@@ -1,324 +0,0 @@
-/*
- * shell_parse.c
- */
-
-#include <string.h>
-#include <assert.h>
-
-#include "lub/string.h"
-#include "lub/system.h"
-#include "private.h"
-
-/*----------------------------------------------------------- */
-clish_pargv_status_e clish_shell_parse(
-	clish_shell_t *this, const char *line,
-	const clish_command_t **ret_cmd, clish_pargv_t **pargv)
-{
-	clish_pargv_status_e result = CLISH_BAD_CMD;
-	clish_context_t context;
-	const clish_command_t *cmd;
-	lub_argv_t *argv = NULL;
-	unsigned int idx;
-
-	*ret_cmd = cmd = clish_shell_resolve_command(this, line);
-	if (!cmd)
-		return result;
-
-	/* Now construct the parameters for the command */
-	/* Prepare context */
-	*pargv = clish_pargv_new();
-	clish_context_init(&context, this);
-	clish_context__set_cmd(&context, cmd);
-	clish_context__set_pargv(&context, *pargv);
-
-	idx = lub_string_wordcount(clish_command__get_name(cmd));
-	argv = lub_argv_new(line, 0);
-	result = clish_shell_parse_pargv(*pargv, cmd, &context,
-		clish_command__get_paramv(cmd),
-		argv, &idx, NULL, 0);
-	lub_argv_delete(argv);
-	if (CLISH_LINE_OK != result) {
-		clish_pargv_delete(*pargv);
-		*pargv = NULL;
-	}
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-static bool_t line_test(const clish_param_t *param, void *context)
-{
-	char *str = NULL;
-	const char *teststr = NULL;
-	bool_t res;
-
-	if (!param)
-		return BOOL_FALSE;
-	teststr = clish_param__get_test(param);
-	if (!teststr)
-		return BOOL_TRUE;
-	str = clish_shell_expand(teststr, SHELL_VAR_ACTION, context);
-	if (!str)
-		return BOOL_FALSE;
-	res = lub_system_line_test(str);
-	lub_string_free(str);
-
-	return res;
-}
-
-/*--------------------------------------------------------- */
-clish_pargv_status_e clish_shell_parse_pargv(clish_pargv_t *pargv,
-	const clish_command_t *cmd,
-	void *context,
-	clish_paramv_t *paramv,
-	const lub_argv_t *argv,
-	unsigned *idx, clish_pargv_t *last, unsigned need_index)
-{
-	unsigned argc = lub_argv__get_count(argv);
-	unsigned index = 0;
-	unsigned nopt_index = 0;
-	clish_param_t *nopt_param = NULL;
-	unsigned i;
-	clish_pargv_status_e retval;
-	unsigned paramc = clish_paramv__get_count(paramv);
-	int up_level = 0; /* Is it a first level of param nesting? */
-
-	assert(pargv);
-	assert(cmd);
-
-	/* Check is it a first level of PARAM nesting. */
-	if (paramv == clish_command__get_paramv(cmd))
-		up_level = 1;
-
-	while (index < paramc) {
-		const char *arg = NULL;
-		clish_param_t *param = clish_paramv__get_param(paramv, index);
-		clish_param_t *cparam = NULL;
-		int is_switch = 0;
-
-		if (!param)
-			return CLISH_BAD_PARAM;
-
-		/* Use real arg or PARAM's default value as argument */
-		if (*idx < argc)
-			arg = lub_argv__get_arg(argv, *idx);
-
-		/* Is parameter in "switch" mode? */
-		if (CLISH_PARAM_SWITCH == clish_param__get_mode(param))
-			is_switch = 1;
-
-		/* Check the 'test' conditions */
-		if (!line_test(param, context)) {
-			index++;
-			continue;
-		}
-
-		/* Add param for help and completion */
-		if (last && (*idx == need_index) &&
-			(NULL == clish_pargv_find_arg(pargv, clish_param__get_name(param)))) {
-			if (is_switch) {
-				unsigned rec_paramc = clish_param__get_param_count(param);
-				for (i = 0; i < rec_paramc; i++) {
-					cparam = clish_param__get_param(param, i);
-					if (!cparam)
-						break;
-					if (!line_test(cparam, context))
-						continue;
-					if (CLISH_PARAM_SUBCOMMAND ==
-						clish_param__get_mode(cparam)) {
-						const char *pname =
-							clish_param__get_value(cparam);
-						if (!arg || (arg && 
-							(pname == lub_string_nocasestr(pname,
-							arg))))
-							clish_pargv_insert(last,
-								cparam, arg);
-					} else {
-						clish_pargv_insert(last,
-							cparam, arg);
-					}
-				}
-			} else {
-				if (CLISH_PARAM_SUBCOMMAND ==
-					clish_param__get_mode(param)) {
-					const char *pname =
-					    clish_param__get_value(param);
-					if (!arg || (arg &&
-						(pname == lub_string_nocasestr(pname, arg))))
-						clish_pargv_insert(last, param, arg);
-				} else {
-					clish_pargv_insert(last, param, arg);
-				}
-			}
-		}
-
-		/* Set parameter value */
-		{
-			char *validated = NULL;
-			clish_paramv_t *rec_paramv =
-			    clish_param__get_paramv(param);
-			unsigned rec_paramc =
-			    clish_param__get_param_count(param);
-
-			/* Save the index of last non-option parameter
-			 * to restore index if the optional parameters
-			 * will be used.
-			 */
-			if (!clish_param__get_optional(param)) {
-				nopt_param = param;
-				nopt_index = index;
-			}
-
-			/* Validate the current parameter. */
-			if (clish_pargv_find_arg(pargv, clish_param__get_name(param))) {
-				/* Duplicated parameter */
-				validated = NULL;
-			} else if (is_switch) {
-				for (i = 0; i < rec_paramc; i++) {
-					cparam = clish_param__get_param(param, i);
-					if (!cparam)
-						break;
-					if (!line_test(cparam, context))
-						continue;
-					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;
-					}
-				}
-			} else {
-				validated = arg ?
-					clish_param_validate(param, arg) : NULL;
-			}
-
-			if (validated) {
-				/* add (or update) this parameter */
-				if (is_switch) {
-					clish_pargv_insert(pargv, param,
-						clish_param__get_name(cparam));
-					clish_pargv_insert(pargv, cparam,
-						validated);
-				} else {
-					clish_pargv_insert(pargv, param,
-						validated);
-				}
-				lub_string_free(validated);
-
-				/* Next command line argument */
-				/* Don't change idx if this is the last
-				   unfinished optional argument.
-				 */
-				if (!(clish_param__get_optional(param) &&
-					(*idx == need_index) &&
-					(need_index == (argc - 1)))) {
-					(*idx)++;
-					/* Walk through the nested parameters */
-					if (rec_paramc) {
-						retval = clish_shell_parse_pargv(pargv, cmd,
-							context, rec_paramv,
-							argv, idx, last, need_index);
-						if (CLISH_LINE_OK != retval)
-							return retval;
-					}
-				}
-
-				/* Choose the next parameter */
-				if (clish_param__get_optional(param) &&
-					!clish_param__get_order(param)) {
-					if (nopt_param)
-						index = nopt_index + 1;
-					else
-						index = 0;
-				} else {
-					/* Save non-option position in
-					   case of ordered optional param */
-					nopt_param = param;
-					nopt_index = index;
-					index++;
-				}
-
-			} else {
-				/* Choose the next parameter if current
-				 * is not validated.
-				 */
-				if (clish_param__get_optional(param))
-					index++;
-				else {
-					if (!arg)
-						break;
-					else
-						return CLISH_BAD_PARAM;
-				}
-			}
-		}
-	}
-
-	/* Check for non-optional parameters without values */
-	if ((*idx >= argc) && (index < paramc)) {
-		unsigned j = index;
-		const clish_param_t *param;
-		while (j < paramc) {
-			param = clish_paramv__get_param(paramv, j++);
-			if (BOOL_TRUE != clish_param__get_optional(param))
-				return CLISH_LINE_PARTIAL;
-		}
-	}
-
-	/* If the number of arguments is bigger than number of
-	 * params than it's a args. So generate the args entry
-	 * in the list of completions.
-	 */
-	if (last && up_level &&
-			clish_command__get_args(cmd) &&
-			(clish_pargv__get_count(last) == 0) &&
-			(*idx <= argc) && (index >= paramc)) {
-		clish_pargv_insert(last, clish_command__get_args(cmd), "");
-	}
-
-	/*
-	 * if we've satisfied all the parameters we can now construct
-	 * an 'args' parameter if one exists
-	 */
-	if (up_level && (*idx < argc) && (index >= paramc)) {
-		const char *arg = lub_argv__get_arg(argv, *idx);
-		const clish_param_t *param = clish_command__get_args(cmd);
-		char *args = NULL;
-
-		if (!param)
-			return CLISH_BAD_CMD;
-
-		/*
-		 * put all the argument into a single string
-		 */
-		while (NULL != arg) {
-			bool_t quoted = lub_argv__get_quoted(argv, *idx);
-			char *enc = NULL;
-			if (BOOL_TRUE == quoted) {
-				lub_string_cat(&args, "\"");
-			}
-			/* place the current argument in the string */
-			/* Escape quote and backslash */
-			enc = lub_string_encode(arg, lub_string_esc_quoted);
-			lub_string_cat(&args, enc);
-			lub_string_free(enc);
-			if (BOOL_TRUE == quoted) {
-				lub_string_cat(&args, "\"");
-			}
-			(*idx)++;
-			arg = lub_argv__get_arg(argv, *idx);
-			if (NULL != arg) {
-				/* add a space if there are more arguments */
-				lub_string_cat(&args, " ");
-			}
-		}
-		/* add (or update) this parameter */
-		clish_pargv_insert(pargv, param, args);
-		lub_string_free(args);
-	}
-
-	return CLISH_LINE_OK;
-}
-
-CLISH_SET(shell, clish_shell_state_e, state);
-CLISH_GET(shell, clish_shell_state_e, state);

+ 0 - 237
clish/shell/shell_plugin.c

@@ -1,237 +0,0 @@
-/*
- * shell_plugin.c
- */
-#include "private.h"
-#include <assert.h>
-#include <string.h>
-#include <dlfcn.h>
-
-#include "lub/string.h"
-#include "lub/list.h"
-#include "lub/bintree.h"
-#include "clish/plugin.h"
-#include "clish/view.h"
-
-/*----------------------------------------------------------------------- */
-clish_plugin_t * clish_shell_find_plugin(clish_shell_t *this, const char *name)
-{
-	lub_list_node_t *iter;
-	clish_plugin_t *plugin;
-
-	assert(this);
-
-	if (!name || !name[0])
-		return NULL;
-	/* Iterate elements */
-	for(iter = lub_list__get_head(this->plugins);
-		iter; iter = lub_list_node__get_next(iter)) {
-		plugin = (clish_plugin_t *)lub_list_node__get_data(iter);
-		if (!strcmp(name, clish_plugin__get_name(plugin)))
-			return plugin;
-	}
-
-	return NULL;
-}
-
-/*----------------------------------------------------------------------- */
-clish_plugin_t * clish_shell_create_plugin(clish_shell_t *this,
-	const char *name)
-{
-	clish_plugin_t *plugin;
-	assert(this);
-
-	if (!name || !name[0])
-		return NULL;
-
-	plugin = clish_plugin_new(name, this);
-	lub_list_add(this->plugins, plugin);
-
-	return plugin;
-}
-
-/*----------------------------------------------------------------------- */
-clish_plugin_t * clish_shell_find_create_plugin(clish_shell_t *this,
-	const char *name)
-{
-	clish_plugin_t *plugin = clish_shell_find_plugin(this, name);
-	return (plugin ? plugin : clish_shell_create_plugin(this, name));
-}
-
-/*----------------------------------------------------------------------- */
-/* For all plugins:
- *  * dlopen(plugin)
- *  * dlsym(initialize function)
- *  * exec init functions to get all plugin syms
- */
-int clish_shell_load_plugins(clish_shell_t *this)
-{
-	lub_list_node_t *iter;
-	clish_plugin_t *plugin;
-
-	assert(this);
-
-	/* Iterate elements */
-	for(iter = lub_list__get_head(this->plugins);
-		iter; iter = lub_list_node__get_next(iter)) {
-		plugin = (clish_plugin_t *)lub_list_node__get_data(iter);
-		if (clish_plugin_load(plugin))
-			return -1;
-#ifdef DEBUG
-		clish_plugin_dump(plugin);
-#endif
-	}
-
-	return 0;
-}
-
-/*----------------------------------------------------------------------- */
-/* Iterate plugins to find symbol by name.
- * The symbol name can be simple or with namespace:
- * mysym@plugin1
- * The symbols with suffix will be resolved using specified plugin only.
- */
-static clish_sym_t *plugins_find_sym(clish_shell_t *this, const char *name, int type)
-{
-	lub_list_node_t *iter;
-	clish_plugin_t *plugin;
-	clish_sym_t *sym = NULL;
-	/* To parse command name */
-	char *saveptr = NULL;
-	const char *delim = "@";
-	char *plugin_name = NULL;
-	char *cmdn = NULL;
-	char *str = lub_string_dup(name);
-
-	assert(this);
-
-	/* Parse name to get sym name and optional plugin name */
-	cmdn = strtok_r(str, delim, &saveptr);
-	if (!cmdn) {
-		lub_string_free(str);
-		return NULL;
-	}
-	plugin_name = strtok_r(NULL, delim, &saveptr);
-
-	if (plugin_name) {
-		/* Search for symbol in specified namespace */
-		/* Iterate elements */
-		for(iter = lub_list__get_head(this->plugins);
-			iter; iter = lub_list_node__get_next(iter)) {
-			plugin = (clish_plugin_t *)lub_list_node__get_data(iter);
-			if (strcmp(clish_plugin__get_pubname(plugin), plugin_name))
-				continue;
-			if ((sym = clish_plugin_get_sym(plugin, cmdn, type)))
-				break;
-		}
-	} else {
-		/* Iterate all plugins */
-		for(iter = lub_list__get_head(this->plugins);
-			iter; iter = lub_list_node__get_next(iter)) {
-			plugin = (clish_plugin_t *)lub_list_node__get_data(iter);
-			if ((sym = clish_plugin_get_sym(plugin, cmdn, type)))
-				break;
-		}
-	}
-	lub_string_free(str);
-
-	return sym;
-}
-
-/*--------------------------------------------------------- */
-/* Find symbol by name in the list of unresolved symbols */
-clish_sym_t *clish_shell_find_sym(clish_shell_t *this, const char *name, int type)
-{
-	lub_list_node_t *iter;
-	clish_sym_t *sym;
-
-	/* Iterate elements */
-	for(iter = lub_list__get_head(this->syms);
-		iter; iter = lub_list_node__get_next(iter)) {
-		int res;
-		sym = (clish_sym_t *)lub_list_node__get_data(iter);
-		res = strcmp(clish_sym__get_name(sym), name);
-		if (!res && ((CLISH_SYM_TYPE_NONE == type) || (clish_sym__get_type(sym) == type)))
-			return sym;
-		if (res > 0) /* No chance to find name */
-			break;
-	}
-
-	return NULL;
-}
-
-/*----------------------------------------------------------------------- */
-/* Add symbol to the table of unresolved symbols */
-clish_sym_t *clish_shell_add_sym(clish_shell_t *this,
-	void *func, const char *name, int type)
-{
-	clish_sym_t *sym = NULL;
-
-	if (!name)
-		return NULL;
-	if ((sym = clish_shell_find_sym(this, name, type)))
-		return sym;
-	if (!(sym = clish_sym_new(name, func, type)))
-		return NULL;
-	lub_list_add(this->syms, sym);
-
-	return sym;
-}
-
-/*----------------------------------------------------------------------- */
-clish_sym_t *clish_shell_add_unresolved_sym(clish_shell_t *this,
-	const char *name, int type)
-{
-	return clish_shell_add_sym(this, NULL, name, type);
-}
-
-/*----------------------------------------------------------------------- */
-/* Link one unresolved symbol.
- * sym - unresolved symbol
- * Returns 0 if the symbol was succesfully resolved
- */
-static int link_unresolved_sym(clish_shell_t *this, clish_sym_t *sym)
-{
-	clish_sym_t *plugin_sym;
-	const char *sym_name = NULL;
-	int sym_type;
-
-	if (clish_sym__get_func(sym)) /* Don't relink non-null fn */
-		return 0;
-	sym_name = clish_sym__get_name(sym);
-	sym_type = clish_sym__get_type(sym);
-	plugin_sym = plugins_find_sym(this, sym_name, sym_type);
-	if (!plugin_sym) {
-		fprintf(stderr, "Error: Can't resolve symbol %s.\n",
-			sym_name);
-		return -1;
-	}
-	/* Copy symbol attributes */
-	clish_sym_clone(sym, plugin_sym);
-
-	return 0;
-}
-
-/*----------------------------------------------------------------------- */
-/* Link unresolved symbols */
-int clish_shell_link_plugins(clish_shell_t *this)
-{
-	clish_sym_t *sym;
-	lub_list_node_t *iter;
-
-	/* Iterate elements */
-	for(iter = lub_list__get_head(this->syms);
-		iter; iter = lub_list_node__get_next(iter)) {
-		sym = (clish_sym_t *)lub_list_node__get_data(iter);
-		if (link_unresolved_sym(this, sym) < 0)
-			return -1;
-	}
-
-	return 0;
-}
-
-/*----------------------------------------------------------------------- */
-/* Get hook sym */
-clish_sym_t *clish_shell_get_hook(const clish_shell_t *this, int type)
-{
-	return this->hooks[type];
-}

+ 0 - 50
clish/shell/shell_ptype.c

@@ -1,50 +0,0 @@
-/*
- * shell_find_create_ptype.c
- */
-
-#include <string.h>
-#include <assert.h>
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-clish_ptype_t *clish_shell_find_ptype(clish_shell_t *this, const char *name)
-{
-	lub_list_node_t *iter;
-
-	assert(this);
-
-	if (!name || !name[0])
-		return NULL;
-	/* Iterate elements */
-	for(iter = lub_list__get_head(this->ptype_tree);
-		iter; iter = lub_list_node__get_next(iter)) {
-		int r;
-		clish_ptype_t *ptype = (clish_ptype_t *)lub_list_node__get_data(iter);
-		r = strcmp(name, clish_ptype__get_name(ptype));
-		if (!r)
-			return ptype;
-		if (r < 0)
-			break;
-	}
-
-	return NULL;
-}
-
-/*--------------------------------------------------------- */
-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)
-{
-	clish_ptype_t *ptype = clish_shell_find_ptype(this, name);
-
-	if (!ptype) {
-		/* Create a ptype */
-		ptype = clish_ptype_new(name, text, pattern,
-			method, preprocess);
-		assert(ptype);
-		lub_list_add(this->ptype_tree, ptype);
-	}
-
-	return ptype;
-}

+ 0 - 183
clish/shell/shell_pwd.c

@@ -1,183 +0,0 @@
-/*
- * shell_pwd.c
- */
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <syslog.h>
-
-#include "lub/string.h"
-#include "private.h"
-
-/*--------------------------------------------------------- */
-void clish_shell__init_pwd(clish_shell_pwd_t *pwd)
-{
-	pwd->line = NULL;
-	pwd->view = NULL;
-	pwd->pargv = NULL;
-	pwd->cmd = NULL;
-	pwd->prefix = NULL;
-	/* initialise the tree of vars */
-	lub_bintree_init(&pwd->viewid,
-		clish_var_bt_offset(),
-		clish_var_bt_compare, clish_var_bt_getkey);
-}
-
-/*--------------------------------------------------------- */
-void clish_shell__fini_pwd(clish_shell_pwd_t *pwd)
-{
-	clish_var_t *var;
-
-	lub_string_free(pwd->line);
-	lub_string_free(pwd->cmd);
-	if (pwd->prefix)
-		lub_string_free(pwd->prefix);
-	pwd->view = NULL;
-	clish_pargv_delete(pwd->pargv);
-	/* delete each VAR held  */
-	while ((var = lub_bintree_findfirst(&pwd->viewid))) {
-		lub_bintree_remove(&pwd->viewid, var);
-		clish_var_delete(var);
-	}
-}
-
-/*--------------------------------------------------------- */
-void clish_shell__set_pwd(clish_shell_t *this,
-	const char *line, clish_view_t *view, const char *viewid, clish_context_t *context)
-{
-	clish_shell_pwd_t **tmp;
-	size_t new_size = 0;
-	unsigned int i;
-	unsigned int index = clish_view__get_depth(view);
-	clish_shell_pwd_t *newpwd;
-	const clish_command_t *full_cmd = clish_context__get_cmd(context);
-
-	/* Create new element */
-	newpwd = malloc(sizeof(*newpwd));
-	assert(newpwd);
-	clish_shell__init_pwd(newpwd);
-
-	/* Resize the pwd vector */
-	if (index >= this->pwdc) {
-		new_size = (index + 1) * sizeof(clish_shell_pwd_t *);
-		tmp = realloc(this->pwdv, new_size);
-		assert(tmp);
-		this->pwdv = tmp;
-		/* Initialize new elements */
-		for (i = this->pwdc; i <= index; i++) {
-			clish_shell_pwd_t *pwd = malloc(sizeof(*pwd));
-			assert(pwd);
-			clish_shell__init_pwd(pwd);
-			this->pwdv[i] = pwd;
-		}
-		this->pwdc = index + 1;
-	}
-
-	/* Fill the new pwd entry */
-	newpwd->line = line ? lub_string_dup(line) : NULL;
-	newpwd->view = view;
-	newpwd->pargv = clish_pargv_clone(clish_context__get_pargv(context));
-	if (full_cmd) {
-		const clish_command_t *cmd = clish_command__get_cmd(full_cmd);
-		newpwd->cmd = lub_string_dup(clish_command__get_name(cmd));
-		if (cmd != full_cmd) {
-			const char *full_cmd_name = clish_command__get_name(full_cmd);
-			const char *cmd_name = clish_command__get_name(cmd);
-			int len = strlen(full_cmd_name) - strlen(cmd_name);
-			if (len > 1)
-				newpwd->prefix = lub_string_dupn(full_cmd_name, len - 1);
-		}
-	}
-	clish_shell__expand_viewid(viewid, &newpwd->viewid, context);
-	clish_shell__fini_pwd(this->pwdv[index]);
-	free(this->pwdv[index]);
-	this->pwdv[index] = newpwd;
-	this->depth = index;
-}
-
-/*--------------------------------------------------------- */
-char *clish_shell__get_pwd_line(const clish_shell_t *this, unsigned int index)
-{
-	if (index >= this->pwdc)
-		return NULL;
-
-	return this->pwdv[index]->line;
-}
-
-/*--------------------------------------------------------- */
-clish_pargv_t *clish_shell__get_pwd_pargv(const clish_shell_t *this, unsigned int index)
-{
-	if (index >= this->pwdc)
-		return NULL;
-
-	return this->pwdv[index]->pargv;
-}
-
-/*--------------------------------------------------------- */
-char *clish_shell__get_pwd_cmd(const clish_shell_t *this, unsigned int index)
-{
-	if (index >= this->pwdc)
-		return NULL;
-
-	return this->pwdv[index]->cmd;
-}
-
-/*--------------------------------------------------------- */
-char *clish_shell__get_pwd_prefix(const clish_shell_t *this, unsigned int index)
-{
-	if (index >= this->pwdc)
-		return NULL;
-
-	return this->pwdv[index]->prefix;
-}
-
-/*--------------------------------------------------------- */
-char *clish_shell__get_pwd_full(const clish_shell_t * this, unsigned int depth)
-{
-	char *pwd = NULL;
-	unsigned int i;
-
-	for (i = 1; i <= depth; i++) {
-		const char *str =
-			clish_shell__get_pwd_line(this, i);
-		/* Cannot get full path */
-		if (!str) {
-			lub_string_free(pwd);
-			return NULL;
-		}
-		if (pwd)
-			lub_string_cat(&pwd, " ");
-		lub_string_cat(&pwd, "\"");
-		lub_string_cat(&pwd, str);
-		lub_string_cat(&pwd, "\"");
-	}
-
-	return pwd;
-}
-
-/*--------------------------------------------------------- */
-clish_view_t *clish_shell__get_pwd_view(const clish_shell_t * this, unsigned int index)
-{
-	if (index >= this->pwdc)
-		return NULL;
-
-	return this->pwdv[index]->view;
-}
-
-/*--------------------------------------------------------- */
-int clish_shell__set_socket(clish_shell_t * this, const char * path)
-{
-	if (!this || !path)
-		return -1;
-
-	konf_client_free(this->client);
-	this->client = konf_client_new(path);
-
-	return 0;
-}
-
-CLISH_SET_STR(shell, lockfile);
-CLISH_GET_STR(shell, lockfile);
-CLISH_SET(shell, int, log_facility);
-CLISH_GET(shell, int, log_facility);
-CLISH_GET(shell, konf_client_t *, client);

+ 0 - 358
clish/shell/shell_roxml.c

@@ -1,358 +0,0 @@
-/*
- * ------------------------------------------------------
- * shell_roxml.c
- *
- * This file implements the means to read an XML encoded file 
- * and populate the CLI tree based on the contents. It implements
- * the clish_xml API using roxml
- * ------------------------------------------------------
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#if defined(HAVE_LIB_ROXML)
-#include <errno.h>
-#include <roxml.h>
-#include "xmlapi.h"
-
-/* dummy stuff ; really a node_t */
-struct clish_xmldoc_s {
-	int dummy;
-};
-
-/* dummy stuff ; really a node_t */
-struct clish_xmlnode_s {
-	int dummy;
-};
-
-static inline node_t *xmldoc_to_node(clish_xmldoc_t *doc)
-{
-	return (node_t*)doc;
-}
-
-static inline node_t *xmlnode_to_node(clish_xmlnode_t *node)
-{
-	return (node_t*)node;
-}
-
-static inline clish_xmldoc_t *node_to_xmldoc(node_t *node)
-{
-	return (clish_xmldoc_t*)node;
-}
-
-static inline clish_xmlnode_t *node_to_xmlnode(node_t *node)
-{
-	return (clish_xmlnode_t*)node;
-}
-
-/*
- * public interface
- */
-
-int clish_xmldoc_start(void)
-{
-	return 0;
-}
-
-int clish_xmldoc_stop(void)
-{
-	return 0;
-}
-
-clish_xmldoc_t *clish_xmldoc_read(const char *filename)
-{
-	node_t *doc = roxml_load_doc((char*)filename);
-	return node_to_xmldoc(doc);
-}
-
-void clish_xmldoc_release(clish_xmldoc_t *doc)
-{
-	if (doc) {
-		node_t *node = xmldoc_to_node(doc);
-		roxml_release(RELEASE_ALL);
-		roxml_close(node);
-	}
-}
-
-int clish_xmldoc_is_valid(clish_xmldoc_t *doc)
-{
-	return doc != NULL;
-}
-
-int clish_xmldoc_error_caps(clish_xmldoc_t *doc)
-{
-	return CLISH_XMLERR_NOCAPS;
-}
-
-int clish_xmldoc_get_err_line(clish_xmldoc_t *doc)
-{
-	return -1;
-}
-
-int clish_xmldoc_get_err_col(clish_xmldoc_t *doc)
-{
-	return -1;
-}
-
-const char *clish_xmldoc_get_err_msg(clish_xmldoc_t *doc)
-{
-	return "";
-}
-
-int clish_xmlnode_get_type(clish_xmlnode_t *node)
-{
-	if (node) {
-		int type = roxml_get_type(xmlnode_to_node(node));
-		switch (type) {
-		case ROXML_ELM_NODE: 
-			return CLISH_XMLNODE_ELM;
-		case ROXML_TXT_NODE: 
-			return CLISH_XMLNODE_TEXT;
-		case ROXML_CMT_NODE: 
-			return CLISH_XMLNODE_COMMENT;
-		case ROXML_PI_NODE: 
-			return CLISH_XMLNODE_PI;
-		case ROXML_ATTR_NODE: 
-			return CLISH_XMLNODE_ATTR;
-		default:
-			break;
-		}
-	}
-
-	return CLISH_XMLNODE_UNKNOWN;
-}
-
-clish_xmlnode_t *clish_xmldoc_get_root(clish_xmldoc_t *doc)
-{
-	node_t *root;
-	char *name = NULL;
-
-	if (!doc)
-		return NULL;
-	root = roxml_get_root(xmldoc_to_node(doc));
-	if (!root)
-		return NULL;
-	/* The root node is always documentRoot since libroxml-2.2.2. */
-	/* It's good but not compatible with another XML parsers. */
-	name = roxml_get_name(root, NULL, 0);
-	if (0 == strcmp(name, "documentRoot"))
-		root = roxml_get_chld(root, NULL, 0);
-	roxml_release(name);
-
-	return node_to_xmlnode(root);
-}
-
-clish_xmlnode_t *clish_xmlnode_parent(clish_xmlnode_t *node)
-{
-	if (node) {
-		node_t *roxn = xmlnode_to_node(node);
-		node_t *root = roxml_get_root(roxn);
-		if (roxn != root)
-			return node_to_xmlnode(roxml_get_parent(roxn));
-	}
-	return NULL;
-}
-
-clish_xmlnode_t *clish_xmlnode_next_child(clish_xmlnode_t *parent, 
-					  clish_xmlnode_t *curchild)
-{
-	node_t *roxc;
-
-	if (!parent)
-		return NULL;
-
-	roxc = xmlnode_to_node(curchild);
-
-	if (roxc) {
-		return node_to_xmlnode(roxml_get_next_sibling(roxc));
-	} else {
-		node_t *roxp = xmlnode_to_node(parent);
-		node_t *child = NULL;
-		int count;
-
-		count = roxml_get_chld_nb(roxp);
-		if (count)
-			child = roxml_get_chld(roxp, NULL, 0);
-
-		return node_to_xmlnode(child);
-	}
-
-	return NULL;
-}
-
-static int i_is_needle(char *src, const char *needle)
-{
-	int nlen = strlen(needle);
-	int slen = strlen(src);
-
-	if (slen >= nlen) {
-		if (strncmp(src, needle, nlen) == 0)
-			return 1;
-	}
-	return 0;
-}
-
-/* warning: dst == src is valid */
-static void i_decode_and_copy(char *dst, char *src)
-{
-	while (*src) {
-		if (*src == '&') {
-			if (i_is_needle(src, "&lt;")) {
-				*dst++ = '<';
-				src += 4;
-			} else if (i_is_needle(src, "&gt;")) {
-				*dst++ = '>';
-				src += 4;
-			} else if (i_is_needle(src, "&amp;")) {
-				*dst++ = '&';
-				src += 5;
-			} else {
-				*dst++ = *src++;
-			}
-		} else {
-			*dst++ = *src++;
-		}
-	}
-	*dst++ = 0;
-}
-
-char *clish_xmlnode_fetch_attr(clish_xmlnode_t *node,
-			       const char *attrname)
-{
-	node_t *roxn;
-	node_t *attr;
-	char *content;
-
-	if (!node || !attrname)
-		return NULL;
-
-	roxn = xmlnode_to_node(node);
-	attr = roxml_get_attr(roxn, (char*)attrname, 0);
-
-	content = roxml_get_content(attr, NULL, 0, NULL);
-	if (content) {
-		i_decode_and_copy(content, content);
-	}
-	return content;
-}
-
-static int i_get_content(node_t *n, char *v, unsigned int *vl)
-{
-	char *c;
-	int len;
-
-	c = roxml_get_content(n, NULL, 0, NULL);
-	if (c) {
-		len = strlen(c) + 1;
-		if (len <= *vl) {
-			i_decode_and_copy(v, c);
-			roxml_release(c);
-			return 0;
-		} else {
-			*vl = len;
-			roxml_release(c);
-			return -E2BIG;
-		}
-	}
-	*vl = (unsigned int)-1;
-	return -ENOMEM;
-}
-
-int clish_xmlnode_get_content(clish_xmlnode_t *node, char *content, 
-			      unsigned int *contentlen)
-{
-	if (content && contentlen && *contentlen)
-		*content = 0;
-
-	if (!node || !content || !contentlen)
-		return -EINVAL;
-
-	if (*contentlen <= 1)
-		return -EINVAL;
-
-	*content = 0;
-
-	return i_get_content(xmlnode_to_node(node), content, contentlen);
-}
-
-static int i_get_name(node_t *n, char *v, unsigned int *vl)
-{
-	char *c;
-	int len;
-
-	c = roxml_get_name(n, NULL, 0);
-	if (c) {
-		len = strlen(c) + 1;
-		if (len <= *vl) {
-			snprintf(v, *vl, "%s", c);
-			v[*vl - 1] = '\0';
-			roxml_release(c);
-			return 0;
-		} else {
-			*vl = len;
-			roxml_release(c);
-			return -E2BIG;
-		}
-	}
-	*vl = (unsigned int)-1;
-	return -ENOMEM;
-}
-
-int clish_xmlnode_get_name(clish_xmlnode_t *node, char *name, 
-			    unsigned int *namelen)
-{
-	if (name && namelen && *namelen)
-		*name = 0;
-
-	if (!node || !name || !namelen)
-		return -EINVAL;
-
-	if (*namelen <= 1)
-		return -EINVAL;
-
-	*name = 0;
-
-	return i_get_name(xmlnode_to_node(node), name, namelen);
-}
-
-void clish_xmlnode_print(clish_xmlnode_t *node, FILE *out)
-{
-	node_t *roxn;
-	char *name;
-
-	roxn = xmlnode_to_node(node);
-	name = roxml_get_name(roxn, NULL, 0);
-	if (name) {
-		fprintf(out, "<%s", name);
-		roxml_release(name);
-		if (roxml_get_attr_nb(roxn)) {
-			int attr_count = roxml_get_attr_nb(roxn);
-			int attr_pos;
-			for (attr_pos = 0; attr_pos < attr_count; ++attr_pos) {
-				node_t *attr = roxml_get_attr(roxn, NULL, attr_pos);
-				char *n = roxml_get_name(attr, NULL, 0);
-				char *v = roxml_get_content(attr, NULL, 0, NULL);
-				if (n && v) {
-					fprintf(out, " %s='%s'", n, v);
-				}
-				if (v) 
-					roxml_release(v);
-				if (n) 
-					roxml_release(n);
-			}
-		}
-		fprintf(out, ">");
-	}
-}
-
-void clish_xml_release(void *p)
-{
-	if (p) {
-		roxml_release(p);
-	}
-}
-
-#endif /* HAVE_LIB_ROXML */
-

+ 0 - 341
clish/shell/shell_startup.c

@@ -1,341 +0,0 @@
-/*
- * shell_startup.c
- */
-#include "private.h"
-#include <assert.h>
-
-#include "lub/string.h"
-
-/* Default hooks */
-const char* clish_plugin_default_hook[] = {
-	NULL,
-	"clish_script@clish",
-	NULL,
-	"clish_hook_config@clish",
-	"clish_hook_log@clish"
-};
-
-/*----------------------------------------------------------- */
-int clish_shell_startup(clish_shell_t *this)
-{
-	const char *banner;
-	clish_context_t context;
-
-	if (!this->startup) {
-		fprintf(stderr, "Error: Can't get valid STARTUP tag.\n");
-		return -1;
-	}
-
-	/* Prepare context */
-	clish_context_init(&context, this);
-	clish_context__set_cmd(&context, this->startup);
-	clish_context__set_action(&context,
-		clish_command__get_action(this->startup));
-
-	banner = clish_command__get_detail(this->startup);
-	if (banner)
-		tinyrl_printf(this->tinyrl, "%s\n", banner);
-
-	/* Call log initialize */
-	if (clish_shell__get_log(this))
-		clish_shell_exec_log(&context, NULL, 0);
-	/* Call startup script */
-	return clish_shell_execute(&context, NULL);
-}
-
-/*----------------------------------------------------------- */
-void clish_shell__set_startup_view(clish_shell_t *this, const char *viewname)
-{
-	clish_view_t *view;
-
-	assert(this);
-	assert(this->startup);
-	/* Search for the view */
-	view = clish_shell_find_view(this, viewname);
-	assert(view);
-	clish_command__force_viewname(this->startup, viewname);
-}
-
-/*----------------------------------------------------------- */
-void clish_shell__set_startup_viewid(clish_shell_t *this, const char *viewid)
-{
-	assert(this);
-	assert(this->startup);
-	clish_command__force_viewid(this->startup, viewid);
-}
-
-
-/*-------------------------------------------------------- */
-/* Resolve PTYPE for given PARAM.
- */
-static clish_ptype_t * resolve_ptype(clish_shell_t *this, clish_param_t *param)
-{
-	clish_ptype_t *ptype = NULL;
-
-	if (!this || !param)
-		return NULL;
-
-	/* Resolve PARAM's PTYPE */
-	ptype = clish_shell_find_ptype(this, clish_param__get_ptype_name(param));
-	if (!ptype) {
-		fprintf(stderr, "Error: Unresolved PTYPE \"%s\" in PARAM \"%s\"\n",
-			clish_param__get_ptype_name(param),
-			clish_param__get_name(param));
-		return NULL;
-	}
-	clish_param__set_ptype(param, ptype);
-	clish_param__set_ptype_name(param, NULL); /* Free some memory */
-
-	return ptype;
-}
-
-/*-------------------------------------------------------- */
-/* Static recursive function to iterate parameters. Logically it's the
- * part of clish_shell_prepare() function.
- */
-static int iterate_paramv(clish_shell_t *this, clish_paramv_t *paramv,
-	clish_hook_access_fn_t *access_fn)
-{
-	int i = 0;
-	clish_param_t *param;
-
-	while((param = clish_paramv__get_param(paramv, i))) {
-		clish_paramv_t *nested_paramv;
-
-		/* Resolve PARAM's PTYPE */
-		if (!resolve_ptype(this, param))
-			return -1;
-
-		/* Check access for PARAM */
-		if (access_fn && clish_param__get_access(param) &&
-			access_fn(this, clish_param__get_access(param))) {
-#ifdef DEBUG
-			fprintf(stderr, "Warning: Access denied. Remove PARAM \"%s\"\n",
-				clish_param__get_name(param));
-#endif
-			if (clish_paramv_remove(paramv, i) < 0) {
-				fprintf(stderr, "Error: Some system problem\n");
-				return -1;
-			}
-			clish_param_delete(param);
-			continue; /* Don't increment index */
-		}
-		/* Recursive iterate nested PARAMs */
-		nested_paramv = clish_param__get_paramv(param);
-		if (iterate_paramv(this, nested_paramv, access_fn) < 0)
-			return -1;
-		i++;
-	}
-
-	return 0;
-}
-
-/*-------------------------------------------------------- */
-/* This function prepares schema for execution. It loads
- * plugins, link unresolved symbols, then iterates all the
- * objects and link them to each other, check access
- * permissions. Don't execute clish_shell_startup() without this
- * function.
- */
-int clish_shell_prepare(clish_shell_t *this)
-{
-	clish_command_t *cmd;
-	clish_view_t *view;
-	clish_nspace_t *nspace;
-	lub_list_t *view_tree, *nspace_tree;
-	lub_list_node_t *nspace_iter, *view_iter;
-	lub_bintree_t *cmd_tree;
-	lub_bintree_iterator_t cmd_iter;
-	clish_hook_access_fn_t *access_fn = NULL;
-	clish_paramv_t *paramv;
-	int i = 0;
-
-	/* Add statically linked plugins */
-	while (clish_plugin_builtin_list[i].name) {
-		clish_plugin_t *plugin;
-		plugin = clish_shell_find_create_plugin(this,
-			clish_plugin_builtin_list[i].name);
-		clish_plugin__set_init(plugin,
-			clish_plugin_builtin_list[i].init);
-		clish_plugin__set_builtin_flag(plugin, BOOL_TRUE);
-		i++;
-	}
-
-	/* Add default plugin to the list of plugins */
-	if (this->default_plugin) {
-		clish_shell_find_create_plugin(this, "clish");
-		/* Default hooks */
-		for (i = 0; i < CLISH_SYM_TYPE_MAX; i++) {
-			if (this->hooks_use[i])
-				continue;
-			if (!clish_plugin_default_hook[i])
-				continue;
-			clish_sym__set_name(this->hooks[i],
-				clish_plugin_default_hook[i]);
-		}
-	}
-	/* Add default syms to unresolved table */
-	for (i = 0; i < CLISH_SYM_TYPE_MAX; i++) {
-		if (clish_sym__get_name(this->hooks[i]))
-			lub_list_add(this->syms, this->hooks[i]);
-	}
-
-	/* Load plugins and link symbols */
-	if (clish_shell_load_plugins(this) < 0)
-		return -1;
-	if (clish_shell_link_plugins(this) < 0)
-		return -1;
-
-	access_fn = clish_sym__get_func(clish_shell_get_hook(this, CLISH_SYM_TYPE_ACCESS));
-
-	/* Iterate the VIEWs */
-	view_tree = this->view_tree;
-	view_iter = lub_list_iterator_init(view_tree);
-	while(view_iter) {
-		lub_list_node_t *old_view_iter;
-		view = (clish_view_t *)lub_list_node__get_data(view_iter);
-		old_view_iter = view_iter;
-		view_iter = lub_list_node__get_next(view_iter);
-		/* Check access rights for the VIEW */
-		if (access_fn && clish_view__get_access(view) &&
-			access_fn(this, clish_view__get_access(view))) {
-#ifdef DEBUG
-			fprintf(stderr, "Warning: Access denied. Remove VIEW \"%s\"\n",
-				clish_view__get_name(view));
-#endif
-			lub_list_del(view_tree, old_view_iter);
-			lub_list_node_free(old_view_iter);
-			clish_view_delete(view);
-			continue;
-		}
-
-		/* Iterate the NAMESPACEs */
-		nspace_tree = clish_view__get_nspaces(view);
-		nspace_iter = lub_list__get_head(nspace_tree);
-		while(nspace_iter) {
-			clish_view_t *ref_view;
-			lub_list_node_t *old_nspace_iter;
-			nspace = (clish_nspace_t *)lub_list_node__get_data(nspace_iter);
-			old_nspace_iter = nspace_iter;
-			nspace_iter = lub_list_node__get_next(nspace_iter);
-			/* Resolve NAMESPACEs and remove unresolved ones */
-			ref_view = clish_shell_find_view(this, clish_nspace__get_view_name(nspace));
-			if (!ref_view) {
-#ifdef DEBUG
-				fprintf(stderr, "Warning: Remove unresolved NAMESPACE \"%s\" from \"%s\" VIEW\n",
-					clish_nspace__get_view_name(nspace), clish_view__get_name(view));
-#endif
-				lub_list_del(nspace_tree, old_nspace_iter);
-				lub_list_node_free(old_nspace_iter);
-				clish_nspace_delete(nspace);
-				continue;
-			}
-			clish_nspace__set_view(nspace, ref_view);
-			clish_nspace__set_view_name(nspace, NULL); /* Free some memory */
-			/* Check access rights for the NAMESPACE */
-			if (access_fn && (
-				/* Check NAMESPASE owned access */
-				(clish_nspace__get_access(nspace) && access_fn(this, clish_nspace__get_access(nspace)))
-				||
-				/* Check referenced VIEW's access */
-				(clish_view__get_access(ref_view) && access_fn(this, clish_view__get_access(ref_view)))
-				)) {
-#ifdef DEBUG
-				fprintf(stderr, "Warning: Access denied. Remove NAMESPACE \"%s\" from \"%s\" VIEW\n",
-					clish_nspace__get_view_name(nspace), clish_view__get_name(view));
-#endif
-				lub_list_del(nspace_tree, old_nspace_iter);
-				lub_list_node_free(old_nspace_iter);
-				clish_nspace_delete(nspace);
-				continue;
-			}
-		}
-
-		/* Iterate the COMMANDs */
-		cmd_tree = clish_view__get_tree(view);
-		cmd = lub_bintree_findfirst(cmd_tree);
-		for (lub_bintree_iterator_init(&cmd_iter, cmd_tree, cmd);
-			cmd; cmd = lub_bintree_iterator_next(&cmd_iter)) {
-			int cmd_is_alias = clish_command__get_alias(cmd)?1:0;
-			clish_param_t *args = NULL;
-
-			/* Check access rights for the COMMAND */
-			if (access_fn && clish_command__get_access(cmd) &&
-				access_fn(this, clish_command__get_access(cmd))) {
-#ifdef DEBUG
-				fprintf(stderr, "Warning: Access denied. Remove COMMAND \"%s\" from VIEW \"%s\"\n",
-					clish_command__get_name(cmd), clish_view__get_name(view));
-#endif
-				lub_bintree_remove(cmd_tree, cmd);
-				clish_command_delete(cmd);
-				continue;
-			}
-
-			/* Resolve command aliases */
-			if (cmd_is_alias) {
-				clish_view_t *aview;
-				clish_command_t *cmdref;
-				const char *alias_view = clish_command__get_alias_view(cmd);
-				if (!alias_view)
-					aview = clish_command__get_pview(cmd);
-				else
-					aview = clish_shell_find_view(this, alias_view);
-				if (!aview /* Removed or broken VIEW */
-					||
-					/* Removed or broken referenced COMMAND */
-					!(cmdref = clish_view_find_command(aview, clish_command__get_alias(cmd), BOOL_FALSE))
-					) {
-#ifdef DEBUG
-					fprintf(stderr, "Warning: Remove unresolved link \"%s\" from \"%s\" VIEW\n",
-						clish_command__get_name(cmd), clish_view__get_name(view));
-#endif
-					lub_bintree_remove(cmd_tree, cmd);
-					clish_command_delete(cmd);
-					continue;
-					/*fprintf(stderr, CLISH_XML_ERROR_STR"Broken VIEW for alias \"%s\"\n",
-						clish_command__get_name(cmd));
-					return -1; */
-					/*fprintf(stderr, CLISH_XML_ERROR_STR"Broken alias \"%s\"\n",
-						clish_command__get_name(cmd));
-					return -1; */
-				}
-				if (!clish_command_alias_to_link(cmd, cmdref)) {
-					fprintf(stderr, CLISH_XML_ERROR_STR"Something wrong with alias \"%s\"\n",
-						clish_command__get_name(cmd));
-					return -1;
-				}
-				/* Check access rights for newly constructed COMMAND.
-				   Now the link has access filed from referenced command.
-				 */
-				if (access_fn && clish_command__get_access(cmd) &&
-					access_fn(this, clish_command__get_access(cmd))) {
-#ifdef DEBUG
-					fprintf(stderr, "Warning: Access denied. Remove COMMAND \"%s\" from VIEW \"%s\"\n",
-						clish_command__get_name(cmd), clish_view__get_name(view));
-#endif
-					lub_bintree_remove(cmd_tree, cmd);
-					clish_command_delete(cmd);
-					continue;
-				}
-			}
-			if (cmd_is_alias) /* Don't duplicate paramv processing for aliases */
-				continue;
-			/* Iterate PARAMeters */
-			paramv = clish_command__get_paramv(cmd);
-			if (iterate_paramv(this, paramv, access_fn) < 0)
-				return -1;
-			/* Resolve PTYPE for args */
-			if ((args = clish_command__get_args(cmd))) {
-				if (!resolve_ptype(this, args))
-					return -1;
-			}
-		}
-	}
-
-	return 0;
-}
-
-CLISH_SET_STR(shell, default_shebang);
-CLISH_GET_STR(shell, default_shebang);
-
-

+ 0 - 602
clish/shell/shell_tinyrl.c

@@ -1,602 +0,0 @@
-/*
- * shell_tinyrl.c
- *
- * This is a specialisation of the tinyrl_t class which maps the readline
- * functionality to the CLISH environment.
- */
-#include "private.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-
-#include "tinyrl/tinyrl.h"
-#include "tinyrl/history.h"
-
-#include "lub/string.h"
-
-/*-------------------------------------------------------- */
-static void clish_shell_renew_prompt(clish_shell_t *this)
-{
-	clish_context_t prompt_context;
-	char *prompt = NULL;
-	const clish_view_t *view;
-	char *str = NULL;
-
-	/* Create appropriate context */
-	clish_context_init(&prompt_context, this);
-
-	/* Obtain the prompt */
-	view = clish_shell__get_view(this);
-	assert(view);
-	lub_string_cat(&str, "${_PROMPT_PREFIX}");
-	lub_string_cat(&str, clish_view__get_prompt(view));
-	lub_string_cat(&str, "${_PROMPT_SUFFIX}");
-	prompt = clish_shell_expand(str, SHELL_VAR_NONE, &prompt_context);
-	assert(prompt);
-	lub_string_free(str);
-	tinyrl__set_prompt(this->tinyrl, prompt);
-	lub_string_free(prompt);
-}
-
-/*-------------------------------------------------------- */
-static bool_t clish_shell_tinyrl_key_help(tinyrl_t *this, int key)
-{
-	bool_t result = BOOL_TRUE;
-
-	if (tinyrl_is_quoting(this)) {
-		/* if we are in the middle of a quote then simply enter a space */
-		result = tinyrl_insert_text(this, "?");
-	} else {
-		/* get the context */
-		clish_context_t *context = tinyrl__get_context(this);
-		clish_shell_t *shell = clish_context__get_shell(context);
-		tinyrl_crlf(this);
-		clish_shell_help(shell, tinyrl__get_line(this));
-		tinyrl_crlf(this);
-		tinyrl_reset_line_state(this);
-	}
-	/* keep the compiler happy */
-	key = key;
-
-	return result;
-}
-
-/*lint +e818 */
-/*-------------------------------------------------------- */
-/*
- * Expand the current line with any history substitutions
- */
-static clish_pargv_status_e clish_shell_tinyrl_expand(tinyrl_t *this)
-{
-	clish_pargv_status_e status = CLISH_LINE_OK;
-#if 0
-	int rtn;
-	char *buffer;
-
-	/* first of all perform any history substitutions */
-	rtn = tinyrl_history_expand(tinyrl__get_history(this),
-		tinyrl__get_line(this), &buffer);
-
-	switch (rtn) {
-	case -1:
-		/* error in expansion */
-		status = CLISH_BAD_HISTORY;
-		break;
-	case 0:
-		/*no expansion */
-		break;
-	case 1:
-		/* expansion occured correctly */
-		tinyrl_replace_line(this, buffer, 1);
-		break;
-	case 2:
-		/* just display line */
-		tinyrl_printf(this, "\n%s", buffer);
-		free(buffer);
-		buffer = NULL;
-		break;
-	default:
-		break;
-	}
-	free(buffer);
-
-#endif
-	this = this;
-	return status;
-}
-
-/*-------------------------------------------------------- */
-/*
- * This is a CLISH specific completion function.
- * If the current prefix is not a recognised prefix then
- * an error is flagged.
- * If it is a recognisable prefix then possible completions are displayed
- * or a unique completion is inserted.
- */
-static tinyrl_match_e clish_shell_tinyrl_complete(tinyrl_t *this)
-{
-	tinyrl_match_e status;
-
-	/* first of all perform any history expansion */
-	(void)clish_shell_tinyrl_expand(this);
-	/* perform normal completion */
-	status = tinyrl_complete(this);
-	switch (status) {
-	case TINYRL_NO_MATCH:
-		if (BOOL_FALSE == tinyrl_is_completion_error_over(this)) {
-			/* The user hasn't even entered a valid prefix! */
-/*			tinyrl_crlf(this);
-			clish_shell_help(context->shell,
-				tinyrl__get_line(this));
-			tinyrl_crlf(this);
-			tinyrl_reset_line_state(this);
-*/		}
-		break;
-	default:
-		/* the default completion function will have prompted for completions as
-		 * necessary
-		 */
-		break;
-	}
-	return status;
-}
-
-/*--------------------------------------------------------- */
-static bool_t clish_shell_tinyrl_key_space(tinyrl_t *this, int key)
-{
-	bool_t result = BOOL_FALSE;
-	tinyrl_match_e status;
-	clish_context_t *context = tinyrl__get_context(this);
-	clish_shell_t *shell = clish_context__get_shell(context);
-	const char *line = tinyrl__get_line(this);
-	clish_pargv_status_e arg_status;
-	const clish_command_t *cmd = NULL;
-	clish_pargv_t *pargv = NULL;
-
-	if(tinyrl_is_empty(this)) {
-		/* ignore space at the begining of the line, don't display commands */
-		return BOOL_TRUE;
-	} else if (tinyrl_is_quoting(this)) {
-		/* if we are in the middle of a quote then simply enter a space */
-		result = BOOL_TRUE;
-	} else {
-		/* Find out if current line is legal. It can be
-		 * fully completed or partially completed.
-		 */
-		arg_status = clish_shell_parse(shell, line, &cmd, &pargv);
-		if (pargv)
-			clish_pargv_delete(pargv);
-		switch (arg_status) {
-		case CLISH_LINE_OK:
-		case CLISH_LINE_PARTIAL:
-			if (' ' != line[strlen(line) - 1])
-				result = BOOL_TRUE;
-			break;
-		default:
-			break;
-		}
-		/* If current line is illegal try to make auto-comletion. */
-		if (!result) {
-			/* perform word completion */
-			status = clish_shell_tinyrl_complete(this);
-			switch (status) {
-			case TINYRL_NO_MATCH:
-			case TINYRL_AMBIGUOUS:
-				/* ambiguous result signal an issue */
-				break;
-			case TINYRL_COMPLETED_AMBIGUOUS:
-				/* perform word completion again in case we just did case
-				   modification the first time */
-				status = clish_shell_tinyrl_complete(this);
-				if (status == TINYRL_MATCH_WITH_EXTENSIONS) {
-					/* all is well with the world just enter a space */
-					result = BOOL_TRUE;
-				}
-				break;
-			case TINYRL_MATCH:
-			case TINYRL_MATCH_WITH_EXTENSIONS:
-			case TINYRL_COMPLETED_MATCH:
-				/* all is well with the world just enter a space */
-				result = BOOL_TRUE;
-				break;
-			}
-		}
-	}
-	if (result)
-		result = tinyrl_insert_text(this, " ");
-	/* keep compiler happy */
-	key = key;
-
-	return result;
-}
-
-/*-------------------------------------------------------- */
-static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
-{
-	clish_context_t *context = tinyrl__get_context(this);
-	clish_shell_t *shell = clish_context__get_shell(context);
-	const clish_command_t *cmd = NULL;
-	const char *line = tinyrl__get_line(this);
-	bool_t result = BOOL_FALSE;
-	char *errmsg = NULL;
-
-	/* Inc line counter */
-	if (shell->current_file)
-		shell->current_file->line++;
-
-	/* nothing to pass simply move down the screen */
-	if (!*line) {
-		tinyrl_multi_crlf(this);
-		tinyrl_done(this);
-		return BOOL_TRUE;
-	}
-
-	/* try and parse the command */
-	cmd = clish_shell_resolve_command(shell, line);
-	if (!cmd) {
-		tinyrl_match_e status = clish_shell_tinyrl_complete(this);
-		switch (status) {
-		case TINYRL_MATCH:
-		case TINYRL_MATCH_WITH_EXTENSIONS:
-		case TINYRL_COMPLETED_MATCH:
-			/* re-fetch the line as it may have changed
-			 * due to auto-completion
-			 */
-			line = tinyrl__get_line(this);
-			/* get the command to parse? */
-			cmd = clish_shell_resolve_command(shell, line);
-			/*
-			 * We have had a match but it is not a command
-			 * so add a space so as not to confuse the user
-			 */
-			if (!cmd)
-				result = tinyrl_insert_text(this, " ");
-			break;
-		default:
-			/* failed to get a unique match... */
-			if (!tinyrl__get_isatty(this)) {
-				/* batch mode */
-				tinyrl_multi_crlf(this);
-				errmsg = "Unknown command";
-			}
-			break;
-		}
-	}
-	if (cmd) {
-		clish_pargv_status_e arg_status;
-		tinyrl_multi_crlf(this);
-		/* we've got a command so check the syntax */
-		arg_status = clish_shell_parse(shell,
-			line, &context->cmd, &context->pargv);
-		switch (arg_status) {
-		case CLISH_LINE_OK:
-			tinyrl_done(this);
-			result = BOOL_TRUE;
-			break;
-		case CLISH_BAD_HISTORY:
-			errmsg = "Bad history entry";
-			break;
-		case CLISH_BAD_CMD:
-			errmsg = "Illegal command line";
-			break;
-		case CLISH_BAD_PARAM:
-			errmsg = "Illegal parameter";
-			break;
-		case CLISH_LINE_PARTIAL:
-			errmsg = "The command is not completed";
-			break;
-		default:
-			errmsg = "Unknown problem";
-			break;
-		}
-	}
-	/* If error then print message */
-	if (errmsg) {
-		if (tinyrl__get_isatty(this) || !shell->current_file) {
-			fprintf(stderr, "Syntax error: %s\n", errmsg);
-			tinyrl_reset_line_state(this);
-		} else {
-			char *fname = "stdin";
-			if (shell->current_file->fname)
-				fname = shell->current_file->fname;
-			fprintf(stderr, "Syntax error on line %s:%u \"%s\": "
-			"%s\n", fname, shell->current_file->line,
-			line, errmsg);
-		}
-	}
-	/* keep the compiler happy */
-	key = key;
-
-	return result;
-}
-
-/*-------------------------------------------------------- */
-static bool_t clish_shell_tinyrl_hotkey(tinyrl_t *this, int key)
-{
-	clish_view_t *view;
-	const char *cmd = NULL;
-	clish_context_t *context = tinyrl__get_context(this);
-	clish_shell_t *shell = clish_context__get_shell(context);
-	int i;
-	char *tmp = NULL;
-
-	i = clish_shell__get_depth(shell);
-	while (i >= 0) {
-		view = clish_shell__get_pwd_view(shell, i);
-		cmd = clish_view_find_hotkey(view, key);
-		if (cmd)
-			break;
-		i--;
-	}
-	/* Check the global view */
-	if (i < 0) {
-		view = shell->global;
-		cmd = clish_view_find_hotkey(view, key);
-	}
-	if (!cmd)
-		return BOOL_FALSE;
-
-	tmp = clish_shell_expand(cmd, SHELL_VAR_NONE, context);
-	tinyrl_replace_line(this, tmp, 0);
-	lub_string_free(tmp);
-	clish_shell_tinyrl_key_enter(this, 0);
-
-	return BOOL_TRUE;
-}
-
-/*-------------------------------------------------------- */
-/* This is the completion function provided for CLISH */
-tinyrl_completion_func_t clish_shell_tinyrl_completion;
-char **clish_shell_tinyrl_completion(tinyrl_t * tinyrl,
-	const char *line, unsigned start, unsigned end)
-{
-	lub_argv_t *matches;
-	clish_context_t *context = tinyrl__get_context(tinyrl);
-	clish_shell_t *this = clish_context__get_shell(context);
-	clish_shell_iterator_t iter;
-	const clish_command_t *cmd = NULL;
-	char *text;
-	char **result = NULL;
-
-	if (tinyrl_is_quoting(tinyrl))
-		return result;
-
-	matches = lub_argv_new(NULL, 0);
-	text = lub_string_dupn(line, end);
-
-	/* Don't bother to resort to filename completion */
-	tinyrl_completion_over(tinyrl);
-
-	/* Search for COMMAND completions */
-	clish_shell_iterator_init(&iter, CLISH_NSPACE_COMPLETION);
-	while ((cmd = clish_shell_find_next_completion(this, text, &iter)))
-		lub_argv_add(matches, clish_command__get_suffix(cmd));
-
-	/* Try and resolve a command */
-	cmd = clish_shell_resolve_command(this, text);
-	/* Search for PARAM completion */
-	if (cmd)
-		clish_shell_param_generator(this, matches, cmd, text, start);
-
-	lub_string_free(text);
-
-	/* Matches were found */
-	if (lub_argv__get_count(matches) > 0) {
-		unsigned i;
-		char *subst = lub_string_dup(lub_argv__get_arg(matches, 0));
-		/* Find out substitution */
-		for (i = 1; i < lub_argv__get_count(matches); i++) {
-			char *p = subst;
-			const char *match = lub_argv__get_arg(matches, i);
-			size_t match_len = strlen(p);
-			/* identify the common prefix */
-			while ((tolower(*p) == tolower(*match)) && match_len--) {
-				p++;
-				match++;
-			}
-			/* Terminate the prefix string */
-			*p = '\0';
-		}
-		result = lub_argv__get_argv(matches, subst);
-		lub_string_free(subst);
-	}
-	lub_argv_delete(matches);
-
-	return result;
-}
-
-/*-------------------------------------------------------- */
-static void clish_shell_tinyrl_init(tinyrl_t * this)
-{
-	bool_t status;
-	/* bind the '?' key to the help function */
-	status = tinyrl_bind_key(this, '?', clish_shell_tinyrl_key_help);
-	assert(status);
-
-	/* bind the <RET> key to the help function */
-	status = tinyrl_bind_key(this, '\r', clish_shell_tinyrl_key_enter);
-	assert(status);
-	status = tinyrl_bind_key(this, '\n', clish_shell_tinyrl_key_enter);
-	assert(status);
-
-	/* bind the <SPACE> key to auto-complete if necessary */
-	status = tinyrl_bind_key(this, ' ', clish_shell_tinyrl_key_space);
-	assert(status);
-
-	/* Set external hotkey callback */
-	tinyrl__set_hotkey_fn(this, clish_shell_tinyrl_hotkey);
-
-	/* Assign timeout callback */
-	tinyrl__set_timeout_fn(this, clish_shell_timeout_fn);
-	/* Assign keypress callback */
-	tinyrl__set_keypress_fn(this, clish_shell_keypress_fn);
-}
-
-/*-------------------------------------------------------- */
-/*
- * Create an instance of the specialised class
- */
-tinyrl_t *clish_shell_tinyrl_new(FILE * istream,
-	FILE * ostream, unsigned stifle)
-{
-	/* call the parent constructor */
-	tinyrl_t *this = tinyrl_new(istream,
-		ostream, stifle, clish_shell_tinyrl_completion);
-	/* now call our own constructor */
-	if (this)
-		clish_shell_tinyrl_init(this);
-	return this;
-}
-
-/*-------------------------------------------------------- */
-void clish_shell_tinyrl_fini(tinyrl_t * this)
-{
-	/* nothing to do... yet */
-	this = this;
-}
-
-/*-------------------------------------------------------- */
-void clish_shell_tinyrl_delete(tinyrl_t * this)
-{
-	/* call our destructor */
-	clish_shell_tinyrl_fini(this);
-	/* and call the parent destructor */
-	tinyrl_delete(this);
-}
-
-/*-------------------------------------------------------- */
-static int clish_shell_execline(clish_shell_t *this, const char *line, char **out)
-{
-	char *str;
-	clish_context_t context;
-	tinyrl_history_t *history;
-	int lerror = 0;
-
-	assert(this);
-	this->state = SHELL_STATE_OK;
-	if (!line && !tinyrl__get_istream(this->tinyrl)) {
-		this->state = SHELL_STATE_SYSTEM_ERROR;
-		return -1;
-	}
-
-	/* Renew prompt */
-	clish_shell_renew_prompt(this);
-
-	/* Set up the context for tinyrl */
-	clish_context_init(&context, this);
-
-	/* Push the specified line or interactive line */
-	if (line)
-		str = tinyrl_forceline(this->tinyrl, &context, line);
-	else
-		str = tinyrl_readline(this->tinyrl, &context);
-	lerror = errno;
-	if (!str) {
-		switch (lerror) {
-		case ENOENT:
-			this->state = SHELL_STATE_EOF;
-			break;
-		case ENOEXEC:
-			this->state = SHELL_STATE_SYNTAX_ERROR;
-			break;
-		default:
-			this->state = SHELL_STATE_SYSTEM_ERROR;
-			break;
-		};
-		return -1;
-	}
-
-	/* Deal with the history list */
-	if (tinyrl__get_isatty(this->tinyrl)) {
-		history = tinyrl__get_history(this->tinyrl);
-		tinyrl_history_add(history, str);
-	}
-	free(str);
-
-	/* Execute the provided command */
-	if (context.cmd && context.pargv) {
-		int res;
-		if ((res = clish_shell_execute(&context, out))) {
-			this->state = SHELL_STATE_SCRIPT_ERROR;
-			if (context.pargv)
-				clish_pargv_delete(context.pargv);
-			return res;
-		}
-	}
-
-	if (context.pargv)
-		clish_pargv_delete(context.pargv);
-
-	return 0;
-}
-
-/*-------------------------------------------------------- */
-int clish_shell_forceline(clish_shell_t *this, const char *line, char **out)
-{
-	return clish_shell_execline(this, line, out);
-}
-
-/*-------------------------------------------------------- */
-int clish_shell_readline(clish_shell_t *this, char **out)
-{
-	return clish_shell_execline(this, NULL, out);
-}
-
-/*-------------------------------------------------------- */
-FILE * clish_shell__get_istream(const clish_shell_t * this)
-{
-	return tinyrl__get_istream(this->tinyrl);
-}
-
-/*-------------------------------------------------------- */
-FILE * clish_shell__get_ostream(const clish_shell_t * this)
-{
-	return tinyrl__get_ostream(this->tinyrl);
-}
-
-
-/*-------------------------------------------------------- */
-bool_t clish_shell__get_utf8(const clish_shell_t * this)
-{
-	assert(this);
-	return tinyrl__get_utf8(this->tinyrl);
-}
-
-/*-------------------------------------------------------- */
-void clish_shell__set_utf8(clish_shell_t * this, bool_t utf8)
-{
-	assert(this);
-	tinyrl__set_utf8(this->tinyrl, utf8);
-}
-
-/*--------------------------------------------------------- */
-tinyrl_t *clish_shell__get_tinyrl(const clish_shell_t * this)
-{
-	return this->tinyrl;
-}
-
-/*----------------------------------------------------------*/
-int clish_shell__save_history(const clish_shell_t *this, const char *fname)
-{
-	return tinyrl__save_history(this->tinyrl, fname);
-}
-
-/*----------------------------------------------------------*/
-int clish_shell__restore_history(clish_shell_t *this, const char *fname)
-{
-	return tinyrl__restore_history(this->tinyrl, fname);
-}
-
-/*----------------------------------------------------------*/
-void clish_shell__stifle_history(clish_shell_t *this, unsigned int stifle)
-{
-	tinyrl__stifle_history(this->tinyrl, stifle);
-}
-
-CLISH_SET(shell, unsigned int, idle_timeout);
-CLISH_SET(shell, bool_t, interactive);
-CLISH_GET(shell, bool_t, interactive);

+ 0 - 95
clish/shell/shell_udata.c

@@ -1,95 +0,0 @@
-/*
- * shell_udata.c
- */
-#include <assert.h>
-#include <string.h>
-
-#include "private.h"
-#include "clish/udata.h"
-
-/*-------------------------------------------------------- */
-static lub_list_node_t *find_udata_node(const clish_shell_t *this, const char *name)
-{
-	lub_list_node_t *iter;
-	clish_udata_t *udata;
-
-	assert(this);
-	if (!name)
-		return NULL;
-
-	for(iter = lub_list__get_head(this->udata);
-		iter; iter = lub_list_node__get_next(iter)) {
-		int res;
-		udata = (clish_udata_t *)lub_list_node__get_data(iter);
-		res = strcmp(clish_udata__get_name(udata), name);
-		if (!res)
-			return iter;
-		if (res > 0) /* No chance to find name */
-			break;
-	}
-
-	return NULL;
-}
-
-/*-------------------------------------------------------- */
-static clish_udata_t *find_udata(const clish_shell_t *this, const char *name)
-{
-	lub_list_node_t *iter;
-
-	if (!(iter = find_udata_node(this, name)))
-		return NULL;
-	return (clish_udata_t *)lub_list_node__get_data(iter);
-}
-
-/*-------------------------------------------------------- */
-void *clish_shell__get_udata(const clish_shell_t *this, const char *name)
-{
-	clish_udata_t *udata;
-	assert (this);
-
-	udata = find_udata(this, name);
-	return clish_udata__get_data(udata);
-}
-
-/*-------------------------------------------------------- */
-void *clish_shell__del_udata(clish_shell_t *this, const char *name)
-{
-	lub_list_node_t *node = NULL;
-	clish_udata_t *pdata = NULL;
-
-	if (!this || !name)
-		return NULL;
-
-	if(!(node = find_udata_node(this, name)))
-		return NULL;
-
-	pdata = (clish_udata_t *)lub_list_node__get_data(node);
-	lub_list_del(this->udata, node);
-	lub_list_node_free(node);
-
-	return clish_udata_free(pdata);
-}
-
-/*-------------------------------------------------------- */
-int clish_shell__set_udata(clish_shell_t *this,
-	const char *name, void *data)
-{
-	clish_udata_t *pdata = NULL;
-
-	if (!this || !name)
-		return -1;
-
-	if ((pdata = find_udata(this, name))) {
-		clish_udata__set_data(pdata, data);
-		return 0;
-	}
-
-	if (!(pdata = clish_udata_new(name, data)))
-		return -1;
-	if (lub_list_add(this->udata, pdata))
-		return 0;
-
-	clish_udata_free(pdata);
-	return -1;
-}
-/*-------------------------------------------------------- */

+ 0 - 539
clish/shell/shell_var.c

@@ -1,539 +0,0 @@
-/*
- * shell_var.c
- */
-
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "lub/string.h"
-#include "lub/conv.h"
-#include "private.h"
-
-/*----------------------------------------------------------- */
-/*
- * search the current viewid string for a variable
- */
-void clish_shell__expand_viewid(const char *viewid, lub_bintree_t *tree,
-	clish_context_t *context)
-{
-	char *expanded;
-	char *q;
-	char *saveptr = NULL;
-
-	expanded = clish_shell_expand(viewid, SHELL_VAR_NONE, context);
-	if (!expanded)
-		return;
-
-	for (q = strtok_r(expanded, ";", &saveptr);
-		q; q = strtok_r(NULL, ";", &saveptr)) {
-		char *value;
-		clish_var_t *var;
-
-		value = strchr(q, '=');
-		if (!value)
-			continue;
-		*value = '\0';
-		value++;
-		/* Create var instance */
-		var = clish_var_new(q);
-		lub_bintree_insert(tree, var);
-		clish_var__set_value(var, value);
-	}
-	lub_string_free(expanded);
-}
-
-/*----------------------------------------------------------- */
-/*
- * expand context dependent fixed-name variables
- */
-static char *find_context_var(const char *name, clish_context_t *this)
-{
-	char *result = NULL;
-	clish_shell_t *shell = this->shell;
-
-	if (!lub_string_nocasecmp(name, "_width")) {
-		char tmp[5];
-		snprintf(tmp, sizeof(tmp), "%u",
-			tinyrl__get_width(shell->tinyrl));
-		tmp[sizeof(tmp) - 1] = '\0';
-		result = strdup(tmp);
-
-	} else if (!lub_string_nocasecmp(name, "_height")) {
-		char tmp[5];
-		snprintf(tmp, sizeof(tmp), "%u",
-			tinyrl__get_height(shell->tinyrl));
-		tmp[sizeof(tmp) - 1] = '\0';
-		result = strdup(tmp);
-
-	} else if (!lub_string_nocasecmp(name, "_watchdog_timeout")) {
-		char tmp[5];
-		snprintf(tmp, sizeof(tmp), "%u", shell->wdog_timeout);
-		tmp[sizeof(tmp) - 1] = '\0';
-		result = strdup(tmp);
-
-	} else if (!this->cmd) { /* The vars dependent on command */
-		return NULL;
-
-	} else if (!lub_string_nocasecmp(name, "_full_cmd")) {
-		result = lub_string_dup(clish_command__get_name(this->cmd));
-
-	} else if (!lub_string_nocasecmp(name, "_cmd")) {
-		result = lub_string_dup(clish_command__get_name(
-			clish_command__get_cmd(this->cmd)));
-
-	} else if (!lub_string_nocasecmp(name, "_orig_cmd")) {
-		result = lub_string_dup(clish_command__get_name(
-			clish_command__get_orig(this->cmd)));
-
-	} else if (!lub_string_nocasecmp(name, "_line")) {
-		result = clish_shell__get_line(this);
-
-	} else if (!lub_string_nocasecmp(name, "_full_line")) {
-		result = clish_shell__get_full_line(this);
-
-	} else if (!lub_string_nocasecmp(name, "_params")) {
-		if (this->pargv)
-			result = clish_shell__get_params(this);
-
-	} else if (!lub_string_nocasecmp(name, "_interactive")) {
-		if (clish_shell__get_interactive(this->shell) &&
-			tinyrl__get_isatty(this->shell->tinyrl))
-			result = strdup("1");
-		else
-			result = strdup("0");
-
-	} else if (!lub_string_nocasecmp(name, "_isatty")) {
-		if (tinyrl__get_isatty(this->shell->tinyrl))
-			result = strdup("1");
-		else
-			result = strdup("0");
-
-	} else if (!lub_string_nocasecmp(name, "_pid")) {
-		char tmp[10];
-		snprintf(tmp, sizeof(tmp), "%u", getpid());
-		tmp[sizeof(tmp) - 1] = '\0';
-		result = strdup(tmp);
-
-	} else if (lub_string_nocasestr(name, "_prefix") == name) {
-		unsigned int idx = 0;
-		unsigned int pnum = 0;
-		pnum = lub_string_wordcount(clish_command__get_name(this->cmd)) -
-			lub_string_wordcount(clish_command__get_name(
-			clish_command__get_cmd(this->cmd)));
-		lub_conv_atoui(name + strlen("_prefix"), &idx, 0);
-		if (idx < pnum) {
-			lub_argv_t *argv = lub_argv_new(
-				clish_command__get_name(this->cmd), 0);
-			result = lub_string_dup(lub_argv__get_arg(argv, idx));
-			lub_argv_delete(argv);
-		}
-
-	} else if (!lub_string_nocasecmp(name, "_cur_depth")) {
-		char tmp[10];
-		int depth = clish_shell__get_depth(shell);
-		snprintf(tmp, sizeof(tmp), "%u", depth);
-		tmp[sizeof(tmp) - 1] = '\0';
-		result = strdup(tmp);
-
-	} else if (!lub_string_nocasecmp(name, "_cur_pwd")) {
-		int depth = clish_shell__get_depth(shell);
-		result = clish_shell__get_pwd_full(shell, depth);
-	}
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-static char *find_var(const char *name, lub_bintree_t *tree, clish_context_t *context)
-{
-	clish_var_t *var = lub_bintree_find(tree, name);
-	const char *value;
-	bool_t dynamic;
-	char *res = NULL;
-
-	if (!var)
-		return NULL;
-
-	/* Try to get saved value for static var */
-	dynamic = clish_var__get_dynamic(var);
-	if (!dynamic) {
-		const char *saved = clish_var__get_saved(var);
-		if (saved)
-			return lub_string_dup(saved);
-	}
-
-	/* Try to expand value field */
-	value = clish_var__get_value(var);
-	if (value)
-		res = clish_shell_expand(value, SHELL_VAR_NONE,  context);
-
-	/* Try to execute ACTION */
-	if (!res) {
-		char *out = NULL;
-		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)) {
-			lub_string_free(out);
-			return NULL;
-		}
-		res = out;
-	}
-
-	/* Save value for static var */
-	if (!dynamic && res)
-		clish_var__set_saved(var, res);
-
-	return res;
-}
-
-/*--------------------------------------------------------- */
-static char *find_global_var(const char *name, clish_context_t *context)
-{
-	clish_shell_t *shell = clish_context__get_shell(context);
-	return find_var(name, &shell->var_tree, context);
-}
-
-/*--------------------------------------------------------- */
-static char *find_viewid_var(const char *name, clish_context_t *context)
-{
-	clish_shell_t *shell = clish_context__get_shell(context);
-	int depth = clish_shell__get_depth(shell);
-	if (depth < 0)
-		return NULL;
-	return find_var(name, &shell->pwdv[depth]->viewid, context);
-}
-
-static char * chardiff(const char *syms, const char *minus)
-{
-	char *dst = malloc(strlen(syms) + 1);
-	char *p = dst;
-	const char *src;
-
-	for (src = syms; *src; src++) {
-		if (!strchr(minus, *src))
-			*(p++) = *src;
-	}
-	*p = '\0';
-	return dst;
-}
-
-/*--------------------------------------------------------- */
-/*
- * return the next segment of text from the provided string
- * segments are delimited by variables within the string.
- */
-static char *expand_nextsegment(const char **string, const char *escape_chars,
-	clish_context_t *this)
-{
-	const char *p = *string;
-	char *result = NULL;
-	size_t len = 0;
-
-	if (!p)
-		return NULL;
-
-	if (*p && (p[0] == '$') && (p[1] == '{')) {
-		/* start of a variable */
-		const char *tmp;
-		p += 2;
-		tmp = p;
-
-		/*
-		 * find the end of the variable 
-		 */
-		while (*p && p++[0] != '}')
-			len++;
-
-		/* ignore non-terminated variables */
-		if (p[-1] == '}') {
-			bool_t valid = BOOL_FALSE;
-			char *text, *q;
-			char *saveptr = NULL;
-
-			/* get the variable text */
-			text = lub_string_dupn(tmp, len);
-			/*
-			 * tokenise this INTO ':' separated words
-			 * and either expand or duplicate into the result string.
-			 * Only return a result if at least 
-			 * of the words is an expandable variable
-			 */
-			for (q = strtok_r(text, ":", &saveptr);
-				q; q = strtok_r(NULL, ":", &saveptr)) {
-				char *var;
-				int mod_quote = 0; /* quote modifier */
-				int mod_esc = 0; /* internal escape modifier */
-				int mod_esc_chars = 1; /* escaping */
-				int mod_esc_dec = 0; /* remove internal chars from escaping */
-				char *space;
-				char *all_esc = NULL;
-
-				/* Search for modifiers */
-				while (*q && !isalpha(*q)) {
-					if ('#' == *q) {
-						mod_quote = 1;
-						mod_esc = 1;
-					} else if ('\\' == *q) {
-						mod_esc = 1;
-					} else if ('!' == *q) {
-						mod_quote = 1;
-						mod_esc = 1;
-						mod_esc_chars = 0;
-					} else if ('~' == *q) {
-						mod_esc = 1;
-						mod_esc_chars = 0;
-					/* Internal automatic variable like ${__line} */
-					} else if (('_' == *q) && ('_' == *(q+1))) {
-						mod_esc_dec = 1;
-						q++;
-						break;
-					/* No escaping at all. Usefull for macros VAR */
-					} else if ('^' == *q) {
-						mod_quote = 0;
-						mod_esc = 0;
-						mod_esc_chars = 0;
-					} else
-						break;
-					q++;
-				}
-
-				/* Get clean variable value */
-				var = clish_shell_expand_var(q, this);
-				if (!var) {
-					lub_string_cat(&result, q);
-					continue;
-				}
-				valid = BOOL_TRUE;
-
-				/* Quoting */
-				if (mod_quote)
-					space = strchr(var, ' ');
-				if (mod_quote && space)
-					lub_string_cat(&result, "\"");
-
-				/* Escape special chars */
-				if (escape_chars && mod_esc_chars) {
-					/* Remove internal esc from escape chars */
-					if (mod_esc_dec)
-						all_esc = chardiff(escape_chars,
-							lub_string_esc_quoted);
-					else
-						all_esc = lub_string_dup(escape_chars);
-				}
-
-				/* Internal escaping */
-				if (mod_esc)
-					lub_string_cat(&all_esc,
-						lub_string_esc_quoted);
-
-				/* Real escaping */
-				if (all_esc) {
-					char *tstr = lub_string_encode(var,
-						all_esc);
-					lub_string_free(var);
-					var = tstr;
-					lub_string_free(all_esc);
-				}
-
-				/* copy the expansion or the raw word */
-				lub_string_cat(&result, var);
-
-				/* Quoting */
-				if (mod_quote && space)
-					lub_string_cat(&result, "\"");
-
-				lub_string_free(var);
-			}
-
-			if (!valid) {
-				/* not a valid variable expansion */
-				lub_string_free(result);
-				result = lub_string_dup("");
-			}
-
-			/* finished with the variable text */
-			lub_string_free(text);
-		}
-	} else {
-		/* find the start of a variable */
-		while (*p) {
-			if ((p[0] == '$') && (p[1] == '{'))
-				break;
-			len++;
-			p++;
-		}
-		if (len > 0)
-			result = lub_string_dupn(*string, len);
-	}
-	/* move the string pointer on for next time... */
-	*string = p;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-/*
- * This function builds a dynamic string based on that provided
- * subtituting each occurance of a "${FRED}" type variable sub-string
- * with the appropriate value.
- */
-char *clish_shell_expand(const char *str, clish_shell_var_e vtype, clish_context_t *context)
-{
-	char *seg, *result = NULL;
-	const char *escape_chars = NULL;
-	const clish_command_t *cmd = clish_context__get_cmd(context);
-
-	/* Escape special characters */
-	if (SHELL_VAR_REGEX == vtype) {
-		if (cmd)
-			escape_chars = clish_command__get_regex_chars(cmd);
-		if (!escape_chars)
-			escape_chars = lub_string_esc_regex;
-	} else if (SHELL_VAR_ACTION == vtype) {
-		if (cmd)
-			escape_chars = clish_command__get_escape_chars(cmd);
-		if (!escape_chars)
-			escape_chars = lub_string_esc_default;
-	}
-
-	/* read each segment and extend the result */
-	while ((seg = expand_nextsegment(&str, escape_chars, context))) {
-		lub_string_cat(&result, seg);
-		lub_string_free(seg);
-	}
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-char *clish_shell__get_params(clish_context_t *context)
-{
-	clish_pargv_t *pargv = clish_context__get_pargv(context);
-	char *line = NULL;
-	unsigned i, cnt;
-	const clish_param_t *param;
-	const clish_parg_t *parg;
-	char *request = NULL;
-
-	if (!pargv)
-		return NULL;
-
-	cnt = clish_pargv__get_count(pargv);
-	for (i = 0; i < cnt; i++) {
-		param = clish_pargv__get_param(pargv, i);
-		if (clish_param__get_hidden(param))
-			continue;
-		parg = clish_pargv__get_parg(pargv, i);
-		if (request)
-			lub_string_cat(&request, " ");
-		lub_string_cat(&request, "${!");
-		lub_string_cat(&request, clish_parg__get_name(parg));
-		lub_string_cat(&request, "}");
-	}
-
-	line = clish_shell_expand(request, SHELL_VAR_NONE, context);
-	lub_string_free(request);
-
-	return line;
-}
-
-/*--------------------------------------------------------- */
-static char *internal_get_line(clish_context_t *context, int cmd_type)
-{
-	const clish_command_t *cmd = clish_context__get_cmd(context);
-	clish_pargv_t *pargv = clish_context__get_pargv(context);
-	char *line = NULL;
-	char *params = NULL;
-
-	if (0 == cmd_type) /* __cmd */
-		lub_string_cat(&line, clish_command__get_name(
-			clish_command__get_cmd(cmd)));
-	else /* __full_cmd */
-		lub_string_cat(&line, clish_command__get_name(cmd));
-
-	if (!pargv)
-		return line;
-
-	params = clish_shell__get_params(context);
-	if (params) {
-		lub_string_cat(&line, " ");
-		lub_string_cat(&line, params);
-	}
-	lub_string_free(params);
-
-	return line;
-}
-
-/*--------------------------------------------------------- */
-char *clish_shell__get_line(clish_context_t *context)
-{
-	return internal_get_line(context, 0); /* __cmd */
-}
-
-/*--------------------------------------------------------- */
-char *clish_shell__get_full_line(clish_context_t *context)
-{
-	return internal_get_line(context, 1); /* __full_cmd */
-}
-
-/*--------------------------------------------------------- */
-char *clish_shell_expand_var(const char *name, clish_context_t *context)
-{
-	return clish_shell_expand_var_ex(name, context, SHELL_EXPAND_ALL);
-}
-
-/*----------------------------------------------------------- */
-char *clish_shell_expand_var_ex(const char *name, clish_context_t *context, clish_shell_expand_e flags)
-{
-	clish_shell_t *this;
-	const clish_command_t *cmd;
-	clish_pargv_t *pargv;
-	const char *tmp = NULL;
-	char *string = NULL;
-
-	assert(name);
-	if (!context)
-		return NULL;
-	this = clish_context__get_shell(context);
-	cmd = clish_context__get_cmd(context);
-	pargv = clish_context__get_pargv(context);
-
-	/* try and substitute a parameter value */
-	if (pargv && (flags & SHELL_EXPAND_PARAM)) {
-		const clish_parg_t *parg = clish_pargv_find_arg(pargv, name);
-		if (parg)
-			tmp = clish_parg__get_value(parg);
-	}
-
-	/* try and substitute the param's default */
-	if (!tmp && cmd && (flags & SHELL_EXPAND_PARAM))
-		tmp = clish_paramv_find_default(
-			clish_command__get_paramv(cmd), name);
-
-	/* try and substitute a viewId variable */
-	if (!tmp && this && (flags & SHELL_EXPAND_VIEW))
-		tmp = string = find_viewid_var(name, context);
-
-	/* try and substitute context fixed variable */
-	if (!tmp && (flags & SHELL_EXPAND_CONTEXT))
-		tmp = string = find_context_var(name, context);
-
-	/* try and substitute a global var value */
-	if (!tmp && this && (flags & SHELL_EXPAND_VAR))
-		tmp = string = find_global_var(name, context);
-
-	/* get the contents of an environment variable */
-	if (!tmp && (flags & SHELL_EXPAND_ENV))
-		tmp = getenv(name);
-
-	if (string)
-		return string;
-	return lub_string_dup(tmp);
-}
-
-/*----------------------------------------------------------- */

+ 0 - 59
clish/shell/shell_view.c

@@ -1,59 +0,0 @@
-/*
- * shell_find_create_view.c
- */
-
-#include <assert.h>
-#include <string.h>
-
-#include "private.h"
-
-static int find_view(const void *key, const void *data)
-{
-	clish_view_t *view = (clish_view_t *)data;
-	const char *name = key;
-	return strcmp(name, clish_view__get_name(view));
-}
-
-/*--------------------------------------------------------- */
-clish_view_t *clish_shell_find_create_view(clish_shell_t *this,
-	const char *name)
-{
-	clish_view_t *view = clish_shell_find_view(this, name);
-	if (view)
-		return view;
-	view = clish_view_new(name);
-	lub_list_add(this->view_tree, view);
-	return view;
-}
-
-/*--------------------------------------------------------- */
-clish_view_t *clish_shell_find_view(clish_shell_t *this, const char *name)
-{
-	return lub_list_find(this->view_tree, find_view, name);
-}
-
-/*--------------------------------------------------------- */
-clish_view_t *clish_shell__get_view(const clish_shell_t * this)
-{
-	assert(this);
-	if (this->depth < 0)
-		return NULL;
-	return this->pwdv[this->depth]->view;
-}
-
-/*--------------------------------------------------------- */
-clish_view_t *clish_shell__set_depth(clish_shell_t *this, unsigned int depth)
-{
-	clish_view_t *tmp;
-
-	assert(this);
-	/* Check if target view is valid = is not NULL */
-	tmp = this->pwdv[depth]->view;
-	if (!tmp)
-		return NULL;
-	this->depth = depth;
-	return tmp;
-}
-
-CLISH_GET(shell, unsigned int, depth);
-

+ 0 - 66
clish/shell/shell_wdog.c

@@ -1,66 +0,0 @@
-/*
- * shell_wdog.c
- */
-#include "private.h"
-#include <assert.h>
-
-#include "tinyrl/tinyrl.h"
-#include "lub/string.h"
-
-/*----------------------------------------------------------------------- */
-int clish_shell_timeout_fn(tinyrl_t *tinyrl)
-{
-	clish_context_t *context = tinyrl__get_context(tinyrl);
-	clish_shell_t *this = clish_context__get_shell(context);
-
-	/* Idle timeout */
-	if (!this->wdog_active) {
-		tinyrl_crlf(tinyrl);
-		fprintf(stderr, "Warning: Idle timeout. The session will be closed.\n");
-		/* Return -1 to close session on timeout */
-		return -1;
-	}
-
-	/* Watchdog timeout */
-	clish_shell_wdog(this);
-	this->wdog_active = BOOL_FALSE;
-	tinyrl__set_timeout(tinyrl, this->idle_timeout);
-
-	return 0;
-}
-
-/*----------------------------------------------------------------------- */
-int clish_shell_keypress_fn(tinyrl_t *tinyrl, int key)
-{
-	clish_context_t *context = tinyrl__get_context(tinyrl);
-	clish_shell_t *this = clish_context__get_shell(context);
-
-	if (this->wdog_active) {
-		this->wdog_active = BOOL_FALSE;
-		tinyrl__set_timeout(tinyrl, this->idle_timeout);
-	}
-
-	key = key; /* Happy compiler */
-
-	return 0;
-}
-
-/*----------------------------------------------------------- */
-int clish_shell_wdog(clish_shell_t *this)
-{
-	clish_context_t context;
-
-	assert(this->wdog);
-
-	/* Prepare context */
-	clish_context_init(&context, this);
-	clish_context__set_cmd(&context, this->wdog);
-	clish_context__set_action(&context,
-		clish_command__get_action(this->wdog));
-
-	/* Call watchdog script */
-	return clish_shell_execute(&context, NULL);
-}
-
-CLISH_SET(shell, unsigned int, wdog_timeout);
-CLISH_GET(shell, unsigned int, wdog_timeout);

+ 0 - 1317
clish/shell/shell_xml.c

@@ -1,1317 +0,0 @@
-/*
- * ------------------------------------------------------
- * shell_xml.c
- *
- * This file implements the means to read an XML encoded file and populate the
- * CLI tree based on the contents.
- * ------------------------------------------------------
- */
-#include "private.h"
-#include "xmlapi.h"
-#include "lub/string.h"
-#include "lub/ctype.h"
-#include "lub/system.h"
-#include "lub/conv.h"
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <dirent.h>
-
-typedef int (PROCESS_FN) (clish_shell_t *instance,
-	clish_xmlnode_t *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;
-struct clish_xml_cb_s {
-	const char *element;
-	PROCESS_FN *handler;
-};
-
-/* forward declare the handler functions */
-static PROCESS_FN
-	process_clish_module,
-	process_startup,
-	process_view,
-	process_command,
-	process_param,
-	process_action,
-	process_ptype,
-	process_overview,
-	process_detail,
-	process_namespace,
-	process_config,
-	process_var,
-	process_wdog,
-	process_hotkey,
-	process_plugin,
-	process_hook;
-
-static clish_xml_cb_t xml_elements[] = {
-	{"CLISH_MODULE", process_clish_module},
-	{"STARTUP", process_startup},
-	{"VIEW", process_view},
-	{"COMMAND", process_command},
-	{"PARAM", process_param},
-	{"ACTION", process_action},
-	{"PTYPE", process_ptype},
-	{"OVERVIEW", process_overview},
-	{"DETAIL", process_detail},
-	{"NAMESPACE", process_namespace},
-	{"CONFIG", process_config},
-	{"VAR", process_var},
-	{"WATCHDOG", process_wdog},
-	{"HOTKEY", process_hotkey},
-	{"PLUGIN", process_plugin},
-	{"HOOK", process_hook},
-	{NULL, NULL}
-};
-
-/*
- * if CLISH_PATH is unset in the environment then this is the value used. 
- */
-const char *default_path = "/etc/clish;~/.clish";
-
-static int process_node(clish_shell_t *shell, clish_xmlnode_t *node,
-	void *parent);
-
-/*-------------------------------------------------------- */
-int clish_shell_load_scheme(clish_shell_t *this, const char *xml_path, const char *xslt_path)
-{
-	const char *path = xml_path;
-	char *buffer;
-	char *dirname;
-	char *saveptr = NULL;
-	int res = -1;
-	clish_xmldoc_t *doc = NULL;
-	DIR *dir;
-
-#ifdef HAVE_LIB_LIBXSLT
-	clish_xslt_t *xslt = NULL;
-
-	/* Load global XSLT stylesheet */
-	if (xslt_path) {
-		xslt = clish_xslt_read(xslt_path);
-		if (!clish_xslt_is_valid(xslt)) {
-			fprintf(stderr, CLISH_XML_ERROR_STR"Can't load XSLT file %s\n",
-				xslt_path);
-			return -1;
-		}
-	}
-#else
-	xslt_path = xslt_path; /* Happy compiler */
-#endif
-
-	/* Use the default path */
-	if (!path)
-		path = default_path;
-	buffer = lub_system_tilde_expand(path);
-
-	/* Loop though each directory */
-	for (dirname = strtok_r(buffer, ";", &saveptr);
-		dirname; dirname = strtok_r(NULL, ";", &saveptr)) {
-		struct dirent *entry;
-
-		/* Search this directory for any XML files */
-		dir = opendir(dirname);
-		if (NULL == dir) {
-#ifdef DEBUG
-			tinyrl_printf(this->tinyrl,
-				"*** Failed to open '%s' directory\n",
-				dirname);
-#endif
-			continue;
-		}
-		for (entry = readdir(dir); entry; entry = readdir(dir)) {
-			const char *extension = strrchr(entry->d_name, '.');
-			char *filename = NULL;
-			clish_xmlnode_t *root;
-			int r;
-
-			/* Check the filename */
-			if (!extension || strcmp(".xml", extension))
-				continue;
-
-			/* Build the filename */
-			lub_string_cat(&filename, dirname);
-			lub_string_cat(&filename, "/");
-			lub_string_cat(&filename, entry->d_name);
-
-#ifdef DEBUG
-			fprintf(stderr, "Parse XML-file: %s\n", filename);
-#endif
-			/* Load current XML file */
-			doc = clish_xmldoc_read(filename);
-			if (!clish_xmldoc_is_valid(doc)) {
-				int errcaps = clish_xmldoc_error_caps(doc);
-				printf("Unable to open file '%s'", filename);
-				if ((errcaps & CLISH_XMLERR_LINE) == CLISH_XMLERR_LINE)
-					printf(", at line %d", clish_xmldoc_get_err_line(doc));
-				if ((errcaps & CLISH_XMLERR_COL) == CLISH_XMLERR_COL)
-					printf(", at column %d", clish_xmldoc_get_err_col(doc));
-				if ((errcaps & CLISH_XMLERR_DESC) == CLISH_XMLERR_DESC)
-					printf(", message is %s", clish_xmldoc_get_err_msg(doc));
-				printf("\n");
-				goto error;
-			}
-#ifdef HAVE_LIB_LIBXSLT
-			/* Use embedded stylesheet if stylesheet
-			 * filename is not specified.
-			 */
-			if (!xslt_path)
-				xslt = clish_xslt_read_embedded(doc);
-
-			if (clish_xslt_is_valid(xslt)) {
-				clish_xmldoc_t *tmp = NULL;
-				tmp = clish_xslt_apply(doc, xslt);
-				if (!clish_xmldoc_is_valid(tmp)) {
-					fprintf(stderr, CLISH_XML_ERROR_STR"Can't load XSLT file %s\n", xslt_path);
-					goto error;
-				}
-				clish_xmldoc_release(doc);
-				doc = tmp;
-			}
-
-			if (!xslt_path && clish_xslt_is_valid(xslt))
-				clish_xslt_release(xslt);
-#endif
-			root = clish_xmldoc_get_root(doc);
-			r = process_node(this, root, NULL);
-			clish_xmldoc_release(doc);
-
-			/* Error message */
-			if (r) {
-				fprintf(stderr, CLISH_XML_ERROR_STR"File %s\n",
-					filename);
-				lub_string_free(filename);
-				goto error;
-			}
-			lub_string_free(filename);
-		}
-		closedir(dir);
-	}
-
-/* To don't free memory twice on cleanup */
-#ifdef HAVE_LIB_LIBXSLT
-	if (!xslt_path)
-		xslt = NULL;
-#endif
-	doc = NULL;
-	dir = NULL;
-	res = 0; /* Success */
-error:
-	lub_string_free(buffer);
-	if (dir)
-		closedir(dir);
-	if (clish_xmldoc_is_valid(doc))
-		clish_xmldoc_release(doc);
-#ifdef HAVE_LIB_LIBXSLT
-	if (clish_xslt_is_valid(xslt))
-		clish_xslt_release(xslt);
-#endif
-
-	return res;
-}
-
-/*
- * ------------------------------------------------------
- * This function reads an element from the XML stream and processes it.
- * ------------------------------------------------------
- */
-static int process_node(clish_shell_t *shell, clish_xmlnode_t *node,
-	void *parent)
-{
-	int res = 0;
-
-	switch (clish_xmlnode_get_type(node)) {
-	case CLISH_XMLNODE_ELM: {
-			clish_xml_cb_t * cb;
-			char name[128];
-			unsigned int namelen = sizeof(name);
-			if (clish_xmlnode_get_name(node, name, &namelen) == 0) {
-				for (cb = &xml_elements[0]; cb->element; cb++) {
-					if (0 == strcmp(name, cb->element)) {
-#ifdef DEBUG
-						fprintf(stderr, "NODE:");
-						clish_xmlnode_print(node, stderr);
-						fprintf(stderr, "\n");
-#endif
-						/* process the elements at this level */
-						res = cb->handler(shell, node, parent);
-
-						/* Error message */
-						if (res) {
-							char *ename = clish_xmlnode_fetch_attr(node, "name");
-							char *eref = clish_xmlnode_fetch_attr(node, "ref");
-							char *ekey = clish_xmlnode_fetch_attr(node, "key");
-							char *efile = clish_xmlnode_fetch_attr(node, "file");
-							fprintf(stderr, CLISH_XML_ERROR_STR"Node %s", name);
-							if (ename)
-								fprintf(stderr, ", name=\"%s\"", ename);
-							if (eref)
-								fprintf(stderr, ", ref=\"%s\"", eref);
-							if (ekey)
-								fprintf(stderr, ", key=\"%s\"", ekey);
-							if (efile)
-								fprintf(stderr, ", file=\"%s\"", efile);
-							fprintf(stderr, "\n");
-							clish_xml_release(ename);
-							clish_xml_release(eref);
-							clish_xml_release(ekey);
-							clish_xml_release(efile);
-						}
-						break;
-					}
-				}
-			}
-			break;
-		}
-	case CLISH_XMLNODE_DOC:
-	case CLISH_XMLNODE_TEXT:
-	case CLISH_XMLNODE_ATTR:
-	case CLISH_XMLNODE_PI:
-	case CLISH_XMLNODE_COMMENT:
-	case CLISH_XMLNODE_DECL:
-	case CLISH_XMLNODE_UNKNOWN:
-	default:
-		break;
-	}
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_children(clish_shell_t *shell,
-	clish_xmlnode_t *element, void *parent)
-{
-	clish_xmlnode_t *node = NULL;
-	int res;
-
-	while ((node = clish_xmlnode_next_child(element, node)) != NULL) {
-		/* Now deal with all the contained elements */
-		res = process_node(shell, node, parent);
-		if (res)
-			return res;
-	}
-
-	return 0;
-}
-
-/* ------------------------------------------------------ */
-static int process_clish_module(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	/* Create the global view */
-	if (!shell->global)
-		shell->global = clish_shell_find_create_view(shell, "__view_global");
-
-	parent = parent; /* Happy compiler */
-
-	return process_children(shell, element, shell->global);
-}
-
-/* ------------------------------------------------------ */
-static int process_view(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_view_t *view;
-	int res = -1;
-
-	char *name = clish_xmlnode_fetch_attr(element, "name");
-	char *prompt = clish_xmlnode_fetch_attr(element, "prompt");
-	char *depth = clish_xmlnode_fetch_attr(element, "depth");
-	char *restore = clish_xmlnode_fetch_attr(element, "restore");
-	char *access = clish_xmlnode_fetch_attr(element, "access");
-
-	/* Check syntax */
-	if (!name) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
-		goto error;
-	}
-
-	/* re-use a view if it already exists */
-	view = clish_shell_find_create_view(shell, name);
-
-	if (prompt)
-		clish_view__set_prompt(view, prompt);
-
-	if (depth && (lub_ctype_isdigit(*depth))) {
-		unsigned int res = 0;
-		lub_conv_atoui(depth, &res, 0);
-		clish_view__set_depth(view, res);
-	}
-
-	if (restore) {
-		if (!lub_string_nocasecmp(restore, "depth"))
-			clish_view__set_restore(view, CLISH_RESTORE_DEPTH);
-		else if (!lub_string_nocasecmp(restore, "view"))
-			clish_view__set_restore(view, CLISH_RESTORE_VIEW);
-		else
-			clish_view__set_restore(view, CLISH_RESTORE_NONE);
-	}
-
-	if (access)
-		clish_view__set_access(view, access);
-
-//process_view_end:
-	res = process_children(shell, element, view);
-error:
-	clish_xml_release(name);
-	clish_xml_release(prompt);
-	clish_xml_release(depth);
-	clish_xml_release(restore);
-	clish_xml_release(access);
-
-	parent = parent; /* Happy compiler */
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_ptype(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_ptype_method_e method;
-	clish_ptype_preprocess_e preprocess;
-	int res = -1;
-	clish_ptype_t *ptype;
-
-	char *name = clish_xmlnode_fetch_attr(element, "name");
-	char *help = clish_xmlnode_fetch_attr(element, "help");
-	char *pattern = clish_xmlnode_fetch_attr(element, "pattern");
-	char *method_name = clish_xmlnode_fetch_attr(element, "method");
-	char *preprocess_name =	clish_xmlnode_fetch_attr(element, "preprocess");
-
-	/* Check syntax */
-	if (!name) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
-		goto error;
-	}
-
-	method = clish_ptype_method_resolve(method_name);
-	if (CLISH_PTYPE_METHOD_MAX == method) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("method"));
-		goto error;
-	}
-	if ((method != CLISH_PTYPE_METHOD_CODE) && !pattern) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("pattern"));
-		goto error;
-	}
-
-	preprocess = clish_ptype_preprocess_resolve(preprocess_name);
-	ptype = clish_shell_find_create_ptype(shell,
-		name, help, pattern, method, preprocess);
-
-	res = process_children(shell, element, ptype);
-error:
-	clish_xml_release(name);
-	clish_xml_release(help);
-	clish_xml_release(pattern);
-	clish_xml_release(method_name);
-	clish_xml_release(preprocess_name);
-
-	parent = parent; /* Happy compiler */
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_overview(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	char *content = NULL;
-	unsigned int content_len = 2048;
-	int result;
-
-	/*
-	 * the code below faithfully assume that we'll be able fully store
-	 * the content of the node. If it's really, really big, we may have
-	 * an issue (but then, if it's that big, how the hell does it
-	 * already fits in allocated memory?)
-	 * Ergo, it -should- be safe.
-	 */
-	do {
-		char *new = (char*)realloc(content, content_len);
-		if (!new) {
-			if (content)
-				free(content);
-			return -1;
-		}
-		content = new;
-		result = clish_xmlnode_get_content(element, content,
-			&content_len);
-	} while (result == -E2BIG);
-
-	if (result == 0 && content) {
-		/* set the overview text for this view */
-		assert(NULL == shell->overview);
-		/* store the overview */
-		shell->overview = lub_string_dup(content);
-	}
-
-	if (content)
-		free(content);
-
-	parent = parent; /* Happy compiler */
-
-	return 0;
-}
-
-/* ------------------------------------------------------ */
-static int process_command(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_view_t *v = (clish_view_t *) parent;
-	clish_command_t *cmd = NULL;
-	clish_command_t *old;
-	int res = -1;
-
-	char *access = clish_xmlnode_fetch_attr(element, "access");
-	char *name = clish_xmlnode_fetch_attr(element, "name");
-	char *help = clish_xmlnode_fetch_attr(element, "help");
-	char *view = clish_xmlnode_fetch_attr(element, "view");
-	char *viewid = clish_xmlnode_fetch_attr(element, "viewid");
-	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");
-	clish_action_t *action;
-#endif
-
-	/* Check syntax */
-	if (!name) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
-		goto error;
-	}
-	if (!help) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("help"));
-		goto error;
-	}
-
-	/* check this command doesn't already exist */
-	old = clish_view_find_command(v, name, BOOL_FALSE);
-	if (old) {
-		fprintf(stderr, CLISH_XML_ERROR_STR"Duplicate COMMAND name=\"%s\".\n", name);
-		goto error;
-	}
-
-	/* create a command */
-	cmd = clish_view_new_command(v, name, help);
-	clish_command__set_pview(cmd, v);
-
-	/* Reference 'ref' field */
-	if (ref) {
-		char *saveptr = NULL;
-		const char *delim = "@";
-		char *view_name = NULL;
-		char *cmdn = NULL;
-		char *str = lub_string_dup(ref);
-
-		cmdn = strtok_r(str, delim, &saveptr);
-		if (!cmdn) {
-			fprintf(stderr, CLISH_XML_ERROR_STR"Invalid \"ref\" attribute value.\n");
-			lub_string_free(str);
-			goto error;
-		}
-		clish_command__set_alias(cmd, cmdn); /* alias name */
-		view_name = strtok_r(NULL, delim, &saveptr);
-		clish_command__set_alias_view(cmd, view_name);
-		lub_string_free(str);
-	}
-
-	/* define some specialist escape characters */
-	if (escape_chars)
-		clish_command__set_escape_chars(cmd, escape_chars);
-
-	if (args_name) {
-		/* define a "rest of line" argument */
-		clish_param_t *param;
-
-		/* Check syntax */
-		if (!args_help) {
-			fprintf(stderr, CLISH_XML_ERROR_ATTR("args_help"));
-			goto error;
-		}
-		param = clish_param_new(args_name, args_help, "__ptype_ARGS");
-		clish_command__set_args(cmd, param);
-	}
-
-	/* define the view which this command changes to */
-	if (view) {
-		/* reference the next view */
-		clish_command__set_viewname(cmd, view);
-	}
-
-	/* define the view id which this command changes to */
-	if (viewid)
-		clish_command__set_viewid(cmd, viewid);
-
-#ifdef LEGACY
-	action = clish_command__get_action(cmd);
-
-	/* 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);
-
-//process_command_end:
-	res = process_children(shell, element, cmd);
-error:
-	clish_xml_release(access);
-	clish_xml_release(name);
-	clish_xml_release(help);
-	clish_xml_release(view);
-	clish_xml_release(viewid);
-	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);
-#endif
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_startup(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_view_t *v = (clish_view_t *) parent;
-	clish_command_t *cmd = NULL;
-	int res = -1;
-
-	char *view = clish_xmlnode_fetch_attr(element, "view");
-	char *viewid = clish_xmlnode_fetch_attr(element, "viewid");
-	char *default_shebang =
-		clish_xmlnode_fetch_attr(element, "default_shebang");
-	char *timeout = clish_xmlnode_fetch_attr(element, "timeout");
-	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) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("view"));
-		goto error;
-	}
-	if (shell->startup) {
-		fprintf(stderr, CLISH_XML_ERROR_STR"STARTUP tag duplication.\n");
-		goto error;
-	}
-
-	/* create a command with NULL help */
-	cmd = clish_view_new_command(v, "startup", NULL);
-	clish_command__set_internal(cmd, BOOL_TRUE);
-
-	/* reference the next view */
-	clish_command__set_viewname(cmd, view);
-
-	/* define the view id which this command changes to */
-	if (viewid)
-		clish_command__set_viewid(cmd, viewid);
-
-	if (default_shebang)
-		clish_shell__set_default_shebang(shell, default_shebang);
-
-	if (timeout) {
-		unsigned int to = 0;
-		lub_conv_atoui(timeout, &to, 0);
-		clish_shell__set_idle_timeout(shell, to);
-	}
-
-#ifdef LEGACY
-	action = clish_command__get_action(cmd);
-
-	/* 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")))
-		shell->default_plugin = BOOL_FALSE;
-
-	/* remember this command */
-	shell->startup = cmd;
-
-	res = process_children(shell, element, cmd);
-error:
-	clish_xml_release(view);
-	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;
-}
-
-/* ------------------------------------------------------ */
-static int process_param(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_command_t *cmd = NULL;
-	clish_param_t *p_param = NULL;
-	clish_xmlnode_t *pelement;
-	clish_param_t *param;
-	char *pname;
-	int res = -1;
-
-	char *name = clish_xmlnode_fetch_attr(element, "name");
-	char *help = clish_xmlnode_fetch_attr(element, "help");
-	char *ptype = clish_xmlnode_fetch_attr(element, "ptype");
-	char *prefix = clish_xmlnode_fetch_attr(element, "prefix");
-	char *defval = clish_xmlnode_fetch_attr(element, "default");
-	char *mode = clish_xmlnode_fetch_attr(element, "mode");
-	char *optional = clish_xmlnode_fetch_attr(element, "optional");
-	char *order = clish_xmlnode_fetch_attr(element, "order");
-	char *value = clish_xmlnode_fetch_attr(element, "value");
-	char *hidden = clish_xmlnode_fetch_attr(element, "hidden");
-	char *test = clish_xmlnode_fetch_attr(element, "test");
-	char *completion = clish_xmlnode_fetch_attr(element, "completion");
-	char *access = clish_xmlnode_fetch_attr(element, "access");
-
-	/* The PARAM can be child of COMMAND or another PARAM */
-	pelement = clish_xmlnode_parent(element);
-	pname = clish_xmlnode_get_all_name(pelement);
-	if (pname && lub_string_nocasecmp(pname, "PARAM") == 0)
-		p_param = (clish_param_t *)parent;
-	else
-		cmd = (clish_command_t *)parent;
-	if (pname)
-		free(pname);
-	if (!cmd && !p_param)
-		goto error;
-
-	/* Check syntax */
-	if (cmd && (cmd == shell->startup)) {
-		fprintf(stderr, CLISH_XML_ERROR_STR"STARTUP can't contain PARAMs.\n");
-		goto error;
-	}
-	if (!name) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
-		goto error;
-	}
-	if (!help) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("help"));
-		goto error;
-	}
-	if (!ptype) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("ptype"));
-		goto error;
-	}
-
-	param = clish_param_new(name, help, ptype);
-
-	/* If prefix is set clish will emulate old optional
-	 * command syntax over newer optional command mechanism.
-	 * It will create nested PARAM.
-	 */
-	if (prefix) {
-		const char *ptype_name = "__ptype_SUBCOMMAND";
-		clish_param_t *opt_param = NULL;
-		char *str = NULL;
-		clish_ptype_t *tmp;
-
-		/* Create a ptype for prefix-named subcommand that
-		 * will contain the nested optional parameter. The
-		 * name of ptype is hardcoded. It's not good but
-		 * it's only the service ptype.
-		 */
-		tmp = clish_shell_find_create_ptype(shell,
-			ptype_name, "Option", "[^\\\\]+",
-			CLISH_PTYPE_METHOD_REGEXP, CLISH_PTYPE_PRE_NONE);
-		assert(tmp);
-		lub_string_cat(&str, "_prefix_");
-		lub_string_cat(&str, name);
-		opt_param = clish_param_new(str, help, ptype_name);
-		lub_string_free(str);
-		clish_param__set_mode(opt_param,
-			CLISH_PARAM_SUBCOMMAND);
-		clish_param__set_value(opt_param, prefix);
-		clish_param__set_optional(opt_param, BOOL_TRUE);
-
-		if (test)
-			clish_param__set_test(opt_param, test);
-
-		/* Add the parameter to the command */
-		if (cmd)
-			clish_command_insert_param(cmd, opt_param);
-		/* Add the parameter to the param */
-		if (p_param)
-			clish_param_insert_param(p_param, opt_param);
-		/* Unset cmd and set parent param to opt_param */
-		cmd = NULL;
-		p_param = opt_param;
-	}
-
-	if (defval)
-		clish_param__set_defval(param, defval);
-
-	if (hidden && lub_string_nocasecmp(hidden, "true") == 0)
-		clish_param__set_hidden(param, BOOL_TRUE);
-	else
-		clish_param__set_hidden(param, BOOL_FALSE);
-
-	if (mode) {
-		if (lub_string_nocasecmp(mode, "switch") == 0) {
-			clish_param__set_mode(param,
-				CLISH_PARAM_SWITCH);
-			/* Force hidden attribute */
-			clish_param__set_hidden(param, BOOL_TRUE);
-		} else if (lub_string_nocasecmp(mode, "subcommand") == 0)
-			clish_param__set_mode(param,
-				CLISH_PARAM_SUBCOMMAND);
-		else
-			clish_param__set_mode(param,
-				CLISH_PARAM_COMMON);
-	}
-
-	if (optional && lub_string_nocasecmp(optional, "true") == 0)
-		clish_param__set_optional(param, BOOL_TRUE);
-	else
-		clish_param__set_optional(param, BOOL_FALSE);
-
-	if (order && lub_string_nocasecmp(order, "true") == 0)
-		clish_param__set_order(param, BOOL_TRUE);
-	else
-		clish_param__set_order(param, BOOL_FALSE);
-
-	if (value) {
-		clish_param__set_value(param, value);
-		/* Force mode to subcommand */
-		clish_param__set_mode(param,
-			CLISH_PARAM_SUBCOMMAND);
-	}
-
-	if (test && !prefix)
-		clish_param__set_test(param, test);
-
-	if (completion)
-		clish_param__set_completion(param, completion);
-
-	if (access)
-		clish_param__set_access(param, access);
-
-	/* Add the parameter to the command */
-	if (cmd)
-		clish_command_insert_param(cmd, param);
-
-	/* Add the parameter to the param */
-	if (p_param)
-		clish_param_insert_param(p_param, param);
-
-	res = process_children(shell, element, param);
-
-error:
-	clish_xml_release(name);
-	clish_xml_release(help);
-	clish_xml_release(ptype);
-	clish_xml_release(prefix);
-	clish_xml_release(defval);
-	clish_xml_release(mode);
-	clish_xml_release(optional);
-	clish_xml_release(order);
-	clish_xml_release(value);
-	clish_xml_release(hidden);
-	clish_xml_release(test);
-	clish_xml_release(completion);
-	clish_xml_release(access);
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-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;
-	clish_sym_t *sym = NULL;
-
-	if (pname && lub_string_nocasecmp(pname, "VAR") == 0)
-		action = clish_var__get_action((clish_var_t *)parent);
-	else if (pname && lub_string_nocasecmp(pname, "PTYPE") == 0)
-		action = clish_ptype__get_action((clish_ptype_t *)parent);
-	else
-		action = clish_command__get_action((clish_command_t *)parent);
-
-	if (pname)
-		free(pname);
-
-	text = clish_xmlnode_get_all_content(element);
-
-	if (text && *text) {
-		/* store the action */
-		clish_action__set_script(action, text);
-	}
-	if (text)
-		free(text);
-
-	if (builtin)
-		sym = clish_shell_add_unresolved_sym(shell, builtin,
-			CLISH_SYM_TYPE_ACTION);
-	else
-		sym = shell->hooks[CLISH_SYM_TYPE_ACTION];
-
-	clish_action__set_builtin(action, sym);
-	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;
-}
-
-/* ------------------------------------------------------ */
-static int process_detail(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_command_t *cmd = (clish_command_t *) parent;
-
-	/* read the following text element */
-	char *text = clish_xmlnode_get_all_content(element);
-
-	if (text && *text) {
-		/* store the action */
-		clish_command__set_detail(cmd, text);
-	}
-
-	if (text)
-		free(text);
-
-	shell = shell; /* Happy compiler */
-
-	return 0;
-}
-
-/* ------------------------------------------------------ */
-static int process_namespace(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_view_t *v = (clish_view_t *)parent;
-	clish_nspace_t *nspace = NULL;
-	int res = -1;
-
-	char *view = clish_xmlnode_fetch_attr(element, "ref");
-	char *prefix = clish_xmlnode_fetch_attr(element, "prefix");
-	char *prefix_help = clish_xmlnode_fetch_attr(element, "prefix_help");
-	char *help = clish_xmlnode_fetch_attr(element, "help");
-	char *completion = clish_xmlnode_fetch_attr(element, "completion");
-	char *context_help = clish_xmlnode_fetch_attr(element, "context_help");
-	char *inherit = clish_xmlnode_fetch_attr(element, "inherit");
-	char *access = clish_xmlnode_fetch_attr(element, "access");
-
-	/* Check syntax */
-	if (!view) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("ref"));
-		goto error;
-	}
-
-	clish_view_t *ref_view = clish_shell_find_view(shell, view);
-
-	/* Don't include itself without prefix */
-	if ((ref_view == v) && !prefix)
-		goto process_namespace_end;
-
-	nspace = clish_nspace_new(view);
-	clish_view_insert_nspace(v, nspace);
-
-	if (prefix) {
-		clish_nspace__set_prefix(nspace, prefix);
-		if (prefix_help)
-			clish_nspace_create_prefix_cmd(nspace,
-				"prefix",
-				prefix_help);
-		else
-			clish_nspace_create_prefix_cmd(nspace,
-				"prefix",
-				"Prefix for the imported commands.");
-	}
-
-	if (help && lub_string_nocasecmp(help, "true") == 0)
-		clish_nspace__set_help(nspace, BOOL_TRUE);
-	else
-		clish_nspace__set_help(nspace, BOOL_FALSE);
-
-	if (completion && lub_string_nocasecmp(completion, "false") == 0)
-		clish_nspace__set_completion(nspace, BOOL_FALSE);
-	else
-		clish_nspace__set_completion(nspace, BOOL_TRUE);
-
-	if (context_help && lub_string_nocasecmp(context_help, "true") == 0)
-		clish_nspace__set_context_help(nspace, BOOL_TRUE);
-	else
-		clish_nspace__set_context_help(nspace, BOOL_FALSE);
-
-	if (inherit && lub_string_nocasecmp(inherit, "false") == 0)
-		clish_nspace__set_inherit(nspace, BOOL_FALSE);
-	else
-		clish_nspace__set_inherit(nspace, BOOL_TRUE);
-
-	if (access)
-		clish_nspace__set_access(nspace, access);
-
-process_namespace_end:
-	res = 0;
-error:
-	clish_xml_release(view);
-	clish_xml_release(prefix);
-	clish_xml_release(prefix_help);
-	clish_xml_release(help);
-	clish_xml_release(completion);
-	clish_xml_release(context_help);
-	clish_xml_release(inherit);
-	clish_xml_release(access);
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_config(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_command_t *cmd = (clish_command_t *)parent;
-	clish_config_t *config;
-
-	if (!cmd)
-		return 0;
-	config = clish_command__get_config(cmd);
-
-	/* read the following text element */
-	char *operation = clish_xmlnode_fetch_attr(element, "operation");
-	char *priority = clish_xmlnode_fetch_attr(element, "priority");
-	char *pattern = clish_xmlnode_fetch_attr(element, "pattern");
-	char *file = clish_xmlnode_fetch_attr(element, "file");
-	char *splitter = clish_xmlnode_fetch_attr(element, "splitter");
-	char *seq = clish_xmlnode_fetch_attr(element, "sequence");
-	char *unique = clish_xmlnode_fetch_attr(element, "unique");
-	char *depth = clish_xmlnode_fetch_attr(element, "depth");
-
-	if (operation && !lub_string_nocasecmp(operation, "unset"))
-		clish_config__set_op(config, CLISH_CONFIG_UNSET);
-	else if (operation && !lub_string_nocasecmp(operation, "none"))
-		clish_config__set_op(config, CLISH_CONFIG_NONE);
-	else if (operation && !lub_string_nocasecmp(operation, "dump"))
-		clish_config__set_op(config, CLISH_CONFIG_DUMP);
-	else {
-		clish_config__set_op(config, CLISH_CONFIG_SET);
-		/* The priority if no clearly specified */
-		clish_config__set_priority(config, 0x7f00);
-	}
-
-	if (priority) {
-		unsigned short pri = 0;
-		lub_conv_atous(priority, &pri, 0);
-		clish_config__set_priority(config, pri);
-	}
-
-	if (pattern)
-		clish_config__set_pattern(config, pattern);
-	else
-		clish_config__set_pattern(config, "^${__cmd}");
-
-	if (file)
-		clish_config__set_file(config, file);
-
-	if (splitter && lub_string_nocasecmp(splitter, "false") == 0)
-		clish_config__set_splitter(config, BOOL_FALSE);
-	else
-		clish_config__set_splitter(config, BOOL_TRUE);
-
-	if (unique && lub_string_nocasecmp(unique, "false") == 0)
-		clish_config__set_unique(config, BOOL_FALSE);
-	else
-		clish_config__set_unique(config, BOOL_TRUE);
-
-	if (seq)
-		clish_config__set_seq(config, seq);
-	else
-		/* The entries without sequence cannot be non-unique */
-		clish_config__set_unique(config, BOOL_TRUE);
-
-	if (depth)
-		clish_config__set_depth(config, depth);
-
-	clish_xml_release(operation);
-	clish_xml_release(priority);
-	clish_xml_release(pattern);
-	clish_xml_release(file);
-	clish_xml_release(splitter);
-	clish_xml_release(seq);
-	clish_xml_release(unique);
-	clish_xml_release(depth);
-
-	shell = shell; /* Happy compiler */
-
-	return 0;
-}
-
-/* ------------------------------------------------------ */
-static int process_var(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_var_t *var = NULL;
-	int res = -1;
-
-	char *name = clish_xmlnode_fetch_attr(element, "name");
-	char *dynamic = clish_xmlnode_fetch_attr(element, "dynamic");
-	char *value = clish_xmlnode_fetch_attr(element, "value");
-
-	/* Check syntax */
-	if (!name) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
-		goto error;
-	}
-	/* Check if this var doesn't already exist */
-	var = (clish_var_t *)lub_bintree_find(&shell->var_tree, name);
-	if (var) {
-		fprintf(stderr, CLISH_XML_ERROR_STR"Duplicate VAR name=\"%s\".\n", name);
-		goto error;
-	}
-
-	/* Create var instance */
-	var = clish_var_new(name);
-	lub_bintree_insert(&shell->var_tree, var);
-
-	if (dynamic && lub_string_nocasecmp(dynamic, "true") == 0)
-		clish_var__set_dynamic(var, BOOL_TRUE);
-
-	if (value)
-		clish_var__set_value(var, value);
-
-	res = process_children(shell, element, var);
-error:
-	clish_xml_release(name);
-	clish_xml_release(dynamic);
-	clish_xml_release(value);
-
-	parent = parent; /* Happy compiler */
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_wdog(clish_shell_t *shell,
-	clish_xmlnode_t *element, void *parent)
-{
-	clish_view_t *v = (clish_view_t *)parent;
-	clish_command_t *cmd = NULL;
-	int res = -1;
-
-	/* Check syntax */
-	if (shell->wdog) {
-		fprintf(stderr, CLISH_XML_ERROR_STR"WATCHDOG tag duplication.\n");
-		goto error;
-	}
-
-	/* Create a command with NULL help */
-	cmd = clish_view_new_command(v, "watchdog", NULL);
-#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;
-
-	res = process_children(shell, element, cmd);
-error:
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_hotkey(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_view_t *v = (clish_view_t *)parent;
-	int res = -1;
-
-	char *key = clish_xmlnode_fetch_attr(element, "key");
-	char *cmd = clish_xmlnode_fetch_attr(element, "cmd");
-
-	/* Check syntax */
-	if (!key) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("key"));
-		goto error;
-	}
-	if (!cmd) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("cmd"));
-		goto error;
-	}
-
-	clish_view_insert_hotkey(v, key, cmd);
-
-	res = 0;
-error:
-	clish_xml_release(key);
-	clish_xml_release(cmd);
-
-	shell = shell; /* Happy compiler */
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_plugin(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	clish_plugin_t *plugin;
-	char *file = clish_xmlnode_fetch_attr(element, "file");
-	char *name = clish_xmlnode_fetch_attr(element, "name");
-	char *alias = clish_xmlnode_fetch_attr(element, "alias");
-	char *rtld_global = clish_xmlnode_fetch_attr(element, "rtld_global");
-	int res = -1;
-	char *text;
-
-	/* Check syntax */
-	if (!name) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
-		goto error;
-	}
-
-	plugin = clish_shell_find_plugin(shell, name);
-	if (plugin) {
-		fprintf(stderr,
-			CLISH_XML_ERROR_STR"PLUGIN %s duplication.\n", name);
-		goto error;
-	}
-	plugin = clish_shell_create_plugin(shell, name);
-
-	if (alias && *alias)
-		clish_plugin__set_alias(plugin, alias);
-
-	if (file && *file)
-		clish_plugin__set_file(plugin, file);
-
-	if (rtld_global && lub_string_nocasecmp(rtld_global, "true") == 0)
-		clish_plugin__set_rtld_global(plugin, BOOL_TRUE);
-
-	/* Get PLUGIN body content */
-	text = clish_xmlnode_get_all_content(element);
-	if (text && *text)
-		clish_plugin__set_conf(plugin, text);
-	if (text)
-		free(text);
-
-	res = 0;
-error:
-	clish_xml_release(file);
-	clish_xml_release(name);
-	clish_xml_release(alias);
-	clish_xml_release(rtld_global);
-
-	parent = parent; /* Happy compiler */
-
-	return res;
-}
-
-/* ------------------------------------------------------ */
-static int process_hook(clish_shell_t *shell, clish_xmlnode_t *element,
-	void *parent)
-{
-	char *name = clish_xmlnode_fetch_attr(element, "name");
-	char *builtin = clish_xmlnode_fetch_attr(element, "builtin");
-	int res = -1;
-	int type = CLISH_SYM_TYPE_NONE;
-
-	/* Check syntax */
-	if (!name) {
-		fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
-		goto error;
-	}
-	/* Find out HOOK type */
-	if (!strcmp(name, "action"))
-		type = CLISH_SYM_TYPE_ACTION;
-	else if (!strcmp(name, "access"))
-		type = CLISH_SYM_TYPE_ACCESS;
-	else if (!strcmp(name, "config"))
-		type = CLISH_SYM_TYPE_CONFIG;
-	else if (!strcmp(name, "log"))
-		type = CLISH_SYM_TYPE_LOG;
-	if (CLISH_SYM_TYPE_NONE == type) {
-		fprintf(stderr, CLISH_XML_ERROR_STR"Unknown HOOK name %s.\n", name);
-		goto error;
-	}
-
-	/* Check duplicate HOOK tag */
-	if (shell->hooks_use[type]) {
-		fprintf(stderr,
-			CLISH_XML_ERROR_STR"HOOK %s duplication.\n", name);
-		goto error;
-	}
-	shell->hooks_use[type] = BOOL_TRUE;
-	clish_sym__set_name(shell->hooks[type], builtin);
-
-	res = 0;
-error:
-	clish_xml_release(name);
-	clish_xml_release(builtin);
-
-	parent = parent; /* Happy compiler */
-
-	return res;
-}
-
-/* ------------------------------------------------------ */

+ 0 - 242
clish/shell/xmlapi.h

@@ -1,242 +0,0 @@
-/*
- * xmlapi.h
- *
- * private klish file: internal XML API
- */
-
-#ifndef clish_xmlapi_included_h
-#define clish_xmlapi_included_h
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <errno.h>
-#include <stdio.h> /* need for FILE */
-
-/* 
- * XML document (opaque type) 
- * The real type is defined by the selected external API
- */
-typedef struct clish_xmldoc_s clish_xmldoc_t;
-
-/* 
- * XML node (opaque type) 
- * The real type is defined by the selected external API
- */
-typedef struct clish_xmlnode_s clish_xmlnode_t;
-
-/*
- * Start and Stop XML parser engine.
- * Some parsers need a global cleanup at the end of the programm.
- */
-int clish_xmldoc_start(void);
-int clish_xmldoc_stop(void);
-
-/*
- * read an XML document
- */
-clish_xmldoc_t *clish_xmldoc_read(const char *filename);
-
-/*
- * release a previously opened XML document
- */
-void clish_xmldoc_release(clish_xmldoc_t *doc);
-
-/*
- * check if a doc is valid (i.e. it loaded successfully)
- */
-int clish_xmldoc_is_valid(clish_xmldoc_t *doc);
-
-/*
- * XML implementation error capabilitiess
- * The real capabilities is or'ed using the following
- * constants
- */
-typedef enum {
-	CLISH_XMLERR_NOCAPS 	= 0,
-	CLISH_XMLERR_LINE 	= 0x10,
-	CLISH_XMLERR_COL 	= 0x20,
-	CLISH_XMLERR_DESC 	= 0x40
-} clish_xmlerrcaps_e;
-
-/*
- * does this specific implementation define any error?
- * -> get the capabilities
- */
-int clish_xmldoc_error_caps(clish_xmldoc_t *doc);
-
-typedef enum {
-	CLISH_XMLNODE_DOC,
-	CLISH_XMLNODE_ELM,
-	CLISH_XMLNODE_TEXT,
-	CLISH_XMLNODE_ATTR,
-	CLISH_XMLNODE_COMMENT,
-	CLISH_XMLNODE_PI,
-	CLISH_XMLNODE_DECL,
-	CLISH_XMLNODE_UNKNOWN,
-} clish_xmlnodetype_e;
-
-/*
- * get error description, when available
- */
-int clish_xmldoc_get_err_line(clish_xmldoc_t *doc);
-int clish_xmldoc_get_err_col(clish_xmldoc_t *doc);
-const char *clish_xmldoc_get_err_msg(clish_xmldoc_t *doc);
-
-/*
- * get the node type
- */
-int clish_xmlnode_get_type(clish_xmlnode_t *node);
-
-/*
- * get the document root
- */
-clish_xmlnode_t *clish_xmldoc_get_root(clish_xmldoc_t *doc);
-
-/*
- * get the next child or NULL. If curchild is NULL, 
- * then the function returns the first child. 
- */
-clish_xmlnode_t *clish_xmlnode_next_child(
-	clish_xmlnode_t *parent, 
-	clish_xmlnode_t *curchild);
-
-/*
- * get the parent node.
- * returns NULL if node is the document root node.
- */
-clish_xmlnode_t *clish_xmlnode_parent(clish_xmlnode_t *node);
-
-/*
- * get the node name.
- * neither name not namelen shall be NULL. *namelen is the length of the
- * name buffer. If it's too small, we return -E2BIG and set *namelen to
- * the minimum length value.
- * returns < 0 on error. On error, name shall not be modified.
- */
-int clish_xmlnode_get_name(
-	clish_xmlnode_t *node,
-	char *name, 
-	unsigned int *namelen);
-
-/*
- * get the node name
- * dynamically allocate the buffer (it must be freed once you don't need it
- * anymore) that will contain all the content of the node.
- * return NULL on error.
- */
-static inline char* clish_xmlnode_get_all_name(clish_xmlnode_t *node)
-{
-	char *name = NULL; 
-	unsigned int nlen = 2048; 
-	int result;
-
-	do { 
-		name = (char*)realloc(name, nlen);
-		result = clish_xmlnode_get_name(node, name, &nlen);
-	} while (result == -E2BIG);
-
-	if (result < 0) {
-		free(name);
-		return NULL;
-	}
-
-	return name;
-}
-
-/*
- * get the node content.
- * neither content not contentlen shall be NULL. *contentlen is the length
- * of the content buffer. If it's too small, we return -E2BIG and set
- * *contentlen to the minimum length value (including space for the \0 
- * character) so that two subsequent calls to this functions are going
- * to succeed if the forst one failed because of a too small buffer.
- * returns < 0 on error. On error, content shall not be modified.
- */
-int clish_xmlnode_get_content(
-	clish_xmlnode_t *node,
-	char *content, 
-	unsigned int *contentlen);
-
-/*
- * get the node content
- * dynamically allocate the buffer (it must be freed once you don't need it
- * anymore) that will contain all the content of the node.
- * return NULL on error.
- */
-static inline char* clish_xmlnode_get_all_content(clish_xmlnode_t *node)
-{
-	char *content = NULL; 
-	unsigned int clen = 2048; 
-	int result;
-
-	do { 
-		content = (char*)realloc(content, clen);
-		result = clish_xmlnode_get_content(node, content, &clen);
-	} while (result == -E2BIG);
-
-	if (result < 0) {
-		free(content);
-		return NULL;
-	}
-
-	return content;
-}
-
-/*
- * get an attribute by name. May return NULL if the
- * attribute is not found
- * Special: allocate memory (to free with clish_xml_release())
- */
-char *clish_xmlnode_fetch_attr(
-	clish_xmlnode_t *node,
-	const char *attrname);
-
-/*
- * Free a pointer allocated by the XML backend
- */
-void clish_xml_release(void *p);
-
-/*
- * print an XML node to the out file
- */
-void clish_xmlnode_print(clish_xmlnode_t *node, FILE *out);
-
-#ifdef HAVE_LIB_LIBXSLT
-
-/*
- * XSLT stylesheet (opaque type)
- * The real type is defined by the selected external API
- */
-typedef struct clish_xslt_s clish_xslt_t;
-
-/*
- * Load an XSLT stylesheet
- */
-clish_xslt_t *clish_xslt_read(const char *filename);
-
-/*
- * Load an embedded XSLT stylesheet from already
- * loaded XML document.
- */
-clish_xslt_t *clish_xslt_read_embedded(clish_xmldoc_t *xmldoc);
-
-/* Apply XSLT stylesheet */
-clish_xmldoc_t *clish_xslt_apply(clish_xmldoc_t *xmldoc, clish_xslt_t *stylesheet);
-
-/*
- * Release a previously opened XSLT stylesheet
- */
-void clish_xslt_release(clish_xslt_t *stylesheet);
-
-/*
- * Check if a stylesheet is valid (i.e. it loaded successfully)
- */
-int clish_xslt_is_valid(clish_xslt_t *stylesheet);
-
-#endif /* HAVE_LIB_LIBXSLT */
-
-#endif /* clish_xmlapi_included_h */
-

+ 0 - 18
clish/types.h

@@ -1,18 +0,0 @@
-/*
- * types.h
- */
-
-#ifndef _clish_types_h
-#define _clish_types_h
-
-#include "lub/c_decl.h"
-#include "lub/argv.h"
-
-struct clish_help_s {
-	lub_argv_t *name;
-	lub_argv_t *help;
-	lub_argv_t *detail;
-};
-typedef struct clish_help_s clish_help_t;
-
-#endif /* _clish_types_h */

+ 0 - 28
clish/udata.h

@@ -1,28 +0,0 @@
-/*
- * udata.h
- */
- /**
-\ingroup clish
-\defgroup clish_udata udata
-@{
-
-\brief This class represents the top level container for CLI user data.
-*/
-#ifndef _clish_udata_h
-#define _clish_udata_h
-
-#include "clish/macros.h"
-
-typedef struct clish_udata_s clish_udata_t;
-
-int clish_udata_compare(const void *first, const void *second);
-clish_udata_t *clish_udata_new(const char *name, void *data);
-void *clish_udata_free(clish_udata_t *instance);
-void clish_udata_delete(void *data);
-
-_CLISH_SET(udata, void *, data);
-_CLISH_GET(udata, void *, data);
-_CLISH_GET_STR(udata, name);
-
-#endif				/* _clish_udata_h */
-/** @} clish_udata */

+ 0 - 3
clish/udata/module.am

@@ -1,3 +0,0 @@
-libclish_la_SOURCES += \
-	clish/udata/udata.c \
-	clish/udata/private.h

+ 0 - 10
clish/udata/private.h

@@ -1,10 +0,0 @@
-/*
- * udata.h - private interface to the userdata class
- */
-
-#include "clish/udata.h"
-
-struct clish_udata_s {
-	char *name;
-	void *data;
-};

+ 0 - 64
clish/udata/udata.c

@@ -1,64 +0,0 @@
-/*
- * udata.c
- */
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "lub/list.h"
-#include "lub/string.h"
-
-#include "private.h"
-
-/*--------------------------------------------------------- */
-int clish_udata_compare(const void *first, const void *second)
-{
-	const clish_udata_t *f = (const clish_udata_t *)first;
-	const clish_udata_t *s = (const clish_udata_t *)second;
-
-	return strcmp(f->name, s->name);
-}
-
-/*--------------------------------------------------------- */
-clish_udata_t *clish_udata_new(const char *name, void *data)
-{
-	clish_udata_t *pdata =
-		(clish_udata_t *)malloc(sizeof(clish_udata_t));
-
-	if (!name) {
-		free(pdata);
-		return NULL;
-	}
-	memset(pdata, 0, sizeof(*pdata));
-	pdata->name = lub_string_dup(name);
-	pdata->data = data;
-
-	return pdata;
-}
-
-/*--------------------------------------------------------- */
-void *clish_udata_free(clish_udata_t *this)
-{
-	void *data;
-
-	if (!this)
-		return NULL;
-	if (this->name)
-		lub_string_free(this->name);
-	data = this->data;
-	free(this);
-
-	return data;
-}
-
-/*--------------------------------------------------------- */
-void clish_udata_delete(void *data)
-{
-	clish_udata_t *this = (clish_udata_t *)data;
-	clish_udata_free(this);
-}
-
-CLISH_SET(udata, void *, data);
-CLISH_GET(udata, void *, data);
-CLISH_GET_STR(udata, name);

+ 0 - 26
clish/var.h

@@ -1,26 +0,0 @@
-#ifndef _clish_var_h
-#define _clish_var_h
-
-#include "lub/types.h"
-#include "lub/bintree.h"
-#include "clish/action.h"
-
-typedef struct clish_var_s clish_var_t;
-
-int clish_var_bt_compare(const void *clientnode, const void *clientkey);
-void clish_var_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
-size_t clish_var_bt_offset(void);
-clish_var_t *clish_var_new(const char *name);
-void clish_var_delete(clish_var_t *instance);
-void clish_var_dump(const clish_var_t *instance);
-
-_CLISH_GET_STR(var, name);
-_CLISH_SET(var, bool_t, dynamic);
-_CLISH_GET(var, bool_t, dynamic);
-_CLISH_SET_STR(var, value);
-_CLISH_GET_STR(var, value);
-_CLISH_SET_STR(var, saved);
-_CLISH_GET_STR(var, saved);
-_CLISH_GET(var, clish_action_t *, action);
-
-#endif /* _clish_var_h */

+ 0 - 4
clish/var/module.am

@@ -1,4 +0,0 @@
-libclish_la_SOURCES += \
-	clish/var/var.c \
-	clish/var/var_dump.c \
-	clish/var/private.h

+ 0 - 17
clish/var/private.h

@@ -1,17 +0,0 @@
-/*
- * var/private.h
- */
-#include "clish/var.h"
-
-/*---------------------------------------------------------
- * PRIVATE TYPES
- *--------------------------------------------------------- */
-
-struct clish_var_s {
-	lub_bintree_node_t bt_node;
-	char *name;
-	bool_t dynamic;
-	char *value;
-	char *saved; /* Saved value of static variable */
-	clish_action_t *action;
-};

+ 0 - 83
clish/var/var.c

@@ -1,83 +0,0 @@
-/*
- * var.c
- *
- * This file provides the implementation of the "var" class
- */
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "lub/string.h"
-#include "private.h"
-
-/*--------------------------------------------------------- */
-static void clish_var_init(clish_var_t *this, const char *name)
-{
-	this->name = lub_string_dup(name);
-	this->dynamic = BOOL_FALSE;
-	this->value = NULL;
-	this->action = clish_action_new();
-	this->saved = NULL;
-
-	/* Be a good binary tree citizen */
-	lub_bintree_node_init(&this->bt_node);
-}
-
-/*--------------------------------------------------------- */
-static void clish_var_fini(clish_var_t *this)
-{
-	lub_string_free(this->name);
-	lub_string_free(this->value);
-	lub_string_free(this->saved);
-	clish_action_delete(this->action);
-}
-
-/*--------------------------------------------------------- */
-int clish_var_bt_compare(const void *clientnode, const void *clientkey)
-{
-	const clish_var_t *this = clientnode;
-	const char *key = clientkey;
-
-	return strcmp(this->name, key);
-}
-
-/*-------------------------------------------------------- */
-void clish_var_bt_getkey(const void *clientnode, lub_bintree_key_t * key)
-{
-	const clish_var_t *this = clientnode;
-
-	/* fill out the opaque key */
-	strcpy((char *)key, this->name);
-}
-
-/*--------------------------------------------------------- */
-size_t clish_var_bt_offset(void)
-{
-	return offsetof(clish_var_t, bt_node);
-}
-
-/*--------------------------------------------------------- */
-clish_var_t *clish_var_new(const char *name)
-{
-	clish_var_t *this = malloc(sizeof(clish_var_t));
-	if (this)
-		clish_var_init(this, name);
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_var_delete(clish_var_t *this)
-{
-	clish_var_fini(this);
-	free(this);
-}
-
-CLISH_GET_STR(var, name);
-CLISH_SET(var, bool_t, dynamic);
-CLISH_GET(var, bool_t, dynamic);
-CLISH_SET_STR(var, value);
-CLISH_GET_STR(var, value);
-CLISH_SET_STR(var, saved);
-CLISH_GET_STR(var, saved);
-CLISH_GET(var, clish_action_t *, action);

+ 0 - 27
clish/var/var_dump.c

@@ -1,27 +0,0 @@
-#ifdef DEBUG
-
-/*
- * var_dump.c
- */
-
-#include "lub/dump.h"
-#include "clish/action.h"
-#include "private.h"
-
-/*--------------------------------------------------------- */
-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", 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();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 66
clish/view.h

@@ -1,66 +0,0 @@
-/*
- * view.h
- */
- /**
-\ingroup clish
-\defgroup clish_view view
-@{
-
-\brief This class is a container of commands.
-
-A particular CLI session may contain a number of different views. Each 
-view may contain its own specific commands as well as those available at
-a global scope.
-
-*/
-#ifndef _clish_view_h
-#define _clish_view_h
-
-typedef struct clish_view_s clish_view_t;
-
-typedef enum {
-	CLISH_RESTORE_NONE,
-	CLISH_RESTORE_DEPTH,
-	CLISH_RESTORE_VIEW
-} clish_view_restore_e;
-
-#include "lub/list.h"
-#include "clish/command.h"
-#include "clish/nspace.h"
-#include "clish/var.h"
-
-clish_view_t *clish_view_new(const char *name);
-int clish_view_compare(const void *clientnode, const void *clientkey);
-void clish_view_delete(void *instance);
-clish_command_t *clish_view_new_command(clish_view_t * instance,
-	const char *name, const char *text);
-clish_command_t *clish_view_find_command(clish_view_t * instance,
-	const char *name, bool_t inherit);
-const clish_command_t *clish_view_find_next_completion(clish_view_t * instance,
-	const char *iter_cmd, const char *line,
-	clish_nspace_visibility_e field, bool_t inherit);
-clish_command_t *clish_view_resolve_command(clish_view_t * instance,
-	const char *line, bool_t inherit);
-clish_command_t *clish_view_resolve_prefix(clish_view_t * instance,
-	const char *line, bool_t inherit);
-void clish_view_dump(clish_view_t * instance);
-void clish_view_insert_nspace(clish_view_t * instance, clish_nspace_t * nspace);
-void clish_view_clean_proxy(clish_view_t * instance);
-int clish_view_insert_hotkey(const clish_view_t *instance, const char *key, const char *cmd);
-const char *clish_view_find_hotkey(const clish_view_t *instance, int code);
-
-_CLISH_GET(view, lub_list_t *, nspaces);
-_CLISH_GET_STR(view, name);
-_CLISH_SET_STR_ONCE(view, prompt);
-_CLISH_GET_STR(view, prompt);
-_CLISH_SET_STR(view, access);
-_CLISH_GET_STR(view, access);
-_CLISH_SET(view, unsigned int, depth);
-_CLISH_GET(view, unsigned int, depth);
-_CLISH_SET(view, clish_view_restore_e, restore);
-_CLISH_GET(view, clish_view_restore_e, restore);
-
-lub_bintree_t * clish_view__get_tree(clish_view_t *instance);
-
-#endif				/* _clish_view_h */
-/** @} clish_view */

+ 0 - 4
clish/view/module.am

@@ -1,4 +0,0 @@
-libclish_la_SOURCES += \
-	clish/view/view.c \
-	clish/view/view_dump.c \
-	clish/view/private.h

+ 0 - 18
clish/view/private.h

@@ -1,18 +0,0 @@
-/*
- * view.h
- */
-#include "clish/view.h"
-#include "lub/bintree.h"
-#include "lub/list.h"
-#include "clish/hotkey.h"
-
-struct clish_view_s {
-	lub_bintree_t tree;
-	char *name;
-	char *prompt;
-	char *access;
-	lub_list_t *nspaces;
-	clish_hotkeyv_t *hotkeys;
-	unsigned int depth;
-	clish_view_restore_e restore;
-};

+ 0 - 324
clish/view/view.c

@@ -1,324 +0,0 @@
-/*
- * view.c
- *
- * This file provides the implementation of a view class
- */
-#include "private.h"
-#include "lub/argv.h"
-#include "lub/string.h"
-#include "lub/ctype.h"
-#include "lub/list.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-/*-------------------------------------------------------- */
-int clish_view_compare(const void *first, const void *second)
-{
-	const clish_view_t *f = (const clish_view_t *)first;
-	const clish_view_t *s = (const clish_view_t *)second;
-	return strcmp(f->name, s->name);
-}
-
-/*-------------------------------------------------------- */
-static void clish_view_init(clish_view_t * this, const char *name)
-{
-	/* set up defaults */
-	this->name = lub_string_dup(name);
-	this->prompt = NULL;
-	this->depth = 0;
-	this->restore = CLISH_RESTORE_NONE;
-	this->access = NULL;
-
-	/* 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);
-
-	/* Initialise the list of namespaces.
-	 * It's important to add new items to the
-	 * tail of list.
-	 */
-	this->nspaces = lub_list_new(NULL, clish_nspace_delete);
-
-	/* Initialize hotkey structures */
-	this->hotkeys = clish_hotkeyv_new();
-}
-
-/*--------------------------------------------------------- */
-static void clish_view_fini(clish_view_t * this)
-{
-	clish_command_t *cmd;
-
-	/* delete each command held by this view */
-	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);
-	}
-
-	/* Free namespaces list */
-	lub_list_free_all(this->nspaces);
-
-	/* Free hotkey structures */
-	clish_hotkeyv_delete(this->hotkeys);
-
-	/* free our memory */
-	lub_string_free(this->name);
-	lub_string_free(this->prompt);
-	lub_string_free(this->access);
-}
-
-/*--------------------------------------------------------- */
-clish_view_t *clish_view_new(const char *name)
-{
-	clish_view_t *this = malloc(sizeof(clish_view_t));
-
-	if (this)
-		clish_view_init(this, name);
-	return this;
-}
-
-/*-------------------------------------------------------- */
-void clish_view_delete(void *data)
-{
-	clish_view_t *this = (clish_view_t *)data;
-	clish_view_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-clish_command_t *clish_view_new_command(clish_view_t * this,
-	const char *name, const char *help)
-{
-	/* allocate the memory for a new parameter definition */
-	clish_command_t *cmd = clish_command_new(name, help);
-	assert(cmd);
-
-	/* if this is a command other than the startup command... */
-	if (NULL != help) {
-		/* ...insert it into the binary tree for this view */
-		if (-1 == lub_bintree_insert(&this->tree, cmd)) {
-			/* inserting a duplicate command is bad */
-			clish_command_delete(cmd);
-			cmd = NULL;
-		}
-	}
-	return cmd;
-}
-
-/*--------------------------------------------------------- */
-/* This method identifies the command (if any) which provides
- * the longest match with the specified line of text.
- *
- * NB this comparison is case insensitive.
- *
- * this - the view instance upon which to operate
- * line - the command line to analyse 
- */
-clish_command_t *clish_view_resolve_prefix(clish_view_t * this,
-	const char *line, bool_t inherit)
-{
-	clish_command_t *result = NULL, *cmd;
-	char *buffer = NULL;
-	lub_argv_t *argv;
-	unsigned i;
-
-	/* create a vector of arguments */
-	argv = lub_argv_new(line, 0);
-
-	for (i = 0; i < lub_argv__get_count(argv); i++) {
-		/* set our buffer to be that of the first "i" arguments  */
-		lub_string_cat(&buffer, lub_argv__get_arg(argv, i));
-
-		/* set the result to the longest match */
-		cmd = clish_view_find_command(this, buffer, inherit);
-
-		/* job done */
-		if (!cmd)
-			break;
-		result = cmd;
-
-		/* ready for the next word */
-		lub_string_cat(&buffer, " ");
-	}
-
-	/* free up our dynamic storage */
-	lub_string_free(buffer);
-	lub_argv_delete(argv);
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-clish_command_t *clish_view_resolve_command(clish_view_t *this,
-	const char *line, bool_t inherit)
-{
-	clish_command_t *result = clish_view_resolve_prefix(this, line, inherit);
-
-	if (result) {
-		clish_action_t *action = clish_command__get_action(result);
-		clish_config_t *config = clish_command__get_config(result);
-		if (!clish_action__get_script(action) &&
-			(!clish_action__get_builtin(action)) &&
-			(CLISH_CONFIG_NONE == clish_config__get_op(config)) &&
-			(!clish_command__get_param_count(result)) &&
-			(!clish_command__get_viewname(result))) {
-			/* if this doesn't do anything we've
-			 * not resolved a command
-			 */
-			result = NULL;
-		}
-	}
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-clish_command_t *clish_view_find_command(clish_view_t * this,
-	const char *name, bool_t inherit)
-{
-	clish_command_t *result = NULL;
-
-	/* Search the current view */
-	result = lub_bintree_find(&this->tree, name);
-
-	if (inherit) {
-		lub_list_node_t *iter;
-		clish_command_t *cmd;
-		clish_nspace_t *nspace;
-
-		/* Iterate elements. It's important to iterate
-		 * items starting from tail bacause the next
-		 * NAMESPACE has higher priority than previous one
-		 * in a case then the both NAMESPACEs have the
-		 * commands with the same name.
-		 */
-		for(iter = lub_list__get_tail(this->nspaces);
-			iter; iter = lub_list_node__get_prev(iter)) {
-			nspace = (clish_nspace_t *)lub_list_node__get_data(iter);
-			cmd = clish_nspace_find_command(nspace, name);
-			/* Choose the longest match */
-			result = clish_command_choose_longest(result, cmd);
-		}
-	}
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-static const clish_command_t *find_next_completion(clish_view_t * this,
-		const char *iter_cmd, const char *line)
-{
-	clish_command_t *cmd;
-	const char *name = "";
-	lub_argv_t *largv;
-	unsigned words;
-
-	/* build an argument vector for the line */
-	largv = lub_argv_new(line, 0);
-	words = lub_argv__get_count(largv);
-
-	/* account for trailing space */
-	if (!*line || lub_ctype_isspace(line[strlen(line) - 1]))
-		words++;
-
-	if (iter_cmd)
-		name = iter_cmd;
-	while ((cmd = lub_bintree_findnext(&this->tree, name))) {
-		name = clish_command__get_name(cmd);
-		if (words == lub_string_wordcount(name)) {
-			/* only bother with commands of which this line is a prefix */
-			/* this is a completion */
-			if (lub_string_nocasestr(name, line) == name)
-				break;
-		}
-	}
-	/* clean up the dynamic memory */
-	lub_argv_delete(largv);
-
-	return cmd;
-}
-
-/*--------------------------------------------------------- */
-const clish_command_t *clish_view_find_next_completion(clish_view_t * this,
-	const char *iter_cmd, const char *line,
-	clish_nspace_visibility_e field, bool_t inherit)
-{
-	const clish_command_t *result, *cmd;
-	clish_nspace_t *nspace;
-	lub_list_node_t *iter;
-
-	/* ask local view for next command */
-	result = find_next_completion(this, iter_cmd, line);
-
-	if (!inherit)
-		return result;
-
-	/* ask the imported namespaces for next command */
-
-	/* Iterate elements */
-	for(iter = lub_list__get_tail(this->nspaces);
-		iter; iter = lub_list_node__get_prev(iter)) {
-		nspace = (clish_nspace_t *)lub_list_node__get_data(iter);
-		if (!clish_nspace__get_visibility(nspace, field))
-			continue;
-		cmd = clish_nspace_find_next_completion(nspace,
-			iter_cmd, line, field);
-		if (clish_command_diff(result, cmd) > 0)
-			result = cmd;
-	}
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-void clish_view_insert_nspace(clish_view_t * this, clish_nspace_t * nspace)
-{
-	lub_list_add(this->nspaces, nspace);
-}
-
-/*--------------------------------------------------------- */
-void clish_view_clean_proxy(clish_view_t * this)
-{
-	lub_list_node_t *iter;
-
-	/* Iterate elements */
-	for(iter = lub_list__get_head(this->nspaces);
-		iter; iter = lub_list_node__get_next(iter)) {
-		clish_nspace_clean_proxy((clish_nspace_t *)lub_list_node__get_data(iter));
-	}
-}
-
-/*--------------------------------------------------------- */
-int clish_view_insert_hotkey(const clish_view_t *this, const char *key, const char *cmd)
-{
-	return clish_hotkeyv_insert(this->hotkeys, key, cmd);
-}
-
-/*--------------------------------------------------------- */
-const char *clish_view_find_hotkey(const clish_view_t *this, int code)
-{
-	return clish_hotkeyv_cmd_by_code(this->hotkeys, code);
-}
-
-CLISH_GET(view, lub_list_t *, nspaces);
-CLISH_GET_STR(view, name);
-CLISH_SET_STR_ONCE(view, prompt);
-CLISH_GET_STR(view, prompt);
-CLISH_SET_STR(view, access);
-CLISH_GET_STR(view, access);
-CLISH_SET(view, unsigned int, depth);
-CLISH_GET(view, unsigned int, depth);
-CLISH_SET(view, clish_view_restore_e, restore);
-CLISH_GET(view, clish_view_restore_e, restore);
-
-/*-------------------------------------------------------- */
-lub_bintree_t * clish_view__get_tree(clish_view_t *inst)
-{
-	assert(inst);
-	return &inst->tree;
-}

+ 0 - 44
clish/view/view_dump.c

@@ -1,44 +0,0 @@
-#ifdef DEBUG
-
-/*
- * view_dump.c
- */
-#include "private.h"
-#include "lub/dump.h"
-#include "lub/list.h"
-
-/*--------------------------------------------------------- */
-void clish_view_dump(clish_view_t * this)
-{
-	clish_command_t *c;
-	lub_list_node_t *iter;
-	lub_bintree_iterator_t iterc;
-	clish_nspace_t *nspace;
-
-	lub_dump_printf("view(%p)\n", this);
-	lub_dump_indent();
-
-	lub_dump_printf("name   : %s\n", clish_view__get_name(this));
-	lub_dump_printf("depth  : %u\n", clish_view__get_depth(this));
-	lub_dump_printf("access : %u\n", clish_view__get_access(this));
-
-	/* Get each namespace to dump their details */
-	for(iter = lub_list__get_head(this->nspaces);
-		iter; iter = lub_list_node__get_next(iter)) {
-		nspace = (clish_nspace_t *)lub_list_node__get_data(iter);
-		clish_nspace_dump(nspace);
-	}
-
-	/* Iterate the tree of commands */
-	c = lub_bintree_findfirst(&this->tree);
-	for (lub_bintree_iterator_init(&iterc, &this->tree, c);
-		c; c = lub_bintree_iterator_next(&iterc)) {
-		clish_command_dump(c);
-	}
-
-	lub_dump_undent();
-}
-
-/*--------------------------------------------------------- */
-
-#endif /* DEBUG */

+ 0 - 43
contrib/README

@@ -1,43 +0,0 @@
---------------------------------------------------------------------------------
- Buildroot
---------------------------------------------------------------------------------
-
-The buildroot/ directory contain the files to embed the klish package into the
-buildroot environment. The buildroot/ files must be copied to the
-buildroot's source tree package/klish directory. Then the package/Config.in
-file must be changed. Add the following string
-
-source "package/klish/Config.in"
-
-to the section started with 'menu "Shell and utilities"' (or to the another
-section if you think it will be better and you know what you do). After that you
-can configure buildroot and enable the building the klish package. You can find
-the menu for the klish within
-"Package Selection for the target"->"Shell and utilities" in the configurator.
-The klish's config allow to use the predefined version of klish or automatically
-download the last revision from the SVN repository.
-
-These files were tested with buildroot-2010.11.
-
---------------------------------------------------------------------------------
- OpenWRT
---------------------------------------------------------------------------------
-
-The openwrt/ directory contain the files to embed the klish package into the
-OpenWRT environment.
-
-The OpenWRT's Makefile was created by Emmanuel Deloget.
-
---------------------------------------------------------------------------------
- Debian
---------------------------------------------------------------------------------
-
-The contrib/debian dir contain konfd initscript for Debian system and some clish
-default XML config files. The klish source tree contain debian/ dir with all
-necessary information to build klish and klish-dev DEV packages. To build these
-packages the following packages must be installed:
-  * devscripts
-  * debhelper
-
-To build it type something like following command within klish source tree:
-$ debuild -uc -us

+ 0 - 16
contrib/buildroot-2010.11/Config.in

@@ -1,16 +0,0 @@
-config BR2_PACKAGE_KLISH
-	bool "klish"
-	help
-	  The klish is a framework for implementing a CISCO-like CLI on a UNIX systems.
-	  It is configurable by XML files. The klish is the fork of clish project.
-
-	  http://klish.googlecode.com
-
-if BR2_PACKAGE_KLISH
-
-config BR2_PACKAGE_KLISH_SVN
-	bool "Get klish sources from the SVN repository"
-	help
-	  Use source code from SVN repository instead klish stable version.
-
-endif

+ 0 - 21
contrib/buildroot-2010.11/klish.mk

@@ -1,21 +0,0 @@
-#############################################################
-#
-# klish
-#
-#############################################################
-
-ifeq ($(BR2_PACKAGE_KLISH_SVN),y)
-KLISH_VERSION:=HEAD
-KLISH_SITE:=http://klish.googlecode.com/svn/trunk
-KLISH_SITE_METHOD:=svn
-else
-KLISH_VERSION = 1.6.0
-KLISH_SOURCE = klish-$(KLISH_VERSION).tar.bz2
-KLISH_SITE = http://klish.googlecode.com/files
-endif
-
-KLISH_INSTALL_STAGING = YES
-KLISH_INSTALL_TARGET = YES
-KLISH_CONF_OPT = --disable-gpl --without-tcl
-
-$(eval $(call AUTOTARGETS,package,klish))

+ 0 - 8
contrib/buildroot-2014.08/Config.in

@@ -1,8 +0,0 @@
-menuconfig BR2_PACKAGE_KLISH
-	bool "klish"
-	depends on BR2_PACKAGE_LIBROXML || BR2_PACKAGE_LIBXML2 || BR2_PACKAGE_EXPAT
-	help
-	  The klish is a framework for implementing a CISCO-like CLI on a UNIX systems.
-	  It is configurable by XML files.
-
-	  http://klish.libcode.org

+ 0 - 29
contrib/buildroot-2014.08/klish.mk

@@ -1,29 +0,0 @@
-#############################################################
-#
-# klish
-#
-#############################################################
-
-KLISH_VERSION = 1.6.9
-KLISH_SOURCE = klish-$(KLISH_VERSION).tar.bz2
-KLISH_SITE = http://libcode.org/attachments/download/45
-
-KLISH_DEPENDENCIES =
-KLISH_CONF_OPT = --disable-gpl --without-tcl
-
-ifeq ($(BR2_PACKAGE_LIBROXML),y)
-KLISH_DEPENDENCIES += libroxml
-KLISH_CONF_OPT += --with-libroxml
-endif
-
-ifeq ($(BR2_PACKAGE_LIBXML2),y)
-KLISH_DEPENDENCIES += libxml2
-KLISH_CONF_OPT += --with-libxml2
-endif
-
-ifeq ($(BR2_PACKAGE_EXPAT),y)
-KLISH_DEPENDENCIES += expat
-KLISH_CONF_OPT += --with-libexpat
-endif
-
-$(eval $(autotools-package))

Some files were not shown because too many files changed in this diff