2010-02-25 09:52:30 -08:00
|
|
|
/* nmcli - command-line tool to control NetworkManager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
2015-02-13 13:25:16 +01:00
|
|
|
* Copyright 2010 - 2015 Red Hat, Inc.
|
2010-02-25 09:52:30 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef NMC_UTILS_H
|
|
|
|
|
#define NMC_UTILS_H
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
#include "nmcli.h"
|
|
|
|
|
|
2013-01-16 12:26:45 +01:00
|
|
|
/* === Types === */
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
const char *name;
|
|
|
|
|
gboolean has_value;
|
|
|
|
|
const char **value;
|
|
|
|
|
gboolean mandatory;
|
|
|
|
|
gboolean found;
|
|
|
|
|
} nmc_arg_t;
|
|
|
|
|
|
2015-06-01 16:45:25 +02:00
|
|
|
typedef enum {
|
|
|
|
|
NMC_TRI_STATE_NO,
|
|
|
|
|
NMC_TRI_STATE_YES,
|
|
|
|
|
NMC_TRI_STATE_UNKNOWN,
|
|
|
|
|
} NMCTriStateValue;
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
/* === Functions === */
|
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
2017-02-15 12:20:55 +01:00
|
|
|
gboolean matches (const char *cmd, const char *pattern);
|
2010-02-25 09:52:30 -08:00
|
|
|
int next_arg (int *argc, char ***argv);
|
2013-04-18 11:25:49 +02:00
|
|
|
gboolean nmc_arg_is_help (const char *arg);
|
2013-11-07 14:47:12 +01:00
|
|
|
gboolean nmc_arg_is_option (const char *arg, const char *opt_name);
|
2013-01-16 12:26:45 +01:00
|
|
|
gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***argv, GError **error);
|
2013-05-16 16:26:15 +02:00
|
|
|
char *ssid_to_hex (const char *str, gsize len);
|
2013-01-16 12:28:37 +01:00
|
|
|
gboolean nmc_string_to_int_base (const char *str,
|
|
|
|
|
int base,
|
|
|
|
|
gboolean range_check,
|
|
|
|
|
long int min,
|
|
|
|
|
long int max,
|
|
|
|
|
long int *value);
|
|
|
|
|
gboolean nmc_string_to_uint_base (const char *str,
|
|
|
|
|
int base,
|
|
|
|
|
gboolean range_check,
|
|
|
|
|
unsigned long int min,
|
|
|
|
|
unsigned long int max,
|
|
|
|
|
unsigned long int *value);
|
|
|
|
|
gboolean nmc_string_to_int (const char *str,
|
|
|
|
|
gboolean range_check,
|
|
|
|
|
long int min,
|
|
|
|
|
long int max,
|
|
|
|
|
long int *value);
|
|
|
|
|
gboolean nmc_string_to_uint (const char *str,
|
|
|
|
|
gboolean range_check,
|
|
|
|
|
unsigned long int min,
|
|
|
|
|
unsigned long int max,
|
|
|
|
|
unsigned long int *value);
|
2013-04-06 23:25:38 +02:00
|
|
|
gboolean nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error);
|
2015-06-01 16:45:25 +02:00
|
|
|
gboolean nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError **error);
|
2012-04-28 22:32:21 +01:00
|
|
|
void nmc_terminal_erase_line (void);
|
|
|
|
|
void nmc_terminal_show_progress (const char *str);
|
2013-04-05 23:42:56 +02:00
|
|
|
const char *nmc_term_color_sequence (NmcTermColor color);
|
2015-02-17 13:20:37 +01:00
|
|
|
const char *nmc_term_format_sequence (NmcTermFormat format);
|
2015-06-10 17:41:53 +02:00
|
|
|
NmcTermColor nmc_term_color_parse_string (const char *str, GError **error);
|
2016-06-05 12:21:48 +02:00
|
|
|
char *nmc_colorize (NmCli *nmc, NmcTermColor color, NmcTermFormat format, const char * fmt, ...) _nm_printf (4, 5);
|
2015-02-13 13:25:16 +01:00
|
|
|
void nmc_filter_out_colors_inplace (char *str);
|
|
|
|
|
char *nmc_filter_out_colors (const char *str);
|
2012-11-21 16:53:23 +01:00
|
|
|
char *nmc_get_user_input (const char *ask_str);
|
2015-03-12 14:11:18 +01:00
|
|
|
int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote,
|
|
|
|
|
char ***argv, int *argc);
|
2013-04-08 09:25:44 +02:00
|
|
|
const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error);
|
2015-04-22 11:46:55 +02:00
|
|
|
char * nmc_util_strv_for_display (const char **strv, gboolean brackets);
|
2013-01-18 15:21:00 +01:00
|
|
|
char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens);
|
2010-04-26 17:32:18 +02:00
|
|
|
int nmc_string_screen_width (const char *start, const char *end);
|
2013-05-22 08:36:09 +02:00
|
|
|
void set_val_str (NmcOutputField fields_array[], guint32 index, char *value);
|
|
|
|
|
void set_val_strc (NmcOutputField fields_array[], guint32 index, const char *value);
|
|
|
|
|
void set_val_arr (NmcOutputField fields_array[], guint32 index, char **value);
|
|
|
|
|
void set_val_arrc (NmcOutputField fields_array[], guint32 index, const char **value);
|
2015-02-13 08:54:32 +01:00
|
|
|
void set_val_color_all (NmcOutputField fields_array[], NmcTermColor color);
|
2015-02-17 13:20:37 +01:00
|
|
|
void set_val_color_fmt_all (NmcOutputField fields_array[], NmcTermFormat format);
|
2013-03-25 10:44:15 -04:00
|
|
|
void nmc_free_output_field_values (NmcOutputField fields_array[]);
|
2013-12-10 12:00:53 +01:00
|
|
|
GArray *parse_output_fields (const char *fields_str,
|
|
|
|
|
const NmcOutputField fields_array[],
|
|
|
|
|
gboolean parse_groups,
|
|
|
|
|
GPtrArray **group_fields,
|
|
|
|
|
GError **error);
|
2013-11-07 14:47:12 +01:00
|
|
|
char *nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx);
|
2013-05-22 08:36:09 +02:00
|
|
|
NmcOutputField *nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags);
|
|
|
|
|
void nmc_empty_output_fields (NmCli *nmc);
|
|
|
|
|
void print_required_fields (NmCli *nmc, const NmcOutputField field_values[]);
|
|
|
|
|
void print_data (NmCli *nmc);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
#endif /* NMC_UTILS_H */
|