CValue *GetVariable( CStr &var, BOOL create, int *position, BOOL local ) { int pos, startPos; bool oldStyle = false, reference = false, isPtr = false; CStr entryName; CMapStrToValue *map = NULL; CValue *value; CValue *dummy; pos = 0; if ( !local ) { if ( LocalVariables != NULL && LocalVariables->Lookup( L"%AUTOLOCAL%", dummy ) ) local = TRUE; } // Skip spaces while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++; if ( pos < var.GetLength() && var[pos] == L'%' ) { oldStyle = true; pos++; while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++; } if ( create && pos < var.GetLength() && var[pos] == L'[' ) { reference = true; pos++; while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++; } startPos = pos; // Skip all valid variable name characters while ( pos < var.GetLength() && ( GetCharacterType( var[pos] ) == CInterpreter::CHAR_ALPHA || GetCharacterType( var[pos] ) == CInterpreter::CHAR_DIGIT || GetCharacterType( var[pos] ) == CInterpreter::CHAR_UNDERSCORE || (var[pos] == L':' && (pos == startPos || pos == startPos + 1 )) ) ) pos++; // Skip Regex variable name characters if ((var[pos]==L'$') && (pos+1<var.GetLength())){ if ( var[pos+1] == L'&' || var[pos+1] == L'`' || var[pos+1] == L'\'' || var[pos+1] == L'+' || var[pos+1] == L'_' )pos +=2; else{ int i=0; for (i=1;i<=3;i++){ if ( pos+i<var.GetLength() && var[pos+i] >=L'0' && var[pos+i]<=L'9') { /* do nothing */ }else break; } pos+=i; } } // Skip spaces while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++; //jwz:add for Global Variable if (var[startPos]==L':' && var[startPos+1]==L':'){ local = FALSE; startPos +=2; } // No array index? if ( pos == -1 || pos >= var.GetLength() || var[pos] != L'[' ) { entryName = var; if ( pos != -1 && pos <= var.GetLength() ) entryName = var.Mid( startPos, pos-startPos ); entryName.TrimLeft(); entryName.TrimRight(); if ( position != NULL ) *position = pos; if ( entryName.IsEmpty()) { VarError = L"Empty variable name not allowed"; if ( position != NULL ) *position = -1; return NULL; } entryName.MakeUpper(); if ( local && LocalVariables != NULL && LocalVariables->Lookup( L"%GL_" + entryName + L"%", dummy ) ) //predefined GLOBAL declare variable { local = FALSE; } if ( local && LocalVariables != NULL && LocalVariables->Lookup( entryName, value ) ) {} else if ( local == FALSE && Variables.Lookup( entryName, value ) ) {} else { if ( create ) { // MessageBox( NULL, L"%GL_" + entryName + L"%", L"Debug", MB_OK ); if ( LocalVariables != NULL && local ) { LocalVariables->SetAt( entryName, CValue() ); LocalVariables->Lookup( entryName, value ); } else { Variables.SetAt( entryName, CValue() ); Variables.Lookup( entryName, value ); } } else value = NULL; } } else { entryName = var.Mid( startPos, pos-startPos ); entryName.TrimLeft(); entryName.TrimRight(); entryName.MakeUpper(); if ( entryName.IsEmpty() ) { VarError = L"'[' without array name"; if ( position != NULL ) *position = -1; value = NULL; } else { if ( local && LocalVariables != NULL && LocalVariables->Lookup( L"%GL_" + entryName + L"%", dummy ) ) { local = FALSE; } if ( local && LocalVariables != NULL && LocalVariables->Lookup( entryName, value ) ) {} else if ( local == FALSE && Variables.Lookup( entryName, value ) ) {} else { if ( create ) { if ( LocalVariables != NULL && local ) { LocalVariables->SetAt( entryName, CValue() ); LocalVariables->Lookup( entryName, value ); } else { Variables.SetAt( entryName, CValue() ); Variables.Lookup( entryName, value ); } } else value = NULL; } if ( value != NULL ) map = value->GetMap(); while ( pos != -1 && pos < var.GetLength() && var[pos] == L'[' ) { startPos = pos+1; CStr arrIdxExpr = var.Mid( startPos ); CInterpreter parser; entryName = (LPCTSTR)parser.EvaluateExpression( arrIdxExpr, FALSE ); if ( parser.GetError() != 0 ) { VarError = parser.GetErrorMessage(); if ( position != NULL ) *position = -1; value = NULL; break; } if ( entryName.IsEmpty() != 0 ) { VarError = L"Array index is empty"; if ( position != NULL ) *position = -1; value = NULL; break; } pos = startPos + parser.GetErrorPosition(); if ( var[pos] != L']' ) { VarError = L"Missing ']'"; if ( position != NULL ) *position = -1; value = NULL; break; } if ( position != NULL ) *position = pos+1; while ( pos < var.GetLength() && parser.GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++; entryName.MakeUpper(); BOOL isArray = FALSE; if ( pos <= var.GetLength() && var[pos+1] == L'[' ) { isArray = TRUE; pos++; } if ( value != NULL ) { if ( map != NULL ) { if ( map->Lookup( entryName, value ) == FALSE ) { if ( create ) { map->SetAt( entryName, CValue() ); map->Lookup( entryName, value ); if ( isArray ) map = value->GetMap(); } else value = NULL; } else if ( isArray ) map = value->GetMap(); } } } } } if ( create && reference && value != NULL ) { while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++; if ( pos < var.GetLength() && var[pos] == L']' ) { pos++; CStr referredVar = (CStr)*value; value = GetVariable( referredVar, create ); } else { VarError = L"Missing ']'"; pos = -1; if ( position != NULL ) *position = -1; value = NULL; } } if ( oldStyle && value != NULL ) { while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++; if ( pos < var.GetLength() && var[pos] == L'%' ) { pos++; //CStr referredVar = (LPCTSTR)value; //value = GetVariable( referredVar, create ); } else { VarError = L"Missing '%'"; pos = -1; if ( position != NULL ) *position = -1; value = NULL; } } return value; }
int CIniFile::SetComPort( LPCTSTR filename, HANDLE file ) { CStr port = filename; CValue *comData; int timeout, rate, bits, parity, stopBit, flow; port.MakeUpper(); if ( Variables.Lookup( L"[Port_" + port + L"]", comData ) ) { CStrArray data; CStr dataString; dataString = (CStr)*comData; Split( dataString, L"\n", data ); timeout = _wtol( data[0] ); rate = _wtol( data[1] ); parity = _wtol( data[2] ); bits = _wtol( data[3] ); stopBit = _wtol( data[4] ); flow = _wtol( data[5] ); //MessageBox( NULL, comData, L"Debug", MB_OK ); } else { timeout = 10000; rate = 4800; parity = NOPARITY; bits = 8; stopBit = ONESTOPBIT; flow = 0; } DCB PortDCB; ZeroMemory (&PortDCB, sizeof(PortDCB)); PortDCB.DCBlength = sizeof(DCB); GetCommState( file, &PortDCB ); // Change the DCB structure settings. PortDCB.BaudRate = rate; // Current baud PortDCB.fBinary = TRUE; // ASCII mode PortDCB.fParity = TRUE; // Enable parity checking PortDCB.fOutxCtsFlow = (flow==1); // CTS output flow control PortDCB.fOutxDsrFlow = FALSE; // DSR output flow control PortDCB.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type PortDCB.fDsrSensitivity = FALSE; // DSR sensitivity PortDCB.fTXContinueOnXoff = TRUE; // XOFF continues Tx PortDCB.fOutX = (flow==2); // XON/XOFF out flow control PortDCB.fInX = (flow==2); // XON/XOFF in flow control PortDCB.fErrorChar = FALSE; // Disable error replacement PortDCB.fNull = TRUE; // Enable null stripping PortDCB.fRtsControl = (flow==1) ? RTS_CONTROL_HANDSHAKE : RTS_CONTROL_ENABLE; // RTS flow control PortDCB.fAbortOnError = FALSE; // Do not abort reads/writes on // error PortDCB.ByteSize = bits; // Number of bits/byte, 4-8 PortDCB.Parity = parity; // 0-4=no,odd,even,mark,space PortDCB.StopBits = stopBit; // 0,1,2 = 1, 1.5, 2 //CStr msg; //msg.Format( L"BaudRate: %d\nByteSize: %d\nStopBits: %d\nParity: %d\nfOutX: %d\nfInX: %d\nfOutxCtsFlow: %d\nfRtsControl: %d\nfDsrSensitivity: %d", // PortDCB.BaudRate, // PortDCB.ByteSize, // PortDCB.StopBits, // PortDCB.Parity, // PortDCB.fOutX, // PortDCB.fInX, // PortDCB.fOutxCtsFlow, // PortDCB.fRtsControl, // PortDCB.fDsrSensitivity ); //MessageBox( NULL, L"Port-Info: " + msg, L"Port-Info", MB_OK|MB_SETFOREGROUND ); // Configure the port according to the specifications of the DCB // structure. SetCommState( file, &PortDCB ); // Retrieve the time-out parameters for all read and write operations // on the port. COMMTIMEOUTS CommTimeouts; GetCommTimeouts( file, &CommTimeouts); // Change the COMMTIMEOUTS structure settings. CommTimeouts.ReadIntervalTimeout = MAXDWORD; CommTimeouts.ReadTotalTimeoutMultiplier = MAXDWORD; CommTimeouts.ReadTotalTimeoutConstant = timeout; CommTimeouts.WriteTotalTimeoutMultiplier = 10; CommTimeouts.WriteTotalTimeoutConstant = 1000; // Set the time-out parameters for all read and write operations // on the port. SetCommTimeouts( file, &CommTimeouts); EscapeCommFunction( file, SETDTR ); EscapeCommFunction( file, SETRTS ); return timeout; }