cli_infos_t * cli_infos_init (gint argc, gchar **argv) { cli_infos_t *infos; alias_define_t *aliaslist; gchar *filename; gint i; infos = g_new0 (cli_infos_t, 1); /* readline_init needs PROMPT */ filename = configuration_get_filename (); infos->config = configuration_init (filename); g_free (filename); readline_init (infos); if (argc == 0) { infos->mode = CLI_EXECUTION_MODE_SHELL; /* print welcome message before initialising readline */ if (configuration_get_boolean (infos->config, "SHELL_START_MESSAGE")) { g_printf (_("Welcome to the XMMS2 CLI shell!\n")); g_printf (_("Type 'help' to list the available commands " "and 'exit' (or CTRL-D) to leave the shell.\n")); } readline_resume (infos); } else { infos->mode = CLI_EXECUTION_MODE_INLINE; } infos->status = CLI_ACTION_STATUS_READY; infos->commands = command_trie_alloc (); /* Register commands and command names */ for (i = 0; commandlist[i]; ++i) { command_action_t *action = command_action_alloc (); commandlist[i] (action); if (!register_command (infos->commands, &infos->cmdnames, action)) { command_action_free (action); } } /* Register aliases with a default callback */ aliaslist = alias_list (configuration_get_aliases (infos->config)); for (i = 0; aliaslist[i].name; ++i) { command_action_t *action = command_action_alloc (); alias_setup (action, &aliaslist[i]); if (!register_command (infos->commands, &infos->aliasnames, action)) { command_action_free (action); } } alias_list_free (aliaslist); infos->alias_count = 0; infos->aliasnames = cmdnames_reverse (infos->aliasnames); infos->cmdnames = cmdnames_reverse (infos->cmdnames); infos->cache = cli_cache_init (); return infos; }
command_trie_t* command_trie_new (gchar c) { command_trie_t* trie = command_trie_alloc (); trie->c = c; trie->match.type = COMMAND_TRIE_MATCH_NONE; return trie; }
cli_infos_t * cli_infos_init (gint argc, gchar **argv) { cli_infos_t *infos; alias_define_t *aliaslist; gint i; infos = g_new0 (cli_infos_t, 1); /* readline_init needs PROMPT */ infos->config = configuration_init (NULL); if (argc == 0) { infos->mode = CLI_EXECUTION_MODE_SHELL; readline_init (infos); } else { infos->mode = CLI_EXECUTION_MODE_INLINE; } infos->status = CLI_ACTION_STATUS_READY; infos->commands = command_trie_alloc (); /* Register commands and command names */ for (i = 0; commandlist[i]; ++i) { command_action_t *action = command_action_alloc (); commandlist[i] (action); if (!register_command (infos->commands, &infos->cmdnames, action)) { command_action_free (action); } } /* Register aliases with a default callback */ aliaslist = alias_list (configuration_get_aliases (infos->config)); for (i = 0; aliaslist[i].name; ++i) { command_action_t *action = command_action_alloc (); alias_setup (action, &aliaslist[i]); if (!register_command (infos->commands, &infos->aliasnames, action)) { command_action_free (action); } } alias_list_free (aliaslist); infos->alias_count = 0; infos->aliasnames = cmdnames_reverse (infos->aliasnames); infos->cmdnames = cmdnames_reverse (infos->cmdnames); infos->cache = cli_cache_init (); return infos; }
static command_trie_t* command_trie_subtrie_insert (command_trie_t* node, gchar c, gchar *prefix) { if (node->match.type == COMMAND_TRIE_MATCH_ACTION) { /* Cannot overwrite an existing action, error! */ return NULL; } else if (node->match.type == COMMAND_TRIE_MATCH_NONE) { node->match.type = COMMAND_TRIE_MATCH_SUBTRIE; node->match.subtrie = command_trie_alloc (); node->match.action = command_action_alloc (); command_action_fill (node->match.action, prefix, NULL, COMMAND_REQ_NONE, NULL, NULL, NULL); } return command_trie_elem_insert (node->match.subtrie, c); }
cli_context_t * cli_context_init (void) { cli_context_t *ctx; alias_define_t *aliaslist; gchar *filename; gint i; ctx = g_new0 (cli_context_t, 1); /* readline_init needs PROMPT */ filename = configuration_get_filename (); ctx->config = configuration_init (filename); g_free (filename); readline_init (ctx); ctx->status = CLI_ACTION_STATUS_READY; ctx->commands = command_trie_alloc (); /* Register commands and command names */ for (i = 0; commandlist[i]; ++i) { command_action_t *action = command_action_alloc (); commandlist[i] (action); if (!register_command (ctx->commands, &ctx->cmdnames, action)) { command_action_free (action); } } /* Register aliases with a default callback */ aliaslist = alias_list (configuration_get_aliases (ctx->config)); for (i = 0; aliaslist[i].name; ++i) { command_action_t *action = command_action_alloc (); alias_setup (action, &aliaslist[i]); if (!register_command (ctx->commands, &ctx->aliasnames, action)) { command_action_free (action); } } alias_list_free (aliaslist); ctx->alias_count = 0; ctx->aliasnames = cmdnames_reverse (ctx->aliasnames); ctx->cmdnames = cmdnames_reverse (ctx->cmdnames); ctx->cache = cli_cache_init (); return ctx; }