Ejemplo n.º 1
0
int main(void)
{
	// To enable the writing into a log file, we have to set the handlers to use
	// We want to write to the stdcout _and_ a log file
	typedef Yuni::Logs::StdCout< Yuni::Logs::File<> >  MyLogHandlers;

	// Our logger
	Yuni::Logs::Logger<MyLogHandlers>  logs;

	// Creating the log file (in the current directory, read-write access required)
	logs.logfile("./sample.log");
	if (not logs.logfileIsOpened())
	{
		// An error has occured. That means the log file could not be opened for
		// writing for some reason
		// In this sample, we will continue anyway
		logs.error() << "Impossible to open the log file !";
		return EXIT_FAILURE;
	}

	logs.info() << "Log file : " << logs.logfile();

	// Hello, world !, all standard verbosity levels
	logs.checkpoint() << "Hello, " << "world !";
	logs.notice() << "Hello, " << "world !";
	logs.warning() << "Hello, " << "world !";
	logs.error() << "Hello, " << "world !";
	logs.debug() << "Hello, " << "world !";
	logs.fatal() << "Hello, " << "world !";

	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
	// All settings
	Settings settings;

	// arguments parsing
	ParseCommandLine(argc, argv, settings);


	Parser::PEG::Grammar grammar;
	grammar.onWarning.connect(& ParseWarning);
	grammar.onError.connect(& ParseError);

	String output;

	for (uint i = 0; i != (uint) settings.filenames.size(); ++i)
	{
		const String& url = settings.filenames[i];

		if (not IO::File::Exists(url))
		{
			logs.error() << "error: \"" << url << "\" file not found";
			hasError = true;
			continue;
		}

		if (grammar.loadFromFile(url))
		{
			//std::cout << grammar << std::endl;

			output = url;
			IO::ReplaceExtension(output, ".");

			switch (settings.format)
			{
				case Settings::sfCPP:
				{
					logs.info() << "generating c++ parser from " << url;
					grammar.exportToCPP(output, settings.namespaceName);
					break;
				}
			}
		}
		else
		{
			logs.error() << "impossible to load the grammar " << url;
			hasError = true;
		}
	}

	return (not hasError) ? 0 : EXIT_FAILURE;
}
Ejemplo n.º 3
0
static inline void ParseCommandLine(int argc, char** argv, Settings& settings)
{
	GetOpt::Parser options;
	String::Vector optFilenames;
	ShortString16 format;

	options.add(optFilenames, 'i', "input", "The input grammar");
	options.add(settings.namespaceName, 'n', "namespace", "The target namespace (mandatory)");
	options.add(format, 'f', "format", "Output format [cpp]");
	options.remainingArguments(optFilenames);

	if (not options(argc, argv))
	{
		if (options.errors())
		{
			std::cout << "Abort due to error" << std::endl;
			exit(EXIT_FAILURE);
		}
		exit(0);
	}

	if (optFilenames.empty())
	{
		logs.error() << "please provide a grammar file";
		exit(EXIT_FAILURE);
	}

	settings.namespaceName.trim(" \t\r\n.:");
	if (settings.namespaceName.empty())
	{
		logs.error() << "no namespace provided";
		exit(EXIT_FAILURE);
	}

	format.trim();
	format.toLower();
	if (format == "cpp")
	{
		settings.format = Settings::sfCPP;
	}
	else
	{
		logs.error() << "invalid output format";
		exit(EXIT_FAILURE);
	}

	settings.filenames.resize((uint) optFilenames.size());
	for (uint i = 0; i != (uint) optFilenames.size(); ++i)
		IO::Canonicalize(settings.filenames[i], optFilenames[i]);
}
Ejemplo n.º 4
0
int main(void)
{
	// A simple logger, which only display on std::cout/cerr
	// Please note that std::cerr can not be used on Windows (the messages would not be displayed)
	Yuni::Logs::Logger<>  logs;


	// Hello, world !, all standard verbosity levels
	logs.checkpoint() << "Hello, " << "world !";
	logs.notice() << "Hello, " << "world !";
	logs.warning() << "Hello, " << "world !";
	logs.error() << "Hello, " << "world !";
	logs.debug() << "Hello, " << "world !";
	logs.fatal() << "Hello, " << "world !";

	return 0;
}
Ejemplo n.º 5
0
static void ParseError(const AnyString& message)
{
	logs.error() << message;
	hasError = true;
}