static char *script_data_get_name(void) { GString *name; char *ret; int n; name = g_string_new(NULL); n = 1; do { g_string_printf(name, "data%d", n); n++; } while (perl_script_find(name->str) != NULL); ret = name->str; g_string_free(name, FALSE); return ret; }
/* NOTE: name must not be free'd */ static PERL_SCRIPT_REC *script_load(char *name, const char *path, const char *data) { PERL_SCRIPT_REC *script; /* if there's a script with a same name, destroy it */ script = perl_script_find(name); if (script != NULL) perl_script_unload(script); script = g_new0(PERL_SCRIPT_REC, 1); script->name = name; script->package = g_strdup_printf("Irssi::Script::%s", name); script->path = g_strdup(path); script->data = g_strdup(data); perl_scripts = g_slist_append(perl_scripts, script); signal_emit("script created", 1, script); if (!perl_script_eval(script)) script = NULL; /* the script is destroyed in "script error" signal */ return script; }
static void cmd_script_unload(const char *data) { PERL_SCRIPT_REC *script; char *name; void *free_arg; if (!cmd_get_params(data, &free_arg, 1, &name)) return; if (*name == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); script_fix_name(name); script = perl_script_find(name); if (script == NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SCRIPT_NOT_LOADED, name); } else { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SCRIPT_UNLOADED, script->name); perl_script_unload(script); } cmd_params_free(free_arg); }