Added string_remove_quotes() function, use of argv and argv_eol for WeeChat commands arguments
parent
0d66286efe
commit
b64b0fe6ca
File diff suppressed because it is too large
Load Diff
|
@ -35,7 +35,7 @@ struct command
|
|||
int min_arg, max_arg; /* min & max number of arguments */
|
||||
int conversion; /* = 1 if cmd args are converted (charset*/
|
||||
/* and color) before execution */
|
||||
int (*cmd_function)(struct t_gui_buffer *, char *, int, char **);
|
||||
int (*cmd_function)(struct t_gui_buffer *, int, char **, char **);
|
||||
/* function called when user enters cmd */
|
||||
};
|
||||
|
||||
|
@ -51,24 +51,22 @@ extern void command_index_remove (char *);
|
|||
extern int command_is_command (char *);
|
||||
extern void command_print_stdout (struct command *);
|
||||
|
||||
extern int command_alias (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_buffer (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_builtin (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_clear (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_debug (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_help (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_history (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_key (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_panel (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_plugin (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_quit (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_save (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_set (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_setp (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_unalias (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_unignore (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_upgrade (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_uptime (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_window (struct t_gui_buffer *, char *, int, char **);
|
||||
extern int command_alias (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_buffer (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_builtin (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_clear (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_debug (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_help (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_history (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_key (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_plugin (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_quit (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_save (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_set (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_setp (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_unalias (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_upgrade (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_uptime (struct t_gui_buffer *, int, char **, char **);
|
||||
extern int command_window (struct t_gui_buffer *, int, char **, char **);
|
||||
|
||||
#endif /* wee-command.h */
|
||||
|
|
|
@ -298,10 +298,13 @@ config_option_section_option_search (char **config_sections,
|
|||
|
||||
for (i = 0; config_sections[i]; i++)
|
||||
{
|
||||
ptr_option = config_option_search (config_options[i],
|
||||
option_name);
|
||||
if (ptr_option)
|
||||
return ptr_option;
|
||||
if (config_options[i])
|
||||
{
|
||||
ptr_option = config_option_search (config_options[i],
|
||||
option_name);
|
||||
if (ptr_option)
|
||||
return ptr_option;
|
||||
}
|
||||
}
|
||||
|
||||
/* option not found */
|
||||
|
|
|
@ -162,8 +162,7 @@ hook_command_exec (void *plugin, char *string)
|
|||
argv = string_explode (string, " ", 0, 0, &argc);
|
||||
if (argc == 0)
|
||||
{
|
||||
if (argv)
|
||||
string_free_exploded (argv);
|
||||
string_free_exploded (argv);
|
||||
return -1;
|
||||
}
|
||||
argv_eol = string_explode (string, " ", 1, 0, NULL);
|
||||
|
@ -184,10 +183,8 @@ hook_command_exec (void *plugin, char *string)
|
|||
}
|
||||
}
|
||||
|
||||
if (argv)
|
||||
string_free_exploded (argv);
|
||||
if (argv_eol)
|
||||
string_free_exploded (argv_eol);
|
||||
string_free_exploded (argv);
|
||||
string_free_exploded (argv_eol);
|
||||
|
||||
/* no hook found */
|
||||
return -1;
|
||||
|
|
|
@ -51,7 +51,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
|
|||
{
|
||||
int i, rc, argc, return_code, length1, length2;
|
||||
char *command, *pos, *ptr_args;
|
||||
char **argv, *alias_command;
|
||||
char **argv, **argv_eol, *alias_command;
|
||||
char **commands, **ptr_cmd, **ptr_next_cmd;
|
||||
char *args_replaced, *vars_replaced, *new_ptr_cmd;
|
||||
int some_args_replaced;
|
||||
|
@ -98,16 +98,17 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
|
|||
|
||||
switch (rc)
|
||||
{
|
||||
case 0: /* plugin handler KO */
|
||||
case 0: /* command hooked, KO */
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: command \"%s\" failed"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
command + 1);
|
||||
break;
|
||||
case 1: /* plugin handler OK, executed */
|
||||
case 1: /* command hooked, OK (executed) */
|
||||
break;
|
||||
default: /* plugin handler not found */
|
||||
default: /* no command hooked */
|
||||
argv = string_explode (ptr_args, " ", 0, 0, &argc);
|
||||
argv_eol = string_explode (ptr_args, " ", 1, 0, NULL);
|
||||
|
||||
/* look for alias */
|
||||
if (!only_builtin)
|
||||
|
@ -222,6 +223,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
|
|||
}
|
||||
}
|
||||
string_free_exploded (argv);
|
||||
string_free_exploded (argv_eol);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
|
@ -277,7 +279,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
|
|||
(weechat_commands[i].conversion
|
||||
&& cfg_irc_colors_send)) : NULL;*/
|
||||
return_code = (int) (weechat_commands[i].cmd_function)
|
||||
(buffer, ptr_args, argc, argv);
|
||||
(buffer, argc, argv, argv_eol);
|
||||
if (return_code < 0)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
|
@ -287,6 +289,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
|
|||
}
|
||||
}
|
||||
string_free_exploded (argv);
|
||||
string_free_exploded (argv_eol);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
|
@ -328,6 +331,7 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
|
|||
command + 1);
|
||||
|
||||
string_free_exploded (argv);
|
||||
string_free_exploded (argv_eol);
|
||||
}
|
||||
free (command);
|
||||
return 0;
|
||||
|
|
|
@ -199,7 +199,7 @@ string_strcasestr (char *string, char *search)
|
|||
|
||||
/*
|
||||
* string_replace: replace a string by new one in a string
|
||||
* note: returned value has to be free() after use
|
||||
* note: returned value has to be free() after use
|
||||
*/
|
||||
|
||||
char *
|
||||
|
@ -253,6 +253,49 @@ string_replace (char *string, char *search, char *replace)
|
|||
return new_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* string_remove_quotes: remove quotes at beginning/end of string
|
||||
* (ignore spaces if there are before first quote or
|
||||
* after last quote)
|
||||
* note: returned value has to be free() after use
|
||||
*/
|
||||
|
||||
char *
|
||||
string_remove_quotes (char *string, char *quotes)
|
||||
{
|
||||
int length;
|
||||
char *pos_start, *pos_end;
|
||||
|
||||
if (!string || !quotes)
|
||||
return NULL;
|
||||
|
||||
if (!string[0])
|
||||
return strdup (string);
|
||||
|
||||
pos_start = string;
|
||||
while (pos_start[0] == ' ')
|
||||
{
|
||||
pos_start++;
|
||||
}
|
||||
length = strlen (string);
|
||||
pos_end = string + length - 1;
|
||||
while ((pos_end[0] == ' ') && (pos_end > pos_start))
|
||||
{
|
||||
pos_end--;
|
||||
}
|
||||
if (!pos_start[0] || !pos_end[0] || (pos_end <= pos_start))
|
||||
return strdup (string);
|
||||
|
||||
if (strchr (quotes, pos_start[0]) && (pos_end[0] == pos_start[0]))
|
||||
{
|
||||
if (pos_end == (pos_start + 1))
|
||||
return strdup ("");
|
||||
return strndup (pos_start + 1, pos_end - pos_start - 1);
|
||||
}
|
||||
|
||||
return strdup (string);
|
||||
}
|
||||
|
||||
/*
|
||||
* string_convert_hex_chars: convert hex chars (\x??) to value
|
||||
*/
|
||||
|
|
|
@ -29,6 +29,7 @@ extern int string_strcasecmp (char *, char *);
|
|||
extern int string_strncasecmp (char *, char *, int);
|
||||
extern char *string_strcasestr (char *, char *);
|
||||
extern char *string_replace (char *, char *, char *);
|
||||
extern char *string_remove_quotes (char *, char *);
|
||||
extern char *string_convert_hex_chars (char *);
|
||||
extern char **string_explode (char *, char *, int, int, int *);
|
||||
extern void string_free_exploded (char **);
|
||||
|
|
|
@ -70,7 +70,7 @@ gui_buffer_new (void *plugin, char *category, char *name)
|
|||
weechat_log_printf ("Creating new buffer\n");
|
||||
#endif
|
||||
|
||||
if (!name)
|
||||
if (!category || !name)
|
||||
return NULL;
|
||||
|
||||
/* create new buffer */
|
||||
|
@ -276,6 +276,27 @@ gui_buffer_set_nick (struct t_gui_buffer *buffer, char *new_nick)
|
|||
buffer->input_nick = (new_nick) ? strdup (new_nick) : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_buffer_search_main: get main buffer (weechat one, created at startup)
|
||||
* return first buffer if not found
|
||||
*/
|
||||
|
||||
struct t_gui_buffer *
|
||||
gui_buffer_search_main ()
|
||||
{
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
for (ptr_buffer = gui_buffers; ptr_buffer;
|
||||
ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
if (!ptr_buffer->plugin)
|
||||
return ptr_buffer;
|
||||
}
|
||||
|
||||
/* buffer not found, return first buffer by default */
|
||||
return gui_buffers;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_buffer_search_by_category_name: search a buffer by category and/or name
|
||||
*/
|
||||
|
|
|
@ -151,6 +151,7 @@ extern void gui_buffer_set_log (struct t_gui_buffer *, char *);
|
|||
extern void gui_buffer_set_title (struct t_gui_buffer *, char *);
|
||||
extern void gui_buffer_set_nick_case_sensitive (struct t_gui_buffer *, int);
|
||||
extern void gui_buffer_set_nick (struct t_gui_buffer *, char *);
|
||||
extern struct t_gui_buffer *gui_buffer_search_main ();
|
||||
extern struct t_gui_buffer *gui_buffer_search_by_category_name (char *,
|
||||
char *);
|
||||
extern struct t_gui_buffer *gui_buffer_search_by_number (int);
|
||||
|
|
|
@ -463,7 +463,7 @@ gui_chat_printf_date (struct t_gui_buffer *buffer, time_t date,
|
|||
if (gui_init_ok)
|
||||
{
|
||||
if (buffer == NULL)
|
||||
buffer = gui_buffers;
|
||||
buffer = gui_buffer_search_main ();
|
||||
|
||||
if (buffer->type == GUI_BUFFER_TYPE_FREE)
|
||||
buffer = gui_buffers;
|
||||
|
|
|
@ -178,6 +178,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
|||
"action: one of following actions:\n"
|
||||
" buffer display infos about buffers",
|
||||
"buffer|buffer_lines", demo_command, NULL);
|
||||
|
||||
weechat_buffer_new ("categ", "nam");
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue