3 #include "trace2/tr2_cfg.h"
4 #include "trace2/tr2_sysenv.h"
6 static struct strbuf
**tr2_cfg_patterns
;
7 static int tr2_cfg_count_patterns
;
8 static int tr2_cfg_loaded
;
11 * Parse a string containing a comma-delimited list of config keys
12 * or wildcard patterns into a list of strbufs.
14 static int tr2_cfg_load_patterns(void)
20 return tr2_cfg_count_patterns
;
23 envvar
= tr2_sysenv_get(TR2_SYSENV_CFG_PARAM
);
24 if (!envvar
|| !*envvar
)
25 return tr2_cfg_count_patterns
;
27 tr2_cfg_patterns
= strbuf_split_buf(envvar
, strlen(envvar
), ',', -1);
28 for (s
= tr2_cfg_patterns
; *s
; s
++) {
29 struct strbuf
*buf
= *s
;
31 if (buf
->len
&& buf
->buf
[buf
->len
- 1] == ',')
32 strbuf_setlen(buf
, buf
->len
- 1);
33 strbuf_trim_trailing_newline(*s
);
37 tr2_cfg_count_patterns
= s
- tr2_cfg_patterns
;
38 return tr2_cfg_count_patterns
;
41 void tr2_cfg_free_patterns(void)
44 strbuf_list_free(tr2_cfg_patterns
);
45 tr2_cfg_count_patterns
= 0;
55 * See if the given config key matches any of our patterns of interest.
57 static int tr2_cfg_cb(const char *key
, const char *value
, void *d
)
60 struct tr2_cfg_data
*data
= (struct tr2_cfg_data
*)d
;
62 for (s
= tr2_cfg_patterns
; *s
; s
++) {
63 struct strbuf
*buf
= *s
;
64 int wm
= wildmatch(buf
->buf
, key
, WM_CASEFOLD
);
66 trace2_def_param_fl(data
->file
, data
->line
, key
, value
);
74 void tr2_cfg_list_config_fl(const char *file
, int line
)
76 struct tr2_cfg_data data
= { file
, line
};
78 if (tr2_cfg_load_patterns() > 0)
79 read_early_config(tr2_cfg_cb
, &data
);
82 void tr2_cfg_set_fl(const char *file
, int line
, const char *key
,
85 struct tr2_cfg_data data
= { file
, line
};
87 if (tr2_cfg_load_patterns() > 0)
88 tr2_cfg_cb(key
, value
, &data
);