// Goldie: GOLD Engine for D
// Written in the D programming language.

/++

This module contains common utility functions for Goldie's tools.

As with all of Goldie, you're certainly free to use this or adapt it for you
own use (in occordance with The zlib/libpng License). But, as-is, this module
is probably only useful for Goldie's tools.

+/

module tools.util;

import std.path;
import std.string;

import semitwist.util.all;

import goldie.all;

/// The directory in which to look for language files
/// whenever the language's filename isn't given.
/// This should always be terminated with a path separator.
string defaultLangDir;
static this()
{
	// Set default, but only if no other static class/module ctor has already set it
	if(defaultLangDir is null)
		defaultLangDir = getExecPath()~"../lang/";
}

string helpInfoHeader(string programName, string copyrightInfo)
{
	return
	("
		Goldie v"~goldieVerStr~" - "~programName~"
		Copyright (c) "~copyrightInfo~"
		See LICENSE.txt for license info
		Site: http://www.semitwist.com/goldie/
	").normalize();
}

string inferLanguageOf(string sourceFilename)
{
	return sourceFilename.getExt();
}

string inferLanguageFilenameOf(string sourceFilename)
{
	return getDefaultLanguageFilename(inferLanguageOf(sourceFilename));
}

string getDefaultLanguageFilename(string language)
{
	string dir = defaultLangDir;
	if(!dir.endsWith(pathSep))
		dir = dir~pathSep;

	return dir~language~".cgt";
}

