From f973f0841a52f5dce0d0eebf99fcba911c83f9c5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 31 Mar 2017 12:55:43 +0200 Subject: [PATCH] cli: merge NmcPrintFields into NmcOutputData and pass it directly to print_required_fields() --- clients/cli/common.c | 16 ++++----- clients/cli/connections.c | 26 ++++++++------ clients/cli/devices.c | 76 ++++++++++++++++++++------------------- clients/cli/general.c | 12 +++---- clients/cli/nmcli.h | 10 ++---- clients/cli/settings.c | 4 +-- clients/cli/utils.c | 38 +++++++++++--------- clients/cli/utils.h | 7 +++- 8 files changed, 101 insertions(+), 88 deletions(-) diff --git a/clients/cli/common.c b/clients/cli/common.c index 39b314f0a..e2e6dc1dd 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -103,8 +103,8 @@ print_ip4_config (NMIPConfig *cfg4, tmpl = nmc_fields_ip4_config; tmpl_len = sizeof (nmc_fields_ip4_config); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -190,8 +190,8 @@ print_ip6_config (NMIPConfig *cfg6, tmpl = nmc_fields_ip6_config; tmpl_len = sizeof (nmc_fields_ip6_config); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -275,8 +275,8 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, tmpl = nmc_fields_dhcp4_config; tmpl_len = sizeof (nmc_fields_dhcp4_config); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -322,8 +322,8 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, tmpl = nmc_fields_dhcp6_config; tmpl_len = sizeof (nmc_fields_dhcp6_config); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 0ddc4e139..6284a9d3c 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -793,12 +793,14 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_connection_get_id (connection)); - out.print_fields.indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL, + out.header_name = construct_header_name (base_hdr, nm_connection_get_id (connection)); + out.indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL, nmc_fields_settings_names, FALSE, NULL, NULL); nmc_fields_settings_names[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, &out.print_fields, nmc_fields_settings_names); + print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, + out.indices, out.header_name, + out.indent, nmc_fields_settings_names); } /* Loop through the required settings and print them. */ @@ -1220,12 +1222,14 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_active_connection_get_uuid (acon)); - out.print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_ALL, + out.header_name = construct_header_name (base_hdr, nm_active_connection_get_uuid (acon)); + out.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_ALL, nmc_fields_con_active_details_groups, FALSE, NULL, NULL); nmc_fields_con_active_details_groups[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, &out.print_fields, nmc_fields_con_active_details_groups); + print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, + out.indices, out.header_name, + out.indent, nmc_fields_con_active_details_groups); } /* Loop through the groups and print them. */ @@ -1245,7 +1249,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) /* Add field names */ tmpl = nmc_fields_con_active_details_general; tmpl_len = sizeof (nmc_fields_con_active_details_general); - out.print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL, + out.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1316,7 +1320,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) tmpl = nmc_fields_con_active_details_vpn; tmpl_len = sizeof (nmc_fields_con_active_details_vpn); - out.print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL, + out.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1810,13 +1814,13 @@ do_connections_show (NmCli *nmc, int argc, char **argv) tmpl = nmc_fields_con_show; tmpl_len = sizeof (nmc_fields_con_show); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err); + out.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err); if (err) goto finish; /* Add headers */ - out.print_fields.header_name = active_only ? _("NetworkManager active profiles") : - _("NetworkManager connection profiles"); + out.header_name = active_only ? _("NetworkManager active profiles") + : _("NetworkManager connection profiles"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); diff --git a/clients/cli/devices.c b/clients/cli/devices.c index e84b134a0..c934c51ce 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -976,8 +976,8 @@ print_bond_bridge_info (NMDevice *device, tmpl = nmc_fields_dev_show_master_prop; tmpl_len = sizeof (nmc_fields_dev_show_master_prop); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1046,8 +1046,8 @@ print_team_info (NMDevice *device, tmpl = nmc_fields_dev_show_team_prop; tmpl_len = sizeof (nmc_fields_dev_show_team_prop); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1108,14 +1108,16 @@ show_device_info (NMDevice *device, NmCli *nmc) NMC_OUTPUT_DATA_DEFINE_SCOPED (out); /* Main header (pretty only) */ - out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (device)); + out.header_name = construct_header_name (base_hdr, nm_device_get_iface (device)); /* Lazy way to retrieve sorted array from 0 to the number of dev fields */ - out.print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL, - nmc_fields_dev_show_general, FALSE, NULL, NULL); + out.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL, + nmc_fields_dev_show_general, FALSE, NULL, NULL); nmc_fields_dev_show_general[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, &out.print_fields, nmc_fields_dev_show_general); + print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, + out.indices, out.header_name, + out.indent, nmc_fields_dev_show_general); } /* Loop through the required sections and print them. */ @@ -1137,8 +1139,8 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_show_general; tmpl_len = sizeof (nmc_fields_dev_show_general); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_GENERAL_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_GENERAL_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1187,8 +1189,8 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_show_cap; tmpl_len = sizeof (nmc_fields_dev_show_cap); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CAP_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CAP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1231,8 +1233,8 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_show_wifi_prop; tmpl_len = sizeof (nmc_fields_dev_show_wifi_prop); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1268,8 +1270,8 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_wifi_list; tmpl_len = sizeof (nmc_fields_dev_wifi_list); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1299,8 +1301,8 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_show_wired_prop; tmpl_len = sizeof (nmc_fields_dev_show_wired_prop); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1366,8 +1368,8 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_show_vlan_prop; tmpl_len = sizeof (nmc_fields_dev_show_vlan_prop); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1390,8 +1392,8 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_show_bluetooth; tmpl_len = sizeof (nmc_fields_dev_show_bluetooth); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1416,8 +1418,8 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_show_connections; tmpl_len = sizeof (nmc_fields_dev_show_connections); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL, - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1546,7 +1548,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv) tmpl = nmc_fields_dev_status; tmpl_len = sizeof (nmc_fields_dev_status); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device status': %s"), error->message); @@ -1555,7 +1557,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv) } /* Add headers */ - out.print_fields.header_name = _("Status of devices"); + out.header_name = _("Status of devices"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -2718,7 +2720,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) tmpl = nmc_fields_dev_wifi_list; tmpl_len = sizeof (nmc_fields_dev_wifi_list); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device wifi': %s"), error->message); @@ -2736,7 +2738,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) return NMC_RESULT_ERROR_NOT_FOUND; } /* Main header name */ - out.print_fields.header_name = (char *) construct_header_name (base_hdr, ifname); + out.header_name = construct_header_name (base_hdr, ifname); if (NM_IS_DEVICE_WIFI (device)) { if (bssid_user) { @@ -2803,8 +2805,8 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) continue; /* Main header name */ - out2.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (dev)); - out2.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); + out2.header_name = construct_header_name (base_hdr, nm_device_get_iface (dev)); + out2.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out2.output_data, arr); @@ -2847,9 +2849,9 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) NMC_OUTPUT_DATA_DEFINE_SCOPED (out2); /* Main header name */ - out2.print_fields.header_name = (char *) construct_header_name (base_hdr, - nm_device_get_iface (dev)); - out2.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); + out2.header_name = construct_header_name (base_hdr, + nm_device_get_iface (dev)); + out2.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); if (NM_IS_DEVICE_WIFI (dev)) { if (empty_line) @@ -3726,9 +3728,9 @@ show_device_lldp_list (NMDevice *device, NmCli *nmc, char *fields_str, int *coun tmpl_len = sizeof (nmc_fields_dev_lldp_list); /* Main header name */ - out.print_fields.header_name = (char *) construct_header_name (_("Device LLDP neighbors"), - nm_device_get_iface (device)); - out.print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, NULL); + out.header_name = construct_header_name (_("Device LLDP neighbors"), + nm_device_get_iface (device)); + out.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -3834,7 +3836,7 @@ do_device_lldp_list (NmCli *nmc, int argc, char **argv) else fields_str = nmc->required_fields; - out.print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, &error); + out.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device lldp list': %s"), error->message); diff --git a/clients/cli/general.c b/clients/cli/general.c index 71f3a626a..7c6752a27 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -336,7 +336,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl tmpl = nmc_fields_nm_status; tmpl_len = sizeof (nmc_fields_nm_status); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all); @@ -354,7 +354,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl wwan_hw_enabled = nm_client_wwan_hardware_get_enabled (nmc->client); wwan_enabled = nm_client_wwan_get_enabled (nmc->client); - out.print_fields.header_name = pretty_header_name ? (char *) pretty_header_name : _("NetworkManager status"); + out.header_name = pretty_header_name ?: _("NetworkManager status"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -486,7 +486,7 @@ print_permissions (void *user_data) tmpl = nmc_fields_nm_permissions; tmpl_len = sizeof (nmc_fields_nm_permissions); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message); @@ -495,7 +495,7 @@ print_permissions (void *user_data) return FALSE; } - out.print_fields.header_name = _("NetworkManager permissions"); + out.header_name = _("NetworkManager permissions"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -598,7 +598,7 @@ show_general_logging (NmCli *nmc) tmpl = nmc_fields_nm_logging; tmpl_len = sizeof (nmc_fields_nm_logging); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message); @@ -615,7 +615,7 @@ show_general_logging (NmCli *nmc) return FALSE; } - out.print_fields.header_name = _("NetworkManager logging"); + out.header_name = _("NetworkManager logging"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 0ee776d3c..373019263 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -128,12 +128,6 @@ typedef struct _NmcOutputField { const struct _NMMetaSettingInfoEditor *setting_info; } NmcOutputField; -typedef struct { - GArray *indices; /* Array of field indices to the array of allowed fields */ - char *header_name; /* Name of the output */ - int indent; /* Indent by this number of spaces */ -} NmcPrintFields; - typedef enum { NMC_USE_COLOR_AUTO, NMC_USE_COLOR_YES, @@ -150,7 +144,9 @@ typedef struct _NmcConfig { typedef struct _NmcOutputData { GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */ - NmcPrintFields print_fields; /* Structure with field indices to print */ + GArray *indices; /* Array of field indices to the array of allowed fields */ + const char *header_name; /* Name of the output */ + int indent; /* Indent by this number of spaces */ } NmcOutputData; /* NmCli - main structure */ diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 85f389281..241249215 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -1021,8 +1021,8 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean tmpl_len = sizeof (NmcOutputField) * (setting_info->properties_num + 1); tmpl = g_memdup (_get_nmc_output_fields (setting_info), tmpl_len); - out.print_fields.indices = parse_output_fields (one_prop ?: (s_all = _all_properties (setting_info)), - tmpl, FALSE, NULL, NULL); + out.indices = parse_output_fields (one_prop ?: (s_all = _all_properties (setting_info)), + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); diff --git a/clients/cli/utils.c b/clients/cli/utils.c index ec268a994..180e5c3a3 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -841,9 +841,9 @@ nmc_empty_output_fields (NmcOutputData *output_data) if (output_data->output_data->len > 0) g_ptr_array_remove_range (output_data->output_data, 0, output_data->output_data->len); - if (output_data->print_fields.indices) { - g_array_free (output_data->print_fields.indices, TRUE); - output_data->print_fields.indices = NULL; + if (output_data->indices) { + g_array_free (output_data->indices, TRUE); + output_data->indices = NULL; } } @@ -905,12 +905,17 @@ get_value_to_print (NmcColorOption color_option, /* * Print both headers or values of 'field_values' array. * Entries to print and their order are specified via indices in - * 'nmc->print_fields.indices' array. + * 'nmc->indices' array. * Various flags influencing the output of fields are set up in the first item * of 'field_values' array. */ void -print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const NmcPrintFields *print_fields, const NmcOutputField *field_values) +print_required_fields (const NmcConfig *nmc_config, + NmcOfFlags of_flags, + const GArray *indices, + const char *header_name, + int indent, + const NmcOutputField *field_values) { GString *str; int width1, width2; @@ -935,7 +940,7 @@ print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const N /* --- Main header --- */ if (main_header && pretty) { - int header_width = nmc_string_screen_width (print_fields->header_name, NULL) + 4; + int header_width = nmc_string_screen_width (header_name, NULL) + 4; if (multiline) { table_width = header_width < ML_HEADER_WIDTH ? ML_HEADER_WIDTH : header_width; @@ -945,10 +950,10 @@ print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const N line = g_strnfill (table_width, '='); } - width1 = strlen (print_fields->header_name); - width2 = nmc_string_screen_width (print_fields->header_name, NULL); + width1 = strlen (header_name); + width2 = nmc_string_screen_width (header_name, NULL); g_print ("%s\n", line); - g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, print_fields->header_name); + g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, header_name); g_print ("%s\n", line); g_free (line); } @@ -965,9 +970,9 @@ print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const N if (multiline) { - for (i = 0; i < print_fields->indices->len; i++) { + for (i = 0; i < indices->len; i++) { char *tmp; - int idx = g_array_index (print_fields->indices, int, i); + int idx = g_array_index (indices, int, i); gboolean is_array = field_values[idx].value_is_array; /* section prefix can't be an array */ @@ -1029,8 +1034,8 @@ print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const N str = g_string_new (NULL); - for (i = 0; i < print_fields->indices->len; i++) { - int idx = g_array_index (print_fields->indices, int, i); + for (i = 0; i < indices->len; i++) { + int idx = g_array_index (indices, int, i); gs_free char *val_to_free = NULL; const char *value = get_value_to_print (nmc_config->use_colors, (NmcOutputField *) field_values+idx, field_names, not_set_str, &val_to_free); @@ -1060,8 +1065,8 @@ print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const N /* Print actual values */ if (str->len > 0) { g_string_truncate (str, str->len-1); /* Chop off last column separator */ - if (print_fields->indent > 0) { - indent_str = g_strnfill (print_fields->indent, ' '); + if (indent > 0) { + indent_str = g_strnfill (indent, ' '); g_string_prepend (str, indent_str); g_free (indent_str); } @@ -1126,7 +1131,8 @@ print_data (const NmcConfig *nmc_config, const NmcOutputData *out) const NmcOutputField *field_values = g_ptr_array_index (out->output_data, i); print_required_fields (nmc_config, field_values[0].flags, - &out->print_fields, field_values); + out->indices, out->header_name, + out->indent, field_values); } } diff --git a/clients/cli/utils.h b/clients/cli/utils.h index bc85c45bc..1eef0513e 100644 --- a/clients/cli/utils.h +++ b/clients/cli/utils.h @@ -68,7 +68,12 @@ GArray *parse_output_fields (const char *fields_str, char *nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx); NmcOutputField *nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags); void nmc_empty_output_fields (NmcOutputData *output_data); -void print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const NmcPrintFields *print_fields, const NmcOutputField field_values[]); +void print_required_fields (const NmcConfig *nmc_config, + NmcOfFlags of_flags, + const GArray *indices, + const char *header_name, + int indent, + const NmcOutputField *field_values); void print_data_prepare_width (GPtrArray *output_data); void print_data (const NmcConfig *nmc_config, const NmcOutputData *out);