TInt CDummyUsbDevice::GetNextLine()
	{
	TInt newLineOffset = (iPtr.Mid(iFileOffset)).Locate(13);
	if (newLineOffset < 0)
		{
		return newLineOffset;
		}
	if (newLineOffset == 0)
		{
		iFileOffset += 2;
		return GetNextLine();
		}
	iLine.Set(iPtr.MidTPtr(iFileOffset, newLineOffset));
	iFileOffset += (newLineOffset + 2);
	if (iLine.Find(_L8("//")) == 0) // i.e. line begins with "//"
		{
		return GetNextLine();
		}
	if (iLine.Find(_L8("**")) == 0) // line begins with **, so display it
		{
		TBuf<100> buf; // max length 100 for test messages
		buf.Copy(iLine);
		iTest.Printf(_L("\n%S\n\n"),&buf);
		return GetNextLine();
		};
	return newLineOffset;
	}
void Config::loadData(char *pbData, int iDatasize){
	int pointer = 0;
	while (pointer < iDatasize){
		char *line = GetNextLine(pbData, iDatasize, &pointer);
		//printf("Line: %s\r\n", line);
		/**/
		if (lineContainSection(line) == true){
			char *section = getSection(line);
			//printf("Section: [%s]\r\n", section);
			do{
				char *sectionDataLine = GetNextLine(pbData, iDatasize, &pointer);
				char *key = NULL;
				char *value = NULL;
				if (sectionDataLine != NULL){
					key = getKey(sectionDataLine);
					value = getValue(sectionDataLine);
					if (key != NULL && value != NULL){
						config.put(section, key, value);
						//printf(" (%s) = |%s|\r\n", key, value);
						//printf()
					}
						
				}
				
				if (sectionDataLine != NULL) delete[] sectionDataLine;
				//if (key != NULL) delete[] key;
				//if (value != NULL) delete[] value;
			}
			while (lineInCurrentSection(pbData, iDatasize, &pointer) == true);
			//if(section != NULL) delete[] section;

		}
		if(line!=NULL) delete[]line;
	}
}
Exemple #3
0
char *
YpNextLine(int context)
{
  p_file *file;
  char *line;

  /* In skip-includes mode, remember where each line begins for
   * use by YpStandby.  */
  if (ypSkipIncludes && nYpIncludes && ypIncludes[nYpIncludes-1].file)
    rememberLine = p_ftell(ypIncludes[nYpIncludes-1].file);
  else
    rememberLine = -1;

  /* If there is an alternate input source, use it.  */
  if (YaltNextLine) {
    line = YaltNextLine(context);
    if (!line) YaltNextLine = 0;  /* "close" alternate input source */
    return line;
  }

  /* get the current include file */
  if (nYpIncludes==0) {
    file = 0;
  } else for (;;) {
    if ((file=ypIncludes[nYpIncludes-1].file)) break;
    need_endif = 0;
    p_free(ypIncludes[nYpIncludes-1].filename);
    if (!(--nYpIncludes)) break;
  }
  if (!file && nYpInputs) do file = YpPop(); while (!file && nYpInputs);

  /* quit if input is not from include file.  */
  if (!file) return 0;

  for (;;) {
    if (p_signalling) p_abort();
    /* Get an arbitrary (okay, < MAX_LINE) length input line.  */
    if (!GetNextLine(file, context)) return 0;
    /* if first line of file begins with #! discard it
     * (allows yorick source files to be scripts on most UNIX systems) */
    if (nYpIncludes && ypIncludes[nYpIncludes-1].lastLineRead==1 &&
        ypBuffer.line[0]=='#' && ypBuffer.line[1]=='!') {
      if (!GetNextLine(file, context)) return 0;
    }

    line = ypBuffer.line;
    if (line && context<=NL_CONTINUE) {
      int flag = yp_chk_hash(file, context, line);
      if (flag&1) {
        file = ypIncludes[nYpIncludes-1].file;
        continue;
      }
    }
    break;
  }

  yImpossible = 0;  /* tell YError that a line has come in */
  return line;
}
//--------------------------------------------------------------------
// @mfunc Tokenize the Provider info
//
// @rdesc BOOL
//      @flag TRUE | Parsing yielded no Error
//
BOOL CParseInitFile::ParseProviderInfo()
{
	//move to beginning of file
    seekg(0L);
	CHAR* pszStart = NULL;
	CHAR* pszEnd = NULL;
	CHAR szVersion[100];

	TRACE_CALL(L"PRIVLIB: CParseInitFile::ParseProviderInfo.\n");

	//Skip over any lines, until the [INFO] section is reached...
	//Make sure the INI contains the required version (at least)
	if( FindSection("[INFO]")==S_OK &&
		GetNextLine(m_pvInput, MAX_INPUT_BUFFER)==S_OK  &&
		(pszStart = strstr(m_pvInput, START_OF_TYPE)) &&
		(pszStart = strstr(pszStart, "VERSION=")) &&
		(pszStart = strstr(pszStart, ",")) &&
		(pszStart = strstr(pszStart+1, ",")) &&
		(pszEnd = strstr(pszStart+1, ",")) )
	{
		//Build Version is between 2nd and 3rd comma.  (1,50,3518,00)
		pszStart++;
		strncpy(szVersion, pszStart, (size_t)(pszEnd - pszStart));
		szVersion[pszEnd - pszStart] = '\0';
		ULONG ulVersion = strtoul(szVersion, NULL, 10);
		if(ulVersion == ULONG_MAX || ulVersion < 3518)
		{
			odtLog << "ERROR:  This version of the Privlib requires a INI File generated from " << ENDL;
			odtLog << "ERROR:  from TableDump.exe 1.50.3518.00 or later." << ENDL;
			return FALSE;
		}
	}
	else
	{
		odtLog << "ERROR:  Unable to find Versioning Information in INI <File:" << m_pszFileName << ">" << ENDL;
		odtLog << "ERROR:  This version of the Privlib requires a INI with a version section" << ENDL;
		odtLog << "ERROR:  and generated using a version of TableDump.exe 1.50.3518.00 or later." << ENDL;
		return FALSE;
	}

	//Get the NextLine {(TABLE=; DEFAULTQUERY=; DATASOURCE=; USERID=; PASSWORD=; etc... )}
	if(GetNextLine(m_pvInput, MAX_INPUT_BUFFER)!=S_OK ||
		(pszStart = strstr(m_pvInput, START_OF_TYPE))==NULL ||
		(pszStart = strstr(pszStart, "TABLE="))==NULL)
	{
		odtLog << "ERROR:  Unable to find InitString containing Initialization Information in INI <File:" << m_pszFileName << ">" << ENDL;
		odtLog << "ERROR:  Make sure your using a correctly generated INI File from TableDump.exe" << ENDL;
		return FALSE;
	}
    
	//We just need to append the InitString from the FILE to the InitString 
	//Already stored in the CModInfo from LTM.  And we will parse both together...
	GetModInfo()->AddToInitString(pszStart);
	return  TRUE;
}
//--------------------------------------------------------------------
// @mfunc Retrieve the data associated with a particular column. 
//
//
// @rdesc BOOL
//      @flag TRUE | Succeeded
//      @flag FALSE | Failed
//
BOOL CParseInitFile::ParseColumnInfo()
{
    HRESULT hr = S_OK;
	CHAR* pszStart = NULL;
	
	TRACE_CALL(L"PRIVLIB: CParseInitFile::ParseColumnInfo.\n");

	// If Column data has not been retrieved,
    if(m_ColData.IsEmpty())
	{
		//Skip over any lines, until the [COLUMN] section is reached...
		if(FAILED(hr = FindSection("[COLUMN]")))
			return FALSE;

		//Get the NextLine {ColName(iOrdinal, TYPE, ulColumnSize, bPrecision, bScale, dwFlags)} 
		if((hr = GetNextLine(m_pvInput, MAX_INPUT_BUFFER))!=S_OK)
		{
			odtLog << "ERROR:  Unable to find Columns in INI <File:" << m_pszFileName << ">" << ENDL;
			odtLog << "ERROR:  Make sure your using a correctly generated INI File from TableDump.exe" << ENDL;
			return FALSE;
		}

		//Now parse the Columns
		m_ColData.RemoveAll();
			    
		// Parse the records
		while(hr==S_OK)
		{	
			pszStart = strstr(m_pvInput, START_OF_TYPE);
			if(pszStart)
			{
				// if we have reached [DATA] part bail out
				pszStart++;
				if(strncmp(pszStart, szDATA, 6) ==0)
					return TRUE;
			
				// parse the column metadata info
				if(!GetColumns(pszStart))
					break;
			}
			
			//Retrieve the next row
			if((hr = GetNextLine(m_pvInput, MAX_INPUT_BUFFER))!=S_OK)
			{
				odtLog << "ERROR:  Unable to finding ColumnInfo for Column " << m_ColData.GetCount() << " in INI <File:" << m_pszFileName << ">" << ENDL;
				odtLog << "ERROR:  Make sure your using a correctly generated INI File from TableDump.exe" << ENDL;
				return FALSE;
			}
		}
    }

	return FALSE;
}
int CTextBase::CoreRequestHeight()
{
    int min = std::max(1, GetMinHeight());
    
    if (!m_Lines.empty())
        min = std::max(min, SafeConvert<int>(m_Lines.size()));
    
    if (!m_QueuedText.empty())
    {
        int lines = 0;
        const int width = RequestWidth();
        TSTLStrSize start = 0, end, length = m_QueuedText.length();
        
        while (start < length)
        {
            end = GetNextLine(m_QueuedText, start, width);
            lines++;
            start = end + 1;
        }
        
        min = std::max(min, lines);
    }
    
    if ((m_iMaxReqHeight > 0) && (min > m_iMaxReqHeight))
        min = m_iMaxReqHeight;
    
    return min;
}
int CTextBase::CoreRequestWidth()
{
    int min = std::max(1, GetMinWidth());
    
    if (m_LongestLine)
        min = std::max(min, SafeConvert<int>(m_LongestLine));
    
    if (!m_QueuedText.empty())
    {
        TSTLStrSize longest = 0, start = 0, end, length = m_QueuedText.length();
        const int width = (m_bWrap && (m_iMaxReqWidth > 0)) ? m_iMaxReqWidth : SafeConvert<int>(length);
        while (start < length)
        {
            end = GetNextLine(m_QueuedText, start, width);
            longest = std::max(longest, (end - start)+1);
            start = end + 1;
        }
        
        min = std::max(min, SafeConvert<int>(longest));
    }
    
    if ((m_iMaxReqWidth > 0) && (min > m_iMaxReqWidth))
        min = m_iMaxReqWidth;
    
    return min;
}
Exemple #8
0
// Get string from next line formated as follows : "Label information = STRING_NAME_HERE"
std::string BenchParams::GetNextString(std::ifstream &inFile) {
   std::string lineStr = GetNextLine(inFile);

   lineStr = lineStr.substr(lineStr.find('=') + 1);

   return lineStr.substr(lineStr.find_first_not_of(' '));
}
/** This function is called when we receive data from a remote
 * server.
 */
void TreeSocket::OnDataReady()
{
	Utils->Creator->loopCall = true;
	std::string line;
	while (GetNextLine(line))
	{
		std::string::size_type rline = line.find('\r');
		if (rline != std::string::npos)
			line = line.substr(0,rline);
		if (line.find('\0') != std::string::npos)
		{
			SendError("Read null character from socket");
			break;
		}

		try
		{
			ProcessLine(line);
		}
		catch (CoreException& ex)
		{
			ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error while processing: " + line);
			ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, ex.GetReason());
			SendError(ex.GetReason() + " - check the log file for details");
		}

		if (!getError().empty())
			break;
	}
	if (LinkState != CONNECTED && recvq.length() > 4096)
		SendError("RecvQ overrun (line too long)");
	Utils->Creator->loopCall = false;
}
Exemple #10
0
wxArrayString CTextFile::ReadLines(EReadTextFile flags, const wxMBConv& conv)
{
	wxArrayString lines;

	while (!Eof()) {
		wxString line = GetNextLine(conv);

		if (flags & txtStripWhitespace) {
			line = line.Strip(wxString::both);
		}

		if (flags & txtIgnoreEmptyLines) {
			if (line.IsEmpty()) {
				continue;
			}
		}
		
		if (flags & txtIgnoreComments) {
			if (flags & txtStripWhitespace) {
				if (line.StartsWith(wxT("#"))) {
					continue;
				}
			} else if (line.Strip(wxString::leading).StartsWith(wxT("#"))) {
				continue;
			}
		}

		lines.Add(line);
	}

	return lines;
}
void CTextBase::UpdateText(int width)
{
    TSTLStrSize length = m_QueuedText.length(), start = 0, end;
    
    if (!m_Lines.empty() && (m_Lines.back().rfind("\n") == std::string::npos))
    {
        // This makes adding text easier
        m_QueuedText = m_Lines.back() + m_QueuedText;
        m_Lines.pop_back();
    }
    
    while (start < length)
    {
        end = GetNextLine(m_QueuedText, start, width);
        
        TSTLStrSize newlen = (end-start)+1;
        m_Lines.push_back(m_QueuedText.substr(start, newlen));
            
        if (newlen > m_LongestLine)
            m_LongestLine = newlen;
            
        start = end + 1;
    }
    
    m_QueuedText.clear();
}
Exemple #12
0
// Get integer from next line formated as follows : "Label information = 5000"
long long BenchParams::GetNextInteger(std::ifstream &inFile) {
   std::string lineStr = GetNextLine(inFile);
   
   lineStr = lineStr.substr(lineStr.find ('=') + 1);
   lineStr = lineStr.substr(lineStr.find_first_not_of(' '));
   
   return std::atoll(lineStr.c_str());
}
int CSVReader::Read(vector<string>& tokens) {
	tokens.clear();

	string nextLine;
	if( GetNextLine(nextLine)<=0 ) {
		return -1;
	}
	Parse(nextLine, tokens);
	return 0;
}
Exemple #14
0
/*
 * Extracts a command from the engine input buffer.
 * 
 * The command is removed from the buffer.
 * If the command is a move, the move is made.
 */
void NextEngineCmd( void )
{
  char engineinput[BUF_SIZE]="";
  char enginemovestr[BUF_SIZE]="";
  leaf* enginemove;
  
  if ( strlen( engineinputbuf ) > 0 ) {
    if ( GetNextLine( engineinputbuf, engineinput ) > 0 ) {
      dbg_printf("< ENGINE: %s\n", engineinput);
      if ( strncmp( engineinput, "move", 4 ) == 0 ) {
        /* Input from engine is a move */
        sscanf( engineinput, "move %s", enginemovestr );
        enginemove = ValidateMove( enginemovestr );
        if ( enginemove == (leaf *) NULL ) {
          dbg_printf( "Bad move from engine\n" );
        } else {
          dbg_printf( "Engine move: <%s> (%d,%d)\n", enginemovestr,
                      (enginemove!=NULL ? enginemove->move : -1), 
                      (enginemove!=NULL ? enginemove->score : -1) );
          SANMove (enginemove->move, 1);
          MakeMove( board.side, &(enginemove->move) );
          strcpy (Game[GameCnt].SANmv, SANmv);
	  if ( !(flags & XBOARD) ) {
		  //ShowBoard();
                  dbg_printf("USER <: My move is : %s\n", SANmv);
		  //printf( "\nMy move is : %s\n", SANmv );
		  printf( "\n<%i:%i>\n", FROMSQ(enginemove->move), TOSQ(enginemove->move) );
                  fflush( stdout );
	  } else {
                  dbg_printf("USER <: %d. ... %s\n", GameCnt/2 + 1, enginemovestr );
                  printf ("%d. ... %s\n", GameCnt/2 + 1, enginemovestr );
                  fflush( stdout );
                  dbg_printf("USER <: My move is : %s\n", enginemovestr);
		  printf( "My move is : %s\n", enginemovestr );
                  fflush( stdout );
          }
          RealGameCnt = GameCnt;
          showprompt = 1;
          /* Check if the color must be changed, e.g. after a go command. */
          if ( changeColor ) {
            RealGameCnt = GameCnt;
            RealSide = board.side;
          }
        }
      } else {
        dbg_printf( "USER <: %s\n",engineinput );
        printf( "%s", engineinput );
        if ( flags & XBOARD ) {
          fflush( stdout );
        }
      }
    }
  }
}
Exemple #15
0
bool CAsmFile::ParseLineCMT()
{
	SetCurLine(0);
	CWord* pWord = NULL;

	do 
	{
		bool bCmt = false;
		while ((pWord = GetLineNextWord()) != NULL)
		{
			string& str = pWord->GetWord();
			if (str == "@")
			{
				bCmt = true;
			}
			if (bCmt)
			{
				pWord->SetAttrib(EWORD_COMMENT);
			}
		}
	} while (GetNextLine());
	SetCurLine(0);

	do 
	{
		bool bCmt = false;
		while ((pWord = GetLineNextWord()) != NULL)
		{
			string& str = pWord->GetWord();
			if (str == "//")
			{
				bCmt = true;
			}
			if (bCmt)
			{
				pWord->SetAttrib(EWORD_COMMENT);
			}
		}
	} while (GetNextLine());
	return true;
}
void CDummyUsbDevice::DoTestsL()
	{
	iTest.SetLogged(ETrue);
	iTest.Title();
	OpenFileL();
	TInt length = GetNextLine();
	if (length <= 0)
		{
		User::Panic(KUsbChargingTestPanic, EUsbChargingTestPanicBadInputData);
		}
	iLineNumber = 1;
	iTest.Start(_L("test"));
	InterpretLine();
	DoCommand();
	DoAsyncOp();
	}
Exemple #17
0
/*#F:#R:The complete current token line regardless of any token seperators contained
within it.*/
const char* CTokenParser::GetNextLine()
  {
  if (bNewLine)
    NextLine();
  bNewLine = 1;
  if (pFileInfo && pFileInfo->bUseIncludes && sTokenLine.GetLength()>pFileInfo->sIncludeChars.GetLength() && sTokenLine[0]==pFileInfo->sIncludeChars[0])
    if (pFileInfo->CheckForInclude())
      {//include file found
      sCurTok = "";
      sTokenLine = "";
      return GetNextLine();
      }
  sCurTok = sTokenLine;
  sTokenLine = "";
  return (const char*)sCurTok;
  }
BOOL PopulateAttrInfoFromFile(LPWSTR pwszFileName,ADS_ATTR_INFO * pattrInfo,DWORD &rdwNumPopulated )
{
    HRESULT hr = S_OK;
    BOOL    bRet = FALSE;
	FILE * fpInput = NULL;
    WCHAR  pwszLine[4096];
    rdwNumPopulated = 0;
	errno_t status = 0;

	if( (status = _wfopen_s( &fpInput, pwszFileName, L"r" )) == NULL )
	{
		wprintf(L"\nError Opening Input File:%s",pwszFileName);
		return FALSE;
	}

    while (GetNextLine(fpInput,pwszLine,4096) && SUCCEEDED(hr))
    {
        Trim(pwszLine);
        
        BSTR bsAttrib;
        BSTR bsValue;

        // Read the line into our BSTRS
        // if S_FALSE is returned, then we do not have a line
        // if E_FAIL is returned, then we have an error condition
        hr = ReadDataFromLine(pwszLine,&bsAttrib,&bsValue);

        if (hr == S_OK) 
        {
            wprintf(L" attrib:%s value:%s\n",bsAttrib,bsValue);
            
            // Take the attribute and value and add them to the Array
            if (!PopulateADSAttrInfo(&pattrInfo[rdwNumPopulated],bsAttrib,bsValue))
            {
                hr = E_FAIL;
                break;
            }

            SysFreeString(bsAttrib);
            SysFreeString(bsValue);

            rdwNumPopulated++;
        }
    }
	fclose(fpInput);
	return (SUCCEEDED(hr));
}
//--------------------------------------------------------------------
// @mfunc	Obtain the offsets into the file for each row
//			
//			
//
// @rdesc BOOL
//      @flag TRUE | Got the offsets, 
//      @flag FALSE | Could not obtain all the necessary info
//
BOOL CParseInitFile::ParseDataInfo()
{
	HRESULT hr = S_OK;
	m_cRows = 0;
	
	TRACE_CALL(L"PRIVLIB: CParseInitFile::ParseDataInfo.\n");

	//Skip over any lines, until the [DATA] section is reached...
	if(FAILED(hr = FindSection("[DATA]")))
		return FALSE;
    
	while(hr==S_OK)
    {
        //Check if we are provided with more rows than 
		//our current array can hold...
		if(m_cRows >= m_cRowOffsets || m_rgRowOffsets == NULL)
		{
			//Realloc the array
			m_cRowOffsets += MAX_ROW;
			m_rgRowOffsets = (DBLENGTH*)PROVIDER_REALLOC(m_rgRowOffsets, m_cRowOffsets*sizeof(DBLENGTH));
			if(m_rgRowOffsets == NULL)
				return FALSE;
		}
		
		//Save the Current Row Offset, so we can get this row data again
		//(ignoring null data)
        if(m_pvInput[0])
			m_rgRowOffsets[m_cRows] = tellg();
						
		//Get the NextLine of input
		//Note we allow S_FALSE to be returned for end of file...
		if(FAILED(hr = GetNextLine(m_pvInput, MAX_INPUT_BUFFER)))
		{
			odtLog << "ERROR:  Unable to find RowData for Row " << m_cRows+1 << " in INI <File:" << m_pszFileName << ">" << ENDL;
			odtLog << "ERROR:  Make sure your using a correctly generated INI File from TableDump.exe" << ENDL;
			return FALSE;
		}

		//We successfully retrieved this row...
		if(hr == S_OK)
			m_cRows++;
    }

	return TRUE;
}
void CDummyUsbDevice::RunL()
	{
	DoCheck();
	if (GetNextLine() < 0)
		{
		iTest.End();
		iTest.Getch();
		CActiveScheduler::Stop();
		}
	else
		{
		iLineNumber++;
		iTest.Next(_L(""));
		InterpretLine();
		DoCommand();
		DoAsyncOp();	
		}
	}
Exemple #21
0
/* Returns 0 on error - 0 is ALWAYS invalid */
int cpus_in_buff(struct buffer *b)
{
   char line[8]; /* We only need the first set of chars */
   int cpu_cnt = -1; /* Dont count the first cpu... line (it is total) */

   if ( NULL == b )
      return(0);

   if(FillReadBuff(b))
      return(0);

   while ( GetNextLine(line, b, 8) )
   {
      if (( line[0] == 'c' ) && ( line[1] == 'p' ) && ( line[2] == 'u' ))
         cpu_cnt++;
   }

   return(cpu_cnt);
}
//--------------------------------------------------------------------
// @mfunc Fetch row data into the internal data buffer
//
// @rdesc HRESULT
//      @flag S_OK    | Row Retrieved successfully
//      @flag S_FALSE | End of Result Set
//      @flag E_FAIL  | Row could not be retrieved
//
HRESULT CParseInitFile::FetchRow(DBCOUNTITEM iRow)
{
	TRACE_CALL(L"PRIVLIB: CParseInitFile::FetchRow.\n");

	//NOTE:  iRow is 1-based.
    //Validate arguments
    if(iRow == 0 || iRow > m_cRows)
        return E_FAIL;

	//Make sure we have the file open!
	if(!is_open())
		return E_FAIL;

    //Seek to the current Row offset
    seekg((LONG)GetRowOffset(iRow)); //64bit TODO - 

    // Retrieve the column names record
	return GetNextLine(m_pvInput, MAX_INPUT_BUFFER);
}
Exemple #23
0
bool CAsmFile::ParseKeyword()
{
	SetCurLine(0);
	CWord* pWord = NULL;

	do 
	{
		// bool bCmt = false;
		while ((pWord = GetLineNextWord()) != NULL)
		{
			if (pWord->GetAttrib() == EWORD_INIT)
			{
				pWord->SetAttrib(EWORD_KEYWORD);
				break;
			}
		}
	} while (GetNextLine());
	return true;
}
HRESULT CParseInitFile::FindSection(
	CHAR* pszSectionName,	//Name of section to find.
	CHAR* pszFirstReqSec	//Name of first required section if pszSectionName
							//is an optional section.
	)
{
	ASSERT(pszSectionName);
	size_t ulNameLen = strlen(pszSectionName);
	HRESULT hr = S_OK;

	//Loop over the File until we find the [sectionname] marker...
	CHAR* pszStartofType = strstr(m_pvInput, START_OF_TYPE);
	while(hr == S_OK)
	{
		//If we have a match were done!
		if(pszStartofType)
		{
			if(strncmp(pszStartofType+1, pszSectionName, ulNameLen)==0)
				return S_OK;
			else if(pszFirstReqSec)
			{
				size_t ulNameLen2 = strlen(pszFirstReqSec);

				if(strncmp(pszStartofType+1, pszFirstReqSec, ulNameLen2)==0)
					return S_FALSE;
			}
		}

		//Get the NextLine
		if((hr = GetNextLine(m_pvInput, MAX_INPUT_BUFFER))!=S_OK)
		{
			odtLog << "ERROR:  Unable to find " << pszSectionName <<" marker in INI <File:" << m_pszFileName << ">" << ENDL;
			odtLog << "ERROR:  Make sure your using a correctly generated INI File from TableDump.exe" << ENDL;
			return E_FAIL;
		}
		
		//Obtain the next starting element
		pszStartofType = strstr(m_pvInput, START_OF_TYPE);
	}

	return E_FAIL;
}
int CSVReader::Parse(string& nextLine, vector<string>& tokens) {
	string token;
	bool interQuotes = false;
	do {
		if (interQuotes) {
			token += '\n';
			if (GetNextLine(nextLine)<0) {
				break;
			}
		}
		
		for (int i = 0; i < (int)nextLine.length(); i++) {

			char c = nextLine.at(i);
			if (c == quote) {
               	if( interQuotes
               	    && (int)nextLine.length() > (i+1)
               	    && nextLine.at(i+1) == quote ){
               		token += nextLine.at(i+1);
               		i++;
               	}else{
               		interQuotes = !interQuotes;
               		if(i>2 
               			&& nextLine.at(i-1) != separator
               			&& (int)nextLine.length()>(i+1) 
               			&& nextLine.at(i+1) != separator
               		){
               			token += c;
               		}
               	}
			} else if (c == separator && !interQuotes) {
				tokens.push_back(token);
				token.clear();
			} else {
				token += c;
			}
		}
	} while (interQuotes);
	tokens.push_back(token);
	return 0;
}
Exemple #26
0
DWORD WINAPI CountWords(LPVOID arg) 
{
	DWORD dwWait;
	BOOL bDone = FALSE;
	char inLine[132];

	while( !bDone )
	{
        switch( WaitForSingleObject( hSemaphore, 0L ) ) 
        { 
            case WAIT_OBJECT_0:
				bDone = (GetNextLine(fd, inLine) == EOF);
				if( !bDone )
				{
					TotalWords += GetWordAndLetterCount(inLine);
				}
                ReleaseSemaphore( hSemaphore, 1, NULL);
			break; 
        }
	}
	return TRUE;
}
Exemple #27
0
/*
 * Extracts a command from the user input buffer.
 * 
 * The command is removed from the buffer.
 * If the command must be sent to the engine, it is sent.
 * This function relies on parse_input().
 */
void NextUserCmd( void )
{
  char userinput[BUF_SIZE]="";
  
  if ( strlen( userinputbuf ) > 0 ) {
    printf("TimeLimit[0] = %g\n", TimeLimit[0]);
    printf("TimeLimit[1] = %g\n", TimeLimit[1]);
    if ( flags & XBOARD ) {
      fflush( stdout );
    }
    if ( GetNextLine( userinputbuf, userinput ) > 0 ) {
      strcpy( inputstr, "" );
      strcpy( inputstr, userinput );
      dbg_printf( "USER >: %s\n", userinput );
      parse_input();
      /* Check if command/move must be sent to engine */
      if ( GetDataToEngine( dataToEngine ) ) {
        dbg_printf( "> ENGINE: %s\n", dataToEngine );
        SendToEngine( dataToEngine );
        if ( GetAutoGo() && UserInputIsAValidMove() ) {
            strcpy( userinputbuf, "go\n" );
            SetAutoGo( false );
        }
      }
      showprompt = !AnswerFromEngineExpected();
      /* Check if command was entered in manual mode */
      if ( (flags & MANUAL) && UserInputIsAValidMove() ) {
        RealGameCnt = GameCnt;
        RealSide = board.side;
        showprompt = 1;
      }
      /* Check if the color must be changed, e.g. after an undo command. */
      if ( changeColor ) {
        RealGameCnt = GameCnt;
        RealSide = board.side;
      }
    }
  } 
}
//
// Reads the version header from the file,
// returns the version number as a long integer.
// Expects the file pointer to be at the BEGINNING of the file.
// 1998.10.08 becomes 19981008.
//
// Return value of -1 indicates an error.  The calling function
// should NOT report an error.  Error reporting is handled here.
//
long ICF_ifstream::GetVersion()
{
	CString version_string;
	int major, middle, minor;
	long version;

	version_string = GetNextLine();
	if (version_string.IsEmpty())
	{
		ErrorMessage("File is improperly formatted.  Empty line found "
			"where file version information was expected.");
		return -1;
	}

	if (!ExtractFirstIntVersion(version_string, major)
		|| !ExtractFirstIntVersion(version_string, middle)
		|| !ExtractFirstIntVersion(version_string, minor))
	{
		ErrorMessage("File is improperly formatted.  "
			"Error retrieving file version information.");
		return -1;
	}

	version = (long) major * 10000 + middle * 100 + minor;

	// Special case test for ancient version "3.26.97" OLTP.txt
	// file distributed with 1998.01.05.
	if ( version == 32697 )
		version = 19980105;

	if ( version < 19980105 )
	{
		ErrorMessage( "Error restoring file.  "
			"Version number earlier than 1998.01.05 or incorrectly formatted." );
		return -1;
	}

	return version;
}
Exemple #29
0
/** This function is called when we receive data from a remote
 * server.
 */
void TreeSocket::OnDataReady()
{
	Utils->Creator->loopCall = true;
	std::string line;
	while (GetNextLine(line))
	{
		std::string::size_type rline = line.find('\r');
		if (rline != std::string::npos)
			line = line.substr(0,rline);
		if (line.find('\0') != std::string::npos)
		{
			SendError("Read null character from socket");
			break;
		}
		ProcessLine(line);
		if (!getError().empty())
			break;
	}
	if (LinkState != CONNECTED && recvq.length() > 4096)
		SendError("RecvQ overrun (line too long)");
	Utils->Creator->loopCall = false;
}
//
// Looks through the whole stream for the given identifier on a line
// by itself, puts the fstream file pointer at the beginning of the
// line below the identifier.
// NOTE: Strips leading and trailing whitespace, ignores case.
//
// Return value of FALSE indicates that the requested identifier was
// not found in the file.  In this case, the caller should generally
// not report an error, nor return a failure status.  If a user
// is restoring information from a config file and a section
// chosen for loading is not present in the saved file, an
// error should not be reported.
//
BOOL ICF_ifstream::SkipTo(CString identifier)
{
	CString curline;

	identifier.TrimLeft();
	identifier.TrimRight();
	
	do
	{
		if (eof())
			return FALSE;

		curline = GetNextLine();

		curline.TrimLeft();
		curline.TrimRight();
	}
	while ( identifier.CompareNoCase(curline.Left(identifier.GetLength())) != 0 );
	// Loop until the identifier is matched.  (Ignore the rest of the line when
	// comparing.)

	return TRUE;
}