mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 15:26:37 +02:00
fset: display number of commands executed in imported file, improve errors displayed
This commit is contained in:
@@ -81,7 +81,7 @@ fset_command_fset (const void *pointer, void *data,
|
||||
struct t_gui_buffer *buffer, int argc,
|
||||
char **argv, char **argv_eol)
|
||||
{
|
||||
int num_options, line, value, i, with_help, min, max, format_number;
|
||||
int num_options, line, value, i, with_help, min, max, format_number, count;
|
||||
char str_command[512], str_number[64];
|
||||
const char *ptr_filename;
|
||||
struct t_fset_option *ptr_fset_option;
|
||||
@@ -427,8 +427,28 @@ fset_command_fset (const void *pointer, void *data,
|
||||
{
|
||||
if (argc < 3)
|
||||
WEECHAT_COMMAND_ERROR;
|
||||
if (!fset_option_import (argv_eol[2]))
|
||||
WEECHAT_COMMAND_ERROR;
|
||||
count = fset_option_import (argv_eol[2]);
|
||||
switch (count)
|
||||
{
|
||||
case -2:
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: not enough memory"),
|
||||
weechat_prefix ("error"), FSET_PLUGIN_NAME);
|
||||
break;
|
||||
case -1:
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: file \"%s\" not found"),
|
||||
weechat_prefix ("error"), FSET_PLUGIN_NAME,
|
||||
argv_eol[2]);
|
||||
break;
|
||||
default:
|
||||
weechat_printf (NULL,
|
||||
NG_("%d command executed in file \"%s\"",
|
||||
"%d commands executed in file \"%s\"",
|
||||
count),
|
||||
count, argv_eol[2]);
|
||||
break;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1474,8 +1474,9 @@ 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
|
||||
* -2: not enough memory
|
||||
* -1: file not found
|
||||
* >= 0: number of commands executed in file
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -1483,17 +1484,19 @@ fset_option_import (const char *filename)
|
||||
{
|
||||
char *filename2, line[4096], *ptr_line;
|
||||
FILE *file;
|
||||
int length;
|
||||
int length, count;
|
||||
|
||||
count = 0;
|
||||
|
||||
filename2 = weechat_string_expand_home (filename);
|
||||
if (!filename2)
|
||||
return 0;
|
||||
return -2;
|
||||
|
||||
file = fopen (filename2, "r");
|
||||
if (!file)
|
||||
{
|
||||
free (filename2);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (!feof (file))
|
||||
@@ -1516,7 +1519,11 @@ fset_option_import (const char *filename)
|
||||
line[length] = '\0';
|
||||
length--;
|
||||
}
|
||||
weechat_command (NULL, ptr_line);
|
||||
if (ptr_line[0])
|
||||
{
|
||||
weechat_command (NULL, ptr_line);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1524,7 +1531,7 @@ fset_option_import (const char *filename)
|
||||
|
||||
free (filename2);
|
||||
|
||||
return 1;
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user