Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / wsutil / feature_list.c
blobfc0d057fb1aafaafce18b94069963691437d639d
1 /* feature_list.c
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
9 */
11 #include <stdbool.h>
13 #include "config.h"
15 #include <wsutil/feature_list.h>
17 #if !GLIB_CHECK_VERSION(2, 68, 0)
18 static GString*
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);
23 if (pos != NULL) {
24 g_string_erase(string, pos - string->str, strlen(find));
26 return string;
28 #endif
30 void
31 with_feature(feature_list l, const char *fmt, ...)
33 va_list arg;
34 GString *msg = g_string_new("+");
35 va_start(arg, fmt);
36 g_string_append_vprintf(msg, fmt, arg);
37 va_end(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);
42 #else
43 g_string_find_and_erase(msg, " version");
44 g_string_find_and_erase(msg, " based on");
45 #endif
46 *l = g_list_prepend(*l, g_string_free(msg, FALSE));
49 void
50 without_feature(feature_list l, const char *fmt, ...)
52 va_list arg;
53 GString *msg = g_string_new("-");
54 va_start(arg, fmt);
55 g_string_append_vprintf(msg, fmt, arg);
56 va_end(arg);
57 *l = g_list_prepend(*l, g_string_free(msg, FALSE));
60 static int
61 feature_sort_alpha(const void *a, const void *b)
63 return g_ascii_strcasecmp((char *)a + 1, (char *)b + 1);
66 void
67 sort_features(feature_list l)
69 *l = g_list_sort(*l, feature_sort_alpha);
72 void
73 separate_features(feature_list l, feature_list with_list, feature_list without_list)
75 GList *iter;
76 gchar *data;
77 for (iter = *l; iter != NULL; iter = iter->next) {
78 data = (gchar *)iter->data;
79 if (data[0] == '+')
80 *with_list = g_list_prepend(*with_list, g_strdup(data));
81 else
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);
88 void
89 free_features(feature_list l)
91 g_list_free_full(*l, g_free);
92 *l = NULL;