1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 09:13:14 +02:00

Perl scripts auto-load, if no path given, look in ~/.weechat/perl when loading Perl script, auto create plugin directories at startup (~/.weechat/perl, /perl/autoload, /python, /python/autoload, /ruby, /ruby/autoload)

This commit is contained in:
uid67137
2003-12-26 12:59:31 +00:00
parent 57e00428ca
commit 3ea696bbc0
18 changed files with 750 additions and 472 deletions
+14 -1
View File
@@ -993,6 +993,7 @@ weechat_cmd_perl (int argc, char **argv)
t_plugin_script *ptr_plugin_script;
t_plugin_handler *ptr_plugin_handler;
int handler_found;
char *path_script;
#ifdef PLUGIN_PERL
switch (argc)
@@ -1078,7 +1079,19 @@ weechat_cmd_perl (int argc, char **argv)
if (strcmp (argv[0], "load") == 0)
{
/* load Perl script */
plugin_load (PLUGIN_TYPE_PERL, argv[1]);
if (strstr(argv[1], DIR_SEPARATOR))
path_script = NULL;
else
{
path_script = (char *) malloc ((strlen (weechat_home) +
strlen (argv[1]) + 7) * sizeof (char));
sprintf (path_script, "%s%s%s%s%s", weechat_home,
DIR_SEPARATOR, "perl", DIR_SEPARATOR, argv[1]);
}
plugin_load (PLUGIN_TYPE_PERL,
(path_script) ? path_script : argv[1]);
if (path_script)
free (path_script);
}
else
{
+71 -19
View File
@@ -62,7 +62,7 @@
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
char *weechat_home; /* WeeChat home dir. (example: /home/toto/.weechat) */
FILE *log_file; /* WeeChat log file (~/.weechat/weechat.log */
FILE *log_file; /* WeeChat log file (~/.weechat/weechat.log) */
/*
@@ -73,6 +73,7 @@ FILE *log_file; /* WeeChat log file (~/.weechat/weechat.log */
void
my_sigint ()
{
/* do nothing */
}
/*
@@ -142,31 +143,82 @@ wee_parse_args (int argc, char *argv[])
}
/*
* wee_create_home_dir: create weechat home directory (if not found)
* wee_create_dir: create a directory
* return: 1 if ok (or directory already exists)
* 0 if error
*/
void
wee_create_home_dir ()
int
wee_create_dir (char *directory)
{
int return_code;
/* TODO: rewrite this code for Windows version */
weechat_home =
(char *) malloc ((strlen (getenv ("HOME")) + 10) * sizeof (char));
sprintf (weechat_home, "%s/.weechat", getenv ("HOME"));
/* try to create home directory */
return_code = mkdir (weechat_home, 0755);
if (return_code < 0)
if (mkdir (directory, 0755) < 0)
{
/* exit if error (except if directory already exists) */
if (errno != EEXIST)
{
fprintf (stderr, _("%s cannot create directory \"%s\"\n"),
WEECHAT_ERROR, weechat_home);
exit (1);
WEECHAT_ERROR, directory);
return 0;
}
}
return 1;
}
/*
* wee_create_home_dirs: create (if not found):
* - WeeChat home directory ("~/.weechat")
* - "perl" directory (and "autoload")
* - "ruby" directory (and "autoload")
* - "python" directory (and "autoload")
*/
void
wee_create_home_dirs ()
{
char *dir_name;
/* TODO: rewrite this code for Windows version */
weechat_home =
(char *) malloc ((strlen (getenv ("HOME")) + 10) * sizeof (char));
sprintf (weechat_home, "%s%s.weechat", getenv ("HOME"), DIR_SEPARATOR);
/* create home directory "~/.weechat" ; error is fatal */
if (!wee_create_dir (weechat_home))
exit (1);
dir_name = (char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
/* create "~/.weechat/perl" */
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "perl");
if (wee_create_dir (dir_name))
{
/* create "~/.weechat/perl/autoload" */
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "perl",
DIR_SEPARATOR, "autoload");
wee_create_dir (dir_name);
}
/* create "~/.weechat/python" */
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "python");
if (wee_create_dir (dir_name))
{
/* create "~/.weechat/python/autoload" */
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "python",
DIR_SEPARATOR, "autoload");
wee_create_dir (dir_name);
}
/* create "~/.weechat/ruby" */
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "ruby");
if (wee_create_dir (dir_name))
{
/* create "~/.weechat/ruby/autoload" */
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "ruby",
DIR_SEPARATOR, "autoload");
wee_create_dir (dir_name);
}
free (dir_name);
}
/*
@@ -200,8 +252,8 @@ wee_init_log ()
{
free (filename);
fprintf (stderr,
_("%s unable to create/append to log file (~/.weechat/"
WEECHAT_LOG_NAME), WEECHAT_ERROR);
_("%s unable to create/append to log file (~/.weechat/%s)"),
WEECHAT_ERROR, WEECHAT_LOG_NAME);
}
free (filename);
}
@@ -277,7 +329,7 @@ main (int argc, char *argv[])
gui_pre_init (&argc, &argv); /* pre-initiliaze interface */
wee_init_vars (); /* initialize some variables */
wee_parse_args (argc, argv); /* parse command line args */
wee_create_home_dir (); /* create weechat home directory */
wee_create_home_dirs (); /* create WeeChat directories */
wee_init_log (); /* init log file */
index_command_build (); /* build commands index for completion */
+9
View File
@@ -86,6 +86,15 @@
" -l, --license display WeeChat license\n" \
" -v, --version display WeeChat version\n\n"
/* directory separator, depending on OS */
#ifdef _WIN32
#define DIR_SEPARATOR "\\"
#else
#define DIR_SEPARATOR "/"
#endif
/* global variables and functions */
extern int quit_weechat;
extern char *weechat_home;
+3 -3
View File
@@ -722,7 +722,7 @@ config_read ()
filename =
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
sprintf (filename, "%s/" WEECHAT_CONFIG_NAME, weechat_home);
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
if ((file = fopen (filename, "rt")) == NULL)
{
gui_printf (NULL, _("%s config file \"%s\" not found.\n"),
@@ -938,7 +938,7 @@ config_create_default ()
filename =
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
sprintf (filename, "%s/" WEECHAT_CONFIG_NAME, weechat_home);
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
if ((file = fopen (filename, "wt")) == NULL)
{
gui_printf (NULL, _("%s cannot create file \"%s\"\n"),
@@ -1070,7 +1070,7 @@ config_write (char *config_name)
{
filename =
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
sprintf (filename, "%s/" WEECHAT_CONFIG_NAME, weechat_home);
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
}
if ((file = fopen (filename, "wt")) == NULL)