config.c 19.3 KB
Newer Older
1
/* SPDX-License-Identifier: Zlib */
Moritz Lipp's avatar
Moritz Lipp committed
2

Sebastian Ramacher's avatar
Sebastian Ramacher committed
3 4
#include "config.h"

Moritz Lipp's avatar
Moritz Lipp committed
5 6
#include <stdlib.h>
#include <string.h>
7
#include <glib/gi18n-lib.h>
Moritz Lipp's avatar
Moritz Lipp committed
8

9
#include "commands.h"
Sebastian Ramacher's avatar
Sebastian Ramacher committed
10
#include "datastructures.h"
11
#include "internal.h"
Sebastian Ramacher's avatar
Sebastian Ramacher committed
12
#include "session.h"
13 14
#include "settings.h"
#include "shortcuts.h"
Sebastian Ramacher's avatar
Sebastian Ramacher committed
15
#include "template.h"
Sebastian Ramacher's avatar
Sebastian Ramacher committed
16
#include "utils.h"
Moritz Lipp's avatar
Moritz Lipp committed
17

Moritz Lipp's avatar
Moritz Lipp committed
18
#define COMMENT_PREFIX "\"#"
Moritz Lipp's avatar
Moritz Lipp committed
19

20
static void
Moritz Lipp's avatar
Moritz Lipp committed
21 22
cb_window_icon(girara_session_t* session, const char* UNUSED(name),
    girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
23 24 25
{
  g_return_if_fail(session != NULL && value != NULL);

26 27 28 29
  if (session->gtk.window == NULL) {
    return;
  }

30
  girara_set_window_icon(session, value);
31 32 33
}

static void
Moritz Lipp's avatar
Moritz Lipp committed
34 35
cb_font(girara_session_t* session, const char* UNUSED(name),
    girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
36 37 38
{
  g_return_if_fail(session != NULL && value != NULL);

39
  css_template_fill_font(session->private_data->csstemplate, value);
40 41
}

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
static void
cb_color(girara_session_t* session, const char* name,
    girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{
  g_return_if_fail(session != NULL && value != NULL);

  const char* str_value = value;

  GdkRGBA color = { 0, 0, 0, 0 };
  gdk_rgba_parse(&color, str_value);

  char* colorstr = gdk_rgba_to_string(&color);
  girara_template_set_variable_value(session->private_data->csstemplate, name, colorstr);
  g_free(colorstr);
}

Moritz Lipp's avatar
Moritz Lipp committed
58 59 60 61 62 63 64 65 66
static void
cb_guioptions(girara_session_t* session, const char* UNUSED(name),
    girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{
  g_return_if_fail(session != NULL && value != NULL);

  /* set default values */
  bool show_commandline = false;
  bool show_statusbar   = false;
67 68
  bool show_hscrollbar  = false;
  bool show_vscrollbar  = false;
Moritz Lipp's avatar
Moritz Lipp committed
69 70

  /* evaluate input */
71 72
  char* input               = (char*) value;
  const size_t input_length = strlen(input);
Moritz Lipp's avatar
Moritz Lipp committed
73

74
  for (size_t i = 0; i < input_length; i++) {
Moritz Lipp's avatar
Moritz Lipp committed
75 76 77 78 79 80 81 82 83
    switch (input[i]) {
      /* command line */
      case 'c':
        show_commandline = true;
        break;
      /* statusbar */
      case 's':
        show_statusbar = true;
        break;
84 85 86 87 88 89
      case 'h':
        show_hscrollbar = true;
        break;
      case 'v':
        show_vscrollbar = true;
        break;
Moritz Lipp's avatar
Moritz Lipp committed
90 91 92 93 94 95 96 97 98 99 100 101 102
    }
  }

  /* apply settings */
  if (show_commandline == true) {
    session->global.autohide_inputbar = false;
    gtk_widget_show(session->gtk.inputbar);
  } else {
    session->global.autohide_inputbar = true;
    gtk_widget_hide(session->gtk.inputbar);
  }

  if (show_statusbar == true) {
103
    session->global.hide_statusbar = false;
Moritz Lipp's avatar
Moritz Lipp committed
104 105
    gtk_widget_show(session->gtk.statusbar);
  } else {
106
    session->global.hide_statusbar = true;
Moritz Lipp's avatar
Moritz Lipp committed
107 108
    gtk_widget_hide(session->gtk.statusbar);
  }
109

110 111
  scrolled_window_set_scrollbar_visibility(
    GTK_SCROLLED_WINDOW(session->gtk.view), show_hscrollbar, show_vscrollbar);
Moritz Lipp's avatar
Moritz Lipp committed
112
}
113

114
static void
115
cb_scrollbars(girara_session_t* session, const char* name,
116 117 118 119
    girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{
  g_return_if_fail(session != NULL && value != NULL);

120
  const bool val = *(bool*) value;
121

122 123 124
  char* guioptions = NULL;
  girara_setting_get(session, "guioptions", &guioptions);
  g_return_if_fail(guioptions != NULL);
125

126 127
  bool show_hscrollbar = strchr(guioptions, 'h') != NULL;
  bool show_vscrollbar = strchr(guioptions, 'v') != NULL;
128

Sebastian Ramacher's avatar
Sebastian Ramacher committed
129
  if (g_strcmp0(name, "show-scrollbars") == 0) {
130
    show_hscrollbar = show_vscrollbar = val;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
131
  } else if (g_strcmp0(name, "show-h-scrollbar") == 0) {
132
    show_hscrollbar = val;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
133
  } else if (g_strcmp0(name, "show-v-scrollbar") == 0) {
134 135 136
    show_vscrollbar = val;
  }

137
  const size_t guioptions_len = strlen(guioptions);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
138
  char* new_guioptions        = g_try_malloc0(sizeof(char) * (guioptions_len + 3));
139
  char* iterator              = new_guioptions;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
140 141 142 143
  if (new_guioptions == NULL) {
    g_free(guioptions);
    return;
  }
144

145 146 147 148 149 150
  /* copy everything apart from h and v */
  for (size_t i = 0; i != guioptions_len; ++i) {
    if (guioptions[i] != 'h' && guioptions[i] != 'v') {
      *iterator = guioptions[i];
      ++iterator;
    }
151
  }
152
  g_free(guioptions);
153

154 155 156 157 158 159 160
  if (show_hscrollbar == true) {
    *iterator = 'h';
    ++iterator;
  }
  if (show_vscrollbar == true) {
    *iterator = 'v';
    ++iterator;
161
  }
162 163 164

  girara_setting_set(session, "guioptions", new_guioptions);
  g_free(new_guioptions);
165 166
}

167 168 169 170 171 172 173 174
void
girara_config_load_default(girara_session_t* session)
{
  if (session == NULL) {
    return;
  }

  /* values */
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
175 176
  int statusbar_h_padding   = 8;
  int statusbar_v_padding   = 2;
177 178 179 180 181
  int window_width          = 800;
  int window_height         = 600;
  int n_completion_items    = 15;
  bool show_scrollbars      = false;
  girara_mode_t normal_mode = session->modes.normal;
182
  bool use_smooth_scroll    = false;
183

Moritz Lipp's avatar
Moritz Lipp committed
184 185 186
  /* other values */
  session->global.autohide_inputbar = true;

187 188
  /* settings */
  girara_setting_add(session, "font",                     "monospace normal 9", STRING,  FALSE, _("Font"), cb_font, NULL);
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
  girara_setting_add(session, "default-fg",               "#DDDDDD",            STRING,  FALSE,  _("Default foreground color"), cb_color, NULL);
  girara_setting_add(session, "default-bg",               "#000000",            STRING,  FALSE,  _("Default background color"), cb_color, NULL);
  girara_setting_add(session, "inputbar-fg",              "#9FBC00",            STRING,  FALSE,  _("Inputbar foreground color"), cb_color, NULL);
  girara_setting_add(session, "inputbar-bg",              "#131313",            STRING,  FALSE,  _("Inputbar background color"), cb_color, NULL);
  girara_setting_add(session, "statusbar-fg",             "#FFFFFF",            STRING,  FALSE,  _("Statusbar foreground color"), cb_color, NULL);
  girara_setting_add(session, "statusbar-bg",             "#000000",            STRING,  FALSE,  _("Statsubar background color"), cb_color, NULL);
  girara_setting_add(session, "completion-fg",            "#DDDDDD",            STRING,  FALSE,  _("Completion foreground color"), cb_color, NULL);
  girara_setting_add(session, "completion-bg",            "#232323",            STRING,  FALSE,  _("Completion background color"), cb_color, NULL);
  girara_setting_add(session, "completion-group-fg",      "#DEDEDE",            STRING,  FALSE,  _("Completion group foreground color"), cb_color, NULL);
  girara_setting_add(session, "completion-group-bg",      "#000000",            STRING,  FALSE,  _("Completion group background color"), cb_color, NULL);
  girara_setting_add(session, "completion-highlight-fg",  "#232323",            STRING,  FALSE,  _("Completion highlight foreground color"), cb_color, NULL);
  girara_setting_add(session, "completion-highlight-bg",  "#9FBC00",            STRING,  FALSE,  _("Completion highlight background color"), cb_color, NULL);
  girara_setting_add(session, "notification-error-fg",    "#FFFFFF",            STRING,  FALSE,  _("Error notification foreground color"), cb_color, NULL);
  girara_setting_add(session, "notification-error-bg",    "#FF1212",            STRING,  FALSE,  _("Error notification background color"), cb_color, NULL);
  girara_setting_add(session, "notification-warning-fg",  "#000000",            STRING,  FALSE,  _("Warning notification foreground color"), cb_color, NULL);
  girara_setting_add(session, "notification-warning-bg",  "#F3F000",            STRING,  FALSE,  _("Warning notifaction background color"), cb_color, NULL);
  girara_setting_add(session, "notification-fg",          "#000000",            STRING,  FALSE,  _("Notification foreground color"), cb_color, NULL);
  girara_setting_add(session, "notification-bg",          "#FFFFFF",            STRING,  FALSE,  _("Notification background color"), cb_color, NULL);
  girara_setting_add(session, "scrollbar-fg",             "#DDDDDD",            STRING,  FALSE,  _("Scrollbar foreground color"), cb_color, NULL);
  girara_setting_add(session, "scrollbar-bg",             "#000000",            STRING,  FALSE,  _("Scrollbar background color"), cb_color, NULL);
209 210 211
  girara_setting_add(session, "word-separator",           " /.-=&#?",           STRING,  TRUE,  NULL, NULL, NULL);
  girara_setting_add(session, "window-width",             &window_width,        INT,     TRUE,  _("Initial window width"), NULL, NULL);
  girara_setting_add(session, "window-height",            &window_height,       INT,     TRUE,  _("Initial window height"), NULL, NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
212 213
  girara_setting_add(session, "statusbar-h-padding",      &statusbar_h_padding, INT,     TRUE,  _("Horizontal padding for the status, input, and notification bars"), NULL, NULL);
  girara_setting_add(session, "statusbar-v-padding",      &statusbar_v_padding, INT,     TRUE,  _("Vertical padding for the status, input, and notification bars"), NULL, NULL);
214
  girara_setting_add(session, "n-completion-items",       &n_completion_items,  INT,     TRUE,  _("Number of completion items"), NULL, NULL);
215 216 217
  girara_setting_add(session, "show-scrollbars",          &show_scrollbars,     BOOLEAN, FALSE, _("Show both the horizontal and vertical scrollbars"), cb_scrollbars, NULL);
  girara_setting_add(session, "show-h-scrollbar",         &show_scrollbars,     BOOLEAN, FALSE, _("Show the horizontal scrollbar"), cb_scrollbars, NULL);
  girara_setting_add(session, "show-v-scrollbar",         &show_scrollbars,     BOOLEAN, FALSE, _("Show the vertical scrollbar"), cb_scrollbars, NULL);
218 219
  girara_setting_add(session, "window-icon",              "",                   STRING,  FALSE, _("Window icon"), cb_window_icon, NULL);
  girara_setting_add(session, "exec-command",             "",                   STRING,  FALSE, _("Command to execute in :exec"), NULL, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
220
  girara_setting_add(session, "guioptions",               "s",                  STRING,  FALSE, _("Show or hide certain GUI elements"), cb_guioptions, NULL);
221
  girara_setting_add(session, "smooth-scroll",            &use_smooth_scroll,   BOOLEAN, TRUE,  _("Enable smooth scrolling and zooming"), NULL, NULL);
222 223

  /* shortcuts */
224 225 226 227 228
  girara_shortcut_add(session, 0,                GDK_KEY_Escape,      NULL, girara_sc_abort,           normal_mode, 0, NULL);
  girara_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_bracketleft, NULL, girara_sc_abort,           normal_mode, 0, NULL);
  girara_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_c,           NULL, girara_sc_abort,           normal_mode, 0, NULL);
  girara_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_q,           NULL, girara_sc_quit,            normal_mode, 0, NULL);
  girara_shortcut_add(session, 0,                GDK_KEY_colon,       NULL, girara_sc_focus_inputbar,  normal_mode, 0, ":");
229 230

  /* inputbar shortcuts */
231
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_j,            girara_isc_activate,            0,                           NULL);
232
  girara_inputbar_shortcut_add(session, 0,                GDK_KEY_Escape,       girara_isc_abort,               0,                           NULL);
Matthew hague's avatar
Matthew hague committed
233
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_bracketleft,  girara_isc_abort,               0,                           NULL);
234 235 236 237 238 239 240 241 242 243 244 245 246
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_c,            girara_isc_abort,               0,                           NULL);
  girara_inputbar_shortcut_add(session, 0,                GDK_KEY_Tab,          girara_isc_completion,          GIRARA_NEXT,                 NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_Tab,          girara_isc_completion,          GIRARA_NEXT_GROUP,           NULL);
  girara_inputbar_shortcut_add(session, 0,                GDK_KEY_ISO_Left_Tab, girara_isc_completion,          GIRARA_PREVIOUS,             NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_ISO_Left_Tab, girara_isc_completion,          GIRARA_PREVIOUS_GROUP,       NULL);
  girara_inputbar_shortcut_add(session, 0,                GDK_KEY_BackSpace,    girara_isc_string_manipulation, GIRARA_DELETE_LAST_CHAR,     NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_h,            girara_isc_string_manipulation, GIRARA_DELETE_LAST_CHAR,     NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_u,            girara_isc_string_manipulation, GIRARA_DELETE_TO_LINE_START, NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_k,            girara_isc_string_manipulation, GIRARA_DELETE_TO_LINE_END,   NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_d,            girara_isc_string_manipulation, GIRARA_DELETE_CURR_CHAR,     NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_w,            girara_isc_string_manipulation, GIRARA_DELETE_LAST_WORD,     NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_f,            girara_isc_string_manipulation, GIRARA_NEXT_CHAR,            NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_b,            girara_isc_string_manipulation, GIRARA_PREVIOUS_CHAR,        NULL);
247 248
  girara_inputbar_shortcut_add(session, 0,                GDK_KEY_Right,        girara_isc_string_manipulation, GIRARA_NEXT_CHAR,            NULL);
  girara_inputbar_shortcut_add(session, 0,                GDK_KEY_Left,         girara_isc_string_manipulation, GIRARA_PREVIOUS_CHAR,        NULL);
249 250
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_a,            girara_isc_string_manipulation, GIRARA_GOTO_START,           NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_e,            girara_isc_string_manipulation, GIRARA_GOTO_END,             NULL);
Moritz Lipp's avatar
Moritz Lipp committed
251 252
  girara_inputbar_shortcut_add(session, 0,                GDK_KEY_Up,           girara_isc_command_history,     GIRARA_PREVIOUS,             NULL);
  girara_inputbar_shortcut_add(session, 0,                GDK_KEY_Down,         girara_isc_command_history,     GIRARA_NEXT,                 NULL);
253 254
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_p,            girara_isc_command_history,     GIRARA_PREVIOUS,             NULL);
  girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_n,            girara_isc_command_history,     GIRARA_NEXT,                 NULL);
255 256

  /* commands */
257 258 259 260 261 262 263 264
  girara_inputbar_command_add(session, "exec",  NULL, girara_cmd_exec,        NULL,          _("Execute a command"));
  girara_inputbar_command_add(session, "map",   "m",  girara_cmd_map,         NULL,          _("Map a key sequence"));
  girara_inputbar_command_add(session, "quit",  "q",  girara_cmd_quit,        NULL,          _("Quit the program"));
  girara_inputbar_command_add(session, "set",   "s",  girara_cmd_set,         girara_cc_set, _("Set an option"));
  girara_inputbar_command_add(session, "unmap", NULL, girara_cmd_unmap,       NULL,          _("Unmap a key sequence"));
#ifdef WITH_JSON
  girara_inputbar_command_add(session, "dump",  NULL, girara_cmd_dump_config, NULL,          _("Dump settings to a file"));
#endif
265 266 267 268 269 270 271

  /* config handle */
  girara_config_handle_add(session, "map",   girara_cmd_map);
  girara_config_handle_add(session, "set",   girara_cmd_set);
  girara_config_handle_add(session, "unmap", girara_cmd_unmap);

  /* shortcut mappings */
272 273 274 275 276 277 278
  girara_shortcut_mapping_add(session, "exec",             girara_sc_exec);
  girara_shortcut_mapping_add(session, "feedkeys",         girara_sc_feedkeys);
  girara_shortcut_mapping_add(session, "focus_inputbar",   girara_sc_focus_inputbar);
  girara_shortcut_mapping_add(session, "quit",             girara_sc_quit);
  girara_shortcut_mapping_add(session, "set",              girara_sc_set);
  girara_shortcut_mapping_add(session, "toggle_inputbar",  girara_sc_toggle_inputbar);
  girara_shortcut_mapping_add(session, "toggle_statusbar", girara_sc_toggle_statusbar);
279 280
}

Moritz Lipp's avatar
Moritz Lipp committed
281 282 283
bool
girara_config_handle_add(girara_session_t* session, const char* identifier, girara_command_function_t handle)
{
284 285
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(identifier != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
286

287
  girara_session_private_t* session_private = session->private_data;
288 289
  bool found = false;

Moritz Lipp's avatar
Moritz Lipp committed
290
  /* search for existing config handle */
291
  GIRARA_LIST_FOREACH_BODY(session_private->config.handles, girara_config_handle_t*, data,
Sebastian Ramacher's avatar
Sebastian Ramacher committed
292
    if (g_strcmp0(data->identifier, identifier) == 0) {
293
      data->handle = handle;
294 295
      found = true;
      break;
Moritz Lipp's avatar
Moritz Lipp committed
296
    }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
297
  );
298

299 300 301
  if (found == false) {
    /* add new config handle */
    girara_config_handle_t* config_handle = g_slice_new(girara_config_handle_t);
Moritz Lipp's avatar
Moritz Lipp committed
302

303 304 305 306
    config_handle->identifier = g_strdup(identifier);
    config_handle->handle     = handle;
    girara_list_append(session_private->config.handles, config_handle);
  }
307 308 309

  return true;
}
Moritz Lipp's avatar
Moritz Lipp committed
310

311 312 313 314 315
void
girara_config_handle_free(girara_config_handle_t* handle)
{
  if (handle == NULL) {
    return;
Moritz Lipp's avatar
Moritz Lipp committed
316 317
  }

318 319
  g_free(handle->identifier);
  g_slice_free(girara_config_handle_t, handle);
Moritz Lipp's avatar
Moritz Lipp committed
320 321
}

322 323
static bool
config_parse(girara_session_t* session, const char* path)
Moritz Lipp's avatar
Moritz Lipp committed
324 325
{
  /* open file */
326
  FILE* file = girara_file_open(path, "r");
Moritz Lipp's avatar
Moritz Lipp committed
327 328

  if (file == NULL) {
329
    return false;
Moritz Lipp's avatar
Moritz Lipp committed
330 331 332 333
  }

  /* read lines */
  char* line = NULL;
Moritz Lipp's avatar
Moritz Lipp committed
334
  unsigned int line_number = 1;
Moritz Lipp's avatar
Moritz Lipp committed
335 336
  while ((line = girara_file_read_line(file)) != NULL) {
    /* skip empty lines and comments */
Moritz Lipp's avatar
Moritz Lipp committed
337
    if (strlen(line) == 0 || strchr(COMMENT_PREFIX, line[0]) != NULL) {
338
      g_free(line);
Moritz Lipp's avatar
Moritz Lipp committed
339 340 341
      continue;
    }

342 343
    girara_list_t* argument_list = girara_list_new();
    if (argument_list == NULL) {
344
      g_free(line);
345
      fclose(file);
346
      return false;
347 348
    }

349
    girara_list_set_free_function(argument_list, g_free);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
350 351 352 353

    gchar** argv = NULL;
    gint    argc = 0;

354
    if (g_shell_parse_argv(line, &argc, &argv, NULL) != FALSE) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
355
      for (int i = 1; i < argc; i++) {
356
        char* argument = g_strdup(argv[i]);
Moritz Lipp's avatar
Moritz Lipp committed
357
        girara_list_append(argument_list, (void*) argument);
358 359 360
      }
    } else {
      girara_list_free(argument_list);
361
      fclose(file);
362
      g_free(line);
363
      return false;
364
    }
Moritz Lipp's avatar
Moritz Lipp committed
365

366
    /* include gets a special treatment */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
367
    if (g_strcmp0(argv[0], "include") == 0) {
368 369
      if (argc != 2) {
        girara_warning("Could not process line %d in '%s': usage: include path.", line_number, path);
370
      } else {
371 372 373 374 375 376 377 378 379 380 381
        char* newpath = NULL;
        if (g_path_is_absolute(argv[1]) == TRUE) {
          newpath = g_strdup(argv[1]);
        } else {
          char* basename = g_path_get_dirname(path);
          char* tmp = g_build_filename(basename, argv[1], NULL);
          newpath = girara_fix_path(tmp);
          g_free(tmp);
          g_free(basename);
        }

Sebastian Ramacher's avatar
Sebastian Ramacher committed
382
        if (g_strcmp0(newpath, path) == 0) {
383 384 385
          girara_warning("Could not process line %d in '%s': trying to include itself.", line_number, path);
        } else {
          girara_debug("Loading config file '%s'.", newpath);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
386
          if (config_parse(session, newpath) == false) {
387 388 389 390 391 392 393
            girara_warning("Could not process line %d in '%s': failed to load '%s'.", line_number, path, newpath);
          }
        }
        g_free(newpath);
      }
    } else {
      /* search for config handle */
394
      girara_session_private_t* session_private = session->private_data;
395
      girara_config_handle_t* handle = NULL;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
396
      GIRARA_LIST_FOREACH_BODY(session_private->config.handles, girara_config_handle_t*, tmp,
397
        handle = tmp;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
398
        if (g_strcmp0(handle->identifier, argv[0]) == 0) {
399 400 401 402 403
          handle->handle(session, argument_list);
          break;
        } else {
          handle = NULL;
        }
Sebastian Ramacher's avatar
Sebastian Ramacher committed
404
      );
405 406 407

      if (handle == NULL) {
        girara_warning("Could not process line %d in '%s': Unknown handle '%s'", line_number, path, argv[0]);
Moritz Lipp's avatar
Moritz Lipp committed
408 409 410
      }
    }

Moritz Lipp's avatar
Moritz Lipp committed
411
    line_number++;
412 413
    girara_list_free(argument_list);
    g_strfreev(argv);
414
    g_free(line);
Moritz Lipp's avatar
Moritz Lipp committed
415
  }
416 417

  fclose(file);
418
  return true;
Moritz Lipp's avatar
Moritz Lipp committed
419
}
420 421 422 423 424 425

void
girara_config_parse(girara_session_t* session, const char* path)
{
  config_parse(session, path);
}