static void			extend_tokens(t_alias_processor *p, char **accumulator)
{
	t_lst			*tokenized_tokens;
	t_tokenizer		*tokenizer;

	if (twl_lst_len(p->tokens))
	{
		*accumulator = twl_strjoinfree(*accumulator, "  ", 'l');
		*accumulator = twl_strjoinfree(*accumulator,
				token_mgr_first(p->tokens)->text, 'l');
		twl_lst_pop_front(p->tokens);
	}
	tokenizer = tokenizer_new(*accumulator);
	tokenizer->cur_line = p->line;
	tokenized_tokens = tokenizer_tokenize(tokenizer);
	token_mgr_mark_is_alias_expan(tokenized_tokens, p->processed);
	token_mgr_mark_is_alias_expan(tokenized_tokens, p->prev_processed);
	twl_lst_extend_front(p->tokens, tokenized_tokens);
	if (p->ast)
	{
		twl_lst_extend(p->ast->tokens_ref_tracker, tokenized_tokens);
	}
	tokenizer_del(tokenizer);
	twl_lst_del(tokenized_tokens, NULL);
}
示例#2
0
文件: plugins.c 项目: niximor/prebot
/**
 * Unloads plugin
 * @param plugin Plugin that should be unloaded.
 */
void plugins_unloadplugin(Plugin plugin) {
	if (plugin->beforeDepsUnload != NULL) {
		plugin->beforeDepsUnload(plugin->info);
	}

	// Unload all plugin's dependencies.
	if (plugin->deps != NULL) {
		TOKENS tok = tokenizer_tokenize(plugin->deps, ',');

		for (size_t i = 0; i < tok->count; i++) {
			if (plugins_isloaded(tokenizer_gettok(tok, i))) {
				plugins_unload(tokenizer_gettok(tok, i));
			}
		}

		tokenizer_free(tok);
	}

	if (plugin->done != NULL) {
		plugin->done(plugin->info);
	}

	// Free plugin handle.
	if (dlclose(plugin->handle) != 0) {
		printError("plugins", "Unable to unload library: %s", dlerror());
	}

	free(plugin->info);
	free(plugin->name);
	free(plugin->path);

	// Remove plugin from chain
	if (plugin->prev != NULL) {
		plugin->prev->next = plugin->next;
	} else {
		loadedPlugins->first = plugin->next;
	}

	if (plugin->next != NULL) {
		plugin->next->prev = plugin->prev;
	} else {
		loadedPlugins->last = plugin->prev;
	}

	free(plugin);
} // plugins_unloadplugin
示例#3
0
t_ast				*ast_new_from_string(char *input, int ast_flags, int line)
{
	t_ast			*ast;
	t_lst			*tokens;
	t_tokenizer		*tokenizer;

	print_if_verbose(input, ast_flags);
	tokenizer = tokenizer_new(input);
	tokenizer->cur_line = line;
	tokens = tokenizer_tokenize(tokenizer);
	ast = ast_new(tokens, ast_flags);
	twl_lst_iter(tokenizer->tok_open_stack,
		push_to_ast_open_stack, ast->ast_open_stack);
	tokenizer_del(tokenizer);
	token_mgr_del(tokens);
	return (ast);
}
示例#4
0
int main ( int argc, char * argv[] )
{
    static char* testinp = "First sentence. Second nice sentence. Is this all? No, this is the end!";
    char* output;
    int outlen;
	t_tokenizer mytokenizer;
	int i;

	printf("Input='%s'\n", testinp);

	printf("Initializing... ");	
	i = tokenizer_init(&mytokenizer);
	printf("Done(%d)\n", i);
	
	tokenizer_tokenize(mytokenizer, testinp, &output, &outlen);
	printf("Output(%d)='%s'\n", outlen, output);
	
	free(output);
	tokenizer_destroy(mytokenizer);

	return 0;
}
示例#5
0
文件: plugins.c 项目: niximor/prebot
/**
 * Load plugin in exactly given filename. It checks plugin's dependencies,
 * and tries to load them too.
 * @param path Path to plugin
 * @return Plugin load status
 */
PluginLoadStatus plugins_loadplugin(char *path) {
	PluginLoadStatus result = PLUG_OK;

	char *pathdup = path;

	if (file_exists(pathdup)) {
		char *basename = dirs_basename(pathdup);

		if (plugins_isloaded(basename)) {
			free(basename);
			printError("plugins", "Plugin %s is already loaded.", pathdup);
			return PLUG_ALREADY_LOADED;
		}

		printError("plugins", "Loading plugin %s", pathdup);

		Plugin plugin = malloc(sizeof(struct sPlugin));

		// Add plugin to linked list, for circular dependency check
		plugin->prev = loadedPlugins->last;
		plugin->next = NULL;
		if (loadedPlugins->last != NULL) {
			loadedPlugins->last->next = plugin;
		} else {
			loadedPlugins->first = plugin;
		}
		loadedPlugins->last = plugin;

		plugin->handle = dlopen(pathdup, RTLD_LAZY | RTLD_GLOBAL);
		if (plugin->handle != NULL) {
			plugin->name = basename;
			plugin->path = strdup(path);

			plugin->info = malloc(sizeof(PluginInfo));
			plugin->info->name = NULL;
			plugin->info->author = NULL;
			plugin->info->version = NULL;
			plugin->info->customData = NULL;
			plugin->info->irc = loadedPlugins->irc;
			plugin->info->config = loadedPlugins->config;
			plugin->info->events = loadedPlugins->events;
			plugin->info->socketpool = loadedPlugins->socketpool;

			plugin->deps = NULL;

			plugin->init = (PluginInitPrototype *)dlsym(
				plugin->handle, "PluginInit");
			plugin->done = (PluginDonePrototype *)dlsym(
				plugin->handle, "PluginDone");
			plugin->beforeDepsUnload = (PluginDonePrototype *)dlsym(
				plugin->handle, "PluginBeforeUnload");

			if (plugin->init != NULL && plugin->done != NULL) {
				// Scan plugin dependencies.

				PluginLoadStatus depsLoad = PLUG_OK;

				// PluginDeps function is optional.
				PluginDepsPrototype *plugindeps =
					(PluginDepsPrototype *)dlsym(plugin->handle, "PluginDeps");
				if (plugindeps != NULL) {
					plugindeps(&plugin->deps);

					if (plugin->deps != NULL) {
						TOKENS tok = tokenizer_tokenize(plugin->deps, ',');
						for (size_t i = 0; i < tok->count; i++) {
							if (!plugins_isloaded(tokenizer_gettok(tok, i))) {
								depsLoad = plugins_load(
									tokenizer_gettok(tok, i));
								if (depsLoad != PLUG_OK) {
									break;
								}
							}
						}
						tokenizer_free(tok);
					}
				}

				if (depsLoad == PLUG_OK) {
					// And finally, when everything is OK, call init function.
					plugin->init(plugin->info);
					result = PLUG_OK;
				} else {
					printError("plugins", "Plugin %s will not be loaded, "
						"because of dependency error.", path);
					result = PLUG_DEPENDENCY;
				}
			} else {
				// If no init and done functions were found.
				plugins_unloadplugin(plugin);
				printError("plugins", "%s is not valid plugin.", pathdup);
				result = PLUG_INVALID;
			}

			// Unload plugin if it's loading failed.
			if (result != PLUG_OK) {
				plugin->done = NULL;
				plugins_unloadplugin(plugin);
			}
		// End of plug->handle != NULL
		} else {
			// Remove plugin from linked list
			loadedPlugins->last = loadedPlugins->last->prev;
			loadedPlugins->last->next = NULL;

			printError("plugins", "Plugin loading error: %s", dlerror());
			result = PLUG_DL_ERROR;
		}
	} else {
		printError("plugins", "Plugin file not found.");
		result = PLUG_FILE_NOT_FOUND;
	}

	return result;
} // plugins_loadplugin