示例#1
0
文件: cli_infos.c 项目: chrippa/xmms2
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;
}
示例#2
0
static void
initialize_main_loop (void)
{
    GtpEngineList site_configuration_engines;

#if THREADS_SUPPORTED
    thread_events_queue = g_async_queue_new ();

    thread_events = g_source_new (&thread_events_functions, sizeof (GSource));
    g_source_set_callback (thread_events, thread_event_callback, NULL, NULL);
    g_source_attach (thread_events, NULL);
#endif

    quarry_stock_init ();

    user_real_name = g_get_real_name ();
    configuration_init (gtk_configuration_sections,
                        NUM_GTK_CONFIGURATION_SECTIONS);

    /* Try to read site configuration file.  Later,
     * configuration_write_to_file() will effectively copy all
     * site-default settings to user's configuration, with any changes
     * she has made.
     *
     * Site configuration file is meant for distributions, to
     * e.g. automatically register GNU Go with Quarry.
     */
    configuration_read_from_file (gtk_configuration_sections,
                                  NUM_GTK_CONFIGURATION_SECTIONS,
                                  PACKAGE_DATA_DIR "/quarry.cfg");

    gtp_engine_list_init (&site_configuration_engines);
    string_list_steal_items (&site_configuration_engines, &gtp_engines);

    configuration_file = g_build_path (G_DIR_SEPARATOR_S,
                                       g_get_home_dir (), ".quarry", NULL);
    configuration_read_from_file (gtk_configuration_sections,
                                  NUM_GTK_CONFIGURATION_SECTIONS,
                                  configuration_file);

    configuration_combine_string_lists (&gtp_engines,
                                        &site_configuration_engines,
                                        (G_STRUCT_OFFSET
                                         (GtpEngineListItem,
                                          site_configuration_name)));

    gtk_preferences_init ();

#if GTK_2_2_OR_LATER
    gtk_window_set_default_icon_from_file (DATA_DIR "/pixmaps/quarry.png", NULL);
#endif
}
示例#3
0
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;
}
示例#4
0
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;
}
示例#5
0
文件: ngp.c 项目: hippiehunter/ngp
static const char * get_config(const char *editor, extension_list_t **curext,
		specific_files_t **curspec)
{
	char *ptr;
	char *buf;
	config_t cfg;
	const char *specific_files;
	const char *extensions;
	specific_files_t	*tmpspec;
	extension_list_t	*tmpext;

	/* grab conf */
	configuration_init(&cfg);
	if (!config_lookup_string(&cfg, "editor", &editor)) {
		fprintf(stderr, "ngprc: no editor string found!\n");
		exit(-1);
	}

	if (!config_lookup_string(&cfg, "files", &specific_files)) {
		fprintf(stderr, "ngprc: no files string found!\n");
		exit(-1);
	}

	/* get specific files names from configuration */
	ptr = strtok_r((char *) specific_files, " ", &buf);
	while (ptr != NULL) {
		tmpspec = malloc(sizeof(specific_files_t));
		if (!mainsearch_attr.firstspec) {
			mainsearch_attr.firstspec = tmpspec;
		} else {
			(*curspec)->next = tmpspec;
		}

		strncpy(tmpspec->spec, ptr, LINE_MAX);
		tmpspec->next = NULL;
		*curspec = tmpspec;
		ptr = strtok_r(NULL, " ", &buf);
	}

	/* get files extensions from configuration */
	if (!config_lookup_string(&cfg, "extensions", &extensions)) {
		fprintf(stderr, "ngprc: no extensions string found!\n");
		exit(-1);
	}

	ptr = strtok_r((char *) extensions, " ", &buf);
	while (ptr != NULL) {
		tmpext = malloc(sizeof(extension_list_t));
		if (!mainsearch_attr.firstext) {
			mainsearch_attr.firstext = tmpext;
		} else {
			(*curext)->next = tmpext;
		}

		strncpy(tmpext->ext, ptr, LINE_MAX);
		tmpext->next = NULL;
		*curext = tmpext;
		ptr = strtok_r(NULL, " ", &buf);
	}

	return editor;
}