/** * ParseLine.cpp * Copyright (C) 2004 Nate * * This file is part of DigitalWatch, a free DTV watching and recording * program for the VisionPlus DVB-T. * * DigitalWatch is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * DigitalWatch is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DigitalWatch; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "ParseLine.h" #include "GlobalFunctions.h" ////////////////////////////////////////////////////////////////////// // ParseLine ////////////////////////////////////////////////////////////////////// ParseLine::ParseLine() { m_strLine = NULL; m_strCurr = NULL; m_strErrorMessage = NULL; m_nErrorPosition = 0; m_bHasRHS = FALSE; ZeroMemory(&LHS, sizeof(PARSELINE_FUNCTION)); ZeroMemory(&RHS, sizeof(PARSELINE_FUNCTION)); } ParseLine::~ParseLine() { if (m_strLine) delete[] m_strLine; if (m_strErrorMessage) delete[] m_strErrorMessage; if (LHS.Function) delete[] LHS.Function; if (LHS.FunctionName) delete[] LHS.FunctionName; if (LHS.ParameterCount > 0) { for (int i=0 ; i 0) { for (int i=0 ; i strCurr) && (isWhitespace(nextChr[0]))) ; nextChr--); if (nextChr >= strCurr) nextChr++; if (nextChr <= strCurr) return SetErrorMessage(L"Missing parameter", strCurr-m_strLine); if (bRHS) AddParameter(RHS, strCurr, nextChr - strCurr); else AddParameter(LHS, strCurr, nextChr - strCurr); strCurr = nextChr; } skipWhitespaces((LPCWSTR &)strCurr); } while (strCurr[0] == ','); } if (strCurr[0] == '\0') return SetErrorMessage(L"End of line found. Expecting ',' or ')'", strCurr-m_strLine); if (strCurr[0] != ')') return SetErrorMessage(L"Invalid character found. Expecting ',' or ')'", strCurr-m_strLine); strCurr++; bResult = TRUE; } if (bRHS) strCopy(RHS.Function, startOfFunction, strCurr-startOfFunction); else strCopy(LHS.Function, startOfFunction, strCurr-startOfFunction); if (!m_bIgnoreRHS) { skipWhitespaces((LPCWSTR &)strCurr); if (strCurr[0] == '=') { if (bRHS) return SetErrorMessage(L"Cannot assign twice. Unexpected '=' found", strCurr-m_strLine); m_bHasRHS = TRUE; strCurr++; LPWSTR endOfFunction = strCurr; return ParseFunction(endOfFunction, TRUE); } } m_cbLength = strCurr - m_strLine; if (m_bIgnoreRHS) return TRUE; else if (strCurr[0] == '\0') return TRUE; else if (strCurr[0] == '#') return TRUE; else return SetErrorMessage(L"Invalid character found. Expecting '=' or '('", strCurr-m_strLine); } void ParseLine::AddParameter(PARSELINE_FUNCTION &LHS, LPCWSTR src, long length) { LPWSTR *newParams = new LPWSTR[LHS.ParameterCount+1]; for (int i=0 ; i