resource_address resource_system::resolve_address_to_file_in_directory( const char* resource_type_name, const resource_address& dir_address, const char* extensions, const char* id) { ASSERT(dir_address.is_directory()); ASSERT(dir_address.get_provider_type() == resource_provider_type::FILE_SYSTEM); if (is_string_empty(extensions)) { auto file_path = make_file_path(dir_address.get_path(), id); if (_file_system.does_file_exist(file_path)) { return make_resource_address_with_file_system_provider(true, file_path); } } for (auto& ext : split_string(extensions, ";")) { auto file_name = std::string(id) + ext; auto file_path = make_file_path(dir_address.get_path(), file_name); if (_file_system.does_file_exist(file_path)) { return make_resource_address_with_file_system_provider(true, file_path); } } ALERT("resource not found : {}{}\n\nresource_type: {}\ndirectory: {}", id, extensions, resource_type_name, dir_address.get_path()); return resource_address(); }
static void feel_1_fname(Button *m, Raster *rast, int x, int y, Names *entry, int why) { char *name; (void)rast; (void)x; (void)y; name = entry->name; if (name[0] == DIR_DELIM) /* a directory */ { if(why == SCR_ARROW) return; strcpy(und_drawer, fq_drawer); make_file_path(fq_drawer,name,fq_drawer); strcat(fq_drawer, DIR_DELIM_STR); init_stq_string(&drawer_stringq); if(new_drawer() < Success) { strcpy(fq_drawer,und_drawer); init_stq_string(&drawer_stringq); } } else { if(why & (SCR_MDHIT|SCR_ENTER)) mb_close_ok(m); setf_stringq(&ffile_sel,1,"%s", name); } }
Errcode load_default_flidef(Vset_flidef *fdef) /* used by flisize menu to load the flidef fields in the buttons */ { Errcode err; Chunkparse_data pd; XFILE *xf; char path[PATH_SIZE]; make_file_path(vb.init_drawer,default_name,path); err = xffopen(path, &xf, XREADONLY); if (err < Success) return err; init_chunkparse(&pd, xf, VSETFILE_MAGIC, 0, sizeof(Fat_chunk), 0); while (get_next_chunk(&pd)) { if (pd.type == VSET_FLIDEF_ID) { if (pd.fchunk.version == VSET_FLIDEF_VERS) { pd.error = read_parsed_chunk(&pd,fdef,sizeof(*fdef)); fdef->id.size = sizeof(*fdef); /* keep host size the same */ } else pd.error = Err_version; goto done; } } if (pd.error >= Success) pd.error = Err_no_chunk; done: xffclose(&xf); return pd.error; }
char *json_to_path(json_t *object, baton_error_t *error) { char *path = NULL; init_baton_error(error); const char *collection = get_collection_value(object, error); if (error->code != 0) goto error; if (represents_collection(object)) { path = make_dir_path(collection, error); } else { const char *data_object = get_data_object_value(object, error); path = make_file_path(collection, data_object, error); } if (error->code != 0) goto error; return path; error: if (path) free(path); return NULL; }
void save_default_settings(void) /* Write out copy of settings to default settings file */ { char path[PATH_SIZE]; make_file_path(vb.init_drawer,default_name,path); softerr(save_settings_file(path,TRUE),"!%s", "cant_save", path ); }
resource_address resource_system::resolve_address_with_file_system(bool is_file, const char* folder, const char* extensions, const char* id, const std::string& root_path) { if (is_file) { for (auto& ext : split_string(extensions, ";")) { auto file_name = std::string(id) + ext; auto file_path = make_file_path(root_path, folder, file_name); if (_file_system.does_file_exist(file_path)) { return make_resource_address_with_file_system_provider(true, file_path); } } } else { ASSERT(is_string_empty(extensions)); auto dir_path = make_file_path(root_path, folder, id); if (_file_system.does_directory_exist(dir_path)) { return make_resource_address_with_file_system_provider(false, dir_path); } } return resource_address(); }
char *json_to_local_path(json_t *object, baton_error_t *error) { char *path = NULL; init_baton_error(error); const char *directory = get_directory_value(object, error); if (error->code != 0) goto error; const char *filename = get_file_value(object, error); if (error->code != 0) goto error; const char *data_object = get_data_object_value(object, error); if (error->code != 0) goto error; if (directory && filename) { path = make_file_path(directory, filename, error); } else if (directory && data_object) { path = make_file_path(directory, data_object, error); } else if (filename) { path = make_file_path(".", filename, error); } else if (data_object) { path = make_file_path(".", data_object, error); } else if (directory) { path = make_dir_path(directory, error); } else { path = make_dir_path(".", error); } if (error->code != 0) goto error; return path; error: if (path) free(path); return NULL; }
Errcode load_default_settings(Vset_flidef *fdef) /*** called by open_default_flx() ***************/ { Errcode err; char path[PATH_SIZE]; close_zwinmenu(); make_file_path(vb.init_drawer,default_name,path); err = load_file_settings(path,fdef,TRUE); if(err < Success) { if(err != Err_no_file) softerr(err,"!%s","set_load", path ); vs = default_vs; pj_get_default_cmap(vb.screen->wndo.cmap); if((err = default_tsettings(fdef)) < Success) return(err); } rethink_settings(); see_cmap(); return(Success); }
void xml_compiler::reload(void) { error_information_.clear(); replacement_.clear(); symbol_map_.clear(); app_vector_.clear(); vk_change_inputsource_map_.clear(); inputsource_vector_.clear(); identifier_map_.clear(); essential_configurations_.clear(); remapclasses_initialize_vector_.clear(); preferences_checkbox_node_tree_.clear(); preferences_number_node_tree_.clear(); try { std::string private_xml_file_path = make_file_path(private_xml_directory_, "private.xml"); // ------------------------------------------------------------ // Loading replacement { replacement_loader loader(*this, replacement_); // private.xml { ptree_ptr ptree_ptr; pqrs::string::replacement dummy; // Use dummy replacement when we read <replacementdef>. read_xml_(ptree_ptr, private_xml_file_path, dummy); if (ptree_ptr) { loader.traverse(make_extracted_ptree(*ptree_ptr, private_xml_file_path)); } } // replacementdef.xml { ptree_ptr ptree_ptr; pqrs::string::replacement dummy; // Use dummy replacement when we read <replacementdef>. std::string xml_file_path = make_file_path(system_xml_directory_, "replacementdef.xml"); read_xml_(ptree_ptr, xml_file_path, dummy); if (ptree_ptr) { loader.traverse(make_extracted_ptree(*ptree_ptr, xml_file_path)); } } } // ------------------------------------------------------------ // Then, we read private.xml with replacement and loaders share it. ptree_ptr private_xml_ptree_ptr; read_xml_(private_xml_ptree_ptr, private_xml_file_path); if (private_xml_ptree_ptr && private_xml_ptree_ptr->empty()) { private_xml_ptree_ptr.reset(); } // symbol_map { symbol_map_loader loader(*this, symbol_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<symbol_map_loader>::traverse_system_xml(*this, loader, "symbol_map.xml"); } // app { app_loader loader(*this, symbol_map_, app_vector_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<app_loader>::traverse_system_xml(*this, loader, "appdef.xml"); } // device { device_loader loader(*this, symbol_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<device_loader>::traverse_system_xml(*this, loader, "devicevendordef.xml"); loader_wrapper<device_loader>::traverse_system_xml(*this, loader, "deviceproductdef.xml"); loader_wrapper<device_loader>::traverse_system_xml(*this, loader, "devicelocationdef.xml"); } // inputsource { inputsource_loader loader(*this, symbol_map_, remapclasses_initialize_vector_, identifier_map_, vk_change_inputsource_map_, inputsource_vector_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<inputsource_loader>::traverse_system_xml(*this, loader, "vkchangeinputsourcedef.xml"); loader_wrapper<inputsource_loader>::traverse_system_xml(*this, loader, "inputsourcedef.xml"); } // config_index, remapclasses_initialize_vector, preferences_node { std::string checkbox_xml_file_path = make_file_path(system_xml_directory_, "checkbox.xml"); ptree_ptr checkbox_xml_ptree_ptr; read_xml_(checkbox_xml_ptree_ptr, checkbox_xml_file_path); std::string number_xml_file_path = make_file_path(system_xml_directory_, "number.xml"); ptree_ptr number_xml_ptree_ptr; read_xml_(number_xml_ptree_ptr, number_xml_file_path); // remapclasses_initialize_vector { // prepare { remapclasses_initialize_vector_prepare_loader<preferences_node_tree<preferences_number_node> > loader(*this, symbol_map_, essential_configurations_, &preferences_number_node_tree_); if (number_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*number_xml_ptree_ptr, number_xml_file_path)); loader.fixup(); } loader.cleanup(); } { remapclasses_initialize_vector_prepare_loader<preferences_node_tree<preferences_checkbox_node> > loader(*this, symbol_map_, essential_configurations_, &preferences_checkbox_node_tree_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); loader.fixup(); } if (checkbox_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*checkbox_xml_ptree_ptr, checkbox_xml_file_path)); loader.fixup(); } loader.cleanup(); } // ---------------------------------------- { remapclasses_initialize_vector_loader loader(*this, symbol_map_, remapclasses_initialize_vector_, identifier_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path), ""); } if (checkbox_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*checkbox_xml_ptree_ptr, checkbox_xml_file_path), ""); } } remapclasses_initialize_vector_.freeze(); } } } catch (std::exception& e) { error_information_.set(e.what()); } }
inline string make_file_path(string const& dir, string const& file_name, string const& extension) { return make_file_path(dir, make_file_name(file_name, extension)); }
void xml_compiler::reload(const std::string& checkbox_xml_file_name) { error_information_.clear(); replacement_warnings_.clear(); global_included_files_.clear(); replacement_.clear(); symbol_map_.clear(); modifier_map_.clear(); app_vector_.clear(); bundle_identifier_override_vector_.clear(); window_name_vector_.clear(); vk_change_inputsource_map_.clear(); inputsource_vector_.clear(); vk_open_url_map_.clear(); identifier_map_.clear(); essential_configurations_.clear(); remapclasses_initialize_vector_.clear(); preferences_checkbox_node_tree_.clear(); preferences_number_node_tree_.clear(); try { std::string private_xml_file_path = make_file_path(private_xml_directory_, "private.xml"); // ------------------------------------------------------------ // Loading replacement { replacement_loader loader(*this, replacement_); pqrs::string::replacement dummy; // Use dummy replacement when we read <replacementdef>. append_environments_to_replacement_(dummy); // private.xml { ptree_ptr ptree_ptr; read_xml_(ptree_ptr, private_xml_file_path, dummy); if (ptree_ptr) { loader.traverse(make_extracted_ptree(*ptree_ptr, private_xml_file_path, dummy)); } } // replacementdef.xml { ptree_ptr ptree_ptr; std::string xml_file_path = make_file_path(system_xml_directory_, "replacementdef.xml"); read_xml_(ptree_ptr, xml_file_path, dummy); if (ptree_ptr) { loader.traverse(make_extracted_ptree(*ptree_ptr, xml_file_path, dummy)); } } append_environments_to_replacement_(replacement_); } // Reset replacement warnings that occur during loading replacement. replacement_warnings_.clear(); // Reset global_included_files_ for each loading. global_included_files_.clear(); // ------------------------------------------------------------ // Then, we read private.xml with replacement and loaders share it. ptree_ptr private_xml_ptree_ptr; read_xml_(private_xml_ptree_ptr, private_xml_file_path); if (private_xml_ptree_ptr && private_xml_ptree_ptr->empty()) { private_xml_ptree_ptr.reset(); } // symbol_map { symbol_map_loader loader(*this, symbol_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<symbol_map_loader>::traverse_system_xml(*this, loader, "symbol_map.xml"); global_included_files_.clear(); } // modifier { modifier_loader loader(*this, symbol_map_, remapclasses_initialize_vector_, identifier_map_, modifier_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<modifier_loader>::traverse_system_xml(*this, loader, "modifierdef.xml"); global_included_files_.clear(); } // app { app_loader loader(*this, symbol_map_, app_vector_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<app_loader>::traverse_system_xml(*this, loader, "appdef.xml"); global_included_files_.clear(); } // bundle_identifier_override { bundle_identifier_override_loader loader(*this, symbol_map_, bundle_identifier_override_vector_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<bundle_identifier_override_loader>::traverse_system_xml(*this, loader, "bundleidentifieroverridedef.xml"); global_included_files_.clear(); } // window_name { window_name_loader loader(*this, symbol_map_, window_name_vector_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<window_name_loader>::traverse_system_xml(*this, loader, "windownamedef.xml"); global_included_files_.clear(); } // ui_element_role { ui_element_role_loader loader(*this, symbol_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<ui_element_role_loader>::traverse_system_xml(*this, loader, "uielementroledef.xml"); global_included_files_.clear(); } // device { device_loader loader(*this, symbol_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<device_loader>::traverse_system_xml(*this, loader, "devicevendordef.xml"); loader_wrapper<device_loader>::traverse_system_xml(*this, loader, "deviceproductdef.xml"); loader_wrapper<device_loader>::traverse_system_xml(*this, loader, "devicelocationdef.xml"); global_included_files_.clear(); } // inputsource { inputsource_loader loader(*this, symbol_map_, remapclasses_initialize_vector_, identifier_map_, vk_change_inputsource_map_, inputsource_vector_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<inputsource_loader>::traverse_system_xml(*this, loader, "vkchangeinputsourcedef.xml"); loader_wrapper<inputsource_loader>::traverse_system_xml(*this, loader, "inputsourcedef.xml"); global_included_files_.clear(); } // url { url_loader loader(*this, symbol_map_, remapclasses_initialize_vector_, identifier_map_, vk_open_url_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path)); } loader_wrapper<url_loader>::traverse_system_xml(*this, loader, "vkopenurldef.xml"); global_included_files_.clear(); } // config_index, remapclasses_initialize_vector, preferences_node { std::string checkbox_xml_file_path = make_file_path(system_xml_directory_, checkbox_xml_file_name); ptree_ptr checkbox_xml_ptree_ptr; read_xml_(checkbox_xml_ptree_ptr, checkbox_xml_file_path); std::string number_xml_file_path = make_file_path(system_xml_directory_, "number.xml"); ptree_ptr number_xml_ptree_ptr; read_xml_(number_xml_ptree_ptr, number_xml_file_path); // remapclasses_initialize_vector { // prepare { remapclasses_initialize_vector_prepare_loader<preferences_node_tree<preferences_number_node>> loader(*this, symbol_map_, essential_configurations_, &preferences_number_node_tree_); if (number_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*number_xml_ptree_ptr, number_xml_file_path), ""); loader.fixup(); } loader.cleanup(); global_included_files_.clear(); } { remapclasses_initialize_vector_prepare_loader<preferences_node_tree<preferences_checkbox_node>> loader(*this, symbol_map_, essential_configurations_, &preferences_checkbox_node_tree_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path), ""); loader.fixup(); } if (checkbox_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*checkbox_xml_ptree_ptr, checkbox_xml_file_path), ""); loader.fixup(); } loader.cleanup(); global_included_files_.clear(); } // ---------------------------------------- { remapclasses_initialize_vector_loader loader(*this, symbol_map_, remapclasses_initialize_vector_, identifier_map_); if (private_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*private_xml_ptree_ptr, private_xml_file_path), ""); } if (checkbox_xml_ptree_ptr) { loader.traverse(make_extracted_ptree(*checkbox_xml_ptree_ptr, checkbox_xml_file_path), ""); } global_included_files_.clear(); } remapclasses_initialize_vector_.freeze(); } } if (!replacement_warnings_.empty()) { error_information_.set(replacement_warnings_); } } catch (std::exception& e) { error_information_.set(e.what()); } }
char *make_resource_name(char *name, char *path_buf) { make_file_path(resource_dir, name, path_buf); return(path_buf); }
std::string make_file_path(const std::string& part1, const std::string& part2, const std::string& part3) { return make_file_path(make_file_path(part1, part2), part3); }
int evaluate(struct SLList *tokens) { struct SLList cmds; init_list(&cmds); IOModifier prev_mod = NO_MODIFIER; struct ExecutableCmd *exe = (struct ExecutableCmd *)malloc(sizeof(struct ExecutableCmd)); init_executable_cmd(exe); while (tokens->length != 0) { struct Token *tok = pop_front(tokens); // check for output redirection conflicts here. if ( prev_mod == PIPE ) { if (exe->output_redir_to) { // conflict // dump the token and cmd lists. destroy_token(tok); while ( (tok = pop_front(tokens)) ) destroy_token(tok); destroy_exe_cmd(exe); destroy_cmd_list(&cmds); fprintf(stderr, "error: syntax error in output redirection.\n"); return -1; } add_back(&cmds, exe); exe = (struct ExecutableCmd *)malloc(sizeof(struct ExecutableCmd)); init_executable_cmd(exe); prev_mod = NO_MODIFIER; } // use previous token's mod, if mod exists, // and this token's info to populate redirection of exe. if (prev_mod == INPUT_REDIR) { exe->input_redir_from = make_file_path(tok->name); } else if (prev_mod == OUTPUT_REDIR) { exe->output_redir_to = make_file_path(tok->name); } else if (prev_mod == ERR_OUTPUT_REDIR) { exe->err_output_redir_to = make_file_path(tok->name); } if ( prev_mod == NO_MODIFIER ) { if ( (exe->full_path = find_cmd(tok->name)) != NULL ) { exe->args = populate_args(tok); if (tok->mod == NO_MODIFIER) { add_back(&cmds, exe); } } else { fprintf(stderr, "error: not a valid command.\n"); destroy_token(tok); destroy_exe_cmd(exe); destroy_cmd_list(&cmds); return -1; } } else if (tok->mod == NO_MODIFIER) { add_back(&cmds, exe); } prev_mod = tok->mod; destroy_token(tok); } // Execute the commands. int exe_status = execute_cmds(&cmds); // TODO: destroy the cmds list. destroy_cmd_list(&cmds); // return 0 if everything went peachy. return exe_status; }