void bmarks_find(const char tags[], bmarks_find_cb cb, void *arg) { char *clone = strdup(tags); size_t i; for(i = 0U; i < bmark_count; ++i) { int nmatches = 0; int nmismatches = 0; char *tag = clone, *state = NULL; while((tag = split_and_get(tag, ',', &state)) != NULL) { int match = 0; char *bmark_tag = bmarks[i].tags, *state = NULL; while((bmark_tag = split_and_get(bmark_tag, ',', &state)) != NULL) { if(strcmp(tag, bmark_tag) == 0) { match = 1; } } nmatches += match; nmismatches += !match; } if(nmatches != 0 && nmismatches == 0) { cb(bmarks[i].path, bmarks[i].tags, bmarks[i].timestamp, arg); } } free(clone); }
/* Sorts specified range of entries according to sorting groups option. */ static void sort_by_groups(dir_entry_t *entries, size_t nentries) { char **groups = NULL; int ngroups = 0; const int optimize = (view_sort_groups != view->sort_groups_g); int i; char *const copy = strdup(view_sort_groups); char *group = copy, *state = NULL; while((group = split_and_get(group, ',', &state)) != NULL) { ngroups = add_to_string_array(&groups, ngroups, 1, group); } free(copy); for(i = ngroups - (optimize ? 1 : 0); i >= 1; --i) { regex_t regex; (void)regcomp(®ex, groups[i], REG_EXTENDED | REG_ICASE); sort_by_key(entries, nentries, SK_BY_GROUPS, ®ex); regfree(®ex); } if(optimize && ngroups != 0) { sort_by_key(entries, nentries, SK_BY_GROUPS, &view->primary_group); } free_string_array(groups, ngroups); }
int iop_mkdir(io_args_t *const args) { const char *const path = args->arg1.path; const int create_parent = args->arg2.process_parents; const mode_t mode = args->arg3.mode; #ifndef _WIN32 enum { PATH_PREFIX_LEN = 0 }; #else enum { PATH_PREFIX_LEN = 2 }; #endif if(create_parent) { char *const partial_path = strdup(path); char *part = partial_path + PATH_PREFIX_LEN, *state = NULL; while((part = split_and_get(part, '/', &state)) != NULL) { if(is_dir(partial_path)) { continue; } /* Create intermediate directories with 0700 permissions. */ if(os_mkdir(partial_path, S_IRWXU) != 0) { (void)ioe_errlst_append(&args->result.errors, partial_path, errno, strerror(errno)); free(partial_path); return -1; } } #ifndef _WIN32 if(os_chmod(path, mode) != 0) { (void)ioe_errlst_append(&args->result.errors, partial_path, errno, strerror(errno)); free(partial_path); return 1; } #endif free(partial_path); return 0; } if(os_mkdir(path, mode) != 0) { (void)ioe_errlst_append(&args->result.errors, path, errno, strerror(errno)); return 1; } return 0; }
void bmarks_complete(int n, char *tags[], const char str[]) { const size_t len = strlen(str); size_t i; for(i = 0U; i < bmark_count; ++i) { char *tag = bmarks[i].tags, *state = NULL; while((tag = split_and_get(tag, ',', &state)) != NULL) { if(strncmp(tag, str, len) == 0 && !is_in_string_array(tags, n, tag)) { vle_compl_add_match(tag, ""); } } } vle_compl_finish_group(); vle_compl_add_last_match(str); }
/* Callback for listings of bookmarks. */ static void bmarks_cb(const char path[], const char tags[], time_t timestamp, void *arg) { menu_info *m = arg; char *line = format_str("%s: ", replace_home_part_strict(path)); size_t len = strlen(line); char *dup = strdup(tags); char *tag = dup, *state = NULL; while((tag = split_and_get(tag, ',', &state)) != NULL) { strappendch(&line, &len, '['); strappend(&line, &len, tag); strappendch(&line, &len, ']'); } free(dup); (void)add_to_string_array(&m->data, m->len, 1, path); m->len = put_into_string_array(&m->items, m->len, line); }