mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 06:10:14 +01:00
libnm: use NMStrBuf in "gen-metadata-nm-settings-libnm-core.c"
It's more convenient to use, because we don't need to keep track (and free) the allocated string.
This commit is contained in:
parent
82384b8fd8
commit
4f4f9807a4
1 changed files with 18 additions and 17 deletions
|
|
@ -2,18 +2,23 @@
|
|||
|
||||
#include "libnm-core-impl/nm-default-libnm-core.h"
|
||||
|
||||
#include "libnm-glib-aux/nm-str-buf.h"
|
||||
#include "libnm-core-intern/nm-meta-setting-base.h"
|
||||
#include "libnm-core-intern/nm-core-internal.h"
|
||||
|
||||
#define INDENT 4
|
||||
|
||||
static char *
|
||||
_xml_escape_attribute(const char *value)
|
||||
static const char *
|
||||
_xml_escape_attr(NMStrBuf *sbuf, const char *value)
|
||||
{
|
||||
gs_free char *s = NULL;
|
||||
|
||||
nm_str_buf_reset(sbuf);
|
||||
s = g_markup_escape_text(value, -1);
|
||||
return g_strdup_printf("\"%s\"", s);
|
||||
nm_str_buf_append_c(sbuf, '"');
|
||||
nm_str_buf_append(sbuf, s);
|
||||
nm_str_buf_append_c(sbuf, '"');
|
||||
return nm_str_buf_get_str(sbuf);
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
|
@ -28,16 +33,15 @@ _indent_level(guint num_spaces)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
nm_auto_str_buf NMStrBuf sbuf1 = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_1000, FALSE);
|
||||
const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings();
|
||||
NMMetaSettingType meta_type;
|
||||
|
||||
g_print("<nm-setting-docs>\n");
|
||||
for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) {
|
||||
const NMSettInfoSetting *sis = &sett_info_settings[meta_type];
|
||||
const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type];
|
||||
nm_auto_unref_gtypeclass NMSettingClass *klass = NULL;
|
||||
gs_free char *tmp_s1 = NULL;
|
||||
gs_free char *tmp_s2 = NULL;
|
||||
const NMSettInfoSetting *sis = &sett_info_settings[meta_type];
|
||||
const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type];
|
||||
nm_auto_unref_gtypeclass NMSettingClass *klass = NULL;
|
||||
guint prop_idx;
|
||||
GType gtype;
|
||||
|
||||
|
|
@ -45,23 +49,20 @@ main(int argc, char *argv[])
|
|||
klass = g_type_class_ref(gtype);
|
||||
|
||||
g_print("%s<setting", _indent_level(INDENT));
|
||||
g_print(" name=%s", (tmp_s1 = _xml_escape_attribute(msi->setting_name)));
|
||||
g_print(" name=%s", _xml_escape_attr(&sbuf1, msi->setting_name));
|
||||
g_print(" >\n");
|
||||
|
||||
for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) {
|
||||
const NMSettInfoProperty *sip = &sis->property_infos[prop_idx];
|
||||
gs_free char *tmp2 = NULL;
|
||||
gs_free char *tmp3 = NULL;
|
||||
const NMSettInfoProperty *sip = &sis->property_infos[prop_idx];
|
||||
|
||||
g_print("%s<property", _indent_level(2 * INDENT));
|
||||
g_print(" name=%s", (tmp2 = _xml_escape_attribute(sip->name)));
|
||||
g_print(" name=%s", _xml_escape_attr(&sbuf1, sip->name));
|
||||
if (sip->is_deprecated)
|
||||
g_print("\n%sis-deprecated=\"1\"", _indent_level(2 * INDENT + 10));
|
||||
if (sip->property_type->dbus_type) {
|
||||
g_print(
|
||||
"\n%sdbus-type=%s",
|
||||
_indent_level(2 * INDENT + 10),
|
||||
(tmp3 = _xml_escape_attribute((const char *) sip->property_type->dbus_type)));
|
||||
g_print("\n%sdbus-type=%s",
|
||||
_indent_level(2 * INDENT + 10),
|
||||
_xml_escape_attr(&sbuf1, (const char *) sip->property_type->dbus_type));
|
||||
}
|
||||
if (sip->dbus_deprecated) {
|
||||
nm_assert(sip->property_type->dbus_type);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue