2 * Routines for gathering and handling lists of present/absent features
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <wsutil/feature_list.h>
17 #if !GLIB_CHECK_VERSION(2, 68, 0)
19 g_string_find_and_erase(GString
*string
, const char* find
)
21 /* Find and erases find a single time. */
22 const char* pos
= strstr(string
->str
, find
);
24 g_string_erase(string
, pos
- string
->str
, strlen(find
));
31 with_feature(feature_list l
, const char *fmt
, ...)
34 GString
*msg
= g_string_new("+");
36 g_string_append_vprintf(msg
, fmt
, arg
);
38 /* Strip "version" from the string */
39 #if GLIB_CHECK_VERSION(2, 68, 0)
40 g_string_replace(msg
, " version", "", 0);
41 g_string_replace(msg
, " based on", "", 0);
43 g_string_find_and_erase(msg
, " version");
44 g_string_find_and_erase(msg
, " based on");
46 *l
= g_list_prepend(*l
, g_string_free(msg
, FALSE
));
50 without_feature(feature_list l
, const char *fmt
, ...)
53 GString
*msg
= g_string_new("-");
55 g_string_append_vprintf(msg
, fmt
, arg
);
57 *l
= g_list_prepend(*l
, g_string_free(msg
, FALSE
));
61 feature_sort_alpha(const void *a
, const void *b
)
63 return g_ascii_strcasecmp((char *)a
+ 1, (char *)b
+ 1);
67 sort_features(feature_list l
)
69 *l
= g_list_sort(*l
, feature_sort_alpha
);
73 separate_features(feature_list l
, feature_list with_list
, feature_list without_list
)
77 for (iter
= *l
; iter
!= NULL
; iter
= iter
->next
) {
78 data
= (gchar
*)iter
->data
;
80 *with_list
= g_list_prepend(*with_list
, g_strdup(data
));
82 *without_list
= g_list_prepend(*without_list
, g_strdup(data
));
84 *with_list
= g_list_reverse(*with_list
);
85 *without_list
= g_list_reverse(*without_list
);
89 free_features(feature_list l
)
91 g_list_free_full(*l
, g_free
);