1 // Created on: 1992-06-24
2 // Created by: Gilles DEBARBOUILLE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <Units_Lexicon.ixx>
24 #include <Units_Token.hxx>
25 #include <TCollection_HAsciiString.hxx>
26 #include <TCollection_AsciiString.hxx>
28 #include <sys/types.h>
34 #include <Standard_Stream.hxx>
37 //=======================================================================
38 //function : Units_Lexicon
40 //=======================================================================
42 Units_Lexicon::Units_Lexicon()
47 //=======================================================================
50 //=======================================================================
52 void Units_Lexicon::Creates(const Standard_CString afilename)
54 char chain[256],line[256];
55 char oper[11],coeff[31];
65 Handle(Units_Token) token;
74 //for(i=0; i<=255; i++)chain[i]=0;
75 ifstream file(afilename, ios::in);
77 cout<<"unable to open "<<afilename<<" for input"<<endl;
81 thefilename = new TCollection_HAsciiString(afilename);
82 thesequenceoftokens = new Units_TokensSequence();
84 if(!stat(afilename,&buf)) thetime = buf.st_ctime;
86 //for(i=0; i<=255; i++)line[i]=0;
88 while(file.getline(line,255)) {
89 Standard_Size len = strlen( line ) ;
90 if(len == 1) continue; //skl - ???
91 for ( i = 0 ; i < 30 ; i++ ) {
93 fr=sscanf(&line[i],"%c",&chain[i]);
97 for ( i = 0 ; i < 10 ; i++ ) {
99 fr=sscanf(&line[30+i],"%c",&oper[i]);
103 for ( i = 0 ; i < 30 ; i++ ) {
105 fr=sscanf(&line[40+i],"%c",&coeff[i]);
110 cout << "Lexiconsscanf(%c )" << endl << "Chain" << Chain << endl
111 << "Oper" << Oper << endl
112 << "Coeff" << Coeff << endl ;
115 while( i>=0 && ( chain[i] == ' ' || !chain[i] ))
119 while( i>=0 && ( oper [i] == ' ' || !oper [i] ))
122 while( i>=0 && ( coeff[i] == ' ' || !coeff[i] ))
130 if(thesequenceoftokens->IsEmpty()) {
131 token = new Units_Token(chain,oper,value);
132 thesequenceoftokens->Prepend(token);
135 AddToken(chain,oper,value);
145 //=======================================================================
146 //function : UpToDate
148 //=======================================================================
150 Standard_Boolean Units_Lexicon::UpToDate() const
153 TCollection_AsciiString string = FileName();
155 if(!stat(string.ToCString(),&buf)) {
156 if(thetime >= buf.st_ctime)
157 return Standard_True;
160 return Standard_False;
164 //=======================================================================
165 //function : FileName
167 //=======================================================================
169 TCollection_AsciiString Units_Lexicon::FileName() const
171 return thefilename->String();
175 //=======================================================================
176 //function : AddToken
178 //=======================================================================
180 void Units_Lexicon::AddToken(const Standard_CString aword,
181 const Standard_CString amean,
182 const Standard_Real avalue)
184 Handle(Units_Token) token;
185 Handle(Units_Token) referencetoken;
186 Standard_Boolean found = Standard_False;
187 Standard_Integer index;
189 for(index=1;index<=thesequenceoftokens->Length();index++) {
190 referencetoken = thesequenceoftokens->Value(index);
191 if( referencetoken->Word() == aword ) {
192 referencetoken->Update(amean);
193 found = Standard_True;
196 else if( !( referencetoken->Word()>aword ) ) {
197 token = new Units_Token(aword,amean,avalue);
198 thesequenceoftokens->InsertBefore(index,token);
199 found = Standard_True;
204 token = new Units_Token(aword,amean,avalue);
205 thesequenceoftokens->Append(token);