summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-10-30 19:41:13 -0400
committerAdam <Adam@anope.org>2010-10-30 19:41:13 -0400
commitfb9f41b3e52cfddada7773a65b9723cd3a96b785 (patch)
treebd97f21b4a5098d43f2a680ae09136f3e0ef6bb5 /src
parenta7e5d51616363214d391500b2d9d647379fba833 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt6
-rwxr-xr-xsrc/bin/mydbgen11
-rw-r--r--src/language.cpp81
-rw-r--r--src/modes.cpp32
-rw-r--r--src/module.cpp2
-rw-r--r--src/modules.cpp30
-rw-r--r--src/operserv.cpp2
-rw-r--r--src/socketengines/socketengine_win32.cpp4
-rw-r--r--src/sockets.cpp2
-rw-r--r--src/win32/Config.cs100
-rw-r--r--src/win32/windows.cpp30
11 files changed, 207 insertions, 93 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a9f77f40b..617029a9b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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)
diff --git a/src/bin/mydbgen b/src/bin/mydbgen
index 7e3d1929b..12bee8063 100755
--- a/src/bin/mydbgen
+++ b/src/bin/mydbgen
@@ -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:"
diff --git a/src/language.cpp b/src/language.cpp
index d5fe5d40b..000b4d103 100644
--- a/src/language.cpp
+++ b/src/language.cpp
@@ -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())
diff --git a/src/modes.cpp b/src/modes.cpp
index 16bb1590b..e8ee076fc 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -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");
diff --git a/src/module.cpp b/src/module.cpp
index 2b7676550..f5c3a9194 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -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)
diff --git a/src/modules.cpp b/src/modules.cpp
index c15f468e8..1fc83c06e 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -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');
diff --git a/src/operserv.cpp b/src/operserv.cpp
index ef561a03d..2d509f25f 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -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);
diff --git a/src/socketengines/socketengine_win32.cpp b/src/socketengines/socketengine_win32.cpp
index 240c4282e..78d4bf92d 100644
--- a/src/socketengines/socketengine_win32.cpp
+++ b/src/socketengines/socketengine_win32.cpp
@@ -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;
diff --git a/src/sockets.cpp b/src/sockets.cpp
index f22238fcc..9e32f85eb 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -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
diff --git a/src/win32/Config.cs b/src/win32/Config.cs
index cdd64a6f1..fd1cbbfda 100644
--- a/src/win32/Config.cs
+++ b/src/win32/Config.cs
@@ -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;
diff --git a/src/win32/windows.cpp b/src/win32/windows.cpp
index 5f0c6d5e4..af37282c8 100644
--- a/src/win32/windows.cpp
+++ b/src/win32/windows.cpp
@@ -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