1
0
mirror of https://github.com/anope/anope.git synced 2026-07-06 19:23:15 +02:00

Made gettext work on most OSs. Tested on Debian, FreeBSD, Gentoo, and Windows.

Added a search path option to the Config script for cmake to use when finding libraries for modules or for gettext.
Fixed m_mysql and m_ssl to work under Windows, made the Windows Config
program remember the last used options, and fixed Windows release builds.
This commit is contained in:
Adam
2010-10-30 19:41:13 -04:00
parent a7e5d51616
commit fb9f41b3e5
29 changed files with 315 additions and 128 deletions
+5 -1
View File
@@ -79,8 +79,12 @@ add_executable(${PROGRAM_NAME} ${SRC_SRCS})
set_target_properties(${PROGRAM_NAME} PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}" ENABLE_EXPORTS ON)
# On Windows, also link Anope to the wsock32 and Ws2_32 library, as well as set the version
if(WIN32)
target_link_libraries(${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
target_link_libraries(${PROGRAM_NAME} wsock32 Ws2_32 ${GETTEXT_LIBRARIES} ${WIN32_MEMORY})
set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}")
else(WIN32)
if(GETTEXT_LIBRARIES)
target_link_libraries(${PROGRAM_NAME} ${GETTEXT_LIBRARIES})
endif(GETTEXT_LIBRARIES)
endif(WIN32)
# Building the Anope executable requires the language files to be compiled first as well as the version.h header to be generated
add_dependencies(${PROGRAM_NAME} language headers)
+1 -10
View File
@@ -138,16 +138,7 @@ if test "x$FAILED" = "x" ; then
echo ""
echo "Your MySQL setup is complete and your Anope schema is up to date. Make"
echo "sure you configure MySQL on your services.conf file prior to launching"
echo "Anope with MySQL support. Your configuration values are:"
echo ""
echo "mysql"
echo "{"
echo " database = \"$SQLDB\""
echo " server = \"$SQLHOST\""
echo " username = \"$SQLUSER\""
echo " password = \"$SQLPASS\""
echo " port = \"$SQLPORT\""
echo "}"
echo "Anope with MySQL support."
echo ""
else
echo "The following operations failed:"
+51 -30
View File
@@ -1,7 +1,7 @@
#include "services.h"
#if GETTEXT_FOUND
# include <libintl.h>
# include LIBINTL
# define _(x) gettext(x)
#else
# define _(x) x
@@ -38,40 +38,14 @@ void InitLanguages()
#endif
}
#if GETTEXT_FOUND
/* Used by gettext to make it always dynamically load language strings (so we can drop them in while Anope is running) */
extern "C" int _nl_msg_cat_cntr;
#endif
const Anope::string GetString(Anope::string language, LanguageString string)
const Anope::string GetString(const Anope::string &language, LanguageString string)
{
#if GETTEXT_FOUND
/* For older databases */
if (language == "en")
language.clear();
/* Apply def language */
if (language.empty() && !Config->NSDefLanguage.empty())
language = Config->NSDefLanguage;
if (language.empty())
#endif
return language_strings[string];
#if GETTEXT_FOUND
++_nl_msg_cat_cntr;
setenv("LANGUAGE", language.c_str(), 1);
setlocale(LC_ALL, language.c_str()); // This is only required by some systems, but must not be C or POSIX
const char *ret = dgettext("anope", language_strings[string].c_str());
unsetenv("LANGUAGE");
setlocale(LC_ALL, "");
return ret ? ret : "";
#endif
return GetString("anope", language, language_strings[string]);
}
const Anope::string GetString(LanguageString string)
{
return GetString("", string);
return GetString("anope", "", language_strings[string]);
}
const Anope::string GetString(const NickCore *nc, LanguageString string)
@@ -90,6 +64,53 @@ const Anope::string GetString(const User *u, LanguageString string)
return GetString(nc ? nc : (na ? na->nc : NULL), string);
}
#if GETTEXT_FOUND
/* Used by gettext to make it always dynamically load language strings (so we can drop them in while Anope is running) */
extern "C" int _nl_msg_cat_cntr;
const Anope::string GetString(const char *domain, Anope::string language, const Anope::string &string)
{
if (language == "en")
language.clear();
/* Apply def language */
if (language.empty() && !Config->NSDefLanguage.empty())
language = Config->NSDefLanguage;
if (language.empty())
return string;
++_nl_msg_cat_cntr;
#ifdef _WIN32
SetThreadLocale(MAKELCID(MAKELANGID(WindowsGetLanguage(language.c_str()), SUBLANG_DEFAULT), SORT_DEFAULT));
#else
/* First, set LANGUAGE env variable.
* Some systems (Debian) don't care about this, so we must setlocale LC_ALL aswell.
* BUT if this call fails because the LANGUAGE env variable is set, setlocale resets
* the locale to "C", which short circuits gettext and causes it to fail on systems that
* use the LANGUAGE env variable. We must reset the locale to en_US (or, anything not
* C or POSIX) then.
*/
setenv("LANGUAGE", language.c_str(), 1);
if (setlocale(LC_ALL, language.c_str()) == NULL)
setlocale(LC_ALL, "en_US");
#endif
const char *ret = dgettext(domain, string.c_str());
#ifdef _WIN32
SetThreadLocale(MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), SORT_DEFAULT));
#else
unsetenv("LANGUAGE");
setlocale(LC_ALL, "");
#endif
return ret ? ret : "";
}
#else
const Anope::string GetString(const char *domain, const Anope::string &language, const Anope::string &string)
{
return language_strings[string];
}
#endif
void SyntaxError(BotInfo *bi, User *u, const Anope::string &command, LanguageString message)
{
if (!bi || !u || command.empty())
+16 -16
View File
@@ -441,7 +441,7 @@ void ChannelModeInvex::DelMask(Channel *chan, const Anope::string &mask)
}
}
void StackerInfo::AddMode(Base *Mode, bool Set, const Anope::string &Param)
void StackerInfo::AddMode(Mode *mode, bool Set, const Anope::string &Param)
{
ChannelMode *cm = NULL;
UserMode *um = NULL;
@@ -449,13 +449,13 @@ void StackerInfo::AddMode(Base *Mode, bool Set, const Anope::string &Param)
if (Type == ST_CHANNEL)
{
cm = debug_cast<ChannelMode *>(Mode);
cm = debug_cast<ChannelMode *>(mode);
if (cm->Type == MODE_PARAM)
IsParam = true;
}
else if (Type == ST_USER)
{
um = debug_cast<UserMode *>(Mode);
um = debug_cast<UserMode *>(mode);
if (um->Type == MODE_PARAM)
IsParam = true;
}
@@ -478,7 +478,7 @@ void StackerInfo::AddMode(Base *Mode, bool Set, const Anope::string &Param)
/* The param must match too (can have multiple status or list modes), but
* if it is a param mode it can match no matter what the param is
*/
if (it->first == Mode && (Param.equals_cs(it->second) || IsParam))
if (it->first == mode && (Param.equals_cs(it->second) || IsParam))
{
list->erase(it);
/* It can only be on this list once */
@@ -491,7 +491,7 @@ void StackerInfo::AddMode(Base *Mode, bool Set, const Anope::string &Param)
/* The param must match too (can have multiple status or list modes), but
* if it is a param mode it can match no matter what the param is
*/
if (it->first == Mode && (Param.equals_cs(it->second) || IsParam))
if (it->first == mode && (Param.equals_cs(it->second) || IsParam))
{
otherlist->erase(it);
return;
@@ -503,7 +503,7 @@ void StackerInfo::AddMode(Base *Mode, bool Set, const Anope::string &Param)
}
/* Add this mode and its param to our list */
list->push_back(std::make_pair(Mode, Param));
list->push_back(std::make_pair(mode, Param));
}
/** Get the stacker info for an item, if one doesnt exist it is created
@@ -549,12 +549,12 @@ std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info)
if (info->Type == ST_CHANNEL)
{
cm = debug_cast<ChannelMode *>(it->first);
cm = dynamic_cast<ChannelMode *>(it->first);
buf += cm->ModeChar;
}
else if (info->Type == ST_USER)
{
um = debug_cast<UserMode *>(it->first);
um = dynamic_cast<UserMode *>(it->first);
buf += um->ModeChar;
}
@@ -578,12 +578,12 @@ std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info)
if (info->Type == ST_CHANNEL)
{
cm = debug_cast<ChannelMode *>(it->first);
cm = dynamic_cast<ChannelMode *>(it->first);
buf += cm->ModeChar;
}
else if (info->Type == ST_USER)
{
um = debug_cast<UserMode *>(it->first);
um = dynamic_cast<UserMode *>(it->first);
buf += um->ModeChar;
}
@@ -603,20 +603,20 @@ std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info)
/** Really add a mode to the stacker, internal use only
* @param bi The client to set the modes from
* @param Object The object, user/channel
* @param Mode The mode
* @param mode The mode
* @param Set Adding or removing?
* @param Param A param, if there is one
* @param Type The type this is, user or channel
*/
void ModeManager::StackerAddInternal(BotInfo *bi, Base *Object, Base *Mode, bool Set, const Anope::string &Param, StackerType Type)
void ModeManager::StackerAddInternal(BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type)
{
StackerInfo *s = GetInfo(Object);
s->Type = Type;
s->AddMode(Mode, Set, Param);
s->AddMode(mode, Set, Param);
if (bi)
s->bi = bi;
else if (Type == ST_CHANNEL)
s->bi = whosends(debug_cast<Channel *>(Object)->ci);
s->bi = whosends(dynamic_cast<Channel *>(Object)->ci);
else if (Type == ST_USER)
s->bi = NULL;
}
@@ -803,9 +803,9 @@ void ModeManager::ProcessModes()
Channel *c = NULL;
if (s->Type == ST_USER)
u = debug_cast<User *>(it->first);
u = dynamic_cast<User *>(it->first);
else if (s->Type == ST_CHANNEL)
c = debug_cast<Channel *>(it->first);
c = dynamic_cast<Channel *>(it->first);
else
throw CoreException("ModeManager::ProcessModes got invalid Stacker Info type");
+1 -1
View File
@@ -9,7 +9,7 @@
#include "modules.h"
#ifdef GETTEXT_FOUND
# include <libintl.h>
# include LIBINTL
#endif
Module::Module(const Anope::string &mname, const Anope::string &creator)
+3 -27
View File
@@ -12,10 +12,6 @@
#include "modules.h"
#include "version.h"
#if GETTEXT_FOUND
# include <libintl.h>
#endif
message_map MessageMap;
std::list<Module *> Modules;
@@ -286,36 +282,16 @@ Version Module::GetVersion() const
return Version(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
}
#if GETTEXT_FOUND
/* Used by gettext to make it always dynamically load language strings (so we can drop them in while Anope is running) */
extern "C" int _nl_msg_cat_cntr;
#endif
void Module::SendMessage(BotInfo *from, User *to, const char *fmt, ...)
{
Anope::string language = (to && to->Account() ? to->Account()->language : "");
/* For older databases */
if (language == "en")
language.clear();
if (language.empty() && !Config->NSDefLanguage.empty())
language = Config->NSDefLanguage;
const char *message = fmt;
#if GETTEXT_FOUND
if (!language.empty())
{
++_nl_msg_cat_cntr;
setenv("LANGUAGE", language.c_str(), 1);
setlocale(LC_ALL, language.c_str()); // This is only required by some systems, but must not be C or POSIX
message = dgettext(this->name.c_str(), fmt);
unsetenv("LANGUAGE");
setlocale(LC_ALL, "");
}
#endif
Anope::string message = GetString(this->name.c_str(), language, fmt);
va_list args;
char buf[4096];
va_start(args, fmt);
vsnprintf(buf, sizeof(buf) - 1, message, args);
vsnprintf(buf, sizeof(buf) - 1, message.c_str(), args);
va_end(args);
sepstream sep(buf, '\n');
+1 -1
View File
@@ -494,7 +494,7 @@ XLine *SGLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_
Anope::string realreason = reason;
if (u && Config->AddAkiller)
realreason = "[" + u->nick + "]" + reason;
realreason = "[" + u->nick + "] " + reason;
XLine *x = new XLine(mask, u ? u->nick : (OperServ ? OperServ->nick : "OperServ"), expires, realreason);
+2 -2
View File
@@ -26,7 +26,7 @@ class PipeIO : public SocketIO
int Recv(Socket *s, char *buf, size_t sz) const
{
static char dummy[512];
return read(s->GetFD(), &dummy, 512);
return recv(s->GetFD(), dummy, 512, 0);
}
/** Write something to the socket
@@ -38,7 +38,7 @@ class PipeIO : public SocketIO
{
static const char dummy = '*';
Pipe *pipe = debug_cast<Pipe *>(s);
return write(pipe->WritePipe, &dummy, 1);
return send(pipe->WritePipe, &dummy, 1, 0);
}
} pipeSocketIO;
+1 -1
View File
@@ -225,7 +225,7 @@ void SocketIO::Accept(ListenSocket *s)
{
sockaddrs conaddr;
socklen_t size = conaddr.size();
socklen_t size = sizeof(conaddr);
int newsock = accept(s->GetFD(), &conaddr.sa, &size);
#ifndef INVALID_SOCKET
+96 -4
View File
@@ -13,7 +13,7 @@
* Written by Scott <stealtharcher.scott@gmail.com>
* Written by Adam <Adam@anope.org>
*
* Compile with: csc /out:Config.exe Config.cs
* Compile with: csc /out:../../Config.exe /win32icon:anope-icon.ico Config.cs
*
*/
@@ -27,8 +27,8 @@ namespace Config
{
class Config
{
static string InstallDirectory, VSVersion, VSShortVer;
static bool UseNMake, BuildDebug;
static string InstallDirectory, VSVersion, VSShortVer, ExtraArguments;
static bool UseNMake = true, BuildDebug = false;
static bool CheckResponse(string InstallerResponse)
{
@@ -36,6 +36,78 @@ namespace Config
return true;
return false;
}
static bool LoadCache()
{
try
{
string[] cache = File.ReadAllLines("config.cache");
if (cache.Length > 0)
Console.WriteLine("Using defaults from config.cache");
foreach (string line in cache)
{
int e = line.IndexOf('=');
string name = line.Substring(0, e);
string value = line.Substring(e + 1);
if (name == "INSTDIR")
InstallDirectory = value;
else if (name == "DEBUG")
BuildDebug = CheckResponse(value);
else if (name == "USENMAKE")
UseNMake = CheckResponse(value);
else if (name == "EXTRAARGS")
ExtraArguments = value;
else if (name == "VSVERSION")
VSVersion = value;
else if (name == "VSSHORTVER")
VSShortVer = value;
}
return true;
}
catch (Exception) { }
return false;
}
static void SaveCache()
{
TextWriter tw = new StreamWriter("config.cache");
tw.WriteLine("INSTDIR=" + InstallDirectory);
tw.WriteLine("DEBUG=" + (BuildDebug ? "yes" : "no"));
tw.WriteLine("USENMAKE=" + (UseNMake ? "yes" : "no"));
tw.WriteLine("EXTRAARGS=" + ExtraArguments);
tw.WriteLine("VSVERSION=" + VSVersion);
tw.WriteLine("VSSHORTVER=" + VSShortVer);
tw.Close();
}
static string HandleCache(int i)
{
switch (i)
{
case 0:
Console.Write("[" + InstallDirectory + "] ");
return InstallDirectory;
case 1:
Console.Write("[" + UseNMake + "] ");
return (UseNMake ? "yes" : "no");
case 2:
Console.Write("[" + VSShortVer + "] ");
return VSShortVer;
case 3:
Console.Write("[" + BuildDebug + "] ");
return (BuildDebug ? "yes" : "no");
case 4:
Console.Write("[" + ExtraArguments + "] ");
return ExtraArguments;
default:
break;
}
return null;
}
static string FindAnopeVersion()
{
@@ -126,18 +198,27 @@ namespace Config
Console.WriteLine("Press Enter to begin");
Console.WriteLine("");
Console.ReadKey();
bool UseCache = LoadCache();
Dictionary<int, string> InstallerQuestions = new Dictionary<int, string>();
InstallerQuestions.Add(0, "Where do you want Anope to be installed?");
InstallerQuestions.Add(1, "Would you like to build using NMake instead of using Visual Studio?\r\nNOTE: If you decide to use NMake, you must be in an environment where\r\nNMake can function, such as the Visual Studio command line. If you say\r\nyes to this while not in an environment that can run NMake, it can\r\ncause the CMake configuration to enter an endless loop. [y/n]");
InstallerQuestions.Add(2, "Are you using Visual Studio 2008 or 2010? You can leave this blank\nand have CMake try and auto detect it, but this usually doesn't\nwork correctly. [2008/2010]");
InstallerQuestions.Add(3, "Would you like to build a debug version of Anope? [y/n]");
InstallerQuestions.Add(4, "Are there any extra arguments you wish to pass to cmake?\nYou may only need to do this if cmake is unable to locate missing dependencies without hints.\nTo do this, set the variable EXTRA_INCLUDE like this: -DEXTRA_INCLUDE:STRING=c:/some/path/include;c:/some/path/bin;c:/some/path/lib");
for (int i = 0; i < InstallerQuestions.Count; ++i)
{
Console.WriteLine(InstallerQuestions[i]);
string CacheResponse = null;
if (UseCache)
CacheResponse = HandleCache(i);
string InstallerResponse = Console.ReadLine();
Console.WriteLine("");
if (CacheResponse != null && (InstallerResponse == null || InstallerResponse.Length < 1))
InstallerResponse = CacheResponse;
if (InstallerResponse == null || InstallerResponse.Length < 1)
{
@@ -192,6 +273,9 @@ namespace Config
case 3:
BuildDebug = CheckResponse(InstallerResponse);
break;
case 4:
ExtraArguments = InstallerResponse;
break;
default:
break;
}
@@ -206,12 +290,20 @@ namespace Config
Console.WriteLine("Using Visual Studio: No");
Console.WriteLine("Build debug: {0}", BuildDebug ? "Yes" : "No");
Console.WriteLine("Anope Version: {0}", AnopeVersion); ;
if (ExtraArguments != null)
Console.WriteLine("Extra Arguments: {0}", ExtraArguments);
Console.WriteLine("Press Enter to continue...");
Console.ReadKey();
SaveCache();
if (ExtraArguments != null)
ExtraArguments += " ";
InstallDirectory = "-DINSTDIR:STRING=\"" + InstallDirectory.Replace('\\', '/') + "\" ";
string NMake = UseNMake ? "-G\"NMake Makefiles\" " : "";
string Debug = BuildDebug ? "-DCMAKE_BUILD_TYPE:STRING=DEBUG " : "-DCMAKE_BUILD_TYPE:STRING=RELEASE ";
string cMake = InstallDirectory + NMake + Debug + VSVersion + Environment.CurrentDirectory.Replace('\\','/');
string cMake = InstallDirectory + NMake + Debug + VSVersion + ExtraArguments + Environment.CurrentDirectory.Replace('\\','/');
RunCMake(cMake);
return 0;
+30
View File
@@ -12,6 +12,36 @@
#ifdef _WIN32
#include "services.h"
struct WindowsLanguage
{
const char *languageName;
USHORT windowsLanguageName;
};
WindowsLanguage WindowsLanguages[] = {
{"ca_ES", LANG_CATALAN},
{"de_DE", LANG_GERMAN},
{"el_GR", LANG_GREEK},
{"es_ES", LANG_SPANISH},
{"fr_FR", LANG_FRENCH},
{"hu_HU", LANG_HUNGARIAN},
{"it_IT", LANG_ITALIAN},
{"nl_NL", LANG_DUTCH},
{"pl_PL", LANG_POLISH},
{"pt_PT", LANG_PORTUGUESE},
{"ru_RU", LANG_RUSSIAN},
{"tr_TR", LANG_TURKISH},
{NULL, 0}
};
USHORT WindowsGetLanguage(const char *lang)
{
for (int i = 0; WindowsLanguages[i].languageName; ++i)
if (!strcmp(lang, WindowsLanguages[i].languageName))
return WindowsLanguages[i].windowsLanguageName;
return LANG_NEUTRAL;
}
/** This is inet_pton, but it works on Windows
* @param af The protocol type, AF_INET or AF_INET6
* @param src The address