📄 nutconfdoc.cpp
字号:
return (CConfigItem *) m_items[i];}/*! * \brief Find NUTCOMPONENTOPTION by name. */NUTCOMPONENTOPTION *CNutConfDoc::FindOptionByName(NUTCOMPONENT * compo, char *name){ while (compo) { NUTCOMPONENTOPTION *opts = compo->nc_opts; while (opts) { if (strcmp(opts->nco_name, name) == 0) { return opts; } opts = opts->nco_nxt; } if ((opts = FindOptionByName(compo->nc_child, name)) != NULL) { return opts; } compo = compo->nc_nxt; } return NULL;}/*! * \brief Return the activation state of an item with a specified name. */bool CNutConfDoc::IsOptionActive(char *name){ NUTCOMPONENTOPTION *opt = FindOptionByName(m_root->nc_child, name); if (opt && opt->nco_active) { return true; } return false;}bool CNutConfDoc::IsRequirementProvided(NUTCOMPONENT *compo, char *requirement){ int i; while (compo) { if(compo->nc_enabled) { for (i = 0; compo->nc_provides[i]; i++) { if(strcmp(compo->nc_provides[i], requirement) == 0) { return true; } } NUTCOMPONENTOPTION *opts = compo->nc_opts; while (opts) { for (i = 0; opts->nco_provides[i]; i++) { if(strcmp(opts->nco_provides[i], requirement) == 0) { if(opts->nco_active) { return true; } } } opts = opts->nco_nxt; } if (IsRequirementProvided(compo->nc_child, requirement)) { return true; } } compo = compo->nc_nxt; } return false;}bool CNutConfDoc::IsRequirementProvided(char *requirement){ return IsRequirementProvided(m_root, requirement);}/*! * \brief Set value of an integer item. */bool CNutConfDoc::SetValue(CConfigItem & item, long nValue){ if (item.m_option) { if (item.m_option->nco_value) { free(item.m_option->nco_value); item.m_option->nco_value = NULL; } wxString str; str.Printf(wxT("%ld"), nValue); item.m_option->nco_value = strdup(str.fn_str()); Modify(true); } return true;}/*! * \brief Set value of a string item. */bool CNutConfDoc::SetValue(CConfigItem & item, const wxString & strValue){ if (item.m_option) { if (item.m_option->nco_value) { free(item.m_option->nco_value); } if (strValue.IsEmpty()) { item.m_option->nco_value = NULL; } else { item.m_option->nco_value = strdup(strValue.fn_str()); } item.m_option->nco_active = 1; Modify(true); CNutConfHint hint(&item, nutValueChanged); UpdateAllViews(NULL, &hint); } return true;}/*! * \brief Set value of a boolean item. */bool CNutConfDoc::SetActive(CConfigItem & item, bool bEnabled){ item.SetActive(bEnabled); RefreshComponents(m_root); Modify(true); CNutConfHint hint(&item, nutExternallyChanged); UpdateAllViews(NULL, &hint); return true;}/*! * \brief Return build tree path. */wxString CNutConfDoc::GetBuildTree(){ return wxGetApp().GetSettings()->m_buildpath;}/*! * \brief Return build tree path. */wxString CNutConfDoc::GetInstallDir(){ return wxGetApp().GetSettings()->m_lib_dir;}/*! * \brief Create all header amd make files. * * \return true on success, otherwise false. */bool CNutConfDoc::GenerateBuildTree(){ CSettings *cfg = wxGetApp().GetSettings(); wxBusyCursor wait; wxString ins_dir(cfg->m_lib_dir); if(ins_dir.IsEmpty()) { ins_dir = cfg->m_buildpath + wxT("/lib"); } wxLogMessage(wxT("Creating Makefiles for %s in %s"), cfg->m_platform.c_str(), cfg->m_buildpath.c_str()); if(CreateMakeFiles(m_root, cfg->m_buildpath.fn_str(), cfg->m_source_dir.fn_str(), cfg->m_platform.fn_str(), cfg->m_firstidir.fn_str(), cfg->m_lastidir.fn_str(), ins_dir.fn_str())) { return false; } wxLogMessage(wxT("Creating header files in %s"), cfg->m_buildpath.c_str()); if(CreateHeaderFiles(m_root, cfg->m_buildpath.fn_str())) { return false; } wxLogMessage(wxT("OK")); return true;}class CDirCopyTraverser : public wxDirTraverser{public: CDirCopyTraverser(wxString source, wxString target) : m_source(source) , m_target(target) { } virtual wxDirTraverseResult OnFile(const wxString& filename) { wxString sub = filename.Mid(m_source.Length()); wxFileName name(m_target + sub); if(!name.GetName().IsSameAs(wxT("Makedefs"), false) && !name.GetName().IsSameAs(wxT("Makerules"), false) && !name.GetName().IsSameAs(wxT("Makeburn"), false)) { ::wxCopyFile(filename, name.GetFullPath()); } return wxDIR_CONTINUE; } virtual wxDirTraverseResult OnDir(const wxString& dirname) { wxString sub = dirname.Mid(m_source.Length()); wxFileName name(m_target + sub); if(!name.GetName().IsSameAs(wxT("CVS"), true)) { name.Mkdir(0777, wxPATH_MKDIR_FULL); return wxDIR_CONTINUE; } return wxDIR_IGNORE; }private: wxString m_source; wxString m_target;};#ifdef _WIN32class CDirIccAvrProjectTraverser : public wxDirTraverser{public: CDirIccAvrProjectTraverser(wxString source, wxString target) : m_source(source) , m_target(target) { } virtual wxDirTraverseResult OnFile(const wxString& filename) { wxString sub = filename.Mid(m_source.Length()); wxFileName name(m_target + sub); if(name.GetExt().IsSameAs(wxT("src"), false)) { TransferSourcesFile(filename, name.GetFullPath()); } if(name.GetExt().IsSameAs(wxT("prj"), false)) { TransferProjectFile(filename, name.GetFullPath()); } return wxDIR_CONTINUE; } virtual wxDirTraverseResult OnDir(const wxString& dirname) { wxString sub = dirname.Mid(m_source.Length()); wxFileName name(m_target + sub); if(!name.GetName().IsSameAs(wxT("CVS"), true)) { name.Mkdir(0777, wxPATH_MKDIR_FULL); return wxDIR_CONTINUE; } return wxDIR_IGNORE; }private: wxString m_source; wxString m_target; bool TransferProjectFile(wxString source, wxString target) { bool in_section = false; wxFileInputStream f_source(source); if (!f_source.Ok()) { wxLogMessage(wxT("Failed to read from %s"), source.c_str()); return false; } wxFileOutputStream f_target(target); if (!f_target.Ok()) { wxLogMessage(wxT("Failed to write to %s"), target.c_str()); return false; } CSettings *cfg = wxGetApp().GetSettings(); wxTextInputStream istream(f_source); wxTextOutputStream ostream(f_target); for(;;) { wxString line = istream.ReadLine(); if (f_source.Eof() && line.IsEmpty()) { break; } if (in_section) { if (line.StartsWith(wxT("Edit1="))) { line.Empty(); if(!cfg->m_firstidir.IsEmpty()) { line += cfg->m_firstidir; } if (!line.IsEmpty()) { line += wxT(";"); } line += cfg->m_buildpath + wxT("\\include"); line += wxT(";") + cfg->m_source_dir + wxT("\\include"); if(!cfg->m_lastidir.IsEmpty()) { line += wxT(";") + cfg->m_lastidir; } line = wxT("Edit1=") + line; line.Replace(wxT("/"), wxT("\\")); } else if (line.StartsWith(wxT("Edit2="))) { line = wxT("Edit2=") + cfg->m_buildpath + wxT("\\lib"); line.Replace(wxT("/"), wxT("\\")); } else if (line.StartsWith(wxT("Edit3="))) { line = wxT("Edit3=ETHERNUT2 _MCU_enhanced __HARVARD_ARCH__"); } else if (line.StartsWith(wxT("Edit27="))) { line = wxT("Edit27=-ucrtnutram.o ") + cfg->m_buildpath + wxT("\\lib\\nutinit.o"); line.Replace(wxT("/"), wxT("\\")); } } else if (line[0] == '[') { in_section = line.IsSameAs(wxT("[Compiler Options]"), false); } ostream.WriteString(line + wxT("\n")); } return true; } bool TransferSourcesFile(wxString source, wxString target) { wxFileInputStream f_source(source); if (!f_source.Ok()) { wxLogMessage(wxT("Failed to read from %s"), source.c_str()); return false; } wxFileOutputStream f_target(target); if (!f_target.Ok()) { wxLogMessage(wxT("Failed to write to %s"), target.c_str()); return false; } wxTextInputStream istream(f_source); wxTextOutputStream ostream(f_target); for(;;) { wxString line = istream.ReadLine(); wxString rest; if (f_source.Eof() && line.IsEmpty()) { break; } if (line.StartsWith(wxT("..\\..\\app\\"), &rest)) { line = rest.AfterFirst('\\'); } ostream.WriteString(line + wxT("\n")); } return true; }};#endifbool CNutConfDoc::GenerateApplicationTree(){ CSettings *cfg = wxGetApp().GetSettings(); wxBusyCursor wait; wxString src_dir = cfg->m_source_dir + wxT("/app"); wxString cfg_inc = cfg->m_firstidir; wxLogMessage(wxT("Copying samples from %s to %s"), src_dir.c_str(), cfg->m_app_dir.c_str()); CDirCopyTraverser traverser(src_dir, cfg->m_app_dir); wxDir dir(src_dir); dir.Traverse(traverser);#ifdef _WIN32 src_dir = cfg->m_source_dir + wxT("/appicc"); wxLogMessage("Translating ICCAVR projects from %s to %s", src_dir.c_str(), cfg->m_app_dir.c_str()); CDirIccAvrProjectTraverser icc_traverser(src_dir, cfg->m_app_dir); wxDir icc_dir(src_dir); icc_dir.Traverse(icc_traverser);#endif wxLogMessage(wxT("Creating Makefiles for %s in %s"), cfg->m_platform.c_str(), cfg->m_app_dir.c_str()); wxString lib_dir(cfg->m_lib_dir); if(lib_dir.IsEmpty()) { lib_dir = cfg->m_buildpath + wxT("/lib"); } if(CreateSampleDirectory(m_root, cfg->m_buildpath.fn_str(), cfg->m_app_dir.fn_str(), cfg->m_source_dir.fn_str(), lib_dir.fn_str(), cfg->m_platform.fn_str(), cfg->m_programmer.fn_str(), cfg->m_firstidir.fn_str(), cfg->m_lastidir.fn_str())) { return false; } wxLogMessage(wxT("OK")); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -