//--------------------------------------------------------------- void CSF::InitSFAttrib() { CSFType * pType; CSFunction *pFun = GetFun(); m_Attr.SetAt("PORT_INP", (double) GetNumInVar()); m_Attr.SetAt("PORT_OUT", (double) GetNumOutVar()); m_Attr.SetAt("PORT_INTER", (double) GetNumInterVar()); m_Attr.SetAt("TYPE", (double) m_TypeMap.mtp.size()); m_Attr.SetAt("NET", (double) m_ElemTypeMap.size()); m_Attr.SetAt("CIRC_MACH", (double)COMB); m_Attr.SetAt("ERROR", 1); if ( GetFirstType(pType)) { do { if (pType->GetReg()) { m_Attr.SetAt("CIRC_MACH", MACHINE); break; } } while ( GetNextType(pType)); } m_Attr.SetAt("BIBL", (double)NOBIBL); if (pFun != NULL && pFun->GetTyp()=="LOG") m_Attr.SetAt("FUNCTION",FLOG); else if (pFun != NULL && pFun->GetTyp()=="SDF") m_Attr.SetAt("FUNCTION", FSDF); }
void CMapStringToType::Serialize(CArch& ar) { string key, s1="CMapStringToType"; CSFType *pType; int Count; if (ar.IsStoring()) { Count = mtp.size(); ar<<Count<<s1; itp=mtp.begin(); for (; itp!=mtp.end();) { GetNextAssoc(s1, *&pType); pType->Serialize(ar); } } else { ar>>Count>>key; if (key !=s1) { throw (-7); } for(int i=0; i<Count; i++) { pType = new CSFType; pType->Serialize(ar); mtp[pType->m_Name]=pType; } } }
//--------------------------------------------------------------- bool CSF::WriteSF(string FileName) { string Buf, Buf1, Buf0, endl; string one, two; // POSITION pos; map<string,string>::iterator pos; int i, j; CSFunction *pFun; endl = "\n"; FILE* f; try { f = fopen(FileName.c_str(),"a"); Buf = "TITLE "+GetTitle(); if (m_TitleComments != "") { Buf+= " /*"; Buf+= m_TitleComments; Buf += "*/"; } Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = "FORMAT SF"+endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = "AUTHOR "+GetAuthor(); if (m_AuthorComments != "") { Buf+= " /*"; Buf+= m_AuthorComments; Buf += "*/"; } Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = "DATE "+GetDate(); if (m_DateComments != "") { Buf+= " /*"; Buf+= m_DateComments; Buf += "*/"; } Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = "PROJECT "+GetProject(); if (m_ProjectComments != "") { Buf+= " /*"; Buf+= m_ProjectComments; Buf += "*/"; } Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = "DCL_PIN "; if (m_SFVarComments != "") { Buf+= " /*"; Buf+= m_SFVarComments; Buf += "*/"; } Buf += endl+ "EXT"; Buf += endl+ "INP" +endl; fwrite(Buf.c_str(), Buf.size(),1,f); WriteVar(f,'i', &m_SFVarArray); Buf = "OUT" +endl; fwrite(Buf.c_str(), Buf.size(),1,f); WriteVar(f, 'o', &m_SFVarArray); Buf = "INTER"+endl; fwrite(Buf.c_str(), Buf.size(),1,f); WriteVar(f, 't', &m_SFVarArray); Buf = endl; if (GetFirstPareInter(pos, one, two)) { Buf = one + "=" + two + endl; fwrite(Buf.c_str(), Buf.size(),1,f); while (GetNextPareInter(pos, one, two)) { Buf = one + "=" + two +endl; fwrite(Buf.c_str(), Buf.size(),1,f); } } Buf = "END_PIN"+endl; fwrite(Buf.c_str(), Buf.size(),1,f); CSFType * pType; if (GetFirstType(pType)) { Buf = "DCL_EL"+endl; if (m_TypeComments != "") { Buf+= " /*"; Buf+= m_TypeComments; Buf += "*/"+endl; } fwrite(Buf.c_str(), Buf.size(),1,f); do { if (pType->GetReg()) Buf = "TYPE_N " + pType->GetName() +endl; else Buf = "TYPE " + pType->GetName() +endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = ""; for (int i=0; i<(int)pType->m_ElemArray.size(); i++) { Buf += pType->m_ElemArray.at(i); Buf += " "; } Buf += endl + "INP" + endl; fwrite(Buf.c_str(), Buf.size(),1,f); WriteVar(f,'i', &(pType->m_SFVarArray)); Buf = "OUT"+endl; fwrite(Buf.c_str(), Buf.size(),1,f); WriteVar(f, 'o', &(pType->m_SFVarArray)); if (pType->GetLib() != "") { Buf = "LIB " + pType->GetLib() + endl; fwrite(Buf.c_str(), Buf.size(),1,f); } } while (GetNextType(pType)); Buf = "END_EL" + endl; fwrite(Buf.c_str(), Buf.size(),1,f); } i = 0; CSFConnect *pCon = GetConnect(i); if (pCon != NULL) { Buf = "CONNECT "; if (m_ConnectComments != "") { Buf+= " /*"; Buf+= m_ConnectComments; Buf += "*/"; } Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); for (pCon = GetConnect(i=0); pCon != NULL; pCon = GetConnect(i)) { i++; Buf = pCon->GetName() + endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = ""; if (pCon->GetFirstPare(one, two)) { while (1) { Buf += one + "=" + two + " "; if (Buf.size() >70) { Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = ""; } //if (!pos) break; if (pCon->GetNextPare(one, two)==false) break; } } else Buf = " "; if (Buf.size() >0) { Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); Buf = ""; } } Buf = "END_CONNECT" + endl; fwrite(Buf.c_str(), Buf.size(),1,f); } // if (pCon != NULL) if (GetFirstPareNet(pos, one, two)) { Buf = "NET"; if (m_NetComments != "") { Buf+= " /*"; Buf+= m_NetComments; Buf += "*/"; } Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); do { Buf = one + "=" + two + endl; fwrite(Buf.c_str(), Buf.size(),1,f); } while (GetNextPareNet(pos, one, two)); Buf = "END_NET" + endl; fwrite(Buf.c_str(), Buf.size(),1,f); } if ( (pFun = GetFun()) != NULL ) { Buf = "FUNCTION "; if (m_FunComments != "") { Buf+= " /*"; Buf+= m_FunComments; Buf += "*/"; } Buf += endl; Buf += pFun->GetTyp(); Buf += endl; char b[100]; #ifndef _MSVC9 sprintf(b,"%u %u %u",pFun->GetNumInt(),pFun->GetNumOut(),pFun->GetNumInter()); #else sprintf_s(b,100, "%u %u %u",pFun->GetNumInt(),pFun->GetNumOut(),pFun->GetNumInter()); #endif /* _itoa_s(pFun->GetNumInt(), b, 10,10); Buf += b; Buf += " "; _itoa_s(pFun->GetNumOut(), b, 10, 10); Buf += b; Buf += " "; _itoa_s(pFun->GetNumInter(), b, 10, 10); */ Buf += b; Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); for (i=0; ; ) { if (!pFun->GetTextLine(i,Buf)) break; while (Buf.size() > 70) { Buf0 = Buf; Buf0.erase(0,60); //.Right(Buf.GetLength() - 60); j = Buf0.find_first_of("+*"); if (j < 0) break; Buf1 = Buf.substr(0, 60+j); Buf.erase(0,j+60); //.Right(Buf.GetLength() - 60 - j); Buf1 += endl; fwrite(Buf1.c_str(), Buf1.size(),1,f); } Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); } Buf = "END_"; Buf += pFun->GetTyp(); Buf += endl + "END_FUNCTION" + endl; fwrite(Buf.c_str(), Buf.size(),1,f); } Buf = "END_"; Buf += GetTitle(); // Buf += endl+endl; Buf += endl; fwrite(Buf.c_str(), Buf.size(),1,f); } /* #ifndef _LINUX catch( CFileException e ) #else */ catch( ... ) //#endif { //#ifdef _LINUX printf("Error at record of a file %s\n",FileName.c_str()); /* #else #ifdef ENG Buf="Error at record of a file " + FileName; #else Buf="Ошибка при записи файла " + FileName; #endif AfxMessageBox(Buf.c_str()); #endif */ return false; } // END_CATCH fclose(f); return true; }
//--------------------------------------------------------------- bool CSF::WriteSF(vector <string>& Obj) { string Buf, Buf1, Buf0; string one, two; map<string,string>::iterator pos; // POSITION pos; int i, j; CSFunction *pFun; // Obj.RemoveAll(); // 16.05.2006 Buf = "TITLE "+GetTitle(); if (m_TitleComments != "") { Buf+= " /*"; Buf+= m_TitleComments; Buf += "*/"; } Obj.push_back(Buf); Buf = "FORMAT SF"; Obj.push_back(Buf); Buf = "AUTHOR "+GetAuthor(); if (m_AuthorComments != "") { Buf+= " /*"; Buf+= m_AuthorComments; Buf += "*/"; } Obj.push_back(Buf); Buf = "DATE "+GetDate(); if (m_DateComments != "") { Buf+= " /*"; Buf+= m_DateComments; Buf += "*/"; } Obj.push_back(Buf); Buf = "PROJECT "+GetProject(); if (m_ProjectComments != "") { Buf+= " /*"; Buf+= m_ProjectComments; Buf += "*/"; } Obj.push_back(Buf); Buf = "DCL_PIN "; if (m_SFVarComments != "") { Buf+= " /*"; Buf+= m_SFVarComments; Buf += "*/"; } Obj.push_back(Buf); Obj.push_back("EXT"); Obj.push_back("INP"); WriteVar(Obj,'i', &m_SFVarArray); Obj.push_back("OUT"); WriteVar(Obj, 'o', &m_SFVarArray); Obj.push_back("INTER"); WriteVar(Obj, 't', &m_SFVarArray); if (GetFirstPareInter(pos, one, two)) { Buf = one + "=" + two; Obj.push_back(Buf); while (GetNextPareInter(pos, one, two)) { Buf = one + "=" + two; Obj.push_back(Buf); } } Obj.push_back("END_PIN"); CSFType * pType; if (GetFirstType(pType)) { Buf="DCL_EL"; if (m_TypeComments != "") { Buf+= " /*"; Buf+= m_TypeComments; Buf += "*/"; } Obj.push_back(Buf); do { if (pType->GetReg()) Buf = "TYPE_N " + pType->GetName(); else Buf = "TYPE " + pType->GetName(); Obj.push_back(Buf); Buf = ""; for (int i=0; i<(int)pType->m_ElemArray.size(); i++) { Buf += pType->m_ElemArray.at(i); Buf += " "; } Obj.push_back(Buf); Obj.push_back("INP"); WriteVar(Obj,'i', &(pType->m_SFVarArray)); Obj.push_back("OUT"); WriteVar(Obj, 'o', &(pType->m_SFVarArray)); if (pType->GetLib() != "") { Buf = "LIB " + pType->GetLib(); Obj.push_back(Buf); } } while (GetNextType(pType)); Obj.push_back("END_EL"); } i = 0; CSFConnect *pCon = GetConnect(i); if (pCon != NULL) { Buf = "CONNECT "; if (m_ConnectComments != "") { Buf+= " /*"; Buf+= m_ConnectComments; Buf += "*/"; } Obj.push_back(Buf); for (pCon = GetConnect(i=0); pCon != NULL; pCon = GetConnect(i)) { i++; Buf = pCon->GetName(); Obj.push_back(Buf); Buf = ""; if (pCon->GetFirstPare(one, two)) { while (1) { Buf += one + "=" + two + " "; if (Buf.size() >70) { Obj.push_back(Buf); Buf = ""; } // if (!pos) break; if (pCon->GetNextPare(one, two)==false) break; } } else Buf = " "; if (Buf.size() >0) { Obj.push_back(Buf); Buf = ""; } } Obj.push_back("END_CONNECT"); } // if (pCon != NULL) if (GetFirstPareNet(pos, one, two)) { Buf = "NET"; if (m_NetComments != "") { Buf+= " /*"; Buf+= m_NetComments; Buf += "*/"; } Obj.push_back(Buf); do { Buf = one + "=" + two; Obj.push_back(Buf); } while (GetNextPareNet(pos, one, two)); Obj.push_back("END_NET"); } if ( (pFun = GetFun()) != NULL ) { Buf = "FUNCTION "; if (m_FunComments != "") { Buf+= " /*"; Buf+= m_FunComments; Buf += "*/"; } Obj.push_back(Buf); Buf=""; Buf += pFun->GetTyp(); Obj.push_back(Buf); Buf=""; char b[100]; #ifndef _MSVC9 sprintf(b,"%u %u %u",pFun->GetNumInt(),pFun->GetNumOut(),pFun->GetNumInter()); #else sprintf_s(b,100, "%u %u %u",pFun->GetNumInt(),pFun->GetNumOut(),pFun->GetNumInter()); #endif /* _itoa_s(pFun->GetNumInt(), b, 10, 10); Buf += b; Buf += " "; _itoa_s(pFun->GetNumOut(), b, 10, 10); Buf += b; Buf += " "; _itoa_s(pFun->GetNumInter(), b, 10, 10); */ Buf += b; Obj.push_back(Buf); for (i=0; ; ) { if (!pFun->GetTextLine(i,Buf)) break; while (Buf.size() > 70) { Buf0 = Buf; Buf0.erase(0,60); //Right(Buf.GetLength() - 60); j = Buf0.find_first_of("+*"); if (j < 0) break; Buf1 = Buf.substr(0,60+j); Buf.erase(0,j+60); // = Buf.Right(Buf.GetLength() - 60 - j); Obj.push_back(Buf1); } Obj.push_back(Buf); } Buf = "END_"; Buf += pFun->GetTyp(); Obj.push_back(Buf); Obj.push_back("END_FUNCTION"); } Buf = "END_"; Buf += GetTitle(); Obj.push_back(Buf); Obj.push_back(""); return TRUE; }
//--------------------------------------------------------------- bool CSF::ReadNextSF(FILE* fp, long& len) { string buf, buf1, buf2, bufname, comments, InvalidSect; int i, nRes, pos, first, last,NumInSF; CSFConnect *pConnect; bool bRes; #ifdef ENG InvalidSect = "Wrong section "; #else InvalidSect = "Неверный раздел "; #endif if (GetFileLine(fp, buf,len, comments) !=0 ) { //TITLE if ((i = buf.find("TITLE")) >=0) { for (i+=5; buf[i] == ' '; i++); m_Title = buf.erase(0, i); //Right(buf.size() - i); m_Title = BeginEndTrim(m_Title); //m_Title.TrimLeft(); //m_Title.TrimRight(); } else { InvalidMessage(InvalidSect, "TITLE"); return false; } } else { InvalidMessage(InvalidSect, "TITLE"); return false; } if (GetFileLine(fp, buf,len, comments) !=0 ) { // FORMAT if (((int)buf.find("FORMAT")) >=0) { if ((int)buf.find("SF")<0) { InvalidMessage(InvalidSect, "FORMAT"); return false; } } } else { InvalidMessage(InvalidSect, "FORMAT"); return false; } if (GetFileLine(fp, buf,len, comments) !=0 ) { //AUTHOR if ((i=buf.find("AUTHOR")) >=0) { m_TitleComments = comments; comments = ""; for ( i+=6; i<(int)buf.size() && buf[i] == ' '; i++); m_Author = buf.erase(0,i); // Right(buf.size() - i); } else { InvalidMessage(InvalidSect, "AUTHOR"); return false; } } else { InvalidMessage(InvalidSect, "AUTHOR"); return false; } if (GetFileLine(fp, buf,len, comments) !=0 ) { //DATE if ((i=buf.find("DATE")) >=0) { m_AuthorComments = comments; comments = ""; for (i+=4; i<(int)buf.size() && buf[i] == ' '; i++); m_Date = buf.erase(0,i); // Right(buf.size() - i); } else { InvalidMessage(InvalidSect, "DATE"); return false; } } else { InvalidMessage(InvalidSect, "DATE"); return false; } if (GetFileLine(fp, buf,len, comments) !=0 ) { //PROJECT if ((i=buf.find("PROJECT")) >=0) { m_DateComments = comments; comments = ""; if (buf.size()>8) { for (i+=8; i<(int)buf.size() && buf[i] == ' '; i++); m_Project = buf.erase(0,i); // Right(buf.size() - i); } } else { InvalidMessage(InvalidSect, "PROJECT"); return false; } } else { InvalidMessage(InvalidSect, "PROJECT"); return false; } if (GetFileLine(fp, buf,len, comments) !=0 ) { //DCL_PIN if ((i = buf.find("DCL_PIN")) <0) { InvalidMessage(InvalidSect, "DCL_PIN"); return false; } m_ProjectComments = comments; comments = ""; } else { InvalidMessage(InvalidSect, "DCL_PIN"); return false; } if (GetFileLine(fp, buf,len, comments) !=0 ) { //EXT if ((i = buf.find("EXT")) <0) { InvalidMessage(InvalidSect, "EXT"); return false; } } else { InvalidMessage(InvalidSect, "EXT"); return false; } if (GetFileLine(fp, buf,len, comments) !=0 ) { //INP if ((i = buf.find("INP")) <0) { InvalidMessage(InvalidSect, "INP"); return false; } } else { InvalidMessage(InvalidSect, "INP"); return false; } NumInSF=0; // 25.02.00 правила Кириенко, чтобы формировался номер m_NumInSF; inp_var: if (GetFileLine(fp, buf,len, comments) !=0 ) { //INP pos =0; while((i = buf.find("OUT")) < 0) { // read all input variables nRes = GetNextName(buf,pos, bufname); if (nRes ==0) goto inp_var; first = last = 0; if (pos<(int)buf.size() && buf[pos] == '[') { // this variable has interval nRes = GetNextName(buf,pos, buf1); if (nRes ==0) { InvalidMessage(InvalidSect, "OUT"); return false; } first = atoi(buf1.c_str()); nRes = GetNextName(buf,pos, buf2); if (nRes ==0) { InvalidMessage(InvalidSect, "OUT"); return false; } last = atoi(buf2.c_str()); } // if (buf[pos] == '[') CSFVar *pVar = new CSFVar(bufname, 'i',first,last); pVar->m_NumInSF=NumInSF; NumInSF++; AddVar(pVar); } // while(i = buf.find("OUT") <0) } // if (GetFileLine(fp, buf,len) !=0 ) else { InvalidMessage(InvalidSect, "OUT"); return false; } out_var: if (GetFileLine(fp, buf,len, comments) !=0 ) { //OUT pos =0; while((i = buf.find("INTER")) < 0 ) { // read all output variables nRes = GetNextName(buf,pos, bufname); if (nRes ==0) goto out_var; first = last = 0; if (pos<(int)buf.size() && buf[pos] == '[') { // this variable has interval nRes = GetNextName(buf,pos, buf1); if (nRes ==0) { InvalidMessage(InvalidSect, "INTER"); return false; } first = atoi(buf1.c_str()); nRes = GetNextName(buf,pos, buf2); if (nRes ==0) { InvalidMessage(InvalidSect, "INTER"); return false; } last = atoi(buf2.c_str()); } // if (buf[pos] == '[') CSFVar *pVar = new CSFVar(bufname, 'o',first,last); pVar->m_NumInSF=NumInSF; NumInSF++; AddVar(pVar); } // while(i = buf.find("INTER") <0) } else { InvalidMessage(InvalidSect, "INTER"); return false; } inter: if (GetFileLine(fp, buf,len, comments) !=0 ) { //INTER pos =0; while((i = buf.find("END_PIN")) < 0) { // read all output variables if ((i = buf.find("=")) < 0) { nRes = GetNextName(buf,pos, bufname); if (nRes ==0) goto inter; first = last = 0; if (pos<(int)buf.size() && buf[pos] == '[') { // this variable has interval nRes = GetNextName(buf,pos, buf1); if (nRes ==0) { InvalidMessage(InvalidSect, "INTER"); return false; } first = atoi(buf1.c_str()); nRes = GetNextName(buf,pos, buf2); if (nRes ==0) { InvalidMessage(InvalidSect, "INTER"); return false; } last = atoi(buf2.c_str()); } // if (buf[pos] == '[') CSFVar *pVar = new CSFVar(bufname, 't',first,last); pVar->m_NumInSF=NumInSF; NumInSF++; AddVar(pVar); } //if ((i = buf.find("=")) < 0) else { buf = BeginEndTrim(buf); i = buf.find("="); buf1 = buf.substr(0,i); buf2 = buf.erase(0,i+1); //Right(buf.size()-i-1); AddPareInter(buf1, buf2); goto inter; } } // while(i = buf.find("END_PIN") <0) } else { InvalidMessage(InvalidSect, "END_PIN"); return false; } m_SFVarComments = comments; comments = ""; while (GetFileLine(fp, buf,len, comments) !=0 ) { if ((i = buf.find("DCL_EL")) >= 0) { //DCL_EL CSFType *pSFType; if (GetFileLine(fp, buf,len, comments) !=0 ) { while((i = buf.find("END_EL")) < 0) { // read all output variables pos = 0; nRes = GetNextName(buf,pos, bufname); if (bufname == "TYPE_N") bRes = true; else if (bufname == "TYPE") bRes = false; else { InvalidMessage(InvalidSect, "TYPE"); return false; } nRes = GetNextName(buf,pos, buf1); if (buf1 == "") { InvalidMessage(InvalidSect, "TYPE"); return false; } pSFType = new CSFType(buf1,bRes); AddType(pSFType); NumInSF=0; if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "TYPE"); return false; } pos=0; while (1) { i = GetNextNameWithAdd(fp, len,comments, buf, pos, bufname); if (i==0) { InvalidMessage(InvalidSect, "TYPE"); return false; } if (bufname == "INP") break; AddElemForType(pSFType, bufname); } // while (1) while (1) { i = GetNextNameWithAdd(fp, len,comments, buf, pos, bufname); if (i==0) { InvalidMessage(InvalidSect, "TYPE"); return false; } if (bufname == "OUT") break; CSFVar *pVar = new CSFVar(bufname, 'i',0,0); pVar->m_NumInSF=NumInSF; NumInSF++; pSFType->AddVar(pVar); } // while (1) NumInSF=0; while (1) { i = GetNextNameWithAdd(fp, len,comments, buf, pos, bufname); if (i==0) { InvalidMessage(InvalidSect, "TYPE"); return false; } if (bufname == "LIB" ||bufname == "TYPE" ||bufname == "TYPE_N" || bufname == "END_EL" ) break; CSFVar *pVar = new CSFVar(bufname, 'o',0,0); pVar->m_NumInSF=NumInSF; NumInSF++; pSFType->AddVar(pVar); } // while (1) if (bufname == "LIB") { i = GetNextNameWithAdd(fp, len,comments, buf, pos, bufname); if (i==0) { InvalidMessage(InvalidSect, "TYPE"); return false; } pSFType->SetLib(bufname); if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "TYPE"); return false; } } } // while((i = buf.find("END_EL")) < 0) } else { InvalidMessage(InvalidSect, "TYPE"); return false; } m_TypeComments = comments; comments = ""; if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "TYPE"); return false; } } // if ((i = buf.find("DCL_EL")) >= 0) if ((i = buf.find("CONNECT")) >= 0) { //CONNECT if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "CONNECT"); return false; } buf = BeginEndTrim(buf); //buf.TrimLeft(); // 25.06.2008 //buf.TrimRight(); bufname = buf; new_connect: pConnect = new CSFConnect(bufname); AddConnect(pConnect); if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "CONNECT"); return false; } pos = 0; while (1) { buf2 = ""; GetNextPartString(fp, len,comments, buf, pos, bufname); if ((int)buf.find("END_CONNECT")>=0) break; if (pos>=(int)buf.size() || buf[pos] != '=') goto new_connect; new_connect_right: GetNextPartString(fp, len,comments, buf, pos, buf1); if (buf2 == "") buf2 += buf1; else buf2 = (buf2 + "=" + buf1); if (pos < (int)buf.size() && buf[pos] == '=') goto new_connect_right; if (bufname != "" || buf2 != "") pConnect->AddPare(bufname, buf2); bufname = ""; buf2 = ""; // if (pos >= buf.size()) goto new_connect; } // while (1) m_ConnectComments = comments; comments = ""; if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "CONNECT"); return false; } } // if ((i = buf.find("CONNECT")) >= 0) if ((i = buf.find("NET")) >= 0) { //NET pos =0; if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "NET"); return false; } while((i = buf.find("END_NET")) < 0) { if ((i = buf.find("=")) < 0) { InvalidMessage(InvalidSect, "NET"); return false; } buf = BeginEndTrim(buf); i = buf.find("="); buf1 = buf.substr(0,i); buf2 = buf.erase(0,i+1); //Right(buf.size()-i-1); AddPareNet(buf1, buf2); if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "NET"); return false; } } // while(i = buf.find("END_PIN") <0) m_NetComments = comments; comments = ""; if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, "NET"); return false; } } // if ((i = buf.find("NET")) >= 0) if ((i = buf.find("FUNCTION")) >= 0) { //FUNCTION int num_in; int num_out; int num_inter; if (GetFileLine(fp, buf,len, comments) ==0 ) goto err_func; if ((i = buf.find("LOG")) >= 0) buf1= "LOG"; //LOG else buf1= "SDF"; //SDF if (GetFileLine(fp, buf,len, comments) ==0 ) goto err_func; pos = 0; i = GetNextNameWithAdd(fp, len,comments, buf, pos, bufname); if (i==0) goto err_func; num_in = atoi(bufname.c_str()); i = GetNextNameWithAdd(fp, len,comments, buf, pos, bufname); if (i==0) goto err_func; num_out = atoi(bufname.c_str()); i = GetNextNameWithAdd(fp, len,comments, buf, pos, bufname); if (i==0) goto err_func; num_inter = atoi(bufname.c_str()); if (/* num_in < 1 ||*/ num_out < 1) { err_func: InvalidMessage(InvalidSect, "FUNCTION"); return false; } CSFunction *pFun = new CSFunction(buf1, num_in, num_out, num_inter); while(1) { if (GetFileLine(fp, buf,len, comments) ==0 ) goto err_func; i = buf.find("END_"); if (i >= 0 && (int)buf.find("=")<0) break; pFun->AddTextLine(buf); } SetFun(pFun); m_FunComments = comments; comments = ""; if ((i = buf.find("END_")) < 0) { InvalidMessage(InvalidSect, buf); return false; } // if ((i = buf.find("END")) >= 0) if (GetFileLine(fp, buf,len, comments) ==0 ) { InvalidMessage(InvalidSect, buf); return false; } continue; } // if ((i = buf.find("FUNCTION")) >= 0) if ((i = buf.find("END_")) >= 0) break; //#ifdef _LINUX printf("Error in SF-description: %s\n", buf.c_str()); /* #else #ifdef ENG buf = "Error in SF-description:" + buf; #else buf = "Ошибка в SF-описании: " + buf; #endif AfxMessageBox(buf.c_str()); #endif */ return false; } // while (GetFileLine(fp, buf,len, comments) !=0 ) InitSFAttrib(); return true; }
//--------------------------------------------------------------- int CSF::ReadSFFromFile(string Path) // Return: 0 - normal, 1 - error at reading, -1 - file not found { string Buf; bool bRes; #if defined(_LINUX) || defined(__APPLE__) if (access(Path.c_str(),0) != -1 ){ // Файл существует? #else if (_access(Path.c_str(),0) != -1 ){ // Файл существует? #endif try { // чтение исходного SF- описания из файла FILE* f; f = fopen(Path.c_str(), "r"); // int fn =_fileno( f ); long dwFileSize ;//= _filelength( fn ); fseek(f, 0, SEEK_END); dwFileSize = ftell(f); fseek(f, 0L, SEEK_SET); bRes = ReadNextSF(f, dwFileSize); if (bRes == 0) { //#ifdef _LINUX printf("Error at reading SF-description %s\n", Path.c_str()); /* #else #ifdef ENG Buf = "Error at reading SF-description " + Path; #else Buf = "Ошибка при чтении SF-опиcания " + Path; #endif AfxMessageBox(Buf.c_str()); #endif */ return 1; // Сбой при чтении SF-опиcания } } /* #ifndef _LINUX catch( CFileException e ) #else */ catch( ... ) //#endif { //#ifdef _LINUX printf("Error at reading %s\n", Path.c_str()); /* #else #ifdef ENG Buf = ("Error at reading " + Path); #else Buf = ("Ошибка при чтении файла " + Path); #endif AfxMessageBox(Buf.c_str()); #endif */ return 1; // Сбой при чтении файла } // END_CATCH return 0; } return -1; // SF-описание не найдено } //--------------------------------------------------------------- bool CSF::ReadNextSF(vector <string>& Obj, int & index) //Кириенко 11.05.06 { string buf, buf1, buf2, bufname, comments, InvalidSect; int i, nRes, pos, first, last,NumInSF, ii, size; CSFConnect *pConnect; bool bRes; #ifdef ENG InvalidSect = "Wrong section "; #else InvalidSect = "Неверный раздел "; #endif size=Obj.size(); for (ii=0; ii<size; ii++) { if (GetLineFromStringArray(Obj, buf, index, comments)!=0 ) { //TITLE if ((i = buf.find("TITLE")) >=0) { for (i+=5; buf[i] == ' '; i++); m_Title = buf; m_Title.erase(0,i); //.Right(buf.size() - i); m_Title = BeginEndTrim(m_Title); // m_Title.TrimLeft(); // m_Title.TrimRight(); break; } } else { InvalidMessage(InvalidSect, "TITLE"); return false; } } if (i<0)return false; if (GetLineFromStringArray(Obj, buf, index, comments) !=0 ) { // FORMAT if (((int)buf.find("FORMAT")) >=0) { if ((int)buf.find("SF")<0) { InvalidMessage(InvalidSect, "FORMAT"); return false; } } } else { InvalidMessage(InvalidSect, "FORMAT"); return false; } if (GetLineFromStringArray(Obj, buf, index, comments) !=0 ) { //AUTHOR if ((i=buf.find("AUTHOR")) >=0) { m_TitleComments = comments; comments = ""; for ( i+=6; i<(int)buf.size() && buf[i] == ' '; i++); m_Author = buf.erase(0,i); //Right(buf.size() - i); } else { InvalidMessage(InvalidSect, "AUTHOR"); return false; } } else { InvalidMessage(InvalidSect, "AUTHOR"); return false; } if (GetLineFromStringArray(Obj, buf, index, comments) !=0 ) { //DATE if ((i=buf.find("DATE")) >=0) { m_AuthorComments = comments; comments = ""; for (i+=4; i<(int)buf.size() && buf[i] == ' '; i++); m_Date = buf.erase(0,i); //Right(buf.size() - i); } else { InvalidMessage(InvalidSect, "DATE"); return false; } } else { InvalidMessage(InvalidSect, "DATE"); return false; } if (GetLineFromStringArray(Obj, buf, index, comments)!=0 ) { //PROJECT if ((i=buf.find("PROJECT")) >=0) { m_DateComments = comments; comments = ""; if (buf.size()>8) { for (i+=8; i<(int) buf.size() && buf[i] == ' '; i++); m_Project = buf.erase(0,i); } } else { InvalidMessage(InvalidSect, "PROJECT"); return false; } } if (GetLineFromStringArray(Obj, buf, index, comments)!=0 ) { //DCL_PIN if ((i = buf.find("DCL_PIN")) <0) { InvalidMessage(InvalidSect, "DCL_PIN"); return false; } m_ProjectComments = comments; comments = ""; } else { InvalidMessage(InvalidSect, "DCL_PIN"); return false; } if (GetLineFromStringArray(Obj, buf, index, comments)!=0 ) {//EXT if ((i = buf.find("EXT")) <0) { InvalidMessage(InvalidSect, "EXT"); return false; } } else { InvalidMessage(InvalidSect, "EXT"); return false; } if (GetLineFromStringArray(Obj, buf, index, comments)!=0 ) {//INP if ((i = buf.find("INP")) <0) { InvalidMessage(InvalidSect, "INP"); return false; } } else { InvalidMessage(InvalidSect, "INP"); return false; } NumInSF=0; // 25.02.00 правила Кириенко, чтобы формировался номер m_NumInSF; inp_var: if (GetLineFromStringArray(Obj, buf, index, comments)!=0 ) {//INP pos =0; while((i = buf.find("OUT")) < 0) { // read all input variables nRes = GetNextName(buf,pos, bufname); if (nRes ==0) goto inp_var; first = last = 0; if (pos<(int)buf.size() && buf[pos] == '[') { // this variable has interval nRes = GetNextName(buf,pos, buf1); if (nRes ==0) { InvalidMessage(InvalidSect, "OUT"); return false; } first = atoi(buf1.c_str()); nRes = GetNextName(buf,pos, buf2); if (nRes ==0) { InvalidMessage(InvalidSect, "OUT"); return false; } last = atoi(buf2.c_str()); } // if (buf[pos] == '[') CSFVar *pVar = new CSFVar(bufname, 'i',first,last); pVar->m_NumInSF=NumInSF; NumInSF++; AddVar(pVar); } // while(i = buf.find("OUT") <0) } // if (GetFileLine(fp, buf,len) !=0 ) else { InvalidMessage(InvalidSect, "OUT"); return false; } out_var: if (GetLineFromStringArray(Obj, buf, index, comments)!=0) {//OUT pos =0; while((i = buf.find("INTER")) < 0 ) { // read all output variables nRes = GetNextName(buf,pos, bufname); if (nRes ==0) goto out_var; first = last = 0; if (pos<(int)buf.size() && buf[pos] == '[') { // this variable has interval nRes = GetNextName(buf,pos, buf1); if (nRes ==0) { InvalidMessage(InvalidSect, "INTER"); return false; } first = atoi(buf1.c_str()); nRes = GetNextName(buf,pos, buf2); if (nRes ==0) { InvalidMessage(InvalidSect, "INTER"); return false; } last = atoi(buf2.c_str()); } // if (buf[pos] == '[') CSFVar *pVar = new CSFVar(bufname, 'o',first,last); pVar->m_NumInSF=NumInSF; NumInSF++; AddVar(pVar); } // while(i = buf.find("INTER") <0) } else { InvalidMessage(InvalidSect, "INTER"); return false; } inter: if (GetLineFromStringArray(Obj, buf, index, comments)!=0) { //INTER pos =0; while((i = buf.find("END_PIN")) < 0) { // read all output variables if ((i = buf.find("=")) < 0) { nRes = GetNextName(buf,pos, bufname); if (nRes ==0) goto inter; first = last = 0; if (pos<(int)buf.size() && buf[pos] == '[') { // this variable has interval nRes = GetNextName(buf,pos, buf1); if (nRes ==0) { InvalidMessage(InvalidSect, "INTER"); return false; } first = atoi(buf1.c_str()); nRes = GetNextName(buf,pos, buf2); if (nRes ==0) { InvalidMessage(InvalidSect, "INTER"); return false; } last = atoi(buf2.c_str()); } // if (buf[pos] == '[') CSFVar *pVar = new CSFVar(bufname, 't',first,last); pVar->m_NumInSF=NumInSF; NumInSF++; AddVar(pVar); } //if ((i = buf.find("=")) < 0) else { buf = BeginEndTrim(buf); i = buf.find("="); buf1 = buf.substr(0,i); buf2 = buf.erase(0, i+1); //Right(buf.size()-i-1); AddPareInter(buf1, buf2); goto inter; } // while(i = buf.find("END_PIN") <0) } } else { InvalidMessage(InvalidSect, "END_PIN"); return false; } m_SFVarComments = comments; comments = ""; while (GetLineFromStringArray(Obj, buf, index, comments) !=0 ) { if ((i = buf.find("DCL_EL")) >= 0) { //DCL_EL CSFType *pSFType; if (GetLineFromStringArray(Obj, buf, index, comments)!=0 ) { while((i = buf.find("END_EL")) < 0) { // read all output variables pos = 0; nRes = GetNextName(buf,pos, bufname); if (bufname == "TYPE_N") bRes = true; else if (bufname == "TYPE") bRes = false; else { InvalidMessage(InvalidSect, "TYPE"); return false; } nRes = GetNextName(buf,pos, buf1); if (buf1 == "") { InvalidMessage(InvalidSect, "TYPE"); return false; } pSFType = new CSFType(buf1,bRes); AddType(pSFType); NumInSF=0; if (GetLineFromStringArray(Obj, buf, index, comments)==0 ){ InvalidMessage(InvalidSect, "TYPE"); return false; } pos=0; while (1) { i=GetNextNameWithAdd(Obj,index,comments,buf,pos,bufname); if (i==0) { InvalidMessage(InvalidSect, "TYPE"); return false; } if (bufname == "INP") break; AddElemForType(pSFType, bufname); } // while (1) while (1) { i=GetNextNameWithAdd(Obj,index,comments,buf,pos,bufname); if (i==0) { InvalidMessage(InvalidSect, "TYPE"); return false; } if (bufname == "OUT") break; CSFVar *pVar = new CSFVar(bufname, 'i',0,0); pVar->m_NumInSF=NumInSF; NumInSF++; pSFType->AddVar(pVar); } // while (1) NumInSF=0; while (1) { i=GetNextNameWithAdd(Obj,index,comments,buf,pos,bufname); if (i==0) { InvalidMessage(InvalidSect, "TYPE"); return false; } if (bufname == "LIB" ||bufname == "TYPE" ||bufname == "TYPE_N" || bufname == "END_EL" ) break; CSFVar *pVar = new CSFVar(bufname, 'o',0,0); pVar->m_NumInSF=NumInSF; NumInSF++; pSFType->AddVar(pVar); } // while (1) if (bufname == "LIB") { i=GetNextNameWithAdd(Obj,index,comments,buf,pos,bufname); if (i==0) { InvalidMessage(InvalidSect, "TYPE"); return false; } pSFType->SetLib(bufname); if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "TYPE"); return false; } } } // while((i = buf.find("END_EL")) < 0) } else { InvalidMessage(InvalidSect, "TYPE"); return false; } m_TypeComments = comments; comments = ""; if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "TYPE"); return false; } } // if ((i = buf.find("DCL_EL")) >= 0) if ((i = buf.find("CONNECT")) >= 0) { //CONNECT if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "TYPE"); return false; } bufname = buf; new_connect: pConnect = new CSFConnect(bufname); AddConnect(pConnect); if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "CONNECT"); return false; } pos = 0; while (1) { buf2 = ""; GetNextPartString(Obj,index,comments,buf,pos,bufname); if ((int)buf.find("END_CONNECT")>=0) break; if (pos>=(int)buf.size() || buf[pos] != '=') goto new_connect; new_connect_right: GetNextPartString(Obj,index,comments,buf,pos,buf1); if (buf2 == "") buf2 += buf1; else buf2 = (buf2 + "=" + buf1); if (pos < (int)buf.size() && buf[pos] == '=') goto new_connect_right; if (bufname != "" || buf2 != "") pConnect->AddPare(bufname, buf2); bufname = ""; buf2 = ""; // if (pos >= buf.size()) goto new_connect; } // while (1) m_ConnectComments = comments; comments = ""; if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "CONNECT"); return false; } } // if ((i = buf.find("CONNECT")) >= 0) if ((i = buf.find("NET")) >= 0) { //NET pos =0; if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "NET"); return false; } while((i = buf.find("END_NET")) < 0) { if ((i = buf.find("=")) < 0) { InvalidMessage(InvalidSect, "NET"); return false; } buf = BeginEndTrim(buf); i = buf.find("="); buf1 = buf.substr(0,i); buf2 = buf.erase(0,i+1); //Right(buf.size()-i-1); AddPareNet(buf1, buf2); if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "NET"); return false; } } // while(i = buf.find("END_PIN") <0) m_NetComments = comments; comments = ""; if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "NET"); return false; } } // if ((i = buf.find("NET")) >= 0) if ((i = buf.find("FUNCTION")) >= 0) { //FUNCTION if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "FUNCTION"); return false; } if ((i = buf.find("LOG")) >= 0) buf1= "LOG"; //LOG else buf1= "SDF"; //SDF if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, "FUNCTION"); return false; } pos = 0; i=GetNextNameWithAdd(Obj,index,comments,buf,pos,bufname); if (i==0) { InvalidMessage(InvalidSect, "FUNCTION"); return false; } int num_in = atoi(bufname.c_str()); i=GetNextNameWithAdd(Obj,index,comments,buf,pos,bufname); if (i==0) { InvalidMessage(InvalidSect, "FUNCTION"); return false; } int num_out = atoi(bufname.c_str()); i=GetNextNameWithAdd(Obj,index,comments,buf,pos,bufname); if (i==0) { InvalidMessage(InvalidSect, "FUNCTION"); return false; } int num_inter = atoi(bufname.c_str()); if ( /*num_in < 1 ||*/ num_out < 1) { err_func: InvalidMessage(InvalidSect, "FUNCTION"); return false; } CSFunction *pFun = new CSFunction(buf1, num_in, num_out, num_inter); while(1) { if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) goto err_func; i = buf.find("END_"); if (i >= 0 && (int)buf.find("=")<0) break; buf.erase(0,buf.find_last_not_of(" ")); pFun->AddTextLine(buf); } SetFun(pFun); m_FunComments = comments; comments = ""; if ((i = buf.find("END_")) < 0) { InvalidMessage(InvalidSect, buf); return false; } // if ((i = buf.find("NET")) >= 0) if (GetLineFromStringArray(Obj, buf, index, comments)==0 ) { InvalidMessage(InvalidSect, buf); return false; } continue; } // if ((i = buf.find("NET")) >= 0) if ((i = buf.find("END_")) >= 0) break; //#ifdef _LINUX printf("Error in SF-description: %s\n", buf.c_str()); /* #else #ifdef ENG buf = "Error in SF-description:" + buf; #else buf = "Ошибка в SF-описании:" + buf; #endif AfxMessageBox(buf.c_str()); #endif */ return false; } // while (GetFileLine(fp, buf,len, comments) !=0 ) InitSFAttrib(); return true; }