svector *load_text_file(const char *filename) { svector *vec; char *t; if(filename[0] == '/') return do_load_text_file(filename); t = expand_tilde(filename); if(t != NULL) { vec = do_load_text_file(t); delete[] t; return vec; } vec = search_text_file(config->project_dir, filename); if(vec != NULL) return vec; vec = search_text_file(config->home_style_dir, filename); if(vec != NULL) return vec; vec = search_text_file(config->env_style_dir, filename); if(vec != NULL) return vec; vec = search_text_file(config->sys_style_dir, filename); if(vec != NULL) return vec; error("Cannot locate text file <%s>", filename); return NULL; }
svector *search_text_file(const char *dir, const char *filename) { char *text_file; svector *vec; if(dir == NULL) // Possible if environment variable not set return NULL; text_file = combine_path(dir, filename); if(fexists(text_file)) { vec = do_load_text_file(text_file); delete[] text_file; return vec; } delete[] text_file; return NULL; }
/* * Read, parse, and validate a capture configuration file from either an on-disk * file or an in-memory buffer. * * To read from a file, specify @config_file, and use NULL for @buf. * To read from a buffer, specify @buf and @bufsize. * * @config must be initialized to all 0's. * * On success, 0 will be returned, and the resulting capture configuration will * be stored in @config. * * On failure, a positive error code will be returned, and the contents of * @config will be invalidated. */ int read_capture_config(const tchar *config_file, const void *buf, size_t bufsize, struct capture_config *config) { int ret; /* [PrepopulateList] is used for apply, not capture. But since we do * understand it, recognize it, thereby avoiding the unrecognized * section warning, but discard the resulting strings. * * We currently ignore [CompressionExclusionList] and * [CompressionFolderList]. This is a known issue that doesn't seem to * have any real consequences, so don't issue warnings about not * recognizing those sections. */ STRING_SET(prepopulate_pats); STRING_SET(compression_exclusion_pats); STRING_SET(compression_folder_pats); struct text_file_section sections[] = { {T("ExclusionList"), &config->exclusion_pats}, {T("ExclusionException"), &config->exclusion_exception_pats}, {T("PrepopulateList"), &prepopulate_pats}, {T("CompressionExclusionList"), &compression_exclusion_pats}, {T("CompressionFolderList"), &compression_folder_pats}, }; void *mem; ret = do_load_text_file(config_file, buf, bufsize, &mem, sections, ARRAY_LEN(sections), LOAD_TEXT_FILE_REMOVE_QUOTES, mangle_pat); if (ret) return ret; FREE(prepopulate_pats.strings); FREE(compression_exclusion_pats.strings); FREE(compression_folder_pats.strings); config->buf = mem; return 0; }