From ba445fe37eba5fe0138904b41987d45ab0ae41a2 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 25 Nov 2001 16:17:44 +0000 Subject: [PATCH] /SCRIPT LOAD modifies the script name so that all non-alphanumeric characters are translated to '_' char .. now this behaviour is done also when /SCRIPT UNLOAD is done, so people don't get confused why their "test-1" script can't be unloaded. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2145 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/perl/perl-core.c | 17 ++++++++++++----- src/perl/perl-core.h | 3 +++ src/perl/perl-fe.c | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/perl/perl-core.c b/src/perl/perl-core.c index 8c3aec7e..aa774cc6 100644 --- a/src/perl/perl-core.c +++ b/src/perl/perl-core.c @@ -165,11 +165,11 @@ void perl_scripts_deinit(void) my_perl = NULL; } -static char *script_file_get_name(const char *path) +/* Modify the script name so that all non-alphanumeric characters are + translated to '_' */ +void script_fix_name(char *name) { - char *name, *ret, *p; - - ret = name = g_strdup(g_basename(path)); + char *ret, *p; p = strrchr(name, '.'); if (p != NULL) *p = '\0'; @@ -179,8 +179,15 @@ static char *script_file_get_name(const char *path) *name = '_'; name++; } +} - return ret; +static char *script_file_get_name(const char *path) +{ + char *name; + + name = g_strdup(g_basename(path)); + script_fix_name(name); + return name; } static char *script_data_get_name(void) diff --git a/src/perl/perl-core.h b/src/perl/perl-core.h index a883ead0..b451cc5c 100644 --- a/src/perl/perl-core.h +++ b/src/perl/perl-core.h @@ -31,6 +31,9 @@ PERL_SCRIPT_REC *perl_script_find_package(const char *package); /* Returns full path for the script */ char *perl_script_get_path(const char *name); +/* Modify the script name so that all non-alphanumeric characters are + translated to '_' */ +void script_fix_name(char *name); /* If core should handle printing script errors */ void perl_core_print_script_error(int print); diff --git a/src/perl/perl-fe.c b/src/perl/perl-fe.c index 17b57ee1..19889adf 100644 --- a/src/perl/perl-fe.c +++ b/src/perl/perl-fe.c @@ -104,10 +104,11 @@ static void cmd_script_unload(const char *data) 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, data); + TXT_SCRIPT_NOT_LOADED, name); } else { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SCRIPT_UNLOADED, script->name);