69 const char *rc_suffix =
"/.ug.rc";
75 strncpy(buf, getenv(
"HOME"), buf_len - 1);
76 strncat(buf, rc_suffix, buf_len - 1);
92 FILE *
f = fopen(
name,
"r");
118 fseek(s->
f, 0, SEEK_SET);
119 while (fgets(line,
sizeof(line), s->
f)) {
120 if (strncmp(prefix, line, strlen(prefix)) == 0) {
121 char *
suffix = line + strlen(prefix);
125 char *
item, *save_ptr, *tmp;
128 while ((
item = strtok_r(tmp,
" ", &save_ptr))) {
131 if (strlen(
item) == 0) {
158 const char *requested_name)
165 memset(prefix, 0,
sizeof(prefix));
167 snprintf(prefix,
sizeof(prefix) - 1,
"alias %s %s ",
168 req_item_class, requested_name);
181 memset(prefix, 0,
sizeof(prefix));
183 snprintf(prefix,
sizeof(prefix) - 1,
"capture-filter %s ",
195 fseek(s->
f, 0, SEEK_SET);
197 std::list<std::pair<std::string, std::string>> ret;
200 char prefix[1024] =
"";
201 snprintf(prefix,
sizeof prefix,
"alias capture ");
202 fseek(s->
f, 0, SEEK_SET);
203 while (fgets(line,
sizeof(line), s->
f)) {
204 if (line[strlen(line) - 1] ==
'\n')
205 line[strlen(line) - 1] =
'\0';
207 if (strncasecmp(prefix, line, strlen(prefix)) == 0) {
208 char *
suffix = line + strlen(prefix);
209 char *save_ptr, *
item;
210 if ((
item = strtok_r(
suffix,
" ", &save_ptr))) {
213 char *cfg = strtok_r(NULL,
" ", &save_ptr);
214 item = strtok_r(NULL,
" ", &save_ptr);
217 while ((
item = strtok_r(NULL,
" ", &save_ptr))) {
struct config_file * config_file_open(const char *name)
void config_file_close(struct config_file *s)
static string get_nth_word(struct config_file *s, const char *prefix, int index)
string config_file_get_capture_filter_for_alias(struct config_file *s, const char *alias)
std::list< std::pair< std::string, std::string > > get_configured_capture_aliases(struct config_file *s)
char * default_config_file(char *buf, int buf_len)
string config_file_get_alias(struct config_file *s, const char *req_item_class, const char *requested_name)
FILE * f
handle to config file, NULL if opening failed