bool OpTransform::Initialize()
{
  _dataLoaded=true;
  _transforms.clear();
  ifstream ifs;
  if(ifs.is_open())
    ifs.close();
  char charBuffer[BUFF_SIZE];

  // Set the locale for number parsing to avoid locale issues: PR#1785463
  obLocale.SetLocale();

  if(strcmp(_filename,"*"))
  {
    if(!strncmp(_filename,"TRANSFORM",9))//A single transform can replace the filename
    {
      ParseLine(_filename);
      return true;
    }
    OpenDatafile(ifs, _filename);
    if(!ifs)
    {
      obErrorLog.ThrowError(__FUNCTION__," Could not open " + string(_filename), obError);
      return false;
    }
    while(ifs.getline(charBuffer,BUFF_SIZE))
      ParseLine(charBuffer);
  }
  else //When filename is * use data in lines following
    for(int i=4;i<_textlines.size();++i)
      ParseLine(_textlines[i].c_str());
      
          
  // return the locale to the original one
  obLocale.RestoreLocale();
  
  return true;
}
Exemple #2
0
static void 
WebRunBinCmd(FILE *f, const char *query, int priv)
{
    Console		c = &gConsole;
    struct console_session css;
    ConsoleSession	cs = &css;
    char		*buf;
    char		*tmp;
    int			argc, k;
    char		*argv[MAX_CONSOLE_ARGS];
  
    memset(cs, 0, sizeof(*cs));

    cs->cookie = f;
    cs->console = c;
    cs->close = NULL;
    cs->write = WebConsoleSessionWrite;
    cs->writev = WebConsoleSessionWriteV;
    cs->prompt = WebConsoleSessionShowPrompt;
    cs->context.cs = cs;
    cs->context.priv = priv;

    tmp = buf = Mstrdup(MB_WEB, query);
    for (argc = 0; (argv[argc] = strsep(&tmp, "&")) != NULL;)
	if (argv[argc][0] != '\0')
    	    if (++argc >= MAX_CONSOLE_ARGS)
        	break;

    for (k = 0; k < argc; k++) {
	int	ac, rtn;
	char	*av[MAX_CONSOLE_ARGS];
	char	*buf1;

	buf1 = Malloc(MB_WEB, strlen(argv[k]) + 1);
	http_request_url_decode(argv[k], buf1);
        Log2(LG_CONSOLE, ("[%s] WEB: %s", 
	    cs->context.lnk ? cs->context.lnk->name :
		(cs->context.bund? cs->context.bund->name : ""), 
	    buf1));
	ac = ParseLine(buf1, av, sizeof(av) / sizeof(*av), 0);
	cs->context.errmsg[0] = 0;
	rtn = DoCommandTab(&cs->context, gCommands, ac, av);
	Freee(buf1);
	fprintf(f, "RESULT: %d %s\n", rtn, cs->context.errmsg);
    }
    Freee(buf);
    RESETREF(cs->context.lnk, NULL);
    RESETREF(cs->context.bund, NULL);
    RESETREF(cs->context.rep, NULL);
}
Exemple #3
0
// reads data from socket
void Read(int conn)
{
 char buffer[1024+1];
 
 // read request
 const int total = read(conn, buffer, 1024);
 
 // handle error
 if (total < 0) {
  printf("Error: read failed (%i)\n", errno);
  SendError(conn, 500, NULL);
  //AddToWatchList( conn );
  return;
 }
 
 // nothing read
 if (total == 0) return;

 // check if we got everything
 if (total == 1024) {
  char dummy;
  if (read(conn, &dummy, 1) > 0) {
   SendError(conn, 431, NULL);
   //AddToWatchList( conn );
   return;
  }
 }
 
 // terminate buffer
 buffer[total] = '\0';
 
 // reject if bad characters in request string
 for (int i=0; i<total; i++)
 {
  if (!IsValidChar( buffer[i] )) {
   //AddToWatchList( conn );
   return;
  }
 }
 
 //printf(">>> buffer:[%s]\n", buffer);
 
 // tokenize first line
 char *tok = strtok(buffer, "\r\n");
 
 // process
 if (tok) {
  ParseLine(conn, tok);
 }
}
Exemple #4
0
bool ObjectImporter::Import(std::wstring file, ImportedObjectData* rawData)
{
	size_t first = file.find_last_of('\\') + 1;
	size_t last = file.find_last_of('.');
	rawData->name = file.substr(first, last-first);
	

	std::wifstream in (file);
	if(!in.is_open())
	{
		std::wstring msg = L"Failed to open file: \n";
		msg.append(file);
		MessageBox(0, msg.c_str(), L"Import error", 0);
		return false;
	}
	else
	{
		std::wstring buff;

		while (!in.eof())
		{
			in >> buff;

			if(buff.size())
			{
				if(buff == ObjImpFormat::animationCount) 
				{ 
					int count = 0;
					if(!ParseInteger(in, count))
						return false;

					if(count)
					{
						rawData->animations.resize(count);
						if(!ParseAnimationFile(in, rawData))
							return false;
					}
					else		
						if(!ParseStandardFile(in, rawData))
							return false;
				}
				else { ParseLine(in, true); }
			}
		}

		in.close();
	}

	return true;
}
Exemple #5
0
// Return a list of all keys in a section
bool IniFile::GetKeys(const char* sectionName, std::vector<std::string>& keys) const
{
	const Section* section = GetSection(sectionName);
	if (!section)
		return false;
	keys.clear();
	for (std::vector<std::string>::const_iterator liter = section->lines.begin(); liter != section->lines.end(); ++liter)
	{
		std::string key;
		ParseLine(*liter, &key, 0, 0);
		keys.push_back(key);
	}
	return true;
}
void ConfigInfo::Parse(string fileName) {
	string line;
	ifstream fs(fileName.c_str());
	if (fs.is_open()) {
		param_set.clear();
		while (fs.good()) {
			getline(fs, line);
			ParseLine(line, '=');
		}
		fs.close();
	} else {
		cout << "Cannot open config file to read." << endl;
	}
}
   void ParseScene(SceneObjectList& objList, const char *ScenePath) {
      objList.clear();

      std::string line;
      RTextFile scenefile(ScenePath);

      K_LOG("ESceneParser -- Start parsing: %s",ScenePath);
      SceneObjectMap obj;
      while (scenefile.GetLine(line)) {
         ParseLine(obj,line);
         if (obj.size() > 0)
            objList.push_back(obj);
      }
      K_LOG("ESceneParser -- End parsing: %s",ScenePath); 
   }
Exemple #8
0
bool
NmeaReplay::ReadUntilRMC(NMEAInfo &data)
{
  char *buffer;

  while ((buffer = reader->ReadLine()) != NULL) {
    ParseLine(buffer, data);

    if (StringStartsWith(buffer, "$GPRMC") ||
        StringStartsWith(buffer, "$FLYSEN"))
      return true;
  }

  return false;
}
Exemple #9
0
void ParseFile(std::string Path)
{
	FILE *localFP;
	if ((localFP = fopen(Path.c_str(), READ)) == NULL)
	{
		error  = "File does not exist: ";
		
	}
	char line[MAX_RECORD_SIZE];
	//get each line
	while(fgets(line, sizeof(line), localFP) != NULL)
	{
		ParseLine(std::string(line));	
	}
}
Exemple #10
0
void
DeviceDescriptor::LineReceived(const char *line)
{
  NMEALogger::Log(line);

  if (pipe_to_device && pipe_to_device->port) {
    // stream pipe, pass nmea to other device (NmeaOut)
    // TODO code: check TX buffer usage and skip it if buffer is full (outbaudrate < inbaudrate)
    pipe_to_device->port->Write(line);
    pipe_to_device->port->Write("\r\n");
  }

  if (ParseLine(line))
    device_blackboard->ScheduleMerge();
}
bool MemoryWatcher::LoadAddresses(const std::string& path)
{
	std::ifstream locations(path);
	if (!locations)
	{
	  std::cout << "No MemoryWatcher Locations." << std::endl;
		return false;
	}

	std::string line;
	while (std::getline(locations, line))
		ParseLine(line);

	return m_values.size() > 0;
}
bool BezierParser::ParseFile(const std::string& filename)
{
	Clear();

	std::ifstream fs(filename.c_str());
	if(!fs) 
	{
		m_valid = false;
		return false;
	}

	std::string fileLine;
	char file_line[1000];
	while(!fs.eof()) 
	{
		fs.getline(file_line, 1000, '\n');
		fileLine = std::string(file_line);
		
		if(!ParseLine(fileLine))
		{ 
			fs.close();
			m_valid = false;
			return false; 
		}

		if(ParseStateDone == m_state)
		{ break; }
	}

	// eof
	if(SplineTypeBspline == m_curves[m_crvIdx].m_type)
	{
		if(ParseStatePoints == m_state)
		{
			m_state = ParseStateDone;
		}
	}
	else if(SplineTypeBezier == m_curves[m_crvIdx].m_type)
	{
		if(ParseStateNone == m_state)
		{
			m_state = ParseStateDone;
		}
	}

	fs.close();
	return (ParseStateDone == m_state);
}
	void SourceTASReader::ParseVariables()
	{
		while (ParseLine())
		{
			if (IsFramesLine())
			{
				break;
			}

			if (!freezeVariables)
				ParseVariable();
		}

		variables.Iteration(searchType);
		variables.PrintState();
	}
Exemple #14
0
void DOS_Shell::RunInternal(void)
{
	char input_line[CMD_MAXLINE] = {0};
	while(bf && bf->ReadLine(input_line)) 
	{
		if (echo) {
				if (input_line[0] != '@') {
					ShowPrompt();
					WriteOut_NoParsing(input_line);
					WriteOut_NoParsing("\n");
				};
			};
		ParseLine(input_line);
	}
	return;
}
GameplaySettings::GameplaySettings( const std::string& levelpath )
: playerSize( 10, 32 )
, playerOffset( 0, 0 )
{
	std::ifstream file( levelpath + "/gameplay.txt" );
	if( !file )
	{
		Debug::Error( "Could not open ", levelpath, "/gameplay.txt!" );
	}
	std::string curLine;
	while( std::getline( file, curLine ) )
	{
		std::transform( curLine.begin(), curLine.end(), curLine.begin(), std::tolower );
		ParseLine( curLine );
	}
}
Exemple #16
0
int FILE_ParseFile( const char *fileName, FILE_ParserCallback_t *callback )
{
    FILE       *fs = NULL;
    Parser_t    parser;
    char        line[ 100 ];
    int         rc = FALSE;

    memset( &parser, 0, sizeof( parser ));

    parser.lineNum = 0;
    parser.callback = callback;

    if (( fs = fopen( fileName, "rt" )) == NULL )
    {
        Error( &parser, "Unable to open file '%s' for reading", fileName );
        goto cleanup;
    }

    while ( fgets( line, sizeof( line ), fs ) != NULL )
    {
        parser.lineNum++;

        if ( !ParseLine( &parser, line ))
        {
            goto cleanup;
        }
    }
    if ( !Flush( &parser ))
    {
        goto cleanup;
    }

    // Everything went successfully

    rc = TRUE;

cleanup:

    if ( fs != NULL )
    {
        fclose( fs );
    }

    return rc;

} // FILE_ParseFile
void
WaypointReaderBase::Parse(Waypoints &way_points, TLineReader &reader,
                          OperationEnvironment &operation)
{
  const long filesize = std::max(reader.GetSize(), 1l);
  operation.SetProgressRange(100);

  // Read through the lines of the file
  TCHAR *line;
  for (unsigned i = 0; (line = reader.ReadLine()) != nullptr; i++) {
    // and parse them
    ParseLine(line, i, way_points);

    if ((i & 0x3f) == 0)
      operation.SetProgressPosition(reader.Tell() * 100 / filesize);
  }
}
Exemple #18
0
bool KNN::LoadCenteroidVec(string & fileName)
{
	 map<int,vector<float> > cache;

	 
	 ifstream fin(fileName.c_str());                                              
	 string line;                                                                 
     float featureDotProduct = 0.0;
	                                                                                                   
	 while(getline(fin,line))   
	 {

		vector<float> oneCentor;
		int catIndex;
		if(ParseLine(line,oneCentor,catIndex,m_FeatureSize,featureDotProduct)==false)
		{
			cout<<"Wrong:parsing knn model file("<<fileName<< ") wrong"<<endl;
			return false;
		}
		else
		{
			pair<int,vector<float> > value=make_pair(catIndex,oneCentor);
			cache.insert(value);
		}
        m_centoroidFeatureDotProduct.push_back(sqrt(featureDotProduct));
	 }

	 m_CatNum=cache.size();

	 /*transfer to memory data structure,note:according to the cat index number*/
	 map<int,vector<float> >::iterator it;
	 for(it=cache.begin();it!=cache.end();it++)
	 {
		m_centoroid.push_back((*it).second);

	 }


	 if(cache.size()!=m_CatNum)
	 {
		cout<<"Wrong:the category number is wrong!"<<endl;
		return false;
	 }

	 return true;
}
bool IsTimeFile(vector<string> &linesInFile)
{
	bool bIsValid = true;
	string currentLine;
	long line = 0;

	DateTimeRec time;
	VelocityRec velocity;

	currentLine = linesInFile[line++];

	std::replace(currentLine.begin(), currentLine.end(), ',', ' ');
	if (!ParseLine(currentLine, time, velocity))
		bIsValid = false;

	return bIsValid;
}
Exemple #20
0
/** Parse a teletext page
 * \param filename - Name of the teletext file
 * \return true if there is an error
 */
uint8_t ParsePage(PAGE *page, char *filename)
{
	FILE *file;
	char *str;
	const unsigned char MAXLINE=80;
	char line[MAXLINE];
	// printf("[Parse page]Started looking at %s\n",filename);
	// open the page
	file=fopen(filename,"r");
	if (!file)
	{
		printf("[Parse page]Failed to open tti page\n");			
		//put_rc(res);
		return 1;
	}
	// Shouldn't we clear the page at this point?
	ClearPage(page);
	// page->filesize=(unsigned int)file.fsize; // Not sure that Pi needs this
	// Read a line
	// printf("[ParsePage]Ready to parse\n");
	while (!feof(file))
	{
		str=fgets(line,MAXLINE,file);
		if (!str) break;	// Ooops, no more data
		/* debug
		for (i=0;i<16;i++)
			printf("%02x ",str[i]);
		printf("[ParsePage]Parsing a line %s\n",str);
		printf("\n");
		*/
		if (ParseLine(page,str))
		{
			fclose(file);
			return 1;
		}
		// printf("[ParsePage] chewing next line\n");
	}
	// printf("[ParsePage] mag=%d page=%X, subpage=%X\n",page->mag,page->page,page->subpage);
	// delay(1000);

	fclose(file);
	// printf("[Parse page]Ended\n");	
	
	return 0;
}
Exemple #21
0
int CConfigFileParser::LoadFile()
{
	if (!m_sFileName.length())
	{
		return -1;
	}

	FILE* fp = fopen(m_sFileName.c_str(), "r");
	if (!fp)
	{
		printf("can not open %s\n", m_sFileName.c_str());
		return -1;
	}

	char buf[256];
	for (;;)
	{
		buf[256]={0};
		char* p = fgets(buf, 256, fp);
		if (!p)
		{
           break;
		}

		if (0==strlen(buf)||'#' == buf[0] || '\n' == buf[0] || '\0' == buf[0])
		{
			continue;
		}

		char* ch = strchr(buf, '#');	// remove  #
		if (ch)
		{
           *ch = 0;
		}

		if (ParseLine(buf)!=0)
		{
			return -1;
		}
			
	}

	return 0;

}
Exemple #22
0
size_t cEnvelopeParser::Parse(const char * a_Data, size_t a_Size)
{
	if (!m_IsInHeaders)
	{
		return 0;
	}

	// Start searching 1 char from the end of the already received data, if available:
	auto searchStart = m_IncomingData.size();
	searchStart = (searchStart > 1) ? searchStart - 1 : 0;

	m_IncomingData.append(a_Data, a_Size);

	size_t idxCRLF = m_IncomingData.find("\r\n", searchStart);
	if (idxCRLF == AString::npos)
	{
		// Not a complete line yet, all input consumed:
		return a_Size;
	}

	// Parse as many lines as found:
	size_t Last = 0;
	do
	{
		if (idxCRLF == Last)
		{
			// This was the last line of the data. Finish whatever value has been cached and return:
			NotifyLast();
			m_IsInHeaders = false;
			return a_Size - (m_IncomingData.size() - idxCRLF) + 2;
		}
		if (!ParseLine(m_IncomingData.c_str() + Last, idxCRLF - Last))
		{
			// An error has occurred
			m_IsInHeaders = false;
			return AString::npos;
		}
		Last = idxCRLF + 2;
		idxCRLF = m_IncomingData.find("\r\n", idxCRLF + 2);
	} while (idxCRLF != AString::npos);
	m_IncomingData.erase(0, Last);

	// Parsed all lines and still expecting more
	return a_Size;
}
Exemple #23
0
Repl::Status Repl::RunOneCommand (const string& line, string* report) {
  int id;
  string command, params;

  ParseLine (line, &id, &command, &params);

  Io io(params);

  *report = "";
  if (command == "") return NoOp;

  if (IsCommand (command)) {
    // Callback call with optional fast return.
    BOOST_FOREACH (Callback& cmd, callbacks [command]) {
      io.PrepareIn();
      try { cmd (io); } catch (Return) { }
    }
  } else {
bool SRecordParser::ParseFile( FILE *fs )
{
   unsigned lineNum = 0;
   char     line[ 100 ];

   while ( fgets( line, sizeof( line ), fs ) != NULL )
   {
      lineNum++;

      if ( !ParseLine( lineNum, line ))
      {
         return false;
      }
   }
   Flush();

   return true;
}
Exemple #25
0
void
CConfig::LoadConfig(std::string path)
{
	std::string line = "";

	std::ifstream ifs(path.c_str(), std::ios::in);

	if(!ifs.good()) {
		iprintf("Config file (%s) does not exist or is not readable.", path.c_str());
		return;
	}

	while(ifs.good()) {
		getline(ifs, line);
		ParseLine(line);
	}

}
Exemple #26
0
 void ConfigReader::LoadFile() {
     if (m_filename.empty()) {
         return;
     }
     m_config_map.clear();
     FILE *fp = fopen(m_filename.c_str(), "r");
     if (!fp) {
         LOG(ERROR) << "ConfigReader::LoadFile() open file failed, file="
             << m_filename << ", err=" << strerror(errno);
         return;
     }
     char buf[DEFAULT_READ_BUFFER_SIZE];
     while (fgets(buf, 256, fp)) {
         ParseLine(buf);
     }
     fclose(fp);
     m_is_loaded = true;
 }
nsresult
nsHttpTransaction::ParseLineSegment(char *segment, PRUint32 len)
{
    NS_PRECONDITION(!mHaveAllHeaders, "already have all headers");

    if (!mLineBuf.IsEmpty() && mLineBuf.Last() == '\n') {
        // trim off the new line char, and if this segment is
        // not a continuation of the previous or if we haven't
        // parsed the status line yet, then parse the contents
        // of mLineBuf.
        mLineBuf.Truncate(mLineBuf.Length() - 1);
        if (!mHaveStatusLine || (*segment != ' ' && *segment != '\t')) {
            nsresult rv = ParseLine(mLineBuf.BeginWriting());
            mLineBuf.Truncate();
            if (NS_FAILED(rv)) {
                return rv;
            }
        }
    }

    // append segment to mLineBuf...
    if (mLineBuf.Length() + len > MAX_LINEBUF_LENGTH) {
        LOG(("excessively long header received, canceling transaction [trans=%x]", this));
        return NS_ERROR_ABORT;
    }
    mLineBuf.Append(segment, len);
    
    // a line buf with only a new line char signifies the end of headers.
    if (mLineBuf.First() == '\n') {
        mLineBuf.Truncate();
        // discard this response if it is a 100 continue or other 1xx status.
        PRUint16 status = mResponseHead->Status();
        if ((status != 101) && (status / 100 == 1)) {
            LOG(("ignoring 1xx response\n"));
            mHaveStatusLine = PR_FALSE;
            mHttpResponseMatched = PR_FALSE;
            mConnection->SetLastTransactionExpectedNoContent(PR_TRUE);
            mResponseHead->Reset();
            return NS_OK;
        }
        mHaveAllHeaders = PR_TRUE;
    }
    return NS_OK;
}
Exemple #28
0
void CHttpHeader::Parse(const std::string& strData)
{
  size_t pos = 0;
  const size_t len = strData.length();
  const char* const strDataC = strData.c_str();

  // According to RFC 2616 any header line can have continuation on next line, if next line is started from whitespace char
  // This code at first checks for whitespace char at the begging of the line, and if found, then current line is appended to m_lastHeaderLine
  // If current line is NOT started from whitespace char, then previously stored (and completed) m_lastHeaderLine is parsed and current line is assigned to m_lastHeaderLine (to be parsed later)
  while (pos < len)
  {
    size_t lineEnd = strData.find('\x0a', pos); // use '\x0a' instead of '\n' to be platform independent

    if (lineEnd == std::string::npos)
      return; // error: expected only complete lines

    const size_t nextLine = lineEnd + 1;
    if (lineEnd > pos && strDataC[lineEnd - 1] == '\x0d') // use '\x0d' instead of '\r' to be platform independent
      lineEnd--; 

    if (m_headerdone)
      Clear(); // clear previous header and process new one

    if (strDataC[pos] == ' ' || strDataC[pos] == '\t') // same chars as in CHttpHeader::m_whitespaceChars
    { // line is started from whitespace char: this is continuation of previous line
      pos = strData.find_first_not_of(m_whitespaceChars, pos);

      m_lastHeaderLine.push_back(' '); // replace all whitespace chars at start of the line with single space
      m_lastHeaderLine.append(strData, pos, lineEnd - pos); // append current line
    }
    else
    { // this line is NOT continuation, this line is new header line
      if (!m_lastHeaderLine.empty())
        ParseLine(m_lastHeaderLine); // process previously stored completed line (if any)

      m_lastHeaderLine.assign(strData, pos, lineEnd - pos); // store current line to (possibly) complete later. Will be parsed on next turns.

      if (pos == lineEnd)
        m_headerdone = true; // current line is bare "\r\n" (or "\n"), means end of header; no need to process current m_lastHeaderLine
    }

    pos = nextLine; // go to next line (if any)
  }
}
void
GFGLink::ParseClass
	(
	GFGClass* 		  list,
	const JCharacter* filename, 
	const JCharacter* classname
	)
{
	JBoolean ok	= kJTrue;
	if (itsCTagsProcess == NULL)
		{
		ok = StartCTags();
		}

	if (ok)
		{
		itsClassList	= list;
		itsCurrentClass	= classname;
		itsCurrentFile	= filename;

		JConvertToAbsolutePath(filename, "", &itsCurrentFile);

		itsCurrentFile.Print(*itsOutputLink);
		*itsOutputLink << std::endl;
		itsOutputLink->flush();

		JBoolean found = kJFalse;
		JString result = JReadUntil(itsInputFD, kDelimiter, &found);

		if (found)
			{
			JIndex findex;
			while (	result.LocateSubstring("\n", &findex) &&
					findex > 1)
				{
				JString line	= result.GetSubstring(1, findex - 1);
				result.RemoveSubstring(1, findex);
				ParseLine(line);
				}
			Broadcast(FileParsed());
			}
		}
}
Exemple #30
0
TaVarChooser::TaVarChooser(TString filename) : 
  fVarFile(0),
  isRead(kFALSE),
  opt_batteries(0),
  opt_ditbpms(0),
  opt_bpms(0),
  opt_hallbpms_sat(0),
  opt_bcms(0),
  opt_flumi(0),
  opt_blumi(0),
  opt_he4detectors(0),
  opt_lh2detectors(0),
  opt_bmw_words(0)
{

//   cout << "TaVarChooser():  Reading file: " << filename 
//        << endl;

  fVarFile = new ifstream(filename);
  if ( ! (*fVarFile) ) {
    cerr << "TaVarChooser::Load WARNING: variable file " << filename
	 << " does not exist." << endl;
    isRead = kFALSE;
  } else {
    string comment = "#";
    vector<string> strvect;
    TaString sinput,sline;
    while (getline(*fVarFile,sinput)) {
      strvect.clear();   strvect = sinput.Split();
      sline = "";
      for (vector<string>::iterator str = strvect.begin();
	   str != strvect.end(); str++) {
	if ( *str == comment ) break;
	sline += *str;   sline += " ";
      }
      if (sline == "") continue;
      strvect = sline.Split();
      //Parse here.
      ParseLine(strvect);
    }
    isRead = kTRUE;
  }
}