void cli_context_loop (cli_context_t *ctx, gint argc, gchar **argv) { /* Execute command, if connection status is ok */ if (argc == 0) { gchar *filename = configuration_get_string (ctx->config, "HISTORY_FILE"); ctx->mode = CLI_EXECUTION_MODE_SHELL; /* print welcome message before initialising readline */ if (configuration_get_boolean (ctx->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 (ctx); read_history (filename); using_history (); while (!cli_context_in_status (ctx, CLI_ACTION_STATUS_FINISH)) { cli_context_event_loop_select (ctx); } write_history (filename); } else { ctx->mode = CLI_EXECUTION_MODE_INLINE; cli_context_command_or_flag_dispatch (ctx, argc , argv); while (cli_context_in_status (ctx, CLI_ACTION_STATUS_BUSY) || cli_context_in_status (ctx, CLI_ACTION_STATUS_REFRESH)) { cli_context_event_loop_select (ctx); } } }
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; }
void cli_context_loop_resume (cli_context_t *ctx) { if (ctx->status != CLI_ACTION_STATUS_BUSY) { return; } if (ctx->mode == CLI_EXECUTION_MODE_SHELL) { readline_resume (ctx); } ctx->status = CLI_ACTION_STATUS_READY; }
void cli_infos_loop_resume (cli_infos_t *infos) { if (infos->status != CLI_ACTION_STATUS_BUSY) { return; } if (infos->mode == CLI_EXECUTION_MODE_SHELL) { readline_resume (infos); } infos->status = CLI_ACTION_STATUS_READY; }