--- a/mcabber/doc/help/en/hlp_source.txt Mon Jan 18 17:49:30 2010 +0200
+++ b/mcabber/doc/help/en/hlp_source.txt Mon Jan 18 16:36:55 2010 +0200
@@ -1,4 +1,4 @@
- /SOURCE file
+ /SOURCE pattern
-Read a configuration file.
+Read configuration files, that match glob pattern (sorted in alphabetical order).
--- a/mcabber/doc/help/fr/hlp_source.txt Mon Jan 18 17:49:30 2010 +0200
+++ b/mcabber/doc/help/fr/hlp_source.txt Mon Jan 18 16:36:55 2010 +0200
@@ -1,4 +1,4 @@
/SOURCE fichier
-Cette commande permet de lire un fichier de configuration.
+Cette commande permet de lire un fichier de configuration. Il est possible d'utiliser un motif, auquel cas les fichiers sont lus dans l'ordre alphabétique.
--- a/mcabber/doc/help/ru/hlp_source.txt Mon Jan 18 17:49:30 2010 +0200
+++ b/mcabber/doc/help/ru/hlp_source.txt Mon Jan 18 16:36:55 2010 +0200
@@ -1,4 +1,4 @@
- /SOURCE имя_файла
+ /SOURCE шаблон
-Загружает конфигурационный файл.
+Загружает все файлы, которые соответствуют данному шаблону (в алфавитном порядке).
--- a/mcabber/doc/help/uk/hlp_source.txt Mon Jan 18 17:49:30 2010 +0200
+++ b/mcabber/doc/help/uk/hlp_source.txt Mon Jan 18 16:36:55 2010 +0200
@@ -1,5 +1,5 @@
- /SOURCE файл
+ /SOURCE шаблон
-Читає налаштування з файлу.
+Читає налаштування з файлів, що відповідають вказаному шаблону (у алфавітному порядку).
Примітка: у під'єднаному до сервера стані команда розуміє й звичайні команди (як то say, group та інші) це можна використати у hook-post-connect (див. mcabberrc).
--- a/mcabber/mcabber/commands.c Mon Jan 18 17:49:30 2010 +0200
+++ b/mcabber/mcabber/commands.c Mon Jan 18 16:36:55 2010 +0200
@@ -24,6 +24,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <errno.h>
+#include <glob.h>
#include "commands.h"
#include "help.h"
@@ -3782,10 +3784,17 @@
readline_disable_chat_mode(show_roster);
}
+static int source_print_error(const char *path, int eerrno)
+{
+ scr_LogPrint(LPRINT_DEBUG, "Source: glob (%s) error: %s.", path, strerror(eerrno));
+ return 0;
+}
+
static void do_source(char *arg)
{
static int recur_level;
gchar *filename, *expfname;
+ glob_t flist;
if (!*arg) {
scr_LogPrint(LPRINT_NORMAL, "Missing filename.");
return;
@@ -3797,10 +3806,35 @@
filename = g_strdup(arg);
strip_arg_special_chars(filename);
expfname = expand_filename(filename);
- recur_level++;
- cfg_read_file(expfname, FALSE);
- recur_level--;
g_free(filename);
+ // match
+ flist.gl_offs = 0;
+ if (glob(expfname, 0, source_print_error, &flist)) {
+ scr_LogPrint(LPRINT_LOGNORM, "Source: error: %s.", strerror (errno));
+ } else {
+ int i;
+ // sort list
+ for (i = 1; i < flist.gl_pathc; ++i) {
+ int j;
+ for (j = i-1; j > 0; --j) {
+ char *a = flist.gl_pathv[j+1];
+ char *b = flist.gl_pathv[j];
+ if (strcmp(a, b) < 0) {
+ flist.gl_pathv[j] = a;
+ flist.gl_pathv[j+1] = b;
+ } else
+ break;
+ }
+ }
+ // source files in list
+ for (i=0; i < flist.gl_pathc; ++i) {
+ recur_level++;
+ cfg_read_file(flist.gl_pathv[i], FALSE);
+ recur_level--;
+ }
+ // free
+ globfree(&flist);
+ }
g_free(expfname);
}