/* A utility function for parsing a whole file */ VyParseTree* ParseFile(char* filename){ if(filename == NULL){ fprintf(stderr, "Null pointer as filename."); return NULL; } /* Perform lexing */ LexFile(filename); if(GetNumTokens() < 1){ printf("Empty file: %s\n", filename); return NULL; } /* Parse the tokens */ VyParseTree* list = MakeListTree(); while(MoreTokensExist()) { VyParseTree* tree = Parse(); AddToList(list, tree); } CleanLexer(); return list; }
Vector3D CPolyDlg::GetCnrVector( CString cnrstr ) { //Extract 3D coordinates from vertex string. String is assumed to be: // "[cnrnum] [v.x] [v.y] [v.z] R G B" istrstream lin( cnrstr.GetBuffer( cnrstr.GetLength() ) ) ; //extract & discard corner number if necessary if( GetNumTokens( cnrstr ) > 6 ) { int cnrnum ; lin >> cnrnum ; }
inline bool IsEmpty() const { return GetNumTokens() == 0; }
void CPolyDlg::OnEnterKey( UINT ctlID ) { CString csMsg, csEditstr, csItemNum, newitmstr ; int itemnum ; CComboBox& combo = m_Combo_Corner ; //convenience //Get editbox string CWnd* pWnd = (combo.GetWindow(GW_CHILD)) ; CWnd* pEditWnd = (pWnd->GetNextWindow()); //pointer to editbox window pEditWnd->GetWindowText( csEditstr ); csEditstr.TrimLeft() ; csEditstr.TrimRight() ; int numtokens = GetNumTokens( csEditstr ) ; int numitems = combo.GetCount() ; //check for too few or too many tokens in the entry string if( numtokens < 2 ) { csMsg = "Each entry must have at least X & Y positions " ; AfxMessageBox( csMsg + "\n" + csEditstr ) ; return ; } else if( numtokens > 7 ) { csMsg = "Each line can have no more than seven items" ; AfxMessageBox( csMsg + "\n" + csEditstr ) ; return ; } //OK, 2 or 3 tokens: get valid X/Y pos Vector3D vcrnr = GetCnrVector( csEditstr ) ; //3 tokens are considered to be [X Position] [Y Position] [Z Position] if( numtokens == 3 ) { //prepend item num & add to end itemnum = numitems + 1 ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, 0, 0, 0 ) ; csEditstr = csItemNum + newitmstr ; combo.AddString( csEditstr ) ; itemnum = GetItemNum( csEditstr ) ; } // 6 tokens are assumed to be [X Position] [Y Position] [Z Position] [R] [G] [B] else if( numtokens == 6 ) { COLORREF col = GetCnrColor( csEditstr ) ; int R = GetRValue( col ) ; int G = GetGValue( col ) ; int B = GetBValue( col ) ; //prepend item num & add to end itemnum = numitems + 1 ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, R, G, B ) ; csEditstr = csItemNum + newitmstr ; combo.AddString( csEditstr ) ; itemnum = GetItemNum( csEditstr ) ; } //otherwise we assume [Item #] [X Position] [Y Position] [Z Position] [R] [G] [B] else { itemnum = GetItemNum( csEditstr ) ; COLORREF col = GetCnrColor( csEditstr ) ; int R = GetRValue( col ) ; int G = GetGValue( col ) ; int B = GetBValue( col ) ; //insert at item number or add to end if( itemnum > numitems ) { //prepend correct item num & add to end itemnum = numitems + 1 ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, R, G, B ) ; csEditstr = csItemNum + newitmstr ; combo.AddString( csEditstr ) ; } else if( itemnum < numitems ) { combo.DeleteString( itemnum - 1 ) ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, R, G, B ) ; csEditstr = csItemNum + newitmstr ; combo.InsertString( itemnum - 1, csEditstr ) ; } else //itemnum points to last string { combo.DeleteString( itemnum - 1 ) ; FormatNumStr( csItemNum, itemnum ) ; newitmstr.Format( m_csCoordFmtStr, vcrnr.x, vcrnr.y, vcrnr.z, R, G, B ) ; csEditstr = csItemNum + newitmstr ; combo.AddString( csEditstr ) ; } } //leave this item selected combo.SetCurSel( itemnum - 1 ) ; UpdateControls() ; //added 07/10/03 }