Example #1
0
LineArray CLineScanner::scan( char* buffer, unsigned long bufferSize )
{
	m_pBuffer = buffer;
	m_nBufferSize = bufferSize;
	reset();

	LineArray lines;
	char strLine[512] = {0};
	while ( readLine( strLine ) != -1 )
	{
		std::string singleLine = strLine;
		CC3String::trim( singleLine );
		if ( !singleLine.empty() )
		{
			lines.push_back( strLine );

			if ( m_pDelegate )
			{
				m_pDelegate->onScanLine( strLine );
			}
		}
	}

	return lines;
}
Example #2
0
   /// <summary>Opens a document template.</summary>
   /// <param name="docPath">document path.</param>
   /// <param name="t">template.</param>
   /// <returns></returns>
   BOOL ScriptDocument::OnOpenTemplate(Path docPath, const TemplateFile& t)
   {
      WorkerData data(Operation::LoadSaveDocument);
      
      try
      {
         // Feedback
         Console << Cons::UserAction << "Creating script: " << docPath << " from template: " << Path(t.SubPath) << ENDL;
         data.SendFeedback(ProgressType::Operation, 0, VString(L"Creating %s '%s'", t.Name.c_str(), docPath.c_str()));

         // Read/Parse template script
         AppPath path(t.SubPath);
         Script = ScriptFileReader(XFileInfo(path).OpenRead()).ReadFile(path, false);

         // Set properties
         Script.Name = docPath.RemoveExtension().FileName;
         Script.Game = PrefsLib.GameDataVersion;
         Script.Version = 1;
         Script.Description = L"no description";

         // Populate template
         LineArray lines;
         wstring date = COleDateTime(time(nullptr)).Format(L"%d/%m/%Y");
         for (auto& cmd : Script.Commands.Input)
         {
            cmd.Text = cmd.Text.ReplaceAll(L"$NAME$", Script.Name);
            cmd.Text = cmd.Text.ReplaceAll(L"$DATE$", date);
            cmd.Text = cmd.Text.ReplaceAll(L"$AUTHOR$", L"");
            lines.push_back(cmd.Text);
         }

         // Create temp scriptFile
         ScriptFile tmp(Script);
         tmp.FullPath = docPath;

         // Compile changes into temporary script
         ScriptParser parser(tmp, lines, Script.Game);
         parser.Compile();
         
         // Write to disc
         ScriptFileWriter w(XFileInfo(docPath).OpenWrite());
         w.Write(tmp);
         w.Close();

         // Feedback
         data.SendFeedback(Cons::Success, ProgressType::Succcess, 0, L"Script created successfully");
         return TRUE;
      }
      catch (ExceptionBase&  e)
      {
         // Feedback/Display error
         data.SendFeedback(Cons::Error, ProgressType::Failure, 0, VString(L"Failed to create %s '%s'", t.Name.c_str(), docPath.c_str()));
         theApp.ShowError(HERE, e, VString(L"Failed to create %s '%s'", t.Name.c_str(), docPath.c_str()));
         return FALSE;
      }
   }