/* Creates new tab with the specified name, which might be NULL. Returns newly * created tab on success or NULL on error. */ static pane_tab_t * tabs_new_pane(pane_tabs_t *ptabs, view_t *view, const char name[]) { pane_tab_t new_tab = {}; if(DA_EXTEND(ptabs->tabs) == NULL) { return NULL; } DA_COMMIT(ptabs->tabs); /* We're called from tabs_init() and just need to create internal structures * without cloning data (or it will leak). */ if(DA_SIZE(gtabs) == 0U) { ptabs->tabs[0] = new_tab; return &ptabs->tabs[0]; } clone_view(&new_tab.view, view); update_string(&new_tab.name, name); if(DA_SIZE(ptabs->tabs) == 1U) { ptabs->tabs[0] = new_tab; return &ptabs->tabs[0]; } memmove(ptabs->tabs + ptabs->current + 2, ptabs->tabs + ptabs->current + 1, sizeof(*ptabs->tabs)*(DA_SIZE(ptabs->tabs) - (ptabs->current + 2))); ptabs->tabs[ptabs->current + 1] = new_tab; return &ptabs->tabs[ptabs->current + 1]; }
/* Creates new global tab with the specified name, which might be NULL. Returns * zero on success, otherwise non-zero is returned. */ static int tabs_new_global(const char name[]) { global_tab_t new_tab = {}; if(DA_EXTEND(gtabs) == NULL) { return 1; } if(tabs_new_pane(&new_tab.left, &lwin, NULL) == NULL || tabs_new_pane(&new_tab.right, &rwin, NULL) == NULL) { free_global_tab(&new_tab); return 1; } update_string(&new_tab.name, name); capture_global_state(&new_tab); new_tab.preview.on = curr_stats.preview.on; DA_COMMIT(gtabs); /* We're called from tabs_init(). */ if(DA_SIZE(gtabs) == 1U) { gtabs[0U] = new_tab; return 0; } memmove(gtabs + current_tab + 2, gtabs + current_tab + 1, sizeof(*gtabs)*(DA_SIZE(gtabs) - (current_tab + 2))); gtabs[current_tab + 1] = new_tab; tabs_goto(current_tab + 1); return 0; }
/* Registers action handler for a particular combination of event and path * pattern. Event name is case insensitive. Returns zero on successful * registration or non-zero on error. */ static int add_aucmd(const char event[], const char pattern[], int negated, const char action[], vle_aucmd_handler handler) { char canonic_path[PATH_MAX]; aucmd_info_t *autocmd; char *regexp; autocmd = DA_EXTEND(autocmds); if(autocmd == NULL) { return 1; } if(strchr(pattern, '/') != NULL) { canonicalize_path(pattern, canonic_path, sizeof(canonic_path)); if(!is_root_dir(canonic_path)) { chosp(canonic_path); } pattern = canonic_path; } regexp = glob_to_regex(pattern, 1); if(regexp == NULL) { return 1; } if(regcomp(&autocmd->regex, regexp, REG_EXTENDED | REG_ICASE) != 0) { free(regexp); return 1; } free(regexp); autocmd->event = strdup(event); autocmd->pattern = strdup(pattern); autocmd->negated = negated; autocmd->action = strdup(action); autocmd->handler = handler; if(autocmd->event == NULL || autocmd->pattern == NULL || autocmd->action == NULL) { free_autocmd_data(autocmd); return 1; } DA_COMMIT(autocmds); /* TODO: sort by event name (case insensitive) and then by pattern? */ return 0; }