summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/fset/fset-command.c13
-rw-r--r--src/plugins/fset/fset-option.c57
-rw-r--r--src/plugins/fset/fset-option.h1
3 files changed, 71 insertions, 0 deletions
diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c
index a3135107c..946c4c17f 100644
--- a/src/plugins/fset/fset-command.c
+++ b/src/plugins/fset/fset-command.c
@@ -423,6 +423,15 @@ fset_command_fset (const void *pointer, void *data,
return WEECHAT_RC_OK;
}
+ if (weechat_strcmp (argv[1], "-import") == 0)
+ {
+ if (argc < 3)
+ WEECHAT_COMMAND_ERROR;
+ if (!fset_option_import (argv_eol[2]))
+ WEECHAT_COMMAND_ERROR;
+ return WEECHAT_RC_OK;
+ }
+
WEECHAT_COMMAND_ERROR;
}
else
@@ -639,6 +648,7 @@ fset_command_init ()
" || -mark"
" || -format"
" || -export [-help|-nohelp] <filename>"
+ " || -import <filename>"
" || <filter>"),
WEECHAT_CMD_ARGS_DESC(
N_("raw[-bar]: add the help bar"),
@@ -666,6 +676,8 @@ fset_command_init ()
N_("raw[-format]: switch to the next available format"),
N_("raw[-export]: export the options and values displayed in a file "
"(each line has format: \"/set name value\" or \"/unset name\")"),
+ N_("raw[-import]: import the options from a file "
+ "(all lines containing commands are are executed)"),
N_("raw[-help]: force writing of help on options in exported file "
"(see /help fset.look.export_help_default)"),
N_("raw[-nohelp]: do not write help on options in exported file "
@@ -784,6 +796,7 @@ fset_command_init ()
" || -mark"
" || -format"
" || -export -help|-nohelp|%(filename) %(filename)"
+ " || -import %(filename)"
" || *|c:|f:|s:|d|d:|d=|d==|=|==|%(fset_options)",
&fset_command_fset, NULL, NULL);
weechat_hook_command_run ("/set", &fset_command_run_set_cb, NULL, NULL);
diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c
index 2ef8c219d..a783d2f0e 100644
--- a/src/plugins/fset/fset-option.c
+++ b/src/plugins/fset/fset-option.c
@@ -1471,6 +1471,63 @@ fset_option_export (const char *filename, int with_help)
}
/*
+ * Imports options from a file: all lines starting with "/" are executed.
+ *
+ * Returns:
+ * 1: export OK
+ * 0: error
+ */
+
+int
+fset_option_import (const char *filename)
+{
+ char *filename2, line[4096], *ptr_line;
+ FILE *file;
+ int length;
+
+ filename2 = weechat_string_expand_home (filename);
+ if (!filename2)
+ return 0;
+
+ file = fopen (filename2, "r");
+ if (!file)
+ {
+ free (filename2);
+ return 0;
+ }
+
+ while (!feof (file))
+ {
+ ptr_line = fgets (line, sizeof (line) - 1, file);
+ if (!ptr_line)
+ continue;
+ /* ignore comments */
+ if (ptr_line[0] == '#')
+ continue;
+ /* execute command (if it's a valid command) */
+ if (!weechat_string_input_for_buffer (ptr_line))
+ {
+ /* remove trailing '\r' and '\n' */
+ length = strlen (line) - 1;
+ while ((length >= 0)
+ && ((line[length] == '\n')
+ || (line[length] == '\r')))
+ {
+ line[length] = '\0';
+ length--;
+ }
+ weechat_command (NULL, ptr_line);
+ }
+ }
+
+ fclose (file);
+
+ free (filename2);
+
+ return 1;
+}
+
+/*
* Refreshes the fset buffer after the change of an option.
*/
diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h
index 82be59c73..b8266274d 100644
--- a/src/plugins/fset/fset-option.h
+++ b/src/plugins/fset/fset-option.h
@@ -121,6 +121,7 @@ extern void fset_option_mark_options_matching_filter (const char *filter,
int mark);
extern void fset_option_unmark_all ();
extern int fset_option_export (const char *filename, int with_help);
+extern int fset_option_import (const char *filename);
extern int fset_option_config_cb (const void *pointer,
void *data,
const char *option,