Ejemplo n.º 1
0
WString GetDirectory(const WString& fileName)
{
	int index=0;
	for(int i=0;i<fileName.Length();i++)
	{
		if(fileName[i]==PATH_DELIMITER)
		{
			index=i;
		}
	}
	return fileName.Left(index+1);
}
Ejemplo n.º 2
0
bool WString::ReplaceAll(const WString &findWhat,const WString &replaceWith)
{
  WString process = *this;
  WString result;
  int pos;
  bool processed = false;
  while ((pos = process.Find(findWhat)) != -1)
  {
	result = result+process.Left(pos)+replaceWith;
	process = process.Right(pos+findWhat.GetLength());
	processed = true;
  }
  *this = result+process;
  return processed;
}
Ejemplo n.º 3
0
void FileTabs::ComposeTab(Tab& tab, const Font &font, Color ink, int style)
{
	if(PaintIcons() && tab.HasIcon())
	{
		tab.AddImage(tab.img);
		tab.AddSpace(TB_SPACEICON);
	}

	WString txt = IsString(tab.value) ? tab.value : StdConvert().Format(tab.value);
	int extpos = txt.ReverseFind('.');
	tab.AddText(extpos >= 0 ? txt.Left(extpos) : txt, font, filecolor);

	if (extpos >= 0) {
		tab.AddText(txt.Right(txt.GetLength() - extpos), font, extcolor);
	}
}
Ejemplo n.º 4
0
			bool GuiSinglelineTextBox::TextElementOperatorCallback::BeforeModify(TextPos start, TextPos end, const WString& originalText, WString& inputText)
			{
				vint length=inputText.Length();
				const wchar_t* input=inputText.Buffer();
				for(vint i=0;i<length;i++)
				{
					if(*input==0 || *input==L'\r' || *input==L'\n')
					{
						length=i;
						break;
					}
				}
				if(length!=inputText.Length())
				{
					inputText=inputText.Left(length);
				}
				return true;
			}
Ejemplo n.º 5
0
		void FilePath::GetPathComponents(WString path, collections::List<WString>& components)
		{
			WString pathRemaining = path;
			WString delimiter = Delimiter;

			components.Clear();

			while(true)
			{
				auto index = INVLOC.FindFirst(pathRemaining, delimiter, Locale::None);
				if (index.key == -1)
					break;

				if(index.key != 0)
					components.Add(pathRemaining.Left(index.key));
				else
				{
#if defined VCZH_GCC
					// Unix absolute path starting with "/"
					// components[0] will be L"/"
					components.Add(delimiter);
#elif defined VCZH_MSVC
					if(pathRemaining.Length() >= 2 && pathRemaining[1] == Delimiter)
					{
						// Windows UNC Path starting with "\\"
						// components[0] will be L"\\"
						components.Add(L"\\");
						index.value++;
					}
#endif
				}

				pathRemaining = pathRemaining.Right(pathRemaining.Length() - (index.key + index.value));
			}

			if(pathRemaining.Length() != 0)
			{
				components.Add(pathRemaining);
			}
		}
Ejemplo n.º 6
0
int main(int argc, char* argv[])
#endif
{
	WString baseDirectory;
	{
#if defined VCZH_MSVC
		wchar_t currentDirectory[MAX_PATH]={0};
		GetCurrentDirectory(MAX_PATH, currentDirectory);
		baseDirectory=currentDirectory;
#elif defined VCZHGCC
		char currentDirectory[1024]={0};
		getcwd(currentDirectory, 1024);
		baseDirectory=atow(currentDirectory);
#endif
		if(baseDirectory[baseDirectory.Length()-1]!=PATH_DELIMITER)
		{
			baseDirectory+=PATH_DELIMITER;
		}
	}


	Regex regexPathSplitter(L"[///\\]");
	Ptr<ParsingGeneralParser> parser=CreateBootstrapStrictParser();

	Console::SetTitle(L"Vczh Parser Generator for C++");
	Console::SetColor(false, true, false, true);
	Console::WriteLine(L"parsing>Files : "+itow(argc-1));
	for(int i=1;i<argc;i++)
	{
		Console::WriteLine(L"------------------------------------------------------------");
#if defined VCZH_MSVC
		WString inputPath=argv[i];
#elif defined VCZH_GCC
		WString inputPath=atow(argv[i]);
#endif
		if(inputPath.Length()<2 || inputPath[1]!=L':')
		{
			inputPath=baseDirectory+inputPath;
		}
		Console::WriteLine(L"parsing>Making : "+inputPath);
		if(inputPath.Length()<11 || inputPath.Right(11)!=L".parser.txt")
		{
			Console::SetColor(true, false, false, true);
			Console::WriteLine(L"error> The extenion name of the input file path must be \".parser.txt\".");
			Console::SetColor(false, true, false, true);
		}
		else
		{
			WString name;
			{
				List<Ptr<RegexMatch>> matches;
				regexPathSplitter.Split(inputPath, true, matches);
				name=matches[matches.Count()-1]->Result().Value();
				name=name.Left(name.Length()-11);
			}
			WString outputMetaPath=inputPath.Left(inputPath.Length()-11);
			WString outputHeaderPath=outputMetaPath+L".h";
			WString outputCppPath=outputMetaPath+L".cpp";
			WString logPath=outputMetaPath+L".log";
			Console::WriteLine(L"parsing>Output header path : "+outputHeaderPath);
			Console::WriteLine(L"parsing>Output cpp path : "+outputCppPath);
			Console::WriteLine(L"parsing>Log path : "+logPath);

			CodegenConfig config;
			WString codeGrammar;
			{
				FileStream fileStream(inputPath, FileStream::ReadOnly);
				if(!fileStream.IsAvailable())
				{
					Console::SetColor(true, false, false, true);
					Console::WriteLine(L"error> Cannot open \""+inputPath+L" for read.");
					Console::SetColor(false, true, false, true);
					goto STOP_PARSING;
				}
				BomDecoder decoder;
				DecoderStream decoderStream(fileStream, decoder);
				StreamReader reader(decoderStream);

				if(!config.ReadConfig(reader))
				{
					goto STOP_PARSING;
				}
				codeGrammar=reader.ReadToEnd();
			}

			Ptr<ParsingDefinition> definition;
			Ptr<ParsingTable> table;
			{
				FileStream fileStream(logPath, FileStream::WriteOnly);
				if(!fileStream.IsAvailable())
				{
					Console::SetColor(true, false, false, true);
					Console::WriteLine(L"error> Cannot open \""+logPath+L" for write.");
					Console::SetColor(false, true, false, true);
					goto STOP_PARSING;
				}
				BomEncoder encoder(BomEncoder::Utf16);
				EncoderStream encoderStream(fileStream, encoder);
				StreamWriter writer(encoderStream);
				
				if(codeGrammar==L"<bootstrap-grammar>")
				{
					definition=CreateParserDefinition();
					MemoryStream bootstrapStream;
					{
						StreamWriter bootstrapWriter(bootstrapStream);
						Log(definition, bootstrapWriter);
					}
					bootstrapStream.SeekFromBegin(0);
					StreamReader bootstrapReader(bootstrapStream);
					codeGrammar=bootstrapReader.ReadToEnd();
				}
				else
				{
					definition=CreateDefinition(parser, codeGrammar, writer);
				}
				if(!definition)
				{
					Console::SetColor(true, false, false, true);
					Console::WriteLine(L"error> Error happened. Open \""+logPath+L" for details.");
					Console::SetColor(false, true, false, true);
					goto STOP_PARSING;
				}

				table=CreateTable(definition, writer, config.ambiguity);
				if(!table)
				{
					Console::SetColor(true, false, false, true);
					Console::WriteLine(L"error> Error happened. Open \""+logPath+L" for details.");
					Console::SetColor(false, true, false, true);
					goto STOP_PARSING;
				}
			}
			{
				FileStream fileStream(outputHeaderPath, FileStream::WriteOnly);
				if(!fileStream.IsAvailable())
				{
					Console::SetColor(true, false, false, true);
					Console::WriteLine(L"error> Cannot open \""+outputHeaderPath+L" for write.");
					Console::SetColor(false, true, false, true);
					goto STOP_PARSING;
				}
				BomEncoder encoder(BomEncoder::Mbcs);
				EncoderStream encoderStream(fileStream, encoder);
				StreamWriter writer(encoderStream);
				WriteHeaderFile(name, definition, table, config, writer);
			}
			{
				FileStream fileStream(outputCppPath, FileStream::WriteOnly);
				if(!fileStream.IsAvailable())
				{
					Console::SetColor(true, false, false, true);
					Console::WriteLine(L"error> Cannot open \""+outputCppPath+L" for write.");
					Console::SetColor(false, true, false, true);
					goto STOP_PARSING;
				}
				BomEncoder encoder(BomEncoder::Mbcs);
				EncoderStream encoderStream(fileStream, encoder);
				StreamWriter writer(encoderStream);
				
				config.includes.Clear();
				config.includes.Add(L"\""+name+L".h\"");
				WriteCppFile(name, codeGrammar, definition, table, config, writer);
			}
		}
	STOP_PARSING:;
	}
	Console::WriteLine(L"Finished!");
	return 0;
}