mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 10:10:28 +01:00
cli: make match() return boolean
Coccinelle semantic patch:
@@
@@
-int
+gboolean
matches (...);
@@
expression pattern, cmd, len;
@@
-int
+gboolean
matches (...)
{
...
- return memcmp (pattern, cmd, len);
+ return memcmp (pattern, cmd, len) == 0;
}
@@
expression prefix, str;
@@
(
-matches (prefix, str) != 0
+!matches (prefix, str)
|
-matches (prefix, str) == 0
+matches (prefix, str)
)
@@
expression prefix, str;
@@
-(matches (prefix, str))
+matches (prefix, str)
@@
expression prefix, str;
@@
-(!matches (prefix, str))
+!matches (prefix, str)
spatch --smpl-spacing --sp-file match.cocci --dir clients/cli/ \
--include-headers --macro-file shared/nm-utils/gsystem-local-alloc.h
This commit is contained in:
parent
1d40c5f476
commit
84c484ed5b
8 changed files with 86 additions and 86 deletions
|
|
@ -1689,7 +1689,7 @@ nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, char
|
|||
|
||||
if (argc == 1 && nmc->complete) {
|
||||
for (c = cmds; c->cmd; ++c) {
|
||||
if (!*cmd || matches (cmd, c->cmd) == 0)
|
||||
if (!*cmd || matches (cmd, c->cmd))
|
||||
g_print ("%s\n", c->cmd);
|
||||
}
|
||||
nmc_complete_help (cmd);
|
||||
|
|
@ -1699,7 +1699,7 @@ nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, char
|
|||
}
|
||||
|
||||
for (c = cmds; c->cmd; ++c) {
|
||||
if (cmd && matches (cmd, c->cmd) == 0)
|
||||
if (cmd && matches (cmd, c->cmd))
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1754,7 +1754,7 @@ nmc_complete_strings (const char *prefix, ...)
|
|||
|
||||
va_start (args, prefix);
|
||||
while ((candidate = va_arg (args, const char *))) {
|
||||
if (!*prefix || matches (prefix, candidate) == 0)
|
||||
if (!*prefix || matches (prefix, candidate))
|
||||
g_print ("%s\n", candidate);
|
||||
}
|
||||
va_end (args);
|
||||
|
|
|
|||
|
|
@ -1658,13 +1658,13 @@ parse_preferred_connection_order (const char *order, GError **error)
|
|||
if (str[0] == '+' || str[0] == '-')
|
||||
str++;
|
||||
|
||||
if (matches (str, "active") == 0)
|
||||
if (matches (str, "active"))
|
||||
val = inverse ? NMC_SORT_ACTIVE_INV : NMC_SORT_ACTIVE;
|
||||
else if (matches (str, "name") == 0)
|
||||
else if (matches (str, "name"))
|
||||
val = inverse ? NMC_SORT_NAME_INV : NMC_SORT_NAME;
|
||||
else if (matches (str, "type") == 0)
|
||||
else if (matches (str, "type"))
|
||||
val = inverse ? NMC_SORT_TYPE_INV : NMC_SORT_TYPE;
|
||||
else if (matches (str, "path") == 0)
|
||||
else if (matches (str, "path"))
|
||||
val = inverse ? NMC_SORT_PATH_INV : NMC_SORT_PATH;
|
||||
else {
|
||||
g_array_unref (order_arr);
|
||||
|
|
@ -4156,9 +4156,9 @@ set_bond_monitoring_mode (NmCli *nmc, NMConnection *con, OptionInfo *option, con
|
|||
monitor_mode = g_strdup (WORD_MIIMON);
|
||||
}
|
||||
|
||||
if (matches (monitor_mode, WORD_MIIMON) == 0)
|
||||
if (matches (monitor_mode, WORD_MIIMON))
|
||||
enable_options (NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS, miimon_opts);
|
||||
else if (matches (monitor_mode, WORD_ARP) == 0)
|
||||
else if (matches (monitor_mode, WORD_ARP))
|
||||
enable_options (NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS, arp_opts);
|
||||
else {
|
||||
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
|
|
@ -4844,7 +4844,7 @@ want_provide_opt_args (const char *type, int num)
|
|||
"Do you want to provide them? %s", num),
|
||||
prompt_yes_no (TRUE, NULL));
|
||||
answer = answer ? g_strstrip (answer) : NULL;
|
||||
if (answer && matches (answer, WORD_LOC_YES) != 0)
|
||||
if (answer && !matches (answer, WORD_LOC_YES))
|
||||
ret = FALSE;
|
||||
g_free (answer);
|
||||
return ret;
|
||||
|
|
@ -5441,13 +5441,13 @@ get_gen_func_cmd_nmcli (const char *str)
|
|||
{
|
||||
if (!str)
|
||||
return NULL;
|
||||
if (matches (str, "status-line") == 0)
|
||||
if (matches (str, "status-line"))
|
||||
return gen_func_bool_values;
|
||||
if (matches (str, "save-confirmation") == 0)
|
||||
if (matches (str, "save-confirmation"))
|
||||
return gen_func_bool_values;
|
||||
if (matches (str, "show-secrets") == 0)
|
||||
if (matches (str, "show-secrets"))
|
||||
return gen_func_bool_values;
|
||||
if (matches (str, "prompt-color") == 0)
|
||||
if (matches (str, "prompt-color"))
|
||||
return gen_cmd_nmcli_prompt_color;
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -5524,7 +5524,7 @@ should_complete_cmd (const char *line, int end, const char *cmd,
|
|||
*prev_word = g_strdup (word3);
|
||||
}
|
||||
|
||||
if (word1 && matches (word1, cmd) == 0)
|
||||
if (word1 && matches (word1, cmd))
|
||||
ret = TRUE;
|
||||
|
||||
g_free (tmp);
|
||||
|
|
@ -6075,29 +6075,29 @@ parse_editor_main_cmd (const char *cmd, char **cmd_arg)
|
|||
return NMC_EDITOR_MAIN_CMD_UNKNOWN;
|
||||
}
|
||||
|
||||
if (matches (vec[0], "goto") == 0)
|
||||
if (matches (vec[0], "goto"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_GOTO;
|
||||
else if (matches (vec[0], "remove") == 0)
|
||||
else if (matches (vec[0], "remove"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_REMOVE;
|
||||
else if (matches (vec[0], "set") == 0)
|
||||
else if (matches (vec[0], "set"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_SET;
|
||||
else if (matches (vec[0], "describe") == 0)
|
||||
else if (matches (vec[0], "describe"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_DESCRIBE;
|
||||
else if (matches (vec[0], "print") == 0)
|
||||
else if (matches (vec[0], "print"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_PRINT;
|
||||
else if (matches (vec[0], "verify") == 0)
|
||||
else if (matches (vec[0], "verify"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_VERIFY;
|
||||
else if (matches (vec[0], "save") == 0)
|
||||
else if (matches (vec[0], "save"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_SAVE;
|
||||
else if (matches (vec[0], "activate") == 0)
|
||||
else if (matches (vec[0], "activate"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_ACTIVATE;
|
||||
else if (matches (vec[0], "back") == 0)
|
||||
else if (matches (vec[0], "back"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_BACK;
|
||||
else if (matches (vec[0], "help") == 0 || strcmp (vec[0], "?") == 0)
|
||||
else if (matches (vec[0], "help") || strcmp (vec[0], "?") == 0)
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_HELP;
|
||||
else if (matches (vec[0], "quit") == 0)
|
||||
else if (matches (vec[0], "quit"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_QUIT;
|
||||
else if (matches (vec[0], "nmcli") == 0)
|
||||
else if (matches (vec[0], "nmcli"))
|
||||
editor_cmd = NMC_EDITOR_MAIN_CMD_NMCLI;
|
||||
|
||||
/* set pointer to command argument */
|
||||
|
|
@ -6263,23 +6263,23 @@ parse_editor_sub_cmd (const char *cmd, char **cmd_arg)
|
|||
return NMC_EDITOR_SUB_CMD_UNKNOWN;
|
||||
}
|
||||
|
||||
if (matches (vec[0], "set") == 0)
|
||||
if (matches (vec[0], "set"))
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_SET;
|
||||
else if (matches (vec[0], "add") == 0)
|
||||
else if (matches (vec[0], "add"))
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_ADD;
|
||||
else if (matches (vec[0], "change") == 0)
|
||||
else if (matches (vec[0], "change"))
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_CHANGE;
|
||||
else if (matches (vec[0], "remove") == 0)
|
||||
else if (matches (vec[0], "remove"))
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_REMOVE;
|
||||
else if (matches (vec[0], "describe") == 0)
|
||||
else if (matches (vec[0], "describe"))
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_DESCRIBE;
|
||||
else if (matches (vec[0], "print") == 0)
|
||||
else if (matches (vec[0], "print"))
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_PRINT;
|
||||
else if (matches (vec[0], "back") == 0)
|
||||
else if (matches (vec[0], "back"))
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_BACK;
|
||||
else if (matches (vec[0], "help") == 0 || strcmp (vec[0], "?") == 0)
|
||||
else if (matches (vec[0], "help") || strcmp (vec[0], "?") == 0)
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_HELP;
|
||||
else if (matches (vec[0], "quit") == 0)
|
||||
else if (matches (vec[0], "quit"))
|
||||
editor_cmd = NMC_EDITOR_SUB_CMD_QUIT;
|
||||
|
||||
/* set pointer to command argument */
|
||||
|
|
@ -6595,7 +6595,7 @@ confirm_quit (void)
|
|||
"Do you really want to quit? %s"),
|
||||
prompt_yes_no (FALSE, NULL));
|
||||
answer = answer ? g_strstrip (answer) : NULL;
|
||||
if (answer && matches (answer, WORD_LOC_YES) == 0)
|
||||
if (answer && matches (answer, WORD_LOC_YES))
|
||||
want_quit = TRUE;
|
||||
|
||||
g_free (answer);
|
||||
|
|
@ -6750,10 +6750,10 @@ property_edit_submenu (NmCli *nmc,
|
|||
case NMC_EDITOR_SUB_CMD_PRINT:
|
||||
/* Print current connection settings/properties */
|
||||
if (cmd_property_arg) {
|
||||
if (matches (cmd_property_arg, "setting") == 0)
|
||||
if (matches (cmd_property_arg, "setting"))
|
||||
editor_show_setting (curr_setting, nmc);
|
||||
else if ( matches (cmd_property_arg, "connection") == 0
|
||||
|| matches (cmd_property_arg, "all") == 0)
|
||||
else if ( matches (cmd_property_arg, "connection")
|
||||
|| matches (cmd_property_arg, "all"))
|
||||
editor_show_connection (connection, nmc);
|
||||
else
|
||||
g_print (_("Unknown command argument: '%s'\n"), cmd_property_arg);
|
||||
|
|
@ -6943,7 +6943,7 @@ confirm_connection_saving (NMConnection *local, NMConnection *remote)
|
|||
"That might result in an immediate activation of the connection.\n"
|
||||
"Do you still want to save? %s"), prompt_yes_no (TRUE, NULL));
|
||||
answer = answer ? g_strstrip (answer) : NULL;
|
||||
if (!answer || matches (answer, WORD_LOC_YES) == 0)
|
||||
if (!answer || matches (answer, WORD_LOC_YES))
|
||||
confirmed = TRUE;
|
||||
else
|
||||
confirmed = FALSE;
|
||||
|
|
@ -7510,9 +7510,9 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
|
||||
/* parse argument */
|
||||
if (cmd_arg) {
|
||||
if (matches (cmd_arg, "temporary") == 0)
|
||||
if (matches (cmd_arg, "temporary"))
|
||||
persistent = FALSE;
|
||||
else if (matches (cmd_arg, "persistent") == 0)
|
||||
else if (matches (cmd_arg, "persistent"))
|
||||
persistent = TRUE;
|
||||
else {
|
||||
g_print (_("Error: invalid argument '%s'\n"), cmd_arg);
|
||||
|
|
@ -7672,7 +7672,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
break;
|
||||
|
||||
case NMC_EDITOR_MAIN_CMD_NMCLI:
|
||||
if (cmd_arg_p && matches (cmd_arg_p, "status-line") == 0) {
|
||||
if (cmd_arg_p && matches (cmd_arg_p, "status-line")) {
|
||||
GError *tmp_err = NULL;
|
||||
gboolean bb;
|
||||
if (!nmc_string_to_bool (cmd_arg_v ? g_strstrip (cmd_arg_v) : "", &bb, &tmp_err)) {
|
||||
|
|
@ -7680,7 +7680,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
g_clear_error (&tmp_err);
|
||||
} else
|
||||
nmc->editor_status_line = bb;
|
||||
} else if (cmd_arg_p && matches (cmd_arg_p, "save-confirmation") == 0) {
|
||||
} else if (cmd_arg_p && matches (cmd_arg_p, "save-confirmation")) {
|
||||
GError *tmp_err = NULL;
|
||||
gboolean bb;
|
||||
if (!nmc_string_to_bool (cmd_arg_v ? g_strstrip (cmd_arg_v) : "", &bb, &tmp_err)) {
|
||||
|
|
@ -7688,7 +7688,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
g_clear_error (&tmp_err);
|
||||
} else
|
||||
nmc->editor_save_confirmation = bb;
|
||||
} else if (cmd_arg_p && matches (cmd_arg_p, "show-secrets") == 0) {
|
||||
} else if (cmd_arg_p && matches (cmd_arg_p, "show-secrets")) {
|
||||
GError *tmp_err = NULL;
|
||||
gboolean bb;
|
||||
if (!nmc_string_to_bool (cmd_arg_v ? g_strstrip (cmd_arg_v) : "", &bb, &tmp_err)) {
|
||||
|
|
@ -7696,7 +7696,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
g_clear_error (&tmp_err);
|
||||
} else
|
||||
nmc->editor_show_secrets = bb;
|
||||
} else if (cmd_arg_p && matches (cmd_arg_p, "prompt-color") == 0) {
|
||||
} else if (cmd_arg_p && matches (cmd_arg_p, "prompt-color")) {
|
||||
GError *tmp_err = NULL;
|
||||
NmcTermColor color;
|
||||
color = nmc_term_color_parse_string (cmd_arg_v ? g_strstrip (cmd_arg_v) : " ", &tmp_err);
|
||||
|
|
@ -7880,9 +7880,9 @@ static void
|
|||
nmc_complete_connection_type (const char *prefix, const NameItem *types)
|
||||
{
|
||||
while (types->name) {
|
||||
if (!*prefix || matches (prefix, types->name) == 0)
|
||||
if (!*prefix || matches (prefix, types->name))
|
||||
g_print ("%s\n", types->name);
|
||||
if (types->alias && (!*prefix || matches (prefix, types->alias) == 0))
|
||||
if (types->alias && (!*prefix || matches (prefix, types->alias)))
|
||||
g_print ("%s\n", types->alias);
|
||||
types++;
|
||||
}
|
||||
|
|
@ -8577,7 +8577,7 @@ nmc_complete_vpn_service (const char *prefix)
|
|||
for (candidate = services; *candidate; candidate++) {
|
||||
if (!*prefix && g_str_has_prefix (*candidate, NM_DBUS_INTERFACE))
|
||||
continue;
|
||||
if (!*prefix || matches (prefix, *candidate) == 0)
|
||||
if (!*prefix || matches (prefix, *candidate))
|
||||
g_print ("%s\n", *candidate);
|
||||
}
|
||||
g_strfreev (services);
|
||||
|
|
|
|||
|
|
@ -2316,7 +2316,7 @@ do_device_set (NmCli *nmc, int argc, char **argv)
|
|||
if (argc == 1 && nmc->complete)
|
||||
nmc_complete_strings (*argv, "managed", "autoconnect", NULL);
|
||||
|
||||
if (matches (*argv, "managed") == 0) {
|
||||
if (matches (*argv, "managed")) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1));
|
||||
return NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -2331,7 +2331,7 @@ do_device_set (NmCli *nmc, int argc, char **argv)
|
|||
values[DEV_SET_MANAGED].idx = ++i;
|
||||
values[DEV_SET_MANAGED].value = flag;
|
||||
}
|
||||
else if (matches (*argv, "autoconnect") == 0) {
|
||||
else if (matches (*argv, "autoconnect")) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1));
|
||||
return NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
|
|||
|
|
@ -674,7 +674,7 @@ do_general_logging (NmCli *nmc, int argc, char **argv)
|
|||
if (argc == 1 && nmc->complete)
|
||||
nmc_complete_strings (*argv, "level", "domains", NULL);
|
||||
|
||||
if (matches (*argv, "level") == 0) {
|
||||
if (matches (*argv, "level")) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1));
|
||||
return NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -684,7 +684,7 @@ do_general_logging (NmCli *nmc, int argc, char **argv)
|
|||
"ERR", "OFF", "KEEP", NULL);
|
||||
}
|
||||
level = *argv;
|
||||
} else if (matches (*argv, "domains") == 0) {
|
||||
} else if (matches (*argv, "domains")) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1));
|
||||
return NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -864,7 +864,7 @@ do_networking_connectivity (NmCli *nmc, int argc, char **argv)
|
|||
if (!argc) {
|
||||
/* no arguments -> get current state */
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_CONNECTIVITY, _("Connectivity"));
|
||||
} else if (matches (*argv, "check") == 0) {
|
||||
} else if (matches (*argv, "check")) {
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
/* Register polkit agent */
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ complete_one (gpointer key, gpointer value, gpointer user_data)
|
|||
else
|
||||
last = prefix;
|
||||
|
||||
if ((!*last && !strchr (name, '.')) || matches (last, name) == 0) {
|
||||
if ((!*last && !strchr (name, '.')) || matches (last, name)) {
|
||||
g_print ("%.*s%s%s\n", (int)(last-prefix), prefix, name,
|
||||
strcmp (last, name) == 0 ? "," : "");
|
||||
}
|
||||
|
|
@ -243,7 +243,7 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
if (matches (opt, "-terse") == 0) {
|
||||
if (matches (opt, "-terse")) {
|
||||
if (nmc->print_output == NMC_PRINT_TERSE) {
|
||||
g_string_printf (nmc->return_text, _("Error: Option '--terse' is specified the second time."));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -256,7 +256,7 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
else
|
||||
nmc->print_output = NMC_PRINT_TERSE;
|
||||
} else if (matches (opt, "-pretty") == 0) {
|
||||
} else if (matches (opt, "-pretty")) {
|
||||
if (nmc->print_output == NMC_PRINT_PRETTY) {
|
||||
g_string_printf (nmc->return_text, _("Error: Option '--pretty' is specified the second time."));
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -269,7 +269,7 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
else
|
||||
nmc->print_output = NMC_PRINT_PRETTY;
|
||||
} else if (matches (opt, "-mode") == 0) {
|
||||
} else if (matches (opt, "-mode")) {
|
||||
nmc->mode_specified = TRUE;
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: missing argument for '%s' option."), opt);
|
||||
|
|
@ -278,16 +278,16 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
if (argc == 1 && nmc->complete)
|
||||
nmc_complete_strings (argv[0], "tabular", "multiline", NULL);
|
||||
if (matches (argv[0], "tabular") == 0)
|
||||
if (matches (argv[0], "tabular"))
|
||||
nmc->multiline_output = FALSE;
|
||||
else if (matches (argv[0], "multiline") == 0)
|
||||
else if (matches (argv[0], "multiline"))
|
||||
nmc->multiline_output = TRUE;
|
||||
else {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), argv[0], opt);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
return FALSE;
|
||||
}
|
||||
} else if (matches (opt, "-colors") == 0) {
|
||||
} else if (matches (opt, "-colors")) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: missing argument for '%s' option."), opt);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -295,18 +295,18 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
if (argc == 1 && nmc->complete)
|
||||
nmc_complete_strings (argv[0], "yes", "no", "auto", NULL);
|
||||
if (matches (argv[0], "auto") == 0)
|
||||
if (matches (argv[0], "auto"))
|
||||
nmc->use_colors = NMC_USE_COLOR_AUTO;
|
||||
else if (matches (argv[0], "yes") == 0)
|
||||
else if (matches (argv[0], "yes"))
|
||||
nmc->use_colors = NMC_USE_COLOR_YES;
|
||||
else if (matches (argv[0], "no") == 0)
|
||||
else if (matches (argv[0], "no"))
|
||||
nmc->use_colors = NMC_USE_COLOR_NO;
|
||||
else {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), argv[0], opt);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
return FALSE;
|
||||
}
|
||||
} else if (matches (opt, "-escape") == 0) {
|
||||
} else if (matches (opt, "-escape")) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: missing argument for '%s' option."), opt);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -314,16 +314,16 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
if (argc == 1 && nmc->complete)
|
||||
nmc_complete_strings (argv[0], "yes", "no", NULL);
|
||||
if (matches (argv[0], "yes") == 0)
|
||||
if (matches (argv[0], "yes"))
|
||||
nmc->escape_values = TRUE;
|
||||
else if (matches (argv[0], "no") == 0)
|
||||
else if (matches (argv[0], "no"))
|
||||
nmc->escape_values = FALSE;
|
||||
else {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), argv[0], opt);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
return FALSE;
|
||||
}
|
||||
} else if (matches (opt, "-fields") == 0) {
|
||||
} else if (matches (opt, "-fields")) {
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: fields for '%s' options are missing."), opt);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -332,13 +332,13 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
if (argc == 1 && nmc->complete)
|
||||
complete_fields (argv[0]);
|
||||
nmc->required_fields = g_strdup (argv[0]);
|
||||
} else if (matches (opt, "-nocheck") == 0) {
|
||||
} else if (matches (opt, "-nocheck")) {
|
||||
/* ignore for backward compatibility */
|
||||
} else if (matches (opt, "-ask") == 0) {
|
||||
} else if (matches (opt, "-ask")) {
|
||||
nmc->ask = TRUE;
|
||||
} else if (matches (opt, "-show-secrets") == 0) {
|
||||
} else if (matches (opt, "-show-secrets")) {
|
||||
nmc->show_secrets = TRUE;
|
||||
} else if (matches (opt, "-wait") == 0) {
|
||||
} else if (matches (opt, "-wait")) {
|
||||
unsigned long timeout;
|
||||
if (next_arg (&argc, &argv) != 0) {
|
||||
g_string_printf (nmc->return_text, _("Error: missing argument for '%s' option."), opt);
|
||||
|
|
@ -352,11 +352,11 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
return FALSE;
|
||||
}
|
||||
nmc->timeout = (int) timeout;
|
||||
} else if (matches (opt, "-version") == 0) {
|
||||
} else if (matches (opt, "-version")) {
|
||||
if (!nmc->complete)
|
||||
g_print (_("nmcli tool, version %s\n"), NMCLI_VERSION);
|
||||
return NMC_RESULT_SUCCESS;
|
||||
} else if (matches (opt, "-help") == 0) {
|
||||
} else if (matches (opt, "-help")) {
|
||||
if (!nmc->complete)
|
||||
usage ();
|
||||
return NMC_RESULT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -3533,7 +3533,7 @@ static gboolean
|
|||
nmc_property_ipv4_set_method (NMSetting *setting, const char *prop, const char *val, GError **error)
|
||||
{
|
||||
/* Silently accept "static" and convert to "manual" */
|
||||
if (val && strlen (val) > 1 && matches (val, "static") == 0)
|
||||
if (val && strlen (val) > 1 && matches (val, "static"))
|
||||
val = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
|
||||
|
||||
return check_and_set_string (setting, prop, val, ipv4_valid_methods, error);
|
||||
|
|
@ -3871,7 +3871,7 @@ static gboolean
|
|||
nmc_property_ipv6_set_method (NMSetting *setting, const char *prop, const char *val, GError **error)
|
||||
{
|
||||
/* Silently accept "static" and convert to "manual" */
|
||||
if (val && strlen (val) > 1 && matches (val, "static") == 0)
|
||||
if (val && strlen (val) > 1 && matches (val, "static"))
|
||||
val = NM_SETTING_IP6_CONFIG_METHOD_MANUAL;
|
||||
|
||||
return check_and_set_string (setting, prop, val, ipv6_valid_methods, error);
|
||||
|
|
@ -5726,7 +5726,7 @@ get_answer (const char *prop, const char *value)
|
|||
else
|
||||
question = g_strdup_printf (_("Do you also want to clear '%s'? [yes]: "), prop);
|
||||
tmp_str = nmc_get_user_input (question);
|
||||
if (!tmp_str || matches (tmp_str, "yes") == 0)
|
||||
if (!tmp_str || matches (tmp_str, "yes"))
|
||||
answer = TRUE;
|
||||
g_free (tmp_str);
|
||||
g_free (question);
|
||||
|
|
@ -5922,7 +5922,7 @@ connection_master_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_
|
|||
g_print (_("Warning: setting %s.%s requires removing ipv4 and ipv6 settings\n"),
|
||||
nm_setting_get_name (NM_SETTING (s_con)), g_param_spec_get_name (pspec));
|
||||
tmp_str = nmc_get_user_input (_("Do you want to remove them? [yes] "));
|
||||
if (!tmp_str || matches (tmp_str, "yes") == 0) {
|
||||
if (!tmp_str || matches (tmp_str, "yes")) {
|
||||
if (s_ipv4)
|
||||
nm_connection_remove_setting (connection, G_OBJECT_TYPE (s_ipv4));
|
||||
if (s_ipv6)
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@
|
|||
|
||||
#include "utils.h"
|
||||
|
||||
int
|
||||
gboolean
|
||||
matches (const char *cmd, const char *pattern)
|
||||
{
|
||||
size_t len = strlen (cmd);
|
||||
if (!len || len > strlen (pattern))
|
||||
return -1;
|
||||
return memcmp (pattern, cmd, len);
|
||||
return memcmp (pattern, cmd, len) == 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -58,9 +58,9 @@ nmc_arg_is_help (const char *arg)
|
|||
{
|
||||
if (!arg)
|
||||
return FALSE;
|
||||
if ( matches (arg, "help") == 0
|
||||
|| (g_str_has_prefix (arg, "-") && matches (arg+1, "help") == 0)
|
||||
|| (g_str_has_prefix (arg, "--") && matches (arg+2, "help") == 0)) {
|
||||
if ( matches (arg, "help")
|
||||
|| (g_str_has_prefix (arg, "-") && matches (arg + 1, "help"))
|
||||
|| (g_str_has_prefix (arg, "--") && matches (arg + 2, "help"))) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
|
@ -79,7 +79,7 @@ nmc_arg_is_option (const char *str, const char *opt_name)
|
|||
|
||||
p = (str[1] == '-') ? str + 2 : str + 1;
|
||||
|
||||
return (*p ? (matches (p, opt_name) == 0) : FALSE);
|
||||
return (*p ? matches (p, opt_name) : FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ typedef enum {
|
|||
} NMCTriStateValue;
|
||||
|
||||
/* === Functions === */
|
||||
int matches (const char *cmd, const char *pattern);
|
||||
gboolean matches (const char *cmd, const char *pattern);
|
||||
int next_arg (int *argc, char ***argv);
|
||||
gboolean nmc_arg_is_help (const char *arg);
|
||||
gboolean nmc_arg_is_option (const char *arg, const char *opt_name);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue