attr_dissector_fn_t
[wireshark-sm.git] / epan / ex-opt.c
blob95eecfcd8e2868094d820708ae3c61d32520f0b0
1 /*
2 * ex-opt.c
4 * Extension command line options
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include "config.h"
17 #include <glib.h>
18 #include "ex-opt.h"
20 static GHashTable* ex_opts;
22 bool ex_opt_add(const char* ws_optarg) {
23 char** splitted;
25 if (!ex_opts)
26 ex_opts = g_hash_table_new(g_str_hash,g_str_equal);
28 splitted = g_strsplit(ws_optarg,":",2);
30 if (splitted[0] && splitted[1]) {
31 GPtrArray* this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,splitted[0]);
33 if (this_opts) {
34 g_ptr_array_add(this_opts,splitted[1]);
35 g_free(splitted[0]);
36 } else {
37 this_opts = g_ptr_array_new();
38 g_ptr_array_add(this_opts,splitted[1]);
39 g_hash_table_insert(ex_opts,splitted[0],this_opts);
42 g_free(splitted);
44 return true;
45 } else {
46 g_strfreev(splitted);
47 return false;
51 int ex_opt_count(const char* key) {
52 GPtrArray* this_opts;
54 if (! ex_opts)
55 return 0;
57 this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
59 if (this_opts) {
60 return this_opts->len;
61 } else {
62 return 0;
66 const char* ex_opt_get_nth(const char* key, unsigned key_index) {
67 GPtrArray* this_opts;
69 if (! ex_opts)
70 return 0;
72 this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
74 if (this_opts) {
75 if (this_opts->len > key_index) {
76 return (const char *)g_ptr_array_index(this_opts,key_index);
77 } else {
78 /* XXX: assert? */
79 return NULL;
81 } else {
82 return NULL;
87 extern const char* ex_opt_get_next(const char* key) {
88 GPtrArray* this_opts;
90 if (! ex_opts)
91 return 0;
93 this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
95 if (this_opts) {
96 if (this_opts->len)
97 return (const char *)g_ptr_array_remove_index(this_opts,0);
98 else
99 return NULL;
100 } else {
101 return NULL;
106 * Editor modelines - https://www.wireshark.org/tools/modelines.html
108 * Local variables:
109 * c-basic-offset: 4
110 * tab-width: 8
111 * indent-tabs-mode: nil
112 * End:
114 * vi: set shiftwidth=4 tabstop=8 expandtab:
115 * :indentSize=4:tabSize=8:noTabs=true: