aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/feature_list.c
blob: 65acf40846e2d4c708ea2be90286fd91a9c06874 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* feature_list.c
 * Routines for gathering and handling lists of present/absent features
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <wsutil/feature_list.h>

void
with_feature(feature_list l, const char *fmt, ...)
{
    va_list arg;
    GString *msg = g_string_new("+");
    va_start(arg, fmt);
    g_string_append_vprintf(msg, fmt, arg);
    va_end(arg);
    *l = g_list_prepend(*l, g_string_free(msg, FALSE));
}

void
without_feature(feature_list l, const char *fmt, ...)
{
    va_list arg;
    GString *msg = g_string_new("-");
    va_start(arg, fmt);
    g_string_append_vprintf(msg, fmt, arg);
    va_end(arg);
    *l = g_list_prepend(*l, g_string_free(msg, FALSE));
}

static gint
feature_sort_alpha(gconstpointer a, gconstpointer b)
{
    return g_ascii_strcasecmp((gchar *)a + 1, (gchar *)b + 1);
}

void
sort_features(feature_list l)
{
    *l = g_list_sort(*l, feature_sort_alpha);
}

void
free_features(feature_list l)
{
    g_list_free_full(*l, g_free);
    *l = NULL;
}