void HashtableInsert(const char *name, const char* ipaddr) { char ip[20]; if(inet_pton(AF_INET, ipaddr, ip) == 0) { printf("wrong ip adress\n"); return; } unsigned int pos = hash_str(name)%HASHTABLE_MAX_SIZE; HashNode *pNewNode = (HashNode*)malloc(sizeof(HashNode)); if(pNewNode == NULL) { printf("alloc memory fail\n"); return; } memset(pNewNode, 0, sizeof(HashNode)); FillStr(&(pNewNode->name), name); FillStr(&(pNewNode->ipaddr), ipaddr); if(!hashtable[pos]) { hashtable[pos] = pNewNode; hashtable_cur_size++; return; } HashNode *pHead = hashtable[pos]; while(pHead) { if(strcmp(pHead->name,name) == 0) { printf("%s already exists\n",name); return; } pHead = pHead; } pHead->pNext = pNewNode; hashtable_cur_size++; }
bool CCodeBlocksWorkspace::GenerateMakefile (const CString& FileName, CCodeBlocksBuildConfig& Config) { // generate individual makefiles for projects CString cwd = GetCurrentDir(); CString workspace_path = ExtractFilePath(FileName); if (!workspace_path.IsEmpty()) { ChangeDir(workspace_path); } // m_TargetNames.Clear(); m_MakefileNames.Clear(); m_TargetDeps.Clear(); for (size_t i = 0; i < m_Units.size(); i++) { CString project_name = m_Units[i]->m_FileName; //CString makefile_path = JoinPaths(workspace_path,ExtractFilePath(project_name)); CString makefile_path = ExtractFilePath(project_name); //CString makefile_pathname = JoinPaths(workspace_path,project_name+".mak"); CString makefile_pathname = project_name+".mak"; CString target_name = ChangeFileExt(project_name,""); CString makefile_name = ExtractFileName(makefile_pathname); target_name = CCodeBlocksProject::DecorateTargetName(target_name,Config.TargetNameCase()); CString target_deps; for (int j = 0; j < m_Units[i]->m_Depends.GetCount(); j++) { CString dep_name = ChangeFileExt(m_Units[i]->m_Depends[j],""); if (j>0) target_deps += " "; target_deps += CCodeBlocksProject::DecorateTargetName(dep_name,Config.TargetNameCase()); } m_TargetDeps.Insert(target_deps); m_TargetNames.Insert(target_name); m_MakefilePaths.Insert(makefile_path); m_MakefileNames.Insert(makefile_name); makefile_pathname = MakeNativePath(makefile_pathname); //std::cout<<"cwd "<<cwd.GetCString()<<std::endl; //std::cout<<"gen_makefile "<<makefile_pathname.GetCString()<<std::endl; m_Units[i]->m_Project.GenerateMakefile(makefile_pathname,Config); } // generate workspace makefile int active_platforms = 0; for (size_t pi = 0, pn = Config.Platforms().GetCount(); pi < pn; pi++) { if (Config.Platforms().Platform(pi)->Active()) active_platforms++; } bool single_platform = (1==active_platforms); for (size_t pi = 0, pn = Config.Platforms().GetCount(); pi < pn; pi++) { CPlatform *pl = Config.Platforms().Platform(pi); if (!pl->Active()) continue; CString makefile_path = ExtractFilePath(FileName); CString makefile_name = ExtractFileName(FileName); CString platform_suffix; if (!single_platform) platform_suffix = "."+LowerCase(pl->Name()); makefile_name += platform_suffix; ChangeDir(makefile_path); // begin makefile m_Makefile.Clear(); int section = 0; // head comment const int header_width = 80; m_Makefile.Header().Insert(FillStr("#",'-',"#",header_width)); #ifdef REVISION_NUMBER { CString rn = IntegerToString(REVISION_NUMBER); CString line = FillStr("# This makefile was generated by 'cbp2make' tool rev."+rn,' ',"#",header_width); m_Makefile.Header().Insert(line); } #else CString line = FillStr("# This makefile was generated by 'cbp2make' tool rev.",' ',"#",header_width) #endif m_Makefile.Header().Insert(FillStr("#",'-',"#",header_width)); m_Makefile.Header().Insert(""); section++; // macros CString line = pl->EvalWorkDir(); m_Makefile.AddMacro("WRKDIR",line,section); m_Makefile.AddMacro("MAKE",pl->Tool_Make(),section); section++; // targets CMakefileRule& rule_all = m_Makefile.AddRule("all",section); for (int i = 0; i < m_TargetNames.GetCount(); i++) { rule_all.Dependencies().Insert(m_TargetNames[i]); } section++; for (int i = 0; i < m_TargetNames.GetCount(); i++) { CString makefile_path = m_MakefilePaths[i]; CMakefileRule& rule_target = m_Makefile.AddRule(m_TargetNames[i],section); rule_target.Dependencies().Insert(m_TargetDeps[i]); line = "$(MAKE)"; if (!makefile_path.IsEmpty()) { line += " -C "+pl->ProtectPath(pl->Pd(makefile_path),Config.QuotePathMode()); } line += " all -f "+pl->ProtectPath(pl->Pd(m_MakefileNames[i])+platform_suffix,Config.QuotePathMode()); rule_target.Commands().Insert(line); } section++; // CMakefileRule& rule_clean = m_Makefile.AddRule("clean",section); for (int i = 0; i < m_TargetNames.GetCount(); i++) { rule_clean.Dependencies().Insert("clean_"+m_TargetNames[i]); } section++; for (int i = 0; i < m_TargetNames.GetCount(); i++) { CString makefile_path = m_MakefilePaths[i]; CMakefileRule& rule_clean_target = m_Makefile.AddRule("clean_"+m_TargetNames[i],section); line = "$(MAKE)"; if (!makefile_path.IsEmpty()) { line += " -C "+pl->ProtectPath(pl->Pd(makefile_path),Config.QuotePathMode()); } line += " clean -f "+pl->ProtectPath(pl->Pd(m_MakefileNames[i])+platform_suffix,Config.QuotePathMode()); rule_clean_target.Commands().Insert(line); } // save makefile CStringList& text = m_Makefile.Update(); text.SaveToFile(makefile_name); m_Makefile.Clear(); ChangeDir(cwd); } return true; }