/* macro_filter_func instantiation that filters out non-single element macros. * Returns the argument on allowed macro and '\0' otherwise. */ static char filter_single(int *quoted, char c, char data) { if(strchr("cCdD", c) != NULL) { *quoted = 0; return c; } if(c == 'f' && curr_view->selected_files <= 1) { return c; } if(c == 'F' && other_view->selected_files <= 1) { return c; } if(c == 'r') { reg_t *reg = regs_find(tolower(data)); if(reg != NULL && reg->nfiles == 1) { return c; } } return '\0'; }
/* Writes registers to vifminfo file. regs is a list of length nregs registers * read from vifminfo. */ static void write_registers(FILE *const fp, char *regs[], int nregs) { int i; fputs("\n# Registers:\n", fp); for(i = 0; i < nregs; i++) { fprintf(fp, "%s\n", regs[i]); } for(i = 0; valid_registers[i] != '\0'; i++) { const reg_t *const reg = regs_find(valid_registers[i]); if(reg != NULL) { int j; for(j = 0; j < reg->nfiles; ++j) { if(reg->files[j] != NULL) { fprintf(fp, "\"%c%s\n", reg->name, reg->files[j]); } } } } }
int regs_append(int reg_name, const char file[]) { reg_t *reg; if(reg_name == BLACKHOLE_REG_NAME) { return 0; } if((reg = regs_find(reg_name)) == NULL) { return 1; } if(!path_exists(file, NODEREF)) { return 1; } if(check_for_duplicate_file_names(reg, file)) { return 1; } reg->nfiles = add_to_string_array(®->files, reg->nfiles, 1, file); return 0; }
void regs_clear(int reg_name) { reg_t *const reg = regs_find(reg_name); if(reg == NULL) { return; } free_string_array(reg->files, reg->nfiles); reg->files = NULL; reg->nfiles = 0; }
/* Expands content of a register specified by the key argument considering * filename-modifiers. If key is unknown, falls back to the default register. * Sets *well_formed to non-zero for valid value of the key. Reallocates the * expanded string and returns result (possibly NULL). */ static char * expand_register(const char curr_dir[], char expanded[], int quotes, const char mod[], int key, int *well_formed, int for_shell) { int i; reg_t *reg; *well_formed = 1; reg = regs_find(tolower(key)); if(reg == NULL) { *well_formed = 0; reg = regs_find(DEFAULT_REG_NAME); assert(reg != NULL); mod--; } for(i = 0; i < reg->nfiles; ++i) { const char *const modified = apply_mods(reg->files[i], curr_dir, mod, for_shell); expanded = append_path_to_expanded(expanded, quotes, modified); if(i != reg->nfiles - 1) { expanded = append_to_expanded(expanded, " "); } } #ifdef _WIN32 if(for_shell && curr_stats.shell_type == ST_CMD) { to_back_slash(expanded); } #endif return expanded; }
void regs_pack(int reg_name) { int j, i; reg_t *const reg = regs_find(reg_name); if(reg == NULL) { return; } j = 0; for(i = 0; i < reg->nfiles; ++i) { if(reg->files[i] != NULL) { reg->files[j++] = reg->files[i]; } } reg->nfiles = j; }